Procházet zdrojové kódy

explicitly look up webgl1 or webgl2 functions in html5

Vladimir Vukicevic před 6 roky
rodič
revize
6b8d0c7ba2
2 změnil soubory, kde provedl 8 přidání a 4 odebrání
  1. 7 3
      src/glcontext_html5.cpp
  2. 1 1
      src/glcontext_html5.h

+ 7 - 3
src/glcontext_html5.cpp

@@ -16,6 +16,8 @@
 // from emscripten gl.c, because we're not going to go
 // through egl
 extern "C" void* emscripten_GetProcAddress(const char *name_);
+extern "C" void* emscripten_webgl1_get_proc_address(const char *name_);
+extern "C" void* emscripten_webgl2_get_proc_address(const char *name_);
 
 namespace bgfx { namespace gl
 {
@@ -130,7 +132,7 @@ namespace bgfx { namespace gl
 
 		SwapChainGL* swapChain = BX_NEW(g_allocator, SwapChainGL)(context, canvas);
 
-		import();
+		import(1);
 
 		return swapChain;
 	}
@@ -169,14 +171,16 @@ namespace bgfx { namespace gl
 		}
 	}
 
-	void GlContext::import()
+	void GlContext::import(int webGLVersion)
 	{
 		BX_TRACE("Import:");
 #		define GL_EXTENSION(_optional, _proto, _func, _import)                                                                                                   \
 			{                                                                                                                                                    \
 				if (NULL == _func)                                                                                                                               \
 				{                                                                                                                                                \
-					_func = (_proto)emscripten_GetProcAddress(#_import);                                                                                                 \
+					_func = (_proto)emscripten_webgl1_get_proc_address(#_import);                                                                                \
+					if (!_func && webGLVersion >= 2)                                                                                                             \
+					    _func = (_proto)emscripten_webgl2_get_proc_address(#_import);                                                                            \
 					BX_TRACE("\t%p " #_func " (" #_import ")", _func);                                                                                           \
 					BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create WebGL/OpenGLES context. GetProcAddress(\"%s\")", #_import); \
 				}                                                                                                                                                \

+ 1 - 1
src/glcontext_html5.h

@@ -30,7 +30,7 @@ namespace bgfx { namespace gl
 		void swap(SwapChainGL* _swapChain = NULL);
 		void makeCurrent(SwapChainGL* _swapChain = NULL);
 
-		void import();
+		void import(int webGLVersion);
 
 		bool isValid() const
 		{