2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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 /* This indicates the client-side GLX API and GLX encoder version. */
57 #define CLIENT_MAJOR_VERSION 1
58 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
60 /* This indicates the server-side GLX decoder version.
61 * GLX 1.4 indicates OpenGL 1.3 support
63 #define SERVER_MAJOR_VERSION 1
64 #define SERVER_MINOR_VERSION 4
66 /* This is appended onto the glXGetClient/ServerString version strings. */
67 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
69 /* Who implemented this GLX? */
70 #define VENDOR "Brian Paul"
73 "GLX_MESA_set_3dfx_mode " \
74 "GLX_MESA_copy_sub_buffer " \
75 "GLX_MESA_pixmap_colormap " \
76 "GLX_MESA_release_buffers " \
77 "GLX_ARB_get_proc_address " \
78 "GLX_EXT_visual_info " \
79 "GLX_EXT_visual_rating " \
80 "GLX_SGI_video_sync " \
81 "GLX_SGIX_fbconfig " \
84 "GLX_ARB_render_texture"
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 #define MAX_VISUALS 100
113 static XMesaVisual VisualTable
[MAX_VISUALS
];
114 static int NumVisuals
= 0;
118 * This struct and some code fragments borrowed
119 * from Mark Kilgard's GLUT library.
121 typedef struct _OverlayInfo
{
122 /* Avoid 64-bit portability problems by being careful to use
123 longs due to the way XGetWindowProperty is specified. Note
124 that these parameters are passed as CARD32s over X
126 unsigned long overlay_visual
;
127 long transparent_type
;
134 /* Macro to handle c_class vs class field name in XVisualInfo struct */
135 #if defined(__cplusplus) || defined(c_plusplus)
136 #define CLASS c_class
145 * Test if the given XVisualInfo is usable for Mesa rendering.
147 static GLboolean
is_usable_visual( XVisualInfo
*vinfo
)
149 switch (vinfo
->CLASS
) {
152 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
156 /* Any StaticColor/PseudoColor visual of at least 4 bits */
157 if (vinfo
->depth
>=4) {
165 /* Any depth of TrueColor or DirectColor works in RGB mode */
168 /* This should never happen */
176 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
177 * Input: dpy - the X display
178 * vinfo - the XVisualInfo to test
179 * Return: level of the visual:
181 * >0 = overlay planes
182 * <0 = underlay planes
184 static int level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
186 Atom overlayVisualsAtom
;
187 OverlayInfo
*overlay_info
= NULL
;
188 int numOverlaysPerScreen
;
192 unsigned long sizeData
, bytesLeft
;
196 * The SERVER_OVERLAY_VISUALS property on the root window contains
197 * a list of overlay visuals. Get that list now.
199 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
200 if (overlayVisualsAtom
== None
) {
204 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, vinfo
->screen
),
205 overlayVisualsAtom
, 0L, (long) 10000, False
,
206 overlayVisualsAtom
, &actualType
, &actualFormat
,
207 &sizeData
, &bytesLeft
,
208 (unsigned char **) &overlay_info
);
210 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
211 actualFormat
!= 32 || sizeData
< 4) {
212 /* something went wrong */
213 XFree((void *) overlay_info
);
217 /* search the overlay visual list for the visual ID of interest */
218 numOverlaysPerScreen
= (int) (sizeData
/ 4);
219 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
221 ov
= overlay_info
+ i
;
222 if (ov
->overlay_visual
==vinfo
->visualid
) {
223 /* found the visual */
224 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
225 int level
= ov
->layer
;
226 XFree((void *) overlay_info
);
230 XFree((void *) overlay_info
);
236 /* The visual ID was not found in the overlay list. */
237 XFree((void *) overlay_info
);
245 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
246 * configuration in our list of GLX visuals.
249 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
250 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
251 GLboolean stereoFlag
,
252 GLint depth_size
, GLint stencil_size
,
253 GLint accumRedSize
, GLint accumGreenSize
,
254 GLint accumBlueSize
, GLint accumAlphaSize
,
255 GLint level
, GLint numAuxBuffers
)
257 GLboolean ximageFlag
= GL_TRUE
;
260 GLboolean comparePointers
;
263 /* Check if the MESA_BACK_BUFFER env var is set */
264 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
266 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
267 ximageFlag
= GL_FALSE
;
269 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
270 ximageFlag
= GL_TRUE
;
273 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
278 /* Comparing IDs uses less memory but sometimes fails. */
279 /* XXX revisit this after 3.0 is finished. */
280 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
281 comparePointers
= GL_TRUE
;
283 comparePointers
= GL_FALSE
;
285 /* First check if a matching visual is already in the list */
286 for (i
=0; i
<NumVisuals
; i
++) {
287 XMesaVisual v
= VisualTable
[i
];
288 if (v
->display
== dpy
289 && v
->mesa_visual
.level
== level
290 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
291 && v
->ximage_flag
== ximageFlag
292 && v
->mesa_visual
.rgbMode
== rgbFlag
293 && v
->mesa_visual
.doubleBufferMode
== dbFlag
294 && v
->mesa_visual
.stereoMode
== stereoFlag
295 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
296 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
297 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
298 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
299 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
300 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
301 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
302 /* now either compare XVisualInfo pointers or visual IDs */
303 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
304 || (comparePointers
&& v
->vishandle
== vinfo
)) {
310 /* Create a new visual and add it to the list. */
312 if (NumVisuals
>= MAX_VISUALS
) {
313 _mesa_problem(NULL
, "GLX Error: maximum number of visuals exceeded");
317 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
318 stereoFlag
, ximageFlag
,
319 depth_size
, stencil_size
,
320 accumRedSize
, accumBlueSize
,
321 accumBlueSize
, accumAlphaSize
, 0, level
,
324 /* Save a copy of the pointer now so we can find this visual again
325 * if we need to search for it in find_glx_visual().
327 xmvis
->vishandle
= vinfo
;
328 /* add xmvis to the list */
329 VisualTable
[NumVisuals
] = xmvis
;
332 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
340 * Create a GLX visual from a regular XVisualInfo.
341 * This is called when Fake GLX is given an XVisualInfo which wasn't
342 * returned by glXChooseVisual. Since this is the first time we're
343 * considering this visual we'll take a guess at reasonable values
344 * for depth buffer size, stencil size, accum size, etc.
345 * This is the best we can do with a client-side emulation of GLX.
348 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
352 vislevel
= level_of_visual( dpy
, visinfo
);
354 /* Configure this visual as a CI, single-buffered overlay */
355 return save_glx_visual( dpy
, visinfo
,
357 GL_FALSE
, /* alpha */
358 GL_FALSE
, /* double */
359 GL_FALSE
, /* stereo */
361 0, /* stencil bits */
362 0,0,0,0, /* accum bits */
363 vislevel
, /* level */
367 else if (is_usable_visual( visinfo
)) {
368 if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
369 /* Configure this visual as a COLOR INDEX visual. */
370 return save_glx_visual( dpy
, visinfo
,
372 GL_FALSE
, /* alpha */
373 GL_TRUE
, /* double */
374 GL_FALSE
, /* stereo */
375 DEFAULT_SOFTWARE_DEPTH_BITS
,
376 8 * sizeof(GLstencil
),
377 0 * sizeof(GLaccum
), /* r */
378 0 * sizeof(GLaccum
), /* g */
379 0 * sizeof(GLaccum
), /* b */
380 0 * sizeof(GLaccum
), /* a */
386 /* Configure this visual as RGB, double-buffered, depth-buffered. */
387 /* This is surely wrong for some people's needs but what else */
388 /* can be done? They should use glXChooseVisual(). */
389 return save_glx_visual( dpy
, visinfo
,
391 GL_FALSE
, /* alpha */
392 GL_TRUE
, /* double */
393 GL_FALSE
, /* stereo */
394 DEFAULT_SOFTWARE_DEPTH_BITS
,
395 8 * sizeof(GLstencil
),
396 8 * sizeof(GLaccum
), /* r */
397 8 * sizeof(GLaccum
), /* g */
398 8 * sizeof(GLaccum
), /* b */
399 8 * sizeof(GLaccum
), /* a */
406 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
414 * Find the GLX visual associated with an XVisualInfo.
417 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
421 /* try to match visual id */
422 for (i
=0;i
<NumVisuals
;i
++) {
423 if (VisualTable
[i
]->display
==dpy
424 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
425 return VisualTable
[i
];
429 /* if that fails, try to match pointers */
430 for (i
=0;i
<NumVisuals
;i
++) {
431 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
432 return VisualTable
[i
];
442 * Return the transparent pixel value for a GLX visual.
443 * Input: glxvis - the glx_visual
444 * Return: a pixel value or -1 if no transparent pixel
446 static int transparent_pixel( XMesaVisual glxvis
)
448 Display
*dpy
= glxvis
->display
;
449 XVisualInfo
*vinfo
= glxvis
->visinfo
;
450 Atom overlayVisualsAtom
;
451 OverlayInfo
*overlay_info
= NULL
;
452 int numOverlaysPerScreen
;
456 unsigned long sizeData
, bytesLeft
;
460 * The SERVER_OVERLAY_VISUALS property on the root window contains
461 * a list of overlay visuals. Get that list now.
463 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
464 if (overlayVisualsAtom
== None
) {
468 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, vinfo
->screen
),
469 overlayVisualsAtom
, 0L, (long) 10000, False
,
470 overlayVisualsAtom
, &actualType
, &actualFormat
,
471 &sizeData
, &bytesLeft
,
472 (unsigned char **) &overlay_info
);
474 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
475 actualFormat
!= 32 || sizeData
< 4) {
476 /* something went wrong */
477 XFree((void *) overlay_info
);
481 /* search the overlay visual list for the visual ID of interest */
482 numOverlaysPerScreen
= (int) (sizeData
/ 4);
483 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
485 ov
= overlay_info
+ i
;
486 if (ov
->overlay_visual
==vinfo
->visualid
) {
488 if (ov
->transparent_type
==0) {
489 /* type 0 indicates no transparency */
490 XFree((void *) overlay_info
);
494 /* ov->value is the transparent pixel */
495 XFree((void *) overlay_info
);
501 /* The visual ID was not found in the overlay list. */
502 XFree((void *) overlay_info
);
509 * Try to get an X visual which matches the given arguments.
511 static XVisualInfo
*get_visual( Display
*dpy
, int scr
,
512 unsigned int depth
, int xclass
)
514 XVisualInfo temp
, *vis
;
517 unsigned int default_depth
;
520 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
525 default_depth
= DefaultDepth(dpy
,scr
);
526 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
528 if (depth
==default_depth
&& xclass
==default_class
) {
529 /* try to get root window's visual */
530 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
531 mask
|= VisualIDMask
;
534 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
536 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
537 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
538 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
540 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
541 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
542 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
543 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
558 * Retrieve the value of the given environment variable and find
559 * the X visual which matches it.
560 * Input: dpy - the display
561 * screen - the screen number
562 * varname - the name of the environment variable
563 * Return: an XVisualInfo pointer to NULL if error.
565 static XVisualInfo
*get_env_visual(Display
*dpy
, int scr
, const char *varname
)
567 char value
[100], type
[100];
568 int depth
, xclass
= -1;
571 if (!_mesa_getenv( varname
)) {
575 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
578 sscanf( value
, "%s %d", type
, &depth
);
580 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
581 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
582 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
583 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
584 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
585 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
587 if (xclass
>-1 && depth
>0) {
588 vis
= get_visual( dpy
, scr
, depth
, xclass
);
594 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
603 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
604 * Input: dpy, screen - X display and screen number
605 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
606 * min_depth - minimum visual depth
607 * preferred_class - preferred GLX visual class or DONT_CARE
608 * Return: pointer to an XVisualInfo or NULL.
610 static XVisualInfo
*choose_x_visual( Display
*dpy
, int screen
,
611 GLboolean rgba
, int min_depth
,
612 int preferred_class
)
615 int xclass
, visclass
= 0;
619 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
620 /* First see if the MESA_RGB_VISUAL env var is defined */
621 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
625 /* Otherwise, search for a suitable visual */
626 if (preferred_class
==DONT_CARE
) {
627 for (xclass
=0;xclass
<6;xclass
++) {
629 case 0: visclass
= TrueColor
; break;
630 case 1: visclass
= DirectColor
; break;
631 case 2: visclass
= PseudoColor
; break;
632 case 3: visclass
= StaticColor
; break;
633 case 4: visclass
= GrayScale
; break;
634 case 5: visclass
= StaticGray
; break;
637 /* start with shallowest */
638 for (depth
=0;depth
<=32;depth
++) {
639 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
640 /* Special case: try to get 8-bit PseudoColor before */
641 /* 8-bit TrueColor */
642 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
647 vis
= get_visual( dpy
, screen
, depth
, visclass
);
654 /* start with deepest */
655 for (depth
=32;depth
>=min_depth
;depth
--) {
656 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
657 /* Special case: try to get 8-bit PseudoColor before */
658 /* 8-bit TrueColor */
659 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
664 vis
= get_visual( dpy
, screen
, depth
, visclass
);
673 /* search for a specific visual class */
674 switch (preferred_class
) {
675 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
676 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
677 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
678 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
679 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
680 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
681 default: return NULL
;
684 /* start with shallowest */
685 for (depth
=0;depth
<=32;depth
++) {
686 vis
= get_visual( dpy
, screen
, depth
, visclass
);
693 /* start with deepest */
694 for (depth
=32;depth
>=min_depth
;depth
--) {
695 vis
= get_visual( dpy
, screen
, depth
, visclass
);
704 /* First see if the MESA_CI_VISUAL env var is defined */
705 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
709 /* Otherwise, search for a suitable visual, starting with shallowest */
710 if (preferred_class
==DONT_CARE
) {
711 for (xclass
=0;xclass
<4;xclass
++) {
713 case 0: visclass
= PseudoColor
; break;
714 case 1: visclass
= StaticColor
; break;
715 case 2: visclass
= GrayScale
; break;
716 case 3: visclass
= StaticGray
; break;
718 /* try 8-bit up through 16-bit */
719 for (depth
=8;depth
<=16;depth
++) {
720 vis
= get_visual( dpy
, screen
, depth
, visclass
);
725 /* try min_depth up to 8-bit */
726 for (depth
=min_depth
;depth
<8;depth
++) {
727 vis
= get_visual( dpy
, screen
, depth
, visclass
);
735 /* search for a specific visual class */
736 switch (preferred_class
) {
737 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
738 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
739 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
740 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
741 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
742 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
743 default: return NULL
;
745 /* try 8-bit up through 16-bit */
746 for (depth
=8;depth
<=16;depth
++) {
747 vis
= get_visual( dpy
, screen
, depth
, visclass
);
752 /* try min_depth up to 8-bit */
753 for (depth
=min_depth
;depth
<8;depth
++) {
754 vis
= get_visual( dpy
, screen
, depth
, visclass
);
762 /* didn't find a visual */
769 * Find the deepest X over/underlay visual of at least min_depth.
770 * Input: dpy, screen - X display and screen number
771 * level - the over/underlay level
772 * trans_type - transparent pixel type: GLX_NONE_EXT,
773 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
775 * trans_value - transparent pixel value or DONT_CARE
776 * min_depth - minimum visual depth
777 * preferred_class - preferred GLX visual class or DONT_CARE
778 * Return: pointer to an XVisualInfo or NULL.
780 static XVisualInfo
*choose_x_overlay_visual( Display
*dpy
, int scr
,
782 int level
, int trans_type
,
785 int preferred_class
)
787 Atom overlayVisualsAtom
;
788 OverlayInfo
*overlay_info
;
789 int numOverlaysPerScreen
;
793 unsigned long sizeData
, bytesLeft
;
795 XVisualInfo
*deepvis
;
798 /*DEBUG int tt, tv; */
800 switch (preferred_class
) {
801 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
802 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
803 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
804 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
805 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
806 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
807 default: preferred_class
= DONT_CARE
;
811 * The SERVER_OVERLAY_VISUALS property on the root window contains
812 * a list of overlay visuals. Get that list now.
814 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
815 if (overlayVisualsAtom
== (Atom
) None
) {
819 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, scr
),
820 overlayVisualsAtom
, 0L, (long) 10000, False
,
821 overlayVisualsAtom
, &actualType
, &actualFormat
,
822 &sizeData
, &bytesLeft
,
823 (unsigned char **) &overlay_info
);
825 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
826 actualFormat
!= 32 || sizeData
< 4) {
827 /* something went wrong */
831 /* Search for the deepest overlay which satisifies all criteria. */
835 numOverlaysPerScreen
= (int) (sizeData
/ 4);
836 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
837 XVisualInfo
*vislist
, vistemplate
;
840 ov
= overlay_info
+ i
;
842 if (ov
->layer
!=level
) {
843 /* failed overlay level criteria */
846 if (!(trans_type
==DONT_CARE
847 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
848 && ov
->transparent_type
>0)
849 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
850 /* failed transparent pixel type criteria */
853 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
854 /* failed transparent pixel value criteria */
858 /* get XVisualInfo and check the depth */
859 vistemplate
.visualid
= ov
->overlay_visual
;
860 vistemplate
.screen
= scr
;
861 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
862 &vistemplate
, &count
);
865 /* something went wrong */
868 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
869 /* wrong visual class */
873 /* if RGB was requested, make sure we have True/DirectColor */
874 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
875 && vislist
->CLASS
!= DirectColor
)
878 /* if CI was requested, make sure we have a color indexed visual */
880 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
883 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
884 /* YES! found a satisfactory visual */
888 deepest
= vislist
->depth
;
890 /* DEBUG tt = ov->transparent_type;*/
891 /* DEBUG tv = ov->value; */
897 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
898 deepvis->visualid, level, deepvis->depth, tt, tv );
905 /**********************************************************************/
906 /*** Begin Fake GLX API Functions ***/
907 /**********************************************************************/
910 static XMesaVisual
choose_visual( Display
*dpy
, int screen
, const int *list
,
911 GLboolean rgbModeDefault
)
913 const int *parselist
;
916 int min_red
=0, min_green
=0, min_blue
=0;
917 GLboolean rgb_flag
= rgbModeDefault
;
918 GLboolean alpha_flag
= GL_FALSE
;
919 GLboolean double_flag
= GL_FALSE
;
920 GLboolean stereo_flag
= GL_FALSE
;
921 GLint depth_size
= 0;
922 GLint stencil_size
= 0;
923 GLint accumRedSize
= 0;
924 GLint accumGreenSize
= 0;
925 GLint accumBlueSize
= 0;
926 GLint accumAlphaSize
= 0;
928 int visual_type
= DONT_CARE
;
929 int trans_type
= DONT_CARE
;
930 int trans_value
= DONT_CARE
;
931 GLint caveat
= DONT_CARE
;
932 XMesaVisual xmvis
= NULL
;
933 int desiredVisualID
= -1;
940 switch (*parselist
) {
945 case GLX_BUFFER_SIZE
:
947 min_ci
= *parselist
++;
951 level
= *parselist
++;
957 case GLX_DOUBLEBUFFER
:
958 double_flag
= GL_TRUE
;
962 stereo_flag
= GL_TRUE
;
964 case GLX_AUX_BUFFERS
:
967 numAux
= *parselist
++;
968 if (numAux
> MAX_AUX_BUFFERS
)
973 min_red
= *parselist
++;
977 min_green
= *parselist
++;
981 min_blue
= *parselist
++;
986 GLint size
= *parselist
++;
987 alpha_flag
= size
>0 ? 1 : 0;
992 depth_size
= *parselist
++;
994 case GLX_STENCIL_SIZE
:
996 stencil_size
= *parselist
++;
998 case GLX_ACCUM_RED_SIZE
:
1001 GLint size
= *parselist
++;
1002 accumRedSize
= MAX2( accumRedSize
, size
);
1005 case GLX_ACCUM_GREEN_SIZE
:
1008 GLint size
= *parselist
++;
1009 accumGreenSize
= MAX2( accumGreenSize
, size
);
1012 case GLX_ACCUM_BLUE_SIZE
:
1015 GLint size
= *parselist
++;
1016 accumBlueSize
= MAX2( accumBlueSize
, size
);
1019 case GLX_ACCUM_ALPHA_SIZE
:
1022 GLint size
= *parselist
++;
1023 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1028 * GLX_EXT_visual_info extension
1030 case GLX_X_VISUAL_TYPE_EXT
:
1032 visual_type
= *parselist
++;
1034 case GLX_TRANSPARENT_TYPE_EXT
:
1036 trans_type
= *parselist
++;
1038 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1040 trans_value
= *parselist
++;
1042 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1043 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1044 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1045 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1052 * GLX_EXT_visual_info extension
1054 case GLX_VISUAL_CAVEAT_EXT
:
1056 caveat
= *parselist
++; /* ignored for now */
1060 * GLX_ARB_multisample
1062 case GLX_SAMPLE_BUFFERS_ARB
:
1063 /* ms not supported */
1065 case GLX_SAMPLES_ARB
:
1066 /* ms not supported */
1072 case GLX_RENDER_TYPE
:
1074 if (*parselist
== GLX_RGBA_BIT
) {
1077 else if (*parselist
== GLX_COLOR_INDEX_BIT
) {
1078 rgb_flag
= GL_FALSE
;
1080 else if (*parselist
== 0) {
1085 case GLX_DRAWABLE_TYPE
:
1087 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1088 return NULL
; /* bad bit */
1092 case GLX_FBCONFIG_ID
:
1094 desiredVisualID
= *parselist
;
1102 /* undefined attribute */
1103 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1112 * Since we're only simulating the GLX extension this function will never
1113 * find any real GL visuals. Instead, all we can do is try to find an RGB
1114 * or CI visual of appropriate depth. Other requested attributes such as
1115 * double buffering, depth buffer, etc. will be associated with the X
1116 * visual and stored in the VisualTable[].
1118 if (desiredVisualID
!= -1) {
1119 /* try to get a specific visual, by visualID */
1122 temp
.visualid
= desiredVisualID
;
1123 temp
.screen
= screen
;
1124 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1126 /* give the visual some useful GLX attributes */
1127 double_flag
= GL_TRUE
;
1130 depth_size
= DEFAULT_SOFTWARE_DEPTH_BITS
;
1131 stencil_size
= STENCIL_BITS
;
1135 else if (level
==0) {
1136 /* normal color planes */
1138 /* Get an RGB visual */
1139 int min_rgb
= min_red
+ min_green
+ min_blue
;
1140 if (min_rgb
>1 && min_rgb
<8) {
1141 /* a special case to be sure we can get a monochrome visual */
1144 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1147 /* Get a color index visual */
1148 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1149 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1153 /* over/underlay planes */
1156 int min_rgb
= min_red
+ min_green
+ min_blue
;
1157 if (min_rgb
>1 && min_rgb
<8) {
1158 /* a special case to be sure we can get a monochrome visual */
1161 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1162 trans_type
, trans_value
, min_rgb
, visual_type
);
1165 /* color index overlay */
1166 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1167 trans_type
, trans_value
, min_ci
, visual_type
);
1172 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1173 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1174 * largest depth buffer size, which is 32bits/value. Instead, we
1175 * return 16 to maintain performance with earlier versions of Mesa.
1177 if (depth_size
> 24)
1178 depth_size
= 31; /* 32 causes int overflow problems */
1179 else if (depth_size
> 16)
1181 else if (depth_size
> 0)
1182 depth_size
= DEFAULT_SOFTWARE_DEPTH_BITS
; /*16*/
1184 /* we only support one size of stencil and accum buffers. */
1185 if (stencil_size
> 0)
1186 stencil_size
= STENCIL_BITS
;
1187 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1188 accumAlphaSize
> 0) {
1189 accumRedSize
= ACCUM_BITS
;
1190 accumGreenSize
= ACCUM_BITS
;
1191 accumBlueSize
= ACCUM_BITS
;
1192 accumAlphaSize
= alpha_flag
? ACCUM_BITS
: 0;
1195 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1196 stereo_flag
, depth_size
, stencil_size
,
1197 accumRedSize
, accumGreenSize
,
1198 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1205 static XVisualInfo
*
1206 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1208 XMesaVisual xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1211 return xmvis
->vishandle
;
1213 /* create a new vishandle - the cached one may be stale */
1214 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1215 if (xmvis
->vishandle
) {
1216 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1218 return xmvis
->vishandle
;
1227 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1228 GLXContext share_list
, Bool direct
)
1231 struct fake_glx_context
*glxCtx
;
1232 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1234 if (!dpy
|| !visinfo
)
1237 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1241 /* deallocate unused windows/buffers */
1242 XMesaGarbageCollect();
1244 xmvis
= find_glx_visual( dpy
, visinfo
);
1246 /* This visual wasn't found with glXChooseVisual() */
1247 xmvis
= create_glx_visual( dpy
, visinfo
);
1249 /* unusable visual */
1255 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1256 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1257 if (!glxCtx
->xmesaContext
) {
1262 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
1263 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
1264 glxCtx
->glxContext
.currentDpy
= dpy
;
1265 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1267 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1269 return (GLXContext
) glxCtx
;
1273 /* XXX these may have to be removed due to thread-safety issues. */
1274 static GLXContext MakeCurrent_PrevContext
= 0;
1275 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1276 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1277 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1278 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1281 /* GLX 1.3 and later */
1283 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1284 GLXDrawable read
, GLXContext ctx
)
1286 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1288 if (ctx
&& draw
&& read
) {
1289 XMesaBuffer drawBuffer
, readBuffer
;
1290 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1292 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1293 if (ctx
== MakeCurrent_PrevContext
1294 && draw
== MakeCurrent_PrevDrawable
) {
1295 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1298 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1301 /* drawable must be a new window! */
1302 drawBuffer
= XMesaCreateWindowBuffer2( xmctx
->xm_visual
, draw
, xmctx
);
1304 /* Out of memory, or context/drawable depth mismatch */
1309 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1310 if (ctx
== MakeCurrent_PrevContext
1311 && read
== MakeCurrent_PrevReadable
) {
1312 readBuffer
= MakeCurrent_PrevReadBuffer
;
1315 readBuffer
= XMesaFindBuffer( dpy
, read
);
1318 /* drawable must be a new window! */
1319 readBuffer
= XMesaCreateWindowBuffer2(glxCtx
->xmesaContext
->xm_visual
,
1322 /* Out of memory, or context/drawable depth mismatch */
1327 MakeCurrent_PrevContext
= ctx
;
1328 MakeCurrent_PrevDrawable
= draw
;
1329 MakeCurrent_PrevReadable
= read
;
1330 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1331 MakeCurrent_PrevReadBuffer
= readBuffer
;
1333 /* Now make current! */
1334 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1335 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1336 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1337 #ifndef GLX_BUILT_IN_XMESA
1338 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1340 __glXSetCurrentContext(ctx
);
1348 else if (!ctx
&& !draw
&& !read
) {
1349 /* release current context w/out assigning new one. */
1350 XMesaMakeCurrent( NULL
, NULL
);
1351 MakeCurrent_PrevContext
= 0;
1352 MakeCurrent_PrevDrawable
= 0;
1353 MakeCurrent_PrevReadable
= 0;
1354 MakeCurrent_PrevDrawBuffer
= 0;
1355 MakeCurrent_PrevReadBuffer
= 0;
1356 #ifdef GLX_BUILT_IN_XMESA
1357 /* XXX bind dummy context with __glXSetCurrentContext(ctx); */
1362 /* The args must either all be non-zero or all zero.
1372 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1374 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1380 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1385 v
= find_glx_visual( dpy
, visinfo
);
1387 v
= create_glx_visual( dpy
, visinfo
);
1389 /* unusable visual */
1394 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1398 return b
->frontbuffer
;
1402 /*** GLX_MESA_pixmap_colormap ***/
1405 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1406 Pixmap pixmap
, Colormap cmap
)
1411 v
= find_glx_visual( dpy
, visinfo
);
1413 v
= create_glx_visual( dpy
, visinfo
);
1415 /* unusable visual */
1420 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1424 return b
->frontbuffer
;
1429 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1431 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1433 XMesaDestroyBuffer(b
);
1435 else if (_mesa_getenv("MESA_DEBUG")) {
1436 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1443 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1444 unsigned long mask
)
1446 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1447 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1448 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1449 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1451 _mesa_copy_context( &(xm_src
->mesa
), &(xm_dst
->mesa
), (GLuint
) mask
);
1457 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1459 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1467 extern void _kw_ungrab_all( Display
*dpy
);
1468 void _kw_ungrab_all( Display
*dpy
)
1470 XUngrabPointer( dpy
, CurrentTime
);
1471 XUngrabKeyboard( dpy
, CurrentTime
);
1476 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1478 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1480 MakeCurrent_PrevContext
= 0;
1481 MakeCurrent_PrevDrawable
= 0;
1482 MakeCurrent_PrevReadable
= 0;
1483 MakeCurrent_PrevDrawBuffer
= 0;
1484 MakeCurrent_PrevReadBuffer
= 0;
1485 XMesaDestroyContext( glxCtx
->xmesaContext
);
1486 XMesaGarbageCollect();
1492 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1494 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1496 return glxCtx
->xmesaContext
->direct
;
1502 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1504 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1507 XMesaSwapBuffers(buffer
);
1509 else if (_mesa_getenv("MESA_DEBUG")) {
1510 _mesa_warning(NULL
, "Mesa: glXSwapBuffers: invalid drawable\n");
1516 /*** GLX_MESA_copy_sub_buffer ***/
1519 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1520 int x
, int y
, int width
, int height
)
1522 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1524 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1526 else if (_mesa_getenv("MESA_DEBUG")) {
1527 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1534 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1537 /* Return GLX version, not Mesa version */
1538 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1539 *maj
= CLIENT_MAJOR_VERSION
;
1540 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1547 * Query the GLX attributes of the given XVisualInfo.
1550 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1555 *value
= (int) True
;
1557 case GLX_BUFFER_SIZE
:
1558 *value
= xmvis
->visinfo
->depth
;
1561 *value
= xmvis
->mesa_visual
.level
;
1564 if (xmvis
->mesa_visual
.rgbMode
) {
1571 case GLX_DOUBLEBUFFER
:
1572 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1575 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1577 case GLX_AUX_BUFFERS
:
1578 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1581 *value
= xmvis
->mesa_visual
.redBits
;
1583 case GLX_GREEN_SIZE
:
1584 *value
= xmvis
->mesa_visual
.greenBits
;
1587 *value
= xmvis
->mesa_visual
.blueBits
;
1589 case GLX_ALPHA_SIZE
:
1590 *value
= xmvis
->mesa_visual
.alphaBits
;
1592 case GLX_DEPTH_SIZE
:
1593 *value
= xmvis
->mesa_visual
.depthBits
;
1595 case GLX_STENCIL_SIZE
:
1596 *value
= xmvis
->mesa_visual
.stencilBits
;
1598 case GLX_ACCUM_RED_SIZE
:
1599 *value
= xmvis
->mesa_visual
.accumRedBits
;
1601 case GLX_ACCUM_GREEN_SIZE
:
1602 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1604 case GLX_ACCUM_BLUE_SIZE
:
1605 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1607 case GLX_ACCUM_ALPHA_SIZE
:
1608 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1612 * GLX_EXT_visual_info extension
1614 case GLX_X_VISUAL_TYPE_EXT
:
1615 switch (xmvis
->visinfo
->CLASS
) {
1616 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1617 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1618 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1619 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1620 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1621 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1624 case GLX_TRANSPARENT_TYPE_EXT
:
1625 if (xmvis
->mesa_visual
.level
==0) {
1627 *value
= GLX_NONE_EXT
;
1629 else if (xmvis
->mesa_visual
.level
>0) {
1631 if (xmvis
->mesa_visual
.rgbMode
) {
1632 *value
= GLX_TRANSPARENT_RGB_EXT
;
1635 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1638 else if (xmvis
->mesa_visual
.level
<0) {
1640 *value
= GLX_NONE_EXT
;
1643 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1645 int pixel
= transparent_pixel( xmvis
);
1649 /* else undefined */
1652 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1655 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1658 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1661 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1666 * GLX_EXT_visual_info extension
1668 case GLX_VISUAL_CAVEAT_EXT
:
1669 /* test for zero, just in case */
1670 if (xmvis
->mesa_visual
.visualRating
> 0)
1671 *value
= xmvis
->mesa_visual
.visualRating
;
1673 *value
= GLX_NONE_EXT
;
1677 * GLX_ARB_multisample
1679 case GLX_SAMPLE_BUFFERS_ARB
:
1682 case GLX_SAMPLES_ARB
:
1689 case GLX_SCREEN_EXT
:
1691 return GLX_BAD_ATTRIBUTE
;
1692 *value
= xmvis
->visinfo
->screen
;
1694 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1696 return GLX_BAD_ATTRIBUTE
;
1697 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1699 case GLX_RENDER_TYPE_SGIX
:
1701 return GLX_BAD_ATTRIBUTE
;
1702 if (xmvis
->mesa_visual
.rgbMode
)
1703 *value
= GLX_RGBA_BIT
;
1705 *value
= GLX_COLOR_INDEX_BIT
;
1707 case GLX_X_RENDERABLE_SGIX
:
1709 return GLX_BAD_ATTRIBUTE
;
1710 *value
= True
; /* XXX really? */
1712 case GLX_FBCONFIG_ID_SGIX
:
1714 return GLX_BAD_ATTRIBUTE
;
1715 *value
= xmvis
->visinfo
->visualid
;
1717 case GLX_MAX_PBUFFER_WIDTH
:
1719 return GLX_BAD_ATTRIBUTE
;
1720 /* XXX or MAX_WIDTH? */
1721 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1723 case GLX_MAX_PBUFFER_HEIGHT
:
1725 return GLX_BAD_ATTRIBUTE
;
1726 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1728 case GLX_MAX_PBUFFER_PIXELS
:
1730 return GLX_BAD_ATTRIBUTE
;
1731 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1732 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1736 return GLX_BAD_ATTRIBUTE
;
1737 *value
= xmvis
->visinfo
->visualid
;
1741 return GLX_BAD_ATTRIBUTE
;
1748 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1749 int attrib
, int *value
)
1753 if (!dpy
|| !visinfo
)
1754 return GLX_BAD_ATTRIBUTE
;
1756 xmvis
= find_glx_visual( dpy
, visinfo
);
1758 /* this visual wasn't obtained with glXChooseVisual */
1759 xmvis
= create_glx_visual( dpy
, visinfo
);
1761 /* this visual can't be used for GL rendering */
1762 if (attrib
==GLX_USE_GL
) {
1763 *value
= (int) False
;
1767 return GLX_BAD_VISUAL
;
1772 return get_config(xmvis
, attrib
, value
, GL_FALSE
);
1777 Fake_glXWaitGL( void )
1779 XMesaContext xmesa
= XMesaGetCurrentContext();
1780 XMesaFlush( xmesa
);
1786 Fake_glXWaitX( void )
1788 XMesaContext xmesa
= XMesaGetCurrentContext();
1789 XMesaFlush( xmesa
);
1794 get_extensions( void )
1797 const char *fx
= _mesa_getenv("MESA_GLX_FX");
1798 if (fx
&& fx
[0] != 'd') {
1802 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
1807 /* GLX 1.1 and later */
1809 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1813 return get_extensions();
1818 /* GLX 1.1 and later */
1820 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1822 static char version
[1000];
1823 _mesa_sprintf(version
, "%d.%d %s",
1824 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1830 case GLX_EXTENSIONS
:
1831 return get_extensions();
1843 /* GLX 1.1 and later */
1845 Fake_glXGetClientString( Display
*dpy
, int name
)
1847 static char version
[1000];
1848 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1849 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1854 case GLX_EXTENSIONS
:
1855 return get_extensions();
1872 static GLXFBConfig
*
1873 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1874 const int *attribList
, int *nitems
)
1876 XMesaVisual xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1878 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
1884 config
[0] = (GLXFBConfig
) xmvis
;
1885 return (GLXFBConfig
*) config
;
1895 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1896 int attribute
, int *value
)
1898 XMesaVisual v
= (XMesaVisual
) config
;
1902 if (!dpy
|| !config
|| !value
)
1905 return get_config(v
, attribute
, value
, GL_TRUE
);
1909 static GLXFBConfig
*
1910 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1912 XVisualInfo
*visuals
, visTemplate
;
1913 const long visMask
= VisualScreenMask
;
1916 /* Get list of all X visuals */
1917 visTemplate
.screen
= screen
;
1918 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1919 if (*nelements
> 0) {
1920 XMesaVisual
*results
;
1921 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
1926 for (i
= 0; i
< *nelements
; i
++) {
1927 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1929 return (GLXFBConfig
*) results
;
1935 static XVisualInfo
*
1936 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1938 if (dpy
&& config
) {
1939 XMesaVisual xmvis
= (XMesaVisual
) config
;
1941 return xmvis
->vishandle
;
1943 /* create a new vishandle - the cached one may be stale */
1944 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1945 if (xmvis
->vishandle
) {
1946 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1948 return xmvis
->vishandle
;
1958 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1959 const int *attribList
)
1961 XMesaVisual xmvis
= (XMesaVisual
) config
;
1966 xmbuf
= XMesaCreateWindowBuffer2(xmvis
, win
, NULL
);
1971 (void) attribList
; /* Ignored in GLX 1.3 */
1973 return win
; /* A hack for now */
1978 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1980 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
1982 XMesaDestroyBuffer(b
);
1983 /* don't destroy X window */
1989 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1990 const int *attribList
)
1992 XMesaVisual v
= (XMesaVisual
) config
;
1998 (void) attribList
; /* Ignored in GLX 1.3 */
2000 if (!dpy
|| !config
|| !pixmap
)
2003 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2013 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2015 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2017 XMesaDestroyBuffer(b
);
2018 /* don't destroy X pixmap */
2023 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2024 const int *attribList
)
2026 XMesaVisual xmvis
= (XMesaVisual
) config
;
2029 int width
= 0, height
= 0;
2030 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2034 for (attrib
= attribList
; *attrib
; attrib
++) {
2036 case GLX_PBUFFER_WIDTH
:
2040 case GLX_PBUFFER_HEIGHT
:
2044 case GLX_PRESERVED_CONTENTS
:
2046 preserveContents
= *attrib
; /* ignored */
2048 case GLX_LARGEST_PBUFFER
:
2050 useLargest
= *attrib
; /* ignored */
2057 /* not used at this time */
2059 (void) preserveContents
;
2061 if (width
== 0 || height
== 0)
2064 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2065 /* A GLXPbuffer handle must be an X Drawable because that's what
2066 * glXMakeCurrent takes.
2068 return (GLXPbuffer
) xmbuf
->frontbuffer
;
2073 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2075 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2077 XMesaDestroyBuffer(b
);
2083 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2084 unsigned int *value
)
2086 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2090 switch (attribute
) {
2092 *value
= xmbuf
->width
;
2095 *value
= xmbuf
->height
;
2097 case GLX_PRESERVED_CONTENTS
:
2100 case GLX_LARGEST_PBUFFER
:
2101 *value
= xmbuf
->width
* xmbuf
->height
;
2103 case GLX_FBCONFIG_ID
:
2104 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2107 return; /* GLX_BAD_ATTRIBUTE? */
2113 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2114 int renderType
, GLXContext shareList
, Bool direct
)
2116 struct fake_glx_context
*glxCtx
;
2117 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2118 XMesaVisual xmvis
= (XMesaVisual
) config
;
2120 if (!dpy
|| !config
||
2121 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2124 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2128 /* deallocate unused windows/buffers */
2129 XMesaGarbageCollect();
2131 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2132 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2133 if (!glxCtx
->xmesaContext
) {
2138 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2139 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2140 glxCtx
->glxContext
.currentDpy
= dpy
;
2141 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2143 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2145 return (GLXContext
) glxCtx
;
2150 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2152 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2153 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2158 switch (attribute
) {
2159 case GLX_FBCONFIG_ID
:
2160 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2162 case GLX_RENDER_TYPE
:
2163 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2164 *value
= GLX_RGBA_BIT
;
2166 *value
= GLX_COLOR_INDEX_BIT
;
2172 return GLX_BAD_ATTRIBUTE
;
2179 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2181 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2183 xmbuf
->selectedEvents
= mask
;
2188 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2189 unsigned long *mask
)
2191 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2193 *mask
= xmbuf
->selectedEvents
;
2200 /*** GLX_SGI_swap_control ***/
2203 Fake_glXSwapIntervalSGI(int interval
)
2211 /*** GLX_SGI_video_sync ***/
2214 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2221 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2231 /*** GLX_SGI_make_current_read ***/
2234 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2236 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2241 Fake_glXGetCurrentReadDrawableSGI(void)
2248 /*** GLX_SGIX_video_source ***/
2251 static GLXVideoSourceSGIX
2252 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2264 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2273 /*** GLX_EXT_import_context ***/
2276 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2283 Fake_glXGetContextIDEXT(const GLXContext context
)
2290 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2298 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2309 /*** GLX_SGIX_fbconfig ***/
2312 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2314 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2317 static GLXFBConfigSGIX
*
2318 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2320 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2325 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2327 XMesaVisual xmvis
= (XMesaVisual
) config
;
2328 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2329 return xmbuf
->frontbuffer
; /* need to return an X ID */
2334 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2336 XMesaVisual xmvis
= (XMesaVisual
) config
;
2337 struct fake_glx_context
*glxCtx
;
2338 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2340 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2344 /* deallocate unused windows/buffers */
2345 XMesaGarbageCollect();
2347 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2348 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2349 if (!glxCtx
->xmesaContext
) {
2354 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2355 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2356 glxCtx
->glxContext
.currentDpy
= dpy
;
2357 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2359 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2361 return (GLXContext
) glxCtx
;
2365 static XVisualInfo
*
2366 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2368 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2372 static GLXFBConfigSGIX
2373 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2375 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2377 /* This visual wasn't found with glXChooseVisual() */
2378 xmvis
= create_glx_visual(dpy
, vis
);
2381 return (GLXFBConfigSGIX
) xmvis
;
2386 /*** GLX_SGIX_pbuffer ***/
2388 static GLXPbufferSGIX
2389 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2390 unsigned int width
, unsigned int height
,
2393 XMesaVisual xmvis
= (XMesaVisual
) config
;
2396 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2400 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2402 case GLX_PRESERVED_CONTENTS_SGIX
:
2404 preserveContents
= *attrib
; /* ignored */
2406 case GLX_LARGEST_PBUFFER_SGIX
:
2408 useLargest
= *attrib
; /* ignored */
2415 /* not used at this time */
2417 (void) preserveContents
;
2419 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2420 /* A GLXPbuffer handle must be an X Drawable because that's what
2421 * glXMakeCurrent takes.
2423 return (GLXPbuffer
) xmbuf
->frontbuffer
;
2428 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2430 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2432 XMesaDestroyBuffer(xmbuf
);
2438 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2440 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2443 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2447 switch (attribute
) {
2448 case GLX_PRESERVED_CONTENTS_SGIX
:
2451 case GLX_LARGEST_PBUFFER_SGIX
:
2452 *value
= xmbuf
->width
* xmbuf
->height
;
2454 case GLX_WIDTH_SGIX
:
2455 *value
= xmbuf
->width
;
2457 case GLX_HEIGHT_SGIX
:
2458 *value
= xmbuf
->height
;
2460 case GLX_EVENT_MASK_SGIX
:
2461 *value
= 0; /* XXX might be wrong */
2471 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2473 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2475 /* Note: we'll never generate clobber events */
2476 xmbuf
->selectedEvents
= mask
;
2482 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2484 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2486 *mask
= xmbuf
->selectedEvents
;
2495 /*** GLX_SGI_cushion ***/
2498 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2507 /*** GLX_SGIX_video_resize ***/
2510 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2520 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2533 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2546 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2559 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2570 /*** GLX_SGIX_dmbuffer **/
2572 #if defined(_DM_BUFFER_H_)
2574 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2585 /*** GLX_SGIX_swap_group ***/
2588 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2597 /*** GLX_SGIX_swap_barrier ***/
2600 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2608 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2618 /*** GLX_SUN_get_transparent_index ***/
2621 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2626 (void) pTransparent
;
2632 /*** GLX_MESA_release_buffers ***/
2635 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2636 * (a window or pixmap) prior to destroying the GLXDrawable.
2639 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2641 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2643 XMesaDestroyBuffer(b
);
2651 /*** GLX_MESA_set_3dfx_mode ***/
2654 Fake_glXSet3DfxModeMESA( int mode
)
2656 return XMesaSetFXmode( mode
);
2661 /*** GLX_NV_vertex_array range ***/
2663 Fake_glXAllocateMemoryNV( GLsizei size
,
2664 GLfloat readFrequency
,
2665 GLfloat writeFrequency
,
2669 (void) readFrequency
;
2670 (void) writeFrequency
;
2677 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2683 /*** GLX_MESA_agp_offset ***/
2686 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
2693 /*** GLX_ARB_render_texture ***/
2696 Fake_glXBindTexImageARB( Display
*dpy
, GLXPbuffer pbuffer
, int buffer
)
2703 Fake_glXReleaseTexImageARB(Display
*dpy
, GLXPbuffer pbuffer
, int buffer
)
2710 Fake_glXDrawableAttribARB( Display
*dpy
, GLXDrawable draw
, const int *attribList
)
2717 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2718 struct _glxapi_table
*_mesa_GetGLXDispatchTable(void)
2720 static struct _glxapi_table glx
;
2722 /* be sure our dispatch table size <= libGL's table */
2724 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2726 assert(_glxapi_get_dispatch_table_size() >= size
);
2729 /* initialize the whole table to no-ops */
2730 _glxapi_set_no_op_table(&glx
);
2732 /* now initialize the table with the functions I implement */
2733 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2734 glx
.CopyContext
= Fake_glXCopyContext
;
2735 glx
.CreateContext
= Fake_glXCreateContext
;
2736 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2737 glx
.DestroyContext
= Fake_glXDestroyContext
;
2738 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2739 glx
.GetConfig
= Fake_glXGetConfig
;
2740 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2741 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2742 glx
.IsDirect
= Fake_glXIsDirect
;
2743 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2744 glx
.QueryExtension
= Fake_glXQueryExtension
;
2745 glx
.QueryVersion
= Fake_glXQueryVersion
;
2746 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2747 glx
.UseXFont
= Fake_glXUseXFont
;
2748 glx
.WaitGL
= Fake_glXWaitGL
;
2749 glx
.WaitX
= Fake_glXWaitX
;
2751 /*** GLX_VERSION_1_1 ***/
2752 glx
.GetClientString
= Fake_glXGetClientString
;
2753 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2754 glx
.QueryServerString
= Fake_glXQueryServerString
;
2756 /*** GLX_VERSION_1_2 ***/
2757 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2759 /*** GLX_VERSION_1_3 ***/
2760 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2761 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2762 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2763 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2764 glx
.CreateWindow
= Fake_glXCreateWindow
;
2765 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2766 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2767 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2768 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2769 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2770 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2771 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2772 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2773 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2774 glx
.QueryContext
= Fake_glXQueryContext
;
2775 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2776 glx
.SelectEvent
= Fake_glXSelectEvent
;
2778 /*** GLX_SGI_swap_control ***/
2779 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2781 /*** GLX_SGI_video_sync ***/
2782 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2783 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2785 /*** GLX_SGI_make_current_read ***/
2786 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2787 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2789 /*** GLX_SGIX_video_source ***/
2791 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2792 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2795 /*** GLX_EXT_import_context ***/
2796 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2797 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2798 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2799 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2800 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2802 /*** GLX_SGIX_fbconfig ***/
2803 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2804 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2805 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2806 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
2807 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
2808 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
2810 /*** GLX_SGIX_pbuffer ***/
2811 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
2812 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
2813 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
2814 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
2815 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
2817 /*** GLX_SGI_cushion ***/
2818 glx
.CushionSGI
= Fake_glXCushionSGI
;
2820 /*** GLX_SGIX_video_resize ***/
2821 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
2822 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
2823 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
2824 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
2825 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
2827 /*** GLX_SGIX_dmbuffer **/
2828 #if defined(_DM_BUFFER_H_)
2829 glx
.AssociateDMPbufferSGIX
= NULL
;
2832 /*** GLX_SGIX_swap_group ***/
2833 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
2835 /*** GLX_SGIX_swap_barrier ***/
2836 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
2837 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
2839 /*** GLX_SUN_get_transparent_index ***/
2840 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
2842 /*** GLX_MESA_copy_sub_buffer ***/
2843 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
2845 /*** GLX_MESA_release_buffers ***/
2846 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
2848 /*** GLX_MESA_pixmap_colormap ***/
2849 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
2851 /*** GLX_MESA_set_3dfx_mode ***/
2852 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
2854 /*** GLX_NV_vertex_array_range ***/
2855 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
2856 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
2858 /*** GLX_MESA_agp_offset ***/
2859 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
2861 /*** GLX_ARB_render_texture ***/
2862 glx
.BindTexImageARB
= Fake_glXBindTexImageARB
;
2863 glx
.ReleaseTexImageARB
= Fake_glXReleaseTexImageARB
;
2864 glx
.DrawableAttribARB
= Fake_glXDrawableAttribARB
;