This commit is contained in:
Бранимир Караџић 2020-09-02 20:43:47 -07:00
parent 0093a67681
commit 8f4750b199
6 changed files with 116 additions and 73 deletions

View File

@ -6,7 +6,7 @@ os:
environment: environment:
matrix: matrix:
- TOOLSET: vs2017 - TOOLSET: vs2017
- TOOLSET: vs2019 # - TOOLSET: vs2019
configuration: configuration:
- Debug - Debug

View File

@ -44,8 +44,6 @@
, _handleAlloc.getMaxHandles() \ , _handleAlloc.getMaxHandles() \
) )
#define BGFX_CAST_FUNCTION(proto, func) ((proto)(void(*)(void))func)
#if BGFX_CONFIG_MULTITHREADED #if BGFX_CONFIG_MULTITHREADED
# define BGFX_MUTEX_SCOPE(_mutex) bx::MutexScope BX_CONCATENATE(mutexScope, __LINE__)(_mutex) # define BGFX_MUTEX_SCOPE(_mutex) bx::MutexScope BX_CONCATENATE(mutexScope, __LINE__)(_mutex)
#else #else

View File

@ -444,30 +444,41 @@ EGL_IMPORT
void GlContext::import() void GlContext::import()
{ {
BX_TRACE("Import:"); BX_TRACE("Import:");
# if BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX # if BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX
void* glesv2 = bx::dlopen("libGLESv2." BX_DL_EXT); void* glesv2 = bx::dlopen("libGLESv2." BX_DL_EXT);
# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \ # define GL_EXTENSION(_optional, _proto, _func, _import) \
if (NULL == _func) \ { \
{ \ if (NULL == _func) \
_func = BGFX_CAST_FUNCTION(_proto, bx::dlsym(glesv2, #_import)); \ { \
BX_TRACE("\t%p " #_func " (" #_import ")", _func); \ _func = bx::functionCast<_proto>(bx::dlsym(glesv2, #_import)); \
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_import); \ BX_TRACE("\t%p " #_func " (" #_import ")", _func); \
} \ BGFX_FATAL(_optional || NULL != _func \
, Fatal::UnableToInitialize \
, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")" \
, #_import); \
} \
} }
# else # else
# define GL_EXTENSION(_optional, _proto, _func, _import) \ # define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \ { \
if (NULL == _func) \ if (NULL == _func) \
{ \ { \
_func = BGFX_CAST_FUNCTION(_proto , eglGetProcAddress(#_import)); \ _func = bx::functionCast<_proto>(eglGetProcAddress(#_import) ); \
BX_TRACE("\t%p " #_func " (" #_import ")", _func); \ BX_TRACE("\t%p " #_func " (" #_import ")", _func); \
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")", #_import); \ BGFX_FATAL(_optional || NULL != _func \
} \ , Fatal::UnableToInitialize \
, "Failed to create OpenGLES context. eglGetProcAddress(\"%s\")" \
, #_import); \
} \
} }
# endif // BX_PLATFORM_ # endif // BX_PLATFORM_
# include "glimports.h" # include "glimports.h"
# undef GL_EXTENSION
} }
} /* namespace gl */ } // namespace bgfx } /* namespace gl */ } // namespace bgfx

View File

@ -66,7 +66,7 @@ namespace bgfx { namespace gl
for(;;) for(;;)
{ {
bx::StringView found = bx::strFind(searchStart, _ext); bx::StringView found = bx::strFind(searchStart, _ext);
if (found.isEmpty()) if (found.isEmpty() )
{ {
return false; return false;
} }
@ -74,7 +74,7 @@ namespace bgfx { namespace gl
// We found the substring, but need an exact match, with a word // We found the substring, but need an exact match, with a word
// boundary at both the front and back of the found spot. // boundary at both the front and back of the found spot.
if ((found.getPtr() == _extList || *(found.getPtr() - 1) == ' ') if ((found.getPtr() == _extList || *(found.getPtr() - 1) == ' ')
&& (found.getTerm() == end || *found.getTerm() == ' ')) && (found.getTerm() == end || *found.getTerm() == ' ') )
{ {
return true; return true;
} }
@ -222,12 +222,16 @@ namespace bgfx { namespace gl
glXMakeCurrent(m_display, (::Window)g_platformData.nwh, m_context); glXMakeCurrent(m_display, (::Window)g_platformData.nwh, m_context);
m_current = NULL; m_current = NULL;
const char* extensions = glXQueryExtensionsString(m_display, DefaultScreen(m_display)); const char* extensions = glXQueryExtensionsString(m_display, DefaultScreen(m_display) );
if (NULL != extensions) if (NULL != extensions)
{ {
bool foundSwapControl = false; 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) if (NULL != glXSwapIntervalEXT)
{ {
BX_TRACE("Using glXSwapIntervalEXT."); BX_TRACE("Using glXSwapIntervalEXT.");
@ -235,8 +239,12 @@ namespace bgfx { namespace gl
foundSwapControl = true; 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) if (NULL != glXSwapIntervalMESA)
{ {
BX_TRACE("Using glXSwapIntervalMESA."); BX_TRACE("Using glXSwapIntervalMESA.");
@ -244,8 +252,12 @@ namespace bgfx { namespace gl
foundSwapControl = true; 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) if (NULL != glXSwapIntervalSGI)
{ {
BX_TRACE("Using glXSwapIntervalSGI."); BX_TRACE("Using glXSwapIntervalSGI.");
@ -348,16 +360,23 @@ namespace bgfx { namespace gl
void GlContext::import() void GlContext::import()
{ {
# define GL_EXTENSION(_optional, _proto, _func, _import) \ BX_TRACE("Import:");
{ \
if (NULL == _func) \ # define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \ { \
_func = BGFX_CAST_FUNCTION(_proto, glXGetProcAddress( (const GLubyte*)#_import)); \ if (NULL == _func) \
BX_TRACE("%p " #_func " (" #_import ")", _func); \ { \
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create OpenGL context. glXGetProcAddress %s", #_import); \ _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" # include "glimports.h"
# undef GL_EXTENSION
} }
} /* namespace gl */ } // namespace bgfx } /* namespace gl */ } // namespace bgfx

View File

@ -182,19 +182,28 @@ namespace bgfx { namespace gl
void GlContext::import(int webGLVersion) void GlContext::import(int webGLVersion)
{ {
BX_TRACE("Import:"); BX_TRACE("Import:");
# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \ # define GL_EXTENSION(_optional, _proto, _func, _import) \
if (NULL == _func) \ { \
{ \ if (NULL == _func) \
_func = (_proto)emscripten_webgl1_get_proc_address(#_import); \ { \
if (!_func && webGLVersion >= 2) \ _func = (_proto)emscripten_webgl1_get_proc_address(#_import); \
_func = BGFX_CAST_FUNCTION(_proto, emscripten_webgl2_get_proc_address(#_import)); \ if (!_func && webGLVersion >= 2) \
BX_TRACE("\t%p " #_func " (" #_import ")", _func); \ { \
BGFX_FATAL(_optional || NULL != _func, Fatal::UnableToInitialize, "Failed to create WebGL/OpenGLES context. GetProcAddress(\"%s\")", #_import); \ _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" # include "glimports.h"
# undef GL_EXTENSION
} }
} /* namespace gl */ } // namespace bgfx } /* namespace gl */ } // namespace bgfx

View File

@ -106,7 +106,7 @@ namespace bgfx { namespace gl
m_opengl32dll = bx::dlopen("opengl32.dll"); m_opengl32dll = bx::dlopen("opengl32.dll");
BGFX_FATAL(NULL != m_opengl32dll, Fatal::UnableToInitialize, "Failed to load 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."); 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 ) 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."); 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."); 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."); BGFX_FATAL(NULL != wglDeleteContext, Fatal::UnableToInitialize, "Failed get wglDeleteContext.");
m_hdc = GetDC( (HWND)g_platformData.nwh); m_hdc = GetDC( (HWND)g_platformData.nwh);
@ -171,10 +171,10 @@ namespace bgfx { namespace gl
HGLRC context = createContext(hdc); HGLRC context = createContext(hdc);
wglGetExtensionsStringARB = BGFX_CAST_FUNCTION(PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetProcAddress("wglGetExtensionsStringARB")); wglGetExtensionsStringARB = bx::functionCast<PFNWGLGETEXTENSIONSSTRINGARBPROC>(wglGetProcAddress("wglGetExtensionsStringARB") );
wglChoosePixelFormatARB = BGFX_CAST_FUNCTION(PFNWGLCHOOSEPIXELFORMATARBPROC, wglGetProcAddress("wglChoosePixelFormatARB")); wglChoosePixelFormatARB = bx::functionCast<PFNWGLCHOOSEPIXELFORMATARBPROC>(wglGetProcAddress("wglChoosePixelFormatARB") );
wglCreateContextAttribsARB = BGFX_CAST_FUNCTION(PFNWGLCREATECONTEXTATTRIBSARBPROC, wglGetProcAddress("wglCreateContextAttribsARB")); wglCreateContextAttribsARB = bx::functionCast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB") );
wglSwapIntervalEXT = BGFX_CAST_FUNCTION(PFNWGLSWAPINTERVALEXTPROC, wglGetProcAddress("wglSwapIntervalEXT")); wglSwapIntervalEXT = bx::functionCast<PFNWGLSWAPINTERVALEXTPROC>(wglGetProcAddress("wglSwapIntervalEXT") );
if (NULL != wglGetExtensionsStringARB) if (NULL != wglGetExtensionsStringARB)
{ {
@ -387,24 +387,30 @@ namespace bgfx { namespace gl
void GlContext::import() void GlContext::import()
{ {
BX_TRACE("Import:"); BX_TRACE("Import:");
# define GL_EXTENSION(_optional, _proto, _func, _import) \
{ \ # define GL_EXTENSION(_optional, _proto, _func, _import) \
if (NULL == _func) \ { \
{ \ if (NULL == _func) \
_func = BGFX_CAST_FUNCTION(_proto, wglGetProcAddress(#_import)); \ { \
if (_func == NULL) \ _func = bx::functionCast<_proto>(wglGetProcAddress(#_import); \
{ \ if (_func == NULL) \
_func = BGFX_CAST_FUNCTION(_proto, bx::dlsym(m_opengl32dll, #_import)); \ { \
BX_TRACE(" %p " #_func " (" #_import ")", _func); \ _func = bx::functionCast<_proto>(bx::dlsym(m_opengl32dll, #_import); \
} \ BX_TRACE(" %p " #_func " (" #_import ")", _func); \
else \ } \
{ \ else \
BX_TRACE("wgl %p " #_func " (" #_import ")", _func); \ { \
} \ 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); \ } \
} \ BGFX_FATAL(BX_IGNORE_C4127(_optional) || NULL != _func \
} , Fatal::UnableToInitialize \
, "Failed to create OpenGL context. wglGetProcAddress(\"%s\")", #_import); \
} \
}
# include "glimports.h" # include "glimports.h"
# undef GL_EXTENSION
} }
} } // namespace bgfx } } // namespace bgfx