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
69 /** XXX this could be based on gallium's max texture size */
70 #define PBUFFER_MAX_SIZE 16384
74 * The GLXContext typedef is defined as a pointer to this structure.
76 struct __GLXcontextRec
80 GLXDrawable currentDrawable
;
81 GLXDrawable currentReadable
;
84 XMesaContext xmesaContext
;
89 static pipe_tsd ContextTSD
;
91 /** Set current context for calling thread */
93 SetCurrentContext(GLXContext c
)
95 pipe_tsd_set(&ContextTSD
, c
);
98 /** Get current context for calling thread */
100 GetCurrentContext(void)
102 return pipe_tsd_get(&ContextTSD
);
107 /**********************************************************************/
108 /*** GLX Visual Code ***/
109 /**********************************************************************/
114 static XMesaVisual
*VisualTable
= NULL
;
115 static int NumVisuals
= 0;
119 /* Macro to handle c_class vs class field name in XVisualInfo struct */
120 #if defined(__cplusplus) || defined(c_plusplus)
121 #define CLASS c_class
129 * Test if the given XVisualInfo is usable for Mesa rendering.
132 is_usable_visual( XVisualInfo
*vinfo
)
134 switch (vinfo
->CLASS
) {
137 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
141 /* Any StaticColor/PseudoColor visual of at least 4 bits */
142 if (vinfo
->depth
>=4) {
150 /* Any depth of TrueColor or DirectColor works in RGB mode */
153 /* This should never happen */
160 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
161 * configuration in our list of GLX visuals.
164 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
165 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
166 GLboolean stereoFlag
,
167 GLint depth_size
, GLint stencil_size
,
168 GLint accumRedSize
, GLint accumGreenSize
,
169 GLint accumBlueSize
, GLint accumAlphaSize
,
170 GLint level
, GLint numAuxBuffers
)
172 GLboolean ximageFlag
= GL_TRUE
;
175 GLboolean comparePointers
;
178 /* Check if the MESA_BACK_BUFFER env var is set */
179 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
181 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
182 ximageFlag
= GL_FALSE
;
184 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
185 ximageFlag
= GL_TRUE
;
188 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
194 /* stereo not supported */
198 if (stencil_size
> 0 && depth_size
> 0)
201 /* Comparing IDs uses less memory but sometimes fails. */
202 /* XXX revisit this after 3.0 is finished. */
203 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
204 comparePointers
= GL_TRUE
;
206 comparePointers
= GL_FALSE
;
208 /* Force the visual to have an alpha channel */
209 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
212 /* First check if a matching visual is already in the list */
213 for (i
=0; i
<NumVisuals
; i
++) {
214 XMesaVisual v
= VisualTable
[i
];
215 if (v
->display
== dpy
216 && v
->mesa_visual
.level
== level
217 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
218 && v
->ximage_flag
== ximageFlag
219 && v
->mesa_visual
.rgbMode
== rgbFlag
220 && v
->mesa_visual
.doubleBufferMode
== dbFlag
221 && v
->mesa_visual
.stereoMode
== stereoFlag
222 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
223 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
224 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
225 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
226 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
227 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
228 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
229 /* now either compare XVisualInfo pointers or visual IDs */
230 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
231 || (comparePointers
&& v
->vishandle
== vinfo
)) {
237 /* Create a new visual and add it to the list. */
239 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
240 stereoFlag
, ximageFlag
,
241 depth_size
, stencil_size
,
242 accumRedSize
, accumBlueSize
,
243 accumBlueSize
, accumAlphaSize
, 0, level
,
246 /* Save a copy of the pointer now so we can find this visual again
247 * if we need to search for it in find_glx_visual().
249 xmvis
->vishandle
= vinfo
;
250 /* Allocate more space for additional visual */
251 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
252 sizeof(XMesaVisual
) * NumVisuals
,
253 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
254 /* add xmvis to the list */
255 VisualTable
[NumVisuals
] = xmvis
;
257 /* XXX minor hack, because XMesaCreateVisual doesn't support an
258 * aux buffers parameter.
260 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
267 * Return the default number of bits for the Z buffer.
268 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
269 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
270 * XXX probably do the same thing for stencil, accum, etc.
273 default_depth_bits(void)
276 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
285 default_alpha_bits(void)
288 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
297 default_accum_bits(void)
305 * Create a GLX visual from a regular XVisualInfo.
306 * This is called when Fake GLX is given an XVisualInfo which wasn't
307 * returned by glXChooseVisual. Since this is the first time we're
308 * considering this visual we'll take a guess at reasonable values
309 * for depth buffer size, stencil size, accum size, etc.
310 * This is the best we can do with a client-side emulation of GLX.
313 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
315 GLint zBits
= default_depth_bits();
316 GLint accBits
= default_accum_bits();
317 GLboolean alphaFlag
= default_alpha_bits() > 0;
319 if (is_usable_visual( visinfo
)) {
320 /* Configure this visual as RGB, double-buffered, depth-buffered. */
321 /* This is surely wrong for some people's needs but what else */
322 /* can be done? They should use glXChooseVisual(). */
323 return save_glx_visual( dpy
, visinfo
,
325 alphaFlag
, /* alpha */
326 GL_TRUE
, /* double */
327 GL_FALSE
, /* stereo */
329 8, /* stencil bits */
339 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
347 * Find the GLX visual associated with an XVisualInfo.
350 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
354 /* try to match visual id */
355 for (i
=0;i
<NumVisuals
;i
++) {
356 if (VisualTable
[i
]->display
==dpy
357 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
358 return VisualTable
[i
];
362 /* if that fails, try to match pointers */
363 for (i
=0;i
<NumVisuals
;i
++) {
364 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
365 return VisualTable
[i
];
374 * Try to get an X visual which matches the given arguments.
377 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
379 XVisualInfo temp
, *vis
;
382 unsigned int default_depth
;
385 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
390 default_depth
= DefaultDepth(dpy
,scr
);
391 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
393 if (depth
==default_depth
&& xclass
==default_class
) {
394 /* try to get root window's visual */
395 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
396 mask
|= VisualIDMask
;
399 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
401 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
402 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
403 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
405 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
406 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
407 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
408 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
422 * Retrieve the value of the given environment variable and find
423 * the X visual which matches it.
424 * Input: dpy - the display
425 * screen - the screen number
426 * varname - the name of the environment variable
427 * Return: an XVisualInfo pointer to NULL if error.
430 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
432 char value
[100], type
[100];
433 int depth
, xclass
= -1;
436 if (!_mesa_getenv( varname
)) {
440 strncpy( value
, _mesa_getenv(varname
), 100 );
443 sscanf( value
, "%s %d", type
, &depth
);
445 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
446 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
447 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
448 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
449 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
450 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
452 if (xclass
>-1 && depth
>0) {
453 vis
= get_visual( dpy
, scr
, depth
, xclass
);
459 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
468 * Select an X visual which satisfies the RGBA flag and minimum depth.
470 * screen - X display and screen number
471 * min_depth - minimum visual depth
472 * preferred_class - preferred GLX visual class or DONT_CARE
473 * Return: pointer to an XVisualInfo or NULL.
476 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
477 int preferred_class
)
480 int xclass
, visclass
= 0;
483 /* First see if the MESA_RGB_VISUAL env var is defined */
484 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
488 /* Otherwise, search for a suitable visual */
489 if (preferred_class
==DONT_CARE
) {
490 for (xclass
=0;xclass
<6;xclass
++) {
492 case 0: visclass
= TrueColor
; break;
493 case 1: visclass
= DirectColor
; break;
494 case 2: visclass
= PseudoColor
; break;
495 case 3: visclass
= StaticColor
; break;
496 case 4: visclass
= GrayScale
; break;
497 case 5: visclass
= StaticGray
; break;
500 /* start with shallowest */
501 for (depth
=0;depth
<=32;depth
++) {
502 if (visclass
==TrueColor
&& depth
==8) {
503 /* Special case: try to get 8-bit PseudoColor before */
504 /* 8-bit TrueColor */
505 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
510 vis
= get_visual( dpy
, screen
, depth
, visclass
);
517 /* start with deepest */
518 for (depth
=32;depth
>=min_depth
;depth
--) {
519 if (visclass
==TrueColor
&& depth
==8) {
520 /* Special case: try to get 8-bit PseudoColor before */
521 /* 8-bit TrueColor */
522 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
527 vis
= get_visual( dpy
, screen
, depth
, visclass
);
536 /* search for a specific visual class */
537 switch (preferred_class
) {
538 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
539 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
540 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
541 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
542 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
543 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
544 default: return NULL
;
547 /* start with shallowest */
548 for (depth
=0;depth
<=32;depth
++) {
549 vis
= get_visual( dpy
, screen
, depth
, visclass
);
556 /* start with deepest */
557 for (depth
=32;depth
>=min_depth
;depth
--) {
558 vis
= get_visual( dpy
, screen
, depth
, visclass
);
566 /* didn't find a visual */
573 /**********************************************************************/
574 /*** Display-related functions ***/
575 /**********************************************************************/
579 * Free all XMesaVisuals which are associated with the given display.
582 destroy_visuals_on_display(Display
*dpy
)
585 for (i
= 0; i
< NumVisuals
; i
++) {
586 if (VisualTable
[i
]->display
== dpy
) {
587 /* remove this visual */
589 free(VisualTable
[i
]);
590 for (j
= i
; j
< NumVisuals
- 1; j
++)
591 VisualTable
[j
] = VisualTable
[j
+ 1];
599 * Called from XCloseDisplay() to let us free our display-related data.
602 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
604 xmesa_destroy_buffers_on_display(dpy
);
605 destroy_visuals_on_display(dpy
);
611 * Look for the named extension on given display and return a pointer
612 * to the _XExtension data, or NULL if extension not found.
615 lookup_extension(Display
*dpy
, const char *extName
)
618 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
619 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
628 * Whenever we're given a new Display pointer, call this function to
629 * register our close_display_callback function.
632 register_with_display(Display
*dpy
)
634 const char *extName
= "MesaGLX";
637 ext
= lookup_extension(dpy
, extName
);
639 XExtCodes
*c
= XAddExtension(dpy
);
640 ext
= dpy
->ext_procs
; /* new extension is at head of list */
641 assert(c
->extension
== ext
->codes
.extension
);
643 ext
->name
= _mesa_strdup(extName
);
644 ext
->close_display
= close_display_callback
;
649 /**********************************************************************/
650 /*** Begin Fake GLX API Functions ***/
651 /**********************************************************************/
655 * Helper used by glXChooseVisual and glXChooseFBConfig.
656 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
658 * In either case, the attribute list is terminated with the value 'None'.
661 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
663 const GLboolean rgbModeDefault
= fbConfig
;
664 const int *parselist
;
666 int min_red
=0, min_green
=0, min_blue
=0;
667 GLboolean rgb_flag
= rgbModeDefault
;
668 GLboolean alpha_flag
= GL_FALSE
;
669 GLboolean double_flag
= GL_FALSE
;
670 GLboolean stereo_flag
= GL_FALSE
;
671 GLint depth_size
= 0;
672 GLint stencil_size
= 0;
673 GLint accumRedSize
= 0;
674 GLint accumGreenSize
= 0;
675 GLint accumBlueSize
= 0;
676 GLint accumAlphaSize
= 0;
678 int visual_type
= DONT_CARE
;
679 GLint caveat
= DONT_CARE
;
680 XMesaVisual xmvis
= NULL
;
681 int desiredVisualID
= -1;
690 switch (*parselist
) {
701 case GLX_BUFFER_SIZE
:
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
:
810 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
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)
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 /* register ourselves as an extension on this display */
1792 register_with_display(dpy
);
1794 if (!attribList
|| !attribList
[0]) {
1795 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1796 return glXGetFBConfigs(dpy
, screen
, nitems
);
1799 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1801 GLXFBConfig
*config
= (GLXFBConfig
*) malloc(sizeof(XMesaVisual
));
1807 config
[0] = (GLXFBConfig
) xmvis
;
1808 return (GLXFBConfig
*) config
;
1817 PUBLIC XVisualInfo
*
1818 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1820 if (dpy
&& config
) {
1821 XMesaVisual xmvis
= (XMesaVisual
) config
;
1823 return xmvis
->vishandle
;
1825 /* create a new vishandle - the cached one may be stale */
1826 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1827 if (xmvis
->vishandle
) {
1828 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1830 return xmvis
->vishandle
;
1840 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1841 const int *attribList
)
1843 XMesaVisual xmvis
= (XMesaVisual
) config
;
1848 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1853 (void) attribList
; /* Ignored in GLX 1.3 */
1855 return win
; /* A hack for now */
1860 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1862 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1864 XMesaDestroyBuffer(b
);
1865 /* don't destroy X window */
1871 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1872 const int *attribList
)
1874 XMesaVisual v
= (XMesaVisual
) config
;
1877 int target
= 0, format
= 0, mipmap
= 0;
1880 if (!dpy
|| !config
|| !pixmap
)
1883 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1885 case GLX_TEXTURE_FORMAT_EXT
:
1888 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1889 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1890 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1898 case GLX_TEXTURE_TARGET_EXT
:
1901 case GLX_TEXTURE_1D_EXT
:
1902 case GLX_TEXTURE_2D_EXT
:
1903 case GLX_TEXTURE_RECTANGLE_EXT
:
1911 case GLX_MIPMAP_TEXTURE_EXT
:
1922 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1923 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1924 &value
, GL_TRUE
) != Success
1926 return 0; /* error! */
1929 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1930 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1931 &value
, GL_TRUE
) != Success
1933 return 0; /* error! */
1937 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1938 &value
, GL_TRUE
) != Success
1940 return 0; /* error! */
1943 if (target
== GLX_TEXTURE_1D_EXT
) {
1944 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1945 &value
, GL_TRUE
) != Success
1946 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1947 return 0; /* error! */
1950 else if (target
== GLX_TEXTURE_2D_EXT
) {
1951 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1952 &value
, GL_TRUE
) != Success
1953 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1954 return 0; /* error! */
1957 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1958 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1959 &value
, GL_TRUE
) != Success
1960 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1961 return 0; /* error! */
1965 if (format
|| target
|| mipmap
) {
1966 /* texture from pixmap */
1967 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1970 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1981 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1983 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
1985 XMesaDestroyBuffer(b
);
1986 /* don't destroy X pixmap */
1991 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
1993 XMesaVisual xmvis
= (XMesaVisual
) config
;
1996 int width
= 0, height
= 0;
1997 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2001 for (attrib
= attribList
; *attrib
; attrib
++) {
2003 case GLX_PBUFFER_WIDTH
:
2007 case GLX_PBUFFER_HEIGHT
:
2011 case GLX_PRESERVED_CONTENTS
:
2013 preserveContents
= *attrib
;
2015 case GLX_LARGEST_PBUFFER
:
2017 useLargest
= *attrib
;
2024 if (width
== 0 || height
== 0)
2027 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2028 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2029 * allocate the largest possible buffer.
2032 width
= PBUFFER_MAX_SIZE
;
2033 height
= PBUFFER_MAX_SIZE
;
2037 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2038 /* A GLXPbuffer handle must be an X Drawable because that's what
2039 * glXMakeCurrent takes.
2042 xmbuf
->largestPbuffer
= useLargest
;
2043 xmbuf
->preservedContents
= preserveContents
;
2044 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2053 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2055 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2057 XMesaDestroyBuffer(b
);
2063 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2064 unsigned int *value
)
2066 GLuint width
, height
;
2067 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2071 /* make sure buffer's dimensions are up to date */
2072 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2074 switch (attribute
) {
2081 case GLX_PRESERVED_CONTENTS
:
2082 *value
= xmbuf
->preservedContents
;
2084 case GLX_LARGEST_PBUFFER
:
2085 *value
= xmbuf
->largestPbuffer
;
2087 case GLX_FBCONFIG_ID
:
2088 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2090 #ifdef GLX_EXT_texture_from_pixmap
2091 case GLX_TEXTURE_FORMAT_EXT
:
2092 *value
= xmbuf
->TextureFormat
;
2094 case GLX_TEXTURE_TARGET_EXT
:
2095 *value
= xmbuf
->TextureTarget
;
2097 case GLX_MIPMAP_TEXTURE_EXT
:
2098 *value
= xmbuf
->TextureMipmap
;
2103 return; /* raise BadValue error */
2109 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2110 int renderType
, GLXContext shareCtx
, Bool direct
)
2112 XMesaVisual xmvis
= (XMesaVisual
) config
;
2114 if (!dpy
|| !config
||
2115 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2118 return create_context(dpy
, xmvis
,
2119 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2121 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2126 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2128 GLXContext glxCtx
= ctx
;
2129 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2134 switch (attribute
) {
2135 case GLX_FBCONFIG_ID
:
2136 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2138 case GLX_RENDER_TYPE
:
2139 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2140 *value
= GLX_RGBA_TYPE
;
2142 *value
= GLX_COLOR_INDEX_TYPE
;
2148 return GLX_BAD_ATTRIBUTE
;
2155 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2157 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2159 xmbuf
->selectedEvents
= mask
;
2164 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2166 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2168 *mask
= xmbuf
->selectedEvents
;
2175 /*** GLX_SGI_swap_control ***/
2178 glXSwapIntervalSGI(int interval
)
2186 /*** GLX_SGI_video_sync ***/
2188 static unsigned int FrameCounter
= 0;
2191 glXGetVideoSyncSGI(unsigned int *count
)
2193 /* this is a bogus implementation */
2194 *count
= FrameCounter
++;
2199 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2201 if (divisor
<= 0 || remainder
< 0)
2202 return GLX_BAD_VALUE
;
2203 /* this is a bogus implementation */
2205 while (FrameCounter
% divisor
!= remainder
)
2207 *count
= FrameCounter
;
2213 /*** GLX_SGI_make_current_read ***/
2216 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2219 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2224 glXGetCurrentReadDrawableSGI(void)
2231 /*** GLX_SGIX_video_source ***/
2234 PUBLIC GLXVideoSourceSGIX
2235 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2236 VLPath path
, int nodeClass
, VLNode drainNode
)
2248 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2257 /*** GLX_EXT_import_context ***/
2260 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2267 glXGetContextIDEXT(const GLXContext context
)
2274 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2282 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2294 /*** GLX_SGIX_fbconfig ***/
2297 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2298 int attribute
, int *value
)
2300 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2303 PUBLIC GLXFBConfigSGIX
*
2304 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2307 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2308 attrib_list
, nelements
);
2313 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2316 XMesaVisual xmvis
= (XMesaVisual
) config
;
2317 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2318 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2323 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2324 int renderType
, GLXContext shareCtx
,
2327 XMesaVisual xmvis
= (XMesaVisual
) config
;
2329 if (!dpy
|| !config
||
2330 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2333 return create_context(dpy
, xmvis
,
2334 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2336 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2340 PUBLIC XVisualInfo
*
2341 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2343 return glXGetVisualFromFBConfig(dpy
, config
);
2347 PUBLIC GLXFBConfigSGIX
2348 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2350 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2352 /* This visual wasn't found with glXChooseVisual() */
2353 xmvis
= create_glx_visual(dpy
, vis
);
2356 return (GLXFBConfigSGIX
) xmvis
;
2361 /*** GLX_SGIX_pbuffer ***/
2363 PUBLIC GLXPbufferSGIX
2364 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2365 unsigned int width
, unsigned int height
,
2368 XMesaVisual xmvis
= (XMesaVisual
) config
;
2371 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2375 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2377 case GLX_PRESERVED_CONTENTS_SGIX
:
2379 preserveContents
= *attrib
; /* ignored */
2381 case GLX_LARGEST_PBUFFER_SGIX
:
2383 useLargest
= *attrib
; /* ignored */
2390 /* not used at this time */
2392 (void) preserveContents
;
2394 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2395 /* A GLXPbuffer handle must be an X Drawable because that's what
2396 * glXMakeCurrent takes.
2398 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2403 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2405 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2407 XMesaDestroyBuffer(xmbuf
);
2413 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2414 unsigned int *value
)
2416 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2419 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2423 switch (attribute
) {
2424 case GLX_PRESERVED_CONTENTS_SGIX
:
2427 case GLX_LARGEST_PBUFFER_SGIX
:
2428 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2430 case GLX_WIDTH_SGIX
:
2431 *value
= xmesa_buffer_width(xmbuf
);
2433 case GLX_HEIGHT_SGIX
:
2434 *value
= xmesa_buffer_height(xmbuf
);
2436 case GLX_EVENT_MASK_SGIX
:
2437 *value
= 0; /* XXX might be wrong */
2447 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2449 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2451 /* Note: we'll never generate clobber events */
2452 xmbuf
->selectedEvents
= mask
;
2458 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2459 unsigned long *mask
)
2461 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2463 *mask
= xmbuf
->selectedEvents
;
2472 /*** GLX_SGI_cushion ***/
2475 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2484 /*** GLX_SGIX_video_resize ***/
2487 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2498 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2499 int x
, int y
, int w
, int h
)
2512 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2513 int *x
, int *y
, int *w
, int *h
)
2526 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2527 int *dx
, int *dy
, int *dw
, int *dh
)
2540 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2551 /*** GLX_SGIX_dmbuffer **/
2553 #if defined(_DM_BUFFER_H_)
2555 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2556 DMparams
*params
, DMbuffer dmbuffer
)
2567 /*** GLX_SGIX_swap_group ***/
2570 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2579 /*** GLX_SGIX_swap_barrier ***/
2582 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2590 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2600 /*** GLX_SUN_get_transparent_index ***/
2603 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2609 (void) pTransparent
;
2615 /*** GLX_MESA_release_buffers ***/
2618 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2619 * (a window or pixmap) prior to destroying the GLXDrawable.
2622 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2624 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2626 XMesaDestroyBuffer(b
);
2632 /*** GLX_EXT_texture_from_pixmap ***/
2635 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2636 const int *attrib_list
)
2638 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2640 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2644 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2646 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2648 XMesaReleaseTexImage(dpy
, b
, buffer
);
2653 /*** GLX_ARB_create_context ***/
2656 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2657 GLXContext shareCtx
, Bool direct
,
2658 const int *attrib_list
)
2660 XMesaVisual xmvis
= (XMesaVisual
) config
;
2661 int majorVersion
= 1, minorVersion
= 0;
2662 int contextFlags
= 0x0;
2663 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2664 int renderType
= GLX_RGBA_TYPE
;
2667 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2668 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2670 /* parse attrib_list */
2671 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2672 switch (attrib_list
[i
]) {
2673 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2674 majorVersion
= attrib_list
[++i
];
2676 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2677 minorVersion
= attrib_list
[++i
];
2679 case GLX_CONTEXT_FLAGS_ARB
:
2680 contextFlags
= attrib_list
[++i
];
2682 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2683 profileMask
= attrib_list
[++i
];
2685 case GLX_RENDER_TYPE
:
2686 renderType
= attrib_list
[++i
];
2694 /* XXX generate BadValue X Error */
2699 /* check contextFlags */
2700 if (contextFlags
& ~contextFlagsAll
) {
2701 return NULL
; /* generate BadValue X Error */
2704 /* check profileMask */
2705 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2706 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
) {
2707 return NULL
; /* generate BadValue X Error */
2710 /* check version (generate BadMatch if bad) */
2711 switch (majorVersion
) {
2713 if (minorVersion
< 0 || minorVersion
> 5)
2717 if (minorVersion
< 0 || minorVersion
> 1)
2721 if (minorVersion
< 0 || minorVersion
> 2)
2725 if (minorVersion
< 0 || minorVersion
> 0)
2732 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2734 return NULL
; /* generate GLXBadProfileARB */
2736 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3)
2737 return NULL
; /* generate BadMatch */
2739 return create_context(dpy
, xmvis
,
2740 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2742 majorVersion
, minorVersion
,
2743 profileMask
, contextFlags
);