2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
28 * to run on X servers which do not have the real GLX extension.
30 * Thanks to the contributors:
32 * Initial version: Philip Brown (phil@bolthole.com)
33 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
34 * Further visual-handling refinements: Wolfram Gloger
35 * (wmglo@Dent.MED.Uni-Muenchen.DE).
38 * Don't be fooled, stereo isn't supported yet.
43 #include "glxheader.h"
56 #define _mesa_sprintf sprintf
59 /* This indicates the client-side GLX API and GLX encoder version. */
60 #define CLIENT_MAJOR_VERSION 1
61 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
63 /* This indicates the server-side GLX decoder version.
64 * GLX 1.4 indicates OpenGL 1.3 support
66 #define SERVER_MAJOR_VERSION 1
67 #define SERVER_MINOR_VERSION 4
69 /* This is appended onto the glXGetClient/ServerString version strings. */
70 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
72 /* Who implemented this GLX? */
73 #define VENDOR "Brian Paul"
76 "GLX_MESA_set_3dfx_mode " \
77 "GLX_MESA_copy_sub_buffer " \
78 "GLX_MESA_pixmap_colormap " \
79 "GLX_MESA_release_buffers " \
80 "GLX_ARB_get_proc_address " \
81 "GLX_EXT_texture_from_pixmap " \
82 "GLX_EXT_visual_info " \
83 "GLX_EXT_visual_rating " \
84 /*"GLX_SGI_video_sync "*/ \
85 "GLX_SGIX_fbconfig " \
89 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
91 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
94 * We really just need this structure in order to make the libGL functions
95 * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
98 struct fake_glx_context
{
99 __GLXcontext glxContext
; /* this MUST be first! */
100 XMesaContext xmesaContext
;
105 /**********************************************************************/
106 /*** GLX Visual Code ***/
107 /**********************************************************************/
112 static XMesaVisual
*VisualTable
= NULL
;
113 static int NumVisuals
= 0;
117 * This struct and some code fragments borrowed
118 * from Mark Kilgard's GLUT library.
120 typedef struct _OverlayInfo
{
121 /* Avoid 64-bit portability problems by being careful to use
122 longs due to the way XGetWindowProperty is specified. Note
123 that these parameters are passed as CARD32s over X
125 unsigned long overlay_visual
;
126 long transparent_type
;
133 /* Macro to handle c_class vs class field name in XVisualInfo struct */
134 #if defined(__cplusplus) || defined(c_plusplus)
135 #define CLASS c_class
143 * Test if the given XVisualInfo is usable for Mesa rendering.
146 is_usable_visual( XVisualInfo
*vinfo
)
148 switch (vinfo
->CLASS
) {
151 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
155 /* Any StaticColor/PseudoColor visual of at least 4 bits */
156 if (vinfo
->depth
>=4) {
164 /* Any depth of TrueColor or DirectColor works in RGB mode */
167 /* This should never happen */
175 * Get an array OverlayInfo records for specified screen.
176 * \param dpy the display
177 * \param screen screen number
178 * \param numOverlays returns numver of OverlayInfo records
179 * \return pointer to OverlayInfo array, free with XFree()
182 GetOverlayInfo(Display
*dpy
, int screen
, int *numOverlays
)
184 Atom overlayVisualsAtom
;
187 unsigned char *ovInfo
;
188 unsigned long sizeData
, bytesLeft
;
192 * The SERVER_OVERLAY_VISUALS property on the root window contains
193 * a list of overlay visuals. Get that list now.
195 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
196 if (overlayVisualsAtom
== None
) {
200 status
= XGetWindowProperty(dpy
, RootWindow(dpy
, screen
),
201 overlayVisualsAtom
, 0L, (long) 10000, False
,
202 overlayVisualsAtom
, &actualType
, &actualFormat
,
203 &sizeData
, &bytesLeft
,
206 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
207 actualFormat
!= 32 || sizeData
< 4) {
208 /* something went wrong */
209 XFree((void *) ovInfo
);
214 *numOverlays
= sizeData
/ 4;
215 return (OverlayInfo
*) ovInfo
;
221 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
222 * Input: dpy - the X display
223 * vinfo - the XVisualInfo to test
224 * Return: level of the visual:
226 * >0 = overlay planes
227 * <0 = underlay planes
230 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
232 OverlayInfo
*overlay_info
;
233 int numOverlaysPerScreen
, i
;
235 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
240 /* search the overlay visual list for the visual ID of interest */
241 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
242 const OverlayInfo
*ov
= overlay_info
+ i
;
243 if (ov
->overlay_visual
== vinfo
->visualid
) {
244 /* found the visual */
245 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
246 int level
= ov
->layer
;
247 XFree((void *) overlay_info
);
251 XFree((void *) overlay_info
);
257 /* The visual ID was not found in the overlay list. */
258 XFree((void *) overlay_info
);
266 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
267 * configuration in our list of GLX visuals.
270 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
271 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
272 GLboolean stereoFlag
,
273 GLint depth_size
, GLint stencil_size
,
274 GLint accumRedSize
, GLint accumGreenSize
,
275 GLint accumBlueSize
, GLint accumAlphaSize
,
276 GLint level
, GLint numAuxBuffers
)
278 GLboolean ximageFlag
= GL_TRUE
;
281 GLboolean comparePointers
;
284 /* Check if the MESA_BACK_BUFFER env var is set */
285 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
287 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
288 ximageFlag
= GL_FALSE
;
290 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
291 ximageFlag
= GL_TRUE
;
294 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
299 /* Comparing IDs uses less memory but sometimes fails. */
300 /* XXX revisit this after 3.0 is finished. */
301 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
302 comparePointers
= GL_TRUE
;
304 comparePointers
= GL_FALSE
;
306 /* Force the visual to have an alpha channel */
307 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
310 /* First check if a matching visual is already in the list */
311 for (i
=0; i
<NumVisuals
; i
++) {
312 XMesaVisual v
= VisualTable
[i
];
313 if (v
->display
== dpy
314 && v
->mesa_visual
.level
== level
315 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
316 && v
->ximage_flag
== ximageFlag
317 && v
->mesa_visual
.rgbMode
== rgbFlag
318 && v
->mesa_visual
.doubleBufferMode
== dbFlag
319 && v
->mesa_visual
.stereoMode
== stereoFlag
320 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
321 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
322 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
323 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
324 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
325 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
326 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
327 /* now either compare XVisualInfo pointers or visual IDs */
328 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
329 || (comparePointers
&& v
->vishandle
== vinfo
)) {
335 /* Create a new visual and add it to the list. */
337 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
338 stereoFlag
, ximageFlag
,
339 depth_size
, stencil_size
,
340 accumRedSize
, accumBlueSize
,
341 accumBlueSize
, accumAlphaSize
, 0, level
,
344 /* Save a copy of the pointer now so we can find this visual again
345 * if we need to search for it in find_glx_visual().
347 xmvis
->vishandle
= vinfo
;
348 /* Allocate more space for additional visual */
349 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
350 sizeof(XMesaVisual
) * NumVisuals
,
351 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
352 /* add xmvis to the list */
353 VisualTable
[NumVisuals
] = xmvis
;
355 /* XXX minor hack, because XMesaCreateVisual doesn't support an
356 * aux buffers parameter.
358 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
365 * Return the default number of bits for the Z buffer.
366 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
367 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
368 * XXX probably do the same thing for stencil, accum, etc.
371 default_depth_bits(void)
374 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
376 zBits
= _mesa_atoi(zEnv
);
378 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
383 default_alpha_bits(void)
386 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
388 aBits
= _mesa_atoi(aEnv
);
395 default_accum_bits(void)
403 * Create a GLX visual from a regular XVisualInfo.
404 * This is called when Fake GLX is given an XVisualInfo which wasn't
405 * returned by glXChooseVisual. Since this is the first time we're
406 * considering this visual we'll take a guess at reasonable values
407 * for depth buffer size, stencil size, accum size, etc.
408 * This is the best we can do with a client-side emulation of GLX.
411 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
414 GLint zBits
= default_depth_bits();
415 GLint accBits
= default_accum_bits();
416 GLboolean alphaFlag
= default_alpha_bits() > 0;
418 vislevel
= level_of_visual( dpy
, visinfo
);
420 /* Configure this visual as a CI, single-buffered overlay */
421 return save_glx_visual( dpy
, visinfo
,
423 GL_FALSE
, /* alpha */
424 GL_FALSE
, /* double */
425 GL_FALSE
, /* stereo */
427 0, /* stencil bits */
428 0,0,0,0, /* accum bits */
429 vislevel
, /* level */
433 else if (is_usable_visual( visinfo
)) {
434 if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
435 /* Configure this visual as a COLOR INDEX visual. */
436 return save_glx_visual( dpy
, visinfo
,
438 GL_FALSE
, /* alpha */
439 GL_TRUE
, /* double */
440 GL_FALSE
, /* stereo */
443 0, 0, 0, 0, /* accum bits */
449 /* Configure this visual as RGB, double-buffered, depth-buffered. */
450 /* This is surely wrong for some people's needs but what else */
451 /* can be done? They should use glXChooseVisual(). */
452 return save_glx_visual( dpy
, visinfo
,
454 alphaFlag
, /* alpha */
455 GL_TRUE
, /* double */
456 GL_FALSE
, /* stereo */
469 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
477 * Find the GLX visual associated with an XVisualInfo.
480 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
484 /* try to match visual id */
485 for (i
=0;i
<NumVisuals
;i
++) {
486 if (VisualTable
[i
]->display
==dpy
487 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
488 return VisualTable
[i
];
492 /* if that fails, try to match pointers */
493 for (i
=0;i
<NumVisuals
;i
++) {
494 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
495 return VisualTable
[i
];
505 * Return the transparent pixel value for a GLX visual.
506 * Input: glxvis - the glx_visual
507 * Return: a pixel value or -1 if no transparent pixel
510 transparent_pixel( XMesaVisual glxvis
)
512 Display
*dpy
= glxvis
->display
;
513 XVisualInfo
*vinfo
= glxvis
->visinfo
;
514 OverlayInfo
*overlay_info
;
515 int numOverlaysPerScreen
, i
;
517 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
522 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
523 const OverlayInfo
*ov
= overlay_info
+ i
;
524 if (ov
->overlay_visual
== vinfo
->visualid
) {
526 if (ov
->transparent_type
== 0) {
527 /* type 0 indicates no transparency */
528 XFree((void *) overlay_info
);
532 /* ov->value is the transparent pixel */
533 XFree((void *) overlay_info
);
539 /* The visual ID was not found in the overlay list. */
540 XFree((void *) overlay_info
);
547 * Try to get an X visual which matches the given arguments.
550 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
552 XVisualInfo temp
, *vis
;
555 unsigned int default_depth
;
558 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
563 default_depth
= DefaultDepth(dpy
,scr
);
564 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
566 if (depth
==default_depth
&& xclass
==default_class
) {
567 /* try to get root window's visual */
568 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
569 mask
|= VisualIDMask
;
572 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
574 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
575 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
576 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
578 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
579 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
580 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
581 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
596 * Retrieve the value of the given environment variable and find
597 * the X visual which matches it.
598 * Input: dpy - the display
599 * screen - the screen number
600 * varname - the name of the environment variable
601 * Return: an XVisualInfo pointer to NULL if error.
604 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
606 char value
[100], type
[100];
607 int depth
, xclass
= -1;
610 if (!_mesa_getenv( varname
)) {
614 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
617 sscanf( value
, "%s %d", type
, &depth
);
619 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
620 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
621 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
622 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
623 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
624 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
626 if (xclass
>-1 && depth
>0) {
627 vis
= get_visual( dpy
, scr
, depth
, xclass
);
633 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
642 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
643 * Input: dpy, screen - X display and screen number
644 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
645 * min_depth - minimum visual depth
646 * preferred_class - preferred GLX visual class or DONT_CARE
647 * Return: pointer to an XVisualInfo or NULL.
650 choose_x_visual( Display
*dpy
, int screen
, GLboolean rgba
, int min_depth
,
651 int preferred_class
)
654 int xclass
, visclass
= 0;
658 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
659 /* First see if the MESA_RGB_VISUAL env var is defined */
660 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
664 /* Otherwise, search for a suitable visual */
665 if (preferred_class
==DONT_CARE
) {
666 for (xclass
=0;xclass
<6;xclass
++) {
668 case 0: visclass
= TrueColor
; break;
669 case 1: visclass
= DirectColor
; break;
670 case 2: visclass
= PseudoColor
; break;
671 case 3: visclass
= StaticColor
; break;
672 case 4: visclass
= GrayScale
; break;
673 case 5: visclass
= StaticGray
; break;
676 /* start with shallowest */
677 for (depth
=0;depth
<=32;depth
++) {
678 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
679 /* Special case: try to get 8-bit PseudoColor before */
680 /* 8-bit TrueColor */
681 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
686 vis
= get_visual( dpy
, screen
, depth
, visclass
);
693 /* start with deepest */
694 for (depth
=32;depth
>=min_depth
;depth
--) {
695 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
696 /* Special case: try to get 8-bit PseudoColor before */
697 /* 8-bit TrueColor */
698 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
703 vis
= get_visual( dpy
, screen
, depth
, visclass
);
712 /* search for a specific visual class */
713 switch (preferred_class
) {
714 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
715 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
716 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
717 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
718 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
719 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
720 default: return NULL
;
723 /* start with shallowest */
724 for (depth
=0;depth
<=32;depth
++) {
725 vis
= get_visual( dpy
, screen
, depth
, visclass
);
732 /* start with deepest */
733 for (depth
=32;depth
>=min_depth
;depth
--) {
734 vis
= get_visual( dpy
, screen
, depth
, visclass
);
743 /* First see if the MESA_CI_VISUAL env var is defined */
744 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
748 /* Otherwise, search for a suitable visual, starting with shallowest */
749 if (preferred_class
==DONT_CARE
) {
750 for (xclass
=0;xclass
<4;xclass
++) {
752 case 0: visclass
= PseudoColor
; break;
753 case 1: visclass
= StaticColor
; break;
754 case 2: visclass
= GrayScale
; break;
755 case 3: visclass
= StaticGray
; break;
757 /* try 8-bit up through 16-bit */
758 for (depth
=8;depth
<=16;depth
++) {
759 vis
= get_visual( dpy
, screen
, depth
, visclass
);
764 /* try min_depth up to 8-bit */
765 for (depth
=min_depth
;depth
<8;depth
++) {
766 vis
= get_visual( dpy
, screen
, depth
, visclass
);
774 /* search for a specific visual class */
775 switch (preferred_class
) {
776 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
777 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
778 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
779 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
780 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
781 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
782 default: return NULL
;
784 /* try 8-bit up through 16-bit */
785 for (depth
=8;depth
<=16;depth
++) {
786 vis
= get_visual( dpy
, screen
, depth
, visclass
);
791 /* try min_depth up to 8-bit */
792 for (depth
=min_depth
;depth
<8;depth
++) {
793 vis
= get_visual( dpy
, screen
, depth
, visclass
);
801 /* didn't find a visual */
808 * Find the deepest X over/underlay visual of at least min_depth.
809 * Input: dpy, screen - X display and screen number
810 * level - the over/underlay level
811 * trans_type - transparent pixel type: GLX_NONE_EXT,
812 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
814 * trans_value - transparent pixel value or DONT_CARE
815 * min_depth - minimum visual depth
816 * preferred_class - preferred GLX visual class or DONT_CARE
817 * Return: pointer to an XVisualInfo or NULL.
820 choose_x_overlay_visual( Display
*dpy
, int scr
, GLboolean rgbFlag
,
821 int level
, int trans_type
, int trans_value
,
822 int min_depth
, int preferred_class
)
824 OverlayInfo
*overlay_info
;
825 int numOverlaysPerScreen
;
827 XVisualInfo
*deepvis
;
830 /*DEBUG int tt, tv; */
832 switch (preferred_class
) {
833 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
834 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
835 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
836 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
837 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
838 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
839 default: preferred_class
= DONT_CARE
;
842 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
847 /* Search for the deepest overlay which satisifies all criteria. */
851 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
852 const OverlayInfo
*ov
= overlay_info
+ i
;
853 XVisualInfo
*vislist
, vistemplate
;
856 if (ov
->layer
!=level
) {
857 /* failed overlay level criteria */
860 if (!(trans_type
==DONT_CARE
861 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
862 && ov
->transparent_type
>0)
863 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
864 /* failed transparent pixel type criteria */
867 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
868 /* failed transparent pixel value criteria */
872 /* get XVisualInfo and check the depth */
873 vistemplate
.visualid
= ov
->overlay_visual
;
874 vistemplate
.screen
= scr
;
875 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
876 &vistemplate
, &count
);
879 /* something went wrong */
882 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
883 /* wrong visual class */
887 /* if RGB was requested, make sure we have True/DirectColor */
888 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
889 && vislist
->CLASS
!= DirectColor
)
892 /* if CI was requested, make sure we have a color indexed visual */
894 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
897 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
898 /* YES! found a satisfactory visual */
902 deepest
= vislist
->depth
;
904 /* DEBUG tt = ov->transparent_type;*/
905 /* DEBUG tv = ov->value; */
911 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
912 deepvis->visualid, level, deepvis->depth, tt, tv );
919 /**********************************************************************/
920 /*** Display-related functions ***/
921 /**********************************************************************/
925 * Free all XMesaVisuals which are associated with the given display.
928 destroy_visuals_on_display(Display
*dpy
)
931 for (i
= 0; i
< NumVisuals
; i
++) {
932 if (VisualTable
[i
]->display
== dpy
) {
933 /* remove this visual */
935 free(VisualTable
[i
]);
936 for (j
= i
; j
< NumVisuals
- 1; j
++)
937 VisualTable
[j
] = VisualTable
[j
+ 1];
945 * Called from XCloseDisplay() to let us free our display-related data.
948 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
950 destroy_visuals_on_display(dpy
);
951 xmesa_destroy_buffers_on_display(dpy
);
957 * Look for the named extension on given display and return a pointer
958 * to the _XExtension data, or NULL if extension not found.
961 lookup_extension(Display
*dpy
, const char *extName
)
964 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
965 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
974 * Whenever we're given a new Display pointer, call this function to
975 * register our close_display_callback function.
978 register_with_display(Display
*dpy
)
980 const char *extName
= "MesaGLX";
983 ext
= lookup_extension(dpy
, extName
);
985 XExtCodes
*c
= XAddExtension(dpy
);
986 ext
= dpy
->ext_procs
; /* new extension is at head of list */
987 assert(c
->extension
== ext
->codes
.extension
);
988 ext
->name
= _mesa_strdup(extName
);
989 ext
->close_display
= close_display_callback
;
994 /**********************************************************************/
995 /*** Begin Fake GLX API Functions ***/
996 /**********************************************************************/
1000 * Helper used by glXChooseVisual and glXChooseFBConfig.
1001 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
1003 * In either case, the attribute list is terminated with the value 'None'.
1006 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
1008 const GLboolean rgbModeDefault
= fbConfig
;
1009 const int *parselist
;
1012 int min_red
=0, min_green
=0, min_blue
=0;
1013 GLboolean rgb_flag
= rgbModeDefault
;
1014 GLboolean alpha_flag
= GL_FALSE
;
1015 GLboolean double_flag
= GL_FALSE
;
1016 GLboolean stereo_flag
= GL_FALSE
;
1017 GLint depth_size
= 0;
1018 GLint stencil_size
= 0;
1019 GLint accumRedSize
= 0;
1020 GLint accumGreenSize
= 0;
1021 GLint accumBlueSize
= 0;
1022 GLint accumAlphaSize
= 0;
1024 int visual_type
= DONT_CARE
;
1025 int trans_type
= DONT_CARE
;
1026 int trans_value
= DONT_CARE
;
1027 GLint caveat
= DONT_CARE
;
1028 XMesaVisual xmvis
= NULL
;
1029 int desiredVisualID
= -1;
1034 while (*parselist
) {
1036 switch (*parselist
) {
1047 case GLX_BUFFER_SIZE
:
1049 min_ci
= *parselist
++;
1053 level
= *parselist
++;
1065 case GLX_DOUBLEBUFFER
:
1068 double_flag
= *parselist
++;
1071 double_flag
= GL_TRUE
;
1077 stereo_flag
= *parselist
++;
1080 stereo_flag
= GL_TRUE
;
1082 return NULL
; /* stereo not supported */
1083 case GLX_AUX_BUFFERS
:
1085 numAux
= *parselist
++;
1086 if (numAux
> MAX_AUX_BUFFERS
)
1091 min_red
= *parselist
++;
1093 case GLX_GREEN_SIZE
:
1095 min_green
= *parselist
++;
1099 min_blue
= *parselist
++;
1101 case GLX_ALPHA_SIZE
:
1104 GLint size
= *parselist
++;
1105 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
1108 case GLX_DEPTH_SIZE
:
1110 depth_size
= *parselist
++;
1112 case GLX_STENCIL_SIZE
:
1114 stencil_size
= *parselist
++;
1116 case GLX_ACCUM_RED_SIZE
:
1119 GLint size
= *parselist
++;
1120 accumRedSize
= MAX2( accumRedSize
, size
);
1123 case GLX_ACCUM_GREEN_SIZE
:
1126 GLint size
= *parselist
++;
1127 accumGreenSize
= MAX2( accumGreenSize
, size
);
1130 case GLX_ACCUM_BLUE_SIZE
:
1133 GLint size
= *parselist
++;
1134 accumBlueSize
= MAX2( accumBlueSize
, size
);
1137 case GLX_ACCUM_ALPHA_SIZE
:
1140 GLint size
= *parselist
++;
1141 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1146 * GLX_EXT_visual_info extension
1148 case GLX_X_VISUAL_TYPE_EXT
:
1150 visual_type
= *parselist
++;
1152 case GLX_TRANSPARENT_TYPE_EXT
:
1154 trans_type
= *parselist
++;
1156 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1158 trans_value
= *parselist
++;
1160 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1161 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1162 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1163 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1170 * GLX_EXT_visual_info extension
1172 case GLX_VISUAL_CAVEAT_EXT
:
1174 caveat
= *parselist
++; /* ignored for now */
1178 * GLX_ARB_multisample
1180 case GLX_SAMPLE_BUFFERS_ARB
:
1181 /* ms not supported */
1183 case GLX_SAMPLES_ARB
:
1184 /* ms not supported */
1190 case GLX_RENDER_TYPE
:
1194 if (*parselist
== GLX_RGBA_BIT
) {
1197 else if (*parselist
== GLX_COLOR_INDEX_BIT
) {
1198 rgb_flag
= GL_FALSE
;
1200 else if (*parselist
== 0) {
1205 case GLX_DRAWABLE_TYPE
:
1209 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1210 return NULL
; /* bad bit */
1214 case GLX_FBCONFIG_ID
:
1218 desiredVisualID
= *parselist
++;
1220 case GLX_X_RENDERABLE
:
1227 #ifdef GLX_EXT_texture_from_pixmap
1228 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1229 parselist
++; /*skip*/
1231 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1232 parselist
++; /*skip*/
1234 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1235 parselist
++; /*skip*/
1237 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1239 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1240 GLX_TEXTURE_2D_BIT_EXT
|
1241 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1246 case GLX_Y_INVERTED_EXT
:
1247 parselist
++; /*skip*/
1256 /* undefined attribute */
1257 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1266 * Since we're only simulating the GLX extension this function will never
1267 * find any real GL visuals. Instead, all we can do is try to find an RGB
1268 * or CI visual of appropriate depth. Other requested attributes such as
1269 * double buffering, depth buffer, etc. will be associated with the X
1270 * visual and stored in the VisualTable[].
1272 if (desiredVisualID
!= -1) {
1273 /* try to get a specific visual, by visualID */
1276 temp
.visualid
= desiredVisualID
;
1277 temp
.screen
= screen
;
1278 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1280 /* give the visual some useful GLX attributes */
1281 double_flag
= GL_TRUE
;
1284 depth_size
= default_depth_bits();
1285 stencil_size
= STENCIL_BITS
;
1289 else if (level
==0) {
1290 /* normal color planes */
1292 /* Get an RGB visual */
1293 int min_rgb
= min_red
+ min_green
+ min_blue
;
1294 if (min_rgb
>1 && min_rgb
<8) {
1295 /* a special case to be sure we can get a monochrome visual */
1298 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1301 /* Get a color index visual */
1302 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1303 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1307 /* over/underlay planes */
1310 int min_rgb
= min_red
+ min_green
+ min_blue
;
1311 if (min_rgb
>1 && min_rgb
<8) {
1312 /* a special case to be sure we can get a monochrome visual */
1315 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1316 trans_type
, trans_value
, min_rgb
, visual_type
);
1319 /* color index overlay */
1320 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1321 trans_type
, trans_value
, min_ci
, visual_type
);
1326 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1327 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1328 * largest depth buffer size, which is 32bits/value. Instead, we
1329 * return 16 to maintain performance with earlier versions of Mesa.
1331 if (depth_size
> 24)
1333 else if (depth_size
> 16)
1335 else if (depth_size
> 0) {
1336 depth_size
= default_depth_bits();
1340 alpha_flag
= default_alpha_bits() > 0;
1343 /* we only support one size of stencil and accum buffers. */
1344 if (stencil_size
> 0)
1345 stencil_size
= STENCIL_BITS
;
1346 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1347 accumAlphaSize
> 0) {
1350 accumBlueSize
= default_accum_bits();
1351 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1354 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1355 stereo_flag
, depth_size
, stencil_size
,
1356 accumRedSize
, accumGreenSize
,
1357 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1364 static XVisualInfo
*
1365 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1369 /* register ourselves as an extension on this display */
1370 register_with_display(dpy
);
1372 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1375 return xmvis
->vishandle
;
1377 /* create a new vishandle - the cached one may be stale */
1378 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1379 if (xmvis
->vishandle
) {
1380 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1382 return xmvis
->vishandle
;
1391 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1392 GLXContext share_list
, Bool direct
)
1395 struct fake_glx_context
*glxCtx
;
1396 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1398 if (!dpy
|| !visinfo
)
1401 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1405 /* deallocate unused windows/buffers */
1407 XMesaGarbageCollect();
1410 xmvis
= find_glx_visual( dpy
, visinfo
);
1412 /* This visual wasn't found with glXChooseVisual() */
1413 xmvis
= create_glx_visual( dpy
, visinfo
);
1415 /* unusable visual */
1421 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1422 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1423 if (!glxCtx
->xmesaContext
) {
1428 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
1429 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
1430 glxCtx
->glxContext
.currentDpy
= dpy
;
1431 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1433 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1435 return (GLXContext
) glxCtx
;
1439 /* XXX these may have to be removed due to thread-safety issues. */
1440 static GLXContext MakeCurrent_PrevContext
= 0;
1441 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1442 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1443 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1444 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1447 /* GLX 1.3 and later */
1449 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1450 GLXDrawable read
, GLXContext ctx
)
1452 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1454 if (ctx
&& draw
&& read
) {
1455 XMesaBuffer drawBuffer
, readBuffer
;
1456 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1458 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1459 if (ctx
== MakeCurrent_PrevContext
1460 && draw
== MakeCurrent_PrevDrawable
) {
1461 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1464 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1467 /* drawable must be a new window! */
1468 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1470 /* Out of memory, or context/drawable depth mismatch */
1474 FXcreateContext( xmctx
->xm_visual
, draw
, xmctx
, drawBuffer
);
1478 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1479 if (ctx
== MakeCurrent_PrevContext
1480 && read
== MakeCurrent_PrevReadable
) {
1481 readBuffer
= MakeCurrent_PrevReadBuffer
;
1484 readBuffer
= XMesaFindBuffer( dpy
, read
);
1487 /* drawable must be a new window! */
1488 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1490 /* Out of memory, or context/drawable depth mismatch */
1494 FXcreateContext( xmctx
->xm_visual
, read
, xmctx
, readBuffer
);
1498 MakeCurrent_PrevContext
= ctx
;
1499 MakeCurrent_PrevDrawable
= draw
;
1500 MakeCurrent_PrevReadable
= read
;
1501 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1502 MakeCurrent_PrevReadBuffer
= readBuffer
;
1504 /* Now make current! */
1505 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1506 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1507 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1508 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1515 else if (!ctx
&& !draw
&& !read
) {
1516 /* release current context w/out assigning new one. */
1517 XMesaMakeCurrent( NULL
, NULL
);
1518 MakeCurrent_PrevContext
= 0;
1519 MakeCurrent_PrevDrawable
= 0;
1520 MakeCurrent_PrevReadable
= 0;
1521 MakeCurrent_PrevDrawBuffer
= 0;
1522 MakeCurrent_PrevReadBuffer
= 0;
1526 /* The args must either all be non-zero or all zero.
1535 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1537 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1542 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1547 v
= find_glx_visual( dpy
, visinfo
);
1549 v
= create_glx_visual( dpy
, visinfo
);
1551 /* unusable visual */
1556 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1560 return b
->frontxrb
->pixmap
;
1564 /*** GLX_MESA_pixmap_colormap ***/
1567 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1568 Pixmap pixmap
, Colormap cmap
)
1573 v
= find_glx_visual( dpy
, visinfo
);
1575 v
= create_glx_visual( dpy
, visinfo
);
1577 /* unusable visual */
1582 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1586 return b
->frontxrb
->pixmap
;
1591 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1593 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1595 XMesaDestroyBuffer(b
);
1597 else if (_mesa_getenv("MESA_DEBUG")) {
1598 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1604 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1605 unsigned long mask
)
1607 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1608 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1609 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1610 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1612 if (MakeCurrent_PrevContext
== src
) {
1615 _mesa_copy_context( &(xm_src
->mesa
), &(xm_dst
->mesa
), (GLuint
) mask
);
1620 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1622 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1630 extern void _kw_ungrab_all( Display
*dpy
);
1631 void _kw_ungrab_all( Display
*dpy
)
1633 XUngrabPointer( dpy
, CurrentTime
);
1634 XUngrabKeyboard( dpy
, CurrentTime
);
1639 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1641 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1643 MakeCurrent_PrevContext
= 0;
1644 MakeCurrent_PrevDrawable
= 0;
1645 MakeCurrent_PrevReadable
= 0;
1646 MakeCurrent_PrevDrawBuffer
= 0;
1647 MakeCurrent_PrevReadBuffer
= 0;
1648 XMesaDestroyContext( glxCtx
->xmesaContext
);
1649 XMesaGarbageCollect();
1655 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1657 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1659 return glxCtx
->xmesaContext
->direct
;
1665 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1667 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1670 XMesaSwapBuffers(buffer
);
1672 else if (_mesa_getenv("MESA_DEBUG")) {
1673 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1680 /*** GLX_MESA_copy_sub_buffer ***/
1683 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1684 int x
, int y
, int width
, int height
)
1686 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1688 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1690 else if (_mesa_getenv("MESA_DEBUG")) {
1691 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1697 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1700 /* Return GLX version, not Mesa version */
1701 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1702 *maj
= CLIENT_MAJOR_VERSION
;
1703 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1709 * Query the GLX attributes of the given XVisualInfo.
1712 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1718 return GLX_BAD_ATTRIBUTE
;
1719 *value
= (int) True
;
1721 case GLX_BUFFER_SIZE
:
1722 *value
= xmvis
->visinfo
->depth
;
1725 *value
= xmvis
->mesa_visual
.level
;
1729 return GLX_BAD_ATTRIBUTE
;
1730 if (xmvis
->mesa_visual
.rgbMode
) {
1737 case GLX_DOUBLEBUFFER
:
1738 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1741 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1743 case GLX_AUX_BUFFERS
:
1744 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1747 *value
= xmvis
->mesa_visual
.redBits
;
1749 case GLX_GREEN_SIZE
:
1750 *value
= xmvis
->mesa_visual
.greenBits
;
1753 *value
= xmvis
->mesa_visual
.blueBits
;
1755 case GLX_ALPHA_SIZE
:
1756 *value
= xmvis
->mesa_visual
.alphaBits
;
1758 case GLX_DEPTH_SIZE
:
1759 *value
= xmvis
->mesa_visual
.depthBits
;
1761 case GLX_STENCIL_SIZE
:
1762 *value
= xmvis
->mesa_visual
.stencilBits
;
1764 case GLX_ACCUM_RED_SIZE
:
1765 *value
= xmvis
->mesa_visual
.accumRedBits
;
1767 case GLX_ACCUM_GREEN_SIZE
:
1768 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1770 case GLX_ACCUM_BLUE_SIZE
:
1771 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1773 case GLX_ACCUM_ALPHA_SIZE
:
1774 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1778 * GLX_EXT_visual_info extension
1780 case GLX_X_VISUAL_TYPE_EXT
:
1781 switch (xmvis
->visinfo
->CLASS
) {
1782 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1783 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1784 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1785 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1786 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1787 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1790 case GLX_TRANSPARENT_TYPE_EXT
:
1791 if (xmvis
->mesa_visual
.level
==0) {
1793 *value
= GLX_NONE_EXT
;
1795 else if (xmvis
->mesa_visual
.level
>0) {
1797 if (xmvis
->mesa_visual
.rgbMode
) {
1798 *value
= GLX_TRANSPARENT_RGB_EXT
;
1801 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1804 else if (xmvis
->mesa_visual
.level
<0) {
1806 *value
= GLX_NONE_EXT
;
1809 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1811 int pixel
= transparent_pixel( xmvis
);
1815 /* else undefined */
1818 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1821 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1824 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1827 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1832 * GLX_EXT_visual_info extension
1834 case GLX_VISUAL_CAVEAT_EXT
:
1835 /* test for zero, just in case */
1836 if (xmvis
->mesa_visual
.visualRating
> 0)
1837 *value
= xmvis
->mesa_visual
.visualRating
;
1839 *value
= GLX_NONE_EXT
;
1843 * GLX_ARB_multisample
1845 case GLX_SAMPLE_BUFFERS_ARB
:
1848 case GLX_SAMPLES_ARB
:
1855 case GLX_SCREEN_EXT
:
1857 return GLX_BAD_ATTRIBUTE
;
1858 *value
= xmvis
->visinfo
->screen
;
1860 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1862 return GLX_BAD_ATTRIBUTE
;
1863 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1865 case GLX_RENDER_TYPE_SGIX
:
1867 return GLX_BAD_ATTRIBUTE
;
1868 if (xmvis
->mesa_visual
.rgbMode
)
1869 *value
= GLX_RGBA_BIT
;
1871 *value
= GLX_COLOR_INDEX_BIT
;
1873 case GLX_X_RENDERABLE_SGIX
:
1875 return GLX_BAD_ATTRIBUTE
;
1876 *value
= True
; /* XXX really? */
1878 case GLX_FBCONFIG_ID_SGIX
:
1880 return GLX_BAD_ATTRIBUTE
;
1881 *value
= xmvis
->visinfo
->visualid
;
1883 case GLX_MAX_PBUFFER_WIDTH
:
1885 return GLX_BAD_ATTRIBUTE
;
1886 /* XXX or MAX_WIDTH? */
1887 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1889 case GLX_MAX_PBUFFER_HEIGHT
:
1891 return GLX_BAD_ATTRIBUTE
;
1892 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1894 case GLX_MAX_PBUFFER_PIXELS
:
1896 return GLX_BAD_ATTRIBUTE
;
1897 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1898 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1902 return GLX_BAD_ATTRIBUTE
;
1903 *value
= xmvis
->visinfo
->visualid
;
1906 #ifdef GLX_EXT_texture_from_pixmap
1907 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1908 *value
= True
; /*XXX*/
1910 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1912 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1914 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1915 *value
= True
; /*XXX*/
1917 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1918 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1919 GLX_TEXTURE_2D_BIT_EXT
|
1920 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1922 case GLX_Y_INVERTED_EXT
:
1923 *value
= True
; /*XXX*/
1928 return GLX_BAD_ATTRIBUTE
;
1935 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1936 int attrib
, int *value
)
1940 if (!dpy
|| !visinfo
)
1941 return GLX_BAD_ATTRIBUTE
;
1943 xmvis
= find_glx_visual( dpy
, visinfo
);
1945 /* this visual wasn't obtained with glXChooseVisual */
1946 xmvis
= create_glx_visual( dpy
, visinfo
);
1948 /* this visual can't be used for GL rendering */
1949 if (attrib
==GLX_USE_GL
) {
1950 *value
= (int) False
;
1954 return GLX_BAD_VISUAL
;
1959 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1965 Fake_glXWaitGL( void )
1967 XMesaContext xmesa
= XMesaGetCurrentContext();
1968 XMesaFlush( xmesa
);
1974 Fake_glXWaitX( void )
1976 XMesaContext xmesa
= XMesaGetCurrentContext();
1977 XMesaFlush( xmesa
);
1982 get_extensions( void )
1985 const char *fx
= _mesa_getenv("MESA_GLX_FX");
1986 if (fx
&& fx
[0] != 'd') {
1990 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
1995 /* GLX 1.1 and later */
1997 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
2001 return get_extensions();
2006 /* GLX 1.1 and later */
2008 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
2010 static char version
[1000];
2011 _mesa_sprintf(version
, "%d.%d %s",
2012 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
2018 case GLX_EXTENSIONS
:
2019 return get_extensions();
2031 /* GLX 1.1 and later */
2033 Fake_glXGetClientString( Display
*dpy
, int name
)
2035 static char version
[1000];
2036 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
2037 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
2042 case GLX_EXTENSIONS
:
2043 return get_extensions();
2061 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
2062 int attribute
, int *value
)
2064 XMesaVisual v
= (XMesaVisual
) config
;
2068 if (!dpy
|| !config
|| !value
)
2071 return get_config(v
, attribute
, value
, GL_TRUE
);
2075 static GLXFBConfig
*
2076 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
2078 XVisualInfo
*visuals
, visTemplate
;
2079 const long visMask
= VisualScreenMask
;
2082 /* Get list of all X visuals */
2083 visTemplate
.screen
= screen
;
2084 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
2085 if (*nelements
> 0) {
2086 XMesaVisual
*results
;
2087 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
2092 for (i
= 0; i
< *nelements
; i
++) {
2093 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
2095 return (GLXFBConfig
*) results
;
2101 static GLXFBConfig
*
2102 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
2103 const int *attribList
, int *nitems
)
2107 if (!attribList
|| !attribList
[0]) {
2108 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
2109 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
2112 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
2114 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
2120 config
[0] = (GLXFBConfig
) xmvis
;
2121 return (GLXFBConfig
*) config
;
2130 static XVisualInfo
*
2131 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
2133 if (dpy
&& config
) {
2134 XMesaVisual xmvis
= (XMesaVisual
) config
;
2136 return xmvis
->vishandle
;
2138 /* create a new vishandle - the cached one may be stale */
2139 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
2140 if (xmvis
->vishandle
) {
2141 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
2143 return xmvis
->vishandle
;
2153 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
2154 const int *attribList
)
2156 XMesaVisual xmvis
= (XMesaVisual
) config
;
2161 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
2166 /* XXX this will segfault if actually called */
2167 FXcreateContext(xmvis
, win
, NULL
, xmbuf
);
2171 (void) attribList
; /* Ignored in GLX 1.3 */
2173 return win
; /* A hack for now */
2178 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
2180 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2182 XMesaDestroyBuffer(b
);
2183 /* don't destroy X window */
2189 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2190 const int *attribList
)
2192 XMesaVisual v
= (XMesaVisual
) config
;
2195 int target
= 0, format
= 0, mipmap
= 0;
2198 if (!dpy
|| !config
|| !pixmap
)
2201 for (attr
= attribList
; *attr
; attr
++) {
2203 case GLX_TEXTURE_FORMAT_EXT
:
2206 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2207 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2208 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2216 case GLX_TEXTURE_TARGET_EXT
:
2219 case GLX_TEXTURE_1D_EXT
:
2220 case GLX_TEXTURE_2D_EXT
:
2221 case GLX_TEXTURE_RECTANGLE_EXT
:
2229 case GLX_MIPMAP_TEXTURE_EXT
:
2240 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2241 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2242 &value
, GL_TRUE
) != Success
2244 return 0; /* error! */
2247 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2248 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2249 &value
, GL_TRUE
) != Success
2251 return 0; /* error! */
2255 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2256 &value
, GL_TRUE
) != Success
2258 return 0; /* error! */
2261 if (target
== GLX_TEXTURE_1D_EXT
) {
2262 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2263 &value
, GL_TRUE
) != Success
2264 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2265 return 0; /* error! */
2268 else if (target
== GLX_TEXTURE_2D_EXT
) {
2269 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2270 &value
, GL_TRUE
) != Success
2271 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2272 return 0; /* error! */
2275 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2276 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2277 &value
, GL_TRUE
) != Success
2278 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2279 return 0; /* error! */
2283 if (format
|| target
|| mipmap
) {
2284 /* texture from pixmap */
2285 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2288 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2299 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2301 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2303 XMesaDestroyBuffer(b
);
2304 /* don't destroy X pixmap */
2309 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2310 const int *attribList
)
2312 XMesaVisual xmvis
= (XMesaVisual
) config
;
2315 int width
= 0, height
= 0;
2316 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2320 for (attrib
= attribList
; *attrib
; attrib
++) {
2322 case GLX_PBUFFER_WIDTH
:
2326 case GLX_PBUFFER_HEIGHT
:
2330 case GLX_PRESERVED_CONTENTS
:
2332 preserveContents
= *attrib
; /* ignored */
2334 case GLX_LARGEST_PBUFFER
:
2336 useLargest
= *attrib
; /* ignored */
2343 /* not used at this time */
2345 (void) preserveContents
;
2347 if (width
== 0 || height
== 0)
2350 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2351 /* A GLXPbuffer handle must be an X Drawable because that's what
2352 * glXMakeCurrent takes.
2355 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2362 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2364 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2366 XMesaDestroyBuffer(b
);
2372 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2373 unsigned int *value
)
2375 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2379 switch (attribute
) {
2381 *value
= xmbuf
->mesa_buffer
.Width
;
2384 *value
= xmbuf
->mesa_buffer
.Height
;
2386 case GLX_PRESERVED_CONTENTS
:
2389 case GLX_LARGEST_PBUFFER
:
2390 *value
= xmbuf
->mesa_buffer
.Width
* xmbuf
->mesa_buffer
.Height
;
2392 case GLX_FBCONFIG_ID
:
2393 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2395 #ifdef GLX_EXT_texture_from_pixmap
2396 case GLX_TEXTURE_FORMAT_EXT
:
2397 *value
= xmbuf
->TextureFormat
;
2399 case GLX_TEXTURE_TARGET_EXT
:
2400 *value
= xmbuf
->TextureTarget
;
2402 case GLX_MIPMAP_TEXTURE_EXT
:
2403 *value
= xmbuf
->TextureMipmap
;
2408 return; /* raise BadValue error */
2414 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2415 int renderType
, GLXContext shareList
, Bool direct
)
2417 struct fake_glx_context
*glxCtx
;
2418 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2419 XMesaVisual xmvis
= (XMesaVisual
) config
;
2421 if (!dpy
|| !config
||
2422 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2425 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2429 /* deallocate unused windows/buffers */
2430 XMesaGarbageCollect();
2432 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2433 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2434 if (!glxCtx
->xmesaContext
) {
2439 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2440 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2441 glxCtx
->glxContext
.currentDpy
= dpy
;
2442 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2444 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2446 return (GLXContext
) glxCtx
;
2451 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2453 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2454 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2459 switch (attribute
) {
2460 case GLX_FBCONFIG_ID
:
2461 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2463 case GLX_RENDER_TYPE
:
2464 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2465 *value
= GLX_RGBA_BIT
;
2467 *value
= GLX_COLOR_INDEX_BIT
;
2473 return GLX_BAD_ATTRIBUTE
;
2480 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2482 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2484 xmbuf
->selectedEvents
= mask
;
2489 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2490 unsigned long *mask
)
2492 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2494 *mask
= xmbuf
->selectedEvents
;
2501 /*** GLX_SGI_swap_control ***/
2504 Fake_glXSwapIntervalSGI(int interval
)
2512 /*** GLX_SGI_video_sync ***/
2514 static unsigned int FrameCounter
= 0;
2517 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2519 /* this is a bogus implementation */
2520 *count
= FrameCounter
++;
2525 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2527 if (divisor
<= 0 || remainder
< 0)
2528 return GLX_BAD_VALUE
;
2529 /* this is a bogus implementation */
2531 while (FrameCounter
% divisor
!= remainder
)
2533 *count
= FrameCounter
;
2539 /*** GLX_SGI_make_current_read ***/
2542 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2544 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2549 Fake_glXGetCurrentReadDrawableSGI(void)
2556 /*** GLX_SGIX_video_source ***/
2559 static GLXVideoSourceSGIX
2560 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2572 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2581 /*** GLX_EXT_import_context ***/
2584 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2591 Fake_glXGetContextIDEXT(const GLXContext context
)
2598 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2606 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2617 /*** GLX_SGIX_fbconfig ***/
2620 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2622 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2625 static GLXFBConfigSGIX
*
2626 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2628 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2633 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2635 XMesaVisual xmvis
= (XMesaVisual
) config
;
2636 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2637 return xmbuf
->frontxrb
->pixmap
; /* need to return an X ID */
2642 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2644 XMesaVisual xmvis
= (XMesaVisual
) config
;
2645 struct fake_glx_context
*glxCtx
;
2646 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2648 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2652 /* deallocate unused windows/buffers */
2653 XMesaGarbageCollect();
2655 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2656 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2657 if (!glxCtx
->xmesaContext
) {
2662 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2663 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2664 glxCtx
->glxContext
.currentDpy
= dpy
;
2665 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2667 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2669 return (GLXContext
) glxCtx
;
2673 static XVisualInfo
*
2674 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2676 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2680 static GLXFBConfigSGIX
2681 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2683 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2685 /* This visual wasn't found with glXChooseVisual() */
2686 xmvis
= create_glx_visual(dpy
, vis
);
2689 return (GLXFBConfigSGIX
) xmvis
;
2694 /*** GLX_SGIX_pbuffer ***/
2696 static GLXPbufferSGIX
2697 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2698 unsigned int width
, unsigned int height
,
2701 XMesaVisual xmvis
= (XMesaVisual
) config
;
2704 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2708 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2710 case GLX_PRESERVED_CONTENTS_SGIX
:
2712 preserveContents
= *attrib
; /* ignored */
2714 case GLX_LARGEST_PBUFFER_SGIX
:
2716 useLargest
= *attrib
; /* ignored */
2723 /* not used at this time */
2725 (void) preserveContents
;
2727 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2728 /* A GLXPbuffer handle must be an X Drawable because that's what
2729 * glXMakeCurrent takes.
2731 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2736 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2738 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2740 XMesaDestroyBuffer(xmbuf
);
2746 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2748 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2751 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2755 switch (attribute
) {
2756 case GLX_PRESERVED_CONTENTS_SGIX
:
2759 case GLX_LARGEST_PBUFFER_SGIX
:
2760 *value
= xmbuf
->mesa_buffer
.Width
* xmbuf
->mesa_buffer
.Height
;
2762 case GLX_WIDTH_SGIX
:
2763 *value
= xmbuf
->mesa_buffer
.Width
;
2765 case GLX_HEIGHT_SGIX
:
2766 *value
= xmbuf
->mesa_buffer
.Height
;
2768 case GLX_EVENT_MASK_SGIX
:
2769 *value
= 0; /* XXX might be wrong */
2779 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2781 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2783 /* Note: we'll never generate clobber events */
2784 xmbuf
->selectedEvents
= mask
;
2790 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2792 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2794 *mask
= xmbuf
->selectedEvents
;
2803 /*** GLX_SGI_cushion ***/
2806 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2815 /*** GLX_SGIX_video_resize ***/
2818 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2828 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2841 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2854 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2867 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2878 /*** GLX_SGIX_dmbuffer **/
2880 #if defined(_DM_BUFFER_H_)
2882 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2893 /*** GLX_SGIX_swap_group ***/
2896 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2905 /*** GLX_SGIX_swap_barrier ***/
2908 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2916 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2926 /*** GLX_SUN_get_transparent_index ***/
2929 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2934 (void) pTransparent
;
2940 /*** GLX_MESA_release_buffers ***/
2943 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2944 * (a window or pixmap) prior to destroying the GLXDrawable.
2947 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2949 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2951 XMesaDestroyBuffer(b
);
2959 /*** GLX_MESA_set_3dfx_mode ***/
2962 Fake_glXSet3DfxModeMESA( int mode
)
2964 return XMesaSetFXmode( mode
);
2969 /*** GLX_NV_vertex_array range ***/
2971 Fake_glXAllocateMemoryNV( GLsizei size
,
2972 GLfloat readFrequency
,
2973 GLfloat writeFrequency
,
2977 (void) readFrequency
;
2978 (void) writeFrequency
;
2985 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2991 /*** GLX_MESA_agp_offset ***/
2994 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
3001 /*** GLX_EXT_texture_from_pixmap ***/
3004 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
3005 const int *attrib_list
)
3007 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3009 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
3013 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
3015 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3017 XMesaReleaseTexImage(dpy
, b
, buffer
);
3021 /* silence warning */
3022 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
3026 * Create a new GLX API dispatch table with its function pointers
3027 * initialized to point to Mesa's "fake" GLX API functions.
3028 * Note: there's a similar function (_real_GetGLXDispatchTable) that
3029 * returns a new dispatch table with all pointers initalized to point
3030 * to "real" GLX functions (which understand GLX wire protocol, etc).
3032 struct _glxapi_table
*
3033 _mesa_GetGLXDispatchTable(void)
3035 static struct _glxapi_table glx
;
3037 /* be sure our dispatch table size <= libGL's table */
3039 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
3041 assert(_glxapi_get_dispatch_table_size() >= size
);
3044 /* initialize the whole table to no-ops */
3045 _glxapi_set_no_op_table(&glx
);
3047 /* now initialize the table with the functions I implement */
3048 glx
.ChooseVisual
= Fake_glXChooseVisual
;
3049 glx
.CopyContext
= Fake_glXCopyContext
;
3050 glx
.CreateContext
= Fake_glXCreateContext
;
3051 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
3052 glx
.DestroyContext
= Fake_glXDestroyContext
;
3053 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
3054 glx
.GetConfig
= Fake_glXGetConfig
;
3055 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
3056 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
3057 glx
.IsDirect
= Fake_glXIsDirect
;
3058 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
3059 glx
.QueryExtension
= Fake_glXQueryExtension
;
3060 glx
.QueryVersion
= Fake_glXQueryVersion
;
3061 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
3062 glx
.UseXFont
= Fake_glXUseXFont
;
3063 glx
.WaitGL
= Fake_glXWaitGL
;
3064 glx
.WaitX
= Fake_glXWaitX
;
3066 /*** GLX_VERSION_1_1 ***/
3067 glx
.GetClientString
= Fake_glXGetClientString
;
3068 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
3069 glx
.QueryServerString
= Fake_glXQueryServerString
;
3071 /*** GLX_VERSION_1_2 ***/
3072 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
3074 /*** GLX_VERSION_1_3 ***/
3075 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
3076 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
3077 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
3078 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
3079 glx
.CreateWindow
= Fake_glXCreateWindow
;
3080 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
3081 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
3082 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
3083 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
3084 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
3085 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
3086 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
3087 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
3088 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
3089 glx
.QueryContext
= Fake_glXQueryContext
;
3090 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
3091 glx
.SelectEvent
= Fake_glXSelectEvent
;
3093 /*** GLX_SGI_swap_control ***/
3094 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
3096 /*** GLX_SGI_video_sync ***/
3097 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
3098 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
3100 /*** GLX_SGI_make_current_read ***/
3101 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
3102 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
3104 /*** GLX_SGIX_video_source ***/
3106 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
3107 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
3110 /*** GLX_EXT_import_context ***/
3111 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
3112 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
3113 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
3114 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
3115 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
3117 /*** GLX_SGIX_fbconfig ***/
3118 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
3119 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
3120 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
3121 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
3122 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
3123 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
3125 /*** GLX_SGIX_pbuffer ***/
3126 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
3127 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
3128 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
3129 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
3130 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
3132 /*** GLX_SGI_cushion ***/
3133 glx
.CushionSGI
= Fake_glXCushionSGI
;
3135 /*** GLX_SGIX_video_resize ***/
3136 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
3137 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
3138 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
3139 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
3140 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
3142 /*** GLX_SGIX_dmbuffer **/
3143 #if defined(_DM_BUFFER_H_)
3144 glx
.AssociateDMPbufferSGIX
= NULL
;
3147 /*** GLX_SGIX_swap_group ***/
3148 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
3150 /*** GLX_SGIX_swap_barrier ***/
3151 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
3152 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
3154 /*** GLX_SUN_get_transparent_index ***/
3155 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
3157 /*** GLX_MESA_copy_sub_buffer ***/
3158 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3160 /*** GLX_MESA_release_buffers ***/
3161 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3163 /*** GLX_MESA_pixmap_colormap ***/
3164 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3166 /*** GLX_MESA_set_3dfx_mode ***/
3167 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3169 /*** GLX_NV_vertex_array_range ***/
3170 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3171 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3173 /*** GLX_MESA_agp_offset ***/
3174 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3176 /*** GLX_EXT_texture_from_pixmap ***/
3177 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3178 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;