Merge branch 'mesa_7_6_branch'
[mesa.git] / src / gallium / state_trackers / glx / xlib / glx_api.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.6
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * "Fake" GLX API implemented in terms of the XMesa*() functions.
29 */
30
31
32
33 #define GLX_GLXEXT_PROTOTYPES
34 #include "GL/glx.h"
35
36 #include "xm_api.h"
37 #include "main/context.h"
38 #include "main/config.h"
39 #include "main/macros.h"
40 #include "main/imports.h"
41 #include "main/version.h"
42 #include "state_tracker/st_context.h"
43 #include "state_tracker/st_public.h"
44
45
46 /* This indicates the client-side GLX API and GLX encoder version. */
47 #define CLIENT_MAJOR_VERSION 1
48 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
49
50 /* This indicates the server-side GLX decoder version.
51 * GLX 1.4 indicates OpenGL 1.3 support
52 */
53 #define SERVER_MAJOR_VERSION 1
54 #define SERVER_MINOR_VERSION 4
55
56 /* This is appended onto the glXGetClient/ServerString version strings. */
57 #define MESA_GLX_VERSION "Mesa " MESA_VERSION_STRING
58
59 /* Who implemented this GLX? */
60 #define VENDOR "Brian Paul"
61
62 #define EXTENSIONS \
63 "GLX_MESA_copy_sub_buffer " \
64 "GLX_MESA_pixmap_colormap " \
65 "GLX_MESA_release_buffers " \
66 "GLX_ARB_get_proc_address " \
67 "GLX_EXT_texture_from_pixmap " \
68 "GLX_EXT_visual_info " \
69 "GLX_EXT_visual_rating " \
70 /*"GLX_SGI_video_sync "*/ \
71 "GLX_SGIX_fbconfig " \
72 "GLX_SGIX_pbuffer "
73
74 #define DEFAULT_DIRECT GL_TRUE
75
76
77
78 /**
79 * The GLXContext typedef is defined as a pointer to this structure.
80 */
81 struct __GLXcontextRec
82 {
83 Display *currentDpy;
84 GLboolean isDirect;
85 GLXDrawable currentDrawable;
86 GLXDrawable currentReadable;
87 XID xid;
88
89 XMesaContext xmesaContext;
90 };
91
92
93
94 static pipe_tsd ContextTSD;
95
96 /** Set current context for calling thread */
97 static void
98 SetCurrentContext(GLXContext c)
99 {
100 pipe_tsd_set(&ContextTSD, c);
101 }
102
103 /** Get current context for calling thread */
104 static GLXContext
105 GetCurrentContext(void)
106 {
107 return pipe_tsd_get(&ContextTSD);
108 }
109
110
111
112 /**********************************************************************/
113 /*** GLX Visual Code ***/
114 /**********************************************************************/
115
116 #define DONT_CARE -1
117
118
119 static XMesaVisual *VisualTable = NULL;
120 static int NumVisuals = 0;
121
122
123
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
127 #else
128 #define CLASS class
129 #endif
130
131
132
133 /*
134 * Test if the given XVisualInfo is usable for Mesa rendering.
135 */
136 static GLboolean
137 is_usable_visual( XVisualInfo *vinfo )
138 {
139 switch (vinfo->CLASS) {
140 case StaticGray:
141 case GrayScale:
142 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
143 return GL_TRUE;
144 case StaticColor:
145 case PseudoColor:
146 /* Any StaticColor/PseudoColor visual of at least 4 bits */
147 if (vinfo->depth>=4) {
148 return GL_TRUE;
149 }
150 else {
151 return GL_FALSE;
152 }
153 case TrueColor:
154 case DirectColor:
155 /* Any depth of TrueColor or DirectColor works in RGB mode */
156 return GL_TRUE;
157 default:
158 /* This should never happen */
159 return GL_FALSE;
160 }
161 }
162
163
164 /*
165 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
166 * configuration in our list of GLX visuals.
167 */
168 static XMesaVisual
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 )
176 {
177 GLboolean ximageFlag = GL_TRUE;
178 XMesaVisual xmvis;
179 GLint i;
180 GLboolean comparePointers;
181
182 if (dbFlag) {
183 /* Check if the MESA_BACK_BUFFER env var is set */
184 char *backbuffer = _mesa_getenv("MESA_BACK_BUFFER");
185 if (backbuffer) {
186 if (backbuffer[0]=='p' || backbuffer[0]=='P') {
187 ximageFlag = GL_FALSE;
188 }
189 else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
190 ximageFlag = GL_TRUE;
191 }
192 else {
193 _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
194 }
195 }
196 }
197
198 if (stereoFlag) {
199 /* stereo not supported */
200 return NULL;
201 }
202
203 if (stencil_size > 0 && depth_size > 0)
204 depth_size = 24;
205
206 /* Comparing IDs uses less memory but sometimes fails. */
207 /* XXX revisit this after 3.0 is finished. */
208 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
209 comparePointers = GL_TRUE;
210 else
211 comparePointers = GL_FALSE;
212
213 /* Force the visual to have an alpha channel */
214 if (rgbFlag && _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
215 alphaFlag = GL_TRUE;
216
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)) {
237 return v;
238 }
239 }
240 }
241
242 /* Create a new visual and add it to the list. */
243
244 xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag,
245 stereoFlag, ximageFlag,
246 depth_size, stencil_size,
247 accumRedSize, accumBlueSize,
248 accumBlueSize, accumAlphaSize, 0, level,
249 GLX_NONE_EXT );
250 if (xmvis) {
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().
253 */
254 xmvis->vishandle = vinfo;
255 /* Allocate more space for additional visual */
256 VisualTable = (XMesaVisual *) _mesa_realloc( VisualTable,
257 sizeof(XMesaVisual) * NumVisuals,
258 sizeof(XMesaVisual) * (NumVisuals + 1));
259 /* add xmvis to the list */
260 VisualTable[NumVisuals] = xmvis;
261 NumVisuals++;
262 /* XXX minor hack, because XMesaCreateVisual doesn't support an
263 * aux buffers parameter.
264 */
265 xmvis->mesa_visual.numAuxBuffers = numAuxBuffers;
266 }
267 return xmvis;
268 }
269
270
271 /**
272 * Return the default number of bits for the Z buffer.
273 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
274 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
275 * XXX probably do the same thing for stencil, accum, etc.
276 */
277 static GLint
278 default_depth_bits(void)
279 {
280 int zBits;
281 const char *zEnv = _mesa_getenv("MESA_GLX_DEPTH_BITS");
282 if (zEnv)
283 zBits = _mesa_atoi(zEnv);
284 else
285 zBits = DEFAULT_SOFTWARE_DEPTH_BITS;
286 return zBits;
287 }
288
289 static GLint
290 default_alpha_bits(void)
291 {
292 int aBits;
293 const char *aEnv = _mesa_getenv("MESA_GLX_ALPHA_BITS");
294 if (aEnv)
295 aBits = _mesa_atoi(aEnv);
296 else
297 aBits = 0;
298 return aBits;
299 }
300
301 static GLint
302 default_accum_bits(void)
303 {
304 return 16;
305 }
306
307
308
309 /*
310 * Create a GLX visual from a regular XVisualInfo.
311 * This is called when Fake GLX is given an XVisualInfo which wasn't
312 * returned by glXChooseVisual. Since this is the first time we're
313 * considering this visual we'll take a guess at reasonable values
314 * for depth buffer size, stencil size, accum size, etc.
315 * This is the best we can do with a client-side emulation of GLX.
316 */
317 static XMesaVisual
318 create_glx_visual( Display *dpy, XVisualInfo *visinfo )
319 {
320 GLint zBits = default_depth_bits();
321 GLint accBits = default_accum_bits();
322 GLboolean alphaFlag = default_alpha_bits() > 0;
323
324 if (is_usable_visual( visinfo )) {
325 /* Configure this visual as RGB, double-buffered, depth-buffered. */
326 /* This is surely wrong for some people's needs but what else */
327 /* can be done? They should use glXChooseVisual(). */
328 return save_glx_visual( dpy, visinfo,
329 GL_TRUE, /* rgb */
330 alphaFlag, /* alpha */
331 GL_TRUE, /* double */
332 GL_FALSE, /* stereo */
333 zBits,
334 STENCIL_BITS,
335 accBits, /* r */
336 accBits, /* g */
337 accBits, /* b */
338 accBits, /* a */
339 0, /* level */
340 0 /* numAux */
341 );
342 }
343 else {
344 _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
345 return NULL;
346 }
347 }
348
349
350
351 /*
352 * Find the GLX visual associated with an XVisualInfo.
353 */
354 static XMesaVisual
355 find_glx_visual( Display *dpy, XVisualInfo *vinfo )
356 {
357 int i;
358
359 /* try to match visual id */
360 for (i=0;i<NumVisuals;i++) {
361 if (VisualTable[i]->display==dpy
362 && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
363 return VisualTable[i];
364 }
365 }
366
367 /* if that fails, try to match pointers */
368 for (i=0;i<NumVisuals;i++) {
369 if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {
370 return VisualTable[i];
371 }
372 }
373
374 return NULL;
375 }
376
377
378 /**
379 * Try to get an X visual which matches the given arguments.
380 */
381 static XVisualInfo *
382 get_visual( Display *dpy, int scr, unsigned int depth, int xclass )
383 {
384 XVisualInfo temp, *vis;
385 long mask;
386 int n;
387 unsigned int default_depth;
388 int default_class;
389
390 mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
391 temp.screen = scr;
392 temp.depth = depth;
393 temp.CLASS = xclass;
394
395 default_depth = DefaultDepth(dpy,scr);
396 default_class = DefaultVisual(dpy,scr)->CLASS;
397
398 if (depth==default_depth && xclass==default_class) {
399 /* try to get root window's visual */
400 temp.visualid = DefaultVisual(dpy,scr)->visualid;
401 mask |= VisualIDMask;
402 }
403
404 vis = XGetVisualInfo( dpy, mask, &temp, &n );
405
406 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
407 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
408 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
409 */
410 if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
411 if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&
412 _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&
413 _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {
414 return vis;
415 }
416 else {
417 XFree((void *) vis);
418 return NULL;
419 }
420 }
421
422 return vis;
423 }
424
425
426 /*
427 * Retrieve the value of the given environment variable and find
428 * the X visual which matches it.
429 * Input: dpy - the display
430 * screen - the screen number
431 * varname - the name of the environment variable
432 * Return: an XVisualInfo pointer to NULL if error.
433 */
434 static XVisualInfo *
435 get_env_visual(Display *dpy, int scr, const char *varname)
436 {
437 char value[100], type[100];
438 int depth, xclass = -1;
439 XVisualInfo *vis;
440
441 if (!_mesa_getenv( varname )) {
442 return NULL;
443 }
444
445 _mesa_strncpy( value, _mesa_getenv(varname), 100 );
446 value[99] = 0;
447
448 sscanf( value, "%s %d", type, &depth );
449
450 if (_mesa_strcmp(type,"TrueColor")==0) xclass = TrueColor;
451 else if (_mesa_strcmp(type,"DirectColor")==0) xclass = DirectColor;
452 else if (_mesa_strcmp(type,"PseudoColor")==0) xclass = PseudoColor;
453 else if (_mesa_strcmp(type,"StaticColor")==0) xclass = StaticColor;
454 else if (_mesa_strcmp(type,"GrayScale")==0) xclass = GrayScale;
455 else if (_mesa_strcmp(type,"StaticGray")==0) xclass = StaticGray;
456
457 if (xclass>-1 && depth>0) {
458 vis = get_visual( dpy, scr, depth, xclass );
459 if (vis) {
460 return vis;
461 }
462 }
463
464 _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",
465 type, depth);
466
467 return NULL;
468 }
469
470
471
472 /*
473 * Select an X visual which satisfies the RGBA flag and minimum depth.
474 * Input: dpy,
475 * screen - X display and screen number
476 * min_depth - minimum visual depth
477 * preferred_class - preferred GLX visual class or DONT_CARE
478 * Return: pointer to an XVisualInfo or NULL.
479 */
480 static XVisualInfo *
481 choose_x_visual( Display *dpy, int screen, int min_depth,
482 int preferred_class )
483 {
484 XVisualInfo *vis;
485 int xclass, visclass = 0;
486 int depth;
487
488 /* First see if the MESA_RGB_VISUAL env var is defined */
489 vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
490 if (vis) {
491 return vis;
492 }
493 /* Otherwise, search for a suitable visual */
494 if (preferred_class==DONT_CARE) {
495 for (xclass=0;xclass<6;xclass++) {
496 switch (xclass) {
497 case 0: visclass = TrueColor; break;
498 case 1: visclass = DirectColor; break;
499 case 2: visclass = PseudoColor; break;
500 case 3: visclass = StaticColor; break;
501 case 4: visclass = GrayScale; break;
502 case 5: visclass = StaticGray; break;
503 }
504 if (min_depth==0) {
505 /* start with shallowest */
506 for (depth=0;depth<=32;depth++) {
507 if (visclass==TrueColor && depth==8) {
508 /* Special case: try to get 8-bit PseudoColor before */
509 /* 8-bit TrueColor */
510 vis = get_visual( dpy, screen, 8, PseudoColor );
511 if (vis) {
512 return vis;
513 }
514 }
515 vis = get_visual( dpy, screen, depth, visclass );
516 if (vis) {
517 return vis;
518 }
519 }
520 }
521 else {
522 /* start with deepest */
523 for (depth=32;depth>=min_depth;depth--) {
524 if (visclass==TrueColor && depth==8) {
525 /* Special case: try to get 8-bit PseudoColor before */
526 /* 8-bit TrueColor */
527 vis = get_visual( dpy, screen, 8, PseudoColor );
528 if (vis) {
529 return vis;
530 }
531 }
532 vis = get_visual( dpy, screen, depth, visclass );
533 if (vis) {
534 return vis;
535 }
536 }
537 }
538 }
539 }
540 else {
541 /* search for a specific visual class */
542 switch (preferred_class) {
543 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
544 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
545 case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break;
546 case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break;
547 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
548 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
549 default: return NULL;
550 }
551 if (min_depth==0) {
552 /* start with shallowest */
553 for (depth=0;depth<=32;depth++) {
554 vis = get_visual( dpy, screen, depth, visclass );
555 if (vis) {
556 return vis;
557 }
558 }
559 }
560 else {
561 /* start with deepest */
562 for (depth=32;depth>=min_depth;depth--) {
563 vis = get_visual( dpy, screen, depth, visclass );
564 if (vis) {
565 return vis;
566 }
567 }
568 }
569 }
570
571 /* didn't find a visual */
572 return NULL;
573 }
574
575
576
577
578 /**********************************************************************/
579 /*** Display-related functions ***/
580 /**********************************************************************/
581
582
583 /**
584 * Free all XMesaVisuals which are associated with the given display.
585 */
586 static void
587 destroy_visuals_on_display(Display *dpy)
588 {
589 int i;
590 for (i = 0; i < NumVisuals; i++) {
591 if (VisualTable[i]->display == dpy) {
592 /* remove this visual */
593 int j;
594 free(VisualTable[i]);
595 for (j = i; j < NumVisuals - 1; j++)
596 VisualTable[j] = VisualTable[j + 1];
597 NumVisuals--;
598 }
599 }
600 }
601
602
603 /**
604 * Called from XCloseDisplay() to let us free our display-related data.
605 */
606 static int
607 close_display_callback(Display *dpy, XExtCodes *codes)
608 {
609 destroy_visuals_on_display(dpy);
610 xmesa_destroy_buffers_on_display(dpy);
611 return 0;
612 }
613
614
615 /**
616 * Look for the named extension on given display and return a pointer
617 * to the _XExtension data, or NULL if extension not found.
618 */
619 static _XExtension *
620 lookup_extension(Display *dpy, const char *extName)
621 {
622 _XExtension *ext;
623 for (ext = dpy->ext_procs; ext; ext = ext->next) {
624 if (ext->name && strcmp(ext->name, extName) == 0) {
625 return ext;
626 }
627 }
628 return NULL;
629 }
630
631
632 /**
633 * Whenever we're given a new Display pointer, call this function to
634 * register our close_display_callback function.
635 */
636 static void
637 register_with_display(Display *dpy)
638 {
639 const char *extName = "MesaGLX";
640 _XExtension *ext;
641
642 ext = lookup_extension(dpy, extName);
643 if (!ext) {
644 XExtCodes *c = XAddExtension(dpy);
645 ext = dpy->ext_procs; /* new extension is at head of list */
646 assert(c->extension == ext->codes.extension);
647 ext->name = _mesa_strdup(extName);
648 ext->close_display = close_display_callback;
649 }
650 }
651
652
653 /**********************************************************************/
654 /*** Begin Fake GLX API Functions ***/
655 /**********************************************************************/
656
657
658 /**
659 * Helper used by glXChooseVisual and glXChooseFBConfig.
660 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
661 * the later.
662 * In either case, the attribute list is terminated with the value 'None'.
663 */
664 static XMesaVisual
665 choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
666 {
667 const GLboolean rgbModeDefault = fbConfig;
668 const int *parselist;
669 XVisualInfo *vis;
670 int min_ci = 0;
671 int min_red=0, min_green=0, min_blue=0;
672 GLboolean rgb_flag = rgbModeDefault;
673 GLboolean alpha_flag = GL_FALSE;
674 GLboolean double_flag = GL_FALSE;
675 GLboolean stereo_flag = GL_FALSE;
676 GLint depth_size = 0;
677 GLint stencil_size = 0;
678 GLint accumRedSize = 0;
679 GLint accumGreenSize = 0;
680 GLint accumBlueSize = 0;
681 GLint accumAlphaSize = 0;
682 int level = 0;
683 int visual_type = DONT_CARE;
684 int trans_type = DONT_CARE;
685 int trans_value = DONT_CARE;
686 GLint caveat = DONT_CARE;
687 XMesaVisual xmvis = NULL;
688 int desiredVisualID = -1;
689 int numAux = 0;
690
691 parselist = list;
692
693 while (*parselist) {
694
695 switch (*parselist) {
696 case GLX_USE_GL:
697 if (fbConfig) {
698 /* invalid token */
699 return NULL;
700 }
701 else {
702 /* skip */
703 parselist++;
704 }
705 break;
706 case GLX_BUFFER_SIZE:
707 parselist++;
708 min_ci = *parselist++;
709 break;
710 case GLX_LEVEL:
711 parselist++;
712 level = *parselist++;
713 break;
714 case GLX_RGBA:
715 if (fbConfig) {
716 /* invalid token */
717 return NULL;
718 }
719 else {
720 rgb_flag = GL_TRUE;
721 parselist++;
722 }
723 break;
724 case GLX_DOUBLEBUFFER:
725 parselist++;
726 if (fbConfig) {
727 double_flag = *parselist++;
728 }
729 else {
730 double_flag = GL_TRUE;
731 }
732 break;
733 case GLX_STEREO:
734 parselist++;
735 if (fbConfig) {
736 stereo_flag = *parselist++;
737 }
738 else {
739 stereo_flag = GL_TRUE;
740 }
741 break;
742 case GLX_AUX_BUFFERS:
743 parselist++;
744 numAux = *parselist++;
745 if (numAux > MAX_AUX_BUFFERS)
746 return NULL;
747 break;
748 case GLX_RED_SIZE:
749 parselist++;
750 min_red = *parselist++;
751 break;
752 case GLX_GREEN_SIZE:
753 parselist++;
754 min_green = *parselist++;
755 break;
756 case GLX_BLUE_SIZE:
757 parselist++;
758 min_blue = *parselist++;
759 break;
760 case GLX_ALPHA_SIZE:
761 parselist++;
762 {
763 GLint size = *parselist++;
764 alpha_flag = size ? GL_TRUE : GL_FALSE;
765 }
766 break;
767 case GLX_DEPTH_SIZE:
768 parselist++;
769 depth_size = *parselist++;
770 break;
771 case GLX_STENCIL_SIZE:
772 parselist++;
773 stencil_size = *parselist++;
774 break;
775 case GLX_ACCUM_RED_SIZE:
776 parselist++;
777 {
778 GLint size = *parselist++;
779 accumRedSize = MAX2( accumRedSize, size );
780 }
781 break;
782 case GLX_ACCUM_GREEN_SIZE:
783 parselist++;
784 {
785 GLint size = *parselist++;
786 accumGreenSize = MAX2( accumGreenSize, size );
787 }
788 break;
789 case GLX_ACCUM_BLUE_SIZE:
790 parselist++;
791 {
792 GLint size = *parselist++;
793 accumBlueSize = MAX2( accumBlueSize, size );
794 }
795 break;
796 case GLX_ACCUM_ALPHA_SIZE:
797 parselist++;
798 {
799 GLint size = *parselist++;
800 accumAlphaSize = MAX2( accumAlphaSize, size );
801 }
802 break;
803
804 /*
805 * GLX_EXT_visual_info extension
806 */
807 case GLX_X_VISUAL_TYPE_EXT:
808 parselist++;
809 visual_type = *parselist++;
810 break;
811 case GLX_TRANSPARENT_TYPE_EXT:
812 parselist++;
813 trans_type = *parselist++;
814 break;
815 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
816 parselist++;
817 trans_value = *parselist++;
818 break;
819 case GLX_TRANSPARENT_RED_VALUE_EXT:
820 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
821 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
822 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
823 /* ignore */
824 parselist++;
825 parselist++;
826 break;
827
828 /*
829 * GLX_EXT_visual_info extension
830 */
831 case GLX_VISUAL_CAVEAT_EXT:
832 parselist++;
833 caveat = *parselist++; /* ignored for now */
834 break;
835
836 /*
837 * GLX_ARB_multisample
838 */
839 case GLX_SAMPLE_BUFFERS_ARB:
840 /* ms not supported */
841 return NULL;
842 case GLX_SAMPLES_ARB:
843 /* ms not supported */
844 return NULL;
845
846 /*
847 * FBConfig attribs.
848 */
849 case GLX_RENDER_TYPE:
850 if (!fbConfig)
851 return NULL;
852 parselist++;
853 if (*parselist & GLX_RGBA_BIT) {
854 rgb_flag = GL_TRUE;
855 }
856 else if (*parselist & GLX_COLOR_INDEX_BIT) {
857 rgb_flag = GL_FALSE;
858 }
859 else if (*parselist == 0) {
860 rgb_flag = GL_TRUE;
861 }
862 parselist++;
863 break;
864 case GLX_DRAWABLE_TYPE:
865 if (!fbConfig)
866 return NULL;
867 parselist++;
868 if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) {
869 return NULL; /* bad bit */
870 }
871 parselist++;
872 break;
873 case GLX_FBCONFIG_ID:
874 if (!fbConfig)
875 return NULL;
876 parselist++;
877 desiredVisualID = *parselist++;
878 break;
879 case GLX_X_RENDERABLE:
880 if (!fbConfig)
881 return NULL;
882 parselist += 2;
883 /* ignore */
884 break;
885
886 #ifdef GLX_EXT_texture_from_pixmap
887 case GLX_BIND_TO_TEXTURE_RGB_EXT:
888 parselist++; /*skip*/
889 break;
890 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
891 parselist++; /*skip*/
892 break;
893 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
894 parselist++; /*skip*/
895 break;
896 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
897 parselist++;
898 if (*parselist & ~(GLX_TEXTURE_1D_BIT_EXT |
899 GLX_TEXTURE_2D_BIT_EXT |
900 GLX_TEXTURE_RECTANGLE_BIT_EXT)) {
901 /* invalid bit */
902 return NULL;
903 }
904 break;
905 case GLX_Y_INVERTED_EXT:
906 parselist++; /*skip*/
907 break;
908 #endif
909
910 case None:
911 /* end of list */
912 break;
913
914 default:
915 /* undefined attribute */
916 _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
917 *parselist);
918 return NULL;
919 }
920 }
921
922 (void) caveat;
923
924
925 /*
926 * Since we're only simulating the GLX extension this function will never
927 * find any real GL visuals. Instead, all we can do is try to find an RGB
928 * or CI visual of appropriate depth. Other requested attributes such as
929 * double buffering, depth buffer, etc. will be associated with the X
930 * visual and stored in the VisualTable[].
931 */
932 if (desiredVisualID != -1) {
933 /* try to get a specific visual, by visualID */
934 XVisualInfo temp;
935 int n;
936 temp.visualid = desiredVisualID;
937 temp.screen = screen;
938 vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n);
939 if (vis) {
940 /* give the visual some useful GLX attributes */
941 double_flag = GL_TRUE;
942 rgb_flag = GL_TRUE;
943 depth_size = default_depth_bits();
944 stencil_size = STENCIL_BITS;
945 /* XXX accum??? */
946 }
947 }
948 else if (level==0) {
949 /* normal color planes */
950 /* Get an RGB visual */
951 int min_rgb = min_red + min_green + min_blue;
952 if (min_rgb>1 && min_rgb<8) {
953 /* a special case to be sure we can get a monochrome visual */
954 min_rgb = 1;
955 }
956 vis = choose_x_visual( dpy, screen, min_rgb, visual_type );
957 }
958 else {
959 _mesa_warning(NULL, "overlay not supported");
960 return NULL;
961 }
962
963 if (vis) {
964 /* Note: we're not exactly obeying the glXChooseVisual rules here.
965 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
966 * largest depth buffer size, which is 32bits/value. Instead, we
967 * return 16 to maintain performance with earlier versions of Mesa.
968 */
969 if (stencil_size > 0)
970 depth_size = 24; /* if Z and stencil, always use 24+8 format */
971 else if (depth_size > 24)
972 depth_size = 32;
973 else if (depth_size > 16)
974 depth_size = 24;
975 else if (depth_size > 0) {
976 depth_size = default_depth_bits();
977 }
978
979 if (!alpha_flag) {
980 alpha_flag = default_alpha_bits() > 0;
981 }
982
983 /* we only support one size of stencil and accum buffers. */
984 if (stencil_size > 0)
985 stencil_size = STENCIL_BITS;
986
987 if (accumRedSize > 0 ||
988 accumGreenSize > 0 ||
989 accumBlueSize > 0 ||
990 accumAlphaSize > 0) {
991
992 accumRedSize =
993 accumGreenSize =
994 accumBlueSize = default_accum_bits();
995
996 accumAlphaSize = alpha_flag ? accumRedSize : 0;
997 }
998
999 xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
1000 stereo_flag, depth_size, stencil_size,
1001 accumRedSize, accumGreenSize,
1002 accumBlueSize, accumAlphaSize, level, numAux );
1003 }
1004
1005 return xmvis;
1006 }
1007
1008
1009 XVisualInfo *
1010 glXChooseVisual( Display *dpy, int screen, int *list )
1011 {
1012 XMesaVisual xmvis;
1013
1014 /* register ourselves as an extension on this display */
1015 register_with_display(dpy);
1016
1017 xmvis = choose_visual(dpy, screen, list, GL_FALSE);
1018 if (xmvis) {
1019 /* create a new vishandle - the cached one may be stale */
1020 xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
1021 if (xmvis->vishandle) {
1022 _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1023 }
1024 return xmvis->vishandle;
1025 }
1026 else
1027 return NULL;
1028 }
1029
1030
1031 GLXContext
1032 glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1033 GLXContext share_list, Bool direct )
1034 {
1035 XMesaVisual xmvis;
1036 GLXContext glxCtx;
1037 GLXContext shareCtx = share_list;
1038
1039 if (!dpy || !visinfo)
1040 return 0;
1041
1042 glxCtx = CALLOC_STRUCT(__GLXcontextRec);
1043 if (!glxCtx)
1044 return 0;
1045
1046 /* deallocate unused windows/buffers */
1047 #if 0
1048 XMesaGarbageCollect();
1049 #endif
1050
1051 xmvis = find_glx_visual( dpy, visinfo );
1052 if (!xmvis) {
1053 /* This visual wasn't found with glXChooseVisual() */
1054 xmvis = create_glx_visual( dpy, visinfo );
1055 if (!xmvis) {
1056 /* unusable visual */
1057 _mesa_free(glxCtx);
1058 return NULL;
1059 }
1060 }
1061
1062 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
1063 shareCtx ? shareCtx->xmesaContext : NULL);
1064 if (!glxCtx->xmesaContext) {
1065 _mesa_free(glxCtx);
1066 return NULL;
1067 }
1068
1069 glxCtx->isDirect = DEFAULT_DIRECT;
1070 glxCtx->currentDpy = dpy;
1071 glxCtx->xid = (XID) glxCtx; /* self pointer */
1072
1073 return glxCtx;
1074 }
1075
1076
1077 /* XXX these may have to be removed due to thread-safety issues. */
1078 static GLXContext MakeCurrent_PrevContext = 0;
1079 static GLXDrawable MakeCurrent_PrevDrawable = 0;
1080 static GLXDrawable MakeCurrent_PrevReadable = 0;
1081 static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1082 static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
1083
1084
1085 /* GLX 1.3 and later */
1086 Bool
1087 glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
1088 GLXDrawable read, GLXContext ctx )
1089 {
1090 GLXContext glxCtx = ctx;
1091 static boolean firsttime = 1, no_rast = 0;
1092
1093 if (firsttime) {
1094 no_rast = getenv("SP_NO_RAST") != NULL;
1095 firsttime = 0;
1096 }
1097
1098 if (ctx && draw && read) {
1099 XMesaBuffer drawBuffer, readBuffer;
1100 XMesaContext xmctx = glxCtx->xmesaContext;
1101
1102 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1103 if (ctx == MakeCurrent_PrevContext
1104 && draw == MakeCurrent_PrevDrawable) {
1105 drawBuffer = MakeCurrent_PrevDrawBuffer;
1106 }
1107 else {
1108 drawBuffer = XMesaFindBuffer( dpy, draw );
1109 }
1110 if (!drawBuffer) {
1111 /* drawable must be a new window! */
1112 drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw );
1113 if (!drawBuffer) {
1114 /* Out of memory, or context/drawable depth mismatch */
1115 return False;
1116 }
1117 }
1118
1119 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1120 if (ctx == MakeCurrent_PrevContext
1121 && read == MakeCurrent_PrevReadable) {
1122 readBuffer = MakeCurrent_PrevReadBuffer;
1123 }
1124 else {
1125 readBuffer = XMesaFindBuffer( dpy, read );
1126 }
1127 if (!readBuffer) {
1128 /* drawable must be a new window! */
1129 readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read );
1130 if (!readBuffer) {
1131 /* Out of memory, or context/drawable depth mismatch */
1132 return False;
1133 }
1134 }
1135
1136 if (no_rast &&
1137 MakeCurrent_PrevContext == ctx &&
1138 MakeCurrent_PrevDrawable == draw &&
1139 MakeCurrent_PrevReadable == read &&
1140 MakeCurrent_PrevDrawBuffer == drawBuffer &&
1141 MakeCurrent_PrevReadBuffer == readBuffer)
1142 return True;
1143
1144 MakeCurrent_PrevContext = ctx;
1145 MakeCurrent_PrevDrawable = draw;
1146 MakeCurrent_PrevReadable = read;
1147 MakeCurrent_PrevDrawBuffer = drawBuffer;
1148 MakeCurrent_PrevReadBuffer = readBuffer;
1149
1150 /* Now make current! */
1151 if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
1152 ctx->currentDpy = dpy;
1153 ctx->currentDrawable = draw;
1154 ctx->currentReadable = read;
1155 SetCurrentContext(ctx);
1156 return True;
1157 }
1158 else {
1159 return False;
1160 }
1161 }
1162 else if (!ctx && !draw && !read) {
1163 /* release current context w/out assigning new one. */
1164 XMesaMakeCurrent2( NULL, NULL, NULL );
1165 MakeCurrent_PrevContext = 0;
1166 MakeCurrent_PrevDrawable = 0;
1167 MakeCurrent_PrevReadable = 0;
1168 MakeCurrent_PrevDrawBuffer = 0;
1169 MakeCurrent_PrevReadBuffer = 0;
1170 SetCurrentContext(NULL);
1171 return True;
1172 }
1173 else {
1174 /* The args must either all be non-zero or all zero.
1175 * This is an error.
1176 */
1177 return False;
1178 }
1179 }
1180
1181
1182 Bool
1183 glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1184 {
1185 return glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1186 }
1187
1188
1189 GLXContext
1190 glXGetCurrentContext(void)
1191 {
1192 return GetCurrentContext();
1193 }
1194
1195
1196 Display *
1197 glXGetCurrentDisplay(void)
1198 {
1199 GLXContext glxCtx = glXGetCurrentContext();
1200
1201 return glxCtx ? glxCtx->currentDpy : NULL;
1202 }
1203
1204
1205 Display *
1206 glXGetCurrentDisplayEXT(void)
1207 {
1208 return glXGetCurrentDisplay();
1209 }
1210
1211
1212 GLXDrawable
1213 glXGetCurrentDrawable(void)
1214 {
1215 GLXContext gc = glXGetCurrentContext();
1216 return gc ? gc->currentDrawable : 0;
1217 }
1218
1219
1220 GLXDrawable
1221 glXGetCurrentReadDrawable(void)
1222 {
1223 GLXContext gc = glXGetCurrentContext();
1224 return gc ? gc->currentReadable : 0;
1225 }
1226
1227
1228 GLXDrawable
1229 glXGetCurrentReadDrawableSGI(void)
1230 {
1231 return glXGetCurrentReadDrawable();
1232 }
1233
1234
1235 GLXPixmap
1236 glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1237 {
1238 XMesaVisual v;
1239 XMesaBuffer b;
1240
1241 v = find_glx_visual( dpy, visinfo );
1242 if (!v) {
1243 v = create_glx_visual( dpy, visinfo );
1244 if (!v) {
1245 /* unusable visual */
1246 return 0;
1247 }
1248 }
1249
1250 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1251 if (!b) {
1252 return 0;
1253 }
1254 return b->drawable;
1255 }
1256
1257
1258 /*** GLX_MESA_pixmap_colormap ***/
1259
1260 GLXPixmap
1261 glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1262 Pixmap pixmap, Colormap cmap )
1263 {
1264 XMesaVisual v;
1265 XMesaBuffer b;
1266
1267 v = find_glx_visual( dpy, visinfo );
1268 if (!v) {
1269 v = create_glx_visual( dpy, visinfo );
1270 if (!v) {
1271 /* unusable visual */
1272 return 0;
1273 }
1274 }
1275
1276 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1277 if (!b) {
1278 return 0;
1279 }
1280 return b->drawable;
1281 }
1282
1283
1284 void
1285 glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1286 {
1287 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1288 if (b) {
1289 XMesaDestroyBuffer(b);
1290 }
1291 else if (_mesa_getenv("MESA_DEBUG")) {
1292 _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1293 }
1294 }
1295
1296
1297 void
1298 glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1299 unsigned long mask )
1300 {
1301 XMesaContext xm_src = src->xmesaContext;
1302 XMesaContext xm_dst = dst->xmesaContext;
1303 (void) dpy;
1304 if (MakeCurrent_PrevContext == src) {
1305 _mesa_Flush();
1306 }
1307 st_copy_context_state( xm_src->st, xm_dst->st, (GLuint) mask );
1308 }
1309
1310
1311 Bool
1312 glXQueryExtension( Display *dpy, int *errorBase, int *eventBase )
1313 {
1314 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1315 (void) dpy;
1316 if (errorBase)
1317 *errorBase = 0;
1318 if (eventBase)
1319 *eventBase = 0;
1320 return True;
1321 }
1322
1323
1324 void
1325 glXDestroyContext( Display *dpy, GLXContext ctx )
1326 {
1327 GLXContext glxCtx = ctx;
1328 (void) dpy;
1329 MakeCurrent_PrevContext = 0;
1330 MakeCurrent_PrevDrawable = 0;
1331 MakeCurrent_PrevReadable = 0;
1332 MakeCurrent_PrevDrawBuffer = 0;
1333 MakeCurrent_PrevReadBuffer = 0;
1334 XMesaDestroyContext( glxCtx->xmesaContext );
1335 XMesaGarbageCollect();
1336 _mesa_free(glxCtx);
1337 }
1338
1339
1340 Bool
1341 glXIsDirect( Display *dpy, GLXContext ctx )
1342 {
1343 GLXContext glxCtx = ctx;
1344 (void) ctx;
1345 return glxCtx->isDirect;
1346 }
1347
1348
1349
1350 void
1351 glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1352 {
1353 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1354 static boolean firsttime = 1, no_rast = 0;
1355
1356 if (firsttime) {
1357 no_rast = getenv("SP_NO_RAST") != NULL;
1358 firsttime = 0;
1359 }
1360
1361 if (no_rast)
1362 return;
1363
1364 if (buffer) {
1365 XMesaSwapBuffers(buffer);
1366 }
1367 else if (_mesa_getenv("MESA_DEBUG")) {
1368 _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n",
1369 (int) drawable);
1370 }
1371 }
1372
1373
1374
1375 /*** GLX_MESA_copy_sub_buffer ***/
1376
1377 void
1378 glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1379 int x, int y, int width, int height )
1380 {
1381 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1382 if (buffer) {
1383 XMesaCopySubBuffer(buffer, x, y, width, height);
1384 }
1385 else if (_mesa_getenv("MESA_DEBUG")) {
1386 _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1387 }
1388 }
1389
1390
1391 Bool
1392 glXQueryVersion( Display *dpy, int *maj, int *min )
1393 {
1394 (void) dpy;
1395 /* Return GLX version, not Mesa version */
1396 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1397 *maj = CLIENT_MAJOR_VERSION;
1398 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1399 return True;
1400 }
1401
1402
1403 /*
1404 * Query the GLX attributes of the given XVisualInfo.
1405 */
1406 static int
1407 get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
1408 {
1409 ASSERT(xmvis);
1410 switch(attrib) {
1411 case GLX_USE_GL:
1412 if (fbconfig)
1413 return GLX_BAD_ATTRIBUTE;
1414 *value = (int) True;
1415 return 0;
1416 case GLX_BUFFER_SIZE:
1417 *value = xmvis->visinfo->depth;
1418 return 0;
1419 case GLX_LEVEL:
1420 *value = xmvis->mesa_visual.level;
1421 return 0;
1422 case GLX_RGBA:
1423 if (fbconfig)
1424 return GLX_BAD_ATTRIBUTE;
1425 if (xmvis->mesa_visual.rgbMode) {
1426 *value = True;
1427 }
1428 else {
1429 *value = False;
1430 }
1431 return 0;
1432 case GLX_DOUBLEBUFFER:
1433 *value = (int) xmvis->mesa_visual.doubleBufferMode;
1434 return 0;
1435 case GLX_STEREO:
1436 *value = (int) xmvis->mesa_visual.stereoMode;
1437 return 0;
1438 case GLX_AUX_BUFFERS:
1439 *value = xmvis->mesa_visual.numAuxBuffers;
1440 return 0;
1441 case GLX_RED_SIZE:
1442 *value = xmvis->mesa_visual.redBits;
1443 return 0;
1444 case GLX_GREEN_SIZE:
1445 *value = xmvis->mesa_visual.greenBits;
1446 return 0;
1447 case GLX_BLUE_SIZE:
1448 *value = xmvis->mesa_visual.blueBits;
1449 return 0;
1450 case GLX_ALPHA_SIZE:
1451 *value = xmvis->mesa_visual.alphaBits;
1452 return 0;
1453 case GLX_DEPTH_SIZE:
1454 *value = xmvis->mesa_visual.depthBits;
1455 return 0;
1456 case GLX_STENCIL_SIZE:
1457 *value = xmvis->mesa_visual.stencilBits;
1458 return 0;
1459 case GLX_ACCUM_RED_SIZE:
1460 *value = xmvis->mesa_visual.accumRedBits;
1461 return 0;
1462 case GLX_ACCUM_GREEN_SIZE:
1463 *value = xmvis->mesa_visual.accumGreenBits;
1464 return 0;
1465 case GLX_ACCUM_BLUE_SIZE:
1466 *value = xmvis->mesa_visual.accumBlueBits;
1467 return 0;
1468 case GLX_ACCUM_ALPHA_SIZE:
1469 *value = xmvis->mesa_visual.accumAlphaBits;
1470 return 0;
1471
1472 /*
1473 * GLX_EXT_visual_info extension
1474 */
1475 case GLX_X_VISUAL_TYPE_EXT:
1476 switch (xmvis->visinfo->CLASS) {
1477 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1478 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1479 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1480 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1481 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1482 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1483 }
1484 return 0;
1485 case GLX_TRANSPARENT_TYPE_EXT:
1486 /* normal planes */
1487 *value = GLX_NONE_EXT;
1488 return 0;
1489 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1490 /* undefined */
1491 return 0;
1492 case GLX_TRANSPARENT_RED_VALUE_EXT:
1493 /* undefined */
1494 return 0;
1495 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1496 /* undefined */
1497 return 0;
1498 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1499 /* undefined */
1500 return 0;
1501 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1502 /* undefined */
1503 return 0;
1504
1505 /*
1506 * GLX_EXT_visual_info extension
1507 */
1508 case GLX_VISUAL_CAVEAT_EXT:
1509 /* test for zero, just in case */
1510 if (xmvis->mesa_visual.visualRating > 0)
1511 *value = xmvis->mesa_visual.visualRating;
1512 else
1513 *value = GLX_NONE_EXT;
1514 return 0;
1515
1516 /*
1517 * GLX_ARB_multisample
1518 */
1519 case GLX_SAMPLE_BUFFERS_ARB:
1520 *value = 0;
1521 return 0;
1522 case GLX_SAMPLES_ARB:
1523 *value = 0;
1524 return 0;
1525
1526 /*
1527 * For FBConfigs:
1528 */
1529 case GLX_SCREEN_EXT:
1530 if (!fbconfig)
1531 return GLX_BAD_ATTRIBUTE;
1532 *value = xmvis->visinfo->screen;
1533 break;
1534 case GLX_DRAWABLE_TYPE: /*SGIX too */
1535 if (!fbconfig)
1536 return GLX_BAD_ATTRIBUTE;
1537 *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
1538 break;
1539 case GLX_RENDER_TYPE_SGIX:
1540 if (!fbconfig)
1541 return GLX_BAD_ATTRIBUTE;
1542 if (xmvis->mesa_visual.rgbMode)
1543 *value = GLX_RGBA_BIT;
1544 else
1545 *value = GLX_COLOR_INDEX_BIT;
1546 break;
1547 case GLX_X_RENDERABLE_SGIX:
1548 if (!fbconfig)
1549 return GLX_BAD_ATTRIBUTE;
1550 *value = True; /* XXX really? */
1551 break;
1552 case GLX_FBCONFIG_ID_SGIX:
1553 if (!fbconfig)
1554 return GLX_BAD_ATTRIBUTE;
1555 *value = xmvis->visinfo->visualid;
1556 break;
1557 case GLX_MAX_PBUFFER_WIDTH:
1558 if (!fbconfig)
1559 return GLX_BAD_ATTRIBUTE;
1560 /* XXX or MAX_WIDTH? */
1561 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
1562 break;
1563 case GLX_MAX_PBUFFER_HEIGHT:
1564 if (!fbconfig)
1565 return GLX_BAD_ATTRIBUTE;
1566 *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1567 break;
1568 case GLX_MAX_PBUFFER_PIXELS:
1569 if (!fbconfig)
1570 return GLX_BAD_ATTRIBUTE;
1571 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1572 DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1573 break;
1574 case GLX_VISUAL_ID:
1575 if (!fbconfig)
1576 return GLX_BAD_ATTRIBUTE;
1577 *value = xmvis->visinfo->visualid;
1578 break;
1579
1580 #ifdef GLX_EXT_texture_from_pixmap
1581 case GLX_BIND_TO_TEXTURE_RGB_EXT:
1582 *value = True; /*XXX*/
1583 break;
1584 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1585 /* XXX review */
1586 *value = xmvis->mesa_visual.alphaBits > 0 ? True : False;
1587 break;
1588 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1589 *value = True; /*XXX*/
1590 break;
1591 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1592 *value = (GLX_TEXTURE_1D_BIT_EXT |
1593 GLX_TEXTURE_2D_BIT_EXT |
1594 GLX_TEXTURE_RECTANGLE_BIT_EXT); /*XXX*/
1595 break;
1596 case GLX_Y_INVERTED_EXT:
1597 *value = True; /*XXX*/
1598 break;
1599 #endif
1600
1601 default:
1602 return GLX_BAD_ATTRIBUTE;
1603 }
1604 return Success;
1605 }
1606
1607
1608 int
1609 glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1610 int attrib, int *value )
1611 {
1612 XMesaVisual xmvis;
1613 int k;
1614 if (!dpy || !visinfo)
1615 return GLX_BAD_ATTRIBUTE;
1616
1617 xmvis = find_glx_visual( dpy, visinfo );
1618 if (!xmvis) {
1619 /* this visual wasn't obtained with glXChooseVisual */
1620 xmvis = create_glx_visual( dpy, visinfo );
1621 if (!xmvis) {
1622 /* this visual can't be used for GL rendering */
1623 if (attrib==GLX_USE_GL) {
1624 *value = (int) False;
1625 return 0;
1626 }
1627 else {
1628 return GLX_BAD_VISUAL;
1629 }
1630 }
1631 }
1632
1633 k = get_config(xmvis, attrib, value, GL_FALSE);
1634 return k;
1635 }
1636
1637
1638 void
1639 glXWaitGL( void )
1640 {
1641 XMesaContext xmesa = XMesaGetCurrentContext();
1642 XMesaFlush( xmesa );
1643 }
1644
1645
1646
1647 void
1648 glXWaitX( void )
1649 {
1650 XMesaContext xmesa = XMesaGetCurrentContext();
1651 XMesaFlush( xmesa );
1652 }
1653
1654
1655 static const char *
1656 get_extensions( void )
1657 {
1658 return EXTENSIONS;
1659 }
1660
1661
1662
1663 /* GLX 1.1 and later */
1664 const char *
1665 glXQueryExtensionsString( Display *dpy, int screen )
1666 {
1667 (void) dpy;
1668 (void) screen;
1669 return get_extensions();
1670 }
1671
1672
1673
1674 /* GLX 1.1 and later */
1675 const char *
1676 glXQueryServerString( Display *dpy, int screen, int name )
1677 {
1678 static char version[1000];
1679 _mesa_sprintf(version, "%d.%d %s",
1680 SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
1681
1682 (void) dpy;
1683 (void) screen;
1684
1685 switch (name) {
1686 case GLX_EXTENSIONS:
1687 return get_extensions();
1688 case GLX_VENDOR:
1689 return VENDOR;
1690 case GLX_VERSION:
1691 return version;
1692 default:
1693 return NULL;
1694 }
1695 }
1696
1697
1698
1699 /* GLX 1.1 and later */
1700 const char *
1701 glXGetClientString( Display *dpy, int name )
1702 {
1703 static char version[1000];
1704 _mesa_sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
1705 CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
1706
1707 (void) dpy;
1708
1709 switch (name) {
1710 case GLX_EXTENSIONS:
1711 return get_extensions();
1712 case GLX_VENDOR:
1713 return VENDOR;
1714 case GLX_VERSION:
1715 return version;
1716 default:
1717 return NULL;
1718 }
1719 }
1720
1721
1722
1723 /*
1724 * GLX 1.3 and later
1725 */
1726
1727
1728 int
1729 glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
1730 int attribute, int *value )
1731 {
1732 XMesaVisual v = (XMesaVisual) config;
1733 (void) dpy;
1734 (void) config;
1735
1736 if (!dpy || !config || !value)
1737 return -1;
1738
1739 return get_config(v, attribute, value, GL_TRUE);
1740 }
1741
1742
1743 GLXFBConfig *
1744 glXGetFBConfigs( Display *dpy, int screen, int *nelements )
1745 {
1746 XVisualInfo *visuals, visTemplate;
1747 const long visMask = VisualScreenMask;
1748 int i;
1749
1750 /* Get list of all X visuals */
1751 visTemplate.screen = screen;
1752 visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
1753 if (*nelements > 0) {
1754 XMesaVisual *results;
1755 results = (XMesaVisual *) _mesa_malloc(*nelements * sizeof(XMesaVisual));
1756 if (!results) {
1757 *nelements = 0;
1758 return NULL;
1759 }
1760 for (i = 0; i < *nelements; i++) {
1761 results[i] = create_glx_visual(dpy, visuals + i);
1762 }
1763 return (GLXFBConfig *) results;
1764 }
1765 return NULL;
1766 }
1767
1768
1769 GLXFBConfig *
1770 glXChooseFBConfig( Display *dpy, int screen,
1771 const int *attribList, int *nitems )
1772 {
1773 XMesaVisual xmvis;
1774
1775 if (!attribList || !attribList[0]) {
1776 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1777 return glXGetFBConfigs(dpy, screen, nitems);
1778 }
1779
1780 xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
1781 if (xmvis) {
1782 GLXFBConfig *config = (GLXFBConfig *) _mesa_malloc(sizeof(XMesaVisual));
1783 if (!config) {
1784 *nitems = 0;
1785 return NULL;
1786 }
1787 *nitems = 1;
1788 config[0] = (GLXFBConfig) xmvis;
1789 return (GLXFBConfig *) config;
1790 }
1791 else {
1792 *nitems = 0;
1793 return NULL;
1794 }
1795 }
1796
1797
1798 XVisualInfo *
1799 glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1800 {
1801 if (dpy && config) {
1802 XMesaVisual xmvis = (XMesaVisual) config;
1803 #if 0
1804 return xmvis->vishandle;
1805 #else
1806 /* create a new vishandle - the cached one may be stale */
1807 xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
1808 if (xmvis->vishandle) {
1809 _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1810 }
1811 return xmvis->vishandle;
1812 #endif
1813 }
1814 else {
1815 return NULL;
1816 }
1817 }
1818
1819
1820 GLXWindow
1821 glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
1822 const int *attribList )
1823 {
1824 XMesaVisual xmvis = (XMesaVisual) config;
1825 XMesaBuffer xmbuf;
1826 if (!xmvis)
1827 return 0;
1828
1829 xmbuf = XMesaCreateWindowBuffer(xmvis, win);
1830 if (!xmbuf)
1831 return 0;
1832
1833 (void) dpy;
1834 (void) attribList; /* Ignored in GLX 1.3 */
1835
1836 return win; /* A hack for now */
1837 }
1838
1839
1840 void
1841 glXDestroyWindow( Display *dpy, GLXWindow window )
1842 {
1843 XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable) window);
1844 if (b)
1845 XMesaDestroyBuffer(b);
1846 /* don't destroy X window */
1847 }
1848
1849
1850 /* XXX untested */
1851 GLXPixmap
1852 glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
1853 const int *attribList )
1854 {
1855 XMesaVisual v = (XMesaVisual) config;
1856 XMesaBuffer b;
1857 const int *attr;
1858 int target = 0, format = 0, mipmap = 0;
1859 int value;
1860
1861 if (!dpy || !config || !pixmap)
1862 return 0;
1863
1864 for (attr = attribList; attr && *attr; attr++) {
1865 switch (*attr) {
1866 case GLX_TEXTURE_FORMAT_EXT:
1867 attr++;
1868 switch (*attr) {
1869 case GLX_TEXTURE_FORMAT_NONE_EXT:
1870 case GLX_TEXTURE_FORMAT_RGB_EXT:
1871 case GLX_TEXTURE_FORMAT_RGBA_EXT:
1872 format = *attr;
1873 break;
1874 default:
1875 /* error */
1876 return 0;
1877 }
1878 break;
1879 case GLX_TEXTURE_TARGET_EXT:
1880 attr++;
1881 switch (*attr) {
1882 case GLX_TEXTURE_1D_EXT:
1883 case GLX_TEXTURE_2D_EXT:
1884 case GLX_TEXTURE_RECTANGLE_EXT:
1885 target = *attr;
1886 break;
1887 default:
1888 /* error */
1889 return 0;
1890 }
1891 break;
1892 case GLX_MIPMAP_TEXTURE_EXT:
1893 attr++;
1894 if (*attr)
1895 mipmap = 1;
1896 break;
1897 default:
1898 /* error */
1899 return 0;
1900 }
1901 }
1902
1903 if (format == GLX_TEXTURE_FORMAT_RGB_EXT) {
1904 if (get_config(v, GLX_BIND_TO_TEXTURE_RGB_EXT,
1905 &value, GL_TRUE) != Success
1906 || !value) {
1907 return 0; /* error! */
1908 }
1909 }
1910 else if (format == GLX_TEXTURE_FORMAT_RGBA_EXT) {
1911 if (get_config(v, GLX_BIND_TO_TEXTURE_RGBA_EXT,
1912 &value, GL_TRUE) != Success
1913 || !value) {
1914 return 0; /* error! */
1915 }
1916 }
1917 if (mipmap) {
1918 if (get_config(v, GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
1919 &value, GL_TRUE) != Success
1920 || !value) {
1921 return 0; /* error! */
1922 }
1923 }
1924 if (target == GLX_TEXTURE_1D_EXT) {
1925 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1926 &value, GL_TRUE) != Success
1927 || (value & GLX_TEXTURE_1D_BIT_EXT) == 0) {
1928 return 0; /* error! */
1929 }
1930 }
1931 else if (target == GLX_TEXTURE_2D_EXT) {
1932 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1933 &value, GL_TRUE) != Success
1934 || (value & GLX_TEXTURE_2D_BIT_EXT) == 0) {
1935 return 0; /* error! */
1936 }
1937 }
1938 if (target == GLX_TEXTURE_RECTANGLE_EXT) {
1939 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1940 &value, GL_TRUE) != Success
1941 || (value & GLX_TEXTURE_RECTANGLE_BIT_EXT) == 0) {
1942 return 0; /* error! */
1943 }
1944 }
1945
1946 if (format || target || mipmap) {
1947 /* texture from pixmap */
1948 b = XMesaCreatePixmapTextureBuffer(v, pixmap, 0, format, target, mipmap);
1949 }
1950 else {
1951 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1952 }
1953 if (!b) {
1954 return 0;
1955 }
1956
1957 return pixmap;
1958 }
1959
1960
1961 void
1962 glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
1963 {
1964 XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable)pixmap);
1965 if (b)
1966 XMesaDestroyBuffer(b);
1967 /* don't destroy X pixmap */
1968 }
1969
1970
1971 GLXPbuffer
1972 glXCreatePbuffer( Display *dpy, GLXFBConfig config,
1973 const int *attribList )
1974 {
1975 XMesaVisual xmvis = (XMesaVisual) config;
1976 XMesaBuffer xmbuf;
1977 const int *attrib;
1978 int width = 0, height = 0;
1979 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
1980
1981 (void) dpy;
1982
1983 for (attrib = attribList; *attrib; attrib++) {
1984 switch (*attrib) {
1985 case GLX_PBUFFER_WIDTH:
1986 attrib++;
1987 width = *attrib;
1988 break;
1989 case GLX_PBUFFER_HEIGHT:
1990 attrib++;
1991 height = *attrib;
1992 break;
1993 case GLX_PRESERVED_CONTENTS:
1994 attrib++;
1995 preserveContents = *attrib;
1996 break;
1997 case GLX_LARGEST_PBUFFER:
1998 attrib++;
1999 useLargest = *attrib;
2000 break;
2001 default:
2002 return 0;
2003 }
2004 }
2005
2006 if (width == 0 || height == 0)
2007 return 0;
2008
2009 if (width > MAX_WIDTH || height > MAX_HEIGHT) {
2010 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2011 * allocate the largest possible buffer.
2012 */
2013 if (useLargest) {
2014 width = MAX_WIDTH;
2015 height = MAX_HEIGHT;
2016 }
2017 }
2018
2019 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2020 /* A GLXPbuffer handle must be an X Drawable because that's what
2021 * glXMakeCurrent takes.
2022 */
2023 if (xmbuf) {
2024 xmbuf->largestPbuffer = useLargest;
2025 xmbuf->preservedContents = preserveContents;
2026 return (GLXPbuffer) xmbuf->drawable;
2027 }
2028 else {
2029 return 0;
2030 }
2031 }
2032
2033
2034 void
2035 glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2036 {
2037 XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2038 if (b) {
2039 XMesaDestroyBuffer(b);
2040 }
2041 }
2042
2043
2044 void
2045 glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2046 unsigned int *value )
2047 {
2048 GLuint width, height;
2049 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2050 if (!xmbuf)
2051 return;
2052
2053 /* make sure buffer's dimensions are up to date */
2054 xmesa_get_window_size(dpy, xmbuf, &width, &height);
2055
2056 switch (attribute) {
2057 case GLX_WIDTH:
2058 *value = width;
2059 break;
2060 case GLX_HEIGHT:
2061 *value = height;
2062 break;
2063 case GLX_PRESERVED_CONTENTS:
2064 *value = xmbuf->preservedContents;
2065 break;
2066 case GLX_LARGEST_PBUFFER:
2067 *value = xmbuf->largestPbuffer;
2068 break;
2069 case GLX_FBCONFIG_ID:
2070 *value = xmbuf->xm_visual->visinfo->visualid;
2071 return;
2072 #ifdef GLX_EXT_texture_from_pixmap
2073 case GLX_TEXTURE_FORMAT_EXT:
2074 *value = xmbuf->TextureFormat;
2075 break;
2076 case GLX_TEXTURE_TARGET_EXT:
2077 *value = xmbuf->TextureTarget;
2078 break;
2079 case GLX_MIPMAP_TEXTURE_EXT:
2080 *value = xmbuf->TextureMipmap;
2081 break;
2082 #endif
2083
2084 default:
2085 return; /* raise BadValue error */
2086 }
2087 }
2088
2089
2090 GLXContext
2091 glXCreateNewContext( Display *dpy, GLXFBConfig config,
2092 int renderType, GLXContext shareList, Bool direct )
2093 {
2094 GLXContext glxCtx;
2095 GLXContext shareCtx = shareList;
2096 XMesaVisual xmvis = (XMesaVisual) config;
2097
2098 if (!dpy || !config ||
2099 (renderType != GLX_RGBA_TYPE && renderType != GLX_COLOR_INDEX_TYPE))
2100 return 0;
2101
2102 glxCtx = CALLOC_STRUCT(__GLXcontextRec);
2103 if (!glxCtx)
2104 return 0;
2105
2106 /* deallocate unused windows/buffers */
2107 XMesaGarbageCollect();
2108
2109 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2110 shareCtx ? shareCtx->xmesaContext : NULL);
2111 if (!glxCtx->xmesaContext) {
2112 _mesa_free(glxCtx);
2113 return NULL;
2114 }
2115
2116 glxCtx->isDirect = DEFAULT_DIRECT;
2117 glxCtx->currentDpy = dpy;
2118 glxCtx->xid = (XID) glxCtx; /* self pointer */
2119
2120 return glxCtx;
2121 }
2122
2123
2124 int
2125 glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2126 {
2127 GLXContext glxCtx = ctx;
2128 XMesaContext xmctx = glxCtx->xmesaContext;
2129
2130 (void) dpy;
2131 (void) ctx;
2132
2133 switch (attribute) {
2134 case GLX_FBCONFIG_ID:
2135 *value = xmctx->xm_visual->visinfo->visualid;
2136 break;
2137 case GLX_RENDER_TYPE:
2138 if (xmctx->xm_visual->mesa_visual.rgbMode)
2139 *value = GLX_RGBA_TYPE;
2140 else
2141 *value = GLX_COLOR_INDEX_TYPE;
2142 break;
2143 case GLX_SCREEN:
2144 *value = 0;
2145 return Success;
2146 default:
2147 return GLX_BAD_ATTRIBUTE;
2148 }
2149 return 0;
2150 }
2151
2152
2153 void
2154 glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2155 {
2156 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2157 if (xmbuf)
2158 xmbuf->selectedEvents = mask;
2159 }
2160
2161
2162 void
2163 glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
2164 unsigned long *mask )
2165 {
2166 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2167 if (xmbuf)
2168 *mask = xmbuf->selectedEvents;
2169 else
2170 *mask = 0;
2171 }
2172
2173
2174
2175 /*** GLX_SGI_swap_control ***/
2176
2177 int
2178 glXSwapIntervalSGI(int interval)
2179 {
2180 (void) interval;
2181 return 0;
2182 }
2183
2184
2185
2186 /*** GLX_SGI_video_sync ***/
2187
2188 static unsigned int FrameCounter = 0;
2189
2190 int
2191 glXGetVideoSyncSGI(unsigned int *count)
2192 {
2193 /* this is a bogus implementation */
2194 *count = FrameCounter++;
2195 return 0;
2196 }
2197
2198 int
2199 glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2200 {
2201 if (divisor <= 0 || remainder < 0)
2202 return GLX_BAD_VALUE;
2203 /* this is a bogus implementation */
2204 FrameCounter++;
2205 while (FrameCounter % divisor != remainder)
2206 FrameCounter++;
2207 *count = FrameCounter;
2208 return 0;
2209 }
2210
2211
2212
2213 /*** GLX_SGI_make_current_read ***/
2214
2215 Bool
2216 glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2217 {
2218 return glXMakeContextCurrent( dpy, draw, read, ctx );
2219 }
2220
2221 /* not used
2222 static GLXDrawable
2223 glXGetCurrentReadDrawableSGI(void)
2224 {
2225 return 0;
2226 }
2227 */
2228
2229
2230 /*** GLX_SGIX_video_source ***/
2231 #if defined(_VL_H)
2232
2233 GLXVideoSourceSGIX
2234 glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
2235 {
2236 (void) dpy;
2237 (void) screen;
2238 (void) server;
2239 (void) path;
2240 (void) nodeClass;
2241 (void) drainNode;
2242 return 0;
2243 }
2244
2245 void
2246 glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2247 {
2248 (void) dpy;
2249 (void) src;
2250 }
2251
2252 #endif
2253
2254
2255 /*** GLX_EXT_import_context ***/
2256
2257 void
2258 glXFreeContextEXT(Display *dpy, GLXContext context)
2259 {
2260 (void) dpy;
2261 (void) context;
2262 }
2263
2264 GLXContextID
2265 glXGetContextIDEXT(const GLXContext context)
2266 {
2267 (void) context;
2268 return 0;
2269 }
2270
2271 GLXContext
2272 glXImportContextEXT(Display *dpy, GLXContextID contextID)
2273 {
2274 (void) dpy;
2275 (void) contextID;
2276 return 0;
2277 }
2278
2279 int
2280 glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value)
2281 {
2282 (void) dpy;
2283 (void) context;
2284 (void) attribute;
2285 (void) value;
2286 return 0;
2287 }
2288
2289
2290
2291 /*** GLX_SGIX_fbconfig ***/
2292
2293 int
2294 glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2295 {
2296 return glXGetFBConfigAttrib(dpy, config, attribute, value);
2297 }
2298
2299 GLXFBConfigSGIX *
2300 glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
2301 {
2302 return (GLXFBConfig *) glXChooseFBConfig(dpy, screen, attrib_list, nelements);
2303 }
2304
2305
2306 GLXPixmap
2307 glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
2308 {
2309 XMesaVisual xmvis = (XMesaVisual) config;
2310 XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
2311 return xmbuf->drawable; /* need to return an X ID */
2312 }
2313
2314
2315 GLXContext
2316 glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
2317 {
2318 XMesaVisual xmvis = (XMesaVisual) config;
2319 GLXContext glxCtx;
2320 GLXContext shareCtx = share_list;
2321
2322 glxCtx = CALLOC_STRUCT(__GLXcontextRec);
2323 if (!glxCtx)
2324 return 0;
2325
2326 /* deallocate unused windows/buffers */
2327 XMesaGarbageCollect();
2328
2329 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
2330 shareCtx ? shareCtx->xmesaContext : NULL);
2331 if (!glxCtx->xmesaContext) {
2332 _mesa_free(glxCtx);
2333 return NULL;
2334 }
2335
2336 glxCtx->isDirect = DEFAULT_DIRECT;
2337 glxCtx->currentDpy = dpy;
2338 glxCtx->xid = (XID) glxCtx; /* self pointer */
2339
2340 return glxCtx;
2341 }
2342
2343
2344 XVisualInfo *
2345 glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2346 {
2347 return glXGetVisualFromFBConfig(dpy, config);
2348 }
2349
2350
2351 GLXFBConfigSGIX
2352 glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2353 {
2354 XMesaVisual xmvis = find_glx_visual(dpy, vis);
2355 if (!xmvis) {
2356 /* This visual wasn't found with glXChooseVisual() */
2357 xmvis = create_glx_visual(dpy, vis);
2358 }
2359
2360 return (GLXFBConfigSGIX) xmvis;
2361 }
2362
2363
2364
2365 /*** GLX_SGIX_pbuffer ***/
2366
2367 GLXPbufferSGIX
2368 glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
2369 unsigned int width, unsigned int height,
2370 int *attribList)
2371 {
2372 XMesaVisual xmvis = (XMesaVisual) config;
2373 XMesaBuffer xmbuf;
2374 const int *attrib;
2375 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2376
2377 (void) dpy;
2378
2379 for (attrib = attribList; attrib && *attrib; attrib++) {
2380 switch (*attrib) {
2381 case GLX_PRESERVED_CONTENTS_SGIX:
2382 attrib++;
2383 preserveContents = *attrib; /* ignored */
2384 break;
2385 case GLX_LARGEST_PBUFFER_SGIX:
2386 attrib++;
2387 useLargest = *attrib; /* ignored */
2388 break;
2389 default:
2390 return 0;
2391 }
2392 }
2393
2394 /* not used at this time */
2395 (void) useLargest;
2396 (void) preserveContents;
2397
2398 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2399 /* A GLXPbuffer handle must be an X Drawable because that's what
2400 * glXMakeCurrent takes.
2401 */
2402 return (GLXPbuffer) xmbuf->drawable;
2403 }
2404
2405
2406 void
2407 glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2408 {
2409 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2410 if (xmbuf) {
2411 XMesaDestroyBuffer(xmbuf);
2412 }
2413 }
2414
2415
2416 int
2417 glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
2418 {
2419 const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2420
2421 if (!xmbuf) {
2422 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2423 return 0;
2424 }
2425
2426 switch (attribute) {
2427 case GLX_PRESERVED_CONTENTS_SGIX:
2428 *value = True;
2429 break;
2430 case GLX_LARGEST_PBUFFER_SGIX:
2431 *value = xmesa_buffer_width(xmbuf) * xmesa_buffer_height(xmbuf);
2432 break;
2433 case GLX_WIDTH_SGIX:
2434 *value = xmesa_buffer_width(xmbuf);
2435 break;
2436 case GLX_HEIGHT_SGIX:
2437 *value = xmesa_buffer_height(xmbuf);
2438 break;
2439 case GLX_EVENT_MASK_SGIX:
2440 *value = 0; /* XXX might be wrong */
2441 break;
2442 default:
2443 *value = 0;
2444 }
2445 return 0;
2446 }
2447
2448
2449 void
2450 glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2451 {
2452 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2453 if (xmbuf) {
2454 /* Note: we'll never generate clobber events */
2455 xmbuf->selectedEvents = mask;
2456 }
2457 }
2458
2459
2460 void
2461 glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2462 {
2463 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2464 if (xmbuf) {
2465 *mask = xmbuf->selectedEvents;
2466 }
2467 else {
2468 *mask = 0;
2469 }
2470 }
2471
2472
2473
2474 /*** GLX_SGI_cushion ***/
2475
2476 void
2477 glXCushionSGI(Display *dpy, Window win, float cushion)
2478 {
2479 (void) dpy;
2480 (void) win;
2481 (void) cushion;
2482 }
2483
2484
2485
2486 /*** GLX_SGIX_video_resize ***/
2487
2488 int
2489 glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
2490 {
2491 (void) dpy;
2492 (void) screen;
2493 (void) channel;
2494 (void) window;
2495 return 0;
2496 }
2497
2498 int
2499 glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
2500 {
2501 (void) dpy;
2502 (void) screen;
2503 (void) channel;
2504 (void) x;
2505 (void) y;
2506 (void) w;
2507 (void) h;
2508 return 0;
2509 }
2510
2511 int
2512 glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
2513 {
2514 (void) dpy;
2515 (void) screen;
2516 (void) channel;
2517 (void) x;
2518 (void) y;
2519 (void) w;
2520 (void) h;
2521 return 0;
2522 }
2523
2524 int
2525 glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
2526 {
2527 (void) dpy;
2528 (void) screen;
2529 (void) channel;
2530 (void) dx;
2531 (void) dy;
2532 (void) dw;
2533 (void) dh;
2534 return 0;
2535 }
2536
2537 int
2538 glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2539 {
2540 (void) dpy;
2541 (void) screen;
2542 (void) channel;
2543 (void) synctype;
2544 return 0;
2545 }
2546
2547
2548
2549 /*** GLX_SGIX_dmbuffer **/
2550
2551 #if defined(_DM_BUFFER_H_)
2552 Bool
2553 glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
2554 {
2555 (void) dpy;
2556 (void) pbuffer;
2557 (void) params;
2558 (void) dmbuffer;
2559 return False;
2560 }
2561 #endif
2562
2563
2564 /*** GLX_SGIX_swap_group ***/
2565
2566 void
2567 glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2568 {
2569 (void) dpy;
2570 (void) drawable;
2571 (void) member;
2572 }
2573
2574
2575
2576 /*** GLX_SGIX_swap_barrier ***/
2577
2578 void
2579 glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2580 {
2581 (void) dpy;
2582 (void) drawable;
2583 (void) barrier;
2584 }
2585
2586 Bool
2587 glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2588 {
2589 (void) dpy;
2590 (void) screen;
2591 (void) max;
2592 return False;
2593 }
2594
2595
2596
2597 /*** GLX_SUN_get_transparent_index ***/
2598
2599 Status
2600 glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
2601 {
2602 (void) dpy;
2603 (void) overlay;
2604 (void) underlay;
2605 (void) pTransparent;
2606 return 0;
2607 }
2608
2609
2610
2611 /*** GLX_MESA_release_buffers ***/
2612
2613 /*
2614 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2615 * (a window or pixmap) prior to destroying the GLXDrawable.
2616 */
2617 Bool
2618 glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2619 {
2620 XMesaBuffer b = XMesaFindBuffer(dpy, d);
2621 if (b) {
2622 XMesaDestroyBuffer(b);
2623 return True;
2624 }
2625 return False;
2626 }
2627
2628 /*** GLX_EXT_texture_from_pixmap ***/
2629
2630 void
2631 glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer,
2632 const int *attrib_list)
2633 {
2634 XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2635 if (b)
2636 XMesaBindTexImage(dpy, b, buffer, attrib_list);
2637 }
2638
2639 void
2640 glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer)
2641 {
2642 XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2643 if (b)
2644 XMesaReleaseTexImage(dpy, b, buffer);
2645 }