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/config.h"
39 #include "main/macros.h"
40 #include "main/imports.h"
41 #include "main/version.h"
42 #include "state_tracker/st_context.h"
43 #include "state_tracker/st_public.h"
46 /* This indicates the client-side GLX API and GLX encoder version. */
47 #define CLIENT_MAJOR_VERSION 1
48 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
50 /* This indicates the server-side GLX decoder version.
51 * GLX 1.4 indicates OpenGL 1.3 support
53 #define SERVER_MAJOR_VERSION 1
54 #define SERVER_MINOR_VERSION 4
56 /* This is appended onto the glXGetClient/ServerString version strings. */
57 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
59 /* Who implemented this GLX? */
60 #define VENDOR "Brian Paul"
63 "GLX_MESA_copy_sub_buffer " \
64 "GLX_MESA_pixmap_colormap " \
65 "GLX_MESA_release_buffers " \
66 "GLX_ARB_get_proc_address " \
67 "GLX_EXT_texture_from_pixmap " \
68 "GLX_EXT_visual_info " \
69 "GLX_EXT_visual_rating " \
70 /*"GLX_SGI_video_sync "*/ \
71 "GLX_SGIX_fbconfig " \
74 #define DEFAULT_DIRECT GL_TRUE
79 * The GLXContext typedef is defined as a pointer to this structure.
81 struct __GLXcontextRec
85 GLXDrawable currentDrawable
;
86 GLXDrawable currentReadable
;
89 XMesaContext xmesaContext
;
94 static pipe_tsd ContextTSD
;
96 /** Set current context for calling thread */
98 SetCurrentContext(GLXContext c
)
100 pipe_tsd_set(&ContextTSD
, c
);
103 /** Get current context for calling thread */
105 GetCurrentContext(void)
107 return pipe_tsd_get(&ContextTSD
);
112 /**********************************************************************/
113 /*** GLX Visual Code ***/
114 /**********************************************************************/
119 static XMesaVisual
*VisualTable
= NULL
;
120 static int NumVisuals
= 0;
124 /* Macro to handle c_class vs class field name in XVisualInfo struct */
125 #if defined(__cplusplus) || defined(c_plusplus)
126 #define CLASS c_class
134 * Test if the given XVisualInfo is usable for Mesa rendering.
137 is_usable_visual( XVisualInfo
*vinfo
)
139 switch (vinfo
->CLASS
) {
142 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
146 /* Any StaticColor/PseudoColor visual of at least 4 bits */
147 if (vinfo
->depth
>=4) {
155 /* Any depth of TrueColor or DirectColor works in RGB mode */
158 /* This should never happen */
165 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
166 * configuration in our list of GLX visuals.
169 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
170 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
171 GLboolean stereoFlag
,
172 GLint depth_size
, GLint stencil_size
,
173 GLint accumRedSize
, GLint accumGreenSize
,
174 GLint accumBlueSize
, GLint accumAlphaSize
,
175 GLint level
, GLint numAuxBuffers
)
177 GLboolean ximageFlag
= GL_TRUE
;
180 GLboolean comparePointers
;
183 /* Check if the MESA_BACK_BUFFER env var is set */
184 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
186 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
187 ximageFlag
= GL_FALSE
;
189 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
190 ximageFlag
= GL_TRUE
;
193 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
199 /* stereo not supported */
203 if (stencil_size
> 0 && depth_size
> 0)
206 /* Comparing IDs uses less memory but sometimes fails. */
207 /* XXX revisit this after 3.0 is finished. */
208 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
209 comparePointers
= GL_TRUE
;
211 comparePointers
= GL_FALSE
;
213 /* Force the visual to have an alpha channel */
214 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
217 /* First check if a matching visual is already in the list */
218 for (i
=0; i
<NumVisuals
; i
++) {
219 XMesaVisual v
= VisualTable
[i
];
220 if (v
->display
== dpy
221 && v
->mesa_visual
.level
== level
222 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
223 && v
->ximage_flag
== ximageFlag
224 && v
->mesa_visual
.rgbMode
== rgbFlag
225 && v
->mesa_visual
.doubleBufferMode
== dbFlag
226 && v
->mesa_visual
.stereoMode
== stereoFlag
227 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
228 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
229 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
230 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
231 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
232 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
233 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
234 /* now either compare XVisualInfo pointers or visual IDs */
235 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
236 || (comparePointers
&& v
->vishandle
== vinfo
)) {
242 /* Create a new visual and add it to the list. */
244 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
245 stereoFlag
, ximageFlag
,
246 depth_size
, stencil_size
,
247 accumRedSize
, accumBlueSize
,
248 accumBlueSize
, accumAlphaSize
, 0, level
,
251 /* Save a copy of the pointer now so we can find this visual again
252 * if we need to search for it in find_glx_visual().
254 xmvis
->vishandle
= vinfo
;
255 /* Allocate more space for additional visual */
256 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
257 sizeof(XMesaVisual
) * NumVisuals
,
258 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
259 /* add xmvis to the list */
260 VisualTable
[NumVisuals
] = xmvis
;
262 /* XXX minor hack, because XMesaCreateVisual doesn't support an
263 * aux buffers parameter.
265 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
272 * Return the default number of bits for the Z buffer.
273 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
274 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
275 * XXX probably do the same thing for stencil, accum, etc.
278 default_depth_bits(void)
281 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
283 zBits
= _mesa_atoi(zEnv
);
285 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
290 default_alpha_bits(void)
293 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
295 aBits
= _mesa_atoi(aEnv
);
302 default_accum_bits(void)
310 * Create a GLX visual from a regular XVisualInfo.
311 * This is called when Fake GLX is given an XVisualInfo which wasn't
312 * returned by glXChooseVisual. Since this is the first time we're
313 * considering this visual we'll take a guess at reasonable values
314 * for depth buffer size, stencil size, accum size, etc.
315 * This is the best we can do with a client-side emulation of GLX.
318 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
320 GLint zBits
= default_depth_bits();
321 GLint accBits
= default_accum_bits();
322 GLboolean alphaFlag
= default_alpha_bits() > 0;
324 if (is_usable_visual( visinfo
)) {
325 /* Configure this visual as RGB, double-buffered, depth-buffered. */
326 /* This is surely wrong for some people's needs but what else */
327 /* can be done? They should use glXChooseVisual(). */
328 return save_glx_visual( dpy
, visinfo
,
330 alphaFlag
, /* alpha */
331 GL_TRUE
, /* double */
332 GL_FALSE
, /* stereo */
344 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
352 * Find the GLX visual associated with an XVisualInfo.
355 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
359 /* try to match visual id */
360 for (i
=0;i
<NumVisuals
;i
++) {
361 if (VisualTable
[i
]->display
==dpy
362 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
363 return VisualTable
[i
];
367 /* if that fails, try to match pointers */
368 for (i
=0;i
<NumVisuals
;i
++) {
369 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
370 return VisualTable
[i
];
379 * Try to get an X visual which matches the given arguments.
382 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
384 XVisualInfo temp
, *vis
;
387 unsigned int default_depth
;
390 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
395 default_depth
= DefaultDepth(dpy
,scr
);
396 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
398 if (depth
==default_depth
&& xclass
==default_class
) {
399 /* try to get root window's visual */
400 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
401 mask
|= VisualIDMask
;
404 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
406 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
407 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
408 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
410 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
411 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
412 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
413 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
427 * Retrieve the value of the given environment variable and find
428 * the X visual which matches it.
429 * Input: dpy - the display
430 * screen - the screen number
431 * varname - the name of the environment variable
432 * Return: an XVisualInfo pointer to NULL if error.
435 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
437 char value
[100], type
[100];
438 int depth
, xclass
= -1;
441 if (!_mesa_getenv( varname
)) {
445 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
448 sscanf( value
, "%s %d", type
, &depth
);
450 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
451 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
452 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
453 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
454 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
455 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
457 if (xclass
>-1 && depth
>0) {
458 vis
= get_visual( dpy
, scr
, depth
, xclass
);
464 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
473 * Select an X visual which satisfies the RGBA flag and minimum depth.
475 * screen - X display and screen number
476 * min_depth - minimum visual depth
477 * preferred_class - preferred GLX visual class or DONT_CARE
478 * Return: pointer to an XVisualInfo or NULL.
481 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
482 int preferred_class
)
485 int xclass
, visclass
= 0;
488 /* First see if the MESA_RGB_VISUAL env var is defined */
489 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
493 /* Otherwise, search for a suitable visual */
494 if (preferred_class
==DONT_CARE
) {
495 for (xclass
=0;xclass
<6;xclass
++) {
497 case 0: visclass
= TrueColor
; break;
498 case 1: visclass
= DirectColor
; break;
499 case 2: visclass
= PseudoColor
; break;
500 case 3: visclass
= StaticColor
; break;
501 case 4: visclass
= GrayScale
; break;
502 case 5: visclass
= StaticGray
; break;
505 /* start with shallowest */
506 for (depth
=0;depth
<=32;depth
++) {
507 if (visclass
==TrueColor
&& depth
==8) {
508 /* Special case: try to get 8-bit PseudoColor before */
509 /* 8-bit TrueColor */
510 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
515 vis
= get_visual( dpy
, screen
, depth
, visclass
);
522 /* start with deepest */
523 for (depth
=32;depth
>=min_depth
;depth
--) {
524 if (visclass
==TrueColor
&& depth
==8) {
525 /* Special case: try to get 8-bit PseudoColor before */
526 /* 8-bit TrueColor */
527 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
532 vis
= get_visual( dpy
, screen
, depth
, visclass
);
541 /* search for a specific visual class */
542 switch (preferred_class
) {
543 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
544 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
545 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
546 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
547 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
548 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
549 default: return NULL
;
552 /* start with shallowest */
553 for (depth
=0;depth
<=32;depth
++) {
554 vis
= get_visual( dpy
, screen
, depth
, visclass
);
561 /* start with deepest */
562 for (depth
=32;depth
>=min_depth
;depth
--) {
563 vis
= get_visual( dpy
, screen
, depth
, visclass
);
571 /* didn't find a visual */
578 /**********************************************************************/
579 /*** Display-related functions ***/
580 /**********************************************************************/
584 * Free all XMesaVisuals which are associated with the given display.
587 destroy_visuals_on_display(Display
*dpy
)
590 for (i
= 0; i
< NumVisuals
; i
++) {
591 if (VisualTable
[i
]->display
== dpy
) {
592 /* remove this visual */
594 free(VisualTable
[i
]);
595 for (j
= i
; j
< NumVisuals
- 1; j
++)
596 VisualTable
[j
] = VisualTable
[j
+ 1];
604 * Called from XCloseDisplay() to let us free our display-related data.
607 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
609 destroy_visuals_on_display(dpy
);
610 xmesa_destroy_buffers_on_display(dpy
);
616 * Look for the named extension on given display and return a pointer
617 * to the _XExtension data, or NULL if extension not found.
620 lookup_extension(Display
*dpy
, const char *extName
)
623 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
624 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
633 * Whenever we're given a new Display pointer, call this function to
634 * register our close_display_callback function.
637 register_with_display(Display
*dpy
)
639 const char *extName
= "MesaGLX";
642 ext
= lookup_extension(dpy
, extName
);
644 XExtCodes
*c
= XAddExtension(dpy
);
645 ext
= dpy
->ext_procs
; /* new extension is at head of list */
646 assert(c
->extension
== ext
->codes
.extension
);
647 ext
->name
= _mesa_strdup(extName
);
648 ext
->close_display
= close_display_callback
;
653 /**********************************************************************/
654 /*** Begin Fake GLX API Functions ***/
655 /**********************************************************************/
659 * Helper used by glXChooseVisual and glXChooseFBConfig.
660 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
662 * In either case, the attribute list is terminated with the value 'None'.
665 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
667 const GLboolean rgbModeDefault
= fbConfig
;
668 const int *parselist
;
671 int min_red
=0, min_green
=0, min_blue
=0;
672 GLboolean rgb_flag
= rgbModeDefault
;
673 GLboolean alpha_flag
= GL_FALSE
;
674 GLboolean double_flag
= GL_FALSE
;
675 GLboolean stereo_flag
= GL_FALSE
;
676 GLint depth_size
= 0;
677 GLint stencil_size
= 0;
678 GLint accumRedSize
= 0;
679 GLint accumGreenSize
= 0;
680 GLint accumBlueSize
= 0;
681 GLint accumAlphaSize
= 0;
683 int visual_type
= DONT_CARE
;
684 int trans_type
= DONT_CARE
;
685 int trans_value
= DONT_CARE
;
686 GLint caveat
= DONT_CARE
;
687 XMesaVisual xmvis
= NULL
;
688 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
;
943 depth_size
= default_depth_bits();
944 stencil_size
= STENCIL_BITS
;
949 /* normal color planes */
950 /* Get an RGB visual */
951 int min_rgb
= min_red
+ min_green
+ min_blue
;
952 if (min_rgb
>1 && min_rgb
<8) {
953 /* a special case to be sure we can get a monochrome visual */
956 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
959 _mesa_warning(NULL
, "overlay not supported");
964 /* Note: we're not exactly obeying the glXChooseVisual rules here.
965 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
966 * largest depth buffer size, which is 32bits/value. Instead, we
967 * return 16 to maintain performance with earlier versions of Mesa.
969 if (stencil_size
> 0)
970 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
971 else if (depth_size
> 24)
973 else if (depth_size
> 16)
975 else if (depth_size
> 0) {
976 depth_size
= default_depth_bits();
980 alpha_flag
= default_alpha_bits() > 0;
983 /* we only support one size of stencil and accum buffers. */
984 if (stencil_size
> 0)
985 stencil_size
= STENCIL_BITS
;
987 if (accumRedSize
> 0 ||
988 accumGreenSize
> 0 ||
990 accumAlphaSize
> 0) {
994 accumBlueSize
= default_accum_bits();
996 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
999 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1000 stereo_flag
, depth_size
, stencil_size
,
1001 accumRedSize
, accumGreenSize
,
1002 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1010 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1014 /* register ourselves as an extension on this display */
1015 register_with_display(dpy
);
1017 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1019 /* create a new vishandle - the cached one may be stale */
1020 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1021 if (xmvis
->vishandle
) {
1022 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1024 return xmvis
->vishandle
;
1032 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1033 GLXContext share_list
, Bool direct
)
1037 GLXContext shareCtx
= share_list
;
1039 if (!dpy
|| !visinfo
)
1042 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1046 /* deallocate unused windows/buffers */
1048 XMesaGarbageCollect();
1051 xmvis
= find_glx_visual( dpy
, visinfo
);
1053 /* This visual wasn't found with glXChooseVisual() */
1054 xmvis
= create_glx_visual( dpy
, visinfo
);
1056 /* unusable visual */
1062 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1063 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1064 if (!glxCtx
->xmesaContext
) {
1069 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1070 glxCtx
->currentDpy
= dpy
;
1071 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1077 /* XXX these may have to be removed due to thread-safety issues. */
1078 static GLXContext MakeCurrent_PrevContext
= 0;
1079 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1080 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1081 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1082 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1085 /* GLX 1.3 and later */
1087 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1088 GLXDrawable read
, GLXContext ctx
)
1090 GLXContext glxCtx
= ctx
;
1091 static boolean firsttime
= 1, no_rast
= 0;
1094 no_rast
= getenv("SP_NO_RAST") != NULL
;
1098 if (ctx
&& draw
&& read
) {
1099 XMesaBuffer drawBuffer
, readBuffer
;
1100 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1102 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1103 if (ctx
== MakeCurrent_PrevContext
1104 && draw
== MakeCurrent_PrevDrawable
) {
1105 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1108 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1111 /* drawable must be a new window! */
1112 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1114 /* Out of memory, or context/drawable depth mismatch */
1119 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1120 if (ctx
== MakeCurrent_PrevContext
1121 && read
== MakeCurrent_PrevReadable
) {
1122 readBuffer
= MakeCurrent_PrevReadBuffer
;
1125 readBuffer
= XMesaFindBuffer( dpy
, read
);
1128 /* drawable must be a new window! */
1129 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1131 /* Out of memory, or context/drawable depth mismatch */
1137 MakeCurrent_PrevContext
== ctx
&&
1138 MakeCurrent_PrevDrawable
== draw
&&
1139 MakeCurrent_PrevReadable
== read
&&
1140 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1141 MakeCurrent_PrevReadBuffer
== readBuffer
)
1144 MakeCurrent_PrevContext
= ctx
;
1145 MakeCurrent_PrevDrawable
= draw
;
1146 MakeCurrent_PrevReadable
= read
;
1147 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1148 MakeCurrent_PrevReadBuffer
= readBuffer
;
1150 /* Now make current! */
1151 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1152 ctx
->currentDpy
= dpy
;
1153 ctx
->currentDrawable
= draw
;
1154 ctx
->currentReadable
= read
;
1155 SetCurrentContext(ctx
);
1162 else if (!ctx
&& !draw
&& !read
) {
1163 /* release current context w/out assigning new one. */
1164 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1165 MakeCurrent_PrevContext
= 0;
1166 MakeCurrent_PrevDrawable
= 0;
1167 MakeCurrent_PrevReadable
= 0;
1168 MakeCurrent_PrevDrawBuffer
= 0;
1169 MakeCurrent_PrevReadBuffer
= 0;
1170 SetCurrentContext(NULL
);
1174 /* The args must either all be non-zero or all zero.
1183 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1185 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1190 glXGetCurrentContext(void)
1192 return GetCurrentContext();
1197 glXGetCurrentDisplay(void)
1199 GLXContext glxCtx
= glXGetCurrentContext();
1201 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1206 glXGetCurrentDisplayEXT(void)
1208 return glXGetCurrentDisplay();
1213 glXGetCurrentDrawable(void)
1215 GLXContext gc
= glXGetCurrentContext();
1216 return gc
? gc
->currentDrawable
: 0;
1221 glXGetCurrentReadDrawable(void)
1223 GLXContext gc
= glXGetCurrentContext();
1224 return gc
? gc
->currentReadable
: 0;
1229 glXGetCurrentReadDrawableSGI(void)
1231 return glXGetCurrentReadDrawable();
1236 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1241 v
= find_glx_visual( dpy
, visinfo
);
1243 v
= create_glx_visual( dpy
, visinfo
);
1245 /* unusable visual */
1250 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1258 /*** GLX_MESA_pixmap_colormap ***/
1261 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1262 Pixmap pixmap
, Colormap cmap
)
1267 v
= find_glx_visual( dpy
, visinfo
);
1269 v
= create_glx_visual( dpy
, visinfo
);
1271 /* unusable visual */
1276 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1285 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1287 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1289 XMesaDestroyBuffer(b
);
1291 else if (_mesa_getenv("MESA_DEBUG")) {
1292 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1298 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1299 unsigned long mask
)
1301 XMesaContext xm_src
= src
->xmesaContext
;
1302 XMesaContext xm_dst
= dst
->xmesaContext
;
1304 if (MakeCurrent_PrevContext
== src
) {
1307 st_copy_context_state( xm_src
->st
, xm_dst
->st
, (GLuint
) mask
);
1312 glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1314 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1323 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1325 GLXContext glxCtx
= ctx
;
1327 MakeCurrent_PrevContext
= 0;
1328 MakeCurrent_PrevDrawable
= 0;
1329 MakeCurrent_PrevReadable
= 0;
1330 MakeCurrent_PrevDrawBuffer
= 0;
1331 MakeCurrent_PrevReadBuffer
= 0;
1332 XMesaDestroyContext( glxCtx
->xmesaContext
);
1333 XMesaGarbageCollect();
1339 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1341 GLXContext glxCtx
= ctx
;
1343 return glxCtx
->isDirect
;
1349 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1351 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1352 static boolean firsttime
= 1, no_rast
= 0;
1355 no_rast
= getenv("SP_NO_RAST") != NULL
;
1363 XMesaSwapBuffers(buffer
);
1365 else if (_mesa_getenv("MESA_DEBUG")) {
1366 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1373 /*** GLX_MESA_copy_sub_buffer ***/
1376 glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1377 int x
, int y
, int width
, int height
)
1379 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1381 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1383 else if (_mesa_getenv("MESA_DEBUG")) {
1384 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1390 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1393 /* Return GLX version, not Mesa version */
1394 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1395 *maj
= CLIENT_MAJOR_VERSION
;
1396 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1402 * Query the GLX attributes of the given XVisualInfo.
1405 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1411 return GLX_BAD_ATTRIBUTE
;
1412 *value
= (int) True
;
1414 case GLX_BUFFER_SIZE
:
1415 *value
= xmvis
->visinfo
->depth
;
1418 *value
= xmvis
->mesa_visual
.level
;
1422 return GLX_BAD_ATTRIBUTE
;
1423 if (xmvis
->mesa_visual
.rgbMode
) {
1430 case GLX_DOUBLEBUFFER
:
1431 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1434 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1436 case GLX_AUX_BUFFERS
:
1437 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1440 *value
= xmvis
->mesa_visual
.redBits
;
1442 case GLX_GREEN_SIZE
:
1443 *value
= xmvis
->mesa_visual
.greenBits
;
1446 *value
= xmvis
->mesa_visual
.blueBits
;
1448 case GLX_ALPHA_SIZE
:
1449 *value
= xmvis
->mesa_visual
.alphaBits
;
1451 case GLX_DEPTH_SIZE
:
1452 *value
= xmvis
->mesa_visual
.depthBits
;
1454 case GLX_STENCIL_SIZE
:
1455 *value
= xmvis
->mesa_visual
.stencilBits
;
1457 case GLX_ACCUM_RED_SIZE
:
1458 *value
= xmvis
->mesa_visual
.accumRedBits
;
1460 case GLX_ACCUM_GREEN_SIZE
:
1461 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1463 case GLX_ACCUM_BLUE_SIZE
:
1464 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1466 case GLX_ACCUM_ALPHA_SIZE
:
1467 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1471 * GLX_EXT_visual_info extension
1473 case GLX_X_VISUAL_TYPE_EXT
:
1474 switch (xmvis
->visinfo
->CLASS
) {
1475 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1476 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1477 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1478 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1479 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1480 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1483 case GLX_TRANSPARENT_TYPE_EXT
:
1485 *value
= GLX_NONE_EXT
;
1487 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1490 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1493 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1496 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1499 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1504 * GLX_EXT_visual_info extension
1506 case GLX_VISUAL_CAVEAT_EXT
:
1507 /* test for zero, just in case */
1508 if (xmvis
->mesa_visual
.visualRating
> 0)
1509 *value
= xmvis
->mesa_visual
.visualRating
;
1511 *value
= GLX_NONE_EXT
;
1515 * GLX_ARB_multisample
1517 case GLX_SAMPLE_BUFFERS_ARB
:
1520 case GLX_SAMPLES_ARB
:
1527 case GLX_SCREEN_EXT
:
1529 return GLX_BAD_ATTRIBUTE
;
1530 *value
= xmvis
->visinfo
->screen
;
1532 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1534 return GLX_BAD_ATTRIBUTE
;
1535 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1537 case GLX_RENDER_TYPE_SGIX
:
1539 return GLX_BAD_ATTRIBUTE
;
1540 if (xmvis
->mesa_visual
.rgbMode
)
1541 *value
= GLX_RGBA_BIT
;
1543 *value
= GLX_COLOR_INDEX_BIT
;
1545 case GLX_X_RENDERABLE_SGIX
:
1547 return GLX_BAD_ATTRIBUTE
;
1548 *value
= True
; /* XXX really? */
1550 case GLX_FBCONFIG_ID_SGIX
:
1552 return GLX_BAD_ATTRIBUTE
;
1553 *value
= xmvis
->visinfo
->visualid
;
1555 case GLX_MAX_PBUFFER_WIDTH
:
1557 return GLX_BAD_ATTRIBUTE
;
1558 /* XXX or MAX_WIDTH? */
1559 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1561 case GLX_MAX_PBUFFER_HEIGHT
:
1563 return GLX_BAD_ATTRIBUTE
;
1564 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1566 case GLX_MAX_PBUFFER_PIXELS
:
1568 return GLX_BAD_ATTRIBUTE
;
1569 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1570 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1574 return GLX_BAD_ATTRIBUTE
;
1575 *value
= xmvis
->visinfo
->visualid
;
1578 #ifdef GLX_EXT_texture_from_pixmap
1579 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1580 *value
= True
; /*XXX*/
1582 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1584 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1586 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1587 *value
= True
; /*XXX*/
1589 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1590 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1591 GLX_TEXTURE_2D_BIT_EXT
|
1592 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1594 case GLX_Y_INVERTED_EXT
:
1595 *value
= True
; /*XXX*/
1600 return GLX_BAD_ATTRIBUTE
;
1607 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1608 int attrib
, int *value
)
1612 if (!dpy
|| !visinfo
)
1613 return GLX_BAD_ATTRIBUTE
;
1615 xmvis
= find_glx_visual( dpy
, visinfo
);
1617 /* this visual wasn't obtained with glXChooseVisual */
1618 xmvis
= create_glx_visual( dpy
, visinfo
);
1620 /* this visual can't be used for GL rendering */
1621 if (attrib
==GLX_USE_GL
) {
1622 *value
= (int) False
;
1626 return GLX_BAD_VISUAL
;
1631 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1639 XMesaContext xmesa
= XMesaGetCurrentContext();
1640 XMesaFlush( xmesa
);
1648 XMesaContext xmesa
= XMesaGetCurrentContext();
1649 XMesaFlush( xmesa
);
1654 get_extensions( void )
1661 /* GLX 1.1 and later */
1663 glXQueryExtensionsString( Display
*dpy
, int screen
)
1667 return get_extensions();
1672 /* GLX 1.1 and later */
1674 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1676 static char version
[1000];
1677 _mesa_sprintf(version
, "%d.%d %s",
1678 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1684 case GLX_EXTENSIONS
:
1685 return get_extensions();
1697 /* GLX 1.1 and later */
1699 glXGetClientString( Display
*dpy
, int name
)
1701 static char version
[1000];
1702 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1703 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1708 case GLX_EXTENSIONS
:
1709 return get_extensions();
1727 glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1728 int attribute
, int *value
)
1730 XMesaVisual v
= (XMesaVisual
) config
;
1734 if (!dpy
|| !config
|| !value
)
1737 return get_config(v
, attribute
, value
, GL_TRUE
);
1742 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1744 XVisualInfo
*visuals
, visTemplate
;
1745 const long visMask
= VisualScreenMask
;
1748 /* Get list of all X visuals */
1749 visTemplate
.screen
= screen
;
1750 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1751 if (*nelements
> 0) {
1752 XMesaVisual
*results
;
1753 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
1758 for (i
= 0; i
< *nelements
; i
++) {
1759 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1761 return (GLXFBConfig
*) results
;
1768 glXChooseFBConfig( Display
*dpy
, int screen
,
1769 const int *attribList
, int *nitems
)
1773 if (!attribList
|| !attribList
[0]) {
1774 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1775 return glXGetFBConfigs(dpy
, screen
, nitems
);
1778 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1780 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
1786 config
[0] = (GLXFBConfig
) xmvis
;
1787 return (GLXFBConfig
*) config
;
1797 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1799 if (dpy
&& config
) {
1800 XMesaVisual xmvis
= (XMesaVisual
) config
;
1802 return xmvis
->vishandle
;
1804 /* create a new vishandle - the cached one may be stale */
1805 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1806 if (xmvis
->vishandle
) {
1807 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1809 return xmvis
->vishandle
;
1819 glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1820 const int *attribList
)
1822 XMesaVisual xmvis
= (XMesaVisual
) config
;
1827 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1832 (void) attribList
; /* Ignored in GLX 1.3 */
1834 return win
; /* A hack for now */
1839 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1841 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1843 XMesaDestroyBuffer(b
);
1844 /* don't destroy X window */
1850 glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1851 const int *attribList
)
1853 XMesaVisual v
= (XMesaVisual
) config
;
1856 int target
= 0, format
= 0, mipmap
= 0;
1859 if (!dpy
|| !config
|| !pixmap
)
1862 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1864 case GLX_TEXTURE_FORMAT_EXT
:
1867 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1868 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1869 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1877 case GLX_TEXTURE_TARGET_EXT
:
1880 case GLX_TEXTURE_1D_EXT
:
1881 case GLX_TEXTURE_2D_EXT
:
1882 case GLX_TEXTURE_RECTANGLE_EXT
:
1890 case GLX_MIPMAP_TEXTURE_EXT
:
1901 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1902 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1903 &value
, GL_TRUE
) != Success
1905 return 0; /* error! */
1908 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1909 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1910 &value
, GL_TRUE
) != Success
1912 return 0; /* error! */
1916 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1917 &value
, GL_TRUE
) != Success
1919 return 0; /* error! */
1922 if (target
== GLX_TEXTURE_1D_EXT
) {
1923 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1924 &value
, GL_TRUE
) != Success
1925 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1926 return 0; /* error! */
1929 else if (target
== GLX_TEXTURE_2D_EXT
) {
1930 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1931 &value
, GL_TRUE
) != Success
1932 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1933 return 0; /* error! */
1936 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1937 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1938 &value
, GL_TRUE
) != Success
1939 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1940 return 0; /* error! */
1944 if (format
|| target
|| mipmap
) {
1945 /* texture from pixmap */
1946 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1949 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1960 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1962 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
1964 XMesaDestroyBuffer(b
);
1965 /* don't destroy X pixmap */
1970 glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
1971 const int *attribList
)
1973 XMesaVisual xmvis
= (XMesaVisual
) config
;
1976 int width
= 0, height
= 0;
1977 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
1981 for (attrib
= attribList
; *attrib
; attrib
++) {
1983 case GLX_PBUFFER_WIDTH
:
1987 case GLX_PBUFFER_HEIGHT
:
1991 case GLX_PRESERVED_CONTENTS
:
1993 preserveContents
= *attrib
; /* ignored */
1995 case GLX_LARGEST_PBUFFER
:
1997 useLargest
= *attrib
; /* ignored */
2004 /* not used at this time */
2006 (void) preserveContents
;
2008 if (width
== 0 || height
== 0)
2011 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2012 /* A GLXPbuffer handle must be an X Drawable because that's what
2013 * glXMakeCurrent takes.
2016 return (GLXPbuffer
) xmbuf
->drawable
;
2023 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2025 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2027 XMesaDestroyBuffer(b
);
2033 glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2034 unsigned int *value
)
2036 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2040 switch (attribute
) {
2042 *value
= xmesa_buffer_width(xmbuf
);
2045 *value
= xmesa_buffer_width(xmbuf
);
2047 case GLX_PRESERVED_CONTENTS
:
2050 case GLX_LARGEST_PBUFFER
:
2051 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2053 case GLX_FBCONFIG_ID
:
2054 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2056 #ifdef GLX_EXT_texture_from_pixmap
2057 case GLX_TEXTURE_FORMAT_EXT
:
2058 *value
= xmbuf
->TextureFormat
;
2060 case GLX_TEXTURE_TARGET_EXT
:
2061 *value
= xmbuf
->TextureTarget
;
2063 case GLX_MIPMAP_TEXTURE_EXT
:
2064 *value
= xmbuf
->TextureMipmap
;
2069 return; /* raise BadValue error */
2075 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2076 int renderType
, GLXContext shareList
, Bool direct
)
2079 GLXContext shareCtx
= shareList
;
2080 XMesaVisual xmvis
= (XMesaVisual
) config
;
2082 if (!dpy
|| !config
||
2083 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2086 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
2090 /* deallocate unused windows/buffers */
2091 XMesaGarbageCollect();
2093 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2094 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2095 if (!glxCtx
->xmesaContext
) {
2100 glxCtx
->isDirect
= DEFAULT_DIRECT
;
2101 glxCtx
->currentDpy
= dpy
;
2102 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
2109 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2111 GLXContext glxCtx
= ctx
;
2112 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2117 switch (attribute
) {
2118 case GLX_FBCONFIG_ID
:
2119 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2121 case GLX_RENDER_TYPE
:
2122 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2123 *value
= GLX_RGBA_BIT
;
2125 *value
= GLX_COLOR_INDEX_BIT
;
2131 return GLX_BAD_ATTRIBUTE
;
2138 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2140 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2142 xmbuf
->selectedEvents
= mask
;
2147 glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2148 unsigned long *mask
)
2150 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2152 *mask
= xmbuf
->selectedEvents
;
2159 /*** GLX_SGI_swap_control ***/
2162 glXSwapIntervalSGI(int interval
)
2170 /*** GLX_SGI_video_sync ***/
2172 static unsigned int FrameCounter
= 0;
2175 glXGetVideoSyncSGI(unsigned int *count
)
2177 /* this is a bogus implementation */
2178 *count
= FrameCounter
++;
2183 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2185 if (divisor
<= 0 || remainder
< 0)
2186 return GLX_BAD_VALUE
;
2187 /* this is a bogus implementation */
2189 while (FrameCounter
% divisor
!= remainder
)
2191 *count
= FrameCounter
;
2197 /*** GLX_SGI_make_current_read ***/
2200 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2202 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2207 glXGetCurrentReadDrawableSGI(void)
2214 /*** GLX_SGIX_video_source ***/
2218 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2230 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2239 /*** GLX_EXT_import_context ***/
2242 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2249 glXGetContextIDEXT(const GLXContext context
)
2256 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2264 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2275 /*** GLX_SGIX_fbconfig ***/
2278 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2280 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2284 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2286 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2291 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2293 XMesaVisual xmvis
= (XMesaVisual
) config
;
2294 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2295 return xmbuf
->drawable
; /* need to return an X ID */
2300 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2302 XMesaVisual xmvis
= (XMesaVisual
) config
;
2304 GLXContext shareCtx
= share_list
;
2306 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
2310 /* deallocate unused windows/buffers */
2311 XMesaGarbageCollect();
2313 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2314 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2315 if (!glxCtx
->xmesaContext
) {
2320 glxCtx
->isDirect
= DEFAULT_DIRECT
;
2321 glxCtx
->currentDpy
= dpy
;
2322 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
2329 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2331 return glXGetVisualFromFBConfig(dpy
, config
);
2336 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2338 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2340 /* This visual wasn't found with glXChooseVisual() */
2341 xmvis
= create_glx_visual(dpy
, vis
);
2344 return (GLXFBConfigSGIX
) xmvis
;
2349 /*** GLX_SGIX_pbuffer ***/
2352 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2353 unsigned int width
, unsigned int height
,
2356 XMesaVisual xmvis
= (XMesaVisual
) config
;
2359 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2363 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2365 case GLX_PRESERVED_CONTENTS_SGIX
:
2367 preserveContents
= *attrib
; /* ignored */
2369 case GLX_LARGEST_PBUFFER_SGIX
:
2371 useLargest
= *attrib
; /* ignored */
2378 /* not used at this time */
2380 (void) preserveContents
;
2382 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2383 /* A GLXPbuffer handle must be an X Drawable because that's what
2384 * glXMakeCurrent takes.
2386 return (GLXPbuffer
) xmbuf
->drawable
;
2391 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2393 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2395 XMesaDestroyBuffer(xmbuf
);
2401 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2403 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2406 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2410 switch (attribute
) {
2411 case GLX_PRESERVED_CONTENTS_SGIX
:
2414 case GLX_LARGEST_PBUFFER_SGIX
:
2415 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2417 case GLX_WIDTH_SGIX
:
2418 *value
= xmesa_buffer_width(xmbuf
);
2420 case GLX_HEIGHT_SGIX
:
2421 *value
= xmesa_buffer_height(xmbuf
);
2423 case GLX_EVENT_MASK_SGIX
:
2424 *value
= 0; /* XXX might be wrong */
2434 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2436 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2438 /* Note: we'll never generate clobber events */
2439 xmbuf
->selectedEvents
= mask
;
2445 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2447 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2449 *mask
= xmbuf
->selectedEvents
;
2458 /*** GLX_SGI_cushion ***/
2461 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2470 /*** GLX_SGIX_video_resize ***/
2473 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2483 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2496 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2509 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2522 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2533 /*** GLX_SGIX_dmbuffer **/
2535 #if defined(_DM_BUFFER_H_)
2537 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2548 /*** GLX_SGIX_swap_group ***/
2551 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2560 /*** GLX_SGIX_swap_barrier ***/
2563 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2571 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2581 /*** GLX_SUN_get_transparent_index ***/
2584 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2589 (void) pTransparent
;
2595 /*** GLX_MESA_release_buffers ***/
2598 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2599 * (a window or pixmap) prior to destroying the GLXDrawable.
2602 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2604 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2606 XMesaDestroyBuffer(b
);
2612 /*** GLX_EXT_texture_from_pixmap ***/
2615 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2616 const int *attrib_list
)
2618 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2620 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2624 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2626 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2628 XMesaReleaseTexImage(dpy
, b
, buffer
);