2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
28 * "Fake" GLX API implemented in terms of the XMesa*() functions.
33 #define GLX_GLXEXT_PROTOTYPES
37 #include <GL/glxproto.h>
42 /* This indicates the client-side GLX API and GLX encoder version. */
43 #define CLIENT_MAJOR_VERSION 1
44 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
46 /* This indicates the server-side GLX decoder version.
47 * GLX 1.4 indicates OpenGL 1.3 support
49 #define SERVER_MAJOR_VERSION 1
50 #define SERVER_MINOR_VERSION 4
52 /* Who implemented this GLX? */
53 #define VENDOR "Brian Paul"
56 "GLX_MESA_copy_sub_buffer " \
57 "GLX_MESA_pixmap_colormap " \
58 "GLX_MESA_release_buffers " \
59 "GLX_ARB_create_context " \
60 "GLX_ARB_create_context_profile " \
61 "GLX_ARB_get_proc_address " \
62 "GLX_EXT_create_context_es_profile " \
63 "GLX_EXT_create_context_es2_profile " \
64 "GLX_EXT_texture_from_pixmap " \
65 "GLX_EXT_visual_info " \
66 "GLX_EXT_visual_rating " \
67 /*"GLX_SGI_video_sync "*/ \
68 "GLX_SGIX_fbconfig " \
71 #define DEFAULT_DIRECT GL_TRUE
74 /** XXX this could be based on gallium's max texture size */
75 #define PBUFFER_MAX_SIZE 16384
79 * The GLXContext typedef is defined as a pointer to this structure.
81 struct __GLXcontextRec
85 GLXDrawable currentDrawable
;
86 GLXDrawable currentReadable
;
89 XMesaContext xmesaContext
;
94 static pipe_tsd ContextTSD
;
96 /** Set current context for calling thread */
98 SetCurrentContext(GLXContext c
)
100 pipe_tsd_set(&ContextTSD
, c
);
103 /** Get current context for calling thread */
105 GetCurrentContext(void)
107 return pipe_tsd_get(&ContextTSD
);
112 /**********************************************************************/
113 /*** GLX Visual Code ***/
114 /**********************************************************************/
119 static XMesaVisual
*VisualTable
= NULL
;
120 static int NumVisuals
= 0;
124 /* Macro to handle c_class vs class field name in XVisualInfo struct */
125 #if defined(__cplusplus) || defined(c_plusplus)
126 #define CLASS c_class
134 * Test if the given XVisualInfo is usable for Mesa rendering.
137 is_usable_visual( XVisualInfo
*vinfo
)
139 switch (vinfo
->CLASS
) {
142 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
146 /* Any StaticColor/PseudoColor visual of at least 4 bits */
147 if (vinfo
->depth
>=4) {
155 /* Any depth of TrueColor or DirectColor works in RGB mode */
158 /* This should never happen */
165 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
166 * configuration in our list of GLX visuals.
169 save_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
,
170 GLboolean rgbFlag
, GLboolean alphaFlag
, GLboolean dbFlag
,
171 GLboolean stereoFlag
,
172 GLint depth_size
, GLint stencil_size
,
173 GLint accumRedSize
, GLint accumGreenSize
,
174 GLint accumBlueSize
, GLint accumAlphaSize
,
175 GLint level
, GLint numAuxBuffers
)
177 GLboolean ximageFlag
= GL_TRUE
;
180 GLboolean comparePointers
;
183 /* Check if the MESA_BACK_BUFFER env var is set */
184 char *backbuffer
= getenv("MESA_BACK_BUFFER");
186 if (backbuffer
[0]=='p' || backbuffer
[0]=='P') {
187 ximageFlag
= GL_FALSE
;
189 else if (backbuffer
[0]=='x' || backbuffer
[0]=='X') {
190 ximageFlag
= GL_TRUE
;
193 _mesa_warning(NULL
, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
199 /* stereo not supported */
203 if (stencil_size
> 0 && depth_size
> 0)
206 /* Comparing IDs uses less memory but sometimes fails. */
207 /* XXX revisit this after 3.0 is finished. */
208 if (getenv("MESA_GLX_VISUAL_HACK"))
209 comparePointers
= GL_TRUE
;
211 comparePointers
= GL_FALSE
;
213 /* Force the visual to have an alpha channel */
214 if (rgbFlag
&& getenv("MESA_GLX_FORCE_ALPHA"))
217 /* First check if a matching visual is already in the list */
218 for (i
=0; i
<NumVisuals
; i
++) {
219 XMesaVisual v
= VisualTable
[i
];
220 if (v
->display
== dpy
221 && v
->mesa_visual
.level
== level
222 && v
->mesa_visual
.numAuxBuffers
== numAuxBuffers
223 && v
->ximage_flag
== ximageFlag
224 && v
->mesa_visual
.rgbMode
== rgbFlag
225 && v
->mesa_visual
.doubleBufferMode
== dbFlag
226 && v
->mesa_visual
.stereoMode
== stereoFlag
227 && (v
->mesa_visual
.alphaBits
> 0) == alphaFlag
228 && (v
->mesa_visual
.depthBits
>= depth_size
|| depth_size
== 0)
229 && (v
->mesa_visual
.stencilBits
>= stencil_size
|| stencil_size
== 0)
230 && (v
->mesa_visual
.accumRedBits
>= accumRedSize
|| accumRedSize
== 0)
231 && (v
->mesa_visual
.accumGreenBits
>= accumGreenSize
|| accumGreenSize
== 0)
232 && (v
->mesa_visual
.accumBlueBits
>= accumBlueSize
|| accumBlueSize
== 0)
233 && (v
->mesa_visual
.accumAlphaBits
>= accumAlphaSize
|| accumAlphaSize
== 0)) {
234 /* now either compare XVisualInfo pointers or visual IDs */
235 if ((!comparePointers
&& v
->visinfo
->visualid
== vinfo
->visualid
)
236 || (comparePointers
&& v
->vishandle
== vinfo
)) {
242 /* Create a new visual and add it to the list. */
244 xmvis
= XMesaCreateVisual( dpy
, vinfo
, rgbFlag
, alphaFlag
, dbFlag
,
245 stereoFlag
, ximageFlag
,
246 depth_size
, stencil_size
,
247 accumRedSize
, accumBlueSize
,
248 accumBlueSize
, accumAlphaSize
, 0, level
,
251 /* Save a copy of the pointer now so we can find this visual again
252 * if we need to search for it in find_glx_visual().
254 xmvis
->vishandle
= vinfo
;
255 /* Allocate more space for additional visual */
256 VisualTable
= realloc(VisualTable
, sizeof(XMesaVisual
) * (NumVisuals
+ 1));
257 /* add xmvis to the list */
258 VisualTable
[NumVisuals
] = xmvis
;
260 /* XXX minor hack, because XMesaCreateVisual doesn't support an
261 * aux buffers parameter.
263 xmvis
->mesa_visual
.numAuxBuffers
= numAuxBuffers
;
270 * Return the default number of bits for the Z buffer.
271 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
272 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
273 * XXX probably do the same thing for stencil, accum, etc.
276 default_depth_bits(void)
279 const char *zEnv
= getenv("MESA_GLX_DEPTH_BITS");
288 default_alpha_bits(void)
291 const char *aEnv
= getenv("MESA_GLX_ALPHA_BITS");
300 default_accum_bits(void)
308 * Create a GLX visual from a regular XVisualInfo.
309 * This is called when Fake GLX is given an XVisualInfo which wasn't
310 * returned by glXChooseVisual. Since this is the first time we're
311 * considering this visual we'll take a guess at reasonable values
312 * for depth buffer size, stencil size, accum size, etc.
313 * This is the best we can do with a client-side emulation of GLX.
316 create_glx_visual( Display
*dpy
, XVisualInfo
*visinfo
)
318 GLint zBits
= default_depth_bits();
319 GLint accBits
= default_accum_bits();
320 GLboolean alphaFlag
= default_alpha_bits() > 0;
322 if (is_usable_visual( visinfo
)) {
323 /* Configure this visual as RGB, double-buffered, depth-buffered. */
324 /* This is surely wrong for some people's needs but what else */
325 /* can be done? They should use glXChooseVisual(). */
326 return save_glx_visual( dpy
, visinfo
,
328 alphaFlag
, /* alpha */
329 GL_TRUE
, /* double */
330 GL_FALSE
, /* stereo */
332 8, /* stencil bits */
342 _mesa_warning(NULL
, "Mesa: error in glXCreateContext: bad visual\n");
350 * Find the GLX visual associated with an XVisualInfo.
353 find_glx_visual( Display
*dpy
, XVisualInfo
*vinfo
)
357 /* try to match visual id */
358 for (i
=0;i
<NumVisuals
;i
++) {
359 if (VisualTable
[i
]->display
==dpy
360 && VisualTable
[i
]->visinfo
->visualid
== vinfo
->visualid
) {
361 return VisualTable
[i
];
365 /* if that fails, try to match pointers */
366 for (i
=0;i
<NumVisuals
;i
++) {
367 if (VisualTable
[i
]->display
==dpy
&& VisualTable
[i
]->vishandle
==vinfo
) {
368 return VisualTable
[i
];
377 * Try to get an X visual which matches the given arguments.
380 get_visual( Display
*dpy
, int scr
, unsigned int depth
, int xclass
)
382 XVisualInfo temp
, *vis
;
385 unsigned int default_depth
;
388 mask
= VisualScreenMask
| VisualDepthMask
| VisualClassMask
;
393 default_depth
= DefaultDepth(dpy
,scr
);
394 default_class
= DefaultVisual(dpy
,scr
)->CLASS
;
396 if (depth
==default_depth
&& xclass
==default_class
) {
397 /* try to get root window's visual */
398 temp
.visualid
= DefaultVisual(dpy
,scr
)->visualid
;
399 mask
|= VisualIDMask
;
402 vis
= XGetVisualInfo( dpy
, mask
, &temp
, &n
);
404 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
405 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
406 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
408 if (vis
&& depth
> 24 && (xclass
==TrueColor
|| xclass
==DirectColor
)) {
409 if (_mesa_bitcount((GLuint
) vis
->red_mask
) <= 8 &&
410 _mesa_bitcount((GLuint
) vis
->green_mask
) <= 8 &&
411 _mesa_bitcount((GLuint
) vis
->blue_mask
) <= 8) {
425 * Retrieve the value of the given environment variable and find
426 * the X visual which matches it.
427 * Input: dpy - the display
428 * screen - the screen number
429 * varname - the name of the environment variable
430 * Return: an XVisualInfo pointer to NULL if error.
433 get_env_visual(Display
*dpy
, int scr
, const char *varname
)
435 char value
[100], type
[100];
436 int depth
, xclass
= -1;
439 if (!getenv( varname
)) {
443 strncpy( value
, getenv(varname
), 100 );
446 sscanf( value
, "%s %d", type
, &depth
);
448 if (strcmp(type
,"TrueColor")==0) xclass
= TrueColor
;
449 else if (strcmp(type
,"DirectColor")==0) xclass
= DirectColor
;
450 else if (strcmp(type
,"PseudoColor")==0) xclass
= PseudoColor
;
451 else if (strcmp(type
,"StaticColor")==0) xclass
= StaticColor
;
452 else if (strcmp(type
,"GrayScale")==0) xclass
= GrayScale
;
453 else if (strcmp(type
,"StaticGray")==0) xclass
= StaticGray
;
455 if (xclass
>-1 && depth
>0) {
456 vis
= get_visual( dpy
, scr
, depth
, xclass
);
462 _mesa_warning(NULL
, "GLX unable to find visual class=%s, depth=%d.",
471 * Select an X visual which satisfies the RGBA flag and minimum depth.
473 * screen - X display and screen number
474 * min_depth - minimum visual depth
475 * preferred_class - preferred GLX visual class or DONT_CARE
476 * Return: pointer to an XVisualInfo or NULL.
479 choose_x_visual( Display
*dpy
, int screen
, int min_depth
,
480 int preferred_class
)
483 int xclass
, visclass
= 0;
486 /* First see if the MESA_RGB_VISUAL env var is defined */
487 vis
= get_env_visual( dpy
, screen
, "MESA_RGB_VISUAL" );
491 /* Otherwise, search for a suitable visual */
492 if (preferred_class
==DONT_CARE
) {
493 for (xclass
=0;xclass
<6;xclass
++) {
495 case 0: visclass
= TrueColor
; break;
496 case 1: visclass
= DirectColor
; break;
497 case 2: visclass
= PseudoColor
; break;
498 case 3: visclass
= StaticColor
; break;
499 case 4: visclass
= GrayScale
; break;
500 case 5: visclass
= StaticGray
; break;
503 /* start with shallowest */
504 for (depth
=0;depth
<=32;depth
++) {
505 if (visclass
==TrueColor
&& depth
==8) {
506 /* Special case: try to get 8-bit PseudoColor before */
507 /* 8-bit TrueColor */
508 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
513 vis
= get_visual( dpy
, screen
, depth
, visclass
);
520 /* start with deepest */
521 for (depth
=32;depth
>=min_depth
;depth
--) {
522 if (visclass
==TrueColor
&& depth
==8) {
523 /* Special case: try to get 8-bit PseudoColor before */
524 /* 8-bit TrueColor */
525 vis
= get_visual( dpy
, screen
, 8, PseudoColor
);
530 vis
= get_visual( dpy
, screen
, depth
, visclass
);
539 /* search for a specific visual class */
540 switch (preferred_class
) {
541 case GLX_TRUE_COLOR_EXT
: visclass
= TrueColor
; break;
542 case GLX_DIRECT_COLOR_EXT
: visclass
= DirectColor
; break;
543 case GLX_PSEUDO_COLOR_EXT
: visclass
= PseudoColor
; break;
544 case GLX_STATIC_COLOR_EXT
: visclass
= StaticColor
; break;
545 case GLX_GRAY_SCALE_EXT
: visclass
= GrayScale
; break;
546 case GLX_STATIC_GRAY_EXT
: visclass
= StaticGray
; break;
547 default: return NULL
;
550 /* start with shallowest */
551 for (depth
=0;depth
<=32;depth
++) {
552 vis
= get_visual( dpy
, screen
, depth
, visclass
);
559 /* start with deepest */
560 for (depth
=32;depth
>=min_depth
;depth
--) {
561 vis
= get_visual( dpy
, screen
, depth
, visclass
);
569 /* didn't find a visual */
576 /**********************************************************************/
577 /*** Display-related functions ***/
578 /**********************************************************************/
582 * Free all XMesaVisuals which are associated with the given display.
585 destroy_visuals_on_display(Display
*dpy
)
588 for (i
= 0; i
< NumVisuals
; i
++) {
589 if (VisualTable
[i
]->display
== dpy
) {
590 /* remove this visual */
592 free(VisualTable
[i
]);
593 for (j
= i
; j
< NumVisuals
- 1; j
++)
594 VisualTable
[j
] = VisualTable
[j
+ 1];
602 * Called from XCloseDisplay() to let us free our display-related data.
605 close_display_callback(Display
*dpy
, XExtCodes
*codes
)
607 xmesa_destroy_buffers_on_display(dpy
);
608 destroy_visuals_on_display(dpy
);
614 * Look for the named extension on given display and return a pointer
615 * to the _XExtension data, or NULL if extension not found.
618 lookup_extension(Display
*dpy
, const char *extName
)
621 for (ext
= dpy
->ext_procs
; ext
; ext
= ext
->next
) {
622 if (ext
->name
&& strcmp(ext
->name
, extName
) == 0) {
631 * Whenever we're given a new Display pointer, call this function to
632 * register our close_display_callback function.
635 register_with_display(Display
*dpy
)
637 const char *extName
= "MesaGLX";
640 ext
= lookup_extension(dpy
, extName
);
642 XExtCodes
*c
= XAddExtension(dpy
);
643 ext
= dpy
->ext_procs
; /* new extension is at head of list */
644 assert(c
->extension
== ext
->codes
.extension
);
646 ext
->name
= _mesa_strdup(extName
);
647 ext
->close_display
= close_display_callback
;
656 generate_error(Display
*dpy
,
657 unsigned char error_code
,
659 unsigned char minor_code
,
662 XErrorHandler handler
;
668 handler
= XSetErrorHandler(NULL
);
669 XSetErrorHandler(handler
);
674 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_opcode
, &first_event
, &first_error
)) {
681 error_code
+= first_error
;
684 memset(&event
, 0, sizeof event
);
686 event
.xerror
.type
= X_Error
;
687 event
.xerror
.display
= dpy
;
688 event
.xerror
.resourceid
= resourceid
;
689 event
.xerror
.serial
= NextRequest(dpy
) - 1;
690 event
.xerror
.error_code
= error_code
;
691 event
.xerror
.request_code
= major_opcode
;
692 event
.xerror
.minor_code
= minor_code
;
694 return handler(dpy
, &event
.xerror
);
698 /**********************************************************************/
699 /*** Begin Fake GLX API Functions ***/
700 /**********************************************************************/
704 * Helper used by glXChooseVisual and glXChooseFBConfig.
705 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
707 * In either case, the attribute list is terminated with the value 'None'.
710 choose_visual( Display
*dpy
, int screen
, const int *list
, GLboolean fbConfig
)
712 const GLboolean rgbModeDefault
= fbConfig
;
713 const int *parselist
;
715 int min_red
=0, min_green
=0, min_blue
=0;
716 GLboolean rgb_flag
= rgbModeDefault
;
717 GLboolean alpha_flag
= GL_FALSE
;
718 GLboolean double_flag
= GL_FALSE
;
719 GLboolean stereo_flag
= GL_FALSE
;
720 GLint depth_size
= 0;
721 GLint stencil_size
= 0;
722 GLint accumRedSize
= 0;
723 GLint accumGreenSize
= 0;
724 GLint accumBlueSize
= 0;
725 GLint accumAlphaSize
= 0;
727 int visual_type
= DONT_CARE
;
728 GLint caveat
= DONT_CARE
;
729 XMesaVisual xmvis
= NULL
;
730 int desiredVisualID
= -1;
740 parselist
[1] == GLX_DONT_CARE
&&
741 parselist
[0] != GLX_LEVEL
) {
742 /* For glXChooseFBConfig(), skip attributes whose value is
743 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
746 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
747 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
753 switch (*parselist
) {
764 case GLX_BUFFER_SIZE
:
770 level
= *parselist
++;
782 case GLX_DOUBLEBUFFER
:
785 double_flag
= *parselist
++;
788 double_flag
= GL_TRUE
;
794 stereo_flag
= *parselist
++;
797 stereo_flag
= GL_TRUE
;
800 case GLX_AUX_BUFFERS
:
802 numAux
= *parselist
++;
803 if (numAux
> MAX_AUX_BUFFERS
)
808 min_red
= *parselist
++;
812 min_green
= *parselist
++;
816 min_blue
= *parselist
++;
821 GLint size
= *parselist
++;
822 alpha_flag
= size
? GL_TRUE
: GL_FALSE
;
827 depth_size
= *parselist
++;
829 case GLX_STENCIL_SIZE
:
831 stencil_size
= *parselist
++;
833 case GLX_ACCUM_RED_SIZE
:
836 GLint size
= *parselist
++;
837 accumRedSize
= MAX2( accumRedSize
, size
);
840 case GLX_ACCUM_GREEN_SIZE
:
843 GLint size
= *parselist
++;
844 accumGreenSize
= MAX2( accumGreenSize
, size
);
847 case GLX_ACCUM_BLUE_SIZE
:
850 GLint size
= *parselist
++;
851 accumBlueSize
= MAX2( accumBlueSize
, size
);
854 case GLX_ACCUM_ALPHA_SIZE
:
857 GLint size
= *parselist
++;
858 accumAlphaSize
= MAX2( accumAlphaSize
, size
);
863 * GLX_EXT_visual_info extension
865 case GLX_X_VISUAL_TYPE_EXT
:
867 visual_type
= *parselist
++;
869 case GLX_TRANSPARENT_TYPE_EXT
:
873 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
877 case GLX_TRANSPARENT_RED_VALUE_EXT
:
878 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
879 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
880 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
887 * GLX_EXT_visual_info extension
889 case GLX_VISUAL_CAVEAT_EXT
:
891 caveat
= *parselist
++; /* ignored for now */
895 * GLX_ARB_multisample
897 case GLX_SAMPLE_BUFFERS_ARB
:
898 case GLX_SAMPLES_ARB
:
900 if (*parselist
++ != 0) {
901 /* ms not supported */
909 case GLX_RENDER_TYPE
:
913 if (*parselist
& GLX_RGBA_BIT
) {
916 else if (*parselist
& GLX_COLOR_INDEX_BIT
) {
919 else if (*parselist
== 0) {
924 case GLX_DRAWABLE_TYPE
:
928 if (*parselist
& ~(GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
)) {
929 return NULL
; /* bad bit */
933 case GLX_FBCONFIG_ID
:
938 desiredVisualID
= *parselist
++;
940 case GLX_X_RENDERABLE
:
941 case GLX_MAX_PBUFFER_WIDTH
:
942 case GLX_MAX_PBUFFER_HEIGHT
:
943 case GLX_MAX_PBUFFER_PIXELS
:
945 return NULL
; /* invalid config option */
946 parselist
+= 2; /* ignore the parameter */
949 #ifdef GLX_EXT_texture_from_pixmap
950 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
951 parselist
++; /*skip*/
953 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
954 parselist
++; /*skip*/
956 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
957 parselist
++; /*skip*/
959 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
961 if (*parselist
& ~(GLX_TEXTURE_1D_BIT_EXT
|
962 GLX_TEXTURE_2D_BIT_EXT
|
963 GLX_TEXTURE_RECTANGLE_BIT_EXT
)) {
968 case GLX_Y_INVERTED_EXT
:
969 parselist
++; /*skip*/
978 /* undefined attribute */
979 _mesa_warning(NULL
, "unexpected attrib 0x%x in choose_visual()",
989 * Since we're only simulating the GLX extension this function will never
990 * find any real GL visuals. Instead, all we can do is try to find an RGB
991 * or CI visual of appropriate depth. Other requested attributes such as
992 * double buffering, depth buffer, etc. will be associated with the X
993 * visual and stored in the VisualTable[].
995 if (desiredVisualID
!= -1) {
996 /* try to get a specific visual, by visualID */
999 temp
.visualid
= desiredVisualID
;
1000 temp
.screen
= screen
;
1001 vis
= XGetVisualInfo(dpy
, VisualIDMask
| VisualScreenMask
, &temp
, &n
);
1003 /* give the visual some useful GLX attributes */
1004 double_flag
= GL_TRUE
;
1008 else if (level
==0) {
1009 /* normal color planes */
1010 /* Get an RGB visual */
1011 int min_rgb
= min_red
+ min_green
+ min_blue
;
1012 if (min_rgb
>1 && min_rgb
<8) {
1013 /* a special case to be sure we can get a monochrome visual */
1016 vis
= choose_x_visual( dpy
, screen
, min_rgb
, visual_type
);
1019 _mesa_warning(NULL
, "overlay not supported");
1024 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1025 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1026 * largest depth buffer size, which is 32bits/value. Instead, we
1027 * return 16 to maintain performance with earlier versions of Mesa.
1029 if (stencil_size
> 0)
1030 depth_size
= 24; /* if Z and stencil, always use 24+8 format */
1031 else if (depth_size
> 24)
1033 else if (depth_size
> 16)
1035 else if (depth_size
> 0) {
1036 depth_size
= default_depth_bits();
1040 alpha_flag
= default_alpha_bits() > 0;
1043 /* we only support one size of stencil and accum buffers. */
1044 if (stencil_size
> 0)
1047 if (accumRedSize
> 0 ||
1048 accumGreenSize
> 0 ||
1049 accumBlueSize
> 0 ||
1050 accumAlphaSize
> 0) {
1054 accumBlueSize
= default_accum_bits();
1056 accumAlphaSize
= alpha_flag
? accumRedSize
: 0;
1059 xmvis
= save_glx_visual( dpy
, vis
, rgb_flag
, alpha_flag
, double_flag
,
1060 stereo_flag
, depth_size
, stencil_size
,
1061 accumRedSize
, accumGreenSize
,
1062 accumBlueSize
, accumAlphaSize
, level
, numAux
);
1069 PUBLIC XVisualInfo
*
1070 glXChooseVisual( Display
*dpy
, int screen
, int *list
)
1074 /* register ourselves as an extension on this display */
1075 register_with_display(dpy
);
1077 xmvis
= choose_visual(dpy
, screen
, list
, GL_FALSE
);
1079 /* create a new vishandle - the cached one may be stale */
1080 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1081 if (xmvis
->vishandle
) {
1082 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1084 return xmvis
->vishandle
;
1092 * Helper function used by other glXCreateContext functions.
1095 create_context(Display
*dpy
, XMesaVisual xmvis
,
1096 XMesaContext shareCtx
, Bool direct
,
1097 unsigned major
, unsigned minor
,
1098 unsigned profileMask
, unsigned contextFlags
)
1105 glxCtx
= CALLOC_STRUCT(__GLXcontextRec
);
1109 /* deallocate unused windows/buffers */
1111 XMesaGarbageCollect();
1114 glxCtx
->xmesaContext
= XMesaCreateContext(xmvis
, shareCtx
, major
, minor
,
1115 profileMask
, contextFlags
);
1116 if (!glxCtx
->xmesaContext
) {
1121 glxCtx
->isDirect
= DEFAULT_DIRECT
;
1122 glxCtx
->currentDpy
= dpy
;
1123 glxCtx
->xid
= (XID
) glxCtx
; /* self pointer */
1130 glXCreateContext( Display
*dpy
, XVisualInfo
*visinfo
,
1131 GLXContext shareCtx
, Bool direct
)
1135 xmvis
= find_glx_visual( dpy
, visinfo
);
1137 /* This visual wasn't found with glXChooseVisual() */
1138 xmvis
= create_glx_visual( dpy
, visinfo
);
1140 /* unusable visual */
1145 return create_context(dpy
, xmvis
,
1146 shareCtx
? shareCtx
->xmesaContext
: NULL
,
1148 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
1152 /* XXX these may have to be removed due to thread-safety issues. */
1153 static GLXContext MakeCurrent_PrevContext
= 0;
1154 static GLXDrawable MakeCurrent_PrevDrawable
= 0;
1155 static GLXDrawable MakeCurrent_PrevReadable
= 0;
1156 static XMesaBuffer MakeCurrent_PrevDrawBuffer
= 0;
1157 static XMesaBuffer MakeCurrent_PrevReadBuffer
= 0;
1160 /* GLX 1.3 and later */
1162 glXMakeContextCurrent( Display
*dpy
, GLXDrawable draw
,
1163 GLXDrawable read
, GLXContext ctx
)
1165 GLXContext glxCtx
= ctx
;
1166 static boolean firsttime
= 1, no_rast
= 0;
1169 no_rast
= getenv("SP_NO_RAST") != NULL
;
1173 if (ctx
&& draw
&& read
) {
1174 XMesaBuffer drawBuffer
, readBuffer
;
1175 XMesaContext xmctx
= glxCtx
->xmesaContext
;
1177 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1178 if (ctx
== MakeCurrent_PrevContext
1179 && draw
== MakeCurrent_PrevDrawable
) {
1180 drawBuffer
= MakeCurrent_PrevDrawBuffer
;
1183 drawBuffer
= XMesaFindBuffer( dpy
, draw
);
1186 /* drawable must be a new window! */
1187 drawBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, draw
);
1189 /* Out of memory, or context/drawable depth mismatch */
1194 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1195 if (ctx
== MakeCurrent_PrevContext
1196 && read
== MakeCurrent_PrevReadable
) {
1197 readBuffer
= MakeCurrent_PrevReadBuffer
;
1200 readBuffer
= XMesaFindBuffer( dpy
, read
);
1203 /* drawable must be a new window! */
1204 readBuffer
= XMesaCreateWindowBuffer( xmctx
->xm_visual
, read
);
1206 /* Out of memory, or context/drawable depth mismatch */
1212 MakeCurrent_PrevContext
== ctx
&&
1213 MakeCurrent_PrevDrawable
== draw
&&
1214 MakeCurrent_PrevReadable
== read
&&
1215 MakeCurrent_PrevDrawBuffer
== drawBuffer
&&
1216 MakeCurrent_PrevReadBuffer
== readBuffer
)
1219 MakeCurrent_PrevContext
= ctx
;
1220 MakeCurrent_PrevDrawable
= draw
;
1221 MakeCurrent_PrevReadable
= read
;
1222 MakeCurrent_PrevDrawBuffer
= drawBuffer
;
1223 MakeCurrent_PrevReadBuffer
= readBuffer
;
1225 /* Now make current! */
1226 if (XMesaMakeCurrent2(xmctx
, drawBuffer
, readBuffer
)) {
1227 ctx
->currentDpy
= dpy
;
1228 ctx
->currentDrawable
= draw
;
1229 ctx
->currentReadable
= read
;
1230 SetCurrentContext(ctx
);
1237 else if (!ctx
&& !draw
&& !read
) {
1238 /* release current context w/out assigning new one. */
1239 XMesaMakeCurrent2( NULL
, NULL
, NULL
);
1240 MakeCurrent_PrevContext
= 0;
1241 MakeCurrent_PrevDrawable
= 0;
1242 MakeCurrent_PrevReadable
= 0;
1243 MakeCurrent_PrevDrawBuffer
= 0;
1244 MakeCurrent_PrevReadBuffer
= 0;
1245 SetCurrentContext(NULL
);
1249 /* The args must either all be non-zero or all zero.
1258 glXMakeCurrent( Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
1260 return glXMakeContextCurrent( dpy
, drawable
, drawable
, ctx
);
1265 glXGetCurrentContext(void)
1267 return GetCurrentContext();
1272 glXGetCurrentDisplay(void)
1274 GLXContext glxCtx
= glXGetCurrentContext();
1276 return glxCtx
? glxCtx
->currentDpy
: NULL
;
1281 glXGetCurrentDisplayEXT(void)
1283 return glXGetCurrentDisplay();
1288 glXGetCurrentDrawable(void)
1290 GLXContext gc
= glXGetCurrentContext();
1291 return gc
? gc
->currentDrawable
: 0;
1296 glXGetCurrentReadDrawable(void)
1298 GLXContext gc
= glXGetCurrentContext();
1299 return gc
? gc
->currentReadable
: 0;
1304 glXGetCurrentReadDrawableSGI(void)
1306 return glXGetCurrentReadDrawable();
1311 glXCreateGLXPixmap( Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
1316 v
= find_glx_visual( dpy
, visinfo
);
1318 v
= create_glx_visual( dpy
, visinfo
);
1320 /* unusable visual */
1325 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
1329 return b
->ws
.drawable
;
1333 /*** GLX_MESA_pixmap_colormap ***/
1336 glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visinfo
,
1337 Pixmap pixmap
, Colormap cmap
)
1342 v
= find_glx_visual( dpy
, visinfo
);
1344 v
= create_glx_visual( dpy
, visinfo
);
1346 /* unusable visual */
1351 b
= XMesaCreatePixmapBuffer( v
, pixmap
, cmap
);
1355 return b
->ws
.drawable
;
1360 glXDestroyGLXPixmap( Display
*dpy
, GLXPixmap pixmap
)
1362 XMesaBuffer b
= XMesaFindBuffer(dpy
, pixmap
);
1364 XMesaDestroyBuffer(b
);
1366 else if (getenv("MESA_DEBUG")) {
1367 _mesa_warning(NULL
, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1373 glXCopyContext( Display
*dpy
, GLXContext src
, GLXContext dst
,
1374 unsigned long mask
)
1376 XMesaContext xm_src
= src
->xmesaContext
;
1377 XMesaContext xm_dst
= dst
->xmesaContext
;
1379 if (MakeCurrent_PrevContext
== src
) {
1382 XMesaCopyContext(xm_src
, xm_dst
, mask
);
1387 glXQueryExtension( Display
*dpy
, int *errorBase
, int *eventBase
)
1390 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1391 if (!XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &op
, &ev
, &err
))
1397 return True
; /* we're faking GLX so always return success */
1402 glXDestroyContext( Display
*dpy
, GLXContext ctx
)
1405 GLXContext glxCtx
= ctx
;
1407 MakeCurrent_PrevContext
= 0;
1408 MakeCurrent_PrevDrawable
= 0;
1409 MakeCurrent_PrevReadable
= 0;
1410 MakeCurrent_PrevDrawBuffer
= 0;
1411 MakeCurrent_PrevReadBuffer
= 0;
1412 XMesaDestroyContext( glxCtx
->xmesaContext
);
1413 XMesaGarbageCollect();
1420 glXIsDirect( Display
*dpy
, GLXContext ctx
)
1422 return ctx
? ctx
->isDirect
: False
;
1428 glXSwapBuffers( Display
*dpy
, GLXDrawable drawable
)
1430 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1431 static boolean firsttime
= 1, no_rast
= 0;
1434 no_rast
= getenv("SP_NO_RAST") != NULL
;
1442 XMesaSwapBuffers(buffer
);
1444 else if (getenv("MESA_DEBUG")) {
1445 _mesa_warning(NULL
, "glXSwapBuffers: invalid drawable 0x%x\n",
1452 /*** GLX_MESA_copy_sub_buffer ***/
1455 glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
1456 int x
, int y
, int width
, int height
)
1458 XMesaBuffer buffer
= XMesaFindBuffer( dpy
, drawable
);
1460 XMesaCopySubBuffer(buffer
, x
, y
, width
, height
);
1462 else if (getenv("MESA_DEBUG")) {
1463 _mesa_warning(NULL
, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1469 glXQueryVersion( Display
*dpy
, int *maj
, int *min
)
1472 /* Return GLX version, not Mesa version */
1473 assert(CLIENT_MAJOR_VERSION
== SERVER_MAJOR_VERSION
);
1474 *maj
= CLIENT_MAJOR_VERSION
;
1475 *min
= MIN2( CLIENT_MINOR_VERSION
, SERVER_MINOR_VERSION
);
1481 * Query the GLX attributes of the given XVisualInfo.
1484 get_config( XMesaVisual xmvis
, int attrib
, int *value
, GLboolean fbconfig
)
1490 return GLX_BAD_ATTRIBUTE
;
1491 *value
= (int) True
;
1493 case GLX_BUFFER_SIZE
:
1494 *value
= xmvis
->visinfo
->depth
;
1497 *value
= xmvis
->mesa_visual
.level
;
1501 return GLX_BAD_ATTRIBUTE
;
1502 if (xmvis
->mesa_visual
.rgbMode
) {
1509 case GLX_DOUBLEBUFFER
:
1510 *value
= (int) xmvis
->mesa_visual
.doubleBufferMode
;
1513 *value
= (int) xmvis
->mesa_visual
.stereoMode
;
1515 case GLX_AUX_BUFFERS
:
1516 *value
= xmvis
->mesa_visual
.numAuxBuffers
;
1519 *value
= xmvis
->mesa_visual
.redBits
;
1521 case GLX_GREEN_SIZE
:
1522 *value
= xmvis
->mesa_visual
.greenBits
;
1525 *value
= xmvis
->mesa_visual
.blueBits
;
1527 case GLX_ALPHA_SIZE
:
1528 *value
= xmvis
->mesa_visual
.alphaBits
;
1530 case GLX_DEPTH_SIZE
:
1531 *value
= xmvis
->mesa_visual
.depthBits
;
1533 case GLX_STENCIL_SIZE
:
1534 *value
= xmvis
->mesa_visual
.stencilBits
;
1536 case GLX_ACCUM_RED_SIZE
:
1537 *value
= xmvis
->mesa_visual
.accumRedBits
;
1539 case GLX_ACCUM_GREEN_SIZE
:
1540 *value
= xmvis
->mesa_visual
.accumGreenBits
;
1542 case GLX_ACCUM_BLUE_SIZE
:
1543 *value
= xmvis
->mesa_visual
.accumBlueBits
;
1545 case GLX_ACCUM_ALPHA_SIZE
:
1546 *value
= xmvis
->mesa_visual
.accumAlphaBits
;
1550 * GLX_EXT_visual_info extension
1552 case GLX_X_VISUAL_TYPE_EXT
:
1553 switch (xmvis
->visinfo
->CLASS
) {
1554 case StaticGray
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1555 case GrayScale
: *value
= GLX_GRAY_SCALE_EXT
; return 0;
1556 case StaticColor
: *value
= GLX_STATIC_GRAY_EXT
; return 0;
1557 case PseudoColor
: *value
= GLX_PSEUDO_COLOR_EXT
; return 0;
1558 case TrueColor
: *value
= GLX_TRUE_COLOR_EXT
; return 0;
1559 case DirectColor
: *value
= GLX_DIRECT_COLOR_EXT
; return 0;
1562 case GLX_TRANSPARENT_TYPE_EXT
:
1564 *value
= GLX_NONE_EXT
;
1566 case GLX_TRANSPARENT_INDEX_VALUE_EXT
:
1569 case GLX_TRANSPARENT_RED_VALUE_EXT
:
1572 case GLX_TRANSPARENT_GREEN_VALUE_EXT
:
1575 case GLX_TRANSPARENT_BLUE_VALUE_EXT
:
1578 case GLX_TRANSPARENT_ALPHA_VALUE_EXT
:
1583 * GLX_EXT_visual_info extension
1585 case GLX_VISUAL_CAVEAT_EXT
:
1586 /* test for zero, just in case */
1587 if (xmvis
->mesa_visual
.visualRating
> 0)
1588 *value
= xmvis
->mesa_visual
.visualRating
;
1590 *value
= GLX_NONE_EXT
;
1594 * GLX_ARB_multisample
1596 case GLX_SAMPLE_BUFFERS_ARB
:
1599 case GLX_SAMPLES_ARB
:
1606 case GLX_SCREEN_EXT
:
1608 return GLX_BAD_ATTRIBUTE
;
1609 *value
= xmvis
->visinfo
->screen
;
1611 case GLX_DRAWABLE_TYPE
: /*SGIX too */
1613 return GLX_BAD_ATTRIBUTE
;
1614 *value
= GLX_WINDOW_BIT
| GLX_PIXMAP_BIT
| GLX_PBUFFER_BIT
;
1616 case GLX_RENDER_TYPE_SGIX
:
1618 return GLX_BAD_ATTRIBUTE
;
1619 if (xmvis
->mesa_visual
.rgbMode
)
1620 *value
= GLX_RGBA_BIT
;
1622 *value
= GLX_COLOR_INDEX_BIT
;
1624 case GLX_X_RENDERABLE_SGIX
:
1626 return GLX_BAD_ATTRIBUTE
;
1627 *value
= True
; /* XXX really? */
1629 case GLX_FBCONFIG_ID_SGIX
:
1631 return GLX_BAD_ATTRIBUTE
;
1632 *value
= xmvis
->visinfo
->visualid
;
1634 case GLX_MAX_PBUFFER_WIDTH
:
1636 return GLX_BAD_ATTRIBUTE
;
1637 /* XXX or MAX_WIDTH? */
1638 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
);
1640 case GLX_MAX_PBUFFER_HEIGHT
:
1642 return GLX_BAD_ATTRIBUTE
;
1643 *value
= DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1645 case GLX_MAX_PBUFFER_PIXELS
:
1647 return GLX_BAD_ATTRIBUTE
;
1648 *value
= DisplayWidth(xmvis
->display
, xmvis
->visinfo
->screen
) *
1649 DisplayHeight(xmvis
->display
, xmvis
->visinfo
->screen
);
1653 return GLX_BAD_ATTRIBUTE
;
1654 *value
= xmvis
->visinfo
->visualid
;
1657 #ifdef GLX_EXT_texture_from_pixmap
1658 case GLX_BIND_TO_TEXTURE_RGB_EXT
:
1659 *value
= True
; /*XXX*/
1661 case GLX_BIND_TO_TEXTURE_RGBA_EXT
:
1663 *value
= xmvis
->mesa_visual
.alphaBits
> 0 ? True
: False
;
1665 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT
:
1666 *value
= True
; /*XXX*/
1668 case GLX_BIND_TO_TEXTURE_TARGETS_EXT
:
1669 *value
= (GLX_TEXTURE_1D_BIT_EXT
|
1670 GLX_TEXTURE_2D_BIT_EXT
|
1671 GLX_TEXTURE_RECTANGLE_BIT_EXT
); /*XXX*/
1673 case GLX_Y_INVERTED_EXT
:
1674 *value
= True
; /*XXX*/
1679 return GLX_BAD_ATTRIBUTE
;
1686 glXGetConfig( Display
*dpy
, XVisualInfo
*visinfo
,
1687 int attrib
, int *value
)
1691 if (!dpy
|| !visinfo
)
1692 return GLX_BAD_ATTRIBUTE
;
1694 xmvis
= find_glx_visual( dpy
, visinfo
);
1696 /* this visual wasn't obtained with glXChooseVisual */
1697 xmvis
= create_glx_visual( dpy
, visinfo
);
1699 /* this visual can't be used for GL rendering */
1700 if (attrib
==GLX_USE_GL
) {
1701 *value
= (int) False
;
1705 return GLX_BAD_VISUAL
;
1710 k
= get_config(xmvis
, attrib
, value
, GL_FALSE
);
1718 XMesaContext xmesa
= XMesaGetCurrentContext();
1719 XMesaFlush( xmesa
);
1727 XMesaContext xmesa
= XMesaGetCurrentContext();
1728 XMesaFlush( xmesa
);
1733 get_extensions( void )
1740 /* GLX 1.1 and later */
1742 glXQueryExtensionsString( Display
*dpy
, int screen
)
1746 return get_extensions();
1751 /* GLX 1.1 and later */
1753 glXQueryServerString( Display
*dpy
, int screen
, int name
)
1755 static char version
[1000];
1756 sprintf(version
, "%d.%d %s",
1757 SERVER_MAJOR_VERSION
, SERVER_MINOR_VERSION
, xmesa_get_name());
1763 case GLX_EXTENSIONS
:
1764 return get_extensions();
1776 /* GLX 1.1 and later */
1778 glXGetClientString( Display
*dpy
, int name
)
1780 static char version
[1000];
1781 sprintf(version
, "%d.%d %s", CLIENT_MAJOR_VERSION
,
1782 CLIENT_MINOR_VERSION
, xmesa_get_name());
1787 case GLX_EXTENSIONS
:
1788 return get_extensions();
1806 glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1807 int attribute
, int *value
)
1809 XMesaVisual v
= (XMesaVisual
) config
;
1813 if (!dpy
|| !config
|| !value
)
1816 return get_config(v
, attribute
, value
, GL_TRUE
);
1820 PUBLIC GLXFBConfig
*
1821 glXGetFBConfigs( Display
*dpy
, int screen
, int *nelements
)
1823 XVisualInfo
*visuals
, visTemplate
;
1824 const long visMask
= VisualScreenMask
;
1827 /* Get list of all X visuals */
1828 visTemplate
.screen
= screen
;
1829 visuals
= XGetVisualInfo(dpy
, visMask
, &visTemplate
, nelements
);
1830 if (*nelements
> 0) {
1831 XMesaVisual
*results
= malloc(*nelements
* sizeof(XMesaVisual
));
1836 for (i
= 0; i
< *nelements
; i
++) {
1837 results
[i
] = create_glx_visual(dpy
, visuals
+ i
);
1843 return (GLXFBConfig
*) results
;
1849 PUBLIC GLXFBConfig
*
1850 glXChooseFBConfig(Display
*dpy
, int screen
,
1851 const int *attribList
, int *nitems
)
1855 /* register ourselves as an extension on this display */
1856 register_with_display(dpy
);
1858 if (!attribList
|| !attribList
[0]) {
1859 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1860 return glXGetFBConfigs(dpy
, screen
, nitems
);
1863 xmvis
= choose_visual(dpy
, screen
, attribList
, GL_TRUE
);
1865 GLXFBConfig
*config
= malloc(sizeof(XMesaVisual
));
1871 config
[0] = (GLXFBConfig
) xmvis
;
1872 return (GLXFBConfig
*) config
;
1881 PUBLIC XVisualInfo
*
1882 glXGetVisualFromFBConfig( Display
*dpy
, GLXFBConfig config
)
1884 if (dpy
&& config
) {
1885 XMesaVisual xmvis
= (XMesaVisual
) config
;
1887 return xmvis
->vishandle
;
1889 /* create a new vishandle - the cached one may be stale */
1890 xmvis
->vishandle
= malloc(sizeof(XVisualInfo
));
1891 if (xmvis
->vishandle
) {
1892 memcpy(xmvis
->vishandle
, xmvis
->visinfo
, sizeof(XVisualInfo
));
1894 return xmvis
->vishandle
;
1904 glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
,
1905 const int *attribList
)
1907 XMesaVisual xmvis
= (XMesaVisual
) config
;
1912 xmbuf
= XMesaCreateWindowBuffer(xmvis
, win
);
1917 (void) attribList
; /* Ignored in GLX 1.3 */
1919 return win
; /* A hack for now */
1924 glXDestroyWindow( Display
*dpy
, GLXWindow window
)
1926 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
) window
);
1928 XMesaDestroyBuffer(b
);
1929 /* don't destroy X window */
1935 glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
,
1936 const int *attribList
)
1938 XMesaVisual v
= (XMesaVisual
) config
;
1941 int target
= 0, format
= 0, mipmap
= 0;
1944 if (!dpy
|| !config
|| !pixmap
)
1947 for (attr
= attribList
; attr
&& *attr
; attr
++) {
1949 case GLX_TEXTURE_FORMAT_EXT
:
1952 case GLX_TEXTURE_FORMAT_NONE_EXT
:
1953 case GLX_TEXTURE_FORMAT_RGB_EXT
:
1954 case GLX_TEXTURE_FORMAT_RGBA_EXT
:
1962 case GLX_TEXTURE_TARGET_EXT
:
1965 case GLX_TEXTURE_1D_EXT
:
1966 case GLX_TEXTURE_2D_EXT
:
1967 case GLX_TEXTURE_RECTANGLE_EXT
:
1975 case GLX_MIPMAP_TEXTURE_EXT
:
1986 if (format
== GLX_TEXTURE_FORMAT_RGB_EXT
) {
1987 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGB_EXT
,
1988 &value
, GL_TRUE
) != Success
1990 return 0; /* error! */
1993 else if (format
== GLX_TEXTURE_FORMAT_RGBA_EXT
) {
1994 if (get_config(v
, GLX_BIND_TO_TEXTURE_RGBA_EXT
,
1995 &value
, GL_TRUE
) != Success
1997 return 0; /* error! */
2001 if (get_config(v
, GLX_BIND_TO_MIPMAP_TEXTURE_EXT
,
2002 &value
, GL_TRUE
) != Success
2004 return 0; /* error! */
2007 if (target
== GLX_TEXTURE_1D_EXT
) {
2008 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2009 &value
, GL_TRUE
) != Success
2010 || (value
& GLX_TEXTURE_1D_BIT_EXT
) == 0) {
2011 return 0; /* error! */
2014 else if (target
== GLX_TEXTURE_2D_EXT
) {
2015 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2016 &value
, GL_TRUE
) != Success
2017 || (value
& GLX_TEXTURE_2D_BIT_EXT
) == 0) {
2018 return 0; /* error! */
2021 if (target
== GLX_TEXTURE_RECTANGLE_EXT
) {
2022 if (get_config(v
, GLX_BIND_TO_TEXTURE_TARGETS_EXT
,
2023 &value
, GL_TRUE
) != Success
2024 || (value
& GLX_TEXTURE_RECTANGLE_BIT_EXT
) == 0) {
2025 return 0; /* error! */
2029 if (format
|| target
|| mipmap
) {
2030 /* texture from pixmap */
2031 b
= XMesaCreatePixmapTextureBuffer(v
, pixmap
, 0, format
, target
, mipmap
);
2034 b
= XMesaCreatePixmapBuffer( v
, pixmap
, 0 );
2045 glXDestroyPixmap( Display
*dpy
, GLXPixmap pixmap
)
2047 XMesaBuffer b
= XMesaFindBuffer(dpy
, (Drawable
)pixmap
);
2049 XMesaDestroyBuffer(b
);
2050 /* don't destroy X pixmap */
2055 glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
2057 XMesaVisual xmvis
= (XMesaVisual
) config
;
2060 int width
= 0, height
= 0;
2061 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2065 for (attrib
= attribList
; *attrib
; attrib
++) {
2067 case GLX_PBUFFER_WIDTH
:
2071 case GLX_PBUFFER_HEIGHT
:
2075 case GLX_PRESERVED_CONTENTS
:
2077 preserveContents
= *attrib
;
2079 case GLX_LARGEST_PBUFFER
:
2081 useLargest
= *attrib
;
2088 if (width
== 0 || height
== 0)
2091 if (width
> PBUFFER_MAX_SIZE
|| height
> PBUFFER_MAX_SIZE
) {
2092 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2093 * allocate the largest possible buffer.
2096 width
= PBUFFER_MAX_SIZE
;
2097 height
= PBUFFER_MAX_SIZE
;
2101 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2102 /* A GLXPbuffer handle must be an X Drawable because that's what
2103 * glXMakeCurrent takes.
2106 xmbuf
->largestPbuffer
= useLargest
;
2107 xmbuf
->preservedContents
= preserveContents
;
2108 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2117 glXDestroyPbuffer( Display
*dpy
, GLXPbuffer pbuf
)
2119 XMesaBuffer b
= XMesaFindBuffer(dpy
, pbuf
);
2121 XMesaDestroyBuffer(b
);
2127 glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
,
2128 unsigned int *value
)
2130 GLuint width
, height
;
2131 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, draw
);
2133 generate_error(dpy
, GLXBadDrawable
, draw
, X_GLXGetDrawableAttributes
, False
);
2137 /* make sure buffer's dimensions are up to date */
2138 xmesa_get_window_size(dpy
, xmbuf
, &width
, &height
);
2140 switch (attribute
) {
2147 case GLX_PRESERVED_CONTENTS
:
2148 *value
= xmbuf
->preservedContents
;
2150 case GLX_LARGEST_PBUFFER
:
2151 *value
= xmbuf
->largestPbuffer
;
2153 case GLX_FBCONFIG_ID
:
2154 *value
= xmbuf
->xm_visual
->visinfo
->visualid
;
2156 #ifdef GLX_EXT_texture_from_pixmap
2157 case GLX_TEXTURE_FORMAT_EXT
:
2158 *value
= xmbuf
->TextureFormat
;
2160 case GLX_TEXTURE_TARGET_EXT
:
2161 *value
= xmbuf
->TextureTarget
;
2163 case GLX_MIPMAP_TEXTURE_EXT
:
2164 *value
= xmbuf
->TextureMipmap
;
2169 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAtrribsARB
, true);
2176 glXCreateNewContext( Display
*dpy
, GLXFBConfig config
,
2177 int renderType
, GLXContext shareCtx
, Bool direct
)
2179 XMesaVisual xmvis
= (XMesaVisual
) config
;
2181 if (!dpy
|| !config
||
2182 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2185 return create_context(dpy
, xmvis
,
2186 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2188 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2193 glXQueryContext( Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
2195 GLXContext glxCtx
= ctx
;
2196 XMesaContext xmctx
= glxCtx
->xmesaContext
;
2201 switch (attribute
) {
2202 case GLX_FBCONFIG_ID
:
2203 *value
= xmctx
->xm_visual
->visinfo
->visualid
;
2205 case GLX_RENDER_TYPE
:
2206 if (xmctx
->xm_visual
->mesa_visual
.rgbMode
)
2207 *value
= GLX_RGBA_TYPE
;
2209 *value
= GLX_COLOR_INDEX_TYPE
;
2215 return GLX_BAD_ATTRIBUTE
;
2222 glXSelectEvent( Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2224 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2226 xmbuf
->selectedEvents
= mask
;
2231 glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
2233 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2235 *mask
= xmbuf
->selectedEvents
;
2242 /*** GLX_SGI_swap_control ***/
2245 glXSwapIntervalSGI(int interval
)
2253 /*** GLX_SGI_video_sync ***/
2255 static unsigned int FrameCounter
= 0;
2258 glXGetVideoSyncSGI(unsigned int *count
)
2260 /* this is a bogus implementation */
2261 *count
= FrameCounter
++;
2266 glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2268 if (divisor
<= 0 || remainder
< 0)
2269 return GLX_BAD_VALUE
;
2270 /* this is a bogus implementation */
2272 while (FrameCounter
% divisor
!= remainder
)
2274 *count
= FrameCounter
;
2280 /*** GLX_SGI_make_current_read ***/
2283 glXMakeCurrentReadSGI(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
,
2286 return glXMakeContextCurrent( dpy
, draw
, read
, ctx
);
2291 glXGetCurrentReadDrawableSGI(void)
2298 /*** GLX_SGIX_video_source ***/
2301 PUBLIC GLXVideoSourceSGIX
2302 glXCreateGLXVideoSourceSGIX(Display
*dpy
, int screen
, VLServer server
,
2303 VLPath path
, int nodeClass
, VLNode drainNode
)
2315 glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
2324 /*** GLX_EXT_import_context ***/
2327 glXFreeContextEXT(Display
*dpy
, GLXContext context
)
2334 glXGetContextIDEXT(const GLXContext context
)
2341 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
2349 glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,
2361 /*** GLX_SGIX_fbconfig ***/
2364 glXGetFBConfigAttribSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2365 int attribute
, int *value
)
2367 return glXGetFBConfigAttrib(dpy
, config
, attribute
, value
);
2370 PUBLIC GLXFBConfigSGIX
*
2371 glXChooseFBConfigSGIX(Display
*dpy
, int screen
, int *attrib_list
,
2374 return (GLXFBConfig
*) glXChooseFBConfig(dpy
, screen
,
2375 attrib_list
, nelements
);
2380 glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2383 XMesaVisual xmvis
= (XMesaVisual
) config
;
2384 XMesaBuffer xmbuf
= XMesaCreatePixmapBuffer(xmvis
, pixmap
, 0);
2385 return xmbuf
->ws
.drawable
; /* need to return an X ID */
2390 glXCreateContextWithConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2391 int renderType
, GLXContext shareCtx
,
2394 XMesaVisual xmvis
= (XMesaVisual
) config
;
2396 if (!dpy
|| !config
||
2397 (renderType
!= GLX_RGBA_TYPE
&& renderType
!= GLX_COLOR_INDEX_TYPE
))
2400 return create_context(dpy
, xmvis
,
2401 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2403 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
, 0x0);
2407 PUBLIC XVisualInfo
*
2408 glXGetVisualFromFBConfigSGIX(Display
*dpy
, GLXFBConfigSGIX config
)
2410 return glXGetVisualFromFBConfig(dpy
, config
);
2414 PUBLIC GLXFBConfigSGIX
2415 glXGetFBConfigFromVisualSGIX(Display
*dpy
, XVisualInfo
*vis
)
2417 XMesaVisual xmvis
= find_glx_visual(dpy
, vis
);
2419 /* This visual wasn't found with glXChooseVisual() */
2420 xmvis
= create_glx_visual(dpy
, vis
);
2423 return (GLXFBConfigSGIX
) xmvis
;
2428 /*** GLX_SGIX_pbuffer ***/
2430 PUBLIC GLXPbufferSGIX
2431 glXCreateGLXPbufferSGIX(Display
*dpy
, GLXFBConfigSGIX config
,
2432 unsigned int width
, unsigned int height
,
2435 XMesaVisual xmvis
= (XMesaVisual
) config
;
2438 GLboolean useLargest
= GL_FALSE
, preserveContents
= GL_FALSE
;
2442 for (attrib
= attribList
; attrib
&& *attrib
; attrib
++) {
2444 case GLX_PRESERVED_CONTENTS_SGIX
:
2446 preserveContents
= *attrib
; /* ignored */
2448 case GLX_LARGEST_PBUFFER_SGIX
:
2450 useLargest
= *attrib
; /* ignored */
2457 /* not used at this time */
2459 (void) preserveContents
;
2461 xmbuf
= XMesaCreatePBuffer( xmvis
, 0, width
, height
);
2462 /* A GLXPbuffer handle must be an X Drawable because that's what
2463 * glXMakeCurrent takes.
2465 return (GLXPbuffer
) xmbuf
->ws
.drawable
;
2470 glXDestroyGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
)
2472 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2474 XMesaDestroyBuffer(xmbuf
);
2480 glXQueryGLXPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuf
, int attribute
,
2481 unsigned int *value
)
2483 const XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, pbuf
);
2486 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2490 switch (attribute
) {
2491 case GLX_PRESERVED_CONTENTS_SGIX
:
2494 case GLX_LARGEST_PBUFFER_SGIX
:
2495 *value
= xmesa_buffer_width(xmbuf
) * xmesa_buffer_height(xmbuf
);
2497 case GLX_WIDTH_SGIX
:
2498 *value
= xmesa_buffer_width(xmbuf
);
2500 case GLX_HEIGHT_SGIX
:
2501 *value
= xmesa_buffer_height(xmbuf
);
2503 case GLX_EVENT_MASK_SGIX
:
2504 *value
= 0; /* XXX might be wrong */
2514 glXSelectEventSGIX(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
2516 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2518 /* Note: we'll never generate clobber events */
2519 xmbuf
->selectedEvents
= mask
;
2525 glXGetSelectedEventSGIX(Display
*dpy
, GLXDrawable drawable
,
2526 unsigned long *mask
)
2528 XMesaBuffer xmbuf
= XMesaFindBuffer(dpy
, drawable
);
2530 *mask
= xmbuf
->selectedEvents
;
2539 /*** GLX_SGI_cushion ***/
2542 glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2551 /*** GLX_SGIX_video_resize ***/
2554 glXBindChannelToWindowSGIX(Display
*dpy
, int screen
, int channel
,
2565 glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2566 int x
, int y
, int w
, int h
)
2579 glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2580 int *x
, int *y
, int *w
, int *h
)
2593 glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2594 int *dx
, int *dy
, int *dw
, int *dh
)
2607 glXChannelRectSyncSGIX(Display
*dpy
, int screen
, int channel
, GLenum synctype
)
2618 /*** GLX_SGIX_dmbuffer **/
2620 #if defined(_DM_BUFFER_H_)
2622 glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2623 DMparams
*params
, DMbuffer dmbuffer
)
2634 /*** GLX_SGIX_swap_group ***/
2637 glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
, GLXDrawable member
)
2646 /*** GLX_SGIX_swap_barrier ***/
2649 glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
, int barrier
)
2657 glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2667 /*** GLX_SUN_get_transparent_index ***/
2670 glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
, Window underlay
,
2676 (void) pTransparent
;
2682 /*** GLX_MESA_release_buffers ***/
2685 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2686 * (a window or pixmap) prior to destroying the GLXDrawable.
2689 glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2691 XMesaBuffer b
= XMesaFindBuffer(dpy
, d
);
2693 XMesaDestroyBuffer(b
);
2699 /*** GLX_EXT_texture_from_pixmap ***/
2702 glXBindTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
,
2703 const int *attrib_list
)
2705 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2707 XMesaBindTexImage(dpy
, b
, buffer
, attrib_list
);
2711 glXReleaseTexImageEXT(Display
*dpy
, GLXDrawable drawable
, int buffer
)
2713 XMesaBuffer b
= XMesaFindBuffer(dpy
, drawable
);
2715 XMesaReleaseTexImage(dpy
, b
, buffer
);
2720 /*** GLX_ARB_create_context ***/
2724 glXCreateContextAttribsARB(Display
*dpy
, GLXFBConfig config
,
2725 GLXContext shareCtx
, Bool direct
,
2726 const int *attrib_list
)
2728 XMesaVisual xmvis
= (XMesaVisual
) config
;
2729 int majorVersion
= 1, minorVersion
= 0;
2730 int contextFlags
= 0x0;
2731 int profileMask
= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
;
2732 int renderType
= GLX_RGBA_TYPE
;
2735 const int contextFlagsAll
= (GLX_CONTEXT_DEBUG_BIT_ARB
|
2736 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
);
2739 /* parse attrib_list */
2740 for (i
= 0; !done
&& attrib_list
&& attrib_list
[i
]; i
++) {
2741 switch (attrib_list
[i
]) {
2742 case GLX_CONTEXT_MAJOR_VERSION_ARB
:
2743 majorVersion
= attrib_list
[++i
];
2745 case GLX_CONTEXT_MINOR_VERSION_ARB
:
2746 minorVersion
= attrib_list
[++i
];
2748 case GLX_CONTEXT_FLAGS_ARB
:
2749 contextFlags
= attrib_list
[++i
];
2751 case GLX_CONTEXT_PROFILE_MASK_ARB
:
2752 profileMask
= attrib_list
[++i
];
2754 case GLX_RENDER_TYPE
:
2755 renderType
= attrib_list
[++i
];
2763 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAtrribsARB
, True
);
2768 /* check contextFlags */
2769 if (contextFlags
& ~contextFlagsAll
) {
2770 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAtrribsARB
, True
);
2774 /* check profileMask */
2775 if (profileMask
!= GLX_CONTEXT_CORE_PROFILE_BIT_ARB
&&
2776 profileMask
!= GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
&&
2777 profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
) {
2778 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAtrribsARB
, False
);
2782 /* check renderType */
2783 if (renderType
!= GLX_RGBA_TYPE
&&
2784 renderType
!= GLX_COLOR_INDEX_TYPE
) {
2785 generate_error(dpy
, BadValue
, 0, X_GLXCreateContextAtrribsARB
, True
);
2790 if (majorVersion
<= 0 ||
2792 (profileMask
!= GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2793 ((majorVersion
== 1 && minorVersion
> 5) ||
2794 (majorVersion
== 2 && minorVersion
> 1) ||
2795 (majorVersion
== 3 && minorVersion
> 3) ||
2796 (majorVersion
== 4 && minorVersion
> 5) ||
2797 majorVersion
> 4))) {
2798 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAtrribsARB
, True
);
2801 if (profileMask
== GLX_CONTEXT_ES_PROFILE_BIT_EXT
&&
2802 ((majorVersion
== 1 && minorVersion
> 1) ||
2803 (majorVersion
== 2 && minorVersion
> 0) ||
2804 (majorVersion
== 3 && minorVersion
> 1) ||
2805 majorVersion
> 3)) {
2806 /* GLX_EXT_create_context_es2_profile says nothing to justifying a
2807 * different error code for invalid ES versions, but this is what NVIDIA
2808 * does and piglit expects.
2810 generate_error(dpy
, GLXBadProfileARB
, 0, X_GLXCreateContextAtrribsARB
, False
);
2814 if ((contextFlags
& GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB
) &&
2816 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAtrribsARB
, True
);
2820 if (renderType
== GLX_COLOR_INDEX_TYPE
&& majorVersion
>= 3) {
2821 generate_error(dpy
, BadMatch
, 0, X_GLXCreateContextAtrribsARB
, True
);
2825 ctx
= create_context(dpy
, xmvis
,
2826 shareCtx
? shareCtx
->xmesaContext
: NULL
,
2828 majorVersion
, minorVersion
,
2829 profileMask
, contextFlags
);
2831 generate_error(dpy
, GLXBadFBConfig
, 0, X_GLXCreateContextAtrribsARB
, False
);