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