23 #if SDL_VIDEO_DRIVER_X11
30 #if SDL_VIDEO_OPENGL_GLX
36 #define DEFAULT_OPENGL "libGL.so"
37 #elif defined(__MACOSX__)
38 #define DEFAULT_OPENGL "/usr/X11R6/lib/libGL.1.dylib"
39 #elif defined(__QNXNTO__)
40 #define DEFAULT_OPENGL "libGL.so.3"
42 #define DEFAULT_OPENGL "libGL.so.1"
46 #define GLX_NONE_EXT 0x8000
49 #ifndef GLX_ARB_multisample
50 #define GLX_ARB_multisample
51 #define GLX_SAMPLE_BUFFERS_ARB 100000
52 #define GLX_SAMPLES_ARB 100001
55 #ifndef GLX_EXT_visual_rating
56 #define GLX_EXT_visual_rating
57 #define GLX_VISUAL_CAVEAT_EXT 0x20
58 #define GLX_NONE_EXT 0x8000
59 #define GLX_SLOW_VISUAL_EXT 0x8001
60 #define GLX_NON_CONFORMANT_VISUAL_EXT 0x800D
63 #ifndef GLX_EXT_visual_info
64 #define GLX_EXT_visual_info
65 #define GLX_X_VISUAL_TYPE_EXT 0x22
66 #define GLX_DIRECT_COLOR_EXT 0x8003
69 #ifndef GLX_ARB_create_context
70 #define GLX_ARB_create_context
71 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
72 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
73 #define GLX_CONTEXT_FLAGS_ARB 0x2094
74 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x0001
75 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
87 #ifndef GLX_ARB_create_context_profile
88 #define GLX_ARB_create_context_profile
89 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
90 #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
91 #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
94 #ifndef GLX_ARB_create_context_robustness
95 #define GLX_ARB_create_context_robustness
96 #define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
97 #define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
98 #define GLX_NO_RESET_NOTIFICATION_ARB 0x8261
99 #define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252
102 #ifndef GLX_EXT_create_context_es2_profile
103 #define GLX_EXT_create_context_es2_profile
104 #ifndef GLX_CONTEXT_ES2_PROFILE_BIT_EXT
105 #define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000002
109 #ifndef GLX_EXT_swap_control
110 #define GLX_SWAP_INTERVAL_EXT 0x20F1
111 #define GLX_MAX_SWAP_INTERVAL_EXT 0x20F2
114 #ifndef GLX_EXT_swap_control_tear
115 #define GLX_LATE_SWAPS_TEAR_EXT 0x20F3
118 #define OPENGL_REQUIRES_DLOPEN
119 #if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
121 #define GL_LoadObject(X) dlopen(X, (RTLD_NOW|RTLD_GLOBAL))
122 #define GL_LoadFunction dlsym
123 #define GL_UnloadObject dlclose
125 #define GL_LoadObject SDL_LoadObject
126 #define GL_LoadFunction SDL_LoadFunction
127 #define GL_UnloadObject SDL_UnloadObject
130 static void X11_GL_InitExtensions(
_THIS);
134 X11_GL_LoadLibrary(
_THIS,
const char *
path)
148 path = DEFAULT_OPENGL;
152 #if defined(OPENGL_REQUIRES_DLOPEN) && defined(SDL_LOADSO_DLOPEN)
172 (
Bool (*)(Display *,
int *,
int *))
173 GL_LoadFunction(handle,
"glXQueryExtension");
176 GL_LoadFunction(handle,
"glXGetProcAddressARB");
178 (XVisualInfo * (*)(Display *,
int,
int *))
179 X11_GL_GetProcAddress(
_this,
"glXChooseVisual");
182 X11_GL_GetProcAddress(
_this,
"glXCreateContext");
185 X11_GL_GetProcAddress(
_this,
"glXDestroyContext");
188 X11_GL_GetProcAddress(
_this,
"glXMakeCurrent");
191 X11_GL_GetProcAddress(
_this,
"glXSwapBuffers");
194 X11_GL_GetProcAddress(
_this,
"glXQueryDrawable");
202 return SDL_SetError(
"Could not retrieve OpenGL functions");
211 X11_GL_InitExtensions(
_this);
217 !
_this->
gl_data->HAS_GLX_EXT_create_context_es2_profile ) {
218 #if SDL_VIDEO_OPENGL_EGL
219 X11_GL_UnloadLibrary(
_this);
234 return X11_GLES_LoadLibrary(
_this,
NULL);
236 return SDL_SetError(
"SDL not configured with EGL support");
244 X11_GL_GetProcAddress(
_THIS,
const char *proc)
253 X11_GL_UnloadLibrary(
_THIS)
270 HasExtension(
const char *extension,
const char *extensions)
273 const char *where, *terminator;
277 if (where || *extension ==
'\0')
295 if (where == start || *(where - 1) ==
' ')
296 if (*terminator ==
' ' || *terminator ==
'\0')
305 X11_GL_InitExtensions(
_THIS)
308 int screen = DefaultScreen(display);
310 XSetWindowAttributes xattr;
313 const char *(*glXQueryExtensionsStringFunc) (Display *,
int);
314 const char *extensions;
316 vinfo = X11_GL_GetVisual(
_this, display, screen);
320 xattr.background_pixel = 0;
321 xattr.border_pixel = 0;
323 XCreateColormap(display, RootWindow(display, screen), vinfo->visual,
325 w = XCreateWindow(display, RootWindow(display, screen), 0, 0, 32, 32, 0,
326 vinfo->depth, InputOutput, vinfo->visual,
327 (CWBackPixel | CWBorderPixel | CWColormap), &xattr);
334 glXQueryExtensionsStringFunc =
335 (
const char *(*)(Display *,
int)) X11_GL_GetProcAddress(
_this,
336 "glXQueryExtensionsString");
337 if (glXQueryExtensionsStringFunc) {
338 extensions = glXQueryExtensionsStringFunc(display, screen);
345 if (HasExtension(
"GLX_EXT_swap_control", extensions)) {
348 X11_GL_GetProcAddress(
_this,
"glXSwapIntervalEXT");
349 if (HasExtension(
"GLX_EXT_swap_control_tear", extensions)) {
355 if (HasExtension(
"GLX_MESA_swap_control", extensions)) {
357 (
int(*)(
int)) X11_GL_GetProcAddress(
_this,
"glXSwapIntervalMESA");
360 "glXGetSwapIntervalMESA");
364 if (HasExtension(
"GLX_SGI_swap_control", extensions)) {
366 (
int (*)(
int)) X11_GL_GetProcAddress(
_this,
"glXSwapIntervalSGI");
370 if (HasExtension(
"GLX_EXT_visual_rating", extensions)) {
375 if (HasExtension(
"GLX_EXT_visual_info", extensions)) {
380 if (HasExtension(
"GLX_EXT_create_context_es2_profile", extensions)) {
396 X11_GL_GetAttributes(
_THIS, Display * display,
int screen,
int *
attribs,
int size,
Bool for_FBConfig)
399 const int MAX_ATTRIBUTES = 64;
498 X11_GL_GetVisual(
_THIS, Display * display,
int screen)
511 vinfo =
_this->
gl_data->glXChooseVisual(display, screen, attribs);
518 #ifndef GLXBadContext
519 #define GLXBadContext 0
521 #ifndef GLXBadFBConfig
522 #define GLXBadFBConfig 9
524 #ifndef GLXBadProfileARB
525 #define GLXBadProfileARB 13
527 static int (*handler) (Display *, XErrorEvent *) =
NULL;
528 static int errorBase = 0;
530 X11_GL_CreateContextErrorHandler(Display *
d, XErrorEvent *
e)
532 switch (e->error_code) {
540 (e->error_code == errorBase + GLXBadContext ||
541 e->error_code == errorBase + GLXBadFBConfig ||
542 e->error_code == errorBase + GLXBadProfileARB)) {
545 return (handler(d, e));
556 XWindowAttributes xattr;
557 XVisualInfo
v, *vinfo;
559 GLXContext context =
NULL, share_context;
565 share_context =
NULL;
569 XSync(display, False);
571 handler = XSetErrorHandler(X11_GL_CreateContextErrorHandler);
574 v.visualid = XVisualIDFromVisual(xattr.visual);
575 vinfo = XGetVisualInfo(display, VisualScreenMask | VisualIDMask, &v, &n);
582 _this->
gl_data->glXCreateContext(display, vinfo, share_context, True);
586 GLXContext temp_context =
611 attribs[iattr++] = 0;
614 glXCreateContextAttribs =
617 "glXCreateContextAttribsARB");
618 if (!glXCreateContextAttribs) {
620 context = temp_context;
634 (*)(Display *,
int,
const int *,
638 X11_GL_GetAttributes(
_this,display,screen,glxAttribs,64,
SDL_TRUE);
640 if (!glXChooseFBConfig
641 || !(framebuffer_config =
643 DefaultScreen(display), glxAttribs,
646 (
"No good framebuffers found. GL 3.x disabled");
647 context = temp_context;
650 glXCreateContextAttribs(display,
651 framebuffer_config[0],
652 share_context, True, attribs);
661 XSync(display, False);
662 XSetErrorHandler(handler);
669 if (X11_GL_MakeCurrent(
_this, window, context) < 0) {
670 X11_GL_DeleteContext(
_this, context);
683 GLXContext glx_context = (
GLXContext) context;
689 if (!
_this->
gl_data->glXMakeCurrent(display, drawable, glx_context)) {
690 return SDL_SetError(
"Unable to make GL context current");
706 X11_GL_SetSwapInterval(
_THIS,
int interval)
710 if ((interval < 0) && (!
_this->
gl_data->HAS_GLX_EXT_swap_control_tear)) {
711 SDL_SetError(
"Negative swap interval unsupported in this GL");
717 Window drawable = windowdata->
xwindow;
727 int currentInterval = X11_GL_GetSwapInterval(
_this);
728 _this->
gl_data->glXSwapIntervalEXT(display, drawable, currentInterval);
729 _this->
gl_data->glXSwapIntervalEXT(display, drawable, interval);
732 swapinterval = interval;
738 swapinterval = interval;
745 swapinterval = interval;
754 X11_GL_GetSwapInterval(
_THIS)
760 Window drawable = windowdata->
xwindow;
761 unsigned int allow_late_swap_tearing = 0;
762 unsigned int interval = 0;
767 &allow_late_swap_tearing);
773 if ((allow_late_swap_tearing) && (interval > 0)) {
774 return -((
int) interval);
777 return (
int) interval;
798 GLXContext glx_context = (
GLXContext) context;
803 _this->
gl_data->glXDestroyContext(display, glx_context);
804 XSync(display, False);
void X11_PumpEvents(_THIS)
GLXContext(* PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list)
#define GLX_SWAP_INTERVAL_EXT
#define GLX_SLOW_VISUAL_EXT
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size)
struct __GLXcontextRec * GLXContext
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
#define GLX_ACCUM_GREEN_SIZE
#define glXGetProcAddress
return Display return Display Bool Bool int int e
DECLSPEC SDL_Window *SDLCALL SDL_GL_GetCurrentWindow(void)
Get the currently active OpenGL window.
SDL_bool X11_UseDirectColorVisuals(void)
DECLSPEC void SDLCALL SDL_free(void *mem)
GLXFBConfig * glXChooseFBConfig(Display *dpy, int screen, const int *attribList, int *nitems)
void * SDL_GLContext
An opaque handle to an OpenGL context.
EGLSurface const EGLint * attrib_list
return Display return Display Bool Bool int d
DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c)
GLsizei const GLchar *const * path
#define GLX_VISUAL_CAVEAT_EXT
struct SDL_GLDriverData * gl_data
int(* GL_SetSwapInterval)(_THIS, int interval)
#define GLX_X_VISUAL_TYPE_EXT
#define GLX_SAMPLE_BUFFERS_ARB
static SDL_VideoDevice * _this
void(* GL_UnloadLibrary)(_THIS)
#define GLX_CONTEXT_FLAGS_ARB
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
struct SDL_VideoData * videodata
#define GLX_CONTEXT_PROFILE_MASK_ARB
DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle)
DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen)
struct __GLXFBConfigRec * GLXFBConfig
#define GLX_DIRECT_COLOR_EXT
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor return Display Window return Display Drawable GC int int unsigned int unsigned int return Display Drawable GC int int _Xconst char int return Display Drawable GC int int unsigned int unsigned int return Display return Display Cursor return Display GC return XModifierKeymap return char Display Window int return Display return Display Atom retur XGetWindowAttributes)
#define GLX_ACCUM_BLUE_SIZE
int share_with_current_context
#define SDL_assert(condition)
DECLSPEC size_t SDLCALL SDL_strlen(const char *str)
int(* GL_GetSwapInterval)(_THIS)
#define SDL_OutOfMemory()
#define SDL_arraysize(array)
#define GLX_ACCUM_ALPHA_SIZE
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
#define GLX_CONTEXT_MAJOR_VERSION_ARB
#define GLX_CONTEXT_MINOR_VERSION_ARB
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
#define GLX_ACCUM_RED_SIZE
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
int(* GL_LoadLibrary)(_THIS, const char *path)
void(* GL_SwapWindow)(_THIS, SDL_Window *window)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int int return Display Window Cursor retur XDestroyWindow)
GLint GLint GLint GLint GLint w
DECLSPEC char *SDLCALL SDL_getenv(const char *name)
EGLImageKHR EGLint EGLint * handle
struct SDL_VideoDevice::@87 gl_config
void *(* GL_GetProcAddress)(_THIS, const char *proc)
#define SDL_Unsupported()
DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void)
Get the currently active OpenGL context.
#define GLX_LATE_SWAPS_TEAR_EXT