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