2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * "Fake" GLX API implemented in terms of the XMesa*() functions.
33 #define GLX_GLXEXT_PROTOTYPES
39 /* This indicates the client-side GLX API and GLX encoder version. */
40 #define CLIENT_MAJOR_VERSION 1
41 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
43 /* This indicates the server-side GLX decoder version.
44 * GLX 1.4 indicates OpenGL 1.3 support
46 #define SERVER_MAJOR_VERSION 1
47 #define SERVER_MINOR_VERSION 4
49 /* Who implemented this GLX? */
50 #define VENDOR "Brian Paul"
53 "GLX_MESA_copy_sub_buffer " \
54 "GLX_MESA_pixmap_colormap " \
55 "GLX_MESA_release_buffers " \
56 "GLX_ARB_create_context " \
57 "GLX_ARB_create_context_profile " \
58 "GLX_ARB_get_proc_address " \
59 "GLX_EXT_texture_from_pixmap " \
60 "GLX_EXT_visual_info " \
61 "GLX_EXT_visual_rating " \
62 /*"GLX_SGI_video_sync "*/ \
63 "GLX_SGIX_fbconfig " \
66 #define DEFAULT_DIRECT GL_TRUE
71 * The GLXContext typedef is defined as a pointer to this structure.
73 struct __GLXcontextRec
77 GLXDrawable currentDrawable
;
78 GLXDrawable currentReadable
;
81 XMesaContext xmesaContext
;
86 static pipe_tsd ContextTSD
;
88 /** Set current context for calling thread */
90 SetCurrentContext(GLXContext c
)
92 pipe_tsd_set(&ContextTSD
, c
);
95 /** Get current context for calling thread */
97 GetCurrentContext(void)
99 return pipe_tsd_get(&ContextTSD
);
104 /**********************************************************************/
105 /*** GLX Visual Code ***/
106 /**********************************************************************/
111 static XMesaVisual
*VisualTable
= NULL
;
112 static int NumVisuals
= 0;
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 /* Any StaticColor/PseudoColor visual of at least 4 bits */
139 if (vinfo
->depth
>=4) {
147 /* Any depth of TrueColor or DirectColor works in RGB mode */
150 /* This should never happen */
157 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
158 * configuration in our list of GLX visuals.
161 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
162 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
163 GLboolean stereoFlag
,
164 GLint depth_size
, GLint stencil_size
,
165 GLint accumRedSize
, GLint accumGreenSize
,
166 GLint accumBlueSize
, GLint accumAlphaSize
,
167 GLint level
, GLint numAuxBuffers
)
169 GLboolean ximageFlag
= GL_TRUE
;
172 GLboolean comparePointers
;
175 /* Check if the MESA_BACK_BUFFER env var is set */
176 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
178 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
179 ximageFlag
= GL_FALSE
;
181 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
182 ximageFlag
= GL_TRUE
;
185 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
191 /* stereo not supported */
195 if (stencil_size
> 0 && depth_size
> 0)
198 /* Comparing IDs uses less memory but sometimes fails. */
199 /* XXX revisit this after 3.0 is finished. */
200 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
201 comparePointers
= GL_TRUE
;
203 comparePointers
= GL_FALSE
;
205 /* Force the visual to have an alpha channel */
206 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
209 /* First check if a matching visual is already in the list */
210 for (i
=0; i
<NumVisuals
; i
++) {
211 XMesaVisual v
= VisualTable
[i
];
212 if (v
->display
== dpy
213 && v
->mesa_visual
.level
== level
214 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
215 && v
->ximage_flag
== ximageFlag
216 && v
->mesa_visual
.rgbMode
== rgbFlag
217 && v
->mesa_visual
.doubleBufferMode
== dbFlag
218 && v
->mesa_visual
.stereoMode
== stereoFlag
219 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
220 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
221 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
222 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
223 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
224 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
225 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
226 /* now either compare XVisualInfo pointers or visual IDs */
227 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
228 || (comparePointers
&& v
->vishandle
== vinfo
)) {
234 /* Create a new visual and add it to the list. */
236 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
237 stereoFlag
, ximageFlag
,
238 depth_size
, stencil_size
,
239 accumRedSize
, accumBlueSize
,
240 accumBlueSize
, accumAlphaSize
, 0, level
,
243 /* Save a copy of the pointer now so we can find this visual again
244 * if we need to search for it in find_glx_visual().
246 xmvis
->vishandle
= vinfo
;
247 /* Allocate more space for additional visual */
248 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
249 sizeof(XMesaVisual
) * NumVisuals
,
250 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
251 /* add xmvis to the list */
252 VisualTable
[NumVisuals
] = xmvis
;
254 /* XXX minor hack, because XMesaCreateVisual doesn't support an
255 * aux buffers parameter.
257 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
264 * Return the default number of bits for the Z buffer.
265 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
266 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
267 * XXX probably do the same thing for stencil, accum, etc.
270 default_depth_bits(void)
273 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
277 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
282 default_alpha_bits(void)
285 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
294 default_accum_bits(void)
302 * Create a GLX visual from a regular XVisualInfo.
303 * This is called when Fake GLX is given an XVisualInfo which wasn't
304 * returned by glXChooseVisual. Since this is the first time we're
305 * considering this visual we'll take a guess at reasonable values
306 * for depth buffer size, stencil size, accum size, etc.
307 * This is the best we can do with a client-side emulation of GLX.
310 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
312 GLint zBits
= default_depth_bits();
313 GLint accBits
= default_accum_bits();
314 GLboolean alphaFlag
= default_alpha_bits() > 0;
316 if (is_usable_visual( visinfo
)) {
317 /* Configure this visual as RGB, double-buffered, depth-buffered. */
318 /* This is surely wrong for some people's needs but what else */
319 /* can be done? They should use glXChooseVisual(). */
320 return save_glx_visual( dpy
, visinfo
,
322 alphaFlag
, /* alpha */
323 GL_TRUE
, /* double */
324 GL_FALSE
, /* stereo */
336 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
344 * Find the GLX visual associated with an XVisualInfo.
347 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
351 /* try to match visual id */
352 for (i
=0;i
<NumVisuals
;i
++) {
353 if (VisualTable
[i
]->display
==dpy
354 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
355 return VisualTable
[i
];
359 /* if that fails, try to match pointers */
360 for (i
=0;i
<NumVisuals
;i
++) {
361 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
362 return VisualTable
[i
];
371 * Try to get an X visual which matches the given arguments.
374 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
376 XVisualInfo temp
, *vis
;
379 unsigned int default_depth
;
382 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
387 default_depth
= DefaultDepth(dpy
,scr
);
388 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
390 if (depth
==default_depth
&& xclass
==default_class
) {
391 /* try to get root window's visual */
392 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
393 mask
|= VisualIDMask
;
396 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
398 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
399 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
400 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
402 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
403 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
404 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
405 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
419 * Retrieve the value of the given environment variable and find
420 * the X visual which matches it.
421 * Input: dpy - the display
422 * screen - the screen number
423 * varname - the name of the environment variable
424 * Return: an XVisualInfo pointer to NULL if error.
427 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
429 char value
[100], type
[100];
430 int depth
, xclass
= -1;
433 if (!_mesa_getenv( varname
)) {
437 strncpy( value
, _mesa_getenv(varname
), 100 );
440 sscanf( value
, "%s %d", type
, &depth
);
442 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
443 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
444 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
445 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
446 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
447 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
449 if (xclass
>-1 && depth
>0) {
450 vis
= get_visual( dpy
, scr
, depth
, xclass
);
456 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
465 * Select an X visual which satisfies the RGBA flag and minimum depth.
467 * screen - X display and screen number
468 * min_depth - minimum visual depth
469 * preferred_class - preferred GLX visual class or DONT_CARE
470 * Return: pointer to an XVisualInfo or NULL.
473 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
474 int preferred_class
)
477 int xclass
, visclass
= 0;
480 /* First see if the MESA_RGB_VISUAL env var is defined */
481 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
485 /* Otherwise, search for a suitable visual */
486 if (preferred_class
==DONT_CARE
) {
487 for (xclass
=0;xclass
<6;xclass
++) {
489 case 0: visclass
= TrueColor
; break;
490 case 1: visclass
= DirectColor
; break;
491 case 2: visclass
= PseudoColor
; break;
492 case 3: visclass
= StaticColor
; break;
493 case 4: visclass
= GrayScale
; break;
494 case 5: visclass
= StaticGray
; break;
497 /* start with shallowest */
498 for (depth
=0;depth
<=32;depth
++) {
499 if (visclass
==TrueColor
&& depth
==8) {
500 /* Special case: try to get 8-bit PseudoColor before */
501 /* 8-bit TrueColor */
502 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
507 vis
= get_visual( dpy
, screen
, depth
, visclass
);
514 /* start with deepest */
515 for (depth
=32;depth
>=min_depth
;depth
--) {
516 if (visclass
==TrueColor
&& depth
==8) {
517 /* Special case: try to get 8-bit PseudoColor before */
518 /* 8-bit TrueColor */
519 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
524 vis
= get_visual( dpy
, screen
, depth
, visclass
);
533 /* search for a specific visual class */
534 switch (preferred_class
) {
535 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
536 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
537 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
538 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
539 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
540 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
541 default: return NULL
;
544 /* start with shallowest */
545 for (depth
=0;depth
<=32;depth
++) {
546 vis
= get_visual( dpy
, screen
, depth
, visclass
);
553 /* start with deepest */
554 for (depth
=32;depth
>=min_depth
;depth
--) {
555 vis
= get_visual( dpy
, screen
, depth
, visclass
);
563 /* didn't find a visual */
570 /**********************************************************************/
571 /*** Display-related functions ***/
572 /**********************************************************************/
576 * Free all XMesaVisuals which are associated with the given display.
579 destroy_visuals_on_display(Display
*dpy
)
582 for (i
= 0; i
< NumVisuals
; i
++) {
583 if (VisualTable
[i
]->display
== dpy
) {
584 /* remove this visual */
586 free(VisualTable
[i
]);
587 for (j
= i
; j
< NumVisuals
- 1; j
++)
588 VisualTable
[j
] = VisualTable
[j
+ 1];
596 * Called from XCloseDisplay() to let us free our display-related data.
599 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
601 xmesa_destroy_buffers_on_display(dpy
);
602 destroy_visuals_on_display(dpy
);
608 * Look for the named extension on given display and return a pointer
609 * to the _XExtension data, or NULL if extension not found.
612 lookup_extension(Display
*dpy
, const char *extName
)
615 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
616 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
625 * Whenever we're given a new Display pointer, call this function to
626 * register our close_display_callback function.
629 register_with_display(Display
*dpy
)
631 const char *extName
= "MesaGLX";
634 ext
= lookup_extension(dpy
, extName
);
636 XExtCodes
*c
= XAddExtension(dpy
);
637 ext
= dpy
->ext_procs
; /* new extension is at head of list */
638 assert(c
->extension
== ext
->codes
.extension
);
640 ext
->name
= _mesa_strdup(extName
);
641 ext
->close_display
= close_display_callback
;
646 /**********************************************************************/
647 /*** Begin Fake GLX API Functions ***/
648 /**********************************************************************/
652 * Helper used by glXChooseVisual and glXChooseFBConfig.
653 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
655 * In either case, the attribute list is terminated with the value 'None'.
658 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
660 const GLboolean rgbModeDefault
= fbConfig
;
661 const int *parselist
;
663 int min_red
=0, min_green
=0, min_blue
=0;
664 GLboolean rgb_flag
= rgbModeDefault
;
665 GLboolean alpha_flag
= GL_FALSE
;
666 GLboolean double_flag
= GL_FALSE
;
667 GLboolean stereo_flag
= GL_FALSE
;
668 GLint depth_size
= 0;
669 GLint stencil_size
= 0;
670 GLint accumRedSize
= 0;
671 GLint accumGreenSize
= 0;
672 GLint accumBlueSize
= 0;
673 GLint accumAlphaSize
= 0;
675 int visual_type
= DONT_CARE
;
676 GLint caveat
= DONT_CARE
;
677 XMesaVisual xmvis
= NULL
;
678 int desiredVisualID
= -1;
687 switch (*parselist
) {
698 case GLX_BUFFER_SIZE
:
704 level
= *parselist
++;
716 case GLX_DOUBLEBUFFER
:
719 double_flag
= *parselist
++;
722 double_flag
= GL_TRUE
;
728 stereo_flag
= *parselist
++;
731 stereo_flag
= GL_TRUE
;
734 case GLX_AUX_BUFFERS
:
736 numAux
= *parselist
++;
737 if (numAux
> MAX_AUX_BUFFERS
)
742 min_red
= *parselist
++;
746 min_green
= *parselist
++;
750 min_blue
= *parselist
++;
755 GLint size
= *parselist
++;
756 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
761 depth_size
= *parselist
++;
763 case GLX_STENCIL_SIZE
:
765 stencil_size
= *parselist
++;
767 case GLX_ACCUM_RED_SIZE
:
770 GLint size
= *parselist
++;
771 accumRedSize
= MAX2( accumRedSize
, size
);
774 case GLX_ACCUM_GREEN_SIZE
:
777 GLint size
= *parselist
++;
778 accumGreenSize
= MAX2( accumGreenSize
, size
);
781 case GLX_ACCUM_BLUE_SIZE
:
784 GLint size
= *parselist
++;
785 accumBlueSize
= MAX2( accumBlueSize
, size
);
788 case GLX_ACCUM_ALPHA_SIZE
:
791 GLint size
= *parselist
++;
792 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
797 * GLX_EXT_visual_info extension
799 case GLX_X_VISUAL_TYPE_EXT
:
801 visual_type
= *parselist
++;
803 case GLX_TRANSPARENT_TYPE_EXT
:
807 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
811 case GLX_TRANSPARENT_RED_VALUE_EXT
:
812 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
813 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
814 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
821 * GLX_EXT_visual_info extension
823 case GLX_VISUAL_CAVEAT_EXT
:
825 caveat
= *parselist
++; /* ignored for now */
829 * GLX_ARB_multisample
831 case GLX_SAMPLE_BUFFERS_ARB
:
832 /* ms not supported */
834 case GLX_SAMPLES_ARB
:
835 /* ms not supported */
841 case GLX_RENDER_TYPE
:
845 if (*parselist
& GLX_RGBA_BIT
) {
848 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
851 else if (*parselist
== 0) {
856 case GLX_DRAWABLE_TYPE
:
860 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
861 return NULL
; /* bad bit */
865 case GLX_FBCONFIG_ID
:
870 desiredVisualID
= *parselist
++;
872 case GLX_X_RENDERABLE
:
873 case GLX_MAX_PBUFFER_WIDTH
:
874 case GLX_MAX_PBUFFER_HEIGHT
:
875 case GLX_MAX_PBUFFER_PIXELS
:
877 return NULL
; /* invalid config option */
878 parselist
+= 2; /* ignore the parameter */
881 #ifdef GLX_EXT_texture_from_pixmap
882 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
883 parselist
++; /*skip*/
885 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
886 parselist
++; /*skip*/
888 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
889 parselist
++; /*skip*/
891 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
893 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
894 GLX_TEXTURE_2D_BIT_EXT
|
895 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
900 case GLX_Y_INVERTED_EXT
:
901 parselist
++; /*skip*/
910 /* undefined attribute */
911 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
921 * Since we're only simulating the GLX extension this function will never
922 * find any real GL visuals. Instead, all we can do is try to find an RGB
923 * or CI visual of appropriate depth. Other requested attributes such as
924 * double buffering, depth buffer, etc. will be associated with the X
925 * visual and stored in the VisualTable[].
927 if (desiredVisualID
!= -1) {
928 /* try to get a specific visual, by visualID */
931 temp
.visualid
= desiredVisualID
;
932 temp
.screen
= screen
;
933 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
935 /* give the visual some useful GLX attributes */
936 double_flag
= GL_TRUE
;
941 /* normal color planes */
942 /* Get an RGB visual */
943 int min_rgb
= min_red
+ min_green
+ min_blue
;
944 if (min_rgb
>1 && min_rgb
<8) {
945 /* a special case to be sure we can get a monochrome visual */
948 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
951 _mesa_warning(NULL
, "overlay not supported");
956 /* Note: we're not exactly obeying the glXChooseVisual rules here.
957 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
958 * largest depth buffer size, which is 32bits/value. Instead, we
959 * return 16 to maintain performance with earlier versions of Mesa.
961 if (stencil_size
> 0)
962 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
963 else if (depth_size
> 24)
965 else if (depth_size
> 16)
967 else if (depth_size
> 0) {
968 depth_size
= default_depth_bits();
972 alpha_flag
= default_alpha_bits() > 0;
975 /* we only support one size of stencil and accum buffers. */
976 if (stencil_size
> 0)
977 stencil_size
= STENCIL_BITS
;
979 if (accumRedSize
> 0 ||
980 accumGreenSize
> 0 ||
982 accumAlphaSize
> 0) {
986 accumBlueSize
= default_accum_bits();
988 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
991 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
992 stereo_flag
, depth_size
, stencil_size
,
993 accumRedSize
, accumGreenSize
,
994 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1001 PUBLIC XVisualInfo
*
1002 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1006 /* register ourselves as an extension on this display */
1007 register_with_display(dpy
);
1009 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1011 /* create a new vishandle - the cached one may be stale */
1012 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1013 if (xmvis
->vishandle
) {
1014 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1016 return xmvis
->vishandle
;
1024 * Helper function used by other glXCreateContext functions.
1027 create_context(Display
*dpy
, XMesaVisual xmvis
,
1028 XMesaContext shareCtx
, Bool direct
,
1029 unsigned major
, unsigned minor
,
1030 unsigned profileMask
, unsigned contextFlags
)
1037 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1041 /* deallocate unused windows/buffers */
1043 XMesaGarbageCollect();
1046 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1047 profileMask
, contextFlags
);
1048 if (!glxCtx
->xmesaContext
) {
1053 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1054 glxCtx
->currentDpy
= dpy
;
1055 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1062 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1063 GLXContext shareCtx
, Bool direct
)
1067 xmvis
= find_glx_visual( dpy
, visinfo
);
1069 /* This visual wasn't found with glXChooseVisual() */
1070 xmvis
= create_glx_visual( dpy
, visinfo
);
1072 /* unusable visual */
1077 return create_context(dpy
, xmvis
,
1078 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1080 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1084 /* XXX these may have to be removed due to thread-safety issues. */
1085 static GLXContext MakeCurrent_PrevContext
= 0;
1086 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1087 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1088 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1089 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1092 /* GLX 1.3 and later */
1094 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1095 GLXDrawable read
, GLXContext ctx
)
1097 GLXContext glxCtx
= ctx
;
1098 static boolean firsttime
= 1, no_rast
= 0;
1101 no_rast
= getenv("SP_NO_RAST") != NULL
;
1105 if (ctx
&& draw
&& read
) {
1106 XMesaBuffer drawBuffer
, readBuffer
;
1107 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1109 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1110 if (ctx
== MakeCurrent_PrevContext
1111 && draw
== MakeCurrent_PrevDrawable
) {
1112 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1115 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1118 /* drawable must be a new window! */
1119 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1121 /* Out of memory, or context/drawable depth mismatch */
1126 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1127 if (ctx
== MakeCurrent_PrevContext
1128 && read
== MakeCurrent_PrevReadable
) {
1129 readBuffer
= MakeCurrent_PrevReadBuffer
;
1132 readBuffer
= XMesaFindBuffer( dpy
, read
);
1135 /* drawable must be a new window! */
1136 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1138 /* Out of memory, or context/drawable depth mismatch */
1144 MakeCurrent_PrevContext
== ctx
&&
1145 MakeCurrent_PrevDrawable
== draw
&&
1146 MakeCurrent_PrevReadable
== read
&&
1147 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1148 MakeCurrent_PrevReadBuffer
== readBuffer
)
1151 MakeCurrent_PrevContext
= ctx
;
1152 MakeCurrent_PrevDrawable
= draw
;
1153 MakeCurrent_PrevReadable
= read
;
1154 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1155 MakeCurrent_PrevReadBuffer
= readBuffer
;
1157 /* Now make current! */
1158 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1159 ctx
->currentDpy
= dpy
;
1160 ctx
->currentDrawable
= draw
;
1161 ctx
->currentReadable
= read
;
1162 SetCurrentContext(ctx
);
1169 else if (!ctx
&& !draw
&& !read
) {
1170 /* release current context w/out assigning new one. */
1171 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1172 MakeCurrent_PrevContext
= 0;
1173 MakeCurrent_PrevDrawable
= 0;
1174 MakeCurrent_PrevReadable
= 0;
1175 MakeCurrent_PrevDrawBuffer
= 0;
1176 MakeCurrent_PrevReadBuffer
= 0;
1177 SetCurrentContext(NULL
);
1181 /* The args must either all be non-zero or all zero.
1190 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1192 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1197 glXGetCurrentContext(void)
1199 return GetCurrentContext();
1204 glXGetCurrentDisplay(void)
1206 GLXContext glxCtx
= glXGetCurrentContext();
1208 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1213 glXGetCurrentDisplayEXT(void)
1215 return glXGetCurrentDisplay();
1220 glXGetCurrentDrawable(void)
1222 GLXContext gc
= glXGetCurrentContext();
1223 return gc
? gc
->currentDrawable
: 0;
1228 glXGetCurrentReadDrawable(void)
1230 GLXContext gc
= glXGetCurrentContext();
1231 return gc
? gc
->currentReadable
: 0;
1236 glXGetCurrentReadDrawableSGI(void)
1238 return glXGetCurrentReadDrawable();
1243 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1248 v
= find_glx_visual( dpy
, visinfo
);
1250 v
= create_glx_visual( dpy
, visinfo
);
1252 /* unusable visual */
1257 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1261 return b
->ws
.drawable
;
1265 /*** GLX_MESA_pixmap_colormap ***/
1268 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1269 Pixmap pixmap
, Colormap cmap
)
1274 v
= find_glx_visual( dpy
, visinfo
);
1276 v
= create_glx_visual( dpy
, visinfo
);
1278 /* unusable visual */
1283 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1287 return b
->ws
.drawable
;
1292 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1294 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1296 XMesaDestroyBuffer(b
);
1298 else if (_mesa_getenv("MESA_DEBUG")) {
1299 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1305 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1306 unsigned long mask
)
1308 XMesaContext xm_src
= src
->xmesaContext
;
1309 XMesaContext xm_dst
= dst
->xmesaContext
;
1311 if (MakeCurrent_PrevContext
== src
) {
1314 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1319 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1322 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1323 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1329 return True
; /* we're faking GLX so always return success */
1334 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1336 GLXContext glxCtx
= ctx
;
1338 MakeCurrent_PrevContext
= 0;
1339 MakeCurrent_PrevDrawable
= 0;
1340 MakeCurrent_PrevReadable
= 0;
1341 MakeCurrent_PrevDrawBuffer
= 0;
1342 MakeCurrent_PrevReadBuffer
= 0;
1343 XMesaDestroyContext( glxCtx
->xmesaContext
);
1344 XMesaGarbageCollect();
1350 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1352 GLXContext glxCtx
= ctx
;
1354 return glxCtx
->isDirect
;
1360 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1362 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1363 static boolean firsttime
= 1, no_rast
= 0;
1366 no_rast
= getenv("SP_NO_RAST") != NULL
;
1374 XMesaSwapBuffers(buffer
);
1376 else if (_mesa_getenv("MESA_DEBUG")) {
1377 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1384 /*** GLX_MESA_copy_sub_buffer ***/
1387 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1388 int x
, int y
, int width
, int height
)
1390 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1392 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1394 else if (_mesa_getenv("MESA_DEBUG")) {
1395 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1401 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1404 /* Return GLX version, not Mesa version */
1405 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1406 *maj
= CLIENT_MAJOR_VERSION
;
1407 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1413 * Query the GLX attributes of the given XVisualInfo.
1416 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1422 return GLX_BAD_ATTRIBUTE
;
1423 *value
= (int) True
;
1425 case GLX_BUFFER_SIZE
:
1426 *value
= xmvis
->visinfo
->depth
;
1429 *value
= xmvis
->mesa_visual
.level
;
1433 return GLX_BAD_ATTRIBUTE
;
1434 if (xmvis
->mesa_visual
.rgbMode
) {
1441 case GLX_DOUBLEBUFFER
:
1442 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1445 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1447 case GLX_AUX_BUFFERS
:
1448 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1451 *value
= xmvis
->mesa_visual
.redBits
;
1453 case GLX_GREEN_SIZE
:
1454 *value
= xmvis
->mesa_visual
.greenBits
;
1457 *value
= xmvis
->mesa_visual
.blueBits
;
1459 case GLX_ALPHA_SIZE
:
1460 *value
= xmvis
->mesa_visual
.alphaBits
;
1462 case GLX_DEPTH_SIZE
:
1463 *value
= xmvis
->mesa_visual
.depthBits
;
1465 case GLX_STENCIL_SIZE
:
1466 *value
= xmvis
->mesa_visual
.stencilBits
;
1468 case GLX_ACCUM_RED_SIZE
:
1469 *value
= xmvis
->mesa_visual
.accumRedBits
;
1471 case GLX_ACCUM_GREEN_SIZE
:
1472 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1474 case GLX_ACCUM_BLUE_SIZE
:
1475 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1477 case GLX_ACCUM_ALPHA_SIZE
:
1478 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1482 * GLX_EXT_visual_info extension
1484 case GLX_X_VISUAL_TYPE_EXT
:
1485 switch (xmvis
->visinfo
->CLASS
) {
1486 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1487 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1488 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1489 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1490 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1491 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1494 case GLX_TRANSPARENT_TYPE_EXT
:
1496 *value
= GLX_NONE_EXT
;
1498 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1501 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1504 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1507 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1510 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1515 * GLX_EXT_visual_info extension
1517 case GLX_VISUAL_CAVEAT_EXT
:
1518 /* test for zero, just in case */
1519 if (xmvis
->mesa_visual
.visualRating
> 0)
1520 *value
= xmvis
->mesa_visual
.visualRating
;
1522 *value
= GLX_NONE_EXT
;
1526 * GLX_ARB_multisample
1528 case GLX_SAMPLE_BUFFERS_ARB
:
1531 case GLX_SAMPLES_ARB
:
1538 case GLX_SCREEN_EXT
:
1540 return GLX_BAD_ATTRIBUTE
;
1541 *value
= xmvis
->visinfo
->screen
;
1543 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1545 return GLX_BAD_ATTRIBUTE
;
1546 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1548 case GLX_RENDER_TYPE_SGIX
:
1550 return GLX_BAD_ATTRIBUTE
;
1551 if (xmvis
->mesa_visual
.rgbMode
)
1552 *value
= GLX_RGBA_BIT
;
1554 *value
= GLX_COLOR_INDEX_BIT
;
1556 case GLX_X_RENDERABLE_SGIX
:
1558 return GLX_BAD_ATTRIBUTE
;
1559 *value
= True
; /* XXX really? */
1561 case GLX_FBCONFIG_ID_SGIX
:
1563 return GLX_BAD_ATTRIBUTE
;
1564 *value
= xmvis
->visinfo
->visualid
;
1566 case GLX_MAX_PBUFFER_WIDTH
:
1568 return GLX_BAD_ATTRIBUTE
;
1569 /* XXX or MAX_WIDTH? */
1570 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1572 case GLX_MAX_PBUFFER_HEIGHT
:
1574 return GLX_BAD_ATTRIBUTE
;
1575 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1577 case GLX_MAX_PBUFFER_PIXELS
:
1579 return GLX_BAD_ATTRIBUTE
;
1580 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1581 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1585 return GLX_BAD_ATTRIBUTE
;
1586 *value
= xmvis
->visinfo
->visualid
;
1589 #ifdef GLX_EXT_texture_from_pixmap
1590 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1591 *value
= True
; /*XXX*/
1593 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1595 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1597 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1598 *value
= True
; /*XXX*/
1600 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1601 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1602 GLX_TEXTURE_2D_BIT_EXT
|
1603 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1605 case GLX_Y_INVERTED_EXT
:
1606 *value
= True
; /*XXX*/
1611 return GLX_BAD_ATTRIBUTE
;
1618 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1619 int attrib
, int *value
)
1623 if (!dpy
|| !visinfo
)
1624 return GLX_BAD_ATTRIBUTE
;
1626 xmvis
= find_glx_visual( dpy
, visinfo
);
1628 /* this visual wasn't obtained with glXChooseVisual */
1629 xmvis
= create_glx_visual( dpy
, visinfo
);
1631 /* this visual can't be used for GL rendering */
1632 if (attrib
==GLX_USE_GL
) {
1633 *value
= (int) False
;
1637 return GLX_BAD_VISUAL
;
1642 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1650 XMesaContext xmesa
= XMesaGetCurrentContext();
1651 XMesaFlush( xmesa
);
1659 XMesaContext xmesa
= XMesaGetCurrentContext();
1660 XMesaFlush( xmesa
);
1665 get_extensions( void )
1672 /* GLX 1.1 and later */
1674 glXQueryExtensionsString( Display
*dpy
, int screen
)
1678 return get_extensions();
1683 /* GLX 1.1 and later */
1685 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1687 static char version
[1000];
1688 sprintf(version
, "%d.%d %s",
1689 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1695 case GLX_EXTENSIONS
:
1696 return get_extensions();
1708 /* GLX 1.1 and later */
1710 glXGetClientString( Display
*dpy
, int name
)
1712 static char version
[1000];
1713 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1714 CLIENT_MINOR_VERSION
, xmesa_get_name());
1719 case GLX_EXTENSIONS
:
1720 return get_extensions();
1738 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1739 int attribute
, int *value
)
1741 XMesaVisual v
= (XMesaVisual
) config
;
1745 if (!dpy
|| !config
|| !value
)
1748 return get_config(v
, attribute
, value
, GL_TRUE
);
1752 PUBLIC GLXFBConfig
*
1753 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1755 XVisualInfo
*visuals
, visTemplate
;
1756 const long visMask
= VisualScreenMask
;
1759 /* Get list of all X visuals */
1760 visTemplate
.screen
= screen
;
1761 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1762 if (*nelements
> 0) {
1763 XMesaVisual
*results
;
1764 results
= (XMesaVisual
*) malloc(*nelements
* sizeof(XMesaVisual
));
1769 for (i
= 0; i
< *nelements
; i
++) {
1770 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1776 return (GLXFBConfig
*) results
;
1782 PUBLIC GLXFBConfig
*
1783 glXChooseFBConfig(Display
*dpy
, int screen
,
1784 const int *attribList
, int *nitems
)
1788 /* register ourselves as an extension on this display */
1789 register_with_display(dpy
);
1791 if (!attribList
|| !attribList
[0]) {
1792 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1793 return glXGetFBConfigs(dpy
, screen
, nitems
);
1796 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1798 GLXFBConfig
*config
= (GLXFBConfig
*) malloc(sizeof(XMesaVisual
));
1804 config
[0] = (GLXFBConfig
) xmvis
;
1805 return (GLXFBConfig
*) config
;
1814 PUBLIC XVisualInfo
*
1815 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1817 if (dpy
&& config
) {
1818 XMesaVisual xmvis
= (XMesaVisual
) config
;
1820 return xmvis
->vishandle
;
1822 /* create a new vishandle - the cached one may be stale */
1823 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1824 if (xmvis
->vishandle
) {
1825 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1827 return xmvis
->vishandle
;
1837 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1838 const int *attribList
)
1840 XMesaVisual xmvis
= (XMesaVisual
) config
;
1845 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1850 (void) attribList
; /* Ignored in GLX 1.3 */
1852 return win
; /* A hack for now */
1857 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1859 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1861 XMesaDestroyBuffer(b
);
1862 /* don't destroy X window */
1868 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1869 const int *attribList
)
1871 XMesaVisual v
= (XMesaVisual
) config
;
1874 int target
= 0, format
= 0, mipmap
= 0;
1877 if (!dpy
|| !config
|| !pixmap
)
1880 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1882 case GLX_TEXTURE_FORMAT_EXT
:
1885 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1886 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1887 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1895 case GLX_TEXTURE_TARGET_EXT
:
1898 case GLX_TEXTURE_1D_EXT
:
1899 case GLX_TEXTURE_2D_EXT
:
1900 case GLX_TEXTURE_RECTANGLE_EXT
:
1908 case GLX_MIPMAP_TEXTURE_EXT
:
1919 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1920 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1921 &value
, GL_TRUE
) != Success
1923 return 0; /* error! */
1926 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1927 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1928 &value
, GL_TRUE
) != Success
1930 return 0; /* error! */
1934 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1935 &value
, GL_TRUE
) != Success
1937 return 0; /* error! */
1940 if (target
== GLX_TEXTURE_1D_EXT
) {
1941 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1942 &value
, GL_TRUE
) != Success
1943 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1944 return 0; /* error! */
1947 else if (target
== GLX_TEXTURE_2D_EXT
) {
1948 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1949 &value
, GL_TRUE
) != Success
1950 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1951 return 0; /* error! */
1954 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1955 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1956 &value
, GL_TRUE
) != Success
1957 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1958 return 0; /* error! */
1962 if (format
|| target
|| mipmap
) {
1963 /* texture from pixmap */
1964 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1967 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1978 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1980 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
1982 XMesaDestroyBuffer(b
);
1983 /* don't destroy X pixmap */
1988 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
1990 XMesaVisual xmvis
= (XMesaVisual
) config
;
1993 int width
= 0, height
= 0;
1994 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
1998 for (attrib
= attribList
; *attrib
; attrib
++) {
2000 case GLX_PBUFFER_WIDTH
:
2004 case GLX_PBUFFER_HEIGHT
:
2008 case GLX_PRESERVED_CONTENTS
:
2010 preserveContents
= *attrib
;
2012 case GLX_LARGEST_PBUFFER
:
2014 useLargest
= *attrib
;
2021 if (width
== 0 || height
== 0)
2024 if (width
> MAX_WIDTH
|| height
> MAX_HEIGHT
) {
2025 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2026 * allocate the largest possible buffer.
2030 height
= MAX_HEIGHT
;
2034 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2035 /* A GLXPbuffer handle must be an X Drawable because that's what
2036 * glXMakeCurrent takes.
2039 xmbuf
->largestPbuffer
= useLargest
;
2040 xmbuf
->preservedContents
= preserveContents
;
2041 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2050 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2052 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2054 XMesaDestroyBuffer(b
);
2060 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2061 unsigned int *value
)
2063 GLuint width
, height
;
2064 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2068 /* make sure buffer's dimensions are up to date */
2069 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2071 switch (attribute
) {
2078 case GLX_PRESERVED_CONTENTS
:
2079 *value
= xmbuf
->preservedContents
;
2081 case GLX_LARGEST_PBUFFER
:
2082 *value
= xmbuf
->largestPbuffer
;
2084 case GLX_FBCONFIG_ID
:
2085 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2087 #ifdef GLX_EXT_texture_from_pixmap
2088 case GLX_TEXTURE_FORMAT_EXT
:
2089 *value
= xmbuf
->TextureFormat
;
2091 case GLX_TEXTURE_TARGET_EXT
:
2092 *value
= xmbuf
->TextureTarget
;
2094 case GLX_MIPMAP_TEXTURE_EXT
:
2095 *value
= xmbuf
->TextureMipmap
;
2100 return; /* raise BadValue error */
2106 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2107 int renderType
, GLXContext shareCtx
, Bool direct
)
2109 XMesaVisual xmvis
= (XMesaVisual
) config
;
2111 if (!dpy
|| !config
||
2112 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2115 return create_context(dpy
, xmvis
,
2116 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2118 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2123 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2125 GLXContext glxCtx
= ctx
;
2126 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2131 switch (attribute
) {
2132 case GLX_FBCONFIG_ID
:
2133 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2135 case GLX_RENDER_TYPE
:
2136 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2137 *value
= GLX_RGBA_TYPE
;
2139 *value
= GLX_COLOR_INDEX_TYPE
;
2145 return GLX_BAD_ATTRIBUTE
;
2152 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2154 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2156 xmbuf
->selectedEvents
= mask
;
2161 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2163 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2165 *mask
= xmbuf
->selectedEvents
;
2172 /*** GLX_SGI_swap_control ***/
2175 glXSwapIntervalSGI(int interval
)
2183 /*** GLX_SGI_video_sync ***/
2185 static unsigned int FrameCounter
= 0;
2188 glXGetVideoSyncSGI(unsigned int *count
)
2190 /* this is a bogus implementation */
2191 *count
= FrameCounter
++;
2196 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2198 if (divisor
<= 0 || remainder
< 0)
2199 return GLX_BAD_VALUE
;
2200 /* this is a bogus implementation */
2202 while (FrameCounter
% divisor
!= remainder
)
2204 *count
= FrameCounter
;
2210 /*** GLX_SGI_make_current_read ***/
2213 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2216 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2221 glXGetCurrentReadDrawableSGI(void)
2228 /*** GLX_SGIX_video_source ***/
2231 PUBLIC GLXVideoSourceSGIX
2232 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2233 VLPath path
, int nodeClass
, VLNode drainNode
)
2245 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2254 /*** GLX_EXT_import_context ***/
2257 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2264 glXGetContextIDEXT(const GLXContext context
)
2271 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2279 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2291 /*** GLX_SGIX_fbconfig ***/
2294 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2295 int attribute
, int *value
)
2297 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2300 PUBLIC GLXFBConfigSGIX
*
2301 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2304 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2305 attrib_list
, nelements
);
2310 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2313 XMesaVisual xmvis
= (XMesaVisual
) config
;
2314 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2315 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2320 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2321 int renderType
, GLXContext shareCtx
,
2324 XMesaVisual xmvis
= (XMesaVisual
) config
;
2326 if (!dpy
|| !config
||
2327 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2330 return create_context(dpy
, xmvis
,
2331 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2333 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2337 PUBLIC XVisualInfo
*
2338 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2340 return glXGetVisualFromFBConfig(dpy
, config
);
2344 PUBLIC GLXFBConfigSGIX
2345 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2347 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2349 /* This visual wasn't found with glXChooseVisual() */
2350 xmvis
= create_glx_visual(dpy
, vis
);
2353 return (GLXFBConfigSGIX
) xmvis
;
2358 /*** GLX_SGIX_pbuffer ***/
2360 PUBLIC GLXPbufferSGIX
2361 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2362 unsigned int width
, unsigned int height
,
2365 XMesaVisual xmvis
= (XMesaVisual
) config
;
2368 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2372 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2374 case GLX_PRESERVED_CONTENTS_SGIX
:
2376 preserveContents
= *attrib
; /* ignored */
2378 case GLX_LARGEST_PBUFFER_SGIX
:
2380 useLargest
= *attrib
; /* ignored */
2387 /* not used at this time */
2389 (void) preserveContents
;
2391 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2392 /* A GLXPbuffer handle must be an X Drawable because that's what
2393 * glXMakeCurrent takes.
2395 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2400 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2402 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2404 XMesaDestroyBuffer(xmbuf
);
2410 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2411 unsigned int *value
)
2413 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2416 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2420 switch (attribute
) {
2421 case GLX_PRESERVED_CONTENTS_SGIX
:
2424 case GLX_LARGEST_PBUFFER_SGIX
:
2425 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2427 case GLX_WIDTH_SGIX
:
2428 *value
= xmesa_buffer_width(xmbuf
);
2430 case GLX_HEIGHT_SGIX
:
2431 *value
= xmesa_buffer_height(xmbuf
);
2433 case GLX_EVENT_MASK_SGIX
:
2434 *value
= 0; /* XXX might be wrong */
2444 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2446 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2448 /* Note: we'll never generate clobber events */
2449 xmbuf
->selectedEvents
= mask
;
2455 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2456 unsigned long *mask
)
2458 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2460 *mask
= xmbuf
->selectedEvents
;
2469 /*** GLX_SGI_cushion ***/
2472 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2481 /*** GLX_SGIX_video_resize ***/
2484 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2495 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2496 int x
, int y
, int w
, int h
)
2509 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2510 int *x
, int *y
, int *w
, int *h
)
2523 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2524 int *dx
, int *dy
, int *dw
, int *dh
)
2537 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2548 /*** GLX_SGIX_dmbuffer **/
2550 #if defined(_DM_BUFFER_H_)
2552 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2553 DMparams
*params
, DMbuffer dmbuffer
)
2564 /*** GLX_SGIX_swap_group ***/
2567 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2576 /*** GLX_SGIX_swap_barrier ***/
2579 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2587 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2597 /*** GLX_SUN_get_transparent_index ***/
2600 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2606 (void) pTransparent
;
2612 /*** GLX_MESA_release_buffers ***/
2615 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2616 * (a window or pixmap) prior to destroying the GLXDrawable.
2619 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2621 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2623 XMesaDestroyBuffer(b
);
2629 /*** GLX_EXT_texture_from_pixmap ***/
2632 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2633 const int *attrib_list
)
2635 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2637 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2641 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2643 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2645 XMesaReleaseTexImage(dpy
, b
, buffer
);
2650 /*** GLX_ARB_create_context ***/
2653 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2654 GLXContext shareCtx
, Bool direct
,
2655 const int *attrib_list
)
2657 XMesaVisual xmvis
= (XMesaVisual
) config
;
2658 int majorVersion
= 1, minorVersion
= 0;
2659 int contextFlags
= 0x0;
2660 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2661 int renderType
= GLX_RGBA_TYPE
;
2664 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2665 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2667 /* parse attrib_list */
2668 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2669 switch (attrib_list
[i
]) {
2670 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2671 majorVersion
= attrib_list
[++i
];
2673 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2674 minorVersion
= attrib_list
[++i
];
2676 case GLX_CONTEXT_FLAGS_ARB
:
2677 contextFlags
= attrib_list
[++i
];
2679 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2680 profileMask
= attrib_list
[++i
];
2682 case GLX_RENDER_TYPE
:
2683 renderType
= attrib_list
[++i
];
2691 /* XXX generate BadValue X Error */
2696 /* check contextFlags */
2697 if (contextFlags
& ~contextFlagsAll
) {
2698 return NULL
; /* generate BadValue X Error */
2701 /* check profileMask */
2702 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2703 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
) {
2704 return NULL
; /* generate BadValue X Error */
2707 /* check version (generate BadMatch if bad) */
2708 switch (majorVersion
) {
2710 if (minorVersion
< 0 || minorVersion
> 5)
2714 if (minorVersion
< 0 || minorVersion
> 1)
2718 if (minorVersion
< 0 || minorVersion
> 2)
2722 if (minorVersion
< 0 || minorVersion
> 0)
2729 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2731 return NULL
; /* generate GLXBadProfileARB */
2733 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3)
2734 return NULL
; /* generate BadMatch */
2736 return create_context(dpy
, xmvis
,
2737 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2739 majorVersion
, minorVersion
,
2740 profileMask
, contextFlags
);