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