From 1190a1901cbe2150ed962a69039c17ec6633ba6c Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 8 Sep 2020 13:04:50 -0700 Subject: [PATCH 1/3] fix mipmap rendering from previous commit, making Macbook really slow --- .../OpenGLWindow/GLInstancingRenderer.cpp | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp index 0c18d0344..6f687b389 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.cpp +++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp @@ -1624,10 +1624,6 @@ void GLInstancingRenderer::renderScene() { renderSceneInternal(B3_CREATE_SHADOWMAP_RENDERMODE); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_2D, m_data->m_shadowTexture); - glGenerateMipmap(GL_TEXTURE_2D); - if (m_planeReflectionShapeIndex >= 0) { /* Don't update color or depth. */ @@ -2361,12 +2357,21 @@ void GLInstancingRenderer::renderSceneInternal(int orgRenderMode) if (gfxObj->m_flags & B3_INSTANCE_TEXTURE) { curBindTexture = m_data->m_textureHandles[gfxObj->m_textureIndex].m_glTexture; - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glBindTexture(GL_TEXTURE_2D, curBindTexture); if (m_data->m_textureHandles[gfxObj->m_textureIndex].m_enableFiltering) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + if (renderMode == B3_CREATE_SHADOWMAP_RENDERMODE) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } + else + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + + } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else @@ -2378,13 +2383,12 @@ void GLInstancingRenderer::renderSceneInternal(int orgRenderMode) else { curBindTexture = m_data->m_defaultTexturehandle; + glBindTexture(GL_TEXTURE_2D, curBindTexture); } //disable lazy evaluation, it just leads to bugs //if (lastBindTexture != curBindTexture) - { - glBindTexture(GL_TEXTURE_2D, curBindTexture); - } + //lastBindTexture = curBindTexture; b3Assert(glGetError() == GL_NO_ERROR); From f876319c5a2bda8410d63ee97c42eb459cf7de09 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Tue, 8 Sep 2020 06:13:43 -0700 Subject: [PATCH 2/3] bump up PyBullet version (regression in GPU rendering on Mac) --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e8f303c63..a0ab2d757 100644 --- a/setup.py +++ b/setup.py @@ -501,7 +501,7 @@ if 'BT_USE_EGL' in EGL_CXX_FLAGS: setup( name='pybullet', - version='2.9.4', + version='2.9.5', description= 'Official Python Interface for the Bullet Physics SDK specialized for Robotics Simulation and Reinforcement Learning', long_description= From 448dd1a2449228df3f2fa53ea07aa476a0082ad6 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Wed, 9 Sep 2020 09:45:38 -0700 Subject: [PATCH 3/3] Synchronize 'resetDebugVisualizeCamera' using GUI critical section instead of waiting for the render thread, to avoid slow-down Fixes issue https://github.com/bulletphysics/bullet3/issues/3045 --- .../SharedMemory/PhysicsServerExample.cpp | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 264ff7542..09b502441 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -13,6 +13,7 @@ #include "../MultiThreading/b3ThreadSupportInterface.h" #include "SharedMemoryPublic.h" //#define BT_ENABLE_VR +#define SYNC_CAMERA_USING_GUI_CS #ifdef BT_ENABLE_VR #include "../RenderingExamples/TinyVRGui.h" #endif //BT_ENABLE_VR @@ -740,18 +741,19 @@ public: MultiThreadedOpenGLGuiHelper(CommonGraphicsApp* app, GUIHelperInterface* guiHelper, int skipGraphicsUpdate) : //m_app(app), - m_cs(0), - m_cs2(0), - m_cs3(0), - m_csGUI(0), - m_debugDraw(0), - m_uidGenerator(0), - m_texels(0), - m_shapeIndex(-1), - m_textureId(-1), - m_instanceId(-1), - m_skipGraphicsUpdate(skipGraphicsUpdate) + m_cs(0), + m_cs2(0), + m_cs3(0), + m_csGUI(0), + m_debugDraw(0), + m_uidGenerator(0), + m_texels(0), + m_shapeIndex(-1), + m_textureId(-1), + m_instanceId(-1), + m_skipGraphicsUpdate(skipGraphicsUpdate) { + m_cameraUpdated = 0; m_childGuiHelper = guiHelper; } @@ -805,6 +807,12 @@ public: { return m_cs3; } + + b3CriticalSection* getCriticalSectionGUI() + { + return m_csGUI; + } + btRigidBody* m_body; btVector3 m_color3; virtual void createRigidBodyGraphicsObject(btRigidBody* body, const btVector3& color) @@ -1087,6 +1095,8 @@ public: { m_childGuiHelper->setUpAxis(axis); } + + bool m_cameraUpdated; float m_resetCameraCamDist; float m_resetCameraYaw; float m_resetCameraPitch; @@ -1096,16 +1106,22 @@ public: virtual void resetCamera(float camDist, float yaw, float pitch, float camPosX, float camPosY, float camPosZ) { - m_cs->lock(); + m_csGUI->lock(); + m_cameraUpdated = true; m_resetCameraCamDist = camDist; m_resetCameraYaw = yaw; m_resetCameraPitch = pitch; m_resetCameraCamPosX = camPosX; m_resetCameraCamPosY = camPosY; m_resetCameraCamPosZ = camPosZ; + +#ifdef SYNC_CAMERA_USING_GUI_CS + m_csGUI->unlock(); +#else m_cs->setSharedParam(1, eGUIHelperResetCamera); workerThreadWait(); - //m_childGuiHelper->resetCamera(camDist, yaw, pitch, camPosX, camPosY, camPosZ); + m_childGuiHelper->resetCamera(camDist, yaw, pitch, camPosX, camPosY, camPosZ); +#endif //SYNC_CAMERA_USING_GUI_CS } virtual bool getCameraInfo(int* width, int* height, float viewMatrix[16], float projectionMatrix[16], float camUp[3], float camForward[3], float hor[3], float vert[3], float* yaw, float* pitch, float* camDist, float camTarget[3]) const @@ -1948,6 +1964,21 @@ void PhysicsServerExample::updateGraphics() { //check if any graphics related tasks are requested +#ifdef SYNC_CAMERA_USING_GUI_CS + m_multiThreadedHelper->getCriticalSectionGUI()->lock(); + if (m_multiThreadedHelper->m_cameraUpdated) + { + m_multiThreadedHelper->m_cameraUpdated = false; + m_multiThreadedHelper->m_childGuiHelper->resetCamera( + m_multiThreadedHelper->m_resetCameraCamDist, + m_multiThreadedHelper->m_resetCameraYaw, + m_multiThreadedHelper->m_resetCameraPitch, + m_multiThreadedHelper->m_resetCameraCamPosX, + m_multiThreadedHelper->m_resetCameraCamPosY, + m_multiThreadedHelper->m_resetCameraCamPosZ); + } + m_multiThreadedHelper->getCriticalSectionGUI()->unlock(); +#endif switch (m_multiThreadedHelper->getCriticalSection()->getSharedParam(1)) { case eGUIHelperCreateCollisionShapeGraphicsObject: @@ -2587,6 +2618,7 @@ void PhysicsServerExample::stepSimulation(float deltaTime) } updateGraphics(); + { if (m_multiThreadedHelper->m_childGuiHelper->getRenderInterface()) {