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