Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Be slightly more efficient when doing ray-mesh intersection tests
  • Loading branch information
wonder-sk committed Jun 28, 2018
1 parent 1002a14 commit 30ddbbf
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/3d/terrain/qgsdemterraintilegeometry_p.cpp
Expand Up @@ -303,10 +303,7 @@ static bool intersectionDemTriangles( const QByteArray &vertexBuf, const QByteAr

bool DemTerrainTileGeometry::rayIntersection( const QgsRayCastingUtils::Ray3D &ray, const QMatrix4x4 &worldTransform, QVector3D &intersectionPoint )
{
// TODO: optimize this so we do not recreate vertex/index buffer every time!!!
QByteArray vertexBuf = ( *mVertexBuffer->dataGenerator() )();
QByteArray indexBuf = ( *mIndexBuffer->dataGenerator() )();
return intersectionDemTriangles( vertexBuf, indexBuf, ray, worldTransform, intersectionPoint );
return intersectionDemTriangles( mVertexBuffer->data(), mIndexBuffer->data(), ray, worldTransform, intersectionPoint );
}

void DemTerrainTileGeometry::init()
Expand Down Expand Up @@ -357,8 +354,10 @@ void DemTerrainTileGeometry::init()
// Each primitive has 3 vertives
mIndexAttribute->setCount( faces * 3 );

mVertexBuffer->setDataGenerator( QSharedPointer<PlaneVertexBufferFunctor>::create( mResolution, mSkirtHeight, mHeightMap ) ); // skip-keyword-check
mIndexBuffer->setDataGenerator( QSharedPointer<PlaneIndexBufferFunctor>::create( mResolution, mHeightMap ) ); // skip-keyword-check
// switched to setting data instead of just setting data generators because we also need the buffers
// available for ray-mesh intersections and we can't access the private copy of data in Qt (if there is any)
mVertexBuffer->setData( PlaneVertexBufferFunctor( mResolution, mSkirtHeight, mHeightMap )() );
mIndexBuffer->setData( PlaneIndexBufferFunctor( mResolution, mHeightMap )() );

addAttribute( mPositionAttribute );
addAttribute( mTexCoordAttribute );
Expand Down

0 comments on commit 30ddbbf

Please sign in to comment.