1 //========================================================================
2 // GLFW 3.4 GLX - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2017 Camilla Löwy <elmindreda@glfw.org>
6 //
7 // This software is provided 'as-is', without any express or implied
8 // warranty. In no event will the authors be held liable for any damages
9 // arising from the use of this software.
10 //
11 // Permission is granted to anyone to use this software for any purpose,
12 // including commercial applications, and to alter it and redistribute it
13 // freely, subject to the following restrictions:
14 //
15 // 1. The origin of this software must not be misrepresented; you must not
16 //    claim that you wrote the original software. If you use this software
17 //    in a product, an acknowledgment in the product documentation would
18 //    be appreciated but is not required.
19 //
20 // 2. Altered source versions must be plainly marked as such, and must not
21 //    be misrepresented as being the original software.
22 //
23 // 3. This notice may not be removed or altered from any source
24 //    distribution.
25 //
26 //========================================================================
27 
28 #define GLX_VENDOR 1
29 #define GLX_RGBA_BIT 0x00000001
30 #define GLX_WINDOW_BIT 0x00000001
31 #define GLX_DRAWABLE_TYPE 0x8010
32 #define GLX_RENDER_TYPE 0x8011
33 #define GLX_RGBA_TYPE 0x8014
34 #define GLX_DOUBLEBUFFER 5
35 #define GLX_STEREO 6
36 #define GLX_AUX_BUFFERS 7
37 #define GLX_RED_SIZE 8
38 #define GLX_GREEN_SIZE 9
39 #define GLX_BLUE_SIZE 10
40 #define GLX_ALPHA_SIZE 11
41 #define GLX_DEPTH_SIZE 12
42 #define GLX_STENCIL_SIZE 13
43 #define GLX_ACCUM_RED_SIZE 14
44 #define GLX_ACCUM_GREEN_SIZE 15
45 #define GLX_ACCUM_BLUE_SIZE 16
46 #define GLX_ACCUM_ALPHA_SIZE 17
47 #define GLX_SAMPLES 0x186a1
48 #define GLX_VISUAL_ID 0x800b
49 
50 #define GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB 0x20b2
51 #define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001
52 #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002
53 #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001
54 #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126
55 #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002
56 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091
57 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092
58 #define GLX_CONTEXT_FLAGS_ARB 0x2094
59 #define GLX_CONTEXT_ES2_PROFILE_BIT_EXT 0x00000004
60 #define GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB 0x00000004
61 #define GLX_LOSE_CONTEXT_ON_RESET_ARB 0x8252
62 #define GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB 0x8256
63 #define GLX_NO_RESET_NOTIFICATION_ARB 0x8261
64 #define GLX_CONTEXT_RELEASE_BEHAVIOR_ARB 0x2097
65 #define GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB 0
66 #define GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB 0x2098
67 #define GLX_CONTEXT_OPENGL_NO_ERROR_ARB 0x31b3
68 
69 typedef XID GLXWindow;
70 typedef XID GLXDrawable;
71 typedef struct __GLXFBConfig* GLXFBConfig;
72 typedef struct __GLXcontext* GLXContext;
73 typedef void (*__GLXextproc)(void);
74 
75 typedef int (*PFNGLXGETFBCONFIGATTRIBPROC)(Display*,GLXFBConfig,int,int*);
76 typedef GLXFBConfig* (*PFNGLXCHOOSEFBCONFIGPROC)(Display*,int,const int*,int*);
77 typedef const char* (*PFNGLXGETCLIENTSTRINGPROC)(Display*,int);
78 typedef Bool (*PFNGLXQUERYEXTENSIONPROC)(Display*,int*,int*);
79 typedef Bool (*PFNGLXQUERYVERSIONPROC)(Display*,int*,int*);
80 typedef void (*PFNGLXDESTROYCONTEXTPROC)(Display*,GLXContext);
81 typedef Bool (*PFNGLXMAKECURRENTPROC)(Display*,GLXDrawable,GLXContext);
82 typedef void (*PFNGLXSWAPBUFFERSPROC)(Display*,GLXDrawable);
83 typedef const char* (*PFNGLXQUERYEXTENSIONSSTRINGPROC)(Display*,int);
84 typedef GLXFBConfig* (*PFNGLXGETFBCONFIGSPROC)(Display*,int,int*);
85 typedef GLXContext (*PFNGLXCREATENEWCONTEXTPROC)(Display*,GLXFBConfig,int,GLXContext,Bool);
86 typedef __GLXextproc (* PFNGLXGETPROCADDRESSPROC)(const GLubyte *procName);
87 typedef void (*PFNGLXSWAPINTERVALEXTPROC)(Display*,GLXDrawable,int);
88 typedef XVisualInfo* (*PFNGLXGETVISUALFROMFBCONFIGPROC)(Display*,GLXFBConfig);
89 typedef GLXWindow (*PFNGLXCREATEWINDOWPROC)(Display*,GLXFBConfig,Window,const int*);
90 typedef void (*PFNGLXDESTROYWINDOWPROC)(Display*,GLXWindow);
91 
92 typedef int (*PFNGLXSWAPINTERVALMESAPROC)(int);
93 typedef int (*PFNGLXSWAPINTERVALSGIPROC)(int);
94 typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display*,GLXFBConfig,GLXContext,Bool,const int*);
95 
96 // libGL.so function pointer typedefs
97 #define glXGetFBConfigs _glfw.glx.GetFBConfigs
98 #define glXGetFBConfigAttrib _glfw.glx.GetFBConfigAttrib
99 #define glXChooseFBConfig _glfw.glx.ChooseFBConfig
100 #define glXGetClientString _glfw.glx.GetClientString
101 #define glXQueryExtension _glfw.glx.QueryExtension
102 #define glXQueryVersion _glfw.glx.QueryVersion
103 #define glXDestroyContext _glfw.glx.DestroyContext
104 #define glXMakeCurrent _glfw.glx.MakeCurrent
105 #define glXSwapBuffers _glfw.glx.SwapBuffers
106 #define glXQueryExtensionsString _glfw.glx.QueryExtensionsString
107 #define glXCreateNewContext _glfw.glx.CreateNewContext
108 #define glXGetVisualFromFBConfig _glfw.glx.GetVisualFromFBConfig
109 #define glXCreateWindow _glfw.glx.CreateWindow
110 #define glXDestroyWindow _glfw.glx.DestroyWindow
111 
112 #define _GLFW_PLATFORM_CONTEXT_STATE            _GLFWcontextGLX glx;
113 #define _GLFW_PLATFORM_LIBRARY_CONTEXT_STATE    _GLFWlibraryGLX glx;
114 
115 
116 // GLX-specific per-context data
117 //
118 typedef struct _GLFWcontextGLX
119 {
120     GLXContext      handle;
121     GLXWindow       window;
122 
123 } _GLFWcontextGLX;
124 
125 // GLX-specific global data
126 //
127 typedef struct _GLFWlibraryGLX
128 {
129     int             major, minor;
130     int             eventBase;
131     int             errorBase;
132 
133     // dlopen handle for libGL.so.1
134     void*           handle;
135 
136     // GLX 1.3 functions
137     PFNGLXGETFBCONFIGSPROC              GetFBConfigs;
138     PFNGLXGETFBCONFIGATTRIBPROC         GetFBConfigAttrib;
139     PFNGLXCHOOSEFBCONFIGPROC            ChooseFBConfig;
140     PFNGLXGETCLIENTSTRINGPROC           GetClientString;
141     PFNGLXQUERYEXTENSIONPROC            QueryExtension;
142     PFNGLXQUERYVERSIONPROC              QueryVersion;
143     PFNGLXDESTROYCONTEXTPROC            DestroyContext;
144     PFNGLXMAKECURRENTPROC               MakeCurrent;
145     PFNGLXSWAPBUFFERSPROC               SwapBuffers;
146     PFNGLXQUERYEXTENSIONSSTRINGPROC     QueryExtensionsString;
147     PFNGLXCREATENEWCONTEXTPROC          CreateNewContext;
148     PFNGLXGETVISUALFROMFBCONFIGPROC     GetVisualFromFBConfig;
149     PFNGLXCREATEWINDOWPROC              CreateWindow;
150     PFNGLXDESTROYWINDOWPROC             DestroyWindow;
151 
152     // GLX 1.4 and extension functions
153     PFNGLXGETPROCADDRESSPROC            GetProcAddress;
154     PFNGLXGETPROCADDRESSPROC            GetProcAddressARB;
155     PFNGLXSWAPINTERVALSGIPROC           SwapIntervalSGI;
156     PFNGLXSWAPINTERVALEXTPROC           SwapIntervalEXT;
157     PFNGLXSWAPINTERVALMESAPROC          SwapIntervalMESA;
158     PFNGLXCREATECONTEXTATTRIBSARBPROC   CreateContextAttribsARB;
159     bool            SGI_swap_control;
160     bool            EXT_swap_control;
161     bool            MESA_swap_control;
162     bool            ARB_multisample;
163     bool            ARB_framebuffer_sRGB;
164     bool            EXT_framebuffer_sRGB;
165     bool            ARB_create_context;
166     bool            ARB_create_context_profile;
167     bool            ARB_create_context_robustness;
168     bool            EXT_create_context_es2_profile;
169     bool            ARB_create_context_no_error;
170     bool            ARB_context_flush_control;
171 
172 } _GLFWlibraryGLX;
173 
174 bool _glfwInitGLX(void);
175 void _glfwTerminateGLX(void);
176 bool _glfwCreateContextGLX(_GLFWwindow* window,
177                                const _GLFWctxconfig* ctxconfig,
178                                const _GLFWfbconfig* fbconfig);
179 void _glfwDestroyContextGLX(_GLFWwindow* window);
180 bool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig,
181                               const _GLFWctxconfig* ctxconfig,
182                               const _GLFWfbconfig* fbconfig,
183                               Visual** visual, int* depth);
184