Selaa lähdekoodia

Merge pull request #431 from attilaz/glimport

added iOS GL extension function import
Branimir Karadžić 10 vuotta sitten
vanhempi
sitoutus
284b8ef65b
1 muutettua tiedostoa jossa 20 lisäystä ja 0 poistoa
  1. 20 0
      src/glcontext_eagl.mm

+ 20 - 0
src/glcontext_eagl.mm

@@ -15,8 +15,13 @@ namespace bgfx { namespace gl
 #	define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL
 #	define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL
 #	include "glimports.h"
 #	include "glimports.h"
 
 
+	static void* s_opengles = NULL;
+	
 	void GlContext::create(uint32_t _width, uint32_t _height)
 	void GlContext::create(uint32_t _width, uint32_t _height)
 	{
 	{
+		s_opengles = bx::dlopen("/System/Library/Frameworks/OpenGLES.framework/OpenGLES");
+		BX_CHECK(NULL != s_opengles, "OpenGLES dynamic library is not found!");
+		
 		BX_UNUSED(_width, _height);
 		BX_UNUSED(_width, _height);
 		CAEAGLLayer* layer = (CAEAGLLayer*)g_platformData.nwh;
 		CAEAGLLayer* layer = (CAEAGLLayer*)g_platformData.nwh;
 		layer.opaque = true;
 		layer.opaque = true;
@@ -59,6 +64,8 @@ namespace bgfx { namespace gl
 			, "glCheckFramebufferStatus failed 0x%08x"
 			, "glCheckFramebufferStatus failed 0x%08x"
 			, glCheckFramebufferStatus(GL_FRAMEBUFFER)
 			, glCheckFramebufferStatus(GL_FRAMEBUFFER)
 			);
 			);
+		
+		import();
 	}
 	}
 
 
 	void GlContext::destroy()
 	void GlContext::destroy()
@@ -83,6 +90,8 @@ namespace bgfx { namespace gl
 
 
 		EAGLContext* context = (EAGLContext*)m_context;
 		EAGLContext* context = (EAGLContext*)m_context;
 		[context release];
 		[context release];
+		
+		bx::dlclose(s_opengles);
 	}
 	}
 
 
 	void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags)
 	void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags)
@@ -121,6 +130,17 @@ namespace bgfx { namespace gl
 
 
 	void GlContext::import()
 	void GlContext::import()
 	{
 	{
+		BX_TRACE("Import:");
+#	define GL_EXTENSION(_optional, _proto, _func, _import) \
+		{ \
+			if (_func == NULL) \
+			{ \
+				_func = (_proto)bx::dlsym(s_opengles, #_import); \
+				BX_TRACE("%p " #_func " (" #_import ")", _func); \
+			} \
+			BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. EAGLGetProcAddress(\"%s\")", #_import); \
+		}
+#	include "glimports.h"
 	}
 	}
 
 
 } /* namespace gl */ } // namespace bgfx
 } /* namespace gl */ } // namespace bgfx