2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. 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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
29 * to run on X servers which do not have the real GLX extension.
31 * Thanks to the contributors:
33 * Initial version: Philip Brown (phil@bolthole.com)
34 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
35 * Further visual-handling refinements: Wolfram Gloger
36 * (wmglo@Dent.MED.Uni-Muenchen.DE).
39 * Don't be fooled, stereo isn't supported yet.
45 #include "glxheader.h"
47 #include "main/context.h"
48 #include "main/config.h"
49 #include "main/macros.h"
50 #include "main/imports.h"
51 #include "main/mtypes.h"
52 #include "main/version.h"
55 #include "util/u_math.h"
57 /* This indicates the client-side GLX API and GLX encoder version. */
58 #define CLIENT_MAJOR_VERSION 1
59 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
61 /* This indicates the server-side GLX decoder version.
62 * GLX 1.4 indicates OpenGL 1.3 support
64 #define SERVER_MAJOR_VERSION 1
65 #define SERVER_MINOR_VERSION 4
67 /* This is appended onto the glXGetClient/ServerString version strings. */
68 #define MESA_GLX_VERSION "Mesa " PACKAGE_VERSION
70 /* Who implemented this GLX? */
71 #define VENDOR "Brian Paul"
74 "GLX_MESA_set_3dfx_mode " \
75 "GLX_MESA_copy_sub_buffer " \
76 "GLX_MESA_pixmap_colormap " \
77 "GLX_MESA_release_buffers " \
78 "GLX_ARB_create_context " \
79 "GLX_ARB_get_proc_address " \
80 "GLX_EXT_texture_from_pixmap " \
81 "GLX_EXT_visual_info " \
82 "GLX_EXT_visual_rating " \
83 /*"GLX_SGI_video_sync "*/ \
84 "GLX_SGIX_fbconfig " \
89 /**********************************************************************/
90 /*** GLX Visual Code ***/
91 /**********************************************************************/
96 static XMesaVisual
*VisualTable
= NULL
;
97 static int NumVisuals
= 0;
101 * This struct and some code fragments borrowed
102 * from Mark Kilgard's GLUT library.
104 typedef struct _OverlayInfo
{
105 /* Avoid 64-bit portability problems by being careful to use
106 longs due to the way XGetWindowProperty is specified. Note
107 that these parameters are passed as CARD32s over X
109 unsigned long overlay_visual
;
110 long transparent_type
;
117 /* Macro to handle c_class vs class field name in XVisualInfo struct */
118 #if defined(__cplusplus) || defined(c_plusplus)
119 #define CLASS c_class
127 * Test if the given XVisualInfo is usable for Mesa rendering.
130 is_usable_visual( XVisualInfo
*vinfo
)
132 switch (vinfo
->CLASS
) {
135 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
139 /* Color-index rendering is not supported. */
143 /* Any depth of TrueColor or DirectColor works in RGB mode */
146 /* This should never happen */
154 * Get an array OverlayInfo records for specified screen.
155 * \param dpy the display
156 * \param screen screen number
157 * \param numOverlays returns numver of OverlayInfo records
158 * \return pointer to OverlayInfo array, free with XFree()
161 GetOverlayInfo(Display
*dpy
, int screen
, int *numOverlays
)
163 Atom overlayVisualsAtom
;
166 unsigned char *ovInfo
;
167 unsigned long sizeData
, bytesLeft
;
171 * The SERVER_OVERLAY_VISUALS property on the root window contains
172 * a list of overlay visuals. Get that list now.
174 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
175 if (overlayVisualsAtom
== None
) {
179 status
= XGetWindowProperty(dpy
, RootWindow(dpy
, screen
),
180 overlayVisualsAtom
, 0L, (long) 10000, False
,
181 overlayVisualsAtom
, &actualType
, &actualFormat
,
182 &sizeData
, &bytesLeft
,
185 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
186 actualFormat
!= 32 || sizeData
< 4) {
187 /* something went wrong */
188 free((void *) ovInfo
);
193 *numOverlays
= sizeData
/ 4;
194 return (OverlayInfo
*) ovInfo
;
200 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
201 * Input: dpy - the X display
202 * vinfo - the XVisualInfo to test
203 * Return: level of the visual:
205 * >0 = overlay planes
206 * <0 = underlay planes
209 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
211 OverlayInfo
*overlay_info
;
212 int numOverlaysPerScreen
, i
;
214 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
219 /* search the overlay visual list for the visual ID of interest */
220 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
221 const OverlayInfo
*ov
= overlay_info
+ i
;
222 if (ov
->overlay_visual
== vinfo
->visualid
) {
223 /* found the visual */
224 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
225 int level
= ov
->layer
;
226 free((void *) overlay_info
);
230 free((void *) overlay_info
);
236 /* The visual ID was not found in the overlay list. */
237 free((void *) overlay_info
);
245 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
246 * configuration in our list of GLX visuals.
249 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
250 GLboolean alphaFlag
, GLboolean dbFlag
,
251 GLboolean stereoFlag
,
252 GLint depth_size
, GLint stencil_size
,
253 GLint accumRedSize
, GLint accumGreenSize
,
254 GLint accumBlueSize
, GLint accumAlphaSize
,
255 GLint level
, GLint numAuxBuffers
)
257 GLboolean ximageFlag
= GL_TRUE
;
262 /* Check if the MESA_BACK_BUFFER env var is set */
263 char *backbuffer
= getenv("MESA_BACK_BUFFER");
265 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
266 ximageFlag
= GL_FALSE
;
268 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
269 ximageFlag
= GL_TRUE
;
272 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
278 /* stereo not supported */
283 /* Force the visual to have an alpha channel */
284 if (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
.doubleBufferMode
== dbFlag
295 && v
->mesa_visual
.stereoMode
== stereoFlag
296 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
297 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
298 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
299 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
300 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
301 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
302 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
303 /* now compare visual IDs */
304 if (v
->visinfo
->visualid
== vinfo
->visualid
) {
310 /* Create a new visual and add it to the list. */
312 xmvis
= XMesaCreateVisual( dpy
, vinfo
, GL_TRUE
, alphaFlag
, dbFlag
,
313 stereoFlag
, ximageFlag
,
314 depth_size
, stencil_size
,
315 accumRedSize
, accumBlueSize
,
316 accumBlueSize
, accumAlphaSize
, 0, level
,
319 /* Allocate more space for additional visual */
320 VisualTable
= realloc(VisualTable
, sizeof(XMesaVisual
) * (NumVisuals
+ 1));
321 /* add xmvis to the list */
322 VisualTable
[NumVisuals
] = xmvis
;
324 /* XXX minor hack, because XMesaCreateVisual doesn't support an
325 * aux buffers parameter.
327 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
334 * Return the default number of bits for the Z buffer.
335 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
336 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
337 * XXX probably do the same thing for stencil, accum, etc.
340 default_depth_bits(void)
343 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
347 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
352 default_alpha_bits(void)
355 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
364 default_accum_bits(void)
372 * Create a GLX visual from a regular XVisualInfo.
373 * This is called when Fake GLX is given an XVisualInfo which wasn't
374 * returned by glXChooseVisual. Since this is the first time we're
375 * considering this visual we'll take a guess at reasonable values
376 * for depth buffer size, stencil size, accum size, etc.
377 * This is the best we can do with a client-side emulation of GLX.
380 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
383 GLint zBits
= default_depth_bits();
384 GLint accBits
= default_accum_bits();
385 GLboolean alphaFlag
= default_alpha_bits() > 0;
387 vislevel
= level_of_visual( dpy
, visinfo
);
389 /* Color-index rendering to overlays is not supported. */
392 else if (is_usable_visual( visinfo
)) {
393 /* Configure this visual as RGB, double-buffered, depth-buffered. */
394 /* This is surely wrong for some people's needs but what else */
395 /* can be done? They should use glXChooseVisual(). */
396 return save_glx_visual( dpy
, visinfo
,
397 alphaFlag
, /* alpha */
398 GL_TRUE
, /* double */
399 GL_FALSE
, /* stereo */
401 8, /* stencil bits */
411 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
419 * Find the GLX visual associated with an XVisualInfo.
422 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
426 /* try to match visual id */
427 for (i
=0;i
<NumVisuals
;i
++) {
428 if (VisualTable
[i
]->display
==dpy
429 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
430 return VisualTable
[i
];
440 * Return the transparent pixel value for a GLX visual.
441 * Input: glxvis - the glx_visual
442 * Return: a pixel value or -1 if no transparent pixel
445 transparent_pixel( XMesaVisual glxvis
)
447 Display
*dpy
= glxvis
->display
;
448 XVisualInfo
*vinfo
= glxvis
->visinfo
;
449 OverlayInfo
*overlay_info
;
450 int numOverlaysPerScreen
, i
;
452 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
457 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
458 const OverlayInfo
*ov
= overlay_info
+ i
;
459 if (ov
->overlay_visual
== vinfo
->visualid
) {
461 if (ov
->transparent_type
== 0) {
462 /* type 0 indicates no transparency */
463 free((void *) overlay_info
);
467 /* ov->value is the transparent pixel */
468 free((void *) overlay_info
);
474 /* The visual ID was not found in the overlay list. */
475 free((void *) overlay_info
);
482 * Try to get an X visual which matches the given arguments.
485 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
487 XVisualInfo temp
, *vis
;
490 unsigned int default_depth
;
493 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
498 default_depth
= DefaultDepth(dpy
,scr
);
499 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
501 if (depth
==default_depth
&& xclass
==default_class
) {
502 /* try to get root window's visual */
503 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
504 mask
|= VisualIDMask
;
507 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
509 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
510 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
511 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
513 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
514 if (util_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
515 util_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
516 util_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
531 * Retrieve the value of the given environment variable and find
532 * the X visual which matches it.
533 * Input: dpy - the display
534 * screen - the screen number
535 * varname - the name of the environment variable
536 * Return: an XVisualInfo pointer to NULL if error.
539 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
541 char value
[100], type
[100];
542 int depth
, xclass
= -1;
545 if (!getenv( varname
)) {
549 strncpy( value
, getenv(varname
), 100 );
552 sscanf( value
, "%s %d", type
, &depth
);
554 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
555 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
556 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
557 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
559 if (xclass
>-1 && depth
>0) {
560 vis
= get_visual( dpy
, scr
, depth
, xclass
);
566 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
575 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
576 * Input: dpy, screen - X display and screen number
577 * min_depth - minimum visual depth
578 * preferred_class - preferred GLX visual class or DONT_CARE
579 * Return: pointer to an XVisualInfo or NULL.
582 choose_x_visual(Display
*dpy
, int screen
, int min_depth
, int preferred_class
)
585 int xclass
, visclass
= 0;
588 /* First see if the MESA_RGB_VISUAL env var is defined */
589 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
593 /* Otherwise, search for a suitable visual */
594 if (preferred_class
==DONT_CARE
) {
595 for (xclass
=0;xclass
<4;xclass
++) {
597 case 0: visclass
= TrueColor
; break;
598 case 1: visclass
= DirectColor
; break;
599 case 2: visclass
= GrayScale
; break;
600 case 3: visclass
= StaticGray
; break;
603 /* start with shallowest */
604 for (depth
=0;depth
<=32;depth
++) {
605 vis
= get_visual( dpy
, screen
, depth
, visclass
);
612 /* start with deepest */
613 for (depth
=32;depth
>=min_depth
;depth
--) {
614 vis
= get_visual( dpy
, screen
, depth
, visclass
);
623 /* search for a specific visual class */
624 switch (preferred_class
) {
625 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
626 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
627 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
628 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
629 case GLX_PSEUDO_COLOR_EXT
:
630 case GLX_STATIC_COLOR_EXT
:
631 default: return NULL
;
634 /* start with shallowest */
635 for (depth
=0;depth
<=32;depth
++) {
636 vis
= get_visual( dpy
, screen
, depth
, visclass
);
643 /* start with deepest */
644 for (depth
=32;depth
>=min_depth
;depth
--) {
645 vis
= get_visual( dpy
, screen
, depth
, visclass
);
653 /* didn't find a visual */
660 * Find the deepest X over/underlay visual of at least min_depth.
661 * Input: dpy, screen - X display and screen number
662 * level - the over/underlay level
663 * trans_type - transparent pixel type: GLX_NONE_EXT,
664 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
666 * trans_value - transparent pixel value or DONT_CARE
667 * min_depth - minimum visual depth
668 * preferred_class - preferred GLX visual class or DONT_CARE
669 * Return: pointer to an XVisualInfo or NULL.
672 choose_x_overlay_visual( Display
*dpy
, int scr
,
673 int level
, int trans_type
, int trans_value
,
674 int min_depth
, int preferred_class
)
676 OverlayInfo
*overlay_info
;
677 int numOverlaysPerScreen
;
679 XVisualInfo
*deepvis
;
682 /*DEBUG int tt, tv; */
684 switch (preferred_class
) {
685 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
686 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
687 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
688 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
689 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
690 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
691 default: preferred_class
= DONT_CARE
;
694 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
699 /* Search for the deepest overlay which satisifies all criteria. */
703 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
704 const OverlayInfo
*ov
= overlay_info
+ i
;
705 XVisualInfo
*vislist
, vistemplate
;
708 if (ov
->layer
!=level
) {
709 /* failed overlay level criteria */
712 if (!(trans_type
==DONT_CARE
713 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
714 && ov
->transparent_type
>0)
715 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
716 /* failed transparent pixel type criteria */
719 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
720 /* failed transparent pixel value criteria */
724 /* get XVisualInfo and check the depth */
725 vistemplate
.visualid
= ov
->overlay_visual
;
726 vistemplate
.screen
= scr
;
727 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
728 &vistemplate
, &count
);
736 /* something went wrong */
740 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
741 /* wrong visual class */
746 /* Color-index rendering is not supported. Make sure we have True/DirectColor */
747 if (vislist
->CLASS
!= TrueColor
&& vislist
->CLASS
!= DirectColor
) {
752 if (deepvis
!=NULL
&& vislist
->depth
<= deepest
) {
757 /* YES! found a satisfactory visual */
759 deepest
= vislist
->depth
;
761 /* DEBUG tt = ov->transparent_type;*/
762 /* DEBUG tv = ov->value; */
767 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
768 deepvis->visualid, level, deepvis->depth, tt, tv );
775 /**********************************************************************/
776 /*** Display-related functions ***/
777 /**********************************************************************/
781 * Free all XMesaVisuals which are associated with the given display.
784 destroy_visuals_on_display(Display
*dpy
)
787 for (i
= 0; i
< NumVisuals
; i
++) {
788 if (VisualTable
[i
]->display
== dpy
) {
789 /* remove this visual */
791 XMesaDestroyVisual(VisualTable
[i
]);
792 for (j
= i
; j
< NumVisuals
- 1; j
++)
793 VisualTable
[j
] = VisualTable
[j
+ 1];
801 * Called from XCloseDisplay() to let us free our display-related data.
804 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
806 destroy_visuals_on_display(dpy
);
807 xmesa_destroy_buffers_on_display(dpy
);
813 * Look for the named extension on given display and return a pointer
814 * to the _XExtension data, or NULL if extension not found.
817 lookup_extension(Display
*dpy
, const char *extName
)
820 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
821 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
830 * Whenever we're given a new Display pointer, call this function to
831 * register our close_display_callback function.
834 register_with_display(Display
*dpy
)
836 const char *extName
= "MesaGLX";
839 ext
= lookup_extension(dpy
, extName
);
841 XExtCodes
*c
= XAddExtension(dpy
);
842 ext
= dpy
->ext_procs
; /* new extension is at head of list */
843 assert(c
->extension
== ext
->codes
.extension
);
844 (void) c
; /* silence warning */
845 ext
->name
= strdup(extName
);
846 ext
->close_display
= close_display_callback
;
851 /**********************************************************************/
852 /*** Begin Fake GLX API Functions ***/
853 /**********************************************************************/
857 * Helper used by glXChooseVisual and glXChooseFBConfig.
858 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
860 * In either case, the attribute list is terminated with the value 'None'.
863 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
865 const GLboolean rgbModeDefault
= fbConfig
;
866 const int *parselist
;
869 int min_red
=0, min_green
=0, min_blue
=0;
870 GLboolean rgb_flag
= rgbModeDefault
;
871 GLboolean alpha_flag
= GL_FALSE
;
872 GLboolean double_flag
= GL_FALSE
;
873 GLboolean stereo_flag
= GL_FALSE
;
874 GLint depth_size
= 0;
875 GLint stencil_size
= 0;
876 GLint accumRedSize
= 0;
877 GLint accumGreenSize
= 0;
878 GLint accumBlueSize
= 0;
879 GLint accumAlphaSize
= 0;
881 int visual_type
= DONT_CARE
;
882 int trans_type
= DONT_CARE
;
883 int trans_value
= DONT_CARE
;
884 GLint caveat
= DONT_CARE
;
885 XMesaVisual xmvis
= NULL
;
886 int desiredVisualID
= -1;
894 parselist
[1] == GLX_DONT_CARE
&&
895 parselist
[0] != GLX_LEVEL
) {
896 /* For glXChooseFBConfig(), skip attributes whose value is
897 * GLX_DONT_CARE (-1), unless it's GLX_LEVEL (which can legitimately be
900 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
901 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
907 switch (*parselist
) {
918 case GLX_BUFFER_SIZE
:
920 min_ci
= *parselist
++;
924 level
= *parselist
++;
936 case GLX_DOUBLEBUFFER
:
939 double_flag
= *parselist
++;
942 double_flag
= GL_TRUE
;
948 stereo_flag
= *parselist
++;
951 stereo_flag
= GL_TRUE
;
954 case GLX_AUX_BUFFERS
:
956 numAux
= *parselist
++;
957 if (numAux
> MAX_AUX_BUFFERS
)
962 min_red
= *parselist
++;
966 min_green
= *parselist
++;
970 min_blue
= *parselist
++;
975 GLint size
= *parselist
++;
976 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
981 depth_size
= *parselist
++;
983 case GLX_STENCIL_SIZE
:
985 stencil_size
= *parselist
++;
987 case GLX_ACCUM_RED_SIZE
:
990 GLint size
= *parselist
++;
991 accumRedSize
= MAX2( accumRedSize
, size
);
994 case GLX_ACCUM_GREEN_SIZE
:
997 GLint size
= *parselist
++;
998 accumGreenSize
= MAX2( accumGreenSize
, size
);
1001 case GLX_ACCUM_BLUE_SIZE
:
1004 GLint size
= *parselist
++;
1005 accumBlueSize
= MAX2( accumBlueSize
, size
);
1008 case GLX_ACCUM_ALPHA_SIZE
:
1011 GLint size
= *parselist
++;
1012 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1017 * GLX_EXT_visual_info extension
1019 case GLX_X_VISUAL_TYPE_EXT
:
1021 visual_type
= *parselist
++;
1023 case GLX_TRANSPARENT_TYPE_EXT
:
1025 trans_type
= *parselist
++;
1027 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1029 trans_value
= *parselist
++;
1031 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1032 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1033 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1034 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1041 * GLX_EXT_visual_info extension
1043 case GLX_VISUAL_CAVEAT_EXT
:
1045 caveat
= *parselist
++; /* ignored for now */
1049 * GLX_ARB_multisample
1051 case GLX_SAMPLE_BUFFERS_ARB
:
1052 case GLX_SAMPLES_ARB
:
1054 if (*parselist
++ != 0)
1055 /* ms not supported */
1062 case GLX_RENDER_TYPE
:
1066 if (*parselist
& GLX_RGBA_BIT
) {
1069 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
1070 rgb_flag
= GL_FALSE
;
1072 else if (*parselist
& (GLX_RGBA_FLOAT_BIT_ARB
|GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
)) {
1075 else if (*parselist
== 0) {
1080 case GLX_DRAWABLE_TYPE
:
1084 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1085 return NULL
; /* bad bit */
1089 case GLX_FBCONFIG_ID
:
1094 desiredVisualID
= *parselist
++;
1096 case GLX_X_RENDERABLE
:
1097 case GLX_MAX_PBUFFER_WIDTH
:
1098 case GLX_MAX_PBUFFER_HEIGHT
:
1099 case GLX_MAX_PBUFFER_PIXELS
:
1106 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1107 parselist
++; /*skip*/
1109 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1110 parselist
++; /*skip*/
1112 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1113 parselist
++; /*skip*/
1115 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1117 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1118 GLX_TEXTURE_2D_BIT_EXT
|
1119 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1124 case GLX_Y_INVERTED_EXT
:
1125 parselist
++; /*skip*/
1133 /* undefined attribute */
1134 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1147 * Since we're only simulating the GLX extension this function will never
1148 * find any real GL visuals. Instead, all we can do is try to find an RGB
1149 * or CI visual of appropriate depth. Other requested attributes such as
1150 * double buffering, depth buffer, etc. will be associated with the X
1151 * visual and stored in the VisualTable[].
1153 if (desiredVisualID
!= -1) {
1154 /* try to get a specific visual, by visualID */
1157 temp
.visualid
= desiredVisualID
;
1158 temp
.screen
= screen
;
1159 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1161 /* give the visual some useful GLX attributes */
1162 double_flag
= GL_TRUE
;
1163 if (vis
->depth
<= 8)
1165 depth_size
= default_depth_bits();
1172 int min_rgb
= min_red
+ min_green
+ min_blue
;
1173 if (min_rgb
>1 && min_rgb
<8) {
1174 /* a special case to be sure we can get a monochrome visual */
1179 vis
= choose_x_visual(dpy
, screen
, min_rgb
, visual_type
);
1182 vis
= choose_x_overlay_visual(dpy
, screen
, level
,
1183 trans_type
, trans_value
, min_rgb
, visual_type
);
1188 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1189 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1190 * largest depth buffer size, which is 32bits/value. Instead, we
1191 * return 16 to maintain performance with earlier versions of Mesa.
1193 if (depth_size
> 24)
1195 else if (depth_size
> 16)
1197 else if (depth_size
> 0) {
1198 depth_size
= default_depth_bits();
1202 alpha_flag
= default_alpha_bits() > 0;
1205 /* we only support one size of stencil and accum buffers. */
1206 if (stencil_size
> 0)
1208 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1209 accumAlphaSize
> 0) {
1212 accumBlueSize
= default_accum_bits();
1213 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1216 xmvis
= save_glx_visual( dpy
, vis
, alpha_flag
, double_flag
,
1217 stereo_flag
, depth_size
, stencil_size
,
1218 accumRedSize
, accumGreenSize
,
1219 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1227 static XVisualInfo
*
1228 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1232 /* register ourselves as an extension on this display */
1233 register_with_display(dpy
);
1235 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1237 XVisualInfo
* visinfo
= malloc(sizeof(XVisualInfo
));
1239 memcpy(visinfo
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1249 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1250 GLXContext share_list
, Bool direct
)
1253 XMesaContext xmesaCtx
;
1255 if (!dpy
|| !visinfo
)
1258 /* deallocate unused windows/buffers */
1260 XMesaGarbageCollect(dpy
);
1263 xmvis
= find_glx_visual( dpy
, visinfo
);
1265 /* This visual wasn't found with glXChooseVisual() */
1266 xmvis
= create_glx_visual( dpy
, visinfo
);
1272 xmesaCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) share_list
);
1274 return (GLXContext
) xmesaCtx
;
1278 /* XXX these may have to be removed due to thread-safety issues. */
1279 static GLXContext MakeCurrent_PrevContext
= 0;
1280 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1281 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1282 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1283 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1286 /* GLX 1.3 and later */
1288 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1289 GLXDrawable read
, GLXContext ctx
)
1291 if (ctx
&& draw
&& read
) {
1292 XMesaBuffer drawBuffer
, readBuffer
;
1293 XMesaContext xmctx
= (XMesaContext
) ctx
;
1295 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1296 if (ctx
== MakeCurrent_PrevContext
1297 && draw
== MakeCurrent_PrevDrawable
) {
1298 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1301 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1304 /* drawable must be a new window! */
1305 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1307 /* Out of memory, or context/drawable depth mismatch */
1312 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1313 if (ctx
== MakeCurrent_PrevContext
1314 && read
== MakeCurrent_PrevReadable
) {
1315 readBuffer
= MakeCurrent_PrevReadBuffer
;
1318 readBuffer
= XMesaFindBuffer( dpy
, read
);
1321 /* drawable must be a new window! */
1322 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1324 /* Out of memory, or context/drawable depth mismatch */
1329 MakeCurrent_PrevContext
= ctx
;
1330 MakeCurrent_PrevDrawable
= draw
;
1331 MakeCurrent_PrevReadable
= read
;
1332 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1333 MakeCurrent_PrevReadBuffer
= readBuffer
;
1335 /* Now make current! */
1336 return XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
);
1338 else if (!ctx
&& !draw
&& !read
) {
1339 /* release current context w/out assigning new one. */
1340 XMesaMakeCurrent( NULL
, NULL
);
1341 MakeCurrent_PrevContext
= 0;
1342 MakeCurrent_PrevDrawable
= 0;
1343 MakeCurrent_PrevReadable
= 0;
1344 MakeCurrent_PrevDrawBuffer
= 0;
1345 MakeCurrent_PrevReadBuffer
= 0;
1349 /* The args must either all be non-zero or all zero.
1358 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1360 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1365 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1370 v
= find_glx_visual( dpy
, visinfo
);
1372 v
= create_glx_visual( dpy
, visinfo
);
1374 /* unusable visual */
1379 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1383 return b
->frontxrb
->pixmap
;
1387 /*** GLX_MESA_pixmap_colormap ***/
1390 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1391 Pixmap pixmap
, Colormap cmap
)
1396 v
= find_glx_visual( dpy
, visinfo
);
1398 v
= create_glx_visual( dpy
, visinfo
);
1400 /* unusable visual */
1405 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1409 return b
->frontxrb
->pixmap
;
1414 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1416 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1418 XMesaDestroyBuffer(b
);
1420 else if (getenv("MESA_DEBUG")) {
1421 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1427 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1428 unsigned long mask
)
1430 XMesaContext xmSrc
= (XMesaContext
) src
;
1431 XMesaContext xmDst
= (XMesaContext
) dst
;
1433 if (MakeCurrent_PrevContext
== src
) {
1436 _mesa_copy_context( &xmSrc
->mesa
, &xmDst
->mesa
, (GLuint
) mask
);
1441 Fake_glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1444 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1445 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1451 return True
; /* we're faking GLX so always return success */
1455 extern void _kw_ungrab_all( Display
*dpy
);
1456 void _kw_ungrab_all( Display
*dpy
)
1458 XUngrabPointer( dpy
, CurrentTime
);
1459 XUngrabKeyboard( dpy
, CurrentTime
);
1464 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1468 MakeCurrent_PrevContext
= 0;
1469 MakeCurrent_PrevDrawable
= 0;
1470 MakeCurrent_PrevReadable
= 0;
1471 MakeCurrent_PrevDrawBuffer
= 0;
1472 MakeCurrent_PrevReadBuffer
= 0;
1473 XMesaDestroyContext((XMesaContext
) ctx
);
1474 XMesaGarbageCollect(dpy
);
1480 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1482 XMesaContext xmCtx
= (XMesaContext
) ctx
;
1483 return xmCtx
? xmCtx
->direct
: False
;
1489 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1491 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1494 XMesaSwapBuffers(buffer
);
1496 else if (getenv("MESA_DEBUG")) {
1497 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1504 /*** GLX_MESA_copy_sub_buffer ***/
1507 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1508 int x
, int y
, int width
, int height
)
1510 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1512 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1514 else if (getenv("MESA_DEBUG")) {
1515 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1521 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1524 /* Return GLX version, not Mesa version */
1525 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1526 *maj
= CLIENT_MAJOR_VERSION
;
1527 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1533 * Query the GLX attributes of the given XVisualInfo.
1536 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1542 return GLX_BAD_ATTRIBUTE
;
1543 *value
= (int) True
;
1545 case GLX_BUFFER_SIZE
:
1546 *value
= xmvis
->visinfo
->depth
;
1549 *value
= xmvis
->mesa_visual
.level
;
1553 return GLX_BAD_ATTRIBUTE
;
1554 if (xmvis
->mesa_visual
.rgbMode
) {
1561 case GLX_DOUBLEBUFFER
:
1562 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1565 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1567 case GLX_AUX_BUFFERS
:
1568 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1571 *value
= xmvis
->mesa_visual
.redBits
;
1573 case GLX_GREEN_SIZE
:
1574 *value
= xmvis
->mesa_visual
.greenBits
;
1577 *value
= xmvis
->mesa_visual
.blueBits
;
1579 case GLX_ALPHA_SIZE
:
1580 *value
= xmvis
->mesa_visual
.alphaBits
;
1582 case GLX_DEPTH_SIZE
:
1583 *value
= xmvis
->mesa_visual
.depthBits
;
1585 case GLX_STENCIL_SIZE
:
1586 *value
= xmvis
->mesa_visual
.stencilBits
;
1588 case GLX_ACCUM_RED_SIZE
:
1589 *value
= xmvis
->mesa_visual
.accumRedBits
;
1591 case GLX_ACCUM_GREEN_SIZE
:
1592 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1594 case GLX_ACCUM_BLUE_SIZE
:
1595 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1597 case GLX_ACCUM_ALPHA_SIZE
:
1598 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1602 * GLX_EXT_visual_info extension
1604 case GLX_X_VISUAL_TYPE_EXT
:
1605 switch (xmvis
->visinfo
->CLASS
) {
1606 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1607 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1608 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1609 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1610 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1611 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1614 case GLX_TRANSPARENT_TYPE_EXT
:
1615 if (xmvis
->mesa_visual
.level
==0) {
1617 *value
= GLX_NONE_EXT
;
1619 else if (xmvis
->mesa_visual
.level
>0) {
1621 if (xmvis
->mesa_visual
.rgbMode
) {
1622 *value
= GLX_TRANSPARENT_RGB_EXT
;
1625 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1628 else if (xmvis
->mesa_visual
.level
<0) {
1630 *value
= GLX_NONE_EXT
;
1633 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1635 int pixel
= transparent_pixel( xmvis
);
1639 /* else undefined */
1642 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1645 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1648 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1651 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1656 * GLX_EXT_visual_info extension
1658 case GLX_VISUAL_CAVEAT_EXT
:
1659 /* test for zero, just in case */
1660 if (xmvis
->mesa_visual
.visualRating
> 0)
1661 *value
= xmvis
->mesa_visual
.visualRating
;
1663 *value
= GLX_NONE_EXT
;
1667 * GLX_ARB_multisample
1669 case GLX_SAMPLE_BUFFERS_ARB
:
1672 case GLX_SAMPLES_ARB
:
1679 case GLX_SCREEN_EXT
:
1681 return GLX_BAD_ATTRIBUTE
;
1682 *value
= xmvis
->visinfo
->screen
;
1684 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1686 return GLX_BAD_ATTRIBUTE
;
1687 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1689 case GLX_RENDER_TYPE_SGIX
:
1691 return GLX_BAD_ATTRIBUTE
;
1692 if (xmvis
->mesa_visual
.floatMode
)
1693 *value
= GLX_RGBA_FLOAT_BIT_ARB
;
1694 else if (xmvis
->mesa_visual
.rgbMode
)
1695 *value
= GLX_RGBA_BIT
;
1697 *value
= GLX_COLOR_INDEX_BIT
;
1699 case GLX_X_RENDERABLE_SGIX
:
1701 return GLX_BAD_ATTRIBUTE
;
1702 *value
= True
; /* XXX really? */
1704 case GLX_FBCONFIG_ID_SGIX
:
1706 return GLX_BAD_ATTRIBUTE
;
1707 *value
= xmvis
->visinfo
->visualid
;
1709 case GLX_MAX_PBUFFER_WIDTH
:
1711 return GLX_BAD_ATTRIBUTE
;
1712 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1713 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1715 case GLX_MAX_PBUFFER_HEIGHT
:
1717 return GLX_BAD_ATTRIBUTE
;
1718 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1720 case GLX_MAX_PBUFFER_PIXELS
:
1722 return GLX_BAD_ATTRIBUTE
;
1723 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1724 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1728 return GLX_BAD_ATTRIBUTE
;
1729 *value
= xmvis
->visinfo
->visualid
;
1732 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1733 *value
= True
; /*XXX*/
1735 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1737 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1739 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1740 *value
= True
; /*XXX*/
1742 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1743 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1744 GLX_TEXTURE_2D_BIT_EXT
|
1745 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1747 case GLX_Y_INVERTED_EXT
:
1748 *value
= True
; /*XXX*/
1752 return GLX_BAD_ATTRIBUTE
;
1759 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1760 int attrib
, int *value
)
1764 if (!dpy
|| !visinfo
)
1765 return GLX_BAD_ATTRIBUTE
;
1767 xmvis
= find_glx_visual( dpy
, visinfo
);
1769 /* this visual wasn't obtained with glXChooseVisual */
1770 xmvis
= create_glx_visual( dpy
, visinfo
);
1772 /* this visual can't be used for GL rendering */
1773 if (attrib
==GLX_USE_GL
) {
1774 *value
= (int) False
;
1778 return GLX_BAD_VISUAL
;
1783 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1789 Fake_glXGetCurrentContext(void)
1791 XMesaContext xmesa
= XMesaGetCurrentContext();
1792 return (GLXContext
) xmesa
;
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 )
1815 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
1820 /* GLX 1.1 and later */
1822 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1826 return get_extensions();
1831 /* GLX 1.1 and later */
1833 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1835 static char version
[1000];
1836 sprintf(version
, "%d.%d %s",
1837 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1843 case GLX_EXTENSIONS
:
1844 return get_extensions();
1856 /* GLX 1.1 and later */
1858 Fake_glXGetClientString( Display
*dpy
, int name
)
1860 static char version
[1000];
1861 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1862 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1867 case GLX_EXTENSIONS
:
1868 return get_extensions();
1886 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1887 int attribute
, int *value
)
1889 XMesaVisual v
= (XMesaVisual
) config
;
1893 if (!dpy
|| !config
|| !value
)
1896 return get_config(v
, attribute
, value
, GL_TRUE
);
1900 static GLXFBConfig
*
1901 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1903 XVisualInfo
*visuals
, visTemplate
;
1904 const long visMask
= VisualScreenMask
;
1907 /* Get list of all X visuals */
1908 visTemplate
.screen
= screen
;
1909 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1910 if (*nelements
> 0) {
1911 XMesaVisual
*results
;
1912 results
= malloc(*nelements
* sizeof(XMesaVisual
));
1917 for (i
= 0; i
< *nelements
; i
++) {
1918 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1921 return (GLXFBConfig
*) results
;
1927 static GLXFBConfig
*
1928 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1929 const int *attribList
, int *nitems
)
1933 /* register ourselves as an extension on this display */
1934 register_with_display(dpy
);
1936 if (!attribList
|| !attribList
[0]) {
1937 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1938 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
1941 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1943 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1949 config
[0] = (GLXFBConfig
) xmvis
;
1950 return (GLXFBConfig
*) config
;
1959 static XVisualInfo
*
1960 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1962 if (dpy
&& config
) {
1963 XMesaVisual xmvis
= (XMesaVisual
) config
;
1964 XVisualInfo
* visinfo
= malloc(sizeof(XVisualInfo
));
1966 memcpy(visinfo
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1977 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1978 const int *attribList
)
1980 XMesaVisual xmvis
= (XMesaVisual
) config
;
1985 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
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
;
2014 int target
= 0, format
= 0, mipmap
= 0;
2017 if (!dpy
|| !config
|| !pixmap
)
2020 for (attr
= attribList
; attr
&& *attr
; attr
++) {
2022 case GLX_TEXTURE_FORMAT_EXT
:
2025 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2026 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2027 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2035 case GLX_TEXTURE_TARGET_EXT
:
2038 case GLX_TEXTURE_1D_EXT
:
2039 case GLX_TEXTURE_2D_EXT
:
2040 case GLX_TEXTURE_RECTANGLE_EXT
:
2048 case GLX_MIPMAP_TEXTURE_EXT
:
2059 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2060 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2061 &value
, GL_TRUE
) != Success
2063 return 0; /* error! */
2066 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2067 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2068 &value
, GL_TRUE
) != Success
2070 return 0; /* error! */
2074 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2075 &value
, GL_TRUE
) != Success
2077 return 0; /* error! */
2080 if (target
== GLX_TEXTURE_1D_EXT
) {
2081 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2082 &value
, GL_TRUE
) != Success
2083 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2084 return 0; /* error! */
2087 else if (target
== GLX_TEXTURE_2D_EXT
) {
2088 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2089 &value
, GL_TRUE
) != Success
2090 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2091 return 0; /* error! */
2094 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2095 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2096 &value
, GL_TRUE
) != Success
2097 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2098 return 0; /* error! */
2102 if (format
|| target
|| mipmap
) {
2103 /* texture from pixmap */
2104 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2107 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2118 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2120 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2122 XMesaDestroyBuffer(b
);
2123 /* don't destroy X pixmap */
2128 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2129 const int *attribList
)
2131 XMesaVisual xmvis
= (XMesaVisual
) config
;
2134 int width
= 0, height
= 0;
2135 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2139 for (attrib
= attribList
; *attrib
; attrib
++) {
2141 case GLX_PBUFFER_WIDTH
:
2145 case GLX_PBUFFER_HEIGHT
:
2149 case GLX_PRESERVED_CONTENTS
:
2151 preserveContents
= *attrib
;
2153 case GLX_LARGEST_PBUFFER
:
2155 useLargest
= *attrib
;
2162 if (width
== 0 || height
== 0)
2165 if (width
> SWRAST_MAX_WIDTH
|| height
> SWRAST_MAX_HEIGHT
) {
2166 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2167 * allocate the largest possible buffer.
2170 width
= SWRAST_MAX_WIDTH
;
2171 height
= SWRAST_MAX_HEIGHT
;
2175 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2176 /* A GLXPbuffer handle must be an X Drawable because that's what
2177 * glXMakeCurrent takes.
2180 xmbuf
->largestPbuffer
= useLargest
;
2181 xmbuf
->preservedContents
= preserveContents
;
2182 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2191 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2193 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2195 XMesaDestroyBuffer(b
);
2201 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2202 unsigned int *value
)
2204 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2208 /* make sure buffer's dimensions are up to date */
2209 xmesa_check_and_update_buffer_size(NULL
, xmbuf
);
2211 switch (attribute
) {
2213 *value
= xmbuf
->mesa_buffer
.Width
;
2216 *value
= xmbuf
->mesa_buffer
.Height
;
2218 case GLX_PRESERVED_CONTENTS
:
2219 *value
= xmbuf
->preservedContents
;
2221 case GLX_LARGEST_PBUFFER
:
2222 *value
= xmbuf
->largestPbuffer
;
2224 case GLX_FBCONFIG_ID
:
2225 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2227 case GLX_TEXTURE_FORMAT_EXT
:
2228 *value
= xmbuf
->TextureFormat
;
2230 case GLX_TEXTURE_TARGET_EXT
:
2231 *value
= xmbuf
->TextureTarget
;
2233 case GLX_MIPMAP_TEXTURE_EXT
:
2234 *value
= xmbuf
->TextureMipmap
;
2238 return; /* raise BadValue error */
2244 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2245 int renderType
, GLXContext shareList
, Bool direct
)
2248 XMesaVisual xmvis
= (XMesaVisual
) config
;
2250 if (!dpy
|| !config
||
2251 (renderType
!= GLX_RGBA_TYPE
&&
2252 renderType
!= GLX_COLOR_INDEX_TYPE
&&
2253 renderType
!= GLX_RGBA_FLOAT_TYPE_ARB
&&
2254 renderType
!= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
))
2257 /* deallocate unused windows/buffers */
2258 XMesaGarbageCollect(dpy
);
2260 xmCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) shareList
);
2262 return (GLXContext
) xmCtx
;
2267 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2269 XMesaContext xmctx
= (XMesaContext
) ctx
;
2273 switch (attribute
) {
2274 case GLX_FBCONFIG_ID
:
2275 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2277 case GLX_RENDER_TYPE
:
2278 *value
= GLX_RGBA_TYPE
;
2284 return GLX_BAD_ATTRIBUTE
;
2291 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2293 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2295 xmbuf
->selectedEvents
= mask
;
2300 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2301 unsigned long *mask
)
2303 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2305 *mask
= xmbuf
->selectedEvents
;
2312 /*** GLX_SGI_swap_control ***/
2315 Fake_glXSwapIntervalSGI(int interval
)
2323 /*** GLX_SGI_video_sync ***/
2325 static unsigned int FrameCounter
= 0;
2328 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2330 /* this is a bogus implementation */
2331 *count
= FrameCounter
++;
2336 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2338 if (divisor
<= 0 || remainder
< 0)
2339 return GLX_BAD_VALUE
;
2340 /* this is a bogus implementation */
2342 while (FrameCounter
% divisor
!= remainder
)
2344 *count
= FrameCounter
;
2350 /*** GLX_SGI_make_current_read ***/
2353 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2355 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2360 Fake_glXGetCurrentReadDrawableSGI(void)
2367 /*** GLX_SGIX_video_source ***/
2370 static GLXVideoSourceSGIX
2371 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2383 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2392 /*** GLX_EXT_import_context ***/
2395 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2402 Fake_glXGetContextIDEXT(const GLXContext context
)
2409 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2417 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2428 /*** GLX_SGIX_fbconfig ***/
2431 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2433 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2436 static GLXFBConfigSGIX
*
2437 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2439 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2444 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2446 XMesaVisual xmvis
= (XMesaVisual
) config
;
2447 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2448 return xmbuf
->frontxrb
->pixmap
; /* need to return an X ID */
2453 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2456 XMesaVisual xmvis
= (XMesaVisual
) config
;
2458 /* deallocate unused windows/buffers */
2459 XMesaGarbageCollect(dpy
);
2461 xmCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) share_list
);
2463 return (GLXContext
) xmCtx
;
2467 static XVisualInfo
*
2468 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2470 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2474 static GLXFBConfigSGIX
2475 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2477 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2479 /* This visual wasn't found with glXChooseVisual() */
2480 xmvis
= create_glx_visual(dpy
, vis
);
2483 return (GLXFBConfigSGIX
) xmvis
;
2488 /*** GLX_SGIX_pbuffer ***/
2490 static GLXPbufferSGIX
2491 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2492 unsigned int width
, unsigned int height
,
2495 XMesaVisual xmvis
= (XMesaVisual
) config
;
2498 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2502 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2504 case GLX_PRESERVED_CONTENTS_SGIX
:
2506 preserveContents
= *attrib
; /* ignored */
2508 case GLX_LARGEST_PBUFFER_SGIX
:
2510 useLargest
= *attrib
; /* ignored */
2517 /* not used at this time */
2519 (void) preserveContents
;
2521 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2522 /* A GLXPbuffer handle must be an X Drawable because that's what
2523 * glXMakeCurrent takes.
2525 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2530 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2532 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2534 XMesaDestroyBuffer(xmbuf
);
2540 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2542 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2545 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2549 switch (attribute
) {
2550 case GLX_PRESERVED_CONTENTS_SGIX
:
2551 *value
= xmbuf
->preservedContents
;
2553 case GLX_LARGEST_PBUFFER_SGIX
:
2554 *value
= xmbuf
->largestPbuffer
;
2556 case GLX_WIDTH_SGIX
:
2557 *value
= xmbuf
->mesa_buffer
.Width
;
2559 case GLX_HEIGHT_SGIX
:
2560 *value
= xmbuf
->mesa_buffer
.Height
;
2562 case GLX_EVENT_MASK_SGIX
:
2563 *value
= 0; /* XXX might be wrong */
2572 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2574 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2576 /* Note: we'll never generate clobber events */
2577 xmbuf
->selectedEvents
= mask
;
2583 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2585 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2587 *mask
= xmbuf
->selectedEvents
;
2596 /*** GLX_SGI_cushion ***/
2599 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2608 /*** GLX_SGIX_video_resize ***/
2611 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2621 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2634 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2647 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2660 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2671 /*** GLX_SGIX_dmbuffer **/
2673 #if defined(_DM_BUFFER_H_)
2675 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2686 /*** GLX_SUN_get_transparent_index ***/
2689 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, unsigned long *pTransparent
)
2694 (void) pTransparent
;
2700 /*** GLX_MESA_release_buffers ***/
2703 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2704 * (a window or pixmap) prior to destroying the GLXDrawable.
2707 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2709 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2711 XMesaDestroyBuffer(b
);
2719 /*** GLX_EXT_texture_from_pixmap ***/
2722 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2723 const int *attrib_list
)
2725 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2727 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2731 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2733 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2735 XMesaReleaseTexImage(dpy
, b
, buffer
);
2740 Fake_glXCreateContextAttribs(Display
*dpy
, GLXFBConfig config
,
2741 GLXContext share_context
, Bool direct
,
2742 const int *attrib_list
)
2745 XMesaVisual xmvis
= (XMesaVisual
) config
;
2747 int major
= 0, minor
= 0, ctxFlags
= 0, profileFlags
= 0;
2749 for (i
= 0; attrib_list
[i
]; i
+= 2) {
2750 switch (attrib_list
[i
]) {
2751 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2752 major
= attrib_list
[i
+ 1];
2754 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2755 minor
= attrib_list
[i
+ 1];
2757 case GLX_CONTEXT_FLAGS_ARB
:
2758 ctxFlags
= attrib_list
[i
+ 1];
2760 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2761 profileFlags
= attrib_list
[i
+ 1];
2764 _mesa_warning(NULL
, "Unexpected attribute 0x%x in "
2765 "glXCreateContextAttribs()\n", attrib_list
[i
]);
2770 if (major
* 10 + minor
> 21) {
2771 /* swrast only supports GL 2.1 and earlier */
2775 /* These are ignored for now. We'd have to enhance XMesaCreateContext
2776 * to take these flags and the version, at least.
2779 (void) profileFlags
;
2781 /* deallocate unused windows/buffers */
2782 XMesaGarbageCollect(dpy
);
2784 xmCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) share_context
);
2786 return (GLXContext
) xmCtx
;
2790 /* silence warning */
2791 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2795 * Create a new GLX API dispatch table with its function pointers
2796 * initialized to point to Mesa's "fake" GLX API functions.
2797 * Note: there's a similar function (_real_GetGLXDispatchTable) that
2798 * returns a new dispatch table with all pointers initalized to point
2799 * to "real" GLX functions (which understand GLX wire protocol, etc).
2801 struct _glxapi_table
*
2802 _mesa_GetGLXDispatchTable(void)
2804 static struct _glxapi_table glx
;
2806 /* be sure our dispatch table size <= libGL's table */
2808 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2810 assert(_glxapi_get_dispatch_table_size() >= size
);
2813 /* initialize the whole table to no-ops */
2814 _glxapi_set_no_op_table(&glx
);
2816 /* now initialize the table with the functions I implement */
2817 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2818 glx
.CopyContext
= Fake_glXCopyContext
;
2819 glx
.CreateContext
= Fake_glXCreateContext
;
2820 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2821 glx
.DestroyContext
= Fake_glXDestroyContext
;
2822 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2823 glx
.GetConfig
= Fake_glXGetConfig
;
2824 glx
.GetCurrentContext
= Fake_glXGetCurrentContext
;
2825 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2826 glx
.IsDirect
= Fake_glXIsDirect
;
2827 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2828 glx
.QueryExtension
= Fake_glXQueryExtension
;
2829 glx
.QueryVersion
= Fake_glXQueryVersion
;
2830 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2831 glx
.UseXFont
= Fake_glXUseXFont
;
2832 glx
.WaitGL
= Fake_glXWaitGL
;
2833 glx
.WaitX
= Fake_glXWaitX
;
2835 /*** GLX_VERSION_1_1 ***/
2836 glx
.GetClientString
= Fake_glXGetClientString
;
2837 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2838 glx
.QueryServerString
= Fake_glXQueryServerString
;
2840 /*** GLX_VERSION_1_2 ***/
2841 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2843 /*** GLX_VERSION_1_3 ***/
2844 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2845 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2846 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2847 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2848 glx
.CreateWindow
= Fake_glXCreateWindow
;
2849 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2850 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2851 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2852 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2853 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2854 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2855 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2856 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2857 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2858 glx
.QueryContext
= Fake_glXQueryContext
;
2859 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2860 glx
.SelectEvent
= Fake_glXSelectEvent
;
2862 /*** GLX_SGI_swap_control ***/
2863 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2865 /*** GLX_SGI_video_sync ***/
2866 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2867 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2869 /*** GLX_SGI_make_current_read ***/
2870 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2871 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2873 /*** GLX_SGIX_video_source ***/
2875 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2876 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2879 /*** GLX_EXT_import_context ***/
2880 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2881 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2882 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2883 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2884 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2886 /*** GLX_SGIX_fbconfig ***/
2887 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2888 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2889 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2890 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
2891 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
2892 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
2894 /*** GLX_SGIX_pbuffer ***/
2895 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
2896 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
2897 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
2898 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
2899 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
2901 /*** GLX_SGI_cushion ***/
2902 glx
.CushionSGI
= Fake_glXCushionSGI
;
2904 /*** GLX_SGIX_video_resize ***/
2905 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
2906 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
2907 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
2908 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
2909 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
2911 /*** GLX_SGIX_dmbuffer **/
2912 #if defined(_DM_BUFFER_H_)
2913 glx
.AssociateDMPbufferSGIX
= NULL
;
2916 /*** GLX_SUN_get_transparent_index ***/
2917 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
2919 /*** GLX_MESA_copy_sub_buffer ***/
2920 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
2922 /*** GLX_MESA_release_buffers ***/
2923 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
2925 /*** GLX_MESA_pixmap_colormap ***/
2926 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
2928 /*** GLX_EXT_texture_from_pixmap ***/
2929 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
2930 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;
2932 glx
.CreateContextAttribs
= Fake_glXCreateContextAttribs
;