Fixed attribs and uniforms with WebGL/asmjs.

This commit is contained in:
bkaradzic 2014-03-16 18:16:08 -07:00
parent 81a3e23841
commit dfa6229237
3 changed files with 25 additions and 16 deletions

View file

@ -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 class AllocatorStub : public bx::ReallocatorI
{ {
public: public:
AllocatorStub() AllocatorStub()
#if BGFX_CONFIG_DEBUG #if BGFX_CONFIG_MEMORY_TRACKING
: m_numBlocks(0) : m_numBlocks(0)
, m_maxBlocks(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 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); bx::LwMutexScope scope(m_mutex);
++m_numBlocks; ++m_numBlocks;
m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks); m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks);
} }
#endif // BGFX_CONFIG_DEBUG #endif // BGFX_CONFIG_MEMORY_TRACKING
BX_UNUSED(_file, _line); BX_UNUSED(_file, _line);
return ::malloc(_size); return ::malloc(_size);
@ -158,13 +162,13 @@ namespace bgfx
{ {
if (NULL != _ptr) if (NULL != _ptr)
{ {
#if BGFX_CONFIG_DEBUG #if BGFX_CONFIG_MEMORY_TRACKING
{ {
bx::LwMutexScope scope(m_mutex); bx::LwMutexScope scope(m_mutex);
BX_CHECK(m_numBlocks > 0, "Number of blocks is 0. Possible alloc/free mismatch?"); BX_CHECK(m_numBlocks > 0, "Number of blocks is 0. Possible alloc/free mismatch?");
--m_numBlocks; --m_numBlocks;
} }
#endif // BGFX_CONFIG_DEBUG #endif // BGFX_CONFIG_MEMORY_TRACKING
BX_UNUSED(_file, _line); BX_UNUSED(_file, _line);
::free(_ptr); ::free(_ptr);
@ -173,14 +177,14 @@ namespace bgfx
virtual void* realloc(void* _ptr, size_t _size, const char* _file, uint32_t _line) BX_OVERRIDE 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) if (NULL == _ptr)
{ {
bx::LwMutexScope scope(m_mutex); bx::LwMutexScope scope(m_mutex);
++m_numBlocks; ++m_numBlocks;
m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks); m_maxBlocks = bx::uint32_max(m_maxBlocks, m_numBlocks);
} }
#endif // BGFX_CONFIG_DEBUG #endif // BGFX_CONFIG_MEMORY_TRACKING
BX_UNUSED(_file, _line); BX_UNUSED(_file, _line);
return ::realloc(_ptr, _size); return ::realloc(_ptr, _size);
@ -188,15 +192,17 @@ namespace bgfx
void checkLeaks() void checkLeaks()
{ {
#if BGFX_CONFIG_MEMORY_TRACKING
BX_WARN(0 == m_numBlocks, "MEMORY LEAK: %d (max: %d)", m_numBlocks, m_maxBlocks); BX_WARN(0 == m_numBlocks, "MEMORY LEAK: %d (max: %d)", m_numBlocks, m_maxBlocks);
#endif // BGFX_CONFIG_MEMORY_TRACKING
} }
protected: protected:
#if BGFX_CONFIG_DEBUG #if BGFX_CONFIG_MEMORY_TRACKING
bx::LwMutex m_mutex; bx::LwMutex m_mutex;
uint32_t m_numBlocks; uint32_t m_numBlocks;
uint32_t m_maxBlocks; uint32_t m_maxBlocks;
#endif // BGFX_CONFIG_DEBUG #endif // BGFX_CONFIG_MEMORY_TRACKING
}; };
static CallbackStub* s_callbackStub = NULL; static CallbackStub* s_callbackStub = NULL;

View file

@ -97,7 +97,7 @@
#endif // BGFX_CONFIG_DEBUG_NVPERFHUD #endif // BGFX_CONFIG_DEBUG_NVPERFHUD
#ifndef BGFX_CONFIG_RENDERER_USE_EXTENSIONS #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 #endif // BGFX_CONFIG_RENDERER_USE_EXTENSIONS
/// DX9 PIX markers /// DX9 PIX markers

View file

@ -1682,11 +1682,14 @@ namespace bgfx
GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_ATTRIBUTES, &activeAttribs) ); GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_ATTRIBUTES, &activeAttribs) );
GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_UNIFORMS, &activeUniforms) ); GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_UNIFORMS, &activeUniforms) );
GLint max0, max1; GLint maxLength = 512;
GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &max0) ); if (!BX_ENABLED(BX_PLATFORM_EMSCRIPTEN) )
GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max1) ); {
GLint max0, max1;
GLint maxLength = bx::uint32_max(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); char* name = (char*)alloca(maxLength + 1);
BX_TRACE("Program %d", m_id); BX_TRACE("Program %d", m_id);