add wavefront loader
start adding various scenes to test gpu rigid body pipeline reserve more memory for shapes (concave triangle mesh can be huge) in GLInstancingRenderer fix a few crashes when 0 objects
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "gpu_rigidbody/host/btGpuRigidBodyPipeline.h"
|
||||
#include "gpu_rigidbody/host/btGpuNarrowPhase.h"
|
||||
#include "gpu_rigidbody/host/btConfig.h"
|
||||
#include "GpuRigidBodyDemoInternalData.h"
|
||||
|
||||
static btKeyboardCallback oldCallback = 0;
|
||||
extern bool gReset;
|
||||
@@ -46,26 +47,7 @@ __kernel void
|
||||
);
|
||||
|
||||
|
||||
struct GpuRigidBodyDemoInternalData
|
||||
{
|
||||
|
||||
cl_kernel m_copyTransformsToVBOKernel;
|
||||
|
||||
btOpenCLArray<btVector4>* m_instancePosOrnColor;
|
||||
|
||||
class btGpuRigidBodyPipeline* m_rigidBodyPipeline;
|
||||
|
||||
btGpuNarrowPhase* m_np;
|
||||
btGpuSapBroadphase* m_bp;
|
||||
|
||||
GpuRigidBodyDemoInternalData()
|
||||
:m_instancePosOrnColor(0),
|
||||
m_copyTransformsToVBOKernel(0), m_rigidBodyPipeline(0),
|
||||
m_np(0),
|
||||
m_bp(0)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
GpuRigidBodyDemo::GpuRigidBodyDemo()
|
||||
@@ -97,11 +79,26 @@ static void PairKeyboardCallback(int key, int state)
|
||||
oldCallback(key,state);
|
||||
}
|
||||
|
||||
void GpuRigidBodyDemo::setupScene(const ConstructionInfo& ci)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void GpuRigidBodyDemo::initPhysics(const ConstructionInfo& ci)
|
||||
{
|
||||
|
||||
if (ci.m_window)
|
||||
{
|
||||
m_window = ci.m_window;
|
||||
oldCallback = ci.m_window->getKeyboardCallback();
|
||||
ci.m_window->setKeyboardCallback(PairKeyboardCallback);
|
||||
|
||||
}
|
||||
|
||||
m_instancingRenderer = ci.m_instancingRenderer;
|
||||
|
||||
initCL(ci.preferredOpenCLDeviceIndex,ci.preferredOpenCLPlatformIndex);
|
||||
|
||||
if (m_clData->m_clContext)
|
||||
{
|
||||
int errNum=0;
|
||||
@@ -117,62 +114,13 @@ void GpuRigidBodyDemo::initPhysics(const ConstructionInfo& ci)
|
||||
|
||||
m_data->m_rigidBodyPipeline = new btGpuRigidBodyPipeline(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue, np, bp);
|
||||
|
||||
int strideInBytes = 9*sizeof(float);
|
||||
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(cube_vertices)/sizeof(int);
|
||||
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
int group=1;
|
||||
int mask=1;
|
||||
int index=10;
|
||||
float scaling[4] = {1,1,1,1};
|
||||
|
||||
int colIndex = np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
||||
setupScene(ci);
|
||||
|
||||
|
||||
for (int i=0;i<ci.arraySizeX;i++)
|
||||
{
|
||||
for (int j=0;j<ci.arraySizeY;j++)
|
||||
{
|
||||
for (int k=0;k<ci.arraySizeZ;k++)
|
||||
{
|
||||
float mass = j==0? 0.f : 1.f;
|
||||
|
||||
btVector3 position(i*ci.gapX,j*ci.gapY,k*ci.gapZ);
|
||||
btQuaternion orn(1,0,0,0);
|
||||
|
||||
btVector4 color(0,1,0,1);
|
||||
btVector4 scaling(1,1,1,1);
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index);
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
np->writeAllBodiesToGpu();
|
||||
bp->writeAabbsToGpu();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (ci.m_window)
|
||||
{
|
||||
m_window = ci.m_window;
|
||||
oldCallback = ci.m_window->getKeyboardCallback();
|
||||
ci.m_window->setKeyboardCallback(PairKeyboardCallback);
|
||||
|
||||
}
|
||||
|
||||
m_instancingRenderer = ci.m_instancingRenderer;
|
||||
|
||||
|
||||
float camPos[4]={65.5,4.5,65.5,0};
|
||||
//float camPos[4]={1,12.5,1.5,0};
|
||||
m_instancingRenderer->setCameraTargetPosition(camPos);
|
||||
m_instancingRenderer->setCameraDistance(90);
|
||||
|
||||
m_instancingRenderer->writeTransforms();
|
||||
|
||||
@@ -204,9 +152,10 @@ void GpuRigidBodyDemo::renderScene()
|
||||
void GpuRigidBodyDemo::clientMoveAndDisplay()
|
||||
{
|
||||
bool animate=true;
|
||||
int numObjects= m_instancingRenderer->getInternalData()->m_totalNumInstances;
|
||||
int numObjects= m_data->m_rigidBodyPipeline->getNumBodies();
|
||||
//m_instancingRenderer->getInternalData()->m_totalNumInstances;
|
||||
btVector4* positions = 0;
|
||||
if (animate)
|
||||
if (animate && numObjects)
|
||||
{
|
||||
GLuint vbo = m_instancingRenderer->getInternalData()->m_vbo;
|
||||
int arraySizeInBytes = numObjects * (3)*sizeof(btVector4);
|
||||
@@ -222,9 +171,10 @@ void GpuRigidBodyDemo::clientMoveAndDisplay()
|
||||
m_data->m_instancePosOrnColor->copyFromHostPointer(positions,3*numObjects,0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_data->m_rigidBodyPipeline->stepSimulation(1./60.f);
|
||||
|
||||
if (numObjects)
|
||||
{
|
||||
int ciErrNum = 0;
|
||||
cl_mem bodies = m_data->m_rigidBodyPipeline->getBodyBuffer();
|
||||
@@ -236,7 +186,7 @@ void GpuRigidBodyDemo::clientMoveAndDisplay()
|
||||
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
||||
}
|
||||
|
||||
if (animate)
|
||||
if (animate && numObjects)
|
||||
{
|
||||
GLint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
Reference in New Issue
Block a user