Skip to content

Commit 30ddbbf

Browse files
committed
Be slightly more efficient when doing ray-mesh intersection tests
1 parent 1002a14 commit 30ddbbf

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/3d/terrain/qgsdemterraintilegeometry_p.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,7 @@ static bool intersectionDemTriangles( const QByteArray &vertexBuf, const QByteAr
303303

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

312309
void DemTerrainTileGeometry::init()
@@ -357,8 +354,10 @@ void DemTerrainTileGeometry::init()
357354
// Each primitive has 3 vertives
358355
mIndexAttribute->setCount( faces * 3 );
359356

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

363362
addAttribute( mPositionAttribute );
364363
addAttribute( mTexCoordAttribute );

0 commit comments

Comments
 (0)