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
;
664 int min_red
=0, min_green
=0, min_blue
=0;
665 GLboolean rgb_flag
= rgbModeDefault
;
666 GLboolean alpha_flag
= GL_FALSE
;
667 GLboolean double_flag
= GL_FALSE
;
668 GLboolean stereo_flag
= GL_FALSE
;
669 GLint depth_size
= 0;
670 GLint stencil_size
= 0;
671 GLint accumRedSize
= 0;
672 GLint accumGreenSize
= 0;
673 GLint accumBlueSize
= 0;
674 GLint accumAlphaSize
= 0;
676 int visual_type
= DONT_CARE
;
677 int trans_type
= DONT_CARE
;
678 int trans_value
= DONT_CARE
;
679 GLint caveat
= DONT_CARE
;
680 XMesaVisual xmvis
= NULL
;
681 int desiredVisualID
= -1;
690 switch (*parselist
) {
701 case GLX_BUFFER_SIZE
:
703 min_ci
= *parselist
++;
707 level
= *parselist
++;
719 case GLX_DOUBLEBUFFER
:
722 double_flag
= *parselist
++;
725 double_flag
= GL_TRUE
;
731 stereo_flag
= *parselist
++;
734 stereo_flag
= GL_TRUE
;
737 case GLX_AUX_BUFFERS
:
739 numAux
= *parselist
++;
740 if (numAux
> MAX_AUX_BUFFERS
)
745 min_red
= *parselist
++;
749 min_green
= *parselist
++;
753 min_blue
= *parselist
++;
758 GLint size
= *parselist
++;
759 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
764 depth_size
= *parselist
++;
766 case GLX_STENCIL_SIZE
:
768 stencil_size
= *parselist
++;
770 case GLX_ACCUM_RED_SIZE
:
773 GLint size
= *parselist
++;
774 accumRedSize
= MAX2( accumRedSize
, size
);
777 case GLX_ACCUM_GREEN_SIZE
:
780 GLint size
= *parselist
++;
781 accumGreenSize
= MAX2( accumGreenSize
, size
);
784 case GLX_ACCUM_BLUE_SIZE
:
787 GLint size
= *parselist
++;
788 accumBlueSize
= MAX2( accumBlueSize
, size
);
791 case GLX_ACCUM_ALPHA_SIZE
:
794 GLint size
= *parselist
++;
795 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
800 * GLX_EXT_visual_info extension
802 case GLX_X_VISUAL_TYPE_EXT
:
804 visual_type
= *parselist
++;
806 case GLX_TRANSPARENT_TYPE_EXT
:
808 trans_type
= *parselist
++;
810 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
812 trans_value
= *parselist
++;
814 case GLX_TRANSPARENT_RED_VALUE_EXT
:
815 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
816 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
817 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
824 * GLX_EXT_visual_info extension
826 case GLX_VISUAL_CAVEAT_EXT
:
828 caveat
= *parselist
++; /* ignored for now */
832 * GLX_ARB_multisample
834 case GLX_SAMPLE_BUFFERS_ARB
:
835 /* ms not supported */
837 case GLX_SAMPLES_ARB
:
838 /* ms not supported */
844 case GLX_RENDER_TYPE
:
848 if (*parselist
& GLX_RGBA_BIT
) {
851 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
854 else if (*parselist
== 0) {
859 case GLX_DRAWABLE_TYPE
:
863 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
864 return NULL
; /* bad bit */
868 case GLX_FBCONFIG_ID
:
873 desiredVisualID
= *parselist
++;
875 case GLX_X_RENDERABLE
:
876 case GLX_MAX_PBUFFER_WIDTH
:
877 case GLX_MAX_PBUFFER_HEIGHT
:
878 case GLX_MAX_PBUFFER_PIXELS
:
880 return NULL
; /* invalid config option */
881 parselist
+= 2; /* ignore the parameter */
884 #ifdef GLX_EXT_texture_from_pixmap
885 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
886 parselist
++; /*skip*/
888 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
889 parselist
++; /*skip*/
891 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
892 parselist
++; /*skip*/
894 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
896 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
897 GLX_TEXTURE_2D_BIT_EXT
|
898 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
903 case GLX_Y_INVERTED_EXT
:
904 parselist
++; /*skip*/
913 /* undefined attribute */
914 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
924 * Since we're only simulating the GLX extension this function will never
925 * find any real GL visuals. Instead, all we can do is try to find an RGB
926 * or CI visual of appropriate depth. Other requested attributes such as
927 * double buffering, depth buffer, etc. will be associated with the X
928 * visual and stored in the VisualTable[].
930 if (desiredVisualID
!= -1) {
931 /* try to get a specific visual, by visualID */
934 temp
.visualid
= desiredVisualID
;
935 temp
.screen
= screen
;
936 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
938 /* give the visual some useful GLX attributes */
939 double_flag
= GL_TRUE
;
944 /* normal color planes */
945 /* Get an RGB visual */
946 int min_rgb
= min_red
+ min_green
+ min_blue
;
947 if (min_rgb
>1 && min_rgb
<8) {
948 /* a special case to be sure we can get a monochrome visual */
951 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
954 _mesa_warning(NULL
, "overlay not supported");
959 /* Note: we're not exactly obeying the glXChooseVisual rules here.
960 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
961 * largest depth buffer size, which is 32bits/value. Instead, we
962 * return 16 to maintain performance with earlier versions of Mesa.
964 if (stencil_size
> 0)
965 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
966 else if (depth_size
> 24)
968 else if (depth_size
> 16)
970 else if (depth_size
> 0) {
971 depth_size
= default_depth_bits();
975 alpha_flag
= default_alpha_bits() > 0;
978 /* we only support one size of stencil and accum buffers. */
979 if (stencil_size
> 0)
980 stencil_size
= STENCIL_BITS
;
982 if (accumRedSize
> 0 ||
983 accumGreenSize
> 0 ||
985 accumAlphaSize
> 0) {
989 accumBlueSize
= default_accum_bits();
991 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
994 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
995 stereo_flag
, depth_size
, stencil_size
,
996 accumRedSize
, accumGreenSize
,
997 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1004 PUBLIC XVisualInfo
*
1005 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1009 /* register ourselves as an extension on this display */
1010 register_with_display(dpy
);
1012 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1014 /* create a new vishandle - the cached one may be stale */
1015 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1016 if (xmvis
->vishandle
) {
1017 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1019 return xmvis
->vishandle
;
1027 * Helper function used by other glXCreateContext functions.
1030 create_context(Display
*dpy
, XMesaVisual xmvis
,
1031 XMesaContext shareCtx
, Bool direct
,
1032 unsigned major
, unsigned minor
,
1033 unsigned profileMask
, unsigned contextFlags
)
1040 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1044 /* deallocate unused windows/buffers */
1046 XMesaGarbageCollect();
1049 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1050 profileMask
, contextFlags
);
1051 if (!glxCtx
->xmesaContext
) {
1056 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1057 glxCtx
->currentDpy
= dpy
;
1058 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1065 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1066 GLXContext shareCtx
, Bool direct
)
1070 xmvis
= find_glx_visual( dpy
, visinfo
);
1072 /* This visual wasn't found with glXChooseVisual() */
1073 xmvis
= create_glx_visual( dpy
, visinfo
);
1075 /* unusable visual */
1080 return create_context(dpy
, xmvis
,
1081 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1083 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1087 /* XXX these may have to be removed due to thread-safety issues. */
1088 static GLXContext MakeCurrent_PrevContext
= 0;
1089 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1090 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1091 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1092 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1095 /* GLX 1.3 and later */
1097 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1098 GLXDrawable read
, GLXContext ctx
)
1100 GLXContext glxCtx
= ctx
;
1101 static boolean firsttime
= 1, no_rast
= 0;
1104 no_rast
= getenv("SP_NO_RAST") != NULL
;
1108 if (ctx
&& draw
&& read
) {
1109 XMesaBuffer drawBuffer
, readBuffer
;
1110 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1112 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1113 if (ctx
== MakeCurrent_PrevContext
1114 && draw
== MakeCurrent_PrevDrawable
) {
1115 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1118 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1121 /* drawable must be a new window! */
1122 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1124 /* Out of memory, or context/drawable depth mismatch */
1129 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1130 if (ctx
== MakeCurrent_PrevContext
1131 && read
== MakeCurrent_PrevReadable
) {
1132 readBuffer
= MakeCurrent_PrevReadBuffer
;
1135 readBuffer
= XMesaFindBuffer( dpy
, read
);
1138 /* drawable must be a new window! */
1139 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1141 /* Out of memory, or context/drawable depth mismatch */
1147 MakeCurrent_PrevContext
== ctx
&&
1148 MakeCurrent_PrevDrawable
== draw
&&
1149 MakeCurrent_PrevReadable
== read
&&
1150 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1151 MakeCurrent_PrevReadBuffer
== readBuffer
)
1154 MakeCurrent_PrevContext
= ctx
;
1155 MakeCurrent_PrevDrawable
= draw
;
1156 MakeCurrent_PrevReadable
= read
;
1157 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1158 MakeCurrent_PrevReadBuffer
= readBuffer
;
1160 /* Now make current! */
1161 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1162 ctx
->currentDpy
= dpy
;
1163 ctx
->currentDrawable
= draw
;
1164 ctx
->currentReadable
= read
;
1165 SetCurrentContext(ctx
);
1172 else if (!ctx
&& !draw
&& !read
) {
1173 /* release current context w/out assigning new one. */
1174 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1175 MakeCurrent_PrevContext
= 0;
1176 MakeCurrent_PrevDrawable
= 0;
1177 MakeCurrent_PrevReadable
= 0;
1178 MakeCurrent_PrevDrawBuffer
= 0;
1179 MakeCurrent_PrevReadBuffer
= 0;
1180 SetCurrentContext(NULL
);
1184 /* The args must either all be non-zero or all zero.
1193 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1195 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1200 glXGetCurrentContext(void)
1202 return GetCurrentContext();
1207 glXGetCurrentDisplay(void)
1209 GLXContext glxCtx
= glXGetCurrentContext();
1211 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1216 glXGetCurrentDisplayEXT(void)
1218 return glXGetCurrentDisplay();
1223 glXGetCurrentDrawable(void)
1225 GLXContext gc
= glXGetCurrentContext();
1226 return gc
? gc
->currentDrawable
: 0;
1231 glXGetCurrentReadDrawable(void)
1233 GLXContext gc
= glXGetCurrentContext();
1234 return gc
? gc
->currentReadable
: 0;
1239 glXGetCurrentReadDrawableSGI(void)
1241 return glXGetCurrentReadDrawable();
1246 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1251 v
= find_glx_visual( dpy
, visinfo
);
1253 v
= create_glx_visual( dpy
, visinfo
);
1255 /* unusable visual */
1260 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1264 return b
->ws
.drawable
;
1268 /*** GLX_MESA_pixmap_colormap ***/
1271 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1272 Pixmap pixmap
, Colormap cmap
)
1277 v
= find_glx_visual( dpy
, visinfo
);
1279 v
= create_glx_visual( dpy
, visinfo
);
1281 /* unusable visual */
1286 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1290 return b
->ws
.drawable
;
1295 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1297 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1299 XMesaDestroyBuffer(b
);
1301 else if (_mesa_getenv("MESA_DEBUG")) {
1302 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1308 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1309 unsigned long mask
)
1311 XMesaContext xm_src
= src
->xmesaContext
;
1312 XMesaContext xm_dst
= dst
->xmesaContext
;
1314 if (MakeCurrent_PrevContext
== src
) {
1317 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1322 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1325 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1326 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1332 return True
; /* we're faking GLX so always return success */
1337 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1339 GLXContext glxCtx
= ctx
;
1341 MakeCurrent_PrevContext
= 0;
1342 MakeCurrent_PrevDrawable
= 0;
1343 MakeCurrent_PrevReadable
= 0;
1344 MakeCurrent_PrevDrawBuffer
= 0;
1345 MakeCurrent_PrevReadBuffer
= 0;
1346 XMesaDestroyContext( glxCtx
->xmesaContext
);
1347 XMesaGarbageCollect();
1353 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1355 GLXContext glxCtx
= ctx
;
1357 return glxCtx
->isDirect
;
1363 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1365 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1366 static boolean firsttime
= 1, no_rast
= 0;
1369 no_rast
= getenv("SP_NO_RAST") != NULL
;
1377 XMesaSwapBuffers(buffer
);
1379 else if (_mesa_getenv("MESA_DEBUG")) {
1380 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1387 /*** GLX_MESA_copy_sub_buffer ***/
1390 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1391 int x
, int y
, int width
, int height
)
1393 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1395 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1397 else if (_mesa_getenv("MESA_DEBUG")) {
1398 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1404 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1407 /* Return GLX version, not Mesa version */
1408 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1409 *maj
= CLIENT_MAJOR_VERSION
;
1410 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1416 * Query the GLX attributes of the given XVisualInfo.
1419 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1425 return GLX_BAD_ATTRIBUTE
;
1426 *value
= (int) True
;
1428 case GLX_BUFFER_SIZE
:
1429 *value
= xmvis
->visinfo
->depth
;
1432 *value
= xmvis
->mesa_visual
.level
;
1436 return GLX_BAD_ATTRIBUTE
;
1437 if (xmvis
->mesa_visual
.rgbMode
) {
1444 case GLX_DOUBLEBUFFER
:
1445 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1448 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1450 case GLX_AUX_BUFFERS
:
1451 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1454 *value
= xmvis
->mesa_visual
.redBits
;
1456 case GLX_GREEN_SIZE
:
1457 *value
= xmvis
->mesa_visual
.greenBits
;
1460 *value
= xmvis
->mesa_visual
.blueBits
;
1462 case GLX_ALPHA_SIZE
:
1463 *value
= xmvis
->mesa_visual
.alphaBits
;
1465 case GLX_DEPTH_SIZE
:
1466 *value
= xmvis
->mesa_visual
.depthBits
;
1468 case GLX_STENCIL_SIZE
:
1469 *value
= xmvis
->mesa_visual
.stencilBits
;
1471 case GLX_ACCUM_RED_SIZE
:
1472 *value
= xmvis
->mesa_visual
.accumRedBits
;
1474 case GLX_ACCUM_GREEN_SIZE
:
1475 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1477 case GLX_ACCUM_BLUE_SIZE
:
1478 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1480 case GLX_ACCUM_ALPHA_SIZE
:
1481 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1485 * GLX_EXT_visual_info extension
1487 case GLX_X_VISUAL_TYPE_EXT
:
1488 switch (xmvis
->visinfo
->CLASS
) {
1489 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1490 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1491 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1492 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1493 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1494 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1497 case GLX_TRANSPARENT_TYPE_EXT
:
1499 *value
= GLX_NONE_EXT
;
1501 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1504 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1507 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1510 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1513 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1518 * GLX_EXT_visual_info extension
1520 case GLX_VISUAL_CAVEAT_EXT
:
1521 /* test for zero, just in case */
1522 if (xmvis
->mesa_visual
.visualRating
> 0)
1523 *value
= xmvis
->mesa_visual
.visualRating
;
1525 *value
= GLX_NONE_EXT
;
1529 * GLX_ARB_multisample
1531 case GLX_SAMPLE_BUFFERS_ARB
:
1534 case GLX_SAMPLES_ARB
:
1541 case GLX_SCREEN_EXT
:
1543 return GLX_BAD_ATTRIBUTE
;
1544 *value
= xmvis
->visinfo
->screen
;
1546 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1548 return GLX_BAD_ATTRIBUTE
;
1549 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1551 case GLX_RENDER_TYPE_SGIX
:
1553 return GLX_BAD_ATTRIBUTE
;
1554 if (xmvis
->mesa_visual
.rgbMode
)
1555 *value
= GLX_RGBA_BIT
;
1557 *value
= GLX_COLOR_INDEX_BIT
;
1559 case GLX_X_RENDERABLE_SGIX
:
1561 return GLX_BAD_ATTRIBUTE
;
1562 *value
= True
; /* XXX really? */
1564 case GLX_FBCONFIG_ID_SGIX
:
1566 return GLX_BAD_ATTRIBUTE
;
1567 *value
= xmvis
->visinfo
->visualid
;
1569 case GLX_MAX_PBUFFER_WIDTH
:
1571 return GLX_BAD_ATTRIBUTE
;
1572 /* XXX or MAX_WIDTH? */
1573 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1575 case GLX_MAX_PBUFFER_HEIGHT
:
1577 return GLX_BAD_ATTRIBUTE
;
1578 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1580 case GLX_MAX_PBUFFER_PIXELS
:
1582 return GLX_BAD_ATTRIBUTE
;
1583 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1584 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1588 return GLX_BAD_ATTRIBUTE
;
1589 *value
= xmvis
->visinfo
->visualid
;
1592 #ifdef GLX_EXT_texture_from_pixmap
1593 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1594 *value
= True
; /*XXX*/
1596 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1598 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1600 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1601 *value
= True
; /*XXX*/
1603 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1604 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1605 GLX_TEXTURE_2D_BIT_EXT
|
1606 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1608 case GLX_Y_INVERTED_EXT
:
1609 *value
= True
; /*XXX*/
1614 return GLX_BAD_ATTRIBUTE
;
1621 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1622 int attrib
, int *value
)
1626 if (!dpy
|| !visinfo
)
1627 return GLX_BAD_ATTRIBUTE
;
1629 xmvis
= find_glx_visual( dpy
, visinfo
);
1631 /* this visual wasn't obtained with glXChooseVisual */
1632 xmvis
= create_glx_visual( dpy
, visinfo
);
1634 /* this visual can't be used for GL rendering */
1635 if (attrib
==GLX_USE_GL
) {
1636 *value
= (int) False
;
1640 return GLX_BAD_VISUAL
;
1645 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1653 XMesaContext xmesa
= XMesaGetCurrentContext();
1654 XMesaFlush( xmesa
);
1662 XMesaContext xmesa
= XMesaGetCurrentContext();
1663 XMesaFlush( xmesa
);
1668 get_extensions( void )
1675 /* GLX 1.1 and later */
1677 glXQueryExtensionsString( Display
*dpy
, int screen
)
1681 return get_extensions();
1686 /* GLX 1.1 and later */
1688 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1690 static char version
[1000];
1691 sprintf(version
, "%d.%d %s",
1692 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1698 case GLX_EXTENSIONS
:
1699 return get_extensions();
1711 /* GLX 1.1 and later */
1713 glXGetClientString( Display
*dpy
, int name
)
1715 static char version
[1000];
1716 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1717 CLIENT_MINOR_VERSION
, xmesa_get_name());
1722 case GLX_EXTENSIONS
:
1723 return get_extensions();
1741 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1742 int attribute
, int *value
)
1744 XMesaVisual v
= (XMesaVisual
) config
;
1748 if (!dpy
|| !config
|| !value
)
1751 return get_config(v
, attribute
, value
, GL_TRUE
);
1755 PUBLIC GLXFBConfig
*
1756 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1758 XVisualInfo
*visuals
, visTemplate
;
1759 const long visMask
= VisualScreenMask
;
1762 /* Get list of all X visuals */
1763 visTemplate
.screen
= screen
;
1764 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1765 if (*nelements
> 0) {
1766 XMesaVisual
*results
;
1767 results
= (XMesaVisual
*) malloc(*nelements
* sizeof(XMesaVisual
));
1772 for (i
= 0; i
< *nelements
; i
++) {
1773 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1779 return (GLXFBConfig
*) results
;
1785 PUBLIC GLXFBConfig
*
1786 glXChooseFBConfig(Display
*dpy
, int screen
,
1787 const int *attribList
, int *nitems
)
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
);