1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * This is an EGL driver that wraps GLX. This gives the benefit of being
31 * completely agnostic of the direct rendering implementation.
33 * Authors: Alan Hourihane <alanh@tungstengraphics.com>
41 #include "eglconfigutil.h"
42 #include "eglconfig.h"
43 #include "eglcontext.h"
44 #include "egldisplay.h"
45 #include "egldriver.h"
46 #include "eglglobals.h"
48 #include "eglsurface.h"
50 #define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
51 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
53 #ifndef GLX_VERSION_1_4
54 #error "GL/glx.h must be equal to or greater than GLX 1.4"
57 /** subclass of _EGLDriver */
60 _EGLDriver Base
; /**< base class */
64 /** driver data of _EGLDisplay */
65 struct GLX_egl_display
69 GLXFBConfig
*fbconfigs
;
73 const char *extensions
;
75 EGLBoolean have_make_current_read
;
76 EGLBoolean have_fbconfig
;
77 EGLBoolean have_pbuffer
;
79 /* GLX_SGIX_pbuffer */
80 PFNGLXCREATEGLXPBUFFERSGIXPROC glXCreateGLXPbufferSGIX
;
81 PFNGLXDESTROYGLXPBUFFERSGIXPROC glXDestroyGLXPbufferSGIX
;
83 /* workaround quirks of different GLX implementations */
84 EGLBoolean single_buffered_quirk
;
85 EGLBoolean glx_window_quirk
;
90 /** subclass of _EGLContext */
91 struct GLX_egl_context
93 _EGLContext Base
; /**< base class */
99 /** subclass of _EGLSurface */
100 struct GLX_egl_surface
102 _EGLSurface Base
; /**< base class */
105 GLXDrawable glx_drawable
;
109 /** subclass of _EGLConfig */
110 struct GLX_egl_config
112 _EGLConfig Base
; /**< base class */
113 EGLBoolean double_buffered
;
118 static struct GLX_egl_driver
*
119 GLX_egl_driver(_EGLDriver
*drv
)
121 return (struct GLX_egl_driver
*) drv
;
124 static struct GLX_egl_display
*
125 GLX_egl_display(_EGLDisplay
*dpy
)
127 return (struct GLX_egl_display
*) dpy
->DriverData
;
130 static struct GLX_egl_context
*
131 GLX_egl_context(_EGLContext
*ctx
)
133 return (struct GLX_egl_context
*) ctx
;
136 static struct GLX_egl_surface
*
137 GLX_egl_surface(_EGLSurface
*surf
)
139 return (struct GLX_egl_surface
*) surf
;
143 GLX_egl_config_index(_EGLConfig
*conf
)
145 return ((struct GLX_egl_config
*) conf
)->index
;
149 #define MAP_ATTRIB(attr, memb) \
150 { attr, offsetof(__GLcontextModes, memb) }
153 static const struct {
156 } fbconfig_attributes
[] = {
157 /* table 3.1 of GLX 1.4 */
158 MAP_ATTRIB(GLX_FBCONFIG_ID
, fbconfigID
),
159 MAP_ATTRIB(GLX_BUFFER_SIZE
, rgbBits
),
160 MAP_ATTRIB(GLX_LEVEL
, level
),
161 MAP_ATTRIB(GLX_DOUBLEBUFFER
, doubleBufferMode
),
162 MAP_ATTRIB(GLX_STEREO
, stereoMode
),
163 MAP_ATTRIB(GLX_AUX_BUFFERS
, numAuxBuffers
),
164 MAP_ATTRIB(GLX_RED_SIZE
, redBits
),
165 MAP_ATTRIB(GLX_GREEN_SIZE
, greenBits
),
166 MAP_ATTRIB(GLX_BLUE_SIZE
, blueBits
),
167 MAP_ATTRIB(GLX_ALPHA_SIZE
, alphaBits
),
168 MAP_ATTRIB(GLX_DEPTH_SIZE
, depthBits
),
169 MAP_ATTRIB(GLX_STENCIL_SIZE
, stencilBits
),
170 MAP_ATTRIB(GLX_ACCUM_RED_SIZE
, accumRedBits
),
171 MAP_ATTRIB(GLX_ACCUM_GREEN_SIZE
, accumGreenBits
),
172 MAP_ATTRIB(GLX_ACCUM_BLUE_SIZE
, accumBlueBits
),
173 MAP_ATTRIB(GLX_ACCUM_ALPHA_SIZE
, accumAlphaBits
),
174 MAP_ATTRIB(GLX_SAMPLE_BUFFERS
, sampleBuffers
),
175 MAP_ATTRIB(GLX_SAMPLES
, samples
),
176 MAP_ATTRIB(GLX_RENDER_TYPE
, renderType
),
177 MAP_ATTRIB(GLX_DRAWABLE_TYPE
, drawableType
),
178 MAP_ATTRIB(GLX_X_RENDERABLE
, xRenderable
),
179 MAP_ATTRIB(GLX_X_VISUAL_TYPE
, visualType
),
180 MAP_ATTRIB(GLX_CONFIG_CAVEAT
, visualRating
),
181 MAP_ATTRIB(GLX_TRANSPARENT_TYPE
, transparentPixel
),
182 MAP_ATTRIB(GLX_TRANSPARENT_INDEX_VALUE
, transparentIndex
),
183 MAP_ATTRIB(GLX_TRANSPARENT_RED_VALUE
, transparentRed
),
184 MAP_ATTRIB(GLX_TRANSPARENT_GREEN_VALUE
, transparentGreen
),
185 MAP_ATTRIB(GLX_TRANSPARENT_BLUE_VALUE
, transparentBlue
),
186 MAP_ATTRIB(GLX_TRANSPARENT_ALPHA_VALUE
, transparentAlpha
),
187 MAP_ATTRIB(GLX_MAX_PBUFFER_WIDTH
, maxPbufferWidth
),
188 MAP_ATTRIB(GLX_MAX_PBUFFER_HEIGHT
, maxPbufferHeight
),
189 MAP_ATTRIB(GLX_MAX_PBUFFER_PIXELS
, maxPbufferPixels
),
190 MAP_ATTRIB(GLX_VISUAL_ID
, visualID
),
195 convert_fbconfig(Display
*dpy
, GLXFBConfig fbconfig
,
196 struct GLX_egl_config
*GLX_conf
)
198 __GLcontextModes mode
;
199 int err
= 0, attr
, val
, i
;
201 memset(&mode
, 0, sizeof(mode
));
203 for (i
= 0; i
< ARRAY_SIZE(fbconfig_attributes
); i
++) {
204 int offset
= fbconfig_attributes
[i
].offset
;
205 attr
= fbconfig_attributes
[i
].attr
;
206 err
= glXGetFBConfigAttrib(dpy
, fbconfig
, attr
, &val
);
208 if (err
== GLX_BAD_ATTRIBUTE
) {
214 *((int *) ((char *) &mode
+ offset
)) = val
;
219 /* must have rgba bit */
220 if (!(mode
.renderType
& GLX_RGBA_BIT
))
223 /* pixmap and pbuffer surfaces must be single-buffered in EGL */
224 if (mode
.doubleBufferMode
) {
225 mode
.drawableType
&= ~(GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
);
226 if (!mode
.drawableType
)
230 mode
.rgbMode
= GL_TRUE
;
231 mode
.haveAccumBuffer
= (mode
.accumRedBits
+
232 mode
.accumGreenBits
+
234 mode
.accumAlphaBits
> 0);
235 mode
.haveDepthBuffer
= (mode
.depthBits
> 0);
236 mode
.haveStencilBuffer
= (mode
.stencilBits
> 0);
238 GLX_conf
->double_buffered
= (mode
.doubleBufferMode
!= 0);
239 return _eglConfigFromContextModesRec(&GLX_conf
->Base
, &mode
,
240 EGL_OPENGL_BIT
, EGL_OPENGL_BIT
);
244 static const struct {
247 } visual_attributes
[] = {
248 /* table 3.7 of GLX 1.4 */
250 MAP_ATTRIB(GLX_BUFFER_SIZE
, rgbBits
),
251 MAP_ATTRIB(GLX_LEVEL
, level
),
252 MAP_ATTRIB(GLX_RGBA
, rgbMode
),
253 MAP_ATTRIB(GLX_DOUBLEBUFFER
, doubleBufferMode
),
254 MAP_ATTRIB(GLX_STEREO
, stereoMode
),
255 MAP_ATTRIB(GLX_AUX_BUFFERS
, numAuxBuffers
),
256 MAP_ATTRIB(GLX_RED_SIZE
, redBits
),
257 MAP_ATTRIB(GLX_GREEN_SIZE
, greenBits
),
258 MAP_ATTRIB(GLX_BLUE_SIZE
, blueBits
),
259 MAP_ATTRIB(GLX_ALPHA_SIZE
, alphaBits
),
260 MAP_ATTRIB(GLX_DEPTH_SIZE
, depthBits
),
261 MAP_ATTRIB(GLX_STENCIL_SIZE
, stencilBits
),
262 MAP_ATTRIB(GLX_ACCUM_RED_SIZE
, accumRedBits
),
263 MAP_ATTRIB(GLX_ACCUM_GREEN_SIZE
, accumGreenBits
),
264 MAP_ATTRIB(GLX_ACCUM_BLUE_SIZE
, accumBlueBits
),
265 MAP_ATTRIB(GLX_ACCUM_ALPHA_SIZE
, accumAlphaBits
),
266 MAP_ATTRIB(GLX_SAMPLE_BUFFERS
, sampleBuffers
),
267 MAP_ATTRIB(GLX_SAMPLES
, samples
),
268 MAP_ATTRIB(GLX_FBCONFIG_ID
, fbconfigID
),
269 /* GLX_EXT_visual_rating */
270 MAP_ATTRIB(GLX_VISUAL_CAVEAT_EXT
, visualRating
),
275 get_visual_type(const XVisualInfo
*vis
)
279 #if defined(__cplusplus) || defined(c_plusplus)
280 klass
= vis
->c_class
;
287 return GLX_TRUE_COLOR
;
289 return GLX_DIRECT_COLOR
;
291 return GLX_PSEUDO_COLOR
;
293 return GLX_STATIC_COLOR
;
295 return GLX_GRAY_SCALE
;
297 return GLX_STATIC_GRAY
;
305 convert_visual(Display
*dpy
, XVisualInfo
*vinfo
,
306 struct GLX_egl_config
*GLX_conf
)
308 __GLcontextModes mode
;
309 int err
, attr
, val
, i
;
311 /* the visual must support OpenGL */
312 err
= glXGetConfig(dpy
, vinfo
, GLX_USE_GL
, &val
);
316 memset(&mode
, 0, sizeof(mode
));
318 for (i
= 0; i
< ARRAY_SIZE(visual_attributes
); i
++) {
319 int offset
= visual_attributes
[i
].offset
;
320 attr
= visual_attributes
[i
].attr
;
321 err
= glXGetConfig(dpy
, vinfo
, attr
, &val
);
323 if (err
== GLX_BAD_ATTRIBUTE
) {
329 *((int *) ((char *) &mode
+ offset
)) = val
;
334 /* must be RGB mode */
338 mode
.visualID
= vinfo
->visualid
;
339 mode
.visualType
= get_visual_type(vinfo
);
340 mode
.redMask
= vinfo
->red_mask
;
341 mode
.greenMask
= vinfo
->green_mask
;
342 mode
.blueMask
= vinfo
->blue_mask
;
344 mode
.drawableType
= GLX_WINDOW_BIT
;
345 /* pixmap surfaces must be single-buffered in EGL */
346 if (!mode
.doubleBufferMode
)
347 mode
.drawableType
|= GLX_PIXMAP_BIT
;
349 mode
.renderType
= GLX_RGBA_BIT
;
350 mode
.xRenderable
= GL_TRUE
;
351 mode
.haveAccumBuffer
= (mode
.accumRedBits
+
352 mode
.accumGreenBits
+
354 mode
.accumAlphaBits
> 0);
355 mode
.haveDepthBuffer
= (mode
.depthBits
> 0);
356 mode
.haveStencilBuffer
= (mode
.stencilBits
> 0);
358 GLX_conf
->double_buffered
= (mode
.doubleBufferMode
!= 0);
359 return _eglConfigFromContextModesRec(&GLX_conf
->Base
, &mode
,
360 EGL_OPENGL_BIT
, EGL_OPENGL_BIT
);
365 fix_config(struct GLX_egl_display
*GLX_dpy
, struct GLX_egl_config
*GLX_conf
)
367 _EGLConfig
*conf
= &GLX_conf
->Base
;
368 EGLint surface_type
, r
, g
, b
, a
;
370 surface_type
= GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
);
371 if (!GLX_conf
->double_buffered
&& GLX_dpy
->single_buffered_quirk
) {
372 /* some GLX impls do not like single-buffered window surface */
373 surface_type
&= ~EGL_WINDOW_BIT
;
374 /* pbuffer bit is usually not set */
375 if (GLX_dpy
->have_pbuffer
)
376 surface_type
|= EGL_PBUFFER_BIT
;
377 SET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
, surface_type
);
380 /* no visual attribs unless window bit is set */
381 if (!(surface_type
& EGL_WINDOW_BIT
)) {
382 SET_CONFIG_ATTRIB(conf
, EGL_NATIVE_VISUAL_ID
, 0);
383 SET_CONFIG_ATTRIB(conf
, EGL_NATIVE_VISUAL_TYPE
, EGL_NONE
);
386 /* make sure buffer size is set correctly */
387 r
= GET_CONFIG_ATTRIB(conf
, EGL_RED_SIZE
);
388 g
= GET_CONFIG_ATTRIB(conf
, EGL_GREEN_SIZE
);
389 b
= GET_CONFIG_ATTRIB(conf
, EGL_BLUE_SIZE
);
390 a
= GET_CONFIG_ATTRIB(conf
, EGL_ALPHA_SIZE
);
391 SET_CONFIG_ATTRIB(conf
, EGL_BUFFER_SIZE
, r
+ g
+ b
+ a
);
396 create_configs(_EGLDisplay
*dpy
, struct GLX_egl_display
*GLX_dpy
,
399 EGLint num_configs
= 0, i
;
402 if (GLX_dpy
->have_fbconfig
) {
403 GLX_dpy
->fbconfigs
= glXGetFBConfigs(GLX_dpy
->dpy
, screen
, &num_configs
);
406 XVisualInfo vinfo_template
;
409 vinfo_template
.screen
= screen
;
410 mask
= VisualScreenMask
;
411 GLX_dpy
->visuals
= XGetVisualInfo(GLX_dpy
->dpy
, mask
, &vinfo_template
,
418 for (i
= 0; i
< num_configs
; i
++) {
419 struct GLX_egl_config
*GLX_conf
, template;
422 memset(&template, 0, sizeof(template));
423 _eglInitConfig(&template.Base
, id
);
424 if (GLX_dpy
->have_fbconfig
)
425 ok
= convert_fbconfig(GLX_dpy
->dpy
, GLX_dpy
->fbconfigs
[i
], &template);
427 ok
= convert_visual(GLX_dpy
->dpy
, &GLX_dpy
->visuals
[i
], &template);
431 fix_config(GLX_dpy
, &template);
432 if (!_eglValidateConfig(&template.Base
, EGL_FALSE
)) {
433 _eglLog(_EGL_DEBUG
, "GLX: failed to validate config %d", i
);
437 GLX_conf
= CALLOC_STRUCT(GLX_egl_config
);
439 memcpy(GLX_conf
, &template, sizeof(template));
442 _eglAddConfig(dpy
, &GLX_conf
->Base
);
452 check_extensions(struct GLX_egl_display
*GLX_dpy
, EGLint screen
)
454 GLX_dpy
->extensions
=
455 glXQueryExtensionsString(GLX_dpy
->dpy
, screen
);
456 if (GLX_dpy
->extensions
) {
457 /* glXGetProcAddress is assumed */
459 if (strstr(GLX_dpy
->extensions
, "GLX_SGI_make_current_read")) {
460 /* GLX 1.3 entry points are used */
461 GLX_dpy
->have_make_current_read
= EGL_TRUE
;
464 if (strstr(GLX_dpy
->extensions
, "GLX_SGIX_fbconfig")) {
465 /* GLX 1.3 entry points are used */
466 GLX_dpy
->have_fbconfig
= EGL_TRUE
;
469 if (strstr(GLX_dpy
->extensions
, "GLX_SGIX_pbuffer")) {
470 GLX_dpy
->glXCreateGLXPbufferSGIX
= (PFNGLXCREATEGLXPBUFFERSGIXPROC
)
471 glXGetProcAddress((const GLubyte
*) "glXCreateGLXPbufferSGIX");
472 GLX_dpy
->glXDestroyGLXPbufferSGIX
= (PFNGLXDESTROYGLXPBUFFERSGIXPROC
)
473 glXGetProcAddress((const GLubyte
*) "glXDestroyGLXPbufferSGIX");
475 if (GLX_dpy
->glXCreateGLXPbufferSGIX
&&
476 GLX_dpy
->glXDestroyGLXPbufferSGIX
&&
477 GLX_dpy
->have_fbconfig
)
478 GLX_dpy
->have_pbuffer
= EGL_TRUE
;
482 if (GLX_dpy
->glx_maj
== 1 && GLX_dpy
->glx_min
>= 3) {
483 GLX_dpy
->have_1_3
= EGL_TRUE
;
484 GLX_dpy
->have_make_current_read
= EGL_TRUE
;
485 GLX_dpy
->have_fbconfig
= EGL_TRUE
;
486 GLX_dpy
->have_pbuffer
= EGL_TRUE
;
492 check_quirks(struct GLX_egl_display
*GLX_dpy
, EGLint screen
)
496 GLX_dpy
->single_buffered_quirk
= EGL_TRUE
;
497 GLX_dpy
->glx_window_quirk
= EGL_TRUE
;
499 vendor
= glXGetClientString(GLX_dpy
->dpy
, GLX_VENDOR
);
500 if (vendor
&& strstr(vendor
, "NVIDIA")) {
501 vendor
= glXQueryServerString(GLX_dpy
->dpy
, screen
, GLX_VENDOR
);
502 if (vendor
&& strstr(vendor
, "NVIDIA")) {
503 _eglLog(_EGL_DEBUG
, "disable quirks");
504 GLX_dpy
->single_buffered_quirk
= EGL_FALSE
;
505 GLX_dpy
->glx_window_quirk
= EGL_FALSE
;
512 * Called via eglInitialize(), GLX_drv->API.Initialize().
515 GLX_eglInitialize(_EGLDriver
*drv
, _EGLDisplay
*disp
,
516 EGLint
*major
, EGLint
*minor
)
518 struct GLX_egl_display
*GLX_dpy
;
520 GLX_dpy
= CALLOC_STRUCT(GLX_egl_display
);
522 return _eglError(EGL_BAD_ALLOC
, "eglInitialize");
524 GLX_dpy
->dpy
= (Display
*) disp
->NativeDisplay
;
526 GLX_dpy
->dpy
= XOpenDisplay(NULL
);
528 _eglLog(_EGL_WARNING
, "GLX: XOpenDisplay failed");
534 if (!glXQueryVersion(GLX_dpy
->dpy
, &GLX_dpy
->glx_maj
, &GLX_dpy
->glx_min
)) {
535 _eglLog(_EGL_WARNING
, "GLX: glXQueryVersion failed");
536 if (!disp
->NativeDisplay
)
537 XCloseDisplay(GLX_dpy
->dpy
);
542 check_extensions(GLX_dpy
, DefaultScreen(GLX_dpy
->dpy
));
543 check_quirks(GLX_dpy
, DefaultScreen(GLX_dpy
->dpy
));
545 create_configs(disp
, GLX_dpy
, DefaultScreen(GLX_dpy
->dpy
));
546 if (!disp
->NumConfigs
) {
547 _eglLog(_EGL_WARNING
, "GLX: failed to create any config");
548 if (!disp
->NativeDisplay
)
549 XCloseDisplay(GLX_dpy
->dpy
);
554 disp
->DriverData
= (void *) GLX_dpy
;
555 disp
->ClientAPIsMask
= EGL_OPENGL_BIT
;
557 /* we're supporting EGL 1.4 */
565 * Called via eglTerminate(), drv->API.Terminate().
568 GLX_eglTerminate(_EGLDriver
*drv
, _EGLDisplay
*disp
)
570 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
572 _eglReleaseDisplayResources(drv
, disp
);
573 _eglCleanupDisplay(disp
);
575 if (GLX_dpy
->visuals
)
576 XFree(GLX_dpy
->visuals
);
577 if (GLX_dpy
->fbconfigs
)
578 XFree(GLX_dpy
->fbconfigs
);
580 if (!disp
->NativeDisplay
)
581 XCloseDisplay(GLX_dpy
->dpy
);
584 disp
->DriverData
= NULL
;
591 * Called via eglCreateContext(), drv->API.CreateContext().
594 GLX_eglCreateContext(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
595 _EGLContext
*share_list
, const EGLint
*attrib_list
)
597 struct GLX_egl_context
*GLX_ctx
= CALLOC_STRUCT(GLX_egl_context
);
598 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
599 struct GLX_egl_context
*GLX_ctx_shared
= GLX_egl_context(share_list
);
602 _eglError(EGL_BAD_ALLOC
, "eglCreateContext");
606 if (!_eglInitContext(drv
, &GLX_ctx
->Base
, conf
, attrib_list
)) {
611 if (GLX_dpy
->have_fbconfig
)
613 glXCreateNewContext(GLX_dpy
->dpy
,
614 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
616 GLX_ctx_shared
? GLX_ctx_shared
->context
: NULL
,
620 glXCreateContext(GLX_dpy
->dpy
,
621 &GLX_dpy
->visuals
[GLX_egl_config_index(conf
)],
622 GLX_ctx_shared
? GLX_ctx_shared
->context
: NULL
,
624 if (!GLX_ctx
->context
) {
629 return &GLX_ctx
->Base
;
634 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
637 GLX_eglMakeCurrent(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*dsurf
,
638 _EGLSurface
*rsurf
, _EGLContext
*ctx
)
640 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
641 struct GLX_egl_surface
*GLX_dsurf
= GLX_egl_surface(dsurf
);
642 struct GLX_egl_surface
*GLX_rsurf
= GLX_egl_surface(rsurf
);
643 struct GLX_egl_context
*GLX_ctx
= GLX_egl_context(ctx
);
644 GLXDrawable ddraw
, rdraw
;
647 if (!_eglMakeCurrent(drv
, disp
, dsurf
, rsurf
, ctx
))
650 ddraw
= (GLX_dsurf
) ? GLX_dsurf
->glx_drawable
: None
;
651 rdraw
= (GLX_rsurf
) ? GLX_rsurf
->glx_drawable
: None
;
652 cctx
= (GLX_ctx
) ? GLX_ctx
->context
: NULL
;
654 if (GLX_dpy
->have_make_current_read
)
655 return glXMakeContextCurrent(GLX_dpy
->dpy
, ddraw
, rdraw
, cctx
);
656 else if (ddraw
== rdraw
)
657 return glXMakeCurrent(GLX_dpy
->dpy
, ddraw
, cctx
);
662 /** Get size of given window */
664 get_drawable_size(Display
*dpy
, Drawable d
, uint
*width
, uint
*height
)
669 unsigned int w
, h
, bw
, depth
;
670 stat
= XGetGeometry(dpy
, d
, &root
, &xpos
, &ypos
, &w
, &h
, &bw
, &depth
);
677 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
680 GLX_eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
681 NativeWindowType window
, const EGLint
*attrib_list
)
683 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
684 struct GLX_egl_surface
*GLX_surf
;
687 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
689 _eglError(EGL_BAD_ALLOC
, "eglCreateWindowSurface");
693 if (!_eglInitSurface(drv
, &GLX_surf
->Base
, EGL_WINDOW_BIT
,
694 conf
, attrib_list
)) {
699 GLX_surf
->drawable
= window
;
701 if (GLX_dpy
->have_1_3
&& !GLX_dpy
->glx_window_quirk
)
702 GLX_surf
->glx_drawable
=
703 glXCreateWindow(GLX_dpy
->dpy
,
704 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
705 GLX_surf
->drawable
, NULL
);
707 GLX_surf
->glx_drawable
= GLX_surf
->drawable
;
709 if (!GLX_surf
->glx_drawable
) {
714 get_drawable_size(GLX_dpy
->dpy
, window
, &width
, &height
);
715 GLX_surf
->Base
.Width
= width
;
716 GLX_surf
->Base
.Height
= height
;
718 return &GLX_surf
->Base
;
722 GLX_eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLConfig
*conf
,
723 NativePixmapType pixmap
, const EGLint
*attrib_list
)
725 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
726 struct GLX_egl_surface
*GLX_surf
;
729 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
731 _eglError(EGL_BAD_ALLOC
, "eglCreatePixmapSurface");
735 if (!_eglInitSurface(drv
, &GLX_surf
->Base
, EGL_PIXMAP_BIT
,
736 conf
, attrib_list
)) {
741 GLX_surf
->drawable
= pixmap
;
743 if (GLX_dpy
->have_1_3
) {
744 GLX_surf
->glx_drawable
=
745 glXCreatePixmap(GLX_dpy
->dpy
,
746 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
747 GLX_surf
->drawable
, NULL
);
749 else if (GLX_dpy
->have_fbconfig
) {
750 GLXFBConfig fbconfig
= GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)];
751 XVisualInfo
*vinfo
= glXGetVisualFromFBConfig(GLX_dpy
->dpy
, fbconfig
);
753 GLX_surf
->glx_drawable
=
754 glXCreateGLXPixmap(GLX_dpy
->dpy
, vinfo
, GLX_surf
->drawable
);
759 GLX_surf
->glx_drawable
=
760 glXCreateGLXPixmap(GLX_dpy
->dpy
,
761 &GLX_dpy
->visuals
[GLX_egl_config_index(conf
)],
765 if (!GLX_surf
->glx_drawable
) {
770 get_drawable_size(GLX_dpy
->dpy
, pixmap
, &width
, &height
);
771 GLX_surf
->Base
.Width
= width
;
772 GLX_surf
->Base
.Height
= height
;
774 return &GLX_surf
->Base
;
778 GLX_eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*disp
,
779 _EGLConfig
*conf
, const EGLint
*attrib_list
)
781 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
782 struct GLX_egl_surface
*GLX_surf
;
786 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
788 _eglError(EGL_BAD_ALLOC
, "eglCreatePbufferSurface");
792 if (!_eglInitSurface(drv
, &GLX_surf
->Base
, EGL_PBUFFER_BIT
,
793 conf
, attrib_list
)) {
801 GLX_surf
->drawable
= None
;
803 if (GLX_dpy
->have_1_3
) {
804 /* put geometry in attribs */
805 if (GLX_surf
->Base
.Width
) {
806 attribs
[i
++] = GLX_PBUFFER_WIDTH
;
807 attribs
[i
++] = GLX_surf
->Base
.Width
;
809 if (GLX_surf
->Base
.Height
) {
810 attribs
[i
++] = GLX_PBUFFER_HEIGHT
;
811 attribs
[i
++] = GLX_surf
->Base
.Height
;
815 GLX_surf
->glx_drawable
=
816 glXCreatePbuffer(GLX_dpy
->dpy
,
817 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
820 else if (GLX_dpy
->have_pbuffer
) {
821 GLX_surf
->glx_drawable
= GLX_dpy
->glXCreateGLXPbufferSGIX(
823 GLX_dpy
->fbconfigs
[GLX_egl_config_index(conf
)],
824 GLX_surf
->Base
.Width
,
825 GLX_surf
->Base
.Height
,
829 if (!GLX_surf
->glx_drawable
) {
834 return &GLX_surf
->Base
;
838 GLX_eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*surf
)
840 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
841 if (!_eglIsSurfaceBound(surf
)) {
842 struct GLX_egl_surface
*GLX_surf
= GLX_egl_surface(surf
);
844 if (GLX_dpy
->have_1_3
) {
845 switch (surf
->Type
) {
847 if (!GLX_dpy
->glx_window_quirk
)
848 glXDestroyWindow(GLX_dpy
->dpy
, GLX_surf
->glx_drawable
);
850 case EGL_PBUFFER_BIT
:
851 glXDestroyPbuffer(GLX_dpy
->dpy
, GLX_surf
->glx_drawable
);
854 glXDestroyPixmap(GLX_dpy
->dpy
, GLX_surf
->glx_drawable
);
861 switch (surf
->Type
) {
862 case EGL_PBUFFER_BIT
:
863 GLX_dpy
->glXDestroyGLXPbufferSGIX(GLX_dpy
->dpy
,
864 GLX_surf
->glx_drawable
);
867 glXDestroyGLXPixmap(GLX_dpy
->dpy
, GLX_surf
->glx_drawable
);
881 GLX_eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*disp
, _EGLSurface
*draw
)
883 struct GLX_egl_display
*GLX_dpy
= GLX_egl_display(disp
);
884 struct GLX_egl_surface
*GLX_surf
= GLX_egl_surface(draw
);
886 glXSwapBuffers(GLX_dpy
->dpy
, GLX_surf
->glx_drawable
);
892 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
895 GLX_eglGetProcAddress(_EGLDriver
*drv
, const char *procname
)
897 return (_EGLProc
) glXGetProcAddress((const GLubyte
*) procname
);
901 GLX_eglWaitClient(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLContext
*ctx
)
908 GLX_eglWaitNative(_EGLDriver
*drv
, _EGLDisplay
*dpy
, EGLint engine
)
910 if (engine
!= EGL_CORE_NATIVE_ENGINE
)
911 return _eglError(EGL_BAD_PARAMETER
, "eglWaitNative");
917 GLX_Unload(_EGLDriver
*drv
)
919 struct GLX_egl_driver
*GLX_drv
= GLX_egl_driver(drv
);
925 * This is the main entrypoint into the driver, called by libEGL.
926 * Create a new _EGLDriver object and init its dispatch table.
929 _eglMain(const char *args
)
931 struct GLX_egl_driver
*GLX_drv
= CALLOC_STRUCT(GLX_egl_driver
);
936 _eglInitDriverFallbacks(&GLX_drv
->Base
);
937 GLX_drv
->Base
.API
.Initialize
= GLX_eglInitialize
;
938 GLX_drv
->Base
.API
.Terminate
= GLX_eglTerminate
;
939 GLX_drv
->Base
.API
.CreateContext
= GLX_eglCreateContext
;
940 GLX_drv
->Base
.API
.MakeCurrent
= GLX_eglMakeCurrent
;
941 GLX_drv
->Base
.API
.CreateWindowSurface
= GLX_eglCreateWindowSurface
;
942 GLX_drv
->Base
.API
.CreatePixmapSurface
= GLX_eglCreatePixmapSurface
;
943 GLX_drv
->Base
.API
.CreatePbufferSurface
= GLX_eglCreatePbufferSurface
;
944 GLX_drv
->Base
.API
.DestroySurface
= GLX_eglDestroySurface
;
945 GLX_drv
->Base
.API
.SwapBuffers
= GLX_eglSwapBuffers
;
946 GLX_drv
->Base
.API
.GetProcAddress
= GLX_eglGetProcAddress
;
947 GLX_drv
->Base
.API
.WaitClient
= GLX_eglWaitClient
;
948 GLX_drv
->Base
.API
.WaitNative
= GLX_eglWaitNative
;
950 GLX_drv
->Base
.Name
= "GLX";
951 GLX_drv
->Base
.Unload
= GLX_Unload
;
953 return &GLX_drv
->Base
;