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