2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
29 * to run on X servers which do not have the real GLX extension.
31 * Thanks to the contributors:
33 * Initial version: Philip Brown (phil@bolthole.com)
34 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
35 * Further visual-handling refinements: Wolfram Gloger
36 * (wmglo@Dent.MED.Uni-Muenchen.DE).
39 * Don't be fooled, stereo isn't supported yet.
44 #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 * Init basic fields of a new fake_glx_context.
1400 init_glx_context(struct fake_glx_context
*glxCtx
, Display
*dpy
)
1402 /* Always return True. See if anyone's confused... */
1403 GLboolean direct
= GL_TRUE
;
1405 glxCtx
->xmesaContext
->direct
= direct
;
1406 glxCtx
->glxContext
.isDirect
= direct
;
1407 glxCtx
->glxContext
.currentDpy
= dpy
;
1408 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1410 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1416 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1417 GLXContext share_list
, Bool direct
)
1420 struct fake_glx_context
*glxCtx
;
1421 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1423 if (!dpy
|| !visinfo
)
1426 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1430 /* deallocate unused windows/buffers */
1432 XMesaGarbageCollect();
1435 xmvis
= find_glx_visual( dpy
, visinfo
);
1437 /* This visual wasn't found with glXChooseVisual() */
1438 xmvis
= create_glx_visual( dpy
, visinfo
);
1440 /* unusable visual */
1446 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1447 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1448 if (!glxCtx
->xmesaContext
) {
1453 init_glx_context(glxCtx
, dpy
);
1455 return (GLXContext
) glxCtx
;
1459 /* XXX these may have to be removed due to thread-safety issues. */
1460 static GLXContext MakeCurrent_PrevContext
= 0;
1461 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1462 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1463 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1464 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1467 /* GLX 1.3 and later */
1469 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1470 GLXDrawable read
, GLXContext ctx
)
1472 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1474 if (ctx
&& draw
&& read
) {
1475 XMesaBuffer drawBuffer
, readBuffer
;
1476 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1478 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1479 if (ctx
== MakeCurrent_PrevContext
1480 && draw
== MakeCurrent_PrevDrawable
) {
1481 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1484 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1487 /* drawable must be a new window! */
1488 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1490 /* Out of memory, or context/drawable depth mismatch */
1494 FXcreateContext( xmctx
->xm_visual
, draw
, xmctx
, drawBuffer
);
1498 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1499 if (ctx
== MakeCurrent_PrevContext
1500 && read
== MakeCurrent_PrevReadable
) {
1501 readBuffer
= MakeCurrent_PrevReadBuffer
;
1504 readBuffer
= XMesaFindBuffer( dpy
, read
);
1507 /* drawable must be a new window! */
1508 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1510 /* Out of memory, or context/drawable depth mismatch */
1514 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
;
1524 /* Now make current! */
1525 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1526 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1527 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1528 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1535 else if (!ctx
&& !draw
&& !read
) {
1536 /* release current context w/out assigning new one. */
1537 XMesaMakeCurrent( NULL
, NULL
);
1538 MakeCurrent_PrevContext
= 0;
1539 MakeCurrent_PrevDrawable
= 0;
1540 MakeCurrent_PrevReadable
= 0;
1541 MakeCurrent_PrevDrawBuffer
= 0;
1542 MakeCurrent_PrevReadBuffer
= 0;
1546 /* The args must either all be non-zero or all zero.
1555 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1557 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1562 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1567 v
= find_glx_visual( dpy
, visinfo
);
1569 v
= create_glx_visual( dpy
, visinfo
);
1571 /* unusable visual */
1576 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1580 return b
->frontxrb
->pixmap
;
1584 /*** GLX_MESA_pixmap_colormap ***/
1587 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1588 Pixmap pixmap
, Colormap cmap
)
1593 v
= find_glx_visual( dpy
, visinfo
);
1595 v
= create_glx_visual( dpy
, visinfo
);
1597 /* unusable visual */
1602 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1606 return b
->frontxrb
->pixmap
;
1611 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1613 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1615 XMesaDestroyBuffer(b
);
1617 else if (_mesa_getenv("MESA_DEBUG")) {
1618 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1624 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1625 unsigned long mask
)
1627 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1628 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1629 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1630 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1632 if (MakeCurrent_PrevContext
== src
) {
1635 _mesa_copy_context( &(xm_src
->mesa
), &(xm_dst
->mesa
), (GLuint
) mask
);
1640 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1642 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1650 extern void _kw_ungrab_all( Display
*dpy
);
1651 void _kw_ungrab_all( Display
*dpy
)
1653 XUngrabPointer( dpy
, CurrentTime
);
1654 XUngrabKeyboard( dpy
, CurrentTime
);
1659 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1661 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1663 MakeCurrent_PrevContext
= 0;
1664 MakeCurrent_PrevDrawable
= 0;
1665 MakeCurrent_PrevReadable
= 0;
1666 MakeCurrent_PrevDrawBuffer
= 0;
1667 MakeCurrent_PrevReadBuffer
= 0;
1668 XMesaDestroyContext( glxCtx
->xmesaContext
);
1669 XMesaGarbageCollect();
1675 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1677 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1679 return glxCtx
->xmesaContext
->direct
;
1685 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1687 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1690 XMesaSwapBuffers(buffer
);
1692 else if (_mesa_getenv("MESA_DEBUG")) {
1693 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1700 /*** GLX_MESA_copy_sub_buffer ***/
1703 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1704 int x
, int y
, int width
, int height
)
1706 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1708 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1710 else if (_mesa_getenv("MESA_DEBUG")) {
1711 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1717 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1720 /* Return GLX version, not Mesa version */
1721 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1722 *maj
= CLIENT_MAJOR_VERSION
;
1723 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1729 * Query the GLX attributes of the given XVisualInfo.
1732 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1738 return GLX_BAD_ATTRIBUTE
;
1739 *value
= (int) True
;
1741 case GLX_BUFFER_SIZE
:
1742 *value
= xmvis
->visinfo
->depth
;
1745 *value
= xmvis
->mesa_visual
.level
;
1749 return GLX_BAD_ATTRIBUTE
;
1750 if (xmvis
->mesa_visual
.rgbMode
) {
1757 case GLX_DOUBLEBUFFER
:
1758 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1761 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1763 case GLX_AUX_BUFFERS
:
1764 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1767 *value
= xmvis
->mesa_visual
.redBits
;
1769 case GLX_GREEN_SIZE
:
1770 *value
= xmvis
->mesa_visual
.greenBits
;
1773 *value
= xmvis
->mesa_visual
.blueBits
;
1775 case GLX_ALPHA_SIZE
:
1776 *value
= xmvis
->mesa_visual
.alphaBits
;
1778 case GLX_DEPTH_SIZE
:
1779 *value
= xmvis
->mesa_visual
.depthBits
;
1781 case GLX_STENCIL_SIZE
:
1782 *value
= xmvis
->mesa_visual
.stencilBits
;
1784 case GLX_ACCUM_RED_SIZE
:
1785 *value
= xmvis
->mesa_visual
.accumRedBits
;
1787 case GLX_ACCUM_GREEN_SIZE
:
1788 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1790 case GLX_ACCUM_BLUE_SIZE
:
1791 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1793 case GLX_ACCUM_ALPHA_SIZE
:
1794 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1798 * GLX_EXT_visual_info extension
1800 case GLX_X_VISUAL_TYPE_EXT
:
1801 switch (xmvis
->visinfo
->CLASS
) {
1802 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1803 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1804 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1805 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1806 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1807 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1810 case GLX_TRANSPARENT_TYPE_EXT
:
1811 if (xmvis
->mesa_visual
.level
==0) {
1813 *value
= GLX_NONE_EXT
;
1815 else if (xmvis
->mesa_visual
.level
>0) {
1817 if (xmvis
->mesa_visual
.rgbMode
) {
1818 *value
= GLX_TRANSPARENT_RGB_EXT
;
1821 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1824 else if (xmvis
->mesa_visual
.level
<0) {
1826 *value
= GLX_NONE_EXT
;
1829 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1831 int pixel
= transparent_pixel( xmvis
);
1835 /* else undefined */
1838 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1841 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1844 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1847 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1852 * GLX_EXT_visual_info extension
1854 case GLX_VISUAL_CAVEAT_EXT
:
1855 /* test for zero, just in case */
1856 if (xmvis
->mesa_visual
.visualRating
> 0)
1857 *value
= xmvis
->mesa_visual
.visualRating
;
1859 *value
= GLX_NONE_EXT
;
1863 * GLX_ARB_multisample
1865 case GLX_SAMPLE_BUFFERS_ARB
:
1868 case GLX_SAMPLES_ARB
:
1875 case GLX_SCREEN_EXT
:
1877 return GLX_BAD_ATTRIBUTE
;
1878 *value
= xmvis
->visinfo
->screen
;
1880 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1882 return GLX_BAD_ATTRIBUTE
;
1883 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1885 case GLX_RENDER_TYPE_SGIX
:
1887 return GLX_BAD_ATTRIBUTE
;
1888 if (xmvis
->mesa_visual
.rgbMode
)
1889 *value
= GLX_RGBA_BIT
;
1891 *value
= GLX_COLOR_INDEX_BIT
;
1893 case GLX_X_RENDERABLE_SGIX
:
1895 return GLX_BAD_ATTRIBUTE
;
1896 *value
= True
; /* XXX really? */
1898 case GLX_FBCONFIG_ID_SGIX
:
1900 return GLX_BAD_ATTRIBUTE
;
1901 *value
= xmvis
->visinfo
->visualid
;
1903 case GLX_MAX_PBUFFER_WIDTH
:
1905 return GLX_BAD_ATTRIBUTE
;
1906 /* XXX or MAX_WIDTH? */
1907 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1909 case GLX_MAX_PBUFFER_HEIGHT
:
1911 return GLX_BAD_ATTRIBUTE
;
1912 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1914 case GLX_MAX_PBUFFER_PIXELS
:
1916 return GLX_BAD_ATTRIBUTE
;
1917 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1918 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1922 return GLX_BAD_ATTRIBUTE
;
1923 *value
= xmvis
->visinfo
->visualid
;
1926 #ifdef GLX_EXT_texture_from_pixmap
1927 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1928 *value
= True
; /*XXX*/
1930 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1932 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1934 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1935 *value
= True
; /*XXX*/
1937 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1938 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1939 GLX_TEXTURE_2D_BIT_EXT
|
1940 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1942 case GLX_Y_INVERTED_EXT
:
1943 *value
= True
; /*XXX*/
1948 return GLX_BAD_ATTRIBUTE
;
1955 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1956 int attrib
, int *value
)
1960 if (!dpy
|| !visinfo
)
1961 return GLX_BAD_ATTRIBUTE
;
1963 xmvis
= find_glx_visual( dpy
, visinfo
);
1965 /* this visual wasn't obtained with glXChooseVisual */
1966 xmvis
= create_glx_visual( dpy
, visinfo
);
1968 /* this visual can't be used for GL rendering */
1969 if (attrib
==GLX_USE_GL
) {
1970 *value
= (int) False
;
1974 return GLX_BAD_VISUAL
;
1979 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1985 Fake_glXWaitGL( void )
1987 XMesaContext xmesa
= XMesaGetCurrentContext();
1988 XMesaFlush( xmesa
);
1994 Fake_glXWaitX( void )
1996 XMesaContext xmesa
= XMesaGetCurrentContext();
1997 XMesaFlush( xmesa
);
2002 get_extensions( void )
2005 const char *fx
= _mesa_getenv("MESA_GLX_FX");
2006 if (fx
&& fx
[0] != 'd') {
2010 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
2015 /* GLX 1.1 and later */
2017 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
2021 return get_extensions();
2026 /* GLX 1.1 and later */
2028 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
2030 static char version
[1000];
2031 _mesa_sprintf(version
, "%d.%d %s",
2032 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
2038 case GLX_EXTENSIONS
:
2039 return get_extensions();
2051 /* GLX 1.1 and later */
2053 Fake_glXGetClientString( Display
*dpy
, int name
)
2055 static char version
[1000];
2056 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
2057 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
2062 case GLX_EXTENSIONS
:
2063 return get_extensions();
2081 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
2082 int attribute
, int *value
)
2084 XMesaVisual v
= (XMesaVisual
) config
;
2088 if (!dpy
|| !config
|| !value
)
2091 return get_config(v
, attribute
, value
, GL_TRUE
);
2095 static GLXFBConfig
*
2096 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
2098 XVisualInfo
*visuals
, visTemplate
;
2099 const long visMask
= VisualScreenMask
;
2102 /* Get list of all X visuals */
2103 visTemplate
.screen
= screen
;
2104 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
2105 if (*nelements
> 0) {
2106 XMesaVisual
*results
;
2107 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
2112 for (i
= 0; i
< *nelements
; i
++) {
2113 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
2115 return (GLXFBConfig
*) results
;
2121 static GLXFBConfig
*
2122 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
2123 const int *attribList
, int *nitems
)
2127 if (!attribList
|| !attribList
[0]) {
2128 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
2129 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
2132 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
2134 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
2140 config
[0] = (GLXFBConfig
) xmvis
;
2141 return (GLXFBConfig
*) config
;
2150 static XVisualInfo
*
2151 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
2153 if (dpy
&& config
) {
2154 XMesaVisual xmvis
= (XMesaVisual
) config
;
2156 return xmvis
->vishandle
;
2158 /* create a new vishandle - the cached one may be stale */
2159 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
2160 if (xmvis
->vishandle
) {
2161 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
2163 return xmvis
->vishandle
;
2173 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
2174 const int *attribList
)
2176 XMesaVisual xmvis
= (XMesaVisual
) config
;
2181 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
2186 /* XXX this will segfault if actually called */
2187 FXcreateContext(xmvis
, win
, NULL
, xmbuf
);
2191 (void) attribList
; /* Ignored in GLX 1.3 */
2193 return win
; /* A hack for now */
2198 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
2200 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2202 XMesaDestroyBuffer(b
);
2203 /* don't destroy X window */
2209 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2210 const int *attribList
)
2212 XMesaVisual v
= (XMesaVisual
) config
;
2215 int target
= 0, format
= 0, mipmap
= 0;
2218 if (!dpy
|| !config
|| !pixmap
)
2221 for (attr
= attribList
; attr
&& *attr
; attr
++) {
2223 case GLX_TEXTURE_FORMAT_EXT
:
2226 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2227 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2228 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2236 case GLX_TEXTURE_TARGET_EXT
:
2239 case GLX_TEXTURE_1D_EXT
:
2240 case GLX_TEXTURE_2D_EXT
:
2241 case GLX_TEXTURE_RECTANGLE_EXT
:
2249 case GLX_MIPMAP_TEXTURE_EXT
:
2260 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2261 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2262 &value
, GL_TRUE
) != Success
2264 return 0; /* error! */
2267 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2268 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2269 &value
, GL_TRUE
) != Success
2271 return 0; /* error! */
2275 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2276 &value
, GL_TRUE
) != Success
2278 return 0; /* error! */
2281 if (target
== GLX_TEXTURE_1D_EXT
) {
2282 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2283 &value
, GL_TRUE
) != Success
2284 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2285 return 0; /* error! */
2288 else if (target
== GLX_TEXTURE_2D_EXT
) {
2289 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2290 &value
, GL_TRUE
) != Success
2291 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2292 return 0; /* error! */
2295 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2296 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2297 &value
, GL_TRUE
) != Success
2298 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2299 return 0; /* error! */
2303 if (format
|| target
|| mipmap
) {
2304 /* texture from pixmap */
2305 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2308 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2319 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2321 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2323 XMesaDestroyBuffer(b
);
2324 /* don't destroy X pixmap */
2329 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2330 const int *attribList
)
2332 XMesaVisual xmvis
= (XMesaVisual
) config
;
2335 int width
= 0, height
= 0;
2336 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2340 for (attrib
= attribList
; *attrib
; attrib
++) {
2342 case GLX_PBUFFER_WIDTH
:
2346 case GLX_PBUFFER_HEIGHT
:
2350 case GLX_PRESERVED_CONTENTS
:
2352 preserveContents
= *attrib
; /* ignored */
2354 case GLX_LARGEST_PBUFFER
:
2356 useLargest
= *attrib
; /* ignored */
2363 /* not used at this time */
2365 (void) preserveContents
;
2367 if (width
== 0 || height
== 0)
2370 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2371 /* A GLXPbuffer handle must be an X Drawable because that's what
2372 * glXMakeCurrent takes.
2375 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2382 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2384 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2386 XMesaDestroyBuffer(b
);
2392 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2393 unsigned int *value
)
2395 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2399 switch (attribute
) {
2401 *value
= xmbuf
->mesa_buffer
.Width
;
2404 *value
= xmbuf
->mesa_buffer
.Height
;
2406 case GLX_PRESERVED_CONTENTS
:
2409 case GLX_LARGEST_PBUFFER
:
2410 *value
= xmbuf
->mesa_buffer
.Width
* xmbuf
->mesa_buffer
.Height
;
2412 case GLX_FBCONFIG_ID
:
2413 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2415 #ifdef GLX_EXT_texture_from_pixmap
2416 case GLX_TEXTURE_FORMAT_EXT
:
2417 *value
= xmbuf
->TextureFormat
;
2419 case GLX_TEXTURE_TARGET_EXT
:
2420 *value
= xmbuf
->TextureTarget
;
2422 case GLX_MIPMAP_TEXTURE_EXT
:
2423 *value
= xmbuf
->TextureMipmap
;
2428 return; /* raise BadValue error */
2434 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2435 int renderType
, GLXContext shareList
, Bool direct
)
2437 struct fake_glx_context
*glxCtx
;
2438 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2439 XMesaVisual xmvis
= (XMesaVisual
) config
;
2441 if (!dpy
|| !config
||
2442 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2445 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2449 /* deallocate unused windows/buffers */
2450 XMesaGarbageCollect();
2452 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2453 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2454 if (!glxCtx
->xmesaContext
) {
2459 init_glx_context(glxCtx
, dpy
);
2461 return (GLXContext
) glxCtx
;
2466 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2468 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2469 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2474 switch (attribute
) {
2475 case GLX_FBCONFIG_ID
:
2476 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2478 case GLX_RENDER_TYPE
:
2479 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2480 *value
= GLX_RGBA_TYPE
;
2482 *value
= GLX_COLOR_INDEX_TYPE
;
2488 return GLX_BAD_ATTRIBUTE
;
2495 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2497 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2499 xmbuf
->selectedEvents
= mask
;
2504 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2505 unsigned long *mask
)
2507 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2509 *mask
= xmbuf
->selectedEvents
;
2516 /*** GLX_SGI_swap_control ***/
2519 Fake_glXSwapIntervalSGI(int interval
)
2527 /*** GLX_SGI_video_sync ***/
2529 static unsigned int FrameCounter
= 0;
2532 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2534 /* this is a bogus implementation */
2535 *count
= FrameCounter
++;
2540 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2542 if (divisor
<= 0 || remainder
< 0)
2543 return GLX_BAD_VALUE
;
2544 /* this is a bogus implementation */
2546 while (FrameCounter
% divisor
!= remainder
)
2548 *count
= FrameCounter
;
2554 /*** GLX_SGI_make_current_read ***/
2557 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2559 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2564 Fake_glXGetCurrentReadDrawableSGI(void)
2571 /*** GLX_SGIX_video_source ***/
2574 static GLXVideoSourceSGIX
2575 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2587 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2596 /*** GLX_EXT_import_context ***/
2599 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2606 Fake_glXGetContextIDEXT(const GLXContext context
)
2613 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2621 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2632 /*** GLX_SGIX_fbconfig ***/
2635 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2637 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2640 static GLXFBConfigSGIX
*
2641 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2643 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2648 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2650 XMesaVisual xmvis
= (XMesaVisual
) config
;
2651 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2652 return xmbuf
->frontxrb
->pixmap
; /* need to return an X ID */
2657 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2659 XMesaVisual xmvis
= (XMesaVisual
) config
;
2660 struct fake_glx_context
*glxCtx
;
2661 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2663 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2667 /* deallocate unused windows/buffers */
2668 XMesaGarbageCollect();
2670 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2671 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2672 if (!glxCtx
->xmesaContext
) {
2677 init_glx_context(glxCtx
, dpy
);
2679 return (GLXContext
) glxCtx
;
2683 static XVisualInfo
*
2684 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2686 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2690 static GLXFBConfigSGIX
2691 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2693 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2695 /* This visual wasn't found with glXChooseVisual() */
2696 xmvis
= create_glx_visual(dpy
, vis
);
2699 return (GLXFBConfigSGIX
) xmvis
;
2704 /*** GLX_SGIX_pbuffer ***/
2706 static GLXPbufferSGIX
2707 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2708 unsigned int width
, unsigned int height
,
2711 XMesaVisual xmvis
= (XMesaVisual
) config
;
2714 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2718 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2720 case GLX_PRESERVED_CONTENTS_SGIX
:
2722 preserveContents
= *attrib
; /* ignored */
2724 case GLX_LARGEST_PBUFFER_SGIX
:
2726 useLargest
= *attrib
; /* ignored */
2733 /* not used at this time */
2735 (void) preserveContents
;
2737 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2738 /* A GLXPbuffer handle must be an X Drawable because that's what
2739 * glXMakeCurrent takes.
2741 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2746 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2748 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2750 XMesaDestroyBuffer(xmbuf
);
2756 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2758 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2761 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2765 switch (attribute
) {
2766 case GLX_PRESERVED_CONTENTS_SGIX
:
2769 case GLX_LARGEST_PBUFFER_SGIX
:
2770 *value
= xmbuf
->mesa_buffer
.Width
* xmbuf
->mesa_buffer
.Height
;
2772 case GLX_WIDTH_SGIX
:
2773 *value
= xmbuf
->mesa_buffer
.Width
;
2775 case GLX_HEIGHT_SGIX
:
2776 *value
= xmbuf
->mesa_buffer
.Height
;
2778 case GLX_EVENT_MASK_SGIX
:
2779 *value
= 0; /* XXX might be wrong */
2789 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2791 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2793 /* Note: we'll never generate clobber events */
2794 xmbuf
->selectedEvents
= mask
;
2800 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2802 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2804 *mask
= xmbuf
->selectedEvents
;
2813 /*** GLX_SGI_cushion ***/
2816 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2825 /*** GLX_SGIX_video_resize ***/
2828 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2838 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2851 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2864 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2877 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2888 /*** GLX_SGIX_dmbuffer **/
2890 #if defined(_DM_BUFFER_H_)
2892 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2903 /*** GLX_SGIX_swap_group ***/
2906 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2915 /*** GLX_SGIX_swap_barrier ***/
2918 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2926 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2936 /*** GLX_SUN_get_transparent_index ***/
2939 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2944 (void) pTransparent
;
2950 /*** GLX_MESA_release_buffers ***/
2953 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2954 * (a window or pixmap) prior to destroying the GLXDrawable.
2957 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2959 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2961 XMesaDestroyBuffer(b
);
2969 /*** GLX_MESA_set_3dfx_mode ***/
2972 Fake_glXSet3DfxModeMESA( int mode
)
2974 return XMesaSetFXmode( mode
);
2979 /*** GLX_NV_vertex_array range ***/
2981 Fake_glXAllocateMemoryNV( GLsizei size
,
2982 GLfloat readFrequency
,
2983 GLfloat writeFrequency
,
2987 (void) readFrequency
;
2988 (void) writeFrequency
;
2995 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
3001 /*** GLX_MESA_agp_offset ***/
3004 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
3011 /*** GLX_EXT_texture_from_pixmap ***/
3014 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
3015 const int *attrib_list
)
3017 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3019 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
3023 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
3025 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3027 XMesaReleaseTexImage(dpy
, b
, buffer
);
3031 /* silence warning */
3032 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
3036 * Create a new GLX API dispatch table with its function pointers
3037 * initialized to point to Mesa's "fake" GLX API functions.
3038 * Note: there's a similar function (_real_GetGLXDispatchTable) that
3039 * returns a new dispatch table with all pointers initalized to point
3040 * to "real" GLX functions (which understand GLX wire protocol, etc).
3042 struct _glxapi_table
*
3043 _mesa_GetGLXDispatchTable(void)
3045 static struct _glxapi_table glx
;
3047 /* be sure our dispatch table size <= libGL's table */
3049 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
3051 assert(_glxapi_get_dispatch_table_size() >= size
);
3054 /* initialize the whole table to no-ops */
3055 _glxapi_set_no_op_table(&glx
);
3057 /* now initialize the table with the functions I implement */
3058 glx
.ChooseVisual
= Fake_glXChooseVisual
;
3059 glx
.CopyContext
= Fake_glXCopyContext
;
3060 glx
.CreateContext
= Fake_glXCreateContext
;
3061 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
3062 glx
.DestroyContext
= Fake_glXDestroyContext
;
3063 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
3064 glx
.GetConfig
= Fake_glXGetConfig
;
3065 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
3066 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
3067 glx
.IsDirect
= Fake_glXIsDirect
;
3068 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
3069 glx
.QueryExtension
= Fake_glXQueryExtension
;
3070 glx
.QueryVersion
= Fake_glXQueryVersion
;
3071 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
3072 glx
.UseXFont
= Fake_glXUseXFont
;
3073 glx
.WaitGL
= Fake_glXWaitGL
;
3074 glx
.WaitX
= Fake_glXWaitX
;
3076 /*** GLX_VERSION_1_1 ***/
3077 glx
.GetClientString
= Fake_glXGetClientString
;
3078 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
3079 glx
.QueryServerString
= Fake_glXQueryServerString
;
3081 /*** GLX_VERSION_1_2 ***/
3082 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
3084 /*** GLX_VERSION_1_3 ***/
3085 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
3086 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
3087 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
3088 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
3089 glx
.CreateWindow
= Fake_glXCreateWindow
;
3090 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
3091 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
3092 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
3093 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
3094 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
3095 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
3096 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
3097 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
3098 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
3099 glx
.QueryContext
= Fake_glXQueryContext
;
3100 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
3101 glx
.SelectEvent
= Fake_glXSelectEvent
;
3103 /*** GLX_SGI_swap_control ***/
3104 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
3106 /*** GLX_SGI_video_sync ***/
3107 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
3108 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
3110 /*** GLX_SGI_make_current_read ***/
3111 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
3112 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
3114 /*** GLX_SGIX_video_source ***/
3116 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
3117 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
3120 /*** GLX_EXT_import_context ***/
3121 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
3122 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
3123 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
3124 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
3125 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
3127 /*** GLX_SGIX_fbconfig ***/
3128 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
3129 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
3130 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
3131 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
3132 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
3133 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
3135 /*** GLX_SGIX_pbuffer ***/
3136 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
3137 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
3138 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
3139 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
3140 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
3142 /*** GLX_SGI_cushion ***/
3143 glx
.CushionSGI
= Fake_glXCushionSGI
;
3145 /*** GLX_SGIX_video_resize ***/
3146 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
3147 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
3148 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
3149 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
3150 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
3152 /*** GLX_SGIX_dmbuffer **/
3153 #if defined(_DM_BUFFER_H_)
3154 glx
.AssociateDMPbufferSGIX
= NULL
;
3157 /*** GLX_SGIX_swap_group ***/
3158 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
3160 /*** GLX_SGIX_swap_barrier ***/
3161 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
3162 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
3164 /*** GLX_SUN_get_transparent_index ***/
3165 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
3167 /*** GLX_MESA_copy_sub_buffer ***/
3168 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3170 /*** GLX_MESA_release_buffers ***/
3171 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3173 /*** GLX_MESA_pixmap_colormap ***/
3174 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3176 /*** GLX_MESA_set_3dfx_mode ***/
3177 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3179 /*** GLX_NV_vertex_array_range ***/
3180 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3181 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3183 /*** GLX_MESA_agp_offset ***/
3184 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3186 /*** GLX_EXT_texture_from_pixmap ***/
3187 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3188 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;