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 * Minimal __GLXContextRec that mimics a "real" GLX context.
81 typedef struct __GLXcontextRec
85 GLXDrawable currentDrawable
;
86 GLXDrawable currentReadable
;
92 * Our fake GLX context will contain a "real" GLX context and an XMesa context.
94 * Note that a pointer to a __GLXcontext is a pointer to a fake_glx_context,
97 * XXX merge this struct with the one above.
99 struct fake_glx_context
101 __GLXcontext glxContext
; /* this MUST be first! */
102 XMesaContext xmesaContext
;
107 static pipe_tsd ContextTSD
;
109 /** Set current context for calling thread */
111 SetCurrentContext(GLXContext c
)
113 pipe_tsd_set(&ContextTSD
, c
);
116 /** Get current context for calling thread */
118 GetCurrentContext(void)
120 return pipe_tsd_get(&ContextTSD
);
125 /**********************************************************************/
126 /*** Debug helper code ***/
127 /**********************************************************************/
129 extern void _kw_ungrab_all( Display
*dpy
);
130 void _kw_ungrab_all( Display
*dpy
)
132 XUngrabPointer( dpy
, CurrentTime
);
133 XUngrabKeyboard( dpy
, CurrentTime
);
138 /**********************************************************************/
139 /*** GLX Visual Code ***/
140 /**********************************************************************/
145 static XMesaVisual
*VisualTable
= NULL
;
146 static int NumVisuals
= 0;
150 /* Macro to handle c_class vs class field name in XVisualInfo struct */
151 #if defined(__cplusplus) || defined(c_plusplus)
152 #define CLASS c_class
160 * Test if the given XVisualInfo is usable for Mesa rendering.
163 is_usable_visual( XVisualInfo
*vinfo
)
165 switch (vinfo
->CLASS
) {
168 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
172 /* Any StaticColor/PseudoColor visual of at least 4 bits */
173 if (vinfo
->depth
>=4) {
181 /* Any depth of TrueColor or DirectColor works in RGB mode */
184 /* This should never happen */
191 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
192 * configuration in our list of GLX visuals.
195 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
196 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
197 GLboolean stereoFlag
,
198 GLint depth_size
, GLint stencil_size
,
199 GLint accumRedSize
, GLint accumGreenSize
,
200 GLint accumBlueSize
, GLint accumAlphaSize
,
201 GLint level
, GLint numAuxBuffers
)
203 GLboolean ximageFlag
= GL_TRUE
;
206 GLboolean comparePointers
;
209 /* Check if the MESA_BACK_BUFFER env var is set */
210 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
212 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
213 ximageFlag
= GL_FALSE
;
215 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
216 ximageFlag
= GL_TRUE
;
219 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
225 /* stereo not supported */
229 if (stencil_size
> 0 && depth_size
> 0)
232 /* Comparing IDs uses less memory but sometimes fails. */
233 /* XXX revisit this after 3.0 is finished. */
234 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
235 comparePointers
= GL_TRUE
;
237 comparePointers
= GL_FALSE
;
239 /* Force the visual to have an alpha channel */
240 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
243 /* First check if a matching visual is already in the list */
244 for (i
=0; i
<NumVisuals
; i
++) {
245 XMesaVisual v
= VisualTable
[i
];
246 if (v
->display
== dpy
247 && v
->mesa_visual
.level
== level
248 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
249 && v
->ximage_flag
== ximageFlag
250 && v
->mesa_visual
.rgbMode
== rgbFlag
251 && v
->mesa_visual
.doubleBufferMode
== dbFlag
252 && v
->mesa_visual
.stereoMode
== stereoFlag
253 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
254 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
255 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
256 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
257 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
258 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
259 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
260 /* now either compare XVisualInfo pointers or visual IDs */
261 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
262 || (comparePointers
&& v
->vishandle
== vinfo
)) {
268 /* Create a new visual and add it to the list. */
270 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
271 stereoFlag
, ximageFlag
,
272 depth_size
, stencil_size
,
273 accumRedSize
, accumBlueSize
,
274 accumBlueSize
, accumAlphaSize
, 0, level
,
277 /* Save a copy of the pointer now so we can find this visual again
278 * if we need to search for it in find_glx_visual().
280 xmvis
->vishandle
= vinfo
;
281 /* Allocate more space for additional visual */
282 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
283 sizeof(XMesaVisual
) * NumVisuals
,
284 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
285 /* add xmvis to the list */
286 VisualTable
[NumVisuals
] = xmvis
;
288 /* XXX minor hack, because XMesaCreateVisual doesn't support an
289 * aux buffers parameter.
291 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
298 * Return the default number of bits for the Z buffer.
299 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
300 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
301 * XXX probably do the same thing for stencil, accum, etc.
304 default_depth_bits(void)
307 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
309 zBits
= _mesa_atoi(zEnv
);
311 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
316 default_alpha_bits(void)
319 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
321 aBits
= _mesa_atoi(aEnv
);
328 default_accum_bits(void)
336 * Create a GLX visual from a regular XVisualInfo.
337 * This is called when Fake GLX is given an XVisualInfo which wasn't
338 * returned by glXChooseVisual. Since this is the first time we're
339 * considering this visual we'll take a guess at reasonable values
340 * for depth buffer size, stencil size, accum size, etc.
341 * This is the best we can do with a client-side emulation of GLX.
344 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
346 GLint zBits
= default_depth_bits();
347 GLint accBits
= default_accum_bits();
348 GLboolean alphaFlag
= default_alpha_bits() > 0;
350 if (is_usable_visual( visinfo
)) {
351 /* Configure this visual as RGB, double-buffered, depth-buffered. */
352 /* This is surely wrong for some people's needs but what else */
353 /* can be done? They should use glXChooseVisual(). */
354 return save_glx_visual( dpy
, visinfo
,
356 alphaFlag
, /* alpha */
357 GL_TRUE
, /* double */
358 GL_FALSE
, /* stereo */
370 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
378 * Find the GLX visual associated with an XVisualInfo.
381 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
385 /* try to match visual id */
386 for (i
=0;i
<NumVisuals
;i
++) {
387 if (VisualTable
[i
]->display
==dpy
388 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
389 return VisualTable
[i
];
393 /* if that fails, try to match pointers */
394 for (i
=0;i
<NumVisuals
;i
++) {
395 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
396 return VisualTable
[i
];
405 * Try to get an X visual which matches the given arguments.
408 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
410 XVisualInfo temp
, *vis
;
413 unsigned int default_depth
;
416 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
421 default_depth
= DefaultDepth(dpy
,scr
);
422 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
424 if (depth
==default_depth
&& xclass
==default_class
) {
425 /* try to get root window's visual */
426 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
427 mask
|= VisualIDMask
;
430 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
432 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
433 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
434 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
436 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
437 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
438 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
439 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
453 * Retrieve the value of the given environment variable and find
454 * the X visual which matches it.
455 * Input: dpy - the display
456 * screen - the screen number
457 * varname - the name of the environment variable
458 * Return: an XVisualInfo pointer to NULL if error.
461 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
463 char value
[100], type
[100];
464 int depth
, xclass
= -1;
467 if (!_mesa_getenv( varname
)) {
471 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
474 sscanf( value
, "%s %d", type
, &depth
);
476 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
477 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
478 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
479 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
480 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
481 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
483 if (xclass
>-1 && depth
>0) {
484 vis
= get_visual( dpy
, scr
, depth
, xclass
);
490 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
499 * Select an X visual which satisfies the RGBA flag and minimum depth.
501 * screen - X display and screen number
502 * min_depth - minimum visual depth
503 * preferred_class - preferred GLX visual class or DONT_CARE
504 * Return: pointer to an XVisualInfo or NULL.
507 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
508 int preferred_class
)
511 int xclass
, visclass
= 0;
514 /* First see if the MESA_RGB_VISUAL env var is defined */
515 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
519 /* Otherwise, search for a suitable visual */
520 if (preferred_class
==DONT_CARE
) {
521 for (xclass
=0;xclass
<6;xclass
++) {
523 case 0: visclass
= TrueColor
; break;
524 case 1: visclass
= DirectColor
; break;
525 case 2: visclass
= PseudoColor
; break;
526 case 3: visclass
= StaticColor
; break;
527 case 4: visclass
= GrayScale
; break;
528 case 5: visclass
= StaticGray
; break;
531 /* start with shallowest */
532 for (depth
=0;depth
<=32;depth
++) {
533 if (visclass
==TrueColor
&& depth
==8) {
534 /* Special case: try to get 8-bit PseudoColor before */
535 /* 8-bit TrueColor */
536 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
541 vis
= get_visual( dpy
, screen
, depth
, visclass
);
548 /* start with deepest */
549 for (depth
=32;depth
>=min_depth
;depth
--) {
550 if (visclass
==TrueColor
&& depth
==8) {
551 /* Special case: try to get 8-bit PseudoColor before */
552 /* 8-bit TrueColor */
553 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
558 vis
= get_visual( dpy
, screen
, depth
, visclass
);
567 /* search for a specific visual class */
568 switch (preferred_class
) {
569 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
570 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
571 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
572 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
573 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
574 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
575 default: return NULL
;
578 /* start with shallowest */
579 for (depth
=0;depth
<=32;depth
++) {
580 vis
= get_visual( dpy
, screen
, depth
, visclass
);
587 /* start with deepest */
588 for (depth
=32;depth
>=min_depth
;depth
--) {
589 vis
= get_visual( dpy
, screen
, depth
, visclass
);
597 /* didn't find a visual */
604 /**********************************************************************/
605 /*** Display-related functions ***/
606 /**********************************************************************/
610 * Free all XMesaVisuals which are associated with the given display.
613 destroy_visuals_on_display(Display
*dpy
)
616 for (i
= 0; i
< NumVisuals
; i
++) {
617 if (VisualTable
[i
]->display
== dpy
) {
618 /* remove this visual */
620 free(VisualTable
[i
]);
621 for (j
= i
; j
< NumVisuals
- 1; j
++)
622 VisualTable
[j
] = VisualTable
[j
+ 1];
630 * Called from XCloseDisplay() to let us free our display-related data.
633 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
635 destroy_visuals_on_display(dpy
);
636 xmesa_destroy_buffers_on_display(dpy
);
642 * Look for the named extension on given display and return a pointer
643 * to the _XExtension data, or NULL if extension not found.
646 lookup_extension(Display
*dpy
, const char *extName
)
649 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
650 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
659 * Whenever we're given a new Display pointer, call this function to
660 * register our close_display_callback function.
663 register_with_display(Display
*dpy
)
665 const char *extName
= "MesaGLX";
668 ext
= lookup_extension(dpy
, extName
);
670 XExtCodes
*c
= XAddExtension(dpy
);
671 ext
= dpy
->ext_procs
; /* new extension is at head of list */
672 assert(c
->extension
== ext
->codes
.extension
);
673 ext
->name
= _mesa_strdup(extName
);
674 ext
->close_display
= close_display_callback
;
679 /**********************************************************************/
680 /*** Begin Fake GLX API Functions ***/
681 /**********************************************************************/
685 * Helper used by glXChooseVisual and glXChooseFBConfig.
686 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
688 * In either case, the attribute list is terminated with the value 'None'.
691 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
693 const GLboolean rgbModeDefault
= fbConfig
;
694 const int *parselist
;
697 int min_red
=0, min_green
=0, min_blue
=0;
698 GLboolean rgb_flag
= rgbModeDefault
;
699 GLboolean alpha_flag
= GL_FALSE
;
700 GLboolean double_flag
= GL_FALSE
;
701 GLboolean stereo_flag
= GL_FALSE
;
702 GLint depth_size
= 0;
703 GLint stencil_size
= 0;
704 GLint accumRedSize
= 0;
705 GLint accumGreenSize
= 0;
706 GLint accumBlueSize
= 0;
707 GLint accumAlphaSize
= 0;
709 int visual_type
= DONT_CARE
;
710 int trans_type
= DONT_CARE
;
711 int trans_value
= DONT_CARE
;
712 GLint caveat
= DONT_CARE
;
713 XMesaVisual xmvis
= NULL
;
714 int desiredVisualID
= -1;
721 switch (*parselist
) {
732 case GLX_BUFFER_SIZE
:
734 min_ci
= *parselist
++;
738 level
= *parselist
++;
750 case GLX_DOUBLEBUFFER
:
753 double_flag
= *parselist
++;
756 double_flag
= GL_TRUE
;
762 stereo_flag
= *parselist
++;
765 stereo_flag
= GL_TRUE
;
768 case GLX_AUX_BUFFERS
:
770 numAux
= *parselist
++;
771 if (numAux
> MAX_AUX_BUFFERS
)
776 min_red
= *parselist
++;
780 min_green
= *parselist
++;
784 min_blue
= *parselist
++;
789 GLint size
= *parselist
++;
790 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
795 depth_size
= *parselist
++;
797 case GLX_STENCIL_SIZE
:
799 stencil_size
= *parselist
++;
801 case GLX_ACCUM_RED_SIZE
:
804 GLint size
= *parselist
++;
805 accumRedSize
= MAX2( accumRedSize
, size
);
808 case GLX_ACCUM_GREEN_SIZE
:
811 GLint size
= *parselist
++;
812 accumGreenSize
= MAX2( accumGreenSize
, size
);
815 case GLX_ACCUM_BLUE_SIZE
:
818 GLint size
= *parselist
++;
819 accumBlueSize
= MAX2( accumBlueSize
, size
);
822 case GLX_ACCUM_ALPHA_SIZE
:
825 GLint size
= *parselist
++;
826 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
831 * GLX_EXT_visual_info extension
833 case GLX_X_VISUAL_TYPE_EXT
:
835 visual_type
= *parselist
++;
837 case GLX_TRANSPARENT_TYPE_EXT
:
839 trans_type
= *parselist
++;
841 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
843 trans_value
= *parselist
++;
845 case GLX_TRANSPARENT_RED_VALUE_EXT
:
846 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
847 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
848 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
855 * GLX_EXT_visual_info extension
857 case GLX_VISUAL_CAVEAT_EXT
:
859 caveat
= *parselist
++; /* ignored for now */
863 * GLX_ARB_multisample
865 case GLX_SAMPLE_BUFFERS_ARB
:
866 /* ms not supported */
868 case GLX_SAMPLES_ARB
:
869 /* ms not supported */
875 case GLX_RENDER_TYPE
:
879 if (*parselist
== GLX_RGBA_BIT
) {
882 else if (*parselist
== GLX_COLOR_INDEX_BIT
) {
885 else if (*parselist
== 0) {
890 case GLX_DRAWABLE_TYPE
:
894 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
895 return NULL
; /* bad bit */
899 case GLX_FBCONFIG_ID
:
903 desiredVisualID
= *parselist
++;
905 case GLX_X_RENDERABLE
:
912 #ifdef GLX_EXT_texture_from_pixmap
913 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
914 parselist
++; /*skip*/
916 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
917 parselist
++; /*skip*/
919 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
920 parselist
++; /*skip*/
922 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
924 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
925 GLX_TEXTURE_2D_BIT_EXT
|
926 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
931 case GLX_Y_INVERTED_EXT
:
932 parselist
++; /*skip*/
941 /* undefined attribute */
942 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
952 * Since we're only simulating the GLX extension this function will never
953 * find any real GL visuals. Instead, all we can do is try to find an RGB
954 * or CI visual of appropriate depth. Other requested attributes such as
955 * double buffering, depth buffer, etc. will be associated with the X
956 * visual and stored in the VisualTable[].
958 if (desiredVisualID
!= -1) {
959 /* try to get a specific visual, by visualID */
962 temp
.visualid
= desiredVisualID
;
963 temp
.screen
= screen
;
964 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
966 /* give the visual some useful GLX attributes */
967 double_flag
= GL_TRUE
;
969 depth_size
= default_depth_bits();
970 stencil_size
= STENCIL_BITS
;
975 /* normal color planes */
976 /* Get an RGB visual */
977 int min_rgb
= min_red
+ min_green
+ min_blue
;
978 if (min_rgb
>1 && min_rgb
<8) {
979 /* a special case to be sure we can get a monochrome visual */
982 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
985 _mesa_warning(NULL
, "overlay not supported");
990 /* Note: we're not exactly obeying the glXChooseVisual rules here.
991 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
992 * largest depth buffer size, which is 32bits/value. Instead, we
993 * return 16 to maintain performance with earlier versions of Mesa.
995 if (stencil_size
> 0)
996 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
997 else if (depth_size
> 24)
999 else if (depth_size
> 16)
1001 else if (depth_size
> 0) {
1002 depth_size
= default_depth_bits();
1006 alpha_flag
= default_alpha_bits() > 0;
1009 /* we only support one size of stencil and accum buffers. */
1010 if (stencil_size
> 0)
1011 stencil_size
= STENCIL_BITS
;
1013 if (accumRedSize
> 0 ||
1014 accumGreenSize
> 0 ||
1015 accumBlueSize
> 0 ||
1016 accumAlphaSize
> 0) {
1020 accumBlueSize
= default_accum_bits();
1022 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1025 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1026 stereo_flag
, depth_size
, stencil_size
,
1027 accumRedSize
, accumGreenSize
,
1028 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1036 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1040 /* register ourselves as an extension on this display */
1041 register_with_display(dpy
);
1043 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1045 /* create a new vishandle - the cached one may be stale */
1046 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1047 if (xmvis
->vishandle
) {
1048 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1050 return xmvis
->vishandle
;
1058 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1059 GLXContext share_list
, Bool direct
)
1062 struct fake_glx_context
*glxCtx
;
1063 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
1065 if (!dpy
|| !visinfo
)
1068 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
1072 /* deallocate unused windows/buffers */
1074 XMesaGarbageCollect();
1077 xmvis
= find_glx_visual( dpy
, visinfo
);
1079 /* This visual wasn't found with glXChooseVisual() */
1080 xmvis
= create_glx_visual( dpy
, visinfo
);
1082 /* unusable visual */
1088 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1089 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1090 if (!glxCtx
->xmesaContext
) {
1095 glxCtx
->glxContext
.isDirect
= DEFAULT_DIRECT
;
1096 glxCtx
->glxContext
.currentDpy
= dpy
;
1097 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
1099 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
1101 return (GLXContext
) glxCtx
;
1105 /* XXX these may have to be removed due to thread-safety issues. */
1106 static GLXContext MakeCurrent_PrevContext
= 0;
1107 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1108 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1109 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1110 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1113 /* GLX 1.3 and later */
1115 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1116 GLXDrawable read
, GLXContext ctx
)
1118 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1119 static boolean firsttime
= 1, no_rast
= 0;
1122 no_rast
= getenv("SP_NO_RAST") != NULL
;
1126 if (ctx
&& draw
&& read
) {
1127 XMesaBuffer drawBuffer
, readBuffer
;
1128 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1130 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1131 if (ctx
== MakeCurrent_PrevContext
1132 && draw
== MakeCurrent_PrevDrawable
) {
1133 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1136 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1139 /* drawable must be a new window! */
1140 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1142 /* Out of memory, or context/drawable depth mismatch */
1147 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1148 if (ctx
== MakeCurrent_PrevContext
1149 && read
== MakeCurrent_PrevReadable
) {
1150 readBuffer
= MakeCurrent_PrevReadBuffer
;
1153 readBuffer
= XMesaFindBuffer( dpy
, read
);
1156 /* drawable must be a new window! */
1157 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1159 /* Out of memory, or context/drawable depth mismatch */
1165 MakeCurrent_PrevContext
== ctx
&&
1166 MakeCurrent_PrevDrawable
== draw
&&
1167 MakeCurrent_PrevReadable
== read
&&
1168 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1169 MakeCurrent_PrevReadBuffer
== readBuffer
)
1172 MakeCurrent_PrevContext
= ctx
;
1173 MakeCurrent_PrevDrawable
= draw
;
1174 MakeCurrent_PrevReadable
= read
;
1175 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1176 MakeCurrent_PrevReadBuffer
= readBuffer
;
1178 /* Now make current! */
1179 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1180 ((__GLXcontext
*) ctx
)->currentDpy
= dpy
;
1181 ((__GLXcontext
*) ctx
)->currentDrawable
= draw
;
1182 ((__GLXcontext
*) ctx
)->currentReadable
= read
;
1183 SetCurrentContext(ctx
);
1190 else if (!ctx
&& !draw
&& !read
) {
1191 /* release current context w/out assigning new one. */
1192 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1193 MakeCurrent_PrevContext
= 0;
1194 MakeCurrent_PrevDrawable
= 0;
1195 MakeCurrent_PrevReadable
= 0;
1196 MakeCurrent_PrevDrawBuffer
= 0;
1197 MakeCurrent_PrevReadBuffer
= 0;
1198 SetCurrentContext(NULL
);
1202 /* The args must either all be non-zero or all zero.
1211 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1213 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1218 glXGetCurrentContext(void)
1220 return GetCurrentContext();
1225 glXGetCurrentDisplay(void)
1227 struct fake_glx_context
*glxCtx
=
1228 (struct fake_glx_context
*) glXGetCurrentContext();
1230 return glxCtx
? glxCtx
->glxContext
.currentDpy
: NULL
;
1235 glXGetCurrentDisplayEXT(void)
1237 return glXGetCurrentDisplay();
1242 glXGetCurrentDrawable(void)
1244 __GLXcontext
*gc
= (__GLXcontext
*) glXGetCurrentContext();
1245 return gc
? gc
->currentDrawable
: 0;
1250 glXGetCurrentReadDrawable(void)
1252 __GLXcontext
*gc
= (__GLXcontext
*) glXGetCurrentContext();
1253 return gc
? gc
->currentReadable
: 0;
1258 glXGetCurrentReadDrawableSGI(void)
1260 return glXGetCurrentReadDrawable();
1265 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1270 v
= find_glx_visual( dpy
, visinfo
);
1272 v
= create_glx_visual( dpy
, visinfo
);
1274 /* unusable visual */
1279 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1287 /*** GLX_MESA_pixmap_colormap ***/
1290 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1291 Pixmap pixmap
, Colormap cmap
)
1296 v
= find_glx_visual( dpy
, visinfo
);
1298 v
= create_glx_visual( dpy
, visinfo
);
1300 /* unusable visual */
1305 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1314 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1316 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1318 XMesaDestroyBuffer(b
);
1320 else if (_mesa_getenv("MESA_DEBUG")) {
1321 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1327 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1328 unsigned long mask
)
1330 struct fake_glx_context
*fakeSrc
= (struct fake_glx_context
*) src
;
1331 struct fake_glx_context
*fakeDst
= (struct fake_glx_context
*) dst
;
1332 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1333 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1335 if (MakeCurrent_PrevContext
== src
) {
1338 st_copy_context_state( xm_src
->st
, xm_dst
->st
, (GLuint
) mask
);
1343 glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1345 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1354 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1356 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1358 MakeCurrent_PrevContext
= 0;
1359 MakeCurrent_PrevDrawable
= 0;
1360 MakeCurrent_PrevReadable
= 0;
1361 MakeCurrent_PrevDrawBuffer
= 0;
1362 MakeCurrent_PrevReadBuffer
= 0;
1363 XMesaDestroyContext( glxCtx
->xmesaContext
);
1364 XMesaGarbageCollect();
1370 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1372 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
1374 return glxCtx
->glxContext
.isDirect
;
1380 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1382 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1383 static boolean firsttime
= 1, no_rast
= 0;
1386 no_rast
= getenv("SP_NO_RAST") != NULL
;
1394 XMesaSwapBuffers(buffer
);
1396 else if (_mesa_getenv("MESA_DEBUG")) {
1397 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1404 /*** GLX_MESA_copy_sub_buffer ***/
1407 glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1408 int x
, int y
, int width
, int height
)
1410 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1412 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1414 else if (_mesa_getenv("MESA_DEBUG")) {
1415 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1421 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1424 /* Return GLX version, not Mesa version */
1425 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1426 *maj
= CLIENT_MAJOR_VERSION
;
1427 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1433 * Query the GLX attributes of the given XVisualInfo.
1436 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1442 return GLX_BAD_ATTRIBUTE
;
1443 *value
= (int) True
;
1445 case GLX_BUFFER_SIZE
:
1446 *value
= xmvis
->visinfo
->depth
;
1449 *value
= xmvis
->mesa_visual
.level
;
1453 return GLX_BAD_ATTRIBUTE
;
1454 if (xmvis
->mesa_visual
.rgbMode
) {
1461 case GLX_DOUBLEBUFFER
:
1462 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1465 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1467 case GLX_AUX_BUFFERS
:
1468 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1471 *value
= xmvis
->mesa_visual
.redBits
;
1473 case GLX_GREEN_SIZE
:
1474 *value
= xmvis
->mesa_visual
.greenBits
;
1477 *value
= xmvis
->mesa_visual
.blueBits
;
1479 case GLX_ALPHA_SIZE
:
1480 *value
= xmvis
->mesa_visual
.alphaBits
;
1482 case GLX_DEPTH_SIZE
:
1483 *value
= xmvis
->mesa_visual
.depthBits
;
1485 case GLX_STENCIL_SIZE
:
1486 *value
= xmvis
->mesa_visual
.stencilBits
;
1488 case GLX_ACCUM_RED_SIZE
:
1489 *value
= xmvis
->mesa_visual
.accumRedBits
;
1491 case GLX_ACCUM_GREEN_SIZE
:
1492 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1494 case GLX_ACCUM_BLUE_SIZE
:
1495 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1497 case GLX_ACCUM_ALPHA_SIZE
:
1498 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1502 * GLX_EXT_visual_info extension
1504 case GLX_X_VISUAL_TYPE_EXT
:
1505 switch (xmvis
->visinfo
->CLASS
) {
1506 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1507 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1508 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1509 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1510 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1511 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1514 case GLX_TRANSPARENT_TYPE_EXT
:
1516 *value
= GLX_NONE_EXT
;
1518 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1521 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1524 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1527 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1530 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1535 * GLX_EXT_visual_info extension
1537 case GLX_VISUAL_CAVEAT_EXT
:
1538 /* test for zero, just in case */
1539 if (xmvis
->mesa_visual
.visualRating
> 0)
1540 *value
= xmvis
->mesa_visual
.visualRating
;
1542 *value
= GLX_NONE_EXT
;
1546 * GLX_ARB_multisample
1548 case GLX_SAMPLE_BUFFERS_ARB
:
1551 case GLX_SAMPLES_ARB
:
1558 case GLX_SCREEN_EXT
:
1560 return GLX_BAD_ATTRIBUTE
;
1561 *value
= xmvis
->visinfo
->screen
;
1563 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1565 return GLX_BAD_ATTRIBUTE
;
1566 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1568 case GLX_RENDER_TYPE_SGIX
:
1570 return GLX_BAD_ATTRIBUTE
;
1571 if (xmvis
->mesa_visual
.rgbMode
)
1572 *value
= GLX_RGBA_BIT
;
1574 *value
= GLX_COLOR_INDEX_BIT
;
1576 case GLX_X_RENDERABLE_SGIX
:
1578 return GLX_BAD_ATTRIBUTE
;
1579 *value
= True
; /* XXX really? */
1581 case GLX_FBCONFIG_ID_SGIX
:
1583 return GLX_BAD_ATTRIBUTE
;
1584 *value
= xmvis
->visinfo
->visualid
;
1586 case GLX_MAX_PBUFFER_WIDTH
:
1588 return GLX_BAD_ATTRIBUTE
;
1589 /* XXX or MAX_WIDTH? */
1590 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1592 case GLX_MAX_PBUFFER_HEIGHT
:
1594 return GLX_BAD_ATTRIBUTE
;
1595 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1597 case GLX_MAX_PBUFFER_PIXELS
:
1599 return GLX_BAD_ATTRIBUTE
;
1600 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1601 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1605 return GLX_BAD_ATTRIBUTE
;
1606 *value
= xmvis
->visinfo
->visualid
;
1609 #ifdef GLX_EXT_texture_from_pixmap
1610 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1611 *value
= True
; /*XXX*/
1613 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1615 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1617 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1618 *value
= True
; /*XXX*/
1620 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1621 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1622 GLX_TEXTURE_2D_BIT_EXT
|
1623 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1625 case GLX_Y_INVERTED_EXT
:
1626 *value
= True
; /*XXX*/
1631 return GLX_BAD_ATTRIBUTE
;
1638 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1639 int attrib
, int *value
)
1643 if (!dpy
|| !visinfo
)
1644 return GLX_BAD_ATTRIBUTE
;
1646 xmvis
= find_glx_visual( dpy
, visinfo
);
1648 /* this visual wasn't obtained with glXChooseVisual */
1649 xmvis
= create_glx_visual( dpy
, visinfo
);
1651 /* this visual can't be used for GL rendering */
1652 if (attrib
==GLX_USE_GL
) {
1653 *value
= (int) False
;
1657 return GLX_BAD_VISUAL
;
1662 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1670 XMesaContext xmesa
= XMesaGetCurrentContext();
1671 XMesaFlush( xmesa
);
1679 XMesaContext xmesa
= XMesaGetCurrentContext();
1680 XMesaFlush( xmesa
);
1685 get_extensions( void )
1692 /* GLX 1.1 and later */
1694 glXQueryExtensionsString( Display
*dpy
, int screen
)
1698 return get_extensions();
1703 /* GLX 1.1 and later */
1705 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1707 static char version
[1000];
1708 _mesa_sprintf(version
, "%d.%d %s",
1709 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1715 case GLX_EXTENSIONS
:
1716 return get_extensions();
1728 /* GLX 1.1 and later */
1730 glXGetClientString( Display
*dpy
, int name
)
1732 static char version
[1000];
1733 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1734 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1739 case GLX_EXTENSIONS
:
1740 return get_extensions();
1758 glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1759 int attribute
, int *value
)
1761 XMesaVisual v
= (XMesaVisual
) config
;
1765 if (!dpy
|| !config
|| !value
)
1768 return get_config(v
, attribute
, value
, GL_TRUE
);
1773 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1775 XVisualInfo
*visuals
, visTemplate
;
1776 const long visMask
= VisualScreenMask
;
1779 /* Get list of all X visuals */
1780 visTemplate
.screen
= screen
;
1781 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1782 if (*nelements
> 0) {
1783 XMesaVisual
*results
;
1784 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
1789 for (i
= 0; i
< *nelements
; i
++) {
1790 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1792 return (GLXFBConfig
*) results
;
1799 glXChooseFBConfig( Display
*dpy
, int screen
,
1800 const int *attribList
, int *nitems
)
1804 if (!attribList
|| !attribList
[0]) {
1805 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1806 return glXGetFBConfigs(dpy
, screen
, nitems
);
1809 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1811 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
1817 config
[0] = (GLXFBConfig
) xmvis
;
1818 return (GLXFBConfig
*) config
;
1828 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1830 if (dpy
&& config
) {
1831 XMesaVisual xmvis
= (XMesaVisual
) config
;
1833 return xmvis
->vishandle
;
1835 /* create a new vishandle - the cached one may be stale */
1836 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1837 if (xmvis
->vishandle
) {
1838 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1840 return xmvis
->vishandle
;
1850 glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1851 const int *attribList
)
1853 XMesaVisual xmvis
= (XMesaVisual
) config
;
1858 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1863 (void) attribList
; /* Ignored in GLX 1.3 */
1865 return win
; /* A hack for now */
1870 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1872 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1874 XMesaDestroyBuffer(b
);
1875 /* don't destroy X window */
1881 glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1882 const int *attribList
)
1884 XMesaVisual v
= (XMesaVisual
) config
;
1887 int target
= 0, format
= 0, mipmap
= 0;
1890 if (!dpy
|| !config
|| !pixmap
)
1893 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1895 case GLX_TEXTURE_FORMAT_EXT
:
1898 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1899 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1900 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1908 case GLX_TEXTURE_TARGET_EXT
:
1911 case GLX_TEXTURE_1D_EXT
:
1912 case GLX_TEXTURE_2D_EXT
:
1913 case GLX_TEXTURE_RECTANGLE_EXT
:
1921 case GLX_MIPMAP_TEXTURE_EXT
:
1932 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1933 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1934 &value
, GL_TRUE
) != Success
1936 return 0; /* error! */
1939 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1940 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1941 &value
, GL_TRUE
) != Success
1943 return 0; /* error! */
1947 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1948 &value
, GL_TRUE
) != Success
1950 return 0; /* error! */
1953 if (target
== GLX_TEXTURE_1D_EXT
) {
1954 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1955 &value
, GL_TRUE
) != Success
1956 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1957 return 0; /* error! */
1960 else if (target
== GLX_TEXTURE_2D_EXT
) {
1961 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1962 &value
, GL_TRUE
) != Success
1963 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1964 return 0; /* error! */
1967 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1968 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1969 &value
, GL_TRUE
) != Success
1970 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1971 return 0; /* error! */
1975 if (format
|| target
|| mipmap
) {
1976 /* texture from pixmap */
1977 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1980 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1991 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1993 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
1995 XMesaDestroyBuffer(b
);
1996 /* don't destroy X pixmap */
2001 glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
2002 const int *attribList
)
2004 XMesaVisual xmvis
= (XMesaVisual
) config
;
2007 int width
= 0, height
= 0;
2008 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2012 for (attrib
= attribList
; *attrib
; attrib
++) {
2014 case GLX_PBUFFER_WIDTH
:
2018 case GLX_PBUFFER_HEIGHT
:
2022 case GLX_PRESERVED_CONTENTS
:
2024 preserveContents
= *attrib
; /* ignored */
2026 case GLX_LARGEST_PBUFFER
:
2028 useLargest
= *attrib
; /* ignored */
2035 /* not used at this time */
2037 (void) preserveContents
;
2039 if (width
== 0 || height
== 0)
2042 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2043 /* A GLXPbuffer handle must be an X Drawable because that's what
2044 * glXMakeCurrent takes.
2047 return (GLXPbuffer
) xmbuf
->drawable
;
2054 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2056 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2058 XMesaDestroyBuffer(b
);
2064 glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2065 unsigned int *value
)
2067 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2071 switch (attribute
) {
2073 *value
= xmesa_buffer_width(xmbuf
);
2076 *value
= xmesa_buffer_width(xmbuf
);
2078 case GLX_PRESERVED_CONTENTS
:
2081 case GLX_LARGEST_PBUFFER
:
2082 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2084 case GLX_FBCONFIG_ID
:
2085 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2087 #ifdef GLX_EXT_texture_from_pixmap
2088 case GLX_TEXTURE_FORMAT_EXT
:
2089 *value
= xmbuf
->TextureFormat
;
2091 case GLX_TEXTURE_TARGET_EXT
:
2092 *value
= xmbuf
->TextureTarget
;
2094 case GLX_MIPMAP_TEXTURE_EXT
:
2095 *value
= xmbuf
->TextureMipmap
;
2100 return; /* raise BadValue error */
2106 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2107 int renderType
, GLXContext shareList
, Bool direct
)
2109 struct fake_glx_context
*glxCtx
;
2110 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) shareList
;
2111 XMesaVisual xmvis
= (XMesaVisual
) config
;
2113 if (!dpy
|| !config
||
2114 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2117 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2121 /* deallocate unused windows/buffers */
2122 XMesaGarbageCollect();
2124 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2125 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2126 if (!glxCtx
->xmesaContext
) {
2131 glxCtx
->glxContext
.isDirect
= DEFAULT_DIRECT
;
2132 glxCtx
->glxContext
.currentDpy
= dpy
;
2133 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2135 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2137 return (GLXContext
) glxCtx
;
2142 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2144 struct fake_glx_context
*glxCtx
= (struct fake_glx_context
*) ctx
;
2145 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2150 switch (attribute
) {
2151 case GLX_FBCONFIG_ID
:
2152 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2154 case GLX_RENDER_TYPE
:
2155 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2156 *value
= GLX_RGBA_BIT
;
2158 *value
= GLX_COLOR_INDEX_BIT
;
2164 return GLX_BAD_ATTRIBUTE
;
2171 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2173 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2175 xmbuf
->selectedEvents
= mask
;
2180 glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2181 unsigned long *mask
)
2183 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2185 *mask
= xmbuf
->selectedEvents
;
2192 /*** GLX_SGI_swap_control ***/
2195 glXSwapIntervalSGI(int interval
)
2203 /*** GLX_SGI_video_sync ***/
2205 static unsigned int FrameCounter
= 0;
2208 glXGetVideoSyncSGI(unsigned int *count
)
2210 /* this is a bogus implementation */
2211 *count
= FrameCounter
++;
2216 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2218 if (divisor
<= 0 || remainder
< 0)
2219 return GLX_BAD_VALUE
;
2220 /* this is a bogus implementation */
2222 while (FrameCounter
% divisor
!= remainder
)
2224 *count
= FrameCounter
;
2230 /*** GLX_SGI_make_current_read ***/
2233 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2235 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2240 glXGetCurrentReadDrawableSGI(void)
2247 /*** GLX_SGIX_video_source ***/
2251 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2263 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2272 /*** GLX_EXT_import_context ***/
2275 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2282 glXGetContextIDEXT(const GLXContext context
)
2289 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2297 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2308 /*** GLX_SGIX_fbconfig ***/
2311 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2313 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2317 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2319 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2324 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2326 XMesaVisual xmvis
= (XMesaVisual
) config
;
2327 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2328 return xmbuf
->drawable
; /* need to return an X ID */
2333 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2335 XMesaVisual xmvis
= (XMesaVisual
) config
;
2336 struct fake_glx_context
*glxCtx
;
2337 struct fake_glx_context
*shareCtx
= (struct fake_glx_context
*) share_list
;
2339 glxCtx
= CALLOC_STRUCT(fake_glx_context
);
2343 /* deallocate unused windows/buffers */
2344 XMesaGarbageCollect();
2346 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2347 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2348 if (!glxCtx
->xmesaContext
) {
2353 glxCtx
->glxContext
.isDirect
= DEFAULT_DIRECT
;
2354 glxCtx
->glxContext
.currentDpy
= dpy
;
2355 glxCtx
->glxContext
.xid
= (XID
) glxCtx
; /* self pointer */
2357 assert((void *) glxCtx
== (void *) &(glxCtx
->glxContext
));
2359 return (GLXContext
) glxCtx
;
2364 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2366 return glXGetVisualFromFBConfig(dpy
, config
);
2371 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2373 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2375 /* This visual wasn't found with glXChooseVisual() */
2376 xmvis
= create_glx_visual(dpy
, vis
);
2379 return (GLXFBConfigSGIX
) xmvis
;
2384 /*** GLX_SGIX_pbuffer ***/
2387 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2388 unsigned int width
, unsigned int height
,
2391 XMesaVisual xmvis
= (XMesaVisual
) config
;
2394 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2398 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2400 case GLX_PRESERVED_CONTENTS_SGIX
:
2402 preserveContents
= *attrib
; /* ignored */
2404 case GLX_LARGEST_PBUFFER_SGIX
:
2406 useLargest
= *attrib
; /* ignored */
2413 /* not used at this time */
2415 (void) preserveContents
;
2417 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2418 /* A GLXPbuffer handle must be an X Drawable because that's what
2419 * glXMakeCurrent takes.
2421 return (GLXPbuffer
) xmbuf
->drawable
;
2426 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2428 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2430 XMesaDestroyBuffer(xmbuf
);
2436 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2438 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2441 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2445 switch (attribute
) {
2446 case GLX_PRESERVED_CONTENTS_SGIX
:
2449 case GLX_LARGEST_PBUFFER_SGIX
:
2450 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2452 case GLX_WIDTH_SGIX
:
2453 *value
= xmesa_buffer_width(xmbuf
);
2455 case GLX_HEIGHT_SGIX
:
2456 *value
= xmesa_buffer_height(xmbuf
);
2458 case GLX_EVENT_MASK_SGIX
:
2459 *value
= 0; /* XXX might be wrong */
2469 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2471 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2473 /* Note: we'll never generate clobber events */
2474 xmbuf
->selectedEvents
= mask
;
2480 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2482 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2484 *mask
= xmbuf
->selectedEvents
;
2493 /*** GLX_SGI_cushion ***/
2496 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2505 /*** GLX_SGIX_video_resize ***/
2508 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2518 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2531 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2544 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2557 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2568 /*** GLX_SGIX_dmbuffer **/
2570 #if defined(_DM_BUFFER_H_)
2572 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2583 /*** GLX_SGIX_swap_group ***/
2586 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2595 /*** GLX_SGIX_swap_barrier ***/
2598 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2606 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2616 /*** GLX_SUN_get_transparent_index ***/
2619 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2624 (void) pTransparent
;
2630 /*** GLX_MESA_release_buffers ***/
2633 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2634 * (a window or pixmap) prior to destroying the GLXDrawable.
2637 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2639 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2641 XMesaDestroyBuffer(b
);
2647 /*** GLX_EXT_texture_from_pixmap ***/
2650 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2651 const int *attrib_list
)
2653 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2655 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2659 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2661 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2663 XMesaReleaseTexImage(dpy
, b
, buffer
);