diff --git a/examples/CommonInterfaces/CommonGUIHelperInterface.h b/examples/CommonInterfaces/CommonGUIHelperInterface.h index d7c4f536c..9171ed5c4 100644 --- a/examples/CommonInterfaces/CommonGUIHelperInterface.h +++ b/examples/CommonInterfaces/CommonGUIHelperInterface.h @@ -44,6 +44,7 @@ struct GUIHelperInterface virtual int getShapeIndexFromInstance(int instanceUid){return -1;} virtual void replaceTexture(int shapeIndex, int textureUid){} + virtual void removeTexture(int textureUid) {} virtual Common2dCanvasInterface* get2dCanvasInterface()=0; diff --git a/examples/CommonInterfaces/CommonRenderInterface.h b/examples/CommonInterfaces/CommonRenderInterface.h index d8c9e37ce..7696baf5a 100644 --- a/examples/CommonInterfaces/CommonRenderInterface.h +++ b/examples/CommonInterfaces/CommonRenderInterface.h @@ -72,6 +72,7 @@ struct CommonRenderInterface virtual void updateTexture(int textureIndex, const unsigned char* texels, bool flipPixelsY=true)=0; virtual void activateTexture(int textureIndex)=0; virtual void replaceTexture(int shapeIndex, int textureIndex){}; + virtual void removeTexture(int textureIndex) = 0; virtual int getShapeIndexFromInstance(int srcIndex) {return -1;} diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.cpp b/examples/ExampleBrowser/OpenGLGuiHelper.cpp index 1c7daff79..5df588ec3 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.cpp +++ b/examples/ExampleBrowser/OpenGLGuiHelper.cpp @@ -291,6 +291,15 @@ int OpenGLGuiHelper::registerTexture(const unsigned char* texels, int width, int return textureId; } + +void OpenGLGuiHelper::removeTexture(int textureUid) +{ + m_data->m_glApp->m_renderer->removeTexture(textureUid); +} + + + + void OpenGLGuiHelper::changeTexture(int textureUniqueId, const unsigned char* rgbTexels, int width, int height) { bool flipPixelsY = true; diff --git a/examples/ExampleBrowser/OpenGLGuiHelper.h b/examples/ExampleBrowser/OpenGLGuiHelper.h index a2705fb38..319f2ed21 100644 --- a/examples/ExampleBrowser/OpenGLGuiHelper.h +++ b/examples/ExampleBrowser/OpenGLGuiHelper.h @@ -30,7 +30,7 @@ struct OpenGLGuiHelper : public GUIHelperInterface virtual void changeRGBAColor(int instanceUid, const double rgbaColor[4]); virtual void changeSpecularColor(int instanceUid, const double specularColor[3]); virtual void changeTexture(int textureUniqueId, const unsigned char* rgbTexels, int width, int height); - + virtual void removeTexture(int textureUid); virtual int getShapeIndexFromInstance(int instanceUid); virtual void replaceTexture(int shapeIndex, int textureUid); diff --git a/examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp b/examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp index b5968490a..ce2129435 100644 --- a/examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp +++ b/examples/Importers/ImportURDFDemo/BulletUrdfImporter.cpp @@ -48,6 +48,7 @@ ATTRIBUTE_ALIGNED16(struct) BulletURDFInternalData int m_bodyId; btHashMap m_linkColors; btAlignedObjectArray m_allocatedCollisionShapes; + btAlignedObjectArray m_allocatedTextures; mutable btAlignedObjectArray m_allocatedMeshInterfaces; btHashMap m_bulletCollisionShape2UrdfCollision; @@ -1163,6 +1164,10 @@ int BulletURDFImporter::convertLinkVisualShapes(int linkIndex, const char* pathP { textureIndex = m_data->m_guiHelper->registerTexture(textures[0].textureData1,textures[0].m_width,textures[0].m_height); + if (textureIndex >= 0) + { + m_data->m_allocatedTextures.push_back(textureIndex); + } } { B3_PROFILE("registerGraphicsShape"); @@ -1270,11 +1275,22 @@ int BulletURDFImporter::getNumAllocatedMeshInterfaces() const } + btStridingMeshInterface* BulletURDFImporter::getAllocatedMeshInterface(int index) { return m_data->m_allocatedMeshInterfaces[index]; } +int BulletURDFImporter::getNumAllocatedTextures() const +{ + return m_data->m_allocatedTextures.size(); +} + +int BulletURDFImporter::getAllocatedTexture(int index) const +{ + return m_data->m_allocatedTextures[index]; +} + class btCompoundShape* BulletURDFImporter::convertLinkCollisionShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const diff --git a/examples/Importers/ImportURDFDemo/BulletUrdfImporter.h b/examples/Importers/ImportURDFDemo/BulletUrdfImporter.h index a74fb5117..7de13f35d 100644 --- a/examples/Importers/ImportURDFDemo/BulletUrdfImporter.h +++ b/examples/Importers/ImportURDFDemo/BulletUrdfImporter.h @@ -84,6 +84,9 @@ public: virtual int getNumAllocatedMeshInterfaces() const; virtual class btStridingMeshInterface* getAllocatedMeshInterface(int index); + virtual int getNumAllocatedTextures() const; + virtual int getAllocatedTexture(int index) const; + virtual void setEnableTinyRenderer(bool enable); void convertURDFToVisualShapeInternal(const struct UrdfVisual* visual, const char* urdfPathPrefix, const class btTransform& visualTransform, btAlignedObjectArray& verticesOut, btAlignedObjectArray& indicesOut, btAlignedObjectArray& texturesOut) const; diff --git a/examples/Importers/ImportURDFDemo/URDFImporterInterface.h b/examples/Importers/ImportURDFDemo/URDFImporterInterface.h index 7d99df01d..581c55fc8 100644 --- a/examples/Importers/ImportURDFDemo/URDFImporterInterface.h +++ b/examples/Importers/ImportURDFDemo/URDFImporterInterface.h @@ -85,6 +85,10 @@ public: virtual int getNumModels() const {return 0;} virtual void activateModel(int /*modelIndex*/) { } virtual int getNumAllocatedMeshInterfaces() const { return 0;} + + virtual int getNumAllocatedTextures() const { return 0; } + virtual int getAllocatedTexture(int index) const { return 0; } + virtual class btStridingMeshInterface* getAllocatedMeshInterface(int index) {return 0;} }; diff --git a/examples/OpenGLWindow/GLInstancingRenderer.cpp b/examples/OpenGLWindow/GLInstancingRenderer.cpp index 98b8db58d..deb658500 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.cpp +++ b/examples/OpenGLWindow/GLInstancingRenderer.cpp @@ -944,9 +944,18 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float* return newUid; } +void GLInstancingRenderer::removeTexture(int textureIndex) +{ + if ((textureIndex >= 0) && (textureIndex < m_data->m_textureHandles.size())) + { + InternalTextureHandle& h = m_data->m_textureHandles[textureIndex]; + glDeleteTextures(1, &h.m_glTexture); + } +} int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width, int height, bool flipPixelsY) { + B3_PROFILE("GLInstancingRenderer::registerTexture"); b3Assert(glGetError() ==GL_NO_ERROR); glActiveTexture(GL_TEXTURE0); diff --git a/examples/OpenGLWindow/GLInstancingRenderer.h b/examples/OpenGLWindow/GLInstancingRenderer.h index 528da0370..073c05349 100644 --- a/examples/OpenGLWindow/GLInstancingRenderer.h +++ b/examples/OpenGLWindow/GLInstancingRenderer.h @@ -69,6 +69,7 @@ public: virtual void activateTexture(int textureIndex); virtual void replaceTexture(int shapeIndex, int textureId); virtual int getShapeIndexFromInstance(int srcIndex); + virtual void removeTexture(int textureIndex); ///position x,y,z, quaternion x,y,z,w, color r,g,b,a, scaling x,y,z virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling); diff --git a/examples/OpenGLWindow/SimpleOpenGL2App.cpp b/examples/OpenGLWindow/SimpleOpenGL2App.cpp index a394c125f..381edd628 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2App.cpp +++ b/examples/OpenGLWindow/SimpleOpenGL2App.cpp @@ -44,7 +44,7 @@ static SimpleOpenGL2App* gApp2=0; static void Simple2ResizeCallback( float widthf, float heightf) { - glViewport(0, 0, widthf, heightf); + int width = (int)widthf; int height = (int)heightf; diff --git a/examples/OpenGLWindow/SimpleOpenGL2Renderer.cpp b/examples/OpenGLWindow/SimpleOpenGL2Renderer.cpp index 6431789b2..29d3c3d4b 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2Renderer.cpp +++ b/examples/OpenGLWindow/SimpleOpenGL2Renderer.cpp @@ -460,6 +460,14 @@ void SimpleOpenGL2Renderer::updateTexture(int textureIndex, const unsigned ch } } +void SimpleOpenGL2Renderer::removeTexture(int textureIndex) +{ + if ((textureIndex >= 0) && (textureIndex < m_data->m_textureHandles.size())) + { + glDeleteTextures(1, &m_data->m_textureHandles[textureIndex].m_glTexture); + } + +} void SimpleOpenGL2Renderer::activateTexture(int textureIndex) { glActiveTexture(GL_TEXTURE0); diff --git a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h index f57c98a03..b126750d9 100644 --- a/examples/OpenGLWindow/SimpleOpenGL2Renderer.h +++ b/examples/OpenGLWindow/SimpleOpenGL2Renderer.h @@ -55,7 +55,7 @@ public: virtual int registerTexture(const unsigned char* texels, int width, int height, bool flipTexelsY); virtual void updateTexture(int textureIndex, const unsigned char* texels, bool flipTexelsY); virtual void activateTexture(int textureIndex); - + virtual void removeTexture(int textureIndex); virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling); diff --git a/examples/OpenGLWindow/Win32Window.cpp b/examples/OpenGLWindow/Win32Window.cpp index d49ee24f7..715d421df 100644 --- a/examples/OpenGLWindow/Win32Window.cpp +++ b/examples/OpenGLWindow/Win32Window.cpp @@ -413,10 +413,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) sData->m_fullWindowHeight = wr.bottom-wr.top;//LOWORD (lParam) HIWORD (lParam); sData->m_openglViewportWidth = clientRect.right; sData->m_openglViewportHeight = clientRect.bottom; - //glViewport(0, 0, sData->m_openglViewportWidth, sData->m_openglViewportHeight); + if (sData->m_resizeCallback) - (*sData->m_resizeCallback)(sData->m_openglViewportWidth,sData->m_openglViewportHeight); + { + glViewport(0, 0, sData->m_openglViewportWidth, sData->m_openglViewportHeight); + (*sData->m_resizeCallback)(sData->m_openglViewportWidth, sData->m_openglViewportHeight); + } //if (sOpenGLInitialized) //{ // //gDemoApplication->reshape(sWidth,sHeight); diff --git a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp index 9e2a2745f..5c89ea86a 100644 --- a/examples/SharedMemory/PhysicsServerCommandProcessor.cpp +++ b/examples/SharedMemory/PhysicsServerCommandProcessor.cpp @@ -190,6 +190,7 @@ struct InternalBodyData btAlignedObjectArray m_rigidBodyJointNames; btAlignedObjectArray m_rigidBodyLinkNames; + #ifdef B3_ENABLE_TINY_AUDIO b3HashMap m_audioSources; #endif //B3_ENABLE_TINY_AUDIO @@ -1525,6 +1526,7 @@ struct PhysicsServerCommandProcessorInternalData btAlignedObjectArray m_strings; btAlignedObjectArray m_collisionShapes; + btAlignedObjectArray m_allocatedTextures; btHashMap m_bulletCollisionShape2UrdfCollision; btAlignedObjectArray m_meshInterfaces; @@ -2431,6 +2433,16 @@ void PhysicsServerCommandProcessor::deleteDynamicsWorld() { delete m_data->m_meshInterfaces[j]; } + + if (m_data->m_guiHelper) + { + for (int j = 0; j < m_data->m_allocatedTextures.size(); j++) + { + int texId = m_data->m_allocatedTextures[j]; + m_data->m_guiHelper->removeTexture(texId); + } + } + m_data->m_allocatedTextures.clear(); m_data->m_meshInterfaces.clear(); m_data->m_collisionShapes.clear(); m_data->m_bulletCollisionShape2UrdfCollision.clear(); @@ -2667,6 +2679,15 @@ bool PhysicsServerCommandProcessor::processImportedObjects(const char* fileName, } + + for (int i = 0; i < u2b.getNumAllocatedTextures(); i++) + { + int texId = u2b.getAllocatedTexture(i); + m_data->m_allocatedTextures.push_back(texId); + } + + + for (int i=0;im_meshInterfaces.push_back(u2b.getAllocatedMeshInterface(i)); diff --git a/examples/SharedMemory/PhysicsServerExample.cpp b/examples/SharedMemory/PhysicsServerExample.cpp index 639fc546e..ab592b908 100644 --- a/examples/SharedMemory/PhysicsServerExample.cpp +++ b/examples/SharedMemory/PhysicsServerExample.cpp @@ -135,6 +135,7 @@ enum MultiThreadedGUIHelperCommunicationEnums eGUIHelperChangeGraphicsInstanceTextureId, eGUIHelperGetShapeIndexFromInstance, eGUIHelperChangeTexture, + eGUIHelperRemoveTexture, }; @@ -859,6 +860,17 @@ public: //m_childGuiHelper->createPhysicsDebugDrawer(rbWorld); } + int m_removeTextureUid; + + virtual void removeTexture(int textureUid) + { + m_removeTextureUid = textureUid; + m_cs->lock(); + m_cs->setSharedParam(1, eGUIHelperRemoveTexture); + + workerThreadWait(); + } + virtual int registerTexture(const unsigned char* texels, int width, int height) { m_texels = texels; @@ -1878,6 +1890,13 @@ void PhysicsServerExample::updateGraphics() m_multiThreadedHelper->mainThreadRelease(); break; } + case eGUIHelperRemoveTexture: + { + B3_PROFILE("eGUIHelperRemoveTexture"); + m_multiThreadedHelper->m_childGuiHelper->removeTexture(m_multiThreadedHelper->m_removeTextureUid); + m_multiThreadedHelper->mainThreadRelease(); + break; + } case eGUIHelperRegisterGraphicsShape: { B3_PROFILE("eGUIHelperRegisterGraphicsShape"); diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 0fd41f4bd..f2caf44bd 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -1,3 +1,5 @@ +#include "E:\develop\VisualLeakDetector\include\vld.h" + #include "../SharedMemory/PhysicsClientC_API.h" #include "../SharedMemory/PhysicsDirectC_API.h" #include "../SharedMemory/SharedMemoryInProcessPhysicsC_API.h"