fixed many memory leaks
added working shadows, using basic shadow mapping
This commit is contained in:
@@ -53,7 +53,24 @@ GwenUserInterface::GwenUserInterface()
|
||||
|
||||
GwenUserInterface::~GwenUserInterface()
|
||||
{
|
||||
for (int i=0;i<m_data->m_handlers.size();i++)
|
||||
{
|
||||
delete m_data->m_handlers[i];
|
||||
}
|
||||
|
||||
m_data->m_handlers.clear();
|
||||
|
||||
|
||||
delete m_data->pCanvas;
|
||||
|
||||
GLPrimitiveRenderer* prim = m_data->m_primRenderer;
|
||||
GwenOpenGL3CoreRenderer* coreRend = m_data->pRenderer;
|
||||
|
||||
delete m_data;
|
||||
|
||||
delete prim;
|
||||
delete coreRend;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ GpuDemo::CreateFunc* allDemos[]=
|
||||
|
||||
// ConcaveSphereScene::MyCreateFunc,
|
||||
|
||||
// ShadowMapDemo::MyCreateFunc,
|
||||
|
||||
|
||||
GpuBoxPlaneScene::MyCreateFunc,
|
||||
GpuConvexPlaneScene::MyCreateFunc,
|
||||
@@ -119,6 +119,9 @@ GpuDemo::CreateFunc* allDemos[]=
|
||||
PairBench::MyCreateFunc,
|
||||
|
||||
GpuRaytraceScene::MyCreateFunc,
|
||||
|
||||
ShadowMapDemo::MyCreateFunc,
|
||||
|
||||
//GpuRigidBodyDemo::MyCreateFunc,
|
||||
|
||||
//BroadphaseBenchmark::CreateFunc,
|
||||
@@ -222,7 +225,16 @@ bool enableExperimentalCpuConcaveCollision=false;
|
||||
int droidRegular=0;//, droidItalic, droidBold, droidJapanese, dejavu;
|
||||
|
||||
sth_stash* stash=0;
|
||||
OpenGL2RenderCallbacks* renderCallbacks = 0;
|
||||
|
||||
void exitFont()
|
||||
{
|
||||
sth_delete(stash);
|
||||
stash=0;
|
||||
|
||||
delete renderCallbacks;
|
||||
renderCallbacks=0;
|
||||
}
|
||||
sth_stash* initFont(GLPrimitiveRenderer* primRender)
|
||||
{
|
||||
GLint err;
|
||||
@@ -233,7 +245,7 @@ sth_stash* initFont(GLPrimitiveRenderer* primRender)
|
||||
float sx,sy,dx,dy,lh;
|
||||
GLuint texture;
|
||||
|
||||
OpenGL2RenderCallbacks* renderCallbacks = new OpenGL2RenderCallbacks(primRender);
|
||||
renderCallbacks = new OpenGL2RenderCallbacks(primRender);
|
||||
|
||||
stash = sth_create(512,512,renderCallbacks);//256,256);//,1024);//512,512);
|
||||
err = glGetError();
|
||||
@@ -569,33 +581,31 @@ int main(int argc, char* argv[])
|
||||
stash = initFont(&prim);
|
||||
|
||||
|
||||
gui->init(g_OpenGLWidth,g_OpenGLHeight,stash,window->getRetinaScale());
|
||||
|
||||
printf("init fonts");
|
||||
|
||||
|
||||
gui->setToggleButtonCallback(MyButtonCallback);
|
||||
|
||||
gui->registerToggleButton(MYPAUSE,"Pause");
|
||||
gui->registerToggleButton(MYPROFILE,"Profile");
|
||||
gui->registerToggleButton(MYRESET,"Reset");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int numItems = sizeof(allDemos)/sizeof(ParticleDemo::CreateFunc*);
|
||||
demoNames.clear();
|
||||
for (int i=0;i<numItems;i++)
|
||||
if (gui)
|
||||
{
|
||||
GpuDemo* demo = allDemos[i]();
|
||||
demoNames.push_back(demo->getName());
|
||||
delete demo;
|
||||
}
|
||||
gui->init(g_OpenGLWidth,g_OpenGLHeight,stash,window->getRetinaScale());
|
||||
|
||||
gui->registerComboBox(MYCOMBOBOX1,numItems,&demoNames[0]);
|
||||
gui->setComboBoxCallback(MyComboBoxCallback);
|
||||
printf("init fonts");
|
||||
|
||||
|
||||
gui->setToggleButtonCallback(MyButtonCallback);
|
||||
|
||||
gui->registerToggleButton(MYPAUSE,"Pause");
|
||||
gui->registerToggleButton(MYPROFILE,"Profile");
|
||||
gui->registerToggleButton(MYRESET,"Reset");
|
||||
|
||||
int numItems = sizeof(allDemos)/sizeof(ParticleDemo::CreateFunc*);
|
||||
demoNames.clear();
|
||||
for (int i=0;i<numItems;i++)
|
||||
{
|
||||
GpuDemo* demo = allDemos[i]();
|
||||
demoNames.push_back(demo->getName());
|
||||
delete demo;
|
||||
}
|
||||
|
||||
gui->registerComboBox(MYCOMBOBOX1,numItems,&demoNames[0]);
|
||||
gui->setComboBoxCallback(MyComboBoxCallback);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -610,72 +620,9 @@ int main(int argc, char* argv[])
|
||||
static bool once=true;
|
||||
|
||||
|
||||
|
||||
|
||||
glClearColor(1,0,0,1);
|
||||
glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
{
|
||||
|
||||
window->startRendering();
|
||||
glFinish();
|
||||
|
||||
|
||||
|
||||
|
||||
float color[4] = {1,1,1,1};
|
||||
prim.drawRect(0,0,200,200,color);
|
||||
float retinaScale = 1;
|
||||
|
||||
float x = 10;
|
||||
float y=220;
|
||||
float dx=0;
|
||||
if (1)
|
||||
{
|
||||
B3_PROFILE("font sth_draw_text");
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
GLint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
sth_begin_draw(stash);
|
||||
sth_flush_draw(stash);
|
||||
sth_draw_text(stash, droidRegular,20.f, x, y, "Non-retina font rendering !@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,1);//retinaScale);
|
||||
if (retinaScale!=1.f)
|
||||
sth_draw_text(stash, droidRegular,20.f*retinaScale, x, y+20, "Retina font rendering!@#$", &dx,g_OpenGLWidth,g_OpenGLHeight,0,retinaScale);
|
||||
sth_flush_draw(stash);
|
||||
|
||||
sth_end_draw(stash);
|
||||
}
|
||||
|
||||
gui->draw(g_OpenGLWidth,g_OpenGLHeight);
|
||||
window->endRendering();
|
||||
glFinish();
|
||||
}
|
||||
once=false;
|
||||
|
||||
// OpenGL3CoreRenderer render;
|
||||
|
||||
glClearColor(0,1,0,1);
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
window->endRendering();
|
||||
|
||||
glFinish();
|
||||
|
||||
|
||||
|
||||
window->setWheelCallback(b3DefaultWheelCallback);
|
||||
|
||||
|
||||
@@ -690,7 +637,7 @@ int main(int argc, char* argv[])
|
||||
int maxObjectCapacity=128*1024;
|
||||
maxObjectCapacity = b3Max(maxObjectCapacity,ci.arraySizeX*ci.arraySizeX*ci.arraySizeX+10);
|
||||
|
||||
|
||||
{
|
||||
ci.m_instancingRenderer = new GLInstancingRenderer(maxObjectCapacity);//render.getInstancingRenderer();
|
||||
ci.m_window = window;
|
||||
ci.m_gui = gui;
|
||||
@@ -699,8 +646,11 @@ int main(int argc, char* argv[])
|
||||
ci.m_instancingRenderer->InitShaders();
|
||||
ci.m_primRenderer = &prim;
|
||||
// render.init();
|
||||
}
|
||||
|
||||
demo->initPhysics(ci);
|
||||
{
|
||||
demo->initPhysics(ci);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -793,7 +743,8 @@ int main(int argc, char* argv[])
|
||||
}
|
||||
do
|
||||
{
|
||||
|
||||
|
||||
|
||||
GLint err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
@@ -844,7 +795,6 @@ int main(int argc, char* argv[])
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
|
||||
glClearColor(0,0,0,0);
|
||||
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);//|GL_STENCIL_BUFFER_BIT);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
@@ -896,7 +846,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
{
|
||||
B3_PROFILE("gui->draw");
|
||||
gui->draw(g_OpenGLWidth,g_OpenGLHeight);
|
||||
if (gui)
|
||||
gui->draw(g_OpenGLWidth,g_OpenGLHeight);
|
||||
}
|
||||
err = glGetError();
|
||||
assert(err==GL_NO_ERROR);
|
||||
@@ -948,6 +899,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
demo->exitPhysics();
|
||||
b3ProfileManager::CleanupMemory();
|
||||
delete ci.m_instancingRenderer;
|
||||
|
||||
delete demo;
|
||||
if (detailsFile)
|
||||
{
|
||||
@@ -966,13 +919,24 @@ int main(int argc, char* argv[])
|
||||
} while (gReset);
|
||||
|
||||
|
||||
gui->setComboBoxCallback(0);
|
||||
delete gui;
|
||||
gui=0;
|
||||
if (gui)
|
||||
gui->setComboBoxCallback(0);
|
||||
|
||||
window->closeWindow();
|
||||
delete window;
|
||||
window = 0;
|
||||
{
|
||||
|
||||
|
||||
|
||||
delete gui;
|
||||
gui=0;
|
||||
|
||||
exitFont();
|
||||
|
||||
|
||||
window->closeWindow();
|
||||
delete window;
|
||||
window = 0;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ GpuRaytraceScene::~GpuRaytraceScene()
|
||||
glDeleteTextures(1,m_raytraceData->m_texId);
|
||||
delete[] m_raytraceData->m_texels;
|
||||
delete m_raytraceData->m_renderToTexture;
|
||||
delete m_raytraceData->m_texId;
|
||||
delete m_raytraceData;
|
||||
}
|
||||
|
||||
|
||||
@@ -232,7 +232,9 @@ void ConcaveScene::createConcaveMesh(const ConstructionInfo& ci, const char* fil
|
||||
|
||||
|
||||
|
||||
|
||||
delete shape->m_indices;
|
||||
delete shape->m_vertices;
|
||||
delete shape;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,8 @@ void GpuConvexScene::setupScene(const ConstructionInfo& ci)
|
||||
char msg[1024];
|
||||
int numInstances = index;
|
||||
sprintf(msg,"Num objects = %d",numInstances);
|
||||
ci.m_gui->setStatusBarMessage(msg,true);
|
||||
if (ci.m_gui)
|
||||
ci.m_gui->setStatusBarMessage(msg,true);
|
||||
}
|
||||
|
||||
void GpuConvexScene::destroyScene()
|
||||
@@ -168,6 +169,7 @@ int GpuConvexScene::createDynamicsObjects2(const ConstructionInfo& ci, const flo
|
||||
}
|
||||
}
|
||||
}
|
||||
delete utilPtr;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
@@ -117,9 +117,9 @@ void GpuRigidBodyDemo::initPhysics(const ConstructionInfo& ci)
|
||||
b3GpuSapBroadphase* bp = new b3GpuSapBroadphase(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue);
|
||||
m_data->m_np = np;
|
||||
m_data->m_bp = bp;
|
||||
b3DynamicBvhBroadphase* broadphaseDbvt = new b3DynamicBvhBroadphase(config.m_maxConvexBodies);
|
||||
m_data->m_broadphaseDbvt = new b3DynamicBvhBroadphase(config.m_maxConvexBodies);
|
||||
|
||||
m_data->m_rigidBodyPipeline = new b3GpuRigidBodyPipeline(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue, np, bp,broadphaseDbvt,config);
|
||||
m_data->m_rigidBodyPipeline = new b3GpuRigidBodyPipeline(m_clData->m_clContext,m_clData->m_clDevice,m_clData->m_clQueue, np, bp,m_data->m_broadphaseDbvt,config);
|
||||
|
||||
|
||||
setupScene(ci);
|
||||
@@ -139,8 +139,11 @@ void GpuRigidBodyDemo::initPhysics(const ConstructionInfo& ci)
|
||||
|
||||
void GpuRigidBodyDemo::exitPhysics()
|
||||
{
|
||||
destroyScene();
|
||||
|
||||
delete m_data->m_instancePosOrnColor;
|
||||
delete m_data->m_rigidBodyPipeline;
|
||||
delete m_data->m_broadphaseDbvt;
|
||||
|
||||
m_window->setKeyboardCallback(oldCallback);
|
||||
|
||||
|
||||
@@ -16,12 +16,14 @@ struct GpuRigidBodyDemoInternalData
|
||||
|
||||
class b3GpuNarrowPhase* m_np;
|
||||
class b3GpuSapBroadphase* m_bp;
|
||||
class b3DynamicBvhBroadphase* m_broadphaseDbvt;
|
||||
|
||||
GpuRigidBodyDemoInternalData()
|
||||
:m_instancePosOrnColor(0),
|
||||
m_copyTransformsToVBOKernel(0), m_rigidBodyPipeline(0),
|
||||
m_np(0),
|
||||
m_bp(0)
|
||||
m_bp(0),
|
||||
m_broadphaseDbvt(0)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
#include "ShadowMapDemo.h"
|
||||
#include "ShadowMapDemoInternalData.h"
|
||||
#include "OpenGLWindow/GLInstancingRenderer.h"
|
||||
#include "OpenglWindow/GLPrimitiveRenderer.h"
|
||||
|
||||
#include "OpenGLWindow/ShapeData.h"
|
||||
#include "Bullet3Common/b3Quaternion.h"
|
||||
#include <stdio.h>
|
||||
|
||||
ShadowMapDemo::ShadowMapDemo()
|
||||
{
|
||||
@@ -17,32 +21,52 @@ ShadowMapDemo::~ShadowMapDemo()
|
||||
void ShadowMapDemo::initPhysics(const ConstructionInfo& ci)
|
||||
{
|
||||
m_shadowData->m_instancingRenderer = ci.m_instancingRenderer;
|
||||
m_shadowData->m_primitiveRenderer = ci.m_primRenderer;
|
||||
|
||||
int sphereShape = registerGraphicsSphereShape(ci,0.1,false);
|
||||
float pos[4]={0,3,0,0};
|
||||
float orn[4]={0,0,0,1};
|
||||
float color[4]={1,0,0,1};
|
||||
float scaling[4]={1,1,1,1};
|
||||
if (1)
|
||||
{
|
||||
///create a sphere
|
||||
int sphereShape = registerGraphicsSphereShape(ci,0.1,false);
|
||||
ci.m_instancingRenderer->registerGraphicsInstance(sphereShape,pos,orn,color,scaling);
|
||||
}
|
||||
if (1)
|
||||
{
|
||||
//create a cube
|
||||
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 boxShape = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
pos[1]=0.f;
|
||||
scaling[0]=scaling[2]=50.f;
|
||||
color[0]=1.f;
|
||||
color[1]=1.f;
|
||||
color[2]=1.f;
|
||||
color[3]=1.f;
|
||||
ci.m_instancingRenderer->registerGraphicsInstance(boxShape ,pos,orn,color,scaling);
|
||||
}
|
||||
|
||||
ci.m_instancingRenderer->registerGraphicsInstance(sphereShape,pos,orn,color,scaling);
|
||||
|
||||
b3Vector3 shift(0,0,0);
|
||||
if (0)
|
||||
{
|
||||
b3Vector3 scaling(1,1,1);
|
||||
const char* filename="data/room_thickwalls.obj";
|
||||
this->createConcaveMesh(ci,filename,shift,scaling);
|
||||
}
|
||||
|
||||
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 boxShape = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
pos[1]=0.f;
|
||||
scaling[0]=scaling[2]=10.f;
|
||||
color[0]=1.f;
|
||||
color[1]=1.f;
|
||||
color[2]=1.f;
|
||||
color[3]=1.f;
|
||||
ci.m_instancingRenderer->registerGraphicsInstance(boxShape ,pos,orn,color,scaling);
|
||||
{
|
||||
b3Vector3 camPos(0, 2,5);
|
||||
m_shadowData->m_instancingRenderer->setCameraTargetPosition(camPos);
|
||||
m_shadowData->m_instancingRenderer->setCameraPitch(0);
|
||||
m_shadowData->m_instancingRenderer->setCameraYaw(0);
|
||||
|
||||
|
||||
m_shadowData->m_instancingRenderer->setCameraTargetPosition(pos);
|
||||
m_shadowData->m_instancingRenderer->setCameraDistance(15);
|
||||
m_shadowData->m_instancingRenderer->setCameraDistance(15);
|
||||
}
|
||||
//m_shadowData->m_instancingRenderer->setCameraYaw(55);
|
||||
ci.m_instancingRenderer->writeTransforms();
|
||||
}
|
||||
|
||||
@@ -50,13 +74,233 @@ void ShadowMapDemo::exitPhysics()
|
||||
{
|
||||
}
|
||||
|
||||
void ShadowMapDemo::renderScene()
|
||||
{
|
||||
m_shadowData->m_instancingRenderer->renderScene(B3_CREATE_SHADOWMAP_RENDERMODE);
|
||||
//m_shadowData->m_instancingRenderer->renderScene();
|
||||
m_shadowData->m_instancingRenderer->renderScene(B3_USE_SHADOWMAP_RENDERMODE);
|
||||
}
|
||||
|
||||
void ShadowMapDemo::clientMoveAndDisplay()
|
||||
{
|
||||
}
|
||||
|
||||
#include"../../Wavefront/objLoader.h"
|
||||
#include "OpenGLWindow/GLInstanceGraphicsShape.h"
|
||||
|
||||
static GLInstanceGraphicsShape* createGraphicsShapeFromWavefrontObj(objLoader* obj)
|
||||
{
|
||||
b3AlignedObjectArray<GLInstanceVertex>* vertices = new b3AlignedObjectArray<GLInstanceVertex>;
|
||||
{
|
||||
// int numVertices = obj->vertexCount;
|
||||
// int numIndices = 0;
|
||||
b3AlignedObjectArray<int>* indicesPtr = new b3AlignedObjectArray<int>;
|
||||
/*
|
||||
for (int v=0;v<obj->vertexCount;v++)
|
||||
{
|
||||
vtx.xyzw[0] = obj->vertexList[v]->e[0];
|
||||
vtx.xyzw[1] = obj->vertexList[v]->e[1];
|
||||
vtx.xyzw[2] = obj->vertexList[v]->e[2];
|
||||
b3Vector3 n(vtx.xyzw[0],vtx.xyzw[1],vtx.xyzw[2]);
|
||||
if (n.length2()>B3_EPSILON)
|
||||
{
|
||||
n.normalize();
|
||||
vtx.normal[0] = n[0];
|
||||
vtx.normal[1] = n[1];
|
||||
vtx.normal[2] = n[2];
|
||||
|
||||
} else
|
||||
{
|
||||
vtx.normal[0] = 0; //todo
|
||||
vtx.normal[1] = 1;
|
||||
vtx.normal[2] = 0;
|
||||
}
|
||||
vtx.uv[0] = 0.5f;vtx.uv[1] = 0.5f; //todo
|
||||
vertices->push_back(vtx);
|
||||
}
|
||||
*/
|
||||
|
||||
for (int f=0;f<obj->faceCount;f++)
|
||||
{
|
||||
obj_face* face = obj->faceList[f];
|
||||
//b3Vector3 normal(face.m_plane[0],face.m_plane[1],face.m_plane[2]);
|
||||
if (face->vertex_count>=3)
|
||||
{
|
||||
b3Vector3 normal(0,1,0);
|
||||
int vtxBaseIndex = vertices->size();
|
||||
|
||||
if (face->vertex_count<=4)
|
||||
{
|
||||
indicesPtr->push_back(vtxBaseIndex);
|
||||
indicesPtr->push_back(vtxBaseIndex+1);
|
||||
indicesPtr->push_back(vtxBaseIndex+2);
|
||||
|
||||
GLInstanceVertex vtx0;
|
||||
vtx0.xyzw[0] = obj->vertexList[face->vertex_index[0]]->e[0];
|
||||
vtx0.xyzw[1] = obj->vertexList[face->vertex_index[0]]->e[1];
|
||||
vtx0.xyzw[2] = obj->vertexList[face->vertex_index[0]]->e[2];
|
||||
vtx0.xyzw[3] = 0.f;//obj->vertexList[face->vertex_index[0]]->e[2];
|
||||
|
||||
vtx0.uv[0] = 0.5f;//obj->textureList[face->vertex_index[0]]->e[0];
|
||||
vtx0.uv[1] = 0.5f;//obj->textureList[face->vertex_index[0]]->e[1];
|
||||
|
||||
GLInstanceVertex vtx1;
|
||||
vtx1.xyzw[0] = obj->vertexList[face->vertex_index[1]]->e[0];
|
||||
vtx1.xyzw[1] = obj->vertexList[face->vertex_index[1]]->e[1];
|
||||
vtx1.xyzw[2] = obj->vertexList[face->vertex_index[1]]->e[2];
|
||||
vtx1.xyzw[3]= 0.f;
|
||||
vtx1.uv[0] = 0.5f;//obj->textureList[face->vertex_index[1]]->e[0];
|
||||
vtx1.uv[1] = 0.5f;//obj->textureList[face->vertex_index[1]]->e[1];
|
||||
|
||||
GLInstanceVertex vtx2;
|
||||
vtx2.xyzw[0] = obj->vertexList[face->vertex_index[2]]->e[0];
|
||||
vtx2.xyzw[1] = obj->vertexList[face->vertex_index[2]]->e[1];
|
||||
vtx2.xyzw[2] = obj->vertexList[face->vertex_index[2]]->e[2];
|
||||
vtx2.xyzw[3] = 0.f;
|
||||
vtx2.uv[0] = 0.5f;obj->textureList[face->vertex_index[2]]->e[0];
|
||||
vtx2.uv[1] = 0.5f;obj->textureList[face->vertex_index[2]]->e[1];
|
||||
|
||||
|
||||
b3Vector3 v0(vtx0.xyzw[0],vtx0.xyzw[1],vtx0.xyzw[2]);
|
||||
b3Vector3 v1(vtx1.xyzw[0],vtx1.xyzw[1],vtx1.xyzw[2]);
|
||||
b3Vector3 v2(vtx2.xyzw[0],vtx2.xyzw[1],vtx2.xyzw[2]);
|
||||
|
||||
normal = (v1-v0).cross(v2-v0);
|
||||
normal.normalize();
|
||||
vtx0.normal[0] = normal[0];
|
||||
vtx0.normal[1] = normal[1];
|
||||
vtx0.normal[2] = normal[2];
|
||||
vtx1.normal[0] = normal[0];
|
||||
vtx1.normal[1] = normal[1];
|
||||
vtx1.normal[2] = normal[2];
|
||||
vtx2.normal[0] = normal[0];
|
||||
vtx2.normal[1] = normal[1];
|
||||
vtx2.normal[2] = normal[2];
|
||||
vertices->push_back(vtx0);
|
||||
vertices->push_back(vtx1);
|
||||
vertices->push_back(vtx2);
|
||||
}
|
||||
if (face->vertex_count==4)
|
||||
{
|
||||
|
||||
indicesPtr->push_back(vtxBaseIndex);
|
||||
indicesPtr->push_back(vtxBaseIndex+1);
|
||||
indicesPtr->push_back(vtxBaseIndex+2);
|
||||
indicesPtr->push_back(vtxBaseIndex+3);
|
||||
//
|
||||
GLInstanceVertex vtx3;
|
||||
vtx3.xyzw[0] = obj->vertexList[face->vertex_index[3]]->e[0];
|
||||
vtx3.xyzw[1] = obj->vertexList[face->vertex_index[3]]->e[1];
|
||||
vtx3.xyzw[2] = obj->vertexList[face->vertex_index[3]]->e[2];
|
||||
vtx3.uv[0] = 0.5;
|
||||
vtx3.uv[1] = 0.5;
|
||||
|
||||
vtx3.normal[0] = normal[0];
|
||||
vtx3.normal[1] = normal[1];
|
||||
vtx3.normal[2] = normal[2];
|
||||
|
||||
vertices->push_back(vtx3);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
GLInstanceGraphicsShape* gfxShape = new GLInstanceGraphicsShape;
|
||||
gfxShape->m_vertices = vertices;
|
||||
gfxShape->m_numvertices = vertices->size();
|
||||
gfxShape->m_indices = indicesPtr;
|
||||
gfxShape->m_numIndices = indicesPtr->size();
|
||||
for (int i=0;i<4;i++)
|
||||
gfxShape->m_scaling[i] = 1;//bake the scaling into the vertices
|
||||
return gfxShape;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ShadowMapDemo::createConcaveMesh(const ConstructionInfo& ci, const char* fileName, const b3Vector3& shift, const b3Vector3& scaling)
|
||||
{
|
||||
objLoader* objData = new objLoader();
|
||||
|
||||
FILE* f = 0;
|
||||
|
||||
char relativeFileName[1024];
|
||||
{
|
||||
const char* prefix[]={"./","../","../../","../../../","../../../../"};
|
||||
int numPrefixes = sizeof(prefix)/sizeof(char*);
|
||||
|
||||
for (int i=0;i<numPrefixes;i++)
|
||||
{
|
||||
|
||||
sprintf(relativeFileName,"%s%s",prefix[i],fileName);
|
||||
f = fopen(relativeFileName,"r");
|
||||
if (f)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (f)
|
||||
{
|
||||
fclose(f);
|
||||
f=0;
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
objData->load(relativeFileName);
|
||||
int index=10;
|
||||
|
||||
{
|
||||
GLInstanceGraphicsShape* shape = createGraphicsShapeFromWavefrontObj(objData);
|
||||
|
||||
|
||||
b3AlignedObjectArray<b3Vector3> verts;
|
||||
for (int i=0;i<shape->m_numvertices;i++)
|
||||
{
|
||||
for (int j=0;j<3;j++)
|
||||
shape->m_vertices->at(i).xyzw[j] += shift[j];
|
||||
|
||||
b3Vector3 vtx(shape->m_vertices->at(i).xyzw[0],
|
||||
shape->m_vertices->at(i).xyzw[1],
|
||||
shape->m_vertices->at(i).xyzw[2]);
|
||||
verts.push_back(vtx*scaling);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
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 shapeId = ci.m_instancingRenderer->registerShape(&cube_vertices[0],numVertices,cube_indices,numIndices);
|
||||
|
||||
|
||||
int shapeId = ci.m_instancingRenderer->registerShape(&shape->m_vertices->at(0).xyzw[0], shape->m_numvertices, &shape->m_indices->at(0), shape->m_numIndices);
|
||||
b3Quaternion orn(0,0,0,1);
|
||||
|
||||
b3Vector4 color(0.3,0.3,1,1.f);//0.5);//1.f
|
||||
|
||||
|
||||
{
|
||||
float mass = 0.f;
|
||||
b3Vector3 position(0,0,0);
|
||||
int id = ci.m_instancingRenderer->registerGraphicsInstance(shapeId,position,orn,color,scaling);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
delete objData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ShadowMapDemo::renderScene()
|
||||
{
|
||||
float color[4]={1,1,1,1};
|
||||
m_shadowData->m_instancingRenderer->renderScene();
|
||||
|
||||
m_shadowData->m_instancingRenderer->enableShadowMap();
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE );
|
||||
// glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE );
|
||||
m_shadowData->m_primitiveRenderer->drawTexturedRect(10,10,90,90,color,0,0,1,1,true);
|
||||
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define SHADOW_MAP_DEMO_H
|
||||
|
||||
#include "../GpuDemo.h"
|
||||
#include "Bullet3Common/b3Vector3.h"
|
||||
|
||||
class ShadowMapDemo : public GpuDemo
|
||||
{
|
||||
@@ -23,6 +24,9 @@ public:
|
||||
|
||||
virtual void renderScene();
|
||||
|
||||
void createConcaveMesh(const ConstructionInfo& ci, const char* fileName, const b3Vector3& shift, const b3Vector3& scaling);
|
||||
|
||||
|
||||
virtual void clientMoveAndDisplay();
|
||||
|
||||
static GpuDemo* MyCreateFunc()
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
struct ShadowMapDemoInternalData
|
||||
{
|
||||
class GLInstancingRenderer* m_instancingRenderer;
|
||||
class GLPrimitiveRenderer* m_primitiveRenderer;
|
||||
|
||||
};
|
||||
|
||||
#endif //SHADOW_MAP_INTERNAL_DATA_H
|
||||
|
||||
Reference in New Issue
Block a user