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