1 /* $Id: glxapi.c,v 1.9 1999/11/28 20:18:50 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * This is the GLX API dispatcher. Calls to the glX* functions are
30 * either routed to real (SGI / Utah) GLX encoders or to Mesa's
41 * XXX - this really shouldn't be here.
42 * Instead, add -DUSE_MESA_GLX to the compiler flags when needed.
44 #define USE_MESA_GLX 1
47 /* Rather than include possibly non-existant headers... */
49 extern struct _glxapi_table
*_sgi_GetGLXDispatchtable(void);
52 extern struct _glxapi_table
*_utah_GetGLXDispatchTable(void);
55 extern struct _glxapi_table
*_mesa_GetGLXDispatchTable(void);
60 struct display_dispatch
{
62 struct _glxapi_table
*Table
;
63 struct display_dispatch
*Next
;
66 static struct display_dispatch
*DispatchList
= NULL
;
69 static struct _glxapi_table
*
70 get_dispatch(Display
*dpy
)
72 static Display
*prevDisplay
= NULL
;
73 static struct _glxapi_table
*prevTable
= NULL
;
78 /* try cached display */
79 if (dpy
== prevDisplay
) {
83 /* search list of display/dispatch pairs for this display */
85 const struct display_dispatch
*d
= DispatchList
;
90 return d
->Table
; /* done! */
96 /* A new display, determine if we should use real GLX (SGI / Utah)
97 * or Mesa's pseudo-GLX.
100 struct _glxapi_table
*t
= NULL
;
102 #if defined(USE_SGI_GLX) || defined(USE_UTAH_GLX)
103 if (!getenv("MESA_FORCE_SOFTX")) {
105 if (XQueryExtension( dpy
, "GLX", &ignore
, &ignore
, &ignore
)) {
106 /* the X server has the GLX extension */
107 #if defined(USE_SGI_GLX)
108 t
= _sgi_GetGLXDispatchtable();
109 #elif defined(USE_UTAH_GLX)
110 t
= _utah_GetGLXDispatchTable();
116 #if defined(USE_MESA_GLX)
118 t
= _mesa_GetGLXDispatchTable();
119 assert(t
); /* this has to work */
124 struct display_dispatch
*d
;
125 d
= (struct display_dispatch
*) malloc(sizeof(struct display_dispatch
));
129 /* insert at head of list */
130 d
->Next
= DispatchList
;
140 /* If we get here that means we can't use real GLX on this display
141 * and the Mesa pseudo-GLX software renderer wasn't compiled in.
142 * Or, we ran out of memory!
149 /* Set by glXMakeCurrent() and glXMakeContextCurrent() only */
150 static Display
*CurrentDisplay
= NULL
;
151 static GLXContext CurrentContext
= 0;
152 static GLXDrawable CurrentDrawable
= 0;
153 static GLXDrawable CurrentReadDrawable
= 0;
158 * GLX API entrypoints
162 XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *list
)
164 struct _glxapi_table
*t
= get_dispatch(dpy
);
167 return (t
->ChooseVisual
)(dpy
, screen
, list
);
171 void glXCopyContext(Display
*dpy
, GLXContext src
, GLXContext dst
, GLuint mask
)
173 struct _glxapi_table
*t
= get_dispatch(dpy
);
176 (t
->CopyContext
)(dpy
, src
, dst
, mask
);
180 GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*visinfo
, GLXContext shareList
, Bool direct
)
182 struct _glxapi_table
*t
= get_dispatch(dpy
);
185 return (t
->CreateContext
)(dpy
, visinfo
, shareList
, direct
);
189 GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
)
191 struct _glxapi_table
*t
= get_dispatch(dpy
);
194 return (t
->CreateGLXPixmap
)(dpy
, visinfo
, pixmap
);
198 void glXDestroyContext(Display
*dpy
, GLXContext ctx
)
200 struct _glxapi_table
*t
= get_dispatch(dpy
);
203 (t
->DestroyContext
)(dpy
, ctx
);
207 void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap pixmap
)
209 struct _glxapi_table
*t
= get_dispatch(dpy
);
212 (t
->DestroyGLXPixmap
)(dpy
, pixmap
);
216 int glXGetConfig(Display
*dpy
, XVisualInfo
*visinfo
, int attrib
, int *value
)
218 struct _glxapi_table
*t
= get_dispatch(dpy
);
220 return GLX_NO_EXTENSION
;
221 return (t
->GetConfig
)(dpy
, visinfo
, attrib
, value
);
225 GLXContext
glXGetCurrentContext(void)
227 return CurrentContext
;
231 GLXDrawable
glXGetCurrentDrawable(void)
233 return CurrentDrawable
;
237 Bool
glXIsDirect(Display
*dpy
, GLXContext ctx
)
239 struct _glxapi_table
*t
= get_dispatch(dpy
);
242 return (t
->IsDirect
)(dpy
, ctx
);
246 Bool
glXMakeCurrent(Display
*dpy
, GLXDrawable drawable
, GLXContext ctx
)
249 struct _glxapi_table
*t
= get_dispatch(dpy
);
252 b
= (*t
->MakeCurrent
)(dpy
, drawable
, ctx
);
254 CurrentDisplay
= dpy
;
255 CurrentContext
= ctx
;
256 CurrentDrawable
= drawable
;
257 CurrentReadDrawable
= drawable
;
263 Bool
glXQueryExtension(Display
*dpy
, int *errorb
, int *event
)
265 struct _glxapi_table
*t
= get_dispatch(dpy
);
268 return (t
->QueryExtension
)(dpy
, errorb
, event
);
272 Bool
glXQueryVersion(Display
*dpy
, int *maj
, int *min
)
274 struct _glxapi_table
*t
= get_dispatch(dpy
);
277 return (t
->QueryVersion
)(dpy
, maj
, min
);
281 void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
283 struct _glxapi_table
*t
= get_dispatch(dpy
);
286 (t
->SwapBuffers
)(dpy
, drawable
);
290 void glXUseXFont(Font font
, int first
, int count
, int listBase
)
292 struct _glxapi_table
*t
= get_dispatch(CurrentDisplay
);
295 (t
->UseXFont
)(font
, first
, count
, listBase
);
301 struct _glxapi_table
*t
= get_dispatch(CurrentDisplay
);
310 struct _glxapi_table
*t
= get_dispatch(CurrentDisplay
);
318 #ifdef _GLXAPI_VERSION_1_1
320 const char *glXGetClientString(Display
*dpy
, int name
)
322 struct _glxapi_table
*t
= get_dispatch(dpy
);
325 return (t
->GetClientString
)(dpy
, name
);
329 const char *glXQueryExtensionsString(Display
*dpy
, int screen
)
331 struct _glxapi_table
*t
= get_dispatch(dpy
);
334 return (t
->QueryExtensionsString
)(dpy
, screen
);
338 const char *glXQueryServerString(Display
*dpy
, int screen
, int name
)
340 struct _glxapi_table
*t
= get_dispatch(dpy
);
343 return (t
->QueryServerString
)(dpy
, screen
, name
);
350 #ifdef _GLXAPI_VERSION_1_2
351 Display
*glXGetCurrentDisplay(void)
353 return CurrentDisplay
;
359 #ifdef _GLXAPI_VERSION_1_3
361 GLXFBConfig
glXChooseFBConfig(Display
*dpy
, int screen
, const int *attribList
, int *nitems
)
363 struct _glxapi_table
*t
= get_dispatch(dpy
);
366 return (t
->ChooseFBConfig
)(dpy
, screen
, attribList
, nitems
);
370 GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
, int renderType
, GLXContext shareList
, Bool direct
)
372 struct _glxapi_table
*t
= get_dispatch(dpy
);
375 return (t
->CreateNewContext
)(dpy
, config
, renderType
, shareList
, direct
);
379 GLXPbuffer
glXCreatePbuffer(Display
*dpy
, GLXFBConfig config
, const int *attribList
)
381 struct _glxapi_table
*t
= get_dispatch(dpy
);
384 return (t
->CreatePbuffer
)(dpy
, config
, attribList
);
388 GLXPixmap
glXCreatePixmap(Display
*dpy
, GLXFBConfig config
, Pixmap pixmap
, const int *attribList
)
390 struct _glxapi_table
*t
= get_dispatch(dpy
);
393 return (t
->CreatePixmap
)(dpy
, config
, pixmap
, attribList
);
397 GLXWindow
glXCreateWindow(Display
*dpy
, GLXFBConfig config
, Window win
, const int *attribList
)
399 struct _glxapi_table
*t
= get_dispatch(dpy
);
402 return (t
->CreateWindow
)(dpy
, config
, win
, attribList
);
406 void glXDestroyPbuffer(Display
*dpy
, GLXPbuffer pbuf
)
408 struct _glxapi_table
*t
= get_dispatch(dpy
);
411 (t
->DestroyPbuffer
)(dpy
, pbuf
);
415 void glXDestroyPixmap(Display
*dpy
, GLXPixmap pixmap
)
417 struct _glxapi_table
*t
= get_dispatch(dpy
);
420 (t
->DestroyPixmap
)(dpy
, pixmap
);
424 void glXDestroyWindow(Display
*dpy
, GLXWindow window
)
426 struct _glxapi_table
*t
= get_dispatch(dpy
);
429 (t
->DestroyWindow
)(dpy
, window
);
433 GLXDrawable
glXGetCurrentReadDrawable(void)
435 return CurrentReadDrawable
;
439 int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
, int attribute
, int *value
)
441 struct _glxapi_table
*t
= get_dispatch(dpy
);
443 return GLX_NO_EXTENSION
;
444 return (t
->GetFBConfigAttrib
)(dpy
, config
, attribute
, value
);
448 void glXGetSelectedEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long *mask
)
450 struct _glxapi_table
*t
= get_dispatch(dpy
);
453 (t
->GetSelectedEvent
)(dpy
, drawable
, mask
);
457 XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
459 struct _glxapi_table
*t
= get_dispatch(dpy
);
462 return (t
->GetVisualFromFBConfig
)(dpy
, config
);
466 Bool
glXMakeContextCurrent(Display
*dpy
, GLXDrawable draw
, GLXDrawable read
, GLXContext ctx
)
468 struct _glxapi_table
*t
= get_dispatch(dpy
);
472 b
= (t
->MakeContextCurrent
)(dpy
, draw
, read
, ctx
);
474 CurrentDisplay
= dpy
;
475 CurrentContext
= ctx
;
476 CurrentDrawable
= draw
;
477 CurrentReadDrawable
= read
;
483 int glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
485 struct _glxapi_table
*t
= get_dispatch(dpy
);
488 return 0; /* XXX correct? */
489 return (t
->QueryContext
)(dpy
, ctx
, attribute
, value
);
493 void glXQueryDrawable(Display
*dpy
, GLXDrawable draw
, int attribute
, unsigned int *value
)
495 struct _glxapi_table
*t
= get_dispatch(dpy
);
498 (t
->QueryDrawable
)(dpy
, draw
, attribute
, value
);
502 void glXSelectEvent(Display
*dpy
, GLXDrawable drawable
, unsigned long mask
)
504 struct _glxapi_table
*t
= get_dispatch(dpy
);
507 (t
->SelectEvent
)(dpy
, drawable
, mask
);
510 #endif /* _GLXAPI_VERSION_1_3 */
513 #ifdef _GLXAPI_EXT_import_context
515 void glXFreeContextEXT(Display
*dpy
, GLXContext context
)
517 struct _glxapi_table
*t
= get_dispatch(dpy
);
520 (t
->FreeContextEXT
)(dpy
, context
);
524 GLXContextID
glXGetContextIDEXT(const GLXContext context
)
526 /* XXX is this function right? */
527 struct _glxapi_table
*t
= get_dispatch(CurrentDisplay
);
530 return (t
->GetContextIDEXT
)(context
);
534 Display
*glXGetCurrentDisplayEXT(void)
536 return CurrentDisplay
;
540 GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
542 struct _glxapi_table
*t
= get_dispatch(dpy
);
545 return (t
->ImportContextEXT
)(dpy
, contextID
);
548 int glXQueryContextInfoEXT(Display
*dpy
, GLXContext context
, int attribute
,int *value
)
550 struct _glxapi_table
*t
= get_dispatch(dpy
);
552 return 0; /* XXX ok? */
553 return (t
->QueryContextInfoEXT
)(dpy
, context
, attribute
, value
);
559 #ifdef _GLXAPI_SGI_video_sync
561 int glXGetVideoSyncSGI(unsigned int *count
)
563 struct _glxapi_table
*t
= get_dispatch(CurrentDisplay
);
566 return (t
->GetVideoSyncSGI
)(count
);
570 int glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
572 struct _glxapi_table
*t
= get_dispatch(CurrentDisplay
);
575 return (t
->WaitVideoSyncSGI
)(divisor
, remainder
, count
);
581 #ifdef _GLXAPI_MESA_copy_sub_buffer
583 void glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
, int x
, int y
, int width
, int height
)
585 struct _glxapi_table
*t
= get_dispatch(dpy
);
588 (t
->CopySubBufferMESA
)(dpy
, drawable
, x
, y
, width
, height
);
594 #ifdef _GLXAPI_MESA_release_buffers
596 Bool
glXReleaseBuffersMESA(Display
*dpy
, Window w
)
598 struct _glxapi_table
*t
= get_dispatch(dpy
);
601 return (t
->ReleaseBuffersMESA
)(dpy
, w
);
607 #ifdef _GLXAPI_MESA_pixmap_colormap
609 GLXPixmap
glXCreateGLXPixmapMESA(Display
*dpy
, XVisualInfo
*visinfo
, Pixmap pixmap
, Colormap cmap
)
611 struct _glxapi_table
*t
= get_dispatch(dpy
);
614 return (t
->CreateGLXPixmapMESA
)(dpy
, visinfo
, pixmap
, cmap
);
620 #ifdef _GLXAPI_MESA_set_3dfx_mode
622 GLboolean
glXSet3DfxModeMESA(GLint mode
)
624 struct _glxapi_table
*t
= get_dispatch(CurrentDisplay
);
627 return (t
->Set3DfxModeMESA
)(mode
);
634 /**********************************************************************/
635 /* GLX API management functions */
636 /**********************************************************************/
640 _glxapi_get_version(void)
647 * Return array of extension strings.
650 _glxapi_get_extensions(void)
652 static const char *extensions
[] = {
653 #ifdef _GLXAPI_EXT_import_context
654 "GLX_EXT_import_context",
656 #ifdef _GLXAPI_SGI_video_sync
657 "GLX_SGI_video_sync",
659 #ifdef _GLXAPI_MESA_copy_sub_buffer
660 "GLX_MESA_copy_sub_buffer",
662 #ifdef _GLXAPI_MESA_release_buffers
663 "GLX_MESA_release_buffers",
665 #ifdef _GLXAPI_MESA_pixmap_colormap
666 "GLX_MESA_pixmap_colormap",
668 #ifdef _GLXAPI_MESA_set_3dfx_mode
669 "GLX_MESA_set_3dfx_mode",
678 * Return size of the GLX dispatch table, in entries, not bytes.
681 _glxapi_get_dispatch_table_size(void)
683 return sizeof(struct _glxapi_table
) / sizeof(void *);
688 generic_no_op_func(void)
695 * Initialize all functions in given dispatch table to be no-ops
698 _glxapi_set_no_op_table(struct _glxapi_table
*t
)
700 GLuint n
= _glxapi_get_dispatch_table_size();
702 void **dispatch
= (void **) t
;
703 for (i
= 0; i
< n
; i
++) {
704 dispatch
[i
] = (void *) generic_no_op_func
;
710 struct name_address_pair
{
715 static struct name_address_pair GLX_functions
[] = {
716 { "glXChooseVisual", (GLvoid
*) glXChooseVisual
},
717 { "glXCopyContext", (GLvoid
*) glXCopyContext
},
718 { "glXCreateContext", (GLvoid
*) glXCreateContext
},
719 { "glXCreateGLXPixmap", (GLvoid
*) glXCreateGLXPixmap
},
720 { "glXDestroyContext", (GLvoid
*) glXDestroyContext
},
721 { "glXDestroyGLXPixmap", (GLvoid
*) glXDestroyGLXPixmap
},
722 { "glXGetConfig", (GLvoid
*) glXGetConfig
},
723 { "glXGetCurrentContext", (GLvoid
*) glXGetCurrentContext
},
724 { "glXGetCurrentDrawable", (GLvoid
*) glXGetCurrentDrawable
},
725 { "glXIsDirect", (GLvoid
*) glXIsDirect
},
726 { "glXMakeCurrent", (GLvoid
*) glXMakeCurrent
},
727 { "glXQueryExtension", (GLvoid
*) glXQueryExtension
},
728 { "glXQueryVersion", (GLvoid
*) glXQueryVersion
},
729 { "glXSwapBuffers", (GLvoid
*) glXSwapBuffers
},
730 { "glXUseXFont", (GLvoid
*) glXUseXFont
},
731 { "glXWaitGL", (GLvoid
*) glXWaitGL
},
732 { "glXWaitX", (GLvoid
*) glXWaitX
},
734 #ifdef _GLXAPI_VERSION_1_1
735 { "glXGetClientString", (GLvoid
*) glXGetClientString
},
736 { "glXQueryExtensionsString", (GLvoid
*) glXQueryExtensionsString
},
737 { "glXQueryServerString", (GLvoid
*) glXQueryServerString
},
740 #ifdef _GLXAPI_VERSION_1_2
741 { "glXGetCurrentDisplay", (GLvoid
*) glXGetCurrentDisplay
},
744 #ifdef _GLXAPI_VERSION_1_3
745 { "glXChooseFBConfig", (GLvoid
*) glXChooseFBConfig
},
746 { "glXCreateNewContext", (GLvoid
*) glXCreateNewContext
},
747 { "glXCreatePbuffer", (GLvoid
*) glXCreatePbuffer
},
748 { "glXCreatePixmap", (GLvoid
*) glXCreatePixmap
},
749 { "glXCreateWindow", (GLvoid
*) glXCreateWindow
},
750 { "glXDestroyPbuffer", (GLvoid
*) glXDestroyPbuffer
},
751 { "glXDestroyPixmap", (GLvoid
*) glXDestroyPixmap
},
752 { "glXDestroyWindow", (GLvoid
*) glXDestroyWindow
},
753 { "glXGetCurrentReadDrawable", (GLvoid
*) glXGetCurrentReadDrawable
},
754 { "glXGetFBConfigAttrib", (GLvoid
*) glXGetFBConfigAttrib
},
755 { "glXGetSelectedEvent", (GLvoid
*) glXGetSelectedEvent
},
756 { "glXGetVisualFromFBConfig", (GLvoid
*) glXGetVisualFromFBConfig
},
757 { "glXMakeContextCurrent", (GLvoid
*) glXMakeContextCurrent
},
758 { "glXQueryContext", (GLvoid
*) glXQueryContext
},
759 { "glXQueryDrawable", (GLvoid
*) glXQueryDrawable
},
760 { "glXSelectEvent", (GLvoid
*) glXSelectEvent
},
763 #ifdef _GLXAPI_SGI_video_sync
764 { "glXGetVideoSyncSGI", (GLvoid
*) glXGetVideoSyncSGI
},
765 { "glXWaitVideoSyncSGI", (GLvoid
*) glXWaitVideoSyncSGI
},
768 #ifdef _GLXAPI_MESA_copy_sub_buffer
769 { "glXCopySubBufferMESA", (GLvoid
*) glXCopySubBufferMESA
},
772 #ifdef _GLXAPI_MESA_release_buffers
773 { "glXReleaseBuffersMESA", (GLvoid
*) glXReleaseBuffersMESA
},
776 #ifdef _GLXAPI_MESA_pixmap_colormap
777 { "glXCreateGLXPixmapMESA", (GLvoid
*) glXCreateGLXPixmapMESA
},
780 #ifdef _GLXAPI_MESA_set_3dfx_mode
781 { "glXSet3DfxModeMESA", (GLvoid
*) glXSet3DfxModeMESA
},
784 { NULL
, NULL
} /* end of list */
790 * Return address of named glX function, or NULL if not found.
793 _glxapi_get_proc_address(const char *funcName
)
796 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
797 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
798 return GLX_functions
[i
].Address
;