|
|
|
|
@@ -17,8 +17,8 @@ subject to the following restrictions:
|
|
|
|
|
|
|
|
|
|
///todo: make this configurable in the gui
|
|
|
|
|
bool useShadowMap=true;//false;//true;
|
|
|
|
|
int shadowMapWidth=8192;
|
|
|
|
|
int shadowMapHeight=8192;
|
|
|
|
|
int shadowMapWidth=4096;//8192;
|
|
|
|
|
int shadowMapHeight=4096;
|
|
|
|
|
float shadowMapWorldSize=50;
|
|
|
|
|
|
|
|
|
|
#define MAX_POINTS_IN_BATCH 1024
|
|
|
|
|
@@ -386,24 +386,39 @@ void GLInstancingRenderer::writeTransforms()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo);
|
|
|
|
|
glFlush();
|
|
|
|
|
//glFlush();
|
|
|
|
|
|
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
int totalNumInstances= 0;
|
|
|
|
|
|
|
|
|
|
for (int k=0;k<m_graphicsInstances.size();k++)
|
|
|
|
|
{
|
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[k];
|
|
|
|
|
totalNumInstances+=gfxObj->m_numGraphicsInstances;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int POSITION_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4);
|
|
|
|
|
int ORIENTATION_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4);
|
|
|
|
|
int COLOR_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4);
|
|
|
|
|
// int SCALE_BUFFER_SIZE = (totalNumInstances*sizeof(float)*3);
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
glBufferSubData( GL_ARRAY_BUFFER,m_data->m_maxShapeCapacityInBytes,totalNumInstances*sizeof(float)*4,
|
|
|
|
|
&m_data->m_instance_positions_ptr[0]);
|
|
|
|
|
glBufferSubData( GL_ARRAY_BUFFER,m_data->m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE,totalNumInstances*sizeof(float)*4,
|
|
|
|
|
&m_data->m_instance_quaternion_ptr[0]);
|
|
|
|
|
glBufferSubData( GL_ARRAY_BUFFER,m_data->m_maxShapeCapacityInBytes+ POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE, totalNumInstances*sizeof(float)*4,
|
|
|
|
|
&m_data->m_instance_colors_ptr[0]);
|
|
|
|
|
glBufferSubData( GL_ARRAY_BUFFER, m_data->m_maxShapeCapacityInBytes+POSITION_BUFFER_SIZE+ORIENTATION_BUFFER_SIZE+COLOR_BUFFER_SIZE,totalNumInstances*sizeof(float)*3,
|
|
|
|
|
&m_data->m_instance_scale_ptr[0]);
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
char* orgBase = (char*)glMapBuffer( GL_ARRAY_BUFFER,GL_READ_WRITE);
|
|
|
|
|
if (orgBase)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int totalNumInstances= 0;
|
|
|
|
|
|
|
|
|
|
for (int k=0;k<m_graphicsInstances.size();k++)
|
|
|
|
|
{
|
|
|
|
|
b3GraphicsInstance* gfxObj = m_graphicsInstances[k];
|
|
|
|
|
totalNumInstances+=gfxObj->m_numGraphicsInstances;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_data->m_totalNumInstances = totalNumInstances;
|
|
|
|
|
|
|
|
|
|
for (int k=0;k<m_graphicsInstances.size();k++)
|
|
|
|
|
@@ -413,10 +428,7 @@ void GLInstancingRenderer::writeTransforms()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int POSITION_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4);
|
|
|
|
|
int ORIENTATION_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4);
|
|
|
|
|
int COLOR_BUFFER_SIZE = (totalNumInstances*sizeof(float)*4);
|
|
|
|
|
// int SCALE_BUFFER_SIZE = (totalNumInstances*sizeof(float)*3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char* base = orgBase;
|
|
|
|
|
|
|
|
|
|
@@ -465,6 +477,9 @@ void GLInstancingRenderer::writeTransforms()
|
|
|
|
|
//if this glFinish is removed, the animation is not always working/blocks
|
|
|
|
|
//@todo: figure out why
|
|
|
|
|
glFlush();
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);//m_data->m_vbo);
|
|
|
|
|
|
|
|
|
|
b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
@@ -1006,7 +1021,7 @@ void GLInstancingRenderer::renderScene()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
renderSceneInternal(B3_CREATE_SHADOWMAP_RENDERMODE);
|
|
|
|
|
// glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
//glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
renderSceneInternal(B3_USE_SHADOWMAP_RENDERMODE);
|
|
|
|
|
|
|
|
|
|
} else
|
|
|
|
|
@@ -1075,6 +1090,9 @@ void GLInstancingRenderer::drawPoints(const float* positions, const float color[
|
|
|
|
|
|
|
|
|
|
void GLInstancingRenderer::drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float lineWidthIn)
|
|
|
|
|
{
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D,0);
|
|
|
|
|
|
|
|
|
|
float lineWidth = lineWidthIn;
|
|
|
|
|
b3Clamp(lineWidth,(float)lineWidthRange[0],(float)lineWidthRange[1]);
|
|
|
|
|
glLineWidth(lineWidth);
|
|
|
|
|
@@ -1510,7 +1528,7 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
int curOffset = 0;
|
|
|
|
|
//GLuint lastBindTexture = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<m_graphicsInstances.size();i++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
@@ -1634,6 +1652,7 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
printf("gfxObj->m_numGraphicsInstances=%d\n",gfxObj->m_numGraphicsInstances);
|
|
|
|
|
printf("indexCount=%d\n",indexCount);
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
glUseProgram(createShadowMapInstancingShader);
|
|
|
|
|
glUniformMatrix4fv(createShadow_depthMVP, 1, false, &depthMVP[0][0]);
|
|
|
|
|
glDrawElementsInstanced(GL_TRIANGLES, indexCount, GL_UNSIGNED_INT, indexOffset, gfxObj->m_numGraphicsInstances);
|
|
|
|
|
@@ -1667,6 +1686,7 @@ b3Assert(glGetError() ==GL_NO_ERROR);
|
|
|
|
|
glDisable (GL_BLEND);
|
|
|
|
|
}
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D,0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
@@ -1743,4 +1763,10 @@ void GLInstancingRenderer::setRenderFrameBuffer(unsigned int renderFrameBuffer)
|
|
|
|
|
m_data->m_renderFrameBuffer = (GLuint) renderFrameBuffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GLInstancingRenderer::getTotalNumInstances() const
|
|
|
|
|
{
|
|
|
|
|
return m_data->m_totalNumInstances;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endif //NO_OPENGL3
|
|
|
|
|
|