From 6b97e1e6047007b5ea4f29348b52de9dbfa6b3bc Mon Sep 17 00:00:00 2001 From: yunfeibai Date: Tue, 20 Mar 2018 21:28:47 -0700 Subject: [PATCH] Expose API to set projective texture instead of using global. --- Extras/BulletRobotics/CMakeLists.txt | 2 +- examples/CommonInterfaces/CommonGUIHelperInterface.h | 5 +++++ examples/CommonInterfaces/CommonRenderInterface.h | 1 + examples/ExampleBrowser/OpenGLGuiHelper.cpp | 5 +++++ examples/ExampleBrowser/OpenGLGuiHelper.h | 1 + examples/OpenGLWindow/GLInstancingRenderer.cpp | 11 +++++++++-- examples/OpenGLWindow/GLInstancingRenderer.h | 1 + examples/RobotSimulator/CMakeLists.txt | 2 +- examples/SharedMemory/CMakeLists.txt | 2 +- .../SharedMemory/PhysicsServerCommandProcessor.cpp | 9 ++------- examples/SharedMemory/PhysicsServerExample.cpp | 5 +++++ test/SharedMemory/CMakeLists.txt | 2 +- 12 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Extras/BulletRobotics/CMakeLists.txt b/Extras/BulletRobotics/CMakeLists.txt index b76984846..b2c4523b6 100644 --- a/Extras/BulletRobotics/CMakeLists.txt +++ b/Extras/BulletRobotics/CMakeLists.txt @@ -166,7 +166,7 @@ SET_TARGET_PROPERTIES(BulletRobotics PROPERTIES VERSION ${BULLET_VERSION}) SET_TARGET_PROPERTIES(BulletRobotics PROPERTIES SOVERSION ${BULLET_VERSION}) IF (BUILD_SHARED_LIBS) - TARGET_LINK_LIBRARIES(BulletRobotics BulletInverseDynamicsUtils BulletWorldImporter BulletFileLoader BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamics OpenGLWindow LinearMath Bullet3Common) + TARGET_LINK_LIBRARIES(BulletRobotics BulletInverseDynamicsUtils BulletWorldImporter BulletFileLoader BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamics LinearMath Bullet3Common) ENDIF (BUILD_SHARED_LIBS) IF (INSTALL_EXTRA_LIBS) diff --git a/examples/CommonInterfaces/CommonGUIHelperInterface.h b/examples/CommonInterfaces/CommonGUIHelperInterface.h index 20482d4c8..916a82343 100644 --- a/examples/CommonInterfaces/CommonGUIHelperInterface.h +++ b/examples/CommonInterfaces/CommonGUIHelperInterface.h @@ -95,6 +95,7 @@ struct GUIHelperInterface int startPixelIndex, int destinationWidth, int destinationHeight, int* numPixelsCopied){} virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16])=0; + virtual void setProjectiveTexture(bool useProjectiveTexture)=0; virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) =0; @@ -183,6 +184,10 @@ struct DummyGUIHelper : public GUIHelperInterface virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]) { } + + virtual void setProjectiveTexture(bool useProjectiveTexture) + { + } virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) { diff --git a/examples/CommonInterfaces/CommonRenderInterface.h b/examples/CommonInterfaces/CommonRenderInterface.h index 3706d0c6d..a64fe7dde 100644 --- a/examples/CommonInterfaces/CommonRenderInterface.h +++ b/examples/CommonInterfaces/CommonRenderInterface.h @@ -50,6 +50,7 @@ struct CommonRenderInterface virtual void setLightPosition(const float lightPos[3]) = 0; virtual void setLightPosition(const double lightPos[3]) = 0; virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]){}; + virtual void setProjectiveTexture(bool useProjectiveTexture){}; virtual void renderScene()=0; virtual void renderSceneInternal(int renderMode=B3_DEFAULT_RENDERMODE){}; diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.cpp b/examples/ExampleBrowser/OpenGLGuiHelper.cpp index 82fc9a50d..71970893a 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.cpp +++ b/examples/ExampleBrowser/OpenGLGuiHelper.cpp @@ -1103,6 +1103,11 @@ void OpenGLGuiHelper::setProjectiveTextureMatrices(const float viewMatrix[16], c m_data->m_glApp->m_renderer->setProjectiveTextureMatrices(viewMatrix, projectionMatrix); } +void OpenGLGuiHelper::setProjectiveTexture(bool useProjectiveTexture) +{ + m_data->m_glApp->m_renderer->setProjectiveTexture(useProjectiveTexture); +} + void OpenGLGuiHelper::copyCameraImageData(const float viewMatrix[16], const float projectionMatrix[16], unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.h b/examples/ExampleBrowser/OpenGLGuiHelper.h index 47854b0f2..3a43a0221 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.h +++ b/examples/ExampleBrowser/OpenGLGuiHelper.h @@ -63,6 +63,7 @@ struct OpenGLGuiHelper : public GUIHelperInterface int destinationHeight, int* numPixelsCopied); virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]); + virtual void setProjectiveTexture(bool useProjectiveTexture); virtual void autogenerateGraphicsObjects(btDiscreteDynamicsWorld* rbWorld) ; diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp index 0462f053e..5d91a3bb6 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.cpp +++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp @@ -17,7 +17,6 @@ subject to the following restrictions: ///todo: make this configurable in the gui bool useShadowMap = true;// true;//false;//true; -bool useProjectiveTexture = false; int shadowMapWidth= 4096; int shadowMapHeight= 4096; float shadowMapWorldSize=10; @@ -228,6 +227,7 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData GLfloat m_projectiveTextureProjectionMatrix[16]; GLfloat m_projectiveTextureViewMatrix[16]; GLfloat m_viewMatrixInverse[16]; + bool m_useProjectiveTexture; b3Vector3 m_lightPos; b3Vector3 m_lightSpecularIntensity; @@ -263,6 +263,7 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData m_projectiveTextureViewMatrix[i]=0; } + m_useProjectiveTexture = false; } @@ -1479,6 +1480,12 @@ void GLInstancingRenderer::setProjectiveTextureMatrices(const float viewMatrix[1 } } +void GLInstancingRenderer::setProjectiveTexture(bool useProjectiveTexture) +{ + m_data->m_useProjectiveTexture = useProjectiveTexture; + useShadowMap = !useProjectiveTexture; +} + void GLInstancingRenderer::updateCamera(int upAxis) { @@ -1595,7 +1602,7 @@ void GLInstancingRenderer::renderScene() renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE); } - else if (useProjectiveTexture) + else if (m_data->m_useProjectiveTexture) { renderSceneInternal(B3_USE_PROJECTIVE_TEXTURE_RENDERMODE); } diff --git a/examples/OpenGLWindow/GLInstancingRenderer.h b/examples/OpenGLWindow/GLInstancingRenderer.h index 7f0e5a68e..310d4f03f 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.h +++ b/examples/OpenGLWindow/GLInstancingRenderer.h @@ -132,6 +132,7 @@ public: virtual void setLightPosition(const double lightPos[3]); void setLightSpecularIntensity(const float lightSpecularIntensity[3]); virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]); + virtual void setProjectiveTexture(bool useProjectiveTexture); virtual void resize(int width, int height); virtual int getScreenWidth() diff --git a/examples/RobotSimulator/CMakeLists.txt b/examples/RobotSimulator/CMakeLists.txt index 0be4fd7a8..0647edf72 100644 --- a/examples/RobotSimulator/CMakeLists.txt +++ b/examples/RobotSimulator/CMakeLists.txt @@ -116,7 +116,7 @@ ELSE() ENDIF(APPLE) ENDIF(WIN32) -TARGET_LINK_LIBRARIES(App_RobotSimulator_NoGUI BulletRobotics BulletFileLoader BulletWorldImporter BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow Bullet3Common) +TARGET_LINK_LIBRARIES(App_RobotSimulator_NoGUI BulletRobotics BulletFileLoader BulletWorldImporter BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath Bullet3Common) diff --git a/examples/SharedMemory/CMakeLists.txt b/examples/SharedMemory/CMakeLists.txt index 48100c10d..63f61ebaa 100644 --- a/examples/SharedMemory/CMakeLists.txt +++ b/examples/SharedMemory/CMakeLists.txt @@ -97,7 +97,7 @@ IF (USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD) ENDIF() LINK_LIBRARIES( - Bullet3Common BulletWorldImporter BulletFileLoader BulletInverseDynamicsUtils BulletInverseDynamics BulletDynamics BulletCollision LinearMath OpenGLWindow BussIK + Bullet3Common BulletWorldImporter BulletFileLoader BulletInverseDynamicsUtils BulletInverseDynamics BulletDynamics BulletCollision LinearMath BussIK ) diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index fba94fa52..4352fd5ba 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -1,6 +1,5 @@ #include "PhysicsServerCommandProcessor.h" #include "../CommonInterfaces/CommonRenderInterface.h" -#include "../OpenGLWindow/GLInstancingRenderer.h" #include "../Importers/ImportURDFDemo/BulletUrdfImporter.h" #include "../Importers/ImportURDFDemo/MyMultiBodyCreator.h" @@ -3108,8 +3107,6 @@ bool PhysicsServerCommandProcessor::processStateLoggingCommand(const struct Shar return hasStatus; } -extern bool useShadowMap; -extern bool useProjectiveTexture; bool PhysicsServerCommandProcessor::processRequestCameraImageCommand(const struct SharedMemoryCommand& clientCmd, struct SharedMemoryStatus& serverStatusOut, char* bufferServerToClient, int bufferSizeInBytes) { bool hasStatus = true; @@ -3195,8 +3192,7 @@ bool PhysicsServerCommandProcessor::processRequestCameraImageCommand(const struc { if ((flags & ER_USE_PROJECTIVE_TEXTURE) != 0) { - useShadowMap = false; - useProjectiveTexture = true; + this->m_data->m_guiHelper->setProjectiveTexture(true); if ((clientCmd.m_updateFlags & REQUEST_PIXEL_ARGS_HAS_PROJECTIVE_TEXTURE_MATRICES)!=0) { for (int i=0;i<16;i++) @@ -3217,8 +3213,7 @@ bool PhysicsServerCommandProcessor::processRequestCameraImageCommand(const struc } else { - useShadowMap = true; - useProjectiveTexture = false; + this->m_data->m_guiHelper->setProjectiveTexture(false); } m_data->m_guiHelper->copyCameraImageData(viewMat, diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 01c712af0..0d2908ae5 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -1124,6 +1124,11 @@ public: { m_childGuiHelper->getAppInterface()->m_renderer->setProjectiveTextureMatrices(viewMatrix, projectionMatrix); } + + virtual void setProjectiveTexture(bool useProjectiveTexture) + { + m_childGuiHelper->getAppInterface()->m_renderer->setProjectiveTexture(useProjectiveTexture); + } btDiscreteDynamicsWorld* m_dynamicsWorld; diff --git a/test/SharedMemory/CMakeLists.txt b/test/SharedMemory/CMakeLists.txt index e41b2c06d..e0798123f 100644 --- a/test/SharedMemory/CMakeLists.txt +++ b/test/SharedMemory/CMakeLists.txt @@ -16,7 +16,7 @@ IF (USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD) ENDIF() LINK_LIBRARIES( - BulletInverseDynamicsUtils BulletInverseDynamics BulletFileLoader BulletWorldImporter Bullet3Common BulletDynamics BulletCollision LinearMath gtest OpenGLWindow BussIK + BulletInverseDynamicsUtils BulletInverseDynamics BulletFileLoader BulletWorldImporter Bullet3Common BulletDynamics BulletCollision LinearMath gtest BussIK ) IF (NOT WIN32)