Changeset View
Changeset View
Standalone View
Standalone View
source/renderer/backend/gl/Device.cpp
Show All 23 Lines | |||||
#include "ps/CLogger.h" | #include "ps/CLogger.h" | ||||
#include "scriptinterface/JSON.h" | #include "scriptinterface/JSON.h" | ||||
#include "scriptinterface/Object.h" | #include "scriptinterface/Object.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "scriptinterface/ScriptRequest.h" | #include "scriptinterface/ScriptRequest.h" | ||||
#if OS_WIN | #if OS_WIN | ||||
#include "lib/sysdep/os/win/wgfx.h" | #include "lib/sysdep/os/win/wgfx.h" | ||||
// We can't include wutil directly because GL headers conflict with Windows | |||||
// until we use a proper GL loader. | |||||
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. | // TODO: Support OpenGL platforms which don't use GLX as well. | ||||
#if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | #if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | |||||
// static | // static | ||||
std::unique_ptr<CDevice> CDevice::Create(SDL_Window* window) | std::unique_ptr<CDevice> CDevice::Create(SDL_Window* window) | ||||
{ | { | ||||
std::unique_ptr<CDevice> device(new CDevice()); | std::unique_ptr<CDevice> device(new CDevice()); | ||||
if (window) | if (window) | ||||
{ | { | ||||
device->m_Window = window; | device->m_Context = SDL_GL_CreateContext(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 | |||||
ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC()); | |||||
#elif defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | |||||
ogl_Init(SDL_GL_GetProcAddress, GetX11Display(m_Window)); | |||||
#else | |||||
ogl_Init(SDL_GL_GetProcAddress); | |||||
#endif | |||||
} | } | ||||
else | |||||
{ | |||||
// SDL_GL_GetProcAddress is available because we called SDL_GL_LoadLibrary | |||||
#if OS_WIN | |||||
ogl_Init(SDL_GL_GetProcAddress, wutil_GetAppHDC()); | |||||
#elif defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | |||||
ogl_Init(SDL_GL_GetProcAddress, XOpenDisplay(NULL)); | |||||
#else | |||||
ogl_Init(SDL_GL_GetProcAddress); | |||||
#endif | |||||
ogl_Init(); | #if OS_WIN || defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | ||||
ogl_SetVsyncEnabled(true); | |||||
#endif | |||||
} | |||||
if ((ogl_HaveExtensions(0, "GL_ARB_vertex_program", "GL_ARB_fragment_program", nullptr) // ARB | if ((ogl_HaveExtensions(0, "GL_ARB_vertex_program", "GL_ARB_fragment_program", nullptr) // ARB | ||||
&& ogl_HaveExtensions(0, "GL_ARB_vertex_shader", "GL_ARB_fragment_shader", nullptr)) // GLSL | && ogl_HaveExtensions(0, "GL_ARB_vertex_shader", "GL_ARB_fragment_shader", nullptr)) // GLSL | ||||
|| !ogl_HaveExtension("GL_ARB_vertex_buffer_object") // VBO | || !ogl_HaveExtension("GL_ARB_vertex_buffer_object") // VBO | ||||
|| ogl_HaveExtensions(0, "GL_ARB_multitexture", "GL_EXT_draw_range_elements", nullptr) | || ogl_HaveExtensions(0, "GL_ARB_multitexture", "GL_EXT_draw_range_elements", nullptr) | ||||
|| (!ogl_HaveExtension("GL_EXT_framebuffer_object") && !ogl_HaveExtension("GL_ARB_framebuffer_object"))) | || (!ogl_HaveExtension("GL_EXT_framebuffer_object") && !ogl_HaveExtension("GL_ARB_framebuffer_object"))) | ||||
{ | { | ||||
// It doesn't make sense to continue working here, because we're not | // It doesn't make sense to continue working here, because we're not | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | #define STRING(id) do { \ | ||||
const char* c = (const char*)glGetString(GL_##id); \ | const char* c = (const char*)glGetString(GL_##id); \ | ||||
if (!c) c = ""; \ | if (!c) c = ""; \ | ||||
if (ogl_SquelchError(GL_INVALID_ENUM)) c = errstr; \ | if (ogl_SquelchError(GL_INVALID_ENUM)) c = errstr; \ | ||||
Script::SetProperty(rq, settings, "GL_" #id, std::string(c)); \ | Script::SetProperty(rq, settings, "GL_" #id, std::string(c)); \ | ||||
} while (false) | } while (false) | ||||
#define QUERY(target, pname) do { \ | #define QUERY(target, pname) do { \ | ||||
GLint i = -1; \ | GLint i = -1; \ | ||||
pglGetQueryivARB(GL_##target, GL_##pname, &i); \ | glGetQueryivARB(GL_##target, GL_##pname, &i); \ | ||||
if (ogl_SquelchError(GL_INVALID_ENUM)) \ | if (ogl_SquelchError(GL_INVALID_ENUM)) \ | ||||
Script::SetProperty(rq, settings, "GL_" #target ".GL_" #pname, errstr); \ | Script::SetProperty(rq, settings, "GL_" #target ".GL_" #pname, errstr); \ | ||||
else \ | else \ | ||||
Script::SetProperty(rq, settings, "GL_" #target ".GL_" #pname, i); \ | Script::SetProperty(rq, settings, "GL_" #target ".GL_" #pname, i); \ | ||||
} while (false) | } while (false) | ||||
#define VERTEXPROGRAM(id) do { \ | #define VERTEXPROGRAM(id) do { \ | ||||
GLint i = -1; \ | GLint i = -1; \ | ||||
pglGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_##id, &i); \ | glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_##id, &i); \ | ||||
if (ogl_SquelchError(GL_INVALID_ENUM)) \ | if (ogl_SquelchError(GL_INVALID_ENUM)) \ | ||||
Script::SetProperty(rq, settings, "GL_VERTEX_PROGRAM_ARB.GL_" #id, errstr); \ | Script::SetProperty(rq, settings, "GL_VERTEX_PROGRAM_ARB.GL_" #id, errstr); \ | ||||
else \ | else \ | ||||
Script::SetProperty(rq, settings, "GL_VERTEX_PROGRAM_ARB.GL_" #id, i); \ | Script::SetProperty(rq, settings, "GL_VERTEX_PROGRAM_ARB.GL_" #id, i); \ | ||||
} while (false) | } while (false) | ||||
#define FRAGMENTPROGRAM(id) do { \ | #define FRAGMENTPROGRAM(id) do { \ | ||||
GLint i = -1; \ | GLint i = -1; \ | ||||
pglGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_##id, &i); \ | glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_##id, &i); \ | ||||
if (ogl_SquelchError(GL_INVALID_ENUM)) \ | if (ogl_SquelchError(GL_INVALID_ENUM)) \ | ||||
Script::SetProperty(rq, settings, "GL_FRAGMENT_PROGRAM_ARB.GL_" #id, errstr); \ | Script::SetProperty(rq, settings, "GL_FRAGMENT_PROGRAM_ARB.GL_" #id, errstr); \ | ||||
else \ | else \ | ||||
Script::SetProperty(rq, settings, "GL_FRAGMENT_PROGRAM_ARB.GL_" #id, i); \ | Script::SetProperty(rq, settings, "GL_FRAGMENT_PROGRAM_ARB.GL_" #id, i); \ | ||||
} while (false) | } while (false) | ||||
#define BOOL(id) INTEGER(id) | #define BOOL(id) INTEGER(id) | ||||
▲ Show 20 Lines • Show All 237 Lines • ▼ Show 20 Lines | |||||
#endif // CONFIG2_GLES | #endif // CONFIG2_GLES | ||||
// TODO: Support OpenGL platforms which don't use GLX as well. | // TODO: Support OpenGL platforms which don't use GLX as well. | ||||
#if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | #if defined(SDL_VIDEO_DRIVER_X11) && !CONFIG2_GLES | ||||
#define GLXQCR_INTEGER(id) do { \ | #define GLXQCR_INTEGER(id) do { \ | ||||
unsigned int i = UINT_MAX; \ | unsigned int i = UINT_MAX; \ | ||||
if (pglXQueryCurrentRendererIntegerMESA(id, &i)) \ | if (glXQueryCurrentRendererIntegerMESA(id, &i)) \ | ||||
Script::SetProperty(rq, settings, #id, i); \ | Script::SetProperty(rq, settings, #id, i); \ | ||||
} while (false) | } while (false) | ||||
#define GLXQCR_INTEGER2(id) do { \ | #define GLXQCR_INTEGER2(id) do { \ | ||||
unsigned int i[2] = { UINT_MAX, UINT_MAX }; \ | unsigned int i[2] = { UINT_MAX, UINT_MAX }; \ | ||||
if (pglXQueryCurrentRendererIntegerMESA(id, i)) { \ | if (glXQueryCurrentRendererIntegerMESA(id, i)) { \ | ||||
Script::SetProperty(rq, settings, #id "[0]", i[0]); \ | Script::SetProperty(rq, settings, #id "[0]", i[0]); \ | ||||
Script::SetProperty(rq, settings, #id "[1]", i[1]); \ | Script::SetProperty(rq, settings, #id "[1]", i[1]); \ | ||||
} \ | } \ | ||||
} while (false) | } while (false) | ||||
#define GLXQCR_INTEGER3(id) do { \ | #define GLXQCR_INTEGER3(id) do { \ | ||||
unsigned int i[3] = { UINT_MAX, UINT_MAX, UINT_MAX }; \ | unsigned int i[3] = { UINT_MAX, UINT_MAX, UINT_MAX }; \ | ||||
if (pglXQueryCurrentRendererIntegerMESA(id, i)) { \ | if (glXQueryCurrentRendererIntegerMESA(id, i)) { \ | ||||
Script::SetProperty(rq, settings, #id "[0]", i[0]); \ | Script::SetProperty(rq, settings, #id "[0]", i[0]); \ | ||||
Script::SetProperty(rq, settings, #id "[1]", i[1]); \ | Script::SetProperty(rq, settings, #id "[1]", i[1]); \ | ||||
Script::SetProperty(rq, settings, #id "[2]", i[2]); \ | Script::SetProperty(rq, settings, #id "[2]", i[2]); \ | ||||
} \ | } \ | ||||
} while (false) | } while (false) | ||||
#define GLXQCR_STRING(id) do { \ | #define GLXQCR_STRING(id) do { \ | ||||
const char* str = pglXQueryCurrentRendererStringMESA(id); \ | const char* str = glXQueryCurrentRendererStringMESA(id); \ | ||||
if (str) \ | if (str) \ | ||||
Script::SetProperty(rq, settings, #id ".string", str); \ | Script::SetProperty(rq, settings, #id ".string", str); \ | ||||
} while (false) | } while (false) | ||||
SDL_SysWMinfo wminfo; | SDL_SysWMinfo wminfo; | ||||
SDL_VERSION(&wminfo.version); | SDL_VERSION(&wminfo.version); | ||||
const int ret = SDL_GetWindowWMInfo(m_Window, &wminfo); | const int ret = SDL_GetWindowWMInfo(m_Window, &wminfo); | ||||
if (ret && wminfo.subsystem == SDL_SYSWM_X11) | if (ret && wminfo.subsystem == SDL_SYSWM_X11) | ||||
{ | { | ||||
Display* dpy = wminfo.info.x11.display; | Display* dpy = wminfo.info.x11.display; | ||||
int scrnum = DefaultScreen(dpy); | int scrnum = DefaultScreen(dpy); | ||||
const char* glxexts = glXQueryExtensionsString(dpy, scrnum); | const char* glxexts = glXQueryExtensionsString(dpy, scrnum); | ||||
Script::SetProperty(rq, settings, "glx_extensions", glxexts); | Script::SetProperty(rq, settings, "glx_extensions", glxexts); | ||||
if (strstr(glxexts, "GLX_MESA_query_renderer") && pglXQueryCurrentRendererIntegerMESA && pglXQueryCurrentRendererStringMESA) | if (strstr(glxexts, "GLX_MESA_query_renderer") && glXQueryCurrentRendererIntegerMESA && glXQueryCurrentRendererStringMESA) | ||||
{ | { | ||||
GLXQCR_INTEGER(GLX_RENDERER_VENDOR_ID_MESA); | GLXQCR_INTEGER(GLX_RENDERER_VENDOR_ID_MESA); | ||||
GLXQCR_INTEGER(GLX_RENDERER_DEVICE_ID_MESA); | GLXQCR_INTEGER(GLX_RENDERER_DEVICE_ID_MESA); | ||||
GLXQCR_INTEGER3(GLX_RENDERER_VERSION_MESA); | GLXQCR_INTEGER3(GLX_RENDERER_VERSION_MESA); | ||||
GLXQCR_INTEGER(GLX_RENDERER_ACCELERATED_MESA); | GLXQCR_INTEGER(GLX_RENDERER_ACCELERATED_MESA); | ||||
GLXQCR_INTEGER(GLX_RENDERER_VIDEO_MEMORY_MESA); | GLXQCR_INTEGER(GLX_RENDERER_VIDEO_MEMORY_MESA); | ||||
GLXQCR_INTEGER(GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA); | GLXQCR_INTEGER(GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA); | ||||
GLXQCR_INTEGER(GLX_RENDERER_PREFERRED_PROFILE_MESA); | GLXQCR_INTEGER(GLX_RENDERER_PREFERRED_PROFILE_MESA); | ||||
Show All 16 Lines |
Wildfire Games · Phabricator