1 //========================================================================
2 // GLFW 3.4 EGL - www.glfw.org
3 //------------------------------------------------------------------------
4 // Copyright (c) 2002-2006 Marcus Geelnard
5 // Copyright (c) 2006-2019 Camilla Löwy <elmindreda@glfw.org>
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.
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:
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.
20 // 2. Altered source versions must be plainly marked as such, and must not
21 // be misrepresented as being the original software.
23 // 3. This notice may not be removed or altered from any source
26 //========================================================================
27 // Please use C89 style variable declarations in this file because VS 2010
28 //========================================================================
38 // Return a description of the specified EGL error
40 static const char* getEGLErrorString(EGLint error)
46 case EGL_NOT_INITIALIZED:
47 return "EGL is not or could not be initialized";
49 return "EGL cannot access a requested resource";
51 return "EGL failed to allocate resources for the requested operation";
52 case EGL_BAD_ATTRIBUTE:
53 return "An unrecognized attribute or attribute value was passed in the attribute list";
55 return "An EGLContext argument does not name a valid EGL rendering context";
57 return "An EGLConfig argument does not name a valid EGL frame buffer configuration";
58 case EGL_BAD_CURRENT_SURFACE:
59 return "The current surface of the calling thread is a window, pixel buffer or pixmap that is no longer valid";
61 return "An EGLDisplay argument does not name a valid EGL display connection";
63 return "An EGLSurface argument does not name a valid surface configured for GL rendering";
65 return "Arguments are inconsistent";
66 case EGL_BAD_PARAMETER:
67 return "One or more argument values are invalid";
68 case EGL_BAD_NATIVE_PIXMAP:
69 return "A NativePixmapType argument does not refer to a valid native pixmap";
70 case EGL_BAD_NATIVE_WINDOW:
71 return "A NativeWindowType argument does not refer to a valid native window";
72 case EGL_CONTEXT_LOST:
73 return "The application must destroy all contexts and reinitialise";
75 return "ERROR: UNKNOWN EGL ERROR";
79 // Returns the specified attribute of the specified EGLConfig
81 static int getEGLConfigAttrib(EGLConfig config, int attrib)
84 eglGetConfigAttrib(_glfw.egl.display, config, attrib, &value);
88 // Return the EGLConfig most closely matching the specified hints
90 static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
91 const _GLFWfbconfig* desired,
94 EGLConfig* nativeConfigs;
95 _GLFWfbconfig* usableConfigs;
96 const _GLFWfbconfig* closest;
97 int i, nativeCount, usableCount;
99 eglGetConfigs(_glfw.egl.display, NULL, 0, &nativeCount);
102 _glfwInputError(GLFW_API_UNAVAILABLE, "EGL: No EGLConfigs returned");
106 nativeConfigs = calloc(nativeCount, sizeof(EGLConfig));
107 eglGetConfigs(_glfw.egl.display, nativeConfigs, nativeCount, &nativeCount);
109 usableConfigs = calloc(nativeCount, sizeof(_GLFWfbconfig));
112 for (i = 0; i < nativeCount; i++)
114 const EGLConfig n = nativeConfigs[i];
115 _GLFWfbconfig* u = usableConfigs + usableCount;
117 // Only consider RGB(A) EGLConfigs
118 if (getEGLConfigAttrib(n, EGL_COLOR_BUFFER_TYPE) != EGL_RGB_BUFFER)
121 // Only consider window EGLConfigs
122 if (!(getEGLConfigAttrib(n, EGL_SURFACE_TYPE) & EGL_WINDOW_BIT))
125 #if defined(_GLFW_X11)
127 XVisualInfo vi = {0};
129 // Only consider EGLConfigs with associated Visuals
130 vi.visualid = getEGLConfigAttrib(n, EGL_NATIVE_VISUAL_ID);
134 if (desired->transparent)
138 XGetVisualInfo(_glfw.x11.display, VisualIDMask, &vi, &count);
141 u->transparent = _glfwIsVisualTransparentX11(vis[0].visual);
148 if (ctxconfig->client == GLFW_OPENGL_ES_API)
150 if (ctxconfig->major == 1)
152 if (!(getEGLConfigAttrib(n, EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES_BIT))
157 if (!(getEGLConfigAttrib(n, EGL_RENDERABLE_TYPE) & EGL_OPENGL_ES2_BIT))
161 else if (ctxconfig->client == GLFW_OPENGL_API)
163 if (!(getEGLConfigAttrib(n, EGL_RENDERABLE_TYPE) & EGL_OPENGL_BIT))
167 u->redBits = getEGLConfigAttrib(n, EGL_RED_SIZE);
168 u->greenBits = getEGLConfigAttrib(n, EGL_GREEN_SIZE);
169 u->blueBits = getEGLConfigAttrib(n, EGL_BLUE_SIZE);
171 u->alphaBits = getEGLConfigAttrib(n, EGL_ALPHA_SIZE);
172 u->depthBits = getEGLConfigAttrib(n, EGL_DEPTH_SIZE);
173 u->stencilBits = getEGLConfigAttrib(n, EGL_STENCIL_SIZE);
175 u->samples = getEGLConfigAttrib(n, EGL_SAMPLES);
176 u->doublebuffer = GLFW_TRUE;
178 u->handle = (uintptr_t) n;
182 closest = _glfwChooseFBConfig(desired, usableConfigs, usableCount);
184 *result = (EGLConfig) closest->handle;
189 return closest != NULL;
192 static void makeContextCurrentEGL(_GLFWwindow* window)
196 if (!eglMakeCurrent(_glfw.egl.display,
197 window->context.egl.surface,
198 window->context.egl.surface,
199 window->context.egl.handle))
201 _glfwInputError(GLFW_PLATFORM_ERROR,
202 "EGL: Failed to make context current: %s",
203 getEGLErrorString(eglGetError()));
209 if (!eglMakeCurrent(_glfw.egl.display,
214 _glfwInputError(GLFW_PLATFORM_ERROR,
215 "EGL: Failed to clear current context: %s",
216 getEGLErrorString(eglGetError()));
221 _glfwPlatformSetTls(&_glfw.contextSlot, window);
224 static void swapBuffersEGL(_GLFWwindow* window)
226 if (window != _glfwPlatformGetTls(&_glfw.contextSlot))
228 _glfwInputError(GLFW_PLATFORM_ERROR,
229 "EGL: The context must be current on the calling thread when swapping buffers");
233 eglSwapBuffers(_glfw.egl.display, window->context.egl.surface);
236 static void swapIntervalEGL(int interval)
238 eglSwapInterval(_glfw.egl.display, interval);
241 static int extensionSupportedEGL(const char* extension)
243 const char* extensions = eglQueryString(_glfw.egl.display, EGL_EXTENSIONS);
246 if (_glfwStringInExtensionString(extension, extensions))
253 static GLFWglproc getProcAddressEGL(const char* procname)
255 _GLFWwindow* window = _glfwPlatformGetTls(&_glfw.contextSlot);
257 if (window->context.egl.client)
259 GLFWglproc proc = (GLFWglproc) _glfw_dlsym(window->context.egl.client,
265 return eglGetProcAddress(procname);
268 static void destroyContextEGL(_GLFWwindow* window)
270 #if defined(_GLFW_X11)
271 // NOTE: Do not unload libGL.so.1 while the X11 display is still open,
272 // as it will make XCloseDisplay segfault
273 if (window->context.client != GLFW_OPENGL_API)
276 if (window->context.egl.client)
278 _glfw_dlclose(window->context.egl.client);
279 window->context.egl.client = NULL;
283 if (window->context.egl.surface)
285 eglDestroySurface(_glfw.egl.display, window->context.egl.surface);
286 window->context.egl.surface = EGL_NO_SURFACE;
289 if (window->context.egl.handle)
291 eglDestroyContext(_glfw.egl.display, window->context.egl.handle);
292 window->context.egl.handle = EGL_NO_CONTEXT;
297 //////////////////////////////////////////////////////////////////////////
298 ////// GLFW internal API //////
299 //////////////////////////////////////////////////////////////////////////
303 GLFWbool _glfwInitEGL(void)
306 EGLint* attribs = NULL;
307 const char* extensions;
308 const char* sonames[] =
310 #if defined(_GLFW_EGL_LIBRARY)
312 #elif defined(_GLFW_WIN32)
315 #elif defined(_GLFW_COCOA)
317 #elif defined(__CYGWIN__)
325 if (_glfw.egl.handle)
328 for (i = 0; sonames[i]; i++)
330 _glfw.egl.handle = _glfw_dlopen(sonames[i]);
331 if (_glfw.egl.handle)
335 if (!_glfw.egl.handle)
337 _glfwInputError(GLFW_API_UNAVAILABLE, "EGL: Library not found");
341 _glfw.egl.prefix = (strncmp(sonames[i], "lib", 3) == 0);
343 _glfw.egl.GetConfigAttrib = (PFN_eglGetConfigAttrib)
344 _glfw_dlsym(_glfw.egl.handle, "eglGetConfigAttrib");
345 _glfw.egl.GetConfigs = (PFN_eglGetConfigs)
346 _glfw_dlsym(_glfw.egl.handle, "eglGetConfigs");
347 _glfw.egl.GetDisplay = (PFN_eglGetDisplay)
348 _glfw_dlsym(_glfw.egl.handle, "eglGetDisplay");
349 _glfw.egl.GetError = (PFN_eglGetError)
350 _glfw_dlsym(_glfw.egl.handle, "eglGetError");
351 _glfw.egl.Initialize = (PFN_eglInitialize)
352 _glfw_dlsym(_glfw.egl.handle, "eglInitialize");
353 _glfw.egl.Terminate = (PFN_eglTerminate)
354 _glfw_dlsym(_glfw.egl.handle, "eglTerminate");
355 _glfw.egl.BindAPI = (PFN_eglBindAPI)
356 _glfw_dlsym(_glfw.egl.handle, "eglBindAPI");
357 _glfw.egl.CreateContext = (PFN_eglCreateContext)
358 _glfw_dlsym(_glfw.egl.handle, "eglCreateContext");
359 _glfw.egl.DestroySurface = (PFN_eglDestroySurface)
360 _glfw_dlsym(_glfw.egl.handle, "eglDestroySurface");
361 _glfw.egl.DestroyContext = (PFN_eglDestroyContext)
362 _glfw_dlsym(_glfw.egl.handle, "eglDestroyContext");
363 _glfw.egl.CreateWindowSurface = (PFN_eglCreateWindowSurface)
364 _glfw_dlsym(_glfw.egl.handle, "eglCreateWindowSurface");
365 _glfw.egl.MakeCurrent = (PFN_eglMakeCurrent)
366 _glfw_dlsym(_glfw.egl.handle, "eglMakeCurrent");
367 _glfw.egl.SwapBuffers = (PFN_eglSwapBuffers)
368 _glfw_dlsym(_glfw.egl.handle, "eglSwapBuffers");
369 _glfw.egl.SwapInterval = (PFN_eglSwapInterval)
370 _glfw_dlsym(_glfw.egl.handle, "eglSwapInterval");
371 _glfw.egl.QueryString = (PFN_eglQueryString)
372 _glfw_dlsym(_glfw.egl.handle, "eglQueryString");
373 _glfw.egl.GetProcAddress = (PFN_eglGetProcAddress)
374 _glfw_dlsym(_glfw.egl.handle, "eglGetProcAddress");
376 if (!_glfw.egl.GetConfigAttrib ||
377 !_glfw.egl.GetConfigs ||
378 !_glfw.egl.GetDisplay ||
379 !_glfw.egl.GetError ||
380 !_glfw.egl.Initialize ||
381 !_glfw.egl.Terminate ||
382 !_glfw.egl.BindAPI ||
383 !_glfw.egl.CreateContext ||
384 !_glfw.egl.DestroySurface ||
385 !_glfw.egl.DestroyContext ||
386 !_glfw.egl.CreateWindowSurface ||
387 !_glfw.egl.MakeCurrent ||
388 !_glfw.egl.SwapBuffers ||
389 !_glfw.egl.SwapInterval ||
390 !_glfw.egl.QueryString ||
391 !_glfw.egl.GetProcAddress)
393 _glfwInputError(GLFW_PLATFORM_ERROR,
394 "EGL: Failed to load required entry points");
400 extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
401 if (extensions && eglGetError() == EGL_SUCCESS)
402 _glfw.egl.EXT_client_extensions = GLFW_TRUE;
404 if (_glfw.egl.EXT_client_extensions)
406 _glfw.egl.EXT_platform_base =
407 _glfwStringInExtensionString("EGL_EXT_platform_base", extensions);
408 _glfw.egl.EXT_platform_x11 =
409 _glfwStringInExtensionString("EGL_EXT_platform_x11", extensions);
410 _glfw.egl.EXT_platform_wayland =
411 _glfwStringInExtensionString("EGL_EXT_platform_wayland", extensions);
412 _glfw.egl.ANGLE_platform_angle =
413 _glfwStringInExtensionString("EGL_ANGLE_platform_angle", extensions);
414 _glfw.egl.ANGLE_platform_angle_opengl =
415 _glfwStringInExtensionString("EGL_ANGLE_platform_angle_opengl", extensions);
416 _glfw.egl.ANGLE_platform_angle_d3d =
417 _glfwStringInExtensionString("EGL_ANGLE_platform_angle_d3d", extensions);
418 _glfw.egl.ANGLE_platform_angle_vulkan =
419 _glfwStringInExtensionString("EGL_ANGLE_platform_angle_vulkan", extensions);
420 _glfw.egl.ANGLE_platform_angle_metal =
421 _glfwStringInExtensionString("EGL_ANGLE_platform_angle_metal", extensions);
424 if (_glfw.egl.EXT_platform_base)
426 _glfw.egl.GetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)
427 eglGetProcAddress("eglGetPlatformDisplayEXT");
428 _glfw.egl.CreatePlatformWindowSurfaceEXT = (PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC)
429 eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
432 _glfw.egl.platform = _glfwPlatformGetEGLPlatform(&attribs);
433 if (_glfw.egl.platform)
436 eglGetPlatformDisplayEXT(_glfw.egl.platform,
437 _glfwPlatformGetEGLNativeDisplay(),
441 _glfw.egl.display = eglGetDisplay(_glfwPlatformGetEGLNativeDisplay());
445 if (_glfw.egl.display == EGL_NO_DISPLAY)
447 _glfwInputError(GLFW_API_UNAVAILABLE,
448 "EGL: Failed to get EGL display: %s",
449 getEGLErrorString(eglGetError()));
455 if (!eglInitialize(_glfw.egl.display, &_glfw.egl.major, &_glfw.egl.minor))
457 _glfwInputError(GLFW_API_UNAVAILABLE,
458 "EGL: Failed to initialize EGL: %s",
459 getEGLErrorString(eglGetError()));
465 _glfw.egl.KHR_create_context =
466 extensionSupportedEGL("EGL_KHR_create_context");
467 _glfw.egl.KHR_create_context_no_error =
468 extensionSupportedEGL("EGL_KHR_create_context_no_error");
469 _glfw.egl.KHR_gl_colorspace =
470 extensionSupportedEGL("EGL_KHR_gl_colorspace");
471 _glfw.egl.KHR_get_all_proc_addresses =
472 extensionSupportedEGL("EGL_KHR_get_all_proc_addresses");
473 _glfw.egl.KHR_context_flush_control =
474 extensionSupportedEGL("EGL_KHR_context_flush_control");
481 void _glfwTerminateEGL(void)
483 if (_glfw.egl.display)
485 eglTerminate(_glfw.egl.display);
486 _glfw.egl.display = EGL_NO_DISPLAY;
489 if (_glfw.egl.handle)
491 _glfw_dlclose(_glfw.egl.handle);
492 _glfw.egl.handle = NULL;
496 #define setAttrib(a, v) \
498 assert(((size_t) index + 1) < sizeof(attribs) / sizeof(attribs[0])); \
499 attribs[index++] = a; \
500 attribs[index++] = v; \
503 // Create the OpenGL or OpenGL ES context
505 GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
506 const _GLFWctxconfig* ctxconfig,
507 const _GLFWfbconfig* fbconfig)
511 EGLContext share = NULL;
512 EGLNativeWindowType native;
515 if (!_glfw.egl.display)
517 _glfwInputError(GLFW_API_UNAVAILABLE, "EGL: API not available");
521 if (ctxconfig->share)
522 share = ctxconfig->share->context.egl.handle;
524 if (!chooseEGLConfig(ctxconfig, fbconfig, &config))
526 _glfwInputError(GLFW_FORMAT_UNAVAILABLE,
527 "EGL: Failed to find a suitable EGLConfig");
531 if (ctxconfig->client == GLFW_OPENGL_ES_API)
533 if (!eglBindAPI(EGL_OPENGL_ES_API))
535 _glfwInputError(GLFW_API_UNAVAILABLE,
536 "EGL: Failed to bind OpenGL ES: %s",
537 getEGLErrorString(eglGetError()));
543 if (!eglBindAPI(EGL_OPENGL_API))
545 _glfwInputError(GLFW_API_UNAVAILABLE,
546 "EGL: Failed to bind OpenGL: %s",
547 getEGLErrorString(eglGetError()));
552 if (_glfw.egl.KHR_create_context)
554 int mask = 0, flags = 0;
556 if (ctxconfig->client == GLFW_OPENGL_API)
558 if (ctxconfig->forward)
559 flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
561 if (ctxconfig->profile == GLFW_OPENGL_CORE_PROFILE)
562 mask |= EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
563 else if (ctxconfig->profile == GLFW_OPENGL_COMPAT_PROFILE)
564 mask |= EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
567 if (ctxconfig->debug)
568 flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
570 if (ctxconfig->robustness)
572 if (ctxconfig->robustness == GLFW_NO_RESET_NOTIFICATION)
574 setAttrib(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR,
575 EGL_NO_RESET_NOTIFICATION_KHR);
577 else if (ctxconfig->robustness == GLFW_LOSE_CONTEXT_ON_RESET)
579 setAttrib(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_KHR,
580 EGL_LOSE_CONTEXT_ON_RESET_KHR);
583 flags |= EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR;
586 if (ctxconfig->noerror)
588 if (_glfw.egl.KHR_create_context_no_error)
589 setAttrib(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, GLFW_TRUE);
592 if (ctxconfig->major != 1 || ctxconfig->minor != 0)
594 setAttrib(EGL_CONTEXT_MAJOR_VERSION_KHR, ctxconfig->major);
595 setAttrib(EGL_CONTEXT_MINOR_VERSION_KHR, ctxconfig->minor);
599 setAttrib(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, mask);
602 setAttrib(EGL_CONTEXT_FLAGS_KHR, flags);
606 if (ctxconfig->client == GLFW_OPENGL_ES_API)
607 setAttrib(EGL_CONTEXT_CLIENT_VERSION, ctxconfig->major);
610 if (_glfw.egl.KHR_context_flush_control)
612 if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_NONE)
614 setAttrib(EGL_CONTEXT_RELEASE_BEHAVIOR_KHR,
615 EGL_CONTEXT_RELEASE_BEHAVIOR_NONE_KHR);
617 else if (ctxconfig->release == GLFW_RELEASE_BEHAVIOR_FLUSH)
619 setAttrib(EGL_CONTEXT_RELEASE_BEHAVIOR_KHR,
620 EGL_CONTEXT_RELEASE_BEHAVIOR_FLUSH_KHR);
624 setAttrib(EGL_NONE, EGL_NONE);
626 window->context.egl.handle = eglCreateContext(_glfw.egl.display,
627 config, share, attribs);
629 if (window->context.egl.handle == EGL_NO_CONTEXT)
631 _glfwInputError(GLFW_VERSION_UNAVAILABLE,
632 "EGL: Failed to create context: %s",
633 getEGLErrorString(eglGetError()));
637 // Set up attributes for surface creation
642 if (_glfw.egl.KHR_gl_colorspace)
643 setAttrib(EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR);
646 setAttrib(EGL_NONE, EGL_NONE);
648 native = _glfwPlatformGetEGLNativeWindow(window);
649 // HACK: ANGLE does not implement eglCreatePlatformWindowSurfaceEXT
650 // despite reporting EGL_EXT_platform_base
651 if (_glfw.egl.platform && _glfw.egl.platform != EGL_PLATFORM_ANGLE_ANGLE)
653 window->context.egl.surface =
654 eglCreatePlatformWindowSurfaceEXT(_glfw.egl.display, config, native, attribs);
658 window->context.egl.surface =
659 eglCreateWindowSurface(_glfw.egl.display, config, native, attribs);
662 if (window->context.egl.surface == EGL_NO_SURFACE)
664 _glfwInputError(GLFW_PLATFORM_ERROR,
665 "EGL: Failed to create window surface: %s",
666 getEGLErrorString(eglGetError()));
670 window->context.egl.config = config;
672 // Load the appropriate client library
673 if (!_glfw.egl.KHR_get_all_proc_addresses)
676 const char** sonames;
677 const char* es1sonames[] =
679 #if defined(_GLFW_GLESV1_LIBRARY)
680 _GLFW_GLESV1_LIBRARY,
681 #elif defined(_GLFW_WIN32)
684 #elif defined(_GLFW_COCOA)
685 "libGLESv1_CM.dylib",
692 const char* es2sonames[] =
694 #if defined(_GLFW_GLESV2_LIBRARY)
695 _GLFW_GLESV2_LIBRARY,
696 #elif defined(_GLFW_WIN32)
699 #elif defined(_GLFW_COCOA)
701 #elif defined(__CYGWIN__)
708 const char* glsonames[] =
710 #if defined(_GLFW_OPENGL_LIBRARY)
711 _GLFW_OPENGL_LIBRARY,
712 #elif defined(_GLFW_WIN32)
713 #elif defined(_GLFW_COCOA)
720 if (ctxconfig->client == GLFW_OPENGL_ES_API)
722 if (ctxconfig->major == 1)
723 sonames = es1sonames;
725 sonames = es2sonames;
730 for (i = 0; sonames[i]; i++)
732 // HACK: Match presence of lib prefix to increase chance of finding
733 // a matching pair in the jungle that is Win32 EGL/GLES
734 if (_glfw.egl.prefix != (strncmp(sonames[i], "lib", 3) == 0))
737 window->context.egl.client = _glfw_dlopen(sonames[i]);
738 if (window->context.egl.client)
742 if (!window->context.egl.client)
744 _glfwInputError(GLFW_API_UNAVAILABLE,
745 "EGL: Failed to load client library");
750 window->context.makeCurrent = makeContextCurrentEGL;
751 window->context.swapBuffers = swapBuffersEGL;
752 window->context.swapInterval = swapIntervalEGL;
753 window->context.extensionSupported = extensionSupportedEGL;
754 window->context.getProcAddress = getProcAddressEGL;
755 window->context.destroy = destroyContextEGL;
762 // Returns the Visual and depth of the chosen EGLConfig
764 #if defined(_GLFW_X11)
765 GLFWbool _glfwChooseVisualEGL(const _GLFWwndconfig* wndconfig,
766 const _GLFWctxconfig* ctxconfig,
767 const _GLFWfbconfig* fbconfig,
768 Visual** visual, int* depth)
773 EGLint visualID = 0, count = 0;
774 const long vimask = VisualScreenMask | VisualIDMask;
776 if (!chooseEGLConfig(ctxconfig, fbconfig, &native))
778 _glfwInputError(GLFW_FORMAT_UNAVAILABLE,
779 "EGL: Failed to find a suitable EGLConfig");
783 eglGetConfigAttrib(_glfw.egl.display, native,
784 EGL_NATIVE_VISUAL_ID, &visualID);
786 desired.screen = _glfw.x11.screen;
787 desired.visualid = visualID;
789 result = XGetVisualInfo(_glfw.x11.display, vimask, &desired, &count);
792 _glfwInputError(GLFW_PLATFORM_ERROR,
793 "EGL: Failed to retrieve Visual for EGLConfig");
797 *visual = result->visual;
798 *depth = result->depth;
806 //////////////////////////////////////////////////////////////////////////
807 ////// GLFW native API //////
808 //////////////////////////////////////////////////////////////////////////
810 GLFWAPI EGLDisplay glfwGetEGLDisplay(void)
812 _GLFW_REQUIRE_INIT_OR_RETURN(EGL_NO_DISPLAY);
813 return _glfw.egl.display;
816 GLFWAPI EGLContext glfwGetEGLContext(GLFWwindow* handle)
818 _GLFWwindow* window = (_GLFWwindow*) handle;
819 _GLFW_REQUIRE_INIT_OR_RETURN(EGL_NO_CONTEXT);
821 if (window->context.client == GLFW_NO_API)
823 _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
824 return EGL_NO_CONTEXT;
827 return window->context.egl.handle;
830 GLFWAPI EGLSurface glfwGetEGLSurface(GLFWwindow* handle)
832 _GLFWwindow* window = (_GLFWwindow*) handle;
833 _GLFW_REQUIRE_INIT_OR_RETURN(EGL_NO_SURFACE);
835 if (window->context.client == GLFW_NO_API)
837 _glfwInputError(GLFW_NO_WINDOW_CONTEXT, NULL);
838 return EGL_NO_SURFACE;
841 return window->context.egl.surface;