From 8f4750b19924d1144f7472987c08025bcd8dfd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Wed, 2 Sep 2020 20:43:47 -0700 Subject: [PATCH] Cleanup. --- .appveyor.yml | 2 +- src/bgfx_p.h | 2 -- src/glcontext_egl.cpp | 43 +++++++++++++++++++------------ src/glcontext_glx.cpp | 55 +++++++++++++++++++++++++++------------- src/glcontext_html5.cpp | 31 +++++++++++++++-------- src/glcontext_wgl.cpp | 56 +++++++++++++++++++++++------------------ 6 files changed, 116 insertions(+), 73 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 017010f81..117172f61 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -6,7 +6,7 @@ os: environment: matrix: - TOOLSET: vs2017 - - TOOLSET: vs2019 +# - TOOLSET: vs2019 configuration: - Debug diff --git a/src/bgfx_p.h b/src/bgfx_p.h index d03462dcd..17f0a1aa6 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -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 diff --git a/src/glcontext_egl.cpp b/src/glcontext_egl.cpp index 57549fe87..e0b2782e2 100644 --- a/src/glcontext_egl.cpp +++ b/src/glcontext_egl.cpp @@ -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 diff --git a/src/glcontext_glx.cpp b/src/glcontext_glx.cpp index 4f57840bd..2327cb03e 100644 --- a/src/glcontext_glx.cpp +++ b/src/glcontext_glx.cpp @@ -66,7 +66,7 @@ namespace bgfx { namespace gl for(;;) { bx::StringView found = bx::strFind(searchStart, _ext); - if (found.isEmpty()) + if (found.isEmpty() ) { return false; } @@ -74,7 +74,7 @@ namespace bgfx { namespace gl // 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; } @@ -222,12 +222,16 @@ 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(glXGetProcAddress( (const GLubyte*)"glXSwapIntervalEXT") ); + if (NULL != glXSwapIntervalEXT) { BX_TRACE("Using glXSwapIntervalEXT."); @@ -235,8 +239,12 @@ namespace bgfx { namespace gl 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(glXGetProcAddress( (const GLubyte*)"glXSwapIntervalMESA") ); + if (NULL != glXSwapIntervalMESA) { BX_TRACE("Using glXSwapIntervalMESA."); @@ -244,8 +252,12 @@ namespace bgfx { namespace gl 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(glXGetProcAddress( (const GLubyte*)"glXSwapIntervalSGI") ); + if (NULL != glXSwapIntervalSGI) { BX_TRACE("Using glXSwapIntervalSGI."); @@ -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 diff --git a/src/glcontext_html5.cpp b/src/glcontext_html5.cpp index eb4de60b4..473512d95 100644 --- a/src/glcontext_html5.cpp +++ b/src/glcontext_html5.cpp @@ -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 diff --git a/src/glcontext_wgl.cpp b/src/glcontext_wgl.cpp index 4b466b54b..47465f9bf 100644 --- a/src/glcontext_wgl.cpp +++ b/src/glcontext_wgl.cpp @@ -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(bx::dlsym(m_opengl32dll, "wglGetProcAddress"); BGFX_FATAL(NULL != wglGetProcAddress, Fatal::UnableToInitialize, "Failed get wglGetProcAddress."); @@ -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(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(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(bx::dlsym(m_opengl32dll, "wglDeleteContext") ); BGFX_FATAL(NULL != wglDeleteContext, Fatal::UnableToInitialize, "Failed get wglDeleteContext."); m_hdc = GetDC( (HWND)g_platformData.nwh); @@ -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(wglGetProcAddress("wglGetExtensionsStringARB") ); + wglChoosePixelFormatARB = bx::functionCast(wglGetProcAddress("wglChoosePixelFormatARB") ); + wglCreateContextAttribsARB = bx::functionCast(wglGetProcAddress("wglCreateContextAttribsARB") ); + wglSwapIntervalEXT = bx::functionCast(wglGetProcAddress("wglSwapIntervalEXT") ); if (NULL != wglGetExtensionsStringARB) { @@ -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