Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
bkaradzic committed Sep 3, 2020
1 parent 0093a67 commit 8f4750b
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Expand Up @@ -6,7 +6,7 @@ os:
environment:
matrix:
- TOOLSET: vs2017
- TOOLSET: vs2019
# - TOOLSET: vs2019

configuration:
- Debug
Expand Down
2 changes: 0 additions & 2 deletions src/bgfx_p.h
Expand Up @@ -44,8 +44,6 @@
, _handleAlloc.getMaxHandles() \
)

#define BGFX_CAST_FUNCTION(proto, func) ((proto)(void(*)(void))func)

#if BGFX_CONFIG_MULTITHREADED
# define BGFX_MUTEX_SCOPE(_mutex) bx::MutexScope BX_CONCATENATE(mutexScope, __LINE__)(_mutex)
#else
Expand Down
43 changes: 27 additions & 16 deletions src/glcontext_egl.cpp
Expand Up @@ -444,30 +444,41 @@ EGL_IMPORT
void GlContext::import()
{
BX_TRACE("Import:");

# if BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX
void* glesv2 = bx::dlopen("libGLESv2." BX_DL_EXT);
# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \
if (NULL == _func) \
{ \
_func = BGFX_CAST_FUNCTION(_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); \
} \

# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \
if (NULL == _func) \
{ \
_func = bx::functionCast<_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 = BGFX_CAST_FUNCTION(_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); \
} \
# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \
if (NULL == _func) \
{ \
_func = bx::functionCast<_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_EXTENSION
}

} /* namespace gl */ } // namespace bgfx
Expand Down
55 changes: 37 additions & 18 deletions src/glcontext_glx.cpp
Expand Up @@ -66,15 +66,15 @@ namespace bgfx { namespace gl
for(;;)
{
bx::StringView found = bx::strFind(searchStart, _ext);
if (found.isEmpty())
if (found.isEmpty() )
{
return false;
}

// We found the substring, but need an exact match, with a word
// boundary at both the front and back of the found spot.
if ((found.getPtr() == _extList || *(found.getPtr() - 1) == ' ')
&& (found.getTerm() == end || *found.getTerm() == ' '))
&& (found.getTerm() == end || *found.getTerm() == ' ') )
{
return true;
}
Expand Down Expand Up @@ -222,30 +222,42 @@ namespace bgfx { namespace gl
glXMakeCurrent(m_display, (::Window)g_platformData.nwh, m_context);
m_current = NULL;

const char* extensions = glXQueryExtensionsString(m_display, DefaultScreen(m_display));
const char* extensions = glXQueryExtensionsString(m_display, DefaultScreen(m_display) );

if (NULL != extensions)
{
bool foundSwapControl = false;
if (haveGlxExtension("GLX_EXT_swap_control", extensions)) {
glXSwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT");

if (haveGlxExtension("GLX_EXT_swap_control", extensions) )
{
glXSwapIntervalEXT = bx::functionCast<PFNGLXSWAPINTERVALEXTPROC>(glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT") );

if (NULL != glXSwapIntervalEXT)
{
BX_TRACE("Using glXSwapIntervalEXT.");
glXSwapIntervalEXT(m_display, (::Window)g_platformData.nwh, 0);
foundSwapControl = true;
}
}
if (!foundSwapControl && haveGlxExtension("GLX_MESA_swap_control", extensions)) {
glXSwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalMESA");

if (!foundSwapControl
&& haveGlxExtension("GLX_MESA_swap_control", extensions) )
{
glXSwapIntervalMESA = bx::functionCast<PFNGLXSWAPINTERVALMESAPROC>(glXGetProcAddress( (const GLubyte*)"glXSwapIntervalMESA") );

if (NULL != glXSwapIntervalMESA)
{
BX_TRACE("Using glXSwapIntervalMESA.");
glXSwapIntervalMESA(0);
foundSwapControl = true;
}
}
if (!foundSwapControl && haveGlxExtension("GLX_SGI_swap_control", extensions)) {
glXSwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)glXGetProcAddress( (const GLubyte*)"glXSwapIntervalSGI");

if (!foundSwapControl
&& haveGlxExtension("GLX_SGI_swap_control", extensions) )
{
glXSwapIntervalSGI = bx::functionCast<PFNGLXSWAPINTERVALSGIPROC>(glXGetProcAddress( (const GLubyte*)"glXSwapIntervalSGI") );

if (NULL != glXSwapIntervalSGI)
{
BX_TRACE("Using glXSwapIntervalSGI.");
Expand Down Expand Up @@ -348,16 +360,23 @@ namespace bgfx { namespace gl

void GlContext::import()
{
# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \
if (NULL == _func) \
{ \
_func = BGFX_CAST_FUNCTION(_proto, glXGetProcAddress( (const GLubyte*)#_import)); \
BX_TRACE("%p " #_func " (" #_import ")", _func); \
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. glXGetProcAddress %s", #_import); \
} \
}
BX_TRACE("Import:");

# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \
if (NULL == _func) \
{ \
_func = bx::functionCast<_proto>(glXGetProcAddress( (const GLubyte*)#_import) ); \
BX_TRACE("%p " #_func " (" #_import ")", _func); \
BGFX_FATAL(_optional || NULL != _func \
, Fatal::UnableToInitialize \
, "Failed to create OpenGL context. glXGetProcAddress %s", #_import); \
} \
}

# include "glimports.h"

# undef GL_EXTENSION
}

} /* namespace gl */ } // namespace bgfx
Expand Down
31 changes: 20 additions & 11 deletions src/glcontext_html5.cpp
Expand Up @@ -182,19 +182,28 @@ namespace bgfx { namespace gl
void GlContext::import(int webGLVersion)
{
BX_TRACE("Import:");
# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \
if (NULL == _func) \
{ \
_func = (_proto)emscripten_webgl1_get_proc_address(#_import); \
if (!_func && webGLVersion >= 2) \
_func = BGFX_CAST_FUNCTION(_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); \
} \
}

# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \
if (NULL == _func) \
{ \
_func = (_proto)emscripten_webgl1_get_proc_address(#_import); \
if (!_func && webGLVersion >= 2) \
{ \
_func = bx::functionCast<_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 \
); \
} \
}

# include "glimports.h"

# undef GL_EXTENSION

}

} /* namespace gl */ } // namespace bgfx
Expand Down
56 changes: 31 additions & 25 deletions src/glcontext_wgl.cpp
Expand Up @@ -106,7 +106,7 @@ namespace bgfx { namespace gl
m_opengl32dll = bx::dlopen("opengl32.dll");
BGFX_FATAL(NULL != m_opengl32dll, Fatal::UnableToInitialize, "Failed to load opengl32.dll.");

wglGetProcAddress = BGFX_CAST_FUNCTION(PFNWGLGETPROCADDRESSPROC, bx::dlsym(m_opengl32dll, "wglGetProcAddress"));
wglGetProcAddress = bx::functionCast<PFNWGLGETPROCADDRESSPROC>(bx::dlsym(m_opengl32dll, "wglGetProcAddress");
BGFX_FATAL(NULL != wglGetProcAddress, Fatal::UnableToInitialize, "Failed get wglGetProcAddress.");


Expand Down Expand Up @@ -136,13 +136,13 @@ namespace bgfx { namespace gl

if (NULL != g_platformData.nwh && NULL == g_platformData.context )
{
wglMakeCurrent = BGFX_CAST_FUNCTION(PFNWGLMAKECURRENTPROC, bx::dlsym(m_opengl32dll, "wglMakeCurrent"));
wglMakeCurrent = bx::functionCast<PFNWGLMAKECURRENTPROC>(bx::dlsym(m_opengl32dll, "wglMakeCurrent") );
BGFX_FATAL(NULL != wglMakeCurrent, Fatal::UnableToInitialize, "Failed get wglMakeCurrent.");

wglCreateContext = BGFX_CAST_FUNCTION(PFNWGLCREATECONTEXTPROC, bx::dlsym(m_opengl32dll, "wglCreateContext"));
wglCreateContext = bx::functionCast<PFNWGLCREATECONTEXTPROC>(bx::dlsym(m_opengl32dll, "wglCreateContext") );
BGFX_FATAL(NULL != wglCreateContext, Fatal::UnableToInitialize, "Failed get wglCreateContext.");

wglDeleteContext = BGFX_CAST_FUNCTION(PFNWGLDELETECONTEXTPROC, bx::dlsym(m_opengl32dll, "wglDeleteContext"));
wglDeleteContext = bx::functionCast<PFNWGLDELETECONTEXTPROC>(bx::dlsym(m_opengl32dll, "wglDeleteContext") );
BGFX_FATAL(NULL != wglDeleteContext, Fatal::UnableToInitialize, "Failed get wglDeleteContext.");

m_hdc = GetDC( (HWND)g_platformData.nwh);
Expand Down Expand Up @@ -171,10 +171,10 @@ namespace bgfx { namespace gl

HGLRC context = createContext(hdc);

wglGetExtensionsStringARB = BGFX_CAST_FUNCTION(PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetProcAddress("wglGetExtensionsStringARB"));
wglChoosePixelFormatARB = BGFX_CAST_FUNCTION(PFNWGLCHOOSEPIXELFORMATARBPROC, wglGetProcAddress("wglChoosePixelFormatARB"));
wglCreateContextAttribsARB = BGFX_CAST_FUNCTION(PFNWGLCREATECONTEXTATTRIBSARBPROC, wglGetProcAddress("wglCreateContextAttribsARB"));
wglSwapIntervalEXT = BGFX_CAST_FUNCTION(PFNWGLSWAPINTERVALEXTPROC, wglGetProcAddress("wglSwapIntervalEXT"));
wglGetExtensionsStringARB = bx::functionCast<PFNWGLGETEXTENSIONSSTRINGARBPROC>(wglGetProcAddress("wglGetExtensionsStringARB") );
wglChoosePixelFormatARB = bx::functionCast<PFNWGLCHOOSEPIXELFORMATARBPROC>(wglGetProcAddress("wglChoosePixelFormatARB") );
wglCreateContextAttribsARB = bx::functionCast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB") );
wglSwapIntervalEXT = bx::functionCast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT") );

if (NULL != wglGetExtensionsStringARB)
{
Expand Down Expand Up @@ -387,24 +387,30 @@ namespace bgfx { namespace gl
void GlContext::import()
{
BX_TRACE("Import:");
# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \
if (NULL == _func) \
{ \
_func = BGFX_CAST_FUNCTION(_proto, wglGetProcAddress(#_import)); \
if (_func == NULL) \
{ \
_func = BGFX_CAST_FUNCTION(_proto, bx::dlsym(m_opengl32dll, #_import)); \
BX_TRACE(" %p " #_func " (" #_import ")", _func); \
} \
else \
{ \
BX_TRACE("wgl %p " #_func " (" #_import ")", _func); \
} \
BGFX_FATAL(BX_IGNORE_C4127(_optional) || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_import); \
} \
}

# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \
if (NULL == _func) \
{ \
_func = bx::functionCast<_proto>(wglGetProcAddress(#_import); \
if (_func == NULL) \
{ \
_func = bx::functionCast<_proto>(bx::dlsym(m_opengl32dll, #_import); \
BX_TRACE(" %p " #_func " (" #_import ")", _func); \
} \
else \
{ \
BX_TRACE("wgl %p " #_func " (" #_import ")", _func); \
} \
BGFX_FATAL(BX_IGNORE_C4127(_optional) || NULL != _func \
, Fatal::UnableToInitialize \
, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_import); \
} \
}

# include "glimports.h"

# undef GL_EXTENSION
}

} } // namespace bgfx
Expand Down

0 comments on commit 8f4750b

Please sign in to comment.