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