Changeset View
Changeset View
Standalone View
Standalone View
source/lib/ogl.cpp
Show All 25 Lines | |||||
#include "lib/code_annotation.h" | #include "lib/code_annotation.h" | ||||
#include "lib/config2.h" | #include "lib/config2.h" | ||||
#include "lib/debug.h" | #include "lib/debug.h" | ||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#if !CONFIG2_GLES | #if !CONFIG2_GLES | ||||
# if OS_WIN | # if OS_WIN | ||||
# include <glad/wgl.h> | # include <glad/wgl.h> | ||||
# elif !OS_MACOSX && !OS_MAC | # elif !OS_MACOSX && !OS_MAC | ||||
# include <SDL_syswm.h> | |||||
# if defined(SDL_VIDEO_DRIVER_X11) | |||||
# include <glad/glx.h> | # include <glad/glx.h> | ||||
# endif | # endif | ||||
# if defined(SDL_VIDEO_DRIVER_WAYLAND) | |||||
# include <glad/egl.h> | |||||
# endif | |||||
#endif | # endif | ||||
#endif // !CONFIG2_GLES | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <stdarg.h> | #include <stdarg.h> | ||||
//---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- | ||||
// extensions | // extensions | ||||
//---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- | ||||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Lines | for(;;) | ||||
p = end; | p = end; | ||||
} | } | ||||
} | } | ||||
static int GLVersion; | static int GLVersion; | ||||
#if OS_WIN | #if OS_WIN | ||||
static int WGLVersion; | static int WGLVersion; | ||||
#elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | #elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | ||||
#if defined(SDL_VIDEO_DRIVER_X11) | |||||
static int GLXVersion; | static int GLXVersion; | ||||
#endif | #endif | ||||
#if defined(SDL_VIDEO_DRIVER_WAYLAND) | |||||
static int EGLVersion; | |||||
Stan: Might trac that in userreport | |||||
#endif | |||||
#endif | |||||
bool ogl_HaveVersion(int major, int minor) | bool ogl_HaveVersion(int major, int minor) | ||||
{ | { | ||||
return GLAD_MAKE_VERSION(major, minor) <= GLVersion; | return GLAD_MAKE_VERSION(major, minor) <= GLVersion; | ||||
} | } | ||||
// check if all given extension strings (passed as const char* parameters, | // check if all given extension strings (passed as const char* parameters, | ||||
▲ Show 20 Lines • Show All 185 Lines • ▼ Show 20 Lines | |||||
//---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- | ||||
// feature and limit detect | // feature and limit detect | ||||
//---------------------------------------------------------------------------- | //---------------------------------------------------------------------------- | ||||
#if OS_WIN | #if OS_WIN | ||||
bool ogl_Init(void* (load)(const char*), void* hdc) | bool ogl_Init(void* (load)(const char*), void* hdc) | ||||
#elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | #elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | ||||
bool ogl_Init(void* (load)(const char*), void* display) | bool ogl_Init(void* (load)(const char*), void* display, int subsystem) | ||||
#else | #else | ||||
bool ogl_Init(void* (load)(const char*)) | bool ogl_Init(void* (load)(const char*)) | ||||
#endif | #endif | ||||
{ | { | ||||
GLADloadfunc loadFunc = reinterpret_cast<GLADloadfunc>(load); | GLADloadfunc loadFunc = reinterpret_cast<GLADloadfunc>(load); | ||||
if (!loadFunc) | if (!loadFunc) | ||||
return false; | return false; | ||||
Show All 13 Lines | |||||
# if OS_WIN | # if OS_WIN | ||||
WGLVersion = gladLoadWGL(reinterpret_cast<HDC>(hdc), loadFunc); | WGLVersion = gladLoadWGL(reinterpret_cast<HDC>(hdc), loadFunc); | ||||
if (!WGLVersion) | if (!WGLVersion) | ||||
{ | { | ||||
LOAD_ERROR("Failed to load WGL functions."); | LOAD_ERROR("Failed to load WGL functions."); | ||||
return false; | return false; | ||||
} | } | ||||
# elif !OS_MACOSX && !OS_MAC | # elif !OS_MACOSX && !OS_MAC | ||||
const SDL_SYSWM_TYPE sysWMType = static_cast<SDL_SYSWM_TYPE>(subsystem); | |||||
# if defined(SDL_VIDEO_DRIVER_X11) | |||||
if (sysWMType == SDL_SYSWM_X11) | |||||
{ | |||||
GLXVersion = gladLoadGLX(reinterpret_cast<Display*>(display), DefaultScreen(display), loadFunc); | GLXVersion = gladLoadGLX(reinterpret_cast<Display*>(display), DefaultScreen(display), loadFunc); | ||||
if (!GLXVersion) | if (!GLXVersion) | ||||
{ | { | ||||
LOAD_ERROR("Failed to load GLX functions."); | LOAD_ERROR("Failed to load GLX functions."); | ||||
return false; | return false; | ||||
} | } | ||||
} | |||||
# endif | |||||
# if defined(SDL_VIDEO_DRIVER_WAYLAND) | |||||
if (sysWMType == SDL_SYSWM_WAYLAND) | |||||
{ | |||||
// TODO: investiage do we need Wayland display to load EGL. | |||||
Not Done Inline Actionsinvestigate whether we need... Stan: investigate whether we need... | |||||
// Because without eglGetDisplay we can't get one. But the | |||||
// function is loaded inside gladLoadEGL. So maybe we need to | |||||
// call it twice. | |||||
EGLVersion = gladLoadEGL(nullptr, loadFunc); | |||||
Not Done Inline ActionsStan: Could be https://github.com/libsdl-org/SDL/issues/2710 or https://discourse.libsdl.org/t/sdl… | |||||
if (!EGLVersion) | |||||
{ | |||||
LOAD_ERROR("Failed to load EGL functions."); | |||||
return false; | |||||
} | |||||
} | |||||
# endif | |||||
# endif | # endif | ||||
#else | #else | ||||
GLVersion = gladLoadGLES2(loadFunc); | GLVersion = gladLoadGLES2(loadFunc); | ||||
if (!GLVersion) | if (!GLVersion) | ||||
{ | { | ||||
LOAD_ERROR("Failed to load GLES2 functions."); | LOAD_ERROR("Failed to load GLES2 functions."); | ||||
return false; | return false; | ||||
} | } | ||||
Show All 16 Lines | #undef LOAD_ERROR | ||||
enableDummyFunctions(); | enableDummyFunctions(); | ||||
return true; | return true; | ||||
} | } | ||||
void ogl_SetVsyncEnabled(bool enabled) | void ogl_SetVsyncEnabled(bool enabled) | ||||
{ | { | ||||
const int interval = enabled ? 1 : 0; | |||||
Done Inline ActionsMight trigger a warning on some compilers. Stan: Might trigger a warning on some compilers. | |||||
phositUnsubmitted Not Done Inline ActionsWith [[maybe_unused]] the #else blocks wouldn't be needed. phosit: With `[[maybe_unused]]` the `#else` blocks wouldn't be needed. | |||||
vladislavbelovAuthorUnsubmitted Done Inline ActionsI'm not sure about support of the attribute. vladislavbelov: I'm not sure about support of the attribute. | |||||
StanUnsubmitted Done Inline ActionsIIRC not supported by VS2017. At least it choked on it on some other patch. Maybe it was used in a different context. Stan: IIRC not supported by VS2017. At least it choked on it on some other patch. Maybe it was used… | |||||
phositUnsubmitted Not Done Inline ActionsThat was in another context: ranged-for. if we talk about the same. phosit: That was in another context: ranged-for. if we talk about the same. | |||||
#if !CONFIG2_GLES && OS_WIN | #if !CONFIG2_GLES && OS_WIN | ||||
int interval = enabled ? 1 : 0; | |||||
if (ogl_HaveExtension("WGL_EXT_swap_control")) | if (ogl_HaveExtension("WGL_EXT_swap_control")) | ||||
wglSwapIntervalEXT(interval); | wglSwapIntervalEXT(interval); | ||||
#elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | #elif !CONFIG2_GLES && !OS_MACOSX && !OS_MAC | ||||
int interval = enabled ? 1 : 0; | #if defined(SDL_VIDEO_DRIVER_X11) | ||||
if (ogl_HaveExtension("GLX_SGI_swap_control")) | if (GLXVersion && ogl_HaveExtension("GLX_SGI_swap_control")) | ||||
glXSwapIntervalSGI(interval); | glXSwapIntervalSGI(interval); | ||||
#else | #else | ||||
UNUSED2(enabled); | UNUSED2(interval); | ||||
#endif | |||||
#else | |||||
UNUSED2(interval); | |||||
#endif | #endif | ||||
} | } |
Wildfire Games · Phabricator
Might trac that in userreport