1 /* $Id: fakeglx.c,v 1.58 2001/09/23 16:11:27 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.0"
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 printf("Set fake context ctx %p\n", ctx
);
1239 __glXSetCurrentContext(ctx
);
1247 else if (!ctx
&& !draw
&& !read
) {
1248 /* release current context w/out assigning new one. */
1249 XMesaMakeCurrent( NULL
, NULL
);
1250 MakeCurrent_PrevContext
= 0;
1251 MakeCurrent_PrevDrawable
= 0;
1252 MakeCurrent_PrevReadable
= 0;
1253 MakeCurrent_PrevDrawBuffer
= 0;
1254 MakeCurrent_PrevReadBuffer
= 0;
1255 #ifdef GLX_BUILT_IN_XMESA
1256 /* XXX bind dummy context with __glXSetCurrentContext(ctx); */
1261 /* The args must either all be non-zero or all zero.
1271 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1273 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1279 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1284 v
= find_glx_visual( dpy
, visinfo
);
1286 v
= create_glx_visual( dpy
, visinfo
);
1288 /* unusable visual */
1293 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1297 return b
->frontbuffer
;
1301 /*** GLX_MESA_pixmap_colormap ***/
1304 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1305 Pixmap pixmap
, Colormap cmap
)
1310 v
= find_glx_visual( dpy
, visinfo
);
1312 v
= create_glx_visual( dpy
, visinfo
);
1314 /* unusable visual */
1319 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1323 return b
->frontbuffer
;
1328 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1330 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1332 XMesaDestroyBuffer(b
);
1334 else if (getenv("MESA_DEBUG")) {
1335 fprintf( stderr
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1342 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1343 unsigned long mask
)
1345 XMesaContext xm_src
= (XMesaContext
) src
;
1346 XMesaContext xm_dst
= (XMesaContext
) dst
;
1348 _mesa_copy_context( xm_src
->gl_ctx
, xm_dst
->gl_ctx
, (GLuint
) mask
);
1354 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1356 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1364 extern void _kw_ungrab_all( Display
*dpy
);
1365 void _kw_ungrab_all( Display
*dpy
)
1367 XUngrabPointer( dpy
, CurrentTime
);
1368 XUngrabKeyboard( dpy
, CurrentTime
);
1373 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1375 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1377 MakeCurrent_PrevContext
= 0;
1378 MakeCurrent_PrevDrawable
= 0;
1379 MakeCurrent_PrevReadable
= 0;
1380 MakeCurrent_PrevDrawBuffer
= 0;
1381 MakeCurrent_PrevReadBuffer
= 0;
1382 XMesaDestroyContext( glxCtx
->xmesaContext
);
1383 XMesaGarbageCollect();
1389 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1391 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1393 return glxCtx
->xmesaContext
->direct
;
1399 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1401 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1404 XMesaSwapBuffers(buffer
);
1406 else if (getenv("MESA_DEBUG")) {
1407 fprintf(stderr
, "Mesa Warning: glXSwapBuffers: invalid drawable\n");
1413 /*** GLX_MESA_copy_sub_buffer ***/
1416 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1417 int x
, int y
, int width
, int height
)
1419 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1421 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1423 else if (getenv("MESA_DEBUG")) {
1424 fprintf(stderr
, "Mesa Warning: glXCopySubBufferMESA: invalid drawable\n");
1431 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1434 /* Return GLX version, not Mesa version */
1435 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1436 *maj
= CLIENT_MAJOR_VERSION
;
1437 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1444 * Query the GLX attributes of the given XVisualInfo.
1447 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1448 int attrib
, int *value
)
1452 glxvis
= find_glx_visual( dpy
, visinfo
);
1454 /* this visual wasn't obtained with glXChooseVisual */
1455 glxvis
= create_glx_visual( dpy
, visinfo
);
1457 /* this visual can't be used for GL rendering */
1458 if (attrib
==GLX_USE_GL
) {
1459 *value
= (int) False
;
1463 /*fprintf( stderr, "Mesa: Error in glXGetConfig: bad visual\n");*/
1464 return GLX_BAD_VISUAL
;
1471 *value
= (int) True
;
1473 case GLX_BUFFER_SIZE
:
1474 *value
= visinfo
->depth
;
1477 *value
= glxvis
->level
;
1480 if (glxvis
->mesa_visual
.rgbMode
) {
1487 case GLX_DOUBLEBUFFER
:
1488 *value
= (int) glxvis
->mesa_visual
.doubleBufferMode
;
1491 *value
= (int) glxvis
->mesa_visual
.stereoMode
;
1493 case GLX_AUX_BUFFERS
:
1494 *value
= (int) False
;
1497 *value
= glxvis
->mesa_visual
.redBits
;
1499 case GLX_GREEN_SIZE
:
1500 *value
= glxvis
->mesa_visual
.greenBits
;
1503 *value
= glxvis
->mesa_visual
.blueBits
;
1505 case GLX_ALPHA_SIZE
:
1506 *value
= glxvis
->mesa_visual
.alphaBits
;
1508 case GLX_DEPTH_SIZE
:
1509 *value
= glxvis
->mesa_visual
.depthBits
;
1511 case GLX_STENCIL_SIZE
:
1512 *value
= glxvis
->mesa_visual
.stencilBits
;
1514 case GLX_ACCUM_RED_SIZE
:
1515 *value
= glxvis
->mesa_visual
.accumRedBits
;
1517 case GLX_ACCUM_GREEN_SIZE
:
1518 *value
= glxvis
->mesa_visual
.accumGreenBits
;
1520 case GLX_ACCUM_BLUE_SIZE
:
1521 *value
= glxvis
->mesa_visual
.accumBlueBits
;
1523 case GLX_ACCUM_ALPHA_SIZE
:
1524 *value
= glxvis
->mesa_visual
.accumAlphaBits
;
1528 * GLX_EXT_visual_info extension
1530 case GLX_X_VISUAL_TYPE_EXT
:
1531 switch (glxvis
->visinfo
->CLASS
) {
1532 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1533 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1534 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1535 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1536 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1537 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1540 case GLX_TRANSPARENT_TYPE_EXT
:
1541 if (glxvis
->level
==0) {
1543 *value
= GLX_NONE_EXT
;
1545 else if (glxvis
->level
>0) {
1547 if (glxvis
->mesa_visual
.rgbMode
) {
1548 *value
= GLX_TRANSPARENT_RGB_EXT
;
1551 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1554 else if (glxvis
->level
<0) {
1556 *value
= GLX_NONE_EXT
;
1559 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1561 int pixel
= transparent_pixel( glxvis
);
1565 /* else undefined */
1568 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1571 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1574 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1577 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1582 * GLX_EXT_visual_info extension
1584 case GLX_VISUAL_CAVEAT_EXT
:
1585 /* test for zero, just in case */
1586 if (glxvis
->VisualCaveat
> 0)
1587 *value
= glxvis
->VisualCaveat
;
1589 *value
= GLX_NONE_EXT
;
1596 return GLX_BAD_ATTRIBUTE
;
1603 Fake_glXWaitGL( void )
1605 XMesaContext xmesa
= XMesaGetCurrentContext();
1606 XMesaFlush( xmesa
);
1612 Fake_glXWaitX( void )
1614 XMesaContext xmesa
= XMesaGetCurrentContext();
1615 XMesaFlush( xmesa
);
1620 * Return the extensions string, which is 3Dfx-dependant.
1622 static const char *get_extensions( void )
1625 const char *fx
= getenv("MESA_GLX_FX");
1626 if (fx
&& fx
[0] != 'd') {
1627 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";
1630 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";
1635 /* GLX 1.1 and later */
1637 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1641 return get_extensions();
1646 /* GLX 1.1 and later */
1648 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1650 static char version
[1000];
1651 sprintf(version
, "%d.%d %s", SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
,
1658 case GLX_EXTENSIONS
:
1659 return get_extensions();
1671 /* GLX 1.1 and later */
1673 Fake_glXGetClientString( Display
*dpy
, int name
)
1675 static char version
[1000];
1676 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
, CLIENT_MINOR_VERSION
,
1682 case GLX_EXTENSIONS
:
1683 return get_extensions();
1699 /* XXX Move this when done.
1700 * Create an XMesaBuffer as a Pbuffer.
1701 * New in Mesa 4.0 but untested.
1703 extern XMesaBuffer
XMesaCreatePBuffer( XMesaVisual v
, XMesaColormap cmap
,
1704 unsigned int width
, unsigned int height
);
1708 static GLXFBConfig
*
1709 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1710 const int *attribList
, int *nitems
)
1721 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1722 int attribute
, int *value
)
1724 XMesaVisual v
= NULL
; /* XXX Fix this */
1730 if (!dpy
|| !config
|| !value
)
1733 switch (attribute
) {
1734 case GLX_FBCONFIG_ID
:
1735 case GLX_BUFFER_SIZE
:
1736 if (v
->mesa_visual
.rgbMode
)
1737 *value
= v
->mesa_visual
.redBits
+ v
->mesa_visual
.greenBits
+
1738 v
->mesa_visual
.blueBits
+ v
->mesa_visual
.alphaBits
;
1740 *value
= v
->mesa_visual
.indexBits
;
1745 case GLX_DOUBLEBUFFER
:
1746 *value
= v
->mesa_visual
.doubleBufferMode
;
1749 *value
= v
->mesa_visual
.stereoMode
;
1751 case GLX_AUX_BUFFERS
:
1752 *value
= v
->mesa_visual
.numAuxBuffers
;
1755 *value
= v
->mesa_visual
.redBits
;
1757 case GLX_GREEN_SIZE
:
1758 *value
= v
->mesa_visual
.greenBits
;
1761 *value
= v
->mesa_visual
.blueBits
;
1763 case GLX_ALPHA_SIZE
:
1764 *value
= v
->mesa_visual
.alphaBits
;
1766 case GLX_DEPTH_SIZE
:
1767 *value
= v
->mesa_visual
.depthBits
;
1769 case GLX_STENCIL_SIZE
:
1770 *value
= v
->mesa_visual
.stencilBits
;
1772 case GLX_ACCUM_RED_SIZE
:
1773 *value
= v
->mesa_visual
.accumRedBits
;
1775 case GLX_ACCUM_GREEN_SIZE
:
1776 *value
= v
->mesa_visual
.accumGreenBits
;
1778 case GLX_ACCUM_BLUE_SIZE
:
1779 *value
= v
->mesa_visual
.accumBlueBits
;
1781 case GLX_ACCUM_ALPHA_SIZE
:
1782 *value
= v
->mesa_visual
.accumAlphaBits
;
1784 case GLX_RENDER_TYPE
:
1785 *value
= 0; /* XXX ??? */
1787 case GLX_DRAWABLE_TYPE
:
1788 *value
= GLX_PBUFFER_BIT
; /* XXX fix? */
1790 case GLX_X_RENDERABLE
:
1791 *value
= False
; /* XXX ??? */
1793 case GLX_X_VISUAL_TYPE
:
1794 switch (v
->vishandle
->class) {
1796 *value
= GLX_GRAY_SCALE
;
1799 *value
= GLX_STATIC_GRAY
;
1802 *value
= GLX_STATIC_COLOR
;
1805 *value
= GLX_PSEUDO_COLOR
;
1808 *value
= GLX_TRUE_COLOR
;
1811 *value
= GLX_DIRECT_COLOR
;
1817 case GLX_CONFIG_CAVEAT
:
1818 *value
= 0; /* XXX ??? */
1820 case GLX_TRANSPARENT_TYPE
:
1821 if (v
->level
== 0) {
1823 *value
= GLX_NONE_EXT
;
1825 else if (v
->level
> 0) {
1827 if (v
->mesa_visual
.rgbMode
) {
1828 *value
= GLX_TRANSPARENT_RGB_EXT
;
1831 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1834 else if (v
->level
< 0) {
1836 *value
= GLX_NONE_EXT
;
1839 case GLX_TRANSPARENT_INDEX_VALUE
:
1840 *value
= transparent_pixel( v
);
1842 case GLX_TRANSPARENT_RED_VALUE
:
1843 *value
= 0; /* not implemented */
1845 case GLX_TRANSPARENT_GREEN_VALUE
:
1846 *value
= 0; /* not implemented */
1848 case GLX_TRANSPARENT_BLUE_VALUE
:
1849 *value
= 0; /* not implemented */
1851 case GLX_TRANSPARENT_ALPHA_VALUE
:
1852 *value
= 0; /* not implemented */
1854 case GLX_MAX_PBUFFER_WIDTH
:
1855 *value
= DisplayWidth(dpy
, v
->vishandle
->screen
);
1857 case GLX_MAX_PBUFFER_HEIGHT
:
1858 *value
= DisplayHeight(dpy
, v
->vishandle
->screen
);
1860 case GLX_MAX_PBUFFER_PIXELS
:
1861 *value
= DisplayWidth(dpy
, v
->vishandle
->screen
) *
1862 DisplayHeight(dpy
, v
->vishandle
->screen
);
1865 *value
= v
->vishandle
->visualid
;
1868 return GLX_BAD_ATTRIBUTE
;
1875 static GLXFBConfig
*
1876 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1885 static XVisualInfo
*
1886 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1888 if (dpy
&& config
) {
1889 XMesaVisual v
= (XMesaVisual
) config
;
1890 return v
->vishandle
;
1899 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1900 const int *attribList
)
1905 (void) attribList
; /* Ignored in GLX 1.3 */
1907 return win
; /* A hack for now */
1912 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1914 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
1916 XMesaDestroyBuffer(b
);
1917 /* don't destroy X window */
1923 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1924 const int *attribList
)
1926 XMesaVisual v
= (XMesaVisual
) config
;
1927 XVisualInfo
*visinfo
;
1933 (void) attribList
; /* Ignored in GLX 1.3 */
1935 if (!dpy
|| !config
|| !pixmap
)
1938 visinfo
= v
->vishandle
;
1940 v
= find_glx_visual( dpy
, visinfo
);
1942 v
= create_glx_visual( dpy
, visinfo
);
1944 /* unusable visual */
1949 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1959 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1961 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
1963 XMesaDestroyBuffer(b
);
1964 /* don't destroy X pixmap */
1969 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
1970 const int *attribList
)
1973 int width
= 0, height
= 0;
1974 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
1979 for (attrib
= attribList
; attrib
; attrib
++) {
1981 case GLX_PBUFFER_WIDTH
:
1982 width
= *(++attrib
);
1984 case GLX_PBUFFER_HEIGHT
:
1985 height
= *(++attrib
);
1987 case GLX_PRESERVED_CONTENTS
:
1988 preserveContents
= GL_TRUE
; /* ignored */
1990 case GLX_LARGEST_PBUFFER
:
1991 useLargest
= GL_TRUE
; /* ignored */
1998 if (width
== 0 || height
== 0)
2007 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2015 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2016 unsigned int *value
)
2021 switch (attribute
) {
2024 case GLX_PRESERVED_CONTENTS
:
2025 case GLX_LARGEST_PBUFFER
:
2026 case GLX_FBCONFIG_ID
:
2030 return; /* GLX_BAD_ATTRIBUTE? */
2036 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2037 int renderType
, GLXContext shareList
, Bool direct
)
2039 XMesaVisual v
= (XMesaVisual
) config
;
2041 if (!dpy
|| !config
||
2042 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2045 return Fake_glXCreateContext(dpy
, v
->vishandle
, shareList
, direct
);
2050 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2055 switch (attribute
) {
2056 case GLX_FBCONFIG_ID
:
2057 case GLX_RENDER_TYPE
:
2062 return GLX_BAD_ATTRIBUTE
;
2068 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2077 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2078 unsigned long *mask
)
2087 /*** GLX_SGI_swap_control ***/
2090 Fake_glXSwapIntervalSGI(int interval
)
2098 /*** GLX_SGI_video_sync ***/
2101 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2108 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2118 /*** GLX_SGI_make_current_read ***/
2121 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2132 Fake_glXGetCurrentReadDrawableSGI(void)
2139 /*** GLX_SGIX_video_source ***/
2142 static GLXVideoSourceSGIX
2143 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2155 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2164 /*** GLX_EXT_import_context ***/
2167 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2174 Fake_glXGetContextIDEXT(const GLXContext context
)
2181 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2189 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2200 /*** GLX_SGIX_fbconfig ***/
2203 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2212 static GLXFBConfigSGIX
*
2213 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2223 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2232 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2242 static XVisualInfo
*
2243 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2250 static GLXFBConfigSGIX
2251 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2260 /*** GLX_SGIX_pbuffer ***/
2262 static GLXPbufferSGIX
2263 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
, unsigned int width
, unsigned int height
, int *attrib_list
)
2274 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2281 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2291 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2299 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2308 /*** GLX_SGI_cushion ***/
2311 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2320 /*** GLX_SGIX_video_resize ***/
2323 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2333 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2346 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2359 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2372 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2383 /*** GLX_SGIX_dmbuffer **/
2385 #if defined(_DM_BUFFER_H_)
2387 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2398 /*** GLX_SGIX_swap_group ***/
2401 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2410 /*** GLX_SGIX_swap_barrier ***/
2413 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2421 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2431 /*** GLX_SUN_get_transparent_index ***/
2434 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2439 (void) pTransparent
;
2445 /*** GLX_MESA_release_buffers ***/
2448 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2449 * (a window or pixmap) prior to destroying the GLXDrawable.
2452 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2454 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2456 XMesaDestroyBuffer(b
);
2464 /*** GLX_MESA_set_3dfx_mode ***/
2467 Fake_glXSet3DfxModeMESA( int mode
)
2469 return XMesaSetFXmode( mode
);
2475 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2476 struct _glxapi_table
*_mesa_GetGLXDispatchTable(void)
2478 static struct _glxapi_table glx
;
2480 /* be sure our dispatch table size <= libGL's table */
2482 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2484 assert(_glxapi_get_dispatch_table_size() >= size
);
2487 /* initialize the whole table to no-ops */
2488 _glxapi_set_no_op_table(&glx
);
2490 /* now initialize the table with the functions I implement */
2491 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2492 glx
.CopyContext
= Fake_glXCopyContext
;
2493 glx
.CreateContext
= Fake_glXCreateContext
;
2494 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2495 glx
.DestroyContext
= Fake_glXDestroyContext
;
2496 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2497 glx
.GetConfig
= Fake_glXGetConfig
;
2498 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2499 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2500 glx
.IsDirect
= Fake_glXIsDirect
;
2501 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2502 glx
.QueryExtension
= Fake_glXQueryExtension
;
2503 glx
.QueryVersion
= Fake_glXQueryVersion
;
2504 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2505 glx
.UseXFont
= Fake_glXUseXFont
;
2506 glx
.WaitGL
= Fake_glXWaitGL
;
2507 glx
.WaitX
= Fake_glXWaitX
;
2509 /*** GLX_VERSION_1_1 ***/
2510 glx
.GetClientString
= Fake_glXGetClientString
;
2511 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2512 glx
.QueryServerString
= Fake_glXQueryServerString
;
2514 /*** GLX_VERSION_1_2 ***/
2515 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2517 /*** GLX_VERSION_1_3 ***/
2518 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2519 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2520 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2521 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2522 glx
.CreateWindow
= Fake_glXCreateWindow
;
2523 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2524 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2525 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2526 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2527 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2528 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2529 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2530 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2531 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2532 glx
.QueryContext
= Fake_glXQueryContext
;
2533 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2534 glx
.SelectEvent
= Fake_glXSelectEvent
;
2536 /*** GLX_SGI_swap_control ***/
2537 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2539 /*** GLX_SGI_video_sync ***/
2540 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2541 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2543 /*** GLX_SGI_make_current_read ***/
2544 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2545 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2547 /*** GLX_SGIX_video_source ***/
2549 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2550 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2553 /*** GLX_EXT_import_context ***/
2554 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2555 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2556 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2557 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2558 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2560 /*** GLX_SGIX_fbconfig ***/
2561 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2562 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2563 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2564 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
2565 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
2566 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
2568 /*** GLX_SGIX_pbuffer ***/
2569 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
2570 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
2571 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
2572 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
2573 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
2575 /*** GLX_SGI_cushion ***/
2576 glx
.CushionSGI
= Fake_glXCushionSGI
;
2578 /*** GLX_SGIX_video_resize ***/
2579 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
2580 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
2581 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
2582 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
2583 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
2585 /*** GLX_SGIX_dmbuffer **/
2586 #if defined(_DM_BUFFER_H_)
2587 glx
.AssociateDMPbufferSGIX
= NULL
;
2590 /*** GLX_SGIX_swap_group ***/
2591 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
2593 /*** GLX_SGIX_swap_barrier ***/
2594 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
2595 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
2597 /*** GLX_SUN_get_transparent_index ***/
2598 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
2600 /*** GLX_MESA_copy_sub_buffer ***/
2601 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
2603 /*** GLX_MESA_release_buffers ***/
2604 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
2606 /*** GLX_MESA_pixmap_colormap ***/
2607 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
2609 /*** GLX_MESA_set_3dfx_mode ***/
2610 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;