2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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"
56 /* This indicates the client-side GLX API and GLX encoder version. */
57 #define CLIENT_MAJOR_VERSION 1
58 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
60 /* This indicates the server-side GLX decoder version.
61 * GLX 1.4 indicates OpenGL 1.3 support
63 #define SERVER_MAJOR_VERSION 1
64 #define SERVER_MINOR_VERSION 4
66 /* This is appended onto the glXGetClient/ServerString version strings. */
67 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
69 /* Who implemented this GLX? */
70 #define VENDOR "Brian Paul"
73 "GLX_MESA_set_3dfx_mode " \
74 "GLX_MESA_copy_sub_buffer " \
75 "GLX_MESA_pixmap_colormap " \
76 "GLX_MESA_release_buffers " \
77 "GLX_ARB_get_proc_address " \
78 "GLX_EXT_visual_info " \
79 "GLX_EXT_visual_rating " \
80 "GLX_SGI_video_sync " \
81 "GLX_SGIX_fbconfig " \
85 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
87 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
90 * We really just need this structure in order to make the libGL functions
91 * glXGetCurrentContext(), glXGetCurrentDrawable() and glXGetCurrentDisplay()
94 struct fake_glx_context
{
95 __GLXcontext glxContext
; /* this MUST be first! */
96 XMesaContext xmesaContext
;
101 /**********************************************************************/
102 /*** GLX Visual Code ***/
103 /**********************************************************************/
108 #define MAX_VISUALS 100
109 static XMesaVisual VisualTable
[MAX_VISUALS
];
110 static int NumVisuals
= 0;
114 * This struct and some code fragments borrowed
115 * from Mark Kilgard's GLUT library.
117 typedef struct _OverlayInfo
{
118 /* Avoid 64-bit portability problems by being careful to use
119 longs due to the way XGetWindowProperty is specified. Note
120 that these parameters are passed as CARD32s over X
122 unsigned long overlay_visual
;
123 long transparent_type
;
130 /* Macro to handle c_class vs class field name in XVisualInfo struct */
131 #if defined(__cplusplus) || defined(c_plusplus)
132 #define CLASS c_class
141 * Test if the given XVisualInfo is usable for Mesa rendering.
144 is_usable_visual( XVisualInfo
*vinfo
)
146 switch (vinfo
->CLASS
) {
149 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
153 /* Any StaticColor/PseudoColor visual of at least 4 bits */
154 if (vinfo
->depth
>=4) {
162 /* Any depth of TrueColor or DirectColor works in RGB mode */
165 /* This should never happen */
173 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
174 * Input: dpy - the X display
175 * vinfo - the XVisualInfo to test
176 * Return: level of the visual:
178 * >0 = overlay planes
179 * <0 = underlay planes
182 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
184 Atom overlayVisualsAtom
;
185 OverlayInfo
*overlay_info
= NULL
;
186 int numOverlaysPerScreen
;
190 unsigned long sizeData
, bytesLeft
;
194 * The SERVER_OVERLAY_VISUALS property on the root window contains
195 * a list of overlay visuals. Get that list now.
197 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
198 if (overlayVisualsAtom
== None
) {
202 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, vinfo
->screen
),
203 overlayVisualsAtom
, 0L, (long) 10000, False
,
204 overlayVisualsAtom
, &actualType
, &actualFormat
,
205 &sizeData
, &bytesLeft
,
206 (unsigned char **) &overlay_info
);
208 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
209 actualFormat
!= 32 || sizeData
< 4) {
210 /* something went wrong */
211 XFree((void *) overlay_info
);
215 /* search the overlay visual list for the visual ID of interest */
216 numOverlaysPerScreen
= (int) (sizeData
/ 4);
217 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
219 ov
= overlay_info
+ i
;
220 if (ov
->overlay_visual
==vinfo
->visualid
) {
221 /* found the visual */
222 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
223 int level
= ov
->layer
;
224 XFree((void *) overlay_info
);
228 XFree((void *) overlay_info
);
234 /* The visual ID was not found in the overlay list. */
235 XFree((void *) overlay_info
);
243 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
244 * configuration in our list of GLX visuals.
247 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
248 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
249 GLboolean stereoFlag
,
250 GLint depth_size
, GLint stencil_size
,
251 GLint accumRedSize
, GLint accumGreenSize
,
252 GLint accumBlueSize
, GLint accumAlphaSize
,
253 GLint level
, GLint numAuxBuffers
)
255 GLboolean ximageFlag
= GL_TRUE
;
258 GLboolean comparePointers
;
261 /* Check if the MESA_BACK_BUFFER env var is set */
262 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
264 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
265 ximageFlag
= GL_FALSE
;
267 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
268 ximageFlag
= GL_TRUE
;
271 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
276 /* Comparing IDs uses less memory but sometimes fails. */
277 /* XXX revisit this after 3.0 is finished. */
278 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
279 comparePointers
= GL_TRUE
;
281 comparePointers
= GL_FALSE
;
283 /* Force the visual to have an alpha channel */
284 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
287 /* First check if a matching visual is already in the list */
288 for (i
=0; i
<NumVisuals
; i
++) {
289 XMesaVisual v
= VisualTable
[i
];
290 if (v
->display
== dpy
291 && v
->mesa_visual
.level
== level
292 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
293 && v
->ximage_flag
== ximageFlag
294 && v
->mesa_visual
.rgbMode
== rgbFlag
295 && v
->mesa_visual
.doubleBufferMode
== dbFlag
296 && v
->mesa_visual
.stereoMode
== stereoFlag
297 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
298 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
299 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
300 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
301 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
302 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
303 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
304 /* now either compare XVisualInfo pointers or visual IDs */
305 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
306 || (comparePointers
&& v
->vishandle
== vinfo
)) {
312 /* Create a new visual and add it to the list. */
314 if (NumVisuals
>= MAX_VISUALS
) {
315 _mesa_problem(NULL
, "GLX Error: maximum number of visuals exceeded");
319 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
320 stereoFlag
, ximageFlag
,
321 depth_size
, stencil_size
,
322 accumRedSize
, accumBlueSize
,
323 accumBlueSize
, accumAlphaSize
, 0, level
,
326 /* Save a copy of the pointer now so we can find this visual again
327 * if we need to search for it in find_glx_visual().
329 xmvis
->vishandle
= vinfo
;
330 /* add xmvis to the list */
331 VisualTable
[NumVisuals
] = xmvis
;
333 /* XXX minor hack, because XMesaCreateVisual doesn't support an
334 * aux buffers parameter.
336 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
343 * Return the default number of bits for the Z buffer.
344 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
345 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
346 * XXX probably do the same thing for stencil, accum, etc.
349 default_depth_bits(void)
352 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
354 zBits
= _mesa_atoi(zEnv
);
356 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
363 * Create a GLX visual from a regular XVisualInfo.
364 * This is called when Fake GLX is given an XVisualInfo which wasn't
365 * returned by glXChooseVisual. Since this is the first time we're
366 * considering this visual we'll take a guess at reasonable values
367 * for depth buffer size, stencil size, accum size, etc.
368 * This is the best we can do with a client-side emulation of GLX.
371 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
374 GLint zBits
= default_depth_bits();
376 vislevel
= level_of_visual( dpy
, visinfo
);
378 /* Configure this visual as a CI, single-buffered overlay */
379 return save_glx_visual( dpy
, visinfo
,
381 GL_FALSE
, /* alpha */
382 GL_FALSE
, /* double */
383 GL_FALSE
, /* stereo */
385 0, /* stencil bits */
386 0,0,0,0, /* accum bits */
387 vislevel
, /* level */
391 else if (is_usable_visual( visinfo
)) {
392 if (_mesa_getenv("MESA_GLX_FORCE_CI")) {
393 /* Configure this visual as a COLOR INDEX visual. */
394 return save_glx_visual( dpy
, visinfo
,
396 GL_FALSE
, /* alpha */
397 GL_TRUE
, /* double */
398 GL_FALSE
, /* stereo */
400 8 * sizeof(GLstencil
),
401 0 * sizeof(GLaccum
), /* r */
402 0 * sizeof(GLaccum
), /* g */
403 0 * sizeof(GLaccum
), /* b */
404 0 * sizeof(GLaccum
), /* a */
410 /* Configure this visual as RGB, double-buffered, depth-buffered. */
411 /* This is surely wrong for some people's needs but what else */
412 /* can be done? They should use glXChooseVisual(). */
413 return save_glx_visual( dpy
, visinfo
,
415 GL_FALSE
, /* alpha */
416 GL_TRUE
, /* double */
417 GL_FALSE
, /* stereo */
419 8 * sizeof(GLstencil
),
420 8 * sizeof(GLaccum
), /* r */
421 8 * sizeof(GLaccum
), /* g */
422 8 * sizeof(GLaccum
), /* b */
423 8 * sizeof(GLaccum
), /* a */
430 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
438 * Find the GLX visual associated with an XVisualInfo.
441 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
445 /* try to match visual id */
446 for (i
=0;i
<NumVisuals
;i
++) {
447 if (VisualTable
[i
]->display
==dpy
448 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
449 return VisualTable
[i
];
453 /* if that fails, try to match pointers */
454 for (i
=0;i
<NumVisuals
;i
++) {
455 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
456 return VisualTable
[i
];
466 * Return the transparent pixel value for a GLX visual.
467 * Input: glxvis - the glx_visual
468 * Return: a pixel value or -1 if no transparent pixel
471 transparent_pixel( XMesaVisual glxvis
)
473 Display
*dpy
= glxvis
->display
;
474 XVisualInfo
*vinfo
= glxvis
->visinfo
;
475 Atom overlayVisualsAtom
;
476 OverlayInfo
*overlay_info
= NULL
;
477 int numOverlaysPerScreen
;
481 unsigned long sizeData
, bytesLeft
;
485 * The SERVER_OVERLAY_VISUALS property on the root window contains
486 * a list of overlay visuals. Get that list now.
488 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
489 if (overlayVisualsAtom
== None
) {
493 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, vinfo
->screen
),
494 overlayVisualsAtom
, 0L, (long) 10000, False
,
495 overlayVisualsAtom
, &actualType
, &actualFormat
,
496 &sizeData
, &bytesLeft
,
497 (unsigned char **) &overlay_info
);
499 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
500 actualFormat
!= 32 || sizeData
< 4) {
501 /* something went wrong */
502 XFree((void *) overlay_info
);
506 /* search the overlay visual list for the visual ID of interest */
507 numOverlaysPerScreen
= (int) (sizeData
/ 4);
508 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
510 ov
= overlay_info
+ i
;
511 if (ov
->overlay_visual
==vinfo
->visualid
) {
513 if (ov
->transparent_type
==0) {
514 /* type 0 indicates no transparency */
515 XFree((void *) overlay_info
);
519 /* ov->value is the transparent pixel */
520 XFree((void *) overlay_info
);
526 /* The visual ID was not found in the overlay list. */
527 XFree((void *) overlay_info
);
534 * Try to get an X visual which matches the given arguments.
537 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
539 XVisualInfo temp
, *vis
;
542 unsigned int default_depth
;
545 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
550 default_depth
= DefaultDepth(dpy
,scr
);
551 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
553 if (depth
==default_depth
&& xclass
==default_class
) {
554 /* try to get root window's visual */
555 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
556 mask
|= VisualIDMask
;
559 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
561 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
562 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
563 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
565 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
566 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
567 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
568 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
583 * Retrieve the value of the given environment variable and find
584 * the X visual which matches it.
585 * Input: dpy - the display
586 * screen - the screen number
587 * varname - the name of the environment variable
588 * Return: an XVisualInfo pointer to NULL if error.
591 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
593 char value
[100], type
[100];
594 int depth
, xclass
= -1;
597 if (!_mesa_getenv( varname
)) {
601 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
604 sscanf( value
, "%s %d", type
, &depth
);
606 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
607 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
608 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
609 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
610 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
611 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
613 if (xclass
>-1 && depth
>0) {
614 vis
= get_visual( dpy
, scr
, depth
, xclass
);
620 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
629 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
630 * Input: dpy, screen - X display and screen number
631 * rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode
632 * min_depth - minimum visual depth
633 * preferred_class - preferred GLX visual class or DONT_CARE
634 * Return: pointer to an XVisualInfo or NULL.
637 choose_x_visual( Display
*dpy
, int screen
, GLboolean rgba
, int min_depth
,
638 int preferred_class
)
641 int xclass
, visclass
= 0;
645 Atom hp_cr_maps
= XInternAtom(dpy
, "_HP_RGB_SMOOTH_MAP_LIST", True
);
646 /* First see if the MESA_RGB_VISUAL env var is defined */
647 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
651 /* Otherwise, search for a suitable visual */
652 if (preferred_class
==DONT_CARE
) {
653 for (xclass
=0;xclass
<6;xclass
++) {
655 case 0: visclass
= TrueColor
; break;
656 case 1: visclass
= DirectColor
; break;
657 case 2: visclass
= PseudoColor
; break;
658 case 3: visclass
= StaticColor
; break;
659 case 4: visclass
= GrayScale
; break;
660 case 5: visclass
= StaticGray
; break;
663 /* start with shallowest */
664 for (depth
=0;depth
<=32;depth
++) {
665 if (visclass
==TrueColor
&& depth
==8 && !hp_cr_maps
) {
666 /* Special case: try to get 8-bit PseudoColor before */
667 /* 8-bit TrueColor */
668 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
673 vis
= get_visual( dpy
, screen
, depth
, visclass
);
680 /* start with deepest */
681 for (depth
=32;depth
>=min_depth
;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
);
699 /* search for a specific visual class */
700 switch (preferred_class
) {
701 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
702 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
703 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
704 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
705 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
706 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
707 default: return NULL
;
710 /* start with shallowest */
711 for (depth
=0;depth
<=32;depth
++) {
712 vis
= get_visual( dpy
, screen
, depth
, visclass
);
719 /* start with deepest */
720 for (depth
=32;depth
>=min_depth
;depth
--) {
721 vis
= get_visual( dpy
, screen
, depth
, visclass
);
730 /* First see if the MESA_CI_VISUAL env var is defined */
731 vis
= get_env_visual( dpy
, screen
, "MESA_CI_VISUAL" );
735 /* Otherwise, search for a suitable visual, starting with shallowest */
736 if (preferred_class
==DONT_CARE
) {
737 for (xclass
=0;xclass
<4;xclass
++) {
739 case 0: visclass
= PseudoColor
; break;
740 case 1: visclass
= StaticColor
; break;
741 case 2: visclass
= GrayScale
; break;
742 case 3: visclass
= StaticGray
; break;
744 /* try 8-bit up through 16-bit */
745 for (depth
=8;depth
<=16;depth
++) {
746 vis
= get_visual( dpy
, screen
, depth
, visclass
);
751 /* try min_depth up to 8-bit */
752 for (depth
=min_depth
;depth
<8;depth
++) {
753 vis
= get_visual( dpy
, screen
, depth
, visclass
);
761 /* search for a specific visual class */
762 switch (preferred_class
) {
763 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
764 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
765 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
766 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
767 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
768 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
769 default: return NULL
;
771 /* try 8-bit up through 16-bit */
772 for (depth
=8;depth
<=16;depth
++) {
773 vis
= get_visual( dpy
, screen
, depth
, visclass
);
778 /* try min_depth up to 8-bit */
779 for (depth
=min_depth
;depth
<8;depth
++) {
780 vis
= get_visual( dpy
, screen
, depth
, visclass
);
788 /* didn't find a visual */
795 * Find the deepest X over/underlay visual of at least min_depth.
796 * Input: dpy, screen - X display and screen number
797 * level - the over/underlay level
798 * trans_type - transparent pixel type: GLX_NONE_EXT,
799 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
801 * trans_value - transparent pixel value or DONT_CARE
802 * min_depth - minimum visual depth
803 * preferred_class - preferred GLX visual class or DONT_CARE
804 * Return: pointer to an XVisualInfo or NULL.
807 choose_x_overlay_visual( Display
*dpy
, int scr
, GLboolean rgbFlag
,
808 int level
, int trans_type
, int trans_value
,
809 int min_depth
, int preferred_class
)
811 Atom overlayVisualsAtom
;
812 OverlayInfo
*overlay_info
;
813 int numOverlaysPerScreen
;
817 unsigned long sizeData
, bytesLeft
;
819 XVisualInfo
*deepvis
;
822 /*DEBUG int tt, tv; */
824 switch (preferred_class
) {
825 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
826 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
827 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
828 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
829 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
830 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
831 default: preferred_class
= DONT_CARE
;
835 * The SERVER_OVERLAY_VISUALS property on the root window contains
836 * a list of overlay visuals. Get that list now.
838 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
839 if (overlayVisualsAtom
== (Atom
) None
) {
843 status
= XGetWindowProperty(dpy
, RootWindow( dpy
, scr
),
844 overlayVisualsAtom
, 0L, (long) 10000, False
,
845 overlayVisualsAtom
, &actualType
, &actualFormat
,
846 &sizeData
, &bytesLeft
,
847 (unsigned char **) &overlay_info
);
849 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
850 actualFormat
!= 32 || sizeData
< 4) {
851 /* something went wrong */
855 /* Search for the deepest overlay which satisifies all criteria. */
859 numOverlaysPerScreen
= (int) (sizeData
/ 4);
860 for (i
=0;i
<numOverlaysPerScreen
;i
++) {
861 XVisualInfo
*vislist
, vistemplate
;
864 ov
= overlay_info
+ i
;
866 if (ov
->layer
!=level
) {
867 /* failed overlay level criteria */
870 if (!(trans_type
==DONT_CARE
871 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
872 && ov
->transparent_type
>0)
873 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
874 /* failed transparent pixel type criteria */
877 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
878 /* failed transparent pixel value criteria */
882 /* get XVisualInfo and check the depth */
883 vistemplate
.visualid
= ov
->overlay_visual
;
884 vistemplate
.screen
= scr
;
885 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
886 &vistemplate
, &count
);
889 /* something went wrong */
892 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
893 /* wrong visual class */
897 /* if RGB was requested, make sure we have True/DirectColor */
898 if (rgbFlag
&& vislist
->CLASS
!= TrueColor
899 && vislist
->CLASS
!= DirectColor
)
902 /* if CI was requested, make sure we have a color indexed visual */
904 && (vislist
->CLASS
== TrueColor
|| vislist
->CLASS
== DirectColor
))
907 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
908 /* YES! found a satisfactory visual */
912 deepest
= vislist
->depth
;
914 /* DEBUG tt = ov->transparent_type;*/
915 /* DEBUG tv = ov->value; */
921 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
922 deepvis->visualid, level, deepvis->depth, tt, tv );
929 /**********************************************************************/
930 /*** Begin Fake GLX API Functions ***/
931 /**********************************************************************/
935 choose_visual( Display
*dpy
, int screen
, const int *list
,
936 GLboolean rgbModeDefault
)
938 const int *parselist
;
941 int min_red
=0, min_green
=0, min_blue
=0;
942 GLboolean rgb_flag
= rgbModeDefault
;
943 GLboolean alpha_flag
= GL_FALSE
;
944 GLboolean double_flag
= GL_FALSE
;
945 GLboolean stereo_flag
= GL_FALSE
;
946 GLint depth_size
= 0;
947 GLint stencil_size
= 0;
948 GLint accumRedSize
= 0;
949 GLint accumGreenSize
= 0;
950 GLint accumBlueSize
= 0;
951 GLint accumAlphaSize
= 0;
953 int visual_type
= DONT_CARE
;
954 int trans_type
= DONT_CARE
;
955 int trans_value
= DONT_CARE
;
956 GLint caveat
= DONT_CARE
;
957 XMesaVisual xmvis
= NULL
;
958 int desiredVisualID
= -1;
965 switch (*parselist
) {
970 case GLX_BUFFER_SIZE
:
972 min_ci
= *parselist
++;
976 level
= *parselist
++;
982 case GLX_DOUBLEBUFFER
:
983 double_flag
= GL_TRUE
;
987 stereo_flag
= GL_TRUE
;
989 case GLX_AUX_BUFFERS
:
992 numAux
= *parselist
++;
993 if (numAux
> MAX_AUX_BUFFERS
)
998 min_red
= *parselist
++;
1000 case GLX_GREEN_SIZE
:
1002 min_green
= *parselist
++;
1006 min_blue
= *parselist
++;
1008 case GLX_ALPHA_SIZE
:
1011 GLint size
= *parselist
++;
1012 alpha_flag
= size
>0 ? 1 : 0;
1015 case GLX_DEPTH_SIZE
:
1017 depth_size
= *parselist
++;
1019 case GLX_STENCIL_SIZE
:
1021 stencil_size
= *parselist
++;
1023 case GLX_ACCUM_RED_SIZE
:
1026 GLint size
= *parselist
++;
1027 accumRedSize
= MAX2( accumRedSize
, size
);
1030 case GLX_ACCUM_GREEN_SIZE
:
1033 GLint size
= *parselist
++;
1034 accumGreenSize
= MAX2( accumGreenSize
, size
);
1037 case GLX_ACCUM_BLUE_SIZE
:
1040 GLint size
= *parselist
++;
1041 accumBlueSize
= MAX2( accumBlueSize
, size
);
1044 case GLX_ACCUM_ALPHA_SIZE
:
1047 GLint size
= *parselist
++;
1048 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1053 * GLX_EXT_visual_info extension
1055 case GLX_X_VISUAL_TYPE_EXT
:
1057 visual_type
= *parselist
++;
1059 case GLX_TRANSPARENT_TYPE_EXT
:
1061 trans_type
= *parselist
++;
1063 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1065 trans_value
= *parselist
++;
1067 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1068 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1069 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1070 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1077 * GLX_EXT_visual_info extension
1079 case GLX_VISUAL_CAVEAT_EXT
:
1081 caveat
= *parselist
++; /* ignored for now */
1085 * GLX_ARB_multisample
1087 case GLX_SAMPLE_BUFFERS_ARB
:
1088 /* ms not supported */
1090 case GLX_SAMPLES_ARB
:
1091 /* ms not supported */
1097 case GLX_RENDER_TYPE
:
1099 if (*parselist
== GLX_RGBA_BIT
) {
1102 else if (*parselist
== GLX_COLOR_INDEX_BIT
) {
1103 rgb_flag
= GL_FALSE
;
1105 else if (*parselist
== 0) {
1110 case GLX_DRAWABLE_TYPE
:
1112 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1113 return NULL
; /* bad bit */
1117 case GLX_FBCONFIG_ID
:
1119 desiredVisualID
= *parselist
;
1127 /* undefined attribute */
1128 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1137 * Since we're only simulating the GLX extension this function will never
1138 * find any real GL visuals. Instead, all we can do is try to find an RGB
1139 * or CI visual of appropriate depth. Other requested attributes such as
1140 * double buffering, depth buffer, etc. will be associated with the X
1141 * visual and stored in the VisualTable[].
1143 if (desiredVisualID
!= -1) {
1144 /* try to get a specific visual, by visualID */
1147 temp
.visualid
= desiredVisualID
;
1148 temp
.screen
= screen
;
1149 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1151 /* give the visual some useful GLX attributes */
1152 double_flag
= GL_TRUE
;
1155 depth_size
= default_depth_bits();
1156 stencil_size
= STENCIL_BITS
;
1160 else if (level
==0) {
1161 /* normal color planes */
1163 /* Get an RGB visual */
1164 int min_rgb
= min_red
+ min_green
+ min_blue
;
1165 if (min_rgb
>1 && min_rgb
<8) {
1166 /* a special case to be sure we can get a monochrome visual */
1169 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_rgb
, visual_type
);
1172 /* Get a color index visual */
1173 vis
= choose_x_visual( dpy
, screen
, rgb_flag
, min_ci
, visual_type
);
1174 accumRedSize
= accumGreenSize
= accumBlueSize
= accumAlphaSize
= 0;
1178 /* over/underlay planes */
1181 int min_rgb
= min_red
+ min_green
+ min_blue
;
1182 if (min_rgb
>1 && min_rgb
<8) {
1183 /* a special case to be sure we can get a monochrome visual */
1186 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1187 trans_type
, trans_value
, min_rgb
, visual_type
);
1190 /* color index overlay */
1191 vis
= choose_x_overlay_visual( dpy
, screen
, rgb_flag
, level
,
1192 trans_type
, trans_value
, min_ci
, visual_type
);
1197 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1198 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1199 * largest depth buffer size, which is 32bits/value. Instead, we
1200 * return 16 to maintain performance with earlier versions of Mesa.
1202 if (depth_size
> 24)
1203 depth_size
= 31; /* 32 causes int overflow problems */
1204 else if (depth_size
> 16)
1206 else if (depth_size
> 0) {
1207 depth_size
= default_depth_bits();
1210 /* we only support one size of stencil and accum buffers. */
1211 if (stencil_size
> 0)
1212 stencil_size
= STENCIL_BITS
;
1213 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1214 accumAlphaSize
> 0) {
1215 accumRedSize
= ACCUM_BITS
;
1216 accumGreenSize
= ACCUM_BITS
;
1217 accumBlueSize
= ACCUM_BITS
;
1218 accumAlphaSize
= alpha_flag
? ACCUM_BITS
: 0;
1221 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1222 stereo_flag
, depth_size
, stencil_size
,
1223 accumRedSize
, accumGreenSize
,
1224 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1231 static XVisualInfo
*
1232 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1234 XMesaVisual xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1237 return xmvis
->vishandle
;
1239 /* create a new vishandle - the cached one may be stale */
1240 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1241 if (xmvis
->vishandle
) {
1242 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1244 return xmvis
->vishandle
;
1253 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1254 GLXContext share_list
, Bool direct
)
1257 struct fake_glx_context
*glxCtx
;
1258 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1260 if (!dpy
|| !visinfo
)
1263 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1267 /* deallocate unused windows/buffers */
1268 XMesaGarbageCollect();
1270 xmvis
= find_glx_visual( dpy
, visinfo
);
1272 /* This visual wasn't found with glXChooseVisual() */
1273 xmvis
= create_glx_visual( dpy
, visinfo
);
1275 /* unusable visual */
1281 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1282 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1283 if (!glxCtx
->xmesaContext
) {
1288 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
1289 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
1290 glxCtx
->glxContext
.currentDpy
= dpy
;
1291 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1293 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1295 return (GLXContext
) glxCtx
;
1299 /* XXX these may have to be removed due to thread-safety issues. */
1300 static GLXContext MakeCurrent_PrevContext
= 0;
1301 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1302 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1303 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1304 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1307 /* GLX 1.3 and later */
1309 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1310 GLXDrawable read
, GLXContext ctx
)
1312 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1314 if (ctx
&& draw
&& read
) {
1315 XMesaBuffer drawBuffer
, readBuffer
;
1316 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1318 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1319 if (ctx
== MakeCurrent_PrevContext
1320 && draw
== MakeCurrent_PrevDrawable
) {
1321 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1324 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1327 /* drawable must be a new window! */
1328 drawBuffer
= XMesaCreateWindowBuffer2( xmctx
->xm_visual
, draw
, xmctx
);
1330 /* Out of memory, or context/drawable depth mismatch */
1335 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1336 if (ctx
== MakeCurrent_PrevContext
1337 && read
== MakeCurrent_PrevReadable
) {
1338 readBuffer
= MakeCurrent_PrevReadBuffer
;
1341 readBuffer
= XMesaFindBuffer( dpy
, read
);
1344 /* drawable must be a new window! */
1345 readBuffer
= XMesaCreateWindowBuffer2(glxCtx
->xmesaContext
->xm_visual
,
1348 /* Out of memory, or context/drawable depth mismatch */
1353 MakeCurrent_PrevContext
= ctx
;
1354 MakeCurrent_PrevDrawable
= draw
;
1355 MakeCurrent_PrevReadable
= read
;
1356 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1357 MakeCurrent_PrevReadBuffer
= readBuffer
;
1359 /* Now make current! */
1360 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1361 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1362 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1363 #ifndef GLX_BUILT_IN_XMESA
1364 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1366 __glXSetCurrentContext(ctx
);
1374 else if (!ctx
&& !draw
&& !read
) {
1375 /* release current context w/out assigning new one. */
1376 XMesaMakeCurrent( NULL
, NULL
);
1377 MakeCurrent_PrevContext
= 0;
1378 MakeCurrent_PrevDrawable
= 0;
1379 MakeCurrent_PrevReadable
= 0;
1380 MakeCurrent_PrevDrawBuffer
= 0;
1381 MakeCurrent_PrevReadBuffer
= 0;
1382 #ifdef GLX_BUILT_IN_XMESA
1383 /* XXX bind dummy context with __glXSetCurrentContext(ctx); */
1388 /* The args must either all be non-zero or all zero.
1397 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1399 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1404 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1409 v
= find_glx_visual( dpy
, visinfo
);
1411 v
= create_glx_visual( dpy
, visinfo
);
1413 /* unusable visual */
1418 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1422 return b
->frontbuffer
;
1426 /*** GLX_MESA_pixmap_colormap ***/
1429 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1430 Pixmap pixmap
, Colormap cmap
)
1435 v
= find_glx_visual( dpy
, visinfo
);
1437 v
= create_glx_visual( dpy
, visinfo
);
1439 /* unusable visual */
1444 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1448 return b
->frontbuffer
;
1453 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1455 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1457 XMesaDestroyBuffer(b
);
1459 else if (_mesa_getenv("MESA_DEBUG")) {
1460 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1466 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1467 unsigned long mask
)
1469 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1470 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1471 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1472 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1474 _mesa_copy_context( &(xm_src
->mesa
), &(xm_dst
->mesa
), (GLuint
) mask
);
1479 Fake_glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1481 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1489 extern void _kw_ungrab_all( Display
*dpy
);
1490 void _kw_ungrab_all( Display
*dpy
)
1492 XUngrabPointer( dpy
, CurrentTime
);
1493 XUngrabKeyboard( dpy
, CurrentTime
);
1498 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1500 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1502 MakeCurrent_PrevContext
= 0;
1503 MakeCurrent_PrevDrawable
= 0;
1504 MakeCurrent_PrevReadable
= 0;
1505 MakeCurrent_PrevDrawBuffer
= 0;
1506 MakeCurrent_PrevReadBuffer
= 0;
1507 XMesaDestroyContext( glxCtx
->xmesaContext
);
1508 XMesaGarbageCollect();
1513 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1515 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1517 return glxCtx
->xmesaContext
->direct
;
1523 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1525 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1528 XMesaSwapBuffers(buffer
);
1530 else if (_mesa_getenv("MESA_DEBUG")) {
1531 _mesa_warning(NULL
, "Mesa: glXSwapBuffers: invalid drawable\n");
1537 /*** GLX_MESA_copy_sub_buffer ***/
1540 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1541 int x
, int y
, int width
, int height
)
1543 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1545 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1547 else if (_mesa_getenv("MESA_DEBUG")) {
1548 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1554 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1557 /* Return GLX version, not Mesa version */
1558 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1559 *maj
= CLIENT_MAJOR_VERSION
;
1560 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1566 * Query the GLX attributes of the given XVisualInfo.
1569 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1574 *value
= (int) True
;
1576 case GLX_BUFFER_SIZE
:
1577 *value
= xmvis
->visinfo
->depth
;
1580 *value
= xmvis
->mesa_visual
.level
;
1583 if (xmvis
->mesa_visual
.rgbMode
) {
1590 case GLX_DOUBLEBUFFER
:
1591 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1594 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1596 case GLX_AUX_BUFFERS
:
1597 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1600 *value
= xmvis
->mesa_visual
.redBits
;
1602 case GLX_GREEN_SIZE
:
1603 *value
= xmvis
->mesa_visual
.greenBits
;
1606 *value
= xmvis
->mesa_visual
.blueBits
;
1608 case GLX_ALPHA_SIZE
:
1609 *value
= xmvis
->mesa_visual
.alphaBits
;
1611 case GLX_DEPTH_SIZE
:
1612 *value
= xmvis
->mesa_visual
.depthBits
;
1614 case GLX_STENCIL_SIZE
:
1615 *value
= xmvis
->mesa_visual
.stencilBits
;
1617 case GLX_ACCUM_RED_SIZE
:
1618 *value
= xmvis
->mesa_visual
.accumRedBits
;
1620 case GLX_ACCUM_GREEN_SIZE
:
1621 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1623 case GLX_ACCUM_BLUE_SIZE
:
1624 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1626 case GLX_ACCUM_ALPHA_SIZE
:
1627 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1631 * GLX_EXT_visual_info extension
1633 case GLX_X_VISUAL_TYPE_EXT
:
1634 switch (xmvis
->visinfo
->CLASS
) {
1635 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1636 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1637 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1638 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1639 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1640 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1643 case GLX_TRANSPARENT_TYPE_EXT
:
1644 if (xmvis
->mesa_visual
.level
==0) {
1646 *value
= GLX_NONE_EXT
;
1648 else if (xmvis
->mesa_visual
.level
>0) {
1650 if (xmvis
->mesa_visual
.rgbMode
) {
1651 *value
= GLX_TRANSPARENT_RGB_EXT
;
1654 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1657 else if (xmvis
->mesa_visual
.level
<0) {
1659 *value
= GLX_NONE_EXT
;
1662 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1664 int pixel
= transparent_pixel( xmvis
);
1668 /* else undefined */
1671 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1674 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1677 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1680 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1685 * GLX_EXT_visual_info extension
1687 case GLX_VISUAL_CAVEAT_EXT
:
1688 /* test for zero, just in case */
1689 if (xmvis
->mesa_visual
.visualRating
> 0)
1690 *value
= xmvis
->mesa_visual
.visualRating
;
1692 *value
= GLX_NONE_EXT
;
1696 * GLX_ARB_multisample
1698 case GLX_SAMPLE_BUFFERS_ARB
:
1701 case GLX_SAMPLES_ARB
:
1708 case GLX_SCREEN_EXT
:
1710 return GLX_BAD_ATTRIBUTE
;
1711 *value
= xmvis
->visinfo
->screen
;
1713 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1715 return GLX_BAD_ATTRIBUTE
;
1716 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1718 case GLX_RENDER_TYPE_SGIX
:
1720 return GLX_BAD_ATTRIBUTE
;
1721 if (xmvis
->mesa_visual
.rgbMode
)
1722 *value
= GLX_RGBA_BIT
;
1724 *value
= GLX_COLOR_INDEX_BIT
;
1726 case GLX_X_RENDERABLE_SGIX
:
1728 return GLX_BAD_ATTRIBUTE
;
1729 *value
= True
; /* XXX really? */
1731 case GLX_FBCONFIG_ID_SGIX
:
1733 return GLX_BAD_ATTRIBUTE
;
1734 *value
= xmvis
->visinfo
->visualid
;
1736 case GLX_MAX_PBUFFER_WIDTH
:
1738 return GLX_BAD_ATTRIBUTE
;
1739 /* XXX or MAX_WIDTH? */
1740 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1742 case GLX_MAX_PBUFFER_HEIGHT
:
1744 return GLX_BAD_ATTRIBUTE
;
1745 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1747 case GLX_MAX_PBUFFER_PIXELS
:
1749 return GLX_BAD_ATTRIBUTE
;
1750 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1751 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1755 return GLX_BAD_ATTRIBUTE
;
1756 *value
= xmvis
->visinfo
->visualid
;
1760 return GLX_BAD_ATTRIBUTE
;
1767 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1768 int attrib
, int *value
)
1772 if (!dpy
|| !visinfo
)
1773 return GLX_BAD_ATTRIBUTE
;
1775 xmvis
= find_glx_visual( dpy
, visinfo
);
1777 /* this visual wasn't obtained with glXChooseVisual */
1778 xmvis
= create_glx_visual( dpy
, visinfo
);
1780 /* this visual can't be used for GL rendering */
1781 if (attrib
==GLX_USE_GL
) {
1782 *value
= (int) False
;
1786 return GLX_BAD_VISUAL
;
1791 return get_config(xmvis
, attrib
, value
, GL_FALSE
);
1796 Fake_glXWaitGL( void )
1798 XMesaContext xmesa
= XMesaGetCurrentContext();
1799 XMesaFlush( xmesa
);
1805 Fake_glXWaitX( void )
1807 XMesaContext xmesa
= XMesaGetCurrentContext();
1808 XMesaFlush( xmesa
);
1813 get_extensions( void )
1816 const char *fx
= _mesa_getenv("MESA_GLX_FX");
1817 if (fx
&& fx
[0] != 'd') {
1821 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
1826 /* GLX 1.1 and later */
1828 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1832 return get_extensions();
1837 /* GLX 1.1 and later */
1839 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1841 static char version
[1000];
1842 _mesa_sprintf(version
, "%d.%d %s",
1843 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1849 case GLX_EXTENSIONS
:
1850 return get_extensions();
1862 /* GLX 1.1 and later */
1864 Fake_glXGetClientString( Display
*dpy
, int name
)
1866 static char version
[1000];
1867 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1868 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1873 case GLX_EXTENSIONS
:
1874 return get_extensions();
1891 static GLXFBConfig
*
1892 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1893 const int *attribList
, int *nitems
)
1895 XMesaVisual xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1897 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
1903 config
[0] = (GLXFBConfig
) xmvis
;
1904 return (GLXFBConfig
*) config
;
1914 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1915 int attribute
, int *value
)
1917 XMesaVisual v
= (XMesaVisual
) config
;
1921 if (!dpy
|| !config
|| !value
)
1924 return get_config(v
, attribute
, value
, GL_TRUE
);
1928 static GLXFBConfig
*
1929 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1931 XVisualInfo
*visuals
, visTemplate
;
1932 const long visMask
= VisualScreenMask
;
1935 /* Get list of all X visuals */
1936 visTemplate
.screen
= screen
;
1937 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1938 if (*nelements
> 0) {
1939 XMesaVisual
*results
;
1940 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
1945 for (i
= 0; i
< *nelements
; i
++) {
1946 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1948 return (GLXFBConfig
*) results
;
1954 static XVisualInfo
*
1955 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1957 if (dpy
&& config
) {
1958 XMesaVisual xmvis
= (XMesaVisual
) config
;
1960 return xmvis
->vishandle
;
1962 /* create a new vishandle - the cached one may be stale */
1963 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1964 if (xmvis
->vishandle
) {
1965 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1967 return xmvis
->vishandle
;
1977 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1978 const int *attribList
)
1980 XMesaVisual xmvis
= (XMesaVisual
) config
;
1985 xmbuf
= XMesaCreateWindowBuffer2(xmvis
, win
, NULL
);
1990 (void) attribList
; /* Ignored in GLX 1.3 */
1992 return win
; /* A hack for now */
1997 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1999 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2001 XMesaDestroyBuffer(b
);
2002 /* don't destroy X window */
2008 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2009 const int *attribList
)
2011 XMesaVisual v
= (XMesaVisual
) config
;
2017 (void) attribList
; /* Ignored in GLX 1.3 */
2019 if (!dpy
|| !config
|| !pixmap
)
2022 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2032 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2034 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2036 XMesaDestroyBuffer(b
);
2037 /* don't destroy X pixmap */
2042 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2043 const int *attribList
)
2045 XMesaVisual xmvis
= (XMesaVisual
) config
;
2048 int width
= 0, height
= 0;
2049 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2053 for (attrib
= attribList
; *attrib
; attrib
++) {
2055 case GLX_PBUFFER_WIDTH
:
2059 case GLX_PBUFFER_HEIGHT
:
2063 case GLX_PRESERVED_CONTENTS
:
2065 preserveContents
= *attrib
; /* ignored */
2067 case GLX_LARGEST_PBUFFER
:
2069 useLargest
= *attrib
; /* ignored */
2076 /* not used at this time */
2078 (void) preserveContents
;
2080 if (width
== 0 || height
== 0)
2083 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2084 /* A GLXPbuffer handle must be an X Drawable because that's what
2085 * glXMakeCurrent takes.
2087 return (GLXPbuffer
) xmbuf
->frontbuffer
;
2092 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2094 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2096 XMesaDestroyBuffer(b
);
2102 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2103 unsigned int *value
)
2105 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2109 switch (attribute
) {
2111 *value
= xmbuf
->width
;
2114 *value
= xmbuf
->height
;
2116 case GLX_PRESERVED_CONTENTS
:
2119 case GLX_LARGEST_PBUFFER
:
2120 *value
= xmbuf
->width
* xmbuf
->height
;
2122 case GLX_FBCONFIG_ID
:
2123 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2126 return; /* GLX_BAD_ATTRIBUTE? */
2132 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2133 int renderType
, GLXContext shareList
, Bool direct
)
2135 struct fake_glx_context
*glxCtx
;
2136 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2137 XMesaVisual xmvis
= (XMesaVisual
) config
;
2139 if (!dpy
|| !config
||
2140 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2143 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2147 /* deallocate unused windows/buffers */
2148 XMesaGarbageCollect();
2150 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2151 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2152 if (!glxCtx
->xmesaContext
) {
2157 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2158 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2159 glxCtx
->glxContext
.currentDpy
= dpy
;
2160 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2162 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2164 return (GLXContext
) glxCtx
;
2169 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2171 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2172 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2177 switch (attribute
) {
2178 case GLX_FBCONFIG_ID
:
2179 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2181 case GLX_RENDER_TYPE
:
2182 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2183 *value
= GLX_RGBA_BIT
;
2185 *value
= GLX_COLOR_INDEX_BIT
;
2191 return GLX_BAD_ATTRIBUTE
;
2198 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2200 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2202 xmbuf
->selectedEvents
= mask
;
2207 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2208 unsigned long *mask
)
2210 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2212 *mask
= xmbuf
->selectedEvents
;
2219 /*** GLX_SGI_swap_control ***/
2222 Fake_glXSwapIntervalSGI(int interval
)
2230 /*** GLX_SGI_video_sync ***/
2233 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2240 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2250 /*** GLX_SGI_make_current_read ***/
2253 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2255 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2260 Fake_glXGetCurrentReadDrawableSGI(void)
2267 /*** GLX_SGIX_video_source ***/
2270 static GLXVideoSourceSGIX
2271 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2283 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2292 /*** GLX_EXT_import_context ***/
2295 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2302 Fake_glXGetContextIDEXT(const GLXContext context
)
2309 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2317 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2328 /*** GLX_SGIX_fbconfig ***/
2331 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2333 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2336 static GLXFBConfigSGIX
*
2337 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2339 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2344 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2346 XMesaVisual xmvis
= (XMesaVisual
) config
;
2347 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2348 return xmbuf
->frontbuffer
; /* need to return an X ID */
2353 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2355 XMesaVisual xmvis
= (XMesaVisual
) config
;
2356 struct fake_glx_context
*glxCtx
;
2357 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2359 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2363 /* deallocate unused windows/buffers */
2364 XMesaGarbageCollect();
2366 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2367 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2368 if (!glxCtx
->xmesaContext
) {
2373 glxCtx
->xmesaContext
->direct
= GL_FALSE
;
2374 glxCtx
->glxContext
.isDirect
= GL_FALSE
;
2375 glxCtx
->glxContext
.currentDpy
= dpy
;
2376 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2378 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2380 return (GLXContext
) glxCtx
;
2384 static XVisualInfo
*
2385 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2387 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2391 static GLXFBConfigSGIX
2392 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2394 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2396 /* This visual wasn't found with glXChooseVisual() */
2397 xmvis
= create_glx_visual(dpy
, vis
);
2400 return (GLXFBConfigSGIX
) xmvis
;
2405 /*** GLX_SGIX_pbuffer ***/
2407 static GLXPbufferSGIX
2408 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2409 unsigned int width
, unsigned int height
,
2412 XMesaVisual xmvis
= (XMesaVisual
) config
;
2415 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2419 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2421 case GLX_PRESERVED_CONTENTS_SGIX
:
2423 preserveContents
= *attrib
; /* ignored */
2425 case GLX_LARGEST_PBUFFER_SGIX
:
2427 useLargest
= *attrib
; /* ignored */
2434 /* not used at this time */
2436 (void) preserveContents
;
2438 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2439 /* A GLXPbuffer handle must be an X Drawable because that's what
2440 * glXMakeCurrent takes.
2442 return (GLXPbuffer
) xmbuf
->frontbuffer
;
2447 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2449 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2451 XMesaDestroyBuffer(xmbuf
);
2457 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2459 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2462 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2466 switch (attribute
) {
2467 case GLX_PRESERVED_CONTENTS_SGIX
:
2470 case GLX_LARGEST_PBUFFER_SGIX
:
2471 *value
= xmbuf
->width
* xmbuf
->height
;
2473 case GLX_WIDTH_SGIX
:
2474 *value
= xmbuf
->width
;
2476 case GLX_HEIGHT_SGIX
:
2477 *value
= xmbuf
->height
;
2479 case GLX_EVENT_MASK_SGIX
:
2480 *value
= 0; /* XXX might be wrong */
2490 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2492 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2494 /* Note: we'll never generate clobber events */
2495 xmbuf
->selectedEvents
= mask
;
2501 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2503 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2505 *mask
= xmbuf
->selectedEvents
;
2514 /*** GLX_SGI_cushion ***/
2517 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2526 /*** GLX_SGIX_video_resize ***/
2529 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2539 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2552 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2565 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2578 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2589 /*** GLX_SGIX_dmbuffer **/
2591 #if defined(_DM_BUFFER_H_)
2593 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2604 /*** GLX_SGIX_swap_group ***/
2607 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2616 /*** GLX_SGIX_swap_barrier ***/
2619 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2627 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2637 /*** GLX_SUN_get_transparent_index ***/
2640 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2645 (void) pTransparent
;
2651 /*** GLX_MESA_release_buffers ***/
2654 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2655 * (a window or pixmap) prior to destroying the GLXDrawable.
2658 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2660 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2662 XMesaDestroyBuffer(b
);
2670 /*** GLX_MESA_set_3dfx_mode ***/
2673 Fake_glXSet3DfxModeMESA( int mode
)
2675 return XMesaSetFXmode( mode
);
2680 /*** GLX_NV_vertex_array range ***/
2682 Fake_glXAllocateMemoryNV( GLsizei size
,
2683 GLfloat readFrequency
,
2684 GLfloat writeFrequency
,
2688 (void) readFrequency
;
2689 (void) writeFrequency
;
2696 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2702 /*** GLX_MESA_agp_offset ***/
2705 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
2712 /* silence warning */
2713 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2717 * Create a new GLX API dispatch table with its function pointers
2718 * initialized to point to Mesa's "fake" GLX API functions.
2719 * Note: there's a similar function (_real_GetGLXDispatchTable) that
2720 * returns a new dispatch table with all pointers initalized to point
2721 * to "real" GLX functions (which understand GLX wire protocol, etc).
2723 struct _glxapi_table
*
2724 _mesa_GetGLXDispatchTable(void)
2726 static struct _glxapi_table glx
;
2728 /* be sure our dispatch table size <= libGL's table */
2730 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2732 assert(_glxapi_get_dispatch_table_size() >= size
);
2735 /* initialize the whole table to no-ops */
2736 _glxapi_set_no_op_table(&glx
);
2738 /* now initialize the table with the functions I implement */
2739 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2740 glx
.CopyContext
= Fake_glXCopyContext
;
2741 glx
.CreateContext
= Fake_glXCreateContext
;
2742 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2743 glx
.DestroyContext
= Fake_glXDestroyContext
;
2744 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2745 glx
.GetConfig
= Fake_glXGetConfig
;
2746 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2747 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2748 glx
.IsDirect
= Fake_glXIsDirect
;
2749 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2750 glx
.QueryExtension
= Fake_glXQueryExtension
;
2751 glx
.QueryVersion
= Fake_glXQueryVersion
;
2752 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2753 glx
.UseXFont
= Fake_glXUseXFont
;
2754 glx
.WaitGL
= Fake_glXWaitGL
;
2755 glx
.WaitX
= Fake_glXWaitX
;
2757 /*** GLX_VERSION_1_1 ***/
2758 glx
.GetClientString
= Fake_glXGetClientString
;
2759 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2760 glx
.QueryServerString
= Fake_glXQueryServerString
;
2762 /*** GLX_VERSION_1_2 ***/
2763 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2765 /*** GLX_VERSION_1_3 ***/
2766 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2767 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2768 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2769 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2770 glx
.CreateWindow
= Fake_glXCreateWindow
;
2771 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2772 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2773 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2774 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2775 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2776 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2777 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2778 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2779 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2780 glx
.QueryContext
= Fake_glXQueryContext
;
2781 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2782 glx
.SelectEvent
= Fake_glXSelectEvent
;
2784 /*** GLX_SGI_swap_control ***/
2785 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2787 /*** GLX_SGI_video_sync ***/
2788 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2789 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2791 /*** GLX_SGI_make_current_read ***/
2792 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2793 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2795 /*** GLX_SGIX_video_source ***/
2797 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2798 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2801 /*** GLX_EXT_import_context ***/
2802 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2803 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2804 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2805 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2806 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2808 /*** GLX_SGIX_fbconfig ***/
2809 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2810 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2811 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2812 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
2813 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
2814 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
2816 /*** GLX_SGIX_pbuffer ***/
2817 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
2818 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
2819 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
2820 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
2821 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
2823 /*** GLX_SGI_cushion ***/
2824 glx
.CushionSGI
= Fake_glXCushionSGI
;
2826 /*** GLX_SGIX_video_resize ***/
2827 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
2828 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
2829 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
2830 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
2831 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
2833 /*** GLX_SGIX_dmbuffer **/
2834 #if defined(_DM_BUFFER_H_)
2835 glx
.AssociateDMPbufferSGIX
= NULL
;
2838 /*** GLX_SGIX_swap_group ***/
2839 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
2841 /*** GLX_SGIX_swap_barrier ***/
2842 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
2843 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
2845 /*** GLX_SUN_get_transparent_index ***/
2846 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
2848 /*** GLX_MESA_copy_sub_buffer ***/
2849 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
2851 /*** GLX_MESA_release_buffers ***/
2852 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
2854 /*** GLX_MESA_pixmap_colormap ***/
2855 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
2857 /*** GLX_MESA_set_3dfx_mode ***/
2858 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
2860 /*** GLX_NV_vertex_array_range ***/
2861 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
2862 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
2864 /*** GLX_MESA_agp_offset ***/
2865 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;