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 /* This is appended onto the glXGetClient/ServerString version strings. */
50 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
52 /* Who implemented this GLX? */
53 #define VENDOR "Brian Paul"
56 "GLX_MESA_copy_sub_buffer " \
57 "GLX_MESA_pixmap_colormap " \
58 "GLX_MESA_release_buffers " \
59 "GLX_ARB_get_proc_address " \
60 "GLX_EXT_texture_from_pixmap " \
61 "GLX_EXT_visual_info " \
62 "GLX_EXT_visual_rating " \
63 /*"GLX_SGI_video_sync "*/ \
64 "GLX_SGIX_fbconfig " \
67 #define DEFAULT_DIRECT GL_TRUE
72 * The GLXContext typedef is defined as a pointer to this structure.
74 struct __GLXcontextRec
78 GLXDrawable currentDrawable
;
79 GLXDrawable currentReadable
;
82 XMesaContext xmesaContext
;
87 static pipe_tsd ContextTSD
;
89 /** Set current context for calling thread */
91 SetCurrentContext(GLXContext c
)
93 pipe_tsd_set(&ContextTSD
, c
);
96 /** Get current context for calling thread */
98 GetCurrentContext(void)
100 return pipe_tsd_get(&ContextTSD
);
105 /**********************************************************************/
106 /*** GLX Visual Code ***/
107 /**********************************************************************/
112 static XMesaVisual
*VisualTable
= NULL
;
113 static int NumVisuals
= 0;
117 /* Macro to handle c_class vs class field name in XVisualInfo struct */
118 #if defined(__cplusplus) || defined(c_plusplus)
119 #define CLASS c_class
127 * Test if the given XVisualInfo is usable for Mesa rendering.
130 is_usable_visual( XVisualInfo
*vinfo
)
132 switch (vinfo
->CLASS
) {
135 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
139 /* Any StaticColor/PseudoColor visual of at least 4 bits */
140 if (vinfo
->depth
>=4) {
148 /* Any depth of TrueColor or DirectColor works in RGB mode */
151 /* This should never happen */
158 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
159 * configuration in our list of GLX visuals.
162 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
163 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
164 GLboolean stereoFlag
,
165 GLint depth_size
, GLint stencil_size
,
166 GLint accumRedSize
, GLint accumGreenSize
,
167 GLint accumBlueSize
, GLint accumAlphaSize
,
168 GLint level
, GLint numAuxBuffers
)
170 GLboolean ximageFlag
= GL_TRUE
;
173 GLboolean comparePointers
;
176 /* Check if the MESA_BACK_BUFFER env var is set */
177 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
179 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
180 ximageFlag
= GL_FALSE
;
182 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
183 ximageFlag
= GL_TRUE
;
186 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
192 /* stereo not supported */
196 if (stencil_size
> 0 && depth_size
> 0)
199 /* Comparing IDs uses less memory but sometimes fails. */
200 /* XXX revisit this after 3.0 is finished. */
201 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
202 comparePointers
= GL_TRUE
;
204 comparePointers
= GL_FALSE
;
206 /* Force the visual to have an alpha channel */
207 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
210 /* First check if a matching visual is already in the list */
211 for (i
=0; i
<NumVisuals
; i
++) {
212 XMesaVisual v
= VisualTable
[i
];
213 if (v
->display
== dpy
214 && v
->mesa_visual
.level
== level
215 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
216 && v
->ximage_flag
== ximageFlag
217 && v
->mesa_visual
.rgbMode
== rgbFlag
218 && v
->mesa_visual
.doubleBufferMode
== dbFlag
219 && v
->mesa_visual
.stereoMode
== stereoFlag
220 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
221 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
222 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
223 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
224 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
225 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
226 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
227 /* now either compare XVisualInfo pointers or visual IDs */
228 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
229 || (comparePointers
&& v
->vishandle
== vinfo
)) {
235 /* Create a new visual and add it to the list. */
237 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
238 stereoFlag
, ximageFlag
,
239 depth_size
, stencil_size
,
240 accumRedSize
, accumBlueSize
,
241 accumBlueSize
, accumAlphaSize
, 0, level
,
244 /* Save a copy of the pointer now so we can find this visual again
245 * if we need to search for it in find_glx_visual().
247 xmvis
->vishandle
= vinfo
;
248 /* Allocate more space for additional visual */
249 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
250 sizeof(XMesaVisual
) * NumVisuals
,
251 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
252 /* add xmvis to the list */
253 VisualTable
[NumVisuals
] = xmvis
;
255 /* XXX minor hack, because XMesaCreateVisual doesn't support an
256 * aux buffers parameter.
258 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
265 * Return the default number of bits for the Z buffer.
266 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
267 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
268 * XXX probably do the same thing for stencil, accum, etc.
271 default_depth_bits(void)
274 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
278 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
283 default_alpha_bits(void)
286 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
295 default_accum_bits(void)
303 * Create a GLX visual from a regular XVisualInfo.
304 * This is called when Fake GLX is given an XVisualInfo which wasn't
305 * returned by glXChooseVisual. Since this is the first time we're
306 * considering this visual we'll take a guess at reasonable values
307 * for depth buffer size, stencil size, accum size, etc.
308 * This is the best we can do with a client-side emulation of GLX.
311 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
313 GLint zBits
= default_depth_bits();
314 GLint accBits
= default_accum_bits();
315 GLboolean alphaFlag
= default_alpha_bits() > 0;
317 if (is_usable_visual( visinfo
)) {
318 /* Configure this visual as RGB, double-buffered, depth-buffered. */
319 /* This is surely wrong for some people's needs but what else */
320 /* can be done? They should use glXChooseVisual(). */
321 return save_glx_visual( dpy
, visinfo
,
323 alphaFlag
, /* alpha */
324 GL_TRUE
, /* double */
325 GL_FALSE
, /* stereo */
337 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
345 * Find the GLX visual associated with an XVisualInfo.
348 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
352 /* try to match visual id */
353 for (i
=0;i
<NumVisuals
;i
++) {
354 if (VisualTable
[i
]->display
==dpy
355 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
356 return VisualTable
[i
];
360 /* if that fails, try to match pointers */
361 for (i
=0;i
<NumVisuals
;i
++) {
362 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
363 return VisualTable
[i
];
372 * Try to get an X visual which matches the given arguments.
375 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
377 XVisualInfo temp
, *vis
;
380 unsigned int default_depth
;
383 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
388 default_depth
= DefaultDepth(dpy
,scr
);
389 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
391 if (depth
==default_depth
&& xclass
==default_class
) {
392 /* try to get root window's visual */
393 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
394 mask
|= VisualIDMask
;
397 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
399 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
400 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
401 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
403 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
404 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
405 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
406 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
420 * Retrieve the value of the given environment variable and find
421 * the X visual which matches it.
422 * Input: dpy - the display
423 * screen - the screen number
424 * varname - the name of the environment variable
425 * Return: an XVisualInfo pointer to NULL if error.
428 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
430 char value
[100], type
[100];
431 int depth
, xclass
= -1;
434 if (!_mesa_getenv( varname
)) {
438 strncpy( value
, _mesa_getenv(varname
), 100 );
441 sscanf( value
, "%s %d", type
, &depth
);
443 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
444 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
445 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
446 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
447 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
448 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
450 if (xclass
>-1 && depth
>0) {
451 vis
= get_visual( dpy
, scr
, depth
, xclass
);
457 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
466 * Select an X visual which satisfies the RGBA flag and minimum depth.
468 * screen - X display and screen number
469 * min_depth - minimum visual depth
470 * preferred_class - preferred GLX visual class or DONT_CARE
471 * Return: pointer to an XVisualInfo or NULL.
474 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
475 int preferred_class
)
478 int xclass
, visclass
= 0;
481 /* First see if the MESA_RGB_VISUAL env var is defined */
482 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
486 /* Otherwise, search for a suitable visual */
487 if (preferred_class
==DONT_CARE
) {
488 for (xclass
=0;xclass
<6;xclass
++) {
490 case 0: visclass
= TrueColor
; break;
491 case 1: visclass
= DirectColor
; break;
492 case 2: visclass
= PseudoColor
; break;
493 case 3: visclass
= StaticColor
; break;
494 case 4: visclass
= GrayScale
; break;
495 case 5: visclass
= StaticGray
; break;
498 /* start with shallowest */
499 for (depth
=0;depth
<=32;depth
++) {
500 if (visclass
==TrueColor
&& depth
==8) {
501 /* Special case: try to get 8-bit PseudoColor before */
502 /* 8-bit TrueColor */
503 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
508 vis
= get_visual( dpy
, screen
, depth
, visclass
);
515 /* start with deepest */
516 for (depth
=32;depth
>=min_depth
;depth
--) {
517 if (visclass
==TrueColor
&& depth
==8) {
518 /* Special case: try to get 8-bit PseudoColor before */
519 /* 8-bit TrueColor */
520 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
525 vis
= get_visual( dpy
, screen
, depth
, visclass
);
534 /* search for a specific visual class */
535 switch (preferred_class
) {
536 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
537 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
538 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
539 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
540 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
541 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
542 default: return NULL
;
545 /* start with shallowest */
546 for (depth
=0;depth
<=32;depth
++) {
547 vis
= get_visual( dpy
, screen
, depth
, visclass
);
554 /* start with deepest */
555 for (depth
=32;depth
>=min_depth
;depth
--) {
556 vis
= get_visual( dpy
, screen
, depth
, visclass
);
564 /* didn't find a visual */
571 /**********************************************************************/
572 /*** Display-related functions ***/
573 /**********************************************************************/
577 * Free all XMesaVisuals which are associated with the given display.
580 destroy_visuals_on_display(Display
*dpy
)
583 for (i
= 0; i
< NumVisuals
; i
++) {
584 if (VisualTable
[i
]->display
== dpy
) {
585 /* remove this visual */
587 free(VisualTable
[i
]);
588 for (j
= i
; j
< NumVisuals
- 1; j
++)
589 VisualTable
[j
] = VisualTable
[j
+ 1];
597 * Called from XCloseDisplay() to let us free our display-related data.
600 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
602 xmesa_destroy_buffers_on_display(dpy
);
603 destroy_visuals_on_display(dpy
);
609 * Look for the named extension on given display and return a pointer
610 * to the _XExtension data, or NULL if extension not found.
613 lookup_extension(Display
*dpy
, const char *extName
)
616 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
617 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
626 * Whenever we're given a new Display pointer, call this function to
627 * register our close_display_callback function.
630 register_with_display(Display
*dpy
)
632 const char *extName
= "MesaGLX";
635 ext
= lookup_extension(dpy
, extName
);
637 XExtCodes
*c
= XAddExtension(dpy
);
638 ext
= dpy
->ext_procs
; /* new extension is at head of list */
639 assert(c
->extension
== ext
->codes
.extension
);
641 ext
->name
= _mesa_strdup(extName
);
642 ext
->close_display
= close_display_callback
;
647 /**********************************************************************/
648 /*** Begin Fake GLX API Functions ***/
649 /**********************************************************************/
653 * Helper used by glXChooseVisual and glXChooseFBConfig.
654 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
656 * In either case, the attribute list is terminated with the value 'None'.
659 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
661 const GLboolean rgbModeDefault
= fbConfig
;
662 const int *parselist
;
665 int min_red
=0, min_green
=0, min_blue
=0;
666 GLboolean rgb_flag
= rgbModeDefault
;
667 GLboolean alpha_flag
= GL_FALSE
;
668 GLboolean double_flag
= GL_FALSE
;
669 GLboolean stereo_flag
= GL_FALSE
;
670 GLint depth_size
= 0;
671 GLint stencil_size
= 0;
672 GLint accumRedSize
= 0;
673 GLint accumGreenSize
= 0;
674 GLint accumBlueSize
= 0;
675 GLint accumAlphaSize
= 0;
677 int visual_type
= DONT_CARE
;
678 int trans_type
= DONT_CARE
;
679 int trans_value
= DONT_CARE
;
680 GLint caveat
= DONT_CARE
;
681 XMesaVisual xmvis
= NULL
;
682 int desiredVisualID
= -1;
691 switch (*parselist
) {
702 case GLX_BUFFER_SIZE
:
704 min_ci
= *parselist
++;
708 level
= *parselist
++;
720 case GLX_DOUBLEBUFFER
:
723 double_flag
= *parselist
++;
726 double_flag
= GL_TRUE
;
732 stereo_flag
= *parselist
++;
735 stereo_flag
= GL_TRUE
;
738 case GLX_AUX_BUFFERS
:
740 numAux
= *parselist
++;
741 if (numAux
> MAX_AUX_BUFFERS
)
746 min_red
= *parselist
++;
750 min_green
= *parselist
++;
754 min_blue
= *parselist
++;
759 GLint size
= *parselist
++;
760 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
765 depth_size
= *parselist
++;
767 case GLX_STENCIL_SIZE
:
769 stencil_size
= *parselist
++;
771 case GLX_ACCUM_RED_SIZE
:
774 GLint size
= *parselist
++;
775 accumRedSize
= MAX2( accumRedSize
, size
);
778 case GLX_ACCUM_GREEN_SIZE
:
781 GLint size
= *parselist
++;
782 accumGreenSize
= MAX2( accumGreenSize
, size
);
785 case GLX_ACCUM_BLUE_SIZE
:
788 GLint size
= *parselist
++;
789 accumBlueSize
= MAX2( accumBlueSize
, size
);
792 case GLX_ACCUM_ALPHA_SIZE
:
795 GLint size
= *parselist
++;
796 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
801 * GLX_EXT_visual_info extension
803 case GLX_X_VISUAL_TYPE_EXT
:
805 visual_type
= *parselist
++;
807 case GLX_TRANSPARENT_TYPE_EXT
:
809 trans_type
= *parselist
++;
811 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
813 trans_value
= *parselist
++;
815 case GLX_TRANSPARENT_RED_VALUE_EXT
:
816 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
817 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
818 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
825 * GLX_EXT_visual_info extension
827 case GLX_VISUAL_CAVEAT_EXT
:
829 caveat
= *parselist
++; /* ignored for now */
833 * GLX_ARB_multisample
835 case GLX_SAMPLE_BUFFERS_ARB
:
836 /* ms not supported */
838 case GLX_SAMPLES_ARB
:
839 /* ms not supported */
845 case GLX_RENDER_TYPE
:
849 if (*parselist
& GLX_RGBA_BIT
) {
852 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
855 else if (*parselist
== 0) {
860 case GLX_DRAWABLE_TYPE
:
864 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
865 return NULL
; /* bad bit */
869 case GLX_FBCONFIG_ID
:
873 desiredVisualID
= *parselist
++;
875 case GLX_X_RENDERABLE
:
882 #ifdef GLX_EXT_texture_from_pixmap
883 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
884 parselist
++; /*skip*/
886 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
887 parselist
++; /*skip*/
889 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
890 parselist
++; /*skip*/
892 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
894 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
895 GLX_TEXTURE_2D_BIT_EXT
|
896 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
901 case GLX_Y_INVERTED_EXT
:
902 parselist
++; /*skip*/
911 /* undefined attribute */
912 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
922 * Since we're only simulating the GLX extension this function will never
923 * find any real GL visuals. Instead, all we can do is try to find an RGB
924 * or CI visual of appropriate depth. Other requested attributes such as
925 * double buffering, depth buffer, etc. will be associated with the X
926 * visual and stored in the VisualTable[].
928 if (desiredVisualID
!= -1) {
929 /* try to get a specific visual, by visualID */
932 temp
.visualid
= desiredVisualID
;
933 temp
.screen
= screen
;
934 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
936 /* give the visual some useful GLX attributes */
937 double_flag
= GL_TRUE
;
942 /* normal color planes */
943 /* Get an RGB visual */
944 int min_rgb
= min_red
+ min_green
+ min_blue
;
945 if (min_rgb
>1 && min_rgb
<8) {
946 /* a special case to be sure we can get a monochrome visual */
949 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
952 _mesa_warning(NULL
, "overlay not supported");
957 /* Note: we're not exactly obeying the glXChooseVisual rules here.
958 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
959 * largest depth buffer size, which is 32bits/value. Instead, we
960 * return 16 to maintain performance with earlier versions of Mesa.
962 if (stencil_size
> 0)
963 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
964 else if (depth_size
> 24)
966 else if (depth_size
> 16)
968 else if (depth_size
> 0) {
969 depth_size
= default_depth_bits();
973 alpha_flag
= default_alpha_bits() > 0;
976 /* we only support one size of stencil and accum buffers. */
977 if (stencil_size
> 0)
978 stencil_size
= STENCIL_BITS
;
980 if (accumRedSize
> 0 ||
981 accumGreenSize
> 0 ||
983 accumAlphaSize
> 0) {
987 accumBlueSize
= default_accum_bits();
989 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
992 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
993 stereo_flag
, depth_size
, stencil_size
,
994 accumRedSize
, accumGreenSize
,
995 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1002 PUBLIC XVisualInfo
*
1003 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1007 /* register ourselves as an extension on this display */
1008 register_with_display(dpy
);
1010 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1012 /* create a new vishandle - the cached one may be stale */
1013 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1014 if (xmvis
->vishandle
) {
1015 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1017 return xmvis
->vishandle
;
1025 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1026 GLXContext share_list
, Bool direct
)
1030 GLXContext shareCtx
= share_list
;
1032 if (!dpy
|| !visinfo
)
1035 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1039 /* deallocate unused windows/buffers */
1041 XMesaGarbageCollect();
1044 xmvis
= find_glx_visual( dpy
, visinfo
);
1046 /* This visual wasn't found with glXChooseVisual() */
1047 xmvis
= create_glx_visual( dpy
, visinfo
);
1049 /* unusable visual */
1055 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1056 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1057 if (!glxCtx
->xmesaContext
) {
1062 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1063 glxCtx
->currentDpy
= dpy
;
1064 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1070 /* XXX these may have to be removed due to thread-safety issues. */
1071 static GLXContext MakeCurrent_PrevContext
= 0;
1072 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1073 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1074 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1075 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1078 /* GLX 1.3 and later */
1080 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1081 GLXDrawable read
, GLXContext ctx
)
1083 GLXContext glxCtx
= ctx
;
1084 static boolean firsttime
= 1, no_rast
= 0;
1087 no_rast
= getenv("SP_NO_RAST") != NULL
;
1091 if (ctx
&& draw
&& read
) {
1092 XMesaBuffer drawBuffer
, readBuffer
;
1093 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1095 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1096 if (ctx
== MakeCurrent_PrevContext
1097 && draw
== MakeCurrent_PrevDrawable
) {
1098 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1101 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1104 /* drawable must be a new window! */
1105 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1107 /* Out of memory, or context/drawable depth mismatch */
1112 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1113 if (ctx
== MakeCurrent_PrevContext
1114 && read
== MakeCurrent_PrevReadable
) {
1115 readBuffer
= MakeCurrent_PrevReadBuffer
;
1118 readBuffer
= XMesaFindBuffer( dpy
, read
);
1121 /* drawable must be a new window! */
1122 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1124 /* Out of memory, or context/drawable depth mismatch */
1130 MakeCurrent_PrevContext
== ctx
&&
1131 MakeCurrent_PrevDrawable
== draw
&&
1132 MakeCurrent_PrevReadable
== read
&&
1133 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1134 MakeCurrent_PrevReadBuffer
== readBuffer
)
1137 MakeCurrent_PrevContext
= ctx
;
1138 MakeCurrent_PrevDrawable
= draw
;
1139 MakeCurrent_PrevReadable
= read
;
1140 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1141 MakeCurrent_PrevReadBuffer
= readBuffer
;
1143 /* Now make current! */
1144 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1145 ctx
->currentDpy
= dpy
;
1146 ctx
->currentDrawable
= draw
;
1147 ctx
->currentReadable
= read
;
1148 SetCurrentContext(ctx
);
1155 else if (!ctx
&& !draw
&& !read
) {
1156 /* release current context w/out assigning new one. */
1157 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1158 MakeCurrent_PrevContext
= 0;
1159 MakeCurrent_PrevDrawable
= 0;
1160 MakeCurrent_PrevReadable
= 0;
1161 MakeCurrent_PrevDrawBuffer
= 0;
1162 MakeCurrent_PrevReadBuffer
= 0;
1163 SetCurrentContext(NULL
);
1167 /* The args must either all be non-zero or all zero.
1176 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1178 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1183 glXGetCurrentContext(void)
1185 return GetCurrentContext();
1190 glXGetCurrentDisplay(void)
1192 GLXContext glxCtx
= glXGetCurrentContext();
1194 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1199 glXGetCurrentDisplayEXT(void)
1201 return glXGetCurrentDisplay();
1206 glXGetCurrentDrawable(void)
1208 GLXContext gc
= glXGetCurrentContext();
1209 return gc
? gc
->currentDrawable
: 0;
1214 glXGetCurrentReadDrawable(void)
1216 GLXContext gc
= glXGetCurrentContext();
1217 return gc
? gc
->currentReadable
: 0;
1222 glXGetCurrentReadDrawableSGI(void)
1224 return glXGetCurrentReadDrawable();
1229 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1234 v
= find_glx_visual( dpy
, visinfo
);
1236 v
= create_glx_visual( dpy
, visinfo
);
1238 /* unusable visual */
1243 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1251 /*** GLX_MESA_pixmap_colormap ***/
1254 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1255 Pixmap pixmap
, Colormap cmap
)
1260 v
= find_glx_visual( dpy
, visinfo
);
1262 v
= create_glx_visual( dpy
, visinfo
);
1264 /* unusable visual */
1269 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1278 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1280 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1282 XMesaDestroyBuffer(b
);
1284 else if (_mesa_getenv("MESA_DEBUG")) {
1285 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1291 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1292 unsigned long mask
)
1294 XMesaContext xm_src
= src
->xmesaContext
;
1295 XMesaContext xm_dst
= dst
->xmesaContext
;
1297 if (MakeCurrent_PrevContext
== src
) {
1300 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1305 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1308 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1309 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1315 return True
; /* we're faking GLX so always return success */
1320 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1322 GLXContext glxCtx
= ctx
;
1324 MakeCurrent_PrevContext
= 0;
1325 MakeCurrent_PrevDrawable
= 0;
1326 MakeCurrent_PrevReadable
= 0;
1327 MakeCurrent_PrevDrawBuffer
= 0;
1328 MakeCurrent_PrevReadBuffer
= 0;
1329 XMesaDestroyContext( glxCtx
->xmesaContext
);
1330 XMesaGarbageCollect();
1336 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1338 GLXContext glxCtx
= ctx
;
1340 return glxCtx
->isDirect
;
1346 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1348 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1349 static boolean firsttime
= 1, no_rast
= 0;
1352 no_rast
= getenv("SP_NO_RAST") != NULL
;
1360 XMesaSwapBuffers(buffer
);
1362 else if (_mesa_getenv("MESA_DEBUG")) {
1363 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1370 /*** GLX_MESA_copy_sub_buffer ***/
1373 glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1374 int x
, int y
, int width
, int height
)
1376 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1378 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1380 else if (_mesa_getenv("MESA_DEBUG")) {
1381 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1387 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1390 /* Return GLX version, not Mesa version */
1391 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1392 *maj
= CLIENT_MAJOR_VERSION
;
1393 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1399 * Query the GLX attributes of the given XVisualInfo.
1402 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1408 return GLX_BAD_ATTRIBUTE
;
1409 *value
= (int) True
;
1411 case GLX_BUFFER_SIZE
:
1412 *value
= xmvis
->visinfo
->depth
;
1415 *value
= xmvis
->mesa_visual
.level
;
1419 return GLX_BAD_ATTRIBUTE
;
1420 if (xmvis
->mesa_visual
.rgbMode
) {
1427 case GLX_DOUBLEBUFFER
:
1428 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1431 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1433 case GLX_AUX_BUFFERS
:
1434 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1437 *value
= xmvis
->mesa_visual
.redBits
;
1439 case GLX_GREEN_SIZE
:
1440 *value
= xmvis
->mesa_visual
.greenBits
;
1443 *value
= xmvis
->mesa_visual
.blueBits
;
1445 case GLX_ALPHA_SIZE
:
1446 *value
= xmvis
->mesa_visual
.alphaBits
;
1448 case GLX_DEPTH_SIZE
:
1449 *value
= xmvis
->mesa_visual
.depthBits
;
1451 case GLX_STENCIL_SIZE
:
1452 *value
= xmvis
->mesa_visual
.stencilBits
;
1454 case GLX_ACCUM_RED_SIZE
:
1455 *value
= xmvis
->mesa_visual
.accumRedBits
;
1457 case GLX_ACCUM_GREEN_SIZE
:
1458 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1460 case GLX_ACCUM_BLUE_SIZE
:
1461 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1463 case GLX_ACCUM_ALPHA_SIZE
:
1464 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1468 * GLX_EXT_visual_info extension
1470 case GLX_X_VISUAL_TYPE_EXT
:
1471 switch (xmvis
->visinfo
->CLASS
) {
1472 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1473 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1474 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1475 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1476 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1477 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1480 case GLX_TRANSPARENT_TYPE_EXT
:
1482 *value
= GLX_NONE_EXT
;
1484 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1487 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1490 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1493 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1496 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1501 * GLX_EXT_visual_info extension
1503 case GLX_VISUAL_CAVEAT_EXT
:
1504 /* test for zero, just in case */
1505 if (xmvis
->mesa_visual
.visualRating
> 0)
1506 *value
= xmvis
->mesa_visual
.visualRating
;
1508 *value
= GLX_NONE_EXT
;
1512 * GLX_ARB_multisample
1514 case GLX_SAMPLE_BUFFERS_ARB
:
1517 case GLX_SAMPLES_ARB
:
1524 case GLX_SCREEN_EXT
:
1526 return GLX_BAD_ATTRIBUTE
;
1527 *value
= xmvis
->visinfo
->screen
;
1529 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1531 return GLX_BAD_ATTRIBUTE
;
1532 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1534 case GLX_RENDER_TYPE_SGIX
:
1536 return GLX_BAD_ATTRIBUTE
;
1537 if (xmvis
->mesa_visual
.rgbMode
)
1538 *value
= GLX_RGBA_BIT
;
1540 *value
= GLX_COLOR_INDEX_BIT
;
1542 case GLX_X_RENDERABLE_SGIX
:
1544 return GLX_BAD_ATTRIBUTE
;
1545 *value
= True
; /* XXX really? */
1547 case GLX_FBCONFIG_ID_SGIX
:
1549 return GLX_BAD_ATTRIBUTE
;
1550 *value
= xmvis
->visinfo
->visualid
;
1552 case GLX_MAX_PBUFFER_WIDTH
:
1554 return GLX_BAD_ATTRIBUTE
;
1555 /* XXX or MAX_WIDTH? */
1556 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1558 case GLX_MAX_PBUFFER_HEIGHT
:
1560 return GLX_BAD_ATTRIBUTE
;
1561 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1563 case GLX_MAX_PBUFFER_PIXELS
:
1565 return GLX_BAD_ATTRIBUTE
;
1566 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1567 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1571 return GLX_BAD_ATTRIBUTE
;
1572 *value
= xmvis
->visinfo
->visualid
;
1575 #ifdef GLX_EXT_texture_from_pixmap
1576 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1577 *value
= True
; /*XXX*/
1579 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1581 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1583 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1584 *value
= True
; /*XXX*/
1586 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1587 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1588 GLX_TEXTURE_2D_BIT_EXT
|
1589 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1591 case GLX_Y_INVERTED_EXT
:
1592 *value
= True
; /*XXX*/
1597 return GLX_BAD_ATTRIBUTE
;
1604 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1605 int attrib
, int *value
)
1609 if (!dpy
|| !visinfo
)
1610 return GLX_BAD_ATTRIBUTE
;
1612 xmvis
= find_glx_visual( dpy
, visinfo
);
1614 /* this visual wasn't obtained with glXChooseVisual */
1615 xmvis
= create_glx_visual( dpy
, visinfo
);
1617 /* this visual can't be used for GL rendering */
1618 if (attrib
==GLX_USE_GL
) {
1619 *value
= (int) False
;
1623 return GLX_BAD_VISUAL
;
1628 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1636 XMesaContext xmesa
= XMesaGetCurrentContext();
1637 XMesaFlush( xmesa
);
1645 XMesaContext xmesa
= XMesaGetCurrentContext();
1646 XMesaFlush( xmesa
);
1651 get_extensions( void )
1658 /* GLX 1.1 and later */
1660 glXQueryExtensionsString( Display
*dpy
, int screen
)
1664 return get_extensions();
1669 /* GLX 1.1 and later */
1671 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1673 static char version
[1000];
1674 sprintf(version
, "%d.%d %s",
1675 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1681 case GLX_EXTENSIONS
:
1682 return get_extensions();
1694 /* GLX 1.1 and later */
1696 glXGetClientString( Display
*dpy
, int name
)
1698 static char version
[1000];
1699 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1700 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1705 case GLX_EXTENSIONS
:
1706 return get_extensions();
1724 glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1725 int attribute
, int *value
)
1727 XMesaVisual v
= (XMesaVisual
) config
;
1731 if (!dpy
|| !config
|| !value
)
1734 return get_config(v
, attribute
, value
, GL_TRUE
);
1738 PUBLIC GLXFBConfig
*
1739 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1741 XVisualInfo
*visuals
, visTemplate
;
1742 const long visMask
= VisualScreenMask
;
1745 /* Get list of all X visuals */
1746 visTemplate
.screen
= screen
;
1747 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1748 if (*nelements
> 0) {
1749 XMesaVisual
*results
;
1750 results
= (XMesaVisual
*) malloc(*nelements
* sizeof(XMesaVisual
));
1755 for (i
= 0; i
< *nelements
; i
++) {
1756 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1762 return (GLXFBConfig
*) results
;
1768 PUBLIC GLXFBConfig
*
1769 glXChooseFBConfig( Display
*dpy
, int screen
,
1770 const int *attribList
, int *nitems
)
1774 if (!attribList
|| !attribList
[0]) {
1775 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1776 return glXGetFBConfigs(dpy
, screen
, nitems
);
1779 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1781 GLXFBConfig
*config
= (GLXFBConfig
*) malloc(sizeof(XMesaVisual
));
1787 config
[0] = (GLXFBConfig
) xmvis
;
1788 return (GLXFBConfig
*) config
;
1797 PUBLIC XVisualInfo
*
1798 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1800 if (dpy
&& config
) {
1801 XMesaVisual xmvis
= (XMesaVisual
) config
;
1803 return xmvis
->vishandle
;
1805 /* create a new vishandle - the cached one may be stale */
1806 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1807 if (xmvis
->vishandle
) {
1808 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1810 return xmvis
->vishandle
;
1820 glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1821 const int *attribList
)
1823 XMesaVisual xmvis
= (XMesaVisual
) config
;
1828 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1833 (void) attribList
; /* Ignored in GLX 1.3 */
1835 return win
; /* A hack for now */
1840 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1842 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1844 XMesaDestroyBuffer(b
);
1845 /* don't destroy X window */
1851 glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1852 const int *attribList
)
1854 XMesaVisual v
= (XMesaVisual
) config
;
1857 int target
= 0, format
= 0, mipmap
= 0;
1860 if (!dpy
|| !config
|| !pixmap
)
1863 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1865 case GLX_TEXTURE_FORMAT_EXT
:
1868 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1869 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1870 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1878 case GLX_TEXTURE_TARGET_EXT
:
1881 case GLX_TEXTURE_1D_EXT
:
1882 case GLX_TEXTURE_2D_EXT
:
1883 case GLX_TEXTURE_RECTANGLE_EXT
:
1891 case GLX_MIPMAP_TEXTURE_EXT
:
1902 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1903 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1904 &value
, GL_TRUE
) != Success
1906 return 0; /* error! */
1909 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1910 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1911 &value
, GL_TRUE
) != Success
1913 return 0; /* error! */
1917 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1918 &value
, GL_TRUE
) != Success
1920 return 0; /* error! */
1923 if (target
== GLX_TEXTURE_1D_EXT
) {
1924 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1925 &value
, GL_TRUE
) != Success
1926 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1927 return 0; /* error! */
1930 else if (target
== GLX_TEXTURE_2D_EXT
) {
1931 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1932 &value
, GL_TRUE
) != Success
1933 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1934 return 0; /* error! */
1937 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1938 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1939 &value
, GL_TRUE
) != Success
1940 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1941 return 0; /* error! */
1945 if (format
|| target
|| mipmap
) {
1946 /* texture from pixmap */
1947 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1950 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1961 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1963 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
1965 XMesaDestroyBuffer(b
);
1966 /* don't destroy X pixmap */
1971 glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
1972 const int *attribList
)
1974 XMesaVisual xmvis
= (XMesaVisual
) config
;
1977 int width
= 0, height
= 0;
1978 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
1982 for (attrib
= attribList
; *attrib
; attrib
++) {
1984 case GLX_PBUFFER_WIDTH
:
1988 case GLX_PBUFFER_HEIGHT
:
1992 case GLX_PRESERVED_CONTENTS
:
1994 preserveContents
= *attrib
;
1996 case GLX_LARGEST_PBUFFER
:
1998 useLargest
= *attrib
;
2005 if (width
== 0 || height
== 0)
2008 if (width
> MAX_WIDTH
|| height
> MAX_HEIGHT
) {
2009 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2010 * allocate the largest possible buffer.
2014 height
= MAX_HEIGHT
;
2018 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2019 /* A GLXPbuffer handle must be an X Drawable because that's what
2020 * glXMakeCurrent takes.
2023 xmbuf
->largestPbuffer
= useLargest
;
2024 xmbuf
->preservedContents
= preserveContents
;
2025 return (GLXPbuffer
) xmbuf
->drawable
;
2034 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2036 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2038 XMesaDestroyBuffer(b
);
2044 glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2045 unsigned int *value
)
2047 GLuint width
, height
;
2048 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2052 /* make sure buffer's dimensions are up to date */
2053 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2055 switch (attribute
) {
2062 case GLX_PRESERVED_CONTENTS
:
2063 *value
= xmbuf
->preservedContents
;
2065 case GLX_LARGEST_PBUFFER
:
2066 *value
= xmbuf
->largestPbuffer
;
2068 case GLX_FBCONFIG_ID
:
2069 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2071 #ifdef GLX_EXT_texture_from_pixmap
2072 case GLX_TEXTURE_FORMAT_EXT
:
2073 *value
= xmbuf
->TextureFormat
;
2075 case GLX_TEXTURE_TARGET_EXT
:
2076 *value
= xmbuf
->TextureTarget
;
2078 case GLX_MIPMAP_TEXTURE_EXT
:
2079 *value
= xmbuf
->TextureMipmap
;
2084 return; /* raise BadValue error */
2090 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2091 int renderType
, GLXContext shareList
, Bool direct
)
2094 GLXContext shareCtx
= shareList
;
2095 XMesaVisual xmvis
= (XMesaVisual
) config
;
2097 if (!dpy
|| !config
||
2098 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2101 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
2105 /* deallocate unused windows/buffers */
2106 XMesaGarbageCollect();
2108 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2109 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2110 if (!glxCtx
->xmesaContext
) {
2115 glxCtx
->isDirect
= DEFAULT_DIRECT
;
2116 glxCtx
->currentDpy
= dpy
;
2117 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
2124 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2126 GLXContext glxCtx
= ctx
;
2127 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2132 switch (attribute
) {
2133 case GLX_FBCONFIG_ID
:
2134 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2136 case GLX_RENDER_TYPE
:
2137 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2138 *value
= GLX_RGBA_TYPE
;
2140 *value
= GLX_COLOR_INDEX_TYPE
;
2146 return GLX_BAD_ATTRIBUTE
;
2153 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2155 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2157 xmbuf
->selectedEvents
= mask
;
2162 glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2163 unsigned long *mask
)
2165 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2167 *mask
= xmbuf
->selectedEvents
;
2174 /*** GLX_SGI_swap_control ***/
2177 glXSwapIntervalSGI(int interval
)
2185 /*** GLX_SGI_video_sync ***/
2187 static unsigned int FrameCounter
= 0;
2190 glXGetVideoSyncSGI(unsigned int *count
)
2192 /* this is a bogus implementation */
2193 *count
= FrameCounter
++;
2198 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2200 if (divisor
<= 0 || remainder
< 0)
2201 return GLX_BAD_VALUE
;
2202 /* this is a bogus implementation */
2204 while (FrameCounter
% divisor
!= remainder
)
2206 *count
= FrameCounter
;
2212 /*** GLX_SGI_make_current_read ***/
2215 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2217 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2222 glXGetCurrentReadDrawableSGI(void)
2229 /*** GLX_SGIX_video_source ***/
2232 PUBLIC GLXVideoSourceSGIX
2233 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, 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
, int *value
)
2290 /*** GLX_SGIX_fbconfig ***/
2293 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2295 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2298 PUBLIC GLXFBConfigSGIX
*
2299 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2301 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2306 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2308 XMesaVisual xmvis
= (XMesaVisual
) config
;
2309 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2310 return xmbuf
->drawable
; /* need to return an X ID */
2315 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2317 XMesaVisual xmvis
= (XMesaVisual
) config
;
2319 GLXContext shareCtx
= share_list
;
2321 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
2325 /* deallocate unused windows/buffers */
2326 XMesaGarbageCollect();
2328 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2329 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2330 if (!glxCtx
->xmesaContext
) {
2335 glxCtx
->isDirect
= DEFAULT_DIRECT
;
2336 glxCtx
->currentDpy
= dpy
;
2337 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
2343 PUBLIC XVisualInfo
*
2344 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2346 return glXGetVisualFromFBConfig(dpy
, config
);
2350 PUBLIC GLXFBConfigSGIX
2351 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2353 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2355 /* This visual wasn't found with glXChooseVisual() */
2356 xmvis
= create_glx_visual(dpy
, vis
);
2359 return (GLXFBConfigSGIX
) xmvis
;
2364 /*** GLX_SGIX_pbuffer ***/
2366 PUBLIC GLXPbufferSGIX
2367 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2368 unsigned int width
, unsigned int height
,
2371 XMesaVisual xmvis
= (XMesaVisual
) config
;
2374 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2378 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2380 case GLX_PRESERVED_CONTENTS_SGIX
:
2382 preserveContents
= *attrib
; /* ignored */
2384 case GLX_LARGEST_PBUFFER_SGIX
:
2386 useLargest
= *attrib
; /* ignored */
2393 /* not used at this time */
2395 (void) preserveContents
;
2397 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2398 /* A GLXPbuffer handle must be an X Drawable because that's what
2399 * glXMakeCurrent takes.
2401 return (GLXPbuffer
) xmbuf
->drawable
;
2406 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2408 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2410 XMesaDestroyBuffer(xmbuf
);
2416 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2418 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2421 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2425 switch (attribute
) {
2426 case GLX_PRESERVED_CONTENTS_SGIX
:
2429 case GLX_LARGEST_PBUFFER_SGIX
:
2430 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2432 case GLX_WIDTH_SGIX
:
2433 *value
= xmesa_buffer_width(xmbuf
);
2435 case GLX_HEIGHT_SGIX
:
2436 *value
= xmesa_buffer_height(xmbuf
);
2438 case GLX_EVENT_MASK_SGIX
:
2439 *value
= 0; /* XXX might be wrong */
2449 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2451 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2453 /* Note: we'll never generate clobber events */
2454 xmbuf
->selectedEvents
= mask
;
2460 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2462 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2464 *mask
= xmbuf
->selectedEvents
;
2473 /*** GLX_SGI_cushion ***/
2476 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2485 /*** GLX_SGIX_video_resize ***/
2488 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2498 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2511 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2524 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, 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
, DMparams
*params
, DMbuffer dmbuffer
)
2563 /*** GLX_SGIX_swap_group ***/
2566 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2575 /*** GLX_SGIX_swap_barrier ***/
2578 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2586 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2596 /*** GLX_SUN_get_transparent_index ***/
2599 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2604 (void) pTransparent
;
2610 /*** GLX_MESA_release_buffers ***/
2613 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2614 * (a window or pixmap) prior to destroying the GLXDrawable.
2617 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2619 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2621 XMesaDestroyBuffer(b
);
2627 /*** GLX_EXT_texture_from_pixmap ***/
2630 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2631 const int *attrib_list
)
2633 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2635 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2639 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2641 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2643 XMesaReleaseTexImage(dpy
, b
, buffer
);