2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
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.
37 #include "main/glheader.h"
38 #include "main/compiler.h"
39 #include "glapi/glapi.h"
43 extern struct _glxapi_table *_real_GetGLXDispatchTable(void);
44 extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void);
47 struct display_dispatch {
49 struct _glxapi_table *Table;
50 struct display_dispatch *Next;
55 * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in
56 * libglapi.a. We need to define them here.
58 #ifdef GLX_INDIRECT_RENDERING
60 #include "glapi/glapitable.h"
62 #define KEYWORD1 PUBLIC
64 #if defined(USE_MGL_NAMESPACE)
65 #define NAME(func) mgl##func
67 #define NAME(func) gl##func
70 #define DISPATCH(FUNC, ARGS, MESSAGE) \
71 GET_DISPATCH()->FUNC ARGS
73 #define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \
74 return GET_DISPATCH()->FUNC ARGS
76 /* skip normal ones */
77 #define _GLAPI_SKIP_NORMAL_ENTRY_POINTS
78 #include "glapi/glapitemp.h"
80 #endif /* GLX_INDIRECT_RENDERING */
83 static struct display_dispatch *DispatchList = NULL;
86 /* Display -> Dispatch caching */
87 static Display *prevDisplay = NULL;
88 static struct _glxapi_table *prevTable = NULL;
91 static struct _glxapi_table *
92 get_dispatch(Display *dpy)
97 /* search list of display/dispatch pairs for this display */
99 const struct display_dispatch *d = DispatchList;
103 prevTable = d->Table;
104 return d->Table; /* done! */
110 /* A new display, determine if we should use real GLX
111 * or Mesa's pseudo-GLX.
114 struct _glxapi_table *t = _mesa_GetGLXDispatchTable();
117 struct display_dispatch *d;
118 d = (struct display_dispatch *) malloc(sizeof(struct display_dispatch));
122 /* insert at head of list */
123 d->Next = DispatchList;
133 /* If we get here that means we can't use real GLX on this display
134 * and the Mesa pseudo-GLX software renderer wasn't compiled in.
135 * Or, we ran out of memory!
141 /* Don't use the GET_DISPATCH defined in glthread.h */
144 #define GET_DISPATCH(DPY, TABLE) \
145 if (DPY == prevDisplay) { \
152 TABLE = get_dispatch(DPY); \
159 * GLX API current context.
161 #if defined(GLX_USE_TLS)
162 PUBLIC __thread void * CurrentContext
163 __attribute__((tls_model("initial-exec")));
164 #elif defined(THREADS)
165 static _glthread_TSD ContextTSD; /**< Per-thread context pointer */
167 static GLXContext CurrentContext = 0;
172 SetCurrentContext(GLXContext c)
174 #if defined(GLX_USE_TLS)
176 #elif defined(THREADS)
177 _glthread_SetTSD(&ContextTSD, c);
185 * GLX API entrypoints
188 /*** GLX_VERSION_1_0 ***/
191 glXChooseVisual(Display *dpy, int screen, int *list)
193 struct _glxapi_table *t;
194 GET_DISPATCH(dpy, t);
197 return (t->ChooseVisual)(dpy, screen, list);
202 glXCopyContext(Display *dpy, GLXContext src, GLXContext dst, unsigned long mask)
204 struct _glxapi_table *t;
205 GET_DISPATCH(dpy, t);
208 (t->CopyContext)(dpy, src, dst, mask);
213 glXCreateContext(Display *dpy, XVisualInfo *visinfo, GLXContext shareList, Bool direct)
215 struct _glxapi_table *t;
216 GET_DISPATCH(dpy, t);
219 return (t->CreateContext)(dpy, visinfo, shareList, direct);
224 glXCreateGLXPixmap(Display *dpy, XVisualInfo *visinfo, Pixmap pixmap)
226 struct _glxapi_table *t;
227 GET_DISPATCH(dpy, t);
230 return (t->CreateGLXPixmap)(dpy, visinfo, pixmap);
235 glXDestroyContext(Display *dpy, GLXContext ctx)
237 struct _glxapi_table *t;
238 GET_DISPATCH(dpy, t);
241 if (glXGetCurrentContext() == ctx)
242 SetCurrentContext(NULL);
243 (t->DestroyContext)(dpy, ctx);
248 glXDestroyGLXPixmap(Display *dpy, GLXPixmap pixmap)
250 struct _glxapi_table *t;
251 GET_DISPATCH(dpy, t);
254 (t->DestroyGLXPixmap)(dpy, pixmap);
259 glXGetConfig(Display *dpy, XVisualInfo *visinfo, int attrib, int *value)
261 struct _glxapi_table *t;
262 GET_DISPATCH(dpy, t);
264 return GLX_NO_EXTENSION;
265 return (t->GetConfig)(dpy, visinfo, attrib, value);
270 glXGetCurrentContext(void)
272 #if defined(GLX_USE_TLS)
273 return CurrentContext;
274 #elif defined(THREADS)
275 return (GLXContext) _glthread_GetTSD(&ContextTSD);
277 return CurrentContext;
283 glXGetCurrentDrawable(void)
285 __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();
286 return gc ? gc->currentDrawable : 0;
291 glXIsDirect(Display *dpy, GLXContext ctx)
293 struct _glxapi_table *t;
294 GET_DISPATCH(dpy, t);
297 return (t->IsDirect)(dpy, ctx);
302 glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx)
305 struct _glxapi_table *t;
306 GET_DISPATCH(dpy, t);
310 b = (*t->MakeCurrent)(dpy, drawable, ctx);
312 SetCurrentContext(ctx);
319 glXQueryExtension(Display *dpy, int *errorb, int *event)
321 struct _glxapi_table *t;
322 GET_DISPATCH(dpy, t);
325 return (t->QueryExtension)(dpy, errorb, event);
330 glXQueryVersion(Display *dpy, int *maj, int *min)
332 struct _glxapi_table *t;
333 GET_DISPATCH(dpy, t);
336 return (t->QueryVersion)(dpy, maj, min);
341 glXSwapBuffers(Display *dpy, GLXDrawable drawable)
343 struct _glxapi_table *t;
344 GET_DISPATCH(dpy, t);
347 (t->SwapBuffers)(dpy, drawable);
352 glXUseXFont(Font font, int first, int count, int listBase)
354 struct _glxapi_table *t;
355 Display *dpy = glXGetCurrentDisplay();
356 GET_DISPATCH(dpy, t);
359 (t->UseXFont)(font, first, count, listBase);
366 struct _glxapi_table *t;
367 Display *dpy = glXGetCurrentDisplay();
368 GET_DISPATCH(dpy, t);
378 struct _glxapi_table *t;
379 Display *dpy = glXGetCurrentDisplay();
380 GET_DISPATCH(dpy, t);
388 /*** GLX_VERSION_1_1 ***/
391 glXGetClientString(Display *dpy, int name)
393 struct _glxapi_table *t;
394 GET_DISPATCH(dpy, t);
397 return (t->GetClientString)(dpy, name);
402 glXQueryExtensionsString(Display *dpy, int screen)
404 struct _glxapi_table *t;
405 GET_DISPATCH(dpy, t);
408 return (t->QueryExtensionsString)(dpy, screen);
413 glXQueryServerString(Display *dpy, int screen, int name)
415 struct _glxapi_table *t;
416 GET_DISPATCH(dpy, t);
419 return (t->QueryServerString)(dpy, screen, name);
423 /*** GLX_VERSION_1_2 ***/
426 glXGetCurrentDisplay(void)
428 /* Same code as in libGL's glxext.c */
429 __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();
430 if (NULL == gc) return NULL;
431 return gc->currentDpy;
436 /*** GLX_VERSION_1_3 ***/
439 glXChooseFBConfig(Display *dpy, int screen, const int *attribList, int *nitems)
441 struct _glxapi_table *t;
442 GET_DISPATCH(dpy, t);
445 return (t->ChooseFBConfig)(dpy, screen, attribList, nitems);
450 glXCreateNewContext(Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct)
452 struct _glxapi_table *t;
453 GET_DISPATCH(dpy, t);
456 return (t->CreateNewContext)(dpy, config, renderType, shareList, direct);
461 glXCreatePbuffer(Display *dpy, GLXFBConfig config, const int *attribList)
463 struct _glxapi_table *t;
464 GET_DISPATCH(dpy, t);
467 return (t->CreatePbuffer)(dpy, config, attribList);
472 glXCreatePixmap(Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attribList)
474 struct _glxapi_table *t;
475 GET_DISPATCH(dpy, t);
478 return (t->CreatePixmap)(dpy, config, pixmap, attribList);
483 glXCreateWindow(Display *dpy, GLXFBConfig config, Window win, const int *attribList)
485 struct _glxapi_table *t;
486 GET_DISPATCH(dpy, t);
489 return (t->CreateWindow)(dpy, config, win, attribList);
494 glXDestroyPbuffer(Display *dpy, GLXPbuffer pbuf)
496 struct _glxapi_table *t;
497 GET_DISPATCH(dpy, t);
500 (t->DestroyPbuffer)(dpy, pbuf);
505 glXDestroyPixmap(Display *dpy, GLXPixmap pixmap)
507 struct _glxapi_table *t;
508 GET_DISPATCH(dpy, t);
511 (t->DestroyPixmap)(dpy, pixmap);
516 glXDestroyWindow(Display *dpy, GLXWindow window)
518 struct _glxapi_table *t;
519 GET_DISPATCH(dpy, t);
522 (t->DestroyWindow)(dpy, window);
527 glXGetCurrentReadDrawable(void)
529 __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext();
530 return gc ? gc->currentReadable : 0;
535 glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, int attribute, int *value)
537 struct _glxapi_table *t;
538 GET_DISPATCH(dpy, t);
540 return GLX_NO_EXTENSION;
541 return (t->GetFBConfigAttrib)(dpy, config, attribute, value);
546 glXGetFBConfigs(Display *dpy, int screen, int *nelements)
548 struct _glxapi_table *t;
549 GET_DISPATCH(dpy, t);
552 return (t->GetFBConfigs)(dpy, screen, nelements);
556 glXGetSelectedEvent(Display *dpy, GLXDrawable drawable, unsigned long *mask)
558 struct _glxapi_table *t;
559 GET_DISPATCH(dpy, t);
562 (t->GetSelectedEvent)(dpy, drawable, mask);
567 glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config)
569 struct _glxapi_table *t;
570 GET_DISPATCH(dpy, t);
573 return (t->GetVisualFromFBConfig)(dpy, config);
578 glXMakeContextCurrent(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
581 struct _glxapi_table *t;
582 GET_DISPATCH(dpy, t);
585 b = (t->MakeContextCurrent)(dpy, draw, read, ctx);
587 SetCurrentContext(ctx);
594 glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value)
596 struct _glxapi_table *t;
597 GET_DISPATCH(dpy, t);
600 return 0; /* XXX correct? */
601 return (t->QueryContext)(dpy, ctx, attribute, value);
606 glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value)
608 struct _glxapi_table *t;
609 GET_DISPATCH(dpy, t);
612 (t->QueryDrawable)(dpy, draw, attribute, value);
617 glXSelectEvent(Display *dpy, GLXDrawable drawable, unsigned long mask)
619 struct _glxapi_table *t;
620 GET_DISPATCH(dpy, t);
623 (t->SelectEvent)(dpy, drawable, mask);
628 /*** GLX_SGI_swap_control ***/
631 glXSwapIntervalSGI(int interval)
633 struct _glxapi_table *t;
634 Display *dpy = glXGetCurrentDisplay();
635 GET_DISPATCH(dpy, t);
638 return (t->SwapIntervalSGI)(interval);
643 /*** GLX_SGI_video_sync ***/
646 glXGetVideoSyncSGI(unsigned int *count)
648 struct _glxapi_table *t;
649 Display *dpy = glXGetCurrentDisplay();
650 GET_DISPATCH(dpy, t);
651 if (!t || !glXGetCurrentContext())
652 return GLX_BAD_CONTEXT;
653 return (t->GetVideoSyncSGI)(count);
657 glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
659 struct _glxapi_table *t;
660 Display *dpy = glXGetCurrentDisplay();
661 GET_DISPATCH(dpy, t);
662 if (!t || !glXGetCurrentContext())
663 return GLX_BAD_CONTEXT;
664 return (t->WaitVideoSyncSGI)(divisor, remainder, count);
669 /*** GLX_SGI_make_current_read ***/
672 glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx)
674 struct _glxapi_table *t;
675 GET_DISPATCH(dpy, t);
678 return (t->MakeCurrentReadSGI)(dpy, draw, read, ctx);
682 glXGetCurrentReadDrawableSGI(void)
684 return glXGetCurrentReadDrawable();
690 GLXVideoSourceSGIX PUBLIC
691 glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode)
693 struct _glxapi_table *t;
694 GET_DISPATCH(dpy, t);
697 return (t->CreateGLXVideoSourceSGIX)(dpy, screen, server, path, nodeClass, drainNode);
701 glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src)
703 struct _glxapi_table *t;
704 GET_DISPATCH(dpy, t);
707 return (t->DestroyGLXVideoSourceSGIX)(dpy, src);
713 /*** GLX_EXT_import_context ***/
716 glXFreeContextEXT(Display *dpy, GLXContext context)
718 struct _glxapi_table *t;
719 GET_DISPATCH(dpy, t);
722 (t->FreeContextEXT)(dpy, context);
726 glXGetContextIDEXT(const GLXContext context)
728 return ((__GLXcontext *) context)->xid;
732 glXGetCurrentDisplayEXT(void)
734 return glXGetCurrentDisplay();
738 glXImportContextEXT(Display *dpy, GLXContextID contextID)
740 struct _glxapi_table *t;
741 GET_DISPATCH(dpy, t);
744 return (t->ImportContextEXT)(dpy, contextID);
748 glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute,int *value)
750 struct _glxapi_table *t;
751 GET_DISPATCH(dpy, t);
753 return 0; /* XXX ok? */
754 return (t->QueryContextInfoEXT)(dpy, context, attribute, value);
759 /*** GLX_SGIX_fbconfig ***/
762 glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value)
764 struct _glxapi_table *t;
765 GET_DISPATCH(dpy, t);
768 return (t->GetFBConfigAttribSGIX)(dpy, config, attribute, value);
771 GLXFBConfigSGIX PUBLIC *
772 glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements)
774 struct _glxapi_table *t;
775 GET_DISPATCH(dpy, t);
778 return (t->ChooseFBConfigSGIX)(dpy, screen, attrib_list, nelements);
782 glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap)
784 struct _glxapi_table *t;
785 GET_DISPATCH(dpy, t);
788 return (t->CreateGLXPixmapWithConfigSGIX)(dpy, config, pixmap);
792 glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct)
794 struct _glxapi_table *t;
795 GET_DISPATCH(dpy, t);
798 return (t->CreateContextWithConfigSGIX)(dpy, config, render_type, share_list, direct);
802 glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config)
804 struct _glxapi_table *t;
805 GET_DISPATCH(dpy, t);
808 return (t->GetVisualFromFBConfigSGIX)(dpy, config);
811 GLXFBConfigSGIX PUBLIC
812 glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis)
814 struct _glxapi_table *t;
815 GET_DISPATCH(dpy, t);
818 return (t->GetFBConfigFromVisualSGIX)(dpy, vis);
823 /*** GLX_SGIX_pbuffer ***/
825 GLXPbufferSGIX PUBLIC
826 glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list)
828 struct _glxapi_table *t;
829 GET_DISPATCH(dpy, t);
832 return (t->CreateGLXPbufferSGIX)(dpy, config, width, height, attrib_list);
836 glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf)
838 struct _glxapi_table *t;
839 GET_DISPATCH(dpy, t);
842 (t->DestroyGLXPbufferSGIX)(dpy, pbuf);
846 glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value)
848 struct _glxapi_table *t;
849 GET_DISPATCH(dpy, t);
852 return (t->QueryGLXPbufferSGIX)(dpy, pbuf, attribute, value);
856 glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask)
858 struct _glxapi_table *t;
859 GET_DISPATCH(dpy, t);
862 (t->SelectEventSGIX)(dpy, drawable, mask);
866 glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask)
868 struct _glxapi_table *t;
869 GET_DISPATCH(dpy, t);
872 (t->GetSelectedEventSGIX)(dpy, drawable, mask);
877 /*** GLX_SGI_cushion ***/
880 glXCushionSGI(Display *dpy, Window win, float cushion)
882 struct _glxapi_table *t;
883 GET_DISPATCH(dpy, t);
886 (t->CushionSGI)(dpy, win, cushion);
891 /*** GLX_SGIX_video_resize ***/
894 glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window)
896 struct _glxapi_table *t;
897 GET_DISPATCH(dpy, t);
900 return (t->BindChannelToWindowSGIX)(dpy, screen, channel, window);
904 glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h)
906 struct _glxapi_table *t;
907 GET_DISPATCH(dpy, t);
910 return (t->ChannelRectSGIX)(dpy, screen, channel, x, y, w, h);
914 glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h)
916 struct _glxapi_table *t;
917 GET_DISPATCH(dpy, t);
920 return (t->QueryChannelRectSGIX)(dpy, screen, channel, x, y, w, h);
924 glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh)
926 struct _glxapi_table *t;
927 GET_DISPATCH(dpy, t);
930 return (t->QueryChannelDeltasSGIX)(dpy, screen, channel, dx, dy, dw, dh);
934 glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype)
936 struct _glxapi_table *t;
937 GET_DISPATCH(dpy, t);
940 return (t->ChannelRectSyncSGIX)(dpy, screen, channel, synctype);
945 #if defined(_DM_BUFFER_H_)
948 glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer)
950 struct _glxapi_table *t;
951 GET_DISPATCH(dpy, t);
954 return (t->AssociateDMPbufferSGIX)(dpy, pbuffer, params, dmbuffer);
960 /*** GLX_SGIX_swap_group ***/
963 glXJoinSwapGroupSGIX(Display *dpy, GLXDrawable drawable, GLXDrawable member)
965 struct _glxapi_table *t;
966 GET_DISPATCH(dpy, t);
969 (*t->JoinSwapGroupSGIX)(dpy, drawable, member);
973 /*** GLX_SGIX_swap_barrier ***/
976 glXBindSwapBarrierSGIX(Display *dpy, GLXDrawable drawable, int barrier)
978 struct _glxapi_table *t;
979 GET_DISPATCH(dpy, t);
982 (*t->BindSwapBarrierSGIX)(dpy, drawable, barrier);
986 glXQueryMaxSwapBarriersSGIX(Display *dpy, int screen, int *max)
988 struct _glxapi_table *t;
989 GET_DISPATCH(dpy, t);
992 return (*t->QueryMaxSwapBarriersSGIX)(dpy, screen, max);
997 /*** GLX_SUN_get_transparent_index ***/
1000 glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, long *pTransparent)
1002 struct _glxapi_table *t;
1003 GET_DISPATCH(dpy, t);
1006 return (*t->GetTransparentIndexSUN)(dpy, overlay, underlay, pTransparent);
1011 /*** GLX_MESA_copy_sub_buffer ***/
1014 glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height)
1016 struct _glxapi_table *t;
1017 GET_DISPATCH(dpy, t);
1020 (t->CopySubBufferMESA)(dpy, drawable, x, y, width, height);
1025 /*** GLX_MESA_release_buffers ***/
1028 glXReleaseBuffersMESA(Display *dpy, Window w)
1030 struct _glxapi_table *t;
1031 GET_DISPATCH(dpy, t);
1034 return (t->ReleaseBuffersMESA)(dpy, w);
1039 /*** GLX_MESA_pixmap_colormap ***/
1042 glXCreateGLXPixmapMESA(Display *dpy, XVisualInfo *visinfo, Pixmap pixmap, Colormap cmap)
1044 struct _glxapi_table *t;
1045 GET_DISPATCH(dpy, t);
1048 return (t->CreateGLXPixmapMESA)(dpy, visinfo, pixmap, cmap);
1053 /*** GLX_MESA_set_3dfx_mode ***/
1056 glXSet3DfxModeMESA(int mode)
1058 struct _glxapi_table *t;
1059 Display *dpy = glXGetCurrentDisplay();
1060 GET_DISPATCH(dpy, t);
1063 return (t->Set3DfxModeMESA)(mode);
1068 /*** GLX_NV_vertex_array_range ***/
1071 glXAllocateMemoryNV( GLsizei size,
1072 GLfloat readFrequency,
1073 GLfloat writeFrequency,
1076 struct _glxapi_table *t;
1077 Display *dpy = glXGetCurrentDisplay();
1078 GET_DISPATCH(dpy, t);
1081 return (t->AllocateMemoryNV)(size, readFrequency, writeFrequency, priority);
1086 glXFreeMemoryNV( GLvoid *pointer )
1088 struct _glxapi_table *t;
1089 Display *dpy = glXGetCurrentDisplay();
1090 GET_DISPATCH(dpy, t);
1093 (t->FreeMemoryNV)(pointer);
1099 /*** GLX_MESA_agp_offset */
1102 glXGetAGPOffsetMESA( const GLvoid *pointer )
1104 struct _glxapi_table *t;
1105 Display *dpy = glXGetCurrentDisplay();
1106 GET_DISPATCH(dpy, t);
1109 return (t->GetAGPOffsetMESA)(pointer);
1113 /*** GLX_EXT_texture_from_pixmap */
1116 glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer,
1117 const int *attrib_list)
1119 struct _glxapi_table *t;
1120 GET_DISPATCH(dpy, t);
1122 t->BindTexImageEXT(dpy, drawable, buffer, attrib_list);
1126 glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer)
1128 struct _glxapi_table *t;
1129 GET_DISPATCH(dpy, t);
1131 t->ReleaseTexImageEXT(dpy, drawable, buffer);
1135 /**********************************************************************/
1136 /* GLX API management functions */
1137 /**********************************************************************/
1141 _glxapi_get_version(void)
1148 * Return array of extension strings.
1151 _glxapi_get_extensions(void)
1153 static const char *extensions[] = {
1154 #ifdef GLX_EXT_import_context
1155 "GLX_EXT_import_context",
1157 #ifdef GLX_SGI_video_sync
1158 "GLX_SGI_video_sync",
1160 #ifdef GLX_MESA_copy_sub_buffer
1161 "GLX_MESA_copy_sub_buffer",
1163 #ifdef GLX_MESA_release_buffers
1164 "GLX_MESA_release_buffers",
1166 #ifdef GLX_MESA_pixmap_colormap
1167 "GLX_MESA_pixmap_colormap",
1169 #ifdef GLX_MESA_set_3dfx_mode
1170 "GLX_MESA_set_3dfx_mode",
1172 #ifdef GLX_SGIX_fbconfig
1173 "GLX_SGIX_fbconfig",
1175 #ifdef GLX_SGIX_pbuffer
1178 #ifdef GLX_EXT_texture_from_pixmap
1179 "GLX_EXT_texture_from_pixmap",
1181 #ifdef GLX_INTEL_swap_event
1182 "GLX_INTEL_swap_event",
1191 * Return size of the GLX dispatch table, in entries, not bytes.
1194 _glxapi_get_dispatch_table_size(void)
1196 return sizeof(struct _glxapi_table) / sizeof(void *);
1201 generic_no_op_func(void)
1208 * Initialize all functions in given dispatch table to be no-ops
1211 _glxapi_set_no_op_table(struct _glxapi_table *t)
1213 typedef int (*nop_func)(void);
1214 nop_func *dispatch = (nop_func *) t;
1215 GLuint n = _glxapi_get_dispatch_table_size();
1217 for (i = 0; i < n; i++) {
1218 dispatch[i] = generic_no_op_func;
1223 struct name_address_pair {
1225 __GLXextFuncPtr Address;
1228 static struct name_address_pair GLX_functions[] = {
1229 /*** GLX_VERSION_1_0 ***/
1230 { "glXChooseVisual", (__GLXextFuncPtr) glXChooseVisual },
1231 { "glXCopyContext", (__GLXextFuncPtr) glXCopyContext },
1232 { "glXCreateContext", (__GLXextFuncPtr) glXCreateContext },
1233 { "glXCreateGLXPixmap", (__GLXextFuncPtr) glXCreateGLXPixmap },
1234 { "glXDestroyContext", (__GLXextFuncPtr) glXDestroyContext },
1235 { "glXDestroyGLXPixmap", (__GLXextFuncPtr) glXDestroyGLXPixmap },
1236 { "glXGetConfig", (__GLXextFuncPtr) glXGetConfig },
1237 { "glXGetCurrentContext", (__GLXextFuncPtr) glXGetCurrentContext },
1238 { "glXGetCurrentDrawable", (__GLXextFuncPtr) glXGetCurrentDrawable },
1239 { "glXIsDirect", (__GLXextFuncPtr) glXIsDirect },
1240 { "glXMakeCurrent", (__GLXextFuncPtr) glXMakeCurrent },
1241 { "glXQueryExtension", (__GLXextFuncPtr) glXQueryExtension },
1242 { "glXQueryVersion", (__GLXextFuncPtr) glXQueryVersion },
1243 { "glXSwapBuffers", (__GLXextFuncPtr) glXSwapBuffers },
1244 { "glXUseXFont", (__GLXextFuncPtr) glXUseXFont },
1245 { "glXWaitGL", (__GLXextFuncPtr) glXWaitGL },
1246 { "glXWaitX", (__GLXextFuncPtr) glXWaitX },
1248 /*** GLX_VERSION_1_1 ***/
1249 { "glXGetClientString", (__GLXextFuncPtr) glXGetClientString },
1250 { "glXQueryExtensionsString", (__GLXextFuncPtr) glXQueryExtensionsString },
1251 { "glXQueryServerString", (__GLXextFuncPtr) glXQueryServerString },
1253 /*** GLX_VERSION_1_2 ***/
1254 { "glXGetCurrentDisplay", (__GLXextFuncPtr) glXGetCurrentDisplay },
1256 /*** GLX_VERSION_1_3 ***/
1257 { "glXChooseFBConfig", (__GLXextFuncPtr) glXChooseFBConfig },
1258 { "glXCreateNewContext", (__GLXextFuncPtr) glXCreateNewContext },
1259 { "glXCreatePbuffer", (__GLXextFuncPtr) glXCreatePbuffer },
1260 { "glXCreatePixmap", (__GLXextFuncPtr) glXCreatePixmap },
1261 { "glXCreateWindow", (__GLXextFuncPtr) glXCreateWindow },
1262 { "glXDestroyPbuffer", (__GLXextFuncPtr) glXDestroyPbuffer },
1263 { "glXDestroyPixmap", (__GLXextFuncPtr) glXDestroyPixmap },
1264 { "glXDestroyWindow", (__GLXextFuncPtr) glXDestroyWindow },
1265 { "glXGetCurrentReadDrawable", (__GLXextFuncPtr) glXGetCurrentReadDrawable },
1266 { "glXGetFBConfigAttrib", (__GLXextFuncPtr) glXGetFBConfigAttrib },
1267 { "glXGetFBConfigs", (__GLXextFuncPtr) glXGetFBConfigs },
1268 { "glXGetSelectedEvent", (__GLXextFuncPtr) glXGetSelectedEvent },
1269 { "glXGetVisualFromFBConfig", (__GLXextFuncPtr) glXGetVisualFromFBConfig },
1270 { "glXMakeContextCurrent", (__GLXextFuncPtr) glXMakeContextCurrent },
1271 { "glXQueryContext", (__GLXextFuncPtr) glXQueryContext },
1272 { "glXQueryDrawable", (__GLXextFuncPtr) glXQueryDrawable },
1273 { "glXSelectEvent", (__GLXextFuncPtr) glXSelectEvent },
1275 /*** GLX_VERSION_1_4 ***/
1276 { "glXGetProcAddress", (__GLXextFuncPtr) glXGetProcAddress },
1278 /*** GLX_SGI_swap_control ***/
1279 { "glXSwapIntervalSGI", (__GLXextFuncPtr) glXSwapIntervalSGI },
1281 /*** GLX_SGI_video_sync ***/
1282 { "glXGetVideoSyncSGI", (__GLXextFuncPtr) glXGetVideoSyncSGI },
1283 { "glXWaitVideoSyncSGI", (__GLXextFuncPtr) glXWaitVideoSyncSGI },
1285 /*** GLX_SGI_make_current_read ***/
1286 { "glXMakeCurrentReadSGI", (__GLXextFuncPtr) glXMakeCurrentReadSGI },
1287 { "glXGetCurrentReadDrawableSGI", (__GLXextFuncPtr) glXGetCurrentReadDrawableSGI },
1289 /*** GLX_SGIX_video_source ***/
1291 { "glXCreateGLXVideoSourceSGIX", (__GLXextFuncPtr) glXCreateGLXVideoSourceSGIX },
1292 { "glXDestroyGLXVideoSourceSGIX", (__GLXextFuncPtr) glXDestroyGLXVideoSourceSGIX },
1295 /*** GLX_EXT_import_context ***/
1296 { "glXFreeContextEXT", (__GLXextFuncPtr) glXFreeContextEXT },
1297 { "glXGetContextIDEXT", (__GLXextFuncPtr) glXGetContextIDEXT },
1298 { "glXGetCurrentDisplayEXT", (__GLXextFuncPtr) glXGetCurrentDisplayEXT },
1299 { "glXImportContextEXT", (__GLXextFuncPtr) glXImportContextEXT },
1300 { "glXQueryContextInfoEXT", (__GLXextFuncPtr) glXQueryContextInfoEXT },
1302 /*** GLX_SGIX_fbconfig ***/
1303 { "glXGetFBConfigAttribSGIX", (__GLXextFuncPtr) glXGetFBConfigAttribSGIX },
1304 { "glXChooseFBConfigSGIX", (__GLXextFuncPtr) glXChooseFBConfigSGIX },
1305 { "glXCreateGLXPixmapWithConfigSGIX", (__GLXextFuncPtr) glXCreateGLXPixmapWithConfigSGIX },
1306 { "glXCreateContextWithConfigSGIX", (__GLXextFuncPtr) glXCreateContextWithConfigSGIX },
1307 { "glXGetVisualFromFBConfigSGIX", (__GLXextFuncPtr) glXGetVisualFromFBConfigSGIX },
1308 { "glXGetFBConfigFromVisualSGIX", (__GLXextFuncPtr) glXGetFBConfigFromVisualSGIX },
1310 /*** GLX_SGIX_pbuffer ***/
1311 { "glXCreateGLXPbufferSGIX", (__GLXextFuncPtr) glXCreateGLXPbufferSGIX },
1312 { "glXDestroyGLXPbufferSGIX", (__GLXextFuncPtr) glXDestroyGLXPbufferSGIX },
1313 { "glXQueryGLXPbufferSGIX", (__GLXextFuncPtr) glXQueryGLXPbufferSGIX },
1314 { "glXSelectEventSGIX", (__GLXextFuncPtr) glXSelectEventSGIX },
1315 { "glXGetSelectedEventSGIX", (__GLXextFuncPtr) glXGetSelectedEventSGIX },
1317 /*** GLX_SGI_cushion ***/
1318 { "glXCushionSGI", (__GLXextFuncPtr) glXCushionSGI },
1320 /*** GLX_SGIX_video_resize ***/
1321 { "glXBindChannelToWindowSGIX", (__GLXextFuncPtr) glXBindChannelToWindowSGIX },
1322 { "glXChannelRectSGIX", (__GLXextFuncPtr) glXChannelRectSGIX },
1323 { "glXQueryChannelRectSGIX", (__GLXextFuncPtr) glXQueryChannelRectSGIX },
1324 { "glXQueryChannelDeltasSGIX", (__GLXextFuncPtr) glXQueryChannelDeltasSGIX },
1325 { "glXChannelRectSyncSGIX", (__GLXextFuncPtr) glXChannelRectSyncSGIX },
1327 /*** GLX_SGIX_dmbuffer **/
1328 #if defined(_DM_BUFFER_H_)
1329 { "glXAssociateDMPbufferSGIX", (__GLXextFuncPtr) glXAssociateDMPbufferSGIX },
1332 /*** GLX_SGIX_swap_group ***/
1333 { "glXJoinSwapGroupSGIX", (__GLXextFuncPtr) glXJoinSwapGroupSGIX },
1335 /*** GLX_SGIX_swap_barrier ***/
1336 { "glXBindSwapBarrierSGIX", (__GLXextFuncPtr) glXBindSwapBarrierSGIX },
1337 { "glXQueryMaxSwapBarriersSGIX", (__GLXextFuncPtr) glXQueryMaxSwapBarriersSGIX },
1339 /*** GLX_SUN_get_transparent_index ***/
1340 { "glXGetTransparentIndexSUN", (__GLXextFuncPtr) glXGetTransparentIndexSUN },
1342 /*** GLX_MESA_copy_sub_buffer ***/
1343 { "glXCopySubBufferMESA", (__GLXextFuncPtr) glXCopySubBufferMESA },
1345 /*** GLX_MESA_pixmap_colormap ***/
1346 { "glXCreateGLXPixmapMESA", (__GLXextFuncPtr) glXCreateGLXPixmapMESA },
1348 /*** GLX_MESA_release_buffers ***/
1349 { "glXReleaseBuffersMESA", (__GLXextFuncPtr) glXReleaseBuffersMESA },
1351 /*** GLX_MESA_set_3dfx_mode ***/
1352 { "glXSet3DfxModeMESA", (__GLXextFuncPtr) glXSet3DfxModeMESA },
1354 /*** GLX_ARB_get_proc_address ***/
1355 { "glXGetProcAddressARB", (__GLXextFuncPtr) glXGetProcAddressARB },
1357 /*** GLX_NV_vertex_array_range ***/
1358 { "glXAllocateMemoryNV", (__GLXextFuncPtr) glXAllocateMemoryNV },
1359 { "glXFreeMemoryNV", (__GLXextFuncPtr) glXFreeMemoryNV },
1361 /*** GLX_MESA_agp_offset ***/
1362 { "glXGetAGPOffsetMESA", (__GLXextFuncPtr) glXGetAGPOffsetMESA },
1364 /*** GLX_EXT_texture_from_pixmap ***/
1365 { "glXBindTexImageEXT", (__GLXextFuncPtr) glXBindTexImageEXT },
1366 { "glXReleaseTexImageEXT", (__GLXextFuncPtr) glXReleaseTexImageEXT },
1368 { NULL, NULL } /* end of list */
1374 * Return address of named glX function, or NULL if not found.
1377 _glxapi_get_proc_address(const char *funcName)
1380 for (i = 0; GLX_functions[i].Name; i++) {
1382 /* skip the "m" prefix on the name */
1383 if (strcmp(GLX_functions[i].Name, funcName+1) == 0)
1385 if (strcmp(GLX_functions[i].Name, funcName) == 0)
1387 return GLX_functions[i].Address;
1395 * This function does not get dispatched through the dispatch table
1396 * since it's really a "meta" function.
1398 __GLXextFuncPtr PUBLIC
1399 glXGetProcAddressARB(const GLubyte *procName)
1403 f = _glxapi_get_proc_address((const char *) procName);
1408 f = (__GLXextFuncPtr) _glapi_get_proc_address((const char *) procName);
1415 (*glXGetProcAddress(const GLubyte *procName))()
1417 return glXGetProcAddressARB(procName);