From b696ed7d7b3dda73304f1484952a958f2bb32fac Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Wed, 28 Apr 2021 12:13:31 -0700 Subject: [PATCH 1/6] enable roll angle in pybullet.computeViewMatrixFromYawPitchRoll / b3ComputeViewMatrixFromYawPitchRoll --- examples/SharedMemory/PhysicsClientC_API.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/SharedMemory/PhysicsClientC_API.cpp b/examples/SharedMemory/PhysicsClientC_API.cpp index ca60e9e13f..1d0c4929d9 100644 --- a/examples/SharedMemory/PhysicsClientC_API.cpp +++ b/examples/SharedMemory/PhysicsClientC_API.cpp @@ -4572,7 +4572,7 @@ B3_SHARED_API void b3ComputeViewMatrixFromYawPitchRoll(const float cameraTargetP b3Scalar yawRad = yaw * b3Scalar(0.01745329251994329547); // rads per deg b3Scalar pitchRad = pitch * b3Scalar(0.01745329251994329547); // rads per deg - b3Scalar rollRad = 0.0; + b3Scalar rollRad = roll * b3Scalar(0.01745329251994329547); // rads per deg b3Quaternion eyeRot; int forwardAxis(-1); From 8e85dedaa9dc6b98cdced1a1edae1eadab9ce869 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Thu, 6 May 2021 10:19:15 -0700 Subject: [PATCH 2/6] PyUnicode_AsUTF8 breaks python 2.x compatibility --- examples/pybullet/pybullet.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index f0637919d4..f2a72a76df 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -137,12 +137,20 @@ static const char* pybullet_internalGetCStringFromSequence(PyObject* seq, int in if (PyList_Check(seq)) { item = PyList_GET_ITEM(seq, index); +#if PY_MAJOR_VERSION >= 3 v = PyUnicode_AsUTF8(item); +#else + v = PyBytes_AsString(item); +#endif } else { item = PyTuple_GET_ITEM(seq, index); +#if PY_MAJOR_VERSION >= 3 v = PyUnicode_AsUTF8(item); +#else + v = PyBytes_AsString(item); +#endif } return v; } From e952ac6f63e1247451518aa69fc9447c69366530 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Thu, 6 May 2021 18:08:22 -0700 Subject: [PATCH 3/6] Add pybullet.configureDebugVisualizer(rgbBackground=[red,green,blue]) (each component a float in the range [0,1]) This is an alternative to passing options="--background_color_red=red --background_color_green=green --background_color_blue=blue" in the connect method. --- .../CommonGUIHelperInterface.h | 2 ++ .../CommonInterfaces/CommonRenderInterface.h | 2 ++ examples/ExampleBrowser/OpenGLGuiHelper.cpp | 8 +++++++- examples/ExampleBrowser/OpenGLGuiHelper.h | 2 +- .../OpenGLWindow/GLInstancingRenderer.cpp | 5 +++++ examples/OpenGLWindow/GLInstancingRenderer.h | 2 +- examples/OpenGLWindow/SimpleOpenGL2Renderer.h | 1 + examples/SharedMemory/PhysicsClientC_API.cpp | 15 ++++++++++++++ examples/SharedMemory/PhysicsClientC_API.h | 2 ++ .../PhysicsServerCommandProcessor.cpp | 4 ++++ .../SharedMemory/PhysicsServerExample.cpp | 20 ++++++++++++++++++- examples/SharedMemory/SharedMemoryCommands.h | 2 ++ examples/pybullet/pybullet.c | 15 +++++++++++--- 13 files changed, 73 insertions(+), 7 deletions(-) diff --git a/examples/CommonInterfaces/CommonGUIHelperInterface.h b/examples/CommonInterfaces/CommonGUIHelperInterface.h index eb4e0c76f1..7f8316fd1d 100644 --- a/examples/CommonInterfaces/CommonGUIHelperInterface.h +++ b/examples/CommonInterfaces/CommonGUIHelperInterface.h @@ -52,6 +52,8 @@ struct GUIHelperInterface virtual int getShapeIndexFromInstance(int instanceUid) { return -1; } virtual void replaceTexture(int shapeIndex, int textureUid) {} virtual void removeTexture(int textureUid) {} + virtual void setBackgroundColor(const double rgbBackground[3]) {} + virtual Common2dCanvasInterface* get2dCanvasInterface() = 0; diff --git a/examples/CommonInterfaces/CommonRenderInterface.h b/examples/CommonInterfaces/CommonRenderInterface.h index 25bf828524..03e1484571 100644 --- a/examples/CommonInterfaces/CommonRenderInterface.h +++ b/examples/CommonInterfaces/CommonRenderInterface.h @@ -56,6 +56,8 @@ struct CommonRenderInterface virtual void setLightPosition(const float lightPos[3]) = 0; virtual void setLightPosition(const double lightPos[3]) = 0; + virtual void setBackgroundColor(const double rgbBackground[3]) = 0; + virtual void setShadowMapResolution(int shadowMapResolution) = 0; virtual void setShadowMapIntensity(double shadowMapIntensity) = 0; diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.cpp b/examples/ExampleBrowser/OpenGLGuiHelper.cpp index 90cec71a65..7df4e932bc 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.cpp +++ b/examples/ExampleBrowser/OpenGLGuiHelper.cpp @@ -236,13 +236,19 @@ OpenGLGuiHelper::OpenGLGuiHelper(CommonGraphicsApp* glApp, bool useOpenGL2) m_data->m_debugDraw = 0; } -OpenGLGuiHelper::~OpenGLGuiHelper() + + OpenGLGuiHelper::~OpenGLGuiHelper() { delete m_data->m_debugDraw; delete m_data; } +void OpenGLGuiHelper::setBackgroundColor(const double rgbBackground[3]) +{ + this->getRenderInterface()->setBackgroundColor(rgbBackground); +} + struct CommonRenderInterface* OpenGLGuiHelper::getRenderInterface() { return m_data->m_glApp->m_renderer; diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.h b/examples/ExampleBrowser/OpenGLGuiHelper.h index abeaa9af1d..c512c21b97 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.h +++ b/examples/ExampleBrowser/OpenGLGuiHelper.h @@ -36,7 +36,7 @@ struct OpenGLGuiHelper : public GUIHelperInterface virtual int getShapeIndexFromInstance(int instanceUid); virtual void replaceTexture(int shapeIndex, int textureUid); virtual void updateShape(int shapeIndex, float* vertices, int numVertices); - + virtual void setBackgroundColor(const double rgbBackground[3]); virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape); virtual void syncPhysicsToGraphics(const btDiscreteDynamicsWorld* rbWorld); diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp index ca05522309..c0e2f23702 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.cpp +++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp @@ -1522,6 +1522,11 @@ void GLInstancingRenderer::setLightPosition(const double lightPos[3]) m_data->m_lightPos[2] = lightPos[2]; } +void GLInstancingRenderer::setBackgroundColor(const double rgbBackground[3]) +{ + glClearColor(rgbBackground[0], rgbBackground[1], rgbBackground[2], 1.f); +} + void GLInstancingRenderer::setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]) { for (int i = 0; i < 16; i++) diff --git a/examples/OpenGLWindow/GLInstancingRenderer.h b/examples/OpenGLWindow/GLInstancingRenderer.h index 715758212d..d3aa8c25fd 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.h +++ b/examples/OpenGLWindow/GLInstancingRenderer.h @@ -127,7 +127,7 @@ class GLInstancingRenderer : public CommonRenderInterface void setLightSpecularIntensity(const float lightSpecularIntensity[3]); virtual void setProjectiveTextureMatrices(const float viewMatrix[16], const float projectionMatrix[16]); virtual void setProjectiveTexture(bool useProjectiveTexture); - + virtual void setBackgroundColor(const double rgbBackground[3]); virtual void resize(int width, int height); virtual int getScreenWidth() { diff --git a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h index 19cc8cc10e..4355de5588 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h +++ b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h @@ -30,6 +30,7 @@ class SimpleOpenGL2Renderer : public CommonRenderInterface virtual void setShadowMapIntensity(double shadowMapIntensity) {} virtual void setShadowMapWorldSize(float worldSize) {} virtual void resize(int width, int height); + virtual void setBackgroundColor(const double rgbBackground[3]) {} virtual void removeAllInstances(); virtual void removeGraphicsInstance(int instanceUid); diff --git a/examples/SharedMemory/PhysicsClientC_API.cpp b/examples/SharedMemory/PhysicsClientC_API.cpp index 1d0c4929d9..e4bdb6fc5f 100644 --- a/examples/SharedMemory/PhysicsClientC_API.cpp +++ b/examples/SharedMemory/PhysicsClientC_API.cpp @@ -6064,6 +6064,21 @@ B3_SHARED_API void b3ConfigureOpenGLVisualizerSetLightPosition(b3SharedMemoryCom } } +B3_SHARED_API void b3ConfigureOpenGLVisualizerSetLightRgbBackground(b3SharedMemoryCommandHandle commandHandle, const float rgbBackground[3]) +{ + struct SharedMemoryCommand* command = (struct SharedMemoryCommand*)commandHandle; + b3Assert(command); + b3Assert(command->m_type == CMD_CONFIGURE_OPENGL_VISUALIZER); + if (command->m_type == CMD_CONFIGURE_OPENGL_VISUALIZER) + { + command->m_updateFlags |= COV_SET_RGB_BACKGROUND; + command->m_configureOpenGLVisualizerArguments.m_rgbBackground[0] = rgbBackground[0]; + command->m_configureOpenGLVisualizerArguments.m_rgbBackground[1] = rgbBackground[1]; + command->m_configureOpenGLVisualizerArguments.m_rgbBackground[2] = rgbBackground[2]; + } +} + + B3_SHARED_API void b3ConfigureOpenGLVisualizerSetShadowMapResolution(b3SharedMemoryCommandHandle commandHandle, int shadowMapResolution) { struct SharedMemoryCommand* command = (struct SharedMemoryCommand*)commandHandle; diff --git a/examples/SharedMemory/PhysicsClientC_API.h b/examples/SharedMemory/PhysicsClientC_API.h index cd71fabc6f..d7a9eadd2c 100644 --- a/examples/SharedMemory/PhysicsClientC_API.h +++ b/examples/SharedMemory/PhysicsClientC_API.h @@ -218,7 +218,9 @@ extern "C" B3_SHARED_API void b3ConfigureOpenGLVisualizerSetLightPosition(b3SharedMemoryCommandHandle commandHandle, const float lightPosition[3]); B3_SHARED_API void b3ConfigureOpenGLVisualizerSetShadowMapResolution(b3SharedMemoryCommandHandle commandHandle, int shadowMapResolution); B3_SHARED_API void b3ConfigureOpenGLVisualizerSetShadowMapIntensity(b3SharedMemoryCommandHandle commandHandle, double shadowMapIntensity); + B3_SHARED_API void b3ConfigureOpenGLVisualizerSetLightRgbBackground(b3SharedMemoryCommandHandle commandHandle, const float rgbBackground[3]); + B3_SHARED_API void b3ConfigureOpenGLVisualizerSetShadowMapWorldSize(b3SharedMemoryCommandHandle commandHandle, int shadowMapWorldSize); B3_SHARED_API void b3ConfigureOpenGLVisualizerSetRemoteSyncTransformInterval(b3SharedMemoryCommandHandle commandHandle, double remoteSyncTransformInterval); diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index fbf1b2a37d..95069900f1 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -11305,6 +11305,10 @@ bool PhysicsServerCommandProcessor::processConfigureOpenGLVisualizerCommand(cons { m_data->m_guiHelper->getRenderInterface()->setLightPosition(clientCmd.m_configureOpenGLVisualizerArguments.m_lightPosition); } + if (clientCmd.m_updateFlags & COV_SET_RGB_BACKGROUND) + { + m_data->m_guiHelper->setBackgroundColor(clientCmd.m_configureOpenGLVisualizerArguments.m_rgbBackground); + } if (clientCmd.m_updateFlags & COV_SET_SHADOWMAP_RESOLUTION) { m_data->m_guiHelper->getRenderInterface()->setShadowMapResolution(clientCmd.m_configureOpenGLVisualizerArguments.m_shadowMapResolution); diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 3a33be95dc..9ffc16df67 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -133,6 +133,7 @@ enum MultiThreadedGUIHelperCommunicationEnums eGUIUserDebugRemoveAllParameters, eGUIHelperResetCamera, eGUIHelperChangeGraphicsInstanceFlags, + eGUIHelperSetRgbBackground, }; #include @@ -1058,7 +1059,17 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface workerThreadWait(); } - + double m_rgbBackground[3]; + virtual void setBackgroundColor(const double rgbBackground[3]) + { + m_rgbBackground[0] = rgbBackground[0]; + m_rgbBackground[1] = rgbBackground[1]; + m_rgbBackground[2] = rgbBackground[2]; + m_cs->lock(); + m_cs->setSharedParam(1, eGUIHelperSetRgbBackground); + workerThreadWait(); + this->getRenderInterface()->setBackgroundColor(rgbBackground); + } int m_graphicsInstanceChangeScaling; @@ -2267,6 +2278,13 @@ void PhysicsServerExample::updateGraphics() break; } + case eGUIHelperSetRgbBackground: + { + m_multiThreadedHelper->m_childGuiHelper->setBackgroundColor(m_multiThreadedHelper->m_rgbBackground); + m_multiThreadedHelper->mainThreadRelease(); + break; + } + case eGUIHelperChangeGraphicsInstanceScaling: { B3_PROFILE("eGUIHelperChangeGraphicsInstanceScaling"); diff --git a/examples/SharedMemory/SharedMemoryCommands.h b/examples/SharedMemory/SharedMemoryCommands.h index 8033469262..6347a44d73 100644 --- a/examples/SharedMemory/SharedMemoryCommands.h +++ b/examples/SharedMemory/SharedMemoryCommands.h @@ -962,6 +962,7 @@ enum InternalOpenGLVisualizerUpdateFlags COV_SET_SHADOWMAP_WORLD_SIZE = 16, COV_SET_REMOTE_SYNC_TRANSFORM_INTERVAL = 32, COV_SET_SHADOWMAP_INTENSITY = 64, + COV_SET_RGB_BACKGROUND = 128, }; struct ConfigureOpenGLVisualizerRequest @@ -977,6 +978,7 @@ struct ConfigureOpenGLVisualizerRequest int m_setFlag; int m_setEnabled; double m_shadowMapIntensity; + double m_rgbBackground[3]; }; enum diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index f2a72a76df..b26034e3da 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -7450,11 +7450,12 @@ static PyObject* pybullet_configureDebugVisualizer(PyObject* self, PyObject* arg int physicsClientId = 0; double remoteSyncTransformInterval = -1; PyObject* pyLightPosition = 0; + PyObject* pyRgbBackground = 0; b3PhysicsClientHandle sm = 0; - static char* kwlist[] = {"flag", "enable", "lightPosition", "shadowMapResolution", "shadowMapWorldSize", "remoteSyncTransformInterval", "shadowMapIntensity", "physicsClientId", NULL}; + static char* kwlist[] = {"flag", "enable", "lightPosition", "shadowMapResolution", "shadowMapWorldSize", "remoteSyncTransformInterval", "shadowMapIntensity", "rgbBackground", "physicsClientId", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, keywds, "|iiOiiddi", kwlist, - &flag, &enable, &pyLightPosition, &shadowMapResolution, &shadowMapWorldSize, &remoteSyncTransformInterval, &shadowMapIntensity, &physicsClientId)) + if (!PyArg_ParseTupleAndKeywords(args, keywds, "|iiOiiddOi", kwlist, + &flag, &enable, &pyLightPosition, &shadowMapResolution, &shadowMapWorldSize, &remoteSyncTransformInterval, &shadowMapIntensity, &pyRgbBackground, &physicsClientId)) return NULL; sm = getPhysicsClient(physicsClientId); @@ -7478,6 +7479,14 @@ static PyObject* pybullet_configureDebugVisualizer(PyObject* self, PyObject* arg b3ConfigureOpenGLVisualizerSetLightPosition(commandHandle, lightPosition); } } + if (pyRgbBackground) + { + float rgbBackground[3]; + if (pybullet_internalSetVector(pyRgbBackground, rgbBackground)) + { + b3ConfigureOpenGLVisualizerSetLightRgbBackground(commandHandle, rgbBackground); + } + } if (shadowMapIntensity >= 0) { b3ConfigureOpenGLVisualizerSetShadowMapIntensity(commandHandle, shadowMapIntensity); From f14911c998fc0ff57d4ec626b7c1ebd80033a5c5 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Thu, 6 May 2021 18:34:43 -0700 Subject: [PATCH 4/6] fix a tsan test failure --- .../SharedMemory/PhysicsServerExample.cpp | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 9ffc16df67..64cbacc909 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -725,7 +725,9 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface if (m_skipGraphicsUpdate) { + this->m_csGUI->lock(); getCriticalSection()->setSharedParam(1, eGUIHelperIdle); + this->m_csGUI->unlock(); m_cs->unlock(); return; } @@ -735,9 +737,18 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_cs3->lock(); m_cs3->unlock(); - while (m_cs->getSharedParam(1) != eGUIHelperIdle) + + m_csGUI->lock(); + unsigned int cachedSharedParam = m_cs->getSharedParam(1); + m_csGUI->unlock(); + + + while (cachedSharedParam != eGUIHelperIdle) { b3Clock::usleep(0); + m_csGUI->lock(); + cachedSharedParam = m_cs->getSharedParam(1); + m_csGUI->unlock(); } } @@ -2006,7 +2017,12 @@ void PhysicsServerExample::updateGraphics() } m_multiThreadedHelper->getCriticalSectionGUI()->unlock(); #endif - switch (m_multiThreadedHelper->getCriticalSection()->getSharedParam(1)) + + m_multiThreadedHelper->getCriticalSectionGUI()->lock(); + unsigned int cachedSharedParam = m_multiThreadedHelper->getCriticalSection()->getSharedParam(1); + m_multiThreadedHelper->getCriticalSectionGUI()->unlock(); + + switch (cachedSharedParam) { case eGUIHelperCreateCollisionShapeGraphicsObject: { From cd76d605a9b5cb63279134c2fc8757475aa3edc6 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Fri, 7 May 2021 15:37:56 +0000 Subject: [PATCH 5/6] more fixes for tsan --- .../SharedMemory/PhysicsServerExample.cpp | 149 ++++++++++-------- 1 file changed, 80 insertions(+), 69 deletions(-) diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 64cbacc909..d10c0e317e 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -133,7 +133,6 @@ enum MultiThreadedGUIHelperCommunicationEnums eGUIUserDebugRemoveAllParameters, eGUIHelperResetCamera, eGUIHelperChangeGraphicsInstanceFlags, - eGUIHelperSetRgbBackground, }; #include @@ -710,7 +709,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface { BT_PROFILE("mainThreadRelease"); - getCriticalSection()->setSharedParam(1, eGUIHelperIdle); + setSharedParam(1, eGUIHelperIdle); getCriticalSection3()->lock(); getCriticalSection2()->unlock(); getCriticalSection()->lock(); @@ -830,10 +829,11 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface btVector3 m_color3; virtual void createRigidBodyGraphicsObject(btRigidBody* body, const btVector3& color) { - m_body = body; - m_color3 = color; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperCreateRigidBodyGraphicsObject); + + m_body = body; + m_color3 = color; + setSharedParam(1, eGUIHelperCreateRigidBodyGraphicsObject); workerThreadWait(); } @@ -842,19 +842,21 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface virtual void createCollisionObjectGraphicsObject(btCollisionObject* obj, const btVector3& color) { - m_obj = obj; - m_color2 = color; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperCreateCollisionObjectGraphicsObject); + + m_obj = obj; + m_color2 = color; + setSharedParam(1, eGUIHelperCreateCollisionObjectGraphicsObject); workerThreadWait(); } btCollisionShape* m_colShape; virtual void createCollisionShapeGraphicsObject(btCollisionShape* collisionShape) { - m_colShape = collisionShape; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperCreateCollisionShapeGraphicsObject); + + m_colShape = collisionShape; + setSharedParam(1, eGUIHelperCreateCollisionShapeGraphicsObject); workerThreadWait(); } @@ -901,9 +903,10 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface virtual void removeTexture(int textureUid) { - m_removeTextureUid = textureUid; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperRemoveTexture); + + m_removeTextureUid = textureUid; + setSharedParam(1, eGUIHelperRemoveTexture); workerThreadWait(); } @@ -913,11 +916,12 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface int m_updateNumShapeVertices; virtual void updateShape(int shapeIndex, float* vertices, int numVertices) { - m_updateShapeIndex = shapeIndex; + m_cs->lock(); + + m_updateShapeIndex = shapeIndex; m_updateShapeVertices = vertices; m_updateNumShapeVertices = numVertices; - m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperUpdateShape); + setSharedParam(1, eGUIHelperUpdateShape); workerThreadWait(); } virtual int registerTexture(const unsigned char* texels, int width, int height) @@ -927,12 +931,13 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface { return *cachedTexture; } - m_texels = texels; + m_cs->lock(); + + m_texels = texels; m_textureWidth = width; m_textureHeight = height; - m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperRegisterTexture); + setSharedParam(1, eGUIHelperRegisterTexture); workerThreadWait(); m_cachedTextureIds.insert(texels, m_textureId); @@ -940,31 +945,44 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface } virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices, int primitiveType, int textureId) { - m_vertices = vertices; + m_cs->lock(); + m_csGUI->lock(); + m_vertices = vertices; m_numvertices = numvertices; m_indices = indices; m_numIndices = numIndices; m_primitiveType = primitiveType; m_textureId = textureId; - - m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperRegisterGraphicsShape); + m_csGUI->unlock(); + setSharedParam(1, eGUIHelperRegisterGraphicsShape); workerThreadWait(); - return m_shapeIndex; + m_csGUI->lock(); + int shapeIndex = m_shapeIndex; + m_csGUI->unlock(); + + + return shapeIndex; } int m_visualizerFlag; int m_visualizerEnable; int m_renderedFrames; + void setSharedParam(int slot, int param) + { + m_csGUI->lock(); + m_cs->setSharedParam(slot, param); + m_csGUI->unlock(); + } void setVisualizerFlag(int flag, int enable) { - m_visualizerFlag = flag; + m_cs->lock(); + + m_visualizerFlag = flag; m_visualizerEnable = enable; - m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperSetVisualizerFlag); + setSharedParam(1, eGUIHelperSetVisualizerFlag); workerThreadWait(); } @@ -982,16 +1000,16 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_scaling = scaling; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperRegisterGraphicsInstance); + setSharedParam(1, eGUIHelperRegisterGraphicsInstance); workerThreadWait(); return m_instanceId; } virtual void removeAllGraphicsInstances() { + m_cs->lock(); m_cachedTextureIds.clear(); - m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperRemoveAllGraphicsInstances); + setSharedParam(1, eGUIHelperRemoveAllGraphicsInstances); workerThreadWait(); } @@ -1000,7 +1018,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface { m_graphicsInstanceRemove = graphicsUid; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperRemoveGraphicsInstance); + setSharedParam(1, eGUIHelperRemoveGraphicsInstance); workerThreadWait(); } @@ -1011,7 +1029,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface { m_getShapeIndex_instance = instance; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperGetShapeIndexFromInstance); + setSharedParam(1, eGUIHelperGetShapeIndexFromInstance); getShapeIndex_shapeIndex = -1; workerThreadWait(); return getShapeIndex_shapeIndex; @@ -1024,7 +1042,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_graphicsInstanceChangeTextureShapeIndex = shapeIndex; m_graphicsInstanceChangeTextureId = textureUid; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceTextureId); + setSharedParam(1, eGUIHelperChangeGraphicsInstanceTextureId); workerThreadWait(); } @@ -1040,7 +1058,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_changeTextureWidth = width; m_changeTextureHeight = height; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperChangeTexture); + setSharedParam(1, eGUIHelperChangeTexture); workerThreadWait(); } @@ -1054,7 +1072,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_rgbaColor[2] = rgbaColor[2]; m_rgbaColor[3] = rgbaColor[3]; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceRGBAColor); + setSharedParam(1, eGUIHelperChangeGraphicsInstanceRGBAColor); workerThreadWait(); } @@ -1066,21 +1084,11 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_graphicsInstanceFlagsInstanceUid = instanceUid; m_graphicsInstanceFlags = flags; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceFlags); + setSharedParam(1, eGUIHelperChangeGraphicsInstanceFlags); workerThreadWait(); } - double m_rgbBackground[3]; - virtual void setBackgroundColor(const double rgbBackground[3]) - { - m_rgbBackground[0] = rgbBackground[0]; - m_rgbBackground[1] = rgbBackground[1]; - m_rgbBackground[2] = rgbBackground[2]; - m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperSetRgbBackground); - workerThreadWait(); - this->getRenderInterface()->setBackgroundColor(rgbBackground); - } + int m_graphicsInstanceChangeScaling; @@ -1092,7 +1100,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_baseScaling[1] = scaling[1]; m_baseScaling[2] = scaling[2]; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceScaling); + setSharedParam(1, eGUIHelperChangeGraphicsInstanceScaling); workerThreadWait(); } @@ -1105,7 +1113,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_specularColor[1] = specularColor[1]; m_specularColor[2] = specularColor[2]; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperChangeGraphicsInstanceSpecularColor); + setSharedParam(1, eGUIHelperChangeGraphicsInstanceSpecularColor); workerThreadWait(); } @@ -1156,7 +1164,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface #ifdef SYNC_CAMERA_USING_GUI_CS m_csGUI->unlock(); #else - m_cs->setSharedParam(1, eGUIHelperResetCamera); + setSharedParam(1, eGUIHelperResetCamera); workerThreadWait(); m_childGuiHelper->resetCamera(camDist, yaw, pitch, camPosX, camPosY, camPosZ); #endif //SYNC_CAMERA_USING_GUI_CS @@ -1204,7 +1212,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_destinationHeight = destinationHeight; m_numPixelsCopied = numPixelsCopied; - m_cs->setSharedParam(1, eGUIHelperCopyCameraImageData); + setSharedParam(1, eGUIHelperCopyCameraImageData); workerThreadWait(); } @@ -1231,7 +1239,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_destinationHeight = destinationHeight; m_numPixelsCopied = numPixelsCopied; - m_cs->setSharedParam(1, eGUIHelperDisplayCameraImageData); + setSharedParam(1, eGUIHelperDisplayCameraImageData); workerThreadWait(); } @@ -1257,7 +1265,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface { m_dynamicsWorld = rbWorld; m_cs->lock(); - m_cs->setSharedParam(1, eGUIHelperAutogenerateGraphicsObjects); + setSharedParam(1, eGUIHelperAutogenerateGraphicsObjects); workerThreadWait(); } @@ -1310,7 +1318,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_tmpText.m_textOrientation[3] = orientation[3]; m_cs->lock(); - m_cs->setSharedParam(1, eGUIUserDebugAddText); + setSharedParam(1, eGUIUserDebugAddText); m_resultUserDebugTextUid = -1; workerThreadWait(); @@ -1343,7 +1351,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface m_tmpParam.m_itemUniqueId = m_uidGenerator++; m_cs->lock(); - m_cs->setSharedParam(1, eGUIUserDebugAddParameter); + setSharedParam(1, eGUIUserDebugAddParameter); m_userDebugParamUid = -1; workerThreadWait(); @@ -1398,7 +1406,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface { m_cs->lock(); - m_cs->setSharedParam(1, eGUIUserDebugAddLine); + setSharedParam(1, eGUIUserDebugAddLine); m_resultDebugLineUid = -1; workerThreadWait(); } @@ -1411,20 +1419,20 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface { m_removeDebugItemUid = debugItemUniqueId; m_cs->lock(); - m_cs->setSharedParam(1, eGUIUserDebugRemoveItem); + setSharedParam(1, eGUIUserDebugRemoveItem); workerThreadWait(); } virtual void removeAllUserDebugItems() { m_cs->lock(); - m_cs->setSharedParam(1, eGUIUserDebugRemoveAllItems); + setSharedParam(1, eGUIUserDebugRemoveAllItems); workerThreadWait(); } virtual void removeAllUserParameters() { m_cs->lock(); - m_cs->setSharedParam(1, eGUIUserDebugRemoveAllParameters); + setSharedParam(1, eGUIUserDebugRemoveAllParameters); workerThreadWait(); } @@ -1436,7 +1444,7 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface { m_cs->lock(); m_mp4FileName = mp4FileName; - m_cs->setSharedParam(1, eGUIDumpFramesToVideo); + setSharedParam(1, eGUIDumpFramesToVideo); workerThreadWait(); m_mp4FileName = 0; } @@ -1909,8 +1917,10 @@ void PhysicsServerExample::initPhysics() } } m_args[0].m_cs->lock(); + m_args[0].m_csGUI->lock(); m_args[0].m_cs->setSharedParam(1, eGUIHelperIdle); - m_args[0].m_cs->unlock(); + m_args[0].m_csGUI->unlock(); + m_args[0].m_cs->unlock(); m_args[0].m_cs2->lock(); { @@ -2075,14 +2085,22 @@ void PhysicsServerExample::updateGraphics() case eGUIHelperRegisterGraphicsShape: { B3_PROFILE("eGUIHelperRegisterGraphicsShape"); - m_multiThreadedHelper->m_shapeIndex = m_multiThreadedHelper->m_childGuiHelper->registerGraphicsShape( + int shapeIndex = m_multiThreadedHelper->m_childGuiHelper->registerGraphicsShape( m_multiThreadedHelper->m_vertices, m_multiThreadedHelper->m_numvertices, m_multiThreadedHelper->m_indices, m_multiThreadedHelper->m_numIndices, m_multiThreadedHelper->m_primitiveType, m_multiThreadedHelper->m_textureId); - m_multiThreadedHelper->mainThreadRelease(); + + m_multiThreadedHelper->getCriticalSectionGUI()->lock(); + m_multiThreadedHelper->m_shapeIndex = shapeIndex; + m_multiThreadedHelper->getCriticalSectionGUI()->unlock(); + + + m_multiThreadedHelper->mainThreadRelease(); + + break; } @@ -2294,13 +2312,6 @@ void PhysicsServerExample::updateGraphics() break; } - case eGUIHelperSetRgbBackground: - { - m_multiThreadedHelper->m_childGuiHelper->setBackgroundColor(m_multiThreadedHelper->m_rgbBackground); - m_multiThreadedHelper->mainThreadRelease(); - break; - } - case eGUIHelperChangeGraphicsInstanceScaling: { B3_PROFILE("eGUIHelperChangeGraphicsInstanceScaling"); From adcf785a4a9d71e02734f994a310a4511469fae8 Mon Sep 17 00:00:00 2001 From: erwin coumans Date: Fri, 7 May 2021 09:07:40 -0700 Subject: [PATCH 6/6] re-enable eGUIHelperSetRgbBackground --- .../SharedMemory/PhysicsServerExample.cpp | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index d10c0e317e..6613de42b9 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -133,6 +133,7 @@ enum MultiThreadedGUIHelperCommunicationEnums eGUIUserDebugRemoveAllParameters, eGUIHelperResetCamera, eGUIHelperChangeGraphicsInstanceFlags, + eGUIHelperSetRgbBackground, }; #include @@ -1088,7 +1089,18 @@ class MultiThreadedOpenGLGuiHelper : public GUIHelperInterface workerThreadWait(); } - + double m_rgbBackground[3]; + virtual void setBackgroundColor(const double rgbBackground[3]) + { + m_cs->lock(); + m_rgbBackground[0] = rgbBackground[0]; + m_rgbBackground[1] = rgbBackground[1]; + m_rgbBackground[2] = rgbBackground[2]; + + setSharedParam(1, eGUIHelperSetRgbBackground); + workerThreadWait(); + + } int m_graphicsInstanceChangeScaling; @@ -2312,6 +2324,13 @@ void PhysicsServerExample::updateGraphics() break; } + case eGUIHelperSetRgbBackground: + { + m_multiThreadedHelper->m_childGuiHelper->setBackgroundColor(m_multiThreadedHelper->m_rgbBackground); + m_multiThreadedHelper->mainThreadRelease(); + break; + } + case eGUIHelperChangeGraphicsInstanceScaling: { B3_PROFILE("eGUIHelperChangeGraphicsInstanceScaling");