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"
56 /* This indicates the client-side GLX API and GLX encoder version. */
57 #define CLIENT_MAJOR_VERSION 1
58 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
60 /* This indicates the server-side GLX decoder version.
61 * GLX 1.4 indicates OpenGL 1.3 support
63 #define SERVER_MAJOR_VERSION 1
64 #define SERVER_MINOR_VERSION 4
66 /* This is appended onto the glXGetClient/ServerString version strings. */
67 #define MESA_GLX_VERSION "Mesa " PACKAGE_VERSION
69 /* Who implemented this GLX? */
70 #define VENDOR "Brian Paul"
73 "GLX_MESA_set_3dfx_mode " \
74 "GLX_MESA_copy_sub_buffer " \
75 "GLX_MESA_pixmap_colormap " \
76 "GLX_MESA_release_buffers " \
77 "GLX_ARB_create_context " \
78 "GLX_ARB_get_proc_address " \
79 "GLX_EXT_texture_from_pixmap " \
80 "GLX_EXT_visual_info " \
81 "GLX_EXT_visual_rating " \
82 /*"GLX_SGI_video_sync "*/ \
83 "GLX_SGIX_fbconfig " \
88 /**********************************************************************/
89 /*** GLX Visual Code ***/
90 /**********************************************************************/
95 static XMesaVisual
*VisualTable
= NULL
;
96 static int NumVisuals
= 0;
100 * This struct and some code fragments borrowed
101 * from Mark Kilgard's GLUT library.
103 typedef struct _OverlayInfo
{
104 /* Avoid 64-bit portability problems by being careful to use
105 longs due to the way XGetWindowProperty is specified. Note
106 that these parameters are passed as CARD32s over X
108 unsigned long overlay_visual
;
109 long transparent_type
;
116 /* Macro to handle c_class vs class field name in XVisualInfo struct */
117 #if defined(__cplusplus) || defined(c_plusplus)
118 #define CLASS c_class
126 * Test if the given XVisualInfo is usable for Mesa rendering.
129 is_usable_visual( XVisualInfo
*vinfo
)
131 switch (vinfo
->CLASS
) {
134 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
138 /* Color-index rendering is not supported. */
142 /* Any depth of TrueColor or DirectColor works in RGB mode */
145 /* This should never happen */
153 * Get an array OverlayInfo records for specified screen.
154 * \param dpy the display
155 * \param screen screen number
156 * \param numOverlays returns numver of OverlayInfo records
157 * \return pointer to OverlayInfo array, free with XFree()
160 GetOverlayInfo(Display
*dpy
, int screen
, int *numOverlays
)
162 Atom overlayVisualsAtom
;
165 unsigned char *ovInfo
;
166 unsigned long sizeData
, bytesLeft
;
170 * The SERVER_OVERLAY_VISUALS property on the root window contains
171 * a list of overlay visuals. Get that list now.
173 overlayVisualsAtom
= XInternAtom(dpy
,"SERVER_OVERLAY_VISUALS", True
);
174 if (overlayVisualsAtom
== None
) {
178 status
= XGetWindowProperty(dpy
, RootWindow(dpy
, screen
),
179 overlayVisualsAtom
, 0L, (long) 10000, False
,
180 overlayVisualsAtom
, &actualType
, &actualFormat
,
181 &sizeData
, &bytesLeft
,
184 if (status
!= Success
|| actualType
!= overlayVisualsAtom
||
185 actualFormat
!= 32 || sizeData
< 4) {
186 /* something went wrong */
187 free((void *) ovInfo
);
192 *numOverlays
= sizeData
/ 4;
193 return (OverlayInfo
*) ovInfo
;
199 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
200 * Input: dpy - the X display
201 * vinfo - the XVisualInfo to test
202 * Return: level of the visual:
204 * >0 = overlay planes
205 * <0 = underlay planes
208 level_of_visual( Display
*dpy
, XVisualInfo
*vinfo
)
210 OverlayInfo
*overlay_info
;
211 int numOverlaysPerScreen
, i
;
213 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
218 /* search the overlay visual list for the visual ID of interest */
219 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
220 const OverlayInfo
*ov
= overlay_info
+ i
;
221 if (ov
->overlay_visual
== vinfo
->visualid
) {
222 /* found the visual */
223 if (/*ov->transparent_type==1 &&*/ ov
->layer
!=0) {
224 int level
= ov
->layer
;
225 free((void *) overlay_info
);
229 free((void *) overlay_info
);
235 /* The visual ID was not found in the overlay list. */
236 free((void *) overlay_info
);
244 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
245 * configuration in our list of GLX visuals.
248 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
249 GLboolean alphaFlag
, GLboolean dbFlag
,
250 GLboolean stereoFlag
,
251 GLint depth_size
, GLint stencil_size
,
252 GLint accumRedSize
, GLint accumGreenSize
,
253 GLint accumBlueSize
, GLint accumAlphaSize
,
254 GLint level
, GLint numAuxBuffers
)
256 GLboolean ximageFlag
= GL_TRUE
;
259 GLboolean comparePointers
;
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 */
282 /* Comparing IDs uses less memory but sometimes fails. */
283 /* XXX revisit this after 3.0 is finished. */
284 if (getenv("MESA_GLX_VISUAL_HACK"))
285 comparePointers
= GL_TRUE
;
287 comparePointers
= GL_FALSE
;
289 /* Force the visual to have an alpha channel */
290 if (getenv("MESA_GLX_FORCE_ALPHA"))
293 /* First check if a matching visual is already in the list */
294 for (i
=0; i
<NumVisuals
; i
++) {
295 XMesaVisual v
= VisualTable
[i
];
296 if (v
->display
== dpy
297 && v
->mesa_visual
.level
== level
298 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
299 && v
->ximage_flag
== ximageFlag
300 && v
->mesa_visual
.doubleBufferMode
== dbFlag
301 && v
->mesa_visual
.stereoMode
== stereoFlag
302 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
303 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
304 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
305 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
306 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
307 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
308 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
309 /* now either compare XVisualInfo pointers or visual IDs */
310 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
311 || (comparePointers
&& v
->vishandle
== vinfo
)) {
317 /* Create a new visual and add it to the list. */
319 xmvis
= XMesaCreateVisual( dpy
, vinfo
, GL_TRUE
, alphaFlag
, dbFlag
,
320 stereoFlag
, ximageFlag
,
321 depth_size
, stencil_size
,
322 accumRedSize
, accumBlueSize
,
323 accumBlueSize
, accumAlphaSize
, 0, level
,
326 /* Save a copy of the pointer now so we can find this visual again
327 * if we need to search for it in find_glx_visual().
329 xmvis
->vishandle
= vinfo
;
330 /* Allocate more space for additional visual */
331 VisualTable
= realloc(VisualTable
, sizeof(XMesaVisual
) * (NumVisuals
+ 1));
332 /* add xmvis to the list */
333 VisualTable
[NumVisuals
] = xmvis
;
335 /* XXX minor hack, because XMesaCreateVisual doesn't support an
336 * aux buffers parameter.
338 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
345 * Return the default number of bits for the Z buffer.
346 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
347 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
348 * XXX probably do the same thing for stencil, accum, etc.
351 default_depth_bits(void)
354 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
358 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
363 default_alpha_bits(void)
366 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
375 default_accum_bits(void)
383 * Create a GLX visual from a regular XVisualInfo.
384 * This is called when Fake GLX is given an XVisualInfo which wasn't
385 * returned by glXChooseVisual. Since this is the first time we're
386 * considering this visual we'll take a guess at reasonable values
387 * for depth buffer size, stencil size, accum size, etc.
388 * This is the best we can do with a client-side emulation of GLX.
391 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
394 GLint zBits
= default_depth_bits();
395 GLint accBits
= default_accum_bits();
396 GLboolean alphaFlag
= default_alpha_bits() > 0;
398 vislevel
= level_of_visual( dpy
, visinfo
);
400 /* Color-index rendering to overlays is not supported. */
403 else if (is_usable_visual( visinfo
)) {
404 /* Configure this visual as RGB, double-buffered, depth-buffered. */
405 /* This is surely wrong for some people's needs but what else */
406 /* can be done? They should use glXChooseVisual(). */
407 return save_glx_visual( dpy
, visinfo
,
408 alphaFlag
, /* alpha */
409 GL_TRUE
, /* double */
410 GL_FALSE
, /* stereo */
412 8, /* stencil bits */
422 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
430 * Find the GLX visual associated with an XVisualInfo.
433 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
437 /* try to match visual id */
438 for (i
=0;i
<NumVisuals
;i
++) {
439 if (VisualTable
[i
]->display
==dpy
440 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
441 return VisualTable
[i
];
445 /* if that fails, try to match pointers */
446 for (i
=0;i
<NumVisuals
;i
++) {
447 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
448 return VisualTable
[i
];
458 * Return the transparent pixel value for a GLX visual.
459 * Input: glxvis - the glx_visual
460 * Return: a pixel value or -1 if no transparent pixel
463 transparent_pixel( XMesaVisual glxvis
)
465 Display
*dpy
= glxvis
->display
;
466 XVisualInfo
*vinfo
= glxvis
->visinfo
;
467 OverlayInfo
*overlay_info
;
468 int numOverlaysPerScreen
, i
;
470 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
475 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
476 const OverlayInfo
*ov
= overlay_info
+ i
;
477 if (ov
->overlay_visual
== vinfo
->visualid
) {
479 if (ov
->transparent_type
== 0) {
480 /* type 0 indicates no transparency */
481 free((void *) overlay_info
);
485 /* ov->value is the transparent pixel */
486 free((void *) overlay_info
);
492 /* The visual ID was not found in the overlay list. */
493 free((void *) overlay_info
);
500 * Try to get an X visual which matches the given arguments.
503 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
505 XVisualInfo temp
, *vis
;
508 unsigned int default_depth
;
511 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
516 default_depth
= DefaultDepth(dpy
,scr
);
517 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
519 if (depth
==default_depth
&& xclass
==default_class
) {
520 /* try to get root window's visual */
521 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
522 mask
|= VisualIDMask
;
525 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
527 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
528 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
529 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
531 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
532 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
533 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
534 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
549 * Retrieve the value of the given environment variable and find
550 * the X visual which matches it.
551 * Input: dpy - the display
552 * screen - the screen number
553 * varname - the name of the environment variable
554 * Return: an XVisualInfo pointer to NULL if error.
557 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
559 char value
[100], type
[100];
560 int depth
, xclass
= -1;
563 if (!getenv( varname
)) {
567 strncpy( value
, getenv(varname
), 100 );
570 sscanf( value
, "%s %d", type
, &depth
);
572 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
573 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
574 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
575 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
577 if (xclass
>-1 && depth
>0) {
578 vis
= get_visual( dpy
, scr
, depth
, xclass
);
584 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
593 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
594 * Input: dpy, screen - X display and screen number
595 * min_depth - minimum visual depth
596 * preferred_class - preferred GLX visual class or DONT_CARE
597 * Return: pointer to an XVisualInfo or NULL.
600 choose_x_visual(Display
*dpy
, int screen
, int min_depth
, int preferred_class
)
603 int xclass
, visclass
= 0;
606 /* First see if the MESA_RGB_VISUAL env var is defined */
607 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
611 /* Otherwise, search for a suitable visual */
612 if (preferred_class
==DONT_CARE
) {
613 for (xclass
=0;xclass
<4;xclass
++) {
615 case 0: visclass
= TrueColor
; break;
616 case 1: visclass
= DirectColor
; break;
617 case 2: visclass
= GrayScale
; break;
618 case 3: visclass
= StaticGray
; break;
621 /* start with shallowest */
622 for (depth
=0;depth
<=32;depth
++) {
623 vis
= get_visual( dpy
, screen
, depth
, visclass
);
630 /* start with deepest */
631 for (depth
=32;depth
>=min_depth
;depth
--) {
632 vis
= get_visual( dpy
, screen
, depth
, visclass
);
641 /* search for a specific visual class */
642 switch (preferred_class
) {
643 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
644 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
645 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
646 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
647 case GLX_PSEUDO_COLOR_EXT
:
648 case GLX_STATIC_COLOR_EXT
:
649 default: return NULL
;
652 /* start with shallowest */
653 for (depth
=0;depth
<=32;depth
++) {
654 vis
= get_visual( dpy
, screen
, depth
, visclass
);
661 /* start with deepest */
662 for (depth
=32;depth
>=min_depth
;depth
--) {
663 vis
= get_visual( dpy
, screen
, depth
, visclass
);
671 /* didn't find a visual */
678 * Find the deepest X over/underlay visual of at least min_depth.
679 * Input: dpy, screen - X display and screen number
680 * level - the over/underlay level
681 * trans_type - transparent pixel type: GLX_NONE_EXT,
682 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
684 * trans_value - transparent pixel value or DONT_CARE
685 * min_depth - minimum visual depth
686 * preferred_class - preferred GLX visual class or DONT_CARE
687 * Return: pointer to an XVisualInfo or NULL.
690 choose_x_overlay_visual( Display
*dpy
, int scr
,
691 int level
, int trans_type
, int trans_value
,
692 int min_depth
, int preferred_class
)
694 OverlayInfo
*overlay_info
;
695 int numOverlaysPerScreen
;
697 XVisualInfo
*deepvis
;
700 /*DEBUG int tt, tv; */
702 switch (preferred_class
) {
703 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
704 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
705 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
706 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
707 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
708 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
709 default: preferred_class
= DONT_CARE
;
712 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
717 /* Search for the deepest overlay which satisifies all criteria. */
721 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
722 const OverlayInfo
*ov
= overlay_info
+ i
;
723 XVisualInfo
*vislist
, vistemplate
;
726 if (ov
->layer
!=level
) {
727 /* failed overlay level criteria */
730 if (!(trans_type
==DONT_CARE
731 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
732 && ov
->transparent_type
>0)
733 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
734 /* failed transparent pixel type criteria */
737 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
738 /* failed transparent pixel value criteria */
742 /* get XVisualInfo and check the depth */
743 vistemplate
.visualid
= ov
->overlay_visual
;
744 vistemplate
.screen
= scr
;
745 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
746 &vistemplate
, &count
);
749 /* something went wrong */
752 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
753 /* wrong visual class */
757 /* Color-index rendering is not supported. Make sure we have True/DirectColor */
758 if (vislist
->CLASS
!= TrueColor
&& vislist
->CLASS
!= DirectColor
)
761 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
762 /* YES! found a satisfactory visual */
764 deepest
= vislist
->depth
;
766 /* DEBUG tt = ov->transparent_type;*/
767 /* DEBUG tv = ov->value; */
773 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
774 deepvis->visualid, level, deepvis->depth, tt, tv );
781 /**********************************************************************/
782 /*** Display-related functions ***/
783 /**********************************************************************/
787 * Free all XMesaVisuals which are associated with the given display.
790 destroy_visuals_on_display(Display
*dpy
)
793 for (i
= 0; i
< NumVisuals
; i
++) {
794 if (VisualTable
[i
]->display
== dpy
) {
795 /* remove this visual */
797 XMesaDestroyVisual(VisualTable
[i
]);
798 for (j
= i
; j
< NumVisuals
- 1; j
++)
799 VisualTable
[j
] = VisualTable
[j
+ 1];
807 * Called from XCloseDisplay() to let us free our display-related data.
810 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
812 destroy_visuals_on_display(dpy
);
813 xmesa_destroy_buffers_on_display(dpy
);
819 * Look for the named extension on given display and return a pointer
820 * to the _XExtension data, or NULL if extension not found.
823 lookup_extension(Display
*dpy
, const char *extName
)
826 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
827 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
836 * Whenever we're given a new Display pointer, call this function to
837 * register our close_display_callback function.
840 register_with_display(Display
*dpy
)
842 const char *extName
= "MesaGLX";
845 ext
= lookup_extension(dpy
, extName
);
847 XExtCodes
*c
= XAddExtension(dpy
);
848 ext
= dpy
->ext_procs
; /* new extension is at head of list */
849 assert(c
->extension
== ext
->codes
.extension
);
850 (void) c
; /* silence warning */
851 ext
->name
= strdup(extName
);
852 ext
->close_display
= close_display_callback
;
857 /**********************************************************************/
858 /*** Begin Fake GLX API Functions ***/
859 /**********************************************************************/
863 * Helper used by glXChooseVisual and glXChooseFBConfig.
864 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
866 * In either case, the attribute list is terminated with the value 'None'.
869 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
871 const GLboolean rgbModeDefault
= fbConfig
;
872 const int *parselist
;
875 int min_red
=0, min_green
=0, min_blue
=0;
876 GLboolean rgb_flag
= rgbModeDefault
;
877 GLboolean alpha_flag
= GL_FALSE
;
878 GLboolean double_flag
= GL_FALSE
;
879 GLboolean stereo_flag
= GL_FALSE
;
880 GLint depth_size
= 0;
881 GLint stencil_size
= 0;
882 GLint accumRedSize
= 0;
883 GLint accumGreenSize
= 0;
884 GLint accumBlueSize
= 0;
885 GLint accumAlphaSize
= 0;
887 int visual_type
= DONT_CARE
;
888 int trans_type
= DONT_CARE
;
889 int trans_value
= DONT_CARE
;
890 GLint caveat
= DONT_CARE
;
891 XMesaVisual xmvis
= NULL
;
892 int desiredVisualID
= -1;
900 parselist
[1] == GLX_DONT_CARE
&&
901 parselist
[0] != GLX_LEVEL
) {
902 /* For glXChooseFBConfig(), skip attributes whose value is
903 * GLX_DONT_CARE (-1), unless it's GLX_LEVEL (which can legitimately be
906 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
907 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
913 switch (*parselist
) {
924 case GLX_BUFFER_SIZE
:
926 min_ci
= *parselist
++;
930 level
= *parselist
++;
942 case GLX_DOUBLEBUFFER
:
945 double_flag
= *parselist
++;
948 double_flag
= GL_TRUE
;
954 stereo_flag
= *parselist
++;
957 stereo_flag
= GL_TRUE
;
960 case GLX_AUX_BUFFERS
:
962 numAux
= *parselist
++;
963 if (numAux
> MAX_AUX_BUFFERS
)
968 min_red
= *parselist
++;
972 min_green
= *parselist
++;
976 min_blue
= *parselist
++;
981 GLint size
= *parselist
++;
982 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
987 depth_size
= *parselist
++;
989 case GLX_STENCIL_SIZE
:
991 stencil_size
= *parselist
++;
993 case GLX_ACCUM_RED_SIZE
:
996 GLint size
= *parselist
++;
997 accumRedSize
= MAX2( accumRedSize
, size
);
1000 case GLX_ACCUM_GREEN_SIZE
:
1003 GLint size
= *parselist
++;
1004 accumGreenSize
= MAX2( accumGreenSize
, size
);
1007 case GLX_ACCUM_BLUE_SIZE
:
1010 GLint size
= *parselist
++;
1011 accumBlueSize
= MAX2( accumBlueSize
, size
);
1014 case GLX_ACCUM_ALPHA_SIZE
:
1017 GLint size
= *parselist
++;
1018 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1023 * GLX_EXT_visual_info extension
1025 case GLX_X_VISUAL_TYPE_EXT
:
1027 visual_type
= *parselist
++;
1029 case GLX_TRANSPARENT_TYPE_EXT
:
1031 trans_type
= *parselist
++;
1033 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1035 trans_value
= *parselist
++;
1037 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1038 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1039 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1040 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1047 * GLX_EXT_visual_info extension
1049 case GLX_VISUAL_CAVEAT_EXT
:
1051 caveat
= *parselist
++; /* ignored for now */
1055 * GLX_ARB_multisample
1057 case GLX_SAMPLE_BUFFERS_ARB
:
1058 case GLX_SAMPLES_ARB
:
1060 if (*parselist
++ != 0)
1061 /* ms not supported */
1068 case GLX_RENDER_TYPE
:
1072 if (*parselist
& GLX_RGBA_BIT
) {
1075 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
1076 rgb_flag
= GL_FALSE
;
1078 else if (*parselist
& (GLX_RGBA_FLOAT_BIT_ARB
|GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
)) {
1081 else if (*parselist
== 0) {
1086 case GLX_DRAWABLE_TYPE
:
1090 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1091 return NULL
; /* bad bit */
1095 case GLX_FBCONFIG_ID
:
1100 desiredVisualID
= *parselist
++;
1102 case GLX_X_RENDERABLE
:
1103 case GLX_MAX_PBUFFER_WIDTH
:
1104 case GLX_MAX_PBUFFER_HEIGHT
:
1105 case GLX_MAX_PBUFFER_PIXELS
:
1112 #ifdef GLX_EXT_texture_from_pixmap
1113 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1114 parselist
++; /*skip*/
1116 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1117 parselist
++; /*skip*/
1119 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1120 parselist
++; /*skip*/
1122 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1124 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1125 GLX_TEXTURE_2D_BIT_EXT
|
1126 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1131 case GLX_Y_INVERTED_EXT
:
1132 parselist
++; /*skip*/
1141 /* undefined attribute */
1142 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1155 * Since we're only simulating the GLX extension this function will never
1156 * find any real GL visuals. Instead, all we can do is try to find an RGB
1157 * or CI visual of appropriate depth. Other requested attributes such as
1158 * double buffering, depth buffer, etc. will be associated with the X
1159 * visual and stored in the VisualTable[].
1161 if (desiredVisualID
!= -1) {
1162 /* try to get a specific visual, by visualID */
1165 temp
.visualid
= desiredVisualID
;
1166 temp
.screen
= screen
;
1167 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1169 /* give the visual some useful GLX attributes */
1170 double_flag
= GL_TRUE
;
1171 if (vis
->depth
<= 8)
1173 depth_size
= default_depth_bits();
1180 int min_rgb
= min_red
+ min_green
+ min_blue
;
1181 if (min_rgb
>1 && min_rgb
<8) {
1182 /* a special case to be sure we can get a monochrome visual */
1187 vis
= choose_x_visual(dpy
, screen
, min_rgb
, visual_type
);
1190 vis
= choose_x_overlay_visual(dpy
, screen
, level
,
1191 trans_type
, trans_value
, min_rgb
, visual_type
);
1196 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1197 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1198 * largest depth buffer size, which is 32bits/value. Instead, we
1199 * return 16 to maintain performance with earlier versions of Mesa.
1201 if (depth_size
> 24)
1203 else if (depth_size
> 16)
1205 else if (depth_size
> 0) {
1206 depth_size
= default_depth_bits();
1210 alpha_flag
= default_alpha_bits() > 0;
1213 /* we only support one size of stencil and accum buffers. */
1214 if (stencil_size
> 0)
1216 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1217 accumAlphaSize
> 0) {
1220 accumBlueSize
= default_accum_bits();
1221 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1224 xmvis
= save_glx_visual( dpy
, vis
, alpha_flag
, double_flag
,
1225 stereo_flag
, depth_size
, stencil_size
,
1226 accumRedSize
, accumGreenSize
,
1227 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1234 static XVisualInfo
*
1235 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1239 /* register ourselves as an extension on this display */
1240 register_with_display(dpy
);
1242 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1244 XVisualInfo
* visinfo
= malloc(sizeof(XVisualInfo
));
1246 memcpy(visinfo
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1256 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1257 GLXContext share_list
, Bool direct
)
1260 XMesaContext xmesaCtx
;
1262 if (!dpy
|| !visinfo
)
1265 /* deallocate unused windows/buffers */
1267 XMesaGarbageCollect(dpy
);
1270 xmvis
= find_glx_visual( dpy
, visinfo
);
1272 /* This visual wasn't found with glXChooseVisual() */
1273 xmvis
= create_glx_visual( dpy
, visinfo
);
1279 xmesaCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) share_list
);
1281 return (GLXContext
) xmesaCtx
;
1285 /* XXX these may have to be removed due to thread-safety issues. */
1286 static GLXContext MakeCurrent_PrevContext
= 0;
1287 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1288 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1289 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1290 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1293 /* GLX 1.3 and later */
1295 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1296 GLXDrawable read
, GLXContext ctx
)
1298 if (ctx
&& draw
&& read
) {
1299 XMesaBuffer drawBuffer
, readBuffer
;
1300 XMesaContext xmctx
= (XMesaContext
) ctx
;
1302 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1303 if (ctx
== MakeCurrent_PrevContext
1304 && draw
== MakeCurrent_PrevDrawable
) {
1305 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1308 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1311 /* drawable must be a new window! */
1312 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1314 /* Out of memory, or context/drawable depth mismatch */
1319 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1320 if (ctx
== MakeCurrent_PrevContext
1321 && read
== MakeCurrent_PrevReadable
) {
1322 readBuffer
= MakeCurrent_PrevReadBuffer
;
1325 readBuffer
= XMesaFindBuffer( dpy
, read
);
1328 /* drawable must be a new window! */
1329 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1331 /* Out of memory, or context/drawable depth mismatch */
1336 MakeCurrent_PrevContext
= ctx
;
1337 MakeCurrent_PrevDrawable
= draw
;
1338 MakeCurrent_PrevReadable
= read
;
1339 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1340 MakeCurrent_PrevReadBuffer
= readBuffer
;
1342 /* Now make current! */
1343 return XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
);
1345 else if (!ctx
&& !draw
&& !read
) {
1346 /* release current context w/out assigning new one. */
1347 XMesaMakeCurrent( NULL
, NULL
);
1348 MakeCurrent_PrevContext
= 0;
1349 MakeCurrent_PrevDrawable
= 0;
1350 MakeCurrent_PrevReadable
= 0;
1351 MakeCurrent_PrevDrawBuffer
= 0;
1352 MakeCurrent_PrevReadBuffer
= 0;
1356 /* The args must either all be non-zero or all zero.
1365 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1367 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1372 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1377 v
= find_glx_visual( dpy
, visinfo
);
1379 v
= create_glx_visual( dpy
, visinfo
);
1381 /* unusable visual */
1386 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1390 return b
->frontxrb
->pixmap
;
1394 /*** GLX_MESA_pixmap_colormap ***/
1397 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1398 Pixmap pixmap
, Colormap cmap
)
1403 v
= find_glx_visual( dpy
, visinfo
);
1405 v
= create_glx_visual( dpy
, visinfo
);
1407 /* unusable visual */
1412 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1416 return b
->frontxrb
->pixmap
;
1421 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1423 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1425 XMesaDestroyBuffer(b
);
1427 else if (getenv("MESA_DEBUG")) {
1428 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1434 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1435 unsigned long mask
)
1437 XMesaContext xmSrc
= (XMesaContext
) src
;
1438 XMesaContext xmDst
= (XMesaContext
) dst
;
1440 if (MakeCurrent_PrevContext
== src
) {
1443 _mesa_copy_context( &xmSrc
->mesa
, &xmDst
->mesa
, (GLuint
) mask
);
1448 Fake_glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1451 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1452 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1458 return True
; /* we're faking GLX so always return success */
1462 extern void _kw_ungrab_all( Display
*dpy
);
1463 void _kw_ungrab_all( Display
*dpy
)
1465 XUngrabPointer( dpy
, CurrentTime
);
1466 XUngrabKeyboard( dpy
, CurrentTime
);
1471 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1475 MakeCurrent_PrevContext
= 0;
1476 MakeCurrent_PrevDrawable
= 0;
1477 MakeCurrent_PrevReadable
= 0;
1478 MakeCurrent_PrevDrawBuffer
= 0;
1479 MakeCurrent_PrevReadBuffer
= 0;
1480 XMesaDestroyContext((XMesaContext
) ctx
);
1481 XMesaGarbageCollect(dpy
);
1487 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1489 XMesaContext xmCtx
= (XMesaContext
) ctx
;
1490 return xmCtx
? xmCtx
->direct
: False
;
1496 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1498 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1501 XMesaSwapBuffers(buffer
);
1503 else if (getenv("MESA_DEBUG")) {
1504 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1511 /*** GLX_MESA_copy_sub_buffer ***/
1514 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1515 int x
, int y
, int width
, int height
)
1517 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1519 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1521 else if (getenv("MESA_DEBUG")) {
1522 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1528 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1531 /* Return GLX version, not Mesa version */
1532 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1533 *maj
= CLIENT_MAJOR_VERSION
;
1534 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1540 * Query the GLX attributes of the given XVisualInfo.
1543 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1549 return GLX_BAD_ATTRIBUTE
;
1550 *value
= (int) True
;
1552 case GLX_BUFFER_SIZE
:
1553 *value
= xmvis
->visinfo
->depth
;
1556 *value
= xmvis
->mesa_visual
.level
;
1560 return GLX_BAD_ATTRIBUTE
;
1561 if (xmvis
->mesa_visual
.rgbMode
) {
1568 case GLX_DOUBLEBUFFER
:
1569 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1572 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1574 case GLX_AUX_BUFFERS
:
1575 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1578 *value
= xmvis
->mesa_visual
.redBits
;
1580 case GLX_GREEN_SIZE
:
1581 *value
= xmvis
->mesa_visual
.greenBits
;
1584 *value
= xmvis
->mesa_visual
.blueBits
;
1586 case GLX_ALPHA_SIZE
:
1587 *value
= xmvis
->mesa_visual
.alphaBits
;
1589 case GLX_DEPTH_SIZE
:
1590 *value
= xmvis
->mesa_visual
.depthBits
;
1592 case GLX_STENCIL_SIZE
:
1593 *value
= xmvis
->mesa_visual
.stencilBits
;
1595 case GLX_ACCUM_RED_SIZE
:
1596 *value
= xmvis
->mesa_visual
.accumRedBits
;
1598 case GLX_ACCUM_GREEN_SIZE
:
1599 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1601 case GLX_ACCUM_BLUE_SIZE
:
1602 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1604 case GLX_ACCUM_ALPHA_SIZE
:
1605 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1609 * GLX_EXT_visual_info extension
1611 case GLX_X_VISUAL_TYPE_EXT
:
1612 switch (xmvis
->visinfo
->CLASS
) {
1613 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1614 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1615 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1616 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1617 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1618 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1621 case GLX_TRANSPARENT_TYPE_EXT
:
1622 if (xmvis
->mesa_visual
.level
==0) {
1624 *value
= GLX_NONE_EXT
;
1626 else if (xmvis
->mesa_visual
.level
>0) {
1628 if (xmvis
->mesa_visual
.rgbMode
) {
1629 *value
= GLX_TRANSPARENT_RGB_EXT
;
1632 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1635 else if (xmvis
->mesa_visual
.level
<0) {
1637 *value
= GLX_NONE_EXT
;
1640 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1642 int pixel
= transparent_pixel( xmvis
);
1646 /* else undefined */
1649 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1652 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1655 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1658 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1663 * GLX_EXT_visual_info extension
1665 case GLX_VISUAL_CAVEAT_EXT
:
1666 /* test for zero, just in case */
1667 if (xmvis
->mesa_visual
.visualRating
> 0)
1668 *value
= xmvis
->mesa_visual
.visualRating
;
1670 *value
= GLX_NONE_EXT
;
1674 * GLX_ARB_multisample
1676 case GLX_SAMPLE_BUFFERS_ARB
:
1679 case GLX_SAMPLES_ARB
:
1686 case GLX_SCREEN_EXT
:
1688 return GLX_BAD_ATTRIBUTE
;
1689 *value
= xmvis
->visinfo
->screen
;
1691 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1693 return GLX_BAD_ATTRIBUTE
;
1694 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1696 case GLX_RENDER_TYPE_SGIX
:
1698 return GLX_BAD_ATTRIBUTE
;
1699 if (xmvis
->mesa_visual
.floatMode
)
1700 *value
= GLX_RGBA_FLOAT_BIT_ARB
;
1701 else if (xmvis
->mesa_visual
.rgbMode
)
1702 *value
= GLX_RGBA_BIT
;
1704 *value
= GLX_COLOR_INDEX_BIT
;
1706 case GLX_X_RENDERABLE_SGIX
:
1708 return GLX_BAD_ATTRIBUTE
;
1709 *value
= True
; /* XXX really? */
1711 case GLX_FBCONFIG_ID_SGIX
:
1713 return GLX_BAD_ATTRIBUTE
;
1714 *value
= xmvis
->visinfo
->visualid
;
1716 case GLX_MAX_PBUFFER_WIDTH
:
1718 return GLX_BAD_ATTRIBUTE
;
1719 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1720 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1722 case GLX_MAX_PBUFFER_HEIGHT
:
1724 return GLX_BAD_ATTRIBUTE
;
1725 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1727 case GLX_MAX_PBUFFER_PIXELS
:
1729 return GLX_BAD_ATTRIBUTE
;
1730 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1731 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1735 return GLX_BAD_ATTRIBUTE
;
1736 *value
= xmvis
->visinfo
->visualid
;
1739 #ifdef GLX_EXT_texture_from_pixmap
1740 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1741 *value
= True
; /*XXX*/
1743 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1745 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1747 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1748 *value
= True
; /*XXX*/
1750 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1751 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1752 GLX_TEXTURE_2D_BIT_EXT
|
1753 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1755 case GLX_Y_INVERTED_EXT
:
1756 *value
= True
; /*XXX*/
1761 return GLX_BAD_ATTRIBUTE
;
1768 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1769 int attrib
, int *value
)
1773 if (!dpy
|| !visinfo
)
1774 return GLX_BAD_ATTRIBUTE
;
1776 xmvis
= find_glx_visual( dpy
, visinfo
);
1778 /* this visual wasn't obtained with glXChooseVisual */
1779 xmvis
= create_glx_visual( dpy
, visinfo
);
1781 /* this visual can't be used for GL rendering */
1782 if (attrib
==GLX_USE_GL
) {
1783 *value
= (int) False
;
1787 return GLX_BAD_VISUAL
;
1792 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1798 Fake_glXGetCurrentContext(void)
1800 XMesaContext xmesa
= XMesaGetCurrentContext();
1801 return (GLXContext
) xmesa
;
1805 Fake_glXWaitGL( void )
1807 XMesaContext xmesa
= XMesaGetCurrentContext();
1808 XMesaFlush( xmesa
);
1814 Fake_glXWaitX( void )
1816 XMesaContext xmesa
= XMesaGetCurrentContext();
1817 XMesaFlush( xmesa
);
1822 get_extensions( void )
1824 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
1829 /* GLX 1.1 and later */
1831 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1835 return get_extensions();
1840 /* GLX 1.1 and later */
1842 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1844 static char version
[1000];
1845 sprintf(version
, "%d.%d %s",
1846 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1852 case GLX_EXTENSIONS
:
1853 return get_extensions();
1865 /* GLX 1.1 and later */
1867 Fake_glXGetClientString( Display
*dpy
, int name
)
1869 static char version
[1000];
1870 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1871 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1876 case GLX_EXTENSIONS
:
1877 return get_extensions();
1895 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1896 int attribute
, int *value
)
1898 XMesaVisual v
= (XMesaVisual
) config
;
1902 if (!dpy
|| !config
|| !value
)
1905 return get_config(v
, attribute
, value
, GL_TRUE
);
1909 static GLXFBConfig
*
1910 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1912 XVisualInfo
*visuals
, visTemplate
;
1913 const long visMask
= VisualScreenMask
;
1916 /* Get list of all X visuals */
1917 visTemplate
.screen
= screen
;
1918 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1919 if (*nelements
> 0) {
1920 XMesaVisual
*results
;
1921 results
= malloc(*nelements
* sizeof(XMesaVisual
));
1926 for (i
= 0; i
< *nelements
; i
++) {
1927 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1929 return (GLXFBConfig
*) results
;
1935 static GLXFBConfig
*
1936 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1937 const int *attribList
, int *nitems
)
1941 /* register ourselves as an extension on this display */
1942 register_with_display(dpy
);
1944 if (!attribList
|| !attribList
[0]) {
1945 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1946 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
1949 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1951 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1957 config
[0] = (GLXFBConfig
) xmvis
;
1958 return (GLXFBConfig
*) config
;
1967 static XVisualInfo
*
1968 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1970 if (dpy
&& config
) {
1971 XMesaVisual xmvis
= (XMesaVisual
) config
;
1972 XVisualInfo
* visinfo
= malloc(sizeof(XVisualInfo
));
1974 memcpy(visinfo
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1985 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1986 const int *attribList
)
1988 XMesaVisual xmvis
= (XMesaVisual
) config
;
1993 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1998 (void) attribList
; /* Ignored in GLX 1.3 */
2000 return win
; /* A hack for now */
2005 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
2007 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
2009 XMesaDestroyBuffer(b
);
2010 /* don't destroy X window */
2016 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2017 const int *attribList
)
2019 XMesaVisual v
= (XMesaVisual
) config
;
2022 int target
= 0, format
= 0, mipmap
= 0;
2025 if (!dpy
|| !config
|| !pixmap
)
2028 for (attr
= attribList
; attr
&& *attr
; attr
++) {
2030 case GLX_TEXTURE_FORMAT_EXT
:
2033 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2034 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2035 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2043 case GLX_TEXTURE_TARGET_EXT
:
2046 case GLX_TEXTURE_1D_EXT
:
2047 case GLX_TEXTURE_2D_EXT
:
2048 case GLX_TEXTURE_RECTANGLE_EXT
:
2056 case GLX_MIPMAP_TEXTURE_EXT
:
2067 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2068 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2069 &value
, GL_TRUE
) != Success
2071 return 0; /* error! */
2074 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2075 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2076 &value
, GL_TRUE
) != Success
2078 return 0; /* error! */
2082 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2083 &value
, GL_TRUE
) != Success
2085 return 0; /* error! */
2088 if (target
== GLX_TEXTURE_1D_EXT
) {
2089 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2090 &value
, GL_TRUE
) != Success
2091 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2092 return 0; /* error! */
2095 else if (target
== GLX_TEXTURE_2D_EXT
) {
2096 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2097 &value
, GL_TRUE
) != Success
2098 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2099 return 0; /* error! */
2102 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2103 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2104 &value
, GL_TRUE
) != Success
2105 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2106 return 0; /* error! */
2110 if (format
|| target
|| mipmap
) {
2111 /* texture from pixmap */
2112 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2115 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2126 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2128 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2130 XMesaDestroyBuffer(b
);
2131 /* don't destroy X pixmap */
2136 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2137 const int *attribList
)
2139 XMesaVisual xmvis
= (XMesaVisual
) config
;
2142 int width
= 0, height
= 0;
2143 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2147 for (attrib
= attribList
; *attrib
; attrib
++) {
2149 case GLX_PBUFFER_WIDTH
:
2153 case GLX_PBUFFER_HEIGHT
:
2157 case GLX_PRESERVED_CONTENTS
:
2159 preserveContents
= *attrib
;
2161 case GLX_LARGEST_PBUFFER
:
2163 useLargest
= *attrib
;
2170 if (width
== 0 || height
== 0)
2173 if (width
> SWRAST_MAX_WIDTH
|| height
> SWRAST_MAX_HEIGHT
) {
2174 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2175 * allocate the largest possible buffer.
2178 width
= SWRAST_MAX_WIDTH
;
2179 height
= SWRAST_MAX_HEIGHT
;
2183 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2184 /* A GLXPbuffer handle must be an X Drawable because that's what
2185 * glXMakeCurrent takes.
2188 xmbuf
->largestPbuffer
= useLargest
;
2189 xmbuf
->preservedContents
= preserveContents
;
2190 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2199 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2201 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2203 XMesaDestroyBuffer(b
);
2209 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2210 unsigned int *value
)
2212 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2216 /* make sure buffer's dimensions are up to date */
2217 xmesa_check_and_update_buffer_size(NULL
, xmbuf
);
2219 switch (attribute
) {
2221 *value
= xmbuf
->mesa_buffer
.Width
;
2224 *value
= xmbuf
->mesa_buffer
.Height
;
2226 case GLX_PRESERVED_CONTENTS
:
2227 *value
= xmbuf
->preservedContents
;
2229 case GLX_LARGEST_PBUFFER
:
2230 *value
= xmbuf
->largestPbuffer
;
2232 case GLX_FBCONFIG_ID
:
2233 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2235 #ifdef GLX_EXT_texture_from_pixmap
2236 case GLX_TEXTURE_FORMAT_EXT
:
2237 *value
= xmbuf
->TextureFormat
;
2239 case GLX_TEXTURE_TARGET_EXT
:
2240 *value
= xmbuf
->TextureTarget
;
2242 case GLX_MIPMAP_TEXTURE_EXT
:
2243 *value
= xmbuf
->TextureMipmap
;
2248 return; /* raise BadValue error */
2254 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2255 int renderType
, GLXContext shareList
, Bool direct
)
2258 XMesaVisual xmvis
= (XMesaVisual
) config
;
2260 if (!dpy
|| !config
||
2261 (renderType
!= GLX_RGBA_TYPE
&&
2262 renderType
!= GLX_COLOR_INDEX_TYPE
&&
2263 renderType
!= GLX_RGBA_FLOAT_TYPE_ARB
&&
2264 renderType
!= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
))
2267 /* deallocate unused windows/buffers */
2268 XMesaGarbageCollect(dpy
);
2270 xmCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) shareList
);
2272 return (GLXContext
) xmCtx
;
2277 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2279 XMesaContext xmctx
= (XMesaContext
) ctx
;
2283 switch (attribute
) {
2284 case GLX_FBCONFIG_ID
:
2285 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2287 case GLX_RENDER_TYPE
:
2288 *value
= GLX_RGBA_TYPE
;
2294 return GLX_BAD_ATTRIBUTE
;
2301 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2303 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2305 xmbuf
->selectedEvents
= mask
;
2310 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2311 unsigned long *mask
)
2313 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2315 *mask
= xmbuf
->selectedEvents
;
2322 /*** GLX_SGI_swap_control ***/
2325 Fake_glXSwapIntervalSGI(int interval
)
2333 /*** GLX_SGI_video_sync ***/
2335 static unsigned int FrameCounter
= 0;
2338 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2340 /* this is a bogus implementation */
2341 *count
= FrameCounter
++;
2346 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2348 if (divisor
<= 0 || remainder
< 0)
2349 return GLX_BAD_VALUE
;
2350 /* this is a bogus implementation */
2352 while (FrameCounter
% divisor
!= remainder
)
2354 *count
= FrameCounter
;
2360 /*** GLX_SGI_make_current_read ***/
2363 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2365 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2370 Fake_glXGetCurrentReadDrawableSGI(void)
2377 /*** GLX_SGIX_video_source ***/
2380 static GLXVideoSourceSGIX
2381 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2393 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2402 /*** GLX_EXT_import_context ***/
2405 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2412 Fake_glXGetContextIDEXT(const GLXContext context
)
2419 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2427 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2438 /*** GLX_SGIX_fbconfig ***/
2441 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2443 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2446 static GLXFBConfigSGIX
*
2447 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2449 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2454 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2456 XMesaVisual xmvis
= (XMesaVisual
) config
;
2457 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2458 return xmbuf
->frontxrb
->pixmap
; /* need to return an X ID */
2463 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2466 XMesaVisual xmvis
= (XMesaVisual
) config
;
2468 /* deallocate unused windows/buffers */
2469 XMesaGarbageCollect(dpy
);
2471 xmCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) share_list
);
2473 return (GLXContext
) xmCtx
;
2477 static XVisualInfo
*
2478 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2480 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2484 static GLXFBConfigSGIX
2485 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2487 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2489 /* This visual wasn't found with glXChooseVisual() */
2490 xmvis
= create_glx_visual(dpy
, vis
);
2493 return (GLXFBConfigSGIX
) xmvis
;
2498 /*** GLX_SGIX_pbuffer ***/
2500 static GLXPbufferSGIX
2501 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2502 unsigned int width
, unsigned int height
,
2505 XMesaVisual xmvis
= (XMesaVisual
) config
;
2508 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2512 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2514 case GLX_PRESERVED_CONTENTS_SGIX
:
2516 preserveContents
= *attrib
; /* ignored */
2518 case GLX_LARGEST_PBUFFER_SGIX
:
2520 useLargest
= *attrib
; /* ignored */
2527 /* not used at this time */
2529 (void) preserveContents
;
2531 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2532 /* A GLXPbuffer handle must be an X Drawable because that's what
2533 * glXMakeCurrent takes.
2535 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2540 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2542 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2544 XMesaDestroyBuffer(xmbuf
);
2550 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2552 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2555 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2559 switch (attribute
) {
2560 case GLX_PRESERVED_CONTENTS_SGIX
:
2561 *value
= xmbuf
->preservedContents
;
2563 case GLX_LARGEST_PBUFFER_SGIX
:
2564 *value
= xmbuf
->largestPbuffer
;
2566 case GLX_WIDTH_SGIX
:
2567 *value
= xmbuf
->mesa_buffer
.Width
;
2569 case GLX_HEIGHT_SGIX
:
2570 *value
= xmbuf
->mesa_buffer
.Height
;
2572 case GLX_EVENT_MASK_SGIX
:
2573 *value
= 0; /* XXX might be wrong */
2583 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2585 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2587 /* Note: we'll never generate clobber events */
2588 xmbuf
->selectedEvents
= mask
;
2594 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2596 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2598 *mask
= xmbuf
->selectedEvents
;
2607 /*** GLX_SGI_cushion ***/
2610 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2619 /*** GLX_SGIX_video_resize ***/
2622 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2632 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2645 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2658 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2671 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2682 /*** GLX_SGIX_dmbuffer **/
2684 #if defined(_DM_BUFFER_H_)
2686 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2697 /*** GLX_SGIX_swap_group ***/
2700 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2709 /*** GLX_SGIX_swap_barrier ***/
2712 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2720 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2730 /*** GLX_SUN_get_transparent_index ***/
2733 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2738 (void) pTransparent
;
2744 /*** GLX_MESA_release_buffers ***/
2747 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2748 * (a window or pixmap) prior to destroying the GLXDrawable.
2751 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2753 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2755 XMesaDestroyBuffer(b
);
2763 /*** GLX_MESA_set_3dfx_mode ***/
2766 Fake_glXSet3DfxModeMESA( int mode
)
2768 return XMesaSetFXmode( mode
);
2773 /*** GLX_NV_vertex_array range ***/
2775 Fake_glXAllocateMemoryNV( GLsizei size
,
2776 GLfloat readFrequency
,
2777 GLfloat writeFrequency
,
2781 (void) readFrequency
;
2782 (void) writeFrequency
;
2789 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2795 /*** GLX_MESA_agp_offset ***/
2798 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
2805 /*** GLX_EXT_texture_from_pixmap ***/
2808 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2809 const int *attrib_list
)
2811 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2813 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2817 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2819 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2821 XMesaReleaseTexImage(dpy
, b
, buffer
);
2826 Fake_glXCreateContextAttribs(Display
*dpy
, GLXFBConfig config
,
2827 GLXContext share_context
, Bool direct
,
2828 const int *attrib_list
)
2831 XMesaVisual xmvis
= (XMesaVisual
) config
;
2833 int major
= 0, minor
= 0, ctxFlags
= 0, profileFlags
= 0;
2835 for (i
= 0; attrib_list
[i
]; i
+= 2) {
2836 switch (attrib_list
[i
]) {
2837 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2838 major
= attrib_list
[i
+ 1];
2840 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2841 minor
= attrib_list
[i
+ 1];
2843 case GLX_CONTEXT_FLAGS_ARB
:
2844 ctxFlags
= attrib_list
[i
+ 1];
2846 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2847 profileFlags
= attrib_list
[i
+ 1];
2850 fprintf(stderr
, "Bad attribute in glXCreateContextAttribs()\n");
2855 if (major
* 10 + minor
> 21) {
2856 /* swrast only supports GL 2.1 and earlier */
2860 /* These are ignored for now. We'd have to enhance XMesaCreateContext
2861 * to take these flags and the version, at least.
2864 (void) profileFlags
;
2866 /* deallocate unused windows/buffers */
2867 XMesaGarbageCollect(dpy
);
2869 xmCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) share_context
);
2871 return (GLXContext
) xmCtx
;
2875 /* silence warning */
2876 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2880 * Create a new GLX API dispatch table with its function pointers
2881 * initialized to point to Mesa's "fake" GLX API functions.
2882 * Note: there's a similar function (_real_GetGLXDispatchTable) that
2883 * returns a new dispatch table with all pointers initalized to point
2884 * to "real" GLX functions (which understand GLX wire protocol, etc).
2886 struct _glxapi_table
*
2887 _mesa_GetGLXDispatchTable(void)
2889 static struct _glxapi_table glx
;
2891 /* be sure our dispatch table size <= libGL's table */
2893 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2895 assert(_glxapi_get_dispatch_table_size() >= size
);
2898 /* initialize the whole table to no-ops */
2899 _glxapi_set_no_op_table(&glx
);
2901 /* now initialize the table with the functions I implement */
2902 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2903 glx
.CopyContext
= Fake_glXCopyContext
;
2904 glx
.CreateContext
= Fake_glXCreateContext
;
2905 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2906 glx
.DestroyContext
= Fake_glXDestroyContext
;
2907 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2908 glx
.GetConfig
= Fake_glXGetConfig
;
2909 glx
.GetCurrentContext
= Fake_glXGetCurrentContext
;
2910 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2911 glx
.IsDirect
= Fake_glXIsDirect
;
2912 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2913 glx
.QueryExtension
= Fake_glXQueryExtension
;
2914 glx
.QueryVersion
= Fake_glXQueryVersion
;
2915 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2916 glx
.UseXFont
= Fake_glXUseXFont
;
2917 glx
.WaitGL
= Fake_glXWaitGL
;
2918 glx
.WaitX
= Fake_glXWaitX
;
2920 /*** GLX_VERSION_1_1 ***/
2921 glx
.GetClientString
= Fake_glXGetClientString
;
2922 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2923 glx
.QueryServerString
= Fake_glXQueryServerString
;
2925 /*** GLX_VERSION_1_2 ***/
2926 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2928 /*** GLX_VERSION_1_3 ***/
2929 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2930 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2931 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2932 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2933 glx
.CreateWindow
= Fake_glXCreateWindow
;
2934 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2935 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2936 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2937 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2938 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2939 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2940 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2941 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2942 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2943 glx
.QueryContext
= Fake_glXQueryContext
;
2944 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2945 glx
.SelectEvent
= Fake_glXSelectEvent
;
2947 /*** GLX_SGI_swap_control ***/
2948 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2950 /*** GLX_SGI_video_sync ***/
2951 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2952 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2954 /*** GLX_SGI_make_current_read ***/
2955 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2956 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2958 /*** GLX_SGIX_video_source ***/
2960 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2961 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2964 /*** GLX_EXT_import_context ***/
2965 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2966 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2967 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2968 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2969 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2971 /*** GLX_SGIX_fbconfig ***/
2972 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2973 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2974 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2975 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
2976 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
2977 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
2979 /*** GLX_SGIX_pbuffer ***/
2980 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
2981 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
2982 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
2983 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
2984 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
2986 /*** GLX_SGI_cushion ***/
2987 glx
.CushionSGI
= Fake_glXCushionSGI
;
2989 /*** GLX_SGIX_video_resize ***/
2990 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
2991 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
2992 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
2993 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
2994 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
2996 /*** GLX_SGIX_dmbuffer **/
2997 #if defined(_DM_BUFFER_H_)
2998 glx
.AssociateDMPbufferSGIX
= NULL
;
3001 /*** GLX_SGIX_swap_group ***/
3002 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
3004 /*** GLX_SGIX_swap_barrier ***/
3005 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
3006 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
3008 /*** GLX_SUN_get_transparent_index ***/
3009 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
3011 /*** GLX_MESA_copy_sub_buffer ***/
3012 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3014 /*** GLX_MESA_release_buffers ***/
3015 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3017 /*** GLX_MESA_pixmap_colormap ***/
3018 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3020 /*** GLX_MESA_set_3dfx_mode ***/
3021 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3023 /*** GLX_NV_vertex_array_range ***/
3024 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3025 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3027 /*** GLX_MESA_agp_offset ***/
3028 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3030 /*** GLX_EXT_texture_from_pixmap ***/
3031 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3032 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;
3034 glx
.CreateContextAttribs
= Fake_glXCreateContextAttribs
;