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:
@@ -15,9 +15,9 @@ subject to the following restrictions:
|
|||||||
|
|
||||||
|
|
||||||
///create 125 (5x5x5) dynamic object
|
///create 125 (5x5x5) dynamic object
|
||||||
#define ARRAY_SIZE_X 1//25
|
#define ARRAY_SIZE_X 25
|
||||||
#define ARRAY_SIZE_Y 20//20
|
#define ARRAY_SIZE_Y 20
|
||||||
#define ARRAY_SIZE_Z 1//25
|
#define ARRAY_SIZE_Z 25
|
||||||
|
|
||||||
//maximum number of objects (and allow user to shoot additional boxes)
|
//maximum number of objects (and allow user to shoot additional boxes)
|
||||||
#define MAX_PROXIES (ARRAY_SIZE_X*ARRAY_SIZE_Y*ARRAY_SIZE_Z + 1024)
|
#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
|
//create a few dynamic rigidbodies
|
||||||
// Re-using the same collision is better for memory usage and performance
|
// 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);
|
m_collisionShapes.push_back(colShape);
|
||||||
|
|
||||||
/// Create Dynamic Objects
|
/// Create Dynamic Objects
|
||||||
|
|||||||
@@ -608,6 +608,8 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
|
|
||||||
int maxObjectCapacity=128*1024;
|
int maxObjectCapacity=128*1024;
|
||||||
|
maxObjectCapacity = b3Max(maxObjectCapacity,ci.arraySizeX*ci.arraySizeX*ci.arraySizeX+10);
|
||||||
|
|
||||||
|
|
||||||
ci.m_instancingRenderer = new GLInstancingRenderer(maxObjectCapacity);//render.getInstancingRenderer();
|
ci.m_instancingRenderer = new GLInstancingRenderer(maxObjectCapacity);//render.getInstancingRenderer();
|
||||||
ci.m_window = window;
|
ci.m_window = window;
|
||||||
|
|||||||
@@ -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);
|
m_data->m_copyTransformsToVBOKernel = b3OpenCLUtils::compileCLKernelFromString(m_clData->m_clContext,m_clData->m_clDevice,s_rigidBodyKernelString,"copyTransformsToVBOKernel",&errNum,rbProg);
|
||||||
|
|
||||||
b3Config config;
|
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);
|
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);
|
b3GpuSapBroadphase* bp = new b3GpuSapBroadphase(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue);
|
||||||
m_data->m_np = np;
|
m_data->m_np = np;
|
||||||
@@ -157,7 +163,18 @@ void GpuRigidBodyDemo::clientMoveAndDisplay()
|
|||||||
{
|
{
|
||||||
bool animate=true;
|
bool animate=true;
|
||||||
int numObjects= m_data->m_rigidBodyPipeline->getNumBodies();
|
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;
|
b3Vector4* positions = 0;
|
||||||
if (animate && numObjects)
|
if (animate && numObjects)
|
||||||
{
|
{
|
||||||
@@ -205,7 +222,9 @@ void GpuRigidBodyDemo::clientMoveAndDisplay()
|
|||||||
GLint err = glGetError();
|
GLint err = glGetError();
|
||||||
assert(err==GL_NO_ERROR);
|
assert(err==GL_NO_ERROR);
|
||||||
GLuint vbo = m_instancingRenderer->getInternalData()->m_vbo;
|
GLuint vbo = m_instancingRenderer->getInternalData()->m_vbo;
|
||||||
|
|
||||||
int arraySizeInBytes = numObjects * (3)*sizeof(b3Vector4);
|
int arraySizeInBytes = numObjects * (3)*sizeof(b3Vector4);
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
||||||
cl_bool blocking= CL_TRUE;
|
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
|
positions= (b3Vector4*)glMapBufferRange( GL_ARRAY_BUFFER,m_instancingRenderer->getMaxShapeCapacity(),arraySizeInBytes, GL_MAP_WRITE_BIT );//GL_READ_WRITE);//GL_WRITE_ONLY
|
||||||
|
|||||||
@@ -669,28 +669,34 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float*
|
|||||||
|
|
||||||
int index = gfxObj->m_numGraphicsInstances + gfxObj->m_instanceOffset;
|
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];
|
||||||
|
m_data->m_instance_positions_ptr[index*4+3]=1;
|
||||||
|
|
||||||
|
m_data->m_instance_quaternion_ptr[index*4]=quaternion[0];
|
||||||
|
m_data->m_instance_quaternion_ptr[index*4+1]=quaternion[1];
|
||||||
|
m_data->m_instance_quaternion_ptr[index*4+2]=quaternion[2];
|
||||||
|
m_data->m_instance_quaternion_ptr[index*4+3]=quaternion[3];
|
||||||
|
|
||||||
m_data->m_instance_positions_ptr[index*4]=position[0];
|
m_data->m_instance_colors_ptr[index*4]=color[0];
|
||||||
m_data->m_instance_positions_ptr[index*4+1]=position[1];
|
m_data->m_instance_colors_ptr[index*4+1]=color[1];
|
||||||
m_data->m_instance_positions_ptr[index*4+2]=position[2];
|
m_data->m_instance_colors_ptr[index*4+2]=color[2];
|
||||||
m_data->m_instance_positions_ptr[index*4+3]=1;
|
m_data->m_instance_colors_ptr[index*4+3]=color[3];
|
||||||
|
|
||||||
m_data->m_instance_quaternion_ptr[index*4]=quaternion[0];
|
m_data->m_instance_scale_ptr[index*3] = scaling[0];
|
||||||
m_data->m_instance_quaternion_ptr[index*4+1]=quaternion[1];
|
m_data->m_instance_scale_ptr[index*3+1] = scaling[1];
|
||||||
m_data->m_instance_quaternion_ptr[index*4+2]=quaternion[2];
|
m_data->m_instance_scale_ptr[index*3+2] = scaling[2];
|
||||||
m_data->m_instance_quaternion_ptr[index*4+3]=quaternion[3];
|
|
||||||
|
|
||||||
m_data->m_instance_colors_ptr[index*4]=color[0];
|
gfxObj->m_numGraphicsInstances++;
|
||||||
m_data->m_instance_colors_ptr[index*4+1]=color[1];
|
} else
|
||||||
m_data->m_instance_colors_ptr[index*4+2]=color[2];
|
{
|
||||||
m_data->m_instance_colors_ptr[index*4+3]=color[3];
|
b3Error("registerGraphicsInstance out of range, %d\n", maxElements);
|
||||||
|
return -1;
|
||||||
m_data->m_instance_scale_ptr[index*3] = scaling[0];
|
}
|
||||||
m_data->m_instance_scale_ptr[index*3+1] = scaling[1];
|
|
||||||
m_data->m_instance_scale_ptr[index*3+2] = scaling[2];
|
|
||||||
|
|
||||||
gfxObj->m_numGraphicsInstances++;
|
|
||||||
return gfxObj->m_numGraphicsInstances;
|
return gfxObj->m_numGraphicsInstances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -105,6 +105,10 @@ public:
|
|||||||
{
|
{
|
||||||
return m_maxShapeCapacityInBytes;
|
return m_maxShapeCapacityInBytes;
|
||||||
}
|
}
|
||||||
|
int getInstanceCapacity() const
|
||||||
|
{
|
||||||
|
return m_maxNumObjectCapacity;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //GL_INSTANCING_RENDERER_H
|
#endif //GL_INSTANCING_RENDERER_H
|
||||||
|
|||||||
@@ -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)
|
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 = new b3GpuRigidBodyPipelineInternalData;
|
||||||
|
m_data->m_config = config;
|
||||||
m_data->m_context = ctx;
|
m_data->m_context = ctx;
|
||||||
m_data->m_device = device;
|
m_data->m_device = device;
|
||||||
m_data->m_queue = q;
|
m_data->m_queue = q;
|
||||||
|
|||||||
Reference in New Issue
Block a user