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"
46 #include "main/context.h"
47 #include "main/config.h"
48 #include "main/macros.h"
49 #include "main/imports.h"
50 #include "main/mtypes.h"
51 #include "main/version.h"
56 #define _mesa_sprintf sprintf
59 /* This indicates the client-side GLX API and GLX encoder version. */
60 #define CLIENT_MAJOR_VERSION 1
61 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
63 /* This indicates the server-side GLX decoder version.
64 * GLX 1.4 indicates OpenGL 1.3 support
66 #define SERVER_MAJOR_VERSION 1
67 #define SERVER_MINOR_VERSION 4
69 /* This is appended onto the glXGetClient/ServerString version strings. */
70 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
72 /* Who implemented this GLX? */
73 #define VENDOR "Brian Paul"
76 "GLX_MESA_set_3dfx_mode " \
77 "GLX_MESA_copy_sub_buffer " \
78 "GLX_MESA_pixmap_colormap " \
79 "GLX_MESA_release_buffers " \
80 "GLX_ARB_get_proc_address " \
81 "GLX_EXT_texture_from_pixmap " \
82 "GLX_EXT_visual_info " \
83 "GLX_EXT_visual_rating " \
84 /*"GLX_SGI_video_sync "*/ \
85 "GLX_SGIX_fbconfig " \
89 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
91 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
94 * We really just need this structure in order to make the libGL functions
95 * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
98 struct fake_glx_context
{
99 __GLXcontext glxContext
; /* this MUST be first! */
100 XMesaContext xmesaContext
;
105 /**********************************************************************/
106 /*** GLX Visual Code ***/
107 /**********************************************************************/
112 static XMesaVisual
*VisualTable
= NULL
;
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
143 * Test if the given XVisualInfo is usable for Mesa rendering.
146 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 * Get an array OverlayInfo records for specified screen.
176 * \param dpy the display
177 * \param screen screen number
178 * \param numOverlays returns numver of OverlayInfo records
179 * \return pointer to OverlayInfo array, free with XFree()
182 GetOverlayInfo(Display
*dpy
, int screen
, int *numOverlays
)
184 Atom overlayVisualsAtom
;
187 unsigned char *ovInfo
;
188 unsigned long sizeData
, bytesLeft
;
192 * The SERVER_OVERLAY_VISUALS property on the root window contains
193 * a list of overlay visuals. Get that list now.
195 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
196 if (overlayVisualsAtom
== None
) {
200 status
= XGetWindowProperty(dpy
, RootWindow(dpy
, screen
),
201 overlayVisualsAtom
, 0L, (long) 10000, False
,
202 overlayVisualsAtom
, &actualType
, &actualFormat
,
203 &sizeData
, &bytesLeft
,
206 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
207 actualFormat
!= 32 || sizeData
< 4) {
208 /* something went wrong */
209 XFree((void *) ovInfo
);
214 *numOverlays
= sizeData
/ 4;
215 return (OverlayInfo
*) ovInfo
;
221 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
222 * Input: dpy - the X display
223 * vinfo - the XVisualInfo to test
224 * Return: level of the visual:
226 * >0 = overlay planes
227 * <0 = underlay planes
230 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
232 OverlayInfo
*overlay_info
;
233 int numOverlaysPerScreen
, i
;
235 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
240 /* search the overlay visual list for the visual ID of interest */
241 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
242 const OverlayInfo
*ov
= overlay_info
+ i
;
243 if (ov
->overlay_visual
== vinfo
->visualid
) {
244 /* found the visual */
245 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
246 int level
= ov
->layer
;
247 XFree((void *) overlay_info
);
251 XFree((void *) overlay_info
);
257 /* The visual ID was not found in the overlay list. */
258 XFree((void *) overlay_info
);
266 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
267 * configuration in our list of GLX visuals.
270 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
271 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
272 GLboolean stereoFlag
,
273 GLint depth_size
, GLint stencil_size
,
274 GLint accumRedSize
, GLint accumGreenSize
,
275 GLint accumBlueSize
, GLint accumAlphaSize
,
276 GLint level
, GLint numAuxBuffers
)
278 GLboolean ximageFlag
= GL_TRUE
;
281 GLboolean comparePointers
;
284 /* Check if the MESA_BACK_BUFFER env var is set */
285 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
287 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
288 ximageFlag
= GL_FALSE
;
290 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
291 ximageFlag
= GL_TRUE
;
294 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
300 /* stereo not supported */
304 /* Comparing IDs uses less memory but sometimes fails. */
305 /* XXX revisit this after 3.0 is finished. */
306 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
307 comparePointers
= GL_TRUE
;
309 comparePointers
= GL_FALSE
;
311 /* Force the visual to have an alpha channel */
312 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
315 /* First check if a matching visual is already in the list */
316 for (i
=0; i
<NumVisuals
; i
++) {
317 XMesaVisual v
= VisualTable
[i
];
318 if (v
->display
== dpy
319 && v
->mesa_visual
.level
== level
320 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
321 && v
->ximage_flag
== ximageFlag
322 && v
->mesa_visual
.rgbMode
== rgbFlag
323 && v
->mesa_visual
.doubleBufferMode
== dbFlag
324 && v
->mesa_visual
.stereoMode
== stereoFlag
325 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
326 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
327 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
328 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
329 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
330 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
331 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
332 /* now either compare XVisualInfo pointers or visual IDs */
333 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
334 || (comparePointers
&& v
->vishandle
== vinfo
)) {
340 /* Create a new visual and add it to the list. */
342 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
343 stereoFlag
, ximageFlag
,
344 depth_size
, stencil_size
,
345 accumRedSize
, accumBlueSize
,
346 accumBlueSize
, accumAlphaSize
, 0, level
,
349 /* Save a copy of the pointer now so we can find this visual again
350 * if we need to search for it in find_glx_visual().
352 xmvis
->vishandle
= vinfo
;
353 /* Allocate more space for additional visual */
354 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
355 sizeof(XMesaVisual
) * NumVisuals
,
356 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
357 /* add xmvis to the list */
358 VisualTable
[NumVisuals
] = xmvis
;
360 /* XXX minor hack, because XMesaCreateVisual doesn't support an
361 * aux buffers parameter.
363 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
370 * Return the default number of bits for the Z buffer.
371 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
372 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
373 * XXX probably do the same thing for stencil, accum, etc.
376 default_depth_bits(void)
379 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
381 zBits
= _mesa_atoi(zEnv
);
383 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
388 default_alpha_bits(void)
391 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
393 aBits
= _mesa_atoi(aEnv
);
400 default_accum_bits(void)
408 * Create a GLX visual from a regular XVisualInfo.
409 * This is called when Fake GLX is given an XVisualInfo which wasn't
410 * returned by glXChooseVisual. Since this is the first time we're
411 * considering this visual we'll take a guess at reasonable values
412 * for depth buffer size, stencil size, accum size, etc.
413 * This is the best we can do with a client-side emulation of GLX.
416 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
419 GLint zBits
= default_depth_bits();
420 GLint accBits
= default_accum_bits();
421 GLboolean alphaFlag
= default_alpha_bits() > 0;
423 vislevel
= level_of_visual( dpy
, visinfo
);
425 /* Configure this visual as a CI, single-buffered overlay */
426 return save_glx_visual( dpy
, visinfo
,
428 GL_FALSE
, /* alpha */
429 GL_FALSE
, /* double */
430 GL_FALSE
, /* stereo */
432 0, /* stencil bits */
433 0,0,0,0, /* accum bits */
434 vislevel
, /* level */
438 else if (is_usable_visual( visinfo
)) {
439 if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
440 /* Configure this visual as a COLOR INDEX visual. */
441 return save_glx_visual( dpy
, visinfo
,
443 GL_FALSE
, /* alpha */
444 GL_TRUE
, /* double */
445 GL_FALSE
, /* stereo */
448 0, 0, 0, 0, /* accum bits */
454 /* Configure this visual as RGB, double-buffered, depth-buffered. */
455 /* This is surely wrong for some people's needs but what else */
456 /* can be done? They should use glXChooseVisual(). */
457 return save_glx_visual( dpy
, visinfo
,
459 alphaFlag
, /* alpha */
460 GL_TRUE
, /* double */
461 GL_FALSE
, /* stereo */
474 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
482 * Find the GLX visual associated with an XVisualInfo.
485 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
489 /* try to match visual id */
490 for (i
=0;i
<NumVisuals
;i
++) {
491 if (VisualTable
[i
]->display
==dpy
492 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
493 return VisualTable
[i
];
497 /* if that fails, try to match pointers */
498 for (i
=0;i
<NumVisuals
;i
++) {
499 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
500 return VisualTable
[i
];
510 * Return the transparent pixel value for a GLX visual.
511 * Input: glxvis - the glx_visual
512 * Return: a pixel value or -1 if no transparent pixel
515 transparent_pixel( XMesaVisual glxvis
)
517 Display
*dpy
= glxvis
->display
;
518 XVisualInfo
*vinfo
= glxvis
->visinfo
;
519 OverlayInfo
*overlay_info
;
520 int numOverlaysPerScreen
, i
;
522 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
527 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
528 const OverlayInfo
*ov
= overlay_info
+ i
;
529 if (ov
->overlay_visual
== vinfo
->visualid
) {
531 if (ov
->transparent_type
== 0) {
532 /* type 0 indicates no transparency */
533 XFree((void *) overlay_info
);
537 /* ov->value is the transparent pixel */
538 XFree((void *) overlay_info
);
544 /* The visual ID was not found in the overlay list. */
545 XFree((void *) overlay_info
);
552 * Try to get an X visual which matches the given arguments.
555 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
557 XVisualInfo temp
, *vis
;
560 unsigned int default_depth
;
563 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
568 default_depth
= DefaultDepth(dpy
,scr
);
569 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
571 if (depth
==default_depth
&& xclass
==default_class
) {
572 /* try to get root window's visual */
573 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
574 mask
|= VisualIDMask
;
577 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
579 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
580 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
581 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
583 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
584 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
585 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
586 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
601 * Retrieve the value of the given environment variable and find
602 * the X visual which matches it.
603 * Input: dpy - the display
604 * screen - the screen number
605 * varname - the name of the environment variable
606 * Return: an XVisualInfo pointer to NULL if error.
609 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
611 char value
[100], type
[100];
612 int depth
, xclass
= -1;
615 if (!_mesa_getenv( varname
)) {
619 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
622 sscanf( value
, "%s %d", type
, &depth
);
624 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
625 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
626 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
627 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
628 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
629 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
631 if (xclass
>-1 && depth
>0) {
632 vis
= get_visual( dpy
, scr
, depth
, xclass
);
638 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
647 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
648 * Input: dpy, screen - X display and screen number
649 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
650 * min_depth - minimum visual depth
651 * preferred_class - preferred GLX visual class or DONT_CARE
652 * Return: pointer to an XVisualInfo or NULL.
655 choose_x_visual( Display
*dpy
, int screen
, GLboolean rgba
, int min_depth
,
656 int preferred_class
)
659 int xclass
, visclass
= 0;
663 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
664 /* First see if the MESA_RGB_VISUAL env var is defined */
665 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
669 /* Otherwise, search for a suitable visual */
670 if (preferred_class
==DONT_CARE
) {
671 for (xclass
=0;xclass
<6;xclass
++) {
673 case 0: visclass
= TrueColor
; break;
674 case 1: visclass
= DirectColor
; break;
675 case 2: visclass
= PseudoColor
; break;
676 case 3: visclass
= StaticColor
; break;
677 case 4: visclass
= GrayScale
; break;
678 case 5: visclass
= StaticGray
; break;
681 /* start with shallowest */
682 for (depth
=0;depth
<=32;depth
++) {
683 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
684 /* Special case: try to get 8-bit PseudoColor before */
685 /* 8-bit TrueColor */
686 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
691 vis
= get_visual( dpy
, screen
, depth
, visclass
);
698 /* start with deepest */
699 for (depth
=32;depth
>=min_depth
;depth
--) {
700 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
701 /* Special case: try to get 8-bit PseudoColor before */
702 /* 8-bit TrueColor */
703 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
708 vis
= get_visual( dpy
, screen
, depth
, visclass
);
717 /* search for a specific visual class */
718 switch (preferred_class
) {
719 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
720 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
721 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
722 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
723 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
724 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
725 default: return NULL
;
728 /* start with shallowest */
729 for (depth
=0;depth
<=32;depth
++) {
730 vis
= get_visual( dpy
, screen
, depth
, visclass
);
737 /* start with deepest */
738 for (depth
=32;depth
>=min_depth
;depth
--) {
739 vis
= get_visual( dpy
, screen
, depth
, visclass
);
748 /* First see if the MESA_CI_VISUAL env var is defined */
749 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
753 /* Otherwise, search for a suitable visual, starting with shallowest */
754 if (preferred_class
==DONT_CARE
) {
755 for (xclass
=0;xclass
<4;xclass
++) {
757 case 0: visclass
= PseudoColor
; break;
758 case 1: visclass
= StaticColor
; break;
759 case 2: visclass
= GrayScale
; break;
760 case 3: visclass
= StaticGray
; break;
762 /* try 8-bit up through 16-bit */
763 for (depth
=8;depth
<=16;depth
++) {
764 vis
= get_visual( dpy
, screen
, depth
, visclass
);
769 /* try min_depth up to 8-bit */
770 for (depth
=min_depth
;depth
<8;depth
++) {
771 vis
= get_visual( dpy
, screen
, depth
, visclass
);
779 /* search for a specific visual class */
780 switch (preferred_class
) {
781 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
782 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
783 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
784 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
785 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
786 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
787 default: return NULL
;
789 /* try 8-bit up through 16-bit */
790 for (depth
=8;depth
<=16;depth
++) {
791 vis
= get_visual( dpy
, screen
, depth
, visclass
);
796 /* try min_depth up to 8-bit */
797 for (depth
=min_depth
;depth
<8;depth
++) {
798 vis
= get_visual( dpy
, screen
, depth
, visclass
);
806 /* didn't find a visual */
813 * Find the deepest X over/underlay visual of at least min_depth.
814 * Input: dpy, screen - X display and screen number
815 * level - the over/underlay level
816 * trans_type - transparent pixel type: GLX_NONE_EXT,
817 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
819 * trans_value - transparent pixel value or DONT_CARE
820 * min_depth - minimum visual depth
821 * preferred_class - preferred GLX visual class or DONT_CARE
822 * Return: pointer to an XVisualInfo or NULL.
825 choose_x_overlay_visual( Display
*dpy
, int scr
, GLboolean rgbFlag
,
826 int level
, int trans_type
, int trans_value
,
827 int min_depth
, int preferred_class
)
829 OverlayInfo
*overlay_info
;
830 int numOverlaysPerScreen
;
832 XVisualInfo
*deepvis
;
835 /*DEBUG int tt, tv; */
837 switch (preferred_class
) {
838 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
839 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
840 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
841 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
842 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
843 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
844 default: preferred_class
= DONT_CARE
;
847 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
852 /* Search for the deepest overlay which satisifies all criteria. */
856 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
857 const OverlayInfo
*ov
= overlay_info
+ i
;
858 XVisualInfo
*vislist
, vistemplate
;
861 if (ov
->layer
!=level
) {
862 /* failed overlay level criteria */
865 if (!(trans_type
==DONT_CARE
866 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
867 && ov
->transparent_type
>0)
868 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
869 /* failed transparent pixel type criteria */
872 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
873 /* failed transparent pixel value criteria */
877 /* get XVisualInfo and check the depth */
878 vistemplate
.visualid
= ov
->overlay_visual
;
879 vistemplate
.screen
= scr
;
880 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
881 &vistemplate
, &count
);
884 /* something went wrong */
887 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
888 /* wrong visual class */
892 /* if RGB was requested, make sure we have True/DirectColor */
893 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
894 && vislist
->CLASS
!= DirectColor
)
897 /* if CI was requested, make sure we have a color indexed visual */
899 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
902 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
903 /* YES! found a satisfactory visual */
907 deepest
= vislist
->depth
;
909 /* DEBUG tt = ov->transparent_type;*/
910 /* DEBUG tv = ov->value; */
916 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
917 deepvis->visualid, level, deepvis->depth, tt, tv );
924 /**********************************************************************/
925 /*** Display-related functions ***/
926 /**********************************************************************/
930 * Free all XMesaVisuals which are associated with the given display.
933 destroy_visuals_on_display(Display
*dpy
)
936 for (i
= 0; i
< NumVisuals
; i
++) {
937 if (VisualTable
[i
]->display
== dpy
) {
938 /* remove this visual */
940 free(VisualTable
[i
]);
941 for (j
= i
; j
< NumVisuals
- 1; j
++)
942 VisualTable
[j
] = VisualTable
[j
+ 1];
950 * Called from XCloseDisplay() to let us free our display-related data.
953 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
955 destroy_visuals_on_display(dpy
);
956 xmesa_destroy_buffers_on_display(dpy
);
962 * Look for the named extension on given display and return a pointer
963 * to the _XExtension data, or NULL if extension not found.
966 lookup_extension(Display
*dpy
, const char *extName
)
969 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
970 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
979 * Whenever we're given a new Display pointer, call this function to
980 * register our close_display_callback function.
983 register_with_display(Display
*dpy
)
985 const char *extName
= "MesaGLX";
988 ext
= lookup_extension(dpy
, extName
);
990 XExtCodes
*c
= XAddExtension(dpy
);
991 ext
= dpy
->ext_procs
; /* new extension is at head of list */
992 assert(c
->extension
== ext
->codes
.extension
);
993 ext
->name
= _mesa_strdup(extName
);
994 ext
->close_display
= close_display_callback
;
999 /**********************************************************************/
1000 /*** Begin Fake GLX API Functions ***/
1001 /**********************************************************************/
1005 * Helper used by glXChooseVisual and glXChooseFBConfig.
1006 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
1008 * In either case, the attribute list is terminated with the value 'None'.
1011 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
1013 const GLboolean rgbModeDefault
= fbConfig
;
1014 const int *parselist
;
1017 int min_red
=0, min_green
=0, min_blue
=0;
1018 GLboolean rgb_flag
= rgbModeDefault
;
1019 GLboolean alpha_flag
= GL_FALSE
;
1020 GLboolean double_flag
= GL_FALSE
;
1021 GLboolean stereo_flag
= GL_FALSE
;
1022 GLint depth_size
= 0;
1023 GLint stencil_size
= 0;
1024 GLint accumRedSize
= 0;
1025 GLint accumGreenSize
= 0;
1026 GLint accumBlueSize
= 0;
1027 GLint accumAlphaSize
= 0;
1029 int visual_type
= DONT_CARE
;
1030 int trans_type
= DONT_CARE
;
1031 int trans_value
= DONT_CARE
;
1032 GLint caveat
= DONT_CARE
;
1033 XMesaVisual xmvis
= NULL
;
1034 int desiredVisualID
= -1;
1039 while (*parselist
) {
1041 switch (*parselist
) {
1052 case GLX_BUFFER_SIZE
:
1054 min_ci
= *parselist
++;
1058 level
= *parselist
++;
1070 case GLX_DOUBLEBUFFER
:
1073 double_flag
= *parselist
++;
1076 double_flag
= GL_TRUE
;
1082 stereo_flag
= *parselist
++;
1085 stereo_flag
= GL_TRUE
;
1088 case GLX_AUX_BUFFERS
:
1090 numAux
= *parselist
++;
1091 if (numAux
> MAX_AUX_BUFFERS
)
1096 min_red
= *parselist
++;
1098 case GLX_GREEN_SIZE
:
1100 min_green
= *parselist
++;
1104 min_blue
= *parselist
++;
1106 case GLX_ALPHA_SIZE
:
1109 GLint size
= *parselist
++;
1110 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
1113 case GLX_DEPTH_SIZE
:
1115 depth_size
= *parselist
++;
1117 case GLX_STENCIL_SIZE
:
1119 stencil_size
= *parselist
++;
1121 case GLX_ACCUM_RED_SIZE
:
1124 GLint size
= *parselist
++;
1125 accumRedSize
= MAX2( accumRedSize
, size
);
1128 case GLX_ACCUM_GREEN_SIZE
:
1131 GLint size
= *parselist
++;
1132 accumGreenSize
= MAX2( accumGreenSize
, size
);
1135 case GLX_ACCUM_BLUE_SIZE
:
1138 GLint size
= *parselist
++;
1139 accumBlueSize
= MAX2( accumBlueSize
, size
);
1142 case GLX_ACCUM_ALPHA_SIZE
:
1145 GLint size
= *parselist
++;
1146 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1151 * GLX_EXT_visual_info extension
1153 case GLX_X_VISUAL_TYPE_EXT
:
1155 visual_type
= *parselist
++;
1157 case GLX_TRANSPARENT_TYPE_EXT
:
1159 trans_type
= *parselist
++;
1161 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1163 trans_value
= *parselist
++;
1165 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1166 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1167 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1168 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1175 * GLX_EXT_visual_info extension
1177 case GLX_VISUAL_CAVEAT_EXT
:
1179 caveat
= *parselist
++; /* ignored for now */
1183 * GLX_ARB_multisample
1185 case GLX_SAMPLE_BUFFERS_ARB
:
1186 case GLX_SAMPLES_ARB
:
1188 if (*parselist
++ != 0)
1189 /* ms not supported */
1196 case GLX_RENDER_TYPE
:
1200 if (*parselist
== GLX_RGBA_BIT
) {
1203 else if (*parselist
== GLX_COLOR_INDEX_BIT
) {
1204 rgb_flag
= GL_FALSE
;
1206 else if (*parselist
== 0) {
1211 case GLX_DRAWABLE_TYPE
:
1215 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1216 return NULL
; /* bad bit */
1220 case GLX_FBCONFIG_ID
:
1224 desiredVisualID
= *parselist
++;
1226 case GLX_X_RENDERABLE
:
1233 #ifdef GLX_EXT_texture_from_pixmap
1234 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1235 parselist
++; /*skip*/
1237 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1238 parselist
++; /*skip*/
1240 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1241 parselist
++; /*skip*/
1243 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1245 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1246 GLX_TEXTURE_2D_BIT_EXT
|
1247 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1252 case GLX_Y_INVERTED_EXT
:
1253 parselist
++; /*skip*/
1262 /* undefined attribute */
1263 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1272 * Since we're only simulating the GLX extension this function will never
1273 * find any real GL visuals. Instead, all we can do is try to find an RGB
1274 * or CI visual of appropriate depth. Other requested attributes such as
1275 * double buffering, depth buffer, etc. will be associated with the X
1276 * visual and stored in the VisualTable[].
1278 if (desiredVisualID
!= -1) {
1279 /* try to get a specific visual, by visualID */
1282 temp
.visualid
= desiredVisualID
;
1283 temp
.screen
= screen
;
1284 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1286 /* give the visual some useful GLX attributes */
1287 double_flag
= GL_TRUE
;
1290 depth_size
= default_depth_bits();
1291 stencil_size
= STENCIL_BITS
;
1295 else if (level
==0) {
1296 /* normal color planes */
1298 /* Get an RGB visual */
1299 int min_rgb
= min_red
+ min_green
+ min_blue
;
1300 if (min_rgb
>1 && min_rgb
<8) {
1301 /* a special case to be sure we can get a monochrome visual */
1304 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1307 /* Get a color index visual */
1308 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1309 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1313 /* over/underlay planes */
1316 int min_rgb
= min_red
+ min_green
+ min_blue
;
1317 if (min_rgb
>1 && min_rgb
<8) {
1318 /* a special case to be sure we can get a monochrome visual */
1321 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1322 trans_type
, trans_value
, min_rgb
, visual_type
);
1325 /* color index overlay */
1326 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1327 trans_type
, trans_value
, min_ci
, visual_type
);
1332 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1333 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1334 * largest depth buffer size, which is 32bits/value. Instead, we
1335 * return 16 to maintain performance with earlier versions of Mesa.
1337 if (depth_size
> 24)
1339 else if (depth_size
> 16)
1341 else if (depth_size
> 0) {
1342 depth_size
= default_depth_bits();
1346 alpha_flag
= default_alpha_bits() > 0;
1349 /* we only support one size of stencil and accum buffers. */
1350 if (stencil_size
> 0)
1351 stencil_size
= STENCIL_BITS
;
1352 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1353 accumAlphaSize
> 0) {
1356 accumBlueSize
= default_accum_bits();
1357 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1360 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1361 stereo_flag
, depth_size
, stencil_size
,
1362 accumRedSize
, accumGreenSize
,
1363 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1370 static XVisualInfo
*
1371 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1375 /* register ourselves as an extension on this display */
1376 register_with_display(dpy
);
1378 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1381 return xmvis
->vishandle
;
1383 /* create a new vishandle - the cached one may be stale */
1384 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1385 if (xmvis
->vishandle
) {
1386 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1388 return xmvis
->vishandle
;
1397 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1398 GLXContext share_list
, Bool direct
)
1401 struct fake_glx_context
*glxCtx
;
1402 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1404 if (!dpy
|| !visinfo
)
1407 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1411 /* deallocate unused windows/buffers */
1413 XMesaGarbageCollect();
1416 xmvis
= find_glx_visual( dpy
, visinfo
);
1418 /* This visual wasn't found with glXChooseVisual() */
1419 xmvis
= create_glx_visual( dpy
, visinfo
);
1421 /* unusable visual */
1427 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1428 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1429 if (!glxCtx
->xmesaContext
) {
1434 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
1435 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
1436 glxCtx
->glxContext
.currentDpy
= dpy
;
1437 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1439 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1441 return (GLXContext
) glxCtx
;
1445 /* XXX these may have to be removed due to thread-safety issues. */
1446 static GLXContext MakeCurrent_PrevContext
= 0;
1447 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1448 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1449 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1450 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1453 /* GLX 1.3 and later */
1455 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1456 GLXDrawable read
, GLXContext ctx
)
1458 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1460 if (ctx
&& draw
&& read
) {
1461 XMesaBuffer drawBuffer
, readBuffer
;
1462 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1464 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1465 if (ctx
== MakeCurrent_PrevContext
1466 && draw
== MakeCurrent_PrevDrawable
) {
1467 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1470 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1473 /* drawable must be a new window! */
1474 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1476 /* Out of memory, or context/drawable depth mismatch */
1480 FXcreateContext( xmctx
->xm_visual
, draw
, xmctx
, drawBuffer
);
1484 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1485 if (ctx
== MakeCurrent_PrevContext
1486 && read
== MakeCurrent_PrevReadable
) {
1487 readBuffer
= MakeCurrent_PrevReadBuffer
;
1490 readBuffer
= XMesaFindBuffer( dpy
, read
);
1493 /* drawable must be a new window! */
1494 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1496 /* Out of memory, or context/drawable depth mismatch */
1500 FXcreateContext( xmctx
->xm_visual
, read
, xmctx
, readBuffer
);
1504 MakeCurrent_PrevContext
= ctx
;
1505 MakeCurrent_PrevDrawable
= draw
;
1506 MakeCurrent_PrevReadable
= read
;
1507 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1508 MakeCurrent_PrevReadBuffer
= readBuffer
;
1510 /* Now make current! */
1511 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1512 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1513 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1514 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1521 else if (!ctx
&& !draw
&& !read
) {
1522 /* release current context w/out assigning new one. */
1523 XMesaMakeCurrent( NULL
, NULL
);
1524 MakeCurrent_PrevContext
= 0;
1525 MakeCurrent_PrevDrawable
= 0;
1526 MakeCurrent_PrevReadable
= 0;
1527 MakeCurrent_PrevDrawBuffer
= 0;
1528 MakeCurrent_PrevReadBuffer
= 0;
1532 /* The args must either all be non-zero or all zero.
1541 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1543 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1548 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1553 v
= find_glx_visual( dpy
, visinfo
);
1555 v
= create_glx_visual( dpy
, visinfo
);
1557 /* unusable visual */
1562 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1566 return b
->frontxrb
->pixmap
;
1570 /*** GLX_MESA_pixmap_colormap ***/
1573 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1574 Pixmap pixmap
, Colormap cmap
)
1579 v
= find_glx_visual( dpy
, visinfo
);
1581 v
= create_glx_visual( dpy
, visinfo
);
1583 /* unusable visual */
1588 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1592 return b
->frontxrb
->pixmap
;
1597 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1599 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1601 XMesaDestroyBuffer(b
);
1603 else if (_mesa_getenv("MESA_DEBUG")) {
1604 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1610 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1611 unsigned long mask
)
1613 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1614 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1615 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1616 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1618 if (MakeCurrent_PrevContext
== src
) {
1621 _mesa_copy_context( &(xm_src
->mesa
), &(xm_dst
->mesa
), (GLuint
) mask
);
1626 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1628 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1636 extern void _kw_ungrab_all( Display
*dpy
);
1637 void _kw_ungrab_all( Display
*dpy
)
1639 XUngrabPointer( dpy
, CurrentTime
);
1640 XUngrabKeyboard( dpy
, CurrentTime
);
1645 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1647 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1649 MakeCurrent_PrevContext
= 0;
1650 MakeCurrent_PrevDrawable
= 0;
1651 MakeCurrent_PrevReadable
= 0;
1652 MakeCurrent_PrevDrawBuffer
= 0;
1653 MakeCurrent_PrevReadBuffer
= 0;
1654 XMesaDestroyContext( glxCtx
->xmesaContext
);
1655 XMesaGarbageCollect();
1661 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1663 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1665 return glxCtx
->xmesaContext
->direct
;
1671 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1673 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1676 XMesaSwapBuffers(buffer
);
1678 else if (_mesa_getenv("MESA_DEBUG")) {
1679 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1686 /*** GLX_MESA_copy_sub_buffer ***/
1689 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1690 int x
, int y
, int width
, int height
)
1692 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1694 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1696 else if (_mesa_getenv("MESA_DEBUG")) {
1697 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1703 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1706 /* Return GLX version, not Mesa version */
1707 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1708 *maj
= CLIENT_MAJOR_VERSION
;
1709 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1715 * Query the GLX attributes of the given XVisualInfo.
1718 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1724 return GLX_BAD_ATTRIBUTE
;
1725 *value
= (int) True
;
1727 case GLX_BUFFER_SIZE
:
1728 *value
= xmvis
->visinfo
->depth
;
1731 *value
= xmvis
->mesa_visual
.level
;
1735 return GLX_BAD_ATTRIBUTE
;
1736 if (xmvis
->mesa_visual
.rgbMode
) {
1743 case GLX_DOUBLEBUFFER
:
1744 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1747 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1749 case GLX_AUX_BUFFERS
:
1750 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1753 *value
= xmvis
->mesa_visual
.redBits
;
1755 case GLX_GREEN_SIZE
:
1756 *value
= xmvis
->mesa_visual
.greenBits
;
1759 *value
= xmvis
->mesa_visual
.blueBits
;
1761 case GLX_ALPHA_SIZE
:
1762 *value
= xmvis
->mesa_visual
.alphaBits
;
1764 case GLX_DEPTH_SIZE
:
1765 *value
= xmvis
->mesa_visual
.depthBits
;
1767 case GLX_STENCIL_SIZE
:
1768 *value
= xmvis
->mesa_visual
.stencilBits
;
1770 case GLX_ACCUM_RED_SIZE
:
1771 *value
= xmvis
->mesa_visual
.accumRedBits
;
1773 case GLX_ACCUM_GREEN_SIZE
:
1774 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1776 case GLX_ACCUM_BLUE_SIZE
:
1777 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1779 case GLX_ACCUM_ALPHA_SIZE
:
1780 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1784 * GLX_EXT_visual_info extension
1786 case GLX_X_VISUAL_TYPE_EXT
:
1787 switch (xmvis
->visinfo
->CLASS
) {
1788 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1789 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1790 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1791 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1792 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1793 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1796 case GLX_TRANSPARENT_TYPE_EXT
:
1797 if (xmvis
->mesa_visual
.level
==0) {
1799 *value
= GLX_NONE_EXT
;
1801 else if (xmvis
->mesa_visual
.level
>0) {
1803 if (xmvis
->mesa_visual
.rgbMode
) {
1804 *value
= GLX_TRANSPARENT_RGB_EXT
;
1807 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1810 else if (xmvis
->mesa_visual
.level
<0) {
1812 *value
= GLX_NONE_EXT
;
1815 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1817 int pixel
= transparent_pixel( xmvis
);
1821 /* else undefined */
1824 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1827 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1830 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1833 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1838 * GLX_EXT_visual_info extension
1840 case GLX_VISUAL_CAVEAT_EXT
:
1841 /* test for zero, just in case */
1842 if (xmvis
->mesa_visual
.visualRating
> 0)
1843 *value
= xmvis
->mesa_visual
.visualRating
;
1845 *value
= GLX_NONE_EXT
;
1849 * GLX_ARB_multisample
1851 case GLX_SAMPLE_BUFFERS_ARB
:
1854 case GLX_SAMPLES_ARB
:
1861 case GLX_SCREEN_EXT
:
1863 return GLX_BAD_ATTRIBUTE
;
1864 *value
= xmvis
->visinfo
->screen
;
1866 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1868 return GLX_BAD_ATTRIBUTE
;
1869 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1871 case GLX_RENDER_TYPE_SGIX
:
1873 return GLX_BAD_ATTRIBUTE
;
1874 if (xmvis
->mesa_visual
.rgbMode
)
1875 *value
= GLX_RGBA_BIT
;
1877 *value
= GLX_COLOR_INDEX_BIT
;
1879 case GLX_X_RENDERABLE_SGIX
:
1881 return GLX_BAD_ATTRIBUTE
;
1882 *value
= True
; /* XXX really? */
1884 case GLX_FBCONFIG_ID_SGIX
:
1886 return GLX_BAD_ATTRIBUTE
;
1887 *value
= xmvis
->visinfo
->visualid
;
1889 case GLX_MAX_PBUFFER_WIDTH
:
1891 return GLX_BAD_ATTRIBUTE
;
1892 /* XXX or MAX_WIDTH? */
1893 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1895 case GLX_MAX_PBUFFER_HEIGHT
:
1897 return GLX_BAD_ATTRIBUTE
;
1898 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1900 case GLX_MAX_PBUFFER_PIXELS
:
1902 return GLX_BAD_ATTRIBUTE
;
1903 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1904 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1908 return GLX_BAD_ATTRIBUTE
;
1909 *value
= xmvis
->visinfo
->visualid
;
1912 #ifdef GLX_EXT_texture_from_pixmap
1913 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1914 *value
= True
; /*XXX*/
1916 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1918 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1920 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1921 *value
= True
; /*XXX*/
1923 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1924 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1925 GLX_TEXTURE_2D_BIT_EXT
|
1926 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1928 case GLX_Y_INVERTED_EXT
:
1929 *value
= True
; /*XXX*/
1934 return GLX_BAD_ATTRIBUTE
;
1941 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1942 int attrib
, int *value
)
1946 if (!dpy
|| !visinfo
)
1947 return GLX_BAD_ATTRIBUTE
;
1949 xmvis
= find_glx_visual( dpy
, visinfo
);
1951 /* this visual wasn't obtained with glXChooseVisual */
1952 xmvis
= create_glx_visual( dpy
, visinfo
);
1954 /* this visual can't be used for GL rendering */
1955 if (attrib
==GLX_USE_GL
) {
1956 *value
= (int) False
;
1960 return GLX_BAD_VISUAL
;
1965 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1971 Fake_glXWaitGL( void )
1973 XMesaContext xmesa
= XMesaGetCurrentContext();
1974 XMesaFlush( xmesa
);
1980 Fake_glXWaitX( void )
1982 XMesaContext xmesa
= XMesaGetCurrentContext();
1983 XMesaFlush( xmesa
);
1988 get_extensions( void )
1991 const char *fx
= _mesa_getenv("MESA_GLX_FX");
1992 if (fx
&& fx
[0] != 'd') {
1996 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
2001 /* GLX 1.1 and later */
2003 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
2007 return get_extensions();
2012 /* GLX 1.1 and later */
2014 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
2016 static char version
[1000];
2017 _mesa_sprintf(version
, "%d.%d %s",
2018 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
2024 case GLX_EXTENSIONS
:
2025 return get_extensions();
2037 /* GLX 1.1 and later */
2039 Fake_glXGetClientString( Display
*dpy
, int name
)
2041 static char version
[1000];
2042 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
2043 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
2048 case GLX_EXTENSIONS
:
2049 return get_extensions();
2067 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
2068 int attribute
, int *value
)
2070 XMesaVisual v
= (XMesaVisual
) config
;
2074 if (!dpy
|| !config
|| !value
)
2077 return get_config(v
, attribute
, value
, GL_TRUE
);
2081 static GLXFBConfig
*
2082 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
2084 XVisualInfo
*visuals
, visTemplate
;
2085 const long visMask
= VisualScreenMask
;
2088 /* Get list of all X visuals */
2089 visTemplate
.screen
= screen
;
2090 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
2091 if (*nelements
> 0) {
2092 XMesaVisual
*results
;
2093 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
2098 for (i
= 0; i
< *nelements
; i
++) {
2099 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
2101 return (GLXFBConfig
*) results
;
2107 static GLXFBConfig
*
2108 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
2109 const int *attribList
, int *nitems
)
2113 if (!attribList
|| !attribList
[0]) {
2114 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
2115 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
2118 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
2120 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
2126 config
[0] = (GLXFBConfig
) xmvis
;
2127 return (GLXFBConfig
*) config
;
2136 static XVisualInfo
*
2137 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
2139 if (dpy
&& config
) {
2140 XMesaVisual xmvis
= (XMesaVisual
) config
;
2142 return xmvis
->vishandle
;
2144 /* create a new vishandle - the cached one may be stale */
2145 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
2146 if (xmvis
->vishandle
) {
2147 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
2149 return xmvis
->vishandle
;
2159 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
2160 const int *attribList
)
2162 XMesaVisual xmvis
= (XMesaVisual
) config
;
2167 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
2172 /* XXX this will segfault if actually called */
2173 FXcreateContext(xmvis
, win
, NULL
, xmbuf
);
2177 (void) attribList
; /* Ignored in GLX 1.3 */
2179 return win
; /* A hack for now */
2184 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
2186 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2188 XMesaDestroyBuffer(b
);
2189 /* don't destroy X window */
2195 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2196 const int *attribList
)
2198 XMesaVisual v
= (XMesaVisual
) config
;
2201 int target
= 0, format
= 0, mipmap
= 0;
2204 if (!dpy
|| !config
|| !pixmap
)
2207 for (attr
= attribList
; *attr
; attr
++) {
2209 case GLX_TEXTURE_FORMAT_EXT
:
2212 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2213 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2214 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2222 case GLX_TEXTURE_TARGET_EXT
:
2225 case GLX_TEXTURE_1D_EXT
:
2226 case GLX_TEXTURE_2D_EXT
:
2227 case GLX_TEXTURE_RECTANGLE_EXT
:
2235 case GLX_MIPMAP_TEXTURE_EXT
:
2246 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2247 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2248 &value
, GL_TRUE
) != Success
2250 return 0; /* error! */
2253 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2254 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2255 &value
, GL_TRUE
) != Success
2257 return 0; /* error! */
2261 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2262 &value
, GL_TRUE
) != Success
2264 return 0; /* error! */
2267 if (target
== GLX_TEXTURE_1D_EXT
) {
2268 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2269 &value
, GL_TRUE
) != Success
2270 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2271 return 0; /* error! */
2274 else if (target
== GLX_TEXTURE_2D_EXT
) {
2275 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2276 &value
, GL_TRUE
) != Success
2277 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2278 return 0; /* error! */
2281 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2282 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2283 &value
, GL_TRUE
) != Success
2284 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2285 return 0; /* error! */
2289 if (format
|| target
|| mipmap
) {
2290 /* texture from pixmap */
2291 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2294 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2305 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2307 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2309 XMesaDestroyBuffer(b
);
2310 /* don't destroy X pixmap */
2315 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2316 const int *attribList
)
2318 XMesaVisual xmvis
= (XMesaVisual
) config
;
2321 int width
= 0, height
= 0;
2322 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2326 for (attrib
= attribList
; *attrib
; attrib
++) {
2328 case GLX_PBUFFER_WIDTH
:
2332 case GLX_PBUFFER_HEIGHT
:
2336 case GLX_PRESERVED_CONTENTS
:
2338 preserveContents
= *attrib
; /* ignored */
2340 case GLX_LARGEST_PBUFFER
:
2342 useLargest
= *attrib
; /* ignored */
2349 /* not used at this time */
2351 (void) preserveContents
;
2353 if (width
== 0 || height
== 0)
2356 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2357 /* A GLXPbuffer handle must be an X Drawable because that's what
2358 * glXMakeCurrent takes.
2361 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2368 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2370 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2372 XMesaDestroyBuffer(b
);
2378 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2379 unsigned int *value
)
2381 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2385 switch (attribute
) {
2387 *value
= xmbuf
->mesa_buffer
.Width
;
2390 *value
= xmbuf
->mesa_buffer
.Height
;
2392 case GLX_PRESERVED_CONTENTS
:
2395 case GLX_LARGEST_PBUFFER
:
2396 *value
= xmbuf
->mesa_buffer
.Width
* xmbuf
->mesa_buffer
.Height
;
2398 case GLX_FBCONFIG_ID
:
2399 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2401 #ifdef GLX_EXT_texture_from_pixmap
2402 case GLX_TEXTURE_FORMAT_EXT
:
2403 *value
= xmbuf
->TextureFormat
;
2405 case GLX_TEXTURE_TARGET_EXT
:
2406 *value
= xmbuf
->TextureTarget
;
2408 case GLX_MIPMAP_TEXTURE_EXT
:
2409 *value
= xmbuf
->TextureMipmap
;
2414 return; /* raise BadValue error */
2420 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2421 int renderType
, GLXContext shareList
, Bool direct
)
2423 struct fake_glx_context
*glxCtx
;
2424 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2425 XMesaVisual xmvis
= (XMesaVisual
) config
;
2427 if (!dpy
|| !config
||
2428 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2431 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2435 /* deallocate unused windows/buffers */
2436 XMesaGarbageCollect();
2438 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2439 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2440 if (!glxCtx
->xmesaContext
) {
2445 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2446 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2447 glxCtx
->glxContext
.currentDpy
= dpy
;
2448 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2450 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2452 return (GLXContext
) glxCtx
;
2457 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2459 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2460 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2465 switch (attribute
) {
2466 case GLX_FBCONFIG_ID
:
2467 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2469 case GLX_RENDER_TYPE
:
2470 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2471 *value
= GLX_RGBA_BIT
;
2473 *value
= GLX_COLOR_INDEX_BIT
;
2479 return GLX_BAD_ATTRIBUTE
;
2486 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2488 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2490 xmbuf
->selectedEvents
= mask
;
2495 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2496 unsigned long *mask
)
2498 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2500 *mask
= xmbuf
->selectedEvents
;
2507 /*** GLX_SGI_swap_control ***/
2510 Fake_glXSwapIntervalSGI(int interval
)
2518 /*** GLX_SGI_video_sync ***/
2520 static unsigned int FrameCounter
= 0;
2523 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2525 /* this is a bogus implementation */
2526 *count
= FrameCounter
++;
2531 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2533 if (divisor
<= 0 || remainder
< 0)
2534 return GLX_BAD_VALUE
;
2535 /* this is a bogus implementation */
2537 while (FrameCounter
% divisor
!= remainder
)
2539 *count
= FrameCounter
;
2545 /*** GLX_SGI_make_current_read ***/
2548 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2550 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2555 Fake_glXGetCurrentReadDrawableSGI(void)
2562 /*** GLX_SGIX_video_source ***/
2565 static GLXVideoSourceSGIX
2566 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2578 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2587 /*** GLX_EXT_import_context ***/
2590 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2597 Fake_glXGetContextIDEXT(const GLXContext context
)
2604 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2612 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2623 /*** GLX_SGIX_fbconfig ***/
2626 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2628 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2631 static GLXFBConfigSGIX
*
2632 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2634 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2639 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2641 XMesaVisual xmvis
= (XMesaVisual
) config
;
2642 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2643 return xmbuf
->frontxrb
->pixmap
; /* need to return an X ID */
2648 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2650 XMesaVisual xmvis
= (XMesaVisual
) config
;
2651 struct fake_glx_context
*glxCtx
;
2652 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2654 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2658 /* deallocate unused windows/buffers */
2659 XMesaGarbageCollect();
2661 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2662 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2663 if (!glxCtx
->xmesaContext
) {
2668 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2669 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2670 glxCtx
->glxContext
.currentDpy
= dpy
;
2671 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2673 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2675 return (GLXContext
) glxCtx
;
2679 static XVisualInfo
*
2680 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2682 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2686 static GLXFBConfigSGIX
2687 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2689 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2691 /* This visual wasn't found with glXChooseVisual() */
2692 xmvis
= create_glx_visual(dpy
, vis
);
2695 return (GLXFBConfigSGIX
) xmvis
;
2700 /*** GLX_SGIX_pbuffer ***/
2702 static GLXPbufferSGIX
2703 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2704 unsigned int width
, unsigned int height
,
2707 XMesaVisual xmvis
= (XMesaVisual
) config
;
2710 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2714 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2716 case GLX_PRESERVED_CONTENTS_SGIX
:
2718 preserveContents
= *attrib
; /* ignored */
2720 case GLX_LARGEST_PBUFFER_SGIX
:
2722 useLargest
= *attrib
; /* ignored */
2729 /* not used at this time */
2731 (void) preserveContents
;
2733 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2734 /* A GLXPbuffer handle must be an X Drawable because that's what
2735 * glXMakeCurrent takes.
2737 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2742 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2744 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2746 XMesaDestroyBuffer(xmbuf
);
2752 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2754 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2757 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2761 switch (attribute
) {
2762 case GLX_PRESERVED_CONTENTS_SGIX
:
2765 case GLX_LARGEST_PBUFFER_SGIX
:
2766 *value
= xmbuf
->mesa_buffer
.Width
* xmbuf
->mesa_buffer
.Height
;
2768 case GLX_WIDTH_SGIX
:
2769 *value
= xmbuf
->mesa_buffer
.Width
;
2771 case GLX_HEIGHT_SGIX
:
2772 *value
= xmbuf
->mesa_buffer
.Height
;
2774 case GLX_EVENT_MASK_SGIX
:
2775 *value
= 0; /* XXX might be wrong */
2785 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2787 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2789 /* Note: we'll never generate clobber events */
2790 xmbuf
->selectedEvents
= mask
;
2796 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2798 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2800 *mask
= xmbuf
->selectedEvents
;
2809 /*** GLX_SGI_cushion ***/
2812 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2821 /*** GLX_SGIX_video_resize ***/
2824 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2834 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2847 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2860 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2873 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2884 /*** GLX_SGIX_dmbuffer **/
2886 #if defined(_DM_BUFFER_H_)
2888 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2899 /*** GLX_SGIX_swap_group ***/
2902 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2911 /*** GLX_SGIX_swap_barrier ***/
2914 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2922 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2932 /*** GLX_SUN_get_transparent_index ***/
2935 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2940 (void) pTransparent
;
2946 /*** GLX_MESA_release_buffers ***/
2949 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2950 * (a window or pixmap) prior to destroying the GLXDrawable.
2953 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2955 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2957 XMesaDestroyBuffer(b
);
2965 /*** GLX_MESA_set_3dfx_mode ***/
2968 Fake_glXSet3DfxModeMESA( int mode
)
2970 return XMesaSetFXmode( mode
);
2975 /*** GLX_NV_vertex_array range ***/
2977 Fake_glXAllocateMemoryNV( GLsizei size
,
2978 GLfloat readFrequency
,
2979 GLfloat writeFrequency
,
2983 (void) readFrequency
;
2984 (void) writeFrequency
;
2991 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2997 /*** GLX_MESA_agp_offset ***/
3000 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
3007 /*** GLX_EXT_texture_from_pixmap ***/
3010 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
3011 const int *attrib_list
)
3013 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3015 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
3019 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
3021 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3023 XMesaReleaseTexImage(dpy
, b
, buffer
);
3027 /* silence warning */
3028 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
3032 * Create a new GLX API dispatch table with its function pointers
3033 * initialized to point to Mesa's "fake" GLX API functions.
3034 * Note: there's a similar function (_real_GetGLXDispatchTable) that
3035 * returns a new dispatch table with all pointers initalized to point
3036 * to "real" GLX functions (which understand GLX wire protocol, etc).
3038 struct _glxapi_table
*
3039 _mesa_GetGLXDispatchTable(void)
3041 static struct _glxapi_table glx
;
3043 /* be sure our dispatch table size <= libGL's table */
3045 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
3047 assert(_glxapi_get_dispatch_table_size() >= size
);
3050 /* initialize the whole table to no-ops */
3051 _glxapi_set_no_op_table(&glx
);
3053 /* now initialize the table with the functions I implement */
3054 glx
.ChooseVisual
= Fake_glXChooseVisual
;
3055 glx
.CopyContext
= Fake_glXCopyContext
;
3056 glx
.CreateContext
= Fake_glXCreateContext
;
3057 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
3058 glx
.DestroyContext
= Fake_glXDestroyContext
;
3059 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
3060 glx
.GetConfig
= Fake_glXGetConfig
;
3061 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
3062 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
3063 glx
.IsDirect
= Fake_glXIsDirect
;
3064 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
3065 glx
.QueryExtension
= Fake_glXQueryExtension
;
3066 glx
.QueryVersion
= Fake_glXQueryVersion
;
3067 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
3068 glx
.UseXFont
= Fake_glXUseXFont
;
3069 glx
.WaitGL
= Fake_glXWaitGL
;
3070 glx
.WaitX
= Fake_glXWaitX
;
3072 /*** GLX_VERSION_1_1 ***/
3073 glx
.GetClientString
= Fake_glXGetClientString
;
3074 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
3075 glx
.QueryServerString
= Fake_glXQueryServerString
;
3077 /*** GLX_VERSION_1_2 ***/
3078 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
3080 /*** GLX_VERSION_1_3 ***/
3081 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
3082 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
3083 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
3084 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
3085 glx
.CreateWindow
= Fake_glXCreateWindow
;
3086 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
3087 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
3088 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
3089 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
3090 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
3091 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
3092 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
3093 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
3094 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
3095 glx
.QueryContext
= Fake_glXQueryContext
;
3096 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
3097 glx
.SelectEvent
= Fake_glXSelectEvent
;
3099 /*** GLX_SGI_swap_control ***/
3100 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
3102 /*** GLX_SGI_video_sync ***/
3103 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
3104 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
3106 /*** GLX_SGI_make_current_read ***/
3107 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
3108 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
3110 /*** GLX_SGIX_video_source ***/
3112 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
3113 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
3116 /*** GLX_EXT_import_context ***/
3117 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
3118 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
3119 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
3120 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
3121 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
3123 /*** GLX_SGIX_fbconfig ***/
3124 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
3125 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
3126 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
3127 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
3128 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
3129 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
3131 /*** GLX_SGIX_pbuffer ***/
3132 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
3133 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
3134 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
3135 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
3136 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
3138 /*** GLX_SGI_cushion ***/
3139 glx
.CushionSGI
= Fake_glXCushionSGI
;
3141 /*** GLX_SGIX_video_resize ***/
3142 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
3143 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
3144 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
3145 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
3146 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
3148 /*** GLX_SGIX_dmbuffer **/
3149 #if defined(_DM_BUFFER_H_)
3150 glx
.AssociateDMPbufferSGIX
= NULL
;
3153 /*** GLX_SGIX_swap_group ***/
3154 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
3156 /*** GLX_SGIX_swap_barrier ***/
3157 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
3158 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
3160 /*** GLX_SUN_get_transparent_index ***/
3161 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
3163 /*** GLX_MESA_copy_sub_buffer ***/
3164 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3166 /*** GLX_MESA_release_buffers ***/
3167 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3169 /*** GLX_MESA_pixmap_colormap ***/
3170 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3172 /*** GLX_MESA_set_3dfx_mode ***/
3173 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3175 /*** GLX_NV_vertex_array_range ***/
3176 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3177 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3179 /*** GLX_MESA_agp_offset ***/
3180 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3182 /*** GLX_EXT_texture_from_pixmap ***/
3183 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3184 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;