Physics runs in a separate thread from rendering in PhysicsServerExample (preliminary)
Improve rendering performance. OpenVR experience is smooth now. commit needs a bit more testing before pushing in main repo.
This commit is contained in:
@@ -28,7 +28,7 @@ int gSharedMemoryKey = -1;
|
||||
#include "pathtools.h"
|
||||
|
||||
CommonExampleInterface* sExample;
|
||||
OpenGLGuiHelper* sGuiPtr = 0;
|
||||
GUIHelperInterface* sGuiPtr = 0;
|
||||
|
||||
|
||||
#if defined(POSIX)
|
||||
@@ -375,7 +375,9 @@ bool CMainApplication::BInit()
|
||||
*/
|
||||
m_app = new SimpleOpenGL3App("SimpleOpenGL3App",m_nWindowWidth,m_nWindowHeight,true);
|
||||
|
||||
|
||||
sGuiPtr = new OpenGLGuiHelper(m_app,false);
|
||||
//sGuiPtr = new DummyGUIHelper;
|
||||
|
||||
|
||||
CommonExampleOptions options(sGuiPtr);
|
||||
@@ -1461,6 +1463,8 @@ void CMainApplication::SetupDistortion()
|
||||
//-----------------------------------------------------------------------------
|
||||
void CMainApplication::RenderStereoTargets()
|
||||
{
|
||||
sExample->stepSimulation(1./60.);
|
||||
|
||||
glClearColor( 0.15f, 0.15f, 0.18f, 1.0f ); // nice background color, but not black
|
||||
glEnable( GL_MULTISAMPLE );
|
||||
|
||||
@@ -1476,33 +1480,40 @@ void CMainApplication::RenderStereoTargets()
|
||||
rotYtoZ.rotateX(-90);
|
||||
}
|
||||
|
||||
RenderScene( vr::Eye_Left );
|
||||
|
||||
// Left Eye
|
||||
{
|
||||
|
||||
Matrix4 viewMatLeft = m_mat4eyePosLeft * m_mat4HMDPose * rotYtoZ;
|
||||
|
||||
m_app->m_instancingRenderer->getActiveCamera()->setVRCamera(viewMatLeft.get(),m_mat4ProjectionLeft.get());
|
||||
m_app->m_instancingRenderer->updateCamera();
|
||||
m_app->m_instancingRenderer->updateCamera(m_app->getUpAxis());
|
||||
}
|
||||
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, leftEyeDesc.m_nRenderFramebufferId );
|
||||
glViewport(0, 0, m_nRenderWidth, m_nRenderHeight );
|
||||
|
||||
|
||||
|
||||
|
||||
m_app->m_window->startRendering();
|
||||
RenderScene( vr::Eye_Left );
|
||||
DrawGridData gridUp;
|
||||
gridUp.upAxis = m_app->getUpAxis();
|
||||
m_app->drawGrid(gridUp);
|
||||
sExample->stepSimulation(1./60.);
|
||||
sExample->renderScene();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
m_app->m_instancingRenderer->setRenderFrameBuffer((unsigned int)leftEyeDesc.m_nRenderFramebufferId);
|
||||
|
||||
m_app->m_instancingRenderer->renderScene();
|
||||
sExample->renderScene();
|
||||
//m_app->m_instancingRenderer->renderScene();
|
||||
DrawGridData gridUp;
|
||||
gridUp.upAxis = m_app->getUpAxis();
|
||||
m_app->drawGrid(gridUp);
|
||||
|
||||
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
||||
|
||||
@@ -1522,22 +1533,25 @@ void CMainApplication::RenderStereoTargets()
|
||||
|
||||
// Right Eye
|
||||
|
||||
RenderScene( vr::Eye_Right );
|
||||
|
||||
{
|
||||
Matrix4 viewMatRight = m_mat4eyePosRight * m_mat4HMDPose * rotYtoZ;
|
||||
m_app->m_instancingRenderer->getActiveCamera()->setVRCamera(viewMatRight.get(),m_mat4ProjectionRight.get());
|
||||
m_app->m_instancingRenderer->updateCamera();
|
||||
m_app->m_instancingRenderer->updateCamera(m_app->getUpAxis());
|
||||
}
|
||||
|
||||
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, rightEyeDesc.m_nRenderFramebufferId );
|
||||
glViewport(0, 0, m_nRenderWidth, m_nRenderHeight );
|
||||
|
||||
m_app->m_window->startRendering();
|
||||
RenderScene( vr::Eye_Right );
|
||||
|
||||
m_app->drawGrid(gridUp);
|
||||
|
||||
|
||||
m_app->m_instancingRenderer->setRenderFrameBuffer((unsigned int)rightEyeDesc.m_nRenderFramebufferId);
|
||||
|
||||
m_app->m_renderer->renderScene();
|
||||
//m_app->m_renderer->renderScene();
|
||||
sExample->renderScene();
|
||||
m_app->drawGrid(gridUp);
|
||||
|
||||
glBindFramebuffer( GL_FRAMEBUFFER, 0 );
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ subject to the following restrictions:
|
||||
#include "../ExampleBrowser/OpenGLGuiHelper.h"
|
||||
|
||||
CommonExampleInterface* example;
|
||||
int gSharedMemoryKey=-1;
|
||||
|
||||
b3MouseMoveCallback prevMouseMoveCallback = 0;
|
||||
static void OnMouseMove( float x, float y)
|
||||
@@ -57,6 +58,20 @@ static void OnMouseDown(int button, int state, float x, float y) {
|
||||
}
|
||||
}
|
||||
|
||||
class LessDummyGuiHelper : public DummyGUIHelper
|
||||
{
|
||||
CommonGraphicsApp* m_app;
|
||||
public:
|
||||
virtual CommonGraphicsApp* getAppInterface()
|
||||
{
|
||||
return m_app;
|
||||
}
|
||||
|
||||
LessDummyGuiHelper(CommonGraphicsApp* app)
|
||||
:m_app(app)
|
||||
{
|
||||
}
|
||||
};
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
@@ -69,11 +84,13 @@ int main(int argc, char* argv[])
|
||||
app->m_window->setMouseMoveCallback((b3MouseMoveCallback)OnMouseMove);
|
||||
|
||||
OpenGLGuiHelper gui(app,false);
|
||||
|
||||
//LessDummyGuiHelper gui(app);
|
||||
//DummyGUIHelper gui;
|
||||
|
||||
CommonExampleOptions options(&gui);
|
||||
|
||||
example = StandaloneExampleCreateFunc(options);
|
||||
example->initPhysics();
|
||||
example->initPhysics();
|
||||
example->resetCamera();
|
||||
|
||||
do
|
||||
|
||||
@@ -105,14 +105,20 @@ public:
|
||||
|
||||
}
|
||||
|
||||
virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices)
|
||||
|
||||
virtual int registerTexture(const unsigned char* texels, int width, int height)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureId)
|
||||
{
|
||||
int shapeIndex = OpenGLGuiHelper::registerGraphicsShape(vertices,numvertices,indices,numIndices);
|
||||
int shapeIndex = OpenGLGuiHelper::registerGraphicsShape(vertices,numvertices,indices,numIndices,primitiveType, textureId);
|
||||
if (shapeIndex>=0)
|
||||
{
|
||||
TinyRenderObjectData* swObj = new TinyRenderObjectData(m_rgbColorBuffer,m_depthBuffer);
|
||||
float rgbaColor[4] = {1,1,1,1};
|
||||
swObj->registerMeshShape(vertices,numvertices,indices,numIndices,rgbaColor);
|
||||
float rgbaColor[4] = {1,1,1,1};
|
||||
swObj->registerMeshShape(vertices,numvertices,indices,numIndices,rgbaColor);
|
||||
//swObj->createCube(1,1,1);//MeshShape(vertices,numvertices,indices,numIndices);
|
||||
m_swRenderObjects.insert(shapeIndex,swObj);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,12 @@ static btVector4 sMyColors[4] =
|
||||
//btVector4(1,1,0,1),
|
||||
};
|
||||
|
||||
struct TinyRendererTexture
|
||||
{
|
||||
const unsigned char* m_texels;
|
||||
int m_width;
|
||||
int m_height;
|
||||
};
|
||||
|
||||
struct TinyRendererGUIHelper : public GUIHelperInterface
|
||||
{
|
||||
@@ -45,6 +51,7 @@ struct TinyRendererGUIHelper : public GUIHelperInterface
|
||||
|
||||
btHashMap<btHashInt,TinyRenderObjectData*> m_swRenderObjects;
|
||||
btHashMap<btHashInt,int> m_swInstances;
|
||||
btHashMap<btHashInt,TinyRendererTexture> m_textures;
|
||||
|
||||
int m_swWidth;
|
||||
int m_swHeight;
|
||||
@@ -151,7 +158,8 @@ struct TinyRendererGUIHelper : public GUIHelperInterface
|
||||
|
||||
if (gfxVertices.size() && indices.size())
|
||||
{
|
||||
int shapeId = registerGraphicsShape(&gfxVertices[0].xyzw[0],gfxVertices.size(),&indices[0],indices.size());
|
||||
int shapeId = registerGraphicsShape(&gfxVertices[0].xyzw[0],gfxVertices.size(),&indices[0],indices.size(),
|
||||
1,-1);
|
||||
collisionShape->setUserIndex(shapeId);
|
||||
}
|
||||
}
|
||||
@@ -249,18 +257,41 @@ struct TinyRendererGUIHelper : public GUIHelperInterface
|
||||
|
||||
virtual void createPhysicsDebugDrawer( btDiscreteDynamicsWorld* rbWorld){}
|
||||
|
||||
virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices)
|
||||
virtual int registerTexture(const unsigned char* texels, int width, int height)
|
||||
{
|
||||
//do we need to make a copy?
|
||||
int textureId = m_textures.size();
|
||||
TinyRendererTexture t;
|
||||
t.m_texels = texels;
|
||||
t.m_width = width;
|
||||
t.m_height = height;
|
||||
this->m_textures.insert(textureId,t);
|
||||
return textureId;
|
||||
}
|
||||
|
||||
virtual int registerGraphicsShape(const float* vertices, int numvertices, const int* indices, int numIndices,int primitiveType, int textureId)
|
||||
{
|
||||
int shapeIndex = m_swRenderObjects.size();
|
||||
|
||||
TinyRenderObjectData* swObj = new TinyRenderObjectData(m_rgbColorBuffer,m_depthBuffer);
|
||||
float rgbaColor[4] = {1,1,1,1};
|
||||
swObj->registerMeshShape(vertices,numvertices,indices,numIndices,rgbaColor);
|
||||
|
||||
//if (textureId>=0)
|
||||
//{
|
||||
// swObj->registerMeshShape(vertices,numvertices,indices,numIndices,rgbaColor);
|
||||
//} else
|
||||
{
|
||||
swObj->registerMeshShape(vertices,numvertices,indices,numIndices,rgbaColor);
|
||||
}
|
||||
//swObj->createCube(1,1,1);//MeshShape(vertices,numvertices,indices,numIndices);
|
||||
m_swRenderObjects.insert(shapeIndex,swObj);
|
||||
return shapeIndex;
|
||||
}
|
||||
|
||||
virtual void removeAllGraphicsInstances()
|
||||
{
|
||||
}
|
||||
|
||||
virtual int registerGraphicsInstance(int shapeIndex, const float* position, const float* quaternion, const float* color, const float* scaling)
|
||||
{
|
||||
int colIndex = m_colObjUniqueIndex++;
|
||||
|
||||
Reference in New Issue
Block a user