Browse Source

Fixed attribs and uniforms with WebGL/asmjs.

bkaradzic 11 năm trước cách đây
mục cha
commit
dfa6229237
3 tập tin đã thay đổi với 25 bổ sung16 xóa
  1. 16 10
      src/bgfx.cpp
  2. 1 1
      src/config.h
  3. 8 5
      src/renderer_gl.cpp

+ 16 - 10
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
 	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;

+ 1 - 1
src/config.h

@@ -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

+ 8 - 5
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_ATTRIBUTES, &activeAttribs) );
 		GL_CHECK(glGetProgramiv(m_id, GL_ACTIVE_UNIFORMS, &activeUniforms) );
 		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);
 		char* name = (char*)alloca(maxLength + 1);
 
 
 		BX_TRACE("Program %d", m_id);
 		BX_TRACE("Program %d", m_id);