This commit is contained in:
Бранимир Караџић 2020-03-30 08:34:58 -07:00
parent d26aac6d2c
commit e495c613a5

View File

@ -1175,13 +1175,14 @@ namespace bgfx { namespace gl
return 0 == err ? result : 0; return 0 == err ? result : 0;
} }
static uint64_t currentlyEnabledVertexAttribArrays = 0; static uint64_t s_currentlyEnabledVertexAttribArrays = 0;
static uint64_t vertexAttribArraysPendingDisable = 0; static uint64_t s_vertexAttribArraysPendingDisable = 0;
static uint64_t vertexAttribArraysPendingEnable = 0; static uint64_t s_vertexAttribArraysPendingEnable = 0;
void lazyEnableVertexAttribArray(GLuint index) void lazyEnableVertexAttribArray(GLuint index)
{ {
#if BX_PLATFORM_EMSCRIPTEN if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
{
// On WebGL platform calling out to WebGL API is detrimental to performance, so optimize // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize
// out redundant API calls to glEnable/DisableVertexAttribArray. // out redundant API calls to glEnable/DisableVertexAttribArray.
if (index >= 64) if (index >= 64)
@ -1189,17 +1190,21 @@ namespace bgfx { namespace gl
glEnableVertexAttribArray(index); glEnableVertexAttribArray(index);
return; return;
} }
uint64_t mask = 1ULL << index;
vertexAttribArraysPendingEnable |= mask & (~currentlyEnabledVertexAttribArrays); uint64_t mask = UINT64_C(1) << index;
vertexAttribArraysPendingDisable &= ~mask; s_vertexAttribArraysPendingEnable |= mask & (~s_currentlyEnabledVertexAttribArrays);
#else s_vertexAttribArraysPendingDisable &= ~mask;
}
else
{
glEnableVertexAttribArray(index); glEnableVertexAttribArray(index);
#endif }
} }
void lazyDisableVertexAttribArray(GLuint index) void lazyDisableVertexAttribArray(GLuint index)
{ {
#if BX_PLATFORM_EMSCRIPTEN if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
{
// On WebGL platform calling out to WebGL API is detrimental to performance, so optimize // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize
// out redundant API calls to glEnable/DisableVertexAttribArray. // out redundant API calls to glEnable/DisableVertexAttribArray.
if (index >= 64) if (index >= 64)
@ -1207,35 +1212,39 @@ namespace bgfx { namespace gl
glDisableVertexAttribArray(index); glDisableVertexAttribArray(index);
return; return;
} }
uint64_t mask = 1ULL << index;
vertexAttribArraysPendingDisable |= mask & currentlyEnabledVertexAttribArrays; uint64_t mask = UINT64_C(1) << index;
vertexAttribArraysPendingEnable &= ~mask; s_vertexAttribArraysPendingDisable |= mask & s_currentlyEnabledVertexAttribArrays;
#else s_vertexAttribArraysPendingEnable &= ~mask;
}
else
{
glDisableVertexAttribArray(index); glDisableVertexAttribArray(index);
#endif }
} }
void applyLazyEnabledVertexAttributes() void applyLazyEnabledVertexAttributes()
{ {
#if BX_PLATFORM_EMSCRIPTEN if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
while(vertexAttribArraysPendingDisable)
{ {
int index = __builtin_ctzll(vertexAttribArraysPendingDisable); while (s_vertexAttribArraysPendingDisable)
uint64_t mask = ~(1ULL << index); {
vertexAttribArraysPendingDisable &= mask; uint32_t index = bx::uint32_cnttz(s_vertexAttribArraysPendingDisable);
currentlyEnabledVertexAttribArrays &= mask; uint64_t mask = ~(UINT64_C(1) << index);
s_vertexAttribArraysPendingDisable &= mask;
s_currentlyEnabledVertexAttribArrays &= mask;
glDisableVertexAttribArray(index); glDisableVertexAttribArray(index);
} }
while(vertexAttribArraysPendingEnable) while (s_vertexAttribArraysPendingEnable)
{ {
int index = __builtin_ctzll(vertexAttribArraysPendingEnable); uint32_t index = bx::uint32_cnttz(s_vertexAttribArraysPendingEnable);
uint64_t mask = 1ULL << index; uint64_t mask = UINT64_C(1) << index;
vertexAttribArraysPendingEnable &= ~mask; s_vertexAttribArraysPendingEnable &= ~mask;
currentlyEnabledVertexAttribArrays |= mask; s_currentlyEnabledVertexAttribArrays |= mask;
glEnableVertexAttribArray(index); glEnableVertexAttribArray(index);
} }
#endif }
} }
void setTextureFormat(TextureFormat::Enum _format, GLenum _internalFmt, GLenum _fmt, GLenum _type = GL_ZERO) void setTextureFormat(TextureFormat::Enum _format, GLenum _internalFmt, GLenum _fmt, GLenum _type = GL_ZERO)