Added stub functions for instancing when it's not supported.

This commit is contained in:
bkaradzic 2012-07-08 12:28:38 -07:00
Родитель 1e7b94e82a
Коммит 295f5166f4
3 изменённых файлов: 54 добавлений и 9 удалений

Просмотреть файл

@ -118,10 +118,6 @@ GL_IMPORT(true, PFNGLGETQUERYOBJECTUI64VEXTPROC, glGetQueryObjectui64vE
GL_IMPORT(true, PFNGLSAMPLECOVERAGEARBPROC, glSampleCoverageARB);
GL_IMPORT(true, PFNGLDRAWARRAYSINSTANCEDARBPROC, glDrawArraysInstanced);
GL_IMPORT(true, PFNGLDRAWELEMENTSINSTANCEDARBPROC, glDrawElementsInstanced);
GL_IMPORT(true, PFNGLVERTEXATTRIBDIVISORARBPROC, glVertexAttribDivisor);
#if BGFX_CONFIG_DEBUG_GREMEDY
GL_IMPORT(true, PFNGLSTRINGMARKERGREMEDYPROC, glStringMarkerGREMEDY);
GL_IMPORT(true, PFNGLFRAMETERMINATORGREMEDYPROC, glFrameTerminatorGREMEDY);
@ -135,3 +131,7 @@ GL_IMPORT(true, PFNGLFRAMETERMINATORGREMEDYPROC, glFrameTerminatorGREME
GL_IMPORT(true, PFNGLGETTRANSLATEDSHADERSOURCEANGLEPROC, glGetTranslatedShaderSourceANGLE);
#endif // BGFX_CONFIG_RENDERER_
GL_IMPORT(true, PFNGLVERTEXATTRIBDIVISORBGFXPROC, glVertexAttribDivisor);
GL_IMPORT(true, PFNGLDRAWARRAYSINSTANCEDBGFXPROC, glDrawArraysInstanced);
GL_IMPORT(true, PFNGLDRAWELEMENTSINSTANCEDBGFXPROC, glDrawElementsInstanced);

Просмотреть файл

@ -27,6 +27,24 @@ namespace bgfx
#include "glimports.h"
#undef GL_IMPORT
static void GL_APIENTRY stubVertexAttribDivisor(GLuint /*_index*/, GLuint /*_divisor*/)
{
}
static void GL_APIENTRY stubDrawArraysInstanced(GLenum _mode, GLint _first, GLsizei _count, GLsizei /*_primcount*/)
{
glDrawArrays(_mode, _first, _count);
}
static void GL_APIENTRY stubDrawElementsInstanced(GLenum _mode, GLsizei _count, GLenum _type, const GLvoid* _indices, GLsizei /*_primcount*/)
{
glDrawElements(_mode, _count, _type, _indices);
}
static PFNGLVERTEXATTRIBDIVISORBGFXPROC s_vertexAttribDivisor = stubVertexAttribDivisor;
static PFNGLDRAWARRAYSINSTANCEDBGFXPROC s_drawArraysInstanced = stubDrawArraysInstanced;
static PFNGLDRAWELEMENTSINSTANCEDBGFXPROC s_drawElementsInstanced = stubDrawElementsInstanced;
typedef void (*PostSwapBuffersFn)(uint32_t _width, uint32_t _height);
#if BX_PLATFORM_NACL
@ -358,6 +376,21 @@ namespace bgfx
#endif // BX_PLATFORM_
}
if (NULL != glVertexAttribDivisor
&& NULL != glDrawArraysInstanced
&& NULL != glDrawElementsInstanced)
{
s_vertexAttribDivisor = glVertexAttribDivisor;
s_drawArraysInstanced = glDrawArraysInstanced;
s_drawElementsInstanced = glDrawElementsInstanced;
}
else
{
s_vertexAttribDivisor = stubVertexAttribDivisor;
s_drawArraysInstanced = stubDrawArraysInstanced;
s_drawElementsInstanced = stubDrawElementsInstanced;
}
m_flip = true;
}
@ -1030,7 +1063,7 @@ namespace bgfx
GL_CHECK(glEnableVertexAttribArray(loc) );
enabled |= 1<<attr;
GL_CHECK(glVertexAttribDivisor(loc, 0) );
GL_CHECK(s_vertexAttribDivisor(loc, 0) );
uint32_t baseVertex = _baseVertex*_vertexDecl.m_stride + _vertexDecl.m_offset[attr];
GL_CHECK(glVertexAttribPointer(loc, num, s_attribType[type], normalized, _vertexDecl.m_stride, (void*)(uintptr_t)baseVertex) );
@ -1073,7 +1106,7 @@ namespace bgfx
GLuint loc = m_instanceData[ii];
GL_CHECK(glEnableVertexAttribArray(loc) );
GL_CHECK(glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, _stride, (void*)(uintptr_t)baseVertex) );
GL_CHECK(glVertexAttribDivisor(loc, 1) );
GL_CHECK(s_vertexAttribDivisor(loc, 1) );
baseVertex += 16;
}
}
@ -2381,7 +2414,7 @@ namespace bgfx
numInstances = state.m_numInstances;
numPrimsRendered = numPrimsSubmitted*state.m_numInstances;
GL_CHECK(glDrawElementsInstanced(primType
GL_CHECK(s_drawElementsInstanced(primType
, s_renderCtx.m_indexBuffers[state.m_indexBuffer.idx].m_size/2
, GL_UNSIGNED_SHORT
, (void*)0
@ -2395,7 +2428,7 @@ namespace bgfx
numInstances = state.m_numInstances;
numPrimsRendered = numPrimsSubmitted*state.m_numInstances;
GL_CHECK(glDrawElementsInstanced(primType
GL_CHECK(s_drawElementsInstanced(primType
, numIndices
, GL_UNSIGNED_SHORT
, (void*)(uintptr_t)(state.m_startIndex*2)
@ -2409,7 +2442,7 @@ namespace bgfx
numInstances = state.m_numInstances;
numPrimsRendered = numPrimsSubmitted*state.m_numInstances;
GL_CHECK(glDrawArraysInstanced(primType
GL_CHECK(s_drawArraysInstanced(primType
, 0
, state.m_numVertices
, state.m_numInstances

Просмотреть файл

@ -130,8 +130,20 @@ typedef void (APIENTRYP PFNGLCLEARDEPTHPROC) (GLdouble depth);
typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
#endif // BGFX_USE_WGL
#ifndef GL_APIENTRY
# define GL_APIENTRY APIENTRY
#endif // GL_APIENTRY
#ifndef GL_APIENTRYP
# define GL_APIENTRYP APIENTRYP
#endif // GL_APIENTRYP
namespace bgfx
{
typedef void (GL_APIENTRYP PFNGLVERTEXATTRIBDIVISORBGFXPROC)(GLuint _index, GLuint _divisor);
typedef void (GL_APIENTRYP PFNGLDRAWARRAYSINSTANCEDBGFXPROC)(GLenum _mode, GLint _first, GLsizei _count, GLsizei _primcount);
typedef void (GL_APIENTRYP PFNGLDRAWELEMENTSINSTANCEDBGFXPROC)(GLenum _mode, GLsizei _count, GLenum _type, const GLvoid* _indices, GLsizei _primcount);
# define _GL_CHECK(_call) \
do { \
/*BX_TRACE(#_call);*/ \