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
37 #include "main/context.h"
38 #include "main/macros.h"
39 #include "main/imports.h"
40 #include "main/version.h"
43 /* This indicates the client-side GLX API and GLX encoder version. */
44 #define CLIENT_MAJOR_VERSION 1
45 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
47 /* This indicates the server-side GLX decoder version.
48 * GLX 1.4 indicates OpenGL 1.3 support
50 #define SERVER_MAJOR_VERSION 1
51 #define SERVER_MINOR_VERSION 4
53 /* This is appended onto the glXGetClient/ServerString version strings. */
54 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
56 /* Who implemented this GLX? */
57 #define VENDOR "Brian Paul"
60 "GLX_MESA_copy_sub_buffer " \
61 "GLX_MESA_pixmap_colormap " \
62 "GLX_MESA_release_buffers " \
63 "GLX_ARB_get_proc_address " \
64 "GLX_EXT_texture_from_pixmap " \
65 "GLX_EXT_visual_info " \
66 "GLX_EXT_visual_rating " \
67 /*"GLX_SGI_video_sync "*/ \
68 "GLX_SGIX_fbconfig " \
71 #define DEFAULT_DIRECT GL_TRUE
76 * The GLXContext typedef is defined as a pointer to this structure.
78 struct __GLXcontextRec
82 GLXDrawable currentDrawable
;
83 GLXDrawable currentReadable
;
86 XMesaContext xmesaContext
;
91 static pipe_tsd ContextTSD
;
93 /** Set current context for calling thread */
95 SetCurrentContext(GLXContext c
)
97 pipe_tsd_set(&ContextTSD
, c
);
100 /** Get current context for calling thread */
102 GetCurrentContext(void)
104 return pipe_tsd_get(&ContextTSD
);
109 /**********************************************************************/
110 /*** GLX Visual Code ***/
111 /**********************************************************************/
116 static XMesaVisual
*VisualTable
= NULL
;
117 static int NumVisuals
= 0;
121 /* Macro to handle c_class vs class field name in XVisualInfo struct */
122 #if defined(__cplusplus) || defined(c_plusplus)
123 #define CLASS c_class
131 * Test if the given XVisualInfo is usable for Mesa rendering.
134 is_usable_visual( XVisualInfo
*vinfo
)
136 switch (vinfo
->CLASS
) {
139 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
143 /* Any StaticColor/PseudoColor visual of at least 4 bits */
144 if (vinfo
->depth
>=4) {
152 /* Any depth of TrueColor or DirectColor works in RGB mode */
155 /* This should never happen */
162 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
163 * configuration in our list of GLX visuals.
166 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
167 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
168 GLboolean stereoFlag
,
169 GLint depth_size
, GLint stencil_size
,
170 GLint accumRedSize
, GLint accumGreenSize
,
171 GLint accumBlueSize
, GLint accumAlphaSize
,
172 GLint level
, GLint numAuxBuffers
)
174 GLboolean ximageFlag
= GL_TRUE
;
177 GLboolean comparePointers
;
180 /* Check if the MESA_BACK_BUFFER env var is set */
181 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
183 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
184 ximageFlag
= GL_FALSE
;
186 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
187 ximageFlag
= GL_TRUE
;
190 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
196 /* stereo not supported */
200 if (stencil_size
> 0 && depth_size
> 0)
203 /* Comparing IDs uses less memory but sometimes fails. */
204 /* XXX revisit this after 3.0 is finished. */
205 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
206 comparePointers
= GL_TRUE
;
208 comparePointers
= GL_FALSE
;
210 /* Force the visual to have an alpha channel */
211 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
214 /* First check if a matching visual is already in the list */
215 for (i
=0; i
<NumVisuals
; i
++) {
216 XMesaVisual v
= VisualTable
[i
];
217 if (v
->display
== dpy
218 && v
->mesa_visual
.level
== level
219 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
220 && v
->ximage_flag
== ximageFlag
221 && v
->mesa_visual
.rgbMode
== rgbFlag
222 && v
->mesa_visual
.doubleBufferMode
== dbFlag
223 && v
->mesa_visual
.stereoMode
== stereoFlag
224 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
225 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
226 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
227 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
228 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
229 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
230 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
231 /* now either compare XVisualInfo pointers or visual IDs */
232 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
233 || (comparePointers
&& v
->vishandle
== vinfo
)) {
239 /* Create a new visual and add it to the list. */
241 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
242 stereoFlag
, ximageFlag
,
243 depth_size
, stencil_size
,
244 accumRedSize
, accumBlueSize
,
245 accumBlueSize
, accumAlphaSize
, 0, level
,
248 /* Save a copy of the pointer now so we can find this visual again
249 * if we need to search for it in find_glx_visual().
251 xmvis
->vishandle
= vinfo
;
252 /* Allocate more space for additional visual */
253 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
254 sizeof(XMesaVisual
) * NumVisuals
,
255 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
256 /* add xmvis to the list */
257 VisualTable
[NumVisuals
] = xmvis
;
259 /* XXX minor hack, because XMesaCreateVisual doesn't support an
260 * aux buffers parameter.
262 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
269 * Return the default number of bits for the Z buffer.
270 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
271 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
272 * XXX probably do the same thing for stencil, accum, etc.
275 default_depth_bits(void)
278 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
282 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
287 default_alpha_bits(void)
290 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
299 default_accum_bits(void)
307 * Create a GLX visual from a regular XVisualInfo.
308 * This is called when Fake GLX is given an XVisualInfo which wasn't
309 * returned by glXChooseVisual. Since this is the first time we're
310 * considering this visual we'll take a guess at reasonable values
311 * for depth buffer size, stencil size, accum size, etc.
312 * This is the best we can do with a client-side emulation of GLX.
315 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
317 GLint zBits
= default_depth_bits();
318 GLint accBits
= default_accum_bits();
319 GLboolean alphaFlag
= default_alpha_bits() > 0;
321 if (is_usable_visual( visinfo
)) {
322 /* Configure this visual as RGB, double-buffered, depth-buffered. */
323 /* This is surely wrong for some people's needs but what else */
324 /* can be done? They should use glXChooseVisual(). */
325 return save_glx_visual( dpy
, visinfo
,
327 alphaFlag
, /* alpha */
328 GL_TRUE
, /* double */
329 GL_FALSE
, /* stereo */
341 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
349 * Find the GLX visual associated with an XVisualInfo.
352 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
356 /* try to match visual id */
357 for (i
=0;i
<NumVisuals
;i
++) {
358 if (VisualTable
[i
]->display
==dpy
359 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
360 return VisualTable
[i
];
364 /* if that fails, try to match pointers */
365 for (i
=0;i
<NumVisuals
;i
++) {
366 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
367 return VisualTable
[i
];
376 * Try to get an X visual which matches the given arguments.
379 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
381 XVisualInfo temp
, *vis
;
384 unsigned int default_depth
;
387 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
392 default_depth
= DefaultDepth(dpy
,scr
);
393 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
395 if (depth
==default_depth
&& xclass
==default_class
) {
396 /* try to get root window's visual */
397 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
398 mask
|= VisualIDMask
;
401 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
403 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
404 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
405 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
407 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
408 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
409 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
410 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
424 * Retrieve the value of the given environment variable and find
425 * the X visual which matches it.
426 * Input: dpy - the display
427 * screen - the screen number
428 * varname - the name of the environment variable
429 * Return: an XVisualInfo pointer to NULL if error.
432 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
434 char value
[100], type
[100];
435 int depth
, xclass
= -1;
438 if (!_mesa_getenv( varname
)) {
442 strncpy( value
, _mesa_getenv(varname
), 100 );
445 sscanf( value
, "%s %d", type
, &depth
);
447 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
448 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
449 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
450 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
451 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
452 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
454 if (xclass
>-1 && depth
>0) {
455 vis
= get_visual( dpy
, scr
, depth
, xclass
);
461 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
470 * Select an X visual which satisfies the RGBA flag and minimum depth.
472 * screen - X display and screen number
473 * min_depth - minimum visual depth
474 * preferred_class - preferred GLX visual class or DONT_CARE
475 * Return: pointer to an XVisualInfo or NULL.
478 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
479 int preferred_class
)
482 int xclass
, visclass
= 0;
485 /* First see if the MESA_RGB_VISUAL env var is defined */
486 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
490 /* Otherwise, search for a suitable visual */
491 if (preferred_class
==DONT_CARE
) {
492 for (xclass
=0;xclass
<6;xclass
++) {
494 case 0: visclass
= TrueColor
; break;
495 case 1: visclass
= DirectColor
; break;
496 case 2: visclass
= PseudoColor
; break;
497 case 3: visclass
= StaticColor
; break;
498 case 4: visclass
= GrayScale
; break;
499 case 5: visclass
= StaticGray
; break;
502 /* start with shallowest */
503 for (depth
=0;depth
<=32;depth
++) {
504 if (visclass
==TrueColor
&& depth
==8) {
505 /* Special case: try to get 8-bit PseudoColor before */
506 /* 8-bit TrueColor */
507 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
512 vis
= get_visual( dpy
, screen
, depth
, visclass
);
519 /* start with deepest */
520 for (depth
=32;depth
>=min_depth
;depth
--) {
521 if (visclass
==TrueColor
&& depth
==8) {
522 /* Special case: try to get 8-bit PseudoColor before */
523 /* 8-bit TrueColor */
524 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
529 vis
= get_visual( dpy
, screen
, depth
, visclass
);
538 /* search for a specific visual class */
539 switch (preferred_class
) {
540 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
541 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
542 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
543 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
544 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
545 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
546 default: return NULL
;
549 /* start with shallowest */
550 for (depth
=0;depth
<=32;depth
++) {
551 vis
= get_visual( dpy
, screen
, depth
, visclass
);
558 /* start with deepest */
559 for (depth
=32;depth
>=min_depth
;depth
--) {
560 vis
= get_visual( dpy
, screen
, depth
, visclass
);
568 /* didn't find a visual */
575 /**********************************************************************/
576 /*** Display-related functions ***/
577 /**********************************************************************/
581 * Free all XMesaVisuals which are associated with the given display.
584 destroy_visuals_on_display(Display
*dpy
)
587 for (i
= 0; i
< NumVisuals
; i
++) {
588 if (VisualTable
[i
]->display
== dpy
) {
589 /* remove this visual */
591 free(VisualTable
[i
]);
592 for (j
= i
; j
< NumVisuals
- 1; j
++)
593 VisualTable
[j
] = VisualTable
[j
+ 1];
601 * Called from XCloseDisplay() to let us free our display-related data.
604 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
606 destroy_visuals_on_display(dpy
);
607 xmesa_destroy_buffers_on_display(dpy
);
613 * Look for the named extension on given display and return a pointer
614 * to the _XExtension data, or NULL if extension not found.
617 lookup_extension(Display
*dpy
, const char *extName
)
620 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
621 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
630 * Whenever we're given a new Display pointer, call this function to
631 * register our close_display_callback function.
634 register_with_display(Display
*dpy
)
636 const char *extName
= "MesaGLX";
639 ext
= lookup_extension(dpy
, extName
);
641 XExtCodes
*c
= XAddExtension(dpy
);
642 ext
= dpy
->ext_procs
; /* new extension is at head of list */
643 assert(c
->extension
== ext
->codes
.extension
);
645 ext
->name
= _mesa_strdup(extName
);
646 ext
->close_display
= close_display_callback
;
651 /**********************************************************************/
652 /*** Begin Fake GLX API Functions ***/
653 /**********************************************************************/
657 * Helper used by glXChooseVisual and glXChooseFBConfig.
658 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
660 * In either case, the attribute list is terminated with the value 'None'.
663 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
665 const GLboolean rgbModeDefault
= fbConfig
;
666 const int *parselist
;
669 int min_red
=0, min_green
=0, min_blue
=0;
670 GLboolean rgb_flag
= rgbModeDefault
;
671 GLboolean alpha_flag
= GL_FALSE
;
672 GLboolean double_flag
= GL_FALSE
;
673 GLboolean stereo_flag
= GL_FALSE
;
674 GLint depth_size
= 0;
675 GLint stencil_size
= 0;
676 GLint accumRedSize
= 0;
677 GLint accumGreenSize
= 0;
678 GLint accumBlueSize
= 0;
679 GLint accumAlphaSize
= 0;
681 int visual_type
= DONT_CARE
;
682 int trans_type
= DONT_CARE
;
683 int trans_value
= DONT_CARE
;
684 GLint caveat
= DONT_CARE
;
685 XMesaVisual xmvis
= NULL
;
686 int desiredVisualID
= -1;
695 switch (*parselist
) {
706 case GLX_BUFFER_SIZE
:
708 min_ci
= *parselist
++;
712 level
= *parselist
++;
724 case GLX_DOUBLEBUFFER
:
727 double_flag
= *parselist
++;
730 double_flag
= GL_TRUE
;
736 stereo_flag
= *parselist
++;
739 stereo_flag
= GL_TRUE
;
742 case GLX_AUX_BUFFERS
:
744 numAux
= *parselist
++;
745 if (numAux
> MAX_AUX_BUFFERS
)
750 min_red
= *parselist
++;
754 min_green
= *parselist
++;
758 min_blue
= *parselist
++;
763 GLint size
= *parselist
++;
764 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
769 depth_size
= *parselist
++;
771 case GLX_STENCIL_SIZE
:
773 stencil_size
= *parselist
++;
775 case GLX_ACCUM_RED_SIZE
:
778 GLint size
= *parselist
++;
779 accumRedSize
= MAX2( accumRedSize
, size
);
782 case GLX_ACCUM_GREEN_SIZE
:
785 GLint size
= *parselist
++;
786 accumGreenSize
= MAX2( accumGreenSize
, size
);
789 case GLX_ACCUM_BLUE_SIZE
:
792 GLint size
= *parselist
++;
793 accumBlueSize
= MAX2( accumBlueSize
, size
);
796 case GLX_ACCUM_ALPHA_SIZE
:
799 GLint size
= *parselist
++;
800 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
805 * GLX_EXT_visual_info extension
807 case GLX_X_VISUAL_TYPE_EXT
:
809 visual_type
= *parselist
++;
811 case GLX_TRANSPARENT_TYPE_EXT
:
813 trans_type
= *parselist
++;
815 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
817 trans_value
= *parselist
++;
819 case GLX_TRANSPARENT_RED_VALUE_EXT
:
820 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
821 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
822 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
829 * GLX_EXT_visual_info extension
831 case GLX_VISUAL_CAVEAT_EXT
:
833 caveat
= *parselist
++; /* ignored for now */
837 * GLX_ARB_multisample
839 case GLX_SAMPLE_BUFFERS_ARB
:
840 /* ms not supported */
842 case GLX_SAMPLES_ARB
:
843 /* ms not supported */
849 case GLX_RENDER_TYPE
:
853 if (*parselist
& GLX_RGBA_BIT
) {
856 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
859 else if (*parselist
== 0) {
864 case GLX_DRAWABLE_TYPE
:
868 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
869 return NULL
; /* bad bit */
873 case GLX_FBCONFIG_ID
:
877 desiredVisualID
= *parselist
++;
879 case GLX_X_RENDERABLE
:
886 #ifdef GLX_EXT_texture_from_pixmap
887 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
888 parselist
++; /*skip*/
890 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
891 parselist
++; /*skip*/
893 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
894 parselist
++; /*skip*/
896 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
898 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
899 GLX_TEXTURE_2D_BIT_EXT
|
900 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
905 case GLX_Y_INVERTED_EXT
:
906 parselist
++; /*skip*/
915 /* undefined attribute */
916 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
926 * Since we're only simulating the GLX extension this function will never
927 * find any real GL visuals. Instead, all we can do is try to find an RGB
928 * or CI visual of appropriate depth. Other requested attributes such as
929 * double buffering, depth buffer, etc. will be associated with the X
930 * visual and stored in the VisualTable[].
932 if (desiredVisualID
!= -1) {
933 /* try to get a specific visual, by visualID */
936 temp
.visualid
= desiredVisualID
;
937 temp
.screen
= screen
;
938 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
940 /* give the visual some useful GLX attributes */
941 double_flag
= GL_TRUE
;
946 /* normal color planes */
947 /* Get an RGB visual */
948 int min_rgb
= min_red
+ min_green
+ min_blue
;
949 if (min_rgb
>1 && min_rgb
<8) {
950 /* a special case to be sure we can get a monochrome visual */
953 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
956 _mesa_warning(NULL
, "overlay not supported");
961 /* Note: we're not exactly obeying the glXChooseVisual rules here.
962 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
963 * largest depth buffer size, which is 32bits/value. Instead, we
964 * return 16 to maintain performance with earlier versions of Mesa.
966 if (stencil_size
> 0)
967 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
968 else if (depth_size
> 24)
970 else if (depth_size
> 16)
972 else if (depth_size
> 0) {
973 depth_size
= default_depth_bits();
977 alpha_flag
= default_alpha_bits() > 0;
980 /* we only support one size of stencil and accum buffers. */
981 if (stencil_size
> 0)
982 stencil_size
= STENCIL_BITS
;
984 if (accumRedSize
> 0 ||
985 accumGreenSize
> 0 ||
987 accumAlphaSize
> 0) {
991 accumBlueSize
= default_accum_bits();
993 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
996 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
997 stereo_flag
, depth_size
, stencil_size
,
998 accumRedSize
, accumGreenSize
,
999 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1006 PUBLIC XVisualInfo
*
1007 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1011 /* register ourselves as an extension on this display */
1012 register_with_display(dpy
);
1014 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1016 /* create a new vishandle - the cached one may be stale */
1017 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1018 if (xmvis
->vishandle
) {
1019 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1021 return xmvis
->vishandle
;
1029 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1030 GLXContext share_list
, Bool direct
)
1034 GLXContext shareCtx
= share_list
;
1036 if (!dpy
|| !visinfo
)
1039 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1043 /* deallocate unused windows/buffers */
1045 XMesaGarbageCollect();
1048 xmvis
= find_glx_visual( dpy
, visinfo
);
1050 /* This visual wasn't found with glXChooseVisual() */
1051 xmvis
= create_glx_visual( dpy
, visinfo
);
1053 /* unusable visual */
1059 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1060 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1061 if (!glxCtx
->xmesaContext
) {
1066 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1067 glxCtx
->currentDpy
= dpy
;
1068 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1074 /* XXX these may have to be removed due to thread-safety issues. */
1075 static GLXContext MakeCurrent_PrevContext
= 0;
1076 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1077 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1078 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1079 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1082 /* GLX 1.3 and later */
1084 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1085 GLXDrawable read
, GLXContext ctx
)
1087 GLXContext glxCtx
= ctx
;
1088 static boolean firsttime
= 1, no_rast
= 0;
1091 no_rast
= getenv("SP_NO_RAST") != NULL
;
1095 if (ctx
&& draw
&& read
) {
1096 XMesaBuffer drawBuffer
, readBuffer
;
1097 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1099 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1100 if (ctx
== MakeCurrent_PrevContext
1101 && draw
== MakeCurrent_PrevDrawable
) {
1102 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1105 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1108 /* drawable must be a new window! */
1109 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1111 /* Out of memory, or context/drawable depth mismatch */
1116 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1117 if (ctx
== MakeCurrent_PrevContext
1118 && read
== MakeCurrent_PrevReadable
) {
1119 readBuffer
= MakeCurrent_PrevReadBuffer
;
1122 readBuffer
= XMesaFindBuffer( dpy
, read
);
1125 /* drawable must be a new window! */
1126 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1128 /* Out of memory, or context/drawable depth mismatch */
1134 MakeCurrent_PrevContext
== ctx
&&
1135 MakeCurrent_PrevDrawable
== draw
&&
1136 MakeCurrent_PrevReadable
== read
&&
1137 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1138 MakeCurrent_PrevReadBuffer
== readBuffer
)
1141 MakeCurrent_PrevContext
= ctx
;
1142 MakeCurrent_PrevDrawable
= draw
;
1143 MakeCurrent_PrevReadable
= read
;
1144 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1145 MakeCurrent_PrevReadBuffer
= readBuffer
;
1147 /* Now make current! */
1148 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1149 ctx
->currentDpy
= dpy
;
1150 ctx
->currentDrawable
= draw
;
1151 ctx
->currentReadable
= read
;
1152 SetCurrentContext(ctx
);
1159 else if (!ctx
&& !draw
&& !read
) {
1160 /* release current context w/out assigning new one. */
1161 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1162 MakeCurrent_PrevContext
= 0;
1163 MakeCurrent_PrevDrawable
= 0;
1164 MakeCurrent_PrevReadable
= 0;
1165 MakeCurrent_PrevDrawBuffer
= 0;
1166 MakeCurrent_PrevReadBuffer
= 0;
1167 SetCurrentContext(NULL
);
1171 /* The args must either all be non-zero or all zero.
1180 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1182 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1187 glXGetCurrentContext(void)
1189 return GetCurrentContext();
1194 glXGetCurrentDisplay(void)
1196 GLXContext glxCtx
= glXGetCurrentContext();
1198 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1203 glXGetCurrentDisplayEXT(void)
1205 return glXGetCurrentDisplay();
1210 glXGetCurrentDrawable(void)
1212 GLXContext gc
= glXGetCurrentContext();
1213 return gc
? gc
->currentDrawable
: 0;
1218 glXGetCurrentReadDrawable(void)
1220 GLXContext gc
= glXGetCurrentContext();
1221 return gc
? gc
->currentReadable
: 0;
1226 glXGetCurrentReadDrawableSGI(void)
1228 return glXGetCurrentReadDrawable();
1233 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1238 v
= find_glx_visual( dpy
, visinfo
);
1240 v
= create_glx_visual( dpy
, visinfo
);
1242 /* unusable visual */
1247 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1255 /*** GLX_MESA_pixmap_colormap ***/
1258 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1259 Pixmap pixmap
, Colormap cmap
)
1264 v
= find_glx_visual( dpy
, visinfo
);
1266 v
= create_glx_visual( dpy
, visinfo
);
1268 /* unusable visual */
1273 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1282 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1284 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1286 XMesaDestroyBuffer(b
);
1288 else if (_mesa_getenv("MESA_DEBUG")) {
1289 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1295 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1296 unsigned long mask
)
1298 XMesaContext xm_src
= src
->xmesaContext
;
1299 XMesaContext xm_dst
= dst
->xmesaContext
;
1301 if (MakeCurrent_PrevContext
== src
) {
1304 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1309 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1312 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1313 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1319 return True
; /* we're faking GLX so always return success */
1324 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1326 GLXContext glxCtx
= ctx
;
1328 MakeCurrent_PrevContext
= 0;
1329 MakeCurrent_PrevDrawable
= 0;
1330 MakeCurrent_PrevReadable
= 0;
1331 MakeCurrent_PrevDrawBuffer
= 0;
1332 MakeCurrent_PrevReadBuffer
= 0;
1333 XMesaDestroyContext( glxCtx
->xmesaContext
);
1334 XMesaGarbageCollect();
1340 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1342 GLXContext glxCtx
= ctx
;
1344 return glxCtx
->isDirect
;
1350 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1352 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1353 static boolean firsttime
= 1, no_rast
= 0;
1356 no_rast
= getenv("SP_NO_RAST") != NULL
;
1364 XMesaSwapBuffers(buffer
);
1366 else if (_mesa_getenv("MESA_DEBUG")) {
1367 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1374 /*** GLX_MESA_copy_sub_buffer ***/
1377 glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1378 int x
, int y
, int width
, int height
)
1380 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1382 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1384 else if (_mesa_getenv("MESA_DEBUG")) {
1385 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1391 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1394 /* Return GLX version, not Mesa version */
1395 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1396 *maj
= CLIENT_MAJOR_VERSION
;
1397 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1403 * Query the GLX attributes of the given XVisualInfo.
1406 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1412 return GLX_BAD_ATTRIBUTE
;
1413 *value
= (int) True
;
1415 case GLX_BUFFER_SIZE
:
1416 *value
= xmvis
->visinfo
->depth
;
1419 *value
= xmvis
->mesa_visual
.level
;
1423 return GLX_BAD_ATTRIBUTE
;
1424 if (xmvis
->mesa_visual
.rgbMode
) {
1431 case GLX_DOUBLEBUFFER
:
1432 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1435 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1437 case GLX_AUX_BUFFERS
:
1438 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1441 *value
= xmvis
->mesa_visual
.redBits
;
1443 case GLX_GREEN_SIZE
:
1444 *value
= xmvis
->mesa_visual
.greenBits
;
1447 *value
= xmvis
->mesa_visual
.blueBits
;
1449 case GLX_ALPHA_SIZE
:
1450 *value
= xmvis
->mesa_visual
.alphaBits
;
1452 case GLX_DEPTH_SIZE
:
1453 *value
= xmvis
->mesa_visual
.depthBits
;
1455 case GLX_STENCIL_SIZE
:
1456 *value
= xmvis
->mesa_visual
.stencilBits
;
1458 case GLX_ACCUM_RED_SIZE
:
1459 *value
= xmvis
->mesa_visual
.accumRedBits
;
1461 case GLX_ACCUM_GREEN_SIZE
:
1462 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1464 case GLX_ACCUM_BLUE_SIZE
:
1465 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1467 case GLX_ACCUM_ALPHA_SIZE
:
1468 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1472 * GLX_EXT_visual_info extension
1474 case GLX_X_VISUAL_TYPE_EXT
:
1475 switch (xmvis
->visinfo
->CLASS
) {
1476 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1477 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1478 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1479 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1480 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1481 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1484 case GLX_TRANSPARENT_TYPE_EXT
:
1486 *value
= GLX_NONE_EXT
;
1488 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1491 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1494 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1497 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1500 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1505 * GLX_EXT_visual_info extension
1507 case GLX_VISUAL_CAVEAT_EXT
:
1508 /* test for zero, just in case */
1509 if (xmvis
->mesa_visual
.visualRating
> 0)
1510 *value
= xmvis
->mesa_visual
.visualRating
;
1512 *value
= GLX_NONE_EXT
;
1516 * GLX_ARB_multisample
1518 case GLX_SAMPLE_BUFFERS_ARB
:
1521 case GLX_SAMPLES_ARB
:
1528 case GLX_SCREEN_EXT
:
1530 return GLX_BAD_ATTRIBUTE
;
1531 *value
= xmvis
->visinfo
->screen
;
1533 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1535 return GLX_BAD_ATTRIBUTE
;
1536 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1538 case GLX_RENDER_TYPE_SGIX
:
1540 return GLX_BAD_ATTRIBUTE
;
1541 if (xmvis
->mesa_visual
.rgbMode
)
1542 *value
= GLX_RGBA_BIT
;
1544 *value
= GLX_COLOR_INDEX_BIT
;
1546 case GLX_X_RENDERABLE_SGIX
:
1548 return GLX_BAD_ATTRIBUTE
;
1549 *value
= True
; /* XXX really? */
1551 case GLX_FBCONFIG_ID_SGIX
:
1553 return GLX_BAD_ATTRIBUTE
;
1554 *value
= xmvis
->visinfo
->visualid
;
1556 case GLX_MAX_PBUFFER_WIDTH
:
1558 return GLX_BAD_ATTRIBUTE
;
1559 /* XXX or MAX_WIDTH? */
1560 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1562 case GLX_MAX_PBUFFER_HEIGHT
:
1564 return GLX_BAD_ATTRIBUTE
;
1565 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1567 case GLX_MAX_PBUFFER_PIXELS
:
1569 return GLX_BAD_ATTRIBUTE
;
1570 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1571 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1575 return GLX_BAD_ATTRIBUTE
;
1576 *value
= xmvis
->visinfo
->visualid
;
1579 #ifdef GLX_EXT_texture_from_pixmap
1580 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1581 *value
= True
; /*XXX*/
1583 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1585 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1587 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1588 *value
= True
; /*XXX*/
1590 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1591 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1592 GLX_TEXTURE_2D_BIT_EXT
|
1593 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1595 case GLX_Y_INVERTED_EXT
:
1596 *value
= True
; /*XXX*/
1601 return GLX_BAD_ATTRIBUTE
;
1608 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1609 int attrib
, int *value
)
1613 if (!dpy
|| !visinfo
)
1614 return GLX_BAD_ATTRIBUTE
;
1616 xmvis
= find_glx_visual( dpy
, visinfo
);
1618 /* this visual wasn't obtained with glXChooseVisual */
1619 xmvis
= create_glx_visual( dpy
, visinfo
);
1621 /* this visual can't be used for GL rendering */
1622 if (attrib
==GLX_USE_GL
) {
1623 *value
= (int) False
;
1627 return GLX_BAD_VISUAL
;
1632 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1640 XMesaContext xmesa
= XMesaGetCurrentContext();
1641 XMesaFlush( xmesa
);
1649 XMesaContext xmesa
= XMesaGetCurrentContext();
1650 XMesaFlush( xmesa
);
1655 get_extensions( void )
1662 /* GLX 1.1 and later */
1664 glXQueryExtensionsString( Display
*dpy
, int screen
)
1668 return get_extensions();
1673 /* GLX 1.1 and later */
1675 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1677 static char version
[1000];
1678 sprintf(version
, "%d.%d %s",
1679 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1685 case GLX_EXTENSIONS
:
1686 return get_extensions();
1698 /* GLX 1.1 and later */
1700 glXGetClientString( Display
*dpy
, int name
)
1702 static char version
[1000];
1703 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1704 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1709 case GLX_EXTENSIONS
:
1710 return get_extensions();
1728 glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1729 int attribute
, int *value
)
1731 XMesaVisual v
= (XMesaVisual
) config
;
1735 if (!dpy
|| !config
|| !value
)
1738 return get_config(v
, attribute
, value
, GL_TRUE
);
1742 PUBLIC GLXFBConfig
*
1743 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1745 XVisualInfo
*visuals
, visTemplate
;
1746 const long visMask
= VisualScreenMask
;
1749 /* Get list of all X visuals */
1750 visTemplate
.screen
= screen
;
1751 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1752 if (*nelements
> 0) {
1753 XMesaVisual
*results
;
1754 results
= (XMesaVisual
*) malloc(*nelements
* sizeof(XMesaVisual
));
1759 for (i
= 0; i
< *nelements
; i
++) {
1760 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1766 return (GLXFBConfig
*) results
;
1772 PUBLIC GLXFBConfig
*
1773 glXChooseFBConfig( Display
*dpy
, int screen
,
1774 const int *attribList
, int *nitems
)
1778 if (!attribList
|| !attribList
[0]) {
1779 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1780 return glXGetFBConfigs(dpy
, screen
, nitems
);
1783 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1785 GLXFBConfig
*config
= (GLXFBConfig
*) malloc(sizeof(XMesaVisual
));
1791 config
[0] = (GLXFBConfig
) xmvis
;
1792 return (GLXFBConfig
*) config
;
1801 PUBLIC XVisualInfo
*
1802 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1804 if (dpy
&& config
) {
1805 XMesaVisual xmvis
= (XMesaVisual
) config
;
1807 return xmvis
->vishandle
;
1809 /* create a new vishandle - the cached one may be stale */
1810 xmvis
->vishandle
= (XVisualInfo
*) malloc(sizeof(XVisualInfo
));
1811 if (xmvis
->vishandle
) {
1812 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1814 return xmvis
->vishandle
;
1824 glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1825 const int *attribList
)
1827 XMesaVisual xmvis
= (XMesaVisual
) config
;
1832 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1837 (void) attribList
; /* Ignored in GLX 1.3 */
1839 return win
; /* A hack for now */
1844 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1846 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1848 XMesaDestroyBuffer(b
);
1849 /* don't destroy X window */
1855 glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1856 const int *attribList
)
1858 XMesaVisual v
= (XMesaVisual
) config
;
1861 int target
= 0, format
= 0, mipmap
= 0;
1864 if (!dpy
|| !config
|| !pixmap
)
1867 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1869 case GLX_TEXTURE_FORMAT_EXT
:
1872 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1873 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1874 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1882 case GLX_TEXTURE_TARGET_EXT
:
1885 case GLX_TEXTURE_1D_EXT
:
1886 case GLX_TEXTURE_2D_EXT
:
1887 case GLX_TEXTURE_RECTANGLE_EXT
:
1895 case GLX_MIPMAP_TEXTURE_EXT
:
1906 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1907 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1908 &value
, GL_TRUE
) != Success
1910 return 0; /* error! */
1913 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1914 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1915 &value
, GL_TRUE
) != Success
1917 return 0; /* error! */
1921 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1922 &value
, GL_TRUE
) != Success
1924 return 0; /* error! */
1927 if (target
== GLX_TEXTURE_1D_EXT
) {
1928 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1929 &value
, GL_TRUE
) != Success
1930 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1931 return 0; /* error! */
1934 else if (target
== GLX_TEXTURE_2D_EXT
) {
1935 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1936 &value
, GL_TRUE
) != Success
1937 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1938 return 0; /* error! */
1941 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1942 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1943 &value
, GL_TRUE
) != Success
1944 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1945 return 0; /* error! */
1949 if (format
|| target
|| mipmap
) {
1950 /* texture from pixmap */
1951 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1954 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1965 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1967 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
1969 XMesaDestroyBuffer(b
);
1970 /* don't destroy X pixmap */
1975 glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
1976 const int *attribList
)
1978 XMesaVisual xmvis
= (XMesaVisual
) config
;
1981 int width
= 0, height
= 0;
1982 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
1986 for (attrib
= attribList
; *attrib
; attrib
++) {
1988 case GLX_PBUFFER_WIDTH
:
1992 case GLX_PBUFFER_HEIGHT
:
1996 case GLX_PRESERVED_CONTENTS
:
1998 preserveContents
= *attrib
;
2000 case GLX_LARGEST_PBUFFER
:
2002 useLargest
= *attrib
;
2009 if (width
== 0 || height
== 0)
2012 if (width
> MAX_WIDTH
|| height
> MAX_HEIGHT
) {
2013 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2014 * allocate the largest possible buffer.
2018 height
= MAX_HEIGHT
;
2022 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2023 /* A GLXPbuffer handle must be an X Drawable because that's what
2024 * glXMakeCurrent takes.
2027 xmbuf
->largestPbuffer
= useLargest
;
2028 xmbuf
->preservedContents
= preserveContents
;
2029 return (GLXPbuffer
) xmbuf
->drawable
;
2038 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2040 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2042 XMesaDestroyBuffer(b
);
2048 glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2049 unsigned int *value
)
2051 GLuint width
, height
;
2052 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2056 /* make sure buffer's dimensions are up to date */
2057 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2059 switch (attribute
) {
2066 case GLX_PRESERVED_CONTENTS
:
2067 *value
= xmbuf
->preservedContents
;
2069 case GLX_LARGEST_PBUFFER
:
2070 *value
= xmbuf
->largestPbuffer
;
2072 case GLX_FBCONFIG_ID
:
2073 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2075 #ifdef GLX_EXT_texture_from_pixmap
2076 case GLX_TEXTURE_FORMAT_EXT
:
2077 *value
= xmbuf
->TextureFormat
;
2079 case GLX_TEXTURE_TARGET_EXT
:
2080 *value
= xmbuf
->TextureTarget
;
2082 case GLX_MIPMAP_TEXTURE_EXT
:
2083 *value
= xmbuf
->TextureMipmap
;
2088 return; /* raise BadValue error */
2094 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2095 int renderType
, GLXContext shareList
, Bool direct
)
2098 GLXContext shareCtx
= shareList
;
2099 XMesaVisual xmvis
= (XMesaVisual
) config
;
2101 if (!dpy
|| !config
||
2102 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2105 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
2109 /* deallocate unused windows/buffers */
2110 XMesaGarbageCollect();
2112 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2113 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2114 if (!glxCtx
->xmesaContext
) {
2119 glxCtx
->isDirect
= DEFAULT_DIRECT
;
2120 glxCtx
->currentDpy
= dpy
;
2121 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
2128 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2130 GLXContext glxCtx
= ctx
;
2131 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2136 switch (attribute
) {
2137 case GLX_FBCONFIG_ID
:
2138 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2140 case GLX_RENDER_TYPE
:
2141 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2142 *value
= GLX_RGBA_TYPE
;
2144 *value
= GLX_COLOR_INDEX_TYPE
;
2150 return GLX_BAD_ATTRIBUTE
;
2157 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2159 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2161 xmbuf
->selectedEvents
= mask
;
2166 glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2167 unsigned long *mask
)
2169 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2171 *mask
= xmbuf
->selectedEvents
;
2178 /*** GLX_SGI_swap_control ***/
2181 glXSwapIntervalSGI(int interval
)
2189 /*** GLX_SGI_video_sync ***/
2191 static unsigned int FrameCounter
= 0;
2194 glXGetVideoSyncSGI(unsigned int *count
)
2196 /* this is a bogus implementation */
2197 *count
= FrameCounter
++;
2202 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2204 if (divisor
<= 0 || remainder
< 0)
2205 return GLX_BAD_VALUE
;
2206 /* this is a bogus implementation */
2208 while (FrameCounter
% divisor
!= remainder
)
2210 *count
= FrameCounter
;
2216 /*** GLX_SGI_make_current_read ***/
2219 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2221 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2226 glXGetCurrentReadDrawableSGI(void)
2233 /*** GLX_SGIX_video_source ***/
2236 PUBLIC GLXVideoSourceSGIX
2237 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2249 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2258 /*** GLX_EXT_import_context ***/
2261 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2268 glXGetContextIDEXT(const GLXContext context
)
2275 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2283 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2294 /*** GLX_SGIX_fbconfig ***/
2297 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2299 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2302 PUBLIC GLXFBConfigSGIX
*
2303 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2305 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2310 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2312 XMesaVisual xmvis
= (XMesaVisual
) config
;
2313 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2314 return xmbuf
->drawable
; /* need to return an X ID */
2319 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2321 XMesaVisual xmvis
= (XMesaVisual
) config
;
2323 GLXContext shareCtx
= share_list
;
2325 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
2329 /* deallocate unused windows/buffers */
2330 XMesaGarbageCollect();
2332 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2333 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2334 if (!glxCtx
->xmesaContext
) {
2339 glxCtx
->isDirect
= DEFAULT_DIRECT
;
2340 glxCtx
->currentDpy
= dpy
;
2341 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
2347 PUBLIC XVisualInfo
*
2348 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2350 return glXGetVisualFromFBConfig(dpy
, config
);
2354 PUBLIC GLXFBConfigSGIX
2355 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2357 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2359 /* This visual wasn't found with glXChooseVisual() */
2360 xmvis
= create_glx_visual(dpy
, vis
);
2363 return (GLXFBConfigSGIX
) xmvis
;
2368 /*** GLX_SGIX_pbuffer ***/
2370 PUBLIC GLXPbufferSGIX
2371 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2372 unsigned int width
, unsigned int height
,
2375 XMesaVisual xmvis
= (XMesaVisual
) config
;
2378 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2382 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2384 case GLX_PRESERVED_CONTENTS_SGIX
:
2386 preserveContents
= *attrib
; /* ignored */
2388 case GLX_LARGEST_PBUFFER_SGIX
:
2390 useLargest
= *attrib
; /* ignored */
2397 /* not used at this time */
2399 (void) preserveContents
;
2401 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2402 /* A GLXPbuffer handle must be an X Drawable because that's what
2403 * glXMakeCurrent takes.
2405 return (GLXPbuffer
) xmbuf
->drawable
;
2410 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2412 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2414 XMesaDestroyBuffer(xmbuf
);
2420 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2422 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2425 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2429 switch (attribute
) {
2430 case GLX_PRESERVED_CONTENTS_SGIX
:
2433 case GLX_LARGEST_PBUFFER_SGIX
:
2434 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2436 case GLX_WIDTH_SGIX
:
2437 *value
= xmesa_buffer_width(xmbuf
);
2439 case GLX_HEIGHT_SGIX
:
2440 *value
= xmesa_buffer_height(xmbuf
);
2442 case GLX_EVENT_MASK_SGIX
:
2443 *value
= 0; /* XXX might be wrong */
2453 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2455 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2457 /* Note: we'll never generate clobber events */
2458 xmbuf
->selectedEvents
= mask
;
2464 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2466 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2468 *mask
= xmbuf
->selectedEvents
;
2477 /*** GLX_SGI_cushion ***/
2480 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2489 /*** GLX_SGIX_video_resize ***/
2492 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2502 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2515 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2528 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2541 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2552 /*** GLX_SGIX_dmbuffer **/
2554 #if defined(_DM_BUFFER_H_)
2556 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, 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
, long *pTransparent
)
2608 (void) pTransparent
;
2614 /*** GLX_MESA_release_buffers ***/
2617 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2618 * (a window or pixmap) prior to destroying the GLXDrawable.
2621 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2623 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2625 XMesaDestroyBuffer(b
);
2631 /*** GLX_EXT_texture_from_pixmap ***/
2634 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2635 const int *attrib_list
)
2637 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2639 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2643 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2645 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2647 XMesaReleaseTexImage(dpy
, b
, buffer
);