1 /* $Id: fakeglx.c,v 1.48 2001/03/23 21:37:05 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
30 * to run on X servers which do not have the real GLX extension.
32 * Thanks to the contributors:
34 * Initial version: Philip Brown (phil@bolthole.com)
35 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
36 * Further visual-handling refinements: Wolfram Gloger
37 * (wmglo@Dent.MED.Uni-Muenchen.DE).
40 * Don't be fooled, stereo isn't supported yet.
45 #include "glxheader.h"
57 /* This indicates the client-side GLX API and GLX encoder version. */
58 #define CLIENT_MAJOR_VERSION 1
59 #define CLIENT_MINOR_VERSION 2
61 /* This indicates the server-side GLX decoder version.
62 * GLX 1.3 indicates OpenGL 1.2 support
64 #define SERVER_MAJOR_VERSION 1
65 #define SERVER_MINOR_VERSION 3
67 /* This is appended onto the glXGetClient/ServerString version strings. */
68 #define MESA_GLX_VERSION "Mesa 3.5"
70 /* Who implemented this GLX? */
71 #define VENDOR "Brian Paul"
75 /* Silence compiler warnings */
76 extern void Fake_glXDummyFunc( void );
77 void Fake_glXDummyFunc( void )
91 #define MAX_VISUALS 100
92 static XMesaVisual VisualTable
[MAX_VISUALS
];
93 static int NumVisuals
= 0;
98 * This struct and some code fragments borrowed
99 * from Mark Kilgard's GLUT library.
101 typedef struct _OverlayInfo
{
102 /* Avoid 64-bit portability problems by being careful to use
103 longs due to the way XGetWindowProperty is specified. Note
104 that these parameters are passed as CARD32s over X
106 unsigned long overlay_visual
;
107 long transparent_type
;
114 /* Macro to handle c_class vs class field name in XVisualInfo struct */
115 #if defined(__cplusplus) || defined(c_plusplus)
116 #define CLASS c_class
125 * Test if the given XVisualInfo is usable for Mesa rendering.
127 static GLboolean
is_usable_visual( XVisualInfo
*vinfo
)
129 switch (vinfo
->CLASS
) {
132 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
136 /* Any StaticColor/PseudoColor visual of at least 4 bits */
137 if (vinfo
->depth
>=4) {
145 /* Any depth of TrueColor or DirectColor works in RGB mode */
148 /* This should never happen */
156 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
157 * Input: dpy - the X display
158 * vinfo - the XVisualInfo to test
159 * Return: level of the visual:
161 * >0 = overlay planes
162 * <0 = underlay planes
164 static int level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
166 Atom overlayVisualsAtom
;
167 OverlayInfo
*overlay_info
= NULL
;
168 int numOverlaysPerScreen
;
172 unsigned long sizeData
, bytesLeft
;
176 * The SERVER_OVERLAY_VISUALS property on the root window contains
177 * a list of overlay visuals. Get that list now.
179 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
180 if (overlayVisualsAtom
== None
) {
184 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, vinfo
->screen
),
185 overlayVisualsAtom
, 0L, (long) 10000, False
,
186 overlayVisualsAtom
, &actualType
, &actualFormat
,
187 &sizeData
, &bytesLeft
,
188 (unsigned char **) &overlay_info
);
190 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
191 actualFormat
!= 32 || sizeData
< 4) {
192 /* something went wrong */
193 XFree((void *) overlay_info
);
197 /* search the overlay visual list for the visual ID of interest */
198 numOverlaysPerScreen
= (int) (sizeData
/ 4);
199 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
201 ov
= overlay_info
+ i
;
202 if (ov
->overlay_visual
==vinfo
->visualid
) {
203 /* found the visual */
204 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
205 int level
= ov
->layer
;
206 XFree((void *) overlay_info
);
210 XFree((void *) overlay_info
);
216 /* The visual ID was not found in the overlay list. */
217 XFree((void *) overlay_info
);
225 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
226 * configuration in our list of GLX visuals.
229 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
230 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
231 GLboolean stereoFlag
,
232 GLint depth_size
, GLint stencil_size
,
233 GLint accumRedSize
, GLint accumGreenSize
,
234 GLint accumBlueSize
, GLint accumAlphaSize
,
237 GLboolean ximageFlag
= GL_TRUE
;
240 GLboolean comparePointers
;
243 /* Check if the MESA_BACK_BUFFER env var is set */
244 char *backbuffer
= getenv("MESA_BACK_BUFFER");
246 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
247 ximageFlag
= GL_FALSE
;
249 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
250 ximageFlag
= GL_TRUE
;
253 fprintf(stderr
, "Mesa: invalid value for MESA_BACK_BUFFER ");
254 fprintf(stderr
, "environment variable, using an XImage.\n");
259 /* Comparing IDs uses less memory but sometimes fails. */
260 /* XXX revisit this after 3.0 is finished. */
261 if (getenv("MESA_GLX_VISUAL_HACK"))
262 comparePointers
= GL_TRUE
;
264 comparePointers
= GL_FALSE
;
266 /* First check if a matching visual is already in the list */
267 for (i
=0; i
<NumVisuals
; i
++) {
268 XMesaVisual v
= VisualTable
[i
];
269 if (v
->display
== dpy
271 && v
->ximage_flag
== ximageFlag
272 && v
->gl_visual
->rgbMode
== rgbFlag
273 && v
->gl_visual
->doubleBufferMode
== dbFlag
274 && v
->gl_visual
->stereoMode
== stereoFlag
275 && (v
->gl_visual
->alphaBits
> 0) == alphaFlag
276 && (v
->gl_visual
->depthBits
>= depth_size
|| depth_size
== 0)
277 && (v
->gl_visual
->stencilBits
>= stencil_size
|| stencil_size
== 0)
278 && (v
->gl_visual
->accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
279 && (v
->gl_visual
->accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
280 && (v
->gl_visual
->accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
281 && (v
->gl_visual
->accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
282 /* now either compare XVisualInfo pointers or visual IDs */
283 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
284 || (comparePointers
&& v
->vishandle
== vinfo
)) {
290 /* Create a new visual and add it to the list. */
292 if (NumVisuals
>=MAX_VISUALS
) {
293 fprintf( stderr
, "GLX Error: maximum number of visuals exceeded\n");
297 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
298 stereoFlag
, ximageFlag
,
299 depth_size
, stencil_size
,
300 accumRedSize
, accumBlueSize
,
301 accumBlueSize
, accumAlphaSize
, 0, level
,
304 VisualTable
[NumVisuals
] = xmvis
;
313 * Create a GLX visual from a regular XVisualInfo.
314 * This is called when Fake GLX is given an XVisualInfo which wasn't
315 * returned by glXChooseVisual. Since this is the first time we're
316 * considering this visual we'll take a guess at reasonable values
317 * for depth buffer size, stencil size, accum size, etc.
318 * This is the best we can do with a client-side emulation of GLX.
321 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
325 vislevel
= level_of_visual( dpy
, visinfo
);
327 /* Configure this visual as a CI, single-buffered overlay */
328 return save_glx_visual( dpy
, visinfo
,
330 GL_FALSE
, /* alpha */
331 GL_FALSE
, /* double */
332 GL_FALSE
, /* stereo */
334 0, /* stencil bits */
335 0,0,0,0, /* accum bits */
339 else if (is_usable_visual( visinfo
)) {
340 if (getenv("MESA_GLX_FORCE_CI")) {
341 /* Configure this visual as a COLOR INDEX visual. */
342 return save_glx_visual( dpy
, visinfo
,
344 GL_FALSE
, /* alpha */
345 GL_TRUE
, /* double */
346 GL_FALSE
, /* stereo */
347 DEFAULT_SOFTWARE_DEPTH_BITS
,
348 8 * sizeof(GLstencil
),
349 0 * sizeof(GLaccum
), /* r */
350 0 * sizeof(GLaccum
), /* g */
351 0 * sizeof(GLaccum
), /* b */
352 0 * sizeof(GLaccum
), /* a */
357 /* Configure this visual as RGB, double-buffered, depth-buffered. */
358 /* This is surely wrong for some people's needs but what else */
359 /* can be done? They should use glXChooseVisual(). */
360 return save_glx_visual( dpy
, visinfo
,
362 GL_FALSE
, /* alpha */
363 GL_TRUE
, /* double */
364 GL_FALSE
, /* stereo */
365 DEFAULT_SOFTWARE_DEPTH_BITS
,
366 8 * sizeof(GLstencil
),
367 8 * sizeof(GLaccum
), /* r */
368 8 * sizeof(GLaccum
), /* g */
369 8 * sizeof(GLaccum
), /* b */
370 8 * sizeof(GLaccum
), /* a */
376 fprintf(stderr
,"Mesa: error in glXCreateContext: bad visual\n");
384 * Find the GLX visual associated with an XVisualInfo.
387 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
391 /* First try to match pointers */
392 for (i
=0;i
<NumVisuals
;i
++) {
393 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
394 return VisualTable
[i
];
397 /* try to match visual id */
398 for (i
=0;i
<NumVisuals
;i
++) {
399 if (VisualTable
[i
]->display
==dpy
400 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
401 return VisualTable
[i
];
410 * Return the transparent pixel value for a GLX visual.
411 * Input: glxvis - the glx_visual
412 * Return: a pixel value or -1 if no transparent pixel
414 static int transparent_pixel( XMesaVisual glxvis
)
416 Display
*dpy
= glxvis
->display
;
417 XVisualInfo
*vinfo
= glxvis
->visinfo
;
418 Atom overlayVisualsAtom
;
419 OverlayInfo
*overlay_info
= NULL
;
420 int numOverlaysPerScreen
;
424 unsigned long sizeData
, bytesLeft
;
428 * The SERVER_OVERLAY_VISUALS property on the root window contains
429 * a list of overlay visuals. Get that list now.
431 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
432 if (overlayVisualsAtom
== None
) {
436 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, vinfo
->screen
),
437 overlayVisualsAtom
, 0L, (long) 10000, False
,
438 overlayVisualsAtom
, &actualType
, &actualFormat
,
439 &sizeData
, &bytesLeft
,
440 (unsigned char **) &overlay_info
);
442 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
443 actualFormat
!= 32 || sizeData
< 4) {
444 /* something went wrong */
445 XFree((void *) overlay_info
);
449 /* search the overlay visual list for the visual ID of interest */
450 numOverlaysPerScreen
= (int) (sizeData
/ 4);
451 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
453 ov
= overlay_info
+ i
;
454 if (ov
->overlay_visual
==vinfo
->visualid
) {
456 if (ov
->transparent_type
==0) {
457 /* type 0 indicates no transparency */
458 XFree((void *) overlay_info
);
462 /* ov->value is the transparent pixel */
463 XFree((void *) overlay_info
);
469 /* The visual ID was not found in the overlay list. */
470 XFree((void *) overlay_info
);
477 * Try to get an X visual which matches the given arguments.
479 static XVisualInfo
*get_visual( Display
*dpy
, int scr
,
480 unsigned int depth
, int xclass
)
482 XVisualInfo temp
, *vis
;
485 unsigned int default_depth
;
488 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
493 default_depth
= DefaultDepth(dpy
,scr
);
494 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
496 if (depth
==default_depth
&& xclass
==default_class
) {
497 /* try to get root window's visual */
498 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
499 mask
|= VisualIDMask
;
502 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
504 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
505 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
506 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
508 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
509 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
510 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
511 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
526 * Retrieve the value of the given environment variable and find
527 * the X visual which matches it.
528 * Input: dpy - the display
529 * screen - the screen number
530 * varname - the name of the environment variable
531 * Return: an XVisualInfo pointer to NULL if error.
533 static XVisualInfo
*get_env_visual(Display
*dpy
, int scr
, const char *varname
)
535 char value
[100], type
[100];
536 int depth
, xclass
= -1;
539 if (!getenv( varname
)) {
543 strncpy( value
, getenv(varname
), 100 );
546 sscanf( value
, "%s %d", type
, &depth
);
548 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
549 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
550 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
551 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
552 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
553 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
555 if (xclass
>-1 && depth
>0) {
556 vis
= get_visual( dpy
, scr
, depth
, xclass
);
562 fprintf( stderr
, "Mesa: GLX unable to find visual class=%s, depth=%d.\n",
570 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
571 * Input: dpy, screen - X display and screen number
572 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
573 * min_depth - minimum visual depth
574 * preferred_class - preferred GLX visual class or DONT_CARE
575 * Return: pointer to an XVisualInfo or NULL.
577 static XVisualInfo
*choose_x_visual( Display
*dpy
, int screen
,
578 GLboolean rgba
, int min_depth
,
579 int preferred_class
)
582 int xclass
, visclass
= 0;
586 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
587 /* First see if the MESA_RGB_VISUAL env var is defined */
588 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
592 /* Otherwise, search for a suitable visual */
593 if (preferred_class
==DONT_CARE
) {
594 for (xclass
=0;xclass
<6;xclass
++) {
596 case 0: visclass
= TrueColor
; break;
597 case 1: visclass
= DirectColor
; break;
598 case 2: visclass
= PseudoColor
; break;
599 case 3: visclass
= StaticColor
; break;
600 case 4: visclass
= GrayScale
; break;
601 case 5: visclass
= StaticGray
; break;
604 /* start with shallowest */
605 for (depth
=0;depth
<=32;depth
++) {
606 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
607 /* Special case: try to get 8-bit PseudoColor before */
608 /* 8-bit TrueColor */
609 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
614 vis
= get_visual( dpy
, screen
, depth
, visclass
);
621 /* start with deepest */
622 for (depth
=32;depth
>=min_depth
;depth
--) {
623 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
624 /* Special case: try to get 8-bit PseudoColor before */
625 /* 8-bit TrueColor */
626 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
631 vis
= get_visual( dpy
, screen
, depth
, visclass
);
640 /* search for a specific visual class */
641 switch (preferred_class
) {
642 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
643 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
644 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
645 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
646 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
647 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
648 default: return NULL
;
651 /* start with shallowest */
652 for (depth
=0;depth
<=32;depth
++) {
653 vis
= get_visual( dpy
, screen
, depth
, visclass
);
660 /* start with deepest */
661 for (depth
=32;depth
>=min_depth
;depth
--) {
662 vis
= get_visual( dpy
, screen
, depth
, visclass
);
671 /* First see if the MESA_CI_VISUAL env var is defined */
672 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
676 /* Otherwise, search for a suitable visual, starting with shallowest */
677 if (preferred_class
==DONT_CARE
) {
678 for (xclass
=0;xclass
<4;xclass
++) {
680 case 0: visclass
= PseudoColor
; break;
681 case 1: visclass
= StaticColor
; break;
682 case 2: visclass
= GrayScale
; break;
683 case 3: visclass
= StaticGray
; break;
685 /* try 8-bit up through 16-bit */
686 for (depth
=8;depth
<=16;depth
++) {
687 vis
= get_visual( dpy
, screen
, depth
, visclass
);
692 /* try min_depth up to 8-bit */
693 for (depth
=min_depth
;depth
<8;depth
++) {
694 vis
= get_visual( dpy
, screen
, depth
, visclass
);
702 /* search for a specific visual class */
703 switch (preferred_class
) {
704 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
705 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
706 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
707 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
708 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
709 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
710 default: return NULL
;
712 /* try 8-bit up through 16-bit */
713 for (depth
=8;depth
<=16;depth
++) {
714 vis
= get_visual( dpy
, screen
, depth
, visclass
);
719 /* try min_depth up to 8-bit */
720 for (depth
=min_depth
;depth
<8;depth
++) {
721 vis
= get_visual( dpy
, screen
, depth
, visclass
);
729 /* didn't find a visual */
736 * Find the deepest X over/underlay visual of at least min_depth.
737 * Input: dpy, screen - X display and screen number
738 * level - the over/underlay level
739 * trans_type - transparent pixel type: GLX_NONE_EXT,
740 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
742 * trans_value - transparent pixel value or DONT_CARE
743 * min_depth - minimum visual depth
744 * preferred_class - preferred GLX visual class or DONT_CARE
745 * Return: pointer to an XVisualInfo or NULL.
747 static XVisualInfo
*choose_x_overlay_visual( Display
*dpy
, int scr
,
749 int level
, int trans_type
,
752 int preferred_class
)
754 Atom overlayVisualsAtom
;
755 OverlayInfo
*overlay_info
;
756 int numOverlaysPerScreen
;
760 unsigned long sizeData
, bytesLeft
;
762 XVisualInfo
*deepvis
;
765 /*DEBUG int tt, tv; */
767 switch (preferred_class
) {
768 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
769 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
770 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
771 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
772 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
773 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
774 default: preferred_class
= DONT_CARE
;
778 * The SERVER_OVERLAY_VISUALS property on the root window contains
779 * a list of overlay visuals. Get that list now.
781 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
782 if (overlayVisualsAtom
== (Atom
) None
) {
786 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, scr
),
787 overlayVisualsAtom
, 0L, (long) 10000, False
,
788 overlayVisualsAtom
, &actualType
, &actualFormat
,
789 &sizeData
, &bytesLeft
,
790 (unsigned char **) &overlay_info
);
792 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
793 actualFormat
!= 32 || sizeData
< 4) {
794 /* something went wrong */
798 /* Search for the deepest overlay which satisifies all criteria. */
802 numOverlaysPerScreen
= (int) (sizeData
/ 4);
803 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
804 XVisualInfo
*vislist
, vistemplate
;
807 ov
= overlay_info
+ i
;
809 if (ov
->layer
!=level
) {
810 /* failed overlay level criteria */
813 if (!(trans_type
==DONT_CARE
814 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
815 && ov
->transparent_type
>0)
816 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
817 /* failed transparent pixel type criteria */
820 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
821 /* failed transparent pixel value criteria */
825 /* get XVisualInfo and check the depth */
826 vistemplate
.visualid
= ov
->overlay_visual
;
827 vistemplate
.screen
= scr
;
828 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
829 &vistemplate
, &count
);
832 /* something went wrong */
835 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
836 /* wrong visual class */
840 /* if RGB was requested, make sure we have True/DirectColor */
841 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
842 && vislist
->CLASS
!= DirectColor
)
845 /* if CI was requested, make sure we have a color indexed visual */
847 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
850 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
851 /* YES! found a satisfactory visual */
855 deepest
= vislist
->depth
;
857 /* DEBUG tt = ov->transparent_type;*/
858 /* DEBUG tv = ov->value; */
864 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
865 deepvis->visualid, level, deepvis->depth, tt, tv );
874 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
879 int min_red
=0, min_green
=0, min_blue
=0;
880 GLboolean rgb_flag
= GL_FALSE
;
881 GLboolean alpha_flag
= GL_FALSE
;
882 GLboolean double_flag
= GL_FALSE
;
883 GLboolean stereo_flag
= GL_FALSE
;
884 GLint depth_size
= 0;
885 GLint stencil_size
= 0;
886 GLint accumRedSize
= 0;
887 GLint accumGreenSize
= 0;
888 GLint accumBlueSize
= 0;
889 GLint accumAlphaSize
= 0;
891 int visual_type
= DONT_CARE
;
892 int trans_type
= DONT_CARE
;
893 int trans_value
= DONT_CARE
;
894 GLint caveat
= DONT_CARE
;
900 switch (*parselist
) {
905 case GLX_BUFFER_SIZE
:
907 min_ci
= *parselist
++;
911 level
= *parselist
++;
917 case GLX_DOUBLEBUFFER
:
918 double_flag
= GL_TRUE
;
922 stereo_flag
= GL_TRUE
;
924 case GLX_AUX_BUFFERS
:
931 min_red
= *parselist
++;
935 min_green
= *parselist
++;
939 min_blue
= *parselist
++;
944 GLint size
= *parselist
++;
945 alpha_flag
= size
>0 ? 1 : 0;
950 depth_size
= *parselist
++;
952 case GLX_STENCIL_SIZE
:
954 stencil_size
= *parselist
++;
956 case GLX_ACCUM_RED_SIZE
:
959 GLint size
= *parselist
++;
960 accumRedSize
= MAX2( accumRedSize
, size
);
963 case GLX_ACCUM_GREEN_SIZE
:
966 GLint size
= *parselist
++;
967 accumGreenSize
= MAX2( accumGreenSize
, size
);
970 case GLX_ACCUM_BLUE_SIZE
:
973 GLint size
= *parselist
++;
974 accumBlueSize
= MAX2( accumBlueSize
, size
);
977 case GLX_ACCUM_ALPHA_SIZE
:
980 GLint size
= *parselist
++;
981 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
986 * GLX_EXT_visual_info extension
988 case GLX_X_VISUAL_TYPE_EXT
:
990 visual_type
= *parselist
++;
992 case GLX_TRANSPARENT_TYPE_EXT
:
994 trans_type
= *parselist
++;
996 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
998 trans_value
= *parselist
++;
1000 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1001 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1002 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1003 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1010 * GLX_EXT_visual_info extension
1012 case GLX_VISUAL_CAVEAT_EXT
:
1014 caveat
= *parselist
++; /* ignored for now */
1020 /* undefined attribute */
1026 * Since we're only simulating the GLX extension this function will never
1027 * find any real GL visuals. Instead, all we can do is try to find an RGB
1028 * or CI visual of appropriate depth. Other requested attributes such as
1029 * double buffering, depth buffer, etc. will be associated with the X
1030 * visual and stored in the VisualTable[].
1033 /* normal color planes */
1035 /* Get an RGB visual */
1036 int min_rgb
= min_red
+ min_green
+ min_blue
;
1037 if (min_rgb
>1 && min_rgb
<8) {
1038 /* a special case to be sure we can get a monochrome visual */
1041 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1044 /* Get a color index visual */
1045 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1046 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1050 /* over/underlay planes */
1053 int min_rgb
= min_red
+ min_green
+ min_blue
;
1054 if (min_rgb
>1 && min_rgb
<8) {
1055 /* a special case to be sure we can get a monochrome visual */
1058 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1059 trans_type
, trans_value
, min_rgb
, visual_type
);
1062 /* color index overlay */
1063 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1064 trans_type
, trans_value
, min_ci
, visual_type
);
1069 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1070 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1071 * largest depth buffer size, which is 32bits/value. Instead, we
1072 * return 16 to maintain performance with earlier versions of Mesa.
1074 if (depth_size
> 24)
1075 depth_size
= 31; /* 32 causes int overflow problems */
1076 else if (depth_size
> 16)
1078 else if (depth_size
> 0)
1079 depth_size
= DEFAULT_SOFTWARE_DEPTH_BITS
; /*16*/
1081 /* we only support one size of stencil and accum buffers. */
1082 if (stencil_size
> 0)
1083 stencil_size
= STENCIL_BITS
;
1084 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1085 accumAlphaSize
> 0) {
1086 accumRedSize
= ACCUM_BITS
;
1087 accumGreenSize
= ACCUM_BITS
;
1088 accumBlueSize
= ACCUM_BITS
;
1089 accumAlphaSize
= alpha_flag
? ACCUM_BITS
: 0;
1092 if (!save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1093 stereo_flag
, depth_size
, stencil_size
,
1094 accumRedSize
, accumGreenSize
,
1095 accumBlueSize
, accumAlphaSize
,
1107 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1108 GLXContext share_list
, Bool direct
)
1113 /* deallocate unused windows/buffers */
1114 XMesaGarbageCollect();
1116 glxvis
= find_glx_visual( dpy
, visinfo
);
1118 /* This visual wasn't found with glXChooseVisual() */
1119 glxvis
= create_glx_visual( dpy
, visinfo
);
1121 /* unusable visual */
1126 xmctx
= XMesaCreateContext( glxvis
, (XMesaContext
) share_list
);
1128 /* set the direct/indirect flag */
1129 xmctx
->direct
= direct
;
1131 return (GLXContext
) xmctx
;
1135 static GLXContext MakeCurrent_PrevContext
= 0;
1136 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1137 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1138 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1139 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1141 /* GLX 1.3 and later */
1143 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1144 GLXDrawable read
, GLXContext ctx
)
1146 if (ctx
&& draw
&& read
) {
1147 XMesaBuffer drawBuffer
, readBuffer
;
1148 XMesaContext xmctx
= (XMesaContext
) ctx
;
1150 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1151 if (ctx
== MakeCurrent_PrevContext
1152 && draw
== MakeCurrent_PrevDrawable
) {
1153 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1156 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1159 /* drawable must be a new window! */
1160 drawBuffer
= XMesaCreateWindowBuffer2( xmctx
->xm_visual
, draw
, (XMesaContext
) ctx
);
1162 /* Out of memory, or context/drawable depth mismatch */
1167 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1168 if (ctx
== MakeCurrent_PrevContext
1169 && read
== MakeCurrent_PrevReadable
) {
1170 readBuffer
= MakeCurrent_PrevReadBuffer
;
1173 readBuffer
= XMesaFindBuffer( dpy
, read
);
1176 /* drawable must be a new window! */
1177 readBuffer
= XMesaCreateWindowBuffer2( xmctx
->xm_visual
, read
, (XMesaContext
) ctx
);
1179 /* Out of memory, or context/drawable depth mismatch */
1184 MakeCurrent_PrevContext
= ctx
;
1185 MakeCurrent_PrevDrawable
= draw
;
1186 MakeCurrent_PrevReadable
= read
;
1187 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1188 MakeCurrent_PrevReadBuffer
= readBuffer
;
1190 /* Now make current! */
1191 return (Bool
) XMesaMakeCurrent2((XMesaContext
) ctx
, drawBuffer
, readBuffer
);
1193 else if (!ctx
&& !draw
&& !read
) {
1194 /* release current context w/out assigning new one. */
1195 XMesaMakeCurrent( NULL
, NULL
);
1196 MakeCurrent_PrevContext
= 0;
1197 MakeCurrent_PrevDrawable
= 0;
1198 MakeCurrent_PrevReadable
= 0;
1199 MakeCurrent_PrevDrawBuffer
= 0;
1200 MakeCurrent_PrevReadBuffer
= 0;
1204 /* The args must either all be non-zero or all zero.
1214 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1216 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1222 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1227 v
= find_glx_visual( dpy
, visinfo
);
1229 v
= create_glx_visual( dpy
, visinfo
);
1231 /* unusable visual */
1236 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1240 return b
->frontbuffer
;
1244 #ifdef GLX_MESA_pixmap_colormap
1246 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1247 Pixmap pixmap
, Colormap cmap
)
1252 v
= find_glx_visual( dpy
, visinfo
);
1254 v
= create_glx_visual( dpy
, visinfo
);
1256 /* unusable visual */
1261 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1265 return b
->frontbuffer
;
1271 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1273 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1275 XMesaDestroyBuffer(b
);
1277 else if (getenv("MESA_DEBUG")) {
1278 fprintf( stderr
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1285 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1286 unsigned long mask
)
1288 XMesaContext xm_src
= (XMesaContext
) src
;
1289 XMesaContext xm_dst
= (XMesaContext
) dst
;
1291 _mesa_copy_context( xm_src
->gl_ctx
, xm_dst
->gl_ctx
, (GLuint
) mask
);
1297 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1299 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1307 extern void _kw_ungrab_all( Display
*dpy
);
1308 void _kw_ungrab_all( Display
*dpy
)
1310 XUngrabPointer( dpy
, CurrentTime
);
1311 XUngrabKeyboard( dpy
, CurrentTime
);
1316 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1319 MakeCurrent_PrevContext
= 0;
1320 MakeCurrent_PrevDrawable
= 0;
1321 MakeCurrent_PrevReadable
= 0;
1322 MakeCurrent_PrevDrawBuffer
= 0;
1323 MakeCurrent_PrevReadBuffer
= 0;
1324 XMesaDestroyContext( (XMesaContext
) ctx
);
1325 XMesaGarbageCollect();
1331 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1334 return ((XMesaContext
) ctx
)->direct
;
1340 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1342 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1345 XMesaSwapBuffers(buffer
);
1347 else if (getenv("MESA_DEBUG")) {
1348 fprintf(stderr
, "Mesa Warning: glXSwapBuffers: invalid drawable\n");
1354 #ifdef GLX_MESA_copy_sub_buffer
1356 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1357 int x
, int y
, int width
, int height
)
1359 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1361 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1363 else if (getenv("MESA_DEBUG")) {
1364 fprintf(stderr
, "Mesa Warning: glXCopySubBufferMESA: invalid drawable\n");
1372 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1375 /* Return GLX version, not Mesa version */
1376 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1377 *maj
= CLIENT_MAJOR_VERSION
;
1378 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1385 * Query the GLX attributes of the given XVisualInfo.
1388 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1389 int attrib
, int *value
)
1393 glxvis
= find_glx_visual( dpy
, visinfo
);
1395 /* this visual wasn't obtained with glXChooseVisual */
1396 glxvis
= create_glx_visual( dpy
, visinfo
);
1398 /* this visual can't be used for GL rendering */
1399 if (attrib
==GLX_USE_GL
) {
1400 *value
= (int) False
;
1404 /*fprintf( stderr, "Mesa: Error in glXGetConfig: bad visual\n");*/
1405 return GLX_BAD_VISUAL
;
1412 *value
= (int) True
;
1414 case GLX_BUFFER_SIZE
:
1415 *value
= visinfo
->depth
;
1418 *value
= glxvis
->level
;
1421 if (glxvis
->gl_visual
->rgbMode
) {
1428 case GLX_DOUBLEBUFFER
:
1429 *value
= (int) glxvis
->gl_visual
->doubleBufferMode
;
1432 *value
= (int) glxvis
->gl_visual
->stereoMode
;
1434 case GLX_AUX_BUFFERS
:
1435 *value
= (int) False
;
1438 *value
= glxvis
->gl_visual
->redBits
;
1440 case GLX_GREEN_SIZE
:
1441 *value
= glxvis
->gl_visual
->greenBits
;
1444 *value
= glxvis
->gl_visual
->blueBits
;
1446 case GLX_ALPHA_SIZE
:
1447 *value
= glxvis
->gl_visual
->alphaBits
;
1449 case GLX_DEPTH_SIZE
:
1450 *value
= glxvis
->gl_visual
->depthBits
;
1452 case GLX_STENCIL_SIZE
:
1453 *value
= glxvis
->gl_visual
->stencilBits
;
1455 case GLX_ACCUM_RED_SIZE
:
1456 *value
= glxvis
->gl_visual
->accumRedBits
;
1458 case GLX_ACCUM_GREEN_SIZE
:
1459 *value
= glxvis
->gl_visual
->accumGreenBits
;
1461 case GLX_ACCUM_BLUE_SIZE
:
1462 *value
= glxvis
->gl_visual
->accumBlueBits
;
1464 case GLX_ACCUM_ALPHA_SIZE
:
1465 *value
= glxvis
->gl_visual
->accumAlphaBits
;
1469 * GLX_EXT_visual_info extension
1471 case GLX_X_VISUAL_TYPE_EXT
:
1472 switch (glxvis
->visinfo
->CLASS
) {
1473 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1474 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1475 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1476 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1477 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1478 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1481 case GLX_TRANSPARENT_TYPE_EXT
:
1482 if (glxvis
->level
==0) {
1484 *value
= GLX_NONE_EXT
;
1486 else if (glxvis
->level
>0) {
1488 if (glxvis
->gl_visual
->rgbMode
) {
1489 *value
= GLX_TRANSPARENT_RGB_EXT
;
1492 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1495 else if (glxvis
->level
<0) {
1497 *value
= GLX_NONE_EXT
;
1500 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1502 int pixel
= transparent_pixel( glxvis
);
1506 /* else undefined */
1509 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1512 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1515 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1518 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1523 * GLX_EXT_visual_info extension
1525 case GLX_VISUAL_CAVEAT_EXT
:
1526 /* test for zero, just in case */
1527 if (glxvis
->VisualCaveat
> 0)
1528 *value
= glxvis
->VisualCaveat
;
1530 *value
= GLX_NONE_EXT
;
1537 return GLX_BAD_ATTRIBUTE
;
1544 Fake_glXWaitGL( void )
1546 XMesaContext xmesa
= XMesaGetCurrentContext();
1547 XMesaFlush( xmesa
);
1553 Fake_glXWaitX( void )
1555 XMesaContext xmesa
= XMesaGetCurrentContext();
1556 XMesaFlush( xmesa
);
1561 * Return the extensions string, which is 3Dfx-dependant.
1563 static const char *get_extensions( void )
1566 const char *fx
= getenv("MESA_GLX_FX");
1567 if (fx
&& fx
[0] != 'd') {
1568 return "GLX_MESA_pixmap_colormap GLX_EXT_visual_info GLX_EXT_visual_rating GLX_MESA_release_buffers GLX_MESA_copy_sub_buffer GLX_SGI_video_sync GLX_MESA_set_3dfx_mode GLX_ARB_get_proc_address";
1571 return "GLX_MESA_pixmap_colormap GLX_EXT_visual_info GLX_EXT_visual_rating GLX_MESA_release_buffers GLX_MESA_copy_sub_buffer GLX_SGI_video_sync GLX_ARB_get_proc_address";
1576 /* GLX 1.1 and later */
1578 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1582 return get_extensions();
1587 /* GLX 1.1 and later */
1589 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1591 static char version
[1000];
1592 sprintf(version
, "%d.%d %s", SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
,
1599 case GLX_EXTENSIONS
:
1600 return get_extensions();
1612 /* GLX 1.1 and later */
1614 Fake_glXGetClientString( Display
*dpy
, int name
)
1616 static char version
[1000];
1617 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
, CLIENT_MINOR_VERSION
,
1623 case GLX_EXTENSIONS
:
1624 return get_extensions();
1640 static GLXFBConfig
*
1641 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1642 const int *attribList
, int *nitems
)
1653 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1654 int attribute
, int *value
)
1664 static GLXFBConfig
*
1665 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1674 static XVisualInfo
*
1675 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1684 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1685 const int *attribList
)
1696 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1705 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1706 const int *attribList
)
1717 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1726 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
1727 const int *attribList
)
1737 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
1745 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
1746 unsigned int *value
)
1756 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
1757 int renderType
, GLXContext shareList
, Bool direct
)
1769 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1780 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
1789 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
1790 unsigned long *mask
)
1799 #ifdef GLX_SGI_swap_control
1802 Fake_glXSwapIntervalSGI(int interval
)
1811 #ifdef GLX_SGI_video_sync
1814 Fake_glXGetVideoSyncSGI(unsigned int *count
)
1821 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1832 #ifdef GLX_SGI_make_current_read
1835 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
1845 Fake_glXGetCurrentReadDrawableSGI(void)
1853 #if defined(_VL_H) && defined(GLX_SGIX_video_source)
1855 static GLXVideoSourceSGIX
1856 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
1868 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
1877 #ifdef GLX_EXT_import_context
1880 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
1887 Fake_glXGetContextIDEXT(const GLXContext context
)
1894 Fake_glXGetCurrentDisplayEXT(void)
1896 return glXGetCurrentDisplay();
1900 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1908 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
1920 #ifdef GLX_SGIX_fbconfig
1923 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
1932 static GLXFBConfigSGIX
*
1933 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
1943 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
1952 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
1962 static XVisualInfo
*
1963 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
1970 static GLXFBConfigSGIX
1971 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
1981 #ifdef GLX_SGIX_pbuffer
1983 static GLXPbufferSGIX
1984 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
, unsigned int width
, unsigned int height
, int *attrib_list
)
1995 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2002 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2012 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2020 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2030 #ifdef GLX_SGI_cushion
2033 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2043 #ifdef GLX_SGIX_video_resize
2046 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2056 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2069 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2082 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2095 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2107 #if defined(_DM_BUFFER_H_) && defined(GLX_SGIX_dmbuffer)
2110 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2122 #ifdef GLX_SGIX_swap_group
2125 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2135 #ifdef GLX_SGIX_swap_barrier
2138 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2146 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2157 #ifdef GLX_SUN_get_transparent_index
2160 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2165 (void) pTransparent
;
2172 #ifdef GLX_MESA_release_buffers
2174 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2175 * (a window or pixmap) prior to destroying the GLXDrawable.
2178 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2180 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2182 XMesaDestroyBuffer(b
);
2191 #ifdef GLX_MESA_set_3dfx_mode
2193 Fake_glXSet3DfxModeMESA( int mode
)
2195 return XMesaSetFXmode( mode
);
2202 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2203 struct _glxapi_table
*_mesa_GetGLXDispatchTable(void)
2205 static struct _glxapi_table glx
;
2207 /* be sure our dispatch table size <= libGL's table */
2209 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2211 assert(_glxapi_get_dispatch_table_size() >= size
);
2214 /* initialize the whole table to no-ops */
2215 _glxapi_set_no_op_table(&glx
);
2217 /* now initialize the table with the functions I implement */
2218 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2219 glx
.CopyContext
= Fake_glXCopyContext
;
2220 glx
.CreateContext
= Fake_glXCreateContext
;
2221 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2222 glx
.DestroyContext
= Fake_glXDestroyContext
;
2223 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2224 glx
.GetConfig
= Fake_glXGetConfig
;
2225 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2226 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2227 glx
.IsDirect
= Fake_glXIsDirect
;
2228 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2229 glx
.QueryExtension
= Fake_glXQueryExtension
;
2230 glx
.QueryVersion
= Fake_glXQueryVersion
;
2231 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2232 glx
.UseXFont
= Fake_glXUseXFont
;
2233 glx
.WaitGL
= Fake_glXWaitGL
;
2234 glx
.WaitX
= Fake_glXWaitX
;
2236 #ifdef GLX_VERSION_1_1
2237 glx
.GetClientString
= Fake_glXGetClientString
;
2238 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2239 glx
.QueryServerString
= Fake_glXQueryServerString
;
2242 #ifdef GLX_VERSION_1_2
2243 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2246 #ifdef GLX_VERSION_1_3
2247 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2248 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2249 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2250 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2251 glx
.CreateWindow
= Fake_glXCreateWindow
;
2252 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2253 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2254 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2255 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2256 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2257 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2258 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2259 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2260 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2261 glx
.QueryContext
= Fake_glXQueryContext
;
2262 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2263 glx
.SelectEvent
= Fake_glXSelectEvent
;
2266 #ifdef GLX_SGI_swap_control
2267 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2270 #ifdef GLX_SGI_video_sync
2271 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2272 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2275 #ifdef GLX_SGI_make_current_read
2276 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2277 glx
.GetCurrentReadDrawableSGI
= Fake_glXGetCurrentReadDrawableSGI
;
2280 #if defined(_VL_H) && defined(GLX_SGIX_video_source)
2281 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2282 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2285 #ifdef GLX_EXT_import_context
2286 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2287 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2288 glx
.GetCurrentDisplayEXT
= Fake_glXGetCurrentDisplayEXT
;
2289 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2290 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2293 #ifdef GLX_SGIX_fbconfig
2294 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2295 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2296 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2297 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
2298 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
2299 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
2302 #ifdef GLX_SGIX_pbuffer
2303 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
2304 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
2305 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
2306 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
2307 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
2310 #ifdef GLX_SGI_cushion
2311 glx
.CushionSGI
= Fake_glXCushionSGI
;
2314 #ifdef GLX_SGIX_video_resize
2315 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
2316 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
2317 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
2318 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
2319 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
2322 #if defined(_DM_BUFFER_H_) && defined(GLX_SGIX_dmbuffer)
2323 glx
.AssociateDMPbufferSGIX
= NULL
;
2326 #ifdef GLX_SGIX_swap_group
2327 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
2330 #ifdef GLX_SGIX_swap_barrier
2331 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
2332 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
2335 #ifdef GLX_SUN_get_transparent_index
2336 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
2339 #ifdef GLX_MESA_copy_sub_buffer
2340 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
2343 #ifdef GLX_MESA_release_buffers
2344 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
2347 #ifdef GLX_MESA_pixmap_colormap
2348 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
2351 #ifdef GLX_MESA_set_3dfx_mode
2352 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;