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