2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
29 * to run on X servers which do not have the real GLX extension.
31 * Thanks to the contributors:
33 * Initial version: Philip Brown (phil@bolthole.com)
34 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
35 * Further visual-handling refinements: Wolfram Gloger
36 * (wmglo@Dent.MED.Uni-Muenchen.DE).
39 * Don't be fooled, stereo isn't supported yet.
44 #include "glxheader.h"
46 #include "main/context.h"
47 #include "main/config.h"
48 #include "main/macros.h"
49 #include "main/imports.h"
50 #include "main/mtypes.h"
51 #include "main/version.h"
55 /* This indicates the client-side GLX API and GLX encoder version. */
56 #define CLIENT_MAJOR_VERSION 1
57 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
59 /* This indicates the server-side GLX decoder version.
60 * GLX 1.4 indicates OpenGL 1.3 support
62 #define SERVER_MAJOR_VERSION 1
63 #define SERVER_MINOR_VERSION 4
65 /* This is appended onto the glXGetClient/ServerString version strings. */
66 #define MESA_GLX_VERSION "Mesa " PACKAGE_VERSION
68 /* Who implemented this GLX? */
69 #define VENDOR "Brian Paul"
72 "GLX_MESA_set_3dfx_mode " \
73 "GLX_MESA_copy_sub_buffer " \
74 "GLX_MESA_pixmap_colormap " \
75 "GLX_MESA_release_buffers " \
76 "GLX_ARB_get_proc_address " \
77 "GLX_EXT_texture_from_pixmap " \
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 static XMesaVisual
*VisualTable
= NULL
;
109 static int NumVisuals
= 0;
113 * This struct and some code fragments borrowed
114 * from Mark Kilgard's GLUT library.
116 typedef struct _OverlayInfo
{
117 /* Avoid 64-bit portability problems by being careful to use
118 longs due to the way XGetWindowProperty is specified. Note
119 that these parameters are passed as CARD32s over X
121 unsigned long overlay_visual
;
122 long transparent_type
;
129 /* Macro to handle c_class vs class field name in XVisualInfo struct */
130 #if defined(__cplusplus) || defined(c_plusplus)
131 #define CLASS c_class
139 * Test if the given XVisualInfo is usable for Mesa rendering.
142 is_usable_visual( XVisualInfo
*vinfo
)
144 switch (vinfo
->CLASS
) {
147 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
151 /* Color-index rendering is not supported. */
155 /* Any depth of TrueColor or DirectColor works in RGB mode */
158 /* This should never happen */
166 * Get an array OverlayInfo records for specified screen.
167 * \param dpy the display
168 * \param screen screen number
169 * \param numOverlays returns numver of OverlayInfo records
170 * \return pointer to OverlayInfo array, free with XFree()
173 GetOverlayInfo(Display
*dpy
, int screen
, int *numOverlays
)
175 Atom overlayVisualsAtom
;
178 unsigned char *ovInfo
;
179 unsigned long sizeData
, bytesLeft
;
183 * The SERVER_OVERLAY_VISUALS property on the root window contains
184 * a list of overlay visuals. Get that list now.
186 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
187 if (overlayVisualsAtom
== None
) {
191 status
= XGetWindowProperty(dpy
, RootWindow(dpy
, screen
),
192 overlayVisualsAtom
, 0L, (long) 10000, False
,
193 overlayVisualsAtom
, &actualType
, &actualFormat
,
194 &sizeData
, &bytesLeft
,
197 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
198 actualFormat
!= 32 || sizeData
< 4) {
199 /* something went wrong */
200 free((void *) ovInfo
);
205 *numOverlays
= sizeData
/ 4;
206 return (OverlayInfo
*) ovInfo
;
212 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
213 * Input: dpy - the X display
214 * vinfo - the XVisualInfo to test
215 * Return: level of the visual:
217 * >0 = overlay planes
218 * <0 = underlay planes
221 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
223 OverlayInfo
*overlay_info
;
224 int numOverlaysPerScreen
, i
;
226 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
231 /* search the overlay visual list for the visual ID of interest */
232 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
233 const OverlayInfo
*ov
= overlay_info
+ i
;
234 if (ov
->overlay_visual
== vinfo
->visualid
) {
235 /* found the visual */
236 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
237 int level
= ov
->layer
;
238 free((void *) overlay_info
);
242 free((void *) overlay_info
);
248 /* The visual ID was not found in the overlay list. */
249 free((void *) overlay_info
);
257 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
258 * configuration in our list of GLX visuals.
261 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
262 GLboolean alphaFlag
, GLboolean dbFlag
,
263 GLboolean stereoFlag
,
264 GLint depth_size
, GLint stencil_size
,
265 GLint accumRedSize
, GLint accumGreenSize
,
266 GLint accumBlueSize
, GLint accumAlphaSize
,
267 GLint level
, GLint numAuxBuffers
)
269 GLboolean ximageFlag
= GL_TRUE
;
272 GLboolean comparePointers
;
275 /* Check if the MESA_BACK_BUFFER env var is set */
276 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
278 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
279 ximageFlag
= GL_FALSE
;
281 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
282 ximageFlag
= GL_TRUE
;
285 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
291 /* stereo not supported */
295 /* Comparing IDs uses less memory but sometimes fails. */
296 /* XXX revisit this after 3.0 is finished. */
297 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
298 comparePointers
= GL_TRUE
;
300 comparePointers
= GL_FALSE
;
302 /* Force the visual to have an alpha channel */
303 if (_mesa_getenv("MESA_GLX_FORCE_ALPHA"))
306 /* First check if a matching visual is already in the list */
307 for (i
=0; i
<NumVisuals
; i
++) {
308 XMesaVisual v
= VisualTable
[i
];
309 if (v
->display
== dpy
310 && v
->mesa_visual
.level
== level
311 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
312 && v
->ximage_flag
== ximageFlag
313 && v
->mesa_visual
.doubleBufferMode
== dbFlag
314 && v
->mesa_visual
.stereoMode
== stereoFlag
315 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
316 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
317 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
318 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
319 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
320 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
321 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
322 /* now either compare XVisualInfo pointers or visual IDs */
323 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
324 || (comparePointers
&& v
->vishandle
== vinfo
)) {
330 /* Create a new visual and add it to the list. */
332 xmvis
= XMesaCreateVisual( dpy
, vinfo
, GL_TRUE
, alphaFlag
, dbFlag
,
333 stereoFlag
, ximageFlag
,
334 depth_size
, stencil_size
,
335 accumRedSize
, accumBlueSize
,
336 accumBlueSize
, accumAlphaSize
, 0, level
,
339 /* Save a copy of the pointer now so we can find this visual again
340 * if we need to search for it in find_glx_visual().
342 xmvis
->vishandle
= vinfo
;
343 /* Allocate more space for additional visual */
344 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
345 sizeof(XMesaVisual
) * NumVisuals
,
346 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
347 /* add xmvis to the list */
348 VisualTable
[NumVisuals
] = xmvis
;
350 /* XXX minor hack, because XMesaCreateVisual doesn't support an
351 * aux buffers parameter.
353 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
360 * Return the default number of bits for the Z buffer.
361 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
362 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
363 * XXX probably do the same thing for stencil, accum, etc.
366 default_depth_bits(void)
369 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
373 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
378 default_alpha_bits(void)
381 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
390 default_accum_bits(void)
398 * Create a GLX visual from a regular XVisualInfo.
399 * This is called when Fake GLX is given an XVisualInfo which wasn't
400 * returned by glXChooseVisual. Since this is the first time we're
401 * considering this visual we'll take a guess at reasonable values
402 * for depth buffer size, stencil size, accum size, etc.
403 * This is the best we can do with a client-side emulation of GLX.
406 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
409 GLint zBits
= default_depth_bits();
410 GLint accBits
= default_accum_bits();
411 GLboolean alphaFlag
= default_alpha_bits() > 0;
413 vislevel
= level_of_visual( dpy
, visinfo
);
415 /* Color-index rendering to overlays is not supported. */
418 else if (is_usable_visual( visinfo
)) {
419 /* Configure this visual as RGB, double-buffered, depth-buffered. */
420 /* This is surely wrong for some people's needs but what else */
421 /* can be done? They should use glXChooseVisual(). */
422 return save_glx_visual( dpy
, visinfo
,
423 alphaFlag
, /* alpha */
424 GL_TRUE
, /* double */
425 GL_FALSE
, /* stereo */
427 8, /* stencil bits */
437 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
445 * Find the GLX visual associated with an XVisualInfo.
448 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
452 /* try to match visual id */
453 for (i
=0;i
<NumVisuals
;i
++) {
454 if (VisualTable
[i
]->display
==dpy
455 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
456 return VisualTable
[i
];
460 /* if that fails, try to match pointers */
461 for (i
=0;i
<NumVisuals
;i
++) {
462 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
463 return VisualTable
[i
];
473 * Return the transparent pixel value for a GLX visual.
474 * Input: glxvis - the glx_visual
475 * Return: a pixel value or -1 if no transparent pixel
478 transparent_pixel( XMesaVisual glxvis
)
480 Display
*dpy
= glxvis
->display
;
481 XVisualInfo
*vinfo
= glxvis
->visinfo
;
482 OverlayInfo
*overlay_info
;
483 int numOverlaysPerScreen
, i
;
485 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
490 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
491 const OverlayInfo
*ov
= overlay_info
+ i
;
492 if (ov
->overlay_visual
== vinfo
->visualid
) {
494 if (ov
->transparent_type
== 0) {
495 /* type 0 indicates no transparency */
496 free((void *) overlay_info
);
500 /* ov->value is the transparent pixel */
501 free((void *) overlay_info
);
507 /* The visual ID was not found in the overlay list. */
508 free((void *) overlay_info
);
515 * Try to get an X visual which matches the given arguments.
518 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
520 XVisualInfo temp
, *vis
;
523 unsigned int default_depth
;
526 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
531 default_depth
= DefaultDepth(dpy
,scr
);
532 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
534 if (depth
==default_depth
&& xclass
==default_class
) {
535 /* try to get root window's visual */
536 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
537 mask
|= VisualIDMask
;
540 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
542 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
543 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
544 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
546 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
547 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
548 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
549 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
564 * Retrieve the value of the given environment variable and find
565 * the X visual which matches it.
566 * Input: dpy - the display
567 * screen - the screen number
568 * varname - the name of the environment variable
569 * Return: an XVisualInfo pointer to NULL if error.
572 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
574 char value
[100], type
[100];
575 int depth
, xclass
= -1;
578 if (!_mesa_getenv( varname
)) {
582 strncpy( value
, _mesa_getenv(varname
), 100 );
585 sscanf( value
, "%s %d", type
, &depth
);
587 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
588 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
589 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
590 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
592 if (xclass
>-1 && depth
>0) {
593 vis
= get_visual( dpy
, scr
, depth
, xclass
);
599 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
608 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
609 * Input: dpy, screen - X display and screen number
610 * min_depth - minimum visual depth
611 * preferred_class - preferred GLX visual class or DONT_CARE
612 * Return: pointer to an XVisualInfo or NULL.
615 choose_x_visual(Display
*dpy
, int screen
, int min_depth
, int preferred_class
)
618 int xclass
, visclass
= 0;
621 /* First see if the MESA_RGB_VISUAL env var is defined */
622 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
626 /* Otherwise, search for a suitable visual */
627 if (preferred_class
==DONT_CARE
) {
628 for (xclass
=0;xclass
<4;xclass
++) {
630 case 0: visclass
= TrueColor
; break;
631 case 1: visclass
= DirectColor
; break;
632 case 2: visclass
= GrayScale
; break;
633 case 3: visclass
= StaticGray
; break;
636 /* start with shallowest */
637 for (depth
=0;depth
<=32;depth
++) {
638 vis
= get_visual( dpy
, screen
, depth
, visclass
);
645 /* start with deepest */
646 for (depth
=32;depth
>=min_depth
;depth
--) {
647 vis
= get_visual( dpy
, screen
, depth
, visclass
);
656 /* search for a specific visual class */
657 switch (preferred_class
) {
658 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
659 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
660 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
661 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
662 case GLX_PSEUDO_COLOR_EXT
:
663 case GLX_STATIC_COLOR_EXT
:
664 default: return NULL
;
667 /* start with shallowest */
668 for (depth
=0;depth
<=32;depth
++) {
669 vis
= get_visual( dpy
, screen
, depth
, visclass
);
676 /* start with deepest */
677 for (depth
=32;depth
>=min_depth
;depth
--) {
678 vis
= get_visual( dpy
, screen
, depth
, visclass
);
686 /* didn't find a visual */
693 * Find the deepest X over/underlay visual of at least min_depth.
694 * Input: dpy, screen - X display and screen number
695 * level - the over/underlay level
696 * trans_type - transparent pixel type: GLX_NONE_EXT,
697 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
699 * trans_value - transparent pixel value or DONT_CARE
700 * min_depth - minimum visual depth
701 * preferred_class - preferred GLX visual class or DONT_CARE
702 * Return: pointer to an XVisualInfo or NULL.
705 choose_x_overlay_visual( Display
*dpy
, int scr
,
706 int level
, int trans_type
, int trans_value
,
707 int min_depth
, int preferred_class
)
709 OverlayInfo
*overlay_info
;
710 int numOverlaysPerScreen
;
712 XVisualInfo
*deepvis
;
715 /*DEBUG int tt, tv; */
717 switch (preferred_class
) {
718 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
719 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
720 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
721 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
722 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
723 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
724 default: preferred_class
= DONT_CARE
;
727 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
732 /* Search for the deepest overlay which satisifies all criteria. */
736 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
737 const OverlayInfo
*ov
= overlay_info
+ i
;
738 XVisualInfo
*vislist
, vistemplate
;
741 if (ov
->layer
!=level
) {
742 /* failed overlay level criteria */
745 if (!(trans_type
==DONT_CARE
746 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
747 && ov
->transparent_type
>0)
748 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
749 /* failed transparent pixel type criteria */
752 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
753 /* failed transparent pixel value criteria */
757 /* get XVisualInfo and check the depth */
758 vistemplate
.visualid
= ov
->overlay_visual
;
759 vistemplate
.screen
= scr
;
760 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
761 &vistemplate
, &count
);
764 /* something went wrong */
767 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
768 /* wrong visual class */
772 /* Color-index rendering is not supported. Make sure we have True/DirectColor */
773 if (vislist
->CLASS
!= TrueColor
&& vislist
->CLASS
!= DirectColor
)
776 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
777 /* YES! found a satisfactory visual */
779 deepest
= vislist
->depth
;
781 /* DEBUG tt = ov->transparent_type;*/
782 /* DEBUG tv = ov->value; */
788 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
789 deepvis->visualid, level, deepvis->depth, tt, tv );
796 /**********************************************************************/
797 /*** Display-related functions ***/
798 /**********************************************************************/
802 * Free all XMesaVisuals which are associated with the given display.
805 destroy_visuals_on_display(Display
*dpy
)
808 for (i
= 0; i
< NumVisuals
; i
++) {
809 if (VisualTable
[i
]->display
== dpy
) {
810 /* remove this visual */
812 free(VisualTable
[i
]);
813 for (j
= i
; j
< NumVisuals
- 1; j
++)
814 VisualTable
[j
] = VisualTable
[j
+ 1];
822 * Called from XCloseDisplay() to let us free our display-related data.
825 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
827 destroy_visuals_on_display(dpy
);
828 xmesa_destroy_buffers_on_display(dpy
);
834 * Look for the named extension on given display and return a pointer
835 * to the _XExtension data, or NULL if extension not found.
838 lookup_extension(Display
*dpy
, const char *extName
)
841 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
842 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
851 * Whenever we're given a new Display pointer, call this function to
852 * register our close_display_callback function.
855 register_with_display(Display
*dpy
)
857 const char *extName
= "MesaGLX";
860 ext
= lookup_extension(dpy
, extName
);
862 XExtCodes
*c
= XAddExtension(dpy
);
863 ext
= dpy
->ext_procs
; /* new extension is at head of list */
864 assert(c
->extension
== ext
->codes
.extension
);
865 (void) c
; /* silence warning */
866 ext
->name
= _mesa_strdup(extName
);
867 ext
->close_display
= close_display_callback
;
872 /**********************************************************************/
873 /*** Begin Fake GLX API Functions ***/
874 /**********************************************************************/
878 * Helper used by glXChooseVisual and glXChooseFBConfig.
879 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
881 * In either case, the attribute list is terminated with the value 'None'.
884 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
886 const GLboolean rgbModeDefault
= fbConfig
;
887 const int *parselist
;
890 int min_red
=0, min_green
=0, min_blue
=0;
891 GLboolean rgb_flag
= rgbModeDefault
;
892 GLboolean alpha_flag
= GL_FALSE
;
893 GLboolean double_flag
= GL_FALSE
;
894 GLboolean stereo_flag
= GL_FALSE
;
895 GLint depth_size
= 0;
896 GLint stencil_size
= 0;
897 GLint accumRedSize
= 0;
898 GLint accumGreenSize
= 0;
899 GLint accumBlueSize
= 0;
900 GLint accumAlphaSize
= 0;
902 int visual_type
= DONT_CARE
;
903 int trans_type
= DONT_CARE
;
904 int trans_value
= DONT_CARE
;
905 GLint caveat
= DONT_CARE
;
906 XMesaVisual xmvis
= NULL
;
907 int desiredVisualID
= -1;
915 parselist
[1] == GLX_DONT_CARE
&&
916 parselist
[0] != GLX_LEVEL
) {
917 /* For glXChooseFBConfig(), skip attributes whose value is
918 * GLX_DONT_CARE (-1), unless it's GLX_LEVEL (which can legitimately be
921 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
922 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
928 switch (*parselist
) {
939 case GLX_BUFFER_SIZE
:
941 min_ci
= *parselist
++;
945 level
= *parselist
++;
957 case GLX_DOUBLEBUFFER
:
960 double_flag
= *parselist
++;
963 double_flag
= GL_TRUE
;
969 stereo_flag
= *parselist
++;
972 stereo_flag
= GL_TRUE
;
975 case GLX_AUX_BUFFERS
:
977 numAux
= *parselist
++;
978 if (numAux
> MAX_AUX_BUFFERS
)
983 min_red
= *parselist
++;
987 min_green
= *parselist
++;
991 min_blue
= *parselist
++;
996 GLint size
= *parselist
++;
997 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
1000 case GLX_DEPTH_SIZE
:
1002 depth_size
= *parselist
++;
1004 case GLX_STENCIL_SIZE
:
1006 stencil_size
= *parselist
++;
1008 case GLX_ACCUM_RED_SIZE
:
1011 GLint size
= *parselist
++;
1012 accumRedSize
= MAX2( accumRedSize
, size
);
1015 case GLX_ACCUM_GREEN_SIZE
:
1018 GLint size
= *parselist
++;
1019 accumGreenSize
= MAX2( accumGreenSize
, size
);
1022 case GLX_ACCUM_BLUE_SIZE
:
1025 GLint size
= *parselist
++;
1026 accumBlueSize
= MAX2( accumBlueSize
, size
);
1029 case GLX_ACCUM_ALPHA_SIZE
:
1032 GLint size
= *parselist
++;
1033 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1038 * GLX_EXT_visual_info extension
1040 case GLX_X_VISUAL_TYPE_EXT
:
1042 visual_type
= *parselist
++;
1044 case GLX_TRANSPARENT_TYPE_EXT
:
1046 trans_type
= *parselist
++;
1048 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1050 trans_value
= *parselist
++;
1052 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1053 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1054 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1055 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1062 * GLX_EXT_visual_info extension
1064 case GLX_VISUAL_CAVEAT_EXT
:
1066 caveat
= *parselist
++; /* ignored for now */
1070 * GLX_ARB_multisample
1072 case GLX_SAMPLE_BUFFERS_ARB
:
1073 case GLX_SAMPLES_ARB
:
1075 if (*parselist
++ != 0)
1076 /* ms not supported */
1083 case GLX_RENDER_TYPE
:
1087 if (*parselist
& GLX_RGBA_BIT
) {
1090 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
1091 rgb_flag
= GL_FALSE
;
1093 else if (*parselist
== 0) {
1098 case GLX_DRAWABLE_TYPE
:
1102 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1103 return NULL
; /* bad bit */
1107 case GLX_FBCONFIG_ID
:
1112 desiredVisualID
= *parselist
++;
1114 case GLX_X_RENDERABLE
:
1115 case GLX_MAX_PBUFFER_WIDTH
:
1116 case GLX_MAX_PBUFFER_HEIGHT
:
1117 case GLX_MAX_PBUFFER_PIXELS
:
1124 #ifdef GLX_EXT_texture_from_pixmap
1125 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1126 parselist
++; /*skip*/
1128 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1129 parselist
++; /*skip*/
1131 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1132 parselist
++; /*skip*/
1134 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1136 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1137 GLX_TEXTURE_2D_BIT_EXT
|
1138 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1143 case GLX_Y_INVERTED_EXT
:
1144 parselist
++; /*skip*/
1153 /* undefined attribute */
1154 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1167 * Since we're only simulating the GLX extension this function will never
1168 * find any real GL visuals. Instead, all we can do is try to find an RGB
1169 * or CI visual of appropriate depth. Other requested attributes such as
1170 * double buffering, depth buffer, etc. will be associated with the X
1171 * visual and stored in the VisualTable[].
1173 if (desiredVisualID
!= -1) {
1174 /* try to get a specific visual, by visualID */
1177 temp
.visualid
= desiredVisualID
;
1178 temp
.screen
= screen
;
1179 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1181 /* give the visual some useful GLX attributes */
1182 double_flag
= GL_TRUE
;
1183 if (vis
->depth
<= 8)
1185 depth_size
= default_depth_bits();
1192 int min_rgb
= min_red
+ min_green
+ min_blue
;
1193 if (min_rgb
>1 && min_rgb
<8) {
1194 /* a special case to be sure we can get a monochrome visual */
1199 vis
= choose_x_visual(dpy
, screen
, min_rgb
, visual_type
);
1202 vis
= choose_x_overlay_visual(dpy
, screen
, level
,
1203 trans_type
, trans_value
, min_rgb
, visual_type
);
1208 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1209 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1210 * largest depth buffer size, which is 32bits/value. Instead, we
1211 * return 16 to maintain performance with earlier versions of Mesa.
1213 if (depth_size
> 24)
1215 else if (depth_size
> 16)
1217 else if (depth_size
> 0) {
1218 depth_size
= default_depth_bits();
1222 alpha_flag
= default_alpha_bits() > 0;
1225 /* we only support one size of stencil and accum buffers. */
1226 if (stencil_size
> 0)
1228 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1229 accumAlphaSize
> 0) {
1232 accumBlueSize
= default_accum_bits();
1233 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1236 xmvis
= save_glx_visual( dpy
, vis
, alpha_flag
, double_flag
,
1237 stereo_flag
, depth_size
, stencil_size
,
1238 accumRedSize
, accumGreenSize
,
1239 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1246 static XVisualInfo
*
1247 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1251 /* register ourselves as an extension on this display */
1252 register_with_display(dpy
);
1254 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1257 return xmvis
->vishandle
;
1259 /* create a new vishandle - the cached one may be stale */
1260 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1261 if (xmvis
->vishandle
) {
1262 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1264 return xmvis
->vishandle
;
1273 * Init basic fields of a new fake_glx_context.
1276 init_glx_context(struct fake_glx_context
*glxCtx
, Display
*dpy
)
1278 /* Always return True. See if anyone's confused... */
1279 GLboolean direct
= GL_TRUE
;
1281 glxCtx
->xmesaContext
->direct
= direct
;
1282 glxCtx
->glxContext
.isDirect
= direct
;
1283 glxCtx
->glxContext
.currentDpy
= dpy
;
1284 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1286 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1292 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1293 GLXContext share_list
, Bool direct
)
1296 struct fake_glx_context
*glxCtx
;
1297 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1299 if (!dpy
|| !visinfo
)
1302 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1306 /* deallocate unused windows/buffers */
1308 XMesaGarbageCollect(dpy
);
1311 xmvis
= find_glx_visual( dpy
, visinfo
);
1313 /* This visual wasn't found with glXChooseVisual() */
1314 xmvis
= create_glx_visual( dpy
, visinfo
);
1316 /* unusable visual */
1322 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1323 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1324 if (!glxCtx
->xmesaContext
) {
1329 init_glx_context(glxCtx
, dpy
);
1331 return (GLXContext
) glxCtx
;
1335 /* XXX these may have to be removed due to thread-safety issues. */
1336 static GLXContext MakeCurrent_PrevContext
= 0;
1337 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1338 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1339 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1340 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1343 /* GLX 1.3 and later */
1345 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1346 GLXDrawable read
, GLXContext ctx
)
1348 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1350 if (ctx
&& draw
&& read
) {
1351 XMesaBuffer drawBuffer
, readBuffer
;
1352 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1354 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1355 if (ctx
== MakeCurrent_PrevContext
1356 && draw
== MakeCurrent_PrevDrawable
) {
1357 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1360 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1363 /* drawable must be a new window! */
1364 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1366 /* Out of memory, or context/drawable depth mismatch */
1371 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1372 if (ctx
== MakeCurrent_PrevContext
1373 && read
== MakeCurrent_PrevReadable
) {
1374 readBuffer
= MakeCurrent_PrevReadBuffer
;
1377 readBuffer
= XMesaFindBuffer( dpy
, read
);
1380 /* drawable must be a new window! */
1381 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1383 /* Out of memory, or context/drawable depth mismatch */
1388 MakeCurrent_PrevContext
= ctx
;
1389 MakeCurrent_PrevDrawable
= draw
;
1390 MakeCurrent_PrevReadable
= read
;
1391 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1392 MakeCurrent_PrevReadBuffer
= readBuffer
;
1394 /* Now make current! */
1395 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1396 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1397 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1398 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1405 else if (!ctx
&& !draw
&& !read
) {
1406 /* release current context w/out assigning new one. */
1407 XMesaMakeCurrent( NULL
, NULL
);
1408 MakeCurrent_PrevContext
= 0;
1409 MakeCurrent_PrevDrawable
= 0;
1410 MakeCurrent_PrevReadable
= 0;
1411 MakeCurrent_PrevDrawBuffer
= 0;
1412 MakeCurrent_PrevReadBuffer
= 0;
1416 /* The args must either all be non-zero or all zero.
1425 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1427 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1432 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1437 v
= find_glx_visual( dpy
, visinfo
);
1439 v
= create_glx_visual( dpy
, visinfo
);
1441 /* unusable visual */
1446 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1450 return b
->frontxrb
->pixmap
;
1454 /*** GLX_MESA_pixmap_colormap ***/
1457 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1458 Pixmap pixmap
, Colormap cmap
)
1463 v
= find_glx_visual( dpy
, visinfo
);
1465 v
= create_glx_visual( dpy
, visinfo
);
1467 /* unusable visual */
1472 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1476 return b
->frontxrb
->pixmap
;
1481 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1483 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1485 XMesaDestroyBuffer(b
);
1487 else if (_mesa_getenv("MESA_DEBUG")) {
1488 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1494 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1495 unsigned long mask
)
1497 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1498 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1499 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1500 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1502 if (MakeCurrent_PrevContext
== src
) {
1505 _mesa_copy_context( &(xm_src
->mesa
), &(xm_dst
->mesa
), (GLuint
) mask
);
1510 Fake_glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1513 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1514 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1520 return True
; /* we're faking GLX so always return success */
1524 extern void _kw_ungrab_all( Display
*dpy
);
1525 void _kw_ungrab_all( Display
*dpy
)
1527 XUngrabPointer( dpy
, CurrentTime
);
1528 XUngrabKeyboard( dpy
, CurrentTime
);
1533 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1535 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1537 MakeCurrent_PrevContext
= 0;
1538 MakeCurrent_PrevDrawable
= 0;
1539 MakeCurrent_PrevReadable
= 0;
1540 MakeCurrent_PrevDrawBuffer
= 0;
1541 MakeCurrent_PrevReadBuffer
= 0;
1542 XMesaDestroyContext( glxCtx
->xmesaContext
);
1543 XMesaGarbageCollect(dpy
);
1549 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1551 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1553 return glxCtx
->xmesaContext
->direct
;
1559 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1561 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1564 XMesaSwapBuffers(buffer
);
1566 else if (_mesa_getenv("MESA_DEBUG")) {
1567 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1574 /*** GLX_MESA_copy_sub_buffer ***/
1577 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1578 int x
, int y
, int width
, int height
)
1580 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1582 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1584 else if (_mesa_getenv("MESA_DEBUG")) {
1585 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1591 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1594 /* Return GLX version, not Mesa version */
1595 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1596 *maj
= CLIENT_MAJOR_VERSION
;
1597 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1603 * Query the GLX attributes of the given XVisualInfo.
1606 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1612 return GLX_BAD_ATTRIBUTE
;
1613 *value
= (int) True
;
1615 case GLX_BUFFER_SIZE
:
1616 *value
= xmvis
->visinfo
->depth
;
1619 *value
= xmvis
->mesa_visual
.level
;
1623 return GLX_BAD_ATTRIBUTE
;
1624 if (xmvis
->mesa_visual
.rgbMode
) {
1631 case GLX_DOUBLEBUFFER
:
1632 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1635 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1637 case GLX_AUX_BUFFERS
:
1638 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1641 *value
= xmvis
->mesa_visual
.redBits
;
1643 case GLX_GREEN_SIZE
:
1644 *value
= xmvis
->mesa_visual
.greenBits
;
1647 *value
= xmvis
->mesa_visual
.blueBits
;
1649 case GLX_ALPHA_SIZE
:
1650 *value
= xmvis
->mesa_visual
.alphaBits
;
1652 case GLX_DEPTH_SIZE
:
1653 *value
= xmvis
->mesa_visual
.depthBits
;
1655 case GLX_STENCIL_SIZE
:
1656 *value
= xmvis
->mesa_visual
.stencilBits
;
1658 case GLX_ACCUM_RED_SIZE
:
1659 *value
= xmvis
->mesa_visual
.accumRedBits
;
1661 case GLX_ACCUM_GREEN_SIZE
:
1662 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1664 case GLX_ACCUM_BLUE_SIZE
:
1665 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1667 case GLX_ACCUM_ALPHA_SIZE
:
1668 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1672 * GLX_EXT_visual_info extension
1674 case GLX_X_VISUAL_TYPE_EXT
:
1675 switch (xmvis
->visinfo
->CLASS
) {
1676 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1677 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1678 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1679 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1680 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1681 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1684 case GLX_TRANSPARENT_TYPE_EXT
:
1685 if (xmvis
->mesa_visual
.level
==0) {
1687 *value
= GLX_NONE_EXT
;
1689 else if (xmvis
->mesa_visual
.level
>0) {
1691 if (xmvis
->mesa_visual
.rgbMode
) {
1692 *value
= GLX_TRANSPARENT_RGB_EXT
;
1695 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1698 else if (xmvis
->mesa_visual
.level
<0) {
1700 *value
= GLX_NONE_EXT
;
1703 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1705 int pixel
= transparent_pixel( xmvis
);
1709 /* else undefined */
1712 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1715 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1718 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1721 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1726 * GLX_EXT_visual_info extension
1728 case GLX_VISUAL_CAVEAT_EXT
:
1729 /* test for zero, just in case */
1730 if (xmvis
->mesa_visual
.visualRating
> 0)
1731 *value
= xmvis
->mesa_visual
.visualRating
;
1733 *value
= GLX_NONE_EXT
;
1737 * GLX_ARB_multisample
1739 case GLX_SAMPLE_BUFFERS_ARB
:
1742 case GLX_SAMPLES_ARB
:
1749 case GLX_SCREEN_EXT
:
1751 return GLX_BAD_ATTRIBUTE
;
1752 *value
= xmvis
->visinfo
->screen
;
1754 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1756 return GLX_BAD_ATTRIBUTE
;
1757 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1759 case GLX_RENDER_TYPE_SGIX
:
1761 return GLX_BAD_ATTRIBUTE
;
1762 if (xmvis
->mesa_visual
.rgbMode
)
1763 *value
= GLX_RGBA_BIT
;
1765 *value
= GLX_COLOR_INDEX_BIT
;
1767 case GLX_X_RENDERABLE_SGIX
:
1769 return GLX_BAD_ATTRIBUTE
;
1770 *value
= True
; /* XXX really? */
1772 case GLX_FBCONFIG_ID_SGIX
:
1774 return GLX_BAD_ATTRIBUTE
;
1775 *value
= xmvis
->visinfo
->visualid
;
1777 case GLX_MAX_PBUFFER_WIDTH
:
1779 return GLX_BAD_ATTRIBUTE
;
1780 /* XXX or MAX_WIDTH? */
1781 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1783 case GLX_MAX_PBUFFER_HEIGHT
:
1785 return GLX_BAD_ATTRIBUTE
;
1786 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1788 case GLX_MAX_PBUFFER_PIXELS
:
1790 return GLX_BAD_ATTRIBUTE
;
1791 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1792 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1796 return GLX_BAD_ATTRIBUTE
;
1797 *value
= xmvis
->visinfo
->visualid
;
1800 #ifdef GLX_EXT_texture_from_pixmap
1801 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1802 *value
= True
; /*XXX*/
1804 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1806 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1808 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1809 *value
= True
; /*XXX*/
1811 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1812 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1813 GLX_TEXTURE_2D_BIT_EXT
|
1814 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1816 case GLX_Y_INVERTED_EXT
:
1817 *value
= True
; /*XXX*/
1822 return GLX_BAD_ATTRIBUTE
;
1829 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1830 int attrib
, int *value
)
1834 if (!dpy
|| !visinfo
)
1835 return GLX_BAD_ATTRIBUTE
;
1837 xmvis
= find_glx_visual( dpy
, visinfo
);
1839 /* this visual wasn't obtained with glXChooseVisual */
1840 xmvis
= create_glx_visual( dpy
, visinfo
);
1842 /* this visual can't be used for GL rendering */
1843 if (attrib
==GLX_USE_GL
) {
1844 *value
= (int) False
;
1848 return GLX_BAD_VISUAL
;
1853 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1859 Fake_glXWaitGL( void )
1861 XMesaContext xmesa
= XMesaGetCurrentContext();
1862 XMesaFlush( xmesa
);
1868 Fake_glXWaitX( void )
1870 XMesaContext xmesa
= XMesaGetCurrentContext();
1871 XMesaFlush( xmesa
);
1876 get_extensions( void )
1878 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
1883 /* GLX 1.1 and later */
1885 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1889 return get_extensions();
1894 /* GLX 1.1 and later */
1896 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1898 static char version
[1000];
1899 sprintf(version
, "%d.%d %s",
1900 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1906 case GLX_EXTENSIONS
:
1907 return get_extensions();
1919 /* GLX 1.1 and later */
1921 Fake_glXGetClientString( Display
*dpy
, int name
)
1923 static char version
[1000];
1924 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1925 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1930 case GLX_EXTENSIONS
:
1931 return get_extensions();
1949 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1950 int attribute
, int *value
)
1952 XMesaVisual v
= (XMesaVisual
) config
;
1956 if (!dpy
|| !config
|| !value
)
1959 return get_config(v
, attribute
, value
, GL_TRUE
);
1963 static GLXFBConfig
*
1964 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1966 XVisualInfo
*visuals
, visTemplate
;
1967 const long visMask
= VisualScreenMask
;
1970 /* Get list of all X visuals */
1971 visTemplate
.screen
= screen
;
1972 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1973 if (*nelements
> 0) {
1974 XMesaVisual
*results
;
1975 results
= malloc(*nelements
* sizeof(XMesaVisual
));
1980 for (i
= 0; i
< *nelements
; i
++) {
1981 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1983 return (GLXFBConfig
*) results
;
1989 static GLXFBConfig
*
1990 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1991 const int *attribList
, int *nitems
)
1995 /* register ourselves as an extension on this display */
1996 register_with_display(dpy
);
1998 if (!attribList
|| !attribList
[0]) {
1999 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
2000 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
2003 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
2005 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
2011 config
[0] = (GLXFBConfig
) xmvis
;
2012 return (GLXFBConfig
*) config
;
2021 static XVisualInfo
*
2022 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
2024 if (dpy
&& config
) {
2025 XMesaVisual xmvis
= (XMesaVisual
) config
;
2027 return xmvis
->vishandle
;
2029 /* create a new vishandle - the cached one may be stale */
2030 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
2031 if (xmvis
->vishandle
) {
2032 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
2034 return xmvis
->vishandle
;
2044 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
2045 const int *attribList
)
2047 XMesaVisual xmvis
= (XMesaVisual
) config
;
2052 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
2057 (void) attribList
; /* Ignored in GLX 1.3 */
2059 return win
; /* A hack for now */
2064 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
2066 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2068 XMesaDestroyBuffer(b
);
2069 /* don't destroy X window */
2075 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2076 const int *attribList
)
2078 XMesaVisual v
= (XMesaVisual
) config
;
2081 int target
= 0, format
= 0, mipmap
= 0;
2084 if (!dpy
|| !config
|| !pixmap
)
2087 for (attr
= attribList
; attr
&& *attr
; attr
++) {
2089 case GLX_TEXTURE_FORMAT_EXT
:
2092 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2093 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2094 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2102 case GLX_TEXTURE_TARGET_EXT
:
2105 case GLX_TEXTURE_1D_EXT
:
2106 case GLX_TEXTURE_2D_EXT
:
2107 case GLX_TEXTURE_RECTANGLE_EXT
:
2115 case GLX_MIPMAP_TEXTURE_EXT
:
2126 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2127 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2128 &value
, GL_TRUE
) != Success
2130 return 0; /* error! */
2133 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2134 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2135 &value
, GL_TRUE
) != Success
2137 return 0; /* error! */
2141 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2142 &value
, GL_TRUE
) != Success
2144 return 0; /* error! */
2147 if (target
== GLX_TEXTURE_1D_EXT
) {
2148 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2149 &value
, GL_TRUE
) != Success
2150 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2151 return 0; /* error! */
2154 else if (target
== GLX_TEXTURE_2D_EXT
) {
2155 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2156 &value
, GL_TRUE
) != Success
2157 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2158 return 0; /* error! */
2161 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2162 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2163 &value
, GL_TRUE
) != Success
2164 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2165 return 0; /* error! */
2169 if (format
|| target
|| mipmap
) {
2170 /* texture from pixmap */
2171 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2174 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2185 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2187 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2189 XMesaDestroyBuffer(b
);
2190 /* don't destroy X pixmap */
2195 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2196 const int *attribList
)
2198 XMesaVisual xmvis
= (XMesaVisual
) config
;
2201 int width
= 0, height
= 0;
2202 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2206 for (attrib
= attribList
; *attrib
; attrib
++) {
2208 case GLX_PBUFFER_WIDTH
:
2212 case GLX_PBUFFER_HEIGHT
:
2216 case GLX_PRESERVED_CONTENTS
:
2218 preserveContents
= *attrib
;
2220 case GLX_LARGEST_PBUFFER
:
2222 useLargest
= *attrib
;
2229 if (width
== 0 || height
== 0)
2232 if (width
> SWRAST_MAX_WIDTH
|| height
> SWRAST_MAX_HEIGHT
) {
2233 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2234 * allocate the largest possible buffer.
2237 width
= SWRAST_MAX_WIDTH
;
2238 height
= SWRAST_MAX_HEIGHT
;
2242 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2243 /* A GLXPbuffer handle must be an X Drawable because that's what
2244 * glXMakeCurrent takes.
2247 xmbuf
->largestPbuffer
= useLargest
;
2248 xmbuf
->preservedContents
= preserveContents
;
2249 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2258 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2260 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2262 XMesaDestroyBuffer(b
);
2268 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2269 unsigned int *value
)
2271 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2275 /* make sure buffer's dimensions are up to date */
2276 xmesa_check_and_update_buffer_size(NULL
, xmbuf
);
2278 switch (attribute
) {
2280 *value
= xmbuf
->mesa_buffer
.Width
;
2283 *value
= xmbuf
->mesa_buffer
.Height
;
2285 case GLX_PRESERVED_CONTENTS
:
2286 *value
= xmbuf
->preservedContents
;
2288 case GLX_LARGEST_PBUFFER
:
2289 *value
= xmbuf
->largestPbuffer
;
2291 case GLX_FBCONFIG_ID
:
2292 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2294 #ifdef GLX_EXT_texture_from_pixmap
2295 case GLX_TEXTURE_FORMAT_EXT
:
2296 *value
= xmbuf
->TextureFormat
;
2298 case GLX_TEXTURE_TARGET_EXT
:
2299 *value
= xmbuf
->TextureTarget
;
2301 case GLX_MIPMAP_TEXTURE_EXT
:
2302 *value
= xmbuf
->TextureMipmap
;
2307 return; /* raise BadValue error */
2313 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2314 int renderType
, GLXContext shareList
, Bool direct
)
2316 struct fake_glx_context
*glxCtx
;
2317 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2318 XMesaVisual xmvis
= (XMesaVisual
) config
;
2320 if (!dpy
|| !config
||
2321 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2324 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2328 /* deallocate unused windows/buffers */
2329 XMesaGarbageCollect(dpy
);
2331 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2332 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2333 if (!glxCtx
->xmesaContext
) {
2338 init_glx_context(glxCtx
, dpy
);
2340 return (GLXContext
) glxCtx
;
2345 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2347 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2348 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2353 switch (attribute
) {
2354 case GLX_FBCONFIG_ID
:
2355 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2357 case GLX_RENDER_TYPE
:
2358 *value
= GLX_RGBA_TYPE
;
2364 return GLX_BAD_ATTRIBUTE
;
2371 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2373 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2375 xmbuf
->selectedEvents
= mask
;
2380 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2381 unsigned long *mask
)
2383 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2385 *mask
= xmbuf
->selectedEvents
;
2392 /*** GLX_SGI_swap_control ***/
2395 Fake_glXSwapIntervalSGI(int interval
)
2403 /*** GLX_SGI_video_sync ***/
2405 static unsigned int FrameCounter
= 0;
2408 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2410 /* this is a bogus implementation */
2411 *count
= FrameCounter
++;
2416 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2418 if (divisor
<= 0 || remainder
< 0)
2419 return GLX_BAD_VALUE
;
2420 /* this is a bogus implementation */
2422 while (FrameCounter
% divisor
!= remainder
)
2424 *count
= FrameCounter
;
2430 /*** GLX_SGI_make_current_read ***/
2433 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2435 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2440 Fake_glXGetCurrentReadDrawableSGI(void)
2447 /*** GLX_SGIX_video_source ***/
2450 static GLXVideoSourceSGIX
2451 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2463 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2472 /*** GLX_EXT_import_context ***/
2475 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2482 Fake_glXGetContextIDEXT(const GLXContext context
)
2489 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2497 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2508 /*** GLX_SGIX_fbconfig ***/
2511 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2513 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2516 static GLXFBConfigSGIX
*
2517 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2519 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2524 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2526 XMesaVisual xmvis
= (XMesaVisual
) config
;
2527 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2528 return xmbuf
->frontxrb
->pixmap
; /* need to return an X ID */
2533 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2535 XMesaVisual xmvis
= (XMesaVisual
) config
;
2536 struct fake_glx_context
*glxCtx
;
2537 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2539 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2543 /* deallocate unused windows/buffers */
2544 XMesaGarbageCollect(dpy
);
2546 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2547 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2548 if (!glxCtx
->xmesaContext
) {
2553 init_glx_context(glxCtx
, dpy
);
2555 return (GLXContext
) glxCtx
;
2559 static XVisualInfo
*
2560 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2562 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2566 static GLXFBConfigSGIX
2567 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2569 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2571 /* This visual wasn't found with glXChooseVisual() */
2572 xmvis
= create_glx_visual(dpy
, vis
);
2575 return (GLXFBConfigSGIX
) xmvis
;
2580 /*** GLX_SGIX_pbuffer ***/
2582 static GLXPbufferSGIX
2583 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2584 unsigned int width
, unsigned int height
,
2587 XMesaVisual xmvis
= (XMesaVisual
) config
;
2590 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2594 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2596 case GLX_PRESERVED_CONTENTS_SGIX
:
2598 preserveContents
= *attrib
; /* ignored */
2600 case GLX_LARGEST_PBUFFER_SGIX
:
2602 useLargest
= *attrib
; /* ignored */
2609 /* not used at this time */
2611 (void) preserveContents
;
2613 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2614 /* A GLXPbuffer handle must be an X Drawable because that's what
2615 * glXMakeCurrent takes.
2617 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2622 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2624 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2626 XMesaDestroyBuffer(xmbuf
);
2632 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2634 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2637 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2641 switch (attribute
) {
2642 case GLX_PRESERVED_CONTENTS_SGIX
:
2643 *value
= xmbuf
->preservedContents
;
2645 case GLX_LARGEST_PBUFFER_SGIX
:
2646 *value
= xmbuf
->largestPbuffer
;
2648 case GLX_WIDTH_SGIX
:
2649 *value
= xmbuf
->mesa_buffer
.Width
;
2651 case GLX_HEIGHT_SGIX
:
2652 *value
= xmbuf
->mesa_buffer
.Height
;
2654 case GLX_EVENT_MASK_SGIX
:
2655 *value
= 0; /* XXX might be wrong */
2665 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2667 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2669 /* Note: we'll never generate clobber events */
2670 xmbuf
->selectedEvents
= mask
;
2676 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2678 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2680 *mask
= xmbuf
->selectedEvents
;
2689 /*** GLX_SGI_cushion ***/
2692 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2701 /*** GLX_SGIX_video_resize ***/
2704 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2714 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2727 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2740 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2753 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2764 /*** GLX_SGIX_dmbuffer **/
2766 #if defined(_DM_BUFFER_H_)
2768 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2779 /*** GLX_SGIX_swap_group ***/
2782 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2791 /*** GLX_SGIX_swap_barrier ***/
2794 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2802 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2812 /*** GLX_SUN_get_transparent_index ***/
2815 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2820 (void) pTransparent
;
2826 /*** GLX_MESA_release_buffers ***/
2829 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2830 * (a window or pixmap) prior to destroying the GLXDrawable.
2833 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2835 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2837 XMesaDestroyBuffer(b
);
2845 /*** GLX_MESA_set_3dfx_mode ***/
2848 Fake_glXSet3DfxModeMESA( int mode
)
2850 return XMesaSetFXmode( mode
);
2855 /*** GLX_NV_vertex_array range ***/
2857 Fake_glXAllocateMemoryNV( GLsizei size
,
2858 GLfloat readFrequency
,
2859 GLfloat writeFrequency
,
2863 (void) readFrequency
;
2864 (void) writeFrequency
;
2871 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2877 /*** GLX_MESA_agp_offset ***/
2880 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
2887 /*** GLX_EXT_texture_from_pixmap ***/
2890 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2891 const int *attrib_list
)
2893 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2895 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2899 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2901 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2903 XMesaReleaseTexImage(dpy
, b
, buffer
);
2907 /* silence warning */
2908 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2912 * Create a new GLX API dispatch table with its function pointers
2913 * initialized to point to Mesa's "fake" GLX API functions.
2914 * Note: there's a similar function (_real_GetGLXDispatchTable) that
2915 * returns a new dispatch table with all pointers initalized to point
2916 * to "real" GLX functions (which understand GLX wire protocol, etc).
2918 struct _glxapi_table
*
2919 _mesa_GetGLXDispatchTable(void)
2921 static struct _glxapi_table glx
;
2923 /* be sure our dispatch table size <= libGL's table */
2925 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2927 assert(_glxapi_get_dispatch_table_size() >= size
);
2930 /* initialize the whole table to no-ops */
2931 _glxapi_set_no_op_table(&glx
);
2933 /* now initialize the table with the functions I implement */
2934 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2935 glx
.CopyContext
= Fake_glXCopyContext
;
2936 glx
.CreateContext
= Fake_glXCreateContext
;
2937 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2938 glx
.DestroyContext
= Fake_glXDestroyContext
;
2939 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2940 glx
.GetConfig
= Fake_glXGetConfig
;
2941 /*glx.GetCurrentContext = Fake_glXGetCurrentContext;*/
2942 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2943 glx
.IsDirect
= Fake_glXIsDirect
;
2944 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2945 glx
.QueryExtension
= Fake_glXQueryExtension
;
2946 glx
.QueryVersion
= Fake_glXQueryVersion
;
2947 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2948 glx
.UseXFont
= Fake_glXUseXFont
;
2949 glx
.WaitGL
= Fake_glXWaitGL
;
2950 glx
.WaitX
= Fake_glXWaitX
;
2952 /*** GLX_VERSION_1_1 ***/
2953 glx
.GetClientString
= Fake_glXGetClientString
;
2954 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2955 glx
.QueryServerString
= Fake_glXQueryServerString
;
2957 /*** GLX_VERSION_1_2 ***/
2958 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2960 /*** GLX_VERSION_1_3 ***/
2961 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2962 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2963 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2964 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2965 glx
.CreateWindow
= Fake_glXCreateWindow
;
2966 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2967 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2968 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2969 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2970 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2971 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2972 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2973 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2974 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2975 glx
.QueryContext
= Fake_glXQueryContext
;
2976 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2977 glx
.SelectEvent
= Fake_glXSelectEvent
;
2979 /*** GLX_SGI_swap_control ***/
2980 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2982 /*** GLX_SGI_video_sync ***/
2983 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2984 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2986 /*** GLX_SGI_make_current_read ***/
2987 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2988 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2990 /*** GLX_SGIX_video_source ***/
2992 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2993 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2996 /*** GLX_EXT_import_context ***/
2997 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2998 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2999 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
3000 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
3001 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
3003 /*** GLX_SGIX_fbconfig ***/
3004 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
3005 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
3006 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
3007 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
3008 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
3009 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
3011 /*** GLX_SGIX_pbuffer ***/
3012 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
3013 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
3014 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
3015 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
3016 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
3018 /*** GLX_SGI_cushion ***/
3019 glx
.CushionSGI
= Fake_glXCushionSGI
;
3021 /*** GLX_SGIX_video_resize ***/
3022 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
3023 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
3024 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
3025 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
3026 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
3028 /*** GLX_SGIX_dmbuffer **/
3029 #if defined(_DM_BUFFER_H_)
3030 glx
.AssociateDMPbufferSGIX
= NULL
;
3033 /*** GLX_SGIX_swap_group ***/
3034 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
3036 /*** GLX_SGIX_swap_barrier ***/
3037 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
3038 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
3040 /*** GLX_SUN_get_transparent_index ***/
3041 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
3043 /*** GLX_MESA_copy_sub_buffer ***/
3044 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3046 /*** GLX_MESA_release_buffers ***/
3047 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3049 /*** GLX_MESA_pixmap_colormap ***/
3050 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3052 /*** GLX_MESA_set_3dfx_mode ***/
3053 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3055 /*** GLX_NV_vertex_array_range ***/
3056 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3057 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3059 /*** GLX_MESA_agp_offset ***/
3060 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3062 /*** GLX_EXT_texture_from_pixmap ***/
3063 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3064 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;