GCC Code Coverage Report


Directory: ./
File: submodules/raylib/src/external/glfw/src/glx_context.c
Date: 2023-09-29 04:53:15
Exec Total Coverage
Lines: 0 301 0.0%
Branches: 0 222 0.0%

Line Branch Exec Source
1 //========================================================================
2 // GLFW 3.4 GLX - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2019 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 // It is fine to use C99 in this file because it will not be built with VS
28 //========================================================================
29
30 #include "internal.h"
31
32 #include <string.h>
33 #include <stdlib.h>
34 #include <assert.h>
35
36 #ifndef GLXBadProfileARB
37 #define GLXBadProfileARB 13
38 #endif
39
40
41 // Returns the specified attribute of the specified GLXFBConfig
42 //
43 static int getGLXFBConfigAttrib(GLXFBConfig fbconfig, int attrib)
44 {
45 int value;
46 ✗ glXGetFBConfigAttrib(_glfw.x11.display, fbconfig, attrib, &value);
47 ✗ return value;
48 }
49
50 // Return the GLXFBConfig most closely matching the specified hints
51 //
52 ✗ static GLFWbool chooseGLXFBConfig(const _GLFWfbconfig* desired,
53 GLXFBConfig* result)
54 {
55 GLXFBConfig* nativeConfigs;
56 _GLFWfbconfig* usableConfigs;
57 const _GLFWfbconfig* closest;
58 int nativeCount, usableCount;
59 const char* vendor;
60 GLFWbool trustWindowBit = GLFW_TRUE;
61
62 // HACK: This is a (hopefully temporary) workaround for Chromium
63 // (VirtualBox GL) not setting the window bit on any GLXFBConfigs
64 ✗ vendor = glXGetClientString(_glfw.x11.display, GLX_VENDOR);
65 ✗ if (vendor && strcmp(vendor, "Chromium") == 0)
66 trustWindowBit = GLFW_FALSE;
67
68 nativeConfigs =
69 ✗ glXGetFBConfigs(_glfw.x11.display, _glfw.x11.screen, &nativeCount);
70 ✗ if (!nativeConfigs || !nativeCount)
71 {
72 ✗ _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: No GLXFBConfigs returned");
73 ✗ return GLFW_FALSE;
74 }
75
76 ✗ usableConfigs = _glfw_calloc(nativeCount, sizeof(_GLFWfbconfig));
77 usableCount = 0;
78
79 ✗ for (int i = 0; i < nativeCount; i++)
80 {
81 ✗ const GLXFBConfig n = nativeConfigs[i];
82 ✗ _GLFWfbconfig* u = usableConfigs + usableCount;
83
84 // Only consider RGBA GLXFBConfigs
85 ✗ if (!(getGLXFBConfigAttrib(n, GLX_RENDER_TYPE) & GLX_RGBA_BIT))
86 ✗ continue;
87
88 // Only consider window GLXFBConfigs
89 ✗ if (!(getGLXFBConfigAttrib(n, GLX_DRAWABLE_TYPE) & GLX_WINDOW_BIT))
90 {
91 ✗ if (trustWindowBit)
92 ✗ continue;
93 }
94
95 ✗ if (getGLXFBConfigAttrib(n, GLX_DOUBLEBUFFER) != desired->doublebuffer)
96 ✗ continue;
97
98 ✗ if (desired->transparent)
99 {
100 ✗ XVisualInfo* vi = glXGetVisualFromFBConfig(_glfw.x11.display, n);
101 ✗ if (vi)
102 {
103 ✗ u->transparent = _glfwIsVisualTransparentX11(vi->visual);
104 ✗ XFree(vi);
105 }
106 }
107
108 ✗ u->redBits = getGLXFBConfigAttrib(n, GLX_RED_SIZE);
109 ✗ u->greenBits = getGLXFBConfigAttrib(n, GLX_GREEN_SIZE);
110 ✗ u->blueBits = getGLXFBConfigAttrib(n, GLX_BLUE_SIZE);
111
112 ✗ u->alphaBits = getGLXFBConfigAttrib(n, GLX_ALPHA_SIZE);
113 ✗ u->depthBits = getGLXFBConfigAttrib(n, GLX_DEPTH_SIZE);
114 ✗ u->stencilBits = getGLXFBConfigAttrib(n, GLX_STENCIL_SIZE);
115
116 ✗ u->accumRedBits = getGLXFBConfigAttrib(n, GLX_ACCUM_RED_SIZE);
117 ✗ u->accumGreenBits = getGLXFBConfigAttrib(n, GLX_ACCUM_GREEN_SIZE);
118 ✗ u->accumBlueBits = getGLXFBConfigAttrib(n, GLX_ACCUM_BLUE_SIZE);
119 ✗ u->accumAlphaBits = getGLXFBConfigAttrib(n, GLX_ACCUM_ALPHA_SIZE);
120
121 ✗ u->auxBuffers = getGLXFBConfigAttrib(n, GLX_AUX_BUFFERS);
122
123 ✗ if (getGLXFBConfigAttrib(n, GLX_STEREO))
124 ✗ u->stereo = GLFW_TRUE;
125
126 ✗ if (_glfw.glx.ARB_multisample)
127 ✗ u->samples = getGLXFBConfigAttrib(n, GLX_SAMPLES);
128
129 ✗ if (_glfw.glx.ARB_framebuffer_sRGB || _glfw.glx.EXT_framebuffer_sRGB)
130 ✗ u->sRGB = getGLXFBConfigAttrib(n, GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB);
131
132 ✗ u->handle = (uintptr_t) n;
133 ✗ usableCount++;
134 }
135
136 ✗ closest = _glfwChooseFBConfig(desired, usableConfigs, usableCount);
137 ✗ if (closest)
138 ✗ *result = (GLXFBConfig) closest->handle;
139
140 ✗ XFree(nativeConfigs);
141 ✗ _glfw_free(usableConfigs);
142
143 ✗ return closest != NULL;
144 }
145
146 // Create the OpenGL context using legacy API
147 //
148 static GLXContext createLegacyContextGLX(_GLFWwindow* window,
149 GLXFBConfig fbconfig,
150 GLXContext share)
151 {
152 ✗ return glXCreateNewContext(_glfw.x11.display,
153 fbconfig,
154 GLX_RGBA_TYPE,
155 share,
156 True);
157 }
158
159 ✗ static void makeContextCurrentGLX(_GLFWwindow* window)
160 {
161 ✗ if (window)
162 {
163 ✗ if (!glXMakeCurrent(_glfw.x11.display,
164 window->context.glx.window,
165 window->context.glx.handle))
166 {
167 ✗ _glfwInputError(GLFW_PLATFORM_ERROR,
168 "GLX: Failed to make context current");
169 ✗ return;
170 }
171 }
172 else
173 {
174 ✗ if (!glXMakeCurrent(_glfw.x11.display, None, NULL))
175 {
176 ✗ _glfwInputError(GLFW_PLATFORM_ERROR,
177 "GLX: Failed to clear current context");
178 ✗ return;
179 }
180 }
181
182 ✗ _glfwPlatformSetTls(&_glfw.contextSlot, window);
183 }
184
185 ✗ static void swapBuffersGLX(_GLFWwindow* window)
186 {
187 ✗ glXSwapBuffers(_glfw.x11.display, window->context.glx.window);
188 }
189
190 ✗ static void swapIntervalGLX(int interval)
191 {
192 ✗ _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
193
194 ✗ if (_glfw.glx.EXT_swap_control)
195 {
196 ✗ _glfw.glx.SwapIntervalEXT(_glfw.x11.display,
197 window->context.glx.window,
198 interval);
199 }
200 ✗ else if (_glfw.glx.MESA_swap_control)
201 ✗ _glfw.glx.SwapIntervalMESA(interval);
202 ✗ else if (_glfw.glx.SGI_swap_control)
203 {
204 ✗ if (interval > 0)
205 ✗ _glfw.glx.SwapIntervalSGI(interval);
206 }
207 }
208
209 ✗ static int extensionSupportedGLX(const char* extension)
210 {
211 const char* extensions =
212 ✗ glXQueryExtensionsString(_glfw.x11.display, _glfw.x11.screen);
213 ✗ if (extensions)
214 {
215 ✗ if (_glfwStringInExtensionString(extension, extensions))
216 ✗ return GLFW_TRUE;
217 }
218
219 return GLFW_FALSE;
220 }
221
222 ✗ static GLFWglproc getProcAddressGLX(const char* procname)
223 {
224 ✗ if (_glfw.glx.GetProcAddress)
225 ✗ return _glfw.glx.GetProcAddress((const GLubyte*) procname);
226 ✗ else if (_glfw.glx.GetProcAddressARB)
227 ✗ return _glfw.glx.GetProcAddressARB((const GLubyte*) procname);
228 else
229 {
230 // NOTE: glvnd provides GLX 1.4, so this can only happen with libGL
231 ✗ return _glfwPlatformGetModuleSymbol(_glfw.glx.handle, procname);
232 }
233 }
234
235 ✗ static void destroyContextGLX(_GLFWwindow* window)
236 {
237 ✗ if (window->context.glx.window)
238 {
239 ✗ glXDestroyWindow(_glfw.x11.display, window->context.glx.window);
240 ✗ window->context.glx.window = None;
241 }
242
243 ✗ if (window->context.glx.handle)
244 {
245 ✗ glXDestroyContext(_glfw.x11.display, window->context.glx.handle);
246 ✗ window->context.glx.handle = NULL;
247 }
248 }
249
250
251 //////////////////////////////////////////////////////////////////////////
252 ////// GLFW internal API //////
253 //////////////////////////////////////////////////////////////////////////
254
255 // Initialize GLX
256 //
257 ✗ GLFWbool _glfwInitGLX(void)
258 {
259 ✗ const char* sonames[] =
260 {
261 #if defined(_GLFW_GLX_LIBRARY)
262 _GLFW_GLX_LIBRARY,
263 #elif defined(__CYGWIN__)
264 "libGL-1.so",
265 #elif defined(__OpenBSD__) || defined(__NetBSD__)
266 "libGL.so",
267 #else
268 "libGLX.so.0",
269 "libGL.so.1",
270 "libGL.so",
271 #endif
272 NULL
273 };
274
275 ✗ if (_glfw.glx.handle)
276 return GLFW_TRUE;
277
278 ✗ for (int i = 0; sonames[i]; i++)
279 {
280 ✗ _glfw.glx.handle = _glfwPlatformLoadModule(sonames[i]);
281 ✗ if (_glfw.glx.handle)
282 break;
283 }
284
285 ✗ if (!_glfw.glx.handle)
286 {
287 ✗ _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: Failed to load GLX");
288 ✗ return GLFW_FALSE;
289 }
290
291 ✗ _glfw.glx.GetFBConfigs = (PFNGLXGETFBCONFIGSPROC)
292 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetFBConfigs");
293 ✗ _glfw.glx.GetFBConfigAttrib = (PFNGLXGETFBCONFIGATTRIBPROC)
294 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetFBConfigAttrib");
295 ✗ _glfw.glx.GetClientString = (PFNGLXGETCLIENTSTRINGPROC)
296 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetClientString");
297 ✗ _glfw.glx.QueryExtension = (PFNGLXQUERYEXTENSIONPROC)
298 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXQueryExtension");
299 ✗ _glfw.glx.QueryVersion = (PFNGLXQUERYVERSIONPROC)
300 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXQueryVersion");
301 ✗ _glfw.glx.DestroyContext = (PFNGLXDESTROYCONTEXTPROC)
302 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXDestroyContext");
303 ✗ _glfw.glx.MakeCurrent = (PFNGLXMAKECURRENTPROC)
304 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXMakeCurrent");
305 ✗ _glfw.glx.SwapBuffers = (PFNGLXSWAPBUFFERSPROC)
306 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXSwapBuffers");
307 ✗ _glfw.glx.QueryExtensionsString = (PFNGLXQUERYEXTENSIONSSTRINGPROC)
308 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXQueryExtensionsString");
309 ✗ _glfw.glx.CreateNewContext = (PFNGLXCREATENEWCONTEXTPROC)
310 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXCreateNewContext");
311 ✗ _glfw.glx.CreateWindow = (PFNGLXCREATEWINDOWPROC)
312 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXCreateWindow");
313 ✗ _glfw.glx.DestroyWindow = (PFNGLXDESTROYWINDOWPROC)
314 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXDestroyWindow");
315 ✗ _glfw.glx.GetVisualFromFBConfig = (PFNGLXGETVISUALFROMFBCONFIGPROC)
316 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetVisualFromFBConfig");
317
318 ✗ if (!_glfw.glx.GetFBConfigs ||
319 ✗ !_glfw.glx.GetFBConfigAttrib ||
320 ✗ !_glfw.glx.GetClientString ||
321 ✗ !_glfw.glx.QueryExtension ||
322 ✗ !_glfw.glx.QueryVersion ||
323 ✗ !_glfw.glx.DestroyContext ||
324 ✗ !_glfw.glx.MakeCurrent ||
325 ✗ !_glfw.glx.SwapBuffers ||
326 ✗ !_glfw.glx.QueryExtensionsString ||
327 ✗ !_glfw.glx.CreateNewContext ||
328 ✗ !_glfw.glx.CreateWindow ||
329 ✗ !_glfw.glx.DestroyWindow ||
330 !_glfw.glx.GetVisualFromFBConfig)
331 {
332 ✗ _glfwInputError(GLFW_PLATFORM_ERROR,
333 "GLX: Failed to load required entry points");
334 ✗ return GLFW_FALSE;
335 }
336
337 // NOTE: Unlike GLX 1.3 entry points these are not required to be present
338 ✗ _glfw.glx.GetProcAddress = (PFNGLXGETPROCADDRESSPROC)
339 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetProcAddress");
340 ✗ _glfw.glx.GetProcAddressARB = (PFNGLXGETPROCADDRESSPROC)
341 ✗ _glfwPlatformGetModuleSymbol(_glfw.glx.handle, "glXGetProcAddressARB");
342
343 ✗ if (!glXQueryExtension(_glfw.x11.display,
344 &_glfw.glx.errorBase,
345 &_glfw.glx.eventBase))
346 {
347 ✗ _glfwInputError(GLFW_API_UNAVAILABLE, "GLX: GLX extension not found");
348 ✗ return GLFW_FALSE;
349 }
350
351 ✗ if (!glXQueryVersion(_glfw.x11.display, &_glfw.glx.major, &_glfw.glx.minor))
352 {
353 ✗ _glfwInputError(GLFW_API_UNAVAILABLE,
354 "GLX: Failed to query GLX version");
355 ✗ return GLFW_FALSE;
356 }
357
358 ✗ if (_glfw.glx.major == 1 && _glfw.glx.minor < 3)
359 {
360 ✗ _glfwInputError(GLFW_API_UNAVAILABLE,
361 "GLX: GLX version 1.3 is required");
362 ✗ return GLFW_FALSE;
363 }
364
365 ✗ if (extensionSupportedGLX("GLX_EXT_swap_control"))
366 {
367 ✗ _glfw.glx.SwapIntervalEXT = (PFNGLXSWAPINTERVALEXTPROC)
368 ✗ getProcAddressGLX("glXSwapIntervalEXT");
369
370 ✗ if (_glfw.glx.SwapIntervalEXT)
371 ✗ _glfw.glx.EXT_swap_control = GLFW_TRUE;
372 }
373
374 ✗ if (extensionSupportedGLX("GLX_SGI_swap_control"))
375 {
376 ✗ _glfw.glx.SwapIntervalSGI = (PFNGLXSWAPINTERVALSGIPROC)
377 ✗ getProcAddressGLX("glXSwapIntervalSGI");
378
379 ✗ if (_glfw.glx.SwapIntervalSGI)
380 ✗ _glfw.glx.SGI_swap_control = GLFW_TRUE;
381 }
382
383 ✗ if (extensionSupportedGLX("GLX_MESA_swap_control"))
384 {
385 ✗ _glfw.glx.SwapIntervalMESA = (PFNGLXSWAPINTERVALMESAPROC)
386 ✗ getProcAddressGLX("glXSwapIntervalMESA");
387
388 ✗ if (_glfw.glx.SwapIntervalMESA)
389 ✗ _glfw.glx.MESA_swap_control = GLFW_TRUE;
390 }
391
392 ✗ if (extensionSupportedGLX("GLX_ARB_multisample"))
393 ✗ _glfw.glx.ARB_multisample = GLFW_TRUE;
394
395 ✗ if (extensionSupportedGLX("GLX_ARB_framebuffer_sRGB"))
396 ✗ _glfw.glx.ARB_framebuffer_sRGB = GLFW_TRUE;
397
398 ✗ if (extensionSupportedGLX("GLX_EXT_framebuffer_sRGB"))
399 ✗ _glfw.glx.EXT_framebuffer_sRGB = GLFW_TRUE;
400
401 ✗ if (extensionSupportedGLX("GLX_ARB_create_context"))
402 {
403 ✗ _glfw.glx.CreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
404 ✗ getProcAddressGLX("glXCreateContextAttribsARB");
405
406 ✗ if (_glfw.glx.CreateContextAttribsARB)
407 ✗ _glfw.glx.ARB_create_context = GLFW_TRUE;
408 }
409
410 ✗ if (extensionSupportedGLX("GLX_ARB_create_context_robustness"))
411 ✗ _glfw.glx.ARB_create_context_robustness = GLFW_TRUE;
412
413 ✗ if (extensionSupportedGLX("GLX_ARB_create_context_profile"))
414 ✗ _glfw.glx.ARB_create_context_profile = GLFW_TRUE;
415
416 ✗ if (extensionSupportedGLX("GLX_EXT_create_context_es2_profile"))
417 ✗ _glfw.glx.EXT_create_context_es2_profile = GLFW_TRUE;
418
419 ✗ if (extensionSupportedGLX("GLX_ARB_create_context_no_error"))
420 ✗ _glfw.glx.ARB_create_context_no_error = GLFW_TRUE;
421
422 ✗ if (extensionSupportedGLX("GLX_ARB_context_flush_control"))
423 ✗ _glfw.glx.ARB_context_flush_control = GLFW_TRUE;
424
425 return GLFW_TRUE;
426 }
427
428 // Terminate GLX
429 //
430 ✗ void _glfwTerminateGLX(void)
431 {
432 // NOTE: This function must not call any X11 functions, as it is called
433 // after XCloseDisplay (see _glfwTerminateX11 for details)
434
435 ✗ if (_glfw.glx.handle)
436 {
437 ✗ _glfwPlatformFreeModule(_glfw.glx.handle);
438 ✗ _glfw.glx.handle = NULL;
439 }
440 }
441
442 #define SET_ATTRIB(a, v) \
443 { \
444 assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
445 attribs[index++] = a; \
446 attribs[index++] = v; \
447 }
448
449 // Create the OpenGL or OpenGL ES context
450 //
451 ✗ GLFWbool _glfwCreateContextGLX(_GLFWwindow* window,
452 const _GLFWctxconfig* ctxconfig,
453 const _GLFWfbconfig* fbconfig)
454 {
455 int attribs[40];
456 ✗ GLXFBConfig native = NULL;
457 GLXContext share = NULL;
458
459 ✗ if (ctxconfig->share)
460 ✗ share = ctxconfig->share->context.glx.handle;
461
462 ✗ if (!chooseGLXFBConfig(fbconfig, &native))
463 {
464 ✗ _glfwInputError(GLFW_FORMAT_UNAVAILABLE,
465 "GLX: Failed to find a suitable GLXFBConfig");
466 ✗ return GLFW_FALSE;
467 }
468
469 ✗ if (ctxconfig->client == GLFW_OPENGL_ES_API)
470 {
471 ✗ if (!_glfw.glx.ARB_create_context ||
472 ✗ !_glfw.glx.ARB_create_context_profile ||
473 ✗ !_glfw.glx.EXT_create_context_es2_profile)
474 {
475 ✗ _glfwInputError(GLFW_API_UNAVAILABLE,
476 "GLX: OpenGL ES requested but GLX_EXT_create_context_es2_profile is unavailable");
477 ✗ return GLFW_FALSE;
478 }
479 }
480
481 ✗ if (ctxconfig->forward)
482 {
483 ✗ if (!_glfw.glx.ARB_create_context)
484 {
485 ✗ _glfwInputError(GLFW_VERSION_UNAVAILABLE,
486 "GLX: Forward compatibility requested but GLX_ARB_create_context_profile is unavailable");
487 ✗ return GLFW_FALSE;
488 }
489 }
490
491 ✗ if (ctxconfig->profile)
492 {
493 ✗ if (!_glfw.glx.ARB_create_context ||
494 ✗ !_glfw.glx.ARB_create_context_profile)
495 {
496 ✗ _glfwInputError(GLFW_VERSION_UNAVAILABLE,
497 "GLX: An OpenGL profile requested but GLX_ARB_create_context_profile is unavailable");
498 ✗ return GLFW_FALSE;
499 }
500 }
501
502 ✗ _glfwGrabErrorHandlerX11();
503
504 ✗ if (_glfw.glx.ARB_create_context)
505 {
506 int index = 0, mask = 0, flags = 0;
507
508 ✗ if (ctxconfig->client == GLFW_OPENGL_API)
509 {
510 ✗ if (ctxconfig->forward)
511 flags |= GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
512
513 ✗ if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE)
514 mask |= GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
515 ✗ else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE)
516 mask |= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
517 }
518 else
519 mask |= GLX_CONTEXT_ES2_PROFILE_BIT_EXT;
520
521 ✗ if (ctxconfig->debug)
522 ✗ flags |= GLX_CONTEXT_DEBUG_BIT_ARB;
523
524 ✗ if (ctxconfig->robustness)
525 {
526 ✗ if (_glfw.glx.ARB_create_context_robustness)
527 {
528 ✗ if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION)
529 {
530 ✗ SET_ATTRIB(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
531 GLX_NO_RESET_NOTIFICATION_ARB);
532 }
533 ✗ else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET)
534 {
535 ✗ SET_ATTRIB(GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB,
536 GLX_LOSE_CONTEXT_ON_RESET_ARB);
537 }
538
539 ✗ flags |= GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB;
540 }
541 }
542
543 ✗ if (ctxconfig->release)
544 {
545 ✗ if (_glfw.glx.ARB_context_flush_control)
546 {
547 ✗ if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE)
548 {
549 ✗ SET_ATTRIB(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB,
550 GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB);
551 }
552 ✗ else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH)
553 {
554 ✗ SET_ATTRIB(GLX_CONTEXT_RELEASE_BEHAVIOR_ARB,
555 GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB);
556 }
557 }
558 }
559
560 ✗ if (ctxconfig->noerror)
561 {
562 ✗ if (_glfw.glx.ARB_create_context_no_error)
563 ✗ SET_ATTRIB(GLX_CONTEXT_OPENGL_NO_ERROR_ARB, GLFW_TRUE);
564 }
565
566 // NOTE: Only request an explicitly versioned context when necessary, as
567 // explicitly requesting version 1.0 does not always return the
568 // highest version supported by the driver
569 ✗ if (ctxconfig->major != 1 || ctxconfig->minor != 0)
570 {
571 ✗ SET_ATTRIB(GLX_CONTEXT_MAJOR_VERSION_ARB, ctxconfig->major);
572 ✗ SET_ATTRIB(GLX_CONTEXT_MINOR_VERSION_ARB, ctxconfig->minor);
573 }
574
575 ✗ if (mask)
576 ✗ SET_ATTRIB(GLX_CONTEXT_PROFILE_MASK_ARB, mask);
577
578 ✗ if (flags)
579 ✗ SET_ATTRIB(GLX_CONTEXT_FLAGS_ARB, flags);
580
581 ✗ SET_ATTRIB(None, None);
582
583 ✗ window->context.glx.handle =
584 ✗ _glfw.glx.CreateContextAttribsARB(_glfw.x11.display,
585 native,
586 share,
587 True,
588 attribs);
589
590 // HACK: This is a fallback for broken versions of the Mesa
591 // implementation of GLX_ARB_create_context_profile that fail
592 // default 1.0 context creation with a GLXBadProfileARB error in
593 // violation of the extension spec
594 ✗ if (!window->context.glx.handle)
595 {
596 ✗ if (_glfw.x11.errorCode == _glfw.glx.errorBase + GLXBadProfileARB &&
597 ✗ ctxconfig->client == GLFW_OPENGL_API &&
598 ✗ ctxconfig->profile == GLFW_OPENGL_ANY_PROFILE &&
599 ✗ ctxconfig->forward == GLFW_FALSE)
600 {
601 ✗ window->context.glx.handle =
602 createLegacyContextGLX(window, native, share);
603 }
604 }
605 }
606 else
607 {
608 ✗ window->context.glx.handle =
609 ✗ createLegacyContextGLX(window, native, share);
610 }
611
612 ✗ _glfwReleaseErrorHandlerX11();
613
614 ✗ if (!window->context.glx.handle)
615 {
616 ✗ _glfwInputErrorX11(GLFW_VERSION_UNAVAILABLE, "GLX: Failed to create context");
617 ✗ return GLFW_FALSE;
618 }
619
620 ✗ window->context.glx.window =
621 ✗ glXCreateWindow(_glfw.x11.display, native, window->x11.handle, NULL);
622 ✗ if (!window->context.glx.window)
623 {
624 ✗ _glfwInputError(GLFW_PLATFORM_ERROR, "GLX: Failed to create window");
625 ✗ return GLFW_FALSE;
626 }
627
628 ✗ window->context.makeCurrent = makeContextCurrentGLX;
629 ✗ window->context.swapBuffers = swapBuffersGLX;
630 ✗ window->context.swapInterval = swapIntervalGLX;
631 ✗ window->context.extensionSupported = extensionSupportedGLX;
632 ✗ window->context.getProcAddress = getProcAddressGLX;
633 ✗ window->context.destroy = destroyContextGLX;
634
635 ✗ return GLFW_TRUE;
636 }
637
638 #undef SET_ATTRIB
639
640 // Returns the Visual and depth of the chosen GLXFBConfig
641 //
642 ✗ GLFWbool _glfwChooseVisualGLX(const _GLFWwndconfig* wndconfig,
643 const _GLFWctxconfig* ctxconfig,
644 const _GLFWfbconfig* fbconfig,
645 Visual** visual, int* depth)
646 {
647 GLXFBConfig native;
648 XVisualInfo* result;
649
650 ✗ if (!chooseGLXFBConfig(fbconfig, &native))
651 {
652 ✗ _glfwInputError(GLFW_FORMAT_UNAVAILABLE,
653 "GLX: Failed to find a suitable GLXFBConfig");
654 ✗ return GLFW_FALSE;
655 }
656
657 ✗ result = glXGetVisualFromFBConfig(_glfw.x11.display, native);
658 ✗ if (!result)
659 {
660 ✗ _glfwInputError(GLFW_PLATFORM_ERROR,
661 "GLX: Failed to retrieve Visual for GLXFBConfig");
662 ✗ return GLFW_FALSE;
663 }
664
665 ✗ *visual = result->visual;
666 ✗ *depth = result->depth;
667
668 ✗ XFree(result);
669 ✗ return GLFW_TRUE;
670 }
671
672
673 //////////////////////////////////////////////////////////////////////////
674 ////// GLFW native API //////
675 //////////////////////////////////////////////////////////////////////////
676
677 ✗ GLFWAPI GLXContext glfwGetGLXContext(GLFWwindow* handle)
678 {
679 _GLFWwindow* window = (_GLFWwindow*) handle;
680 ✗ _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
681
682 ✗ if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
683 {
684 ✗ _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "GLX: Platform not initialized");
685 ✗ return NULL;
686 }
687
688 ✗ if (window->context.source != GLFW_NATIVE_CONTEXT_API)
689 {
690 ✗ _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
691 ✗ return NULL;
692 }
693
694 ✗ return window->context.glx.handle;
695 }
696
697 ✗ GLFWAPI GLXWindow glfwGetGLXWindow(GLFWwindow* handle)
698 {
699 _GLFWwindow* window = (_GLFWwindow*) handle;
700 ✗ _GLFW_REQUIRE_INIT_OR_RETURN(None);
701
702 ✗ if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
703 {
704 ✗ _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "GLX: Platform not initialized");
705 ✗ return None;
706 }
707
708 ✗ if (window->context.source != GLFW_NATIVE_CONTEXT_API)
709 {
710 ✗ _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
711 ✗ return None;
712 }
713
714 ✗ return window->context.glx.window;
715 }
716
717