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"
45 #include "main/context.h"
46 #include "main/config.h"
47 #include "main/macros.h"
48 #include "main/imports.h"
49 #include "main/mtypes.h"
50 #include "main/version.h"
55 #define _mesa_sprintf sprintf
58 /* This indicates the client-side GLX API and GLX encoder version. */
59 #define CLIENT_MAJOR_VERSION 1
60 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
62 /* This indicates the server-side GLX decoder version.
63 * GLX 1.4 indicates OpenGL 1.3 support
65 #define SERVER_MAJOR_VERSION 1
66 #define SERVER_MINOR_VERSION 4
68 /* This is appended onto the glXGetClient/ServerString version strings. */
69 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
71 /* Who implemented this GLX? */
72 #define VENDOR "Brian Paul"
75 "GLX_MESA_set_3dfx_mode " \
76 "GLX_MESA_copy_sub_buffer " \
77 "GLX_MESA_pixmap_colormap " \
78 "GLX_MESA_release_buffers " \
79 "GLX_ARB_get_proc_address " \
80 "GLX_EXT_texture_from_pixmap " \
81 "GLX_EXT_visual_info " \
82 "GLX_EXT_visual_rating " \
83 /*"GLX_SGI_video_sync "*/ \
84 "GLX_SGIX_fbconfig " \
88 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
90 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
93 * We really just need this structure in order to make the libGL functions
94 * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
97 struct fake_glx_context
{
98 __GLXcontext glxContext
; /* this MUST be first! */
99 XMesaContext xmesaContext
;
104 /**********************************************************************/
105 /*** GLX Visual Code ***/
106 /**********************************************************************/
111 static XMesaVisual
*VisualTable
= NULL
;
112 static int NumVisuals
= 0;
116 * This struct and some code fragments borrowed
117 * from Mark Kilgard's GLUT library.
119 typedef struct _OverlayInfo
{
120 /* Avoid 64-bit portability problems by being careful to use
121 longs due to the way XGetWindowProperty is specified. Note
122 that these parameters are passed as CARD32s over X
124 unsigned long overlay_visual
;
125 long transparent_type
;
132 /* Macro to handle c_class vs class field name in XVisualInfo struct */
133 #if defined(__cplusplus) || defined(c_plusplus)
134 #define CLASS c_class
142 * Test if the given XVisualInfo is usable for Mesa rendering.
145 is_usable_visual( XVisualInfo
*vinfo
)
147 switch (vinfo
->CLASS
) {
150 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
154 /* Any StaticColor/PseudoColor visual of at least 4 bits */
155 if (vinfo
->depth
>=4) {
163 /* Any depth of TrueColor or DirectColor works in RGB mode */
166 /* This should never happen */
174 * Get an array OverlayInfo records for specified screen.
175 * \param dpy the display
176 * \param screen screen number
177 * \param numOverlays returns numver of OverlayInfo records
178 * \return pointer to OverlayInfo array, free with XFree()
181 GetOverlayInfo(Display
*dpy
, int screen
, int *numOverlays
)
183 Atom overlayVisualsAtom
;
186 unsigned char *ovInfo
;
187 unsigned long sizeData
, bytesLeft
;
191 * The SERVER_OVERLAY_VISUALS property on the root window contains
192 * a list of overlay visuals. Get that list now.
194 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
195 if (overlayVisualsAtom
== None
) {
199 status
= XGetWindowProperty(dpy
, RootWindow(dpy
, screen
),
200 overlayVisualsAtom
, 0L, (long) 10000, False
,
201 overlayVisualsAtom
, &actualType
, &actualFormat
,
202 &sizeData
, &bytesLeft
,
205 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
206 actualFormat
!= 32 || sizeData
< 4) {
207 /* something went wrong */
208 XFree((void *) ovInfo
);
213 *numOverlays
= sizeData
/ 4;
214 return (OverlayInfo
*) ovInfo
;
220 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
221 * Input: dpy - the X display
222 * vinfo - the XVisualInfo to test
223 * Return: level of the visual:
225 * >0 = overlay planes
226 * <0 = underlay planes
229 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
231 OverlayInfo
*overlay_info
;
232 int numOverlaysPerScreen
, i
;
234 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
239 /* search the overlay visual list for the visual ID of interest */
240 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
241 const OverlayInfo
*ov
= overlay_info
+ i
;
242 if (ov
->overlay_visual
== vinfo
->visualid
) {
243 /* found the visual */
244 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
245 int level
= ov
->layer
;
246 XFree((void *) overlay_info
);
250 XFree((void *) overlay_info
);
256 /* The visual ID was not found in the overlay list. */
257 XFree((void *) overlay_info
);
265 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
266 * configuration in our list of GLX visuals.
269 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
270 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
271 GLboolean stereoFlag
,
272 GLint depth_size
, GLint stencil_size
,
273 GLint accumRedSize
, GLint accumGreenSize
,
274 GLint accumBlueSize
, GLint accumAlphaSize
,
275 GLint level
, GLint numAuxBuffers
)
277 GLboolean ximageFlag
= GL_TRUE
;
280 GLboolean comparePointers
;
283 /* Check if the MESA_BACK_BUFFER env var is set */
284 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
286 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
287 ximageFlag
= GL_FALSE
;
289 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
290 ximageFlag
= GL_TRUE
;
293 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
299 /* stereo not supported */
303 /* Comparing IDs uses less memory but sometimes fails. */
304 /* XXX revisit this after 3.0 is finished. */
305 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
306 comparePointers
= GL_TRUE
;
308 comparePointers
= GL_FALSE
;
310 /* Force the visual to have an alpha channel */
311 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
314 /* First check if a matching visual is already in the list */
315 for (i
=0; i
<NumVisuals
; i
++) {
316 XMesaVisual v
= VisualTable
[i
];
317 if (v
->display
== dpy
318 && v
->mesa_visual
.level
== level
319 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
320 && v
->ximage_flag
== ximageFlag
321 && v
->mesa_visual
.rgbMode
== rgbFlag
322 && v
->mesa_visual
.doubleBufferMode
== dbFlag
323 && v
->mesa_visual
.stereoMode
== stereoFlag
324 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
325 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
326 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
327 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
328 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
329 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
330 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
331 /* now either compare XVisualInfo pointers or visual IDs */
332 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
333 || (comparePointers
&& v
->vishandle
== vinfo
)) {
339 /* Create a new visual and add it to the list. */
341 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
342 stereoFlag
, ximageFlag
,
343 depth_size
, stencil_size
,
344 accumRedSize
, accumBlueSize
,
345 accumBlueSize
, accumAlphaSize
, 0, level
,
348 /* Save a copy of the pointer now so we can find this visual again
349 * if we need to search for it in find_glx_visual().
351 xmvis
->vishandle
= vinfo
;
352 /* Allocate more space for additional visual */
353 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
354 sizeof(XMesaVisual
) * NumVisuals
,
355 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
356 /* add xmvis to the list */
357 VisualTable
[NumVisuals
] = xmvis
;
359 /* XXX minor hack, because XMesaCreateVisual doesn't support an
360 * aux buffers parameter.
362 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
369 * Return the default number of bits for the Z buffer.
370 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
371 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
372 * XXX probably do the same thing for stencil, accum, etc.
375 default_depth_bits(void)
378 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
380 zBits
= _mesa_atoi(zEnv
);
382 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
387 default_alpha_bits(void)
390 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
392 aBits
= _mesa_atoi(aEnv
);
399 default_accum_bits(void)
407 * Create a GLX visual from a regular XVisualInfo.
408 * This is called when Fake GLX is given an XVisualInfo which wasn't
409 * returned by glXChooseVisual. Since this is the first time we're
410 * considering this visual we'll take a guess at reasonable values
411 * for depth buffer size, stencil size, accum size, etc.
412 * This is the best we can do with a client-side emulation of GLX.
415 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
418 GLint zBits
= default_depth_bits();
419 GLint accBits
= default_accum_bits();
420 GLboolean alphaFlag
= default_alpha_bits() > 0;
422 vislevel
= level_of_visual( dpy
, visinfo
);
424 /* Configure this visual as a CI, single-buffered overlay */
425 return save_glx_visual( dpy
, visinfo
,
427 GL_FALSE
, /* alpha */
428 GL_FALSE
, /* double */
429 GL_FALSE
, /* stereo */
431 0, /* stencil bits */
432 0,0,0,0, /* accum bits */
433 vislevel
, /* level */
437 else if (is_usable_visual( visinfo
)) {
438 if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
439 /* Configure this visual as a COLOR INDEX visual. */
440 return save_glx_visual( dpy
, visinfo
,
442 GL_FALSE
, /* alpha */
443 GL_TRUE
, /* double */
444 GL_FALSE
, /* stereo */
447 0, 0, 0, 0, /* accum bits */
453 /* Configure this visual as RGB, double-buffered, depth-buffered. */
454 /* This is surely wrong for some people's needs but what else */
455 /* can be done? They should use glXChooseVisual(). */
456 return save_glx_visual( dpy
, visinfo
,
458 alphaFlag
, /* alpha */
459 GL_TRUE
, /* double */
460 GL_FALSE
, /* stereo */
473 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
481 * Find the GLX visual associated with an XVisualInfo.
484 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
488 /* try to match visual id */
489 for (i
=0;i
<NumVisuals
;i
++) {
490 if (VisualTable
[i
]->display
==dpy
491 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
492 return VisualTable
[i
];
496 /* if that fails, try to match pointers */
497 for (i
=0;i
<NumVisuals
;i
++) {
498 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
499 return VisualTable
[i
];
509 * Return the transparent pixel value for a GLX visual.
510 * Input: glxvis - the glx_visual
511 * Return: a pixel value or -1 if no transparent pixel
514 transparent_pixel( XMesaVisual glxvis
)
516 Display
*dpy
= glxvis
->display
;
517 XVisualInfo
*vinfo
= glxvis
->visinfo
;
518 OverlayInfo
*overlay_info
;
519 int numOverlaysPerScreen
, i
;
521 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
526 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
527 const OverlayInfo
*ov
= overlay_info
+ i
;
528 if (ov
->overlay_visual
== vinfo
->visualid
) {
530 if (ov
->transparent_type
== 0) {
531 /* type 0 indicates no transparency */
532 XFree((void *) overlay_info
);
536 /* ov->value is the transparent pixel */
537 XFree((void *) overlay_info
);
543 /* The visual ID was not found in the overlay list. */
544 XFree((void *) overlay_info
);
551 * Try to get an X visual which matches the given arguments.
554 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
556 XVisualInfo temp
, *vis
;
559 unsigned int default_depth
;
562 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
567 default_depth
= DefaultDepth(dpy
,scr
);
568 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
570 if (depth
==default_depth
&& xclass
==default_class
) {
571 /* try to get root window's visual */
572 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
573 mask
|= VisualIDMask
;
576 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
578 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
579 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
580 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
582 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
583 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
584 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
585 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
600 * Retrieve the value of the given environment variable and find
601 * the X visual which matches it.
602 * Input: dpy - the display
603 * screen - the screen number
604 * varname - the name of the environment variable
605 * Return: an XVisualInfo pointer to NULL if error.
608 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
610 char value
[100], type
[100];
611 int depth
, xclass
= -1;
614 if (!_mesa_getenv( varname
)) {
618 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
621 sscanf( value
, "%s %d", type
, &depth
);
623 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
624 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
625 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
626 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
627 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
628 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
630 if (xclass
>-1 && depth
>0) {
631 vis
= get_visual( dpy
, scr
, depth
, xclass
);
637 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
646 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
647 * Input: dpy, screen - X display and screen number
648 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
649 * min_depth - minimum visual depth
650 * preferred_class - preferred GLX visual class or DONT_CARE
651 * Return: pointer to an XVisualInfo or NULL.
654 choose_x_visual( Display
*dpy
, int screen
, GLboolean rgba
, int min_depth
,
655 int preferred_class
)
658 int xclass
, visclass
= 0;
662 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
663 /* First see if the MESA_RGB_VISUAL env var is defined */
664 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
668 /* Otherwise, search for a suitable visual */
669 if (preferred_class
==DONT_CARE
) {
670 for (xclass
=0;xclass
<6;xclass
++) {
672 case 0: visclass
= TrueColor
; break;
673 case 1: visclass
= DirectColor
; break;
674 case 2: visclass
= PseudoColor
; break;
675 case 3: visclass
= StaticColor
; break;
676 case 4: visclass
= GrayScale
; break;
677 case 5: visclass
= StaticGray
; break;
680 /* start with shallowest */
681 for (depth
=0;depth
<=32;depth
++) {
682 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
683 /* Special case: try to get 8-bit PseudoColor before */
684 /* 8-bit TrueColor */
685 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
690 vis
= get_visual( dpy
, screen
, depth
, visclass
);
697 /* start with deepest */
698 for (depth
=32;depth
>=min_depth
;depth
--) {
699 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
700 /* Special case: try to get 8-bit PseudoColor before */
701 /* 8-bit TrueColor */
702 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
707 vis
= get_visual( dpy
, screen
, depth
, visclass
);
716 /* search for a specific visual class */
717 switch (preferred_class
) {
718 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
719 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
720 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
721 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
722 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
723 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
724 default: return NULL
;
727 /* start with shallowest */
728 for (depth
=0;depth
<=32;depth
++) {
729 vis
= get_visual( dpy
, screen
, depth
, visclass
);
736 /* start with deepest */
737 for (depth
=32;depth
>=min_depth
;depth
--) {
738 vis
= get_visual( dpy
, screen
, depth
, visclass
);
747 /* First see if the MESA_CI_VISUAL env var is defined */
748 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
752 /* Otherwise, search for a suitable visual, starting with shallowest */
753 if (preferred_class
==DONT_CARE
) {
754 for (xclass
=0;xclass
<4;xclass
++) {
756 case 0: visclass
= PseudoColor
; break;
757 case 1: visclass
= StaticColor
; break;
758 case 2: visclass
= GrayScale
; break;
759 case 3: visclass
= StaticGray
; break;
761 /* try 8-bit up through 16-bit */
762 for (depth
=8;depth
<=16;depth
++) {
763 vis
= get_visual( dpy
, screen
, depth
, visclass
);
768 /* try min_depth up to 8-bit */
769 for (depth
=min_depth
;depth
<8;depth
++) {
770 vis
= get_visual( dpy
, screen
, depth
, visclass
);
778 /* search for a specific visual class */
779 switch (preferred_class
) {
780 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
781 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
782 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
783 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
784 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
785 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
786 default: return NULL
;
788 /* try 8-bit up through 16-bit */
789 for (depth
=8;depth
<=16;depth
++) {
790 vis
= get_visual( dpy
, screen
, depth
, visclass
);
795 /* try min_depth up to 8-bit */
796 for (depth
=min_depth
;depth
<8;depth
++) {
797 vis
= get_visual( dpy
, screen
, depth
, visclass
);
805 /* didn't find a visual */
812 * Find the deepest X over/underlay visual of at least min_depth.
813 * Input: dpy, screen - X display and screen number
814 * level - the over/underlay level
815 * trans_type - transparent pixel type: GLX_NONE_EXT,
816 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
818 * trans_value - transparent pixel value or DONT_CARE
819 * min_depth - minimum visual depth
820 * preferred_class - preferred GLX visual class or DONT_CARE
821 * Return: pointer to an XVisualInfo or NULL.
824 choose_x_overlay_visual( Display
*dpy
, int scr
, GLboolean rgbFlag
,
825 int level
, int trans_type
, int trans_value
,
826 int min_depth
, int preferred_class
)
828 OverlayInfo
*overlay_info
;
829 int numOverlaysPerScreen
;
831 XVisualInfo
*deepvis
;
834 /*DEBUG int tt, tv; */
836 switch (preferred_class
) {
837 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
838 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
839 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
840 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
841 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
842 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
843 default: preferred_class
= DONT_CARE
;
846 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
851 /* Search for the deepest overlay which satisifies all criteria. */
855 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
856 const OverlayInfo
*ov
= overlay_info
+ i
;
857 XVisualInfo
*vislist
, vistemplate
;
860 if (ov
->layer
!=level
) {
861 /* failed overlay level criteria */
864 if (!(trans_type
==DONT_CARE
865 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
866 && ov
->transparent_type
>0)
867 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
868 /* failed transparent pixel type criteria */
871 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
872 /* failed transparent pixel value criteria */
876 /* get XVisualInfo and check the depth */
877 vistemplate
.visualid
= ov
->overlay_visual
;
878 vistemplate
.screen
= scr
;
879 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
880 &vistemplate
, &count
);
883 /* something went wrong */
886 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
887 /* wrong visual class */
891 /* if RGB was requested, make sure we have True/DirectColor */
892 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
893 && vislist
->CLASS
!= DirectColor
)
896 /* if CI was requested, make sure we have a color indexed visual */
898 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
901 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
902 /* YES! found a satisfactory visual */
906 deepest
= vislist
->depth
;
908 /* DEBUG tt = ov->transparent_type;*/
909 /* DEBUG tv = ov->value; */
915 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
916 deepvis->visualid, level, deepvis->depth, tt, tv );
923 /**********************************************************************/
924 /*** Display-related functions ***/
925 /**********************************************************************/
929 * Free all XMesaVisuals which are associated with the given display.
932 destroy_visuals_on_display(Display
*dpy
)
935 for (i
= 0; i
< NumVisuals
; i
++) {
936 if (VisualTable
[i
]->display
== dpy
) {
937 /* remove this visual */
939 free(VisualTable
[i
]);
940 for (j
= i
; j
< NumVisuals
- 1; j
++)
941 VisualTable
[j
] = VisualTable
[j
+ 1];
949 * Called from XCloseDisplay() to let us free our display-related data.
952 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
954 destroy_visuals_on_display(dpy
);
955 xmesa_destroy_buffers_on_display(dpy
);
961 * Look for the named extension on given display and return a pointer
962 * to the _XExtension data, or NULL if extension not found.
965 lookup_extension(Display
*dpy
, const char *extName
)
968 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
969 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
978 * Whenever we're given a new Display pointer, call this function to
979 * register our close_display_callback function.
982 register_with_display(Display
*dpy
)
984 const char *extName
= "MesaGLX";
987 ext
= lookup_extension(dpy
, extName
);
989 XExtCodes
*c
= XAddExtension(dpy
);
990 ext
= dpy
->ext_procs
; /* new extension is at head of list */
991 assert(c
->extension
== ext
->codes
.extension
);
992 ext
->name
= _mesa_strdup(extName
);
993 ext
->close_display
= close_display_callback
;
998 /**********************************************************************/
999 /*** Begin Fake GLX API Functions ***/
1000 /**********************************************************************/
1004 * Helper used by glXChooseVisual and glXChooseFBConfig.
1005 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
1007 * In either case, the attribute list is terminated with the value 'None'.
1010 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
1012 const GLboolean rgbModeDefault
= fbConfig
;
1013 const int *parselist
;
1016 int min_red
=0, min_green
=0, min_blue
=0;
1017 GLboolean rgb_flag
= rgbModeDefault
;
1018 GLboolean alpha_flag
= GL_FALSE
;
1019 GLboolean double_flag
= GL_FALSE
;
1020 GLboolean stereo_flag
= GL_FALSE
;
1021 GLint depth_size
= 0;
1022 GLint stencil_size
= 0;
1023 GLint accumRedSize
= 0;
1024 GLint accumGreenSize
= 0;
1025 GLint accumBlueSize
= 0;
1026 GLint accumAlphaSize
= 0;
1028 int visual_type
= DONT_CARE
;
1029 int trans_type
= DONT_CARE
;
1030 int trans_value
= DONT_CARE
;
1031 GLint caveat
= DONT_CARE
;
1032 XMesaVisual xmvis
= NULL
;
1033 int desiredVisualID
= -1;
1038 while (*parselist
) {
1040 switch (*parselist
) {
1051 case GLX_BUFFER_SIZE
:
1053 min_ci
= *parselist
++;
1057 level
= *parselist
++;
1069 case GLX_DOUBLEBUFFER
:
1072 double_flag
= *parselist
++;
1075 double_flag
= GL_TRUE
;
1081 stereo_flag
= *parselist
++;
1084 stereo_flag
= GL_TRUE
;
1087 case GLX_AUX_BUFFERS
:
1089 numAux
= *parselist
++;
1090 if (numAux
> MAX_AUX_BUFFERS
)
1095 min_red
= *parselist
++;
1097 case GLX_GREEN_SIZE
:
1099 min_green
= *parselist
++;
1103 min_blue
= *parselist
++;
1105 case GLX_ALPHA_SIZE
:
1108 GLint size
= *parselist
++;
1109 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
1112 case GLX_DEPTH_SIZE
:
1114 depth_size
= *parselist
++;
1116 case GLX_STENCIL_SIZE
:
1118 stencil_size
= *parselist
++;
1120 case GLX_ACCUM_RED_SIZE
:
1123 GLint size
= *parselist
++;
1124 accumRedSize
= MAX2( accumRedSize
, size
);
1127 case GLX_ACCUM_GREEN_SIZE
:
1130 GLint size
= *parselist
++;
1131 accumGreenSize
= MAX2( accumGreenSize
, size
);
1134 case GLX_ACCUM_BLUE_SIZE
:
1137 GLint size
= *parselist
++;
1138 accumBlueSize
= MAX2( accumBlueSize
, size
);
1141 case GLX_ACCUM_ALPHA_SIZE
:
1144 GLint size
= *parselist
++;
1145 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1150 * GLX_EXT_visual_info extension
1152 case GLX_X_VISUAL_TYPE_EXT
:
1154 visual_type
= *parselist
++;
1156 case GLX_TRANSPARENT_TYPE_EXT
:
1158 trans_type
= *parselist
++;
1160 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1162 trans_value
= *parselist
++;
1164 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1165 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1166 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1167 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1174 * GLX_EXT_visual_info extension
1176 case GLX_VISUAL_CAVEAT_EXT
:
1178 caveat
= *parselist
++; /* ignored for now */
1182 * GLX_ARB_multisample
1184 case GLX_SAMPLE_BUFFERS_ARB
:
1185 case GLX_SAMPLES_ARB
:
1187 if (*parselist
++ != 0)
1188 /* ms not supported */
1195 case GLX_RENDER_TYPE
:
1199 if (*parselist
== GLX_RGBA_BIT
) {
1202 else if (*parselist
== GLX_COLOR_INDEX_BIT
) {
1203 rgb_flag
= GL_FALSE
;
1205 else if (*parselist
== 0) {
1210 case GLX_DRAWABLE_TYPE
:
1214 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1215 return NULL
; /* bad bit */
1219 case GLX_FBCONFIG_ID
:
1223 desiredVisualID
= *parselist
++;
1225 case GLX_X_RENDERABLE
:
1232 #ifdef GLX_EXT_texture_from_pixmap
1233 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1234 parselist
++; /*skip*/
1236 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1237 parselist
++; /*skip*/
1239 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1240 parselist
++; /*skip*/
1242 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1244 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1245 GLX_TEXTURE_2D_BIT_EXT
|
1246 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1251 case GLX_Y_INVERTED_EXT
:
1252 parselist
++; /*skip*/
1261 /* undefined attribute */
1262 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1271 * Since we're only simulating the GLX extension this function will never
1272 * find any real GL visuals. Instead, all we can do is try to find an RGB
1273 * or CI visual of appropriate depth. Other requested attributes such as
1274 * double buffering, depth buffer, etc. will be associated with the X
1275 * visual and stored in the VisualTable[].
1277 if (desiredVisualID
!= -1) {
1278 /* try to get a specific visual, by visualID */
1281 temp
.visualid
= desiredVisualID
;
1282 temp
.screen
= screen
;
1283 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1285 /* give the visual some useful GLX attributes */
1286 double_flag
= GL_TRUE
;
1289 depth_size
= default_depth_bits();
1290 stencil_size
= STENCIL_BITS
;
1294 else if (level
==0) {
1295 /* normal color planes */
1297 /* Get an RGB visual */
1298 int min_rgb
= min_red
+ min_green
+ min_blue
;
1299 if (min_rgb
>1 && min_rgb
<8) {
1300 /* a special case to be sure we can get a monochrome visual */
1303 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1306 /* Get a color index visual */
1307 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1308 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1312 /* over/underlay planes */
1315 int min_rgb
= min_red
+ min_green
+ min_blue
;
1316 if (min_rgb
>1 && min_rgb
<8) {
1317 /* a special case to be sure we can get a monochrome visual */
1320 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1321 trans_type
, trans_value
, min_rgb
, visual_type
);
1324 /* color index overlay */
1325 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1326 trans_type
, trans_value
, min_ci
, visual_type
);
1331 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1332 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1333 * largest depth buffer size, which is 32bits/value. Instead, we
1334 * return 16 to maintain performance with earlier versions of Mesa.
1336 if (depth_size
> 24)
1338 else if (depth_size
> 16)
1340 else if (depth_size
> 0) {
1341 depth_size
= default_depth_bits();
1345 alpha_flag
= default_alpha_bits() > 0;
1348 /* we only support one size of stencil and accum buffers. */
1349 if (stencil_size
> 0)
1350 stencil_size
= STENCIL_BITS
;
1351 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1352 accumAlphaSize
> 0) {
1355 accumBlueSize
= default_accum_bits();
1356 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1359 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1360 stereo_flag
, depth_size
, stencil_size
,
1361 accumRedSize
, accumGreenSize
,
1362 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1369 static XVisualInfo
*
1370 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1374 /* register ourselves as an extension on this display */
1375 register_with_display(dpy
);
1377 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1380 return xmvis
->vishandle
;
1382 /* create a new vishandle - the cached one may be stale */
1383 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1384 if (xmvis
->vishandle
) {
1385 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1387 return xmvis
->vishandle
;
1396 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1397 GLXContext share_list
, Bool direct
)
1400 struct fake_glx_context
*glxCtx
;
1401 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1403 if (!dpy
|| !visinfo
)
1406 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1410 /* deallocate unused windows/buffers */
1412 XMesaGarbageCollect();
1415 xmvis
= find_glx_visual( dpy
, visinfo
);
1417 /* This visual wasn't found with glXChooseVisual() */
1418 xmvis
= create_glx_visual( dpy
, visinfo
);
1420 /* unusable visual */
1426 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1427 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1428 if (!glxCtx
->xmesaContext
) {
1433 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
1434 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
1435 glxCtx
->glxContext
.currentDpy
= dpy
;
1436 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1438 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1440 return (GLXContext
) glxCtx
;
1444 /* XXX these may have to be removed due to thread-safety issues. */
1445 static GLXContext MakeCurrent_PrevContext
= 0;
1446 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1447 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1448 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1449 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1452 /* GLX 1.3 and later */
1454 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1455 GLXDrawable read
, GLXContext ctx
)
1457 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1459 if (ctx
&& draw
&& read
) {
1460 XMesaBuffer drawBuffer
, readBuffer
;
1461 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1463 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1464 if (ctx
== MakeCurrent_PrevContext
1465 && draw
== MakeCurrent_PrevDrawable
) {
1466 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1469 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1472 /* drawable must be a new window! */
1473 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1475 /* Out of memory, or context/drawable depth mismatch */
1479 FXcreateContext( xmctx
->xm_visual
, draw
, xmctx
, drawBuffer
);
1483 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1484 if (ctx
== MakeCurrent_PrevContext
1485 && read
== MakeCurrent_PrevReadable
) {
1486 readBuffer
= MakeCurrent_PrevReadBuffer
;
1489 readBuffer
= XMesaFindBuffer( dpy
, read
);
1492 /* drawable must be a new window! */
1493 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1495 /* Out of memory, or context/drawable depth mismatch */
1499 FXcreateContext( xmctx
->xm_visual
, read
, xmctx
, readBuffer
);
1503 MakeCurrent_PrevContext
= ctx
;
1504 MakeCurrent_PrevDrawable
= draw
;
1505 MakeCurrent_PrevReadable
= read
;
1506 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1507 MakeCurrent_PrevReadBuffer
= readBuffer
;
1509 /* Now make current! */
1510 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1511 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1512 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1513 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1520 else if (!ctx
&& !draw
&& !read
) {
1521 /* release current context w/out assigning new one. */
1522 XMesaMakeCurrent( NULL
, NULL
);
1523 MakeCurrent_PrevContext
= 0;
1524 MakeCurrent_PrevDrawable
= 0;
1525 MakeCurrent_PrevReadable
= 0;
1526 MakeCurrent_PrevDrawBuffer
= 0;
1527 MakeCurrent_PrevReadBuffer
= 0;
1531 /* The args must either all be non-zero or all zero.
1540 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1542 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1547 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1552 v
= find_glx_visual( dpy
, visinfo
);
1554 v
= create_glx_visual( dpy
, visinfo
);
1556 /* unusable visual */
1561 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1565 return b
->frontxrb
->pixmap
;
1569 /*** GLX_MESA_pixmap_colormap ***/
1572 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1573 Pixmap pixmap
, Colormap cmap
)
1578 v
= find_glx_visual( dpy
, visinfo
);
1580 v
= create_glx_visual( dpy
, visinfo
);
1582 /* unusable visual */
1587 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1591 return b
->frontxrb
->pixmap
;
1596 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1598 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1600 XMesaDestroyBuffer(b
);
1602 else if (_mesa_getenv("MESA_DEBUG")) {
1603 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1609 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1610 unsigned long mask
)
1612 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1613 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1614 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1615 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1617 if (MakeCurrent_PrevContext
== src
) {
1620 _mesa_copy_context( &(xm_src
->mesa
), &(xm_dst
->mesa
), (GLuint
) mask
);
1625 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1627 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1635 extern void _kw_ungrab_all( Display
*dpy
);
1636 void _kw_ungrab_all( Display
*dpy
)
1638 XUngrabPointer( dpy
, CurrentTime
);
1639 XUngrabKeyboard( dpy
, CurrentTime
);
1644 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1646 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1648 MakeCurrent_PrevContext
= 0;
1649 MakeCurrent_PrevDrawable
= 0;
1650 MakeCurrent_PrevReadable
= 0;
1651 MakeCurrent_PrevDrawBuffer
= 0;
1652 MakeCurrent_PrevReadBuffer
= 0;
1653 XMesaDestroyContext( glxCtx
->xmesaContext
);
1654 XMesaGarbageCollect();
1660 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1662 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1664 return glxCtx
->xmesaContext
->direct
;
1670 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1672 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1675 XMesaSwapBuffers(buffer
);
1677 else if (_mesa_getenv("MESA_DEBUG")) {
1678 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1685 /*** GLX_MESA_copy_sub_buffer ***/
1688 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1689 int x
, int y
, int width
, int height
)
1691 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1693 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1695 else if (_mesa_getenv("MESA_DEBUG")) {
1696 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1702 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1705 /* Return GLX version, not Mesa version */
1706 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1707 *maj
= CLIENT_MAJOR_VERSION
;
1708 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1714 * Query the GLX attributes of the given XVisualInfo.
1717 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1723 return GLX_BAD_ATTRIBUTE
;
1724 *value
= (int) True
;
1726 case GLX_BUFFER_SIZE
:
1727 *value
= xmvis
->visinfo
->depth
;
1730 *value
= xmvis
->mesa_visual
.level
;
1734 return GLX_BAD_ATTRIBUTE
;
1735 if (xmvis
->mesa_visual
.rgbMode
) {
1742 case GLX_DOUBLEBUFFER
:
1743 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1746 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1748 case GLX_AUX_BUFFERS
:
1749 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1752 *value
= xmvis
->mesa_visual
.redBits
;
1754 case GLX_GREEN_SIZE
:
1755 *value
= xmvis
->mesa_visual
.greenBits
;
1758 *value
= xmvis
->mesa_visual
.blueBits
;
1760 case GLX_ALPHA_SIZE
:
1761 *value
= xmvis
->mesa_visual
.alphaBits
;
1763 case GLX_DEPTH_SIZE
:
1764 *value
= xmvis
->mesa_visual
.depthBits
;
1766 case GLX_STENCIL_SIZE
:
1767 *value
= xmvis
->mesa_visual
.stencilBits
;
1769 case GLX_ACCUM_RED_SIZE
:
1770 *value
= xmvis
->mesa_visual
.accumRedBits
;
1772 case GLX_ACCUM_GREEN_SIZE
:
1773 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1775 case GLX_ACCUM_BLUE_SIZE
:
1776 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1778 case GLX_ACCUM_ALPHA_SIZE
:
1779 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1783 * GLX_EXT_visual_info extension
1785 case GLX_X_VISUAL_TYPE_EXT
:
1786 switch (xmvis
->visinfo
->CLASS
) {
1787 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1788 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1789 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1790 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1791 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1792 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1795 case GLX_TRANSPARENT_TYPE_EXT
:
1796 if (xmvis
->mesa_visual
.level
==0) {
1798 *value
= GLX_NONE_EXT
;
1800 else if (xmvis
->mesa_visual
.level
>0) {
1802 if (xmvis
->mesa_visual
.rgbMode
) {
1803 *value
= GLX_TRANSPARENT_RGB_EXT
;
1806 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1809 else if (xmvis
->mesa_visual
.level
<0) {
1811 *value
= GLX_NONE_EXT
;
1814 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1816 int pixel
= transparent_pixel( xmvis
);
1820 /* else undefined */
1823 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1826 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1829 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1832 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1837 * GLX_EXT_visual_info extension
1839 case GLX_VISUAL_CAVEAT_EXT
:
1840 /* test for zero, just in case */
1841 if (xmvis
->mesa_visual
.visualRating
> 0)
1842 *value
= xmvis
->mesa_visual
.visualRating
;
1844 *value
= GLX_NONE_EXT
;
1848 * GLX_ARB_multisample
1850 case GLX_SAMPLE_BUFFERS_ARB
:
1853 case GLX_SAMPLES_ARB
:
1860 case GLX_SCREEN_EXT
:
1862 return GLX_BAD_ATTRIBUTE
;
1863 *value
= xmvis
->visinfo
->screen
;
1865 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1867 return GLX_BAD_ATTRIBUTE
;
1868 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1870 case GLX_RENDER_TYPE_SGIX
:
1872 return GLX_BAD_ATTRIBUTE
;
1873 if (xmvis
->mesa_visual
.rgbMode
)
1874 *value
= GLX_RGBA_BIT
;
1876 *value
= GLX_COLOR_INDEX_BIT
;
1878 case GLX_X_RENDERABLE_SGIX
:
1880 return GLX_BAD_ATTRIBUTE
;
1881 *value
= True
; /* XXX really? */
1883 case GLX_FBCONFIG_ID_SGIX
:
1885 return GLX_BAD_ATTRIBUTE
;
1886 *value
= xmvis
->visinfo
->visualid
;
1888 case GLX_MAX_PBUFFER_WIDTH
:
1890 return GLX_BAD_ATTRIBUTE
;
1891 /* XXX or MAX_WIDTH? */
1892 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1894 case GLX_MAX_PBUFFER_HEIGHT
:
1896 return GLX_BAD_ATTRIBUTE
;
1897 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1899 case GLX_MAX_PBUFFER_PIXELS
:
1901 return GLX_BAD_ATTRIBUTE
;
1902 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1903 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1907 return GLX_BAD_ATTRIBUTE
;
1908 *value
= xmvis
->visinfo
->visualid
;
1911 #ifdef GLX_EXT_texture_from_pixmap
1912 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1913 *value
= True
; /*XXX*/
1915 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1917 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1919 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1920 *value
= True
; /*XXX*/
1922 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1923 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1924 GLX_TEXTURE_2D_BIT_EXT
|
1925 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1927 case GLX_Y_INVERTED_EXT
:
1928 *value
= True
; /*XXX*/
1933 return GLX_BAD_ATTRIBUTE
;
1940 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1941 int attrib
, int *value
)
1945 if (!dpy
|| !visinfo
)
1946 return GLX_BAD_ATTRIBUTE
;
1948 xmvis
= find_glx_visual( dpy
, visinfo
);
1950 /* this visual wasn't obtained with glXChooseVisual */
1951 xmvis
= create_glx_visual( dpy
, visinfo
);
1953 /* this visual can't be used for GL rendering */
1954 if (attrib
==GLX_USE_GL
) {
1955 *value
= (int) False
;
1959 return GLX_BAD_VISUAL
;
1964 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1970 Fake_glXWaitGL( void )
1972 XMesaContext xmesa
= XMesaGetCurrentContext();
1973 XMesaFlush( xmesa
);
1979 Fake_glXWaitX( void )
1981 XMesaContext xmesa
= XMesaGetCurrentContext();
1982 XMesaFlush( xmesa
);
1987 get_extensions( void )
1990 const char *fx
= _mesa_getenv("MESA_GLX_FX");
1991 if (fx
&& fx
[0] != 'd') {
1995 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
2000 /* GLX 1.1 and later */
2002 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
2006 return get_extensions();
2011 /* GLX 1.1 and later */
2013 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
2015 static char version
[1000];
2016 _mesa_sprintf(version
, "%d.%d %s",
2017 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
2023 case GLX_EXTENSIONS
:
2024 return get_extensions();
2036 /* GLX 1.1 and later */
2038 Fake_glXGetClientString( Display
*dpy
, int name
)
2040 static char version
[1000];
2041 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
2042 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
2047 case GLX_EXTENSIONS
:
2048 return get_extensions();
2066 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
2067 int attribute
, int *value
)
2069 XMesaVisual v
= (XMesaVisual
) config
;
2073 if (!dpy
|| !config
|| !value
)
2076 return get_config(v
, attribute
, value
, GL_TRUE
);
2080 static GLXFBConfig
*
2081 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
2083 XVisualInfo
*visuals
, visTemplate
;
2084 const long visMask
= VisualScreenMask
;
2087 /* Get list of all X visuals */
2088 visTemplate
.screen
= screen
;
2089 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
2090 if (*nelements
> 0) {
2091 XMesaVisual
*results
;
2092 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
2097 for (i
= 0; i
< *nelements
; i
++) {
2098 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
2100 return (GLXFBConfig
*) results
;
2106 static GLXFBConfig
*
2107 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
2108 const int *attribList
, int *nitems
)
2112 if (!attribList
|| !attribList
[0]) {
2113 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
2114 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
2117 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
2119 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
2125 config
[0] = (GLXFBConfig
) xmvis
;
2126 return (GLXFBConfig
*) config
;
2135 static XVisualInfo
*
2136 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
2138 if (dpy
&& config
) {
2139 XMesaVisual xmvis
= (XMesaVisual
) config
;
2141 return xmvis
->vishandle
;
2143 /* create a new vishandle - the cached one may be stale */
2144 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
2145 if (xmvis
->vishandle
) {
2146 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
2148 return xmvis
->vishandle
;
2158 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
2159 const int *attribList
)
2161 XMesaVisual xmvis
= (XMesaVisual
) config
;
2166 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
2171 /* XXX this will segfault if actually called */
2172 FXcreateContext(xmvis
, win
, NULL
, xmbuf
);
2176 (void) attribList
; /* Ignored in GLX 1.3 */
2178 return win
; /* A hack for now */
2183 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
2185 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2187 XMesaDestroyBuffer(b
);
2188 /* don't destroy X window */
2194 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2195 const int *attribList
)
2197 XMesaVisual v
= (XMesaVisual
) config
;
2200 int target
= 0, format
= 0, mipmap
= 0;
2203 if (!dpy
|| !config
|| !pixmap
)
2206 for (attr
= attribList
; *attr
; attr
++) {
2208 case GLX_TEXTURE_FORMAT_EXT
:
2211 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2212 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2213 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2221 case GLX_TEXTURE_TARGET_EXT
:
2224 case GLX_TEXTURE_1D_EXT
:
2225 case GLX_TEXTURE_2D_EXT
:
2226 case GLX_TEXTURE_RECTANGLE_EXT
:
2234 case GLX_MIPMAP_TEXTURE_EXT
:
2245 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2246 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2247 &value
, GL_TRUE
) != Success
2249 return 0; /* error! */
2252 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2253 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2254 &value
, GL_TRUE
) != Success
2256 return 0; /* error! */
2260 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2261 &value
, GL_TRUE
) != Success
2263 return 0; /* error! */
2266 if (target
== GLX_TEXTURE_1D_EXT
) {
2267 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2268 &value
, GL_TRUE
) != Success
2269 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2270 return 0; /* error! */
2273 else if (target
== GLX_TEXTURE_2D_EXT
) {
2274 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2275 &value
, GL_TRUE
) != Success
2276 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2277 return 0; /* error! */
2280 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2281 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2282 &value
, GL_TRUE
) != Success
2283 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2284 return 0; /* error! */
2288 if (format
|| target
|| mipmap
) {
2289 /* texture from pixmap */
2290 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2293 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2304 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2306 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2308 XMesaDestroyBuffer(b
);
2309 /* don't destroy X pixmap */
2314 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2315 const int *attribList
)
2317 XMesaVisual xmvis
= (XMesaVisual
) config
;
2320 int width
= 0, height
= 0;
2321 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2325 for (attrib
= attribList
; *attrib
; attrib
++) {
2327 case GLX_PBUFFER_WIDTH
:
2331 case GLX_PBUFFER_HEIGHT
:
2335 case GLX_PRESERVED_CONTENTS
:
2337 preserveContents
= *attrib
; /* ignored */
2339 case GLX_LARGEST_PBUFFER
:
2341 useLargest
= *attrib
; /* ignored */
2348 /* not used at this time */
2350 (void) preserveContents
;
2352 if (width
== 0 || height
== 0)
2355 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2356 /* A GLXPbuffer handle must be an X Drawable because that's what
2357 * glXMakeCurrent takes.
2360 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2367 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2369 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2371 XMesaDestroyBuffer(b
);
2377 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2378 unsigned int *value
)
2380 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2384 switch (attribute
) {
2386 *value
= xmbuf
->mesa_buffer
.Width
;
2389 *value
= xmbuf
->mesa_buffer
.Height
;
2391 case GLX_PRESERVED_CONTENTS
:
2394 case GLX_LARGEST_PBUFFER
:
2395 *value
= xmbuf
->mesa_buffer
.Width
* xmbuf
->mesa_buffer
.Height
;
2397 case GLX_FBCONFIG_ID
:
2398 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2400 #ifdef GLX_EXT_texture_from_pixmap
2401 case GLX_TEXTURE_FORMAT_EXT
:
2402 *value
= xmbuf
->TextureFormat
;
2404 case GLX_TEXTURE_TARGET_EXT
:
2405 *value
= xmbuf
->TextureTarget
;
2407 case GLX_MIPMAP_TEXTURE_EXT
:
2408 *value
= xmbuf
->TextureMipmap
;
2413 return; /* raise BadValue error */
2419 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2420 int renderType
, GLXContext shareList
, Bool direct
)
2422 struct fake_glx_context
*glxCtx
;
2423 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2424 XMesaVisual xmvis
= (XMesaVisual
) config
;
2426 if (!dpy
|| !config
||
2427 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2430 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2434 /* deallocate unused windows/buffers */
2435 XMesaGarbageCollect();
2437 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2438 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2439 if (!glxCtx
->xmesaContext
) {
2444 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2445 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2446 glxCtx
->glxContext
.currentDpy
= dpy
;
2447 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2449 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2451 return (GLXContext
) glxCtx
;
2456 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2458 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2459 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2464 switch (attribute
) {
2465 case GLX_FBCONFIG_ID
:
2466 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2468 case GLX_RENDER_TYPE
:
2469 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2470 *value
= GLX_RGBA_BIT
;
2472 *value
= GLX_COLOR_INDEX_BIT
;
2478 return GLX_BAD_ATTRIBUTE
;
2485 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2487 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2489 xmbuf
->selectedEvents
= mask
;
2494 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2495 unsigned long *mask
)
2497 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2499 *mask
= xmbuf
->selectedEvents
;
2506 /*** GLX_SGI_swap_control ***/
2509 Fake_glXSwapIntervalSGI(int interval
)
2517 /*** GLX_SGI_video_sync ***/
2519 static unsigned int FrameCounter
= 0;
2522 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2524 /* this is a bogus implementation */
2525 *count
= FrameCounter
++;
2530 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2532 if (divisor
<= 0 || remainder
< 0)
2533 return GLX_BAD_VALUE
;
2534 /* this is a bogus implementation */
2536 while (FrameCounter
% divisor
!= remainder
)
2538 *count
= FrameCounter
;
2544 /*** GLX_SGI_make_current_read ***/
2547 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2549 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2554 Fake_glXGetCurrentReadDrawableSGI(void)
2561 /*** GLX_SGIX_video_source ***/
2564 static GLXVideoSourceSGIX
2565 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2577 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2586 /*** GLX_EXT_import_context ***/
2589 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2596 Fake_glXGetContextIDEXT(const GLXContext context
)
2603 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2611 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2622 /*** GLX_SGIX_fbconfig ***/
2625 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2627 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2630 static GLXFBConfigSGIX
*
2631 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2633 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2638 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2640 XMesaVisual xmvis
= (XMesaVisual
) config
;
2641 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2642 return xmbuf
->frontxrb
->pixmap
; /* need to return an X ID */
2647 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2649 XMesaVisual xmvis
= (XMesaVisual
) config
;
2650 struct fake_glx_context
*glxCtx
;
2651 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2653 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2657 /* deallocate unused windows/buffers */
2658 XMesaGarbageCollect();
2660 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2661 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2662 if (!glxCtx
->xmesaContext
) {
2667 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2668 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2669 glxCtx
->glxContext
.currentDpy
= dpy
;
2670 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2672 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2674 return (GLXContext
) glxCtx
;
2678 static XVisualInfo
*
2679 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2681 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2685 static GLXFBConfigSGIX
2686 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2688 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2690 /* This visual wasn't found with glXChooseVisual() */
2691 xmvis
= create_glx_visual(dpy
, vis
);
2694 return (GLXFBConfigSGIX
) xmvis
;
2699 /*** GLX_SGIX_pbuffer ***/
2701 static GLXPbufferSGIX
2702 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2703 unsigned int width
, unsigned int height
,
2706 XMesaVisual xmvis
= (XMesaVisual
) config
;
2709 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2713 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2715 case GLX_PRESERVED_CONTENTS_SGIX
:
2717 preserveContents
= *attrib
; /* ignored */
2719 case GLX_LARGEST_PBUFFER_SGIX
:
2721 useLargest
= *attrib
; /* ignored */
2728 /* not used at this time */
2730 (void) preserveContents
;
2732 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2733 /* A GLXPbuffer handle must be an X Drawable because that's what
2734 * glXMakeCurrent takes.
2736 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2741 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2743 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2745 XMesaDestroyBuffer(xmbuf
);
2751 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2753 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2756 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2760 switch (attribute
) {
2761 case GLX_PRESERVED_CONTENTS_SGIX
:
2764 case GLX_LARGEST_PBUFFER_SGIX
:
2765 *value
= xmbuf
->mesa_buffer
.Width
* xmbuf
->mesa_buffer
.Height
;
2767 case GLX_WIDTH_SGIX
:
2768 *value
= xmbuf
->mesa_buffer
.Width
;
2770 case GLX_HEIGHT_SGIX
:
2771 *value
= xmbuf
->mesa_buffer
.Height
;
2773 case GLX_EVENT_MASK_SGIX
:
2774 *value
= 0; /* XXX might be wrong */
2784 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2786 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2788 /* Note: we'll never generate clobber events */
2789 xmbuf
->selectedEvents
= mask
;
2795 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2797 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2799 *mask
= xmbuf
->selectedEvents
;
2808 /*** GLX_SGI_cushion ***/
2811 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2820 /*** GLX_SGIX_video_resize ***/
2823 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2833 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2846 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2859 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2872 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2883 /*** GLX_SGIX_dmbuffer **/
2885 #if defined(_DM_BUFFER_H_)
2887 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2898 /*** GLX_SGIX_swap_group ***/
2901 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2910 /*** GLX_SGIX_swap_barrier ***/
2913 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2921 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2931 /*** GLX_SUN_get_transparent_index ***/
2934 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2939 (void) pTransparent
;
2945 /*** GLX_MESA_release_buffers ***/
2948 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2949 * (a window or pixmap) prior to destroying the GLXDrawable.
2952 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2954 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2956 XMesaDestroyBuffer(b
);
2964 /*** GLX_MESA_set_3dfx_mode ***/
2967 Fake_glXSet3DfxModeMESA( int mode
)
2969 return XMesaSetFXmode( mode
);
2974 /*** GLX_NV_vertex_array range ***/
2976 Fake_glXAllocateMemoryNV( GLsizei size
,
2977 GLfloat readFrequency
,
2978 GLfloat writeFrequency
,
2982 (void) readFrequency
;
2983 (void) writeFrequency
;
2990 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2996 /*** GLX_MESA_agp_offset ***/
2999 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
3006 /*** GLX_EXT_texture_from_pixmap ***/
3009 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
3010 const int *attrib_list
)
3012 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3014 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
3018 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
3020 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3022 XMesaReleaseTexImage(dpy
, b
, buffer
);
3026 /* silence warning */
3027 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
3031 * Create a new GLX API dispatch table with its function pointers
3032 * initialized to point to Mesa's "fake" GLX API functions.
3033 * Note: there's a similar function (_real_GetGLXDispatchTable) that
3034 * returns a new dispatch table with all pointers initalized to point
3035 * to "real" GLX functions (which understand GLX wire protocol, etc).
3037 struct _glxapi_table
*
3038 _mesa_GetGLXDispatchTable(void)
3040 static struct _glxapi_table glx
;
3042 /* be sure our dispatch table size <= libGL's table */
3044 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
3046 assert(_glxapi_get_dispatch_table_size() >= size
);
3049 /* initialize the whole table to no-ops */
3050 _glxapi_set_no_op_table(&glx
);
3052 /* now initialize the table with the functions I implement */
3053 glx
.ChooseVisual
= Fake_glXChooseVisual
;
3054 glx
.CopyContext
= Fake_glXCopyContext
;
3055 glx
.CreateContext
= Fake_glXCreateContext
;
3056 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
3057 glx
.DestroyContext
= Fake_glXDestroyContext
;
3058 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
3059 glx
.GetConfig
= Fake_glXGetConfig
;
3060 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
3061 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
3062 glx
.IsDirect
= Fake_glXIsDirect
;
3063 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
3064 glx
.QueryExtension
= Fake_glXQueryExtension
;
3065 glx
.QueryVersion
= Fake_glXQueryVersion
;
3066 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
3067 glx
.UseXFont
= Fake_glXUseXFont
;
3068 glx
.WaitGL
= Fake_glXWaitGL
;
3069 glx
.WaitX
= Fake_glXWaitX
;
3071 /*** GLX_VERSION_1_1 ***/
3072 glx
.GetClientString
= Fake_glXGetClientString
;
3073 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
3074 glx
.QueryServerString
= Fake_glXQueryServerString
;
3076 /*** GLX_VERSION_1_2 ***/
3077 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
3079 /*** GLX_VERSION_1_3 ***/
3080 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
3081 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
3082 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
3083 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
3084 glx
.CreateWindow
= Fake_glXCreateWindow
;
3085 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
3086 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
3087 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
3088 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
3089 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
3090 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
3091 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
3092 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
3093 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
3094 glx
.QueryContext
= Fake_glXQueryContext
;
3095 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
3096 glx
.SelectEvent
= Fake_glXSelectEvent
;
3098 /*** GLX_SGI_swap_control ***/
3099 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
3101 /*** GLX_SGI_video_sync ***/
3102 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
3103 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
3105 /*** GLX_SGI_make_current_read ***/
3106 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
3107 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
3109 /*** GLX_SGIX_video_source ***/
3111 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
3112 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
3115 /*** GLX_EXT_import_context ***/
3116 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
3117 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
3118 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
3119 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
3120 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
3122 /*** GLX_SGIX_fbconfig ***/
3123 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
3124 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
3125 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
3126 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
3127 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
3128 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
3130 /*** GLX_SGIX_pbuffer ***/
3131 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
3132 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
3133 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
3134 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
3135 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
3137 /*** GLX_SGI_cushion ***/
3138 glx
.CushionSGI
= Fake_glXCushionSGI
;
3140 /*** GLX_SGIX_video_resize ***/
3141 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
3142 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
3143 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
3144 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
3145 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
3147 /*** GLX_SGIX_dmbuffer **/
3148 #if defined(_DM_BUFFER_H_)
3149 glx
.AssociateDMPbufferSGIX
= NULL
;
3152 /*** GLX_SGIX_swap_group ***/
3153 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
3155 /*** GLX_SGIX_swap_barrier ***/
3156 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
3157 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
3159 /*** GLX_SUN_get_transparent_index ***/
3160 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
3162 /*** GLX_MESA_copy_sub_buffer ***/
3163 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3165 /*** GLX_MESA_release_buffers ***/
3166 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3168 /*** GLX_MESA_pixmap_colormap ***/
3169 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3171 /*** GLX_MESA_set_3dfx_mode ***/
3172 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3174 /*** GLX_NV_vertex_array_range ***/
3175 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3176 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3178 /*** GLX_MESA_agp_offset ***/
3179 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3181 /*** GLX_EXT_texture_from_pixmap ***/
3182 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3183 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;