explicitly remove textures during resetSimulation

move glViewport to Win32Window
This commit is contained in:
erwincoumans
2018-02-21 23:22:16 -08:00
parent 15c46a0237
commit 73a4334e30
16 changed files with 102 additions and 5 deletions

View File

@@ -44,6 +44,7 @@ struct GUIHelperInterface
virtual int getShapeIndexFromInstance(int instanceUid){return -1;} virtual int getShapeIndexFromInstance(int instanceUid){return -1;}
virtual void replaceTexture(int shapeIndex, int textureUid){} virtual void replaceTexture(int shapeIndex, int textureUid){}
virtual void removeTexture(int textureUid) {}
virtual Common2dCanvasInterface* get2dCanvasInterface()=0; virtual Common2dCanvasInterface* get2dCanvasInterface()=0;

View File

@@ -72,6 +72,7 @@ struct CommonRenderInterface
virtual void updateTexture(int textureIndex, const unsigned char* texels, bool flipPixelsY=true)=0; virtual void updateTexture(int textureIndex, const unsigned char* texels, bool flipPixelsY=true)=0;
virtual void activateTexture(int textureIndex)=0; virtual void activateTexture(int textureIndex)=0;
virtual void replaceTexture(int shapeIndex, int textureIndex){}; virtual void replaceTexture(int shapeIndex, int textureIndex){};
virtual void removeTexture(int textureIndex) = 0;
virtual int getShapeIndexFromInstance(int srcIndex) {return -1;} virtual int getShapeIndexFromInstance(int srcIndex) {return -1;}

View File

@@ -291,6 +291,15 @@ int OpenGLGuiHelper::registerTexture(const unsigned char* texels, int width, int
return textureId; 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) void OpenGLGuiHelper::changeTexture(int textureUniqueId, const unsigned char* rgbTexels, int width, int height)
{ {
bool flipPixelsY = true; bool flipPixelsY = true;

View File

@@ -30,7 +30,7 @@ struct OpenGLGuiHelper : public GUIHelperInterface
virtual void changeRGBAColor(int instanceUid, const double rgbaColor[4]); virtual void changeRGBAColor(int instanceUid, const double rgbaColor[4]);
virtual void changeSpecularColor(int instanceUid, const double specularColor[3]); virtual void changeSpecularColor(int instanceUid, const double specularColor[3]);
virtual void changeTexture(int textureUniqueId, const unsigned char* rgbTexels, int width, int height); virtual void changeTexture(int textureUniqueId, const unsigned char* rgbTexels, int width, int height);
virtual void removeTexture(int textureUid);
virtual int getShapeIndexFromInstance(int instanceUid); virtual int getShapeIndexFromInstance(int instanceUid);
virtual void replaceTexture(int shapeIndex, int textureUid); virtual void replaceTexture(int shapeIndex, int textureUid);

View File

@@ -48,6 +48,7 @@ ATTRIBUTE_ALIGNED16(struct) BulletURDFInternalData
int m_bodyId; int m_bodyId;
btHashMap<btHashInt,UrdfMaterialColor> m_linkColors; btHashMap<btHashInt,UrdfMaterialColor> m_linkColors;
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes; btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
btAlignedObjectArray<int> m_allocatedTextures;
mutable btAlignedObjectArray<btTriangleMesh*> m_allocatedMeshInterfaces; mutable btAlignedObjectArray<btTriangleMesh*> m_allocatedMeshInterfaces;
btHashMap<btHashPtr, UrdfCollision> m_bulletCollisionShape2UrdfCollision; btHashMap<btHashPtr, UrdfCollision> 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); 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"); B3_PROFILE("registerGraphicsShape");
@@ -1270,11 +1275,22 @@ int BulletURDFImporter::getNumAllocatedMeshInterfaces() const
} }
btStridingMeshInterface* BulletURDFImporter::getAllocatedMeshInterface(int index) btStridingMeshInterface* BulletURDFImporter::getAllocatedMeshInterface(int index)
{ {
return m_data->m_allocatedMeshInterfaces[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 class btCompoundShape* BulletURDFImporter::convertLinkCollisionShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const

View File

@@ -84,6 +84,9 @@ public:
virtual int getNumAllocatedMeshInterfaces() const; virtual int getNumAllocatedMeshInterfaces() const;
virtual class btStridingMeshInterface* getAllocatedMeshInterface(int index); virtual class btStridingMeshInterface* getAllocatedMeshInterface(int index);
virtual int getNumAllocatedTextures() const;
virtual int getAllocatedTexture(int index) const;
virtual void setEnableTinyRenderer(bool enable); virtual void setEnableTinyRenderer(bool enable);
void convertURDFToVisualShapeInternal(const struct UrdfVisual* visual, const char* urdfPathPrefix, const class btTransform& visualTransform, btAlignedObjectArray<struct GLInstanceVertex>& verticesOut, btAlignedObjectArray<int>& indicesOut, btAlignedObjectArray<struct BulletURDFTexture>& texturesOut) const; void convertURDFToVisualShapeInternal(const struct UrdfVisual* visual, const char* urdfPathPrefix, const class btTransform& visualTransform, btAlignedObjectArray<struct GLInstanceVertex>& verticesOut, btAlignedObjectArray<int>& indicesOut, btAlignedObjectArray<struct BulletURDFTexture>& texturesOut) const;

View File

@@ -85,6 +85,10 @@ public:
virtual int getNumModels() const {return 0;} virtual int getNumModels() const {return 0;}
virtual void activateModel(int /*modelIndex*/) { } virtual void activateModel(int /*modelIndex*/) { }
virtual int getNumAllocatedMeshInterfaces() const { return 0;} 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;} virtual class btStridingMeshInterface* getAllocatedMeshInterface(int index) {return 0;}
}; };

View File

@@ -944,9 +944,18 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float*
return newUid; 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) int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width, int height, bool flipPixelsY)
{ {
B3_PROFILE("GLInstancingRenderer::registerTexture"); B3_PROFILE("GLInstancingRenderer::registerTexture");
b3Assert(glGetError() ==GL_NO_ERROR); b3Assert(glGetError() ==GL_NO_ERROR);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);

View File

@@ -69,6 +69,7 @@ public:
virtual void activateTexture(int textureIndex); virtual void activateTexture(int textureIndex);
virtual void replaceTexture(int shapeIndex, int textureId); virtual void replaceTexture(int shapeIndex, int textureId);
virtual int getShapeIndexFromInstance(int srcIndex); 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 ///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); virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling);

View File

@@ -44,7 +44,7 @@ static SimpleOpenGL2App* gApp2=0;
static void Simple2ResizeCallback( float widthf, float heightf) static void Simple2ResizeCallback( float widthf, float heightf)
{ {
glViewport(0, 0, widthf, heightf);
int width = (int)widthf; int width = (int)widthf;
int height = (int)heightf; int height = (int)heightf;

View File

@@ -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) void SimpleOpenGL2Renderer::activateTexture(int textureIndex)
{ {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);

View File

@@ -55,7 +55,7 @@ public:
virtual int registerTexture(const unsigned char* texels, int width, int height, bool flipTexelsY); 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 updateTexture(int textureIndex, const unsigned char* texels, bool flipTexelsY);
virtual void activateTexture(int textureIndex); 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); virtual int registerGraphicsInstance(int shapeIndex, const double* position, const double* quaternion, const double* color, const double* scaling);

View File

@@ -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_fullWindowHeight = wr.bottom-wr.top;//LOWORD (lParam) HIWORD (lParam);
sData->m_openglViewportWidth = clientRect.right; sData->m_openglViewportWidth = clientRect.right;
sData->m_openglViewportHeight = clientRect.bottom; sData->m_openglViewportHeight = clientRect.bottom;
//glViewport(0, 0, sData->m_openglViewportWidth, sData->m_openglViewportHeight);
if (sData->m_resizeCallback) 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) //if (sOpenGLInitialized)
//{ //{
// //gDemoApplication->reshape(sWidth,sHeight); // //gDemoApplication->reshape(sWidth,sHeight);

View File

@@ -190,6 +190,7 @@ struct InternalBodyData
btAlignedObjectArray<std::string> m_rigidBodyJointNames; btAlignedObjectArray<std::string> m_rigidBodyJointNames;
btAlignedObjectArray<std::string> m_rigidBodyLinkNames; btAlignedObjectArray<std::string> m_rigidBodyLinkNames;
#ifdef B3_ENABLE_TINY_AUDIO #ifdef B3_ENABLE_TINY_AUDIO
b3HashMap<btHashInt, SDFAudioSource> m_audioSources; b3HashMap<btHashInt, SDFAudioSource> m_audioSources;
#endif //B3_ENABLE_TINY_AUDIO #endif //B3_ENABLE_TINY_AUDIO
@@ -1525,6 +1526,7 @@ struct PhysicsServerCommandProcessorInternalData
btAlignedObjectArray<std::string*> m_strings; btAlignedObjectArray<std::string*> m_strings;
btAlignedObjectArray<btCollisionShape*> m_collisionShapes; btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
btAlignedObjectArray<int> m_allocatedTextures;
btHashMap<btHashPtr, UrdfCollision> m_bulletCollisionShape2UrdfCollision; btHashMap<btHashPtr, UrdfCollision> m_bulletCollisionShape2UrdfCollision;
btAlignedObjectArray<btStridingMeshInterface*> m_meshInterfaces; btAlignedObjectArray<btStridingMeshInterface*> m_meshInterfaces;
@@ -2431,6 +2433,16 @@ void PhysicsServerCommandProcessor::deleteDynamicsWorld()
{ {
delete m_data->m_meshInterfaces[j]; 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_meshInterfaces.clear();
m_data->m_collisionShapes.clear(); m_data->m_collisionShapes.clear();
m_data->m_bulletCollisionShape2UrdfCollision.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;i<u2b.getNumAllocatedMeshInterfaces();i++) for (int i=0;i<u2b.getNumAllocatedMeshInterfaces();i++)
{ {
m_data->m_meshInterfaces.push_back(u2b.getAllocatedMeshInterface(i)); m_data->m_meshInterfaces.push_back(u2b.getAllocatedMeshInterface(i));

View File

@@ -135,6 +135,7 @@ enum MultiThreadedGUIHelperCommunicationEnums
eGUIHelperChangeGraphicsInstanceTextureId, eGUIHelperChangeGraphicsInstanceTextureId,
eGUIHelperGetShapeIndexFromInstance, eGUIHelperGetShapeIndexFromInstance,
eGUIHelperChangeTexture, eGUIHelperChangeTexture,
eGUIHelperRemoveTexture,
}; };
@@ -859,6 +860,17 @@ public:
//m_childGuiHelper->createPhysicsDebugDrawer(rbWorld); //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) virtual int registerTexture(const unsigned char* texels, int width, int height)
{ {
m_texels = texels; m_texels = texels;
@@ -1878,6 +1890,13 @@ void PhysicsServerExample::updateGraphics()
m_multiThreadedHelper->mainThreadRelease(); m_multiThreadedHelper->mainThreadRelease();
break; break;
} }
case eGUIHelperRemoveTexture:
{
B3_PROFILE("eGUIHelperRemoveTexture");
m_multiThreadedHelper->m_childGuiHelper->removeTexture(m_multiThreadedHelper->m_removeTextureUid);
m_multiThreadedHelper->mainThreadRelease();
break;
}
case eGUIHelperRegisterGraphicsShape: case eGUIHelperRegisterGraphicsShape:
{ {
B3_PROFILE("eGUIHelperRegisterGraphicsShape"); B3_PROFILE("eGUIHelperRegisterGraphicsShape");

View File

@@ -1,3 +1,5 @@
#include "E:\develop\VisualLeakDetector\include\vld.h"
#include "../SharedMemory/PhysicsClientC_API.h" #include "../SharedMemory/PhysicsClientC_API.h"
#include "../SharedMemory/PhysicsDirectC_API.h" #include "../SharedMemory/PhysicsDirectC_API.h"
#include "../SharedMemory/SharedMemoryInProcessPhysicsC_API.h" #include "../SharedMemory/SharedMemoryInProcessPhysicsC_API.h"