2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
28 * to run on X servers which do not have the real GLX extension.
30 * Thanks to the contributors:
32 * Initial version: Philip Brown (phil@bolthole.com)
33 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
34 * Further visual-handling refinements: Wolfram Gloger
35 * (wmglo@Dent.MED.Uni-Muenchen.DE).
38 * Don't be fooled, stereo isn't supported yet.
43 #include "glxheader.h"
54 #include "state_tracker/st_context.h"
55 #include "state_tracker/st_public.h"
59 #define _mesa_sprintf sprintf
62 /* This indicates the client-side GLX API and GLX encoder version. */
63 #define CLIENT_MAJOR_VERSION 1
64 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
66 /* This indicates the server-side GLX decoder version.
67 * GLX 1.4 indicates OpenGL 1.3 support
69 #define SERVER_MAJOR_VERSION 1
70 #define SERVER_MINOR_VERSION 4
72 /* This is appended onto the glXGetClient/ServerString version strings. */
73 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
75 /* Who implemented this GLX? */
76 #define VENDOR "Brian Paul"
79 "GLX_MESA_set_3dfx_mode " \
80 "GLX_MESA_copy_sub_buffer " \
81 "GLX_MESA_pixmap_colormap " \
82 "GLX_MESA_release_buffers " \
83 "GLX_ARB_get_proc_address " \
84 "GLX_EXT_texture_from_pixmap " \
85 "GLX_EXT_visual_info " \
86 "GLX_EXT_visual_rating " \
87 /*"GLX_SGI_video_sync "*/ \
88 "GLX_SGIX_fbconfig " \
92 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
94 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
97 * We really just need this structure in order to make the libGL functions
98 * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
101 struct fake_glx_context
{
102 __GLXcontext glxContext
; /* this MUST be first! */
103 XMesaContext xmesaContext
;
108 /**********************************************************************/
109 /*** GLX Visual Code ***/
110 /**********************************************************************/
115 static XMesaVisual
*VisualTable
= NULL
;
116 static int NumVisuals
= 0;
120 * This struct and some code fragments borrowed
121 * from Mark Kilgard's GLUT library.
123 typedef struct _OverlayInfo
{
124 /* Avoid 64-bit portability problems by being careful to use
125 longs due to the way XGetWindowProperty is specified. Note
126 that these parameters are passed as CARD32s over X
128 unsigned long overlay_visual
;
129 long transparent_type
;
136 /* Macro to handle c_class vs class field name in XVisualInfo struct */
137 #if defined(__cplusplus) || defined(c_plusplus)
138 #define CLASS c_class
146 * Test if the given XVisualInfo is usable for Mesa rendering.
149 is_usable_visual( XVisualInfo
*vinfo
)
151 switch (vinfo
->CLASS
) {
154 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
158 /* Any StaticColor/PseudoColor visual of at least 4 bits */
159 if (vinfo
->depth
>=4) {
167 /* Any depth of TrueColor or DirectColor works in RGB mode */
170 /* This should never happen */
178 * Get an array OverlayInfo records for specified screen.
179 * \param dpy the display
180 * \param screen screen number
181 * \param numOverlays returns numver of OverlayInfo records
182 * \return pointer to OverlayInfo array, free with XFree()
185 GetOverlayInfo(Display
*dpy
, int screen
, int *numOverlays
)
187 Atom overlayVisualsAtom
;
190 unsigned char *ovInfo
;
191 unsigned long sizeData
, bytesLeft
;
195 * The SERVER_OVERLAY_VISUALS property on the root window contains
196 * a list of overlay visuals. Get that list now.
198 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
199 if (overlayVisualsAtom
== None
) {
203 status
= XGetWindowProperty(dpy
, RootWindow(dpy
, screen
),
204 overlayVisualsAtom
, 0L, (long) 10000, False
,
205 overlayVisualsAtom
, &actualType
, &actualFormat
,
206 &sizeData
, &bytesLeft
,
209 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
210 actualFormat
!= 32 || sizeData
< 4) {
211 /* something went wrong */
212 XFree((void *) ovInfo
);
217 *numOverlays
= sizeData
/ 4;
218 return (OverlayInfo
*) ovInfo
;
224 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
225 * Input: dpy - the X display
226 * vinfo - the XVisualInfo to test
227 * Return: level of the visual:
229 * >0 = overlay planes
230 * <0 = underlay planes
233 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
235 OverlayInfo
*overlay_info
;
236 int numOverlaysPerScreen
, i
;
238 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
243 /* search the overlay visual list for the visual ID of interest */
244 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
245 const OverlayInfo
*ov
= overlay_info
+ i
;
246 if (ov
->overlay_visual
== vinfo
->visualid
) {
247 /* found the visual */
248 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
249 int level
= ov
->layer
;
250 XFree((void *) overlay_info
);
254 XFree((void *) overlay_info
);
260 /* The visual ID was not found in the overlay list. */
261 XFree((void *) overlay_info
);
269 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
270 * configuration in our list of GLX visuals.
273 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
274 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
275 GLboolean stereoFlag
,
276 GLint depth_size
, GLint stencil_size
,
277 GLint accumRedSize
, GLint accumGreenSize
,
278 GLint accumBlueSize
, GLint accumAlphaSize
,
279 GLint level
, GLint numAuxBuffers
)
281 GLboolean ximageFlag
= GL_TRUE
;
284 GLboolean comparePointers
;
287 /* Check if the MESA_BACK_BUFFER env var is set */
288 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
290 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
291 ximageFlag
= GL_FALSE
;
293 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
294 ximageFlag
= GL_TRUE
;
297 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
303 /* stereo not supported */
307 /* Comparing IDs uses less memory but sometimes fails. */
308 /* XXX revisit this after 3.0 is finished. */
309 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
310 comparePointers
= GL_TRUE
;
312 comparePointers
= GL_FALSE
;
314 /* Force the visual to have an alpha channel */
315 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
318 /* First check if a matching visual is already in the list */
319 for (i
=0; i
<NumVisuals
; i
++) {
320 XMesaVisual v
= VisualTable
[i
];
321 if (v
->display
== dpy
322 && v
->mesa_visual
.level
== level
323 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
324 && v
->ximage_flag
== ximageFlag
325 && v
->mesa_visual
.rgbMode
== rgbFlag
326 && v
->mesa_visual
.doubleBufferMode
== dbFlag
327 && v
->mesa_visual
.stereoMode
== stereoFlag
328 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
329 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
330 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
331 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
332 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
333 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
334 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
335 /* now either compare XVisualInfo pointers or visual IDs */
336 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
337 || (comparePointers
&& v
->vishandle
== vinfo
)) {
343 /* Create a new visual and add it to the list. */
345 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
346 stereoFlag
, ximageFlag
,
347 depth_size
, stencil_size
,
348 accumRedSize
, accumBlueSize
,
349 accumBlueSize
, accumAlphaSize
, 0, level
,
352 /* Save a copy of the pointer now so we can find this visual again
353 * if we need to search for it in find_glx_visual().
355 xmvis
->vishandle
= vinfo
;
356 /* Allocate more space for additional visual */
357 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
358 sizeof(XMesaVisual
) * NumVisuals
,
359 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
360 /* add xmvis to the list */
361 VisualTable
[NumVisuals
] = xmvis
;
363 /* XXX minor hack, because XMesaCreateVisual doesn't support an
364 * aux buffers parameter.
366 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
373 * Return the default number of bits for the Z buffer.
374 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
375 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
376 * XXX probably do the same thing for stencil, accum, etc.
379 default_depth_bits(void)
382 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
384 zBits
= _mesa_atoi(zEnv
);
386 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
391 default_alpha_bits(void)
394 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
396 aBits
= _mesa_atoi(aEnv
);
403 default_accum_bits(void)
411 * Create a GLX visual from a regular XVisualInfo.
412 * This is called when Fake GLX is given an XVisualInfo which wasn't
413 * returned by glXChooseVisual. Since this is the first time we're
414 * considering this visual we'll take a guess at reasonable values
415 * for depth buffer size, stencil size, accum size, etc.
416 * This is the best we can do with a client-side emulation of GLX.
419 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
422 GLint zBits
= 24; /*default_depth_bits();*/
423 GLint accBits
= default_accum_bits();
424 GLboolean alphaFlag
= default_alpha_bits() > 0;
426 vislevel
= level_of_visual( dpy
, visinfo
);
428 /* Configure this visual as a CI, single-buffered overlay */
429 return save_glx_visual( dpy
, visinfo
,
431 GL_FALSE
, /* alpha */
432 GL_FALSE
, /* double */
433 GL_FALSE
, /* stereo */
435 0, /* stencil bits */
436 0,0,0,0, /* accum bits */
437 vislevel
, /* level */
441 else if (is_usable_visual( visinfo
)) {
442 if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
443 /* Configure this visual as a COLOR INDEX visual. */
444 return save_glx_visual( dpy
, visinfo
,
446 GL_FALSE
, /* alpha */
447 GL_TRUE
, /* double */
448 GL_FALSE
, /* stereo */
451 0, 0, 0, 0, /* accum bits */
457 /* Configure this visual as RGB, double-buffered, depth-buffered. */
458 /* This is surely wrong for some people's needs but what else */
459 /* can be done? They should use glXChooseVisual(). */
460 return save_glx_visual( dpy
, visinfo
,
462 alphaFlag
, /* alpha */
463 GL_TRUE
, /* double */
464 GL_FALSE
, /* stereo */
477 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
485 * Find the GLX visual associated with an XVisualInfo.
488 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
492 /* try to match visual id */
493 for (i
=0;i
<NumVisuals
;i
++) {
494 if (VisualTable
[i
]->display
==dpy
495 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
496 return VisualTable
[i
];
500 /* if that fails, try to match pointers */
501 for (i
=0;i
<NumVisuals
;i
++) {
502 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
503 return VisualTable
[i
];
513 * Return the transparent pixel value for a GLX visual.
514 * Input: glxvis - the glx_visual
515 * Return: a pixel value or -1 if no transparent pixel
518 transparent_pixel( XMesaVisual glxvis
)
520 Display
*dpy
= glxvis
->display
;
521 XVisualInfo
*vinfo
= glxvis
->visinfo
;
522 OverlayInfo
*overlay_info
;
523 int numOverlaysPerScreen
, i
;
525 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
530 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
531 const OverlayInfo
*ov
= overlay_info
+ i
;
532 if (ov
->overlay_visual
== vinfo
->visualid
) {
534 if (ov
->transparent_type
== 0) {
535 /* type 0 indicates no transparency */
536 XFree((void *) overlay_info
);
540 /* ov->value is the transparent pixel */
541 XFree((void *) overlay_info
);
547 /* The visual ID was not found in the overlay list. */
548 XFree((void *) overlay_info
);
555 * Try to get an X visual which matches the given arguments.
558 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
560 XVisualInfo temp
, *vis
;
563 unsigned int default_depth
;
566 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
571 default_depth
= DefaultDepth(dpy
,scr
);
572 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
574 if (depth
==default_depth
&& xclass
==default_class
) {
575 /* try to get root window's visual */
576 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
577 mask
|= VisualIDMask
;
580 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
582 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
583 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
584 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
586 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
587 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
588 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
589 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
604 * Retrieve the value of the given environment variable and find
605 * the X visual which matches it.
606 * Input: dpy - the display
607 * screen - the screen number
608 * varname - the name of the environment variable
609 * Return: an XVisualInfo pointer to NULL if error.
612 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
614 char value
[100], type
[100];
615 int depth
, xclass
= -1;
618 if (!_mesa_getenv( varname
)) {
622 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
625 sscanf( value
, "%s %d", type
, &depth
);
627 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
628 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
629 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
630 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
631 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
632 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
634 if (xclass
>-1 && depth
>0) {
635 vis
= get_visual( dpy
, scr
, depth
, xclass
);
641 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
650 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
651 * Input: dpy, screen - X display and screen number
652 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
653 * min_depth - minimum visual depth
654 * preferred_class - preferred GLX visual class or DONT_CARE
655 * Return: pointer to an XVisualInfo or NULL.
658 choose_x_visual( Display
*dpy
, int screen
, GLboolean rgba
, int min_depth
,
659 int preferred_class
)
662 int xclass
, visclass
= 0;
666 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
667 /* First see if the MESA_RGB_VISUAL env var is defined */
668 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
672 /* Otherwise, search for a suitable visual */
673 if (preferred_class
==DONT_CARE
) {
674 for (xclass
=0;xclass
<6;xclass
++) {
676 case 0: visclass
= TrueColor
; break;
677 case 1: visclass
= DirectColor
; break;
678 case 2: visclass
= PseudoColor
; break;
679 case 3: visclass
= StaticColor
; break;
680 case 4: visclass
= GrayScale
; break;
681 case 5: visclass
= StaticGray
; break;
684 /* start with shallowest */
685 for (depth
=0;depth
<=32;depth
++) {
686 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
687 /* Special case: try to get 8-bit PseudoColor before */
688 /* 8-bit TrueColor */
689 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
694 vis
= get_visual( dpy
, screen
, depth
, visclass
);
701 /* start with deepest */
702 for (depth
=32;depth
>=min_depth
;depth
--) {
703 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
704 /* Special case: try to get 8-bit PseudoColor before */
705 /* 8-bit TrueColor */
706 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
711 vis
= get_visual( dpy
, screen
, depth
, visclass
);
720 /* search for a specific visual class */
721 switch (preferred_class
) {
722 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
723 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
724 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
725 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
726 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
727 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
728 default: return NULL
;
731 /* start with shallowest */
732 for (depth
=0;depth
<=32;depth
++) {
733 vis
= get_visual( dpy
, screen
, depth
, visclass
);
740 /* start with deepest */
741 for (depth
=32;depth
>=min_depth
;depth
--) {
742 vis
= get_visual( dpy
, screen
, depth
, visclass
);
751 /* First see if the MESA_CI_VISUAL env var is defined */
752 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
756 /* Otherwise, search for a suitable visual, starting with shallowest */
757 if (preferred_class
==DONT_CARE
) {
758 for (xclass
=0;xclass
<4;xclass
++) {
760 case 0: visclass
= PseudoColor
; break;
761 case 1: visclass
= StaticColor
; break;
762 case 2: visclass
= GrayScale
; break;
763 case 3: visclass
= StaticGray
; break;
765 /* try 8-bit up through 16-bit */
766 for (depth
=8;depth
<=16;depth
++) {
767 vis
= get_visual( dpy
, screen
, depth
, visclass
);
772 /* try min_depth up to 8-bit */
773 for (depth
=min_depth
;depth
<8;depth
++) {
774 vis
= get_visual( dpy
, screen
, depth
, visclass
);
782 /* search for a specific visual class */
783 switch (preferred_class
) {
784 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
785 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
786 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
787 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
788 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
789 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
790 default: return NULL
;
792 /* try 8-bit up through 16-bit */
793 for (depth
=8;depth
<=16;depth
++) {
794 vis
= get_visual( dpy
, screen
, depth
, visclass
);
799 /* try min_depth up to 8-bit */
800 for (depth
=min_depth
;depth
<8;depth
++) {
801 vis
= get_visual( dpy
, screen
, depth
, visclass
);
809 /* didn't find a visual */
816 * Find the deepest X over/underlay visual of at least min_depth.
817 * Input: dpy, screen - X display and screen number
818 * level - the over/underlay level
819 * trans_type - transparent pixel type: GLX_NONE_EXT,
820 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
822 * trans_value - transparent pixel value or DONT_CARE
823 * min_depth - minimum visual depth
824 * preferred_class - preferred GLX visual class or DONT_CARE
825 * Return: pointer to an XVisualInfo or NULL.
828 choose_x_overlay_visual( Display
*dpy
, int scr
, GLboolean rgbFlag
,
829 int level
, int trans_type
, int trans_value
,
830 int min_depth
, int preferred_class
)
832 OverlayInfo
*overlay_info
;
833 int numOverlaysPerScreen
;
835 XVisualInfo
*deepvis
;
838 /*DEBUG int tt, tv; */
840 switch (preferred_class
) {
841 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
842 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
843 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
844 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
845 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
846 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
847 default: preferred_class
= DONT_CARE
;
850 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
855 /* Search for the deepest overlay which satisifies all criteria. */
859 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
860 const OverlayInfo
*ov
= overlay_info
+ i
;
861 XVisualInfo
*vislist
, vistemplate
;
864 if (ov
->layer
!=level
) {
865 /* failed overlay level criteria */
868 if (!(trans_type
==DONT_CARE
869 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
870 && ov
->transparent_type
>0)
871 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
872 /* failed transparent pixel type criteria */
875 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
876 /* failed transparent pixel value criteria */
880 /* get XVisualInfo and check the depth */
881 vistemplate
.visualid
= ov
->overlay_visual
;
882 vistemplate
.screen
= scr
;
883 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
884 &vistemplate
, &count
);
887 /* something went wrong */
890 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
891 /* wrong visual class */
895 /* if RGB was requested, make sure we have True/DirectColor */
896 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
897 && vislist
->CLASS
!= DirectColor
)
900 /* if CI was requested, make sure we have a color indexed visual */
902 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
905 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
906 /* YES! found a satisfactory visual */
910 deepest
= vislist
->depth
;
912 /* DEBUG tt = ov->transparent_type;*/
913 /* DEBUG tv = ov->value; */
919 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
920 deepvis->visualid, level, deepvis->depth, tt, tv );
927 /**********************************************************************/
928 /*** Display-related functions ***/
929 /**********************************************************************/
933 * Free all XMesaVisuals which are associated with the given display.
936 destroy_visuals_on_display(Display
*dpy
)
939 for (i
= 0; i
< NumVisuals
; i
++) {
940 if (VisualTable
[i
]->display
== dpy
) {
941 /* remove this visual */
943 free(VisualTable
[i
]);
944 for (j
= i
; j
< NumVisuals
- 1; j
++)
945 VisualTable
[j
] = VisualTable
[j
+ 1];
953 * Called from XCloseDisplay() to let us free our display-related data.
956 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
958 destroy_visuals_on_display(dpy
);
959 xmesa_destroy_buffers_on_display(dpy
);
965 * Look for the named extension on given display and return a pointer
966 * to the _XExtension data, or NULL if extension not found.
969 lookup_extension(Display
*dpy
, const char *extName
)
972 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
973 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
982 * Whenever we're given a new Display pointer, call this function to
983 * register our close_display_callback function.
986 register_with_display(Display
*dpy
)
988 const char *extName
= "MesaGLX";
991 ext
= lookup_extension(dpy
, extName
);
993 XExtCodes
*c
= XAddExtension(dpy
);
994 ext
= dpy
->ext_procs
; /* new extension is at head of list */
995 assert(c
->extension
== ext
->codes
.extension
);
996 ext
->name
= _mesa_strdup(extName
);
997 ext
->close_display
= close_display_callback
;
1002 /**********************************************************************/
1003 /*** Begin Fake GLX API Functions ***/
1004 /**********************************************************************/
1008 * Helper used by glXChooseVisual and glXChooseFBConfig.
1009 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
1011 * In either case, the attribute list is terminated with the value 'None'.
1014 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
1016 const GLboolean rgbModeDefault
= fbConfig
;
1017 const int *parselist
;
1020 int min_red
=0, min_green
=0, min_blue
=0;
1021 GLboolean rgb_flag
= rgbModeDefault
;
1022 GLboolean alpha_flag
= GL_FALSE
;
1023 GLboolean double_flag
= GL_FALSE
;
1024 GLboolean stereo_flag
= GL_FALSE
;
1025 GLint depth_size
= 0;
1026 GLint stencil_size
= 0;
1027 GLint accumRedSize
= 0;
1028 GLint accumGreenSize
= 0;
1029 GLint accumBlueSize
= 0;
1030 GLint accumAlphaSize
= 0;
1032 int visual_type
= DONT_CARE
;
1033 int trans_type
= DONT_CARE
;
1034 int trans_value
= DONT_CARE
;
1035 GLint caveat
= DONT_CARE
;
1036 XMesaVisual xmvis
= NULL
;
1037 int desiredVisualID
= -1;
1042 while (*parselist
) {
1044 switch (*parselist
) {
1055 case GLX_BUFFER_SIZE
:
1057 min_ci
= *parselist
++;
1061 level
= *parselist
++;
1073 case GLX_DOUBLEBUFFER
:
1076 double_flag
= *parselist
++;
1079 double_flag
= GL_TRUE
;
1085 stereo_flag
= *parselist
++;
1088 stereo_flag
= GL_TRUE
;
1091 case GLX_AUX_BUFFERS
:
1093 numAux
= *parselist
++;
1094 if (numAux
> MAX_AUX_BUFFERS
)
1099 min_red
= *parselist
++;
1101 case GLX_GREEN_SIZE
:
1103 min_green
= *parselist
++;
1107 min_blue
= *parselist
++;
1109 case GLX_ALPHA_SIZE
:
1112 GLint size
= *parselist
++;
1113 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
1116 case GLX_DEPTH_SIZE
:
1118 depth_size
= *parselist
++;
1120 case GLX_STENCIL_SIZE
:
1122 stencil_size
= *parselist
++;
1124 case GLX_ACCUM_RED_SIZE
:
1127 GLint size
= *parselist
++;
1128 accumRedSize
= MAX2( accumRedSize
, size
);
1131 case GLX_ACCUM_GREEN_SIZE
:
1134 GLint size
= *parselist
++;
1135 accumGreenSize
= MAX2( accumGreenSize
, size
);
1138 case GLX_ACCUM_BLUE_SIZE
:
1141 GLint size
= *parselist
++;
1142 accumBlueSize
= MAX2( accumBlueSize
, size
);
1145 case GLX_ACCUM_ALPHA_SIZE
:
1148 GLint size
= *parselist
++;
1149 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1154 * GLX_EXT_visual_info extension
1156 case GLX_X_VISUAL_TYPE_EXT
:
1158 visual_type
= *parselist
++;
1160 case GLX_TRANSPARENT_TYPE_EXT
:
1162 trans_type
= *parselist
++;
1164 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1166 trans_value
= *parselist
++;
1168 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1169 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1170 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1171 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1178 * GLX_EXT_visual_info extension
1180 case GLX_VISUAL_CAVEAT_EXT
:
1182 caveat
= *parselist
++; /* ignored for now */
1186 * GLX_ARB_multisample
1188 case GLX_SAMPLE_BUFFERS_ARB
:
1189 /* ms not supported */
1191 case GLX_SAMPLES_ARB
:
1192 /* ms not supported */
1198 case GLX_RENDER_TYPE
:
1202 if (*parselist
== GLX_RGBA_BIT
) {
1205 else if (*parselist
== GLX_COLOR_INDEX_BIT
) {
1206 rgb_flag
= GL_FALSE
;
1208 else if (*parselist
== 0) {
1213 case GLX_DRAWABLE_TYPE
:
1217 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1218 return NULL
; /* bad bit */
1222 case GLX_FBCONFIG_ID
:
1226 desiredVisualID
= *parselist
++;
1228 case GLX_X_RENDERABLE
:
1235 #ifdef GLX_EXT_texture_from_pixmap
1236 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1237 parselist
++; /*skip*/
1239 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1240 parselist
++; /*skip*/
1242 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1243 parselist
++; /*skip*/
1245 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1247 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1248 GLX_TEXTURE_2D_BIT_EXT
|
1249 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1254 case GLX_Y_INVERTED_EXT
:
1255 parselist
++; /*skip*/
1264 /* undefined attribute */
1265 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1274 * Since we're only simulating the GLX extension this function will never
1275 * find any real GL visuals. Instead, all we can do is try to find an RGB
1276 * or CI visual of appropriate depth. Other requested attributes such as
1277 * double buffering, depth buffer, etc. will be associated with the X
1278 * visual and stored in the VisualTable[].
1280 if (desiredVisualID
!= -1) {
1281 /* try to get a specific visual, by visualID */
1284 temp
.visualid
= desiredVisualID
;
1285 temp
.screen
= screen
;
1286 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1288 /* give the visual some useful GLX attributes */
1289 double_flag
= GL_TRUE
;
1292 depth_size
= 24; /*default_depth_bits();*/
1293 stencil_size
= STENCIL_BITS
;
1297 else if (level
==0) {
1298 /* normal color planes */
1300 /* Get an RGB visual */
1301 int min_rgb
= min_red
+ min_green
+ min_blue
;
1302 if (min_rgb
>1 && min_rgb
<8) {
1303 /* a special case to be sure we can get a monochrome visual */
1306 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1309 /* Get a color index visual */
1310 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1311 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1315 /* over/underlay planes */
1318 int min_rgb
= min_red
+ min_green
+ min_blue
;
1319 if (min_rgb
>1 && min_rgb
<8) {
1320 /* a special case to be sure we can get a monochrome visual */
1323 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1324 trans_type
, trans_value
, min_rgb
, visual_type
);
1327 /* color index overlay */
1328 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1329 trans_type
, trans_value
, min_ci
, visual_type
);
1334 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1335 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1336 * largest depth buffer size, which is 32bits/value. Instead, we
1337 * return 16 to maintain performance with earlier versions of Mesa.
1339 if (stencil_size
> 0)
1340 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1341 else if (depth_size
> 24)
1343 else if (depth_size
> 16)
1345 else if (depth_size
> 0) {
1346 depth_size
= default_depth_bits();
1350 alpha_flag
= default_alpha_bits() > 0;
1353 /* we only support one size of stencil and accum buffers. */
1354 if (stencil_size
> 0)
1355 stencil_size
= STENCIL_BITS
;
1356 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1357 accumAlphaSize
> 0) {
1360 accumBlueSize
= default_accum_bits();
1361 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1364 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1365 stereo_flag
, depth_size
, stencil_size
,
1366 accumRedSize
, accumGreenSize
,
1367 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1374 static XVisualInfo
*
1375 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1379 /* register ourselves as an extension on this display */
1380 register_with_display(dpy
);
1382 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1385 return xmvis
->vishandle
;
1387 /* create a new vishandle - the cached one may be stale */
1388 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1389 if (xmvis
->vishandle
) {
1390 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1392 return xmvis
->vishandle
;
1401 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1402 GLXContext share_list
, Bool direct
)
1405 struct fake_glx_context
*glxCtx
;
1406 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1408 if (!dpy
|| !visinfo
)
1411 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1415 /* deallocate unused windows/buffers */
1417 XMesaGarbageCollect();
1420 xmvis
= find_glx_visual( dpy
, visinfo
);
1422 /* This visual wasn't found with glXChooseVisual() */
1423 xmvis
= create_glx_visual( dpy
, visinfo
);
1425 /* unusable visual */
1431 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1432 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1433 if (!glxCtx
->xmesaContext
) {
1438 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
1439 glxCtx
->glxContext
.currentDpy
= dpy
;
1440 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1442 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1444 return (GLXContext
) glxCtx
;
1448 /* XXX these may have to be removed due to thread-safety issues. */
1449 static GLXContext MakeCurrent_PrevContext
= 0;
1450 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1451 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1452 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1453 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1456 /* GLX 1.3 and later */
1458 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1459 GLXDrawable read
, GLXContext ctx
)
1461 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1462 static boolean firsttime
= 1, no_rast
= 0;
1465 no_rast
= getenv("SP_NO_RAST") != NULL
;
1470 if (ctx
&& draw
&& read
) {
1471 XMesaBuffer drawBuffer
, readBuffer
;
1472 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1474 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1475 if (ctx
== MakeCurrent_PrevContext
1476 && draw
== MakeCurrent_PrevDrawable
) {
1477 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1480 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1483 /* drawable must be a new window! */
1484 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1486 /* Out of memory, or context/drawable depth mismatch */
1490 FXcreateContext( xmctx
->xm_visual
, draw
, xmctx
, drawBuffer
);
1494 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1495 if (ctx
== MakeCurrent_PrevContext
1496 && read
== MakeCurrent_PrevReadable
) {
1497 readBuffer
= MakeCurrent_PrevReadBuffer
;
1500 readBuffer
= XMesaFindBuffer( dpy
, read
);
1503 /* drawable must be a new window! */
1504 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1506 /* Out of memory, or context/drawable depth mismatch */
1510 FXcreateContext( xmctx
->xm_visual
, read
, xmctx
, readBuffer
);
1515 MakeCurrent_PrevContext
== ctx
&&
1516 MakeCurrent_PrevDrawable
== draw
&&
1517 MakeCurrent_PrevReadable
== read
&&
1518 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1519 MakeCurrent_PrevReadBuffer
== readBuffer
)
1522 MakeCurrent_PrevContext
= ctx
;
1523 MakeCurrent_PrevDrawable
= draw
;
1524 MakeCurrent_PrevReadable
= read
;
1525 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1526 MakeCurrent_PrevReadBuffer
= readBuffer
;
1528 /* Now make current! */
1529 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1530 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1531 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1532 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1539 else if (!ctx
&& !draw
&& !read
) {
1540 /* release current context w/out assigning new one. */
1541 XMesaMakeCurrent( NULL
, NULL
);
1542 MakeCurrent_PrevContext
= 0;
1543 MakeCurrent_PrevDrawable
= 0;
1544 MakeCurrent_PrevReadable
= 0;
1545 MakeCurrent_PrevDrawBuffer
= 0;
1546 MakeCurrent_PrevReadBuffer
= 0;
1550 /* The args must either all be non-zero or all zero.
1559 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1561 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1566 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1571 v
= find_glx_visual( dpy
, visinfo
);
1573 v
= create_glx_visual( dpy
, visinfo
);
1575 /* unusable visual */
1580 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1588 /*** GLX_MESA_pixmap_colormap ***/
1591 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1592 Pixmap pixmap
, Colormap cmap
)
1597 v
= find_glx_visual( dpy
, visinfo
);
1599 v
= create_glx_visual( dpy
, visinfo
);
1601 /* unusable visual */
1606 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1615 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1617 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1619 XMesaDestroyBuffer(b
);
1621 else if (_mesa_getenv("MESA_DEBUG")) {
1622 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1628 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1629 unsigned long mask
)
1631 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1632 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1633 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1634 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1636 if (MakeCurrent_PrevContext
== src
) {
1639 st_copy_context_state( xm_src
->st
, xm_dst
->st
, (GLuint
) mask
);
1644 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1646 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1654 extern void _kw_ungrab_all( Display
*dpy
);
1655 void _kw_ungrab_all( Display
*dpy
)
1657 XUngrabPointer( dpy
, CurrentTime
);
1658 XUngrabKeyboard( dpy
, CurrentTime
);
1663 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1665 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1667 MakeCurrent_PrevContext
= 0;
1668 MakeCurrent_PrevDrawable
= 0;
1669 MakeCurrent_PrevReadable
= 0;
1670 MakeCurrent_PrevDrawBuffer
= 0;
1671 MakeCurrent_PrevReadBuffer
= 0;
1672 XMesaDestroyContext( glxCtx
->xmesaContext
);
1673 XMesaGarbageCollect();
1679 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1689 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1691 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1694 XMesaSwapBuffers(buffer
);
1696 else if (_mesa_getenv("MESA_DEBUG")) {
1697 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1704 /*** GLX_MESA_copy_sub_buffer ***/
1707 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1708 int x
, int y
, int width
, int height
)
1710 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1712 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1714 else if (_mesa_getenv("MESA_DEBUG")) {
1715 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1721 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1724 /* Return GLX version, not Mesa version */
1725 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1726 *maj
= CLIENT_MAJOR_VERSION
;
1727 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1733 * Query the GLX attributes of the given XVisualInfo.
1736 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1742 return GLX_BAD_ATTRIBUTE
;
1743 *value
= (int) True
;
1745 case GLX_BUFFER_SIZE
:
1746 *value
= xmvis
->visinfo
->depth
;
1749 *value
= xmvis
->mesa_visual
.level
;
1753 return GLX_BAD_ATTRIBUTE
;
1754 if (xmvis
->mesa_visual
.rgbMode
) {
1761 case GLX_DOUBLEBUFFER
:
1762 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1765 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1767 case GLX_AUX_BUFFERS
:
1768 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1771 *value
= xmvis
->mesa_visual
.redBits
;
1773 case GLX_GREEN_SIZE
:
1774 *value
= xmvis
->mesa_visual
.greenBits
;
1777 *value
= xmvis
->mesa_visual
.blueBits
;
1779 case GLX_ALPHA_SIZE
:
1780 *value
= xmvis
->mesa_visual
.alphaBits
;
1782 case GLX_DEPTH_SIZE
:
1783 *value
= xmvis
->mesa_visual
.depthBits
;
1785 case GLX_STENCIL_SIZE
:
1786 *value
= xmvis
->mesa_visual
.stencilBits
;
1788 case GLX_ACCUM_RED_SIZE
:
1789 *value
= xmvis
->mesa_visual
.accumRedBits
;
1791 case GLX_ACCUM_GREEN_SIZE
:
1792 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1794 case GLX_ACCUM_BLUE_SIZE
:
1795 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1797 case GLX_ACCUM_ALPHA_SIZE
:
1798 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1802 * GLX_EXT_visual_info extension
1804 case GLX_X_VISUAL_TYPE_EXT
:
1805 switch (xmvis
->visinfo
->CLASS
) {
1806 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1807 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1808 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1809 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1810 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1811 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1814 case GLX_TRANSPARENT_TYPE_EXT
:
1815 if (xmvis
->mesa_visual
.level
==0) {
1817 *value
= GLX_NONE_EXT
;
1819 else if (xmvis
->mesa_visual
.level
>0) {
1821 if (xmvis
->mesa_visual
.rgbMode
) {
1822 *value
= GLX_TRANSPARENT_RGB_EXT
;
1825 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1828 else if (xmvis
->mesa_visual
.level
<0) {
1830 *value
= GLX_NONE_EXT
;
1833 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1835 int pixel
= transparent_pixel( xmvis
);
1839 /* else undefined */
1842 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1845 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1848 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1851 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1856 * GLX_EXT_visual_info extension
1858 case GLX_VISUAL_CAVEAT_EXT
:
1859 /* test for zero, just in case */
1860 if (xmvis
->mesa_visual
.visualRating
> 0)
1861 *value
= xmvis
->mesa_visual
.visualRating
;
1863 *value
= GLX_NONE_EXT
;
1867 * GLX_ARB_multisample
1869 case GLX_SAMPLE_BUFFERS_ARB
:
1872 case GLX_SAMPLES_ARB
:
1879 case GLX_SCREEN_EXT
:
1881 return GLX_BAD_ATTRIBUTE
;
1882 *value
= xmvis
->visinfo
->screen
;
1884 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1886 return GLX_BAD_ATTRIBUTE
;
1887 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1889 case GLX_RENDER_TYPE_SGIX
:
1891 return GLX_BAD_ATTRIBUTE
;
1892 if (xmvis
->mesa_visual
.rgbMode
)
1893 *value
= GLX_RGBA_BIT
;
1895 *value
= GLX_COLOR_INDEX_BIT
;
1897 case GLX_X_RENDERABLE_SGIX
:
1899 return GLX_BAD_ATTRIBUTE
;
1900 *value
= True
; /* XXX really? */
1902 case GLX_FBCONFIG_ID_SGIX
:
1904 return GLX_BAD_ATTRIBUTE
;
1905 *value
= xmvis
->visinfo
->visualid
;
1907 case GLX_MAX_PBUFFER_WIDTH
:
1909 return GLX_BAD_ATTRIBUTE
;
1910 /* XXX or MAX_WIDTH? */
1911 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1913 case GLX_MAX_PBUFFER_HEIGHT
:
1915 return GLX_BAD_ATTRIBUTE
;
1916 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1918 case GLX_MAX_PBUFFER_PIXELS
:
1920 return GLX_BAD_ATTRIBUTE
;
1921 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1922 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1926 return GLX_BAD_ATTRIBUTE
;
1927 *value
= xmvis
->visinfo
->visualid
;
1930 #ifdef GLX_EXT_texture_from_pixmap
1931 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1932 *value
= True
; /*XXX*/
1934 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1936 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1938 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1939 *value
= True
; /*XXX*/
1941 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1942 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1943 GLX_TEXTURE_2D_BIT_EXT
|
1944 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1946 case GLX_Y_INVERTED_EXT
:
1947 *value
= True
; /*XXX*/
1952 return GLX_BAD_ATTRIBUTE
;
1959 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1960 int attrib
, int *value
)
1964 if (!dpy
|| !visinfo
)
1965 return GLX_BAD_ATTRIBUTE
;
1967 xmvis
= find_glx_visual( dpy
, visinfo
);
1969 /* this visual wasn't obtained with glXChooseVisual */
1970 xmvis
= create_glx_visual( dpy
, visinfo
);
1972 /* this visual can't be used for GL rendering */
1973 if (attrib
==GLX_USE_GL
) {
1974 *value
= (int) False
;
1978 return GLX_BAD_VISUAL
;
1983 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1989 Fake_glXWaitGL( void )
1991 XMesaContext xmesa
= XMesaGetCurrentContext();
1992 XMesaFlush( xmesa
);
1998 Fake_glXWaitX( void )
2000 XMesaContext xmesa
= XMesaGetCurrentContext();
2001 XMesaFlush( xmesa
);
2006 get_extensions( void )
2009 const char *fx
= _mesa_getenv("MESA_GLX_FX");
2010 if (fx
&& fx
[0] != 'd') {
2014 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
2019 /* GLX 1.1 and later */
2021 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
2025 return get_extensions();
2030 /* GLX 1.1 and later */
2032 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
2034 static char version
[1000];
2035 _mesa_sprintf(version
, "%d.%d %s",
2036 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
2042 case GLX_EXTENSIONS
:
2043 return get_extensions();
2055 /* GLX 1.1 and later */
2057 Fake_glXGetClientString( Display
*dpy
, int name
)
2059 static char version
[1000];
2060 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
2061 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
2066 case GLX_EXTENSIONS
:
2067 return get_extensions();
2085 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
2086 int attribute
, int *value
)
2088 XMesaVisual v
= (XMesaVisual
) config
;
2092 if (!dpy
|| !config
|| !value
)
2095 return get_config(v
, attribute
, value
, GL_TRUE
);
2099 static GLXFBConfig
*
2100 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
2102 XVisualInfo
*visuals
, visTemplate
;
2103 const long visMask
= VisualScreenMask
;
2106 /* Get list of all X visuals */
2107 visTemplate
.screen
= screen
;
2108 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
2109 if (*nelements
> 0) {
2110 XMesaVisual
*results
;
2111 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
2116 for (i
= 0; i
< *nelements
; i
++) {
2117 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
2119 return (GLXFBConfig
*) results
;
2125 static GLXFBConfig
*
2126 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
2127 const int *attribList
, int *nitems
)
2131 if (!attribList
|| !attribList
[0]) {
2132 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
2133 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
2136 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
2138 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
2144 config
[0] = (GLXFBConfig
) xmvis
;
2145 return (GLXFBConfig
*) config
;
2154 static XVisualInfo
*
2155 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
2157 if (dpy
&& config
) {
2158 XMesaVisual xmvis
= (XMesaVisual
) config
;
2160 return xmvis
->vishandle
;
2162 /* create a new vishandle - the cached one may be stale */
2163 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
2164 if (xmvis
->vishandle
) {
2165 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
2167 return xmvis
->vishandle
;
2177 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
2178 const int *attribList
)
2180 XMesaVisual xmvis
= (XMesaVisual
) config
;
2185 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
2190 /* XXX this will segfault if actually called */
2191 FXcreateContext(xmvis
, win
, NULL
, xmbuf
);
2195 (void) attribList
; /* Ignored in GLX 1.3 */
2197 return win
; /* A hack for now */
2202 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
2204 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2206 XMesaDestroyBuffer(b
);
2207 /* don't destroy X window */
2213 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2214 const int *attribList
)
2216 XMesaVisual v
= (XMesaVisual
) config
;
2219 int target
= 0, format
= 0, mipmap
= 0;
2222 if (!dpy
|| !config
|| !pixmap
)
2225 for (attr
= attribList
; *attr
; attr
++) {
2227 case GLX_TEXTURE_FORMAT_EXT
:
2230 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2231 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2232 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2240 case GLX_TEXTURE_TARGET_EXT
:
2243 case GLX_TEXTURE_1D_EXT
:
2244 case GLX_TEXTURE_2D_EXT
:
2245 case GLX_TEXTURE_RECTANGLE_EXT
:
2253 case GLX_MIPMAP_TEXTURE_EXT
:
2264 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2265 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2266 &value
, GL_TRUE
) != Success
2268 return 0; /* error! */
2271 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2272 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2273 &value
, GL_TRUE
) != Success
2275 return 0; /* error! */
2279 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2280 &value
, GL_TRUE
) != Success
2282 return 0; /* error! */
2285 if (target
== GLX_TEXTURE_1D_EXT
) {
2286 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2287 &value
, GL_TRUE
) != Success
2288 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2289 return 0; /* error! */
2292 else if (target
== GLX_TEXTURE_2D_EXT
) {
2293 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2294 &value
, GL_TRUE
) != Success
2295 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2296 return 0; /* error! */
2299 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2300 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2301 &value
, GL_TRUE
) != Success
2302 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2303 return 0; /* error! */
2307 if (format
|| target
|| mipmap
) {
2308 /* texture from pixmap */
2309 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2312 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2323 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2325 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2327 XMesaDestroyBuffer(b
);
2328 /* don't destroy X pixmap */
2333 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2334 const int *attribList
)
2336 XMesaVisual xmvis
= (XMesaVisual
) config
;
2339 int width
= 0, height
= 0;
2340 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2344 for (attrib
= attribList
; *attrib
; attrib
++) {
2346 case GLX_PBUFFER_WIDTH
:
2350 case GLX_PBUFFER_HEIGHT
:
2354 case GLX_PRESERVED_CONTENTS
:
2356 preserveContents
= *attrib
; /* ignored */
2358 case GLX_LARGEST_PBUFFER
:
2360 useLargest
= *attrib
; /* ignored */
2367 /* not used at this time */
2369 (void) preserveContents
;
2371 if (width
== 0 || height
== 0)
2374 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2375 /* A GLXPbuffer handle must be an X Drawable because that's what
2376 * glXMakeCurrent takes.
2379 return (GLXPbuffer
) xmbuf
->drawable
;
2386 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2388 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2390 XMesaDestroyBuffer(b
);
2396 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2397 unsigned int *value
)
2399 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2403 switch (attribute
) {
2405 *value
= xmesa_buffer_width(xmbuf
);
2408 *value
= xmesa_buffer_width(xmbuf
);
2410 case GLX_PRESERVED_CONTENTS
:
2413 case GLX_LARGEST_PBUFFER
:
2414 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2416 case GLX_FBCONFIG_ID
:
2417 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2419 #ifdef GLX_EXT_texture_from_pixmap
2420 case GLX_TEXTURE_FORMAT_EXT
:
2421 *value
= xmbuf
->TextureFormat
;
2423 case GLX_TEXTURE_TARGET_EXT
:
2424 *value
= xmbuf
->TextureTarget
;
2426 case GLX_MIPMAP_TEXTURE_EXT
:
2427 *value
= xmbuf
->TextureMipmap
;
2432 return; /* raise BadValue error */
2438 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2439 int renderType
, GLXContext shareList
, Bool direct
)
2441 struct fake_glx_context
*glxCtx
;
2442 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2443 XMesaVisual xmvis
= (XMesaVisual
) config
;
2445 if (!dpy
|| !config
||
2446 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2449 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2453 /* deallocate unused windows/buffers */
2454 XMesaGarbageCollect();
2456 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2457 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2458 if (!glxCtx
->xmesaContext
) {
2463 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2464 glxCtx
->glxContext
.currentDpy
= dpy
;
2465 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2467 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2469 return (GLXContext
) glxCtx
;
2474 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2476 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2477 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2482 switch (attribute
) {
2483 case GLX_FBCONFIG_ID
:
2484 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2486 case GLX_RENDER_TYPE
:
2487 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2488 *value
= GLX_RGBA_BIT
;
2490 *value
= GLX_COLOR_INDEX_BIT
;
2496 return GLX_BAD_ATTRIBUTE
;
2503 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2505 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2507 xmbuf
->selectedEvents
= mask
;
2512 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2513 unsigned long *mask
)
2515 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2517 *mask
= xmbuf
->selectedEvents
;
2524 /*** GLX_SGI_swap_control ***/
2527 Fake_glXSwapIntervalSGI(int interval
)
2535 /*** GLX_SGI_video_sync ***/
2537 static unsigned int FrameCounter
= 0;
2540 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2542 /* this is a bogus implementation */
2543 *count
= FrameCounter
++;
2548 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2550 if (divisor
<= 0 || remainder
< 0)
2551 return GLX_BAD_VALUE
;
2552 /* this is a bogus implementation */
2554 while (FrameCounter
% divisor
!= remainder
)
2556 *count
= FrameCounter
;
2562 /*** GLX_SGI_make_current_read ***/
2565 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2567 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2572 Fake_glXGetCurrentReadDrawableSGI(void)
2579 /*** GLX_SGIX_video_source ***/
2582 static GLXVideoSourceSGIX
2583 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2595 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2604 /*** GLX_EXT_import_context ***/
2607 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2614 Fake_glXGetContextIDEXT(const GLXContext context
)
2621 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2629 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2640 /*** GLX_SGIX_fbconfig ***/
2643 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2645 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2648 static GLXFBConfigSGIX
*
2649 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2651 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2656 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2658 XMesaVisual xmvis
= (XMesaVisual
) config
;
2659 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2660 return xmbuf
->drawable
; /* need to return an X ID */
2665 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2667 XMesaVisual xmvis
= (XMesaVisual
) config
;
2668 struct fake_glx_context
*glxCtx
;
2669 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2671 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2675 /* deallocate unused windows/buffers */
2676 XMesaGarbageCollect();
2678 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2679 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2680 if (!glxCtx
->xmesaContext
) {
2685 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2686 glxCtx
->glxContext
.currentDpy
= dpy
;
2687 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2689 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2691 return (GLXContext
) glxCtx
;
2695 static XVisualInfo
*
2696 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2698 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2702 static GLXFBConfigSGIX
2703 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2705 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2707 /* This visual wasn't found with glXChooseVisual() */
2708 xmvis
= create_glx_visual(dpy
, vis
);
2711 return (GLXFBConfigSGIX
) xmvis
;
2716 /*** GLX_SGIX_pbuffer ***/
2718 static GLXPbufferSGIX
2719 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2720 unsigned int width
, unsigned int height
,
2723 XMesaVisual xmvis
= (XMesaVisual
) config
;
2726 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2730 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2732 case GLX_PRESERVED_CONTENTS_SGIX
:
2734 preserveContents
= *attrib
; /* ignored */
2736 case GLX_LARGEST_PBUFFER_SGIX
:
2738 useLargest
= *attrib
; /* ignored */
2745 /* not used at this time */
2747 (void) preserveContents
;
2749 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2750 /* A GLXPbuffer handle must be an X Drawable because that's what
2751 * glXMakeCurrent takes.
2753 return (GLXPbuffer
) xmbuf
->drawable
;
2758 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2760 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2762 XMesaDestroyBuffer(xmbuf
);
2768 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2770 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2773 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2777 switch (attribute
) {
2778 case GLX_PRESERVED_CONTENTS_SGIX
:
2781 case GLX_LARGEST_PBUFFER_SGIX
:
2782 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2784 case GLX_WIDTH_SGIX
:
2785 *value
= xmesa_buffer_width(xmbuf
);
2787 case GLX_HEIGHT_SGIX
:
2788 *value
= xmesa_buffer_height(xmbuf
);
2790 case GLX_EVENT_MASK_SGIX
:
2791 *value
= 0; /* XXX might be wrong */
2801 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2803 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2805 /* Note: we'll never generate clobber events */
2806 xmbuf
->selectedEvents
= mask
;
2812 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2814 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2816 *mask
= xmbuf
->selectedEvents
;
2825 /*** GLX_SGI_cushion ***/
2828 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2837 /*** GLX_SGIX_video_resize ***/
2840 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2850 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2863 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2876 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2889 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2900 /*** GLX_SGIX_dmbuffer **/
2902 #if defined(_DM_BUFFER_H_)
2904 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2915 /*** GLX_SGIX_swap_group ***/
2918 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2927 /*** GLX_SGIX_swap_barrier ***/
2930 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2938 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2948 /*** GLX_SUN_get_transparent_index ***/
2951 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2956 (void) pTransparent
;
2962 /*** GLX_MESA_release_buffers ***/
2965 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2966 * (a window or pixmap) prior to destroying the GLXDrawable.
2969 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2971 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2973 XMesaDestroyBuffer(b
);
2981 /*** GLX_MESA_set_3dfx_mode ***/
2984 Fake_glXSet3DfxModeMESA( int mode
)
2986 return XMesaSetFXmode( mode
);
2991 /*** GLX_NV_vertex_array range ***/
2993 Fake_glXAllocateMemoryNV( GLsizei size
,
2994 GLfloat readFrequency
,
2995 GLfloat writeFrequency
,
2999 (void) readFrequency
;
3000 (void) writeFrequency
;
3007 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
3013 /*** GLX_MESA_agp_offset ***/
3016 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
3023 /*** GLX_EXT_texture_from_pixmap ***/
3026 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
3027 const int *attrib_list
)
3029 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3031 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
3035 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
3037 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
3039 XMesaReleaseTexImage(dpy
, b
, buffer
);
3043 /* silence warning */
3044 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
3048 * Create a new GLX API dispatch table with its function pointers
3049 * initialized to point to Mesa's "fake" GLX API functions.
3050 * Note: there's a similar function (_real_GetGLXDispatchTable) that
3051 * returns a new dispatch table with all pointers initalized to point
3052 * to "real" GLX functions (which understand GLX wire protocol, etc).
3054 struct _glxapi_table
*
3055 _mesa_GetGLXDispatchTable(void)
3057 static struct _glxapi_table glx
;
3059 /* be sure our dispatch table size <= libGL's table */
3061 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
3063 assert(_glxapi_get_dispatch_table_size() >= size
);
3066 /* initialize the whole table to no-ops */
3067 _glxapi_set_no_op_table(&glx
);
3069 /* now initialize the table with the functions I implement */
3070 glx
.ChooseVisual
= Fake_glXChooseVisual
;
3071 glx
.CopyContext
= Fake_glXCopyContext
;
3072 glx
.CreateContext
= Fake_glXCreateContext
;
3073 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
3074 glx
.DestroyContext
= Fake_glXDestroyContext
;
3075 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
3076 glx
.GetConfig
= Fake_glXGetConfig
;
3077 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
3078 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
3079 glx
.IsDirect
= Fake_glXIsDirect
;
3080 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
3081 glx
.QueryExtension
= Fake_glXQueryExtension
;
3082 glx
.QueryVersion
= Fake_glXQueryVersion
;
3083 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
3084 glx
.UseXFont
= Fake_glXUseXFont
;
3085 glx
.WaitGL
= Fake_glXWaitGL
;
3086 glx
.WaitX
= Fake_glXWaitX
;
3088 /*** GLX_VERSION_1_1 ***/
3089 glx
.GetClientString
= Fake_glXGetClientString
;
3090 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
3091 glx
.QueryServerString
= Fake_glXQueryServerString
;
3093 /*** GLX_VERSION_1_2 ***/
3094 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
3096 /*** GLX_VERSION_1_3 ***/
3097 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
3098 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
3099 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
3100 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
3101 glx
.CreateWindow
= Fake_glXCreateWindow
;
3102 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
3103 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
3104 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
3105 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
3106 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
3107 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
3108 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
3109 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
3110 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
3111 glx
.QueryContext
= Fake_glXQueryContext
;
3112 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
3113 glx
.SelectEvent
= Fake_glXSelectEvent
;
3115 /*** GLX_SGI_swap_control ***/
3116 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
3118 /*** GLX_SGI_video_sync ***/
3119 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
3120 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
3122 /*** GLX_SGI_make_current_read ***/
3123 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
3124 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
3126 /*** GLX_SGIX_video_source ***/
3128 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
3129 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
3132 /*** GLX_EXT_import_context ***/
3133 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
3134 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
3135 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
3136 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
3137 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
3139 /*** GLX_SGIX_fbconfig ***/
3140 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
3141 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
3142 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
3143 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
3144 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
3145 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
3147 /*** GLX_SGIX_pbuffer ***/
3148 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
3149 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
3150 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
3151 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
3152 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
3154 /*** GLX_SGI_cushion ***/
3155 glx
.CushionSGI
= Fake_glXCushionSGI
;
3157 /*** GLX_SGIX_video_resize ***/
3158 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
3159 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
3160 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
3161 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
3162 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
3164 /*** GLX_SGIX_dmbuffer **/
3165 #if defined(_DM_BUFFER_H_)
3166 glx
.AssociateDMPbufferSGIX
= NULL
;
3169 /*** GLX_SGIX_swap_group ***/
3170 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
3172 /*** GLX_SGIX_swap_barrier ***/
3173 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
3174 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
3176 /*** GLX_SUN_get_transparent_index ***/
3177 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
3179 /*** GLX_MESA_copy_sub_buffer ***/
3180 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3182 /*** GLX_MESA_release_buffers ***/
3183 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3185 /*** GLX_MESA_pixmap_colormap ***/
3186 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3188 /*** GLX_MESA_set_3dfx_mode ***/
3189 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3191 /*** GLX_NV_vertex_array_range ***/
3192 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3193 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3195 /*** GLX_MESA_agp_offset ***/
3196 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3198 /*** GLX_EXT_texture_from_pixmap ***/
3199 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3200 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;