From e896ce0e4ef3c44e695c74e2e60c209d5eb72f41 Mon Sep 17 00:00:00 2001 From: rextimmy Date: Wed, 4 Jan 2017 01:47:43 +1000 Subject: [PATCH] Cache PxRenderBuffer --- Engine/source/T3D/physics/physx3/px3World.cpp | 27 +++++++++---------- Engine/source/T3D/physics/physx3/px3World.h | 1 + 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Engine/source/T3D/physics/physx3/px3World.cpp b/Engine/source/T3D/physics/physx3/px3World.cpp index ca5be2302..888417afa 100644 --- a/Engine/source/T3D/physics/physx3/px3World.cpp +++ b/Engine/source/T3D/physics/physx3/px3World.cpp @@ -63,7 +63,8 @@ Px3World::Px3World(): mScene( NULL ), mEditorTimeScale( 1.0f ), mAccumulator( 0 ), mControllerManager(NULL), - mIsSceneLocked(false) + mIsSceneLocked(false), + mRenderBuffer(NULL) { } @@ -177,6 +178,8 @@ void Px3World::destroyWorld() { getPhysicsResults(); + mRenderBuffer = NULL; + // Release the tick processing signals. if ( mProcessList ) { @@ -223,13 +226,14 @@ bool Px3World::initWorld( bool isServer, ProcessList *processList ) sceneDesc.cpuDispatcher = smCpuDispatcher; Con::printf("PhysX3 using Cpu: %d workers", smCpuDispatcher->getWorkerCount()); } - sceneDesc.flags |= physx::PxSceneFlag::eENABLE_CCD; sceneDesc.flags |= physx::PxSceneFlag::eENABLE_ACTIVETRANSFORMS; sceneDesc.filterShader = physx::PxDefaultSimulationFilterShader; mScene = gPhysics3SDK->createScene(sceneDesc); + //cache renderbuffer for use with debug drawing + mRenderBuffer = const_cast(&mScene->getRenderBuffer()); physx::PxDominanceGroupPair debrisDominance( 0.0f, 1.0f ); mScene->setDominanceGroupPair(0,31,debrisDominance); @@ -548,22 +552,17 @@ static ColorI getDebugColor( physx::PxU32 packed ) void Px3World::onDebugDraw( const SceneRenderState *state ) { - if ( !mScene ) + if ( !mScene || !mRenderBuffer ) return; mScene->setVisualizationParameter(physx::PxVisualizationParameter::eSCALE,1.0f); mScene->setVisualizationParameter(physx::PxVisualizationParameter::eBODY_AXES,1.0f); mScene->setVisualizationParameter(physx::PxVisualizationParameter::eCOLLISION_SHAPES,1.0f); - const physx::PxRenderBuffer *renderBuffer = &mScene->getRenderBuffer(); - - if(!renderBuffer) - return; - // Render points { - physx::PxU32 numPoints = renderBuffer->getNbPoints(); - const physx::PxDebugPoint *points = renderBuffer->getPoints(); + physx::PxU32 numPoints = mRenderBuffer->getNbPoints(); + const physx::PxDebugPoint *points = mRenderBuffer->getPoints(); PrimBuild::begin( GFXPointList, numPoints ); @@ -579,8 +578,8 @@ void Px3World::onDebugDraw( const SceneRenderState *state ) // Render lines { - physx::PxU32 numLines = renderBuffer->getNbLines(); - const physx::PxDebugLine *lines = renderBuffer->getLines(); + physx::PxU32 numLines = mRenderBuffer->getNbLines(); + const physx::PxDebugLine *lines = mRenderBuffer->getLines(); PrimBuild::begin( GFXLineList, numLines * 2 ); @@ -598,8 +597,8 @@ void Px3World::onDebugDraw( const SceneRenderState *state ) // Render triangles { - physx::PxU32 numTris = renderBuffer->getNbTriangles(); - const physx::PxDebugTriangle *triangles = renderBuffer->getTriangles(); + physx::PxU32 numTris = mRenderBuffer->getNbTriangles(); + const physx::PxDebugTriangle *triangles = mRenderBuffer->getTriangles(); PrimBuild::begin( GFXTriangleList, numTris * 3 ); diff --git a/Engine/source/T3D/physics/physx3/px3World.h b/Engine/source/T3D/physics/physx3/px3World.h index 9556aac4b..7a14ef4af 100644 --- a/Engine/source/T3D/physics/physx3/px3World.h +++ b/Engine/source/T3D/physics/physx3/px3World.h @@ -61,6 +61,7 @@ protected: ProcessList *mProcessList; F32 mEditorTimeScale; bool mErrorReport; + physx::PxRenderBuffer *mRenderBuffer; physx::PxControllerManager* mControllerManager; static Px3ConsoleStream *smErrorCallback; static physx::PxDefaultAllocator smMemoryAlloc;