Merge branch 'master' of https://github.com/erwincoumans/bullet3
This commit is contained in:
@@ -77,6 +77,7 @@ GpuDemo::CreateFunc* allDemos[]=
|
|||||||
|
|
||||||
//ConcaveSphereScene::MyCreateFunc,
|
//ConcaveSphereScene::MyCreateFunc,
|
||||||
//GpuRaytraceScene::MyCreateFunc,
|
//GpuRaytraceScene::MyCreateFunc,
|
||||||
|
GpuSoftClothDemo::MyCreateFunc,
|
||||||
|
|
||||||
GpuBoxPlaneScene::MyCreateFunc,
|
GpuBoxPlaneScene::MyCreateFunc,
|
||||||
GpuConvexPlaneScene::MyCreateFunc,
|
GpuConvexPlaneScene::MyCreateFunc,
|
||||||
@@ -100,7 +101,6 @@ GpuDemo::CreateFunc* allDemos[]=
|
|||||||
|
|
||||||
GpuSphereScene::MyCreateFunc,
|
GpuSphereScene::MyCreateFunc,
|
||||||
|
|
||||||
GpuSoftClothDemo::MyCreateFunc,
|
|
||||||
|
|
||||||
Bullet2FileDemo::MyCreateFunc,
|
Bullet2FileDemo::MyCreateFunc,
|
||||||
|
|
||||||
@@ -532,6 +532,7 @@ int main(int argc, char* argv[])
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
window->startRendering();
|
window->startRendering();
|
||||||
glFinish();
|
glFinish();
|
||||||
|
|
||||||
@@ -702,6 +703,9 @@ int main(int argc, char* argv[])
|
|||||||
fprintf(defaultOutput,"\n");
|
fprintf(defaultOutput,"\n");
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
GLint err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
b3ProfileManager::Reset();
|
b3ProfileManager::Reset();
|
||||||
b3ProfileManager::Increment_Frame_Counter();
|
b3ProfileManager::Increment_Frame_Counter();
|
||||||
|
|
||||||
@@ -731,6 +735,8 @@ int main(int argc, char* argv[])
|
|||||||
B3_PROFILE("renderScene");
|
B3_PROFILE("renderScene");
|
||||||
demo->renderScene();
|
demo->renderScene();
|
||||||
}
|
}
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
/*if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getNumCollisionObjects())
|
/*if (demo->getDynamicsWorld() && demo->getDynamicsWorld()->getNumCollisionObjects())
|
||||||
@@ -748,39 +754,45 @@ int main(int argc, char* argv[])
|
|||||||
B3_PROFILE("gui->draw");
|
B3_PROFILE("gui->draw");
|
||||||
gui->draw(g_OpenGLWidth,g_OpenGLHeight);
|
gui->draw(g_OpenGLWidth,g_OpenGLHeight);
|
||||||
}
|
}
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
{
|
{
|
||||||
B3_PROFILE("window->endRendering");
|
B3_PROFILE("window->endRendering");
|
||||||
window->endRendering();
|
window->endRendering();
|
||||||
}
|
}
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
{
|
{
|
||||||
B3_PROFILE("glFinish");
|
B3_PROFILE("glFinish");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (dump_timings)
|
if (dump_timings)
|
||||||
{
|
|
||||||
b3ProfileManager::dumpAll(stdout);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (csvFile)
|
|
||||||
{
|
|
||||||
static int frameCount=0;
|
|
||||||
|
|
||||||
if (frameCount>0)
|
|
||||||
{
|
{
|
||||||
DumpSimulationTime(csvFile);
|
b3ProfileManager::dumpAll(stdout);
|
||||||
if (detailsFile)
|
|
||||||
{
|
|
||||||
fprintf(detailsFile,"\n==================================\nFrame %d:\n", frameCount);
|
|
||||||
b3ProfileManager::dumpAll(detailsFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frameCount>=102)
|
if (csvFile)
|
||||||
window->setRequestExit();
|
{
|
||||||
frameCount++;
|
static int frameCount=0;
|
||||||
}
|
|
||||||
|
if (frameCount>0)
|
||||||
|
{
|
||||||
|
DumpSimulationTime(csvFile);
|
||||||
|
if (detailsFile)
|
||||||
|
{
|
||||||
|
fprintf(detailsFile,"\n==================================\nFrame %d:\n", frameCount);
|
||||||
|
b3ProfileManager::dumpAll(detailsFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frameCount>=102)
|
||||||
|
window->setRequestExit();
|
||||||
|
frameCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,9 @@ void GpuSoftBodyDemo::setupScene(const ConstructionInfo& ci)
|
|||||||
void GpuSoftBodyDemo::initPhysics(const ConstructionInfo& ci)
|
void GpuSoftBodyDemo::initPhysics(const ConstructionInfo& ci)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
GLint err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
if (ci.m_window)
|
if (ci.m_window)
|
||||||
{
|
{
|
||||||
m_window = ci.m_window;
|
m_window = ci.m_window;
|
||||||
@@ -117,9 +120,15 @@ void GpuSoftBodyDemo::initPhysics(const ConstructionInfo& ci)
|
|||||||
|
|
||||||
m_data->m_rigidBodyPipeline = new b3GpuRigidBodyPipeline(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue, np, bp,broadphaseDbvt);
|
m_data->m_rigidBodyPipeline = new b3GpuRigidBodyPipeline(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue, np, bp,broadphaseDbvt);
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
setupScene(ci);
|
setupScene(ci);
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
m_data->m_rigidBodyPipeline->writeAllInstancesToGpu();
|
m_data->m_rigidBodyPipeline->writeAllInstancesToGpu();
|
||||||
np->writeAllBodiesToGpu();
|
np->writeAllBodiesToGpu();
|
||||||
bp->writeAabbsToGpu();
|
bp->writeAabbsToGpu();
|
||||||
@@ -205,6 +214,9 @@ void GpuSoftBodyDemo::renderScene()
|
|||||||
|
|
||||||
void GpuSoftBodyDemo::clientMoveAndDisplay()
|
void GpuSoftBodyDemo::clientMoveAndDisplay()
|
||||||
{
|
{
|
||||||
|
GLint err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
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;
|
//m_instancingRenderer->getInternalData()->m_totalNumInstances;
|
||||||
@@ -231,6 +243,9 @@ void GpuSoftBodyDemo::clientMoveAndDisplay()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
{
|
{
|
||||||
B3_PROFILE("stepSimulation");
|
B3_PROFILE("stepSimulation");
|
||||||
m_data->m_rigidBodyPipeline->stepSimulation(1./60.f);
|
m_data->m_rigidBodyPipeline->stepSimulation(1./60.f);
|
||||||
@@ -249,6 +264,9 @@ void GpuSoftBodyDemo::clientMoveAndDisplay()
|
|||||||
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
oclCHECKERROR(ciErrNum, CL_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
if (animate && numObjects)
|
if (animate && numObjects)
|
||||||
{
|
{
|
||||||
B3_PROFILE("cl2gl_upload");
|
B3_PROFILE("cl2gl_upload");
|
||||||
@@ -267,6 +285,9 @@ void GpuSoftBodyDemo::clientMoveAndDisplay()
|
|||||||
assert(err==GL_NO_ERROR);
|
assert(err==GL_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -325,6 +346,10 @@ unsigned char* GpuSoftClothDemo::loadImage(const char* fileName, int& width, int
|
|||||||
|
|
||||||
void GpuSoftClothDemo::setupScene(const ConstructionInfo& ci)
|
void GpuSoftClothDemo::setupScene(const ConstructionInfo& ci)
|
||||||
{
|
{
|
||||||
|
GLint err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
int width = 256;
|
int width = 256;
|
||||||
int height = 256;
|
int height = 256;
|
||||||
|
|
||||||
@@ -355,6 +380,9 @@ void GpuSoftClothDemo::setupScene(const ConstructionInfo& ci)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
int numIndices = 0;
|
int numIndices = 0;
|
||||||
|
|
||||||
// Generate and fill index array for rendering
|
// Generate and fill index array for rendering
|
||||||
@@ -387,17 +415,39 @@ void GpuSoftClothDemo::setupScene(const ConstructionInfo& ci)
|
|||||||
int width,height,n;
|
int width,height,n;
|
||||||
FILE* f = fopen("test.tst","wb");
|
FILE* f = fopen("test.tst","wb");
|
||||||
fclose(f);
|
fclose(f);
|
||||||
const char* filename = "../../data/bullet_logo.png";
|
const char* filename = "data/bullet_logo.png";
|
||||||
const unsigned char* image = loadImage(filename,width,height,n);
|
const unsigned char* image=0;
|
||||||
textureIndex = ci.m_instancingRenderer->registerTexture(image,width,height);
|
|
||||||
|
const char* prefix[]={"./","../","../../","../../../","../../../../"};
|
||||||
|
int numprefix = sizeof(prefix)/sizeof(const char*);
|
||||||
|
|
||||||
|
for (int i=0;!image && i<numprefix;i++)
|
||||||
|
{
|
||||||
|
char relativeFileName[1024];
|
||||||
|
sprintf(relativeFileName,"%s%s",prefix[i],filename);
|
||||||
|
image = loadImage(relativeFileName,width,height,n);
|
||||||
|
}
|
||||||
|
|
||||||
|
b3Assert(image);
|
||||||
|
if (image)
|
||||||
|
{
|
||||||
|
textureIndex = ci.m_instancingRenderer->registerTexture(image,width,height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// int shapeIndex = ci.m_instancingRenderer->registerShape(barrel_vertices,num_barrel_vertices,barrel_indices,num_barrel_indices);
|
// int shapeIndex = ci.m_instancingRenderer->registerShape(barrel_vertices,num_barrel_vertices,barrel_indices,num_barrel_indices);
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
m_data->m_clothVertices = &cpu_buffer[0].pos[0];
|
m_data->m_clothVertices = &cpu_buffer[0].pos[0];
|
||||||
|
|
||||||
int shapeIndex = ci.m_instancingRenderer->registerShape(&cpu_buffer[0].pos[0],numVertices,indices,numIndices,B3_GL_TRIANGLES,textureIndex);
|
int shapeIndex = ci.m_instancingRenderer->registerShape(&cpu_buffer[0].pos[0],numVertices,indices,numIndices,B3_GL_TRIANGLES,textureIndex);
|
||||||
m_data->m_clothShapeIndex = shapeIndex;
|
m_data->m_clothShapeIndex = shapeIndex;
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
float pos[4] = {0,0,0,0};
|
float pos[4] = {0,0,0,0};
|
||||||
float orn[4] = {0,0,0,1};
|
float orn[4] = {0,0,0,1};
|
||||||
float color[4] = {1,1,1,1};
|
float color[4] = {1,1,1,1};
|
||||||
@@ -407,4 +457,7 @@ void GpuSoftClothDemo::setupScene(const ConstructionInfo& ci)
|
|||||||
ci.m_instancingRenderer->setCameraDistance(4);
|
ci.m_instancingRenderer->setCameraDistance(4);
|
||||||
ci.m_instancingRenderer->setCameraTargetPosition(pos);
|
ci.m_instancingRenderer->setCameraTargetPosition(pos);
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -567,10 +567,16 @@ void GLInstancingRenderer::writeSingleInstanceTransformToGPU(float* position, fl
|
|||||||
|
|
||||||
void GLInstancingRenderer::writeTransforms()
|
void GLInstancingRenderer::writeTransforms()
|
||||||
{
|
{
|
||||||
|
GLint err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
||||||
glFlush();
|
glFlush();
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
char* orgBase = (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_READ_WRITE);
|
char* orgBase = (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_READ_WRITE);
|
||||||
if (orgBase)
|
if (orgBase)
|
||||||
{
|
{
|
||||||
@@ -639,13 +645,16 @@ void GLInstancingRenderer::writeTransforms()
|
|||||||
{
|
{
|
||||||
b3Error("ERROR glMapBuffer failed\n");
|
b3Error("ERROR glMapBuffer failed\n");
|
||||||
}
|
}
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
glUnmapBuffer( GL_ARRAY_BUFFER);
|
glUnmapBuffer( GL_ARRAY_BUFFER);
|
||||||
//if this glFinish is removed, the animation is not always working/blocks
|
//if this glFinish is removed, the animation is not always working/blocks
|
||||||
//@todo: figure out why
|
//@todo: figure out why
|
||||||
glFlush();
|
glFlush();
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);//m_data->m_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);//m_data->m_vbo);
|
||||||
|
|
||||||
GLint err = glGetError();
|
err = glGetError();
|
||||||
assert(err==GL_NO_ERROR);
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -688,18 +697,30 @@ int GLInstancingRenderer::registerGraphicsInstance(int shapeIndex, const float*
|
|||||||
|
|
||||||
int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width, int height)
|
int GLInstancingRenderer::registerTexture(const unsigned char* texels, int width, int height)
|
||||||
{
|
{
|
||||||
|
GLint err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
int textureIndex = m_data->m_textureHandles.size();
|
int textureIndex = m_data->m_textureHandles.size();
|
||||||
const GLubyte* image= (const GLubyte*)texels;
|
const GLubyte* image= (const GLubyte*)texels;
|
||||||
GLuint textureHandle;
|
GLuint textureHandle;
|
||||||
glGenTextures(1,(GLuint*)&textureHandle);
|
glGenTextures(1,(GLuint*)&textureHandle);
|
||||||
glBindTexture(GL_TEXTURE_2D,textureHandle);
|
glBindTexture(GL_TEXTURE_2D,textureHandle);
|
||||||
GLenum err;
|
|
||||||
err = glGetError();
|
err = glGetError();
|
||||||
assert(err==GL_NO_ERROR);
|
assert(err==GL_NO_ERROR);
|
||||||
err = glGetError();
|
err = glGetError();
|
||||||
assert(err==GL_NO_ERROR);
|
assert(err==GL_NO_ERROR);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width,height,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width,height,0,GL_RGB,GL_UNSIGNED_BYTE,image);
|
||||||
|
|
||||||
|
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
err = glGetError();
|
||||||
|
assert(err==GL_NO_ERROR);
|
||||||
|
|
||||||
|
|
||||||
m_data->m_textureHandles.push_back(textureHandle);
|
m_data->m_textureHandles.push_back(textureHandle);
|
||||||
return textureIndex;
|
return textureIndex;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -669,8 +669,8 @@ cl_program b3OpenCLUtils_compileCLProgramFromString(cl_context clContext, cl_dev
|
|||||||
|
|
||||||
if (srcFileHandle==INVALID_HANDLE_VALUE)
|
if (srcFileHandle==INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
const char* prefix[]={"../","../../","../../../","../../../../"};
|
const char* prefix[]={"./","../","../../","../../../","../../../../"};
|
||||||
for (int i=0;(srcFileHandle==INVALID_HANDLE_VALUE) && i<3;i++)
|
for (int i=0;(srcFileHandle==INVALID_HANDLE_VALUE) && i<5;i++)
|
||||||
{
|
{
|
||||||
char relativeFileName[1024];
|
char relativeFileName[1024];
|
||||||
sprintf(relativeFileName,"%s%s",prefix[i],clFileNameForCaching);
|
sprintf(relativeFileName,"%s%s",prefix[i],clFileNameForCaching);
|
||||||
|
|||||||
@@ -904,10 +904,15 @@ void b3GpuNarrowPhase::writeAllBodiesToGpu()
|
|||||||
m_data->m_bodyBufferGPU->resize(m_data->m_numAcceleratedRigidBodies);
|
m_data->m_bodyBufferGPU->resize(m_data->m_numAcceleratedRigidBodies);
|
||||||
m_data->m_inertiaBufferGPU->resize(m_data->m_numAcceleratedRigidBodies);
|
m_data->m_inertiaBufferGPU->resize(m_data->m_numAcceleratedRigidBodies);
|
||||||
|
|
||||||
m_data->m_bodyBufferGPU->copyFromHostPointer(&m_data->m_bodyBufferCPU->at(0),m_data->m_numAcceleratedRigidBodies);
|
if (m_data->m_numAcceleratedRigidBodies)
|
||||||
m_data->m_inertiaBufferGPU->copyFromHostPointer(&m_data->m_inertiaBufferCPU->at(0),m_data->m_numAcceleratedRigidBodies);
|
{
|
||||||
|
m_data->m_bodyBufferGPU->copyFromHostPointer(&m_data->m_bodyBufferCPU->at(0),m_data->m_numAcceleratedRigidBodies);
|
||||||
m_data->m_collidablesGPU->copyFromHost(m_data->m_collidablesCPU);
|
m_data->m_inertiaBufferGPU->copyFromHostPointer(&m_data->m_inertiaBufferCPU->at(0),m_data->m_numAcceleratedRigidBodies);
|
||||||
|
}
|
||||||
|
if (m_data->m_collidablesCPU.size())
|
||||||
|
{
|
||||||
|
m_data->m_collidablesGPU->copyFromHost(m_data->m_collidablesCPU);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user