Merge branch 'master' into asm-shader-rework-1
[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 /*** Debug helper code ***/
114 /**********************************************************************/
115
116 extern void _kw_ungrab_all( Display *dpy );
117 void _kw_ungrab_all( Display *dpy )
118 {
119 XUngrabPointer( dpy, CurrentTime );
120 XUngrabKeyboard( dpy, CurrentTime );
121 }
122
123
124
125 /**********************************************************************/
126 /*** GLX Visual Code ***/
127 /**********************************************************************/
128
129 #define DONT_CARE -1
130
131
132 static XMesaVisual *VisualTable = NULL;
133 static int NumVisuals = 0;
134
135
136
137 /* Macro to handle c_class vs class field name in XVisualInfo struct */
138 #if defined(__cplusplus) || defined(c_plusplus)
139 #define CLASS c_class
140 #else
141 #define CLASS class
142 #endif
143
144
145
146 /*
147 * Test if the given XVisualInfo is usable for Mesa rendering.
148 */
149 static GLboolean
150 is_usable_visual( XVisualInfo *vinfo )
151 {
152 switch (vinfo->CLASS) {
153 case StaticGray:
154 case GrayScale:
155 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
156 return GL_TRUE;
157 case StaticColor:
158 case PseudoColor:
159 /* Any StaticColor/PseudoColor visual of at least 4 bits */
160 if (vinfo->depth>=4) {
161 return GL_TRUE;
162 }
163 else {
164 return GL_FALSE;
165 }
166 case TrueColor:
167 case DirectColor:
168 /* Any depth of TrueColor or DirectColor works in RGB mode */
169 return GL_TRUE;
170 default:
171 /* This should never happen */
172 return GL_FALSE;
173 }
174 }
175
176
177 /*
178 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
179 * configuration in our list of GLX visuals.
180 */
181 static XMesaVisual
182 save_glx_visual( Display *dpy, XVisualInfo *vinfo,
183 GLboolean rgbFlag, GLboolean alphaFlag, GLboolean dbFlag,
184 GLboolean stereoFlag,
185 GLint depth_size, GLint stencil_size,
186 GLint accumRedSize, GLint accumGreenSize,
187 GLint accumBlueSize, GLint accumAlphaSize,
188 GLint level, GLint numAuxBuffers )
189 {
190 GLboolean ximageFlag = GL_TRUE;
191 XMesaVisual xmvis;
192 GLint i;
193 GLboolean comparePointers;
194
195 if (dbFlag) {
196 /* Check if the MESA_BACK_BUFFER env var is set */
197 char *backbuffer = _mesa_getenv("MESA_BACK_BUFFER");
198 if (backbuffer) {
199 if (backbuffer[0]=='p' || backbuffer[0]=='P') {
200 ximageFlag = GL_FALSE;
201 }
202 else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
203 ximageFlag = GL_TRUE;
204 }
205 else {
206 _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
207 }
208 }
209 }
210
211 if (stereoFlag) {
212 /* stereo not supported */
213 return NULL;
214 }
215
216 if (stencil_size > 0 && depth_size > 0)
217 depth_size = 24;
218
219 /* Comparing IDs uses less memory but sometimes fails. */
220 /* XXX revisit this after 3.0 is finished. */
221 if (_mesa_getenv("MESA_GLX_VISUAL_HACK"))
222 comparePointers = GL_TRUE;
223 else
224 comparePointers = GL_FALSE;
225
226 /* Force the visual to have an alpha channel */
227 if (rgbFlag && _mesa_getenv("MESA_GLX_FORCE_ALPHA"))
228 alphaFlag = GL_TRUE;
229
230 /* First check if a matching visual is already in the list */
231 for (i=0; i<NumVisuals; i++) {
232 XMesaVisual v = VisualTable[i];
233 if (v->display == dpy
234 && v->mesa_visual.level == level
235 && v->mesa_visual.numAuxBuffers == numAuxBuffers
236 && v->ximage_flag == ximageFlag
237 && v->mesa_visual.rgbMode == rgbFlag
238 && v->mesa_visual.doubleBufferMode == dbFlag
239 && v->mesa_visual.stereoMode == stereoFlag
240 && (v->mesa_visual.alphaBits > 0) == alphaFlag
241 && (v->mesa_visual.depthBits >= depth_size || depth_size == 0)
242 && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0)
243 && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0)
244 && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0)
245 && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0)
246 && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) {
247 /* now either compare XVisualInfo pointers or visual IDs */
248 if ((!comparePointers && v->visinfo->visualid == vinfo->visualid)
249 || (comparePointers && v->vishandle == vinfo)) {
250 return v;
251 }
252 }
253 }
254
255 /* Create a new visual and add it to the list. */
256
257 xmvis = XMesaCreateVisual( dpy, vinfo, rgbFlag, alphaFlag, dbFlag,
258 stereoFlag, ximageFlag,
259 depth_size, stencil_size,
260 accumRedSize, accumBlueSize,
261 accumBlueSize, accumAlphaSize, 0, level,
262 GLX_NONE_EXT );
263 if (xmvis) {
264 /* Save a copy of the pointer now so we can find this visual again
265 * if we need to search for it in find_glx_visual().
266 */
267 xmvis->vishandle = vinfo;
268 /* Allocate more space for additional visual */
269 VisualTable = (XMesaVisual *) _mesa_realloc( VisualTable,
270 sizeof(XMesaVisual) * NumVisuals,
271 sizeof(XMesaVisual) * (NumVisuals + 1));
272 /* add xmvis to the list */
273 VisualTable[NumVisuals] = xmvis;
274 NumVisuals++;
275 /* XXX minor hack, because XMesaCreateVisual doesn't support an
276 * aux buffers parameter.
277 */
278 xmvis->mesa_visual.numAuxBuffers = numAuxBuffers;
279 }
280 return xmvis;
281 }
282
283
284 /**
285 * Return the default number of bits for the Z buffer.
286 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
287 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
288 * XXX probably do the same thing for stencil, accum, etc.
289 */
290 static GLint
291 default_depth_bits(void)
292 {
293 int zBits;
294 const char *zEnv = _mesa_getenv("MESA_GLX_DEPTH_BITS");
295 if (zEnv)
296 zBits = _mesa_atoi(zEnv);
297 else
298 zBits = DEFAULT_SOFTWARE_DEPTH_BITS;
299 return zBits;
300 }
301
302 static GLint
303 default_alpha_bits(void)
304 {
305 int aBits;
306 const char *aEnv = _mesa_getenv("MESA_GLX_ALPHA_BITS");
307 if (aEnv)
308 aBits = _mesa_atoi(aEnv);
309 else
310 aBits = 0;
311 return aBits;
312 }
313
314 static GLint
315 default_accum_bits(void)
316 {
317 return 16;
318 }
319
320
321
322 /*
323 * Create a GLX visual from a regular XVisualInfo.
324 * This is called when Fake GLX is given an XVisualInfo which wasn't
325 * returned by glXChooseVisual. Since this is the first time we're
326 * considering this visual we'll take a guess at reasonable values
327 * for depth buffer size, stencil size, accum size, etc.
328 * This is the best we can do with a client-side emulation of GLX.
329 */
330 static XMesaVisual
331 create_glx_visual( Display *dpy, XVisualInfo *visinfo )
332 {
333 GLint zBits = default_depth_bits();
334 GLint accBits = default_accum_bits();
335 GLboolean alphaFlag = default_alpha_bits() > 0;
336
337 if (is_usable_visual( visinfo )) {
338 /* Configure this visual as RGB, double-buffered, depth-buffered. */
339 /* This is surely wrong for some people's needs but what else */
340 /* can be done? They should use glXChooseVisual(). */
341 return save_glx_visual( dpy, visinfo,
342 GL_TRUE, /* rgb */
343 alphaFlag, /* alpha */
344 GL_TRUE, /* double */
345 GL_FALSE, /* stereo */
346 zBits,
347 STENCIL_BITS,
348 accBits, /* r */
349 accBits, /* g */
350 accBits, /* b */
351 accBits, /* a */
352 0, /* level */
353 0 /* numAux */
354 );
355 }
356 else {
357 _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
358 return NULL;
359 }
360 }
361
362
363
364 /*
365 * Find the GLX visual associated with an XVisualInfo.
366 */
367 static XMesaVisual
368 find_glx_visual( Display *dpy, XVisualInfo *vinfo )
369 {
370 int i;
371
372 /* try to match visual id */
373 for (i=0;i<NumVisuals;i++) {
374 if (VisualTable[i]->display==dpy
375 && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
376 return VisualTable[i];
377 }
378 }
379
380 /* if that fails, try to match pointers */
381 for (i=0;i<NumVisuals;i++) {
382 if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {
383 return VisualTable[i];
384 }
385 }
386
387 return NULL;
388 }
389
390
391 /**
392 * Try to get an X visual which matches the given arguments.
393 */
394 static XVisualInfo *
395 get_visual( Display *dpy, int scr, unsigned int depth, int xclass )
396 {
397 XVisualInfo temp, *vis;
398 long mask;
399 int n;
400 unsigned int default_depth;
401 int default_class;
402
403 mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
404 temp.screen = scr;
405 temp.depth = depth;
406 temp.CLASS = xclass;
407
408 default_depth = DefaultDepth(dpy,scr);
409 default_class = DefaultVisual(dpy,scr)->CLASS;
410
411 if (depth==default_depth && xclass==default_class) {
412 /* try to get root window's visual */
413 temp.visualid = DefaultVisual(dpy,scr)->visualid;
414 mask |= VisualIDMask;
415 }
416
417 vis = XGetVisualInfo( dpy, mask, &temp, &n );
418
419 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
420 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
421 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
422 */
423 if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
424 if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&
425 _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&
426 _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {
427 return vis;
428 }
429 else {
430 XFree((void *) vis);
431 return NULL;
432 }
433 }
434
435 return vis;
436 }
437
438
439 /*
440 * Retrieve the value of the given environment variable and find
441 * the X visual which matches it.
442 * Input: dpy - the display
443 * screen - the screen number
444 * varname - the name of the environment variable
445 * Return: an XVisualInfo pointer to NULL if error.
446 */
447 static XVisualInfo *
448 get_env_visual(Display *dpy, int scr, const char *varname)
449 {
450 char value[100], type[100];
451 int depth, xclass = -1;
452 XVisualInfo *vis;
453
454 if (!_mesa_getenv( varname )) {
455 return NULL;
456 }
457
458 _mesa_strncpy( value, _mesa_getenv(varname), 100 );
459 value[99] = 0;
460
461 sscanf( value, "%s %d", type, &depth );
462
463 if (_mesa_strcmp(type,"TrueColor")==0) xclass = TrueColor;
464 else if (_mesa_strcmp(type,"DirectColor")==0) xclass = DirectColor;
465 else if (_mesa_strcmp(type,"PseudoColor")==0) xclass = PseudoColor;
466 else if (_mesa_strcmp(type,"StaticColor")==0) xclass = StaticColor;
467 else if (_mesa_strcmp(type,"GrayScale")==0) xclass = GrayScale;
468 else if (_mesa_strcmp(type,"StaticGray")==0) xclass = StaticGray;
469
470 if (xclass>-1 && depth>0) {
471 vis = get_visual( dpy, scr, depth, xclass );
472 if (vis) {
473 return vis;
474 }
475 }
476
477 _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",
478 type, depth);
479
480 return NULL;
481 }
482
483
484
485 /*
486 * Select an X visual which satisfies the RGBA flag and minimum depth.
487 * Input: dpy,
488 * screen - X display and screen number
489 * min_depth - minimum visual depth
490 * preferred_class - preferred GLX visual class or DONT_CARE
491 * Return: pointer to an XVisualInfo or NULL.
492 */
493 static XVisualInfo *
494 choose_x_visual( Display *dpy, int screen, int min_depth,
495 int preferred_class )
496 {
497 XVisualInfo *vis;
498 int xclass, visclass = 0;
499 int depth;
500
501 /* First see if the MESA_RGB_VISUAL env var is defined */
502 vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
503 if (vis) {
504 return vis;
505 }
506 /* Otherwise, search for a suitable visual */
507 if (preferred_class==DONT_CARE) {
508 for (xclass=0;xclass<6;xclass++) {
509 switch (xclass) {
510 case 0: visclass = TrueColor; break;
511 case 1: visclass = DirectColor; break;
512 case 2: visclass = PseudoColor; break;
513 case 3: visclass = StaticColor; break;
514 case 4: visclass = GrayScale; break;
515 case 5: visclass = StaticGray; break;
516 }
517 if (min_depth==0) {
518 /* start with shallowest */
519 for (depth=0;depth<=32;depth++) {
520 if (visclass==TrueColor && depth==8) {
521 /* Special case: try to get 8-bit PseudoColor before */
522 /* 8-bit TrueColor */
523 vis = get_visual( dpy, screen, 8, PseudoColor );
524 if (vis) {
525 return vis;
526 }
527 }
528 vis = get_visual( dpy, screen, depth, visclass );
529 if (vis) {
530 return vis;
531 }
532 }
533 }
534 else {
535 /* start with deepest */
536 for (depth=32;depth>=min_depth;depth--) {
537 if (visclass==TrueColor && depth==8) {
538 /* Special case: try to get 8-bit PseudoColor before */
539 /* 8-bit TrueColor */
540 vis = get_visual( dpy, screen, 8, PseudoColor );
541 if (vis) {
542 return vis;
543 }
544 }
545 vis = get_visual( dpy, screen, depth, visclass );
546 if (vis) {
547 return vis;
548 }
549 }
550 }
551 }
552 }
553 else {
554 /* search for a specific visual class */
555 switch (preferred_class) {
556 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
557 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
558 case GLX_PSEUDO_COLOR_EXT: visclass = PseudoColor; break;
559 case GLX_STATIC_COLOR_EXT: visclass = StaticColor; break;
560 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
561 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
562 default: return NULL;
563 }
564 if (min_depth==0) {
565 /* start with shallowest */
566 for (depth=0;depth<=32;depth++) {
567 vis = get_visual( dpy, screen, depth, visclass );
568 if (vis) {
569 return vis;
570 }
571 }
572 }
573 else {
574 /* start with deepest */
575 for (depth=32;depth>=min_depth;depth--) {
576 vis = get_visual( dpy, screen, depth, visclass );
577 if (vis) {
578 return vis;
579 }
580 }
581 }
582 }
583
584 /* didn't find a visual */
585 return NULL;
586 }
587
588
589
590
591 /**********************************************************************/
592 /*** Display-related functions ***/
593 /**********************************************************************/
594
595
596 /**
597 * Free all XMesaVisuals which are associated with the given display.
598 */
599 static void
600 destroy_visuals_on_display(Display *dpy)
601 {
602 int i;
603 for (i = 0; i < NumVisuals; i++) {
604 if (VisualTable[i]->display == dpy) {
605 /* remove this visual */
606 int j;
607 free(VisualTable[i]);
608 for (j = i; j < NumVisuals - 1; j++)
609 VisualTable[j] = VisualTable[j + 1];
610 NumVisuals--;
611 }
612 }
613 }
614
615
616 /**
617 * Called from XCloseDisplay() to let us free our display-related data.
618 */
619 static int
620 close_display_callback(Display *dpy, XExtCodes *codes)
621 {
622 destroy_visuals_on_display(dpy);
623 xmesa_destroy_buffers_on_display(dpy);
624 return 0;
625 }
626
627
628 /**
629 * Look for the named extension on given display and return a pointer
630 * to the _XExtension data, or NULL if extension not found.
631 */
632 static _XExtension *
633 lookup_extension(Display *dpy, const char *extName)
634 {
635 _XExtension *ext;
636 for (ext = dpy->ext_procs; ext; ext = ext->next) {
637 if (ext->name && strcmp(ext->name, extName) == 0) {
638 return ext;
639 }
640 }
641 return NULL;
642 }
643
644
645 /**
646 * Whenever we're given a new Display pointer, call this function to
647 * register our close_display_callback function.
648 */
649 static void
650 register_with_display(Display *dpy)
651 {
652 const char *extName = "MesaGLX";
653 _XExtension *ext;
654
655 ext = lookup_extension(dpy, extName);
656 if (!ext) {
657 XExtCodes *c = XAddExtension(dpy);
658 ext = dpy->ext_procs; /* new extension is at head of list */
659 assert(c->extension == ext->codes.extension);
660 ext->name = _mesa_strdup(extName);
661 ext->close_display = close_display_callback;
662 }
663 }
664
665
666 /**********************************************************************/
667 /*** Begin Fake GLX API Functions ***/
668 /**********************************************************************/
669
670
671 /**
672 * Helper used by glXChooseVisual and glXChooseFBConfig.
673 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
674 * the later.
675 * In either case, the attribute list is terminated with the value 'None'.
676 */
677 static XMesaVisual
678 choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
679 {
680 const GLboolean rgbModeDefault = fbConfig;
681 const int *parselist;
682 XVisualInfo *vis;
683 int min_ci = 0;
684 int min_red=0, min_green=0, min_blue=0;
685 GLboolean rgb_flag = rgbModeDefault;
686 GLboolean alpha_flag = GL_FALSE;
687 GLboolean double_flag = GL_FALSE;
688 GLboolean stereo_flag = GL_FALSE;
689 GLint depth_size = 0;
690 GLint stencil_size = 0;
691 GLint accumRedSize = 0;
692 GLint accumGreenSize = 0;
693 GLint accumBlueSize = 0;
694 GLint accumAlphaSize = 0;
695 int level = 0;
696 int visual_type = DONT_CARE;
697 int trans_type = DONT_CARE;
698 int trans_value = DONT_CARE;
699 GLint caveat = DONT_CARE;
700 XMesaVisual xmvis = NULL;
701 int desiredVisualID = -1;
702 int numAux = 0;
703
704 parselist = list;
705
706 while (*parselist) {
707
708 switch (*parselist) {
709 case GLX_USE_GL:
710 if (fbConfig) {
711 /* invalid token */
712 return NULL;
713 }
714 else {
715 /* skip */
716 parselist++;
717 }
718 break;
719 case GLX_BUFFER_SIZE:
720 parselist++;
721 min_ci = *parselist++;
722 break;
723 case GLX_LEVEL:
724 parselist++;
725 level = *parselist++;
726 break;
727 case GLX_RGBA:
728 if (fbConfig) {
729 /* invalid token */
730 return NULL;
731 }
732 else {
733 rgb_flag = GL_TRUE;
734 parselist++;
735 }
736 break;
737 case GLX_DOUBLEBUFFER:
738 parselist++;
739 if (fbConfig) {
740 double_flag = *parselist++;
741 }
742 else {
743 double_flag = GL_TRUE;
744 }
745 break;
746 case GLX_STEREO:
747 parselist++;
748 if (fbConfig) {
749 stereo_flag = *parselist++;
750 }
751 else {
752 stereo_flag = GL_TRUE;
753 }
754 break;
755 case GLX_AUX_BUFFERS:
756 parselist++;
757 numAux = *parselist++;
758 if (numAux > MAX_AUX_BUFFERS)
759 return NULL;
760 break;
761 case GLX_RED_SIZE:
762 parselist++;
763 min_red = *parselist++;
764 break;
765 case GLX_GREEN_SIZE:
766 parselist++;
767 min_green = *parselist++;
768 break;
769 case GLX_BLUE_SIZE:
770 parselist++;
771 min_blue = *parselist++;
772 break;
773 case GLX_ALPHA_SIZE:
774 parselist++;
775 {
776 GLint size = *parselist++;
777 alpha_flag = size ? GL_TRUE : GL_FALSE;
778 }
779 break;
780 case GLX_DEPTH_SIZE:
781 parselist++;
782 depth_size = *parselist++;
783 break;
784 case GLX_STENCIL_SIZE:
785 parselist++;
786 stencil_size = *parselist++;
787 break;
788 case GLX_ACCUM_RED_SIZE:
789 parselist++;
790 {
791 GLint size = *parselist++;
792 accumRedSize = MAX2( accumRedSize, size );
793 }
794 break;
795 case GLX_ACCUM_GREEN_SIZE:
796 parselist++;
797 {
798 GLint size = *parselist++;
799 accumGreenSize = MAX2( accumGreenSize, size );
800 }
801 break;
802 case GLX_ACCUM_BLUE_SIZE:
803 parselist++;
804 {
805 GLint size = *parselist++;
806 accumBlueSize = MAX2( accumBlueSize, size );
807 }
808 break;
809 case GLX_ACCUM_ALPHA_SIZE:
810 parselist++;
811 {
812 GLint size = *parselist++;
813 accumAlphaSize = MAX2( accumAlphaSize, size );
814 }
815 break;
816
817 /*
818 * GLX_EXT_visual_info extension
819 */
820 case GLX_X_VISUAL_TYPE_EXT:
821 parselist++;
822 visual_type = *parselist++;
823 break;
824 case GLX_TRANSPARENT_TYPE_EXT:
825 parselist++;
826 trans_type = *parselist++;
827 break;
828 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
829 parselist++;
830 trans_value = *parselist++;
831 break;
832 case GLX_TRANSPARENT_RED_VALUE_EXT:
833 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
834 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
835 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
836 /* ignore */
837 parselist++;
838 parselist++;
839 break;
840
841 /*
842 * GLX_EXT_visual_info extension
843 */
844 case GLX_VISUAL_CAVEAT_EXT:
845 parselist++;
846 caveat = *parselist++; /* ignored for now */
847 break;
848
849 /*
850 * GLX_ARB_multisample
851 */
852 case GLX_SAMPLE_BUFFERS_ARB:
853 /* ms not supported */
854 return NULL;
855 case GLX_SAMPLES_ARB:
856 /* ms not supported */
857 return NULL;
858
859 /*
860 * FBConfig attribs.
861 */
862 case GLX_RENDER_TYPE:
863 if (!fbConfig)
864 return NULL;
865 parselist++;
866 if (*parselist == GLX_RGBA_BIT) {
867 rgb_flag = GL_TRUE;
868 }
869 else if (*parselist == GLX_COLOR_INDEX_BIT) {
870 rgb_flag = GL_FALSE;
871 }
872 else if (*parselist == 0) {
873 rgb_flag = GL_TRUE;
874 }
875 parselist++;
876 break;
877 case GLX_DRAWABLE_TYPE:
878 if (!fbConfig)
879 return NULL;
880 parselist++;
881 if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) {
882 return NULL; /* bad bit */
883 }
884 parselist++;
885 break;
886 case GLX_FBCONFIG_ID:
887 if (!fbConfig)
888 return NULL;
889 parselist++;
890 desiredVisualID = *parselist++;
891 break;
892 case GLX_X_RENDERABLE:
893 if (!fbConfig)
894 return NULL;
895 parselist += 2;
896 /* ignore */
897 break;
898
899 #ifdef GLX_EXT_texture_from_pixmap
900 case GLX_BIND_TO_TEXTURE_RGB_EXT:
901 parselist++; /*skip*/
902 break;
903 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
904 parselist++; /*skip*/
905 break;
906 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
907 parselist++; /*skip*/
908 break;
909 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
910 parselist++;
911 if (*parselist & ~(GLX_TEXTURE_1D_BIT_EXT |
912 GLX_TEXTURE_2D_BIT_EXT |
913 GLX_TEXTURE_RECTANGLE_BIT_EXT)) {
914 /* invalid bit */
915 return NULL;
916 }
917 break;
918 case GLX_Y_INVERTED_EXT:
919 parselist++; /*skip*/
920 break;
921 #endif
922
923 case None:
924 /* end of list */
925 break;
926
927 default:
928 /* undefined attribute */
929 _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
930 *parselist);
931 return NULL;
932 }
933 }
934
935 (void) caveat;
936
937
938 /*
939 * Since we're only simulating the GLX extension this function will never
940 * find any real GL visuals. Instead, all we can do is try to find an RGB
941 * or CI visual of appropriate depth. Other requested attributes such as
942 * double buffering, depth buffer, etc. will be associated with the X
943 * visual and stored in the VisualTable[].
944 */
945 if (desiredVisualID != -1) {
946 /* try to get a specific visual, by visualID */
947 XVisualInfo temp;
948 int n;
949 temp.visualid = desiredVisualID;
950 temp.screen = screen;
951 vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n);
952 if (vis) {
953 /* give the visual some useful GLX attributes */
954 double_flag = GL_TRUE;
955 rgb_flag = GL_TRUE;
956 depth_size = default_depth_bits();
957 stencil_size = STENCIL_BITS;
958 /* XXX accum??? */
959 }
960 }
961 else if (level==0) {
962 /* normal color planes */
963 /* Get an RGB visual */
964 int min_rgb = min_red + min_green + min_blue;
965 if (min_rgb>1 && min_rgb<8) {
966 /* a special case to be sure we can get a monochrome visual */
967 min_rgb = 1;
968 }
969 vis = choose_x_visual( dpy, screen, min_rgb, visual_type );
970 }
971 else {
972 _mesa_warning(NULL, "overlay not supported");
973 return NULL;
974 }
975
976 if (vis) {
977 /* Note: we're not exactly obeying the glXChooseVisual rules here.
978 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
979 * largest depth buffer size, which is 32bits/value. Instead, we
980 * return 16 to maintain performance with earlier versions of Mesa.
981 */
982 if (stencil_size > 0)
983 depth_size = 24; /* if Z and stencil, always use 24+8 format */
984 else if (depth_size > 24)
985 depth_size = 32;
986 else if (depth_size > 16)
987 depth_size = 24;
988 else if (depth_size > 0) {
989 depth_size = default_depth_bits();
990 }
991
992 if (!alpha_flag) {
993 alpha_flag = default_alpha_bits() > 0;
994 }
995
996 /* we only support one size of stencil and accum buffers. */
997 if (stencil_size > 0)
998 stencil_size = STENCIL_BITS;
999
1000 if (accumRedSize > 0 ||
1001 accumGreenSize > 0 ||
1002 accumBlueSize > 0 ||
1003 accumAlphaSize > 0) {
1004
1005 accumRedSize =
1006 accumGreenSize =
1007 accumBlueSize = default_accum_bits();
1008
1009 accumAlphaSize = alpha_flag ? accumRedSize : 0;
1010 }
1011
1012 xmvis = save_glx_visual( dpy, vis, rgb_flag, alpha_flag, double_flag,
1013 stereo_flag, depth_size, stencil_size,
1014 accumRedSize, accumGreenSize,
1015 accumBlueSize, accumAlphaSize, level, numAux );
1016 }
1017
1018 return xmvis;
1019 }
1020
1021
1022 XVisualInfo *
1023 glXChooseVisual( Display *dpy, int screen, int *list )
1024 {
1025 XMesaVisual xmvis;
1026
1027 /* register ourselves as an extension on this display */
1028 register_with_display(dpy);
1029
1030 xmvis = choose_visual(dpy, screen, list, GL_FALSE);
1031 if (xmvis) {
1032 /* create a new vishandle - the cached one may be stale */
1033 xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
1034 if (xmvis->vishandle) {
1035 _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1036 }
1037 return xmvis->vishandle;
1038 }
1039 else
1040 return NULL;
1041 }
1042
1043
1044 GLXContext
1045 glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1046 GLXContext share_list, Bool direct )
1047 {
1048 XMesaVisual xmvis;
1049 GLXContext glxCtx;
1050 GLXContext shareCtx = share_list;
1051
1052 if (!dpy || !visinfo)
1053 return 0;
1054
1055 glxCtx = CALLOC_STRUCT(__GLXcontextRec);
1056 if (!glxCtx)
1057 return 0;
1058
1059 /* deallocate unused windows/buffers */
1060 #if 0
1061 XMesaGarbageCollect();
1062 #endif
1063
1064 xmvis = find_glx_visual( dpy, visinfo );
1065 if (!xmvis) {
1066 /* This visual wasn't found with glXChooseVisual() */
1067 xmvis = create_glx_visual( dpy, visinfo );
1068 if (!xmvis) {
1069 /* unusable visual */
1070 _mesa_free(glxCtx);
1071 return NULL;
1072 }
1073 }
1074
1075 glxCtx->xmesaContext = XMesaCreateContext(xmvis,
1076 shareCtx ? shareCtx->xmesaContext : NULL);
1077 if (!glxCtx->xmesaContext) {
1078 _mesa_free(glxCtx);
1079 return NULL;
1080 }
1081
1082 glxCtx->isDirect = DEFAULT_DIRECT;
1083 glxCtx->currentDpy = dpy;
1084 glxCtx->xid = (XID) glxCtx; /* self pointer */
1085
1086 return glxCtx;
1087 }
1088
1089
1090 /* XXX these may have to be removed due to thread-safety issues. */
1091 static GLXContext MakeCurrent_PrevContext = 0;
1092 static GLXDrawable MakeCurrent_PrevDrawable = 0;
1093 static GLXDrawable MakeCurrent_PrevReadable = 0;
1094 static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1095 static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
1096
1097
1098 /* GLX 1.3 and later */
1099 Bool
1100 glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
1101 GLXDrawable read, GLXContext ctx )
1102 {
1103 GLXContext glxCtx = ctx;
1104 static boolean firsttime = 1, no_rast = 0;
1105
1106 if (firsttime) {
1107 no_rast = getenv("SP_NO_RAST") != NULL;
1108 firsttime = 0;
1109 }
1110
1111 if (ctx && draw && read) {
1112 XMesaBuffer drawBuffer, readBuffer;
1113 XMesaContext xmctx = glxCtx->xmesaContext;
1114
1115 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1116 if (ctx == MakeCurrent_PrevContext
1117 && draw == MakeCurrent_PrevDrawable) {
1118 drawBuffer = MakeCurrent_PrevDrawBuffer;
1119 }
1120 else {
1121 drawBuffer = XMesaFindBuffer( dpy, draw );
1122 }
1123 if (!drawBuffer) {
1124 /* drawable must be a new window! */
1125 drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw );
1126 if (!drawBuffer) {
1127 /* Out of memory, or context/drawable depth mismatch */
1128 return False;
1129 }
1130 }
1131
1132 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1133 if (ctx == MakeCurrent_PrevContext
1134 && read == MakeCurrent_PrevReadable) {
1135 readBuffer = MakeCurrent_PrevReadBuffer;
1136 }
1137 else {
1138 readBuffer = XMesaFindBuffer( dpy, read );
1139 }
1140 if (!readBuffer) {
1141 /* drawable must be a new window! */
1142 readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read );
1143 if (!readBuffer) {
1144 /* Out of memory, or context/drawable depth mismatch */
1145 return False;
1146 }
1147 }
1148
1149 if (no_rast &&
1150 MakeCurrent_PrevContext == ctx &&
1151 MakeCurrent_PrevDrawable == draw &&
1152 MakeCurrent_PrevReadable == read &&
1153 MakeCurrent_PrevDrawBuffer == drawBuffer &&
1154 MakeCurrent_PrevReadBuffer == readBuffer)
1155 return True;
1156
1157 MakeCurrent_PrevContext = ctx;
1158 MakeCurrent_PrevDrawable = draw;
1159 MakeCurrent_PrevReadable = read;
1160 MakeCurrent_PrevDrawBuffer = drawBuffer;
1161 MakeCurrent_PrevReadBuffer = readBuffer;
1162
1163 /* Now make current! */
1164 if (XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer)) {
1165 ctx->currentDpy = dpy;
1166 ctx->currentDrawable = draw;
1167 ctx->currentReadable = read;
1168 SetCurrentContext(ctx);
1169 return True;
1170 }
1171 else {
1172 return False;
1173 }
1174 }
1175 else if (!ctx && !draw && !read) {
1176 /* release current context w/out assigning new one. */
1177 XMesaMakeCurrent2( NULL, NULL, NULL );
1178 MakeCurrent_PrevContext = 0;
1179 MakeCurrent_PrevDrawable = 0;
1180 MakeCurrent_PrevReadable = 0;
1181 MakeCurrent_PrevDrawBuffer = 0;
1182 MakeCurrent_PrevReadBuffer = 0;
1183 SetCurrentContext(NULL);
1184 return True;
1185 }
1186 else {
1187 /* The args must either all be non-zero or all zero.
1188 * This is an error.
1189 */
1190 return False;
1191 }
1192 }
1193
1194
1195 Bool
1196 glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1197 {
1198 return glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1199 }
1200
1201
1202 GLXContext
1203 glXGetCurrentContext(void)
1204 {
1205 return GetCurrentContext();
1206 }
1207
1208
1209 Display *
1210 glXGetCurrentDisplay(void)
1211 {
1212 GLXContext glxCtx = glXGetCurrentContext();
1213
1214 return glxCtx ? glxCtx->currentDpy : NULL;
1215 }
1216
1217
1218 Display *
1219 glXGetCurrentDisplayEXT(void)
1220 {
1221 return glXGetCurrentDisplay();
1222 }
1223
1224
1225 GLXDrawable
1226 glXGetCurrentDrawable(void)
1227 {
1228 GLXContext gc = glXGetCurrentContext();
1229 return gc ? gc->currentDrawable : 0;
1230 }
1231
1232
1233 GLXDrawable
1234 glXGetCurrentReadDrawable(void)
1235 {
1236 GLXContext gc = glXGetCurrentContext();
1237 return gc ? gc->currentReadable : 0;
1238 }
1239
1240
1241 GLXDrawable
1242 glXGetCurrentReadDrawableSGI(void)
1243 {
1244 return glXGetCurrentReadDrawable();
1245 }
1246
1247
1248 GLXPixmap
1249 glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1250 {
1251 XMesaVisual v;
1252 XMesaBuffer b;
1253
1254 v = find_glx_visual( dpy, visinfo );
1255 if (!v) {
1256 v = create_glx_visual( dpy, visinfo );
1257 if (!v) {
1258 /* unusable visual */
1259 return 0;
1260 }
1261 }
1262
1263 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1264 if (!b) {
1265 return 0;
1266 }
1267 return b->drawable;
1268 }
1269
1270
1271 /*** GLX_MESA_pixmap_colormap ***/
1272
1273 GLXPixmap
1274 glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1275 Pixmap pixmap, Colormap cmap )
1276 {
1277 XMesaVisual v;
1278 XMesaBuffer b;
1279
1280 v = find_glx_visual( dpy, visinfo );
1281 if (!v) {
1282 v = create_glx_visual( dpy, visinfo );
1283 if (!v) {
1284 /* unusable visual */
1285 return 0;
1286 }
1287 }
1288
1289 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1290 if (!b) {
1291 return 0;
1292 }
1293 return b->drawable;
1294 }
1295
1296
1297 void
1298 glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1299 {
1300 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1301 if (b) {
1302 XMesaDestroyBuffer(b);
1303 }
1304 else if (_mesa_getenv("MESA_DEBUG")) {
1305 _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1306 }
1307 }
1308
1309
1310 void
1311 glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1312 unsigned long mask )
1313 {
1314 GLXContext fakeSrc = src;
1315 GLXContext fakeDst = dst;
1316 XMesaContext xm_src = fakeSrc->xmesaContext;
1317 XMesaContext xm_dst = fakeDst->xmesaContext;
1318 (void) dpy;
1319 if (MakeCurrent_PrevContext == src) {
1320 _mesa_Flush();
1321 }
1322 st_copy_context_state( xm_src->st, xm_dst->st, (GLuint) mask );
1323 }
1324
1325
1326 Bool
1327 glXQueryExtension( Display *dpy, int *errorb, int *event )
1328 {
1329 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1330 (void) dpy;
1331 (void) errorb;
1332 (void) event;
1333 return True;
1334 }
1335
1336
1337 void
1338 glXDestroyContext( Display *dpy, GLXContext ctx )
1339 {
1340 GLXContext glxCtx = ctx;
1341 (void) dpy;
1342 MakeCurrent_PrevContext = 0;
1343 MakeCurrent_PrevDrawable = 0;
1344 MakeCurrent_PrevReadable = 0;
1345 MakeCurrent_PrevDrawBuffer = 0;
1346 MakeCurrent_PrevReadBuffer = 0;
1347 XMesaDestroyContext( glxCtx->xmesaContext );
1348 XMesaGarbageCollect();
1349 _mesa_free(glxCtx);
1350 }
1351
1352
1353 Bool
1354 glXIsDirect( Display *dpy, GLXContext ctx )
1355 {
1356 GLXContext glxCtx = ctx;
1357 (void) ctx;
1358 return glxCtx->isDirect;
1359 }
1360
1361
1362
1363 void
1364 glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1365 {
1366 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1367 static boolean firsttime = 1, no_rast = 0;
1368
1369 if (firsttime) {
1370 no_rast = getenv("SP_NO_RAST") != NULL;
1371 firsttime = 0;
1372 }
1373
1374 if (no_rast)
1375 return;
1376
1377 if (buffer) {
1378 XMesaSwapBuffers(buffer);
1379 }
1380 else if (_mesa_getenv("MESA_DEBUG")) {
1381 _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n",
1382 (int) drawable);
1383 }
1384 }
1385
1386
1387
1388 /*** GLX_MESA_copy_sub_buffer ***/
1389
1390 void
1391 glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1392 int x, int y, int width, int height )
1393 {
1394 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1395 if (buffer) {
1396 XMesaCopySubBuffer(buffer, x, y, width, height);
1397 }
1398 else if (_mesa_getenv("MESA_DEBUG")) {
1399 _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1400 }
1401 }
1402
1403
1404 Bool
1405 glXQueryVersion( Display *dpy, int *maj, int *min )
1406 {
1407 (void) dpy;
1408 /* Return GLX version, not Mesa version */
1409 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1410 *maj = CLIENT_MAJOR_VERSION;
1411 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1412 return True;
1413 }
1414
1415
1416 /*
1417 * Query the GLX attributes of the given XVisualInfo.
1418 */
1419 static int
1420 get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
1421 {
1422 ASSERT(xmvis);
1423 switch(attrib) {
1424 case GLX_USE_GL:
1425 if (fbconfig)
1426 return GLX_BAD_ATTRIBUTE;
1427 *value = (int) True;
1428 return 0;
1429 case GLX_BUFFER_SIZE:
1430 *value = xmvis->visinfo->depth;
1431 return 0;
1432 case GLX_LEVEL:
1433 *value = xmvis->mesa_visual.level;
1434 return 0;
1435 case GLX_RGBA:
1436 if (fbconfig)
1437 return GLX_BAD_ATTRIBUTE;
1438 if (xmvis->mesa_visual.rgbMode) {
1439 *value = True;
1440 }
1441 else {
1442 *value = False;
1443 }
1444 return 0;
1445 case GLX_DOUBLEBUFFER:
1446 *value = (int) xmvis->mesa_visual.doubleBufferMode;
1447 return 0;
1448 case GLX_STEREO:
1449 *value = (int) xmvis->mesa_visual.stereoMode;
1450 return 0;
1451 case GLX_AUX_BUFFERS:
1452 *value = xmvis->mesa_visual.numAuxBuffers;
1453 return 0;
1454 case GLX_RED_SIZE:
1455 *value = xmvis->mesa_visual.redBits;
1456 return 0;
1457 case GLX_GREEN_SIZE:
1458 *value = xmvis->mesa_visual.greenBits;
1459 return 0;
1460 case GLX_BLUE_SIZE:
1461 *value = xmvis->mesa_visual.blueBits;
1462 return 0;
1463 case GLX_ALPHA_SIZE:
1464 *value = xmvis->mesa_visual.alphaBits;
1465 return 0;
1466 case GLX_DEPTH_SIZE:
1467 *value = xmvis->mesa_visual.depthBits;
1468 return 0;
1469 case GLX_STENCIL_SIZE:
1470 *value = xmvis->mesa_visual.stencilBits;
1471 return 0;
1472 case GLX_ACCUM_RED_SIZE:
1473 *value = xmvis->mesa_visual.accumRedBits;
1474 return 0;
1475 case GLX_ACCUM_GREEN_SIZE:
1476 *value = xmvis->mesa_visual.accumGreenBits;
1477 return 0;
1478 case GLX_ACCUM_BLUE_SIZE:
1479 *value = xmvis->mesa_visual.accumBlueBits;
1480 return 0;
1481 case GLX_ACCUM_ALPHA_SIZE:
1482 *value = xmvis->mesa_visual.accumAlphaBits;
1483 return 0;
1484
1485 /*
1486 * GLX_EXT_visual_info extension
1487 */
1488 case GLX_X_VISUAL_TYPE_EXT:
1489 switch (xmvis->visinfo->CLASS) {
1490 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1491 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1492 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1493 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1494 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1495 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1496 }
1497 return 0;
1498 case GLX_TRANSPARENT_TYPE_EXT:
1499 /* normal planes */
1500 *value = GLX_NONE_EXT;
1501 return 0;
1502 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1503 /* undefined */
1504 return 0;
1505 case GLX_TRANSPARENT_RED_VALUE_EXT:
1506 /* undefined */
1507 return 0;
1508 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1509 /* undefined */
1510 return 0;
1511 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1512 /* undefined */
1513 return 0;
1514 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1515 /* undefined */
1516 return 0;
1517
1518 /*
1519 * GLX_EXT_visual_info extension
1520 */
1521 case GLX_VISUAL_CAVEAT_EXT:
1522 /* test for zero, just in case */
1523 if (xmvis->mesa_visual.visualRating > 0)
1524 *value = xmvis->mesa_visual.visualRating;
1525 else
1526 *value = GLX_NONE_EXT;
1527 return 0;
1528
1529 /*
1530 * GLX_ARB_multisample
1531 */
1532 case GLX_SAMPLE_BUFFERS_ARB:
1533 *value = 0;
1534 return 0;
1535 case GLX_SAMPLES_ARB:
1536 *value = 0;
1537 return 0;
1538
1539 /*
1540 * For FBConfigs:
1541 */
1542 case GLX_SCREEN_EXT:
1543 if (!fbconfig)
1544 return GLX_BAD_ATTRIBUTE;
1545 *value = xmvis->visinfo->screen;
1546 break;
1547 case GLX_DRAWABLE_TYPE: /*SGIX too */
1548 if (!fbconfig)
1549 return GLX_BAD_ATTRIBUTE;
1550 *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
1551 break;
1552 case GLX_RENDER_TYPE_SGIX:
1553 if (!fbconfig)
1554 return GLX_BAD_ATTRIBUTE;
1555 if (xmvis->mesa_visual.rgbMode)
1556 *value = GLX_RGBA_BIT;
1557 else
1558 *value = GLX_COLOR_INDEX_BIT;
1559 break;
1560 case GLX_X_RENDERABLE_SGIX:
1561 if (!fbconfig)
1562 return GLX_BAD_ATTRIBUTE;
1563 *value = True; /* XXX really? */
1564 break;
1565 case GLX_FBCONFIG_ID_SGIX:
1566 if (!fbconfig)
1567 return GLX_BAD_ATTRIBUTE;
1568 *value = xmvis->visinfo->visualid;
1569 break;
1570 case GLX_MAX_PBUFFER_WIDTH:
1571 if (!fbconfig)
1572 return GLX_BAD_ATTRIBUTE;
1573 /* XXX or MAX_WIDTH? */
1574 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
1575 break;
1576 case GLX_MAX_PBUFFER_HEIGHT:
1577 if (!fbconfig)
1578 return GLX_BAD_ATTRIBUTE;
1579 *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1580 break;
1581 case GLX_MAX_PBUFFER_PIXELS:
1582 if (!fbconfig)
1583 return GLX_BAD_ATTRIBUTE;
1584 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1585 DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1586 break;
1587 case GLX_VISUAL_ID:
1588 if (!fbconfig)
1589 return GLX_BAD_ATTRIBUTE;
1590 *value = xmvis->visinfo->visualid;
1591 break;
1592
1593 #ifdef GLX_EXT_texture_from_pixmap
1594 case GLX_BIND_TO_TEXTURE_RGB_EXT:
1595 *value = True; /*XXX*/
1596 break;
1597 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1598 /* XXX review */
1599 *value = xmvis->mesa_visual.alphaBits > 0 ? True : False;
1600 break;
1601 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1602 *value = True; /*XXX*/
1603 break;
1604 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1605 *value = (GLX_TEXTURE_1D_BIT_EXT |
1606 GLX_TEXTURE_2D_BIT_EXT |
1607 GLX_TEXTURE_RECTANGLE_BIT_EXT); /*XXX*/
1608 break;
1609 case GLX_Y_INVERTED_EXT:
1610 *value = True; /*XXX*/
1611 break;
1612 #endif
1613
1614 default:
1615 return GLX_BAD_ATTRIBUTE;
1616 }
1617 return Success;
1618 }
1619
1620
1621 int
1622 glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1623 int attrib, int *value )
1624 {
1625 XMesaVisual xmvis;
1626 int k;
1627 if (!dpy || !visinfo)
1628 return GLX_BAD_ATTRIBUTE;
1629
1630 xmvis = find_glx_visual( dpy, visinfo );
1631 if (!xmvis) {
1632 /* this visual wasn't obtained with glXChooseVisual */
1633 xmvis = create_glx_visual( dpy, visinfo );
1634 if (!xmvis) {
1635 /* this visual can't be used for GL rendering */
1636 if (attrib==GLX_USE_GL) {
1637 *value = (int) False;
1638 return 0;
1639 }
1640 else {
1641 return GLX_BAD_VISUAL;
1642 }
1643 }
1644 }
1645
1646 k = get_config(xmvis, attrib, value, GL_FALSE);
1647 return k;
1648 }
1649
1650
1651 void
1652 glXWaitGL( void )
1653 {
1654 XMesaContext xmesa = XMesaGetCurrentContext();
1655 XMesaFlush( xmesa );
1656 }
1657
1658
1659
1660 void
1661 glXWaitX( void )
1662 {
1663 XMesaContext xmesa = XMesaGetCurrentContext();
1664 XMesaFlush( xmesa );
1665 }
1666
1667
1668 static const char *
1669 get_extensions( void )
1670 {
1671 return EXTENSIONS;
1672 }
1673
1674
1675
1676 /* GLX 1.1 and later */
1677 const char *
1678 glXQueryExtensionsString( Display *dpy, int screen )
1679 {
1680 (void) dpy;
1681 (void) screen;
1682 return get_extensions();
1683 }
1684
1685
1686
1687 /* GLX 1.1 and later */
1688 const char *
1689 glXQueryServerString( Display *dpy, int screen, int name )
1690 {
1691 static char version[1000];
1692 _mesa_sprintf(version, "%d.%d %s",
1693 SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
1694
1695 (void) dpy;
1696 (void) screen;
1697
1698 switch (name) {
1699 case GLX_EXTENSIONS:
1700 return get_extensions();
1701 case GLX_VENDOR:
1702 return VENDOR;
1703 case GLX_VERSION:
1704 return version;
1705 default:
1706 return NULL;
1707 }
1708 }
1709
1710
1711
1712 /* GLX 1.1 and later */
1713 const char *
1714 glXGetClientString( Display *dpy, int name )
1715 {
1716 static char version[1000];
1717 _mesa_sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
1718 CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
1719
1720 (void) dpy;
1721
1722 switch (name) {
1723 case GLX_EXTENSIONS:
1724 return get_extensions();
1725 case GLX_VENDOR:
1726 return VENDOR;
1727 case GLX_VERSION:
1728 return version;
1729 default:
1730 return NULL;
1731 }
1732 }
1733
1734
1735
1736 /*
1737 * GLX 1.3 and later
1738 */
1739
1740
1741 int
1742 glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
1743 int attribute, int *value )
1744 {
1745 XMesaVisual v = (XMesaVisual) config;
1746 (void) dpy;
1747 (void) config;
1748
1749 if (!dpy || !config || !value)
1750 return -1;
1751
1752 return get_config(v, attribute, value, GL_TRUE);
1753 }
1754
1755
1756 GLXFBConfig *
1757 glXGetFBConfigs( Display *dpy, int screen, int *nelements )
1758 {
1759 XVisualInfo *visuals, visTemplate;
1760 const long visMask = VisualScreenMask;
1761 int i;
1762
1763 /* Get list of all X visuals */
1764 visTemplate.screen = screen;
1765 visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
1766 if (*nelements > 0) {
1767 XMesaVisual *results;
1768 results = (XMesaVisual *) _mesa_malloc(*nelements * sizeof(XMesaVisual));
1769 if (!results) {
1770 *nelements = 0;
1771 return NULL;
1772 }
1773 for (i = 0; i < *nelements; i++) {
1774 results[i] = create_glx_visual(dpy, visuals + i);
1775 }
1776 return (GLXFBConfig *) results;
1777 }
1778 return NULL;
1779 }
1780
1781
1782 GLXFBConfig *
1783 glXChooseFBConfig( Display *dpy, int screen,
1784 const int *attribList, int *nitems )
1785 {
1786 XMesaVisual xmvis;
1787
1788 if (!attribList || !attribList[0]) {
1789 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1790 return glXGetFBConfigs(dpy, screen, nitems);
1791 }
1792
1793 xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
1794 if (xmvis) {
1795 GLXFBConfig *config = (GLXFBConfig *) _mesa_malloc(sizeof(XMesaVisual));
1796 if (!config) {
1797 *nitems = 0;
1798 return NULL;
1799 }
1800 *nitems = 1;
1801 config[0] = (GLXFBConfig) xmvis;
1802 return (GLXFBConfig *) config;
1803 }
1804 else {
1805 *nitems = 0;
1806 return NULL;
1807 }
1808 }
1809
1810
1811 XVisualInfo *
1812 glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1813 {
1814 if (dpy && config) {
1815 XMesaVisual xmvis = (XMesaVisual) config;
1816 #if 0
1817 return xmvis->vishandle;
1818 #else
1819 /* create a new vishandle - the cached one may be stale */
1820 xmvis->vishandle = (XVisualInfo *) _mesa_malloc(sizeof(XVisualInfo));
1821 if (xmvis->vishandle) {
1822 _mesa_memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
1823 }
1824 return xmvis->vishandle;
1825 #endif
1826 }
1827 else {
1828 return NULL;
1829 }
1830 }
1831
1832
1833 GLXWindow
1834 glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
1835 const int *attribList )
1836 {
1837 XMesaVisual xmvis = (XMesaVisual) config;
1838 XMesaBuffer xmbuf;
1839 if (!xmvis)
1840 return 0;
1841
1842 xmbuf = XMesaCreateWindowBuffer(xmvis, win);
1843 if (!xmbuf)
1844 return 0;
1845
1846 (void) dpy;
1847 (void) attribList; /* Ignored in GLX 1.3 */
1848
1849 return win; /* A hack for now */
1850 }
1851
1852
1853 void
1854 glXDestroyWindow( Display *dpy, GLXWindow window )
1855 {
1856 XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable) window);
1857 if (b)
1858 XMesaDestroyBuffer(b);
1859 /* don't destroy X window */
1860 }
1861
1862
1863 /* XXX untested */
1864 GLXPixmap
1865 glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
1866 const int *attribList )
1867 {
1868 XMesaVisual v = (XMesaVisual) config;
1869 XMesaBuffer b;
1870 const int *attr;
1871 int target = 0, format = 0, mipmap = 0;
1872 int value;
1873
1874 if (!dpy || !config || !pixmap)
1875 return 0;
1876
1877 for (attr = attribList; attr && *attr; attr++) {
1878 switch (*attr) {
1879 case GLX_TEXTURE_FORMAT_EXT:
1880 attr++;
1881 switch (*attr) {
1882 case GLX_TEXTURE_FORMAT_NONE_EXT:
1883 case GLX_TEXTURE_FORMAT_RGB_EXT:
1884 case GLX_TEXTURE_FORMAT_RGBA_EXT:
1885 format = *attr;
1886 break;
1887 default:
1888 /* error */
1889 return 0;
1890 }
1891 break;
1892 case GLX_TEXTURE_TARGET_EXT:
1893 attr++;
1894 switch (*attr) {
1895 case GLX_TEXTURE_1D_EXT:
1896 case GLX_TEXTURE_2D_EXT:
1897 case GLX_TEXTURE_RECTANGLE_EXT:
1898 target = *attr;
1899 break;
1900 default:
1901 /* error */
1902 return 0;
1903 }
1904 break;
1905 case GLX_MIPMAP_TEXTURE_EXT:
1906 attr++;
1907 if (*attr)
1908 mipmap = 1;
1909 break;
1910 default:
1911 /* error */
1912 return 0;
1913 }
1914 }
1915
1916 if (format == GLX_TEXTURE_FORMAT_RGB_EXT) {
1917 if (get_config(v, GLX_BIND_TO_TEXTURE_RGB_EXT,
1918 &value, GL_TRUE) != Success
1919 || !value) {
1920 return 0; /* error! */
1921 }
1922 }
1923 else if (format == GLX_TEXTURE_FORMAT_RGBA_EXT) {
1924 if (get_config(v, GLX_BIND_TO_TEXTURE_RGBA_EXT,
1925 &value, GL_TRUE) != Success
1926 || !value) {
1927 return 0; /* error! */
1928 }
1929 }
1930 if (mipmap) {
1931 if (get_config(v, GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
1932 &value, GL_TRUE) != Success
1933 || !value) {
1934 return 0; /* error! */
1935 }
1936 }
1937 if (target == GLX_TEXTURE_1D_EXT) {
1938 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1939 &value, GL_TRUE) != Success
1940 || (value & GLX_TEXTURE_1D_BIT_EXT) == 0) {
1941 return 0; /* error! */
1942 }
1943 }
1944 else if (target == GLX_TEXTURE_2D_EXT) {
1945 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1946 &value, GL_TRUE) != Success
1947 || (value & GLX_TEXTURE_2D_BIT_EXT) == 0) {
1948 return 0; /* error! */
1949 }
1950 }
1951 if (target == GLX_TEXTURE_RECTANGLE_EXT) {
1952 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
1953 &value, GL_TRUE) != Success
1954 || (value & GLX_TEXTURE_RECTANGLE_BIT_EXT) == 0) {
1955 return 0; /* error! */
1956 }
1957 }
1958
1959 if (format || target || mipmap) {
1960 /* texture from pixmap */
1961 b = XMesaCreatePixmapTextureBuffer(v, pixmap, 0, format, target, mipmap);
1962 }
1963 else {
1964 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1965 }
1966 if (!b) {
1967 return 0;
1968 }
1969
1970 return pixmap;
1971 }
1972
1973
1974 void
1975 glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
1976 {
1977 XMesaBuffer b = XMesaFindBuffer(dpy, (Drawable)pixmap);
1978 if (b)
1979 XMesaDestroyBuffer(b);
1980 /* don't destroy X pixmap */
1981 }
1982
1983
1984 GLXPbuffer
1985 glXCreatePbuffer( Display *dpy, GLXFBConfig config,
1986 const int *attribList )
1987 {
1988 XMesaVisual xmvis = (XMesaVisual) config;
1989 XMesaBuffer xmbuf;
1990 const int *attrib;
1991 int width = 0, height = 0;
1992 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
1993
1994 (void) dpy;
1995
1996 for (attrib = attribList; *attrib; attrib++) {
1997 switch (*attrib) {
1998 case GLX_PBUFFER_WIDTH:
1999 attrib++;
2000 width = *attrib;
2001 break;
2002 case GLX_PBUFFER_HEIGHT:
2003 attrib++;
2004 height = *attrib;
2005 break;
2006 case GLX_PRESERVED_CONTENTS:
2007 attrib++;
2008 preserveContents = *attrib; /* ignored */
2009 break;
2010 case GLX_LARGEST_PBUFFER:
2011 attrib++;
2012 useLargest = *attrib; /* ignored */
2013 break;
2014 default:
2015 return 0;
2016 }
2017 }
2018
2019 /* not used at this time */
2020 (void) useLargest;
2021 (void) preserveContents;
2022
2023 if (width == 0 || height == 0)
2024 return 0;
2025
2026 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2027 /* A GLXPbuffer handle must be an X Drawable because that's what
2028 * glXMakeCurrent takes.
2029 */
2030 if (xmbuf)
2031 return (GLXPbuffer) xmbuf->drawable;
2032 else
2033 return 0;
2034 }
2035
2036
2037 void
2038 glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2039 {
2040 XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2041 if (b) {
2042 XMesaDestroyBuffer(b);
2043 }
2044 }
2045
2046
2047 void
2048 glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2049 unsigned int *value )
2050 {
2051 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2052 if (!xmbuf)
2053 return;
2054
2055 switch (attribute) {
2056 case GLX_WIDTH:
2057 *value = xmesa_buffer_width(xmbuf);
2058 break;
2059 case GLX_HEIGHT:
2060 *value = xmesa_buffer_width(xmbuf);
2061 break;
2062 case GLX_PRESERVED_CONTENTS:
2063 *value = True;
2064 break;
2065 case GLX_LARGEST_PBUFFER:
2066 *value = xmesa_buffer_width(xmbuf) * xmesa_buffer_height(xmbuf);
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 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 _mesa_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 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_BIT;
2139 else
2140 *value = GLX_COLOR_INDEX_BIT;
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 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 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 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 int
2190 glXGetVideoSyncSGI(unsigned int *count)
2191 {
2192 /* this is a bogus implementation */
2193 *count = FrameCounter++;
2194 return 0;
2195 }
2196
2197 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 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 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 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 void
2257 glXFreeContextEXT(Display *dpy, GLXContext context)
2258 {
2259 (void) dpy;
2260 (void) context;
2261 }
2262
2263 GLXContextID
2264 glXGetContextIDEXT(const GLXContext context)
2265 {
2266 (void) context;
2267 return 0;
2268 }
2269
2270 GLXContext
2271 glXImportContextEXT(Display *dpy, GLXContextID contextID)
2272 {
2273 (void) dpy;
2274 (void) contextID;
2275 return 0;
2276 }
2277
2278 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 int
2293 glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2294 {
2295 return glXGetFBConfigAttrib(dpy, config, attribute, value);
2296 }
2297
2298 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 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 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 _mesa_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 XVisualInfo *
2344 glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2345 {
2346 return glXGetVisualFromFBConfig(dpy, config);
2347 }
2348
2349
2350 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 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 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 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 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 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 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 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 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 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 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 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 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 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 void
2578 glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2579 {
2580 (void) dpy;
2581 (void) drawable;
2582 (void) barrier;
2583 }
2584
2585 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 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 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 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 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 }