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
;
261 /* Check if the MESA_BACK_BUFFER env var is set */
262 char *backbuffer
= getenv("MESA_BACK_BUFFER");
264 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
265 ximageFlag
= GL_FALSE
;
267 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
268 ximageFlag
= GL_TRUE
;
271 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
277 /* stereo not supported */
282 /* Force the visual to have an alpha channel */
283 if (getenv("MESA_GLX_FORCE_ALPHA"))
286 /* Comparing IDs uses less memory but sometimes fails. */
287 /* XXX revisit this after 3.0 is finished. */
288 if (!getenv("MESA_GLX_VISUAL_HACK")) {
289 /* First check if a matching visual is already in the list */
290 for (i
=0; i
<NumVisuals
; i
++) {
291 XMesaVisual v
= VisualTable
[i
];
292 if (v
->display
== dpy
293 && v
->mesa_visual
.level
== level
294 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
295 && v
->ximage_flag
== ximageFlag
296 && v
->mesa_visual
.doubleBufferMode
== dbFlag
297 && v
->mesa_visual
.stereoMode
== stereoFlag
298 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
299 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
300 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
301 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
302 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
303 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
304 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
305 /* now compare visual IDs */
306 if (v
->visinfo
->visualid
== vinfo
->visualid
) {
313 /* Create a new visual and add it to the list. */
315 xmvis
= XMesaCreateVisual( dpy
, vinfo
, GL_TRUE
, alphaFlag
, dbFlag
,
316 stereoFlag
, ximageFlag
,
317 depth_size
, stencil_size
,
318 accumRedSize
, accumBlueSize
,
319 accumBlueSize
, accumAlphaSize
, 0, level
,
322 /* Allocate more space for additional visual */
323 VisualTable
= realloc(VisualTable
, sizeof(XMesaVisual
) * (NumVisuals
+ 1));
324 /* add xmvis to the list */
325 VisualTable
[NumVisuals
] = xmvis
;
327 /* XXX minor hack, because XMesaCreateVisual doesn't support an
328 * aux buffers parameter.
330 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
337 * Return the default number of bits for the Z buffer.
338 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
339 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
340 * XXX probably do the same thing for stencil, accum, etc.
343 default_depth_bits(void)
346 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
350 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
355 default_alpha_bits(void)
358 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
367 default_accum_bits(void)
375 * Create a GLX visual from a regular XVisualInfo.
376 * This is called when Fake GLX is given an XVisualInfo which wasn't
377 * returned by glXChooseVisual. Since this is the first time we're
378 * considering this visual we'll take a guess at reasonable values
379 * for depth buffer size, stencil size, accum size, etc.
380 * This is the best we can do with a client-side emulation of GLX.
383 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
386 GLint zBits
= default_depth_bits();
387 GLint accBits
= default_accum_bits();
388 GLboolean alphaFlag
= default_alpha_bits() > 0;
390 vislevel
= level_of_visual( dpy
, visinfo
);
392 /* Color-index rendering to overlays is not supported. */
395 else if (is_usable_visual( visinfo
)) {
396 /* Configure this visual as RGB, double-buffered, depth-buffered. */
397 /* This is surely wrong for some people's needs but what else */
398 /* can be done? They should use glXChooseVisual(). */
399 return save_glx_visual( dpy
, visinfo
,
400 alphaFlag
, /* alpha */
401 GL_TRUE
, /* double */
402 GL_FALSE
, /* stereo */
404 8, /* stencil bits */
414 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
422 * Find the GLX visual associated with an XVisualInfo.
425 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
429 /* try to match visual id */
430 for (i
=0;i
<NumVisuals
;i
++) {
431 if (VisualTable
[i
]->display
==dpy
432 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
433 return VisualTable
[i
];
443 * Return the transparent pixel value for a GLX visual.
444 * Input: glxvis - the glx_visual
445 * Return: a pixel value or -1 if no transparent pixel
448 transparent_pixel( XMesaVisual glxvis
)
450 Display
*dpy
= glxvis
->display
;
451 XVisualInfo
*vinfo
= glxvis
->visinfo
;
452 OverlayInfo
*overlay_info
;
453 int numOverlaysPerScreen
, i
;
455 overlay_info
= GetOverlayInfo(dpy
, vinfo
->screen
, &numOverlaysPerScreen
);
460 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
461 const OverlayInfo
*ov
= overlay_info
+ i
;
462 if (ov
->overlay_visual
== vinfo
->visualid
) {
464 if (ov
->transparent_type
== 0) {
465 /* type 0 indicates no transparency */
466 free((void *) overlay_info
);
470 /* ov->value is the transparent pixel */
471 free((void *) overlay_info
);
477 /* The visual ID was not found in the overlay list. */
478 free((void *) overlay_info
);
485 * Try to get an X visual which matches the given arguments.
488 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
490 XVisualInfo temp
, *vis
;
493 unsigned int default_depth
;
496 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
501 default_depth
= DefaultDepth(dpy
,scr
);
502 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
504 if (depth
==default_depth
&& xclass
==default_class
) {
505 /* try to get root window's visual */
506 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
507 mask
|= VisualIDMask
;
510 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
512 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
513 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
514 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
516 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
517 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
518 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
519 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
534 * Retrieve the value of the given environment variable and find
535 * the X visual which matches it.
536 * Input: dpy - the display
537 * screen - the screen number
538 * varname - the name of the environment variable
539 * Return: an XVisualInfo pointer to NULL if error.
542 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
544 char value
[100], type
[100];
545 int depth
, xclass
= -1;
548 if (!getenv( varname
)) {
552 strncpy( value
, getenv(varname
), 100 );
555 sscanf( value
, "%s %d", type
, &depth
);
557 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
558 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
559 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
560 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
562 if (xclass
>-1 && depth
>0) {
563 vis
= get_visual( dpy
, scr
, depth
, xclass
);
569 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
578 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
579 * Input: dpy, screen - X display and screen number
580 * min_depth - minimum visual depth
581 * preferred_class - preferred GLX visual class or DONT_CARE
582 * Return: pointer to an XVisualInfo or NULL.
585 choose_x_visual(Display
*dpy
, int screen
, int min_depth
, int preferred_class
)
588 int xclass
, visclass
= 0;
591 /* First see if the MESA_RGB_VISUAL env var is defined */
592 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
596 /* Otherwise, search for a suitable visual */
597 if (preferred_class
==DONT_CARE
) {
598 for (xclass
=0;xclass
<4;xclass
++) {
600 case 0: visclass
= TrueColor
; break;
601 case 1: visclass
= DirectColor
; break;
602 case 2: visclass
= GrayScale
; break;
603 case 3: visclass
= StaticGray
; break;
606 /* start with shallowest */
607 for (depth
=0;depth
<=32;depth
++) {
608 vis
= get_visual( dpy
, screen
, depth
, visclass
);
615 /* start with deepest */
616 for (depth
=32;depth
>=min_depth
;depth
--) {
617 vis
= get_visual( dpy
, screen
, depth
, visclass
);
626 /* search for a specific visual class */
627 switch (preferred_class
) {
628 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
629 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
630 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
631 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
632 case GLX_PSEUDO_COLOR_EXT
:
633 case GLX_STATIC_COLOR_EXT
:
634 default: return NULL
;
637 /* start with shallowest */
638 for (depth
=0;depth
<=32;depth
++) {
639 vis
= get_visual( dpy
, screen
, depth
, visclass
);
646 /* start with deepest */
647 for (depth
=32;depth
>=min_depth
;depth
--) {
648 vis
= get_visual( dpy
, screen
, depth
, visclass
);
656 /* didn't find a visual */
663 * Find the deepest X over/underlay visual of at least min_depth.
664 * Input: dpy, screen - X display and screen number
665 * level - the over/underlay level
666 * trans_type - transparent pixel type: GLX_NONE_EXT,
667 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
669 * trans_value - transparent pixel value or DONT_CARE
670 * min_depth - minimum visual depth
671 * preferred_class - preferred GLX visual class or DONT_CARE
672 * Return: pointer to an XVisualInfo or NULL.
675 choose_x_overlay_visual( Display
*dpy
, int scr
,
676 int level
, int trans_type
, int trans_value
,
677 int min_depth
, int preferred_class
)
679 OverlayInfo
*overlay_info
;
680 int numOverlaysPerScreen
;
682 XVisualInfo
*deepvis
;
685 /*DEBUG int tt, tv; */
687 switch (preferred_class
) {
688 case GLX_TRUE_COLOR_EXT
: preferred_class
= TrueColor
; break;
689 case GLX_DIRECT_COLOR_EXT
: preferred_class
= DirectColor
; break;
690 case GLX_PSEUDO_COLOR_EXT
: preferred_class
= PseudoColor
; break;
691 case GLX_STATIC_COLOR_EXT
: preferred_class
= StaticColor
; break;
692 case GLX_GRAY_SCALE_EXT
: preferred_class
= GrayScale
; break;
693 case GLX_STATIC_GRAY_EXT
: preferred_class
= StaticGray
; break;
694 default: preferred_class
= DONT_CARE
;
697 overlay_info
= GetOverlayInfo(dpy
, scr
, &numOverlaysPerScreen
);
702 /* Search for the deepest overlay which satisifies all criteria. */
706 for (i
= 0; i
< numOverlaysPerScreen
; i
++) {
707 const OverlayInfo
*ov
= overlay_info
+ i
;
708 XVisualInfo
*vislist
, vistemplate
;
711 if (ov
->layer
!=level
) {
712 /* failed overlay level criteria */
715 if (!(trans_type
==DONT_CARE
716 || (trans_type
==GLX_TRANSPARENT_INDEX_EXT
717 && ov
->transparent_type
>0)
718 || (trans_type
==GLX_NONE_EXT
&& ov
->transparent_type
==0))) {
719 /* failed transparent pixel type criteria */
722 if (trans_value
!=DONT_CARE
&& trans_value
!=ov
->value
) {
723 /* failed transparent pixel value criteria */
727 /* get XVisualInfo and check the depth */
728 vistemplate
.visualid
= ov
->overlay_visual
;
729 vistemplate
.screen
= scr
;
730 vislist
= XGetVisualInfo( dpy
, VisualIDMask
| VisualScreenMask
,
731 &vistemplate
, &count
);
734 /* something went wrong */
737 if (preferred_class
!=DONT_CARE
&& preferred_class
!=vislist
->CLASS
) {
738 /* wrong visual class */
742 /* Color-index rendering is not supported. Make sure we have True/DirectColor */
743 if (vislist
->CLASS
!= TrueColor
&& vislist
->CLASS
!= DirectColor
)
746 if (deepvis
==NULL
|| vislist
->depth
> deepest
) {
747 /* YES! found a satisfactory visual */
749 deepest
= vislist
->depth
;
751 /* DEBUG tt = ov->transparent_type;*/
752 /* DEBUG tv = ov->value; */
758 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
759 deepvis->visualid, level, deepvis->depth, tt, tv );
766 /**********************************************************************/
767 /*** Display-related functions ***/
768 /**********************************************************************/
772 * Free all XMesaVisuals which are associated with the given display.
775 destroy_visuals_on_display(Display
*dpy
)
778 for (i
= 0; i
< NumVisuals
; i
++) {
779 if (VisualTable
[i
]->display
== dpy
) {
780 /* remove this visual */
782 XMesaDestroyVisual(VisualTable
[i
]);
783 for (j
= i
; j
< NumVisuals
- 1; j
++)
784 VisualTable
[j
] = VisualTable
[j
+ 1];
792 * Called from XCloseDisplay() to let us free our display-related data.
795 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
797 destroy_visuals_on_display(dpy
);
798 xmesa_destroy_buffers_on_display(dpy
);
804 * Look for the named extension on given display and return a pointer
805 * to the _XExtension data, or NULL if extension not found.
808 lookup_extension(Display
*dpy
, const char *extName
)
811 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
812 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
821 * Whenever we're given a new Display pointer, call this function to
822 * register our close_display_callback function.
825 register_with_display(Display
*dpy
)
827 const char *extName
= "MesaGLX";
830 ext
= lookup_extension(dpy
, extName
);
832 XExtCodes
*c
= XAddExtension(dpy
);
833 ext
= dpy
->ext_procs
; /* new extension is at head of list */
834 assert(c
->extension
== ext
->codes
.extension
);
835 (void) c
; /* silence warning */
836 ext
->name
= strdup(extName
);
837 ext
->close_display
= close_display_callback
;
842 /**********************************************************************/
843 /*** Begin Fake GLX API Functions ***/
844 /**********************************************************************/
848 * Helper used by glXChooseVisual and glXChooseFBConfig.
849 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
851 * In either case, the attribute list is terminated with the value 'None'.
854 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
856 const GLboolean rgbModeDefault
= fbConfig
;
857 const int *parselist
;
860 int min_red
=0, min_green
=0, min_blue
=0;
861 GLboolean rgb_flag
= rgbModeDefault
;
862 GLboolean alpha_flag
= GL_FALSE
;
863 GLboolean double_flag
= GL_FALSE
;
864 GLboolean stereo_flag
= GL_FALSE
;
865 GLint depth_size
= 0;
866 GLint stencil_size
= 0;
867 GLint accumRedSize
= 0;
868 GLint accumGreenSize
= 0;
869 GLint accumBlueSize
= 0;
870 GLint accumAlphaSize
= 0;
872 int visual_type
= DONT_CARE
;
873 int trans_type
= DONT_CARE
;
874 int trans_value
= DONT_CARE
;
875 GLint caveat
= DONT_CARE
;
876 XMesaVisual xmvis
= NULL
;
877 int desiredVisualID
= -1;
885 parselist
[1] == GLX_DONT_CARE
&&
886 parselist
[0] != GLX_LEVEL
) {
887 /* For glXChooseFBConfig(), skip attributes whose value is
888 * GLX_DONT_CARE (-1), unless it's GLX_LEVEL (which can legitimately be
891 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
892 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
898 switch (*parselist
) {
909 case GLX_BUFFER_SIZE
:
911 min_ci
= *parselist
++;
915 level
= *parselist
++;
927 case GLX_DOUBLEBUFFER
:
930 double_flag
= *parselist
++;
933 double_flag
= GL_TRUE
;
939 stereo_flag
= *parselist
++;
942 stereo_flag
= GL_TRUE
;
945 case GLX_AUX_BUFFERS
:
947 numAux
= *parselist
++;
948 if (numAux
> MAX_AUX_BUFFERS
)
953 min_red
= *parselist
++;
957 min_green
= *parselist
++;
961 min_blue
= *parselist
++;
966 GLint size
= *parselist
++;
967 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
972 depth_size
= *parselist
++;
974 case GLX_STENCIL_SIZE
:
976 stencil_size
= *parselist
++;
978 case GLX_ACCUM_RED_SIZE
:
981 GLint size
= *parselist
++;
982 accumRedSize
= MAX2( accumRedSize
, size
);
985 case GLX_ACCUM_GREEN_SIZE
:
988 GLint size
= *parselist
++;
989 accumGreenSize
= MAX2( accumGreenSize
, size
);
992 case GLX_ACCUM_BLUE_SIZE
:
995 GLint size
= *parselist
++;
996 accumBlueSize
= MAX2( accumBlueSize
, size
);
999 case GLX_ACCUM_ALPHA_SIZE
:
1002 GLint size
= *parselist
++;
1003 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
1008 * GLX_EXT_visual_info extension
1010 case GLX_X_VISUAL_TYPE_EXT
:
1012 visual_type
= *parselist
++;
1014 case GLX_TRANSPARENT_TYPE_EXT
:
1016 trans_type
= *parselist
++;
1018 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1020 trans_value
= *parselist
++;
1022 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1023 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1024 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1025 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1032 * GLX_EXT_visual_info extension
1034 case GLX_VISUAL_CAVEAT_EXT
:
1036 caveat
= *parselist
++; /* ignored for now */
1040 * GLX_ARB_multisample
1042 case GLX_SAMPLE_BUFFERS_ARB
:
1043 case GLX_SAMPLES_ARB
:
1045 if (*parselist
++ != 0)
1046 /* ms not supported */
1053 case GLX_RENDER_TYPE
:
1057 if (*parselist
& GLX_RGBA_BIT
) {
1060 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
1061 rgb_flag
= GL_FALSE
;
1063 else if (*parselist
& (GLX_RGBA_FLOAT_BIT_ARB
|GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT
)) {
1066 else if (*parselist
== 0) {
1071 case GLX_DRAWABLE_TYPE
:
1075 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
1076 return NULL
; /* bad bit */
1080 case GLX_FBCONFIG_ID
:
1085 desiredVisualID
= *parselist
++;
1087 case GLX_X_RENDERABLE
:
1088 case GLX_MAX_PBUFFER_WIDTH
:
1089 case GLX_MAX_PBUFFER_HEIGHT
:
1090 case GLX_MAX_PBUFFER_PIXELS
:
1097 #ifdef GLX_EXT_texture_from_pixmap
1098 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1099 parselist
++; /*skip*/
1101 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1102 parselist
++; /*skip*/
1104 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1105 parselist
++; /*skip*/
1107 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1109 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
1110 GLX_TEXTURE_2D_BIT_EXT
|
1111 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
1116 case GLX_Y_INVERTED_EXT
:
1117 parselist
++; /*skip*/
1126 /* undefined attribute */
1127 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
1140 * Since we're only simulating the GLX extension this function will never
1141 * find any real GL visuals. Instead, all we can do is try to find an RGB
1142 * or CI visual of appropriate depth. Other requested attributes such as
1143 * double buffering, depth buffer, etc. will be associated with the X
1144 * visual and stored in the VisualTable[].
1146 if (desiredVisualID
!= -1) {
1147 /* try to get a specific visual, by visualID */
1150 temp
.visualid
= desiredVisualID
;
1151 temp
.screen
= screen
;
1152 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1154 /* give the visual some useful GLX attributes */
1155 double_flag
= GL_TRUE
;
1156 if (vis
->depth
<= 8)
1158 depth_size
= default_depth_bits();
1165 int min_rgb
= min_red
+ min_green
+ min_blue
;
1166 if (min_rgb
>1 && min_rgb
<8) {
1167 /* a special case to be sure we can get a monochrome visual */
1172 vis
= choose_x_visual(dpy
, screen
, min_rgb
, visual_type
);
1175 vis
= choose_x_overlay_visual(dpy
, screen
, level
,
1176 trans_type
, trans_value
, min_rgb
, visual_type
);
1181 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1182 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1183 * largest depth buffer size, which is 32bits/value. Instead, we
1184 * return 16 to maintain performance with earlier versions of Mesa.
1186 if (depth_size
> 24)
1188 else if (depth_size
> 16)
1190 else if (depth_size
> 0) {
1191 depth_size
= default_depth_bits();
1195 alpha_flag
= default_alpha_bits() > 0;
1198 /* we only support one size of stencil and accum buffers. */
1199 if (stencil_size
> 0)
1201 if (accumRedSize
> 0 || accumGreenSize
> 0 || accumBlueSize
> 0 ||
1202 accumAlphaSize
> 0) {
1205 accumBlueSize
= default_accum_bits();
1206 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1209 xmvis
= save_glx_visual( dpy
, vis
, alpha_flag
, double_flag
,
1210 stereo_flag
, depth_size
, stencil_size
,
1211 accumRedSize
, accumGreenSize
,
1212 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1220 static XVisualInfo
*
1221 Fake_glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1225 /* register ourselves as an extension on this display */
1226 register_with_display(dpy
);
1228 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1230 XVisualInfo
* visinfo
= malloc(sizeof(XVisualInfo
));
1232 memcpy(visinfo
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1242 Fake_glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1243 GLXContext share_list
, Bool direct
)
1246 XMesaContext xmesaCtx
;
1248 if (!dpy
|| !visinfo
)
1251 /* deallocate unused windows/buffers */
1253 XMesaGarbageCollect(dpy
);
1256 xmvis
= find_glx_visual( dpy
, visinfo
);
1258 /* This visual wasn't found with glXChooseVisual() */
1259 xmvis
= create_glx_visual( dpy
, visinfo
);
1265 xmesaCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) share_list
);
1267 return (GLXContext
) xmesaCtx
;
1271 /* XXX these may have to be removed due to thread-safety issues. */
1272 static GLXContext MakeCurrent_PrevContext
= 0;
1273 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1274 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1275 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1276 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1279 /* GLX 1.3 and later */
1281 Fake_glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1282 GLXDrawable read
, GLXContext ctx
)
1284 if (ctx
&& draw
&& read
) {
1285 XMesaBuffer drawBuffer
, readBuffer
;
1286 XMesaContext xmctx
= (XMesaContext
) ctx
;
1288 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1289 if (ctx
== MakeCurrent_PrevContext
1290 && draw
== MakeCurrent_PrevDrawable
) {
1291 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1294 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1297 /* drawable must be a new window! */
1298 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1300 /* Out of memory, or context/drawable depth mismatch */
1305 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1306 if (ctx
== MakeCurrent_PrevContext
1307 && read
== MakeCurrent_PrevReadable
) {
1308 readBuffer
= MakeCurrent_PrevReadBuffer
;
1311 readBuffer
= XMesaFindBuffer( dpy
, read
);
1314 /* drawable must be a new window! */
1315 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1317 /* Out of memory, or context/drawable depth mismatch */
1322 MakeCurrent_PrevContext
= ctx
;
1323 MakeCurrent_PrevDrawable
= draw
;
1324 MakeCurrent_PrevReadable
= read
;
1325 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1326 MakeCurrent_PrevReadBuffer
= readBuffer
;
1328 /* Now make current! */
1329 return XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
);
1331 else if (!ctx
&& !draw
&& !read
) {
1332 /* release current context w/out assigning new one. */
1333 XMesaMakeCurrent( NULL
, NULL
);
1334 MakeCurrent_PrevContext
= 0;
1335 MakeCurrent_PrevDrawable
= 0;
1336 MakeCurrent_PrevReadable
= 0;
1337 MakeCurrent_PrevDrawBuffer
= 0;
1338 MakeCurrent_PrevReadBuffer
= 0;
1342 /* The args must either all be non-zero or all zero.
1351 Fake_glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1353 return Fake_glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1358 Fake_glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1363 v
= find_glx_visual( dpy
, visinfo
);
1365 v
= create_glx_visual( dpy
, visinfo
);
1367 /* unusable visual */
1372 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1376 return b
->frontxrb
->pixmap
;
1380 /*** GLX_MESA_pixmap_colormap ***/
1383 Fake_glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1384 Pixmap pixmap
, Colormap cmap
)
1389 v
= find_glx_visual( dpy
, visinfo
);
1391 v
= create_glx_visual( dpy
, visinfo
);
1393 /* unusable visual */
1398 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1402 return b
->frontxrb
->pixmap
;
1407 Fake_glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1409 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1411 XMesaDestroyBuffer(b
);
1413 else if (getenv("MESA_DEBUG")) {
1414 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1420 Fake_glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1421 unsigned long mask
)
1423 XMesaContext xmSrc
= (XMesaContext
) src
;
1424 XMesaContext xmDst
= (XMesaContext
) dst
;
1426 if (MakeCurrent_PrevContext
== src
) {
1429 _mesa_copy_context( &xmSrc
->mesa
, &xmDst
->mesa
, (GLuint
) mask
);
1434 Fake_glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1437 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1438 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1444 return True
; /* we're faking GLX so always return success */
1448 extern void _kw_ungrab_all( Display
*dpy
);
1449 void _kw_ungrab_all( Display
*dpy
)
1451 XUngrabPointer( dpy
, CurrentTime
);
1452 XUngrabKeyboard( dpy
, CurrentTime
);
1457 Fake_glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1461 MakeCurrent_PrevContext
= 0;
1462 MakeCurrent_PrevDrawable
= 0;
1463 MakeCurrent_PrevReadable
= 0;
1464 MakeCurrent_PrevDrawBuffer
= 0;
1465 MakeCurrent_PrevReadBuffer
= 0;
1466 XMesaDestroyContext((XMesaContext
) ctx
);
1467 XMesaGarbageCollect(dpy
);
1473 Fake_glXIsDirect( Display
*dpy
, GLXContext ctx
)
1475 XMesaContext xmCtx
= (XMesaContext
) ctx
;
1476 return xmCtx
? xmCtx
->direct
: False
;
1482 Fake_glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1484 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1487 XMesaSwapBuffers(buffer
);
1489 else if (getenv("MESA_DEBUG")) {
1490 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1497 /*** GLX_MESA_copy_sub_buffer ***/
1500 Fake_glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1501 int x
, int y
, int width
, int height
)
1503 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1505 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1507 else if (getenv("MESA_DEBUG")) {
1508 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1514 Fake_glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1517 /* Return GLX version, not Mesa version */
1518 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1519 *maj
= CLIENT_MAJOR_VERSION
;
1520 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1526 * Query the GLX attributes of the given XVisualInfo.
1529 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1535 return GLX_BAD_ATTRIBUTE
;
1536 *value
= (int) True
;
1538 case GLX_BUFFER_SIZE
:
1539 *value
= xmvis
->visinfo
->depth
;
1542 *value
= xmvis
->mesa_visual
.level
;
1546 return GLX_BAD_ATTRIBUTE
;
1547 if (xmvis
->mesa_visual
.rgbMode
) {
1554 case GLX_DOUBLEBUFFER
:
1555 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1558 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1560 case GLX_AUX_BUFFERS
:
1561 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1564 *value
= xmvis
->mesa_visual
.redBits
;
1566 case GLX_GREEN_SIZE
:
1567 *value
= xmvis
->mesa_visual
.greenBits
;
1570 *value
= xmvis
->mesa_visual
.blueBits
;
1572 case GLX_ALPHA_SIZE
:
1573 *value
= xmvis
->mesa_visual
.alphaBits
;
1575 case GLX_DEPTH_SIZE
:
1576 *value
= xmvis
->mesa_visual
.depthBits
;
1578 case GLX_STENCIL_SIZE
:
1579 *value
= xmvis
->mesa_visual
.stencilBits
;
1581 case GLX_ACCUM_RED_SIZE
:
1582 *value
= xmvis
->mesa_visual
.accumRedBits
;
1584 case GLX_ACCUM_GREEN_SIZE
:
1585 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1587 case GLX_ACCUM_BLUE_SIZE
:
1588 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1590 case GLX_ACCUM_ALPHA_SIZE
:
1591 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1595 * GLX_EXT_visual_info extension
1597 case GLX_X_VISUAL_TYPE_EXT
:
1598 switch (xmvis
->visinfo
->CLASS
) {
1599 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1600 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1601 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1602 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1603 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1604 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1607 case GLX_TRANSPARENT_TYPE_EXT
:
1608 if (xmvis
->mesa_visual
.level
==0) {
1610 *value
= GLX_NONE_EXT
;
1612 else if (xmvis
->mesa_visual
.level
>0) {
1614 if (xmvis
->mesa_visual
.rgbMode
) {
1615 *value
= GLX_TRANSPARENT_RGB_EXT
;
1618 *value
= GLX_TRANSPARENT_INDEX_EXT
;
1621 else if (xmvis
->mesa_visual
.level
<0) {
1623 *value
= GLX_NONE_EXT
;
1626 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1628 int pixel
= transparent_pixel( xmvis
);
1632 /* else undefined */
1635 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1638 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1641 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1644 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1649 * GLX_EXT_visual_info extension
1651 case GLX_VISUAL_CAVEAT_EXT
:
1652 /* test for zero, just in case */
1653 if (xmvis
->mesa_visual
.visualRating
> 0)
1654 *value
= xmvis
->mesa_visual
.visualRating
;
1656 *value
= GLX_NONE_EXT
;
1660 * GLX_ARB_multisample
1662 case GLX_SAMPLE_BUFFERS_ARB
:
1665 case GLX_SAMPLES_ARB
:
1672 case GLX_SCREEN_EXT
:
1674 return GLX_BAD_ATTRIBUTE
;
1675 *value
= xmvis
->visinfo
->screen
;
1677 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1679 return GLX_BAD_ATTRIBUTE
;
1680 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1682 case GLX_RENDER_TYPE_SGIX
:
1684 return GLX_BAD_ATTRIBUTE
;
1685 if (xmvis
->mesa_visual
.floatMode
)
1686 *value
= GLX_RGBA_FLOAT_BIT_ARB
;
1687 else if (xmvis
->mesa_visual
.rgbMode
)
1688 *value
= GLX_RGBA_BIT
;
1690 *value
= GLX_COLOR_INDEX_BIT
;
1692 case GLX_X_RENDERABLE_SGIX
:
1694 return GLX_BAD_ATTRIBUTE
;
1695 *value
= True
; /* XXX really? */
1697 case GLX_FBCONFIG_ID_SGIX
:
1699 return GLX_BAD_ATTRIBUTE
;
1700 *value
= xmvis
->visinfo
->visualid
;
1702 case GLX_MAX_PBUFFER_WIDTH
:
1704 return GLX_BAD_ATTRIBUTE
;
1705 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1706 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1708 case GLX_MAX_PBUFFER_HEIGHT
:
1710 return GLX_BAD_ATTRIBUTE
;
1711 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1713 case GLX_MAX_PBUFFER_PIXELS
:
1715 return GLX_BAD_ATTRIBUTE
;
1716 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1717 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1721 return GLX_BAD_ATTRIBUTE
;
1722 *value
= xmvis
->visinfo
->visualid
;
1725 #ifdef GLX_EXT_texture_from_pixmap
1726 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1727 *value
= True
; /*XXX*/
1729 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1731 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1733 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1734 *value
= True
; /*XXX*/
1736 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1737 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1738 GLX_TEXTURE_2D_BIT_EXT
|
1739 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1741 case GLX_Y_INVERTED_EXT
:
1742 *value
= True
; /*XXX*/
1747 return GLX_BAD_ATTRIBUTE
;
1754 Fake_glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1755 int attrib
, int *value
)
1759 if (!dpy
|| !visinfo
)
1760 return GLX_BAD_ATTRIBUTE
;
1762 xmvis
= find_glx_visual( dpy
, visinfo
);
1764 /* this visual wasn't obtained with glXChooseVisual */
1765 xmvis
= create_glx_visual( dpy
, visinfo
);
1767 /* this visual can't be used for GL rendering */
1768 if (attrib
==GLX_USE_GL
) {
1769 *value
= (int) False
;
1773 return GLX_BAD_VISUAL
;
1778 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1784 Fake_glXGetCurrentContext(void)
1786 XMesaContext xmesa
= XMesaGetCurrentContext();
1787 return (GLXContext
) xmesa
;
1791 Fake_glXWaitGL( void )
1793 XMesaContext xmesa
= XMesaGetCurrentContext();
1794 XMesaFlush( xmesa
);
1800 Fake_glXWaitX( void )
1802 XMesaContext xmesa
= XMesaGetCurrentContext();
1803 XMesaFlush( xmesa
);
1808 get_extensions( void )
1810 return EXTENSIONS
+ 23; /* skip "GLX_MESA_set_3dfx_mode" */
1815 /* GLX 1.1 and later */
1817 Fake_glXQueryExtensionsString( Display
*dpy
, int screen
)
1821 return get_extensions();
1826 /* GLX 1.1 and later */
1828 Fake_glXQueryServerString( Display
*dpy
, int screen
, int name
)
1830 static char version
[1000];
1831 sprintf(version
, "%d.%d %s",
1832 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1838 case GLX_EXTENSIONS
:
1839 return get_extensions();
1851 /* GLX 1.1 and later */
1853 Fake_glXGetClientString( Display
*dpy
, int name
)
1855 static char version
[1000];
1856 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1857 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1862 case GLX_EXTENSIONS
:
1863 return get_extensions();
1881 Fake_glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1882 int attribute
, int *value
)
1884 XMesaVisual v
= (XMesaVisual
) config
;
1888 if (!dpy
|| !config
|| !value
)
1891 return get_config(v
, attribute
, value
, GL_TRUE
);
1895 static GLXFBConfig
*
1896 Fake_glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1898 XVisualInfo
*visuals
, visTemplate
;
1899 const long visMask
= VisualScreenMask
;
1902 /* Get list of all X visuals */
1903 visTemplate
.screen
= screen
;
1904 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1905 if (*nelements
> 0) {
1906 XMesaVisual
*results
;
1907 results
= malloc(*nelements
* sizeof(XMesaVisual
));
1912 for (i
= 0; i
< *nelements
; i
++) {
1913 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1915 return (GLXFBConfig
*) results
;
1921 static GLXFBConfig
*
1922 Fake_glXChooseFBConfig( Display
*dpy
, int screen
,
1923 const int *attribList
, int *nitems
)
1927 /* register ourselves as an extension on this display */
1928 register_with_display(dpy
);
1930 if (!attribList
|| !attribList
[0]) {
1931 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1932 return Fake_glXGetFBConfigs(dpy
, screen
, nitems
);
1935 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1937 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1943 config
[0] = (GLXFBConfig
) xmvis
;
1944 return (GLXFBConfig
*) config
;
1953 static XVisualInfo
*
1954 Fake_glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1956 if (dpy
&& config
) {
1957 XMesaVisual xmvis
= (XMesaVisual
) config
;
1958 XVisualInfo
* visinfo
= malloc(sizeof(XVisualInfo
));
1960 memcpy(visinfo
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1971 Fake_glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1972 const int *attribList
)
1974 XMesaVisual xmvis
= (XMesaVisual
) config
;
1979 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1984 (void) attribList
; /* Ignored in GLX 1.3 */
1986 return win
; /* A hack for now */
1991 Fake_glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1993 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
) window
);
1995 XMesaDestroyBuffer(b
);
1996 /* don't destroy X window */
2002 Fake_glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
2003 const int *attribList
)
2005 XMesaVisual v
= (XMesaVisual
) config
;
2008 int target
= 0, format
= 0, mipmap
= 0;
2011 if (!dpy
|| !config
|| !pixmap
)
2014 for (attr
= attribList
; attr
&& *attr
; attr
++) {
2016 case GLX_TEXTURE_FORMAT_EXT
:
2019 case GLX_TEXTURE_FORMAT_NONE_EXT
:
2020 case GLX_TEXTURE_FORMAT_RGB_EXT
:
2021 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
2029 case GLX_TEXTURE_TARGET_EXT
:
2032 case GLX_TEXTURE_1D_EXT
:
2033 case GLX_TEXTURE_2D_EXT
:
2034 case GLX_TEXTURE_RECTANGLE_EXT
:
2042 case GLX_MIPMAP_TEXTURE_EXT
:
2053 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
2054 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
2055 &value
, GL_TRUE
) != Success
2057 return 0; /* error! */
2060 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
2061 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
2062 &value
, GL_TRUE
) != Success
2064 return 0; /* error! */
2068 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2069 &value
, GL_TRUE
) != Success
2071 return 0; /* error! */
2074 if (target
== GLX_TEXTURE_1D_EXT
) {
2075 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2076 &value
, GL_TRUE
) != Success
2077 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2078 return 0; /* error! */
2081 else if (target
== GLX_TEXTURE_2D_EXT
) {
2082 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2083 &value
, GL_TRUE
) != Success
2084 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2085 return 0; /* error! */
2088 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2089 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2090 &value
, GL_TRUE
) != Success
2091 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2092 return 0; /* error! */
2096 if (format
|| target
|| mipmap
) {
2097 /* texture from pixmap */
2098 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2101 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2112 Fake_glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2114 XMesaBuffer b
= XMesaFindBuffer(dpy
, (XMesaDrawable
)pixmap
);
2116 XMesaDestroyBuffer(b
);
2117 /* don't destroy X pixmap */
2122 Fake_glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2123 const int *attribList
)
2125 XMesaVisual xmvis
= (XMesaVisual
) config
;
2128 int width
= 0, height
= 0;
2129 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2133 for (attrib
= attribList
; *attrib
; attrib
++) {
2135 case GLX_PBUFFER_WIDTH
:
2139 case GLX_PBUFFER_HEIGHT
:
2143 case GLX_PRESERVED_CONTENTS
:
2145 preserveContents
= *attrib
;
2147 case GLX_LARGEST_PBUFFER
:
2149 useLargest
= *attrib
;
2156 if (width
== 0 || height
== 0)
2159 if (width
> SWRAST_MAX_WIDTH
|| height
> SWRAST_MAX_HEIGHT
) {
2160 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2161 * allocate the largest possible buffer.
2164 width
= SWRAST_MAX_WIDTH
;
2165 height
= SWRAST_MAX_HEIGHT
;
2169 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2170 /* A GLXPbuffer handle must be an X Drawable because that's what
2171 * glXMakeCurrent takes.
2174 xmbuf
->largestPbuffer
= useLargest
;
2175 xmbuf
->preservedContents
= preserveContents
;
2176 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2185 Fake_glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2187 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2189 XMesaDestroyBuffer(b
);
2195 Fake_glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2196 unsigned int *value
)
2198 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2202 /* make sure buffer's dimensions are up to date */
2203 xmesa_check_and_update_buffer_size(NULL
, xmbuf
);
2205 switch (attribute
) {
2207 *value
= xmbuf
->mesa_buffer
.Width
;
2210 *value
= xmbuf
->mesa_buffer
.Height
;
2212 case GLX_PRESERVED_CONTENTS
:
2213 *value
= xmbuf
->preservedContents
;
2215 case GLX_LARGEST_PBUFFER
:
2216 *value
= xmbuf
->largestPbuffer
;
2218 case GLX_FBCONFIG_ID
:
2219 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2221 #ifdef GLX_EXT_texture_from_pixmap
2222 case GLX_TEXTURE_FORMAT_EXT
:
2223 *value
= xmbuf
->TextureFormat
;
2225 case GLX_TEXTURE_TARGET_EXT
:
2226 *value
= xmbuf
->TextureTarget
;
2228 case GLX_MIPMAP_TEXTURE_EXT
:
2229 *value
= xmbuf
->TextureMipmap
;
2234 return; /* raise BadValue error */
2240 Fake_glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2241 int renderType
, GLXContext shareList
, Bool direct
)
2244 XMesaVisual xmvis
= (XMesaVisual
) config
;
2246 if (!dpy
|| !config
||
2247 (renderType
!= GLX_RGBA_TYPE
&&
2248 renderType
!= GLX_COLOR_INDEX_TYPE
&&
2249 renderType
!= GLX_RGBA_FLOAT_TYPE_ARB
&&
2250 renderType
!= GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT
))
2253 /* deallocate unused windows/buffers */
2254 XMesaGarbageCollect(dpy
);
2256 xmCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) shareList
);
2258 return (GLXContext
) xmCtx
;
2263 Fake_glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2265 XMesaContext xmctx
= (XMesaContext
) ctx
;
2269 switch (attribute
) {
2270 case GLX_FBCONFIG_ID
:
2271 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2273 case GLX_RENDER_TYPE
:
2274 *value
= GLX_RGBA_TYPE
;
2280 return GLX_BAD_ATTRIBUTE
;
2287 Fake_glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2289 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2291 xmbuf
->selectedEvents
= mask
;
2296 Fake_glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2297 unsigned long *mask
)
2299 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2301 *mask
= xmbuf
->selectedEvents
;
2308 /*** GLX_SGI_swap_control ***/
2311 Fake_glXSwapIntervalSGI(int interval
)
2319 /*** GLX_SGI_video_sync ***/
2321 static unsigned int FrameCounter
= 0;
2324 Fake_glXGetVideoSyncSGI(unsigned int *count
)
2326 /* this is a bogus implementation */
2327 *count
= FrameCounter
++;
2332 Fake_glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2334 if (divisor
<= 0 || remainder
< 0)
2335 return GLX_BAD_VALUE
;
2336 /* this is a bogus implementation */
2338 while (FrameCounter
% divisor
!= remainder
)
2340 *count
= FrameCounter
;
2346 /*** GLX_SGI_make_current_read ***/
2349 Fake_glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2351 return Fake_glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2356 Fake_glXGetCurrentReadDrawableSGI(void)
2363 /*** GLX_SGIX_video_source ***/
2366 static GLXVideoSourceSGIX
2367 Fake_glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2379 Fake_glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2388 /*** GLX_EXT_import_context ***/
2391 Fake_glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2398 Fake_glXGetContextIDEXT(const GLXContext context
)
2405 Fake_glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2413 Fake_glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2424 /*** GLX_SGIX_fbconfig ***/
2427 Fake_glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2429 return Fake_glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2432 static GLXFBConfigSGIX
*
2433 Fake_glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2435 return (GLXFBConfig
*) Fake_glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2440 Fake_glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2442 XMesaVisual xmvis
= (XMesaVisual
) config
;
2443 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2444 return xmbuf
->frontxrb
->pixmap
; /* need to return an X ID */
2449 Fake_glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2452 XMesaVisual xmvis
= (XMesaVisual
) config
;
2454 /* deallocate unused windows/buffers */
2455 XMesaGarbageCollect(dpy
);
2457 xmCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) share_list
);
2459 return (GLXContext
) xmCtx
;
2463 static XVisualInfo
*
2464 Fake_glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2466 return Fake_glXGetVisualFromFBConfig(dpy
, config
);
2470 static GLXFBConfigSGIX
2471 Fake_glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2473 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2475 /* This visual wasn't found with glXChooseVisual() */
2476 xmvis
= create_glx_visual(dpy
, vis
);
2479 return (GLXFBConfigSGIX
) xmvis
;
2484 /*** GLX_SGIX_pbuffer ***/
2486 static GLXPbufferSGIX
2487 Fake_glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2488 unsigned int width
, unsigned int height
,
2491 XMesaVisual xmvis
= (XMesaVisual
) config
;
2494 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2498 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2500 case GLX_PRESERVED_CONTENTS_SGIX
:
2502 preserveContents
= *attrib
; /* ignored */
2504 case GLX_LARGEST_PBUFFER_SGIX
:
2506 useLargest
= *attrib
; /* ignored */
2513 /* not used at this time */
2515 (void) preserveContents
;
2517 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2518 /* A GLXPbuffer handle must be an X Drawable because that's what
2519 * glXMakeCurrent takes.
2521 return (GLXPbuffer
) xmbuf
->frontxrb
->pixmap
;
2526 Fake_glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2528 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2530 XMesaDestroyBuffer(xmbuf
);
2536 Fake_glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2538 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2541 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2545 switch (attribute
) {
2546 case GLX_PRESERVED_CONTENTS_SGIX
:
2547 *value
= xmbuf
->preservedContents
;
2549 case GLX_LARGEST_PBUFFER_SGIX
:
2550 *value
= xmbuf
->largestPbuffer
;
2552 case GLX_WIDTH_SGIX
:
2553 *value
= xmbuf
->mesa_buffer
.Width
;
2555 case GLX_HEIGHT_SGIX
:
2556 *value
= xmbuf
->mesa_buffer
.Height
;
2558 case GLX_EVENT_MASK_SGIX
:
2559 *value
= 0; /* XXX might be wrong */
2569 Fake_glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2571 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2573 /* Note: we'll never generate clobber events */
2574 xmbuf
->selectedEvents
= mask
;
2580 Fake_glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2582 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2584 *mask
= xmbuf
->selectedEvents
;
2593 /*** GLX_SGI_cushion ***/
2596 Fake_glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2605 /*** GLX_SGIX_video_resize ***/
2608 Fake_glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2618 Fake_glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2631 Fake_glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2644 Fake_glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2657 Fake_glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2668 /*** GLX_SGIX_dmbuffer **/
2670 #if defined(_DM_BUFFER_H_)
2672 Fake_glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2683 /*** GLX_SGIX_swap_group ***/
2686 Fake_glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2695 /*** GLX_SGIX_swap_barrier ***/
2698 Fake_glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2706 Fake_glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2716 /*** GLX_SUN_get_transparent_index ***/
2719 Fake_glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2724 (void) pTransparent
;
2730 /*** GLX_MESA_release_buffers ***/
2733 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2734 * (a window or pixmap) prior to destroying the GLXDrawable.
2737 Fake_glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2739 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2741 XMesaDestroyBuffer(b
);
2749 /*** GLX_MESA_set_3dfx_mode ***/
2752 Fake_glXSet3DfxModeMESA( int mode
)
2754 return XMesaSetFXmode( mode
);
2759 /*** GLX_NV_vertex_array range ***/
2761 Fake_glXAllocateMemoryNV( GLsizei size
,
2762 GLfloat readFrequency
,
2763 GLfloat writeFrequency
,
2767 (void) readFrequency
;
2768 (void) writeFrequency
;
2775 Fake_glXFreeMemoryNV( GLvoid
*pointer
)
2781 /*** GLX_MESA_agp_offset ***/
2784 Fake_glXGetAGPOffsetMESA( const GLvoid
*pointer
)
2791 /*** GLX_EXT_texture_from_pixmap ***/
2794 Fake_glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2795 const int *attrib_list
)
2797 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2799 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2803 Fake_glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2805 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2807 XMesaReleaseTexImage(dpy
, b
, buffer
);
2812 Fake_glXCreateContextAttribs(Display
*dpy
, GLXFBConfig config
,
2813 GLXContext share_context
, Bool direct
,
2814 const int *attrib_list
)
2817 XMesaVisual xmvis
= (XMesaVisual
) config
;
2819 int major
= 0, minor
= 0, ctxFlags
= 0, profileFlags
= 0;
2821 for (i
= 0; attrib_list
[i
]; i
+= 2) {
2822 switch (attrib_list
[i
]) {
2823 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2824 major
= attrib_list
[i
+ 1];
2826 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2827 minor
= attrib_list
[i
+ 1];
2829 case GLX_CONTEXT_FLAGS_ARB
:
2830 ctxFlags
= attrib_list
[i
+ 1];
2832 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2833 profileFlags
= attrib_list
[i
+ 1];
2836 fprintf(stderr
, "Bad attribute in glXCreateContextAttribs()\n");
2841 if (major
* 10 + minor
> 21) {
2842 /* swrast only supports GL 2.1 and earlier */
2846 /* These are ignored for now. We'd have to enhance XMesaCreateContext
2847 * to take these flags and the version, at least.
2850 (void) profileFlags
;
2852 /* deallocate unused windows/buffers */
2853 XMesaGarbageCollect(dpy
);
2855 xmCtx
= XMesaCreateContext(xmvis
, (XMesaContext
) share_context
);
2857 return (GLXContext
) xmCtx
;
2861 /* silence warning */
2862 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
2866 * Create a new GLX API dispatch table with its function pointers
2867 * initialized to point to Mesa's "fake" GLX API functions.
2868 * Note: there's a similar function (_real_GetGLXDispatchTable) that
2869 * returns a new dispatch table with all pointers initalized to point
2870 * to "real" GLX functions (which understand GLX wire protocol, etc).
2872 struct _glxapi_table
*
2873 _mesa_GetGLXDispatchTable(void)
2875 static struct _glxapi_table glx
;
2877 /* be sure our dispatch table size <= libGL's table */
2879 GLuint size
= sizeof(struct _glxapi_table
) / sizeof(void *);
2881 assert(_glxapi_get_dispatch_table_size() >= size
);
2884 /* initialize the whole table to no-ops */
2885 _glxapi_set_no_op_table(&glx
);
2887 /* now initialize the table with the functions I implement */
2888 glx
.ChooseVisual
= Fake_glXChooseVisual
;
2889 glx
.CopyContext
= Fake_glXCopyContext
;
2890 glx
.CreateContext
= Fake_glXCreateContext
;
2891 glx
.CreateGLXPixmap
= Fake_glXCreateGLXPixmap
;
2892 glx
.DestroyContext
= Fake_glXDestroyContext
;
2893 glx
.DestroyGLXPixmap
= Fake_glXDestroyGLXPixmap
;
2894 glx
.GetConfig
= Fake_glXGetConfig
;
2895 glx
.GetCurrentContext
= Fake_glXGetCurrentContext
;
2896 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2897 glx
.IsDirect
= Fake_glXIsDirect
;
2898 glx
.MakeCurrent
= Fake_glXMakeCurrent
;
2899 glx
.QueryExtension
= Fake_glXQueryExtension
;
2900 glx
.QueryVersion
= Fake_glXQueryVersion
;
2901 glx
.SwapBuffers
= Fake_glXSwapBuffers
;
2902 glx
.UseXFont
= Fake_glXUseXFont
;
2903 glx
.WaitGL
= Fake_glXWaitGL
;
2904 glx
.WaitX
= Fake_glXWaitX
;
2906 /*** GLX_VERSION_1_1 ***/
2907 glx
.GetClientString
= Fake_glXGetClientString
;
2908 glx
.QueryExtensionsString
= Fake_glXQueryExtensionsString
;
2909 glx
.QueryServerString
= Fake_glXQueryServerString
;
2911 /*** GLX_VERSION_1_2 ***/
2912 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2914 /*** GLX_VERSION_1_3 ***/
2915 glx
.ChooseFBConfig
= Fake_glXChooseFBConfig
;
2916 glx
.CreateNewContext
= Fake_glXCreateNewContext
;
2917 glx
.CreatePbuffer
= Fake_glXCreatePbuffer
;
2918 glx
.CreatePixmap
= Fake_glXCreatePixmap
;
2919 glx
.CreateWindow
= Fake_glXCreateWindow
;
2920 glx
.DestroyPbuffer
= Fake_glXDestroyPbuffer
;
2921 glx
.DestroyPixmap
= Fake_glXDestroyPixmap
;
2922 glx
.DestroyWindow
= Fake_glXDestroyWindow
;
2923 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2924 glx
.GetFBConfigAttrib
= Fake_glXGetFBConfigAttrib
;
2925 glx
.GetFBConfigs
= Fake_glXGetFBConfigs
;
2926 glx
.GetSelectedEvent
= Fake_glXGetSelectedEvent
;
2927 glx
.GetVisualFromFBConfig
= Fake_glXGetVisualFromFBConfig
;
2928 glx
.MakeContextCurrent
= Fake_glXMakeContextCurrent
;
2929 glx
.QueryContext
= Fake_glXQueryContext
;
2930 glx
.QueryDrawable
= Fake_glXQueryDrawable
;
2931 glx
.SelectEvent
= Fake_glXSelectEvent
;
2933 /*** GLX_SGI_swap_control ***/
2934 glx
.SwapIntervalSGI
= Fake_glXSwapIntervalSGI
;
2936 /*** GLX_SGI_video_sync ***/
2937 glx
.GetVideoSyncSGI
= Fake_glXGetVideoSyncSGI
;
2938 glx
.WaitVideoSyncSGI
= Fake_glXWaitVideoSyncSGI
;
2940 /*** GLX_SGI_make_current_read ***/
2941 glx
.MakeCurrentReadSGI
= Fake_glXMakeCurrentReadSGI
;
2942 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2944 /*** GLX_SGIX_video_source ***/
2946 glx
.CreateGLXVideoSourceSGIX
= Fake_glXCreateGLXVideoSourceSGIX
;
2947 glx
.DestroyGLXVideoSourceSGIX
= Fake_glXDestroyGLXVideoSourceSGIX
;
2950 /*** GLX_EXT_import_context ***/
2951 glx
.FreeContextEXT
= Fake_glXFreeContextEXT
;
2952 glx
.GetContextIDEXT
= Fake_glXGetContextIDEXT
;
2953 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2954 glx
.ImportContextEXT
= Fake_glXImportContextEXT
;
2955 glx
.QueryContextInfoEXT
= Fake_glXQueryContextInfoEXT
;
2957 /*** GLX_SGIX_fbconfig ***/
2958 glx
.GetFBConfigAttribSGIX
= Fake_glXGetFBConfigAttribSGIX
;
2959 glx
.ChooseFBConfigSGIX
= Fake_glXChooseFBConfigSGIX
;
2960 glx
.CreateGLXPixmapWithConfigSGIX
= Fake_glXCreateGLXPixmapWithConfigSGIX
;
2961 glx
.CreateContextWithConfigSGIX
= Fake_glXCreateContextWithConfigSGIX
;
2962 glx
.GetVisualFromFBConfigSGIX
= Fake_glXGetVisualFromFBConfigSGIX
;
2963 glx
.GetFBConfigFromVisualSGIX
= Fake_glXGetFBConfigFromVisualSGIX
;
2965 /*** GLX_SGIX_pbuffer ***/
2966 glx
.CreateGLXPbufferSGIX
= Fake_glXCreateGLXPbufferSGIX
;
2967 glx
.DestroyGLXPbufferSGIX
= Fake_glXDestroyGLXPbufferSGIX
;
2968 glx
.QueryGLXPbufferSGIX
= Fake_glXQueryGLXPbufferSGIX
;
2969 glx
.SelectEventSGIX
= Fake_glXSelectEventSGIX
;
2970 glx
.GetSelectedEventSGIX
= Fake_glXGetSelectedEventSGIX
;
2972 /*** GLX_SGI_cushion ***/
2973 glx
.CushionSGI
= Fake_glXCushionSGI
;
2975 /*** GLX_SGIX_video_resize ***/
2976 glx
.BindChannelToWindowSGIX
= Fake_glXBindChannelToWindowSGIX
;
2977 glx
.ChannelRectSGIX
= Fake_glXChannelRectSGIX
;
2978 glx
.QueryChannelRectSGIX
= Fake_glXQueryChannelRectSGIX
;
2979 glx
.QueryChannelDeltasSGIX
= Fake_glXQueryChannelDeltasSGIX
;
2980 glx
.ChannelRectSyncSGIX
= Fake_glXChannelRectSyncSGIX
;
2982 /*** GLX_SGIX_dmbuffer **/
2983 #if defined(_DM_BUFFER_H_)
2984 glx
.AssociateDMPbufferSGIX
= NULL
;
2987 /*** GLX_SGIX_swap_group ***/
2988 glx
.JoinSwapGroupSGIX
= Fake_glXJoinSwapGroupSGIX
;
2990 /*** GLX_SGIX_swap_barrier ***/
2991 glx
.BindSwapBarrierSGIX
= Fake_glXBindSwapBarrierSGIX
;
2992 glx
.QueryMaxSwapBarriersSGIX
= Fake_glXQueryMaxSwapBarriersSGIX
;
2994 /*** GLX_SUN_get_transparent_index ***/
2995 glx
.GetTransparentIndexSUN
= Fake_glXGetTransparentIndexSUN
;
2997 /*** GLX_MESA_copy_sub_buffer ***/
2998 glx
.CopySubBufferMESA
= Fake_glXCopySubBufferMESA
;
3000 /*** GLX_MESA_release_buffers ***/
3001 glx
.ReleaseBuffersMESA
= Fake_glXReleaseBuffersMESA
;
3003 /*** GLX_MESA_pixmap_colormap ***/
3004 glx
.CreateGLXPixmapMESA
= Fake_glXCreateGLXPixmapMESA
;
3006 /*** GLX_MESA_set_3dfx_mode ***/
3007 glx
.Set3DfxModeMESA
= Fake_glXSet3DfxModeMESA
;
3009 /*** GLX_NV_vertex_array_range ***/
3010 glx
.AllocateMemoryNV
= Fake_glXAllocateMemoryNV
;
3011 glx
.FreeMemoryNV
= Fake_glXFreeMemoryNV
;
3013 /*** GLX_MESA_agp_offset ***/
3014 glx
.GetAGPOffsetMESA
= Fake_glXGetAGPOffsetMESA
;
3016 /*** GLX_EXT_texture_from_pixmap ***/
3017 glx
.BindTexImageEXT
= Fake_glXBindTexImageEXT
;
3018 glx
.ReleaseTexImageEXT
= Fake_glXReleaseTexImageEXT
;
3020 glx
.CreateContextAttribs
= Fake_glXCreateContextAttribs
;