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>
39 * test eglBind/ReleaseTexImage
45 #include <sys/types.h>
51 #include "glxclient.h"
53 #define _EGL_PLATFORM_X
55 #include "eglconfig.h"
56 #include "eglcontext.h"
57 #include "egldisplay.h"
58 #include "egldriver.h"
59 #include "eglglobals.h"
62 #include "eglsurface.h"
66 #define CALLOC_STRUCT(T) (struct T *) calloc(1, sizeof(struct T))
68 static const EGLint all_apis
= (EGL_OPENGL_ES_BIT
71 /* | EGL_OPENGL_BIT */); /* can't do */
75 /* X visual attribs */
79 int redMask
, greenMask
, blueMask
;
83 /* GL visual attribs */
86 int transparentRedValue
;
87 int transparentGreenValue
;
88 int transparentBlueValue
;
89 int transparentAlphaValue
;
90 int transparentIndexValue
;
97 int redSize
, greenSize
, blueSize
, alphaSize
;
100 int accumRedSize
, accumGreenSize
, accumBlueSize
, accumAlphaSize
;
101 int numSamples
, numMultisample
;
105 /** subclass of _EGLDriver */
106 struct GLX_egl_driver
108 _EGLDriver Base
; /**< base class */
110 XVisualInfo
*visuals
;
111 GLXFBConfig
*fbconfigs
;
113 int glx_maj
, glx_min
;
117 /** subclass of _EGLContext */
118 struct GLX_egl_context
120 _EGLContext Base
; /**< base class */
126 /** subclass of _EGLSurface */
127 struct GLX_egl_surface
129 _EGLSurface Base
; /**< base class */
131 GLXDrawable drawable
;
135 /** subclass of _EGLConfig */
136 struct GLX_egl_config
138 _EGLConfig Base
; /**< base class */
142 static struct GLX_egl_driver
*
143 GLX_egl_driver(_EGLDriver
*drv
)
145 return (struct GLX_egl_driver
*) drv
;
148 static struct GLX_egl_context
*
149 GLX_egl_context(_EGLContext
*ctx
)
151 return (struct GLX_egl_context
*) ctx
;
154 static struct GLX_egl_surface
*
155 GLX_egl_surface(_EGLSurface
*surf
)
157 return (struct GLX_egl_surface
*) surf
;
161 get_visual_attribs(Display
*dpy
, XVisualInfo
*vInfo
,
162 struct visual_attribs
*attribs
)
164 const char *ext
= glXQueryExtensionsString(dpy
, vInfo
->screen
);
167 memset(attribs
, 0, sizeof(struct visual_attribs
));
169 attribs
->id
= vInfo
->visualid
;
170 #if defined(__cplusplus) || defined(c_plusplus)
171 attribs
->klass
= vInfo
->c_class
;
173 attribs
->klass
= vInfo
->class;
175 attribs
->depth
= vInfo
->depth
;
176 attribs
->redMask
= vInfo
->red_mask
;
177 attribs
->greenMask
= vInfo
->green_mask
;
178 attribs
->blueMask
= vInfo
->blue_mask
;
179 attribs
->colormapSize
= vInfo
->colormap_size
;
180 attribs
->bitsPerRGB
= vInfo
->bits_per_rgb
;
182 if (glXGetConfig(dpy
, vInfo
, GLX_USE_GL
, &attribs
->supportsGL
) != 0 ||
183 !attribs
->supportsGL
)
185 glXGetConfig(dpy
, vInfo
, GLX_BUFFER_SIZE
, &attribs
->bufferSize
);
186 glXGetConfig(dpy
, vInfo
, GLX_LEVEL
, &attribs
->level
);
187 glXGetConfig(dpy
, vInfo
, GLX_RGBA
, &rgba
);
190 attribs
->render_type
= GLX_RGBA_BIT
;
192 glXGetConfig(dpy
, vInfo
, GLX_DOUBLEBUFFER
, &attribs
->doubleBuffer
);
193 if (!attribs
->doubleBuffer
)
196 glXGetConfig(dpy
, vInfo
, GLX_STEREO
, &attribs
->stereo
);
197 glXGetConfig(dpy
, vInfo
, GLX_AUX_BUFFERS
, &attribs
->auxBuffers
);
198 glXGetConfig(dpy
, vInfo
, GLX_RED_SIZE
, &attribs
->redSize
);
199 glXGetConfig(dpy
, vInfo
, GLX_GREEN_SIZE
, &attribs
->greenSize
);
200 glXGetConfig(dpy
, vInfo
, GLX_BLUE_SIZE
, &attribs
->blueSize
);
201 glXGetConfig(dpy
, vInfo
, GLX_ALPHA_SIZE
, &attribs
->alphaSize
);
202 glXGetConfig(dpy
, vInfo
, GLX_DEPTH_SIZE
, &attribs
->depthSize
);
203 glXGetConfig(dpy
, vInfo
, GLX_STENCIL_SIZE
, &attribs
->stencilSize
);
204 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_RED_SIZE
, &attribs
->accumRedSize
);
205 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_GREEN_SIZE
, &attribs
->accumGreenSize
);
206 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_BLUE_SIZE
, &attribs
->accumBlueSize
);
207 glXGetConfig(dpy
, vInfo
, GLX_ACCUM_ALPHA_SIZE
, &attribs
->accumAlphaSize
);
209 /* get transparent pixel stuff */
210 glXGetConfig(dpy
, vInfo
,GLX_TRANSPARENT_TYPE
, &attribs
->transparentType
);
211 if (attribs
->transparentType
== GLX_TRANSPARENT_RGB
) {
212 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_RED_VALUE
, &attribs
->transparentRedValue
);
213 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_GREEN_VALUE
, &attribs
->transparentGreenValue
);
214 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_BLUE_VALUE
, &attribs
->transparentBlueValue
);
215 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_ALPHA_VALUE
, &attribs
->transparentAlphaValue
);
217 else if (attribs
->transparentType
== GLX_TRANSPARENT_INDEX
) {
218 glXGetConfig(dpy
, vInfo
, GLX_TRANSPARENT_INDEX_VALUE
, &attribs
->transparentIndexValue
);
221 /* multisample attribs */
222 #ifdef GLX_ARB_multisample
223 if (ext
&& strstr(ext
, "GLX_ARB_multisample")) {
224 glXGetConfig(dpy
, vInfo
, GLX_SAMPLE_BUFFERS_ARB
, &attribs
->numMultisample
);
225 glXGetConfig(dpy
, vInfo
, GLX_SAMPLES_ARB
, &attribs
->numSamples
);
229 attribs
->numSamples
= 0;
230 attribs
->numMultisample
= 0;
233 #if defined(GLX_EXT_visual_rating)
234 if (ext
&& strstr(ext
, "GLX_EXT_visual_rating")) {
235 glXGetConfig(dpy
, vInfo
, GLX_VISUAL_CAVEAT_EXT
, &attribs
->visualCaveat
);
238 attribs
->visualCaveat
= GLX_NONE_EXT
;
241 attribs
->visualCaveat
= 0;
247 #ifdef GLX_VERSION_1_3
250 glx_token_to_visual_class(int visual_type
)
252 switch (visual_type
) {
255 case GLX_DIRECT_COLOR
:
257 case GLX_PSEUDO_COLOR
:
259 case GLX_STATIC_COLOR
:
263 case GLX_STATIC_GRAY
:
271 get_fbconfig_attribs(Display
*dpy
, GLXFBConfig fbconfig
,
272 struct visual_attribs
*attribs
)
276 memset(attribs
, 0, sizeof(struct visual_attribs
));
278 /* We don't use the GLX_FBCONFIG_ID here */
279 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_VISUAL_ID
, &attribs
->id
);
282 attribs
->depth
= vInfo
->depth
;
283 attribs
->redMask
= vInfo
->red_mask
;
284 attribs
->greenMask
= vInfo
->green_mask
;
285 attribs
->blueMask
= vInfo
->blue_mask
;
286 attribs
->colormapSize
= vInfo
->colormap_size
;
287 attribs
->bitsPerRGB
= vInfo
->bits_per_rgb
;
290 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_X_VISUAL_TYPE
, &visual_type
);
291 attribs
->klass
= glx_token_to_visual_class(visual_type
);
293 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_BUFFER_SIZE
, &attribs
->bufferSize
);
294 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_LEVEL
, &attribs
->level
);
295 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_RENDER_TYPE
, &attribs
->render_type
);
296 if (!(attribs
->render_type
& GLX_RGBA_BIT
))
299 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_DOUBLEBUFFER
, &attribs
->doubleBuffer
);
300 if (!attribs
->doubleBuffer
)
303 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_STEREO
, &attribs
->stereo
);
304 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_AUX_BUFFERS
, &attribs
->auxBuffers
);
306 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_RED_SIZE
, &attribs
->redSize
);
307 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_GREEN_SIZE
, &attribs
->greenSize
);
308 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_BLUE_SIZE
, &attribs
->blueSize
);
309 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ALPHA_SIZE
, &attribs
->alphaSize
);
310 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_DEPTH_SIZE
, &attribs
->depthSize
);
311 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_STENCIL_SIZE
, &attribs
->stencilSize
);
313 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ACCUM_RED_SIZE
, &attribs
->accumRedSize
);
314 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ACCUM_GREEN_SIZE
, &attribs
->accumGreenSize
);
315 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ACCUM_BLUE_SIZE
, &attribs
->accumBlueSize
);
316 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_ACCUM_ALPHA_SIZE
, &attribs
->accumAlphaSize
);
318 /* get transparent pixel stuff */
319 glXGetFBConfigAttrib(dpy
, fbconfig
,GLX_TRANSPARENT_TYPE
, &attribs
->transparentType
);
320 if (attribs
->transparentType
== GLX_TRANSPARENT_RGB
) {
321 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_RED_VALUE
, &attribs
->transparentRedValue
);
322 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_GREEN_VALUE
, &attribs
->transparentGreenValue
);
323 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_BLUE_VALUE
, &attribs
->transparentBlueValue
);
324 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_ALPHA_VALUE
, &attribs
->transparentAlphaValue
);
326 else if (attribs
->transparentType
== GLX_TRANSPARENT_INDEX
) {
327 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_TRANSPARENT_INDEX_VALUE
, &attribs
->transparentIndexValue
);
330 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_SAMPLE_BUFFERS
, &attribs
->numMultisample
);
331 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_SAMPLES
, &attribs
->numSamples
);
333 glXGetFBConfigAttrib(dpy
, fbconfig
, GLX_CONFIG_CAVEAT
, &attribs
->visualCaveat
);
341 create_configs(_EGLDisplay
*disp
, struct GLX_egl_driver
*GLX_drv
)
343 XVisualInfo theTemplate
;
347 struct visual_attribs attribs
;
349 GLX_drv
->fbconfigs
= NULL
;
351 #ifdef GLX_VERSION_1_3
352 /* get list of all fbconfigs on this screen */
353 GLX_drv
->fbconfigs
= glXGetFBConfigs(disp
->Xdpy
, DefaultScreen(disp
->Xdpy
), &numVisuals
);
355 if (numVisuals
== 0) {
356 GLX_drv
->fbconfigs
= NULL
;
360 for (i
= 0; i
< numVisuals
; i
++) {
361 struct GLX_egl_config
*config
;
363 if (!get_fbconfig_attribs(disp
->Xdpy
, GLX_drv
->fbconfigs
[i
], &attribs
))
366 config
= CALLOC_STRUCT(GLX_egl_config
);
368 _eglInitConfig(&config
->Base
, i
+1);
369 SET_CONFIG_ATTRIB(&config
->Base
, EGL_NATIVE_VISUAL_ID
, attribs
.id
);
370 SET_CONFIG_ATTRIB(&config
->Base
, EGL_BUFFER_SIZE
, attribs
.bufferSize
);
371 SET_CONFIG_ATTRIB(&config
->Base
, EGL_RED_SIZE
, attribs
.redSize
);
372 SET_CONFIG_ATTRIB(&config
->Base
, EGL_GREEN_SIZE
, attribs
.greenSize
);
373 SET_CONFIG_ATTRIB(&config
->Base
, EGL_BLUE_SIZE
, attribs
.blueSize
);
374 SET_CONFIG_ATTRIB(&config
->Base
, EGL_ALPHA_SIZE
, attribs
.alphaSize
);
375 SET_CONFIG_ATTRIB(&config
->Base
, EGL_DEPTH_SIZE
, attribs
.depthSize
);
376 SET_CONFIG_ATTRIB(&config
->Base
, EGL_STENCIL_SIZE
, attribs
.stencilSize
);
377 SET_CONFIG_ATTRIB(&config
->Base
, EGL_SAMPLES
, attribs
.numSamples
);
378 SET_CONFIG_ATTRIB(&config
->Base
, EGL_SAMPLE_BUFFERS
, attribs
.numMultisample
);
379 SET_CONFIG_ATTRIB(&config
->Base
, EGL_CONFORMANT
, all_apis
);
380 SET_CONFIG_ATTRIB(&config
->Base
, EGL_RENDERABLE_TYPE
, all_apis
);
381 SET_CONFIG_ATTRIB(&config
->Base
, EGL_SURFACE_TYPE
,
382 (EGL_WINDOW_BIT
| EGL_PBUFFER_BIT
| EGL_PIXMAP_BIT
));
384 /* XXX possibly other things to init... */
386 _eglAddConfig(disp
, &config
->Base
);
393 /* get list of all visuals on this screen */
394 theTemplate
.screen
= DefaultScreen(disp
->Xdpy
);
395 mask
= VisualScreenMask
;
396 GLX_drv
->visuals
= XGetVisualInfo(disp
->Xdpy
, mask
, &theTemplate
, &numVisuals
);
398 for (i
= 0; i
< numVisuals
; i
++) {
399 struct GLX_egl_config
*config
;
401 if (!get_visual_attribs(disp
->Xdpy
, &GLX_drv
->visuals
[i
], &attribs
))
404 config
= CALLOC_STRUCT(GLX_egl_config
);
406 _eglInitConfig(&config
->Base
, i
+1);
407 SET_CONFIG_ATTRIB(&config
->Base
, EGL_NATIVE_VISUAL_ID
, attribs
.id
);
408 SET_CONFIG_ATTRIB(&config
->Base
, EGL_BUFFER_SIZE
, attribs
.bufferSize
);
409 SET_CONFIG_ATTRIB(&config
->Base
, EGL_RED_SIZE
, attribs
.redSize
);
410 SET_CONFIG_ATTRIB(&config
->Base
, EGL_GREEN_SIZE
, attribs
.greenSize
);
411 SET_CONFIG_ATTRIB(&config
->Base
, EGL_BLUE_SIZE
, attribs
.blueSize
);
412 SET_CONFIG_ATTRIB(&config
->Base
, EGL_ALPHA_SIZE
, attribs
.alphaSize
);
413 SET_CONFIG_ATTRIB(&config
->Base
, EGL_DEPTH_SIZE
, attribs
.depthSize
);
414 SET_CONFIG_ATTRIB(&config
->Base
, EGL_STENCIL_SIZE
, attribs
.stencilSize
);
415 SET_CONFIG_ATTRIB(&config
->Base
, EGL_SAMPLES
, attribs
.numSamples
);
416 SET_CONFIG_ATTRIB(&config
->Base
, EGL_SAMPLE_BUFFERS
, attribs
.numMultisample
);
417 SET_CONFIG_ATTRIB(&config
->Base
, EGL_CONFORMANT
, all_apis
);
418 SET_CONFIG_ATTRIB(&config
->Base
, EGL_RENDERABLE_TYPE
, all_apis
);
419 SET_CONFIG_ATTRIB(&config
->Base
, EGL_SURFACE_TYPE
,
420 (EGL_WINDOW_BIT
/*| EGL_PBUFFER_BIT | EGL_PIXMAP_BIT*/));
422 /* XXX possibly other things to init... */
424 _eglAddConfig(disp
, &config
->Base
);
432 * Called via eglInitialize(), GLX_drv->API.Initialize().
435 GLX_eglInitialize(_EGLDriver
*drv
, EGLDisplay dpy
,
436 EGLint
*minor
, EGLint
*major
)
438 struct GLX_egl_driver
*GLX_drv
= GLX_egl_driver(drv
);
439 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
441 _eglLog(_EGL_DEBUG
, "GLX: eglInitialize");
444 disp
->Xdpy
= XOpenDisplay(NULL
);
446 _eglLog(_EGL_WARNING
, "GLX: XOpenDisplay failed");
451 glXQueryVersion(disp
->Xdpy
, &GLX_drv
->glx_maj
, &GLX_drv
->glx_min
);
453 GLX_drv
->Base
.Initialized
= EGL_TRUE
;
455 GLX_drv
->Base
.Name
= "GLX";
457 /* we're supporting EGL 1.4 */
461 create_configs(disp
, GLX_drv
);
467 * Do some clean-up that normally occurs in XCloseDisplay().
468 * We do this here because we're about to unload a dynamic library
469 * that has added some per-display extension data and callbacks.
470 * If we don't do this here we'll crash in XCloseDisplay() because it'll
471 * try to call functions that went away when the driver library was unloaded.
474 FreeDisplayExt(Display
*dpy
)
476 _XExtension
*ext
, *next
;
478 for (ext
= dpy
->ext_procs
; ext
; ext
= next
) {
480 if (ext
->close_display
) {
481 ext
->close_display(dpy
, &ext
->codes
);
482 ext
->close_display
= NULL
;
488 dpy
->ext_procs
= NULL
;
490 _XFreeExtData (dpy
->ext_data
);
491 dpy
->ext_data
= NULL
;
495 * Called via eglTerminate(), drv->API.Terminate().
498 GLX_eglTerminate(_EGLDriver
*drv
, EGLDisplay dpy
)
500 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
502 _eglLog(_EGL_DEBUG
, "GLX: eglTerminate");
504 FreeDisplayExt(disp
->Xdpy
);
511 * Called via eglCreateContext(), drv->API.CreateContext().
514 GLX_eglCreateContext(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
515 EGLContext share_list
, const EGLint
*attrib_list
)
517 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
518 struct GLX_egl_context
*GLX_ctx
= CALLOC_STRUCT(GLX_egl_context
);
519 struct GLX_egl_driver
*GLX_drv
= GLX_egl_driver(drv
);
520 struct GLX_egl_context
*GLX_ctx_shared
= NULL
;
524 return EGL_NO_CONTEXT
;
526 if (!_eglInitContext(drv
, dpy
, &GLX_ctx
->Base
, config
, attrib_list
)) {
528 return EGL_NO_CONTEXT
;
531 if (share_list
!= EGL_NO_CONTEXT
) {
532 _EGLContext
*shareCtx
= _eglLookupContext(share_list
);
534 _eglError(EGL_BAD_CONTEXT
, "eglCreateContext(share_list)");
537 GLX_ctx_shared
= GLX_egl_context(shareCtx
);
540 conf
= _eglLookupConfig(drv
, dpy
, config
);
543 #ifdef GLX_VERSION_1_3
544 if (GLX_drv
->fbconfigs
)
545 GLX_ctx
->context
= glXCreateNewContext(disp
->Xdpy
, GLX_drv
->fbconfigs
[(int)config
-1], GLX_RGBA_TYPE
, GLX_ctx_shared
? GLX_ctx_shared
->context
: NULL
, GL_TRUE
);
548 GLX_ctx
->context
= glXCreateContext(disp
->Xdpy
, &GLX_drv
->visuals
[(int)config
-1], GLX_ctx_shared
? GLX_ctx_shared
->context
: NULL
, GL_TRUE
);
549 if (!GLX_ctx
->context
)
553 /* (maybe?) need to have a direct rendering context */
554 if (!glXIsDirect(disp
->Xdpy
, GLX_ctx
->context
))
558 return _eglGetContextHandle(&GLX_ctx
->Base
);
563 * Called via eglMakeCurrent(), drv->API.MakeCurrent().
566 GLX_eglMakeCurrent(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface d
,
567 EGLSurface r
, EGLContext context
)
569 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
570 _EGLContext
*ctx
= _eglLookupContext(context
);
571 _EGLSurface
*dsurf
= _eglLookupSurface(d
);
572 _EGLSurface
*rsurf
= _eglLookupSurface(r
);
573 struct GLX_egl_surface
*GLX_dsurf
= GLX_egl_surface(dsurf
);
574 struct GLX_egl_surface
*GLX_rsurf
= GLX_egl_surface(rsurf
);
575 struct GLX_egl_context
*GLX_ctx
= GLX_egl_context(ctx
);
577 if (!_eglMakeCurrent(drv
, dpy
, d
, r
, context
))
580 #ifdef GLX_VERSION_1_3
581 if (!glXMakeContextCurrent(disp
->Xdpy
, GLX_dsurf
->drawable
, GLX_rsurf
->drawable
, GLX_ctx
->context
))
583 if (!glXMakeCurrent(disp
->Xdpy
, GLX_dsurf
? GLX_dsurf
->drawable
: 0, GLX_ctx
? GLX_ctx
->context
: NULL
))
589 /** Get size of given window */
591 get_drawable_size(Display
*dpy
, Drawable d
, uint
*width
, uint
*height
)
596 unsigned int w
, h
, bw
, depth
;
597 stat
= XGetGeometry(dpy
, d
, &root
, &xpos
, &ypos
, &w
, &h
, &bw
, &depth
);
604 * Called via eglCreateWindowSurface(), drv->API.CreateWindowSurface().
607 GLX_eglCreateWindowSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
608 NativeWindowType window
, const EGLint
*attrib_list
)
610 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
611 struct GLX_egl_surface
*GLX_surf
;
614 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
616 return EGL_NO_SURFACE
;
618 if (!_eglInitSurface(drv
, dpy
, &GLX_surf
->Base
, EGL_WINDOW_BIT
,
619 config
, attrib_list
)) {
624 _eglSaveSurface(&GLX_surf
->Base
);
626 GLX_surf
->drawable
= window
;
627 get_drawable_size(disp
->Xdpy
, window
, &width
, &height
);
628 GLX_surf
->Base
.Width
= width
;
629 GLX_surf
->Base
.Height
= height
;
631 return _eglGetSurfaceHandle(&GLX_surf
->Base
);
634 #ifdef GLX_VERSION_1_3
636 GLX_eglCreatePixmapSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
637 NativePixmapType pixmap
, const EGLint
*attrib_list
)
639 struct GLX_egl_driver
*GLX_drv
= GLX_egl_driver(drv
);
640 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
641 struct GLX_egl_surface
*GLX_surf
;
644 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
646 return EGL_NO_SURFACE
;
648 if (!_eglInitSurface(drv
, dpy
, &GLX_surf
->Base
, EGL_PIXMAP_BIT
,
649 config
, attrib_list
)) {
654 _eglSaveSurface(&GLX_surf
->Base
);
656 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
657 switch (attrib_list
[i
]) {
658 /* no attribs at this time */
660 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreatePixmapSurface");
661 return EGL_NO_SURFACE
;
665 GLX_surf
->drawable
= glXCreatePixmap(disp
->Xdpy
, GLX_drv
->fbconfigs
[(int)config
-1], pixmap
, NULL
);
667 return _eglGetSurfaceHandle(&GLX_surf
->Base
);
671 GLX_eglCreatePbufferSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
672 const EGLint
*attrib_list
)
674 struct GLX_egl_driver
*GLX_drv
= GLX_egl_driver(drv
);
675 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
676 struct GLX_egl_surface
*GLX_surf
;
680 GLX_surf
= CALLOC_STRUCT(GLX_egl_surface
);
682 return EGL_NO_SURFACE
;
684 if (!_eglInitSurface(drv
, dpy
, &GLX_surf
->Base
, EGL_PBUFFER_BIT
,
685 config
, attrib_list
)) {
687 return EGL_NO_SURFACE
;
690 _eglSaveSurface(&GLX_surf
->Base
);
692 while(attrib_list
[i
] != EGL_NONE
) {
693 switch (attrib_list
[i
]) {
695 attribs
[j
++] = GLX_PBUFFER_WIDTH
;
696 attribs
[j
++] = attrib_list
[i
+1];
699 attribs
[j
++] = GLX_PBUFFER_HEIGHT
;
700 attribs
[j
++] = attrib_list
[i
+1];
707 GLX_surf
->drawable
= glXCreatePbuffer(disp
->Xdpy
, GLX_drv
->fbconfigs
[(int)config
-1], attribs
);
709 return _eglGetSurfaceHandle(&GLX_surf
->Base
);
714 GLX_eglDestroySurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
)
716 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
717 _EGLSurface
*surf
= _eglLookupSurface(surface
);
720 _eglHashRemove(_eglGlobal
.Surfaces
, (EGLuint
) surface
);
722 surf
->DeletePending
= EGL_TRUE
;
731 _eglError(EGL_BAD_SURFACE
, "eglDestroySurface");
738 GLX_eglBindTexImage(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
,
741 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
742 _EGLSurface
*surf
= _eglLookupSurface(surface
);
743 struct GLX_egl_surface
*GLX_surf
= GLX_egl_surface(surf
);
746 glXBindTexImageEXT(disp
->Xdpy
, GLX_surf
->drawable
, GLX_FRONT_LEFT_EXT
, NULL
);
753 GLX_eglReleaseTexImage(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
,
756 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
757 _EGLSurface
*surf
= _eglLookupSurface(surface
);
758 struct GLX_egl_surface
*GLX_surf
= GLX_egl_surface(surf
);
761 glXReleaseTexImageEXT(disp
->Xdpy
, GLX_surf
->drawable
, GLX_FRONT_LEFT_EXT
);
768 GLX_eglSwapBuffers(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface draw
)
770 _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
771 _EGLSurface
*surf
= _eglLookupSurface(draw
);
772 struct GLX_egl_surface
*GLX_surf
= GLX_egl_surface(surf
);
774 _eglLog(_EGL_DEBUG
, "GLX: EGL SwapBuffers 0x%x",draw
);
776 /* error checking step: */
777 if (!_eglSwapBuffers(drv
, dpy
, draw
))
780 glXSwapBuffers(disp
->Xdpy
, GLX_surf
->drawable
);
786 * Called from eglGetProcAddress() via drv->API.GetProcAddress().
789 GLX_eglGetProcAddress(const char *procname
)
791 return (_EGLProc
)glXGetProcAddress((const GLubyte
*)procname
);
796 * This is the main entrypoint into the driver, called by libEGL.
797 * Create a new _EGLDriver object and init its dispatch table.
800 _eglMain(_EGLDisplay
*disp
, const char *args
)
802 struct GLX_egl_driver
*GLX_drv
= CALLOC_STRUCT(GLX_egl_driver
);
804 int maj
= 0, min
= 0;
809 _eglInitDriverFallbacks(&GLX_drv
->Base
);
810 GLX_drv
->Base
.API
.Initialize
= GLX_eglInitialize
;
811 GLX_drv
->Base
.API
.Terminate
= GLX_eglTerminate
;
812 GLX_drv
->Base
.API
.CreateContext
= GLX_eglCreateContext
;
813 GLX_drv
->Base
.API
.MakeCurrent
= GLX_eglMakeCurrent
;
814 GLX_drv
->Base
.API
.CreateWindowSurface
= GLX_eglCreateWindowSurface
;
815 #ifdef GLX_VERSION_1_3
816 if (GLX_drv
->glx_maj
== 1 && GLX_drv
->glx_min
>= 3) {
817 GLX_drv
->Base
.API
.CreatePixmapSurface
= GLX_eglCreatePixmapSurface
;
818 GLX_drv
->Base
.API
.CreatePbufferSurface
= GLX_eglCreatePbufferSurface
;
819 printf("GLX: Pbuffer and Pixmap support\n");
821 printf("GLX: No pbuffer or pixmap support\n");
824 GLX_drv
->Base
.API
.DestroySurface
= GLX_eglDestroySurface
;
825 GLX_drv
->Base
.API
.BindTexImage
= GLX_eglBindTexImage
;
826 GLX_drv
->Base
.API
.ReleaseTexImage
= GLX_eglReleaseTexImage
;
827 GLX_drv
->Base
.API
.SwapBuffers
= GLX_eglSwapBuffers
;
828 GLX_drv
->Base
.API
.GetProcAddress
= GLX_eglGetProcAddress
;
830 GLX_drv
->Base
.ClientAPIsMask
= all_apis
;
831 GLX_drv
->Base
.Name
= "GLX";
833 _eglLog(_EGL_DEBUG
, "GLX: main(%s)", args
);
835 /* set new DRI path to pick up EGL version (which doesn't contain any mesa
836 * code), but don't override if one is already set.
838 env
= getenv("LIBGL_DRIVERS_PATH");
840 if (!strstr(env
, "egl")) {
841 sprintf(env
, "%s/egl", env
);
842 setenv("LIBGL_DRIVERS_PATH", env
, 1);
845 setenv("LIBGL_DRIVERS_PATH", DEFAULT_DRIVER_DIR
"/egl", 0);
847 return &GLX_drv
->Base
;