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 /*** Debug helper code ***/
114 /**********************************************************************/
116 extern void _kw_ungrab_all( Display
*dpy
);
117 void _kw_ungrab_all( Display
*dpy
)
119 XUngrabPointer( dpy
, CurrentTime
);
120 XUngrabKeyboard( dpy
, CurrentTime
);
125 /**********************************************************************/
126 /*** GLX Visual Code ***/
127 /**********************************************************************/
132 static XMesaVisual
*VisualTable
= NULL
;
133 static int NumVisuals
= 0;
137 /* Macro to handle c_class vs class field name in XVisualInfo struct */
138 #if defined(__cplusplus) || defined(c_plusplus)
139 #define CLASS c_class
147 * Test if the given XVisualInfo is usable for Mesa rendering.
150 is_usable_visual( XVisualInfo
*vinfo
)
152 switch (vinfo
->CLASS
) {
155 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
159 /* Any StaticColor/PseudoColor visual of at least 4 bits */
160 if (vinfo
->depth
>=4) {
168 /* Any depth of TrueColor or DirectColor works in RGB mode */
171 /* This should never happen */
178 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
179 * configuration in our list of GLX visuals.
182 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
183 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
184 GLboolean stereoFlag
,
185 GLint depth_size
, GLint stencil_size
,
186 GLint accumRedSize
, GLint accumGreenSize
,
187 GLint accumBlueSize
, GLint accumAlphaSize
,
188 GLint level
, GLint numAuxBuffers
)
190 GLboolean ximageFlag
= GL_TRUE
;
193 GLboolean comparePointers
;
196 /* Check if the MESA_BACK_BUFFER env var is set */
197 char *backbuffer
= _mesa_getenv("MESA_BACK_BUFFER");
199 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
200 ximageFlag
= GL_FALSE
;
202 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
203 ximageFlag
= GL_TRUE
;
206 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
212 /* stereo not supported */
216 if (stencil_size
> 0 && depth_size
> 0)
219 /* Comparing IDs uses less memory but sometimes fails. */
220 /* XXX revisit this after 3.0 is finished. */
221 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
222 comparePointers
= GL_TRUE
;
224 comparePointers
= GL_FALSE
;
226 /* Force the visual to have an alpha channel */
227 if (rgbFlag
&& _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
230 /* First check if a matching visual is already in the list */
231 for (i
=0; i
<NumVisuals
; i
++) {
232 XMesaVisual v
= VisualTable
[i
];
233 if (v
->display
== dpy
234 && v
->mesa_visual
.level
== level
235 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
236 && v
->ximage_flag
== ximageFlag
237 && v
->mesa_visual
.rgbMode
== rgbFlag
238 && v
->mesa_visual
.doubleBufferMode
== dbFlag
239 && v
->mesa_visual
.stereoMode
== stereoFlag
240 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
241 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
242 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
243 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
244 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
245 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
246 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
247 /* now either compare XVisualInfo pointers or visual IDs */
248 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
249 || (comparePointers
&& v
->vishandle
== vinfo
)) {
255 /* Create a new visual and add it to the list. */
257 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
258 stereoFlag
, ximageFlag
,
259 depth_size
, stencil_size
,
260 accumRedSize
, accumBlueSize
,
261 accumBlueSize
, accumAlphaSize
, 0, level
,
264 /* Save a copy of the pointer now so we can find this visual again
265 * if we need to search for it in find_glx_visual().
267 xmvis
->vishandle
= vinfo
;
268 /* Allocate more space for additional visual */
269 VisualTable
= (XMesaVisual
*) _mesa_realloc( VisualTable
,
270 sizeof(XMesaVisual
) * NumVisuals
,
271 sizeof(XMesaVisual
) * (NumVisuals
+ 1));
272 /* add xmvis to the list */
273 VisualTable
[NumVisuals
] = xmvis
;
275 /* XXX minor hack, because XMesaCreateVisual doesn't support an
276 * aux buffers parameter.
278 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
285 * Return the default number of bits for the Z buffer.
286 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
287 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
288 * XXX probably do the same thing for stencil, accum, etc.
291 default_depth_bits(void)
294 const char *zEnv
= _mesa_getenv("MESA_GLX_DEPTH_BITS");
296 zBits
= _mesa_atoi(zEnv
);
298 zBits
= DEFAULT_SOFTWARE_DEPTH_BITS
;
303 default_alpha_bits(void)
306 const char *aEnv
= _mesa_getenv("MESA_GLX_ALPHA_BITS");
308 aBits
= _mesa_atoi(aEnv
);
315 default_accum_bits(void)
323 * Create a GLX visual from a regular XVisualInfo.
324 * This is called when Fake GLX is given an XVisualInfo which wasn't
325 * returned by glXChooseVisual. Since this is the first time we're
326 * considering this visual we'll take a guess at reasonable values
327 * for depth buffer size, stencil size, accum size, etc.
328 * This is the best we can do with a client-side emulation of GLX.
331 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
333 GLint zBits
= default_depth_bits();
334 GLint accBits
= default_accum_bits();
335 GLboolean alphaFlag
= default_alpha_bits() > 0;
337 if (is_usable_visual( visinfo
)) {
338 /* Configure this visual as RGB, double-buffered, depth-buffered. */
339 /* This is surely wrong for some people's needs but what else */
340 /* can be done? They should use glXChooseVisual(). */
341 return save_glx_visual( dpy
, visinfo
,
343 alphaFlag
, /* alpha */
344 GL_TRUE
, /* double */
345 GL_FALSE
, /* stereo */
357 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
365 * Find the GLX visual associated with an XVisualInfo.
368 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
372 /* try to match visual id */
373 for (i
=0;i
<NumVisuals
;i
++) {
374 if (VisualTable
[i
]->display
==dpy
375 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
376 return VisualTable
[i
];
380 /* if that fails, try to match pointers */
381 for (i
=0;i
<NumVisuals
;i
++) {
382 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
383 return VisualTable
[i
];
392 * Try to get an X visual which matches the given arguments.
395 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
397 XVisualInfo temp
, *vis
;
400 unsigned int default_depth
;
403 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
408 default_depth
= DefaultDepth(dpy
,scr
);
409 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
411 if (depth
==default_depth
&& xclass
==default_class
) {
412 /* try to get root window's visual */
413 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
414 mask
|= VisualIDMask
;
417 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
419 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
420 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
421 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
423 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
424 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
425 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
426 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
440 * Retrieve the value of the given environment variable and find
441 * the X visual which matches it.
442 * Input: dpy - the display
443 * screen - the screen number
444 * varname - the name of the environment variable
445 * Return: an XVisualInfo pointer to NULL if error.
448 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
450 char value
[100], type
[100];
451 int depth
, xclass
= -1;
454 if (!_mesa_getenv( varname
)) {
458 _mesa_strncpy( value
, _mesa_getenv(varname
), 100 );
461 sscanf( value
, "%s %d", type
, &depth
);
463 if (_mesa_strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
464 else if (_mesa_strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
465 else if (_mesa_strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
466 else if (_mesa_strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
467 else if (_mesa_strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
468 else if (_mesa_strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
470 if (xclass
>-1 && depth
>0) {
471 vis
= get_visual( dpy
, scr
, depth
, xclass
);
477 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
486 * Select an X visual which satisfies the RGBA flag and minimum depth.
488 * screen - X display and screen number
489 * min_depth - minimum visual depth
490 * preferred_class - preferred GLX visual class or DONT_CARE
491 * Return: pointer to an XVisualInfo or NULL.
494 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
495 int preferred_class
)
498 int xclass
, visclass
= 0;
501 /* First see if the MESA_RGB_VISUAL env var is defined */
502 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
506 /* Otherwise, search for a suitable visual */
507 if (preferred_class
==DONT_CARE
) {
508 for (xclass
=0;xclass
<6;xclass
++) {
510 case 0: visclass
= TrueColor
; break;
511 case 1: visclass
= DirectColor
; break;
512 case 2: visclass
= PseudoColor
; break;
513 case 3: visclass
= StaticColor
; break;
514 case 4: visclass
= GrayScale
; break;
515 case 5: visclass
= StaticGray
; break;
518 /* start with shallowest */
519 for (depth
=0;depth
<=32;depth
++) {
520 if (visclass
==TrueColor
&& depth
==8) {
521 /* Special case: try to get 8-bit PseudoColor before */
522 /* 8-bit TrueColor */
523 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
528 vis
= get_visual( dpy
, screen
, depth
, visclass
);
535 /* start with deepest */
536 for (depth
=32;depth
>=min_depth
;depth
--) {
537 if (visclass
==TrueColor
&& depth
==8) {
538 /* Special case: try to get 8-bit PseudoColor before */
539 /* 8-bit TrueColor */
540 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
545 vis
= get_visual( dpy
, screen
, depth
, visclass
);
554 /* search for a specific visual class */
555 switch (preferred_class
) {
556 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
557 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
558 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
559 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
560 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
561 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
562 default: return NULL
;
565 /* start with shallowest */
566 for (depth
=0;depth
<=32;depth
++) {
567 vis
= get_visual( dpy
, screen
, depth
, visclass
);
574 /* start with deepest */
575 for (depth
=32;depth
>=min_depth
;depth
--) {
576 vis
= get_visual( dpy
, screen
, depth
, visclass
);
584 /* didn't find a visual */
591 /**********************************************************************/
592 /*** Display-related functions ***/
593 /**********************************************************************/
597 * Free all XMesaVisuals which are associated with the given display.
600 destroy_visuals_on_display(Display
*dpy
)
603 for (i
= 0; i
< NumVisuals
; i
++) {
604 if (VisualTable
[i
]->display
== dpy
) {
605 /* remove this visual */
607 free(VisualTable
[i
]);
608 for (j
= i
; j
< NumVisuals
- 1; j
++)
609 VisualTable
[j
] = VisualTable
[j
+ 1];
617 * Called from XCloseDisplay() to let us free our display-related data.
620 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
622 destroy_visuals_on_display(dpy
);
623 xmesa_destroy_buffers_on_display(dpy
);
629 * Look for the named extension on given display and return a pointer
630 * to the _XExtension data, or NULL if extension not found.
633 lookup_extension(Display
*dpy
, const char *extName
)
636 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
637 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
646 * Whenever we're given a new Display pointer, call this function to
647 * register our close_display_callback function.
650 register_with_display(Display
*dpy
)
652 const char *extName
= "MesaGLX";
655 ext
= lookup_extension(dpy
, extName
);
657 XExtCodes
*c
= XAddExtension(dpy
);
658 ext
= dpy
->ext_procs
; /* new extension is at head of list */
659 assert(c
->extension
== ext
->codes
.extension
);
660 ext
->name
= _mesa_strdup(extName
);
661 ext
->close_display
= close_display_callback
;
666 /**********************************************************************/
667 /*** Begin Fake GLX API Functions ***/
668 /**********************************************************************/
672 * Helper used by glXChooseVisual and glXChooseFBConfig.
673 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
675 * In either case, the attribute list is terminated with the value 'None'.
678 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
680 const GLboolean rgbModeDefault
= fbConfig
;
681 const int *parselist
;
684 int min_red
=0, min_green
=0, min_blue
=0;
685 GLboolean rgb_flag
= rgbModeDefault
;
686 GLboolean alpha_flag
= GL_FALSE
;
687 GLboolean double_flag
= GL_FALSE
;
688 GLboolean stereo_flag
= GL_FALSE
;
689 GLint depth_size
= 0;
690 GLint stencil_size
= 0;
691 GLint accumRedSize
= 0;
692 GLint accumGreenSize
= 0;
693 GLint accumBlueSize
= 0;
694 GLint accumAlphaSize
= 0;
696 int visual_type
= DONT_CARE
;
697 int trans_type
= DONT_CARE
;
698 int trans_value
= DONT_CARE
;
699 GLint caveat
= DONT_CARE
;
700 XMesaVisual xmvis
= NULL
;
701 int desiredVisualID
= -1;
708 switch (*parselist
) {
719 case GLX_BUFFER_SIZE
:
721 min_ci
= *parselist
++;
725 level
= *parselist
++;
737 case GLX_DOUBLEBUFFER
:
740 double_flag
= *parselist
++;
743 double_flag
= GL_TRUE
;
749 stereo_flag
= *parselist
++;
752 stereo_flag
= GL_TRUE
;
755 case GLX_AUX_BUFFERS
:
757 numAux
= *parselist
++;
758 if (numAux
> MAX_AUX_BUFFERS
)
763 min_red
= *parselist
++;
767 min_green
= *parselist
++;
771 min_blue
= *parselist
++;
776 GLint size
= *parselist
++;
777 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
782 depth_size
= *parselist
++;
784 case GLX_STENCIL_SIZE
:
786 stencil_size
= *parselist
++;
788 case GLX_ACCUM_RED_SIZE
:
791 GLint size
= *parselist
++;
792 accumRedSize
= MAX2( accumRedSize
, size
);
795 case GLX_ACCUM_GREEN_SIZE
:
798 GLint size
= *parselist
++;
799 accumGreenSize
= MAX2( accumGreenSize
, size
);
802 case GLX_ACCUM_BLUE_SIZE
:
805 GLint size
= *parselist
++;
806 accumBlueSize
= MAX2( accumBlueSize
, size
);
809 case GLX_ACCUM_ALPHA_SIZE
:
812 GLint size
= *parselist
++;
813 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
818 * GLX_EXT_visual_info extension
820 case GLX_X_VISUAL_TYPE_EXT
:
822 visual_type
= *parselist
++;
824 case GLX_TRANSPARENT_TYPE_EXT
:
826 trans_type
= *parselist
++;
828 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
830 trans_value
= *parselist
++;
832 case GLX_TRANSPARENT_RED_VALUE_EXT
:
833 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
834 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
835 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
842 * GLX_EXT_visual_info extension
844 case GLX_VISUAL_CAVEAT_EXT
:
846 caveat
= *parselist
++; /* ignored for now */
850 * GLX_ARB_multisample
852 case GLX_SAMPLE_BUFFERS_ARB
:
853 /* ms not supported */
855 case GLX_SAMPLES_ARB
:
856 /* ms not supported */
862 case GLX_RENDER_TYPE
:
866 if (*parselist
== GLX_RGBA_BIT
) {
869 else if (*parselist
== GLX_COLOR_INDEX_BIT
) {
872 else if (*parselist
== 0) {
877 case GLX_DRAWABLE_TYPE
:
881 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
882 return NULL
; /* bad bit */
886 case GLX_FBCONFIG_ID
:
890 desiredVisualID
= *parselist
++;
892 case GLX_X_RENDERABLE
:
899 #ifdef GLX_EXT_texture_from_pixmap
900 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
901 parselist
++; /*skip*/
903 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
904 parselist
++; /*skip*/
906 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
907 parselist
++; /*skip*/
909 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
911 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
912 GLX_TEXTURE_2D_BIT_EXT
|
913 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
918 case GLX_Y_INVERTED_EXT
:
919 parselist
++; /*skip*/
928 /* undefined attribute */
929 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
939 * Since we're only simulating the GLX extension this function will never
940 * find any real GL visuals. Instead, all we can do is try to find an RGB
941 * or CI visual of appropriate depth. Other requested attributes such as
942 * double buffering, depth buffer, etc. will be associated with the X
943 * visual and stored in the VisualTable[].
945 if (desiredVisualID
!= -1) {
946 /* try to get a specific visual, by visualID */
949 temp
.visualid
= desiredVisualID
;
950 temp
.screen
= screen
;
951 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
953 /* give the visual some useful GLX attributes */
954 double_flag
= GL_TRUE
;
956 depth_size
= default_depth_bits();
957 stencil_size
= STENCIL_BITS
;
962 /* normal color planes */
963 /* Get an RGB visual */
964 int min_rgb
= min_red
+ min_green
+ min_blue
;
965 if (min_rgb
>1 && min_rgb
<8) {
966 /* a special case to be sure we can get a monochrome visual */
969 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
972 _mesa_warning(NULL
, "overlay not supported");
977 /* Note: we're not exactly obeying the glXChooseVisual rules here.
978 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
979 * largest depth buffer size, which is 32bits/value. Instead, we
980 * return 16 to maintain performance with earlier versions of Mesa.
982 if (stencil_size
> 0)
983 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
984 else if (depth_size
> 24)
986 else if (depth_size
> 16)
988 else if (depth_size
> 0) {
989 depth_size
= default_depth_bits();
993 alpha_flag
= default_alpha_bits() > 0;
996 /* we only support one size of stencil and accum buffers. */
997 if (stencil_size
> 0)
998 stencil_size
= STENCIL_BITS
;
1000 if (accumRedSize
> 0 ||
1001 accumGreenSize
> 0 ||
1002 accumBlueSize
> 0 ||
1003 accumAlphaSize
> 0) {
1007 accumBlueSize
= default_accum_bits();
1009 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1012 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1013 stereo_flag
, depth_size
, stencil_size
,
1014 accumRedSize
, accumGreenSize
,
1015 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1023 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1027 /* register ourselves as an extension on this display */
1028 register_with_display(dpy
);
1030 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1032 /* create a new vishandle - the cached one may be stale */
1033 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1034 if (xmvis
->vishandle
) {
1035 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1037 return xmvis
->vishandle
;
1045 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1046 GLXContext share_list
, Bool direct
)
1050 GLXContext shareCtx
= share_list
;
1052 if (!dpy
|| !visinfo
)
1055 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1059 /* deallocate unused windows/buffers */
1061 XMesaGarbageCollect();
1064 xmvis
= find_glx_visual( dpy
, visinfo
);
1066 /* This visual wasn't found with glXChooseVisual() */
1067 xmvis
= create_glx_visual( dpy
, visinfo
);
1069 /* unusable visual */
1075 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
1076 shareCtx
? shareCtx
->xmesaContext
: NULL
);
1077 if (!glxCtx
->xmesaContext
) {
1082 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1083 glxCtx
->currentDpy
= dpy
;
1084 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1090 /* XXX these may have to be removed due to thread-safety issues. */
1091 static GLXContext MakeCurrent_PrevContext
= 0;
1092 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1093 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1094 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1095 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1098 /* GLX 1.3 and later */
1100 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1101 GLXDrawable read
, GLXContext ctx
)
1103 GLXContext glxCtx
= ctx
;
1104 static boolean firsttime
= 1, no_rast
= 0;
1107 no_rast
= getenv("SP_NO_RAST") != NULL
;
1111 if (ctx
&& draw
&& read
) {
1112 XMesaBuffer drawBuffer
, readBuffer
;
1113 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1115 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1116 if (ctx
== MakeCurrent_PrevContext
1117 && draw
== MakeCurrent_PrevDrawable
) {
1118 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1121 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1124 /* drawable must be a new window! */
1125 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1127 /* Out of memory, or context/drawable depth mismatch */
1132 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1133 if (ctx
== MakeCurrent_PrevContext
1134 && read
== MakeCurrent_PrevReadable
) {
1135 readBuffer
= MakeCurrent_PrevReadBuffer
;
1138 readBuffer
= XMesaFindBuffer( dpy
, read
);
1141 /* drawable must be a new window! */
1142 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1144 /* Out of memory, or context/drawable depth mismatch */
1150 MakeCurrent_PrevContext
== ctx
&&
1151 MakeCurrent_PrevDrawable
== draw
&&
1152 MakeCurrent_PrevReadable
== read
&&
1153 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1154 MakeCurrent_PrevReadBuffer
== readBuffer
)
1157 MakeCurrent_PrevContext
= ctx
;
1158 MakeCurrent_PrevDrawable
= draw
;
1159 MakeCurrent_PrevReadable
= read
;
1160 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1161 MakeCurrent_PrevReadBuffer
= readBuffer
;
1163 /* Now make current! */
1164 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1165 ctx
->currentDpy
= dpy
;
1166 ctx
->currentDrawable
= draw
;
1167 ctx
->currentReadable
= read
;
1168 SetCurrentContext(ctx
);
1175 else if (!ctx
&& !draw
&& !read
) {
1176 /* release current context w/out assigning new one. */
1177 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1178 MakeCurrent_PrevContext
= 0;
1179 MakeCurrent_PrevDrawable
= 0;
1180 MakeCurrent_PrevReadable
= 0;
1181 MakeCurrent_PrevDrawBuffer
= 0;
1182 MakeCurrent_PrevReadBuffer
= 0;
1183 SetCurrentContext(NULL
);
1187 /* The args must either all be non-zero or all zero.
1196 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1198 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1203 glXGetCurrentContext(void)
1205 return GetCurrentContext();
1210 glXGetCurrentDisplay(void)
1212 GLXContext glxCtx
= glXGetCurrentContext();
1214 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1219 glXGetCurrentDisplayEXT(void)
1221 return glXGetCurrentDisplay();
1226 glXGetCurrentDrawable(void)
1228 GLXContext gc
= glXGetCurrentContext();
1229 return gc
? gc
->currentDrawable
: 0;
1234 glXGetCurrentReadDrawable(void)
1236 GLXContext gc
= glXGetCurrentContext();
1237 return gc
? gc
->currentReadable
: 0;
1242 glXGetCurrentReadDrawableSGI(void)
1244 return glXGetCurrentReadDrawable();
1249 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1254 v
= find_glx_visual( dpy
, visinfo
);
1256 v
= create_glx_visual( dpy
, visinfo
);
1258 /* unusable visual */
1263 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1271 /*** GLX_MESA_pixmap_colormap ***/
1274 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1275 Pixmap pixmap
, Colormap cmap
)
1280 v
= find_glx_visual( dpy
, visinfo
);
1282 v
= create_glx_visual( dpy
, visinfo
);
1284 /* unusable visual */
1289 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1298 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1300 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1302 XMesaDestroyBuffer(b
);
1304 else if (_mesa_getenv("MESA_DEBUG")) {
1305 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1311 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1312 unsigned long mask
)
1314 GLXContext fakeSrc
= src
;
1315 GLXContext fakeDst
= dst
;
1316 XMesaContext xm_src
= fakeSrc
->xmesaContext
;
1317 XMesaContext xm_dst
= fakeDst
->xmesaContext
;
1319 if (MakeCurrent_PrevContext
== src
) {
1322 st_copy_context_state( xm_src
->st
, xm_dst
->st
, (GLuint
) mask
);
1327 glXQueryExtension( Display
*dpy
, int *errorb
, int *event
)
1329 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1338 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1340 GLXContext glxCtx
= ctx
;
1342 MakeCurrent_PrevContext
= 0;
1343 MakeCurrent_PrevDrawable
= 0;
1344 MakeCurrent_PrevReadable
= 0;
1345 MakeCurrent_PrevDrawBuffer
= 0;
1346 MakeCurrent_PrevReadBuffer
= 0;
1347 XMesaDestroyContext( glxCtx
->xmesaContext
);
1348 XMesaGarbageCollect();
1354 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1356 GLXContext glxCtx
= ctx
;
1358 return glxCtx
->isDirect
;
1364 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1366 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1367 static boolean firsttime
= 1, no_rast
= 0;
1370 no_rast
= getenv("SP_NO_RAST") != NULL
;
1378 XMesaSwapBuffers(buffer
);
1380 else if (_mesa_getenv("MESA_DEBUG")) {
1381 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1388 /*** GLX_MESA_copy_sub_buffer ***/
1391 glXCopySubBufferMESA( Display
*dpy
, GLXDrawable drawable
,
1392 int x
, int y
, int width
, int height
)
1394 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1396 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1398 else if (_mesa_getenv("MESA_DEBUG")) {
1399 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1405 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1408 /* Return GLX version, not Mesa version */
1409 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1410 *maj
= CLIENT_MAJOR_VERSION
;
1411 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1417 * Query the GLX attributes of the given XVisualInfo.
1420 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1426 return GLX_BAD_ATTRIBUTE
;
1427 *value
= (int) True
;
1429 case GLX_BUFFER_SIZE
:
1430 *value
= xmvis
->visinfo
->depth
;
1433 *value
= xmvis
->mesa_visual
.level
;
1437 return GLX_BAD_ATTRIBUTE
;
1438 if (xmvis
->mesa_visual
.rgbMode
) {
1445 case GLX_DOUBLEBUFFER
:
1446 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1449 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1451 case GLX_AUX_BUFFERS
:
1452 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1455 *value
= xmvis
->mesa_visual
.redBits
;
1457 case GLX_GREEN_SIZE
:
1458 *value
= xmvis
->mesa_visual
.greenBits
;
1461 *value
= xmvis
->mesa_visual
.blueBits
;
1463 case GLX_ALPHA_SIZE
:
1464 *value
= xmvis
->mesa_visual
.alphaBits
;
1466 case GLX_DEPTH_SIZE
:
1467 *value
= xmvis
->mesa_visual
.depthBits
;
1469 case GLX_STENCIL_SIZE
:
1470 *value
= xmvis
->mesa_visual
.stencilBits
;
1472 case GLX_ACCUM_RED_SIZE
:
1473 *value
= xmvis
->mesa_visual
.accumRedBits
;
1475 case GLX_ACCUM_GREEN_SIZE
:
1476 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1478 case GLX_ACCUM_BLUE_SIZE
:
1479 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1481 case GLX_ACCUM_ALPHA_SIZE
:
1482 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1486 * GLX_EXT_visual_info extension
1488 case GLX_X_VISUAL_TYPE_EXT
:
1489 switch (xmvis
->visinfo
->CLASS
) {
1490 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1491 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1492 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1493 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1494 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1495 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1498 case GLX_TRANSPARENT_TYPE_EXT
:
1500 *value
= GLX_NONE_EXT
;
1502 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1505 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1508 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1511 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1514 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1519 * GLX_EXT_visual_info extension
1521 case GLX_VISUAL_CAVEAT_EXT
:
1522 /* test for zero, just in case */
1523 if (xmvis
->mesa_visual
.visualRating
> 0)
1524 *value
= xmvis
->mesa_visual
.visualRating
;
1526 *value
= GLX_NONE_EXT
;
1530 * GLX_ARB_multisample
1532 case GLX_SAMPLE_BUFFERS_ARB
:
1535 case GLX_SAMPLES_ARB
:
1542 case GLX_SCREEN_EXT
:
1544 return GLX_BAD_ATTRIBUTE
;
1545 *value
= xmvis
->visinfo
->screen
;
1547 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1549 return GLX_BAD_ATTRIBUTE
;
1550 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1552 case GLX_RENDER_TYPE_SGIX
:
1554 return GLX_BAD_ATTRIBUTE
;
1555 if (xmvis
->mesa_visual
.rgbMode
)
1556 *value
= GLX_RGBA_BIT
;
1558 *value
= GLX_COLOR_INDEX_BIT
;
1560 case GLX_X_RENDERABLE_SGIX
:
1562 return GLX_BAD_ATTRIBUTE
;
1563 *value
= True
; /* XXX really? */
1565 case GLX_FBCONFIG_ID_SGIX
:
1567 return GLX_BAD_ATTRIBUTE
;
1568 *value
= xmvis
->visinfo
->visualid
;
1570 case GLX_MAX_PBUFFER_WIDTH
:
1572 return GLX_BAD_ATTRIBUTE
;
1573 /* XXX or MAX_WIDTH? */
1574 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1576 case GLX_MAX_PBUFFER_HEIGHT
:
1578 return GLX_BAD_ATTRIBUTE
;
1579 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1581 case GLX_MAX_PBUFFER_PIXELS
:
1583 return GLX_BAD_ATTRIBUTE
;
1584 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1585 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1589 return GLX_BAD_ATTRIBUTE
;
1590 *value
= xmvis
->visinfo
->visualid
;
1593 #ifdef GLX_EXT_texture_from_pixmap
1594 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1595 *value
= True
; /*XXX*/
1597 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1599 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1601 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1602 *value
= True
; /*XXX*/
1604 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1605 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1606 GLX_TEXTURE_2D_BIT_EXT
|
1607 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1609 case GLX_Y_INVERTED_EXT
:
1610 *value
= True
; /*XXX*/
1615 return GLX_BAD_ATTRIBUTE
;
1622 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1623 int attrib
, int *value
)
1627 if (!dpy
|| !visinfo
)
1628 return GLX_BAD_ATTRIBUTE
;
1630 xmvis
= find_glx_visual( dpy
, visinfo
);
1632 /* this visual wasn't obtained with glXChooseVisual */
1633 xmvis
= create_glx_visual( dpy
, visinfo
);
1635 /* this visual can't be used for GL rendering */
1636 if (attrib
==GLX_USE_GL
) {
1637 *value
= (int) False
;
1641 return GLX_BAD_VISUAL
;
1646 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1654 XMesaContext xmesa
= XMesaGetCurrentContext();
1655 XMesaFlush( xmesa
);
1663 XMesaContext xmesa
= XMesaGetCurrentContext();
1664 XMesaFlush( xmesa
);
1669 get_extensions( void )
1676 /* GLX 1.1 and later */
1678 glXQueryExtensionsString( Display
*dpy
, int screen
)
1682 return get_extensions();
1687 /* GLX 1.1 and later */
1689 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1691 static char version
[1000];
1692 _mesa_sprintf(version
, "%d.%d %s",
1693 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, MESA_GLX_VERSION
);
1699 case GLX_EXTENSIONS
:
1700 return get_extensions();
1712 /* GLX 1.1 and later */
1714 glXGetClientString( Display
*dpy
, int name
)
1716 static char version
[1000];
1717 _mesa_sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1718 CLIENT_MINOR_VERSION
, MESA_GLX_VERSION
);
1723 case GLX_EXTENSIONS
:
1724 return get_extensions();
1742 glXGetFBConfigAttrib( Display
*dpy
, GLXFBConfig config
,
1743 int attribute
, int *value
)
1745 XMesaVisual v
= (XMesaVisual
) config
;
1749 if (!dpy
|| !config
|| !value
)
1752 return get_config(v
, attribute
, value
, GL_TRUE
);
1757 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1759 XVisualInfo
*visuals
, visTemplate
;
1760 const long visMask
= VisualScreenMask
;
1763 /* Get list of all X visuals */
1764 visTemplate
.screen
= screen
;
1765 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1766 if (*nelements
> 0) {
1767 XMesaVisual
*results
;
1768 results
= (XMesaVisual
*) _mesa_malloc(*nelements
* sizeof(XMesaVisual
));
1773 for (i
= 0; i
< *nelements
; i
++) {
1774 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1776 return (GLXFBConfig
*) results
;
1783 glXChooseFBConfig( Display
*dpy
, int screen
,
1784 const int *attribList
, int *nitems
)
1788 if (!attribList
|| !attribList
[0]) {
1789 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1790 return glXGetFBConfigs(dpy
, screen
, nitems
);
1793 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1795 GLXFBConfig
*config
= (GLXFBConfig
*) _mesa_malloc(sizeof(XMesaVisual
));
1801 config
[0] = (GLXFBConfig
) xmvis
;
1802 return (GLXFBConfig
*) config
;
1812 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1814 if (dpy
&& config
) {
1815 XMesaVisual xmvis
= (XMesaVisual
) config
;
1817 return xmvis
->vishandle
;
1819 /* create a new vishandle - the cached one may be stale */
1820 xmvis
->vishandle
= (XVisualInfo
*) _mesa_malloc(sizeof(XVisualInfo
));
1821 if (xmvis
->vishandle
) {
1822 _mesa_memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1824 return xmvis
->vishandle
;
1834 glXCreateWindow( Display
*dpy
, GLXFBConfig config
, Window win
,
1835 const int *attribList
)
1837 XMesaVisual xmvis
= (XMesaVisual
) config
;
1842 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1847 (void) attribList
; /* Ignored in GLX 1.3 */
1849 return win
; /* A hack for now */
1854 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1856 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1858 XMesaDestroyBuffer(b
);
1859 /* don't destroy X window */
1865 glXCreatePixmap( Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1866 const int *attribList
)
1868 XMesaVisual v
= (XMesaVisual
) config
;
1871 int target
= 0, format
= 0, mipmap
= 0;
1874 if (!dpy
|| !config
|| !pixmap
)
1877 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1879 case GLX_TEXTURE_FORMAT_EXT
:
1882 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1883 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1884 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1892 case GLX_TEXTURE_TARGET_EXT
:
1895 case GLX_TEXTURE_1D_EXT
:
1896 case GLX_TEXTURE_2D_EXT
:
1897 case GLX_TEXTURE_RECTANGLE_EXT
:
1905 case GLX_MIPMAP_TEXTURE_EXT
:
1916 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1917 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1918 &value
, GL_TRUE
) != Success
1920 return 0; /* error! */
1923 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1924 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1925 &value
, GL_TRUE
) != Success
1927 return 0; /* error! */
1931 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
1932 &value
, GL_TRUE
) != Success
1934 return 0; /* error! */
1937 if (target
== GLX_TEXTURE_1D_EXT
) {
1938 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1939 &value
, GL_TRUE
) != Success
1940 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
1941 return 0; /* error! */
1944 else if (target
== GLX_TEXTURE_2D_EXT
) {
1945 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1946 &value
, GL_TRUE
) != Success
1947 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
1948 return 0; /* error! */
1951 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
1952 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
1953 &value
, GL_TRUE
) != Success
1954 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
1955 return 0; /* error! */
1959 if (format
|| target
|| mipmap
) {
1960 /* texture from pixmap */
1961 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
1964 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1975 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
1977 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
1979 XMesaDestroyBuffer(b
);
1980 /* don't destroy X pixmap */
1985 glXCreatePbuffer( Display
*dpy
, GLXFBConfig config
,
1986 const int *attribList
)
1988 XMesaVisual xmvis
= (XMesaVisual
) config
;
1991 int width
= 0, height
= 0;
1992 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
1996 for (attrib
= attribList
; *attrib
; attrib
++) {
1998 case GLX_PBUFFER_WIDTH
:
2002 case GLX_PBUFFER_HEIGHT
:
2006 case GLX_PRESERVED_CONTENTS
:
2008 preserveContents
= *attrib
; /* ignored */
2010 case GLX_LARGEST_PBUFFER
:
2012 useLargest
= *attrib
; /* ignored */
2019 /* not used at this time */
2021 (void) preserveContents
;
2023 if (width
== 0 || height
== 0)
2026 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2027 /* A GLXPbuffer handle must be an X Drawable because that's what
2028 * glXMakeCurrent takes.
2031 return (GLXPbuffer
) xmbuf
->drawable
;
2038 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2040 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2042 XMesaDestroyBuffer(b
);
2048 glXQueryDrawable( Display
*dpy
, GLXDrawable draw
, int attribute
,
2049 unsigned int *value
)
2051 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2055 switch (attribute
) {
2057 *value
= xmesa_buffer_width(xmbuf
);
2060 *value
= xmesa_buffer_width(xmbuf
);
2062 case GLX_PRESERVED_CONTENTS
:
2065 case GLX_LARGEST_PBUFFER
:
2066 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2068 case GLX_FBCONFIG_ID
:
2069 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2071 #ifdef GLX_EXT_texture_from_pixmap
2072 case GLX_TEXTURE_FORMAT_EXT
:
2073 *value
= xmbuf
->TextureFormat
;
2075 case GLX_TEXTURE_TARGET_EXT
:
2076 *value
= xmbuf
->TextureTarget
;
2078 case GLX_MIPMAP_TEXTURE_EXT
:
2079 *value
= xmbuf
->TextureMipmap
;
2084 return; /* raise BadValue error */
2090 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2091 int renderType
, GLXContext shareList
, Bool direct
)
2094 GLXContext shareCtx
= shareList
;
2095 XMesaVisual xmvis
= (XMesaVisual
) config
;
2097 if (!dpy
|| !config
||
2098 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2101 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
2105 /* deallocate unused windows/buffers */
2106 XMesaGarbageCollect();
2108 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2109 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2110 if (!glxCtx
->xmesaContext
) {
2115 glxCtx
->isDirect
= DEFAULT_DIRECT
;
2116 glxCtx
->currentDpy
= dpy
;
2117 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
2124 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2126 GLXContext glxCtx
= ctx
;
2127 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2132 switch (attribute
) {
2133 case GLX_FBCONFIG_ID
:
2134 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2136 case GLX_RENDER_TYPE
:
2137 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2138 *value
= GLX_RGBA_BIT
;
2140 *value
= GLX_COLOR_INDEX_BIT
;
2146 return GLX_BAD_ATTRIBUTE
;
2153 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2155 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2157 xmbuf
->selectedEvents
= mask
;
2162 glXGetSelectedEvent( Display
*dpy
, GLXDrawable drawable
,
2163 unsigned long *mask
)
2165 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2167 *mask
= xmbuf
->selectedEvents
;
2174 /*** GLX_SGI_swap_control ***/
2177 glXSwapIntervalSGI(int interval
)
2185 /*** GLX_SGI_video_sync ***/
2187 static unsigned int FrameCounter
= 0;
2190 glXGetVideoSyncSGI(unsigned int *count
)
2192 /* this is a bogus implementation */
2193 *count
= FrameCounter
++;
2198 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2200 if (divisor
<= 0 || remainder
< 0)
2201 return GLX_BAD_VALUE
;
2202 /* this is a bogus implementation */
2204 while (FrameCounter
% divisor
!= remainder
)
2206 *count
= FrameCounter
;
2212 /*** GLX_SGI_make_current_read ***/
2215 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
2217 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2222 glXGetCurrentReadDrawableSGI(void)
2229 /*** GLX_SGIX_video_source ***/
2233 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
, VLPath path
, int nodeClass
, VLNode drainNode
)
2245 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2254 /*** GLX_EXT_import_context ***/
2257 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2264 glXGetContextIDEXT(const GLXContext context
)
2271 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2279 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
, int *value
)
2290 /*** GLX_SGIX_fbconfig ***/
2293 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
)
2295 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2299 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
, int *nelements
)
2301 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
, attrib_list
, nelements
);
2306 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, Pixmap pixmap
)
2308 XMesaVisual xmvis
= (XMesaVisual
) config
;
2309 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2310 return xmbuf
->drawable
; /* need to return an X ID */
2315 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
, int render_type
, GLXContext share_list
, Bool direct
)
2317 XMesaVisual xmvis
= (XMesaVisual
) config
;
2319 GLXContext shareCtx
= share_list
;
2321 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
2325 /* deallocate unused windows/buffers */
2326 XMesaGarbageCollect();
2328 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
,
2329 shareCtx
? shareCtx
->xmesaContext
: NULL
);
2330 if (!glxCtx
->xmesaContext
) {
2335 glxCtx
->isDirect
= DEFAULT_DIRECT
;
2336 glxCtx
->currentDpy
= dpy
;
2337 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
2344 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2346 return glXGetVisualFromFBConfig(dpy
, config
);
2351 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2353 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2355 /* This visual wasn't found with glXChooseVisual() */
2356 xmvis
= create_glx_visual(dpy
, vis
);
2359 return (GLXFBConfigSGIX
) xmvis
;
2364 /*** GLX_SGIX_pbuffer ***/
2367 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2368 unsigned int width
, unsigned int height
,
2371 XMesaVisual xmvis
= (XMesaVisual
) config
;
2374 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2378 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2380 case GLX_PRESERVED_CONTENTS_SGIX
:
2382 preserveContents
= *attrib
; /* ignored */
2384 case GLX_LARGEST_PBUFFER_SGIX
:
2386 useLargest
= *attrib
; /* ignored */
2393 /* not used at this time */
2395 (void) preserveContents
;
2397 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2398 /* A GLXPbuffer handle must be an X Drawable because that's what
2399 * glXMakeCurrent takes.
2401 return (GLXPbuffer
) xmbuf
->drawable
;
2406 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2408 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2410 XMesaDestroyBuffer(xmbuf
);
2416 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
, unsigned int *value
)
2418 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2421 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2425 switch (attribute
) {
2426 case GLX_PRESERVED_CONTENTS_SGIX
:
2429 case GLX_LARGEST_PBUFFER_SGIX
:
2430 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2432 case GLX_WIDTH_SGIX
:
2433 *value
= xmesa_buffer_width(xmbuf
);
2435 case GLX_HEIGHT_SGIX
:
2436 *value
= xmesa_buffer_height(xmbuf
);
2438 case GLX_EVENT_MASK_SGIX
:
2439 *value
= 0; /* XXX might be wrong */
2449 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2451 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2453 /* Note: we'll never generate clobber events */
2454 xmbuf
->selectedEvents
= mask
;
2460 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2462 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2464 *mask
= xmbuf
->selectedEvents
;
2473 /*** GLX_SGI_cushion ***/
2476 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2485 /*** GLX_SGIX_video_resize ***/
2488 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
, Window window
)
2498 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int x
, int y
, int w
, int h
)
2511 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
, int *x
, int *y
, int *w
, int *h
)
2524 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
, int *dx
, int *dy
, int *dw
, int *dh
)
2537 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2548 /*** GLX_SGIX_dmbuffer **/
2550 #if defined(_DM_BUFFER_H_)
2552 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
, DMparams
*params
, DMbuffer dmbuffer
)
2563 /*** GLX_SGIX_swap_group ***/
2566 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2575 /*** GLX_SGIX_swap_barrier ***/
2578 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2586 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2596 /*** GLX_SUN_get_transparent_index ***/
2599 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
, long *pTransparent
)
2604 (void) pTransparent
;
2610 /*** GLX_MESA_release_buffers ***/
2613 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2614 * (a window or pixmap) prior to destroying the GLXDrawable.
2617 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2619 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2621 XMesaDestroyBuffer(b
);
2627 /*** GLX_EXT_texture_from_pixmap ***/
2630 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2631 const int *attrib_list
)
2633 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2635 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2639 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2641 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2643 XMesaReleaseTexImage(dpy
, b
, buffer
);