From e495c613a5a2b0c86b6e77b336f77950b5daba76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Mon, 30 Mar 2020 08:34:58 -0700 Subject: [PATCH] Cleanup. --- src/renderer_gl.cpp | 91 +++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 41 deletions(-) diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 2eea31170..293cd2d78 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1175,67 +1175,76 @@ namespace bgfx { namespace gl return 0 == err ? result : 0; } - static uint64_t currentlyEnabledVertexAttribArrays = 0; - static uint64_t vertexAttribArraysPendingDisable = 0; - static uint64_t vertexAttribArraysPendingEnable = 0; + static uint64_t s_currentlyEnabledVertexAttribArrays = 0; + static uint64_t s_vertexAttribArraysPendingDisable = 0; + static uint64_t s_vertexAttribArraysPendingEnable = 0; void lazyEnableVertexAttribArray(GLuint index) { -#if BX_PLATFORM_EMSCRIPTEN - // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize - // out redundant API calls to glEnable/DisableVertexAttribArray. - if (index >= 64) + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + { + // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize + // out redundant API calls to glEnable/DisableVertexAttribArray. + if (index >= 64) + { + glEnableVertexAttribArray(index); + return; + } + + uint64_t mask = UINT64_C(1) << index; + s_vertexAttribArraysPendingEnable |= mask & (~s_currentlyEnabledVertexAttribArrays); + s_vertexAttribArraysPendingDisable &= ~mask; + } + else { glEnableVertexAttribArray(index); - return; } - uint64_t mask = 1ULL << index; - vertexAttribArraysPendingEnable |= mask & (~currentlyEnabledVertexAttribArrays); - vertexAttribArraysPendingDisable &= ~mask; -#else - glEnableVertexAttribArray(index); -#endif } void lazyDisableVertexAttribArray(GLuint index) { -#if BX_PLATFORM_EMSCRIPTEN - // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize - // out redundant API calls to glEnable/DisableVertexAttribArray. - if (index >= 64) + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + { + // On WebGL platform calling out to WebGL API is detrimental to performance, so optimize + // out redundant API calls to glEnable/DisableVertexAttribArray. + if (index >= 64) + { + glDisableVertexAttribArray(index); + return; + } + + uint64_t mask = UINT64_C(1) << index; + s_vertexAttribArraysPendingDisable |= mask & s_currentlyEnabledVertexAttribArrays; + s_vertexAttribArraysPendingEnable &= ~mask; + } + else { glDisableVertexAttribArray(index); - return; } - uint64_t mask = 1ULL << index; - vertexAttribArraysPendingDisable |= mask & currentlyEnabledVertexAttribArrays; - vertexAttribArraysPendingEnable &= ~mask; -#else - glDisableVertexAttribArray(index); -#endif } void applyLazyEnabledVertexAttributes() { -#if BX_PLATFORM_EMSCRIPTEN - while(vertexAttribArraysPendingDisable) + if (BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) { - int index = __builtin_ctzll(vertexAttribArraysPendingDisable); - uint64_t mask = ~(1ULL << index); - vertexAttribArraysPendingDisable &= mask; - currentlyEnabledVertexAttribArrays &= mask; - glDisableVertexAttribArray(index); - } + while (s_vertexAttribArraysPendingDisable) + { + uint32_t index = bx::uint32_cnttz(s_vertexAttribArraysPendingDisable); + uint64_t mask = ~(UINT64_C(1) << index); + s_vertexAttribArraysPendingDisable &= mask; + s_currentlyEnabledVertexAttribArrays &= mask; + glDisableVertexAttribArray(index); + } - while(vertexAttribArraysPendingEnable) - { - int index = __builtin_ctzll(vertexAttribArraysPendingEnable); - uint64_t mask = 1ULL << index; - vertexAttribArraysPendingEnable &= ~mask; - currentlyEnabledVertexAttribArrays |= mask; - glEnableVertexAttribArray(index); + while (s_vertexAttribArraysPendingEnable) + { + uint32_t index = bx::uint32_cnttz(s_vertexAttribArraysPendingEnable); + uint64_t mask = UINT64_C(1) << index; + s_vertexAttribArraysPendingEnable &= ~mask; + s_currentlyEnabledVertexAttribArrays |= mask; + glEnableVertexAttribArray(index); + } } -#endif } void setTextureFormat(TextureFormat::Enum _format, GLenum _internalFmt, GLenum _fmt, GLenum _type = GL_ZERO)