Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/renderer/backend/gl/Device.cpp
Show All 37 Lines | |||||
// until we use a proper GL loader. | // until we use a proper GL loader. | ||||
extern void* wutil_GetAppHDC(); | extern void* wutil_GetAppHDC(); | ||||
#endif | #endif | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <boost/algorithm/string/classification.hpp> | #include <boost/algorithm/string/classification.hpp> | ||||
#include <boost/algorithm/string/split.hpp> | #include <boost/algorithm/string/split.hpp> | ||||
// TODO: Support OpenGL platforms which don't use GLX as well. | #if !CONFIG2_GLES && (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)) | ||||
#if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | |||||
#if defined(SDL_VIDEO_DRIVER_X11) | |||||
#include <glad/glx.h> | #include <glad/glx.h> | ||||
#include <SDL_syswm.h> | |||||
#endif | #endif | ||||
#if defined(SDL_VIDEO_DRIVER_WAYLAND) | |||||
#include <glad/egl.h> | |||||
#endif | |||||
#include <SDL_syswm.h> | |||||
#endif // !CONFIG2_GLES && (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)) | |||||
namespace Renderer | namespace Renderer | ||||
{ | { | ||||
namespace Backend | namespace Backend | ||||
{ | { | ||||
namespace GL | namespace GL | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | if (window) | ||||
device->m_Context = SDL_GL_CreateContext(device->m_Window); | device->m_Context = SDL_GL_CreateContext(device->m_Window); | ||||
if (!device->m_Context) | if (!device->m_Context) | ||||
{ | { | ||||
LOGERROR("SDL_GL_CreateContext failed: '%s'", SDL_GetError()); | LOGERROR("SDL_GL_CreateContext failed: '%s'", SDL_GetError()); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
#if OS_WIN | #if OS_WIN | ||||
ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC()); | ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC()); | ||||
#elif defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | #elif (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)) && !CONFIG2_GLES | ||||
ogl_Init(SDL_GL_GetProcAddress, GetX11Display(device->m_Window)); | SDL_SysWMinfo wminfo; | ||||
// The info structure must be initialized with the SDL version. | |||||
SDL_VERSION(&wminfo.version); | |||||
if (!SDL_GetWindowWMInfo(window, &wminfo)) | |||||
{ | |||||
LOGERROR("Failed to query SDL WM info: %s", SDL_GetError()); | |||||
return nullptr; | |||||
} | |||||
switch (wminfo.subsystem) | |||||
{ | |||||
#if defined(SDL_VIDEO_DRIVER_WAYLAND) | |||||
case SDL_SYSWM_WAYLAND: | |||||
// TODO: maybe we need to load X11 functions | |||||
// dynamically as well. | |||||
ogl_Init(SDL_GL_GetProcAddress, | |||||
GetWaylandDisplay(device->m_Window), | |||||
static_cast<int>(wminfo.subsystem)); | |||||
break; | |||||
#endif | |||||
#if defined(SDL_VIDEO_DRIVER_X11) | |||||
case SDL_SYSWM_X11: | |||||
ogl_Init(SDL_GL_GetProcAddress, | |||||
GetX11Display(device->m_Window), | |||||
static_cast<int>(wminfo.subsystem)); | |||||
break; | |||||
#endif | |||||
default: | |||||
ogl_Init(SDL_GL_GetProcAddress, nullptr, | |||||
static_cast<int>(wminfo.subsystem)); | |||||
break; | |||||
} | |||||
#else | #else | ||||
ogl_Init(SDL_GL_GetProcAddress); | ogl_Init(SDL_GL_GetProcAddress); | ||||
#endif | #endif | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
#if OS_WIN | #if OS_WIN | ||||
ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC()); | ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC()); | ||||
#elif defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | #elif (defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)) && !CONFIG2_GLES | ||||
ogl_Init(SDL_GL_GetProcAddress, XOpenDisplay(NULL)); | bool initialized = false; | ||||
// Currently we don't have access to the backend type without | |||||
// the window. So we use hack to detect X11. | |||||
#if defined(SDL_VIDEO_DRIVER_X11) | |||||
Display* display = XOpenDisplay(NULL); | |||||
if (display) | |||||
{ | |||||
ogl_Init(SDL_GL_GetProcAddress, display, static_cast<int>(SDL_SYSWM_X11)); | |||||
initialized = true; | |||||
} | |||||
#endif | |||||
#if defined(SDL_VIDEO_DRIVER_WAYLAND) | |||||
if (!initialized) | |||||
{ | |||||
// glad will find default EGLDisplay internally. | |||||
ogl_Init(SDL_GL_GetProcAddress, nullptr, static_cast<int>(SDL_SYSWM_WAYLAND)); | |||||
initialized = true; | |||||
} | |||||
#endif | |||||
if (!initialized) | |||||
{ | |||||
LOGERROR("Can't initialize GL"); | |||||
return nullptr; | |||||
} | |||||
#else | #else | ||||
ogl_Init(SDL_GL_GetProcAddress); | ogl_Init(SDL_GL_GetProcAddress); | ||||
#endif | #endif | ||||
#if OS_WIN || defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | #if OS_WIN || defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | ||||
// Hack to stop things looking very ugly when scrolling in Atlas. | // Hack to stop things looking very ugly when scrolling in Atlas. | ||||
ogl_SetVsyncEnabled(true); | ogl_SetVsyncEnabled(true); | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 682 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator