4680994310ef2d97b6719b86e5569b80d8f6de39
[mesa.git] / src / mesa / drivers / x11 / glxapi.c
1
2 /*
3 * Mesa 3-D graphics library
4 * Version: 5.1
5 *
6 * Copyright (C) 1999-2002 Brian Paul 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 the GLX API dispatcher. Calls to the glX* functions are
29 * either routed to the real GLX encoders or to Mesa's pseudo-GLX functions.
30 * See the glxapi.h file for more details.
31 */
32
33
34 #include <assert.h>
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include "glapi.h"
39 #include "glxapi.h"
40
41
42 extern struct _glxapi_table *_real_GetGLXDispatchTable(void);
43 extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
44
45
46 struct display_dispatch {
47 Display *Dpy;
48 struct _glxapi_table *Table;
49 struct display_dispatch *Next;
50 };
51
52 static struct display_dispatch *DispatchList = NULL;
53
54
55 /* Display -> Dispatch caching */
56 static Display *prevDisplay = NULL;
57 static struct _glxapi_table *prevTable = NULL;
58
59
60 static struct _glxapi_table *
61 get_dispatch(Display *dpy)
62 {
63 if (!dpy)
64 return NULL;
65
66 /* search list of display/dispatch pairs for this display */
67 {
68 const struct display_dispatch *d = DispatchList;
69 while (d) {
70 if (d->Dpy == dpy) {
71 prevDisplay = dpy;
72 prevTable = d->Table;
73 return d->Table; /* done! */
74 }
75 d = d->Next;
76 }
77 }
78
79 /* A new display, determine if we should use real GLX
80 * or Mesa's pseudo-GLX.
81 */
82 {
83 struct _glxapi_table *t = NULL;
84
85 #ifdef GLX_BUILT_IN_XMESA
86 if (!getenv("LIBGL_FORCE_XMESA")) {
87 int ignore;
88 if (XQueryExtension( dpy, "GLX", &ignore, &ignore, &ignore )) {
89 /* the X server has the GLX extension */
90 t = _real_GetGLXDispatchTable();
91 }
92 }
93 #endif
94
95 if (!t) {
96 /* Fallback to Mesa with Xlib driver */
97 #ifdef GLX_BUILT_IN_XMESA
98 if (getenv("LIBGL_DEBUG")) {
99 fprintf(stderr,
100 "libGL: server %s lacks the GLX extension.",
101 dpy->display_name);
102 fprintf(stderr, " Using Mesa Xlib renderer.\n");
103 }
104 #endif
105 t = _mesa_GetGLXDispatchTable();
106 assert(t); /* this has to work */
107 }
108
109 if (t) {
110 struct display_dispatch *d;
111 d = (struct display_dispatch *) malloc(sizeof(struct display_dispatch));
112 if (d) {
113 d->Dpy = dpy;
114 d->Table = t;
115 /* insert at head of list */
116 d->Next = DispatchList;
117 DispatchList = d;
118 /* update cache */
119 prevDisplay = dpy;
120 prevTable = t;
121 return t;
122 }
123 }
124 }
125
126 /* If we get here that means we can't use real GLX on this display
127 * and the Mesa pseudo-GLX software renderer wasn't compiled in.
128 * Or, we ran out of memory!
129 */
130 return NULL;
131 }
132
133
134 #define GET_DISPATCH(DPY, TABLE) \
135 if (DPY == prevDisplay) { \
136 TABLE = prevTable; \
137 } \
138 else if (!DPY) { \
139 TABLE = NULL; \
140 } \
141 else { \
142 TABLE = get_dispatch(DPY); \
143 }
144
145
146
147
148 /* Set by glXMakeCurrent() and glXMakeContextCurrent() only */
149 #ifndef GLX_BUILT_IN_XMESA
150 static GLXContext CurrentContext = 0;
151 #define __glXGetCurrentContext() CurrentContext;
152 #endif
153
154
155 /*
156 * GLX API entrypoints
157 */
158
159 /*** GLX_VERSION_1_0 ***/
160
161 XVisualInfo *glXChooseVisual(Display *dpy, int screen, int *list)
162 {
163 struct _glxapi_table *t;
164 GET_DISPATCH(dpy, t);
165 if (!t)
166 return NULL;
167 return (t->ChooseVisual)(dpy, screen, list);
168 }
169
170
171 void glXCopyContext(Display *dpy, GLXContext src, GLXContext dst, unsigned long mask)
172 {
173 struct _glxapi_table *t;
174 GET_DISPATCH(dpy, t);
175 if (!t)
176 return;
177 (t->CopyContext)(dpy, src, dst, mask);
178 }
179
180
181 GLXContext glXCreateContext(Display *dpy, XVisualInfo *visinfo, GLXContext shareList, Bool direct)
182 {
183 struct _glxapi_table *t;
184 GET_DISPATCH(dpy, t);
185 if (!t)
186 return 0;
187 return (t->CreateContext)(dpy, visinfo, shareList, direct);
188 }
189
190
191 GLXPixmap glXCreateGLXPixmap(Display *dpy, XVisualInfo *visinfo, Pixmap pixmap)
192 {
193 struct _glxapi_table *t;
194 GET_DISPATCH(dpy, t);
195 if (!t)
196 return 0;
197 return (t->CreateGLXPixmap)(dpy, visinfo, pixmap);
198 }
199
200
201 void glXDestroyContext(Display *dpy, GLXContext ctx)
202 {
203 struct _glxapi_table *t;
204 GET_DISPATCH(dpy, t);
205 if (!t)
206 return;
207 (t->DestroyContext)(dpy, ctx);
208 }
209
210
211 void glXDestroyGLXPixmap(Display *dpy, GLXPixmap pixmap)
212 {
213 struct _glxapi_table *t;
214 GET_DISPATCH(dpy, t);
215 if (!t)
216 return;
217 (t->DestroyGLXPixmap)(dpy, pixmap);
218 }
219
220
221 int glXGetConfig(Display *dpy, XVisualInfo *visinfo, int attrib, int *value)
222 {
223 struct _glxapi_table *t;
224 GET_DISPATCH(dpy, t);
225 if (!t)
226 return GLX_NO_EXTENSION;
227 return (t->GetConfig)(dpy, visinfo, attrib, value);
228 }
229
230
231 #ifdef GLX_BUILT_IN_XMESA
232 /* Use real libGL's glXGetCurrentContext() function */
233 #else
234 /* stand-alone Mesa */
235 GLXContext glXGetCurrentContext(void)
236 {
237 return CurrentContext;
238 }
239 #endif
240
241
242 #ifdef GLX_BUILT_IN_XMESA
243 /* Use real libGL's glXGetCurrentContext() function */
244 #else
245 /* stand-alone Mesa */
246 GLXDrawable glXGetCurrentDrawable(void)
247 {
248 __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();
249 return gc ? gc->currentDrawable : 0;
250 }
251 #endif
252
253
254 Bool glXIsDirect(Display *dpy, GLXContext ctx)
255 {
256 struct _glxapi_table *t;
257 GET_DISPATCH(dpy, t);
258 if (!t)
259 return False;
260 return (t->IsDirect)(dpy, ctx);
261 }
262
263
264 Bool glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx)
265 {
266 Bool b;
267 struct _glxapi_table *t;
268 GET_DISPATCH(dpy, t);
269 if (!t) {
270 return False;
271 }
272 b = (*t->MakeCurrent)(dpy, drawable, ctx);
273 #ifndef GLX_BUILT_IN_XMESA
274 if (b) {
275 CurrentContext = ctx;
276 }
277 #endif
278 return b;
279 }
280
281
282 Bool glXQueryExtension(Display *dpy, int *errorb, int *event)
283 {
284 struct _glxapi_table *t;
285 GET_DISPATCH(dpy, t);
286 if (!t)
287 return False;
288 return (t->QueryExtension)(dpy, errorb, event);
289 }
290
291
292 Bool glXQueryVersion(Display *dpy, int *maj, int *min)
293 {
294 struct _glxapi_table *t;
295 GET_DISPATCH(dpy, t);
296 if (!t)
297 return False;
298 return (t->QueryVersion)(dpy, maj, min);
299 }
300
301
302 void glXSwapBuffers(Display *dpy, GLXDrawable drawable)
303 {
304 struct _glxapi_table *t;
305 GET_DISPATCH(dpy, t);
306 if (!t)
307 return;
308 (t->SwapBuffers)(dpy, drawable);
309 }
310
311
312 void glXUseXFont(Font font, int first, int count, int listBase)
313 {
314 struct _glxapi_table *t;
315 Display *dpy = glXGetCurrentDisplay();
316 GET_DISPATCH(dpy, t);
317 if (!t)
318 return;
319 (t->UseXFont)(font, first, count, listBase);
320 }
321
322
323 void glXWaitGL(void)
324 {
325 struct _glxapi_table *t;
326 Display *dpy = glXGetCurrentDisplay();
327 GET_DISPATCH(dpy, t);
328 if (!t)
329 return;
330 (t->WaitGL)();
331 }
332
333
334 void glXWaitX(void)
335 {
336 struct _glxapi_table *t;
337 Display *dpy = glXGetCurrentDisplay();
338 GET_DISPATCH(dpy, t);
339 if (!t)
340 return;
341 (t->WaitX)();
342 }
343
344
345
346 /*** GLX_VERSION_1_1 ***/
347
348 const char *glXGetClientString(Display *dpy, int name)
349 {
350 struct _glxapi_table *t;
351 GET_DISPATCH(dpy, t);
352 if (!t)
353 return NULL;
354 return (t->GetClientString)(dpy, name);
355 }
356
357
358 const char *glXQueryExtensionsString(Display *dpy, int screen)
359 {
360 struct _glxapi_table *t;
361 GET_DISPATCH(dpy, t);
362 if (!t)
363 return NULL;
364 return (t->QueryExtensionsString)(dpy, screen);
365 }
366
367
368 const char *glXQueryServerString(Display *dpy, int screen, int name)
369 {
370 struct _glxapi_table *t;
371 GET_DISPATCH(dpy, t);
372 if (!t)
373 return NULL;
374 return (t->QueryServerString)(dpy, screen, name);
375 }
376
377
378 /*** GLX_VERSION_1_2 ***/
379
380 #if !defined(GLX_BUILT_IN_XMESA)
381 Display *glXGetCurrentDisplay(void)
382 {
383 /* Same code as in libGL's glxext.c */
384 __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();
385 if (NULL == gc) return NULL;
386 return gc->currentDpy;
387 }
388 #endif
389
390
391
392 /*** GLX_VERSION_1_3 ***/
393
394 GLXFBConfig *glXChooseFBConfig(Display *dpy, int screen, const int *attribList, int *nitems)
395 {
396 struct _glxapi_table *t;
397 GET_DISPATCH(dpy, t);
398 if (!t)
399 return 0;
400 return (t->ChooseFBConfig)(dpy, screen, attribList, nitems);
401 }
402
403
404 GLXContext glXCreateNewContext(Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct)
405 {
406 struct _glxapi_table *t;
407 GET_DISPATCH(dpy, t);
408 if (!t)
409 return 0;
410 return (t->CreateNewContext)(dpy, config, renderType, shareList, direct);
411 }
412
413
414 GLXPbuffer glXCreatePbuffer(Display *dpy, GLXFBConfig config, const int *attribList)
415 {
416 struct _glxapi_table *t;
417 GET_DISPATCH(dpy, t);
418 if (!t)
419 return 0;
420 return (t->CreatePbuffer)(dpy, config, attribList);
421 }
422
423
424 GLXPixmap glXCreatePixmap(Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attribList)
425 {
426 struct _glxapi_table *t;
427 GET_DISPATCH(dpy, t);
428 if (!t)
429 return 0;
430 return (t->CreatePixmap)(dpy, config, pixmap, attribList);
431 }
432
433
434 GLXWindow glXCreateWindow(Display *dpy, GLXFBConfig config, Window win, const int *attribList)
435 {
436 struct _glxapi_table *t;
437 GET_DISPATCH(dpy, t);
438 if (!t)
439 return 0;
440 return (t->CreateWindow)(dpy, config, win, attribList);
441 }
442
443
444 void glXDestroyPbuffer(Display *dpy, GLXPbuffer pbuf)
445 {
446 struct _glxapi_table *t;
447 GET_DISPATCH(dpy, t);
448 if (!t)
449 return;
450 (t->DestroyPbuffer)(dpy, pbuf);
451 }
452
453
454 void glXDestroyPixmap(Display *dpy, GLXPixmap pixmap)
455 {
456 struct _glxapi_table *t;
457 GET_DISPATCH(dpy, t);
458 if (!t)
459 return;
460 (t->DestroyPixmap)(dpy, pixmap);
461 }
462
463
464 void glXDestroyWindow(Display *dpy, GLXWindow window)
465 {
466 struct _glxapi_table *t;
467 GET_DISPATCH(dpy, t);
468 if (!t)
469 return;
470 (t->DestroyWindow)(dpy, window);
471 }
472
473
474 #ifdef GLX_BUILT_IN_XMESA
475 /* Use the glXGetCurrentReadDrawable() function from libGL */
476 #else
477 GLXDrawable glXGetCurrentReadDrawable(void)
478 {
479 __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();
480 return gc ? gc->currentReadable : 0;
481 }
482 #endif
483
484
485 int glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, int attribute, int *value)
486 {
487 struct _glxapi_table *t;
488 GET_DISPATCH(dpy, t);
489 if (!t)
490 return GLX_NO_EXTENSION;
491 return (t->GetFBConfigAttrib)(dpy, config, attribute, value);
492 }
493
494
495 GLXFBConfig *glXGetFBConfigs(Display *dpy, int screen, int *nelements)
496 {
497 struct _glxapi_table *t;
498 GET_DISPATCH(dpy, t);
499 if (!t)
500 return 0;
501 return (t->GetFBConfigs)(dpy, screen, nelements);
502 }
503
504 void glXGetSelectedEvent(Display *dpy, GLXDrawable drawable, unsigned long *mask)
505 {
506 struct _glxapi_table *t;
507 GET_DISPATCH(dpy, t);
508 if (!t)
509 return;
510 (t->GetSelectedEvent)(dpy, drawable, mask);
511 }
512
513
514 XVisualInfo *glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config)
515 {
516 struct _glxapi_table *t;
517 GET_DISPATCH(dpy, t);
518 if (!t)
519 return NULL;
520 return (t->GetVisualFromFBConfig)(dpy, config);
521 }
522
523
524 Bool glXMakeContextCurrent(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
525 {
526 Bool b;
527 struct _glxapi_table *t;
528 GET_DISPATCH(dpy, t);
529 if (!t)
530 return False;
531 b = (t->MakeContextCurrent)(dpy, draw, read, ctx);
532 #ifndef GLX_BUILT_IN_XMESA
533 if (b) {
534 CurrentContext = ctx;
535 }
536 #endif
537 return b;
538 }
539
540
541 int glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value)
542 {
543 struct _glxapi_table *t;
544 GET_DISPATCH(dpy, t);
545 assert(t);
546 if (!t)
547 return 0; /* XXX correct? */
548 return (t->QueryContext)(dpy, ctx, attribute, value);
549 }
550
551
552 void glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value)
553 {
554 struct _glxapi_table *t;
555 GET_DISPATCH(dpy, t);
556 if (!t)
557 return;
558 (t->QueryDrawable)(dpy, draw, attribute, value);
559 }
560
561
562 void glXSelectEvent(Display *dpy, GLXDrawable drawable, unsigned long mask)
563 {
564 struct _glxapi_table *t;
565 GET_DISPATCH(dpy, t);
566 if (!t)
567 return;
568 (t->SelectEvent)(dpy, drawable, mask);
569 }
570
571
572
573 /*** GLX_SGI_swap_control ***/
574
575 int glXSwapIntervalSGI(int interval)
576 {
577 struct _glxapi_table *t;
578 Display *dpy = glXGetCurrentDisplay();
579 GET_DISPATCH(dpy, t);
580 if (!t)
581 return 0;
582 return (t->SwapIntervalSGI)(interval);
583 }
584
585
586
587 /*** GLX_SGI_video_sync ***/
588
589 int glXGetVideoSyncSGI(unsigned int *count)
590 {
591 struct _glxapi_table *t;
592 Display *dpy = glXGetCurrentDisplay();
593 GET_DISPATCH(dpy, t);
594 if (!t)
595 return 0;
596 return (t->GetVideoSyncSGI)(count);
597 }
598
599 int glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
600 {
601 struct _glxapi_table *t;
602 Display *dpy = glXGetCurrentDisplay();
603 GET_DISPATCH(dpy, t);
604 if (!t)
605 return 0;
606 return (t->WaitVideoSyncSGI)(divisor, remainder, count);
607 }
608
609
610
611 /*** GLX_SGI_make_current_read ***/
612
613 Bool glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
614 {
615 struct _glxapi_table *t;
616 GET_DISPATCH(dpy, t);
617 if (!t)
618 return 0;
619 return (t->MakeCurrentReadSGI)(dpy, draw, read, ctx);
620 }
621
622 #ifdef GLX_BUILT_IN_XMESA
623 /* Use glXGetCurrentReadDrawableSGI() from libGL */
624 #else
625 /* stand-alone Mesa */
626 GLXDrawable glXGetCurrentReadDrawableSGI(void)
627 {
628 return glXGetCurrentReadDrawable();
629 }
630 #endif
631
632
633 #if defined(_VL_H)
634
635 GLXVideoSourceSGIX glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
636 {
637 struct _glxapi_table *t;
638 GET_DISPATCH(dpy, t);
639 if (!t)
640 return 0;
641 return (t->CreateGLXVideoSourceSGIX)(dpy, screen, server, path, nodeClass, drainNode);
642 }
643
644 void glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
645 {
646 struct _glxapi_table *t;
647 GET_DISPATCH(dpy, t);
648 if (!t)
649 return 0;
650 return (t->DestroyGLXVideoSourceSGIX)(dpy, src);
651 }
652
653 #endif
654
655
656 /*** GLX_EXT_import_context ***/
657
658 void glXFreeContextEXT(Display *dpy, GLXContext context)
659 {
660 struct _glxapi_table *t;
661 GET_DISPATCH(dpy, t);
662 if (!t)
663 return;
664 (t->FreeContextEXT)(dpy, context);
665 }
666
667 #ifdef GLX_BUILT_IN_XMESA
668 /* Use real libGL's glXGetContextIDEXT() function */
669 #else
670 /* stand-alone Mesa */
671 GLXContextID glXGetContextIDEXT(const GLXContext context)
672 {
673 return ((__GLXcontext *) context)->xid;
674 }
675 #endif
676
677 #ifdef GLX_BUILT_IN_XMESA
678 /* Use real libGL's glXGetCurrentDisplayEXT() function */
679 #else
680 /* stand-alone Mesa */
681 Display *glXGetCurrentDisplayEXT(void)
682 {
683 return glXGetCurrentDisplay();
684 }
685 #endif
686
687 GLXContext glXImportContextEXT(Display *dpy, GLXContextID contextID)
688 {
689 struct _glxapi_table *t;
690 GET_DISPATCH(dpy, t);
691 if (!t)
692 return 0;
693 return (t->ImportContextEXT)(dpy, contextID);
694 }
695
696 int glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute,int *value)
697 {
698 struct _glxapi_table *t;
699 GET_DISPATCH(dpy, t);
700 if (!t)
701 return 0; /* XXX ok? */
702 return (t->QueryContextInfoEXT)(dpy, context, attribute, value);
703 }
704
705
706
707 /*** GLX_SGIX_fbconfig ***/
708
709 int glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
710 {
711 struct _glxapi_table *t;
712 GET_DISPATCH(dpy, t);
713 if (!t)
714 return 0;
715 return (t->GetFBConfigAttribSGIX)(dpy, config, attribute, value);
716 }
717
718 GLXFBConfigSGIX *glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
719 {
720 struct _glxapi_table *t;
721 GET_DISPATCH(dpy, t);
722 if (!t)
723 return 0;
724 return (t->ChooseFBConfigSGIX)(dpy, screen, attrib_list, nelements);
725 }
726
727 GLXPixmap glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
728 {
729 struct _glxapi_table *t;
730 GET_DISPATCH(dpy, t);
731 if (!t)
732 return 0;
733 return (t->CreateGLXPixmapWithConfigSGIX)(dpy, config, pixmap);
734 }
735
736 GLXContext glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
737 {
738 struct _glxapi_table *t;
739 GET_DISPATCH(dpy, t);
740 if (!t)
741 return 0;
742 return (t->CreateContextWithConfigSGIX)(dpy, config, render_type, share_list, direct);
743 }
744
745 XVisualInfo * glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
746 {
747 struct _glxapi_table *t;
748 GET_DISPATCH(dpy, t);
749 if (!t)
750 return 0;
751 return (t->GetVisualFromFBConfigSGIX)(dpy, config);
752 }
753
754 GLXFBConfigSGIX glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
755 {
756 struct _glxapi_table *t;
757 GET_DISPATCH(dpy, t);
758 if (!t)
759 return 0;
760 return (t->GetFBConfigFromVisualSGIX)(dpy, vis);
761 }
762
763
764
765 /*** GLX_SGIX_pbuffer ***/
766
767 GLXPbufferSGIX glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list)
768 {
769 struct _glxapi_table *t;
770 GET_DISPATCH(dpy, t);
771 if (!t)
772 return 0;
773 return (t->CreateGLXPbufferSGIX)(dpy, config, width, height, attrib_list);
774 }
775
776 void glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
777 {
778 struct _glxapi_table *t;
779 GET_DISPATCH(dpy, t);
780 if (!t)
781 return;
782 (t->DestroyGLXPbufferSGIX)(dpy, pbuf);
783 }
784
785 int glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
786 {
787 struct _glxapi_table *t;
788 GET_DISPATCH(dpy, t);
789 if (!t)
790 return 0;
791 return (t->QueryGLXPbufferSGIX)(dpy, pbuf, attribute, value);
792 }
793
794 void glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
795 {
796 struct _glxapi_table *t;
797 GET_DISPATCH(dpy, t);
798 if (!t)
799 return;
800 (t->SelectEventSGIX)(dpy, drawable, mask);
801 }
802
803 void glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
804 {
805 struct _glxapi_table *t;
806 GET_DISPATCH(dpy, t);
807 if (!t)
808 return;
809 (t->GetSelectedEventSGIX)(dpy, drawable, mask);
810 }
811
812
813
814 /*** GLX_SGI_cushion ***/
815
816 void glXCushionSGI(Display *dpy, Window win, float cushion)
817 {
818 struct _glxapi_table *t;
819 GET_DISPATCH(dpy, t);
820 if (!t)
821 return;
822 (t->CushionSGI)(dpy, win, cushion);
823 }
824
825
826
827 /*** GLX_SGIX_video_resize ***/
828
829 int glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
830 {
831 struct _glxapi_table *t;
832 GET_DISPATCH(dpy, t);
833 if (!t)
834 return 0;
835 return (t->BindChannelToWindowSGIX)(dpy, screen, channel, window);
836 }
837
838 int glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
839 {
840 struct _glxapi_table *t;
841 GET_DISPATCH(dpy, t);
842 if (!t)
843 return 0;
844 return (t->ChannelRectSGIX)(dpy, screen, channel, x, y, w, h);
845 }
846
847 int glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
848 {
849 struct _glxapi_table *t;
850 GET_DISPATCH(dpy, t);
851 if (!t)
852 return 0;
853 return (t->QueryChannelRectSGIX)(dpy, screen, channel, x, y, w, h);
854 }
855
856 int glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
857 {
858 struct _glxapi_table *t;
859 GET_DISPATCH(dpy, t);
860 if (!t)
861 return 0;
862 return (t->QueryChannelDeltasSGIX)(dpy, screen, channel, dx, dy, dw, dh);
863 }
864
865 int glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
866 {
867 struct _glxapi_table *t;
868 GET_DISPATCH(dpy, t);
869 if (!t)
870 return 0;
871 return (t->ChannelRectSyncSGIX)(dpy, screen, channel, synctype);
872 }
873
874
875
876 #if defined(_DM_BUFFER_H_)
877
878 Bool glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
879 {
880 struct _glxapi_table *t;
881 GET_DISPATCH(dpy, t);
882 if (!t)
883 return False;
884 return (t->AssociateDMPbufferSGIX)(dpy, pbuffer, params, dmbuffer);
885 }
886
887 #endif
888
889
890 /*** GLX_SGIX_swap_group ***/
891
892 void glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
893 {
894 struct _glxapi_table *t;
895 GET_DISPATCH(dpy, t);
896 if (!t)
897 return;
898 (*t->JoinSwapGroupSGIX)(dpy, drawable, member);
899 }
900
901
902 /*** GLX_SGIX_swap_barrier ***/
903
904 void glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
905 {
906 struct _glxapi_table *t;
907 GET_DISPATCH(dpy, t);
908 if (!t)
909 return;
910 (*t->BindSwapBarrierSGIX)(dpy, drawable, barrier);
911 }
912
913 Bool glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
914 {
915 struct _glxapi_table *t;
916 GET_DISPATCH(dpy, t);
917 if (!t)
918 return False;
919 return (*t->QueryMaxSwapBarriersSGIX)(dpy, screen, max);
920 }
921
922
923
924 /*** GLX_SUN_get_transparent_index ***/
925
926 Status glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
927 {
928 struct _glxapi_table *t;
929 GET_DISPATCH(dpy, t);
930 if (!t)
931 return False;
932 return (*t->GetTransparentIndexSUN)(dpy, overlay, underlay, pTransparent);
933 }
934
935
936
937 /*** GLX_MESA_copy_sub_buffer ***/
938
939 void glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height)
940 {
941 struct _glxapi_table *t;
942 GET_DISPATCH(dpy, t);
943 if (!t)
944 return;
945 (t->CopySubBufferMESA)(dpy, drawable, x, y, width, height);
946 }
947
948
949
950 /*** GLX_MESA_release_buffers ***/
951
952 Bool glXReleaseBuffersMESA(Display *dpy, Window w)
953 {
954 struct _glxapi_table *t;
955 GET_DISPATCH(dpy, t);
956 if (!t)
957 return False;
958 return (t->ReleaseBuffersMESA)(dpy, w);
959 }
960
961
962
963 /*** GLX_MESA_pixmap_colormap ***/
964
965 GLXPixmap glXCreateGLXPixmapMESA(Display *dpy, XVisualInfo *visinfo, Pixmap pixmap, Colormap cmap)
966 {
967 struct _glxapi_table *t;
968 GET_DISPATCH(dpy, t);
969 if (!t)
970 return 0;
971 return (t->CreateGLXPixmapMESA)(dpy, visinfo, pixmap, cmap);
972 }
973
974
975
976 /*** GLX_MESA_set_3dfx_mode ***/
977
978 Bool glXSet3DfxModeMESA(int mode)
979 {
980 struct _glxapi_table *t;
981 Display *dpy = glXGetCurrentDisplay();
982 GET_DISPATCH(dpy, t);
983 if (!t)
984 return False;
985 return (t->Set3DfxModeMESA)(mode);
986 }
987
988
989
990 /*** GLX_NV_vertex_array_range ***/
991
992 void *
993 glXAllocateMemoryNV( GLsizei size,
994 GLfloat readFrequency,
995 GLfloat writeFrequency,
996 GLfloat priority )
997 {
998 struct _glxapi_table *t;
999 Display *dpy = glXGetCurrentDisplay();
1000 GET_DISPATCH(dpy, t);
1001 if (!t)
1002 return NULL;
1003 return (t->AllocateMemoryNV)(size, readFrequency, writeFrequency, priority);
1004 }
1005
1006
1007 void
1008 glXFreeMemoryNV( GLvoid *pointer )
1009 {
1010 struct _glxapi_table *t;
1011 Display *dpy = glXGetCurrentDisplay();
1012 GET_DISPATCH(dpy, t);
1013 if (!t)
1014 return;
1015 (t->FreeMemoryNV)(pointer);
1016 }
1017
1018
1019 /*** GLX_MESA_agp_offset */
1020
1021 GLuint
1022 glXGetAGPOffsetMESA( const GLvoid *pointer )
1023 {
1024 struct _glxapi_table *t;
1025 Display *dpy = glXGetCurrentDisplay();
1026 GET_DISPATCH(dpy, t);
1027 if (!t)
1028 return ~0;
1029 return (t->GetAGPOffsetMESA)(pointer);
1030 }
1031
1032
1033 /*** GLX_ARB_render_Texture ***/
1034
1035 Bool
1036 glXBindTexImageARB( Display *dpy, GLXPbuffer pbuffer, int buffer )
1037 {
1038 struct _glxapi_table *t;
1039 GET_DISPATCH(dpy, t);
1040 if (!t)
1041 return False;
1042 return (t->BindTexImageARB)(dpy, pbuffer, buffer);
1043 }
1044
1045
1046 Bool
1047 glXReleaseTexImageARB(Display *dpy, GLXPbuffer pbuffer, int buffer )
1048 {
1049 struct _glxapi_table *t;
1050 GET_DISPATCH(dpy, t);
1051 if (!t)
1052 return False;
1053 return (t->ReleaseTexImageARB)(dpy, pbuffer, buffer);
1054 }
1055
1056
1057 Bool
1058 glXDrawableAttribARB( Display *dpy, GLXDrawable draw, const int *attribList )
1059 {
1060 struct _glxapi_table *t;
1061 GET_DISPATCH(dpy, t);
1062 if (!t)
1063 return False;
1064 return (t->DrawableAttribARB)(dpy, draw, attribList);
1065 }
1066
1067
1068
1069 /**********************************************************************/
1070 /* GLX API management functions */
1071 /**********************************************************************/
1072
1073
1074 const char *
1075 _glxapi_get_version(void)
1076 {
1077 return "1.3";
1078 }
1079
1080
1081 /*
1082 * Return array of extension strings.
1083 */
1084 const char **
1085 _glxapi_get_extensions(void)
1086 {
1087 static const char *extensions[] = {
1088 #ifdef GLX_EXT_import_context
1089 "GLX_EXT_import_context",
1090 #endif
1091 #ifdef GLX_SGI_video_sync
1092 "GLX_SGI_video_sync",
1093 #endif
1094 #ifdef GLX_MESA_copy_sub_buffer
1095 "GLX_MESA_copy_sub_buffer",
1096 #endif
1097 #ifdef GLX_MESA_release_buffers
1098 "GLX_MESA_release_buffers",
1099 #endif
1100 #ifdef GLX_MESA_pixmap_colormap
1101 "GLX_MESA_pixmap_colormap",
1102 #endif
1103 #ifdef GLX_MESA_set_3dfx_mode
1104 "GLX_MESA_set_3dfx_mode",
1105 #endif
1106 #ifdef GLX_SGIX_fbconfig
1107 "GLX_SGIX_fbconfig",
1108 #endif
1109 #ifdef GLX_SGIX_pbuffer
1110 "GLX_SGIX_pbuffer",
1111 #endif
1112 #ifdef GLX_ARB_render_texture
1113 "GLX_ARB_render_texture",
1114 #endif
1115 NULL
1116 };
1117 return extensions;
1118 }
1119
1120
1121 /*
1122 * Return size of the GLX dispatch table, in entries, not bytes.
1123 */
1124 GLuint
1125 _glxapi_get_dispatch_table_size(void)
1126 {
1127 return sizeof(struct _glxapi_table) / sizeof(void *);
1128 }
1129
1130
1131 static int
1132 generic_no_op_func(void)
1133 {
1134 return 0;
1135 }
1136
1137
1138 /*
1139 * Initialize all functions in given dispatch table to be no-ops
1140 */
1141 void
1142 _glxapi_set_no_op_table(struct _glxapi_table *t)
1143 {
1144 GLuint n = _glxapi_get_dispatch_table_size();
1145 GLuint i;
1146 void **dispatch = (void **) t;
1147 for (i = 0; i < n; i++) {
1148 dispatch[i] = (void *) generic_no_op_func;
1149 }
1150 }
1151
1152
1153 struct name_address_pair {
1154 const char *Name;
1155 GLvoid *Address;
1156 };
1157
1158 static struct name_address_pair GLX_functions[] = {
1159 /*** GLX_VERSION_1_0 ***/
1160 { "glXChooseVisual", (GLvoid *) glXChooseVisual },
1161 { "glXCopyContext", (GLvoid *) glXCopyContext },
1162 { "glXCreateContext", (GLvoid *) glXCreateContext },
1163 { "glXCreateGLXPixmap", (GLvoid *) glXCreateGLXPixmap },
1164 { "glXDestroyContext", (GLvoid *) glXDestroyContext },
1165 { "glXDestroyGLXPixmap", (GLvoid *) glXDestroyGLXPixmap },
1166 { "glXGetConfig", (GLvoid *) glXGetConfig },
1167 { "glXGetCurrentContext", (GLvoid *) glXGetCurrentContext },
1168 { "glXGetCurrentDrawable", (GLvoid *) glXGetCurrentDrawable },
1169 { "glXIsDirect", (GLvoid *) glXIsDirect },
1170 { "glXMakeCurrent", (GLvoid *) glXMakeCurrent },
1171 { "glXQueryExtension", (GLvoid *) glXQueryExtension },
1172 { "glXQueryVersion", (GLvoid *) glXQueryVersion },
1173 { "glXSwapBuffers", (GLvoid *) glXSwapBuffers },
1174 { "glXUseXFont", (GLvoid *) glXUseXFont },
1175 { "glXWaitGL", (GLvoid *) glXWaitGL },
1176 { "glXWaitX", (GLvoid *) glXWaitX },
1177
1178 /*** GLX_VERSION_1_1 ***/
1179 { "glXGetClientString", (GLvoid *) glXGetClientString },
1180 { "glXQueryExtensionsString", (GLvoid *) glXQueryExtensionsString },
1181 { "glXQueryServerString", (GLvoid *) glXQueryServerString },
1182
1183 /*** GLX_VERSION_1_2 ***/
1184 { "glXGetCurrentDisplay", (GLvoid *) glXGetCurrentDisplay },
1185
1186 /*** GLX_VERSION_1_3 ***/
1187 { "glXChooseFBConfig", (GLvoid *) glXChooseFBConfig },
1188 { "glXCreateNewContext", (GLvoid *) glXCreateNewContext },
1189 { "glXCreatePbuffer", (GLvoid *) glXCreatePbuffer },
1190 { "glXCreatePixmap", (GLvoid *) glXCreatePixmap },
1191 { "glXCreateWindow", (GLvoid *) glXCreateWindow },
1192 { "glXDestroyPbuffer", (GLvoid *) glXDestroyPbuffer },
1193 { "glXDestroyPixmap", (GLvoid *) glXDestroyPixmap },
1194 { "glXDestroyWindow", (GLvoid *) glXDestroyWindow },
1195 { "glXGetCurrentReadDrawable", (GLvoid *) glXGetCurrentReadDrawable },
1196 { "glXGetFBConfigAttrib", (GLvoid *) glXGetFBConfigAttrib },
1197 { "glXGetFBConfigs", (GLvoid *) glXGetFBConfigs },
1198 { "glXGetSelectedEvent", (GLvoid *) glXGetSelectedEvent },
1199 { "glXGetVisualFromFBConfig", (GLvoid *) glXGetVisualFromFBConfig },
1200 { "glXMakeContextCurrent", (GLvoid *) glXMakeContextCurrent },
1201 { "glXQueryContext", (GLvoid *) glXQueryContext },
1202 { "glXQueryDrawable", (GLvoid *) glXQueryDrawable },
1203 { "glXSelectEvent", (GLvoid *) glXSelectEvent },
1204
1205 /*** GLX_VERSION_1_4 ***/
1206 { "glXGetProcAddress", (GLvoid *) glXGetProcAddress },
1207
1208 /*** GLX_SGI_swap_control ***/
1209 { "glXSwapIntervalSGI", (GLvoid *) glXSwapIntervalSGI },
1210
1211 /*** GLX_SGI_video_sync ***/
1212 { "glXGetVideoSyncSGI", (GLvoid *) glXGetVideoSyncSGI },
1213 { "glXWaitVideoSyncSGI", (GLvoid *) glXWaitVideoSyncSGI },
1214
1215 /*** GLX_SGI_make_current_read ***/
1216 { "glXMakeCurrentReadSGI", (GLvoid *) glXMakeCurrentReadSGI },
1217 { "glXGetCurrentReadDrawableSGI", (GLvoid *) glXGetCurrentReadDrawableSGI },
1218
1219 /*** GLX_SGIX_video_source ***/
1220 #if defined(_VL_H)
1221 { "glXCreateGLXVideoSourceSGIX", (GLvoid *) glXCreateGLXVideoSourceSGIX },
1222 { "glXDestroyGLXVideoSourceSGIX", (GLvoid *) glXDestroyGLXVideoSourceSGIX },
1223 #endif
1224
1225 /*** GLX_EXT_import_context ***/
1226 { "glXFreeContextEXT", (GLvoid *) glXFreeContextEXT },
1227 { "glXGetContextIDEXT", (GLvoid *) glXGetContextIDEXT },
1228 { "glXGetCurrentDisplayEXT", (GLvoid *) glXGetCurrentDisplayEXT },
1229 { "glXImportContextEXT", (GLvoid *) glXImportContextEXT },
1230 { "glXQueryContextInfoEXT", (GLvoid *) glXQueryContextInfoEXT },
1231
1232 /*** GLX_SGIX_fbconfig ***/
1233 { "glXGetFBConfigAttribSGIX", (GLvoid *) glXGetFBConfigAttribSGIX },
1234 { "glXChooseFBConfigSGIX", (GLvoid *) glXChooseFBConfigSGIX },
1235 { "glXCreateGLXPixmapWithConfigSGIX", (GLvoid *) glXCreateGLXPixmapWithConfigSGIX },
1236 { "glXCreateContextWithConfigSGIX", (GLvoid *) glXCreateContextWithConfigSGIX },
1237 { "glXGetVisualFromFBConfigSGIX", (GLvoid *) glXGetVisualFromFBConfigSGIX },
1238 { "glXGetFBConfigFromVisualSGIX", (GLvoid *) glXGetFBConfigFromVisualSGIX },
1239
1240 /*** GLX_SGIX_pbuffer ***/
1241 { "glXCreateGLXPbufferSGIX", (GLvoid *) glXCreateGLXPbufferSGIX },
1242 { "glXDestroyGLXPbufferSGIX", (GLvoid *) glXDestroyGLXPbufferSGIX },
1243 { "glXQueryGLXPbufferSGIX", (GLvoid *) glXQueryGLXPbufferSGIX },
1244 { "glXSelectEventSGIX", (GLvoid *) glXSelectEventSGIX },
1245 { "glXGetSelectedEventSGIX", (GLvoid *) glXGetSelectedEventSGIX },
1246
1247 /*** GLX_SGI_cushion ***/
1248 { "glXCushionSGI", (GLvoid *) glXCushionSGI },
1249
1250 /*** GLX_SGIX_video_resize ***/
1251 { "glXBindChannelToWindowSGIX", (GLvoid *) glXBindChannelToWindowSGIX },
1252 { "glXChannelRectSGIX", (GLvoid *) glXChannelRectSGIX },
1253 { "glXQueryChannelRectSGIX", (GLvoid *) glXQueryChannelRectSGIX },
1254 { "glXQueryChannelDeltasSGIX", (GLvoid *) glXQueryChannelDeltasSGIX },
1255 { "glXChannelRectSyncSGIX", (GLvoid *) glXChannelRectSyncSGIX },
1256
1257 /*** GLX_SGIX_dmbuffer **/
1258 #if defined(_DM_BUFFER_H_)
1259 { "glXAssociateDMPbufferSGIX", (GLvoid *) glXAssociateDMPbufferSGIX },
1260 #endif
1261
1262 /*** GLX_SGIX_swap_group ***/
1263 { "glXJoinSwapGroupSGIX", (GLvoid *) glXJoinSwapGroupSGIX },
1264
1265 /*** GLX_SGIX_swap_barrier ***/
1266 { "glXBindSwapBarrierSGIX", (GLvoid *) glXBindSwapBarrierSGIX },
1267 { "glXQueryMaxSwapBarriersSGIX", (GLvoid *) glXQueryMaxSwapBarriersSGIX },
1268
1269 /*** GLX_SUN_get_transparent_index ***/
1270 { "glXGetTransparentIndexSUN", (GLvoid *) glXGetTransparentIndexSUN },
1271
1272 /*** GLX_MESA_copy_sub_buffer ***/
1273 { "glXCopySubBufferMESA", (GLvoid *) glXCopySubBufferMESA },
1274
1275 /*** GLX_MESA_pixmap_colormap ***/
1276 { "glXCreateGLXPixmapMESA", (GLvoid *) glXCreateGLXPixmapMESA },
1277
1278 /*** GLX_MESA_release_buffers ***/
1279 { "glXReleaseBuffersMESA", (GLvoid *) glXReleaseBuffersMESA },
1280
1281 /*** GLX_MESA_set_3dfx_mode ***/
1282 { "glXSet3DfxModeMESA", (GLvoid *) glXSet3DfxModeMESA },
1283
1284 /*** GLX_ARB_get_proc_address ***/
1285 { "glXGetProcAddressARB", (GLvoid *) glXGetProcAddressARB },
1286
1287 /*** GLX_NV_vertex_array_range ***/
1288 { "glXAllocateMemoryNV", (GLvoid *) glXAllocateMemoryNV },
1289 { "glXFreeMemoryNV", (GLvoid *) glXFreeMemoryNV },
1290
1291 /*** GLX_MESA_agp_offset ***/
1292 { "glXGetAGPOffsetMESA", (GLvoid *) glXGetAGPOffsetMESA },
1293
1294 /*** GLX_ARB_render_texture ***/
1295 { "glXBindTexImageARB", (GLvoid *) glXBindTexImageARB },
1296 { "glXReleaseTexImageARB", (GLvoid *) glXReleaseTexImageARB },
1297 { "glXDrawableAttribARB", (GLvoid *) glXDrawableAttribARB },
1298
1299 { NULL, NULL } /* end of list */
1300 };
1301
1302
1303
1304 /*
1305 * Return address of named glX function, or NULL if not found.
1306 */
1307 const GLvoid *
1308 _glxapi_get_proc_address(const char *funcName)
1309 {
1310 GLuint i;
1311 for (i = 0; GLX_functions[i].Name; i++) {
1312 if (strcmp(GLX_functions[i].Name, funcName) == 0)
1313 return GLX_functions[i].Address;
1314 }
1315 return NULL;
1316 }
1317
1318
1319
1320 /*
1321 * This function does not get dispatched through the dispatch table
1322 * since it's really a "meta" function.
1323 */
1324 void (*glXGetProcAddressARB(const GLubyte *procName))()
1325 {
1326 typedef void (*gl_function)();
1327 gl_function f;
1328
1329 f = (gl_function) _glxapi_get_proc_address((const char *) procName);
1330 if (f) {
1331 return f;
1332 }
1333
1334 f = (gl_function) _glapi_get_proc_address((const char *) procName);
1335 return f;
1336 }
1337
1338
1339 /* GLX 1.4 */
1340 void (*glXGetProcAddress(const GLubyte *procName))()
1341 {
1342 return glXGetProcAddressARB(procName);
1343 }