xlib: fix memory leak of and remove vishandle from XMesaVisualInfo
[mesa.git] / src / mesa / drivers / x11 / fakeglx.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /*
28 * This is an emulation of the GLX API which allows Mesa/GLX-based programs
29 * to run on X servers which do not have the real GLX extension.
30 *
31 * Thanks to the contributors:
32 *
33 * Initial version: Philip Brown (phil@bolthole.com)
34 * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu)
35 * Further visual-handling refinements: Wolfram Gloger
36 * (wmglo@Dent.MED.Uni-Muenchen.DE).
37 *
38 * Notes:
39 * Don't be fooled, stereo isn't supported yet.
40 */
41
42
43 #include <string.h>
44 #include <stdio.h>
45 #include "glxheader.h"
46 #include "glxapi.h"
47 #include "main/context.h"
48 #include "main/config.h"
49 #include "main/macros.h"
50 #include "main/imports.h"
51 #include "main/mtypes.h"
52 #include "main/version.h"
53 #include "xfonts.h"
54 #include "xmesaP.h"
55
56 /* This indicates the client-side GLX API and GLX encoder version. */
57 #define CLIENT_MAJOR_VERSION 1
58 #define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */
59
60 /* This indicates the server-side GLX decoder version.
61 * GLX 1.4 indicates OpenGL 1.3 support
62 */
63 #define SERVER_MAJOR_VERSION 1
64 #define SERVER_MINOR_VERSION 4
65
66 /* This is appended onto the glXGetClient/ServerString version strings. */
67 #define MESA_GLX_VERSION "Mesa " PACKAGE_VERSION
68
69 /* Who implemented this GLX? */
70 #define VENDOR "Brian Paul"
71
72 #define EXTENSIONS \
73 "GLX_MESA_set_3dfx_mode " \
74 "GLX_MESA_copy_sub_buffer " \
75 "GLX_MESA_pixmap_colormap " \
76 "GLX_MESA_release_buffers " \
77 "GLX_ARB_create_context " \
78 "GLX_ARB_get_proc_address " \
79 "GLX_EXT_texture_from_pixmap " \
80 "GLX_EXT_visual_info " \
81 "GLX_EXT_visual_rating " \
82 /*"GLX_SGI_video_sync "*/ \
83 "GLX_SGIX_fbconfig " \
84 "GLX_SGIX_pbuffer "
85
86
87
88 /**********************************************************************/
89 /*** GLX Visual Code ***/
90 /**********************************************************************/
91
92 #define DONT_CARE -1
93
94
95 static XMesaVisual *VisualTable = NULL;
96 static int NumVisuals = 0;
97
98
99 /*
100 * This struct and some code fragments borrowed
101 * from Mark Kilgard's GLUT library.
102 */
103 typedef struct _OverlayInfo {
104 /* Avoid 64-bit portability problems by being careful to use
105 longs due to the way XGetWindowProperty is specified. Note
106 that these parameters are passed as CARD32s over X
107 protocol. */
108 unsigned long overlay_visual;
109 long transparent_type;
110 long value;
111 long layer;
112 } OverlayInfo;
113
114
115
116 /* Macro to handle c_class vs class field name in XVisualInfo struct */
117 #if defined(__cplusplus) || defined(c_plusplus)
118 #define CLASS c_class
119 #else
120 #define CLASS class
121 #endif
122
123
124
125 /*
126 * Test if the given XVisualInfo is usable for Mesa rendering.
127 */
128 static GLboolean
129 is_usable_visual( XVisualInfo *vinfo )
130 {
131 switch (vinfo->CLASS) {
132 case StaticGray:
133 case GrayScale:
134 /* Any StaticGray/GrayScale visual works in RGB or CI mode */
135 return GL_TRUE;
136 case StaticColor:
137 case PseudoColor:
138 /* Color-index rendering is not supported. */
139 return GL_FALSE;
140 case TrueColor:
141 case DirectColor:
142 /* Any depth of TrueColor or DirectColor works in RGB mode */
143 return GL_TRUE;
144 default:
145 /* This should never happen */
146 return GL_FALSE;
147 }
148 }
149
150
151
152 /**
153 * Get an array OverlayInfo records for specified screen.
154 * \param dpy the display
155 * \param screen screen number
156 * \param numOverlays returns numver of OverlayInfo records
157 * \return pointer to OverlayInfo array, free with XFree()
158 */
159 static OverlayInfo *
160 GetOverlayInfo(Display *dpy, int screen, int *numOverlays)
161 {
162 Atom overlayVisualsAtom;
163 Atom actualType;
164 Status status;
165 unsigned char *ovInfo;
166 unsigned long sizeData, bytesLeft;
167 int actualFormat;
168
169 /*
170 * The SERVER_OVERLAY_VISUALS property on the root window contains
171 * a list of overlay visuals. Get that list now.
172 */
173 overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True);
174 if (overlayVisualsAtom == None) {
175 return 0;
176 }
177
178 status = XGetWindowProperty(dpy, RootWindow(dpy, screen),
179 overlayVisualsAtom, 0L, (long) 10000, False,
180 overlayVisualsAtom, &actualType, &actualFormat,
181 &sizeData, &bytesLeft,
182 &ovInfo);
183
184 if (status != Success || actualType != overlayVisualsAtom ||
185 actualFormat != 32 || sizeData < 4) {
186 /* something went wrong */
187 free((void *) ovInfo);
188 *numOverlays = 0;
189 return NULL;
190 }
191
192 *numOverlays = sizeData / 4;
193 return (OverlayInfo *) ovInfo;
194 }
195
196
197
198 /**
199 * Return the level (overlay, normal, underlay) of a given XVisualInfo.
200 * Input: dpy - the X display
201 * vinfo - the XVisualInfo to test
202 * Return: level of the visual:
203 * 0 = normal planes
204 * >0 = overlay planes
205 * <0 = underlay planes
206 */
207 static int
208 level_of_visual( Display *dpy, XVisualInfo *vinfo )
209 {
210 OverlayInfo *overlay_info;
211 int numOverlaysPerScreen, i;
212
213 overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen);
214 if (!overlay_info) {
215 return 0;
216 }
217
218 /* search the overlay visual list for the visual ID of interest */
219 for (i = 0; i < numOverlaysPerScreen; i++) {
220 const OverlayInfo *ov = overlay_info + i;
221 if (ov->overlay_visual == vinfo->visualid) {
222 /* found the visual */
223 if (/*ov->transparent_type==1 &&*/ ov->layer!=0) {
224 int level = ov->layer;
225 free((void *) overlay_info);
226 return level;
227 }
228 else {
229 free((void *) overlay_info);
230 return 0;
231 }
232 }
233 }
234
235 /* The visual ID was not found in the overlay list. */
236 free((void *) overlay_info);
237 return 0;
238 }
239
240
241
242
243 /*
244 * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the
245 * configuration in our list of GLX visuals.
246 */
247 static XMesaVisual
248 save_glx_visual( Display *dpy, XVisualInfo *vinfo,
249 GLboolean alphaFlag, GLboolean dbFlag,
250 GLboolean stereoFlag,
251 GLint depth_size, GLint stencil_size,
252 GLint accumRedSize, GLint accumGreenSize,
253 GLint accumBlueSize, GLint accumAlphaSize,
254 GLint level, GLint numAuxBuffers )
255 {
256 GLboolean ximageFlag = GL_TRUE;
257 XMesaVisual xmvis;
258 GLint i;
259
260 if (dbFlag) {
261 /* Check if the MESA_BACK_BUFFER env var is set */
262 char *backbuffer = getenv("MESA_BACK_BUFFER");
263 if (backbuffer) {
264 if (backbuffer[0]=='p' || backbuffer[0]=='P') {
265 ximageFlag = GL_FALSE;
266 }
267 else if (backbuffer[0]=='x' || backbuffer[0]=='X') {
268 ximageFlag = GL_TRUE;
269 }
270 else {
271 _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage.");
272 }
273 }
274 }
275
276 if (stereoFlag) {
277 /* stereo not supported */
278 return NULL;
279 }
280
281
282 /* Force the visual to have an alpha channel */
283 if (getenv("MESA_GLX_FORCE_ALPHA"))
284 alphaFlag = GL_TRUE;
285
286 /* Comparing IDs uses less memory but sometimes fails. */
287 /* XXX revisit this after 3.0 is finished. */
288 if (!getenv("MESA_GLX_VISUAL_HACK")) {
289 /* First check if a matching visual is already in the list */
290 for (i=0; i<NumVisuals; i++) {
291 XMesaVisual v = VisualTable[i];
292 if (v->display == dpy
293 && v->mesa_visual.level == level
294 && v->mesa_visual.numAuxBuffers == numAuxBuffers
295 && v->ximage_flag == ximageFlag
296 && v->mesa_visual.doubleBufferMode == dbFlag
297 && v->mesa_visual.stereoMode == stereoFlag
298 && (v->mesa_visual.alphaBits > 0) == alphaFlag
299 && (v->mesa_visual.depthBits >= depth_size || depth_size == 0)
300 && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0)
301 && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0)
302 && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0)
303 && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0)
304 && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) {
305 /* now compare visual IDs */
306 if (v->visinfo->visualid == vinfo->visualid) {
307 return v;
308 }
309 }
310 }
311 }
312
313 /* Create a new visual and add it to the list. */
314
315 xmvis = XMesaCreateVisual( dpy, vinfo, GL_TRUE, alphaFlag, dbFlag,
316 stereoFlag, ximageFlag,
317 depth_size, stencil_size,
318 accumRedSize, accumBlueSize,
319 accumBlueSize, accumAlphaSize, 0, level,
320 GLX_NONE_EXT );
321 if (xmvis) {
322 /* Allocate more space for additional visual */
323 VisualTable = realloc(VisualTable, sizeof(XMesaVisual) * (NumVisuals + 1));
324 /* add xmvis to the list */
325 VisualTable[NumVisuals] = xmvis;
326 NumVisuals++;
327 /* XXX minor hack, because XMesaCreateVisual doesn't support an
328 * aux buffers parameter.
329 */
330 xmvis->mesa_visual.numAuxBuffers = numAuxBuffers;
331 }
332 return xmvis;
333 }
334
335
336 /**
337 * Return the default number of bits for the Z buffer.
338 * If defined, use the MESA_GLX_DEPTH_BITS env var value.
339 * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant.
340 * XXX probably do the same thing for stencil, accum, etc.
341 */
342 static GLint
343 default_depth_bits(void)
344 {
345 int zBits;
346 const char *zEnv = getenv("MESA_GLX_DEPTH_BITS");
347 if (zEnv)
348 zBits = atoi(zEnv);
349 else
350 zBits = DEFAULT_SOFTWARE_DEPTH_BITS;
351 return zBits;
352 }
353
354 static GLint
355 default_alpha_bits(void)
356 {
357 int aBits;
358 const char *aEnv = getenv("MESA_GLX_ALPHA_BITS");
359 if (aEnv)
360 aBits = atoi(aEnv);
361 else
362 aBits = 0;
363 return aBits;
364 }
365
366 static GLint
367 default_accum_bits(void)
368 {
369 return 16;
370 }
371
372
373
374 /*
375 * Create a GLX visual from a regular XVisualInfo.
376 * This is called when Fake GLX is given an XVisualInfo which wasn't
377 * returned by glXChooseVisual. Since this is the first time we're
378 * considering this visual we'll take a guess at reasonable values
379 * for depth buffer size, stencil size, accum size, etc.
380 * This is the best we can do with a client-side emulation of GLX.
381 */
382 static XMesaVisual
383 create_glx_visual( Display *dpy, XVisualInfo *visinfo )
384 {
385 int vislevel;
386 GLint zBits = default_depth_bits();
387 GLint accBits = default_accum_bits();
388 GLboolean alphaFlag = default_alpha_bits() > 0;
389
390 vislevel = level_of_visual( dpy, visinfo );
391 if (vislevel) {
392 /* Color-index rendering to overlays is not supported. */
393 return NULL;
394 }
395 else if (is_usable_visual( visinfo )) {
396 /* Configure this visual as RGB, double-buffered, depth-buffered. */
397 /* This is surely wrong for some people's needs but what else */
398 /* can be done? They should use glXChooseVisual(). */
399 return save_glx_visual( dpy, visinfo,
400 alphaFlag, /* alpha */
401 GL_TRUE, /* double */
402 GL_FALSE, /* stereo */
403 zBits,
404 8, /* stencil bits */
405 accBits, /* r */
406 accBits, /* g */
407 accBits, /* b */
408 accBits, /* a */
409 0, /* level */
410 0 /* numAux */
411 );
412 }
413 else {
414 _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");
415 return NULL;
416 }
417 }
418
419
420
421 /*
422 * Find the GLX visual associated with an XVisualInfo.
423 */
424 static XMesaVisual
425 find_glx_visual( Display *dpy, XVisualInfo *vinfo )
426 {
427 int i;
428
429 /* try to match visual id */
430 for (i=0;i<NumVisuals;i++) {
431 if (VisualTable[i]->display==dpy
432 && VisualTable[i]->visinfo->visualid == vinfo->visualid) {
433 return VisualTable[i];
434 }
435 }
436
437 return NULL;
438 }
439
440
441
442 /**
443 * Return the transparent pixel value for a GLX visual.
444 * Input: glxvis - the glx_visual
445 * Return: a pixel value or -1 if no transparent pixel
446 */
447 static int
448 transparent_pixel( XMesaVisual glxvis )
449 {
450 Display *dpy = glxvis->display;
451 XVisualInfo *vinfo = glxvis->visinfo;
452 OverlayInfo *overlay_info;
453 int numOverlaysPerScreen, i;
454
455 overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen);
456 if (!overlay_info) {
457 return -1;
458 }
459
460 for (i = 0; i < numOverlaysPerScreen; i++) {
461 const OverlayInfo *ov = overlay_info + i;
462 if (ov->overlay_visual == vinfo->visualid) {
463 /* found it! */
464 if (ov->transparent_type == 0) {
465 /* type 0 indicates no transparency */
466 free((void *) overlay_info);
467 return -1;
468 }
469 else {
470 /* ov->value is the transparent pixel */
471 free((void *) overlay_info);
472 return ov->value;
473 }
474 }
475 }
476
477 /* The visual ID was not found in the overlay list. */
478 free((void *) overlay_info);
479 return -1;
480 }
481
482
483
484 /**
485 * Try to get an X visual which matches the given arguments.
486 */
487 static XVisualInfo *
488 get_visual( Display *dpy, int scr, unsigned int depth, int xclass )
489 {
490 XVisualInfo temp, *vis;
491 long mask;
492 int n;
493 unsigned int default_depth;
494 int default_class;
495
496 mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
497 temp.screen = scr;
498 temp.depth = depth;
499 temp.CLASS = xclass;
500
501 default_depth = DefaultDepth(dpy,scr);
502 default_class = DefaultVisual(dpy,scr)->CLASS;
503
504 if (depth==default_depth && xclass==default_class) {
505 /* try to get root window's visual */
506 temp.visualid = DefaultVisual(dpy,scr)->visualid;
507 mask |= VisualIDMask;
508 }
509
510 vis = XGetVisualInfo( dpy, mask, &temp, &n );
511
512 /* In case bits/pixel > 24, make sure color channels are still <=8 bits.
513 * An SGI Infinite Reality system, for example, can have 30bpp pixels:
514 * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel.
515 */
516 if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {
517 if (_mesa_bitcount((GLuint) vis->red_mask ) <= 8 &&
518 _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&
519 _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {
520 return vis;
521 }
522 else {
523 free((void *) vis);
524 return NULL;
525 }
526 }
527
528 return vis;
529 }
530
531
532
533 /*
534 * Retrieve the value of the given environment variable and find
535 * the X visual which matches it.
536 * Input: dpy - the display
537 * screen - the screen number
538 * varname - the name of the environment variable
539 * Return: an XVisualInfo pointer to NULL if error.
540 */
541 static XVisualInfo *
542 get_env_visual(Display *dpy, int scr, const char *varname)
543 {
544 char value[100], type[100];
545 int depth, xclass = -1;
546 XVisualInfo *vis;
547
548 if (!getenv( varname )) {
549 return NULL;
550 }
551
552 strncpy( value, getenv(varname), 100 );
553 value[99] = 0;
554
555 sscanf( value, "%s %d", type, &depth );
556
557 if (strcmp(type,"TrueColor")==0) xclass = TrueColor;
558 else if (strcmp(type,"DirectColor")==0) xclass = DirectColor;
559 else if (strcmp(type,"GrayScale")==0) xclass = GrayScale;
560 else if (strcmp(type,"StaticGray")==0) xclass = StaticGray;
561
562 if (xclass>-1 && depth>0) {
563 vis = get_visual( dpy, scr, depth, xclass );
564 if (vis) {
565 return vis;
566 }
567 }
568
569 _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",
570 type, depth);
571
572 return NULL;
573 }
574
575
576
577 /*
578 * Select an X visual which satisfies the RGBA/CI flag and minimum depth.
579 * Input: dpy, screen - X display and screen number
580 * min_depth - minimum visual depth
581 * preferred_class - preferred GLX visual class or DONT_CARE
582 * Return: pointer to an XVisualInfo or NULL.
583 */
584 static XVisualInfo *
585 choose_x_visual(Display *dpy, int screen, int min_depth, int preferred_class)
586 {
587 XVisualInfo *vis;
588 int xclass, visclass = 0;
589 int depth;
590
591 /* First see if the MESA_RGB_VISUAL env var is defined */
592 vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );
593 if (vis) {
594 return vis;
595 }
596 /* Otherwise, search for a suitable visual */
597 if (preferred_class==DONT_CARE) {
598 for (xclass=0;xclass<4;xclass++) {
599 switch (xclass) {
600 case 0: visclass = TrueColor; break;
601 case 1: visclass = DirectColor; break;
602 case 2: visclass = GrayScale; break;
603 case 3: visclass = StaticGray; break;
604 }
605 if (min_depth==0) {
606 /* start with shallowest */
607 for (depth=0;depth<=32;depth++) {
608 vis = get_visual( dpy, screen, depth, visclass );
609 if (vis) {
610 return vis;
611 }
612 }
613 }
614 else {
615 /* start with deepest */
616 for (depth=32;depth>=min_depth;depth--) {
617 vis = get_visual( dpy, screen, depth, visclass );
618 if (vis) {
619 return vis;
620 }
621 }
622 }
623 }
624 }
625 else {
626 /* search for a specific visual class */
627 switch (preferred_class) {
628 case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break;
629 case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break;
630 case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break;
631 case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break;
632 case GLX_PSEUDO_COLOR_EXT:
633 case GLX_STATIC_COLOR_EXT:
634 default: return NULL;
635 }
636 if (min_depth==0) {
637 /* start with shallowest */
638 for (depth=0;depth<=32;depth++) {
639 vis = get_visual( dpy, screen, depth, visclass );
640 if (vis) {
641 return vis;
642 }
643 }
644 }
645 else {
646 /* start with deepest */
647 for (depth=32;depth>=min_depth;depth--) {
648 vis = get_visual( dpy, screen, depth, visclass );
649 if (vis) {
650 return vis;
651 }
652 }
653 }
654 }
655
656 /* didn't find a visual */
657 return NULL;
658 }
659
660
661
662 /*
663 * Find the deepest X over/underlay visual of at least min_depth.
664 * Input: dpy, screen - X display and screen number
665 * level - the over/underlay level
666 * trans_type - transparent pixel type: GLX_NONE_EXT,
667 * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT,
668 * or DONT_CARE
669 * trans_value - transparent pixel value or DONT_CARE
670 * min_depth - minimum visual depth
671 * preferred_class - preferred GLX visual class or DONT_CARE
672 * Return: pointer to an XVisualInfo or NULL.
673 */
674 static XVisualInfo *
675 choose_x_overlay_visual( Display *dpy, int scr,
676 int level, int trans_type, int trans_value,
677 int min_depth, int preferred_class )
678 {
679 OverlayInfo *overlay_info;
680 int numOverlaysPerScreen;
681 int i;
682 XVisualInfo *deepvis;
683 int deepest;
684
685 /*DEBUG int tt, tv; */
686
687 switch (preferred_class) {
688 case GLX_TRUE_COLOR_EXT: preferred_class = TrueColor; break;
689 case GLX_DIRECT_COLOR_EXT: preferred_class = DirectColor; break;
690 case GLX_PSEUDO_COLOR_EXT: preferred_class = PseudoColor; break;
691 case GLX_STATIC_COLOR_EXT: preferred_class = StaticColor; break;
692 case GLX_GRAY_SCALE_EXT: preferred_class = GrayScale; break;
693 case GLX_STATIC_GRAY_EXT: preferred_class = StaticGray; break;
694 default: preferred_class = DONT_CARE;
695 }
696
697 overlay_info = GetOverlayInfo(dpy, scr, &numOverlaysPerScreen);
698 if (!overlay_info) {
699 return NULL;
700 }
701
702 /* Search for the deepest overlay which satisifies all criteria. */
703 deepest = min_depth;
704 deepvis = NULL;
705
706 for (i = 0; i < numOverlaysPerScreen; i++) {
707 const OverlayInfo *ov = overlay_info + i;
708 XVisualInfo *vislist, vistemplate;
709 int count;
710
711 if (ov->layer!=level) {
712 /* failed overlay level criteria */
713 continue;
714 }
715 if (!(trans_type==DONT_CARE
716 || (trans_type==GLX_TRANSPARENT_INDEX_EXT
717 && ov->transparent_type>0)
718 || (trans_type==GLX_NONE_EXT && ov->transparent_type==0))) {
719 /* failed transparent pixel type criteria */
720 continue;
721 }
722 if (trans_value!=DONT_CARE && trans_value!=ov->value) {
723 /* failed transparent pixel value criteria */
724 continue;
725 }
726
727 /* get XVisualInfo and check the depth */
728 vistemplate.visualid = ov->overlay_visual;
729 vistemplate.screen = scr;
730 vislist = XGetVisualInfo( dpy, VisualIDMask | VisualScreenMask,
731 &vistemplate, &count );
732
733 if (count!=1) {
734 /* something went wrong */
735 continue;
736 }
737 if (preferred_class!=DONT_CARE && preferred_class!=vislist->CLASS) {
738 /* wrong visual class */
739 continue;
740 }
741
742 /* Color-index rendering is not supported. Make sure we have True/DirectColor */
743 if (vislist->CLASS != TrueColor && vislist->CLASS != DirectColor)
744 continue;
745
746 if (deepvis==NULL || vislist->depth > deepest) {
747 /* YES! found a satisfactory visual */
748 free(deepvis);
749 deepest = vislist->depth;
750 deepvis = vislist;
751 /* DEBUG tt = ov->transparent_type;*/
752 /* DEBUG tv = ov->value; */
753 }
754 }
755
756 /*DEBUG
757 if (deepvis) {
758 printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n",
759 deepvis->visualid, level, deepvis->depth, tt, tv );
760 }
761 */
762 return deepvis;
763 }
764
765
766 /**********************************************************************/
767 /*** Display-related functions ***/
768 /**********************************************************************/
769
770
771 /**
772 * Free all XMesaVisuals which are associated with the given display.
773 */
774 static void
775 destroy_visuals_on_display(Display *dpy)
776 {
777 int i;
778 for (i = 0; i < NumVisuals; i++) {
779 if (VisualTable[i]->display == dpy) {
780 /* remove this visual */
781 int j;
782 XMesaDestroyVisual(VisualTable[i]);
783 for (j = i; j < NumVisuals - 1; j++)
784 VisualTable[j] = VisualTable[j + 1];
785 NumVisuals--;
786 }
787 }
788 }
789
790
791 /**
792 * Called from XCloseDisplay() to let us free our display-related data.
793 */
794 static int
795 close_display_callback(Display *dpy, XExtCodes *codes)
796 {
797 destroy_visuals_on_display(dpy);
798 xmesa_destroy_buffers_on_display(dpy);
799 return 0;
800 }
801
802
803 /**
804 * Look for the named extension on given display and return a pointer
805 * to the _XExtension data, or NULL if extension not found.
806 */
807 static _XExtension *
808 lookup_extension(Display *dpy, const char *extName)
809 {
810 _XExtension *ext;
811 for (ext = dpy->ext_procs; ext; ext = ext->next) {
812 if (ext->name && strcmp(ext->name, extName) == 0) {
813 return ext;
814 }
815 }
816 return NULL;
817 }
818
819
820 /**
821 * Whenever we're given a new Display pointer, call this function to
822 * register our close_display_callback function.
823 */
824 static void
825 register_with_display(Display *dpy)
826 {
827 const char *extName = "MesaGLX";
828 _XExtension *ext;
829
830 ext = lookup_extension(dpy, extName);
831 if (!ext) {
832 XExtCodes *c = XAddExtension(dpy);
833 ext = dpy->ext_procs; /* new extension is at head of list */
834 assert(c->extension == ext->codes.extension);
835 (void) c; /* silence warning */
836 ext->name = strdup(extName);
837 ext->close_display = close_display_callback;
838 }
839 }
840
841
842 /**********************************************************************/
843 /*** Begin Fake GLX API Functions ***/
844 /**********************************************************************/
845
846
847 /**
848 * Helper used by glXChooseVisual and glXChooseFBConfig.
849 * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for
850 * the later.
851 * In either case, the attribute list is terminated with the value 'None'.
852 */
853 static XMesaVisual
854 choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig )
855 {
856 const GLboolean rgbModeDefault = fbConfig;
857 const int *parselist;
858 XVisualInfo *vis;
859 int min_ci = 0;
860 int min_red=0, min_green=0, min_blue=0;
861 GLboolean rgb_flag = rgbModeDefault;
862 GLboolean alpha_flag = GL_FALSE;
863 GLboolean double_flag = GL_FALSE;
864 GLboolean stereo_flag = GL_FALSE;
865 GLint depth_size = 0;
866 GLint stencil_size = 0;
867 GLint accumRedSize = 0;
868 GLint accumGreenSize = 0;
869 GLint accumBlueSize = 0;
870 GLint accumAlphaSize = 0;
871 int level = 0;
872 int visual_type = DONT_CARE;
873 int trans_type = DONT_CARE;
874 int trans_value = DONT_CARE;
875 GLint caveat = DONT_CARE;
876 XMesaVisual xmvis = NULL;
877 int desiredVisualID = -1;
878 int numAux = 0;
879
880 parselist = list;
881
882 while (*parselist) {
883
884 if (fbConfig &&
885 parselist[1] == GLX_DONT_CARE &&
886 parselist[0] != GLX_LEVEL) {
887 /* For glXChooseFBConfig(), skip attributes whose value is
888 * GLX_DONT_CARE (-1), unless it's GLX_LEVEL (which can legitimately be
889 * a negative value).
890 *
891 * From page 17 (23 of the pdf) of the GLX 1.4 spec:
892 * GLX DONT CARE may be specified for all attributes except GLX LEVEL.
893 */
894 parselist += 2;
895 continue;
896 }
897
898 switch (*parselist) {
899 case GLX_USE_GL:
900 if (fbConfig) {
901 /* invalid token */
902 return NULL;
903 }
904 else {
905 /* skip */
906 parselist++;
907 }
908 break;
909 case GLX_BUFFER_SIZE:
910 parselist++;
911 min_ci = *parselist++;
912 break;
913 case GLX_LEVEL:
914 parselist++;
915 level = *parselist++;
916 break;
917 case GLX_RGBA:
918 if (fbConfig) {
919 /* invalid token */
920 return NULL;
921 }
922 else {
923 rgb_flag = GL_TRUE;
924 parselist++;
925 }
926 break;
927 case GLX_DOUBLEBUFFER:
928 parselist++;
929 if (fbConfig) {
930 double_flag = *parselist++;
931 }
932 else {
933 double_flag = GL_TRUE;
934 }
935 break;
936 case GLX_STEREO:
937 parselist++;
938 if (fbConfig) {
939 stereo_flag = *parselist++;
940 }
941 else {
942 stereo_flag = GL_TRUE;
943 }
944 break;
945 case GLX_AUX_BUFFERS:
946 parselist++;
947 numAux = *parselist++;
948 if (numAux > MAX_AUX_BUFFERS)
949 return NULL;
950 break;
951 case GLX_RED_SIZE:
952 parselist++;
953 min_red = *parselist++;
954 break;
955 case GLX_GREEN_SIZE:
956 parselist++;
957 min_green = *parselist++;
958 break;
959 case GLX_BLUE_SIZE:
960 parselist++;
961 min_blue = *parselist++;
962 break;
963 case GLX_ALPHA_SIZE:
964 parselist++;
965 {
966 GLint size = *parselist++;
967 alpha_flag = size ? GL_TRUE : GL_FALSE;
968 }
969 break;
970 case GLX_DEPTH_SIZE:
971 parselist++;
972 depth_size = *parselist++;
973 break;
974 case GLX_STENCIL_SIZE:
975 parselist++;
976 stencil_size = *parselist++;
977 break;
978 case GLX_ACCUM_RED_SIZE:
979 parselist++;
980 {
981 GLint size = *parselist++;
982 accumRedSize = MAX2( accumRedSize, size );
983 }
984 break;
985 case GLX_ACCUM_GREEN_SIZE:
986 parselist++;
987 {
988 GLint size = *parselist++;
989 accumGreenSize = MAX2( accumGreenSize, size );
990 }
991 break;
992 case GLX_ACCUM_BLUE_SIZE:
993 parselist++;
994 {
995 GLint size = *parselist++;
996 accumBlueSize = MAX2( accumBlueSize, size );
997 }
998 break;
999 case GLX_ACCUM_ALPHA_SIZE:
1000 parselist++;
1001 {
1002 GLint size = *parselist++;
1003 accumAlphaSize = MAX2( accumAlphaSize, size );
1004 }
1005 break;
1006
1007 /*
1008 * GLX_EXT_visual_info extension
1009 */
1010 case GLX_X_VISUAL_TYPE_EXT:
1011 parselist++;
1012 visual_type = *parselist++;
1013 break;
1014 case GLX_TRANSPARENT_TYPE_EXT:
1015 parselist++;
1016 trans_type = *parselist++;
1017 break;
1018 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1019 parselist++;
1020 trans_value = *parselist++;
1021 break;
1022 case GLX_TRANSPARENT_RED_VALUE_EXT:
1023 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1024 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1025 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1026 /* ignore */
1027 parselist++;
1028 parselist++;
1029 break;
1030
1031 /*
1032 * GLX_EXT_visual_info extension
1033 */
1034 case GLX_VISUAL_CAVEAT_EXT:
1035 parselist++;
1036 caveat = *parselist++; /* ignored for now */
1037 break;
1038
1039 /*
1040 * GLX_ARB_multisample
1041 */
1042 case GLX_SAMPLE_BUFFERS_ARB:
1043 case GLX_SAMPLES_ARB:
1044 parselist++;
1045 if (*parselist++ != 0)
1046 /* ms not supported */
1047 return NULL;
1048 break;
1049
1050 /*
1051 * FBConfig attribs.
1052 */
1053 case GLX_RENDER_TYPE:
1054 if (!fbConfig)
1055 return NULL;
1056 parselist++;
1057 if (*parselist & GLX_RGBA_BIT) {
1058 rgb_flag = GL_TRUE;
1059 }
1060 else if (*parselist & GLX_COLOR_INDEX_BIT) {
1061 rgb_flag = GL_FALSE;
1062 }
1063 else if (*parselist & (GLX_RGBA_FLOAT_BIT_ARB|GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT)) {
1064 rgb_flag = GL_TRUE;
1065 }
1066 else if (*parselist == 0) {
1067 rgb_flag = GL_TRUE;
1068 }
1069 parselist++;
1070 break;
1071 case GLX_DRAWABLE_TYPE:
1072 if (!fbConfig)
1073 return NULL;
1074 parselist++;
1075 if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) {
1076 return NULL; /* bad bit */
1077 }
1078 parselist++;
1079 break;
1080 case GLX_FBCONFIG_ID:
1081 case GLX_VISUAL_ID:
1082 if (!fbConfig)
1083 return NULL;
1084 parselist++;
1085 desiredVisualID = *parselist++;
1086 break;
1087 case GLX_X_RENDERABLE:
1088 case GLX_MAX_PBUFFER_WIDTH:
1089 case GLX_MAX_PBUFFER_HEIGHT:
1090 case GLX_MAX_PBUFFER_PIXELS:
1091 if (!fbConfig)
1092 return NULL;
1093 parselist += 2;
1094 /* ignore */
1095 break;
1096
1097 #ifdef GLX_EXT_texture_from_pixmap
1098 case GLX_BIND_TO_TEXTURE_RGB_EXT:
1099 parselist++; /*skip*/
1100 break;
1101 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1102 parselist++; /*skip*/
1103 break;
1104 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1105 parselist++; /*skip*/
1106 break;
1107 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1108 parselist++;
1109 if (*parselist & ~(GLX_TEXTURE_1D_BIT_EXT |
1110 GLX_TEXTURE_2D_BIT_EXT |
1111 GLX_TEXTURE_RECTANGLE_BIT_EXT)) {
1112 /* invalid bit */
1113 return NULL;
1114 }
1115 break;
1116 case GLX_Y_INVERTED_EXT:
1117 parselist++; /*skip*/
1118 break;
1119 #endif
1120
1121 case None:
1122 /* end of list */
1123 break;
1124
1125 default:
1126 /* undefined attribute */
1127 _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()",
1128 *parselist);
1129 return NULL;
1130 }
1131 }
1132
1133 if (!rgb_flag)
1134 return NULL;
1135
1136 (void) caveat;
1137 (void) min_ci;
1138
1139 /*
1140 * Since we're only simulating the GLX extension this function will never
1141 * find any real GL visuals. Instead, all we can do is try to find an RGB
1142 * or CI visual of appropriate depth. Other requested attributes such as
1143 * double buffering, depth buffer, etc. will be associated with the X
1144 * visual and stored in the VisualTable[].
1145 */
1146 if (desiredVisualID != -1) {
1147 /* try to get a specific visual, by visualID */
1148 XVisualInfo temp;
1149 int n;
1150 temp.visualid = desiredVisualID;
1151 temp.screen = screen;
1152 vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n);
1153 if (vis) {
1154 /* give the visual some useful GLX attributes */
1155 double_flag = GL_TRUE;
1156 if (vis->depth <= 8)
1157 return NULL;
1158 depth_size = default_depth_bits();
1159 stencil_size = 8;
1160 /* XXX accum??? */
1161 }
1162 }
1163 else {
1164 /* RGB visual */
1165 int min_rgb = min_red + min_green + min_blue;
1166 if (min_rgb>1 && min_rgb<8) {
1167 /* a special case to be sure we can get a monochrome visual */
1168 min_rgb = 1;
1169 }
1170
1171 if (level==0) {
1172 vis = choose_x_visual(dpy, screen, min_rgb, visual_type);
1173 }
1174 else {
1175 vis = choose_x_overlay_visual(dpy, screen, level,
1176 trans_type, trans_value, min_rgb, visual_type);
1177 }
1178 }
1179
1180 if (vis) {
1181 /* Note: we're not exactly obeying the glXChooseVisual rules here.
1182 * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the
1183 * largest depth buffer size, which is 32bits/value. Instead, we
1184 * return 16 to maintain performance with earlier versions of Mesa.
1185 */
1186 if (depth_size > 24)
1187 depth_size = 32;
1188 else if (depth_size > 16)
1189 depth_size = 24;
1190 else if (depth_size > 0) {
1191 depth_size = default_depth_bits();
1192 }
1193
1194 if (!alpha_flag) {
1195 alpha_flag = default_alpha_bits() > 0;
1196 }
1197
1198 /* we only support one size of stencil and accum buffers. */
1199 if (stencil_size > 0)
1200 stencil_size = 8;
1201 if (accumRedSize > 0 || accumGreenSize > 0 || accumBlueSize > 0 ||
1202 accumAlphaSize > 0) {
1203 accumRedSize =
1204 accumGreenSize =
1205 accumBlueSize = default_accum_bits();
1206 accumAlphaSize = alpha_flag ? accumRedSize : 0;
1207 }
1208
1209 xmvis = save_glx_visual( dpy, vis, alpha_flag, double_flag,
1210 stereo_flag, depth_size, stencil_size,
1211 accumRedSize, accumGreenSize,
1212 accumBlueSize, accumAlphaSize, level, numAux );
1213 free(vis);
1214 }
1215
1216 return xmvis;
1217 }
1218
1219
1220 static XVisualInfo *
1221 Fake_glXChooseVisual( Display *dpy, int screen, int *list )
1222 {
1223 XMesaVisual xmvis;
1224
1225 /* register ourselves as an extension on this display */
1226 register_with_display(dpy);
1227
1228 xmvis = choose_visual(dpy, screen, list, GL_FALSE);
1229 if (xmvis) {
1230 XVisualInfo* visinfo = malloc(sizeof(XVisualInfo));
1231 if (visinfo) {
1232 memcpy(visinfo, xmvis->visinfo, sizeof(XVisualInfo));
1233 }
1234 return visinfo;
1235 }
1236 else
1237 return NULL;
1238 }
1239
1240
1241 static GLXContext
1242 Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo,
1243 GLXContext share_list, Bool direct )
1244 {
1245 XMesaVisual xmvis;
1246 XMesaContext xmesaCtx;
1247
1248 if (!dpy || !visinfo)
1249 return 0;
1250
1251 /* deallocate unused windows/buffers */
1252 #if 0
1253 XMesaGarbageCollect(dpy);
1254 #endif
1255
1256 xmvis = find_glx_visual( dpy, visinfo );
1257 if (!xmvis) {
1258 /* This visual wasn't found with glXChooseVisual() */
1259 xmvis = create_glx_visual( dpy, visinfo );
1260 if (!xmvis) {
1261 return NULL;
1262 }
1263 }
1264
1265 xmesaCtx = XMesaCreateContext(xmvis, (XMesaContext) share_list);
1266
1267 return (GLXContext) xmesaCtx;
1268 }
1269
1270
1271 /* XXX these may have to be removed due to thread-safety issues. */
1272 static GLXContext MakeCurrent_PrevContext = 0;
1273 static GLXDrawable MakeCurrent_PrevDrawable = 0;
1274 static GLXDrawable MakeCurrent_PrevReadable = 0;
1275 static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0;
1276 static XMesaBuffer MakeCurrent_PrevReadBuffer = 0;
1277
1278
1279 /* GLX 1.3 and later */
1280 static Bool
1281 Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw,
1282 GLXDrawable read, GLXContext ctx )
1283 {
1284 if (ctx && draw && read) {
1285 XMesaBuffer drawBuffer, readBuffer;
1286 XMesaContext xmctx = (XMesaContext) ctx;
1287
1288 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */
1289 if (ctx == MakeCurrent_PrevContext
1290 && draw == MakeCurrent_PrevDrawable) {
1291 drawBuffer = MakeCurrent_PrevDrawBuffer;
1292 }
1293 else {
1294 drawBuffer = XMesaFindBuffer( dpy, draw );
1295 }
1296 if (!drawBuffer) {
1297 /* drawable must be a new window! */
1298 drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw );
1299 if (!drawBuffer) {
1300 /* Out of memory, or context/drawable depth mismatch */
1301 return False;
1302 }
1303 }
1304
1305 /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */
1306 if (ctx == MakeCurrent_PrevContext
1307 && read == MakeCurrent_PrevReadable) {
1308 readBuffer = MakeCurrent_PrevReadBuffer;
1309 }
1310 else {
1311 readBuffer = XMesaFindBuffer( dpy, read );
1312 }
1313 if (!readBuffer) {
1314 /* drawable must be a new window! */
1315 readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read );
1316 if (!readBuffer) {
1317 /* Out of memory, or context/drawable depth mismatch */
1318 return False;
1319 }
1320 }
1321
1322 MakeCurrent_PrevContext = ctx;
1323 MakeCurrent_PrevDrawable = draw;
1324 MakeCurrent_PrevReadable = read;
1325 MakeCurrent_PrevDrawBuffer = drawBuffer;
1326 MakeCurrent_PrevReadBuffer = readBuffer;
1327
1328 /* Now make current! */
1329 return XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer);
1330 }
1331 else if (!ctx && !draw && !read) {
1332 /* release current context w/out assigning new one. */
1333 XMesaMakeCurrent( NULL, NULL );
1334 MakeCurrent_PrevContext = 0;
1335 MakeCurrent_PrevDrawable = 0;
1336 MakeCurrent_PrevReadable = 0;
1337 MakeCurrent_PrevDrawBuffer = 0;
1338 MakeCurrent_PrevReadBuffer = 0;
1339 return True;
1340 }
1341 else {
1342 /* The args must either all be non-zero or all zero.
1343 * This is an error.
1344 */
1345 return False;
1346 }
1347 }
1348
1349
1350 static Bool
1351 Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx )
1352 {
1353 return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx );
1354 }
1355
1356
1357 static GLXPixmap
1358 Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap )
1359 {
1360 XMesaVisual v;
1361 XMesaBuffer b;
1362
1363 v = find_glx_visual( dpy, visinfo );
1364 if (!v) {
1365 v = create_glx_visual( dpy, visinfo );
1366 if (!v) {
1367 /* unusable visual */
1368 return 0;
1369 }
1370 }
1371
1372 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
1373 if (!b) {
1374 return 0;
1375 }
1376 return b->frontxrb->pixmap;
1377 }
1378
1379
1380 /*** GLX_MESA_pixmap_colormap ***/
1381
1382 static GLXPixmap
1383 Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo,
1384 Pixmap pixmap, Colormap cmap )
1385 {
1386 XMesaVisual v;
1387 XMesaBuffer b;
1388
1389 v = find_glx_visual( dpy, visinfo );
1390 if (!v) {
1391 v = create_glx_visual( dpy, visinfo );
1392 if (!v) {
1393 /* unusable visual */
1394 return 0;
1395 }
1396 }
1397
1398 b = XMesaCreatePixmapBuffer( v, pixmap, cmap );
1399 if (!b) {
1400 return 0;
1401 }
1402 return b->frontxrb->pixmap;
1403 }
1404
1405
1406 static void
1407 Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap )
1408 {
1409 XMesaBuffer b = XMesaFindBuffer(dpy, pixmap);
1410 if (b) {
1411 XMesaDestroyBuffer(b);
1412 }
1413 else if (getenv("MESA_DEBUG")) {
1414 _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n");
1415 }
1416 }
1417
1418
1419 static void
1420 Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst,
1421 unsigned long mask )
1422 {
1423 XMesaContext xmSrc = (XMesaContext) src;
1424 XMesaContext xmDst = (XMesaContext) dst;
1425 (void) dpy;
1426 if (MakeCurrent_PrevContext == src) {
1427 _mesa_Flush();
1428 }
1429 _mesa_copy_context( &xmSrc->mesa, &xmDst->mesa, (GLuint) mask );
1430 }
1431
1432
1433 static Bool
1434 Fake_glXQueryExtension( Display *dpy, int *errorBase, int *eventBase )
1435 {
1436 int op, ev, err;
1437 /* Mesa's GLX isn't really an X extension but we try to act like one. */
1438 if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &op, &ev, &err))
1439 ev = err = 0;
1440 if (errorBase)
1441 *errorBase = err;
1442 if (eventBase)
1443 *eventBase = ev;
1444 return True; /* we're faking GLX so always return success */
1445 }
1446
1447
1448 extern void _kw_ungrab_all( Display *dpy );
1449 void _kw_ungrab_all( Display *dpy )
1450 {
1451 XUngrabPointer( dpy, CurrentTime );
1452 XUngrabKeyboard( dpy, CurrentTime );
1453 }
1454
1455
1456 static void
1457 Fake_glXDestroyContext( Display *dpy, GLXContext ctx )
1458 {
1459 if (ctx) {
1460 (void) dpy;
1461 MakeCurrent_PrevContext = 0;
1462 MakeCurrent_PrevDrawable = 0;
1463 MakeCurrent_PrevReadable = 0;
1464 MakeCurrent_PrevDrawBuffer = 0;
1465 MakeCurrent_PrevReadBuffer = 0;
1466 XMesaDestroyContext((XMesaContext) ctx);
1467 XMesaGarbageCollect(dpy);
1468 }
1469 }
1470
1471
1472 static Bool
1473 Fake_glXIsDirect( Display *dpy, GLXContext ctx )
1474 {
1475 XMesaContext xmCtx = (XMesaContext) ctx;
1476 return xmCtx ? xmCtx->direct : False;
1477 }
1478
1479
1480
1481 static void
1482 Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable )
1483 {
1484 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1485
1486 if (buffer) {
1487 XMesaSwapBuffers(buffer);
1488 }
1489 else if (getenv("MESA_DEBUG")) {
1490 _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n",
1491 (int) drawable);
1492 }
1493 }
1494
1495
1496
1497 /*** GLX_MESA_copy_sub_buffer ***/
1498
1499 static void
1500 Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable,
1501 int x, int y, int width, int height )
1502 {
1503 XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable );
1504 if (buffer) {
1505 XMesaCopySubBuffer(buffer, x, y, width, height);
1506 }
1507 else if (getenv("MESA_DEBUG")) {
1508 _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n");
1509 }
1510 }
1511
1512
1513 static Bool
1514 Fake_glXQueryVersion( Display *dpy, int *maj, int *min )
1515 {
1516 (void) dpy;
1517 /* Return GLX version, not Mesa version */
1518 assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION);
1519 *maj = CLIENT_MAJOR_VERSION;
1520 *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION );
1521 return True;
1522 }
1523
1524
1525 /*
1526 * Query the GLX attributes of the given XVisualInfo.
1527 */
1528 static int
1529 get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig )
1530 {
1531 assert(xmvis);
1532 switch(attrib) {
1533 case GLX_USE_GL:
1534 if (fbconfig)
1535 return GLX_BAD_ATTRIBUTE;
1536 *value = (int) True;
1537 return 0;
1538 case GLX_BUFFER_SIZE:
1539 *value = xmvis->visinfo->depth;
1540 return 0;
1541 case GLX_LEVEL:
1542 *value = xmvis->mesa_visual.level;
1543 return 0;
1544 case GLX_RGBA:
1545 if (fbconfig)
1546 return GLX_BAD_ATTRIBUTE;
1547 if (xmvis->mesa_visual.rgbMode) {
1548 *value = True;
1549 }
1550 else {
1551 *value = False;
1552 }
1553 return 0;
1554 case GLX_DOUBLEBUFFER:
1555 *value = (int) xmvis->mesa_visual.doubleBufferMode;
1556 return 0;
1557 case GLX_STEREO:
1558 *value = (int) xmvis->mesa_visual.stereoMode;
1559 return 0;
1560 case GLX_AUX_BUFFERS:
1561 *value = xmvis->mesa_visual.numAuxBuffers;
1562 return 0;
1563 case GLX_RED_SIZE:
1564 *value = xmvis->mesa_visual.redBits;
1565 return 0;
1566 case GLX_GREEN_SIZE:
1567 *value = xmvis->mesa_visual.greenBits;
1568 return 0;
1569 case GLX_BLUE_SIZE:
1570 *value = xmvis->mesa_visual.blueBits;
1571 return 0;
1572 case GLX_ALPHA_SIZE:
1573 *value = xmvis->mesa_visual.alphaBits;
1574 return 0;
1575 case GLX_DEPTH_SIZE:
1576 *value = xmvis->mesa_visual.depthBits;
1577 return 0;
1578 case GLX_STENCIL_SIZE:
1579 *value = xmvis->mesa_visual.stencilBits;
1580 return 0;
1581 case GLX_ACCUM_RED_SIZE:
1582 *value = xmvis->mesa_visual.accumRedBits;
1583 return 0;
1584 case GLX_ACCUM_GREEN_SIZE:
1585 *value = xmvis->mesa_visual.accumGreenBits;
1586 return 0;
1587 case GLX_ACCUM_BLUE_SIZE:
1588 *value = xmvis->mesa_visual.accumBlueBits;
1589 return 0;
1590 case GLX_ACCUM_ALPHA_SIZE:
1591 *value = xmvis->mesa_visual.accumAlphaBits;
1592 return 0;
1593
1594 /*
1595 * GLX_EXT_visual_info extension
1596 */
1597 case GLX_X_VISUAL_TYPE_EXT:
1598 switch (xmvis->visinfo->CLASS) {
1599 case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0;
1600 case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0;
1601 case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0;
1602 case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0;
1603 case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0;
1604 case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0;
1605 }
1606 return 0;
1607 case GLX_TRANSPARENT_TYPE_EXT:
1608 if (xmvis->mesa_visual.level==0) {
1609 /* normal planes */
1610 *value = GLX_NONE_EXT;
1611 }
1612 else if (xmvis->mesa_visual.level>0) {
1613 /* overlay */
1614 if (xmvis->mesa_visual.rgbMode) {
1615 *value = GLX_TRANSPARENT_RGB_EXT;
1616 }
1617 else {
1618 *value = GLX_TRANSPARENT_INDEX_EXT;
1619 }
1620 }
1621 else if (xmvis->mesa_visual.level<0) {
1622 /* underlay */
1623 *value = GLX_NONE_EXT;
1624 }
1625 return 0;
1626 case GLX_TRANSPARENT_INDEX_VALUE_EXT:
1627 {
1628 int pixel = transparent_pixel( xmvis );
1629 if (pixel>=0) {
1630 *value = pixel;
1631 }
1632 /* else undefined */
1633 }
1634 return 0;
1635 case GLX_TRANSPARENT_RED_VALUE_EXT:
1636 /* undefined */
1637 return 0;
1638 case GLX_TRANSPARENT_GREEN_VALUE_EXT:
1639 /* undefined */
1640 return 0;
1641 case GLX_TRANSPARENT_BLUE_VALUE_EXT:
1642 /* undefined */
1643 return 0;
1644 case GLX_TRANSPARENT_ALPHA_VALUE_EXT:
1645 /* undefined */
1646 return 0;
1647
1648 /*
1649 * GLX_EXT_visual_info extension
1650 */
1651 case GLX_VISUAL_CAVEAT_EXT:
1652 /* test for zero, just in case */
1653 if (xmvis->mesa_visual.visualRating > 0)
1654 *value = xmvis->mesa_visual.visualRating;
1655 else
1656 *value = GLX_NONE_EXT;
1657 return 0;
1658
1659 /*
1660 * GLX_ARB_multisample
1661 */
1662 case GLX_SAMPLE_BUFFERS_ARB:
1663 *value = 0;
1664 return 0;
1665 case GLX_SAMPLES_ARB:
1666 *value = 0;
1667 return 0;
1668
1669 /*
1670 * For FBConfigs:
1671 */
1672 case GLX_SCREEN_EXT:
1673 if (!fbconfig)
1674 return GLX_BAD_ATTRIBUTE;
1675 *value = xmvis->visinfo->screen;
1676 break;
1677 case GLX_DRAWABLE_TYPE: /*SGIX too */
1678 if (!fbconfig)
1679 return GLX_BAD_ATTRIBUTE;
1680 *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT;
1681 break;
1682 case GLX_RENDER_TYPE_SGIX:
1683 if (!fbconfig)
1684 return GLX_BAD_ATTRIBUTE;
1685 if (xmvis->mesa_visual.floatMode)
1686 *value = GLX_RGBA_FLOAT_BIT_ARB;
1687 else if (xmvis->mesa_visual.rgbMode)
1688 *value = GLX_RGBA_BIT;
1689 else
1690 *value = GLX_COLOR_INDEX_BIT;
1691 break;
1692 case GLX_X_RENDERABLE_SGIX:
1693 if (!fbconfig)
1694 return GLX_BAD_ATTRIBUTE;
1695 *value = True; /* XXX really? */
1696 break;
1697 case GLX_FBCONFIG_ID_SGIX:
1698 if (!fbconfig)
1699 return GLX_BAD_ATTRIBUTE;
1700 *value = xmvis->visinfo->visualid;
1701 break;
1702 case GLX_MAX_PBUFFER_WIDTH:
1703 if (!fbconfig)
1704 return GLX_BAD_ATTRIBUTE;
1705 /* XXX should be same as ctx->Const.MaxRenderbufferSize */
1706 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen);
1707 break;
1708 case GLX_MAX_PBUFFER_HEIGHT:
1709 if (!fbconfig)
1710 return GLX_BAD_ATTRIBUTE;
1711 *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1712 break;
1713 case GLX_MAX_PBUFFER_PIXELS:
1714 if (!fbconfig)
1715 return GLX_BAD_ATTRIBUTE;
1716 *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) *
1717 DisplayHeight(xmvis->display, xmvis->visinfo->screen);
1718 break;
1719 case GLX_VISUAL_ID:
1720 if (!fbconfig)
1721 return GLX_BAD_ATTRIBUTE;
1722 *value = xmvis->visinfo->visualid;
1723 break;
1724
1725 #ifdef GLX_EXT_texture_from_pixmap
1726 case GLX_BIND_TO_TEXTURE_RGB_EXT:
1727 *value = True; /*XXX*/
1728 break;
1729 case GLX_BIND_TO_TEXTURE_RGBA_EXT:
1730 /* XXX review */
1731 *value = xmvis->mesa_visual.alphaBits > 0 ? True : False;
1732 break;
1733 case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
1734 *value = True; /*XXX*/
1735 break;
1736 case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
1737 *value = (GLX_TEXTURE_1D_BIT_EXT |
1738 GLX_TEXTURE_2D_BIT_EXT |
1739 GLX_TEXTURE_RECTANGLE_BIT_EXT); /*XXX*/
1740 break;
1741 case GLX_Y_INVERTED_EXT:
1742 *value = True; /*XXX*/
1743 break;
1744 #endif
1745
1746 default:
1747 return GLX_BAD_ATTRIBUTE;
1748 }
1749 return Success;
1750 }
1751
1752
1753 static int
1754 Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo,
1755 int attrib, int *value )
1756 {
1757 XMesaVisual xmvis;
1758 int k;
1759 if (!dpy || !visinfo)
1760 return GLX_BAD_ATTRIBUTE;
1761
1762 xmvis = find_glx_visual( dpy, visinfo );
1763 if (!xmvis) {
1764 /* this visual wasn't obtained with glXChooseVisual */
1765 xmvis = create_glx_visual( dpy, visinfo );
1766 if (!xmvis) {
1767 /* this visual can't be used for GL rendering */
1768 if (attrib==GLX_USE_GL) {
1769 *value = (int) False;
1770 return 0;
1771 }
1772 else {
1773 return GLX_BAD_VISUAL;
1774 }
1775 }
1776 }
1777
1778 k = get_config(xmvis, attrib, value, GL_FALSE);
1779 return k;
1780 }
1781
1782
1783 static GLXContext
1784 Fake_glXGetCurrentContext(void)
1785 {
1786 XMesaContext xmesa = XMesaGetCurrentContext();
1787 return (GLXContext) xmesa;
1788 }
1789
1790 static void
1791 Fake_glXWaitGL( void )
1792 {
1793 XMesaContext xmesa = XMesaGetCurrentContext();
1794 XMesaFlush( xmesa );
1795 }
1796
1797
1798
1799 static void
1800 Fake_glXWaitX( void )
1801 {
1802 XMesaContext xmesa = XMesaGetCurrentContext();
1803 XMesaFlush( xmesa );
1804 }
1805
1806
1807 static const char *
1808 get_extensions( void )
1809 {
1810 return EXTENSIONS + 23; /* skip "GLX_MESA_set_3dfx_mode" */
1811 }
1812
1813
1814
1815 /* GLX 1.1 and later */
1816 static const char *
1817 Fake_glXQueryExtensionsString( Display *dpy, int screen )
1818 {
1819 (void) dpy;
1820 (void) screen;
1821 return get_extensions();
1822 }
1823
1824
1825
1826 /* GLX 1.1 and later */
1827 static const char *
1828 Fake_glXQueryServerString( Display *dpy, int screen, int name )
1829 {
1830 static char version[1000];
1831 sprintf(version, "%d.%d %s",
1832 SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION);
1833
1834 (void) dpy;
1835 (void) screen;
1836
1837 switch (name) {
1838 case GLX_EXTENSIONS:
1839 return get_extensions();
1840 case GLX_VENDOR:
1841 return VENDOR;
1842 case GLX_VERSION:
1843 return version;
1844 default:
1845 return NULL;
1846 }
1847 }
1848
1849
1850
1851 /* GLX 1.1 and later */
1852 static const char *
1853 Fake_glXGetClientString( Display *dpy, int name )
1854 {
1855 static char version[1000];
1856 sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION,
1857 CLIENT_MINOR_VERSION, MESA_GLX_VERSION);
1858
1859 (void) dpy;
1860
1861 switch (name) {
1862 case GLX_EXTENSIONS:
1863 return get_extensions();
1864 case GLX_VENDOR:
1865 return VENDOR;
1866 case GLX_VERSION:
1867 return version;
1868 default:
1869 return NULL;
1870 }
1871 }
1872
1873
1874
1875 /*
1876 * GLX 1.3 and later
1877 */
1878
1879
1880 static int
1881 Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config,
1882 int attribute, int *value )
1883 {
1884 XMesaVisual v = (XMesaVisual) config;
1885 (void) dpy;
1886 (void) config;
1887
1888 if (!dpy || !config || !value)
1889 return -1;
1890
1891 return get_config(v, attribute, value, GL_TRUE);
1892 }
1893
1894
1895 static GLXFBConfig *
1896 Fake_glXGetFBConfigs( Display *dpy, int screen, int *nelements )
1897 {
1898 XVisualInfo *visuals, visTemplate;
1899 const long visMask = VisualScreenMask;
1900 int i;
1901
1902 /* Get list of all X visuals */
1903 visTemplate.screen = screen;
1904 visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
1905 if (*nelements > 0) {
1906 XMesaVisual *results;
1907 results = malloc(*nelements * sizeof(XMesaVisual));
1908 if (!results) {
1909 *nelements = 0;
1910 return NULL;
1911 }
1912 for (i = 0; i < *nelements; i++) {
1913 results[i] = create_glx_visual(dpy, visuals + i);
1914 }
1915 return (GLXFBConfig *) results;
1916 }
1917 return NULL;
1918 }
1919
1920
1921 static GLXFBConfig *
1922 Fake_glXChooseFBConfig( Display *dpy, int screen,
1923 const int *attribList, int *nitems )
1924 {
1925 XMesaVisual xmvis;
1926
1927 /* register ourselves as an extension on this display */
1928 register_with_display(dpy);
1929
1930 if (!attribList || !attribList[0]) {
1931 /* return list of all configs (per GLX_SGIX_fbconfig spec) */
1932 return Fake_glXGetFBConfigs(dpy, screen, nitems);
1933 }
1934
1935 xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
1936 if (xmvis) {
1937 GLXFBConfig *config = malloc(sizeof(XMesaVisual));
1938 if (!config) {
1939 *nitems = 0;
1940 return NULL;
1941 }
1942 *nitems = 1;
1943 config[0] = (GLXFBConfig) xmvis;
1944 return (GLXFBConfig *) config;
1945 }
1946 else {
1947 *nitems = 0;
1948 return NULL;
1949 }
1950 }
1951
1952
1953 static XVisualInfo *
1954 Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
1955 {
1956 if (dpy && config) {
1957 XMesaVisual xmvis = (XMesaVisual) config;
1958 XVisualInfo* visinfo = malloc(sizeof(XVisualInfo));
1959 if (visinfo) {
1960 memcpy(visinfo, xmvis->visinfo, sizeof(XVisualInfo));
1961 }
1962 return visinfo;
1963 }
1964 else {
1965 return NULL;
1966 }
1967 }
1968
1969
1970 static GLXWindow
1971 Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win,
1972 const int *attribList )
1973 {
1974 XMesaVisual xmvis = (XMesaVisual) config;
1975 XMesaBuffer xmbuf;
1976 if (!xmvis)
1977 return 0;
1978
1979 xmbuf = XMesaCreateWindowBuffer(xmvis, win);
1980 if (!xmbuf)
1981 return 0;
1982
1983 (void) dpy;
1984 (void) attribList; /* Ignored in GLX 1.3 */
1985
1986 return win; /* A hack for now */
1987 }
1988
1989
1990 static void
1991 Fake_glXDestroyWindow( Display *dpy, GLXWindow window )
1992 {
1993 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window);
1994 if (b)
1995 XMesaDestroyBuffer(b);
1996 /* don't destroy X window */
1997 }
1998
1999
2000 /* XXX untested */
2001 static GLXPixmap
2002 Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap,
2003 const int *attribList )
2004 {
2005 XMesaVisual v = (XMesaVisual) config;
2006 XMesaBuffer b;
2007 const int *attr;
2008 int target = 0, format = 0, mipmap = 0;
2009 int value;
2010
2011 if (!dpy || !config || !pixmap)
2012 return 0;
2013
2014 for (attr = attribList; attr && *attr; attr++) {
2015 switch (*attr) {
2016 case GLX_TEXTURE_FORMAT_EXT:
2017 attr++;
2018 switch (*attr) {
2019 case GLX_TEXTURE_FORMAT_NONE_EXT:
2020 case GLX_TEXTURE_FORMAT_RGB_EXT:
2021 case GLX_TEXTURE_FORMAT_RGBA_EXT:
2022 format = *attr;
2023 break;
2024 default:
2025 /* error */
2026 return 0;
2027 }
2028 break;
2029 case GLX_TEXTURE_TARGET_EXT:
2030 attr++;
2031 switch (*attr) {
2032 case GLX_TEXTURE_1D_EXT:
2033 case GLX_TEXTURE_2D_EXT:
2034 case GLX_TEXTURE_RECTANGLE_EXT:
2035 target = *attr;
2036 break;
2037 default:
2038 /* error */
2039 return 0;
2040 }
2041 break;
2042 case GLX_MIPMAP_TEXTURE_EXT:
2043 attr++;
2044 if (*attr)
2045 mipmap = 1;
2046 break;
2047 default:
2048 /* error */
2049 return 0;
2050 }
2051 }
2052
2053 if (format == GLX_TEXTURE_FORMAT_RGB_EXT) {
2054 if (get_config(v, GLX_BIND_TO_TEXTURE_RGB_EXT,
2055 &value, GL_TRUE) != Success
2056 || !value) {
2057 return 0; /* error! */
2058 }
2059 }
2060 else if (format == GLX_TEXTURE_FORMAT_RGBA_EXT) {
2061 if (get_config(v, GLX_BIND_TO_TEXTURE_RGBA_EXT,
2062 &value, GL_TRUE) != Success
2063 || !value) {
2064 return 0; /* error! */
2065 }
2066 }
2067 if (mipmap) {
2068 if (get_config(v, GLX_BIND_TO_MIPMAP_TEXTURE_EXT,
2069 &value, GL_TRUE) != Success
2070 || !value) {
2071 return 0; /* error! */
2072 }
2073 }
2074 if (target == GLX_TEXTURE_1D_EXT) {
2075 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
2076 &value, GL_TRUE) != Success
2077 || (value & GLX_TEXTURE_1D_BIT_EXT) == 0) {
2078 return 0; /* error! */
2079 }
2080 }
2081 else if (target == GLX_TEXTURE_2D_EXT) {
2082 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
2083 &value, GL_TRUE) != Success
2084 || (value & GLX_TEXTURE_2D_BIT_EXT) == 0) {
2085 return 0; /* error! */
2086 }
2087 }
2088 if (target == GLX_TEXTURE_RECTANGLE_EXT) {
2089 if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT,
2090 &value, GL_TRUE) != Success
2091 || (value & GLX_TEXTURE_RECTANGLE_BIT_EXT) == 0) {
2092 return 0; /* error! */
2093 }
2094 }
2095
2096 if (format || target || mipmap) {
2097 /* texture from pixmap */
2098 b = XMesaCreatePixmapTextureBuffer(v, pixmap, 0, format, target, mipmap);
2099 }
2100 else {
2101 b = XMesaCreatePixmapBuffer( v, pixmap, 0 );
2102 }
2103 if (!b) {
2104 return 0;
2105 }
2106
2107 return pixmap;
2108 }
2109
2110
2111 static void
2112 Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap )
2113 {
2114 XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap);
2115 if (b)
2116 XMesaDestroyBuffer(b);
2117 /* don't destroy X pixmap */
2118 }
2119
2120
2121 static GLXPbuffer
2122 Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config,
2123 const int *attribList )
2124 {
2125 XMesaVisual xmvis = (XMesaVisual) config;
2126 XMesaBuffer xmbuf;
2127 const int *attrib;
2128 int width = 0, height = 0;
2129 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2130
2131 (void) dpy;
2132
2133 for (attrib = attribList; *attrib; attrib++) {
2134 switch (*attrib) {
2135 case GLX_PBUFFER_WIDTH:
2136 attrib++;
2137 width = *attrib;
2138 break;
2139 case GLX_PBUFFER_HEIGHT:
2140 attrib++;
2141 height = *attrib;
2142 break;
2143 case GLX_PRESERVED_CONTENTS:
2144 attrib++;
2145 preserveContents = *attrib;
2146 break;
2147 case GLX_LARGEST_PBUFFER:
2148 attrib++;
2149 useLargest = *attrib;
2150 break;
2151 default:
2152 return 0;
2153 }
2154 }
2155
2156 if (width == 0 || height == 0)
2157 return 0;
2158
2159 if (width > SWRAST_MAX_WIDTH || height > SWRAST_MAX_HEIGHT) {
2160 /* If allocation would have failed and GLX_LARGEST_PBUFFER is set,
2161 * allocate the largest possible buffer.
2162 */
2163 if (useLargest) {
2164 width = SWRAST_MAX_WIDTH;
2165 height = SWRAST_MAX_HEIGHT;
2166 }
2167 }
2168
2169 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2170 /* A GLXPbuffer handle must be an X Drawable because that's what
2171 * glXMakeCurrent takes.
2172 */
2173 if (xmbuf) {
2174 xmbuf->largestPbuffer = useLargest;
2175 xmbuf->preservedContents = preserveContents;
2176 return (GLXPbuffer) xmbuf->frontxrb->pixmap;
2177 }
2178 else {
2179 return 0;
2180 }
2181 }
2182
2183
2184 static void
2185 Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf )
2186 {
2187 XMesaBuffer b = XMesaFindBuffer(dpy, pbuf);
2188 if (b) {
2189 XMesaDestroyBuffer(b);
2190 }
2191 }
2192
2193
2194 static void
2195 Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute,
2196 unsigned int *value )
2197 {
2198 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw);
2199 if (!xmbuf)
2200 return;
2201
2202 /* make sure buffer's dimensions are up to date */
2203 xmesa_check_and_update_buffer_size(NULL, xmbuf);
2204
2205 switch (attribute) {
2206 case GLX_WIDTH:
2207 *value = xmbuf->mesa_buffer.Width;
2208 break;
2209 case GLX_HEIGHT:
2210 *value = xmbuf->mesa_buffer.Height;
2211 break;
2212 case GLX_PRESERVED_CONTENTS:
2213 *value = xmbuf->preservedContents;
2214 break;
2215 case GLX_LARGEST_PBUFFER:
2216 *value = xmbuf->largestPbuffer;
2217 break;
2218 case GLX_FBCONFIG_ID:
2219 *value = xmbuf->xm_visual->visinfo->visualid;
2220 return;
2221 #ifdef GLX_EXT_texture_from_pixmap
2222 case GLX_TEXTURE_FORMAT_EXT:
2223 *value = xmbuf->TextureFormat;
2224 break;
2225 case GLX_TEXTURE_TARGET_EXT:
2226 *value = xmbuf->TextureTarget;
2227 break;
2228 case GLX_MIPMAP_TEXTURE_EXT:
2229 *value = xmbuf->TextureMipmap;
2230 break;
2231 #endif
2232
2233 default:
2234 return; /* raise BadValue error */
2235 }
2236 }
2237
2238
2239 static GLXContext
2240 Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config,
2241 int renderType, GLXContext shareList, Bool direct )
2242 {
2243 XMesaContext xmCtx;
2244 XMesaVisual xmvis = (XMesaVisual) config;
2245
2246 if (!dpy || !config ||
2247 (renderType != GLX_RGBA_TYPE &&
2248 renderType != GLX_COLOR_INDEX_TYPE &&
2249 renderType != GLX_RGBA_FLOAT_TYPE_ARB &&
2250 renderType != GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT))
2251 return 0;
2252
2253 /* deallocate unused windows/buffers */
2254 XMesaGarbageCollect(dpy);
2255
2256 xmCtx = XMesaCreateContext(xmvis, (XMesaContext) shareList);
2257
2258 return (GLXContext) xmCtx;
2259 }
2260
2261
2262 static int
2263 Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value )
2264 {
2265 XMesaContext xmctx = (XMesaContext) ctx;
2266 (void) dpy;
2267 (void) ctx;
2268
2269 switch (attribute) {
2270 case GLX_FBCONFIG_ID:
2271 *value = xmctx->xm_visual->visinfo->visualid;
2272 break;
2273 case GLX_RENDER_TYPE:
2274 *value = GLX_RGBA_TYPE;
2275 break;
2276 case GLX_SCREEN:
2277 *value = 0;
2278 return Success;
2279 default:
2280 return GLX_BAD_ATTRIBUTE;
2281 }
2282 return 0;
2283 }
2284
2285
2286 static void
2287 Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask )
2288 {
2289 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2290 if (xmbuf)
2291 xmbuf->selectedEvents = mask;
2292 }
2293
2294
2295 static void
2296 Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable,
2297 unsigned long *mask )
2298 {
2299 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2300 if (xmbuf)
2301 *mask = xmbuf->selectedEvents;
2302 else
2303 *mask = 0;
2304 }
2305
2306
2307
2308 /*** GLX_SGI_swap_control ***/
2309
2310 static int
2311 Fake_glXSwapIntervalSGI(int interval)
2312 {
2313 (void) interval;
2314 return 0;
2315 }
2316
2317
2318
2319 /*** GLX_SGI_video_sync ***/
2320
2321 static unsigned int FrameCounter = 0;
2322
2323 static int
2324 Fake_glXGetVideoSyncSGI(unsigned int *count)
2325 {
2326 /* this is a bogus implementation */
2327 *count = FrameCounter++;
2328 return 0;
2329 }
2330
2331 static int
2332 Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2333 {
2334 if (divisor <= 0 || remainder < 0)
2335 return GLX_BAD_VALUE;
2336 /* this is a bogus implementation */
2337 FrameCounter++;
2338 while (FrameCounter % divisor != remainder)
2339 FrameCounter++;
2340 *count = FrameCounter;
2341 return 0;
2342 }
2343
2344
2345
2346 /*** GLX_SGI_make_current_read ***/
2347
2348 static Bool
2349 Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
2350 {
2351 return Fake_glXMakeContextCurrent( dpy, draw, read, ctx );
2352 }
2353
2354 /* not used
2355 static GLXDrawable
2356 Fake_glXGetCurrentReadDrawableSGI(void)
2357 {
2358 return 0;
2359 }
2360 */
2361
2362
2363 /*** GLX_SGIX_video_source ***/
2364 #if defined(_VL_H)
2365
2366 static GLXVideoSourceSGIX
2367 Fake_glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
2368 {
2369 (void) dpy;
2370 (void) screen;
2371 (void) server;
2372 (void) path;
2373 (void) nodeClass;
2374 (void) drainNode;
2375 return 0;
2376 }
2377
2378 static void
2379 Fake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
2380 {
2381 (void) dpy;
2382 (void) src;
2383 }
2384
2385 #endif
2386
2387
2388 /*** GLX_EXT_import_context ***/
2389
2390 static void
2391 Fake_glXFreeContextEXT(Display *dpy, GLXContext context)
2392 {
2393 (void) dpy;
2394 (void) context;
2395 }
2396
2397 static GLXContextID
2398 Fake_glXGetContextIDEXT(const GLXContext context)
2399 {
2400 (void) context;
2401 return 0;
2402 }
2403
2404 static GLXContext
2405 Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID)
2406 {
2407 (void) dpy;
2408 (void) contextID;
2409 return 0;
2410 }
2411
2412 static int
2413 Fake_glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value)
2414 {
2415 (void) dpy;
2416 (void) context;
2417 (void) attribute;
2418 (void) value;
2419 return 0;
2420 }
2421
2422
2423
2424 /*** GLX_SGIX_fbconfig ***/
2425
2426 static int
2427 Fake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
2428 {
2429 return Fake_glXGetFBConfigAttrib(dpy, config, attribute, value);
2430 }
2431
2432 static GLXFBConfigSGIX *
2433 Fake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
2434 {
2435 return (GLXFBConfig *) Fake_glXChooseFBConfig(dpy, screen, attrib_list, nelements);
2436 }
2437
2438
2439 static GLXPixmap
2440 Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
2441 {
2442 XMesaVisual xmvis = (XMesaVisual) config;
2443 XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0);
2444 return xmbuf->frontxrb->pixmap; /* need to return an X ID */
2445 }
2446
2447
2448 static GLXContext
2449 Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
2450 {
2451 XMesaContext xmCtx;
2452 XMesaVisual xmvis = (XMesaVisual) config;
2453
2454 /* deallocate unused windows/buffers */
2455 XMesaGarbageCollect(dpy);
2456
2457 xmCtx = XMesaCreateContext(xmvis, (XMesaContext) share_list);
2458
2459 return (GLXContext) xmCtx;
2460 }
2461
2462
2463 static XVisualInfo *
2464 Fake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
2465 {
2466 return Fake_glXGetVisualFromFBConfig(dpy, config);
2467 }
2468
2469
2470 static GLXFBConfigSGIX
2471 Fake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
2472 {
2473 XMesaVisual xmvis = find_glx_visual(dpy, vis);
2474 if (!xmvis) {
2475 /* This visual wasn't found with glXChooseVisual() */
2476 xmvis = create_glx_visual(dpy, vis);
2477 }
2478
2479 return (GLXFBConfigSGIX) xmvis;
2480 }
2481
2482
2483
2484 /*** GLX_SGIX_pbuffer ***/
2485
2486 static GLXPbufferSGIX
2487 Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config,
2488 unsigned int width, unsigned int height,
2489 int *attribList)
2490 {
2491 XMesaVisual xmvis = (XMesaVisual) config;
2492 XMesaBuffer xmbuf;
2493 const int *attrib;
2494 GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE;
2495
2496 (void) dpy;
2497
2498 for (attrib = attribList; attrib && *attrib; attrib++) {
2499 switch (*attrib) {
2500 case GLX_PRESERVED_CONTENTS_SGIX:
2501 attrib++;
2502 preserveContents = *attrib; /* ignored */
2503 break;
2504 case GLX_LARGEST_PBUFFER_SGIX:
2505 attrib++;
2506 useLargest = *attrib; /* ignored */
2507 break;
2508 default:
2509 return 0;
2510 }
2511 }
2512
2513 /* not used at this time */
2514 (void) useLargest;
2515 (void) preserveContents;
2516
2517 xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height);
2518 /* A GLXPbuffer handle must be an X Drawable because that's what
2519 * glXMakeCurrent takes.
2520 */
2521 return (GLXPbuffer) xmbuf->frontxrb->pixmap;
2522 }
2523
2524
2525 static void
2526 Fake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
2527 {
2528 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2529 if (xmbuf) {
2530 XMesaDestroyBuffer(xmbuf);
2531 }
2532 }
2533
2534
2535 static int
2536 Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
2537 {
2538 const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf);
2539
2540 if (!xmbuf) {
2541 /* Generate GLXBadPbufferSGIX for bad pbuffer */
2542 return 0;
2543 }
2544
2545 switch (attribute) {
2546 case GLX_PRESERVED_CONTENTS_SGIX:
2547 *value = xmbuf->preservedContents;
2548 break;
2549 case GLX_LARGEST_PBUFFER_SGIX:
2550 *value = xmbuf->largestPbuffer;
2551 break;
2552 case GLX_WIDTH_SGIX:
2553 *value = xmbuf->mesa_buffer.Width;
2554 break;
2555 case GLX_HEIGHT_SGIX:
2556 *value = xmbuf->mesa_buffer.Height;
2557 break;
2558 case GLX_EVENT_MASK_SGIX:
2559 *value = 0; /* XXX might be wrong */
2560 break;
2561 default:
2562 *value = 0;
2563 }
2564 return 0;
2565 }
2566
2567
2568 static void
2569 Fake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
2570 {
2571 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2572 if (xmbuf) {
2573 /* Note: we'll never generate clobber events */
2574 xmbuf->selectedEvents = mask;
2575 }
2576 }
2577
2578
2579 static void
2580 Fake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
2581 {
2582 XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable);
2583 if (xmbuf) {
2584 *mask = xmbuf->selectedEvents;
2585 }
2586 else {
2587 *mask = 0;
2588 }
2589 }
2590
2591
2592
2593 /*** GLX_SGI_cushion ***/
2594
2595 static void
2596 Fake_glXCushionSGI(Display *dpy, Window win, float cushion)
2597 {
2598 (void) dpy;
2599 (void) win;
2600 (void) cushion;
2601 }
2602
2603
2604
2605 /*** GLX_SGIX_video_resize ***/
2606
2607 static int
2608 Fake_glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
2609 {
2610 (void) dpy;
2611 (void) screen;
2612 (void) channel;
2613 (void) window;
2614 return 0;
2615 }
2616
2617 static int
2618 Fake_glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
2619 {
2620 (void) dpy;
2621 (void) screen;
2622 (void) channel;
2623 (void) x;
2624 (void) y;
2625 (void) w;
2626 (void) h;
2627 return 0;
2628 }
2629
2630 static int
2631 Fake_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
2632 {
2633 (void) dpy;
2634 (void) screen;
2635 (void) channel;
2636 (void) x;
2637 (void) y;
2638 (void) w;
2639 (void) h;
2640 return 0;
2641 }
2642
2643 static int
2644 Fake_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
2645 {
2646 (void) dpy;
2647 (void) screen;
2648 (void) channel;
2649 (void) dx;
2650 (void) dy;
2651 (void) dw;
2652 (void) dh;
2653 return 0;
2654 }
2655
2656 static int
2657 Fake_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
2658 {
2659 (void) dpy;
2660 (void) screen;
2661 (void) channel;
2662 (void) synctype;
2663 return 0;
2664 }
2665
2666
2667
2668 /*** GLX_SGIX_dmbuffer **/
2669
2670 #if defined(_DM_BUFFER_H_)
2671 static Bool
2672 Fake_glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
2673 {
2674 (void) dpy;
2675 (void) pbuffer;
2676 (void) params;
2677 (void) dmbuffer;
2678 return False;
2679 }
2680 #endif
2681
2682
2683 /*** GLX_SGIX_swap_group ***/
2684
2685 static void
2686 Fake_glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
2687 {
2688 (void) dpy;
2689 (void) drawable;
2690 (void) member;
2691 }
2692
2693
2694
2695 /*** GLX_SGIX_swap_barrier ***/
2696
2697 static void
2698 Fake_glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
2699 {
2700 (void) dpy;
2701 (void) drawable;
2702 (void) barrier;
2703 }
2704
2705 static Bool
2706 Fake_glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
2707 {
2708 (void) dpy;
2709 (void) screen;
2710 (void) max;
2711 return False;
2712 }
2713
2714
2715
2716 /*** GLX_SUN_get_transparent_index ***/
2717
2718 static Status
2719 Fake_glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
2720 {
2721 (void) dpy;
2722 (void) overlay;
2723 (void) underlay;
2724 (void) pTransparent;
2725 return 0;
2726 }
2727
2728
2729
2730 /*** GLX_MESA_release_buffers ***/
2731
2732 /*
2733 * Release the depth, stencil, accum buffers attached to a GLXDrawable
2734 * (a window or pixmap) prior to destroying the GLXDrawable.
2735 */
2736 static Bool
2737 Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d )
2738 {
2739 XMesaBuffer b = XMesaFindBuffer(dpy, d);
2740 if (b) {
2741 XMesaDestroyBuffer(b);
2742 return True;
2743 }
2744 return False;
2745 }
2746
2747
2748
2749 /*** GLX_MESA_set_3dfx_mode ***/
2750
2751 static Bool
2752 Fake_glXSet3DfxModeMESA( int mode )
2753 {
2754 return XMesaSetFXmode( mode );
2755 }
2756
2757
2758
2759 /*** GLX_NV_vertex_array range ***/
2760 static void *
2761 Fake_glXAllocateMemoryNV( GLsizei size,
2762 GLfloat readFrequency,
2763 GLfloat writeFrequency,
2764 GLfloat priority )
2765 {
2766 (void) size;
2767 (void) readFrequency;
2768 (void) writeFrequency;
2769 (void) priority;
2770 return NULL;
2771 }
2772
2773
2774 static void
2775 Fake_glXFreeMemoryNV( GLvoid *pointer )
2776 {
2777 (void) pointer;
2778 }
2779
2780
2781 /*** GLX_MESA_agp_offset ***/
2782
2783 static GLuint
2784 Fake_glXGetAGPOffsetMESA( const GLvoid *pointer )
2785 {
2786 (void) pointer;
2787 return ~0;
2788 }
2789
2790
2791 /*** GLX_EXT_texture_from_pixmap ***/
2792
2793 static void
2794 Fake_glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer,
2795 const int *attrib_list)
2796 {
2797 XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2798 if (b)
2799 XMesaBindTexImage(dpy, b, buffer, attrib_list);
2800 }
2801
2802 static void
2803 Fake_glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer)
2804 {
2805 XMesaBuffer b = XMesaFindBuffer(dpy, drawable);
2806 if (b)
2807 XMesaReleaseTexImage(dpy, b, buffer);
2808 }
2809
2810
2811 static GLXContext
2812 Fake_glXCreateContextAttribs(Display *dpy, GLXFBConfig config,
2813 GLXContext share_context, Bool direct,
2814 const int *attrib_list)
2815 {
2816 XMesaContext xmCtx;
2817 XMesaVisual xmvis = (XMesaVisual) config;
2818 int i;
2819 int major = 0, minor = 0, ctxFlags = 0, profileFlags = 0;
2820
2821 for (i = 0; attrib_list[i]; i += 2) {
2822 switch (attrib_list[i]) {
2823 case GLX_CONTEXT_MAJOR_VERSION_ARB:
2824 major = attrib_list[i + 1];
2825 break;
2826 case GLX_CONTEXT_MINOR_VERSION_ARB:
2827 minor = attrib_list[i + 1];
2828 break;
2829 case GLX_CONTEXT_FLAGS_ARB:
2830 ctxFlags = attrib_list[i + 1];
2831 break;
2832 case GLX_CONTEXT_PROFILE_MASK_ARB:
2833 profileFlags = attrib_list[i + 1];
2834 break;
2835 default:
2836 fprintf(stderr, "Bad attribute in glXCreateContextAttribs()\n");
2837 return 0;
2838 }
2839 }
2840
2841 if (major * 10 + minor > 21) {
2842 /* swrast only supports GL 2.1 and earlier */
2843 return 0;
2844 }
2845
2846 /* These are ignored for now. We'd have to enhance XMesaCreateContext
2847 * to take these flags and the version, at least.
2848 */
2849 (void) ctxFlags;
2850 (void) profileFlags;
2851
2852 /* deallocate unused windows/buffers */
2853 XMesaGarbageCollect(dpy);
2854
2855 xmCtx = XMesaCreateContext(xmvis, (XMesaContext) share_context);
2856
2857 return (GLXContext) xmCtx;
2858 }
2859
2860
2861 /* silence warning */
2862 extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
2863
2864
2865 /**
2866 * Create a new GLX API dispatch table with its function pointers
2867 * initialized to point to Mesa's "fake" GLX API functions.
2868 * Note: there's a similar function (_real_GetGLXDispatchTable) that
2869 * returns a new dispatch table with all pointers initalized to point
2870 * to "real" GLX functions (which understand GLX wire protocol, etc).
2871 */
2872 struct _glxapi_table *
2873 _mesa_GetGLXDispatchTable(void)
2874 {
2875 static struct _glxapi_table glx;
2876
2877 /* be sure our dispatch table size <= libGL's table */
2878 {
2879 GLuint size = sizeof(struct _glxapi_table) / sizeof(void *);
2880 (void) size;
2881 assert(_glxapi_get_dispatch_table_size() >= size);
2882 }
2883
2884 /* initialize the whole table to no-ops */
2885 _glxapi_set_no_op_table(&glx);
2886
2887 /* now initialize the table with the functions I implement */
2888 glx.ChooseVisual = Fake_glXChooseVisual;
2889 glx.CopyContext = Fake_glXCopyContext;
2890 glx.CreateContext = Fake_glXCreateContext;
2891 glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap;
2892 glx.DestroyContext = Fake_glXDestroyContext;
2893 glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap;
2894 glx.GetConfig = Fake_glXGetConfig;
2895 glx.GetCurrentContext = Fake_glXGetCurrentContext;
2896 /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/
2897 glx.IsDirect = Fake_glXIsDirect;
2898 glx.MakeCurrent = Fake_glXMakeCurrent;
2899 glx.QueryExtension = Fake_glXQueryExtension;
2900 glx.QueryVersion = Fake_glXQueryVersion;
2901 glx.SwapBuffers = Fake_glXSwapBuffers;
2902 glx.UseXFont = Fake_glXUseXFont;
2903 glx.WaitGL = Fake_glXWaitGL;
2904 glx.WaitX = Fake_glXWaitX;
2905
2906 /*** GLX_VERSION_1_1 ***/
2907 glx.GetClientString = Fake_glXGetClientString;
2908 glx.QueryExtensionsString = Fake_glXQueryExtensionsString;
2909 glx.QueryServerString = Fake_glXQueryServerString;
2910
2911 /*** GLX_VERSION_1_2 ***/
2912 /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/
2913
2914 /*** GLX_VERSION_1_3 ***/
2915 glx.ChooseFBConfig = Fake_glXChooseFBConfig;
2916 glx.CreateNewContext = Fake_glXCreateNewContext;
2917 glx.CreatePbuffer = Fake_glXCreatePbuffer;
2918 glx.CreatePixmap = Fake_glXCreatePixmap;
2919 glx.CreateWindow = Fake_glXCreateWindow;
2920 glx.DestroyPbuffer = Fake_glXDestroyPbuffer;
2921 glx.DestroyPixmap = Fake_glXDestroyPixmap;
2922 glx.DestroyWindow = Fake_glXDestroyWindow;
2923 /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/
2924 glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib;
2925 glx.GetFBConfigs = Fake_glXGetFBConfigs;
2926 glx.GetSelectedEvent = Fake_glXGetSelectedEvent;
2927 glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig;
2928 glx.MakeContextCurrent = Fake_glXMakeContextCurrent;
2929 glx.QueryContext = Fake_glXQueryContext;
2930 glx.QueryDrawable = Fake_glXQueryDrawable;
2931 glx.SelectEvent = Fake_glXSelectEvent;
2932
2933 /*** GLX_SGI_swap_control ***/
2934 glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI;
2935
2936 /*** GLX_SGI_video_sync ***/
2937 glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI;
2938 glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI;
2939
2940 /*** GLX_SGI_make_current_read ***/
2941 glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI;
2942 /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/
2943
2944 /*** GLX_SGIX_video_source ***/
2945 #if defined(_VL_H)
2946 glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX;
2947 glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX;
2948 #endif
2949
2950 /*** GLX_EXT_import_context ***/
2951 glx.FreeContextEXT = Fake_glXFreeContextEXT;
2952 glx.GetContextIDEXT = Fake_glXGetContextIDEXT;
2953 /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/
2954 glx.ImportContextEXT = Fake_glXImportContextEXT;
2955 glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT;
2956
2957 /*** GLX_SGIX_fbconfig ***/
2958 glx.GetFBConfigAttribSGIX = Fake_glXGetFBConfigAttribSGIX;
2959 glx.ChooseFBConfigSGIX = Fake_glXChooseFBConfigSGIX;
2960 glx.CreateGLXPixmapWithConfigSGIX = Fake_glXCreateGLXPixmapWithConfigSGIX;
2961 glx.CreateContextWithConfigSGIX = Fake_glXCreateContextWithConfigSGIX;
2962 glx.GetVisualFromFBConfigSGIX = Fake_glXGetVisualFromFBConfigSGIX;
2963 glx.GetFBConfigFromVisualSGIX = Fake_glXGetFBConfigFromVisualSGIX;
2964
2965 /*** GLX_SGIX_pbuffer ***/
2966 glx.CreateGLXPbufferSGIX = Fake_glXCreateGLXPbufferSGIX;
2967 glx.DestroyGLXPbufferSGIX = Fake_glXDestroyGLXPbufferSGIX;
2968 glx.QueryGLXPbufferSGIX = Fake_glXQueryGLXPbufferSGIX;
2969 glx.SelectEventSGIX = Fake_glXSelectEventSGIX;
2970 glx.GetSelectedEventSGIX = Fake_glXGetSelectedEventSGIX;
2971
2972 /*** GLX_SGI_cushion ***/
2973 glx.CushionSGI = Fake_glXCushionSGI;
2974
2975 /*** GLX_SGIX_video_resize ***/
2976 glx.BindChannelToWindowSGIX = Fake_glXBindChannelToWindowSGIX;
2977 glx.ChannelRectSGIX = Fake_glXChannelRectSGIX;
2978 glx.QueryChannelRectSGIX = Fake_glXQueryChannelRectSGIX;
2979 glx.QueryChannelDeltasSGIX = Fake_glXQueryChannelDeltasSGIX;
2980 glx.ChannelRectSyncSGIX = Fake_glXChannelRectSyncSGIX;
2981
2982 /*** GLX_SGIX_dmbuffer **/
2983 #if defined(_DM_BUFFER_H_)
2984 glx.AssociateDMPbufferSGIX = NULL;
2985 #endif
2986
2987 /*** GLX_SGIX_swap_group ***/
2988 glx.JoinSwapGroupSGIX = Fake_glXJoinSwapGroupSGIX;
2989
2990 /*** GLX_SGIX_swap_barrier ***/
2991 glx.BindSwapBarrierSGIX = Fake_glXBindSwapBarrierSGIX;
2992 glx.QueryMaxSwapBarriersSGIX = Fake_glXQueryMaxSwapBarriersSGIX;
2993
2994 /*** GLX_SUN_get_transparent_index ***/
2995 glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN;
2996
2997 /*** GLX_MESA_copy_sub_buffer ***/
2998 glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA;
2999
3000 /*** GLX_MESA_release_buffers ***/
3001 glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA;
3002
3003 /*** GLX_MESA_pixmap_colormap ***/
3004 glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA;
3005
3006 /*** GLX_MESA_set_3dfx_mode ***/
3007 glx.Set3DfxModeMESA = Fake_glXSet3DfxModeMESA;
3008
3009 /*** GLX_NV_vertex_array_range ***/
3010 glx.AllocateMemoryNV = Fake_glXAllocateMemoryNV;
3011 glx.FreeMemoryNV = Fake_glXFreeMemoryNV;
3012
3013 /*** GLX_MESA_agp_offset ***/
3014 glx.GetAGPOffsetMESA = Fake_glXGetAGPOffsetMESA;
3015
3016 /*** GLX_EXT_texture_from_pixmap ***/
3017 glx.BindTexImageEXT = Fake_glXBindTexImageEXT;
3018 glx.ReleaseTexImageEXT = Fake_glXReleaseTexImageEXT;
3019
3020 glx.CreateContextAttribs = Fake_glXCreateContextAttribs;
3021 return &glx;
3022 }