2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
28 * to run on X servers which do not have the real GLX extension.
30 * Thanks to the contributors:
32 * Initial version: Philip Brown (phil@bolthole.com)
33 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
34 * Further visual-handling refinements: Wolfram Gloger
35 * (wmglo@Dent.MED.Uni-Muenchen.DE).
38 * Don't be fooled, stereo isn't supported yet.
43 #include "glxheader.h"
54 #include "state_tracker/st_context.h"
55 #include "state_tracker/st_public.h"
59 #define _mesa_sprintf sprintf
62 /* This indicates the client-side GLX API and GLX encoder version. */
63 #define CLIENT_MAJOR_VERSION 1
64 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
66 /* This indicates the server-side GLX decoder version.
67 * GLX 1.4 indicates OpenGL 1.3 support
69 #define SERVER_MAJOR_VERSION 1
70 #define SERVER_MINOR_VERSION 4
72 /* This is appended onto the glXGetClient/ServerString version strings. */
73 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
75 /* Who implemented this GLX? */
76 #define VENDOR "Brian Paul"
79 "GLX_MESA_set_3dfx_mode " \
80 "GLX_MESA_copy_sub_buffer " \
81 "GLX_MESA_pixmap_colormap " \
82 "GLX_MESA_release_buffers " \
83 "GLX_ARB_get_proc_address " \
84 "GLX_EXT_texture_from_pixmap " \
85 "GLX_EXT_visual_info " \
86 "GLX_EXT_visual_rating " \
87 /*"GLX_SGI_video_sync "*/ \
88 "GLX_SGIX_fbconfig " \
92 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
94 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
97 * We really just need this structure in order to make the libGL functions
98 * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
101 struct fake_glx_context
{
102 __GLXcontext glxContext
; /* this MUST be first! */
103 XMesaContext xmesaContext
;
108 /**********************************************************************/
109 /*** GLX Visual Code ***/
110 /**********************************************************************/
115 static XMesaVisual
*VisualTable
= NULL
;
116 static int NumVisuals
= 0;
120 * This struct and some code fragments borrowed
121 * from Mark Kilgard's GLUT library.
123 typedef struct _OverlayInfo
{
124 /* Avoid 64-bit portability problems by being careful to use
125 longs due to the way XGetWindowProperty is specified. Note
126 that these parameters are passed as CARD32s over X
128 unsigned long overlay_visual
;
129 long transparent_type
;
136 /* Macro to handle c_class vs class field name in XVisualInfo struct */
137 #if defined(__cplusplus) || defined(c_plusplus)
138 #define CLASS c_class
146 * Test if the given XVisualInfo is usable for Mesa rendering.
149 is_usable_visual( XVisualInfo
*vinfo
)
151 switch (vinfo
->CLASS
) {
154 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
158 /* Any StaticColor/PseudoColor visual of at least 4 bits */
159 if (vinfo
->depth
>=4) {
167 /* Any depth of TrueColor or DirectColor works in RGB mode */
170 /* This should never happen */
178 * Get an array OverlayInfo records for specified screen.
179 * \param dpy the display
180 * \param screen screen number
181 * \param numOverlays returns numver of OverlayInfo records
182 * \return pointer to OverlayInfo array, free with XFree()
185 GetOverlayInfo(Display
*dpy
, int screen
, int *numOverlays
)
187 Atom overlayVisualsAtom
;
190 unsigned char *ovInfo
;
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
, screen
),
204 overlayVisualsAtom
, 0L, (long) 10000, False
,
205 overlayVisualsAtom
, &actualType
, &actualFormat
,
206 &sizeData
, &bytesLeft
,
209 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
210 actualFormat
!= 32 || sizeData
< 4) {
211 /* something went wrong */
212 XFree((void *) ovInfo
);
217 *numOverlays
= sizeData
/ 4;
218 return (OverlayInfo
*) ovInfo
;
224 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
225 * Input: dpy - the X display
226 * vinfo - the XVisualInfo to test
227 * Return: level of the visual:
229 * >0 = overlay planes
230 * <0 = underlay planes
233 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
235 OverlayInfo
*overlay_info
;
236 int numOverlaysPerScreen
, i
;
238 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
243 /* search the overlay visual list for the visual ID of interest */
244 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
245 const OverlayInfo
*ov
= overlay_info
+ i
;
246 if (ov
->overlay_visual
== vinfo
->visualid
) {
247 /* found the visual */
248 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
249 int level
= ov
->layer
;
250 XFree((void *) overlay_info
);
254 XFree((void *) overlay_info
);
260 /* The visual ID was not found in the overlay list. */
261 XFree((void *) overlay_info
);
269 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
270 * configuration in our list of GLX visuals.
273 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
274 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
275 GLboolean stereoFlag
,
276 GLint depth_size
, GLint stencil_size
,
277 GLint accumRedSize
, GLint accumGreenSize
,
278 GLint accumBlueSize
, GLint accumAlphaSize
,
279 GLint level
, GLint numAuxBuffers
)
281 GLboolean ximageFlag
= GL_TRUE
;
284 GLboolean comparePointers
;
287 /* Check if the MESA_BACK_BUFFER env var is set */
288 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
290 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
291 ximageFlag
= GL_FALSE
;
293 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
294 ximageFlag
= GL_TRUE
;
297 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
303 /* stereo not supported */
307 if (stencil_size
> 0 && depth_size
> 0)
310 /* Comparing IDs uses less memory but sometimes fails. */
311 /* XXX revisit this after 3.0 is finished. */
312 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
313 comparePointers
= GL_TRUE
;
315 comparePointers
= GL_FALSE
;
317 /* Force the visual to have an alpha channel */
318 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
321 /* First check if a matching visual is already in the list */
322 for (i
=0; i
<NumVisuals
; i
++) {
323 XMesaVisual v
= VisualTable
[i
];
324 if (v
->display
== dpy
325 && v
->mesa_visual
.level
== level
326 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
327 && v
->ximage_flag
== ximageFlag
328 && v
->mesa_visual
.rgbMode
== rgbFlag
329 && v
->mesa_visual
.doubleBufferMode
== dbFlag
330 && v
->mesa_visual
.stereoMode
== stereoFlag
331 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
332 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
333 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
334 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
335 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
336 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
337 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
338 /* now either compare XVisualInfo pointers or visual IDs */
339 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
340 || (comparePointers
&& v
->vishandle
== vinfo
)) {
346 /* Create a new visual and add it to the list. */
348 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
349 stereoFlag
, ximageFlag
,
350 depth_size
, stencil_size
,
351 accumRedSize
, accumBlueSize
,
352 accumBlueSize
, accumAlphaSize
, 0, level
,
355 /* Save a copy of the pointer now so we can find this visual again
356 * if we need to search for it in find_glx_visual().
358 xmvis
->vishandle
= vinfo
;
359 /* Allocate more space for additional visual */
360 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
361 sizeof(XMesaVisual
) * NumVisuals
,
362 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
363 /* add xmvis to the list */
364 VisualTable
[NumVisuals
] = xmvis
;
366 /* XXX minor hack, because XMesaCreateVisual doesn't support an
367 * aux buffers parameter.
369 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
376 * Return the default number of bits for the Z buffer.
377 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
378 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
379 * XXX probably do the same thing for stencil, accum, etc.
382 default_depth_bits(void)
385 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
387 zBits
= _mesa_atoi(zEnv
);
389 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
394 default_alpha_bits(void)
397 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
399 aBits
= _mesa_atoi(aEnv
);
406 default_accum_bits(void)
414 * Create a GLX visual from a regular XVisualInfo.
415 * This is called when Fake GLX is given an XVisualInfo which wasn't
416 * returned by glXChooseVisual. Since this is the first time we're
417 * considering this visual we'll take a guess at reasonable values
418 * for depth buffer size, stencil size, accum size, etc.
419 * This is the best we can do with a client-side emulation of GLX.
422 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
425 GLint zBits
= default_depth_bits();
426 GLint accBits
= default_accum_bits();
427 GLboolean alphaFlag
= default_alpha_bits() > 0;
429 vislevel
= level_of_visual( dpy
, visinfo
);
431 /* Configure this visual as a CI, single-buffered overlay */
432 return save_glx_visual( dpy
, visinfo
,
434 GL_FALSE
, /* alpha */
435 GL_FALSE
, /* double */
436 GL_FALSE
, /* stereo */
438 0, /* stencil bits */
439 0,0,0,0, /* accum bits */
440 vislevel
, /* level */
444 else if (is_usable_visual( visinfo
)) {
445 if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
446 /* Configure this visual as a COLOR INDEX visual. */
447 return save_glx_visual( dpy
, visinfo
,
449 GL_FALSE
, /* alpha */
450 GL_TRUE
, /* double */
451 GL_FALSE
, /* stereo */
454 0, 0, 0, 0, /* accum bits */
460 /* Configure this visual as RGB, double-buffered, depth-buffered. */
461 /* This is surely wrong for some people's needs but what else */
462 /* can be done? They should use glXChooseVisual(). */
463 return save_glx_visual( dpy
, visinfo
,
465 alphaFlag
, /* alpha */
466 GL_TRUE
, /* double */
467 GL_FALSE
, /* stereo */
480 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
488 * Find the GLX visual associated with an XVisualInfo.
491 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
495 /* try to match visual id */
496 for (i
=0;i
<NumVisuals
;i
++) {
497 if (VisualTable
[i
]->display
==dpy
498 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
499 return VisualTable
[i
];
503 /* if that fails, try to match pointers */
504 for (i
=0;i
<NumVisuals
;i
++) {
505 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
506 return VisualTable
[i
];
516 * Return the transparent pixel value for a GLX visual.
517 * Input: glxvis - the glx_visual
518 * Return: a pixel value or -1 if no transparent pixel
521 transparent_pixel( XMesaVisual glxvis
)
523 Display
*dpy
= glxvis
->display
;
524 XVisualInfo
*vinfo
= glxvis
->visinfo
;
525 OverlayInfo
*overlay_info
;
526 int numOverlaysPerScreen
, i
;
528 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
533 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
534 const OverlayInfo
*ov
= overlay_info
+ i
;
535 if (ov
->overlay_visual
== vinfo
->visualid
) {
537 if (ov
->transparent_type
== 0) {
538 /* type 0 indicates no transparency */
539 XFree((void *) overlay_info
);
543 /* ov->value is the transparent pixel */
544 XFree((void *) overlay_info
);
550 /* The visual ID was not found in the overlay list. */
551 XFree((void *) overlay_info
);
558 * Try to get an X visual which matches the given arguments.
561 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
563 XVisualInfo temp
, *vis
;
566 unsigned int default_depth
;
569 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
574 default_depth
= DefaultDepth(dpy
,scr
);
575 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
577 if (depth
==default_depth
&& xclass
==default_class
) {
578 /* try to get root window's visual */
579 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
580 mask
|= VisualIDMask
;
583 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
585 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
586 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
587 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
589 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
590 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
591 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
592 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
607 * Retrieve the value of the given environment variable and find
608 * the X visual which matches it.
609 * Input: dpy - the display
610 * screen - the screen number
611 * varname - the name of the environment variable
612 * Return: an XVisualInfo pointer to NULL if error.
615 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
617 char value
[100], type
[100];
618 int depth
, xclass
= -1;
621 if (!_mesa_getenv( varname
)) {
625 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
628 sscanf( value
, "%s %d", type
, &depth
);
630 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
631 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
632 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
633 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
634 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
635 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
637 if (xclass
>-1 && depth
>0) {
638 vis
= get_visual( dpy
, scr
, depth
, xclass
);
644 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
653 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
654 * Input: dpy, screen - X display and screen number
655 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
656 * min_depth - minimum visual depth
657 * preferred_class - preferred GLX visual class or DONT_CARE
658 * Return: pointer to an XVisualInfo or NULL.
661 choose_x_visual( Display
*dpy
, int screen
, GLboolean rgba
, int min_depth
,
662 int preferred_class
)
665 int xclass
, visclass
= 0;
669 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
670 /* First see if the MESA_RGB_VISUAL env var is defined */
671 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
675 /* Otherwise, search for a suitable visual */
676 if (preferred_class
==DONT_CARE
) {
677 for (xclass
=0;xclass
<6;xclass
++) {
679 case 0: visclass
= TrueColor
; break;
680 case 1: visclass
= DirectColor
; break;
681 case 2: visclass
= PseudoColor
; break;
682 case 3: visclass
= StaticColor
; break;
683 case 4: visclass
= GrayScale
; break;
684 case 5: visclass
= StaticGray
; break;
687 /* start with shallowest */
688 for (depth
=0;depth
<=32;depth
++) {
689 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
690 /* Special case: try to get 8-bit PseudoColor before */
691 /* 8-bit TrueColor */
692 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
697 vis
= get_visual( dpy
, screen
, depth
, visclass
);
704 /* start with deepest */
705 for (depth
=32;depth
>=min_depth
;depth
--) {
706 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
707 /* Special case: try to get 8-bit PseudoColor before */
708 /* 8-bit TrueColor */
709 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
714 vis
= get_visual( dpy
, screen
, depth
, visclass
);
723 /* search for a specific visual class */
724 switch (preferred_class
) {
725 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
726 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
727 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
728 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
729 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
730 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
731 default: return NULL
;
734 /* start with shallowest */
735 for (depth
=0;depth
<=32;depth
++) {
736 vis
= get_visual( dpy
, screen
, depth
, visclass
);
743 /* start with deepest */
744 for (depth
=32;depth
>=min_depth
;depth
--) {
745 vis
= get_visual( dpy
, screen
, depth
, visclass
);
754 /* First see if the MESA_CI_VISUAL env var is defined */
755 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
759 /* Otherwise, search for a suitable visual, starting with shallowest */
760 if (preferred_class
==DONT_CARE
) {
761 for (xclass
=0;xclass
<4;xclass
++) {
763 case 0: visclass
= PseudoColor
; break;
764 case 1: visclass
= StaticColor
; break;
765 case 2: visclass
= GrayScale
; break;
766 case 3: visclass
= StaticGray
; break;
768 /* try 8-bit up through 16-bit */
769 for (depth
=8;depth
<=16;depth
++) {
770 vis
= get_visual( dpy
, screen
, depth
, visclass
);
775 /* try min_depth up to 8-bit */
776 for (depth
=min_depth
;depth
<8;depth
++) {
777 vis
= get_visual( dpy
, screen
, depth
, visclass
);
785 /* search for a specific visual class */
786 switch (preferred_class
) {
787 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
788 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
789 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
790 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
791 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
792 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
793 default: return NULL
;
795 /* try 8-bit up through 16-bit */
796 for (depth
=8;depth
<=16;depth
++) {
797 vis
= get_visual( dpy
, screen
, depth
, visclass
);
802 /* try min_depth up to 8-bit */
803 for (depth
=min_depth
;depth
<8;depth
++) {
804 vis
= get_visual( dpy
, screen
, depth
, visclass
);
812 /* didn't find a visual */
819 * Find the deepest X over/underlay visual of at least min_depth.
820 * Input: dpy, screen - X display and screen number
821 * level - the over/underlay level
822 * trans_type - transparent pixel type: GLX_NONE_EXT,
823 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
825 * trans_value - transparent pixel value or DONT_CARE
826 * min_depth - minimum visual depth
827 * preferred_class - preferred GLX visual class or DONT_CARE
828 * Return: pointer to an XVisualInfo or NULL.
831 choose_x_overlay_visual( Display
*dpy
, int scr
, GLboolean rgbFlag
,
832 int level
, int trans_type
, int trans_value
,
833 int min_depth
, int preferred_class
)
835 OverlayInfo
*overlay_info
;
836 int numOverlaysPerScreen
;
838 XVisualInfo
*deepvis
;
841 /*DEBUG int tt, tv; */
843 switch (preferred_class
) {
844 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
845 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
846 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
847 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
848 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
849 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
850 default: preferred_class
= DONT_CARE
;
853 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
858 /* Search for the deepest overlay which satisifies all criteria. */
862 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
863 const OverlayInfo
*ov
= overlay_info
+ i
;
864 XVisualInfo
*vislist
, vistemplate
;
867 if (ov
->layer
!=level
) {
868 /* failed overlay level criteria */
871 if (!(trans_type
==DONT_CARE
872 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
873 && ov
->transparent_type
>0)
874 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
875 /* failed transparent pixel type criteria */
878 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
879 /* failed transparent pixel value criteria */
883 /* get XVisualInfo and check the depth */
884 vistemplate
.visualid
= ov
->overlay_visual
;
885 vistemplate
.screen
= scr
;
886 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
887 &vistemplate
, &count
);
890 /* something went wrong */
893 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
894 /* wrong visual class */
898 /* if RGB was requested, make sure we have True/DirectColor */
899 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
900 && vislist
->CLASS
!= DirectColor
)
903 /* if CI was requested, make sure we have a color indexed visual */
905 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
908 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
909 /* YES! found a satisfactory visual */
913 deepest
= vislist
->depth
;
915 /* DEBUG tt = ov->transparent_type;*/
916 /* DEBUG tv = ov->value; */
922 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
923 deepvis->visualid, level, deepvis->depth, tt, tv );
930 /**********************************************************************/
931 /*** Display-related functions ***/
932 /**********************************************************************/
936 * Free all XMesaVisuals which are associated with the given display.
939 destroy_visuals_on_display(Display
*dpy
)
942 for (i
= 0; i
< NumVisuals
; i
++) {
943 if (VisualTable
[i
]->display
== dpy
) {
944 /* remove this visual */
946 free(VisualTable
[i
]);
947 for (j
= i
; j
< NumVisuals
- 1; j
++)
948 VisualTable
[j
] = VisualTable
[j
+ 1];
956 * Called from XCloseDisplay() to let us free our display-related data.
959 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
961 destroy_visuals_on_display(dpy
);
962 xmesa_destroy_buffers_on_display(dpy
);
968 * Look for the named extension on given display and return a pointer
969 * to the _XExtension data, or NULL if extension not found.
972 lookup_extension(Display
*dpy
, const char *extName
)
975 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
976 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
985 * Whenever we're given a new Display pointer, call this function to
986 * register our close_display_callback function.
989 register_with_display(Display
*dpy
)
991 const char *extName
= "MesaGLX";
994 ext
= lookup_extension(dpy
, extName
);
996 XExtCodes
*c
= XAddExtension(dpy
);
997 ext
= dpy
->ext_procs
; /* new extension is at head of list */
998 assert(c
->extension
== ext
->codes
.extension
);
999 ext
->name
= _mesa_strdup(extName
);
1000 ext
->close_display
= close_display_callback
;
1005 /**********************************************************************/
1006 /*** Begin Fake GLX API Functions ***/
1007 /**********************************************************************/
1011 * Helper used by glXChooseVisual and glXChooseFBConfig.
1012 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
1014 * In either case, the attribute list is terminated with the value 'None'.
1017 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
1019 const GLboolean rgbModeDefault
= fbConfig
;
1020 const int *parselist
;
1023 int min_red
=0, min_green
=0, min_blue
=0;
1024 GLboolean rgb_flag
= rgbModeDefault
;
1025 GLboolean alpha_flag
= GL_FALSE
;
1026 GLboolean double_flag
= GL_FALSE
;
1027 GLboolean stereo_flag
= GL_FALSE
;
1028 GLint depth_size
= 0;
1029 GLint stencil_size
= 0;
1030 GLint accumRedSize
= 0;
1031 GLint accumGreenSize
= 0;
1032 GLint accumBlueSize
= 0;
1033 GLint accumAlphaSize
= 0;
1035 int visual_type
= DONT_CARE
;
1036 int trans_type
= DONT_CARE
;
1037 int trans_value
= DONT_CARE
;
1038 GLint caveat
= DONT_CARE
;
1039 XMesaVisual xmvis
= NULL
;
1040 int desiredVisualID
= -1;
1045 while (*parselist
) {
1047 switch (*parselist
) {
1058 case GLX_BUFFER_SIZE
:
1060 min_ci
= *parselist
++;
1064 level
= *parselist
++;
1076 case GLX_DOUBLEBUFFER
:
1079 double_flag
= *parselist
++;
1082 double_flag
= GL_TRUE
;
1088 stereo_flag
= *parselist
++;
1091 stereo_flag
= GL_TRUE
;
1094 case GLX_AUX_BUFFERS
:
1096 numAux
= *parselist
++;
1097 if (numAux
> MAX_AUX_BUFFERS
)
1102 min_red
= *parselist
++;
1104 case GLX_GREEN_SIZE
:
1106 min_green
= *parselist
++;
1110 min_blue
= *parselist
++;
1112 case GLX_ALPHA_SIZE
:
1115 GLint size
= *parselist
++;
1116 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
1119 case GLX_DEPTH_SIZE
:
1121 depth_size
= *parselist
++;
1123 case GLX_STENCIL_SIZE
:
1125 stencil_size
= *parselist
++;
1127 case GLX_ACCUM_RED_SIZE
:
1130 GLint size
= *parselist
++;
1131 accumRedSize
= MAX2( accumRedSize
, size
);
1134 case GLX_ACCUM_GREEN_SIZE
:
1137 GLint size
= *parselist
++;
1138 accumGreenSize
= MAX2( accumGreenSize
, size
);
1141 case GLX_ACCUM_BLUE_SIZE
:
1144 GLint size
= *parselist
++;
1145 accumBlueSize
= MAX2( accumBlueSize
, size
);
1148 case GLX_ACCUM_ALPHA_SIZE
:
1151 GLint size
= *parselist
++;
1152 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1157 * GLX_EXT_visual_info extension
1159 case GLX_X_VISUAL_TYPE_EXT
:
1161 visual_type
= *parselist
++;
1163 case GLX_TRANSPARENT_TYPE_EXT
:
1165 trans_type
= *parselist
++;
1167 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1169 trans_value
= *parselist
++;
1171 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1172 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1173 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1174 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1181 * GLX_EXT_visual_info extension
1183 case GLX_VISUAL_CAVEAT_EXT
:
1185 caveat
= *parselist
++; /* ignored for now */
1189 * GLX_ARB_multisample
1191 case GLX_SAMPLE_BUFFERS_ARB
:
1192 /* ms not supported */
1194 case GLX_SAMPLES_ARB
:
1195 /* ms not supported */
1201 case GLX_RENDER_TYPE
:
1205 if (*parselist
== GLX_RGBA_BIT
) {
1208 else if (*parselist
== GLX_COLOR_INDEX_BIT
) {
1209 rgb_flag
= GL_FALSE
;
1211 else if (*parselist
== 0) {
1216 case GLX_DRAWABLE_TYPE
:
1220 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1221 return NULL
; /* bad bit */
1225 case GLX_FBCONFIG_ID
:
1229 desiredVisualID
= *parselist
++;
1231 case GLX_X_RENDERABLE
:
1238 #ifdef GLX_EXT_texture_from_pixmap
1239 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1240 parselist
++; /*skip*/
1242 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1243 parselist
++; /*skip*/
1245 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1246 parselist
++; /*skip*/
1248 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1250 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1251 GLX_TEXTURE_2D_BIT_EXT
|
1252 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1257 case GLX_Y_INVERTED_EXT
:
1258 parselist
++; /*skip*/
1267 /* undefined attribute */
1268 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1277 * Since we're only simulating the GLX extension this function will never
1278 * find any real GL visuals. Instead, all we can do is try to find an RGB
1279 * or CI visual of appropriate depth. Other requested attributes such as
1280 * double buffering, depth buffer, etc. will be associated with the X
1281 * visual and stored in the VisualTable[].
1283 if (desiredVisualID
!= -1) {
1284 /* try to get a specific visual, by visualID */
1287 temp
.visualid
= desiredVisualID
;
1288 temp
.screen
= screen
;
1289 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1291 /* give the visual some useful GLX attributes */
1292 double_flag
= GL_TRUE
;
1295 depth_size
= default_depth_bits();
1296 stencil_size
= STENCIL_BITS
;
1300 else if (level
==0) {
1301 /* normal color planes */
1303 /* Get an RGB visual */
1304 int min_rgb
= min_red
+ min_green
+ min_blue
;
1305 if (min_rgb
>1 && min_rgb
<8) {
1306 /* a special case to be sure we can get a monochrome visual */
1309 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1312 /* Get a color index visual */
1313 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1314 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1318 /* over/underlay planes */
1321 int min_rgb
= min_red
+ min_green
+ min_blue
;
1322 if (min_rgb
>1 && min_rgb
<8) {
1323 /* a special case to be sure we can get a monochrome visual */
1326 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1327 trans_type
, trans_value
, min_rgb
, visual_type
);
1330 /* color index overlay */
1331 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1332 trans_type
, trans_value
, min_ci
, visual_type
);
1337 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1338 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1339 * largest depth buffer size, which is 32bits/value. Instead, we
1340 * return 16 to maintain performance with earlier versions of Mesa.
1342 if (stencil_size
> 0)
1343 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1344 else if (depth_size
> 24)
1346 else if (depth_size
> 16)
1348 else if (depth_size
> 0) {
1349 depth_size
= default_depth_bits();
1353 alpha_flag
= default_alpha_bits() > 0;
1356 /* we only support one size of stencil and accum buffers. */
1357 if (stencil_size
> 0)
1358 stencil_size
= STENCIL_BITS
;
1359 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1360 accumAlphaSize
> 0) {
1363 accumBlueSize
= default_accum_bits();
1364 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1367 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1368 stereo_flag
, depth_size
, stencil_size
,
1369 accumRedSize
, accumGreenSize
,
1370 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1377 static XVisualInfo
*
1378 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1382 /* register ourselves as an extension on this display */
1383 register_with_display(dpy
);
1385 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1388 return xmvis
->vishandle
;
1390 /* create a new vishandle - the cached one may be stale */
1391 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1392 if (xmvis
->vishandle
) {
1393 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1395 return xmvis
->vishandle
;
1404 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1405 GLXContext share_list
, Bool direct
)
1408 struct fake_glx_context
*glxCtx
;
1409 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1411 if (!dpy
|| !visinfo
)
1414 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1418 /* deallocate unused windows/buffers */
1420 XMesaGarbageCollect();
1423 xmvis
= find_glx_visual( dpy
, visinfo
);
1425 /* This visual wasn't found with glXChooseVisual() */
1426 xmvis
= create_glx_visual( dpy
, visinfo
);
1428 /* unusable visual */
1434 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1435 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1436 if (!glxCtx
->xmesaContext
) {
1441 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
1442 glxCtx
->glxContext
.currentDpy
= dpy
;
1443 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1445 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1447 return (GLXContext
) glxCtx
;
1451 /* XXX these may have to be removed due to thread-safety issues. */
1452 static GLXContext MakeCurrent_PrevContext
= 0;
1453 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1454 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1455 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1456 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1459 /* GLX 1.3 and later */
1461 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1462 GLXDrawable read
, GLXContext ctx
)
1464 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1465 static boolean firsttime
= 1, no_rast
= 0;
1468 no_rast
= getenv("SP_NO_RAST") != NULL
;
1473 if (ctx
&& draw
&& read
) {
1474 XMesaBuffer drawBuffer
, readBuffer
;
1475 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1477 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1478 if (ctx
== MakeCurrent_PrevContext
1479 && draw
== MakeCurrent_PrevDrawable
) {
1480 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1483 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1486 /* drawable must be a new window! */
1487 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1489 /* Out of memory, or context/drawable depth mismatch */
1493 FXcreateContext( xmctx
->xm_visual
, draw
, xmctx
, drawBuffer
);
1497 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1498 if (ctx
== MakeCurrent_PrevContext
1499 && read
== MakeCurrent_PrevReadable
) {
1500 readBuffer
= MakeCurrent_PrevReadBuffer
;
1503 readBuffer
= XMesaFindBuffer( dpy
, read
);
1506 /* drawable must be a new window! */
1507 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1509 /* Out of memory, or context/drawable depth mismatch */
1513 FXcreateContext( xmctx
->xm_visual
, read
, xmctx
, readBuffer
);
1518 MakeCurrent_PrevContext
== ctx
&&
1519 MakeCurrent_PrevDrawable
== draw
&&
1520 MakeCurrent_PrevReadable
== read
&&
1521 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1522 MakeCurrent_PrevReadBuffer
== readBuffer
)
1525 MakeCurrent_PrevContext
= ctx
;
1526 MakeCurrent_PrevDrawable
= draw
;
1527 MakeCurrent_PrevReadable
= read
;
1528 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1529 MakeCurrent_PrevReadBuffer
= readBuffer
;
1531 /* Now make current! */
1532 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1533 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1534 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1535 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1542 else if (!ctx
&& !draw
&& !read
) {
1543 /* release current context w/out assigning new one. */
1544 XMesaMakeCurrent( NULL
, NULL
);
1545 MakeCurrent_PrevContext
= 0;
1546 MakeCurrent_PrevDrawable
= 0;
1547 MakeCurrent_PrevReadable
= 0;
1548 MakeCurrent_PrevDrawBuffer
= 0;
1549 MakeCurrent_PrevReadBuffer
= 0;
1553 /* The args must either all be non-zero or all zero.
1562 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1564 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1569 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1574 v
= find_glx_visual( dpy
, visinfo
);
1576 v
= create_glx_visual( dpy
, visinfo
);
1578 /* unusable visual */
1583 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1591 /*** GLX_MESA_pixmap_colormap ***/
1594 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1595 Pixmap pixmap
, Colormap cmap
)
1600 v
= find_glx_visual( dpy
, visinfo
);
1602 v
= create_glx_visual( dpy
, visinfo
);
1604 /* unusable visual */
1609 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1618 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1620 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1622 XMesaDestroyBuffer(b
);
1624 else if (_mesa_getenv("MESA_DEBUG")) {
1625 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1631 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1632 unsigned long mask
)
1634 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1635 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1636 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1637 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1639 if (MakeCurrent_PrevContext
== src
) {
1642 st_copy_context_state( xm_src
->st
, xm_dst
->st
, (GLuint
) mask
);
1647 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1649 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1657 extern void _kw_ungrab_all( Display
*dpy
);
1658 void _kw_ungrab_all( Display
*dpy
)
1660 XUngrabPointer( dpy
, CurrentTime
);
1661 XUngrabKeyboard( dpy
, CurrentTime
);
1666 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1668 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1670 MakeCurrent_PrevContext
= 0;
1671 MakeCurrent_PrevDrawable
= 0;
1672 MakeCurrent_PrevReadable
= 0;
1673 MakeCurrent_PrevDrawBuffer
= 0;
1674 MakeCurrent_PrevReadBuffer
= 0;
1675 XMesaDestroyContext( glxCtx
->xmesaContext
);
1676 XMesaGarbageCollect();
1682 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1692 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1694 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1695 static boolean firsttime
= 1, no_rast
= 0;
1698 no_rast
= getenv("SP_NO_RAST") != NULL
;
1706 XMesaSwapBuffers(buffer
);
1708 else if (_mesa_getenv("MESA_DEBUG")) {
1709 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1716 /*** GLX_MESA_copy_sub_buffer ***/
1719 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1720 int x
, int y
, int width
, int height
)
1722 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1724 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1726 else if (_mesa_getenv("MESA_DEBUG")) {
1727 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1733 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1736 /* Return GLX version, not Mesa version */
1737 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1738 *maj
= CLIENT_MAJOR_VERSION
;
1739 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1745 * Query the GLX attributes of the given XVisualInfo.
1748 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1754 return GLX_BAD_ATTRIBUTE
;
1755 *value
= (int) True
;
1757 case GLX_BUFFER_SIZE
:
1758 *value
= xmvis
->visinfo
->depth
;
1761 *value
= xmvis
->mesa_visual
.level
;
1765 return GLX_BAD_ATTRIBUTE
;
1766 if (xmvis
->mesa_visual
.rgbMode
) {
1773 case GLX_DOUBLEBUFFER
:
1774 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1777 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1779 case GLX_AUX_BUFFERS
:
1780 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1783 *value
= xmvis
->mesa_visual
.redBits
;
1785 case GLX_GREEN_SIZE
:
1786 *value
= xmvis
->mesa_visual
.greenBits
;
1789 *value
= xmvis
->mesa_visual
.blueBits
;
1791 case GLX_ALPHA_SIZE
:
1792 *value
= xmvis
->mesa_visual
.alphaBits
;
1794 case GLX_DEPTH_SIZE
:
1795 *value
= xmvis
->mesa_visual
.depthBits
;
1797 case GLX_STENCIL_SIZE
:
1798 *value
= xmvis
->mesa_visual
.stencilBits
;
1800 case GLX_ACCUM_RED_SIZE
:
1801 *value
= xmvis
->mesa_visual
.accumRedBits
;
1803 case GLX_ACCUM_GREEN_SIZE
:
1804 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1806 case GLX_ACCUM_BLUE_SIZE
:
1807 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1809 case GLX_ACCUM_ALPHA_SIZE
:
1810 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1814 * GLX_EXT_visual_info extension
1816 case GLX_X_VISUAL_TYPE_EXT
:
1817 switch (xmvis
->visinfo
->CLASS
) {
1818 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1819 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1820 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1821 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1822 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1823 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1826 case GLX_TRANSPARENT_TYPE_EXT
:
1827 if (xmvis
->mesa_visual
.level
==0) {
1829 *value
= GLX_NONE_EXT
;
1831 else if (xmvis
->mesa_visual
.level
>0) {
1833 if (xmvis
->mesa_visual
.rgbMode
) {
1834 *value
= GLX_TRANSPARENT_RGB_EXT
;
1837 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1840 else if (xmvis
->mesa_visual
.level
<0) {
1842 *value
= GLX_NONE_EXT
;
1845 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1847 int pixel
= transparent_pixel( xmvis
);
1851 /* else undefined */
1854 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1857 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1860 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1863 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1868 * GLX_EXT_visual_info extension
1870 case GLX_VISUAL_CAVEAT_EXT
:
1871 /* test for zero, just in case */
1872 if (xmvis
->mesa_visual
.visualRating
> 0)
1873 *value
= xmvis
->mesa_visual
.visualRating
;
1875 *value
= GLX_NONE_EXT
;
1879 * GLX_ARB_multisample
1881 case GLX_SAMPLE_BUFFERS_ARB
:
1884 case GLX_SAMPLES_ARB
:
1891 case GLX_SCREEN_EXT
:
1893 return GLX_BAD_ATTRIBUTE
;
1894 *value
= xmvis
->visinfo
->screen
;
1896 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1898 return GLX_BAD_ATTRIBUTE
;
1899 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1901 case GLX_RENDER_TYPE_SGIX
:
1903 return GLX_BAD_ATTRIBUTE
;
1904 if (xmvis
->mesa_visual
.rgbMode
)
1905 *value
= GLX_RGBA_BIT
;
1907 *value
= GLX_COLOR_INDEX_BIT
;
1909 case GLX_X_RENDERABLE_SGIX
:
1911 return GLX_BAD_ATTRIBUTE
;
1912 *value
= True
; /* XXX really? */
1914 case GLX_FBCONFIG_ID_SGIX
:
1916 return GLX_BAD_ATTRIBUTE
;
1917 *value
= xmvis
->visinfo
->visualid
;
1919 case GLX_MAX_PBUFFER_WIDTH
:
1921 return GLX_BAD_ATTRIBUTE
;
1922 /* XXX or MAX_WIDTH? */
1923 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1925 case GLX_MAX_PBUFFER_HEIGHT
:
1927 return GLX_BAD_ATTRIBUTE
;
1928 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1930 case GLX_MAX_PBUFFER_PIXELS
:
1932 return GLX_BAD_ATTRIBUTE
;
1933 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1934 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1938 return GLX_BAD_ATTRIBUTE
;
1939 *value
= xmvis
->visinfo
->visualid
;
1942 #ifdef GLX_EXT_texture_from_pixmap
1943 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1944 *value
= True
; /*XXX*/
1946 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1948 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1950 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1951 *value
= True
; /*XXX*/
1953 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1954 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1955 GLX_TEXTURE_2D_BIT_EXT
|
1956 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1958 case GLX_Y_INVERTED_EXT
:
1959 *value
= True
; /*XXX*/
1964 return GLX_BAD_ATTRIBUTE
;
1971 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1972 int attrib
, int *value
)
1976 if (!dpy
|| !visinfo
)
1977 return GLX_BAD_ATTRIBUTE
;
1979 xmvis
= find_glx_visual( dpy
, visinfo
);
1981 /* this visual wasn't obtained with glXChooseVisual */
1982 xmvis
= create_glx_visual( dpy
, visinfo
);
1984 /* this visual can't be used for GL rendering */
1985 if (attrib
==GLX_USE_GL
) {
1986 *value
= (int) False
;
1990 return GLX_BAD_VISUAL
;
1995 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
2001 Fake_glXWaitGL( void )
2003 XMesaContext xmesa
= XMesaGetCurrentContext();
2004 XMesaFlush( xmesa
);
2010 Fake_glXWaitX( void )
2012 XMesaContext xmesa
= XMesaGetCurrentContext();
2013 XMesaFlush( xmesa
);
2018 get_extensions( void )
2021 const char *fx
= _mesa_getenv("MESA_GLX_FX");
2022 if (fx
&& fx
[0] != 'd') {
2026 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
2031 /* GLX 1.1 and later */
2033 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
2037 return get_extensions();
2042 /* GLX 1.1 and later */
2044 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
2046 static char version
[1000];
2047 _mesa_sprintf(version
, "%d.%d %s",
2048 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
2054 case GLX_EXTENSIONS
:
2055 return get_extensions();
2067 /* GLX 1.1 and later */
2069 Fake_glXGetClientString( Display
*dpy
, int name
)
2071 static char version
[1000];
2072 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
2073 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
2078 case GLX_EXTENSIONS
:
2079 return get_extensions();
2097 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
2098 int attribute
, int *value
)
2100 XMesaVisual v
= (XMesaVisual
) config
;
2104 if (!dpy
|| !config
|| !value
)
2107 return get_config(v
, attribute
, value
, GL_TRUE
);
2111 static GLXFBConfig
*
2112 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
2114 XVisualInfo
*visuals
, visTemplate
;
2115 const long visMask
= VisualScreenMask
;
2118 /* Get list of all X visuals */
2119 visTemplate
.screen
= screen
;
2120 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
2121 if (*nelements
> 0) {
2122 XMesaVisual
*results
;
2123 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
2128 for (i
= 0; i
< *nelements
; i
++) {
2129 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
2131 return (GLXFBConfig
*) results
;
2137 static GLXFBConfig
*
2138 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
2139 const int *attribList
, int *nitems
)
2143 if (!attribList
|| !attribList
[0]) {
2144 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
2145 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
2148 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
2150 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
2156 config
[0] = (GLXFBConfig
) xmvis
;
2157 return (GLXFBConfig
*) config
;
2166 static XVisualInfo
*
2167 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
2169 if (dpy
&& config
) {
2170 XMesaVisual xmvis
= (XMesaVisual
) config
;
2172 return xmvis
->vishandle
;
2174 /* create a new vishandle - the cached one may be stale */
2175 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
2176 if (xmvis
->vishandle
) {
2177 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
2179 return xmvis
->vishandle
;
2189 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
2190 const int *attribList
)
2192 XMesaVisual xmvis
= (XMesaVisual
) config
;
2197 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
2202 /* XXX this will segfault if actually called */
2203 FXcreateContext(xmvis
, win
, NULL
, xmbuf
);
2207 (void) attribList
; /* Ignored in GLX 1.3 */
2209 return win
; /* A hack for now */
2214 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
2216 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2218 XMesaDestroyBuffer(b
);
2219 /* don't destroy X window */
2225 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2226 const int *attribList
)
2228 XMesaVisual v
= (XMesaVisual
) config
;
2231 int target
= 0, format
= 0, mipmap
= 0;
2234 if (!dpy
|| !config
|| !pixmap
)
2237 for (attr
= attribList
; *attr
; attr
++) {
2239 case GLX_TEXTURE_FORMAT_EXT
:
2242 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2243 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2244 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2252 case GLX_TEXTURE_TARGET_EXT
:
2255 case GLX_TEXTURE_1D_EXT
:
2256 case GLX_TEXTURE_2D_EXT
:
2257 case GLX_TEXTURE_RECTANGLE_EXT
:
2265 case GLX_MIPMAP_TEXTURE_EXT
:
2276 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2277 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2278 &value
, GL_TRUE
) != Success
2280 return 0; /* error! */
2283 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2284 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2285 &value
, GL_TRUE
) != Success
2287 return 0; /* error! */
2291 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2292 &value
, GL_TRUE
) != Success
2294 return 0; /* error! */
2297 if (target
== GLX_TEXTURE_1D_EXT
) {
2298 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2299 &value
, GL_TRUE
) != Success
2300 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2301 return 0; /* error! */
2304 else if (target
== GLX_TEXTURE_2D_EXT
) {
2305 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2306 &value
, GL_TRUE
) != Success
2307 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2308 return 0; /* error! */
2311 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2312 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2313 &value
, GL_TRUE
) != Success
2314 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2315 return 0; /* error! */
2319 if (format
|| target
|| mipmap
) {
2320 /* texture from pixmap */
2321 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2324 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2335 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2337 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2339 XMesaDestroyBuffer(b
);
2340 /* don't destroy X pixmap */
2345 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2346 const int *attribList
)
2348 XMesaVisual xmvis
= (XMesaVisual
) config
;
2351 int width
= 0, height
= 0;
2352 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2356 for (attrib
= attribList
; *attrib
; attrib
++) {
2358 case GLX_PBUFFER_WIDTH
:
2362 case GLX_PBUFFER_HEIGHT
:
2366 case GLX_PRESERVED_CONTENTS
:
2368 preserveContents
= *attrib
; /* ignored */
2370 case GLX_LARGEST_PBUFFER
:
2372 useLargest
= *attrib
; /* ignored */
2379 /* not used at this time */
2381 (void) preserveContents
;
2383 if (width
== 0 || height
== 0)
2386 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2387 /* A GLXPbuffer handle must be an X Drawable because that's what
2388 * glXMakeCurrent takes.
2391 return (GLXPbuffer
) xmbuf
->drawable
;
2398 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2400 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2402 XMesaDestroyBuffer(b
);
2408 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2409 unsigned int *value
)
2411 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2415 switch (attribute
) {
2417 *value
= xmesa_buffer_width(xmbuf
);
2420 *value
= xmesa_buffer_width(xmbuf
);
2422 case GLX_PRESERVED_CONTENTS
:
2425 case GLX_LARGEST_PBUFFER
:
2426 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2428 case GLX_FBCONFIG_ID
:
2429 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2431 #ifdef GLX_EXT_texture_from_pixmap
2432 case GLX_TEXTURE_FORMAT_EXT
:
2433 *value
= xmbuf
->TextureFormat
;
2435 case GLX_TEXTURE_TARGET_EXT
:
2436 *value
= xmbuf
->TextureTarget
;
2438 case GLX_MIPMAP_TEXTURE_EXT
:
2439 *value
= xmbuf
->TextureMipmap
;
2444 return; /* raise BadValue error */
2450 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2451 int renderType
, GLXContext shareList
, Bool direct
)
2453 struct fake_glx_context
*glxCtx
;
2454 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2455 XMesaVisual xmvis
= (XMesaVisual
) config
;
2457 if (!dpy
|| !config
||
2458 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2461 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2465 /* deallocate unused windows/buffers */
2466 XMesaGarbageCollect();
2468 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2469 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2470 if (!glxCtx
->xmesaContext
) {
2475 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2476 glxCtx
->glxContext
.currentDpy
= dpy
;
2477 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2479 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2481 return (GLXContext
) glxCtx
;
2486 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2488 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2489 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2494 switch (attribute
) {
2495 case GLX_FBCONFIG_ID
:
2496 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2498 case GLX_RENDER_TYPE
:
2499 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2500 *value
= GLX_RGBA_BIT
;
2502 *value
= GLX_COLOR_INDEX_BIT
;
2508 return GLX_BAD_ATTRIBUTE
;
2515 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2517 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2519 xmbuf
->selectedEvents
= mask
;
2524 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2525 unsigned long *mask
)
2527 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2529 *mask
= xmbuf
->selectedEvents
;
2536 /*** GLX_SGI_swap_control ***/
2539 Fake_glXSwapIntervalSGI(int interval
)
2547 /*** GLX_SGI_video_sync ***/
2549 static unsigned int FrameCounter
= 0;
2552 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2554 /* this is a bogus implementation */
2555 *count
= FrameCounter
++;
2560 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2562 if (divisor
<= 0 || remainder
< 0)
2563 return GLX_BAD_VALUE
;
2564 /* this is a bogus implementation */
2566 while (FrameCounter
% divisor
!= remainder
)
2568 *count
= FrameCounter
;
2574 /*** GLX_SGI_make_current_read ***/
2577 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2579 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2584 Fake_glXGetCurrentReadDrawableSGI(void)
2591 /*** GLX_SGIX_video_source ***/
2594 static GLXVideoSourceSGIX
2595 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2607 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2616 /*** GLX_EXT_import_context ***/
2619 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2626 Fake_glXGetContextIDEXT(const GLXContext context
)
2633 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2641 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2652 /*** GLX_SGIX_fbconfig ***/
2655 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2657 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2660 static GLXFBConfigSGIX
*
2661 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2663 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2668 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2670 XMesaVisual xmvis
= (XMesaVisual
) config
;
2671 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2672 return xmbuf
->drawable
; /* need to return an X ID */
2677 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2679 XMesaVisual xmvis
= (XMesaVisual
) config
;
2680 struct fake_glx_context
*glxCtx
;
2681 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2683 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2687 /* deallocate unused windows/buffers */
2688 XMesaGarbageCollect();
2690 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2691 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2692 if (!glxCtx
->xmesaContext
) {
2697 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2698 glxCtx
->glxContext
.currentDpy
= dpy
;
2699 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2701 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2703 return (GLXContext
) glxCtx
;
2707 static XVisualInfo
*
2708 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2710 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2714 static GLXFBConfigSGIX
2715 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2717 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2719 /* This visual wasn't found with glXChooseVisual() */
2720 xmvis
= create_glx_visual(dpy
, vis
);
2723 return (GLXFBConfigSGIX
) xmvis
;
2728 /*** GLX_SGIX_pbuffer ***/
2730 static GLXPbufferSGIX
2731 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2732 unsigned int width
, unsigned int height
,
2735 XMesaVisual xmvis
= (XMesaVisual
) config
;
2738 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2742 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2744 case GLX_PRESERVED_CONTENTS_SGIX
:
2746 preserveContents
= *attrib
; /* ignored */
2748 case GLX_LARGEST_PBUFFER_SGIX
:
2750 useLargest
= *attrib
; /* ignored */
2757 /* not used at this time */
2759 (void) preserveContents
;
2761 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2762 /* A GLXPbuffer handle must be an X Drawable because that's what
2763 * glXMakeCurrent takes.
2765 return (GLXPbuffer
) xmbuf
->drawable
;
2770 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2772 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2774 XMesaDestroyBuffer(xmbuf
);
2780 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2782 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2785 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2789 switch (attribute
) {
2790 case GLX_PRESERVED_CONTENTS_SGIX
:
2793 case GLX_LARGEST_PBUFFER_SGIX
:
2794 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2796 case GLX_WIDTH_SGIX
:
2797 *value
= xmesa_buffer_width(xmbuf
);
2799 case GLX_HEIGHT_SGIX
:
2800 *value
= xmesa_buffer_height(xmbuf
);
2802 case GLX_EVENT_MASK_SGIX
:
2803 *value
= 0; /* XXX might be wrong */
2813 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2815 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2817 /* Note: we'll never generate clobber events */
2818 xmbuf
->selectedEvents
= mask
;
2824 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2826 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2828 *mask
= xmbuf
->selectedEvents
;
2837 /*** GLX_SGI_cushion ***/
2840 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2849 /*** GLX_SGIX_video_resize ***/
2852 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2862 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2875 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2888 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2901 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2912 /*** GLX_SGIX_dmbuffer **/
2914 #if defined(_DM_BUFFER_H_)
2916 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2927 /*** GLX_SGIX_swap_group ***/
2930 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2939 /*** GLX_SGIX_swap_barrier ***/
2942 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2950 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2960 /*** GLX_SUN_get_transparent_index ***/
2963 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2968 (void) pTransparent
;
2974 /*** GLX_MESA_release_buffers ***/
2977 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2978 * (a window or pixmap) prior to destroying the GLXDrawable.
2981 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2983 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2985 XMesaDestroyBuffer(b
);
2993 /*** GLX_MESA_set_3dfx_mode ***/
2996 Fake_glXSet3DfxModeMESA( int mode
)
2998 return XMesaSetFXmode( mode
);
3003 /*** GLX_NV_vertex_array range ***/
3005 Fake_glXAllocateMemoryNV( GLsizei size
,
3006 GLfloat readFrequency
,
3007 GLfloat writeFrequency
,
3011 (void) readFrequency
;
3012 (void) writeFrequency
;
3019 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
3025 /*** GLX_MESA_agp_offset ***/
3028 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
3035 /*** GLX_EXT_texture_from_pixmap ***/
3038 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
3039 const int *attrib_list
)
3041 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3043 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
3047 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
3049 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3051 XMesaReleaseTexImage(dpy
, b
, buffer
);
3055 /* silence warning */
3056 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
3060 * Create a new GLX API dispatch table with its function pointers
3061 * initialized to point to Mesa's "fake" GLX API functions.
3062 * Note: there's a similar function (_real_GetGLXDispatchTable) that
3063 * returns a new dispatch table with all pointers initalized to point
3064 * to "real" GLX functions (which understand GLX wire protocol, etc).
3066 struct _glxapi_table
*
3067 _mesa_GetGLXDispatchTable(void)
3069 static struct _glxapi_table glx
;
3071 /* be sure our dispatch table size <= libGL's table */
3073 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
3075 assert(_glxapi_get_dispatch_table_size() >= size
);
3078 /* initialize the whole table to no-ops */
3079 _glxapi_set_no_op_table(&glx
);
3081 /* now initialize the table with the functions I implement */
3082 glx
.ChooseVisual
= Fake_glXChooseVisual
;
3083 glx
.CopyContext
= Fake_glXCopyContext
;
3084 glx
.CreateContext
= Fake_glXCreateContext
;
3085 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
3086 glx
.DestroyContext
= Fake_glXDestroyContext
;
3087 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
3088 glx
.GetConfig
= Fake_glXGetConfig
;
3089 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
3090 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
3091 glx
.IsDirect
= Fake_glXIsDirect
;
3092 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
3093 glx
.QueryExtension
= Fake_glXQueryExtension
;
3094 glx
.QueryVersion
= Fake_glXQueryVersion
;
3095 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
3096 glx
.UseXFont
= Fake_glXUseXFont
;
3097 glx
.WaitGL
= Fake_glXWaitGL
;
3098 glx
.WaitX
= Fake_glXWaitX
;
3100 /*** GLX_VERSION_1_1 ***/
3101 glx
.GetClientString
= Fake_glXGetClientString
;
3102 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
3103 glx
.QueryServerString
= Fake_glXQueryServerString
;
3105 /*** GLX_VERSION_1_2 ***/
3106 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
3108 /*** GLX_VERSION_1_3 ***/
3109 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
3110 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
3111 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
3112 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
3113 glx
.CreateWindow
= Fake_glXCreateWindow
;
3114 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
3115 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
3116 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
3117 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
3118 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
3119 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
3120 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
3121 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
3122 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
3123 glx
.QueryContext
= Fake_glXQueryContext
;
3124 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
3125 glx
.SelectEvent
= Fake_glXSelectEvent
;
3127 /*** GLX_SGI_swap_control ***/
3128 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
3130 /*** GLX_SGI_video_sync ***/
3131 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
3132 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
3134 /*** GLX_SGI_make_current_read ***/
3135 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
3136 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
3138 /*** GLX_SGIX_video_source ***/
3140 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
3141 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
3144 /*** GLX_EXT_import_context ***/
3145 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
3146 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
3147 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
3148 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
3149 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
3151 /*** GLX_SGIX_fbconfig ***/
3152 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
3153 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
3154 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
3155 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
3156 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
3157 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
3159 /*** GLX_SGIX_pbuffer ***/
3160 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
3161 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
3162 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
3163 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
3164 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
3166 /*** GLX_SGI_cushion ***/
3167 glx
.CushionSGI
= Fake_glXCushionSGI
;
3169 /*** GLX_SGIX_video_resize ***/
3170 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
3171 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
3172 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
3173 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
3174 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
3176 /*** GLX_SGIX_dmbuffer **/
3177 #if defined(_DM_BUFFER_H_)
3178 glx
.AssociateDMPbufferSGIX
= NULL
;
3181 /*** GLX_SGIX_swap_group ***/
3182 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
3184 /*** GLX_SGIX_swap_barrier ***/
3185 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
3186 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
3188 /*** GLX_SUN_get_transparent_index ***/
3189 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
3191 /*** GLX_MESA_copy_sub_buffer ***/
3192 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3194 /*** GLX_MESA_release_buffers ***/
3195 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3197 /*** GLX_MESA_pixmap_colormap ***/
3198 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3200 /*** GLX_MESA_set_3dfx_mode ***/
3201 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3203 /*** GLX_NV_vertex_array_range ***/
3204 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3205 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3207 /*** GLX_MESA_agp_offset ***/
3208 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3210 /*** GLX_EXT_texture_from_pixmap ***/
3211 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3212 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;