From dfa62292375ab293b0937c75dcc93a7d4fa211f5 Mon Sep 17 00:00:00 2001 From: bkaradzic Date: Sun, 16 Mar 2014 18:16:08 -0700 Subject: [PATCH] Fixed attribs and uniforms with WebGL/asmjs. --- src/bgfx.cpp | 26 ++++++++++++++++---------- src/config.h | 2 +- src/renderer_gl.cpp | 13 ++++++++----- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 4c4795150..c96095769 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -129,26 +129,30 @@ namespace bgfx } }; +#ifndef BGFX_CONFIG_MEMORY_TRACKING +# define BGFX_CONFIG_MEMORY_TRACKING (BGFX_CONFIG_DEBUG && BX_CONFIG_SUPPORTED_THREADING) +#endif // BGFX_CONFIG_MEMORY_TRACKING + class AllocatorStub : public bx::ReallocatorI { public: AllocatorStub() -#if BGFX_CONFIG_DEBUG +#if BGFX_CONFIG_MEMORY_TRACKING : m_numBlocks(0) , m_maxBlocks(0) -#endif // BGFX_CONFIG_DEBUG +#endif // BGFX_CONFIG_MEMORY_TRACKING { } virtual void* alloc(size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE { -#if BGFX_CONFIG_DEBUG +#if BGFX_CONFIG_MEMORY_TRACKING { bx::LwMutexScope scope(m_mutex); ++m_numBlocks; m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks); } -#endif // BGFX_CONFIG_DEBUG +#endif // BGFX_CONFIG_MEMORY_TRACKING BX_UNUSED(_file, _line); return ::malloc(_size); @@ -158,13 +162,13 @@ namespace bgfx { if (NULL != _ptr) { -#if BGFX_CONFIG_DEBUG +#if BGFX_CONFIG_MEMORY_TRACKING { bx::LwMutexScope scope(m_mutex); BX_CHECK(m_numBlocks > 0, "Number of blocks is 0. Possible alloc/free mismatch?"); --m_numBlocks; } -#endif // BGFX_CONFIG_DEBUG +#endif // BGFX_CONFIG_MEMORY_TRACKING BX_UNUSED(_file, _line); ::free(_ptr); @@ -173,14 +177,14 @@ namespace bgfx virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE { -#if BGFX_CONFIG_DEBUG +#if BGFX_CONFIG_MEMORY_TRACKING if (NULL == _ptr) { bx::LwMutexScope scope(m_mutex); ++m_numBlocks; m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks); } -#endif // BGFX_CONFIG_DEBUG +#endif // BGFX_CONFIG_MEMORY_TRACKING BX_UNUSED(_file, _line); return ::realloc(_ptr, _size); @@ -188,15 +192,17 @@ namespace bgfx void checkLeaks() { +#if BGFX_CONFIG_MEMORY_TRACKING BX_WARN(0 == m_numBlocks, "MEMORY LEAK: %d (max: %d)", m_numBlocks, m_maxBlocks); +#endif // BGFX_CONFIG_MEMORY_TRACKING } protected: -#if BGFX_CONFIG_DEBUG +#if BGFX_CONFIG_MEMORY_TRACKING bx::LwMutex m_mutex; uint32_t m_numBlocks; uint32_t m_maxBlocks; -#endif // BGFX_CONFIG_DEBUG +#endif // BGFX_CONFIG_MEMORY_TRACKING }; static CallbackStub* s_callbackStub = NULL; diff --git a/src/config.h b/src/config.h index 39cead567..a0b07c31e 100644 --- a/src/config.h +++ b/src/config.h @@ -97,7 +97,7 @@ #endif // BGFX_CONFIG_DEBUG_NVPERFHUD #ifndef BGFX_CONFIG_RENDERER_USE_EXTENSIONS -# define BGFX_CONFIG_RENDERER_USE_EXTENSIONS 1 +# define BGFX_CONFIG_RENDERER_USE_EXTENSIONS !BX_PLATFORM_EMSCRIPTEN #endif // BGFX_CONFIG_RENDERER_USE_EXTENSIONS /// DX9 PIX markers diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 838d02214..7dea2ec57 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1682,11 +1682,14 @@ namespace bgfx GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_ATTRIBUTES, &activeAttribs) ); GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_UNIFORMS, &activeUniforms) ); - GLint max0, max1; - GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max0) ); - GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max1) ); - - GLint maxLength = bx::uint32_max(max0, max1); + GLint maxLength = 512; + if (!BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) ) + { + GLint max0, max1; + GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max0) ); + GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max1) ); + maxLength = bx::uint32_max(max0, max1); + } char* name = (char*)alloca(maxLength + 1); BX_TRACE("Program %d", m_id);