Conflicts:
	btgui/OpenGLWindow/GLInstancingRenderer.cpp
This commit is contained in:
erwin coumans
2013-04-03 09:24:21 -07:00
36 changed files with 7151 additions and 332 deletions

View File

@@ -32,20 +32,22 @@ public:
float gapZ;
GLInstancingRenderer* m_instancingRenderer;
class btgWindowInterface* m_window;
class GwenUserInterface* m_gui;
ConstructionInfo()
:useOpenCL(true),
preferredOpenCLPlatformIndex(-1),
preferredOpenCLDeviceIndex(-1),
arraySizeX(10),
arraySizeY(20),
arraySizeZ(10),
arraySizeX(25),
arraySizeY(23),
arraySizeZ(23),
m_useConcaveMesh(false),
gapX(14.3),
gapY(14.0),
gapZ(14.3),
m_instancingRenderer(0),
m_window(0)
m_window(0),
m_gui(0)
{
}
};

View File

@@ -29,6 +29,7 @@
#include "rigidbody/ConcaveScene.h"
#include "rigidbody/GpuConvexScene.h"
#include "rigidbody/GpuCompoundScene.h"
#include "rigidbody/GpuSphereScene.h"
//#include "BroadphaseBenchmark.h"
@@ -64,25 +65,25 @@ btAlignedObjectArray<const char*> demoNames;
int selectedDemo = 0;
GpuDemo::CreateFunc* allDemos[]=
{
GpuSphereScene::MyCreateFunc,
GpuConvexScene::MyCreateFunc,
ConcaveScene::MyCreateFunc,
GpuConvexScene::MyCreateFunc,
GpuCompoundScene::MyCreateFunc,
PairBench::MyCreateFunc,
GpuRigidBodyDemo::MyCreateFunc,
//GpuRigidBodyDemo::MyCreateFunc,
//BroadphaseBenchmark::CreateFunc,
//GpuBoxDemo::CreateFunc,
PairBench::MyCreateFunc,
ParticleDemo::MyCreateFunc,
//ParticleDemo::MyCreateFunc,
//SpheresDemo::CreateFunc,
//GpuCompoundDemo::CreateFunc,
//EmptyDemo::CreateFunc,
};
@@ -381,7 +382,11 @@ int main(int argc, char* argv[])
args.GetCmdLineArgument("selected_demo",selectedDemo);
useNewBatchingKernel = args.CheckCmdLineFlag("new_batching");
if (args.CheckCmdLineFlag("new_batching"))
{
useNewBatchingKernel = true;
}
bool benchmark=args.CheckCmdLineFlag("benchmark");
dump_timings=args.CheckCmdLineFlag("dump_timings");
ci.useOpenCL = !args.CheckCmdLineFlag("disable_opencl");
@@ -563,6 +568,7 @@ int main(int argc, char* argv[])
ci.m_instancingRenderer = new GLInstancingRenderer(maxObjectCapacity);//render.getInstancingRenderer();
ci.m_window = window;
ci.m_gui = gui;
ci.m_instancingRenderer->init();
ci.m_instancingRenderer->InitShaders();
@@ -615,11 +621,6 @@ int main(int argc, char* argv[])
window->startRendering();
char msg[1024];
int numInstances = 0;//ci.m_instancingRenderer->getNumInstances();
sprintf(msg,"Num objects = %d",numInstances);
gui->setStatusBarMessage(msg,true);
glClearColor(0.6,0.6,0.6,1);
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);

View File

@@ -16,6 +16,8 @@
#include "gpu_rigidbody/host/btGpuNarrowPhase.h"
#include "gpu_rigidbody/host/btConfig.h"
#include "GpuRigidBodyDemoInternalData.h"
#include "../gwenUserInterface.h"
void GpuConvexScene::setupScene(const ConstructionInfo& ci)
{
@@ -85,5 +87,10 @@ void GpuConvexScene::setupScene(const ConstructionInfo& ci)
//float camPos[4]={1,12.5,1.5,0};
m_instancingRenderer->setCameraTargetPosition(camPos);
m_instancingRenderer->setCameraDistance(120);
char msg[1024];
int numInstances = index;
sprintf(msg,"Num objects = %d",numInstances);
ci.m_gui->setStatusBarMessage(msg,true);
}

View File

@@ -0,0 +1,151 @@
#include "GpuSphereScene.h"
#include "GpuRigidBodyDemo.h"
#include "BulletCommon/btQuickprof.h"
#include "OpenGLWindow/ShapeData.h"
#include "OpenGLWindow/GLInstancingRenderer.h"
#include "BulletCommon/btQuaternion.h"
#include "OpenGLWindow/btgWindowInterface.h"
#include "gpu_broadphase/host/btGpuSapBroadphase.h"
#include "../GpuDemoInternalData.h"
#include "basic_initialize/btOpenCLUtils.h"
#include "OpenGLWindow/OpenGLInclude.h"
#include "OpenGLWindow/GLInstanceRendererInternalData.h"
#include "parallel_primitives/host/btLauncherCL.h"
#include "gpu_rigidbody/host/btGpuRigidBodyPipeline.h"
#include "gpu_rigidbody/host/btGpuNarrowPhase.h"
#include "gpu_rigidbody/host/btConfig.h"
#include "GpuRigidBodyDemoInternalData.h"
#include "../gwenUserInterface.h"
void GpuSphereScene::setupScene(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);
int group=1;
int mask=1;
int index=0;
if (1)
{
int shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
btVector4 scaling(120,2,120,1);
int colIndex = m_data->m_np->registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector3 normal(0,-1,0);
float constant=2;
//int colIndex = m_data->m_np->registerPlaneShape(normal,constant);//>registerConvexHullShape(&cube_vertices[0],strideInBytes,numVertices, scaling);
btVector4 position(0,50,0,0);
//btQuaternion orn(0,0,0,1);
btQuaternion orn(btVector3(1,0,0),0.3);
btVector4 color(0,0,1,1);
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
int pid = m_data->m_rigidBodyPipeline->registerPhysicsInstance(0.f,position,orn,colIndex,index);
index++;
}
{
int prevGraphicsShapeIndex = -1;
float radius = 1;
if (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);
}
}
}
btVector4 colors[4] =
{
btVector4(1,0,0,1),
btVector4(0,1,0,1),
btVector4(0,1,1,1),
btVector4(1,1,0,1),
};
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 = 1.f;
//btVector3 position((j&1)+i*2.2,1+j*2.,(j&1)+k*2.2);
btVector3 position(i*radius*3,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++;
}
}
}
}
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(150);
char msg[1024];
int numInstances = index;
sprintf(msg,"Num objects = %d",numInstances);
ci.m_gui->setStatusBarMessage(msg,true);
}

View File

@@ -0,0 +1,27 @@
#ifndef GPU_SPHERE_SCENE_H
#define GPU_SPHERE_SCENE_H
#include "GpuRigidBodyDemo.h"
class GpuSphereScene : public GpuRigidBodyDemo
{
public:
GpuSphereScene(){}
virtual ~GpuSphereScene(){}
virtual const char* getName()
{
return "GRBSphere";
}
static GpuDemo* MyCreateFunc()
{
GpuDemo* demo = new GpuSphereScene;
return demo;
}
virtual void setupScene(const ConstructionInfo& ci);
};
#endif //GPU_SPHERE_SCENE_H