add re-usable createGraphicsSphere method in GpuDemo.
introduce and use maxContactCapacity (needs to be fixed in various other contact kernels) implement sphere versus trimesh disable new/sequential GPU batching (only uses 1 thread in a warp, slow but works on NVIDIA/Apple OpenCL)
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
#include "GpuDemoInternalData.h"
|
||||
#include "BulletCommon/btScalar.h"
|
||||
#include "basic_initialize/btOpenCLUtils.h"
|
||||
|
||||
#include "OpenGLWindow/ShapeData.h"
|
||||
#include "OpenGLWindow/GLInstancingRenderer.h"
|
||||
|
||||
GpuDemo::GpuDemo()
|
||||
:m_clData(0)
|
||||
@@ -78,3 +79,40 @@ void GpuDemo::initCL(int preferredDeviceIndex, int preferredPlatformIndex)
|
||||
}
|
||||
|
||||
|
||||
int GpuDemo::registerGraphicsSphereShape(const ConstructionInfo& ci, float radius, bool usePointSprites, int largeSphereThreshold, int mediumSphereThreshold)
|
||||
{
|
||||
|
||||
int strideInBytes = 9*sizeof(float);
|
||||
|
||||
int graphicsShapeIndex = -1;
|
||||
|
||||
if (radius>=largeSphereThreshold)
|
||||
{
|
||||
int numVertices = sizeof(detailed_sphere_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(detailed_sphere_indices)/sizeof(int);
|
||||
graphicsShapeIndex = ci.m_instancingRenderer->registerShape(&detailed_sphere_vertices[0],numVertices,detailed_sphere_indices,numIndices);
|
||||
} else
|
||||
{
|
||||
|
||||
if (usePointSprites)
|
||||
{
|
||||
int numVertices = sizeof(point_sphere_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(point_sphere_indices)/sizeof(int);
|
||||
graphicsShapeIndex = ci.m_instancingRenderer->registerShape(&point_sphere_vertices[0],numVertices,point_sphere_indices,numIndices,BT_GL_POINTS);
|
||||
} else
|
||||
{
|
||||
if (radius>=mediumSphereThreshold)
|
||||
{
|
||||
int numVertices = sizeof(medium_sphere_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(medium_sphere_indices)/sizeof(int);
|
||||
graphicsShapeIndex = ci.m_instancingRenderer->registerShape(&medium_sphere_vertices[0],numVertices,medium_sphere_indices,numIndices);
|
||||
} else
|
||||
{
|
||||
int numVertices = sizeof(low_sphere_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(low_sphere_indices)/sizeof(int);
|
||||
graphicsShapeIndex = ci.m_instancingRenderer->registerShape(&low_sphere_vertices[0],numVertices,low_sphere_indices,numIndices);
|
||||
}
|
||||
}
|
||||
}
|
||||
return graphicsShapeIndex;
|
||||
}
|
||||
@@ -38,9 +38,9 @@ public:
|
||||
:useOpenCL(true),
|
||||
preferredOpenCLPlatformIndex(-1),
|
||||
preferredOpenCLDeviceIndex(-1),
|
||||
arraySizeX(15),
|
||||
arraySizeY(15),
|
||||
arraySizeZ(15),
|
||||
arraySizeX(41),
|
||||
arraySizeY(41),
|
||||
arraySizeZ(41),
|
||||
m_useConcaveMesh(false),
|
||||
gapX(14.3),
|
||||
gapY(14.0),
|
||||
@@ -65,6 +65,7 @@ public:
|
||||
|
||||
virtual void clientMoveAndDisplay()=0;
|
||||
|
||||
int registerGraphicsSphereShape(const ConstructionInfo& ci, float radius, bool usePointSprites=true, int largeSphereThreshold=100, int mediumSphereThreshold=10);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -65,16 +65,16 @@ btAlignedObjectArray<const char*> demoNames;
|
||||
int selectedDemo = 0;
|
||||
GpuDemo::CreateFunc* allDemos[]=
|
||||
{
|
||||
|
||||
|
||||
GpuSphereScene::MyCreateFunc,
|
||||
GpuCompoundScene::MyCreateFunc,
|
||||
|
||||
|
||||
|
||||
GpuConvexScene::MyCreateFunc,
|
||||
ConcaveScene::MyCreateFunc,
|
||||
|
||||
ConcaveCompoundScene::MyCreateFunc,
|
||||
|
||||
GpuCompoundScene::MyCreateFunc,
|
||||
PairBench::MyCreateFunc,
|
||||
|
||||
|
||||
|
||||
@@ -154,17 +154,20 @@ GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj)
|
||||
}
|
||||
}
|
||||
|
||||
void ConcaveScene::setupScene(const ConstructionInfo& ci)
|
||||
|
||||
void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci)
|
||||
{
|
||||
objLoader* objData = new objLoader();
|
||||
//char* fileName = "data/slopedPlane100.obj";
|
||||
//char* fileName = "data/plane100.obj";
|
||||
|
||||
//char* fileName = "data/teddy.obj";//"plane.obj";
|
||||
// char* fileName = "data/sponza_closed.obj";//"plane.obj";
|
||||
//char* fileName = "data/leoTest1.obj";
|
||||
char* fileName = "data/samurai_monastry.obj";
|
||||
|
||||
btVector3 shift(0,0,0);//150,-100,-120);
|
||||
btVector4 scaling(10,10,10,1);//4,4,4,1);
|
||||
btVector3 shift(0,0,0);//0,230,80);//150,-100,-120);
|
||||
btVector4 scaling(4,4,4,1);
|
||||
FILE* f = 0;
|
||||
|
||||
char relativeFileName[1024];
|
||||
@@ -233,12 +236,33 @@ void ConcaveScene::setupScene(const ConstructionInfo& ci)
|
||||
index++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int strideInBytes = 9*sizeof(float);
|
||||
}
|
||||
|
||||
void ConcaveScene::setupScene(const ConstructionInfo& ci)
|
||||
{
|
||||
|
||||
createConcaveMesh(ci);
|
||||
|
||||
createDynamicObjects(ci);
|
||||
|
||||
float camPos[4]={0,0,0,0};//65.5,4.5,65.5,0};
|
||||
//float camPos[4]={1,12.5,1.5,0};
|
||||
m_instancingRenderer->setCameraPitch(45);
|
||||
m_instancingRenderer->setCameraTargetPosition(camPos);
|
||||
m_instancingRenderer->setCameraDistance(370);
|
||||
|
||||
}
|
||||
|
||||
void ConcaveScene::createDynamicObjects(const ConstructionInfo& ci)
|
||||
{
|
||||
int strideInBytes = 9*sizeof(float);
|
||||
int numVertices = sizeof(cube_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(cube_indices)/sizeof(int);
|
||||
//int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
@@ -247,7 +271,7 @@ void ConcaveScene::setupScene(const ConstructionInfo& ci)
|
||||
int mask=1;
|
||||
|
||||
|
||||
|
||||
int index=0;
|
||||
|
||||
|
||||
if (1)
|
||||
@@ -287,10 +311,63 @@ void ConcaveScene::setupScene(const ConstructionInfo& ci)
|
||||
}
|
||||
}
|
||||
}
|
||||
float camPos[4]={0,0,0,0};//65.5,4.5,65.5,0};
|
||||
|
||||
}
|
||||
|
||||
void ConcaveCompoundScene::setupScene(const ConstructionInfo& ci)
|
||||
{
|
||||
ConcaveScene::setupScene(ci);
|
||||
|
||||
float camPos[4]={0,50,0,0};//65.5,4.5,65.5,0};
|
||||
//float camPos[4]={1,12.5,1.5,0};
|
||||
m_instancingRenderer->setCameraPitch(45);
|
||||
m_instancingRenderer->setCameraTargetPosition(camPos);
|
||||
m_instancingRenderer->setCameraDistance(370);
|
||||
m_instancingRenderer->setCameraDistance(40);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ConcaveCompoundScene::createDynamicObjects(const ConstructionInfo& ci)
|
||||
{
|
||||
btVector4 colors[4] =
|
||||
{
|
||||
btVector4(1,0,0,1),
|
||||
btVector4(0,1,0,1),
|
||||
btVector4(0,1,1,1),
|
||||
btVector4(1,1,0,1),
|
||||
};
|
||||
|
||||
int index=0;
|
||||
int curColor = 0;
|
||||
float radius = 1;
|
||||
//int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
||||
int colIndex = m_data->m_np->registerSphereShape(radius);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
||||
int prevGraphicsShapeIndex = registerGraphicsSphereShape(ci,radius,false);
|
||||
|
||||
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 = 1.f;
|
||||
|
||||
|
||||
btVector3 position(-(ci.arraySizeX/2)*8+i*8,50+j*8,-(ci.arraySizeZ/2)*8+k*8);
|
||||
|
||||
//btVector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3);
|
||||
|
||||
btQuaternion orn(0,0,0,1);
|
||||
|
||||
btVector4 color = colors[curColor];
|
||||
curColor++;
|
||||
curColor&=3;
|
||||
btVector4 scaling(radius,radius,radius,1);
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(prevGraphicsShapeIndex,position,orn,color,scaling);
|
||||
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index);
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,34 @@ public:
|
||||
|
||||
virtual void setupScene(const ConstructionInfo& ci);
|
||||
|
||||
virtual void createDynamicObjects(const ConstructionInfo& ci);
|
||||
|
||||
virtual void createConcaveMesh(const ConstructionInfo& ci);
|
||||
|
||||
|
||||
};
|
||||
|
||||
class ConcaveCompoundScene : public ConcaveScene
|
||||
{
|
||||
public:
|
||||
|
||||
ConcaveCompoundScene(){}
|
||||
virtual ~ConcaveCompoundScene(){}
|
||||
virtual const char* getName()
|
||||
{
|
||||
return "GRBConcaveCompound";
|
||||
}
|
||||
|
||||
static GpuDemo* MyCreateFunc()
|
||||
{
|
||||
GpuDemo* demo = new ConcaveCompoundScene;
|
||||
return demo;
|
||||
}
|
||||
|
||||
virtual void setupScene(const ConstructionInfo& ci);
|
||||
|
||||
virtual void createDynamicObjects(const ConstructionInfo& ci);
|
||||
|
||||
};
|
||||
|
||||
#endif //CONCAVE_SCENE_H
|
||||
|
||||
@@ -35,7 +35,7 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
|
||||
|
||||
if (0)
|
||||
{
|
||||
float radius = 40;
|
||||
float radius = 60;
|
||||
int prevGraphicsShapeIndex = -1;
|
||||
{
|
||||
|
||||
@@ -86,7 +86,7 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
|
||||
float mass = 0.f;
|
||||
|
||||
//btVector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2);
|
||||
btVector3 position(0,-40,0);
|
||||
btVector3 position(0,0,0);
|
||||
|
||||
btQuaternion orn(0,0,0,1);
|
||||
|
||||
@@ -106,41 +106,7 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
|
||||
|
||||
|
||||
|
||||
{
|
||||
|
||||
|
||||
|
||||
int prevGraphicsShapeIndex = -1;
|
||||
float radius = 41;
|
||||
if (1)//radius>=100)
|
||||
{
|
||||
int numVertices = sizeof(detailed_sphere_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(detailed_sphere_indices)/sizeof(int);
|
||||
prevGraphicsShapeIndex = ci.m_instancingRenderer->registerShape(&detailed_sphere_vertices[0],numVertices,detailed_sphere_indices,numIndices);
|
||||
} else
|
||||
{
|
||||
bool usePointSprites = true;
|
||||
if (usePointSprites)
|
||||
{
|
||||
int numVertices = sizeof(point_sphere_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(point_sphere_indices)/sizeof(int);
|
||||
prevGraphicsShapeIndex = ci.m_instancingRenderer->registerShape(&point_sphere_vertices[0],numVertices,point_sphere_indices,numIndices,BT_GL_POINTS);
|
||||
} else
|
||||
{
|
||||
if (radius>=10)
|
||||
{
|
||||
int numVertices = sizeof(medium_sphere_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(medium_sphere_indices)/sizeof(int);
|
||||
prevGraphicsShapeIndex = ci.m_instancingRenderer->registerShape(&medium_sphere_vertices[0],numVertices,medium_sphere_indices,numIndices);
|
||||
} else
|
||||
{
|
||||
int numVertices = sizeof(low_sphere_vertices)/strideInBytes;
|
||||
int numIndices = sizeof(low_sphere_indices)/sizeof(int);
|
||||
prevGraphicsShapeIndex = ci.m_instancingRenderer->registerShape(&low_sphere_vertices[0],numVertices,low_sphere_indices,numIndices);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -160,35 +126,39 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
|
||||
|
||||
|
||||
|
||||
int curColor = 0;
|
||||
|
||||
//int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
||||
int colIndex = m_data->m_np->registerSphereShape(radius);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
||||
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 = 0.f;
|
||||
int curColor = 0;
|
||||
float radius = 61;
|
||||
//int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
||||
int colIndex = m_data->m_np->registerSphereShape(radius);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
||||
int prevGraphicsShapeIndex = registerGraphicsSphereShape(ci,radius,false);
|
||||
|
||||
btVector3 position((j&1)+i*142.2,-51+j*142.,(j&1)+k*142.2);
|
||||
//btVector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3);
|
||||
//for (int i=0;i<ci.arraySizeX;i++)
|
||||
{
|
||||
// for (int j=0;j<ci.arraySizeY;j++)
|
||||
{
|
||||
// for (int k=0;k<ci.arraySizeZ;k++)
|
||||
{
|
||||
int i=0,j=0,k=0;
|
||||
float mass = 0.f;
|
||||
|
||||
btVector3 position(0,0,0);
|
||||
//btVector3 position((j&1)+i*142.2,-51+j*142.,(j&1)+k*142.2);
|
||||
//btVector3 position(0,-41,0);//0,0,0);//i*radius*3,-41+j*radius*3,k*radius*3);
|
||||
|
||||
btQuaternion orn(0,0,0,1);
|
||||
btQuaternion orn(0,0,0,1);
|
||||
|
||||
btVector4 color = colors[curColor];
|
||||
curColor++;
|
||||
curColor&=3;
|
||||
btVector4 scaling(radius,radius,radius,1);
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(prevGraphicsShapeIndex,position,orn,color,scaling);
|
||||
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index);
|
||||
btVector4 color = colors[curColor];
|
||||
curColor++;
|
||||
curColor&=3;
|
||||
btVector4 scaling(radius,radius,radius,1);
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(prevGraphicsShapeIndex,position,orn,color,scaling);
|
||||
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(mass,position,orn,colIndex,index);
|
||||
|
||||
index++;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (1)
|
||||
{
|
||||
@@ -205,7 +175,7 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
|
||||
//int i=0;int j=0;
|
||||
{
|
||||
//int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
|
||||
btVector4 position(2*i,k*2,2*j+8,0);
|
||||
btVector4 position(2*i,70+k*2,2*j+8,0);
|
||||
//btQuaternion orn(0,0,0,1);
|
||||
btQuaternion orn(btVector3(1,0,0),0.3);
|
||||
|
||||
@@ -221,7 +191,7 @@ void GpuSphereScene::setupScene(const ConstructionInfo& ci)
|
||||
float camPos[4]={ci.arraySizeX,ci.arraySizeY/2,ci.arraySizeZ,0};
|
||||
//float camPos[4]={1,12.5,1.5,0};
|
||||
m_instancingRenderer->setCameraTargetPosition(camPos);
|
||||
m_instancingRenderer->setCameraDistance(30);
|
||||
m_instancingRenderer->setCameraDistance(130);
|
||||
|
||||
|
||||
char msg[1024];
|
||||
|
||||
Reference in New Issue
Block a user