Permalink
Browse files

GL import code cleanup. Added ability to load GLES library dynamically.

  • Loading branch information...
1 parent c6f5fa3 commit db735f5ff6958f8dd2225f21ee004901f7500abc @bkaradzic committed Feb 19, 2014
Showing with 378 additions and 239 deletions.
  1. +2 −0 3rdparty/glext/GLES2/gl2.h
  2. +2 −0 3rdparty/glext/GLES3/gl3.h
  3. +30 −13 src/glcontext_egl.cpp
  4. +10 −8 src/glcontext_glx.cpp
  5. +1 −2 src/glcontext_ppapi.cpp
  6. +19 −13 src/glcontext_wgl.cpp
  7. +299 −156 src/glimports.h
  8. +7 −3 src/renderer_gl.cpp
  9. +8 −44 src/renderer_gl.h
@@ -470,6 +470,7 @@ typedef khronos_ssize_t GLsizeiptr;
* GL core functions.
*-----------------------------------------------------------------------*/
+#if !BGFX_USE_GL_DYNAMIC_LIB
GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture);
GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader);
GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar* name);
@@ -612,6 +613,7 @@ GL_APICALL void GL_APIENTRY glVertexAttrib4f (GLuint indx, GLfloat x, GL
GL_APICALL void GL_APIENTRY glVertexAttrib4fv (GLuint indx, const GLfloat* values);
GL_APICALL void GL_APIENTRY glVertexAttribPointer (GLuint indx, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid* ptr);
GL_APICALL void GL_APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
+#endif // !BGFX_USE_GL_DYNAMIC_LIB
#ifdef __cplusplus
}
@@ -811,6 +811,7 @@ typedef struct __GLsync *GLsync;
/* OpenGL ES 2.0 */
+#if !BGFX_USE_GL_DYNAMIC_LIB
GL_APICALL void GL_APIENTRY glActiveTexture (GLenum texture);
GL_APICALL void GL_APIENTRY glAttachShader (GLuint program, GLuint shader);
GL_APICALL void GL_APIENTRY glBindAttribLocation (GLuint program, GLuint index, const GLchar* name);
@@ -1060,6 +1061,7 @@ GL_APICALL void GL_APIENTRY glInvalidateSubFramebuffer (GLenum target,
GL_APICALL void GL_APIENTRY glTexStorage2D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height);
GL_APICALL void GL_APIENTRY glTexStorage3D (GLenum target, GLsizei levels, GLenum internalformat, GLsizei width, GLsizei height, GLsizei depth);
GL_APICALL void GL_APIENTRY glGetInternalformativ (GLenum target, GLenum internalformat, GLenum pname, GLsizei bufSize, GLint* params);
+#endif // !BGFX_USE_GL_DYNAMIC_LIB
#ifdef __cplusplus
}
View
@@ -12,7 +12,8 @@
namespace bgfx
{
-#if BX_PLATFORM_WINDOWS
+#if BGFX_USE_GL_DYNAMIC_LIB
+
typedef void (*EGLPROC)(void);
typedef EGLPROC (EGLAPIENTRY* PFNEGLGETPROCADDRESSPROC)(const char *procname);
@@ -53,6 +54,7 @@ EGL_IMPORT
#define EGL_IMPORT_FUNC(_proto, _func) \
_func = (_proto)bx::dlsym(handle, #_func); \
+ BX_TRACE("%p " #_func, _func); \
BGFX_FATAL(NULL != _func, Fatal::UnableToInitialize, "Failed get " #_func ".")
EGL_IMPORT
#undef EGL_IMPORT_FUNC
@@ -79,11 +81,10 @@ EGL_IMPORT
void eglClose(void* /*_handle*/)
{
}
-#endif // BX_PLATFORM_WINDOWS
+#endif // BGFX_USE_GL_DYNAMIC_LIB
-# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func
-# include "glimports.h"
-# undef GL_IMPORT
+# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func = NULL
+# include "glimports.h"
void GlContext::create(uint32_t _width, uint32_t _height)
{
@@ -97,7 +98,7 @@ EGL_IMPORT
nwt = g_bgfxHwnd;
# endif // BX_PLATFORM_
m_display = eglGetDisplay(ndt);
- BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display 0x%08x", m_display);
+ BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display);
EGLint major = 0;
EGLint minor = 0;
@@ -184,14 +185,30 @@ EGL_IMPORT
void GlContext::import()
{
# if !BX_PLATFORM_EMSCRIPTEN
-# define GL_IMPORT(_optional, _proto, _func, _import) \
- { \
- _func = (_proto)eglGetProcAddress(#_import); \
- BX_TRACE(#_import " 0x%08x", _func); \
- BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_import); \
- }
+ BX_TRACE("Import:");
+# if BX_PLATFORM_WINDOWS
+ void* glesv2 = bx::dlopen("libGLESv2.dll");
+# define GL_EXTENSION(_optional, _proto, _func, _import) \
+ { \
+ if (NULL == _func) \
+ { \
+ _func = (_proto)bx::dlsym(glesv2, #_import); \
+ BX_TRACE("\t%p " #_func " (" #_import ")", _func); \
+ BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_import); \
+ } \
+ }
+# else
+# define GL_EXTENSION(_optional, _proto, _func, _import) \
+ { \
+ if (NULL == _func) \
+ { \
+ _func = (_proto)eglGetProcAddress(#_import); \
+ BX_TRACE("\t%p " #_func " (" #_import ")", _func); \
+ BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_import); \
+ } \
+ }
+# endif // BX_PLATFORM_
# include "glimports.h"
-# undef GL_IMPORT
# endif // !BX_PLATFORM_EMSCRIPTEN
}
View
@@ -20,8 +20,7 @@ namespace bgfx
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func
-# include "glimports.h"
-# undef GL_IMPORT
+# include "glimports.h"
static ::Display* s_display;
static ::Window s_window;
@@ -220,13 +219,16 @@ namespace bgfx
void GlContext::import()
{
-# define GL_IMPORT(_optional, _proto, _func, _import) \
- { \
- _func = (_proto)glXGetProcAddress((const GLubyte*)#_import); \
- BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. glXGetProcAddress %s", #_import); \
- }
+# define GL_EXTENSION(_optional, _proto, _func, _import) \
+ { \
+ if (NULL == _func) \
+ { \
+ _func = (_proto)glXGetProcAddress((const GLubyte*)#_import); \
+ BX_TRACE(#_func " = " #_import " 0x%08x", _func); \
+ BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. glXGetProcAddress %s", #_import); \
+ } \
+ }
# include "glimports.h"
-# undef GL_IMPORT
}
} // namespace bgfx
@@ -12,8 +12,7 @@
namespace bgfx
{
# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func
-# include "glimports.h"
-# undef GL_IMPORT
+# include "glimports.h"
void naclSwapCompleteCb(void* /*_data*/, int32_t /*_result*/);
View
@@ -22,8 +22,7 @@ namespace bgfx
PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT;
# define GL_IMPORT(_optional, _proto, _func, _import) _proto _func
-# include "glimports.h"
-# undef GL_IMPORT
+# include "glimports.h"
static HGLRC createContext(HDC _hdc)
{
@@ -273,18 +272,25 @@ namespace bgfx
void GlContext::import()
{
-# define GL_IMPORT(_optional, _proto, _func, _import) \
- { \
- BX_TRACE("%s", #_import); \
- _func = (_proto)wglGetProcAddress(#_import); \
- if (_func == NULL) \
- { \
- _func = (_proto)bx::dlsym(m_opengl32dll, #_import); \
- } \
- BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_import); \
- }
+ BX_TRACE("Import:");
+# define GL_EXTENSION(_optional, _proto, _func, _import) \
+ { \
+ if (NULL == _func) \
+ { \
+ _func = (_proto)wglGetProcAddress(#_import); \
+ if (_func == NULL) \
+ { \
+ _func = (_proto)bx::dlsym(m_opengl32dll, #_import); \
+ BX_TRACE(" %p " #_func " (" #_import ")", _func); \
+ } \
+ else \
+ { \
+ BX_TRACE("wgl %p " #_func " (" #_import ")", _func); \
+ } \
+ BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_import); \
+ } \
+ }
# include "glimports.h"
-# undef GL_IMPORT
}
} // namespace bgfx
Oops, something went wrong. Retry.

0 comments on commit db735f5

Please sign in to comment.