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
39 /* This indicates the client-side GLX API and GLX encoder version. */
40 #define CLIENT_MAJOR_VERSION 1
41 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
43 /* This indicates the server-side GLX decoder version.
44 * GLX 1.4 indicates OpenGL 1.3 support
46 #define SERVER_MAJOR_VERSION 1
47 #define SERVER_MINOR_VERSION 4
49 /* Who implemented this GLX? */
50 #define VENDOR "Brian Paul"
53 "GLX_MESA_copy_sub_buffer " \
54 "GLX_MESA_pixmap_colormap " \
55 "GLX_MESA_release_buffers " \
56 "GLX_ARB_create_context " \
57 "GLX_ARB_create_context_profile " \
58 "GLX_ARB_get_proc_address " \
59 "GLX_EXT_texture_from_pixmap " \
60 "GLX_EXT_visual_info " \
61 "GLX_EXT_visual_rating " \
62 /*"GLX_SGI_video_sync "*/ \
63 "GLX_SGIX_fbconfig " \
66 #define DEFAULT_DIRECT GL_TRUE
69 /** XXX this could be based on gallium's max texture size */
70 #define PBUFFER_MAX_SIZE 16384
74 * The GLXContext typedef is defined as a pointer to this structure.
76 struct __GLXcontextRec
80 GLXDrawable currentDrawable;
81 GLXDrawable currentReadable;
84 XMesaContext xmesaContext;
89 static pipe_tsd ContextTSD;
91 /** Set current context for calling thread */
93 SetCurrentContext(GLXContext c)
95 pipe_tsd_set(&ContextTSD, c);
98 /** Get current context for calling thread */
100 GetCurrentContext(void)
102 return pipe_tsd_get(&ContextTSD);
107 /**********************************************************************/
108 /*** GLX Visual Code ***/
109 /**********************************************************************/
114 static XMesaVisual *VisualTable = NULL;
115 static int NumVisuals = 0;
119 /* Macro to handle c_class vs class field name in XVisualInfo struct */
120 #if defined(__cplusplus) || defined(c_plusplus)
121 #define CLASS c_class
129 * Test if the given XVisualInfo is usable for Mesa rendering.
132 is_usable_visual( XVisualInfo *vinfo )
134 switch (vinfo->CLASS) {
137 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
141 /* Any StaticColor/PseudoColor visual of at least 4 bits */
142 if (vinfo->depth>=4) {
150 /* Any depth of TrueColor or DirectColor works in RGB mode */
153 /* This should never happen */
160 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
161 * configuration in our list of GLX visuals.
164 save_glx_visual( Display *dpy, XVisualInfo *vinfo,
165 GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag,
166 GLboolean stereoFlag,
167 GLint depth_size, GLint stencil_size,
168 GLint accumRedSize, GLint accumGreenSize,
169 GLint accumBlueSize, GLint accumAlphaSize,
170 GLint level, GLint numAuxBuffers )
172 GLboolean ximageFlag = GL_TRUE;
175 GLboolean comparePointers;
178 /* Check if the MESA_BACK_BUFFER env var is set */
179 char *backbuffer = _mesa_getenv("MESA_BACK_BUFFER");
181 if (backbuffer[0]=='p' || backbuffer[0]=='P') {
182 ximageFlag = GL_FALSE;
184 else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
185 ximageFlag = GL_TRUE;
188 _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
194 /* stereo not supported */
198 if (stencil_size > 0 && depth_size > 0)
201 /* Comparing IDs uses less memory but sometimes fails. */
202 /* XXX revisit this after 3.0 is finished. */
203 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
204 comparePointers = GL_TRUE;
206 comparePointers = GL_FALSE;
208 /* Force the visual to have an alpha channel */
209 if (rgbFlag && _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
212 /* First check if a matching visual is already in the list */
213 for (i=0; i<NumVisuals; i++) {
214 XMesaVisual v = VisualTable[i];
215 if (v->display == dpy
216 && v->mesa_visual.level == level
217 && v->mesa_visual.numAuxBuffers == numAuxBuffers
218 && v->ximage_flag == ximageFlag
219 && v->mesa_visual.rgbMode == rgbFlag
220 && v->mesa_visual.doubleBufferMode == dbFlag
221 && v->mesa_visual.stereoMode == stereoFlag
222 && (v->mesa_visual.alphaBits > 0) == alphaFlag
223 && (v->mesa_visual.depthBits >= depth_size || depth_size == 0)
224 && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0)
225 && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0)
226 && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0)
227 && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0)
228 && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) {
229 /* now either compare XVisualInfo pointers or visual IDs */
230 if ((!comparePointers && v->visinfo->visualid == vinfo->visualid)
231 || (comparePointers && v->vishandle == vinfo)) {
237 /* Create a new visual and add it to the list. */
239 xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag,
240 stereoFlag, ximageFlag,
241 depth_size, stencil_size,
242 accumRedSize, accumBlueSize,
243 accumBlueSize, accumAlphaSize, 0, level,
246 /* Save a copy of the pointer now so we can find this visual again
247 * if we need to search for it in find_glx_visual().
249 xmvis->vishandle = vinfo;
250 /* Allocate more space for additional visual */
251 VisualTable = (XMesaVisual *) _mesa_realloc( VisualTable,
252 sizeof(XMesaVisual) * NumVisuals,
253 sizeof(XMesaVisual) * (NumVisuals + 1));
254 /* add xmvis to the list */
255 VisualTable[NumVisuals] = xmvis;
257 /* XXX minor hack, because XMesaCreateVisual doesn't support an
258 * aux buffers parameter.
260 xmvis->mesa_visual.numAuxBuffers = numAuxBuffers;
267 * Return the default number of bits for the Z buffer.
268 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
269 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
270 * XXX probably do the same thing for stencil, accum, etc.
273 default_depth_bits(void)
276 const char *zEnv = _mesa_getenv("MESA_GLX_DEPTH_BITS");
285 default_alpha_bits(void)
288 const char *aEnv = _mesa_getenv("MESA_GLX_ALPHA_BITS");
297 default_accum_bits(void)
305 * Create a GLX visual from a regular XVisualInfo.
306 * This is called when Fake GLX is given an XVisualInfo which wasn't
307 * returned by glXChooseVisual. Since this is the first time we're
308 * considering this visual we'll take a guess at reasonable values
309 * for depth buffer size, stencil size, accum size, etc.
310 * This is the best we can do with a client-side emulation of GLX.
313 create_glx_visual( Display *dpy, XVisualInfo *visinfo )
315 GLint zBits = default_depth_bits();
316 GLint accBits = default_accum_bits();
317 GLboolean alphaFlag = default_alpha_bits() > 0;
319 if (is_usable_visual( visinfo )) {
320 /* Configure this visual as RGB, double-buffered, depth-buffered. */
321 /* This is surely wrong for some people's needs but what else */
322 /* can be done? They should use glXChooseVisual(). */
323 return save_glx_visual( dpy, visinfo,
325 alphaFlag, /* alpha */
326 GL_TRUE, /* double */
327 GL_FALSE, /* stereo */
329 8, /* stencil bits */
339 _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
347 * Find the GLX visual associated with an XVisualInfo.
350 find_glx_visual( Display *dpy, XVisualInfo *vinfo )
354 /* try to match visual id */
355 for (i=0;i<NumVisuals;i++) {
356 if (VisualTable[i]->display==dpy
357 && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
358 return VisualTable[i];
362 /* if that fails, try to match pointers */
363 for (i=0;i<NumVisuals;i++) {
364 if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {
365 return VisualTable[i];
374 * Try to get an X visual which matches the given arguments.
377 get_visual( Display *dpy, int scr, unsigned int depth, int xclass )
379 XVisualInfo temp, *vis;
382 unsigned int default_depth;
385 mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
390 default_depth = DefaultDepth(dpy,scr);
391 default_class = DefaultVisual(dpy,scr)->CLASS;
393 if (depth==default_depth && xclass==default_class) {
394 /* try to get root window's visual */
395 temp.visualid = DefaultVisual(dpy,scr)->visualid;
396 mask |= VisualIDMask;
399 vis = XGetVisualInfo( dpy, mask, &temp, &n );
401 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
402 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
403 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
405 if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
406 if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&
407 _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&
408 _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {
422 * Retrieve the value of the given environment variable and find
423 * the X visual which matches it.
424 * Input: dpy - the display
425 * screen - the screen number
426 * varname - the name of the environment variable
427 * Return: an XVisualInfo pointer to NULL if error.
430 get_env_visual(Display *dpy, int scr, const char *varname)
432 char value[100], type[100];
433 int depth, xclass = -1;
436 if (!_mesa_getenv( varname )) {
440 strncpy( value, _mesa_getenv(varname), 100 );
443 sscanf( value, "%s %d", type, &depth );
445 if (strcmp(type,"TrueColor")==0) xclass = TrueColor;
446 else if (strcmp(type,"DirectColor")==0) xclass = DirectColor;
447 else if (strcmp(type,"PseudoColor")==0) xclass = PseudoColor;
448 else if (strcmp(type,"StaticColor")==0) xclass = StaticColor;
449 else if (strcmp(type,"GrayScale")==0) xclass = GrayScale;
450 else if (strcmp(type,"StaticGray")==0) xclass = StaticGray;
452 if (xclass>-1 && depth>0) {
453 vis = get_visual( dpy, scr, depth, xclass );
459 _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",
468 * Select an X visual which satisfies the RGBA flag and minimum depth.
470 * screen - X display and screen number
471 * min_depth - minimum visual depth
472 * preferred_class - preferred GLX visual class or DONT_CARE
473 * Return: pointer to an XVisualInfo or NULL.
476 choose_x_visual( Display *dpy, int screen, int min_depth,
477 int preferred_class )
480 int xclass, visclass = 0;
483 /* First see if the MESA_RGB_VISUAL env var is defined */
484 vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
488 /* Otherwise, search for a suitable visual */
489 if (preferred_class==DONT_CARE) {
490 for (xclass=0;xclass<6;xclass++) {
492 case 0: visclass = TrueColor; break;
493 case 1: visclass = DirectColor; break;
494 case 2: visclass = PseudoColor; break;
495 case 3: visclass = StaticColor; break;
496 case 4: visclass = GrayScale; break;
497 case 5: visclass = StaticGray; break;
500 /* start with shallowest */
501 for (depth=0;depth<=32;depth++) {
502 if (visclass==TrueColor && depth==8) {
503 /* Special case: try to get 8-bit PseudoColor before */
504 /* 8-bit TrueColor */
505 vis = get_visual( dpy, screen, 8, PseudoColor );
510 vis = get_visual( dpy, screen, depth, visclass );
517 /* start with deepest */
518 for (depth=32;depth>=min_depth;depth--) {
519 if (visclass==TrueColor && depth==8) {
520 /* Special case: try to get 8-bit PseudoColor before */
521 /* 8-bit TrueColor */
522 vis = get_visual( dpy, screen, 8, PseudoColor );
527 vis = get_visual( dpy, screen, depth, visclass );
536 /* search for a specific visual class */
537 switch (preferred_class) {
538 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
539 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
540 case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break;
541 case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break;
542 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
543 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
544 default: return NULL;
547 /* start with shallowest */
548 for (depth=0;depth<=32;depth++) {
549 vis = get_visual( dpy, screen, depth, visclass );
556 /* start with deepest */
557 for (depth=32;depth>=min_depth;depth--) {
558 vis = get_visual( dpy, screen, depth, visclass );
566 /* didn't find a visual */
573 /**********************************************************************/
574 /*** Display-related functions ***/
575 /**********************************************************************/
579 * Free all XMesaVisuals which are associated with the given display.
582 destroy_visuals_on_display(Display *dpy)
585 for (i = 0; i < NumVisuals; i++) {
586 if (VisualTable[i]->display == dpy) {
587 /* remove this visual */
589 free(VisualTable[i]);
590 for (j = i; j < NumVisuals - 1; j++)
591 VisualTable[j] = VisualTable[j + 1];
599 * Called from XCloseDisplay() to let us free our display-related data.
602 close_display_callback(Display *dpy, XExtCodes *codes)
604 xmesa_destroy_buffers_on_display(dpy);
605 destroy_visuals_on_display(dpy);
611 * Look for the named extension on given display and return a pointer
612 * to the _XExtension data, or NULL if extension not found.
615 lookup_extension(Display *dpy, const char *extName)
618 for (ext = dpy->ext_procs; ext; ext = ext->next) {
619 if (ext->name && strcmp(ext->name, extName) == 0) {
628 * Whenever we're given a new Display pointer, call this function to
629 * register our close_display_callback function.
632 register_with_display(Display *dpy)
634 const char *extName = "MesaGLX";
637 ext = lookup_extension(dpy, extName);
639 XExtCodes *c = XAddExtension(dpy);
640 ext = dpy->ext_procs; /* new extension is at head of list */
641 assert(c->extension == ext->codes.extension);
643 ext->name = _mesa_strdup(extName);
644 ext->close_display = close_display_callback;
649 /**********************************************************************/
650 /*** Begin Fake GLX API Functions ***/
651 /**********************************************************************/
655 * Helper used by glXChooseVisual and glXChooseFBConfig.
656 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
658 * In either case, the attribute list is terminated with the value 'None'.
661 choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
663 const GLboolean rgbModeDefault = fbConfig;
664 const int *parselist;
666 int min_red=0, min_green=0, min_blue=0;
667 GLboolean rgb_flag = rgbModeDefault;
668 GLboolean alpha_flag = GL_FALSE;
669 GLboolean double_flag = GL_FALSE;
670 GLboolean stereo_flag = GL_FALSE;
671 GLint depth_size = 0;
672 GLint stencil_size = 0;
673 GLint accumRedSize = 0;
674 GLint accumGreenSize = 0;
675 GLint accumBlueSize = 0;
676 GLint accumAlphaSize = 0;
678 int visual_type = DONT_CARE;
679 GLint caveat = DONT_CARE;
680 XMesaVisual xmvis = NULL;
681 int desiredVisualID = -1;
691 parselist[1] == GLX_DONT_CARE &&
692 parselist[0] != GLX_LEVEL) {
693 /* For glXChooseFBConfig(), skip attributes whose value is
694 * GLX_DONT_CARE, unless it's GLX_LEVEL (which can legitimately be
697 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
698 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
704 switch (*parselist) {
715 case GLX_BUFFER_SIZE:
721 level = *parselist++;
733 case GLX_DOUBLEBUFFER:
736 double_flag = *parselist++;
739 double_flag = GL_TRUE;
745 stereo_flag = *parselist++;
748 stereo_flag = GL_TRUE;
751 case GLX_AUX_BUFFERS:
753 numAux = *parselist++;
754 if (numAux > MAX_AUX_BUFFERS)
759 min_red = *parselist++;
763 min_green = *parselist++;
767 min_blue = *parselist++;
772 GLint size = *parselist++;
773 alpha_flag = size ? GL_TRUE : GL_FALSE;
778 depth_size = *parselist++;
780 case GLX_STENCIL_SIZE:
782 stencil_size = *parselist++;
784 case GLX_ACCUM_RED_SIZE:
787 GLint size = *parselist++;
788 accumRedSize = MAX2( accumRedSize, size );
791 case GLX_ACCUM_GREEN_SIZE:
794 GLint size = *parselist++;
795 accumGreenSize = MAX2( accumGreenSize, size );
798 case GLX_ACCUM_BLUE_SIZE:
801 GLint size = *parselist++;
802 accumBlueSize = MAX2( accumBlueSize, size );
805 case GLX_ACCUM_ALPHA_SIZE:
808 GLint size = *parselist++;
809 accumAlphaSize = MAX2( accumAlphaSize, size );
814 * GLX_EXT_visual_info extension
816 case GLX_X_VISUAL_TYPE_EXT:
818 visual_type = *parselist++;
820 case GLX_TRANSPARENT_TYPE_EXT:
824 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
828 case GLX_TRANSPARENT_RED_VALUE_EXT:
829 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
830 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
831 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
838 * GLX_EXT_visual_info extension
840 case GLX_VISUAL_CAVEAT_EXT:
842 caveat = *parselist++; /* ignored for now */
846 * GLX_ARB_multisample
848 case GLX_SAMPLE_BUFFERS_ARB:
849 case GLX_SAMPLES_ARB:
851 if (*parselist++ != 0) {
852 /* ms not supported */
860 case GLX_RENDER_TYPE:
864 if (*parselist & GLX_RGBA_BIT) {
867 else if (*parselist & GLX_COLOR_INDEX_BIT) {
870 else if (*parselist == 0) {
875 case GLX_DRAWABLE_TYPE:
879 if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) {
880 return NULL; /* bad bit */
884 case GLX_FBCONFIG_ID:
889 desiredVisualID = *parselist++;
891 case GLX_X_RENDERABLE:
892 case GLX_MAX_PBUFFER_WIDTH:
893 case GLX_MAX_PBUFFER_HEIGHT:
894 case GLX_MAX_PBUFFER_PIXELS:
896 return NULL; /* invalid config option */
897 parselist += 2; /* ignore the parameter */
900 #ifdef GLX_EXT_texture_from_pixmap
901 case GLX_BIND_TO_TEXTURE_RGB_EXT:
902 parselist++; /*skip*/
904 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
905 parselist++; /*skip*/
907 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
908 parselist++; /*skip*/
910 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
912 if (*parselist & ~(GLX_TEXTURE_1D_BIT_EXT |
913 GLX_TEXTURE_2D_BIT_EXT |
914 GLX_TEXTURE_RECTANGLE_BIT_EXT)) {
919 case GLX_Y_INVERTED_EXT:
920 parselist++; /*skip*/
929 /* undefined attribute */
930 _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
940 * Since we're only simulating the GLX extension this function will never
941 * find any real GL visuals. Instead, all we can do is try to find an RGB
942 * or CI visual of appropriate depth. Other requested attributes such as
943 * double buffering, depth buffer, etc. will be associated with the X
944 * visual and stored in the VisualTable[].
946 if (desiredVisualID != -1) {
947 /* try to get a specific visual, by visualID */
950 temp.visualid = desiredVisualID;
951 temp.screen = screen;
952 vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n);
954 /* give the visual some useful GLX attributes */
955 double_flag = GL_TRUE;
960 /* normal color planes */
961 /* Get an RGB visual */
962 int min_rgb = min_red + min_green + min_blue;
963 if (min_rgb>1 && min_rgb<8) {
964 /* a special case to be sure we can get a monochrome visual */
967 vis = choose_x_visual( dpy, screen, min_rgb, visual_type );
970 _mesa_warning(NULL, "overlay not supported");
975 /* Note: we're not exactly obeying the glXChooseVisual rules here.
976 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
977 * largest depth buffer size, which is 32bits/value. Instead, we
978 * return 16 to maintain performance with earlier versions of Mesa.
980 if (stencil_size > 0)
981 depth_size = 24; /* if Z and stencil, always use 24+8 format */
982 else if (depth_size > 24)
984 else if (depth_size > 16)
986 else if (depth_size > 0) {
987 depth_size = default_depth_bits();
991 alpha_flag = default_alpha_bits() > 0;
994 /* we only support one size of stencil and accum buffers. */
995 if (stencil_size > 0)
998 if (accumRedSize > 0 ||
999 accumGreenSize > 0 ||
1000 accumBlueSize > 0 ||
1001 accumAlphaSize > 0) {
1005 accumBlueSize = default_accum_bits();
1007 accumAlphaSize = alpha_flag ? accumRedSize : 0;
1010 xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
1011 stereo_flag, depth_size, stencil_size,
1012 accumRedSize, accumGreenSize,
1013 accumBlueSize, accumAlphaSize, level, numAux );
1020 PUBLIC XVisualInfo *
1021 glXChooseVisual( Display *dpy, int screen, int *list )
1025 /* register ourselves as an extension on this display */
1026 register_with_display(dpy);
1028 xmvis = choose_visual(dpy, screen, list, GL_FALSE);
1030 /* create a new vishandle - the cached one may be stale */
1031 xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo));
1032 if (xmvis->vishandle) {
1033 memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1035 return xmvis->vishandle;
1043 * Helper function used by other glXCreateContext functions.
1046 create_context(Display *dpy, XMesaVisual xmvis,
1047 XMesaContext shareCtx, Bool direct,
1048 unsigned major, unsigned minor,
1049 unsigned profileMask, unsigned contextFlags)
1056 glxCtx = CALLOC_STRUCT(__GLXcontextRec);
1060 /* deallocate unused windows/buffers */
1062 XMesaGarbageCollect();
1065 glxCtx->xmesaContext = XMesaCreateContext(xmvis, shareCtx, major, minor,
1066 profileMask, contextFlags);
1067 if (!glxCtx->xmesaContext) {
1072 glxCtx->isDirect = DEFAULT_DIRECT;
1073 glxCtx->currentDpy = dpy;
1074 glxCtx->xid = (XID) glxCtx; /* self pointer */
1081 glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1082 GLXContext shareCtx, Bool direct )
1086 xmvis = find_glx_visual( dpy, visinfo );
1088 /* This visual wasn't found with glXChooseVisual() */
1089 xmvis = create_glx_visual( dpy, visinfo );
1091 /* unusable visual */
1096 return create_context(dpy, xmvis,
1097 shareCtx ? shareCtx->xmesaContext : NULL,
1099 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0x0);
1103 /* XXX these may have to be removed due to thread-safety issues. */
1104 static GLXContext MakeCurrent_PrevContext = 0;
1105 static GLXDrawable MakeCurrent_PrevDrawable = 0;
1106 static GLXDrawable MakeCurrent_PrevReadable = 0;
1107 static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1108 static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
1111 /* GLX 1.3 and later */
1113 glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
1114 GLXDrawable read, GLXContext ctx )
1116 GLXContext glxCtx = ctx;
1117 static boolean firsttime = 1, no_rast = 0;
1120 no_rast = getenv("SP_NO_RAST") != NULL;
1124 if (ctx && draw && read) {
1125 XMesaBuffer drawBuffer, readBuffer;
1126 XMesaContext xmctx = glxCtx->xmesaContext;
1128 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1129 if (ctx == MakeCurrent_PrevContext
1130 && draw == MakeCurrent_PrevDrawable) {
1131 drawBuffer = MakeCurrent_PrevDrawBuffer;
1134 drawBuffer = XMesaFindBuffer( dpy, draw );
1137 /* drawable must be a new window! */
1138 drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw );
1140 /* Out of memory, or context/drawable depth mismatch */
1145 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1146 if (ctx == MakeCurrent_PrevContext
1147 && read == MakeCurrent_PrevReadable) {
1148 readBuffer = MakeCurrent_PrevReadBuffer;
1151 readBuffer = XMesaFindBuffer( dpy, read );
1154 /* drawable must be a new window! */
1155 readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read );
1157 /* Out of memory, or context/drawable depth mismatch */
1163 MakeCurrent_PrevContext == ctx &&
1164 MakeCurrent_PrevDrawable == draw &&
1165 MakeCurrent_PrevReadable == read &&
1166 MakeCurrent_PrevDrawBuffer == drawBuffer &&
1167 MakeCurrent_PrevReadBuffer == readBuffer)
1170 MakeCurrent_PrevContext = ctx;
1171 MakeCurrent_PrevDrawable = draw;
1172 MakeCurrent_PrevReadable = read;
1173 MakeCurrent_PrevDrawBuffer = drawBuffer;
1174 MakeCurrent_PrevReadBuffer = readBuffer;
1176 /* Now make current! */
1177 if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
1178 ctx->currentDpy = dpy;
1179 ctx->currentDrawable = draw;
1180 ctx->currentReadable = read;
1181 SetCurrentContext(ctx);
1188 else if (!ctx && !draw && !read) {
1189 /* release current context w/out assigning new one. */
1190 XMesaMakeCurrent2( NULL, NULL, NULL );
1191 MakeCurrent_PrevContext = 0;
1192 MakeCurrent_PrevDrawable = 0;
1193 MakeCurrent_PrevReadable = 0;
1194 MakeCurrent_PrevDrawBuffer = 0;
1195 MakeCurrent_PrevReadBuffer = 0;
1196 SetCurrentContext(NULL);
1200 /* The args must either all be non-zero or all zero.
1209 glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1211 return glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1216 glXGetCurrentContext(void)
1218 return GetCurrentContext();
1223 glXGetCurrentDisplay(void)
1225 GLXContext glxCtx = glXGetCurrentContext();
1227 return glxCtx ? glxCtx->currentDpy : NULL;
1232 glXGetCurrentDisplayEXT(void)
1234 return glXGetCurrentDisplay();
1239 glXGetCurrentDrawable(void)
1241 GLXContext gc = glXGetCurrentContext();
1242 return gc ? gc->currentDrawable : 0;
1247 glXGetCurrentReadDrawable(void)
1249 GLXContext gc = glXGetCurrentContext();
1250 return gc ? gc->currentReadable : 0;
1255 glXGetCurrentReadDrawableSGI(void)
1257 return glXGetCurrentReadDrawable();
1262 glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1267 v = find_glx_visual( dpy, visinfo );
1269 v = create_glx_visual( dpy, visinfo );
1271 /* unusable visual */
1276 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1280 return b->ws.drawable;
1284 /*** GLX_MESA_pixmap_colormap ***/
1287 glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1288 Pixmap pixmap, Colormap cmap )
1293 v = find_glx_visual( dpy, visinfo );
1295 v = create_glx_visual( dpy, visinfo );
1297 /* unusable visual */
1302 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1306 return b->ws.drawable;
1311 glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1313 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1315 XMesaDestroyBuffer(b);
1317 else if (_mesa_getenv("MESA_DEBUG")) {
1318 _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1324 glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1325 unsigned long mask )
1327 XMesaContext xm_src = src->xmesaContext;
1328 XMesaContext xm_dst = dst->xmesaContext;
1330 if (MakeCurrent_PrevContext == src) {
1333 XMesaCopyContext(xm_src, xm_dst, mask);
1338 glXQueryExtension( Display *dpy, int *errorBase, int *eventBase )
1341 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1342 if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &op, &ev, &err))
1348 return True; /* we're faking GLX so always return success */
1353 glXDestroyContext( Display *dpy, GLXContext ctx )
1356 GLXContext glxCtx = ctx;
1358 MakeCurrent_PrevContext = 0;
1359 MakeCurrent_PrevDrawable = 0;
1360 MakeCurrent_PrevReadable = 0;
1361 MakeCurrent_PrevDrawBuffer = 0;
1362 MakeCurrent_PrevReadBuffer = 0;
1363 XMesaDestroyContext( glxCtx->xmesaContext );
1364 XMesaGarbageCollect();
1371 glXIsDirect( Display *dpy, GLXContext ctx )
1373 return ctx ? ctx->isDirect : False;
1379 glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1381 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1382 static boolean firsttime = 1, no_rast = 0;
1385 no_rast = getenv("SP_NO_RAST") != NULL;
1393 XMesaSwapBuffers(buffer);
1395 else if (_mesa_getenv("MESA_DEBUG")) {
1396 _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n",
1403 /*** GLX_MESA_copy_sub_buffer ***/
1406 glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable,
1407 int x, int y, int width, int height)
1409 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1411 XMesaCopySubBuffer(buffer, x, y, width, height);
1413 else if (_mesa_getenv("MESA_DEBUG")) {
1414 _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1420 glXQueryVersion( Display *dpy, int *maj, int *min )
1423 /* Return GLX version, not Mesa version */
1424 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1425 *maj = CLIENT_MAJOR_VERSION;
1426 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1432 * Query the GLX attributes of the given XVisualInfo.
1435 get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
1441 return GLX_BAD_ATTRIBUTE;
1442 *value = (int) True;
1444 case GLX_BUFFER_SIZE:
1445 *value = xmvis->visinfo->depth;
1448 *value = xmvis->mesa_visual.level;
1452 return GLX_BAD_ATTRIBUTE;
1453 if (xmvis->mesa_visual.rgbMode) {
1460 case GLX_DOUBLEBUFFER:
1461 *value = (int) xmvis->mesa_visual.doubleBufferMode;
1464 *value = (int) xmvis->mesa_visual.stereoMode;
1466 case GLX_AUX_BUFFERS:
1467 *value = xmvis->mesa_visual.numAuxBuffers;
1470 *value = xmvis->mesa_visual.redBits;
1472 case GLX_GREEN_SIZE:
1473 *value = xmvis->mesa_visual.greenBits;
1476 *value = xmvis->mesa_visual.blueBits;
1478 case GLX_ALPHA_SIZE:
1479 *value = xmvis->mesa_visual.alphaBits;
1481 case GLX_DEPTH_SIZE:
1482 *value = xmvis->mesa_visual.depthBits;
1484 case GLX_STENCIL_SIZE:
1485 *value = xmvis->mesa_visual.stencilBits;
1487 case GLX_ACCUM_RED_SIZE:
1488 *value = xmvis->mesa_visual.accumRedBits;
1490 case GLX_ACCUM_GREEN_SIZE:
1491 *value = xmvis->mesa_visual.accumGreenBits;
1493 case GLX_ACCUM_BLUE_SIZE:
1494 *value = xmvis->mesa_visual.accumBlueBits;
1496 case GLX_ACCUM_ALPHA_SIZE:
1497 *value = xmvis->mesa_visual.accumAlphaBits;
1501 * GLX_EXT_visual_info extension
1503 case GLX_X_VISUAL_TYPE_EXT:
1504 switch (xmvis->visinfo->CLASS) {
1505 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1506 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1507 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1508 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1509 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1510 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1513 case GLX_TRANSPARENT_TYPE_EXT:
1515 *value = GLX_NONE_EXT;
1517 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1520 case GLX_TRANSPARENT_RED_VALUE_EXT:
1523 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1526 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1529 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1534 * GLX_EXT_visual_info extension
1536 case GLX_VISUAL_CAVEAT_EXT:
1537 /* test for zero, just in case */
1538 if (xmvis->mesa_visual.visualRating > 0)
1539 *value = xmvis->mesa_visual.visualRating;
1541 *value = GLX_NONE_EXT;
1545 * GLX_ARB_multisample
1547 case GLX_SAMPLE_BUFFERS_ARB:
1550 case GLX_SAMPLES_ARB:
1557 case GLX_SCREEN_EXT:
1559 return GLX_BAD_ATTRIBUTE;
1560 *value = xmvis->visinfo->screen;
1562 case GLX_DRAWABLE_TYPE: /*SGIX too */
1564 return GLX_BAD_ATTRIBUTE;
1565 *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
1567 case GLX_RENDER_TYPE_SGIX:
1569 return GLX_BAD_ATTRIBUTE;
1570 if (xmvis->mesa_visual.rgbMode)
1571 *value = GLX_RGBA_BIT;
1573 *value = GLX_COLOR_INDEX_BIT;
1575 case GLX_X_RENDERABLE_SGIX:
1577 return GLX_BAD_ATTRIBUTE;
1578 *value = True; /* XXX really? */
1580 case GLX_FBCONFIG_ID_SGIX:
1582 return GLX_BAD_ATTRIBUTE;
1583 *value = xmvis->visinfo->visualid;
1585 case GLX_MAX_PBUFFER_WIDTH:
1587 return GLX_BAD_ATTRIBUTE;
1588 /* XXX or MAX_WIDTH? */
1589 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
1591 case GLX_MAX_PBUFFER_HEIGHT:
1593 return GLX_BAD_ATTRIBUTE;
1594 *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1596 case GLX_MAX_PBUFFER_PIXELS:
1598 return GLX_BAD_ATTRIBUTE;
1599 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1600 DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1604 return GLX_BAD_ATTRIBUTE;
1605 *value = xmvis->visinfo->visualid;
1608 #ifdef GLX_EXT_texture_from_pixmap
1609 case GLX_BIND_TO_TEXTURE_RGB_EXT:
1610 *value = True; /*XXX*/
1612 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1614 *value = xmvis->mesa_visual.alphaBits > 0 ? True : False;
1616 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1617 *value = True; /*XXX*/
1619 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1620 *value = (GLX_TEXTURE_1D_BIT_EXT |
1621 GLX_TEXTURE_2D_BIT_EXT |
1622 GLX_TEXTURE_RECTANGLE_BIT_EXT); /*XXX*/
1624 case GLX_Y_INVERTED_EXT:
1625 *value = True; /*XXX*/
1630 return GLX_BAD_ATTRIBUTE;
1637 glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1638 int attrib, int *value )
1642 if (!dpy || !visinfo)
1643 return GLX_BAD_ATTRIBUTE;
1645 xmvis = find_glx_visual( dpy, visinfo );
1647 /* this visual wasn't obtained with glXChooseVisual */
1648 xmvis = create_glx_visual( dpy, visinfo );
1650 /* this visual can't be used for GL rendering */
1651 if (attrib==GLX_USE_GL) {
1652 *value = (int) False;
1656 return GLX_BAD_VISUAL;
1661 k = get_config(xmvis, attrib, value, GL_FALSE);
1669 XMesaContext xmesa = XMesaGetCurrentContext();
1670 XMesaFlush( xmesa );
1678 XMesaContext xmesa = XMesaGetCurrentContext();
1679 XMesaFlush( xmesa );
1684 get_extensions( void )
1691 /* GLX 1.1 and later */
1693 glXQueryExtensionsString( Display *dpy, int screen )
1697 return get_extensions();
1702 /* GLX 1.1 and later */
1704 glXQueryServerString( Display *dpy, int screen, int name )
1706 static char version[1000];
1707 sprintf(version, "%d.%d %s",
1708 SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, xmesa_get_name());
1714 case GLX_EXTENSIONS:
1715 return get_extensions();
1727 /* GLX 1.1 and later */
1729 glXGetClientString( Display *dpy, int name )
1731 static char version[1000];
1732 sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
1733 CLIENT_MINOR_VERSION, xmesa_get_name());
1738 case GLX_EXTENSIONS:
1739 return get_extensions();
1757 glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config,
1758 int attribute, int *value)
1760 XMesaVisual v = (XMesaVisual) config;
1764 if (!dpy || !config || !value)
1767 return get_config(v, attribute, value, GL_TRUE);
1771 PUBLIC GLXFBConfig *
1772 glXGetFBConfigs( Display *dpy, int screen, int *nelements )
1774 XVisualInfo *visuals, visTemplate;
1775 const long visMask = VisualScreenMask;
1778 /* Get list of all X visuals */
1779 visTemplate.screen = screen;
1780 visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
1781 if (*nelements > 0) {
1782 XMesaVisual *results;
1783 results = (XMesaVisual *) malloc(*nelements * sizeof(XMesaVisual));
1788 for (i = 0; i < *nelements; i++) {
1789 results[i] = create_glx_visual(dpy, visuals + i);
1795 return (GLXFBConfig *) results;
1801 PUBLIC GLXFBConfig *
1802 glXChooseFBConfig(Display *dpy, int screen,
1803 const int *attribList, int *nitems)
1807 /* register ourselves as an extension on this display */
1808 register_with_display(dpy);
1810 if (!attribList || !attribList[0]) {
1811 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1812 return glXGetFBConfigs(dpy, screen, nitems);
1815 xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
1817 GLXFBConfig *config = (GLXFBConfig *) malloc(sizeof(XMesaVisual));
1823 config[0] = (GLXFBConfig) xmvis;
1824 return (GLXFBConfig *) config;
1833 PUBLIC XVisualInfo *
1834 glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1836 if (dpy && config) {
1837 XMesaVisual xmvis = (XMesaVisual) config;
1839 return xmvis->vishandle;
1841 /* create a new vishandle - the cached one may be stale */
1842 xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo));
1843 if (xmvis->vishandle) {
1844 memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1846 return xmvis->vishandle;
1856 glXCreateWindow(Display *dpy, GLXFBConfig config, Window win,
1857 const int *attribList)
1859 XMesaVisual xmvis = (XMesaVisual) config;
1864 xmbuf = XMesaCreateWindowBuffer(xmvis, win);
1869 (void) attribList; /* Ignored in GLX 1.3 */
1871 return win; /* A hack for now */
1876 glXDestroyWindow( Display *dpy, GLXWindow window )
1878 XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable) window);
1880 XMesaDestroyBuffer(b);
1881 /* don't destroy X window */
1887 glXCreatePixmap(Display *dpy, GLXFBConfig config, Pixmap pixmap,
1888 const int *attribList)
1890 XMesaVisual v = (XMesaVisual) config;
1893 int target = 0, format = 0, mipmap = 0;
1896 if (!dpy || !config || !pixmap)
1899 for (attr = attribList; attr && *attr; attr++) {
1901 case GLX_TEXTURE_FORMAT_EXT:
1904 case GLX_TEXTURE_FORMAT_NONE_EXT:
1905 case GLX_TEXTURE_FORMAT_RGB_EXT:
1906 case GLX_TEXTURE_FORMAT_RGBA_EXT:
1914 case GLX_TEXTURE_TARGET_EXT:
1917 case GLX_TEXTURE_1D_EXT:
1918 case GLX_TEXTURE_2D_EXT:
1919 case GLX_TEXTURE_RECTANGLE_EXT:
1927 case GLX_MIPMAP_TEXTURE_EXT:
1938 if (format == GLX_TEXTURE_FORMAT_RGB_EXT) {
1939 if (get_config(v, GLX_BIND_TO_TEXTURE_RGB_EXT,
1940 &value, GL_TRUE) != Success
1942 return 0; /* error! */
1945 else if (format == GLX_TEXTURE_FORMAT_RGBA_EXT) {
1946 if (get_config(v, GLX_BIND_TO_TEXTURE_RGBA_EXT,
1947 &value, GL_TRUE) != Success
1949 return 0; /* error! */
1953 if (get_config(v, GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
1954 &value, GL_TRUE) != Success
1956 return 0; /* error! */
1959 if (target == GLX_TEXTURE_1D_EXT) {
1960 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1961 &value, GL_TRUE) != Success
1962 || (value & GLX_TEXTURE_1D_BIT_EXT) == 0) {
1963 return 0; /* error! */
1966 else if (target == GLX_TEXTURE_2D_EXT) {
1967 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1968 &value, GL_TRUE) != Success
1969 || (value & GLX_TEXTURE_2D_BIT_EXT) == 0) {
1970 return 0; /* error! */
1973 if (target == GLX_TEXTURE_RECTANGLE_EXT) {
1974 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1975 &value, GL_TRUE) != Success
1976 || (value & GLX_TEXTURE_RECTANGLE_BIT_EXT) == 0) {
1977 return 0; /* error! */
1981 if (format || target || mipmap) {
1982 /* texture from pixmap */
1983 b = XMesaCreatePixmapTextureBuffer(v, pixmap, 0, format, target, mipmap);
1986 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1997 glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
1999 XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable)pixmap);
2001 XMesaDestroyBuffer(b);
2002 /* don't destroy X pixmap */
2007 glXCreatePbuffer(Display *dpy, GLXFBConfig config, const int *attribList)
2009 XMesaVisual xmvis = (XMesaVisual) config;
2012 int width = 0, height = 0;
2013 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2017 for (attrib = attribList; *attrib; attrib++) {
2019 case GLX_PBUFFER_WIDTH:
2023 case GLX_PBUFFER_HEIGHT:
2027 case GLX_PRESERVED_CONTENTS:
2029 preserveContents = *attrib;
2031 case GLX_LARGEST_PBUFFER:
2033 useLargest = *attrib;
2040 if (width == 0 || height == 0)
2043 if (width > PBUFFER_MAX_SIZE || height > PBUFFER_MAX_SIZE) {
2044 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2045 * allocate the largest possible buffer.
2048 width = PBUFFER_MAX_SIZE;
2049 height = PBUFFER_MAX_SIZE;
2053 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2054 /* A GLXPbuffer handle must be an X Drawable because that's what
2055 * glXMakeCurrent takes.
2058 xmbuf->largestPbuffer = useLargest;
2059 xmbuf->preservedContents = preserveContents;
2060 return (GLXPbuffer) xmbuf->ws.drawable;
2069 glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2071 XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2073 XMesaDestroyBuffer(b);
2079 glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute,
2080 unsigned int *value)
2082 GLuint width, height;
2083 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2087 /* make sure buffer's dimensions are up to date */
2088 xmesa_get_window_size(dpy, xmbuf, &width, &height);
2090 switch (attribute) {
2097 case GLX_PRESERVED_CONTENTS:
2098 *value = xmbuf->preservedContents;
2100 case GLX_LARGEST_PBUFFER:
2101 *value = xmbuf->largestPbuffer;
2103 case GLX_FBCONFIG_ID:
2104 *value = xmbuf->xm_visual->visinfo->visualid;
2106 #ifdef GLX_EXT_texture_from_pixmap
2107 case GLX_TEXTURE_FORMAT_EXT:
2108 *value = xmbuf->TextureFormat;
2110 case GLX_TEXTURE_TARGET_EXT:
2111 *value = xmbuf->TextureTarget;
2113 case GLX_MIPMAP_TEXTURE_EXT:
2114 *value = xmbuf->TextureMipmap;
2119 return; /* raise BadValue error */
2125 glXCreateNewContext( Display *dpy, GLXFBConfig config,
2126 int renderType, GLXContext shareCtx, Bool direct )
2128 XMesaVisual xmvis = (XMesaVisual) config;
2130 if (!dpy || !config ||
2131 (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2134 return create_context(dpy, xmvis,
2135 shareCtx ? shareCtx->xmesaContext : NULL,
2137 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0x0);
2142 glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2144 GLXContext glxCtx = ctx;
2145 XMesaContext xmctx = glxCtx->xmesaContext;
2150 switch (attribute) {
2151 case GLX_FBCONFIG_ID:
2152 *value = xmctx->xm_visual->visinfo->visualid;
2154 case GLX_RENDER_TYPE:
2155 if (xmctx->xm_visual->mesa_visual.rgbMode)
2156 *value = GLX_RGBA_TYPE;
2158 *value = GLX_COLOR_INDEX_TYPE;
2164 return GLX_BAD_ATTRIBUTE;
2171 glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2173 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2175 xmbuf->selectedEvents = mask;
2180 glXGetSelectedEvent(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2182 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2184 *mask = xmbuf->selectedEvents;
2191 /*** GLX_SGI_swap_control ***/
2194 glXSwapIntervalSGI(int interval)
2202 /*** GLX_SGI_video_sync ***/
2204 static unsigned int FrameCounter = 0;
2207 glXGetVideoSyncSGI(unsigned int *count)
2209 /* this is a bogus implementation */
2210 *count = FrameCounter++;
2215 glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2217 if (divisor <= 0 || remainder < 0)
2218 return GLX_BAD_VALUE;
2219 /* this is a bogus implementation */
2221 while (FrameCounter % divisor != remainder)
2223 *count = FrameCounter;
2229 /*** GLX_SGI_make_current_read ***/
2232 glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read,
2235 return glXMakeContextCurrent( dpy, draw, read, ctx );
2240 glXGetCurrentReadDrawableSGI(void)
2247 /*** GLX_SGIX_video_source ***/
2250 PUBLIC GLXVideoSourceSGIX
2251 glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server,
2252 VLPath path, int nodeClass, VLNode drainNode)
2264 glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2273 /*** GLX_EXT_import_context ***/
2276 glXFreeContextEXT(Display *dpy, GLXContext context)
2283 glXGetContextIDEXT(const GLXContext context)
2290 glXImportContextEXT(Display *dpy, GLXContextID contextID)
2298 glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute,
2310 /*** GLX_SGIX_fbconfig ***/
2313 glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config,
2314 int attribute, int *value)
2316 return glXGetFBConfigAttrib(dpy, config, attribute, value);
2319 PUBLIC GLXFBConfigSGIX *
2320 glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list,
2323 return (GLXFBConfig *) glXChooseFBConfig(dpy, screen,
2324 attrib_list, nelements);
2329 glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config,
2332 XMesaVisual xmvis = (XMesaVisual) config;
2333 XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
2334 return xmbuf->ws.drawable; /* need to return an X ID */
2339 glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config,
2340 int renderType, GLXContext shareCtx,
2343 XMesaVisual xmvis = (XMesaVisual) config;
2345 if (!dpy || !config ||
2346 (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2349 return create_context(dpy, xmvis,
2350 shareCtx ? shareCtx->xmesaContext : NULL,
2352 1, 0, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, 0x0);
2356 PUBLIC XVisualInfo *
2357 glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2359 return glXGetVisualFromFBConfig(dpy, config);
2363 PUBLIC GLXFBConfigSGIX
2364 glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2366 XMesaVisual xmvis = find_glx_visual(dpy, vis);
2368 /* This visual wasn't found with glXChooseVisual() */
2369 xmvis = create_glx_visual(dpy, vis);
2372 return (GLXFBConfigSGIX) xmvis;
2377 /*** GLX_SGIX_pbuffer ***/
2379 PUBLIC GLXPbufferSGIX
2380 glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
2381 unsigned int width, unsigned int height,
2384 XMesaVisual xmvis = (XMesaVisual) config;
2387 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2391 for (attrib = attribList; attrib && *attrib; attrib++) {
2393 case GLX_PRESERVED_CONTENTS_SGIX:
2395 preserveContents = *attrib; /* ignored */
2397 case GLX_LARGEST_PBUFFER_SGIX:
2399 useLargest = *attrib; /* ignored */
2406 /* not used at this time */
2408 (void) preserveContents;
2410 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2411 /* A GLXPbuffer handle must be an X Drawable because that's what
2412 * glXMakeCurrent takes.
2414 return (GLXPbuffer) xmbuf->ws.drawable;
2419 glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2421 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2423 XMesaDestroyBuffer(xmbuf);
2429 glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute,
2430 unsigned int *value)
2432 const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2435 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2439 switch (attribute) {
2440 case GLX_PRESERVED_CONTENTS_SGIX:
2443 case GLX_LARGEST_PBUFFER_SGIX:
2444 *value = xmesa_buffer_width(xmbuf) * xmesa_buffer_height(xmbuf);
2446 case GLX_WIDTH_SGIX:
2447 *value = xmesa_buffer_width(xmbuf);
2449 case GLX_HEIGHT_SGIX:
2450 *value = xmesa_buffer_height(xmbuf);
2452 case GLX_EVENT_MASK_SGIX:
2453 *value = 0; /* XXX might be wrong */
2463 glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2465 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2467 /* Note: we'll never generate clobber events */
2468 xmbuf->selectedEvents = mask;
2474 glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable,
2475 unsigned long *mask)
2477 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2479 *mask = xmbuf->selectedEvents;
2488 /*** GLX_SGI_cushion ***/
2491 glXCushionSGI(Display *dpy, Window win, float cushion)
2500 /*** GLX_SGIX_video_resize ***/
2503 glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel,
2514 glXChannelRectSGIX(Display *dpy, int screen, int channel,
2515 int x, int y, int w, int h)
2528 glXQueryChannelRectSGIX(Display *dpy, int screen, int channel,
2529 int *x, int *y, int *w, int *h)
2542 glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel,
2543 int *dx, int *dy, int *dw, int *dh)
2556 glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2567 /*** GLX_SGIX_dmbuffer **/
2569 #if defined(_DM_BUFFER_H_)
2571 glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer,
2572 DMparams *params, DMbuffer dmbuffer)
2583 /*** GLX_SGIX_swap_group ***/
2586 glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2595 /*** GLX_SGIX_swap_barrier ***/
2598 glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2606 glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2616 /*** GLX_SUN_get_transparent_index ***/
2619 glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay,
2625 (void) pTransparent;
2631 /*** GLX_MESA_release_buffers ***/
2634 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2635 * (a window or pixmap) prior to destroying the GLXDrawable.
2638 glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2640 XMesaBuffer b = XMesaFindBuffer(dpy, d);
2642 XMesaDestroyBuffer(b);
2648 /*** GLX_EXT_texture_from_pixmap ***/
2651 glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer,
2652 const int *attrib_list)
2654 XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2656 XMesaBindTexImage(dpy, b, buffer, attrib_list);
2660 glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer)
2662 XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2664 XMesaReleaseTexImage(dpy, b, buffer);
2669 /*** GLX_ARB_create_context ***/
2672 glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config,
2673 GLXContext shareCtx, Bool direct,
2674 const int *attrib_list)
2676 XMesaVisual xmvis = (XMesaVisual) config;
2677 int majorVersion = 1, minorVersion = 0;
2678 int contextFlags = 0x0;
2679 int profileMask = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
2680 int renderType = GLX_RGBA_TYPE;
2683 const int contextFlagsAll = (GLX_CONTEXT_DEBUG_BIT_ARB |
2684 GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
2686 /* parse attrib_list */
2687 for (i = 0; !done && attrib_list && attrib_list[i]; i++) {
2688 switch (attrib_list[i]) {
2689 case GLX_CONTEXT_MAJOR_VERSION_ARB:
2690 majorVersion = attrib_list[++i];
2692 case GLX_CONTEXT_MINOR_VERSION_ARB:
2693 minorVersion = attrib_list[++i];
2695 case GLX_CONTEXT_FLAGS_ARB:
2696 contextFlags = attrib_list[++i];
2698 case GLX_CONTEXT_PROFILE_MASK_ARB:
2699 profileMask = attrib_list[++i];
2701 case GLX_RENDER_TYPE:
2702 renderType = attrib_list[++i];
2710 /* XXX generate BadValue X Error */
2715 /* check contextFlags */
2716 if (contextFlags & ~contextFlagsAll) {
2717 return NULL; /* generate BadValue X Error */
2720 /* check profileMask */
2721 if (profileMask != GLX_CONTEXT_CORE_PROFILE_BIT_ARB &&
2722 profileMask != GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) {
2723 return NULL; /* generate BadValue X Error */
2726 /* check version (generate BadMatch if bad) */
2727 switch (majorVersion) {
2729 if (minorVersion < 0 || minorVersion > 5)
2733 if (minorVersion < 0 || minorVersion > 1)
2737 if (minorVersion < 0 || minorVersion > 2)
2741 if (minorVersion < 0 || minorVersion > 0)
2748 if ((contextFlags & GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) &&
2750 return NULL; /* generate GLXBadProfileARB */
2752 if (renderType == GLX_COLOR_INDEX_TYPE && majorVersion >= 3)
2753 return NULL; /* generate BadMatch */
2755 return create_context(dpy, xmvis,
2756 shareCtx ? shareCtx->xmesaContext : NULL,
2758 majorVersion, minorVersion,
2759 profileMask, contextFlags);