1 /* $Id: fakeglx.c,v 1.60 2002/03/15 18:24:53 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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"
58 /* This indicates the client-side GLX API and GLX encoder version. */
59 #define CLIENT_MAJOR_VERSION 1
60 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
62 /* This indicates the server-side GLX decoder version.
63 * GLX 1.4 indicates OpenGL 1.3 support
65 #define SERVER_MAJOR_VERSION 1
66 #define SERVER_MINOR_VERSION 4
68 /* This is appended onto the glXGetClient/ServerString version strings. */
69 #define MESA_GLX_VERSION "Mesa 4.1"
71 /* Who implemented this GLX? */
72 #define VENDOR "Brian Paul"
76 /* Silence compiler warnings */
77 extern void Fake_glXDummyFunc( void );
78 void Fake_glXDummyFunc( void )
88 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
90 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
93 * We really just need this structure in order to make the libGL functions
94 * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
97 struct fake_glx_context
{
98 __GLXcontext glxContext
; /* this MUST be first! */
99 XMesaContext xmesaContext
;
104 /**********************************************************************/
105 /*** GLX Visual Code ***/
106 /**********************************************************************/
111 #define MAX_VISUALS 100
112 static XMesaVisual VisualTable
[MAX_VISUALS
];
113 static int NumVisuals
= 0;
117 * This struct and some code fragments borrowed
118 * from Mark Kilgard's GLUT library.
120 typedef struct _OverlayInfo
{
121 /* Avoid 64-bit portability problems by being careful to use
122 longs due to the way XGetWindowProperty is specified. Note
123 that these parameters are passed as CARD32s over X
125 unsigned long overlay_visual
;
126 long transparent_type
;
133 /* Macro to handle c_class vs class field name in XVisualInfo struct */
134 #if defined(__cplusplus) || defined(c_plusplus)
135 #define CLASS c_class
144 * Test if the given XVisualInfo is usable for Mesa rendering.
146 static GLboolean
is_usable_visual( XVisualInfo
*vinfo
)
148 switch (vinfo
->CLASS
) {
151 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
155 /* Any StaticColor/PseudoColor visual of at least 4 bits */
156 if (vinfo
->depth
>=4) {
164 /* Any depth of TrueColor or DirectColor works in RGB mode */
167 /* This should never happen */
175 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
176 * Input: dpy - the X display
177 * vinfo - the XVisualInfo to test
178 * Return: level of the visual:
180 * >0 = overlay planes
181 * <0 = underlay planes
183 static int level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
185 Atom overlayVisualsAtom
;
186 OverlayInfo
*overlay_info
= NULL
;
187 int numOverlaysPerScreen
;
191 unsigned long sizeData
, bytesLeft
;
195 * The SERVER_OVERLAY_VISUALS property on the root window contains
196 * a list of overlay visuals. Get that list now.
198 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
199 if (overlayVisualsAtom
== None
) {
203 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, vinfo
->screen
),
204 overlayVisualsAtom
, 0L, (long) 10000, False
,
205 overlayVisualsAtom
, &actualType
, &actualFormat
,
206 &sizeData
, &bytesLeft
,
207 (unsigned char **) &overlay_info
);
209 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
210 actualFormat
!= 32 || sizeData
< 4) {
211 /* something went wrong */
212 XFree((void *) overlay_info
);
216 /* search the overlay visual list for the visual ID of interest */
217 numOverlaysPerScreen
= (int) (sizeData
/ 4);
218 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
220 ov
= overlay_info
+ i
;
221 if (ov
->overlay_visual
==vinfo
->visualid
) {
222 /* found the visual */
223 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
224 int level
= ov
->layer
;
225 XFree((void *) overlay_info
);
229 XFree((void *) overlay_info
);
235 /* The visual ID was not found in the overlay list. */
236 XFree((void *) overlay_info
);
244 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
245 * configuration in our list of GLX visuals.
248 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
249 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
250 GLboolean stereoFlag
,
251 GLint depth_size
, GLint stencil_size
,
252 GLint accumRedSize
, GLint accumGreenSize
,
253 GLint accumBlueSize
, GLint accumAlphaSize
,
256 GLboolean ximageFlag
= GL_TRUE
;
259 GLboolean comparePointers
;
262 /* Check if the MESA_BACK_BUFFER env var is set */
263 char *backbuffer
= getenv("MESA_BACK_BUFFER");
265 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
266 ximageFlag
= GL_FALSE
;
268 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
269 ximageFlag
= GL_TRUE
;
272 fprintf(stderr
, "Mesa: invalid value for MESA_BACK_BUFFER ");
273 fprintf(stderr
, "environment variable, using an XImage.\n");
278 /* Comparing IDs uses less memory but sometimes fails. */
279 /* XXX revisit this after 3.0 is finished. */
280 if (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
290 && v
->ximage_flag
== ximageFlag
291 && v
->mesa_visual
.rgbMode
== rgbFlag
292 && v
->mesa_visual
.doubleBufferMode
== dbFlag
293 && v
->mesa_visual
.stereoMode
== stereoFlag
294 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
295 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
296 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
297 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
298 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
299 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
300 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
301 /* now either compare XVisualInfo pointers or visual IDs */
302 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
303 || (comparePointers
&& v
->vishandle
== vinfo
)) {
309 /* Create a new visual and add it to the list. */
311 if (NumVisuals
>=MAX_VISUALS
) {
312 fprintf( stderr
, "GLX Error: maximum number of visuals exceeded\n");
316 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
317 stereoFlag
, ximageFlag
,
318 depth_size
, stencil_size
,
319 accumRedSize
, accumBlueSize
,
320 accumBlueSize
, accumAlphaSize
, 0, level
,
323 VisualTable
[NumVisuals
] = xmvis
;
332 * Create a GLX visual from a regular XVisualInfo.
333 * This is called when Fake GLX is given an XVisualInfo which wasn't
334 * returned by glXChooseVisual. Since this is the first time we're
335 * considering this visual we'll take a guess at reasonable values
336 * for depth buffer size, stencil size, accum size, etc.
337 * This is the best we can do with a client-side emulation of GLX.
340 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
344 vislevel
= level_of_visual( dpy
, visinfo
);
346 /* Configure this visual as a CI, single-buffered overlay */
347 return save_glx_visual( dpy
, visinfo
,
349 GL_FALSE
, /* alpha */
350 GL_FALSE
, /* double */
351 GL_FALSE
, /* stereo */
353 0, /* stencil bits */
354 0,0,0,0, /* accum bits */
358 else if (is_usable_visual( visinfo
)) {
359 if (getenv("MESA_GLX_FORCE_CI")) {
360 /* Configure this visual as a COLOR INDEX visual. */
361 return save_glx_visual( dpy
, visinfo
,
363 GL_FALSE
, /* alpha */
364 GL_TRUE
, /* double */
365 GL_FALSE
, /* stereo */
366 DEFAULT_SOFTWARE_DEPTH_BITS
,
367 8 * sizeof(GLstencil
),
368 0 * sizeof(GLaccum
), /* r */
369 0 * sizeof(GLaccum
), /* g */
370 0 * sizeof(GLaccum
), /* b */
371 0 * sizeof(GLaccum
), /* a */
376 /* Configure this visual as RGB, double-buffered, depth-buffered. */
377 /* This is surely wrong for some people's needs but what else */
378 /* can be done? They should use glXChooseVisual(). */
379 return save_glx_visual( dpy
, visinfo
,
381 GL_FALSE
, /* alpha */
382 GL_TRUE
, /* double */
383 GL_FALSE
, /* stereo */
384 DEFAULT_SOFTWARE_DEPTH_BITS
,
385 8 * sizeof(GLstencil
),
386 8 * sizeof(GLaccum
), /* r */
387 8 * sizeof(GLaccum
), /* g */
388 8 * sizeof(GLaccum
), /* b */
389 8 * sizeof(GLaccum
), /* a */
395 fprintf(stderr
,"Mesa: error in glXCreateContext: bad visual\n");
403 * Find the GLX visual associated with an XVisualInfo.
406 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
410 /* First try to match pointers */
411 for (i
=0;i
<NumVisuals
;i
++) {
412 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
413 return VisualTable
[i
];
416 /* try to match visual id */
417 for (i
=0;i
<NumVisuals
;i
++) {
418 if (VisualTable
[i
]->display
==dpy
419 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
420 return VisualTable
[i
];
429 * Return the transparent pixel value for a GLX visual.
430 * Input: glxvis - the glx_visual
431 * Return: a pixel value or -1 if no transparent pixel
433 static int transparent_pixel( XMesaVisual glxvis
)
435 Display
*dpy
= glxvis
->display
;
436 XVisualInfo
*vinfo
= glxvis
->visinfo
;
437 Atom overlayVisualsAtom
;
438 OverlayInfo
*overlay_info
= NULL
;
439 int numOverlaysPerScreen
;
443 unsigned long sizeData
, bytesLeft
;
447 * The SERVER_OVERLAY_VISUALS property on the root window contains
448 * a list of overlay visuals. Get that list now.
450 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
451 if (overlayVisualsAtom
== None
) {
455 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, vinfo
->screen
),
456 overlayVisualsAtom
, 0L, (long) 10000, False
,
457 overlayVisualsAtom
, &actualType
, &actualFormat
,
458 &sizeData
, &bytesLeft
,
459 (unsigned char **) &overlay_info
);
461 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
462 actualFormat
!= 32 || sizeData
< 4) {
463 /* something went wrong */
464 XFree((void *) overlay_info
);
468 /* search the overlay visual list for the visual ID of interest */
469 numOverlaysPerScreen
= (int) (sizeData
/ 4);
470 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
472 ov
= overlay_info
+ i
;
473 if (ov
->overlay_visual
==vinfo
->visualid
) {
475 if (ov
->transparent_type
==0) {
476 /* type 0 indicates no transparency */
477 XFree((void *) overlay_info
);
481 /* ov->value is the transparent pixel */
482 XFree((void *) overlay_info
);
488 /* The visual ID was not found in the overlay list. */
489 XFree((void *) overlay_info
);
496 * Try to get an X visual which matches the given arguments.
498 static XVisualInfo
*get_visual( Display
*dpy
, int scr
,
499 unsigned int depth
, int xclass
)
501 XVisualInfo temp
, *vis
;
504 unsigned int default_depth
;
507 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
512 default_depth
= DefaultDepth(dpy
,scr
);
513 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
515 if (depth
==default_depth
&& xclass
==default_class
) {
516 /* try to get root window's visual */
517 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
518 mask
|= VisualIDMask
;
521 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
523 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
524 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
525 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
527 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
528 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
529 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
530 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
545 * Retrieve the value of the given environment variable and find
546 * the X visual which matches it.
547 * Input: dpy - the display
548 * screen - the screen number
549 * varname - the name of the environment variable
550 * Return: an XVisualInfo pointer to NULL if error.
552 static XVisualInfo
*get_env_visual(Display
*dpy
, int scr
, const char *varname
)
554 char value
[100], type
[100];
555 int depth
, xclass
= -1;
558 if (!getenv( varname
)) {
562 strncpy( value
, getenv(varname
), 100 );
565 sscanf( value
, "%s %d", type
, &depth
);
567 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
568 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
569 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
570 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
571 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
572 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
574 if (xclass
>-1 && depth
>0) {
575 vis
= get_visual( dpy
, scr
, depth
, xclass
);
581 fprintf( stderr
, "Mesa: GLX unable to find visual class=%s, depth=%d.\n",
589 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
590 * Input: dpy, screen - X display and screen number
591 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
592 * min_depth - minimum visual depth
593 * preferred_class - preferred GLX visual class or DONT_CARE
594 * Return: pointer to an XVisualInfo or NULL.
596 static XVisualInfo
*choose_x_visual( Display
*dpy
, int screen
,
597 GLboolean rgba
, int min_depth
,
598 int preferred_class
)
601 int xclass
, visclass
= 0;
605 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
606 /* First see if the MESA_RGB_VISUAL env var is defined */
607 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
611 /* Otherwise, search for a suitable visual */
612 if (preferred_class
==DONT_CARE
) {
613 for (xclass
=0;xclass
<6;xclass
++) {
615 case 0: visclass
= TrueColor
; break;
616 case 1: visclass
= DirectColor
; break;
617 case 2: visclass
= PseudoColor
; break;
618 case 3: visclass
= StaticColor
; break;
619 case 4: visclass
= GrayScale
; break;
620 case 5: visclass
= StaticGray
; break;
623 /* start with shallowest */
624 for (depth
=0;depth
<=32;depth
++) {
625 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
626 /* Special case: try to get 8-bit PseudoColor before */
627 /* 8-bit TrueColor */
628 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
633 vis
= get_visual( dpy
, screen
, depth
, visclass
);
640 /* start with deepest */
641 for (depth
=32;depth
>=min_depth
;depth
--) {
642 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
643 /* Special case: try to get 8-bit PseudoColor before */
644 /* 8-bit TrueColor */
645 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
650 vis
= get_visual( dpy
, screen
, depth
, visclass
);
659 /* search for a specific visual class */
660 switch (preferred_class
) {
661 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
662 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
663 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
664 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
665 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
666 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
667 default: return NULL
;
670 /* start with shallowest */
671 for (depth
=0;depth
<=32;depth
++) {
672 vis
= get_visual( dpy
, screen
, depth
, visclass
);
679 /* start with deepest */
680 for (depth
=32;depth
>=min_depth
;depth
--) {
681 vis
= get_visual( dpy
, screen
, depth
, visclass
);
690 /* First see if the MESA_CI_VISUAL env var is defined */
691 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
695 /* Otherwise, search for a suitable visual, starting with shallowest */
696 if (preferred_class
==DONT_CARE
) {
697 for (xclass
=0;xclass
<4;xclass
++) {
699 case 0: visclass
= PseudoColor
; break;
700 case 1: visclass
= StaticColor
; break;
701 case 2: visclass
= GrayScale
; break;
702 case 3: visclass
= StaticGray
; break;
704 /* try 8-bit up through 16-bit */
705 for (depth
=8;depth
<=16;depth
++) {
706 vis
= get_visual( dpy
, screen
, depth
, visclass
);
711 /* try min_depth up to 8-bit */
712 for (depth
=min_depth
;depth
<8;depth
++) {
713 vis
= get_visual( dpy
, screen
, depth
, visclass
);
721 /* search for a specific visual class */
722 switch (preferred_class
) {
723 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
724 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
725 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
726 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
727 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
728 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
729 default: return NULL
;
731 /* try 8-bit up through 16-bit */
732 for (depth
=8;depth
<=16;depth
++) {
733 vis
= get_visual( dpy
, screen
, depth
, visclass
);
738 /* try min_depth up to 8-bit */
739 for (depth
=min_depth
;depth
<8;depth
++) {
740 vis
= get_visual( dpy
, screen
, depth
, visclass
);
748 /* didn't find a visual */
755 * Find the deepest X over/underlay visual of at least min_depth.
756 * Input: dpy, screen - X display and screen number
757 * level - the over/underlay level
758 * trans_type - transparent pixel type: GLX_NONE_EXT,
759 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
761 * trans_value - transparent pixel value or DONT_CARE
762 * min_depth - minimum visual depth
763 * preferred_class - preferred GLX visual class or DONT_CARE
764 * Return: pointer to an XVisualInfo or NULL.
766 static XVisualInfo
*choose_x_overlay_visual( Display
*dpy
, int scr
,
768 int level
, int trans_type
,
771 int preferred_class
)
773 Atom overlayVisualsAtom
;
774 OverlayInfo
*overlay_info
;
775 int numOverlaysPerScreen
;
779 unsigned long sizeData
, bytesLeft
;
781 XVisualInfo
*deepvis
;
784 /*DEBUG int tt, tv; */
786 switch (preferred_class
) {
787 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
788 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
789 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
790 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
791 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
792 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
793 default: preferred_class
= DONT_CARE
;
797 * The SERVER_OVERLAY_VISUALS property on the root window contains
798 * a list of overlay visuals. Get that list now.
800 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
801 if (overlayVisualsAtom
== (Atom
) None
) {
805 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, scr
),
806 overlayVisualsAtom
, 0L, (long) 10000, False
,
807 overlayVisualsAtom
, &actualType
, &actualFormat
,
808 &sizeData
, &bytesLeft
,
809 (unsigned char **) &overlay_info
);
811 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
812 actualFormat
!= 32 || sizeData
< 4) {
813 /* something went wrong */
817 /* Search for the deepest overlay which satisifies all criteria. */
821 numOverlaysPerScreen
= (int) (sizeData
/ 4);
822 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
823 XVisualInfo
*vislist
, vistemplate
;
826 ov
= overlay_info
+ i
;
828 if (ov
->layer
!=level
) {
829 /* failed overlay level criteria */
832 if (!(trans_type
==DONT_CARE
833 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
834 && ov
->transparent_type
>0)
835 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
836 /* failed transparent pixel type criteria */
839 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
840 /* failed transparent pixel value criteria */
844 /* get XVisualInfo and check the depth */
845 vistemplate
.visualid
= ov
->overlay_visual
;
846 vistemplate
.screen
= scr
;
847 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
848 &vistemplate
, &count
);
851 /* something went wrong */
854 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
855 /* wrong visual class */
859 /* if RGB was requested, make sure we have True/DirectColor */
860 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
861 && vislist
->CLASS
!= DirectColor
)
864 /* if CI was requested, make sure we have a color indexed visual */
866 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
869 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
870 /* YES! found a satisfactory visual */
874 deepest
= vislist
->depth
;
876 /* DEBUG tt = ov->transparent_type;*/
877 /* DEBUG tv = ov->value; */
883 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
884 deepvis->visualid, level, deepvis->depth, tt, tv );
891 /**********************************************************************/
892 /*** Begin Fake GLX API Functions ***/
893 /**********************************************************************/
897 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
902 int min_red
=0, min_green
=0, min_blue
=0;
903 GLboolean rgb_flag
= GL_FALSE
;
904 GLboolean alpha_flag
= GL_FALSE
;
905 GLboolean double_flag
= GL_FALSE
;
906 GLboolean stereo_flag
= GL_FALSE
;
907 GLint depth_size
= 0;
908 GLint stencil_size
= 0;
909 GLint accumRedSize
= 0;
910 GLint accumGreenSize
= 0;
911 GLint accumBlueSize
= 0;
912 GLint accumAlphaSize
= 0;
914 int visual_type
= DONT_CARE
;
915 int trans_type
= DONT_CARE
;
916 int trans_value
= DONT_CARE
;
917 GLint caveat
= DONT_CARE
;
923 switch (*parselist
) {
928 case GLX_BUFFER_SIZE
:
930 min_ci
= *parselist
++;
934 level
= *parselist
++;
940 case GLX_DOUBLEBUFFER
:
941 double_flag
= GL_TRUE
;
945 stereo_flag
= GL_TRUE
;
947 case GLX_AUX_BUFFERS
:
954 min_red
= *parselist
++;
958 min_green
= *parselist
++;
962 min_blue
= *parselist
++;
967 GLint size
= *parselist
++;
968 alpha_flag
= size
>0 ? 1 : 0;
973 depth_size
= *parselist
++;
975 case GLX_STENCIL_SIZE
:
977 stencil_size
= *parselist
++;
979 case GLX_ACCUM_RED_SIZE
:
982 GLint size
= *parselist
++;
983 accumRedSize
= MAX2( accumRedSize
, size
);
986 case GLX_ACCUM_GREEN_SIZE
:
989 GLint size
= *parselist
++;
990 accumGreenSize
= MAX2( accumGreenSize
, size
);
993 case GLX_ACCUM_BLUE_SIZE
:
996 GLint size
= *parselist
++;
997 accumBlueSize
= MAX2( accumBlueSize
, size
);
1000 case GLX_ACCUM_ALPHA_SIZE
:
1003 GLint size
= *parselist
++;
1004 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1009 * GLX_EXT_visual_info extension
1011 case GLX_X_VISUAL_TYPE_EXT
:
1013 visual_type
= *parselist
++;
1015 case GLX_TRANSPARENT_TYPE_EXT
:
1017 trans_type
= *parselist
++;
1019 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1021 trans_value
= *parselist
++;
1023 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1024 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1025 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1026 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1033 * GLX_EXT_visual_info extension
1035 case GLX_VISUAL_CAVEAT_EXT
:
1037 caveat
= *parselist
++; /* ignored for now */
1043 /* undefined attribute */
1049 * Since we're only simulating the GLX extension this function will never
1050 * find any real GL visuals. Instead, all we can do is try to find an RGB
1051 * or CI visual of appropriate depth. Other requested attributes such as
1052 * double buffering, depth buffer, etc. will be associated with the X
1053 * visual and stored in the VisualTable[].
1056 /* normal color planes */
1058 /* Get an RGB visual */
1059 int min_rgb
= min_red
+ min_green
+ min_blue
;
1060 if (min_rgb
>1 && min_rgb
<8) {
1061 /* a special case to be sure we can get a monochrome visual */
1064 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1067 /* Get a color index visual */
1068 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1069 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1073 /* over/underlay planes */
1076 int min_rgb
= min_red
+ min_green
+ min_blue
;
1077 if (min_rgb
>1 && min_rgb
<8) {
1078 /* a special case to be sure we can get a monochrome visual */
1081 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1082 trans_type
, trans_value
, min_rgb
, visual_type
);
1085 /* color index overlay */
1086 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1087 trans_type
, trans_value
, min_ci
, visual_type
);
1092 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1093 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1094 * largest depth buffer size, which is 32bits/value. Instead, we
1095 * return 16 to maintain performance with earlier versions of Mesa.
1097 if (depth_size
> 24)
1098 depth_size
= 31; /* 32 causes int overflow problems */
1099 else if (depth_size
> 16)
1101 else if (depth_size
> 0)
1102 depth_size
= DEFAULT_SOFTWARE_DEPTH_BITS
; /*16*/
1104 /* we only support one size of stencil and accum buffers. */
1105 if (stencil_size
> 0)
1106 stencil_size
= STENCIL_BITS
;
1107 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1108 accumAlphaSize
> 0) {
1109 accumRedSize
= ACCUM_BITS
;
1110 accumGreenSize
= ACCUM_BITS
;
1111 accumBlueSize
= ACCUM_BITS
;
1112 accumAlphaSize
= alpha_flag
? ACCUM_BITS
: 0;
1115 if (!save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1116 stereo_flag
, depth_size
, stencil_size
,
1117 accumRedSize
, accumGreenSize
,
1118 accumBlueSize
, accumAlphaSize
,
1130 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1131 GLXContext share_list
, Bool direct
)
1134 struct fake_glx_context
*glxCtx
;
1135 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1136 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1140 /* deallocate unused windows/buffers */
1141 XMesaGarbageCollect();
1143 glxvis
= find_glx_visual( dpy
, visinfo
);
1145 /* This visual wasn't found with glXChooseVisual() */
1146 glxvis
= create_glx_visual( dpy
, visinfo
);
1148 /* unusable visual */
1154 glxCtx
->xmesaContext
= XMesaCreateContext(glxvis
,
1155 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1156 if (!glxCtx
->xmesaContext
) {
1161 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
1162 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
1163 glxCtx
->glxContext
.currentDpy
= dpy
;
1164 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1166 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1168 return (GLXContext
) glxCtx
;
1172 /* XXX these may have to be removed due to thread-safety issues. */
1173 static GLXContext MakeCurrent_PrevContext
= 0;
1174 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1175 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1176 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1177 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1180 /* GLX 1.3 and later */
1182 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1183 GLXDrawable read
, GLXContext ctx
)
1185 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1187 if (ctx
&& draw
&& read
) {
1188 XMesaBuffer drawBuffer
, readBuffer
;
1189 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1191 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1192 if (ctx
== MakeCurrent_PrevContext
1193 && draw
== MakeCurrent_PrevDrawable
) {
1194 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1197 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1200 /* drawable must be a new window! */
1201 drawBuffer
= XMesaCreateWindowBuffer2( xmctx
->xm_visual
, draw
, xmctx
);
1203 /* Out of memory, or context/drawable depth mismatch */
1208 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1209 if (ctx
== MakeCurrent_PrevContext
1210 && read
== MakeCurrent_PrevReadable
) {
1211 readBuffer
= MakeCurrent_PrevReadBuffer
;
1214 readBuffer
= XMesaFindBuffer( dpy
, read
);
1217 /* drawable must be a new window! */
1218 readBuffer
= XMesaCreateWindowBuffer2(glxCtx
->xmesaContext
->xm_visual
,
1221 /* Out of memory, or context/drawable depth mismatch */
1226 MakeCurrent_PrevContext
= ctx
;
1227 MakeCurrent_PrevDrawable
= draw
;
1228 MakeCurrent_PrevReadable
= read
;
1229 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1230 MakeCurrent_PrevReadBuffer
= readBuffer
;
1232 /* Now make current! */
1233 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1234 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1235 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1236 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1237 #ifdef GLX_BUILT_IN_XMESA
1238 __glXSetCurrentContext(ctx
);
1246 else if (!ctx
&& !draw
&& !read
) {
1247 /* release current context w/out assigning new one. */
1248 XMesaMakeCurrent( NULL
, NULL
);
1249 MakeCurrent_PrevContext
= 0;
1250 MakeCurrent_PrevDrawable
= 0;
1251 MakeCurrent_PrevReadable
= 0;
1252 MakeCurrent_PrevDrawBuffer
= 0;
1253 MakeCurrent_PrevReadBuffer
= 0;
1254 #ifdef GLX_BUILT_IN_XMESA
1255 /* XXX bind dummy context with __glXSetCurrentContext(ctx); */
1260 /* The args must either all be non-zero or all zero.
1270 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1272 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1278 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1283 v
= find_glx_visual( dpy
, visinfo
);
1285 v
= create_glx_visual( dpy
, visinfo
);
1287 /* unusable visual */
1292 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1296 return b
->frontbuffer
;
1300 /*** GLX_MESA_pixmap_colormap ***/
1303 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1304 Pixmap pixmap
, Colormap cmap
)
1309 v
= find_glx_visual( dpy
, visinfo
);
1311 v
= create_glx_visual( dpy
, visinfo
);
1313 /* unusable visual */
1318 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1322 return b
->frontbuffer
;
1327 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1329 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1331 XMesaDestroyBuffer(b
);
1333 else if (getenv("MESA_DEBUG")) {
1334 fprintf( stderr
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1341 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1342 unsigned long mask
)
1344 XMesaContext xm_src
= (XMesaContext
) src
;
1345 XMesaContext xm_dst
= (XMesaContext
) dst
;
1347 _mesa_copy_context( xm_src
->gl_ctx
, xm_dst
->gl_ctx
, (GLuint
) mask
);
1353 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1355 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1363 extern void _kw_ungrab_all( Display
*dpy
);
1364 void _kw_ungrab_all( Display
*dpy
)
1366 XUngrabPointer( dpy
, CurrentTime
);
1367 XUngrabKeyboard( dpy
, CurrentTime
);
1372 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1374 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1376 MakeCurrent_PrevContext
= 0;
1377 MakeCurrent_PrevDrawable
= 0;
1378 MakeCurrent_PrevReadable
= 0;
1379 MakeCurrent_PrevDrawBuffer
= 0;
1380 MakeCurrent_PrevReadBuffer
= 0;
1381 XMesaDestroyContext( glxCtx
->xmesaContext
);
1382 XMesaGarbageCollect();
1388 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1390 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1392 return glxCtx
->xmesaContext
->direct
;
1398 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1400 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1403 XMesaSwapBuffers(buffer
);
1405 else if (getenv("MESA_DEBUG")) {
1406 fprintf(stderr
, "Mesa Warning: glXSwapBuffers: invalid drawable\n");
1412 /*** GLX_MESA_copy_sub_buffer ***/
1415 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1416 int x
, int y
, int width
, int height
)
1418 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1420 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1422 else if (getenv("MESA_DEBUG")) {
1423 fprintf(stderr
, "Mesa Warning: glXCopySubBufferMESA: invalid drawable\n");
1430 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1433 /* Return GLX version, not Mesa version */
1434 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1435 *maj
= CLIENT_MAJOR_VERSION
;
1436 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1443 * Query the GLX attributes of the given XVisualInfo.
1446 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1447 int attrib
, int *value
)
1451 glxvis
= find_glx_visual( dpy
, visinfo
);
1453 /* this visual wasn't obtained with glXChooseVisual */
1454 glxvis
= create_glx_visual( dpy
, visinfo
);
1456 /* this visual can't be used for GL rendering */
1457 if (attrib
==GLX_USE_GL
) {
1458 *value
= (int) False
;
1462 /*fprintf( stderr, "Mesa: Error in glXGetConfig: bad visual\n");*/
1463 return GLX_BAD_VISUAL
;
1470 *value
= (int) True
;
1472 case GLX_BUFFER_SIZE
:
1473 *value
= visinfo
->depth
;
1476 *value
= glxvis
->level
;
1479 if (glxvis
->mesa_visual
.rgbMode
) {
1486 case GLX_DOUBLEBUFFER
:
1487 *value
= (int) glxvis
->mesa_visual
.doubleBufferMode
;
1490 *value
= (int) glxvis
->mesa_visual
.stereoMode
;
1492 case GLX_AUX_BUFFERS
:
1493 *value
= (int) False
;
1496 *value
= glxvis
->mesa_visual
.redBits
;
1498 case GLX_GREEN_SIZE
:
1499 *value
= glxvis
->mesa_visual
.greenBits
;
1502 *value
= glxvis
->mesa_visual
.blueBits
;
1504 case GLX_ALPHA_SIZE
:
1505 *value
= glxvis
->mesa_visual
.alphaBits
;
1507 case GLX_DEPTH_SIZE
:
1508 *value
= glxvis
->mesa_visual
.depthBits
;
1510 case GLX_STENCIL_SIZE
:
1511 *value
= glxvis
->mesa_visual
.stencilBits
;
1513 case GLX_ACCUM_RED_SIZE
:
1514 *value
= glxvis
->mesa_visual
.accumRedBits
;
1516 case GLX_ACCUM_GREEN_SIZE
:
1517 *value
= glxvis
->mesa_visual
.accumGreenBits
;
1519 case GLX_ACCUM_BLUE_SIZE
:
1520 *value
= glxvis
->mesa_visual
.accumBlueBits
;
1522 case GLX_ACCUM_ALPHA_SIZE
:
1523 *value
= glxvis
->mesa_visual
.accumAlphaBits
;
1527 * GLX_EXT_visual_info extension
1529 case GLX_X_VISUAL_TYPE_EXT
:
1530 switch (glxvis
->visinfo
->CLASS
) {
1531 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1532 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1533 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1534 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1535 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1536 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1539 case GLX_TRANSPARENT_TYPE_EXT
:
1540 if (glxvis
->level
==0) {
1542 *value
= GLX_NONE_EXT
;
1544 else if (glxvis
->level
>0) {
1546 if (glxvis
->mesa_visual
.rgbMode
) {
1547 *value
= GLX_TRANSPARENT_RGB_EXT
;
1550 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1553 else if (glxvis
->level
<0) {
1555 *value
= GLX_NONE_EXT
;
1558 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1560 int pixel
= transparent_pixel( glxvis
);
1564 /* else undefined */
1567 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1570 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1573 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1576 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1581 * GLX_EXT_visual_info extension
1583 case GLX_VISUAL_CAVEAT_EXT
:
1584 /* test for zero, just in case */
1585 if (glxvis
->VisualCaveat
> 0)
1586 *value
= glxvis
->VisualCaveat
;
1588 *value
= GLX_NONE_EXT
;
1595 return GLX_BAD_ATTRIBUTE
;
1602 Fake_glXWaitGL( void )
1604 XMesaContext xmesa
= XMesaGetCurrentContext();
1605 XMesaFlush( xmesa
);
1611 Fake_glXWaitX( void )
1613 XMesaContext xmesa
= XMesaGetCurrentContext();
1614 XMesaFlush( xmesa
);
1619 * Return the extensions string, which is 3Dfx-dependant.
1621 static const char *get_extensions( void )
1624 const char *fx
= getenv("MESA_GLX_FX");
1625 if (fx
&& fx
[0] != 'd') {
1626 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";
1629 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";
1634 /* GLX 1.1 and later */
1636 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1640 return get_extensions();
1645 /* GLX 1.1 and later */
1647 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1649 static char version
[1000];
1650 sprintf(version
, "%d.%d %s", SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
,
1657 case GLX_EXTENSIONS
:
1658 return get_extensions();
1670 /* GLX 1.1 and later */
1672 Fake_glXGetClientString( Display
*dpy
, int name
)
1674 static char version
[1000];
1675 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
, CLIENT_MINOR_VERSION
,
1681 case GLX_EXTENSIONS
:
1682 return get_extensions();
1698 /* XXX Move this when done.
1699 * Create an XMesaBuffer as a Pbuffer.
1700 * New in Mesa 4.0 but untested.
1702 extern XMesaBuffer
XMesaCreatePBuffer( XMesaVisual v
, XMesaColormap cmap
,
1703 unsigned int width
, unsigned int height
);
1707 static GLXFBConfig
*
1708 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1709 const int *attribList
, int *nitems
)
1720 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1721 int attribute
, int *value
)
1723 XMesaVisual v
= NULL
; /* XXX Fix this */
1729 if (!dpy
|| !config
|| !value
)
1732 switch (attribute
) {
1733 case GLX_FBCONFIG_ID
:
1734 case GLX_BUFFER_SIZE
:
1735 if (v
->mesa_visual
.rgbMode
)
1736 *value
= v
->mesa_visual
.redBits
+ v
->mesa_visual
.greenBits
+
1737 v
->mesa_visual
.blueBits
+ v
->mesa_visual
.alphaBits
;
1739 *value
= v
->mesa_visual
.indexBits
;
1744 case GLX_DOUBLEBUFFER
:
1745 *value
= v
->mesa_visual
.doubleBufferMode
;
1748 *value
= v
->mesa_visual
.stereoMode
;
1750 case GLX_AUX_BUFFERS
:
1751 *value
= v
->mesa_visual
.numAuxBuffers
;
1754 *value
= v
->mesa_visual
.redBits
;
1756 case GLX_GREEN_SIZE
:
1757 *value
= v
->mesa_visual
.greenBits
;
1760 *value
= v
->mesa_visual
.blueBits
;
1762 case GLX_ALPHA_SIZE
:
1763 *value
= v
->mesa_visual
.alphaBits
;
1765 case GLX_DEPTH_SIZE
:
1766 *value
= v
->mesa_visual
.depthBits
;
1768 case GLX_STENCIL_SIZE
:
1769 *value
= v
->mesa_visual
.stencilBits
;
1771 case GLX_ACCUM_RED_SIZE
:
1772 *value
= v
->mesa_visual
.accumRedBits
;
1774 case GLX_ACCUM_GREEN_SIZE
:
1775 *value
= v
->mesa_visual
.accumGreenBits
;
1777 case GLX_ACCUM_BLUE_SIZE
:
1778 *value
= v
->mesa_visual
.accumBlueBits
;
1780 case GLX_ACCUM_ALPHA_SIZE
:
1781 *value
= v
->mesa_visual
.accumAlphaBits
;
1783 case GLX_RENDER_TYPE
:
1784 *value
= 0; /* XXX ??? */
1786 case GLX_DRAWABLE_TYPE
:
1787 *value
= GLX_PBUFFER_BIT
; /* XXX fix? */
1789 case GLX_X_RENDERABLE
:
1790 *value
= False
; /* XXX ??? */
1792 case GLX_X_VISUAL_TYPE
:
1793 switch (v
->vishandle
->class) {
1795 *value
= GLX_GRAY_SCALE
;
1798 *value
= GLX_STATIC_GRAY
;
1801 *value
= GLX_STATIC_COLOR
;
1804 *value
= GLX_PSEUDO_COLOR
;
1807 *value
= GLX_TRUE_COLOR
;
1810 *value
= GLX_DIRECT_COLOR
;
1816 case GLX_CONFIG_CAVEAT
:
1817 *value
= 0; /* XXX ??? */
1819 case GLX_TRANSPARENT_TYPE
:
1820 if (v
->level
== 0) {
1822 *value
= GLX_NONE_EXT
;
1824 else if (v
->level
> 0) {
1826 if (v
->mesa_visual
.rgbMode
) {
1827 *value
= GLX_TRANSPARENT_RGB_EXT
;
1830 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1833 else if (v
->level
< 0) {
1835 *value
= GLX_NONE_EXT
;
1838 case GLX_TRANSPARENT_INDEX_VALUE
:
1839 *value
= transparent_pixel( v
);
1841 case GLX_TRANSPARENT_RED_VALUE
:
1842 *value
= 0; /* not implemented */
1844 case GLX_TRANSPARENT_GREEN_VALUE
:
1845 *value
= 0; /* not implemented */
1847 case GLX_TRANSPARENT_BLUE_VALUE
:
1848 *value
= 0; /* not implemented */
1850 case GLX_TRANSPARENT_ALPHA_VALUE
:
1851 *value
= 0; /* not implemented */
1853 case GLX_MAX_PBUFFER_WIDTH
:
1854 *value
= DisplayWidth(dpy
, v
->vishandle
->screen
);
1856 case GLX_MAX_PBUFFER_HEIGHT
:
1857 *value
= DisplayHeight(dpy
, v
->vishandle
->screen
);
1859 case GLX_MAX_PBUFFER_PIXELS
:
1860 *value
= DisplayWidth(dpy
, v
->vishandle
->screen
) *
1861 DisplayHeight(dpy
, v
->vishandle
->screen
);
1864 *value
= v
->vishandle
->visualid
;
1867 return GLX_BAD_ATTRIBUTE
;
1874 static GLXFBConfig
*
1875 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1884 static XVisualInfo
*
1885 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1887 if (dpy
&& config
) {
1888 XMesaVisual v
= (XMesaVisual
) config
;
1889 return v
->vishandle
;
1898 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1899 const int *attribList
)
1904 (void) attribList
; /* Ignored in GLX 1.3 */
1906 return win
; /* A hack for now */
1911 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1913 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
1915 XMesaDestroyBuffer(b
);
1916 /* don't destroy X window */
1922 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1923 const int *attribList
)
1925 XMesaVisual v
= (XMesaVisual
) config
;
1926 XVisualInfo
*visinfo
;
1932 (void) attribList
; /* Ignored in GLX 1.3 */
1934 if (!dpy
|| !config
|| !pixmap
)
1937 visinfo
= v
->vishandle
;
1939 v
= find_glx_visual( dpy
, visinfo
);
1941 v
= create_glx_visual( dpy
, visinfo
);
1943 /* unusable visual */
1948 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1958 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1960 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
1962 XMesaDestroyBuffer(b
);
1963 /* don't destroy X pixmap */
1968 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
1969 const int *attribList
)
1972 int width
= 0, height
= 0;
1973 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
1978 for (attrib
= attribList
; attrib
; attrib
++) {
1980 case GLX_PBUFFER_WIDTH
:
1981 width
= *(++attrib
);
1983 case GLX_PBUFFER_HEIGHT
:
1984 height
= *(++attrib
);
1986 case GLX_PRESERVED_CONTENTS
:
1987 preserveContents
= GL_TRUE
; /* ignored */
1989 case GLX_LARGEST_PBUFFER
:
1990 useLargest
= GL_TRUE
; /* ignored */
1997 if (width
== 0 || height
== 0)
2006 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2014 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2015 unsigned int *value
)
2020 switch (attribute
) {
2023 case GLX_PRESERVED_CONTENTS
:
2024 case GLX_LARGEST_PBUFFER
:
2025 case GLX_FBCONFIG_ID
:
2029 return; /* GLX_BAD_ATTRIBUTE? */
2035 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2036 int renderType
, GLXContext shareList
, Bool direct
)
2038 XMesaVisual v
= (XMesaVisual
) config
;
2040 if (!dpy
|| !config
||
2041 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2044 return Fake_glXCreateContext(dpy
, v
->vishandle
, shareList
, direct
);
2049 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2054 switch (attribute
) {
2055 case GLX_FBCONFIG_ID
:
2056 case GLX_RENDER_TYPE
:
2061 return GLX_BAD_ATTRIBUTE
;
2067 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2076 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2077 unsigned long *mask
)
2086 /*** GLX_SGI_swap_control ***/
2089 Fake_glXSwapIntervalSGI(int interval
)
2097 /*** GLX_SGI_video_sync ***/
2100 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2107 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2117 /*** GLX_SGI_make_current_read ***/
2120 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2131 Fake_glXGetCurrentReadDrawableSGI(void)
2138 /*** GLX_SGIX_video_source ***/
2141 static GLXVideoSourceSGIX
2142 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2154 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2163 /*** GLX_EXT_import_context ***/
2166 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2173 Fake_glXGetContextIDEXT(const GLXContext context
)
2180 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2188 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2199 /*** GLX_SGIX_fbconfig ***/
2202 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2211 static GLXFBConfigSGIX
*
2212 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2222 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2231 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2241 static XVisualInfo
*
2242 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2249 static GLXFBConfigSGIX
2250 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2259 /*** GLX_SGIX_pbuffer ***/
2261 static GLXPbufferSGIX
2262 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
, unsigned int width
, unsigned int height
, int *attrib_list
)
2273 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2280 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2290 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2298 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2307 /*** GLX_SGI_cushion ***/
2310 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2319 /*** GLX_SGIX_video_resize ***/
2322 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2332 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2345 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2358 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2371 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2382 /*** GLX_SGIX_dmbuffer **/
2384 #if defined(_DM_BUFFER_H_)
2386 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2397 /*** GLX_SGIX_swap_group ***/
2400 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2409 /*** GLX_SGIX_swap_barrier ***/
2412 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2420 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2430 /*** GLX_SUN_get_transparent_index ***/
2433 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2438 (void) pTransparent
;
2444 /*** GLX_MESA_release_buffers ***/
2447 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2448 * (a window or pixmap) prior to destroying the GLXDrawable.
2451 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2453 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2455 XMesaDestroyBuffer(b
);
2463 /*** GLX_MESA_set_3dfx_mode ***/
2466 Fake_glXSet3DfxModeMESA( int mode
)
2468 return XMesaSetFXmode( mode
);
2474 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2475 struct _glxapi_table
*_mesa_GetGLXDispatchTable(void)
2477 static struct _glxapi_table glx
;
2479 /* be sure our dispatch table size <= libGL's table */
2481 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2483 assert(_glxapi_get_dispatch_table_size() >= size
);
2486 /* initialize the whole table to no-ops */
2487 _glxapi_set_no_op_table(&glx
);
2489 /* now initialize the table with the functions I implement */
2490 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2491 glx
.CopyContext
= Fake_glXCopyContext
;
2492 glx
.CreateContext
= Fake_glXCreateContext
;
2493 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2494 glx
.DestroyContext
= Fake_glXDestroyContext
;
2495 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2496 glx
.GetConfig
= Fake_glXGetConfig
;
2497 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2498 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2499 glx
.IsDirect
= Fake_glXIsDirect
;
2500 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2501 glx
.QueryExtension
= Fake_glXQueryExtension
;
2502 glx
.QueryVersion
= Fake_glXQueryVersion
;
2503 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2504 glx
.UseXFont
= Fake_glXUseXFont
;
2505 glx
.WaitGL
= Fake_glXWaitGL
;
2506 glx
.WaitX
= Fake_glXWaitX
;
2508 /*** GLX_VERSION_1_1 ***/
2509 glx
.GetClientString
= Fake_glXGetClientString
;
2510 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2511 glx
.QueryServerString
= Fake_glXQueryServerString
;
2513 /*** GLX_VERSION_1_2 ***/
2514 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2516 /*** GLX_VERSION_1_3 ***/
2517 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2518 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2519 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2520 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2521 glx
.CreateWindow
= Fake_glXCreateWindow
;
2522 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2523 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2524 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2525 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2526 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2527 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2528 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2529 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2530 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2531 glx
.QueryContext
= Fake_glXQueryContext
;
2532 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2533 glx
.SelectEvent
= Fake_glXSelectEvent
;
2535 /*** GLX_SGI_swap_control ***/
2536 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2538 /*** GLX_SGI_video_sync ***/
2539 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2540 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2542 /*** GLX_SGI_make_current_read ***/
2543 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2544 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2546 /*** GLX_SGIX_video_source ***/
2548 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2549 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2552 /*** GLX_EXT_import_context ***/
2553 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2554 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2555 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2556 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2557 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2559 /*** GLX_SGIX_fbconfig ***/
2560 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2561 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2562 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2563 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
2564 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
2565 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
2567 /*** GLX_SGIX_pbuffer ***/
2568 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
2569 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
2570 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
2571 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
2572 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
2574 /*** GLX_SGI_cushion ***/
2575 glx
.CushionSGI
= Fake_glXCushionSGI
;
2577 /*** GLX_SGIX_video_resize ***/
2578 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
2579 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
2580 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
2581 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
2582 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
2584 /*** GLX_SGIX_dmbuffer **/
2585 #if defined(_DM_BUFFER_H_)
2586 glx
.AssociateDMPbufferSGIX
= NULL
;
2589 /*** GLX_SGIX_swap_group ***/
2590 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
2592 /*** GLX_SGIX_swap_barrier ***/
2593 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
2594 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
2596 /*** GLX_SUN_get_transparent_index ***/
2597 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
2599 /*** GLX_MESA_copy_sub_buffer ***/
2600 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
2602 /*** GLX_MESA_release_buffers ***/
2603 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
2605 /*** GLX_MESA_pixmap_colormap ***/
2606 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
2608 /*** GLX_MESA_set_3dfx_mode ***/
2609 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;