1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#ifndef SDL_x11opengl_h_
24#define SDL_x11opengl_h_
25
26#ifdef SDL_VIDEO_OPENGL_GLX
27#include <SDL3/SDL_opengl.h>
28#include <GL/glx.h>
29
30typedef void (*__GLXextFuncPtr)(void);
31
32typedef enum SDL_GLSwapIntervalTearBehavior
33{
34 SDL_SWAPINTERVALTEAR_UNTESTED,
35 SDL_SWAPINTERVALTEAR_UNKNOWN,
36 SDL_SWAPINTERVALTEAR_MESA,
37 SDL_SWAPINTERVALTEAR_NVIDIA
38} SDL_GLSwapIntervalTearBehavior;
39
40struct SDL_GLDriverData
41{
42 int errorBase, eventBase;
43
44 bool HAS_GLX_EXT_visual_rating;
45 bool HAS_GLX_EXT_visual_info;
46 bool HAS_GLX_EXT_swap_control_tear;
47 bool HAS_GLX_ARB_context_flush_control;
48 bool HAS_GLX_ARB_create_context_robustness;
49 bool HAS_GLX_ARB_create_context_no_error;
50
51 /* Max version of OpenGL ES context that can be created if the
52 implementation supports GLX_EXT_create_context_es2_profile.
53 major = minor = 0 when unsupported.
54 */
55 struct
56 {
57 int major;
58 int minor;
59 } es_profile_max_supported_version;
60
61 SDL_GLSwapIntervalTearBehavior swap_interval_tear_behavior;
62
63 Bool (*glXQueryExtension)(Display *, int *, int *);
64 __GLXextFuncPtr (*glXGetProcAddress)(const GLubyte *);
65 XVisualInfo *(*glXChooseVisual)(Display *, int, int *);
66 GLXContext (*glXCreateContext)(Display *, XVisualInfo *, GLXContext, Bool);
67 GLXContext (*glXCreateContextAttribsARB)(Display *, GLXFBConfig, GLXContext, Bool, const int *);
68 GLXFBConfig *(*glXChooseFBConfig)(Display *, int, const int *, int *);
69 XVisualInfo *(*glXGetVisualFromFBConfig)(Display *, GLXFBConfig);
70 void (*glXDestroyContext)(Display *, GLXContext);
71 Bool (*glXMakeCurrent)(Display *, GLXDrawable, GLXContext);
72 void (*glXSwapBuffers)(Display *, GLXDrawable);
73 void (*glXQueryDrawable)(Display *, GLXDrawable, int, unsigned int *);
74 void (*glXSwapIntervalEXT)(Display *, GLXDrawable, int);
75 int (*glXSwapIntervalSGI)(int);
76 int (*glXSwapIntervalMESA)(int);
77 int (*glXGetSwapIntervalMESA)(void);
78};
79
80// OpenGL functions
81extern bool X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path);
82extern SDL_FunctionPointer X11_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc);
83extern void X11_GL_UnloadLibrary(SDL_VideoDevice *_this);
84extern bool X11_GL_UseEGL(SDL_VideoDevice *_this);
85extern XVisualInfo *X11_GL_GetVisual(SDL_VideoDevice *_this, Display *display, int screen, bool transparent);
86extern SDL_GLContext X11_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window);
87extern bool X11_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window,
88 SDL_GLContext context);
89extern bool X11_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval);
90extern bool X11_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval);
91extern bool X11_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window);
92extern bool X11_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context);
93
94#endif // SDL_VIDEO_OPENGL_GLX
95
96#endif // SDL_x11opengl_h_
97