1 /* $Id: fakeglx.c,v 1.67 2002/08/22 21:10:01 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 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 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
277 /* Comparing IDs uses less memory but sometimes fails. */
278 /* XXX revisit this after 3.0 is finished. */
279 if (getenv("MESA_GLX_VISUAL_HACK"))
280 comparePointers
= GL_TRUE
;
282 comparePointers
= GL_FALSE
;
284 /* First check if a matching visual is already in the list */
285 for (i
=0; i
<NumVisuals
; i
++) {
286 XMesaVisual v
= VisualTable
[i
];
287 if (v
->display
== dpy
289 && v
->ximage_flag
== ximageFlag
290 && v
->mesa_visual
.rgbMode
== rgbFlag
291 && v
->mesa_visual
.doubleBufferMode
== dbFlag
292 && v
->mesa_visual
.stereoMode
== stereoFlag
293 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
294 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
295 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
296 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
297 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
298 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
299 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
300 /* now either compare XVisualInfo pointers or visual IDs */
301 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
302 || (comparePointers
&& v
->vishandle
== vinfo
)) {
308 /* Create a new visual and add it to the list. */
310 if (NumVisuals
>= MAX_VISUALS
) {
311 _mesa_problem(NULL
, "GLX Error: maximum number of visuals exceeded");
315 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
316 stereoFlag
, ximageFlag
,
317 depth_size
, stencil_size
,
318 accumRedSize
, accumBlueSize
,
319 accumBlueSize
, accumAlphaSize
, 0, level
,
322 VisualTable
[NumVisuals
] = xmvis
;
331 * Create a GLX visual from a regular XVisualInfo.
332 * This is called when Fake GLX is given an XVisualInfo which wasn't
333 * returned by glXChooseVisual. Since this is the first time we're
334 * considering this visual we'll take a guess at reasonable values
335 * for depth buffer size, stencil size, accum size, etc.
336 * This is the best we can do with a client-side emulation of GLX.
339 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
343 vislevel
= level_of_visual( dpy
, visinfo
);
345 /* Configure this visual as a CI, single-buffered overlay */
346 return save_glx_visual( dpy
, visinfo
,
348 GL_FALSE
, /* alpha */
349 GL_FALSE
, /* double */
350 GL_FALSE
, /* stereo */
352 0, /* stencil bits */
353 0,0,0,0, /* accum bits */
357 else if (is_usable_visual( visinfo
)) {
358 if (getenv("MESA_GLX_FORCE_CI")) {
359 /* Configure this visual as a COLOR INDEX visual. */
360 return save_glx_visual( dpy
, visinfo
,
362 GL_FALSE
, /* alpha */
363 GL_TRUE
, /* double */
364 GL_FALSE
, /* stereo */
365 DEFAULT_SOFTWARE_DEPTH_BITS
,
366 8 * sizeof(GLstencil
),
367 0 * sizeof(GLaccum
), /* r */
368 0 * sizeof(GLaccum
), /* g */
369 0 * sizeof(GLaccum
), /* b */
370 0 * sizeof(GLaccum
), /* a */
375 /* Configure this visual as RGB, double-buffered, depth-buffered. */
376 /* This is surely wrong for some people's needs but what else */
377 /* can be done? They should use glXChooseVisual(). */
378 return save_glx_visual( dpy
, visinfo
,
380 GL_FALSE
, /* alpha */
381 GL_TRUE
, /* double */
382 GL_FALSE
, /* stereo */
383 DEFAULT_SOFTWARE_DEPTH_BITS
,
384 8 * sizeof(GLstencil
),
385 8 * sizeof(GLaccum
), /* r */
386 8 * sizeof(GLaccum
), /* g */
387 8 * sizeof(GLaccum
), /* b */
388 8 * sizeof(GLaccum
), /* a */
394 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
402 * Find the GLX visual associated with an XVisualInfo.
405 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
409 /* First try to match pointers */
410 for (i
=0;i
<NumVisuals
;i
++) {
411 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
412 return VisualTable
[i
];
415 /* try to match visual id */
416 for (i
=0;i
<NumVisuals
;i
++) {
417 if (VisualTable
[i
]->display
==dpy
418 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
419 return VisualTable
[i
];
428 * Return the transparent pixel value for a GLX visual.
429 * Input: glxvis - the glx_visual
430 * Return: a pixel value or -1 if no transparent pixel
432 static int transparent_pixel( XMesaVisual glxvis
)
434 Display
*dpy
= glxvis
->display
;
435 XVisualInfo
*vinfo
= glxvis
->visinfo
;
436 Atom overlayVisualsAtom
;
437 OverlayInfo
*overlay_info
= NULL
;
438 int numOverlaysPerScreen
;
442 unsigned long sizeData
, bytesLeft
;
446 * The SERVER_OVERLAY_VISUALS property on the root window contains
447 * a list of overlay visuals. Get that list now.
449 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
450 if (overlayVisualsAtom
== None
) {
454 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, vinfo
->screen
),
455 overlayVisualsAtom
, 0L, (long) 10000, False
,
456 overlayVisualsAtom
, &actualType
, &actualFormat
,
457 &sizeData
, &bytesLeft
,
458 (unsigned char **) &overlay_info
);
460 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
461 actualFormat
!= 32 || sizeData
< 4) {
462 /* something went wrong */
463 XFree((void *) overlay_info
);
467 /* search the overlay visual list for the visual ID of interest */
468 numOverlaysPerScreen
= (int) (sizeData
/ 4);
469 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
471 ov
= overlay_info
+ i
;
472 if (ov
->overlay_visual
==vinfo
->visualid
) {
474 if (ov
->transparent_type
==0) {
475 /* type 0 indicates no transparency */
476 XFree((void *) overlay_info
);
480 /* ov->value is the transparent pixel */
481 XFree((void *) overlay_info
);
487 /* The visual ID was not found in the overlay list. */
488 XFree((void *) overlay_info
);
495 * Try to get an X visual which matches the given arguments.
497 static XVisualInfo
*get_visual( Display
*dpy
, int scr
,
498 unsigned int depth
, int xclass
)
500 XVisualInfo temp
, *vis
;
503 unsigned int default_depth
;
506 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
511 default_depth
= DefaultDepth(dpy
,scr
);
512 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
514 if (depth
==default_depth
&& xclass
==default_class
) {
515 /* try to get root window's visual */
516 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
517 mask
|= VisualIDMask
;
520 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
522 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
523 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
524 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
526 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
527 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
528 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
529 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
544 * Retrieve the value of the given environment variable and find
545 * the X visual which matches it.
546 * Input: dpy - the display
547 * screen - the screen number
548 * varname - the name of the environment variable
549 * Return: an XVisualInfo pointer to NULL if error.
551 static XVisualInfo
*get_env_visual(Display
*dpy
, int scr
, const char *varname
)
553 char value
[100], type
[100];
554 int depth
, xclass
= -1;
557 if (!getenv( varname
)) {
561 strncpy( value
, getenv(varname
), 100 );
564 sscanf( value
, "%s %d", type
, &depth
);
566 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
567 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
568 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
569 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
570 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
571 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
573 if (xclass
>-1 && depth
>0) {
574 vis
= get_visual( dpy
, scr
, depth
, xclass
);
582 sprintf(s
, "Mesa: GLX unable to find visual class=%s, depth=%d.\n",
584 _mesa_warning(NULL
, s
);
593 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
594 * Input: dpy, screen - X display and screen number
595 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
596 * min_depth - minimum visual depth
597 * preferred_class - preferred GLX visual class or DONT_CARE
598 * Return: pointer to an XVisualInfo or NULL.
600 static XVisualInfo
*choose_x_visual( Display
*dpy
, int screen
,
601 GLboolean rgba
, int min_depth
,
602 int preferred_class
)
605 int xclass
, visclass
= 0;
609 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
610 /* First see if the MESA_RGB_VISUAL env var is defined */
611 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
615 /* Otherwise, search for a suitable visual */
616 if (preferred_class
==DONT_CARE
) {
617 for (xclass
=0;xclass
<6;xclass
++) {
619 case 0: visclass
= TrueColor
; break;
620 case 1: visclass
= DirectColor
; break;
621 case 2: visclass
= PseudoColor
; break;
622 case 3: visclass
= StaticColor
; break;
623 case 4: visclass
= GrayScale
; break;
624 case 5: visclass
= StaticGray
; break;
627 /* start with shallowest */
628 for (depth
=0;depth
<=32;depth
++) {
629 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
630 /* Special case: try to get 8-bit PseudoColor before */
631 /* 8-bit TrueColor */
632 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
637 vis
= get_visual( dpy
, screen
, depth
, visclass
);
644 /* start with deepest */
645 for (depth
=32;depth
>=min_depth
;depth
--) {
646 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
647 /* Special case: try to get 8-bit PseudoColor before */
648 /* 8-bit TrueColor */
649 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
654 vis
= get_visual( dpy
, screen
, depth
, visclass
);
663 /* search for a specific visual class */
664 switch (preferred_class
) {
665 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
666 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
667 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
668 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
669 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
670 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
671 default: return NULL
;
674 /* start with shallowest */
675 for (depth
=0;depth
<=32;depth
++) {
676 vis
= get_visual( dpy
, screen
, depth
, visclass
);
683 /* start with deepest */
684 for (depth
=32;depth
>=min_depth
;depth
--) {
685 vis
= get_visual( dpy
, screen
, depth
, visclass
);
694 /* First see if the MESA_CI_VISUAL env var is defined */
695 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
699 /* Otherwise, search for a suitable visual, starting with shallowest */
700 if (preferred_class
==DONT_CARE
) {
701 for (xclass
=0;xclass
<4;xclass
++) {
703 case 0: visclass
= PseudoColor
; break;
704 case 1: visclass
= StaticColor
; break;
705 case 2: visclass
= GrayScale
; break;
706 case 3: visclass
= StaticGray
; break;
708 /* try 8-bit up through 16-bit */
709 for (depth
=8;depth
<=16;depth
++) {
710 vis
= get_visual( dpy
, screen
, depth
, visclass
);
715 /* try min_depth up to 8-bit */
716 for (depth
=min_depth
;depth
<8;depth
++) {
717 vis
= get_visual( dpy
, screen
, depth
, visclass
);
725 /* search for a specific visual class */
726 switch (preferred_class
) {
727 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
728 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
729 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
730 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
731 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
732 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
733 default: return NULL
;
735 /* try 8-bit up through 16-bit */
736 for (depth
=8;depth
<=16;depth
++) {
737 vis
= get_visual( dpy
, screen
, depth
, visclass
);
742 /* try min_depth up to 8-bit */
743 for (depth
=min_depth
;depth
<8;depth
++) {
744 vis
= get_visual( dpy
, screen
, depth
, visclass
);
752 /* didn't find a visual */
759 * Find the deepest X over/underlay visual of at least min_depth.
760 * Input: dpy, screen - X display and screen number
761 * level - the over/underlay level
762 * trans_type - transparent pixel type: GLX_NONE_EXT,
763 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
765 * trans_value - transparent pixel value or DONT_CARE
766 * min_depth - minimum visual depth
767 * preferred_class - preferred GLX visual class or DONT_CARE
768 * Return: pointer to an XVisualInfo or NULL.
770 static XVisualInfo
*choose_x_overlay_visual( Display
*dpy
, int scr
,
772 int level
, int trans_type
,
775 int preferred_class
)
777 Atom overlayVisualsAtom
;
778 OverlayInfo
*overlay_info
;
779 int numOverlaysPerScreen
;
783 unsigned long sizeData
, bytesLeft
;
785 XVisualInfo
*deepvis
;
788 /*DEBUG int tt, tv; */
790 switch (preferred_class
) {
791 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
792 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
793 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
794 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
795 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
796 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
797 default: preferred_class
= DONT_CARE
;
801 * The SERVER_OVERLAY_VISUALS property on the root window contains
802 * a list of overlay visuals. Get that list now.
804 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
805 if (overlayVisualsAtom
== (Atom
) None
) {
809 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, scr
),
810 overlayVisualsAtom
, 0L, (long) 10000, False
,
811 overlayVisualsAtom
, &actualType
, &actualFormat
,
812 &sizeData
, &bytesLeft
,
813 (unsigned char **) &overlay_info
);
815 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
816 actualFormat
!= 32 || sizeData
< 4) {
817 /* something went wrong */
821 /* Search for the deepest overlay which satisifies all criteria. */
825 numOverlaysPerScreen
= (int) (sizeData
/ 4);
826 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
827 XVisualInfo
*vislist
, vistemplate
;
830 ov
= overlay_info
+ i
;
832 if (ov
->layer
!=level
) {
833 /* failed overlay level criteria */
836 if (!(trans_type
==DONT_CARE
837 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
838 && ov
->transparent_type
>0)
839 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
840 /* failed transparent pixel type criteria */
843 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
844 /* failed transparent pixel value criteria */
848 /* get XVisualInfo and check the depth */
849 vistemplate
.visualid
= ov
->overlay_visual
;
850 vistemplate
.screen
= scr
;
851 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
852 &vistemplate
, &count
);
855 /* something went wrong */
858 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
859 /* wrong visual class */
863 /* if RGB was requested, make sure we have True/DirectColor */
864 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
865 && vislist
->CLASS
!= DirectColor
)
868 /* if CI was requested, make sure we have a color indexed visual */
870 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
873 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
874 /* YES! found a satisfactory visual */
878 deepest
= vislist
->depth
;
880 /* DEBUG tt = ov->transparent_type;*/
881 /* DEBUG tv = ov->value; */
887 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
888 deepvis->visualid, level, deepvis->depth, tt, tv );
895 /**********************************************************************/
896 /*** Begin Fake GLX API Functions ***/
897 /**********************************************************************/
901 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
906 int min_red
=0, min_green
=0, min_blue
=0;
907 GLboolean rgb_flag
= GL_FALSE
;
908 GLboolean alpha_flag
= GL_FALSE
;
909 GLboolean double_flag
= GL_FALSE
;
910 GLboolean stereo_flag
= GL_FALSE
;
911 GLint depth_size
= 0;
912 GLint stencil_size
= 0;
913 GLint accumRedSize
= 0;
914 GLint accumGreenSize
= 0;
915 GLint accumBlueSize
= 0;
916 GLint accumAlphaSize
= 0;
918 int visual_type
= DONT_CARE
;
919 int trans_type
= DONT_CARE
;
920 int trans_value
= DONT_CARE
;
921 GLint caveat
= DONT_CARE
;
927 switch (*parselist
) {
932 case GLX_BUFFER_SIZE
:
934 min_ci
= *parselist
++;
938 level
= *parselist
++;
944 case GLX_DOUBLEBUFFER
:
945 double_flag
= GL_TRUE
;
949 stereo_flag
= GL_TRUE
;
951 case GLX_AUX_BUFFERS
:
958 min_red
= *parselist
++;
962 min_green
= *parselist
++;
966 min_blue
= *parselist
++;
971 GLint size
= *parselist
++;
972 alpha_flag
= size
>0 ? 1 : 0;
977 depth_size
= *parselist
++;
979 case GLX_STENCIL_SIZE
:
981 stencil_size
= *parselist
++;
983 case GLX_ACCUM_RED_SIZE
:
986 GLint size
= *parselist
++;
987 accumRedSize
= MAX2( accumRedSize
, size
);
990 case GLX_ACCUM_GREEN_SIZE
:
993 GLint size
= *parselist
++;
994 accumGreenSize
= MAX2( accumGreenSize
, size
);
997 case GLX_ACCUM_BLUE_SIZE
:
1000 GLint size
= *parselist
++;
1001 accumBlueSize
= MAX2( accumBlueSize
, size
);
1004 case GLX_ACCUM_ALPHA_SIZE
:
1007 GLint size
= *parselist
++;
1008 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1013 * GLX_EXT_visual_info extension
1015 case GLX_X_VISUAL_TYPE_EXT
:
1017 visual_type
= *parselist
++;
1019 case GLX_TRANSPARENT_TYPE_EXT
:
1021 trans_type
= *parselist
++;
1023 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1025 trans_value
= *parselist
++;
1027 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1028 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1029 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1030 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1037 * GLX_EXT_visual_info extension
1039 case GLX_VISUAL_CAVEAT_EXT
:
1041 caveat
= *parselist
++; /* ignored for now */
1047 /* undefined attribute */
1053 * Since we're only simulating the GLX extension this function will never
1054 * find any real GL visuals. Instead, all we can do is try to find an RGB
1055 * or CI visual of appropriate depth. Other requested attributes such as
1056 * double buffering, depth buffer, etc. will be associated with the X
1057 * visual and stored in the VisualTable[].
1060 /* normal color planes */
1062 /* Get an RGB visual */
1063 int min_rgb
= min_red
+ min_green
+ min_blue
;
1064 if (min_rgb
>1 && min_rgb
<8) {
1065 /* a special case to be sure we can get a monochrome visual */
1068 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1071 /* Get a color index visual */
1072 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1073 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1077 /* over/underlay planes */
1080 int min_rgb
= min_red
+ min_green
+ min_blue
;
1081 if (min_rgb
>1 && min_rgb
<8) {
1082 /* a special case to be sure we can get a monochrome visual */
1085 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1086 trans_type
, trans_value
, min_rgb
, visual_type
);
1089 /* color index overlay */
1090 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1091 trans_type
, trans_value
, min_ci
, visual_type
);
1096 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1097 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1098 * largest depth buffer size, which is 32bits/value. Instead, we
1099 * return 16 to maintain performance with earlier versions of Mesa.
1101 if (depth_size
> 24)
1102 depth_size
= 31; /* 32 causes int overflow problems */
1103 else if (depth_size
> 16)
1105 else if (depth_size
> 0)
1106 depth_size
= DEFAULT_SOFTWARE_DEPTH_BITS
; /*16*/
1108 /* we only support one size of stencil and accum buffers. */
1109 if (stencil_size
> 0)
1110 stencil_size
= STENCIL_BITS
;
1111 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1112 accumAlphaSize
> 0) {
1113 accumRedSize
= ACCUM_BITS
;
1114 accumGreenSize
= ACCUM_BITS
;
1115 accumBlueSize
= ACCUM_BITS
;
1116 accumAlphaSize
= alpha_flag
? ACCUM_BITS
: 0;
1119 if (!save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1120 stereo_flag
, depth_size
, stencil_size
,
1121 accumRedSize
, accumGreenSize
,
1122 accumBlueSize
, accumAlphaSize
,
1134 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1135 GLXContext share_list
, Bool direct
)
1138 struct fake_glx_context
*glxCtx
;
1139 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1141 if (!dpy
|| !visinfo
)
1144 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1148 /* deallocate unused windows/buffers */
1149 XMesaGarbageCollect();
1151 glxvis
= find_glx_visual( dpy
, visinfo
);
1153 /* This visual wasn't found with glXChooseVisual() */
1154 glxvis
= create_glx_visual( dpy
, visinfo
);
1156 /* unusable visual */
1162 glxCtx
->xmesaContext
= XMesaCreateContext(glxvis
,
1163 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1164 if (!glxCtx
->xmesaContext
) {
1169 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
1170 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
1171 glxCtx
->glxContext
.currentDpy
= dpy
;
1172 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1174 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1176 return (GLXContext
) glxCtx
;
1180 /* XXX these may have to be removed due to thread-safety issues. */
1181 static GLXContext MakeCurrent_PrevContext
= 0;
1182 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1183 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1184 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1185 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1188 /* GLX 1.3 and later */
1190 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1191 GLXDrawable read
, GLXContext ctx
)
1193 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1195 if (ctx
&& draw
&& read
) {
1196 XMesaBuffer drawBuffer
, readBuffer
;
1197 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1199 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1200 if (ctx
== MakeCurrent_PrevContext
1201 && draw
== MakeCurrent_PrevDrawable
) {
1202 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1205 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1208 /* drawable must be a new window! */
1209 drawBuffer
= XMesaCreateWindowBuffer2( xmctx
->xm_visual
, draw
, xmctx
);
1211 /* Out of memory, or context/drawable depth mismatch */
1216 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1217 if (ctx
== MakeCurrent_PrevContext
1218 && read
== MakeCurrent_PrevReadable
) {
1219 readBuffer
= MakeCurrent_PrevReadBuffer
;
1222 readBuffer
= XMesaFindBuffer( dpy
, read
);
1225 /* drawable must be a new window! */
1226 readBuffer
= XMesaCreateWindowBuffer2(glxCtx
->xmesaContext
->xm_visual
,
1229 /* Out of memory, or context/drawable depth mismatch */
1234 MakeCurrent_PrevContext
= ctx
;
1235 MakeCurrent_PrevDrawable
= draw
;
1236 MakeCurrent_PrevReadable
= read
;
1237 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1238 MakeCurrent_PrevReadBuffer
= readBuffer
;
1240 /* Now make current! */
1241 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1242 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1243 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1244 #ifndef GLX_BUILT_IN_XMESA
1245 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1247 __glXSetCurrentContext(ctx
);
1255 else if (!ctx
&& !draw
&& !read
) {
1256 /* release current context w/out assigning new one. */
1257 XMesaMakeCurrent( NULL
, NULL
);
1258 MakeCurrent_PrevContext
= 0;
1259 MakeCurrent_PrevDrawable
= 0;
1260 MakeCurrent_PrevReadable
= 0;
1261 MakeCurrent_PrevDrawBuffer
= 0;
1262 MakeCurrent_PrevReadBuffer
= 0;
1263 #ifdef GLX_BUILT_IN_XMESA
1264 /* XXX bind dummy context with __glXSetCurrentContext(ctx); */
1269 /* The args must either all be non-zero or all zero.
1279 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1281 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1287 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1292 v
= find_glx_visual( dpy
, visinfo
);
1294 v
= create_glx_visual( dpy
, visinfo
);
1296 /* unusable visual */
1301 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1305 return b
->frontbuffer
;
1309 /*** GLX_MESA_pixmap_colormap ***/
1312 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1313 Pixmap pixmap
, Colormap cmap
)
1318 v
= find_glx_visual( dpy
, visinfo
);
1320 v
= create_glx_visual( dpy
, visinfo
);
1322 /* unusable visual */
1327 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1331 return b
->frontbuffer
;
1336 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1338 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1340 XMesaDestroyBuffer(b
);
1342 else if (getenv("MESA_DEBUG")) {
1343 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1350 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1351 unsigned long mask
)
1353 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1354 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1355 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1356 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1358 _mesa_copy_context( xm_src
->gl_ctx
, xm_dst
->gl_ctx
, (GLuint
) mask
);
1364 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1366 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1374 extern void _kw_ungrab_all( Display
*dpy
);
1375 void _kw_ungrab_all( Display
*dpy
)
1377 XUngrabPointer( dpy
, CurrentTime
);
1378 XUngrabKeyboard( dpy
, CurrentTime
);
1383 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1385 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1387 MakeCurrent_PrevContext
= 0;
1388 MakeCurrent_PrevDrawable
= 0;
1389 MakeCurrent_PrevReadable
= 0;
1390 MakeCurrent_PrevDrawBuffer
= 0;
1391 MakeCurrent_PrevReadBuffer
= 0;
1392 XMesaDestroyContext( glxCtx
->xmesaContext
);
1393 XMesaGarbageCollect();
1399 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1401 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1403 return glxCtx
->xmesaContext
->direct
;
1409 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1411 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1414 XMesaSwapBuffers(buffer
);
1416 else if (getenv("MESA_DEBUG")) {
1417 _mesa_warning(NULL
, "Mesa: glXSwapBuffers: invalid drawable\n");
1423 /*** GLX_MESA_copy_sub_buffer ***/
1426 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1427 int x
, int y
, int width
, int height
)
1429 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1431 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1433 else if (getenv("MESA_DEBUG")) {
1434 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1441 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1444 /* Return GLX version, not Mesa version */
1445 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1446 *maj
= CLIENT_MAJOR_VERSION
;
1447 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1454 * Query the GLX attributes of the given XVisualInfo.
1457 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1458 int attrib
, int *value
)
1462 glxvis
= find_glx_visual( dpy
, visinfo
);
1464 /* this visual wasn't obtained with glXChooseVisual */
1465 glxvis
= create_glx_visual( dpy
, visinfo
);
1467 /* this visual can't be used for GL rendering */
1468 if (attrib
==GLX_USE_GL
) {
1469 *value
= (int) False
;
1473 return GLX_BAD_VISUAL
;
1480 *value
= (int) True
;
1482 case GLX_BUFFER_SIZE
:
1483 *value
= visinfo
->depth
;
1486 *value
= glxvis
->level
;
1489 if (glxvis
->mesa_visual
.rgbMode
) {
1496 case GLX_DOUBLEBUFFER
:
1497 *value
= (int) glxvis
->mesa_visual
.doubleBufferMode
;
1500 *value
= (int) glxvis
->mesa_visual
.stereoMode
;
1502 case GLX_AUX_BUFFERS
:
1503 *value
= (int) False
;
1506 *value
= glxvis
->mesa_visual
.redBits
;
1508 case GLX_GREEN_SIZE
:
1509 *value
= glxvis
->mesa_visual
.greenBits
;
1512 *value
= glxvis
->mesa_visual
.blueBits
;
1514 case GLX_ALPHA_SIZE
:
1515 *value
= glxvis
->mesa_visual
.alphaBits
;
1517 case GLX_DEPTH_SIZE
:
1518 *value
= glxvis
->mesa_visual
.depthBits
;
1520 case GLX_STENCIL_SIZE
:
1521 *value
= glxvis
->mesa_visual
.stencilBits
;
1523 case GLX_ACCUM_RED_SIZE
:
1524 *value
= glxvis
->mesa_visual
.accumRedBits
;
1526 case GLX_ACCUM_GREEN_SIZE
:
1527 *value
= glxvis
->mesa_visual
.accumGreenBits
;
1529 case GLX_ACCUM_BLUE_SIZE
:
1530 *value
= glxvis
->mesa_visual
.accumBlueBits
;
1532 case GLX_ACCUM_ALPHA_SIZE
:
1533 *value
= glxvis
->mesa_visual
.accumAlphaBits
;
1537 * GLX_EXT_visual_info extension
1539 case GLX_X_VISUAL_TYPE_EXT
:
1540 switch (glxvis
->visinfo
->CLASS
) {
1541 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1542 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1543 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1544 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1545 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1546 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1549 case GLX_TRANSPARENT_TYPE_EXT
:
1550 if (glxvis
->level
==0) {
1552 *value
= GLX_NONE_EXT
;
1554 else if (glxvis
->level
>0) {
1556 if (glxvis
->mesa_visual
.rgbMode
) {
1557 *value
= GLX_TRANSPARENT_RGB_EXT
;
1560 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1563 else if (glxvis
->level
<0) {
1565 *value
= GLX_NONE_EXT
;
1568 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1570 int pixel
= transparent_pixel( glxvis
);
1574 /* else undefined */
1577 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1580 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1583 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1586 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1591 * GLX_EXT_visual_info extension
1593 case GLX_VISUAL_CAVEAT_EXT
:
1594 /* test for zero, just in case */
1595 if (glxvis
->VisualCaveat
> 0)
1596 *value
= glxvis
->VisualCaveat
;
1598 *value
= GLX_NONE_EXT
;
1605 return GLX_BAD_ATTRIBUTE
;
1612 Fake_glXWaitGL( void )
1614 XMesaContext xmesa
= XMesaGetCurrentContext();
1615 XMesaFlush( xmesa
);
1621 Fake_glXWaitX( void )
1623 XMesaContext xmesa
= XMesaGetCurrentContext();
1624 XMesaFlush( xmesa
);
1629 * Return the extensions string, which is 3Dfx-dependant.
1631 static const char *get_extensions( void )
1634 const char *fx
= getenv("MESA_GLX_FX");
1635 if (fx
&& fx
[0] != 'd') {
1636 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";
1639 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";
1644 /* GLX 1.1 and later */
1646 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1650 return get_extensions();
1655 /* GLX 1.1 and later */
1657 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1659 static char version
[1000];
1660 sprintf(version
, "%d.%d %s", SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
,
1667 case GLX_EXTENSIONS
:
1668 return get_extensions();
1680 /* GLX 1.1 and later */
1682 Fake_glXGetClientString( Display
*dpy
, int name
)
1684 static char version
[1000];
1685 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
, CLIENT_MINOR_VERSION
,
1691 case GLX_EXTENSIONS
:
1692 return get_extensions();
1708 /* XXX Move this when done.
1709 * Create an XMesaBuffer as a Pbuffer.
1710 * New in Mesa 4.0 but untested.
1712 extern XMesaBuffer
XMesaCreatePBuffer( XMesaVisual v
, XMesaColormap cmap
,
1713 unsigned int width
, unsigned int height
);
1718 static GLXFBConfig
*
1719 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1720 const int *attribList
, int *nitems
)
1732 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1733 int attribute
, int *value
)
1735 XMesaVisual v
= NULL
; /* XXX Fix this */
1741 if (!dpy
|| !config
|| !value
)
1744 switch (attribute
) {
1745 case GLX_FBCONFIG_ID
:
1746 case GLX_BUFFER_SIZE
:
1747 if (v
->mesa_visual
.rgbMode
)
1748 *value
= v
->mesa_visual
.redBits
+ v
->mesa_visual
.greenBits
+
1749 v
->mesa_visual
.blueBits
+ v
->mesa_visual
.alphaBits
;
1751 *value
= v
->mesa_visual
.indexBits
;
1756 case GLX_DOUBLEBUFFER
:
1757 *value
= v
->mesa_visual
.doubleBufferMode
;
1760 *value
= v
->mesa_visual
.stereoMode
;
1762 case GLX_AUX_BUFFERS
:
1763 *value
= v
->mesa_visual
.numAuxBuffers
;
1766 *value
= v
->mesa_visual
.redBits
;
1768 case GLX_GREEN_SIZE
:
1769 *value
= v
->mesa_visual
.greenBits
;
1772 *value
= v
->mesa_visual
.blueBits
;
1774 case GLX_ALPHA_SIZE
:
1775 *value
= v
->mesa_visual
.alphaBits
;
1777 case GLX_DEPTH_SIZE
:
1778 *value
= v
->mesa_visual
.depthBits
;
1780 case GLX_STENCIL_SIZE
:
1781 *value
= v
->mesa_visual
.stencilBits
;
1783 case GLX_ACCUM_RED_SIZE
:
1784 *value
= v
->mesa_visual
.accumRedBits
;
1786 case GLX_ACCUM_GREEN_SIZE
:
1787 *value
= v
->mesa_visual
.accumGreenBits
;
1789 case GLX_ACCUM_BLUE_SIZE
:
1790 *value
= v
->mesa_visual
.accumBlueBits
;
1792 case GLX_ACCUM_ALPHA_SIZE
:
1793 *value
= v
->mesa_visual
.accumAlphaBits
;
1795 case GLX_RENDER_TYPE
:
1796 *value
= 0; /* XXX ??? */
1798 case GLX_DRAWABLE_TYPE
:
1799 *value
= GLX_PBUFFER_BIT
; /* XXX fix? */
1801 case GLX_X_RENDERABLE
:
1802 *value
= False
; /* XXX ??? */
1804 case GLX_X_VISUAL_TYPE
:
1805 #if defined(__cplusplus) || defined(c_plusplus)
1806 switch (v
->vishandle
->c_class
) {
1808 switch (v
->vishandle
->class) {
1811 *value
= GLX_GRAY_SCALE
;
1814 *value
= GLX_STATIC_GRAY
;
1817 *value
= GLX_STATIC_COLOR
;
1820 *value
= GLX_PSEUDO_COLOR
;
1823 *value
= GLX_TRUE_COLOR
;
1826 *value
= GLX_DIRECT_COLOR
;
1832 case GLX_CONFIG_CAVEAT
:
1833 *value
= 0; /* XXX ??? */
1835 case GLX_TRANSPARENT_TYPE
:
1836 if (v
->level
== 0) {
1838 *value
= GLX_NONE_EXT
;
1840 else if (v
->level
> 0) {
1842 if (v
->mesa_visual
.rgbMode
) {
1843 *value
= GLX_TRANSPARENT_RGB_EXT
;
1846 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1849 else if (v
->level
< 0) {
1851 *value
= GLX_NONE_EXT
;
1854 case GLX_TRANSPARENT_INDEX_VALUE
:
1855 *value
= transparent_pixel( v
);
1857 case GLX_TRANSPARENT_RED_VALUE
:
1858 *value
= 0; /* not implemented */
1860 case GLX_TRANSPARENT_GREEN_VALUE
:
1861 *value
= 0; /* not implemented */
1863 case GLX_TRANSPARENT_BLUE_VALUE
:
1864 *value
= 0; /* not implemented */
1866 case GLX_TRANSPARENT_ALPHA_VALUE
:
1867 *value
= 0; /* not implemented */
1869 case GLX_MAX_PBUFFER_WIDTH
:
1870 *value
= DisplayWidth(dpy
, v
->vishandle
->screen
);
1872 case GLX_MAX_PBUFFER_HEIGHT
:
1873 *value
= DisplayHeight(dpy
, v
->vishandle
->screen
);
1875 case GLX_MAX_PBUFFER_PIXELS
:
1876 *value
= DisplayWidth(dpy
, v
->vishandle
->screen
) *
1877 DisplayHeight(dpy
, v
->vishandle
->screen
);
1880 *value
= v
->vishandle
->visualid
;
1883 return GLX_BAD_ATTRIBUTE
;
1891 static GLXFBConfig
*
1892 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1894 /* Get list of all X visuals, create FBconfigs from them */
1903 static XVisualInfo
*
1904 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1906 if (dpy
&& config
) {
1907 XMesaVisual v
= (XMesaVisual
) config
;
1908 return v
->vishandle
;
1918 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1919 const int *attribList
)
1924 (void) attribList
; /* Ignored in GLX 1.3 */
1926 return win
; /* A hack for now */
1931 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1933 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
1935 XMesaDestroyBuffer(b
);
1936 /* don't destroy X window */
1942 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1943 const int *attribList
)
1945 XMesaVisual v
= (XMesaVisual
) config
;
1946 XVisualInfo
*visinfo
;
1952 (void) attribList
; /* Ignored in GLX 1.3 */
1954 if (!dpy
|| !config
|| !pixmap
)
1957 visinfo
= v
->vishandle
;
1959 v
= find_glx_visual( dpy
, visinfo
);
1961 v
= create_glx_visual( dpy
, visinfo
);
1963 /* unusable visual */
1968 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1978 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1980 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
1982 XMesaDestroyBuffer(b
);
1983 /* don't destroy X pixmap */
1989 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
1990 const int *attribList
)
1993 int width
= 0, height
= 0;
1994 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
1999 for (attrib
= attribList
; attrib
; attrib
++) {
2001 case GLX_PBUFFER_WIDTH
:
2002 width
= *(++attrib
);
2004 case GLX_PBUFFER_HEIGHT
:
2005 height
= *(++attrib
);
2007 case GLX_PRESERVED_CONTENTS
:
2008 preserveContents
= GL_TRUE
; /* ignored */
2010 case GLX_LARGEST_PBUFFER
:
2011 useLargest
= GL_TRUE
; /* ignored */
2018 if (width
== 0 || height
== 0)
2028 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2037 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2038 unsigned int *value
)
2043 switch (attribute
) {
2046 case GLX_PRESERVED_CONTENTS
:
2047 case GLX_LARGEST_PBUFFER
:
2048 case GLX_FBCONFIG_ID
:
2052 return; /* GLX_BAD_ATTRIBUTE? */
2058 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2059 int renderType
, GLXContext shareList
, Bool direct
)
2061 XMesaVisual v
= (XMesaVisual
) config
;
2063 if (!dpy
|| !config
||
2064 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2067 return Fake_glXCreateContext(dpy
, v
->vishandle
, shareList
, direct
);
2073 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2078 switch (attribute
) {
2079 case GLX_FBCONFIG_ID
:
2080 case GLX_RENDER_TYPE
:
2085 return GLX_BAD_ATTRIBUTE
;
2092 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2102 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2103 unsigned long *mask
)
2112 /*** GLX_SGI_swap_control ***/
2115 Fake_glXSwapIntervalSGI(int interval
)
2123 /*** GLX_SGI_video_sync ***/
2126 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2133 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2143 /*** GLX_SGI_make_current_read ***/
2146 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2148 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2153 Fake_glXGetCurrentReadDrawableSGI(void)
2160 /*** GLX_SGIX_video_source ***/
2163 static GLXVideoSourceSGIX
2164 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2176 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2185 /*** GLX_EXT_import_context ***/
2188 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2195 Fake_glXGetContextIDEXT(const GLXContext context
)
2202 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2210 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2221 /*** GLX_SGIX_fbconfig ***/
2224 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2233 static GLXFBConfigSGIX
*
2234 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2244 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2253 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2263 static XVisualInfo
*
2264 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2271 static GLXFBConfigSGIX
2272 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2281 /*** GLX_SGIX_pbuffer ***/
2283 static GLXPbufferSGIX
2284 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
, unsigned int width
, unsigned int height
, int *attrib_list
)
2295 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2302 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2312 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2320 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2329 /*** GLX_SGI_cushion ***/
2332 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2341 /*** GLX_SGIX_video_resize ***/
2344 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2354 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2367 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2380 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2393 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2404 /*** GLX_SGIX_dmbuffer **/
2406 #if defined(_DM_BUFFER_H_)
2408 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2419 /*** GLX_SGIX_swap_group ***/
2422 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2431 /*** GLX_SGIX_swap_barrier ***/
2434 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2442 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2452 /*** GLX_SUN_get_transparent_index ***/
2455 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2460 (void) pTransparent
;
2466 /*** GLX_MESA_release_buffers ***/
2469 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2470 * (a window or pixmap) prior to destroying the GLXDrawable.
2473 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2475 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2477 XMesaDestroyBuffer(b
);
2485 /*** GLX_MESA_set_3dfx_mode ***/
2488 Fake_glXSet3DfxModeMESA( int mode
)
2490 return XMesaSetFXmode( mode
);
2495 /*** AGP memory allocation ***/
2497 Fake_glXAllocateMemoryNV( GLsizei size
,
2498 GLfloat readFrequency
,
2499 GLfloat writeFrequency
,
2503 (void) readFrequency
;
2504 (void) writeFrequency
;
2511 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2518 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2519 struct _glxapi_table
*_mesa_GetGLXDispatchTable(void)
2521 static struct _glxapi_table glx
;
2523 /* be sure our dispatch table size <= libGL's table */
2525 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2527 assert(_glxapi_get_dispatch_table_size() >= size
);
2530 /* initialize the whole table to no-ops */
2531 _glxapi_set_no_op_table(&glx
);
2533 /* now initialize the table with the functions I implement */
2534 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2535 glx
.CopyContext
= Fake_glXCopyContext
;
2536 glx
.CreateContext
= Fake_glXCreateContext
;
2537 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2538 glx
.DestroyContext
= Fake_glXDestroyContext
;
2539 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2540 glx
.GetConfig
= Fake_glXGetConfig
;
2541 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2542 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2543 glx
.IsDirect
= Fake_glXIsDirect
;
2544 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2545 glx
.QueryExtension
= Fake_glXQueryExtension
;
2546 glx
.QueryVersion
= Fake_glXQueryVersion
;
2547 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2548 glx
.UseXFont
= Fake_glXUseXFont
;
2549 glx
.WaitGL
= Fake_glXWaitGL
;
2550 glx
.WaitX
= Fake_glXWaitX
;
2552 /*** GLX_VERSION_1_1 ***/
2553 glx
.GetClientString
= Fake_glXGetClientString
;
2554 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2555 glx
.QueryServerString
= Fake_glXQueryServerString
;
2557 /*** GLX_VERSION_1_2 ***/
2558 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2560 /*** GLX_VERSION_1_3 ***/
2561 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2562 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2563 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2564 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2565 glx
.CreateWindow
= Fake_glXCreateWindow
;
2566 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2567 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2568 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2569 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2570 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2571 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2572 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2573 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2574 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2575 glx
.QueryContext
= Fake_glXQueryContext
;
2576 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2577 glx
.SelectEvent
= Fake_glXSelectEvent
;
2579 /*** GLX_SGI_swap_control ***/
2580 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2582 /*** GLX_SGI_video_sync ***/
2583 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2584 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2586 /*** GLX_SGI_make_current_read ***/
2587 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2588 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2590 /*** GLX_SGIX_video_source ***/
2592 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2593 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2596 /*** GLX_EXT_import_context ***/
2597 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2598 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2599 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2600 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2601 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2603 /*** GLX_SGIX_fbconfig ***/
2604 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2605 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2606 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2607 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
2608 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
2609 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
2611 /*** GLX_SGIX_pbuffer ***/
2612 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
2613 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
2614 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
2615 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
2616 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
2618 /*** GLX_SGI_cushion ***/
2619 glx
.CushionSGI
= Fake_glXCushionSGI
;
2621 /*** GLX_SGIX_video_resize ***/
2622 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
2623 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
2624 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
2625 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
2626 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
2628 /*** GLX_SGIX_dmbuffer **/
2629 #if defined(_DM_BUFFER_H_)
2630 glx
.AssociateDMPbufferSGIX
= NULL
;
2633 /*** GLX_SGIX_swap_group ***/
2634 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
2636 /*** GLX_SGIX_swap_barrier ***/
2637 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
2638 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
2640 /*** GLX_SUN_get_transparent_index ***/
2641 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
2643 /*** GLX_MESA_copy_sub_buffer ***/
2644 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
2646 /*** GLX_MESA_release_buffers ***/
2647 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
2649 /*** GLX_MESA_pixmap_colormap ***/
2650 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
2652 /*** GLX_MESA_set_3dfx_mode ***/
2653 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
2655 /*** GLX AGP memory allocation ***/
2656 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
2657 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;