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