allow larger amount of rigid bodies, dynamically increase b3Config limits

avoid crashes in instancing renderer if instance maximum is exceeded.
This commit is contained in:
erwincoumans
2013-06-17 17:05:01 -07:00
parent 561a44e5d8
commit 9a92eecf10
6 changed files with 57 additions and 25 deletions

View File

@@ -15,9 +15,9 @@ subject to the following restrictions:
///create 125 (5x5x5) dynamic object
#define ARRAY_SIZE_X 1//25
#define ARRAY_SIZE_Y 20//20
#define ARRAY_SIZE_Z 1//25
#define ARRAY_SIZE_X 25
#define ARRAY_SIZE_Y 20
#define ARRAY_SIZE_Z 25
//maximum number of objects (and allow user to shoot additional boxes)
#define MAX_PROXIES (ARRAY_SIZE_X*ARRAY_SIZE_Y*ARRAY_SIZE_Z + 1024)
@@ -284,9 +284,9 @@ void BasicGpuDemo::initPhysics()
//create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance
//btBoxShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
btBoxShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));
btCollisionShape* colShape = new btSphereShape(btScalar(SCALING*1.f));
//btCollisionShape* colShape = new btSphereShape(btScalar(SCALING*1.f));
m_collisionShapes.push_back(colShape);
/// Create Dynamic Objects

View File

@@ -608,6 +608,8 @@ int main(int argc, char* argv[])
int maxObjectCapacity=128*1024;
maxObjectCapacity = b3Max(maxObjectCapacity,ci.arraySizeX*ci.arraySizeX*ci.arraySizeX+10);
ci.m_instancingRenderer = new GLInstancingRenderer(maxObjectCapacity);//render.getInstancingRenderer();
ci.m_window = window;

View File

@@ -108,6 +108,12 @@ void GpuRigidBodyDemo::initPhysics(const ConstructionInfo& ci)
m_data->m_copyTransformsToVBOKernel = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,s_rigidBodyKernelString,"copyTransformsToVBOKernel",&errNum,rbProg);
b3Config config;
config.m_maxConvexBodies = b3Max(config.m_maxConvexBodies,ci.arraySizeX*ci.arraySizeY*ci.arraySizeZ+10);
config.m_maxConvexShapes = config.m_maxConvexBodies;
config.m_maxBroadphasePairs = 8*config.m_maxConvexBodies;
config.m_maxContactCapacity = config.m_maxBroadphasePairs;
b3GpuNarrowPhase* np = new b3GpuNarrowPhase(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue,config);
b3GpuSapBroadphase* bp = new b3GpuSapBroadphase(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue);
m_data->m_np = np;
@@ -157,7 +163,18 @@ void GpuRigidBodyDemo::clientMoveAndDisplay()
{
bool animate=true;
int numObjects= m_data->m_rigidBodyPipeline->getNumBodies();
//m_instancingRenderer->getInternalData()->m_totalNumInstances;
if (numObjects > m_instancingRenderer->getInstanceCapacity())
{
static bool once = true;
if (once)
{
once=false;
b3Assert(0);
b3Error("m_instancingRenderer out-of-memory\n");
}
numObjects = m_instancingRenderer->getInstanceCapacity();
}
b3Vector4* positions = 0;
if (animate && numObjects)
{
@@ -205,7 +222,9 @@ void GpuRigidBodyDemo::clientMoveAndDisplay()
GLint err = glGetError();
assert(err==GL_NO_ERROR);
GLuint vbo = m_instancingRenderer->getInternalData()->m_vbo;
int arraySizeInBytes = numObjects * (3)*sizeof(b3Vector4);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
cl_bool blocking= CL_TRUE;
positions= (b3Vector4*)glMapBufferRange( GL_ARRAY_BUFFER,m_instancingRenderer->getMaxShapeCapacity(),arraySizeInBytes, GL_MAP_WRITE_BIT );//GL_READ_WRITE);//GL_WRITE_ONLY

View File

@@ -669,8 +669,9 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float*
int index = gfxObj->m_numGraphicsInstances + gfxObj->m_instanceOffset;
int maxElements = m_data->m_instance_positions_ptr.size();
if (index*4<maxElements)
{
m_data->m_instance_positions_ptr[index*4]=position[0];
m_data->m_instance_positions_ptr[index*4+1]=position[1];
m_data->m_instance_positions_ptr[index*4+2]=position[2];
@@ -691,6 +692,11 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float*
m_data->m_instance_scale_ptr[index*3+2] = scaling[2];
gfxObj->m_numGraphicsInstances++;
} else
{
b3Error("registerGraphicsInstance out of range, %d\n", maxElements);
return -1;
}
return gfxObj->m_numGraphicsInstances;
}

View File

@@ -105,6 +105,10 @@ public:
{
return m_maxShapeCapacityInBytes;
}
int getInstanceCapacity() const
{
return m_maxNumObjectCapacity;
}
};
#endif //GL_INSTANCING_RENDERER_H

View File

@@ -40,6 +40,7 @@ bool dumpContactStats = false;
b3GpuRigidBodyPipeline::b3GpuRigidBodyPipeline(cl_context ctx,cl_device_id device, cl_command_queue q,class b3GpuNarrowPhase* narrowphase, class b3GpuSapBroadphase* broadphaseSap , struct b3DynamicBvhBroadphase* broadphaseDbvt, const b3Config& config)
{
m_data = new b3GpuRigidBodyPipelineInternalData;
m_data->m_config = config;
m_data->m_context = ctx;
m_data->m_device = device;
m_data->m_queue = q;