2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included 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 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * Client-side GLX interface.
36 #include "glxclient.h"
38 #include "glxextensions.h"
40 #ifdef GLX_DIRECT_RENDERING
41 #ifdef GLX_USE_APPLEGL
42 #include "apple_glx_context.h"
43 #include "apple_glx.h"
44 #include "glx_error.h"
48 #include <X11/extensions/xf86vmode.h>
56 #include <X11/Xlib-xcb.h>
61 static const char __glXGLXClientVendorName[] = "Mesa Project and SGI";
62 static const char __glXGLXClientVersion[] = "1.4";
64 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
66 static Bool windowExistsFlag;
68 windowExistsErrorHandler(Display * dpy, XErrorEvent * xerr)
72 if (xerr->error_code == BadWindow) {
73 windowExistsFlag = GL_FALSE;
79 * Find drawables in the local hash that have been destroyed on the
82 * \param dpy Display to destroy drawables for
83 * \param screen Screen number to destroy drawables for
86 GarbageCollectDRIDrawables(struct glx_screen * sc)
89 __GLXDRIdrawable *pdraw;
90 struct glx_display *priv = sc->display;
91 XWindowAttributes xwa;
92 int (*oldXErrorHandler) (Display *, XErrorEvent *);
94 /* Set no-op error handler so Xlib doesn't bail out if the windows
95 * has alreay been destroyed on the server. */
96 XSync(priv->dpy, GL_FALSE);
97 oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler);
99 if (__glxHashFirst(priv->drawHash, &draw, (void *) &pdraw) == 1) {
101 windowExistsFlag = GL_TRUE;
102 XGetWindowAttributes(priv->dpy, draw, &xwa); /* dummy request */
103 if (!windowExistsFlag) {
104 /* Destroy the local drawable data, if the drawable no
105 longer exists in the Xserver */
106 (*pdraw->destroyDrawable) (pdraw);
107 __glxHashDelete(priv->drawHash, draw);
109 } while (__glxHashNext(priv->drawHash, &draw, (void *) &pdraw) == 1);
112 XSync(priv->dpy, GL_FALSE);
113 XSetErrorHandler(oldXErrorHandler);
117 * Get the __DRIdrawable for the drawable associated with a GLXContext
119 * \param dpy The display associated with \c drawable.
120 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
121 * \param scrn_num If non-NULL, the drawables screen is stored there
122 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
123 * the drawable is not associated with a direct-rendering context.
125 _X_HIDDEN __GLXDRIdrawable *
126 GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable)
128 struct glx_display *priv = __glXInitialize(dpy);
129 __GLXDRIdrawable *pdraw;
134 if (__glxHashLookup(priv->drawHash, drawable, (void *) &pdraw) == 0)
144 * Get the GLX per-screen data structure associated with a GLX context.
146 * \param dpy Display for which the GLX per-screen information is to be
148 * \param scrn Screen on \c dpy for which the GLX per-screen information is
150 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
151 * specify a valid GLX screen, or NULL otherwise.
153 * \todo Should this function validate that \c scrn is within the screen
154 * number range for \c dpy?
157 static struct glx_screen *
158 GetGLXScreenConfigs(Display * dpy, int scrn)
160 struct glx_display *const priv = __glXInitialize(dpy);
164 NULL) ? priv->screens[scrn] : NULL;
169 GetGLXPrivScreenConfig(Display * dpy, int scrn, struct glx_display ** ppriv,
170 struct glx_screen ** ppsc)
172 /* Initialize the extension, if needed . This has the added value
173 * of initializing/allocating the display private
177 return GLX_NO_EXTENSION;
180 *ppriv = __glXInitialize(dpy);
181 if (*ppriv == NULL) {
182 return GLX_NO_EXTENSION;
185 /* Check screen number to see if its valid */
186 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
187 return GLX_BAD_SCREEN;
190 /* Check to see if the GL is supported on this screen */
191 *ppsc = (*ppriv)->screens[scrn];
192 if ((*ppsc)->configs == NULL) {
193 /* No support for GL on this screen regardless of visual */
194 return GLX_BAD_VISUAL;
202 * Determine if a \c GLXFBConfig supplied by the application is valid.
204 * \param dpy Application supplied \c Display pointer.
205 * \param config Application supplied \c GLXFBConfig.
207 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
208 * \c struct glx_config structure is returned. Otherwise, \c NULL
211 static struct glx_config *
212 ValidateGLXFBConfig(Display * dpy, GLXFBConfig fbconfig)
214 struct glx_display *const priv = __glXInitialize(dpy);
215 int num_screens = ScreenCount(dpy);
217 struct glx_config *config;
220 for (i = 0; i < num_screens; i++) {
221 for (config = priv->screens[i]->configs; config != NULL;
222 config = config->next) {
223 if (config == (struct glx_config *) fbconfig) {
234 glx_context_init(struct glx_context *gc,
235 struct glx_screen *psc, struct glx_config *config)
237 gc->majorOpcode = __glXSetupForCommand(psc->display->dpy);
238 if (!gc->majorOpcode)
241 gc->screen = psc->scr;
244 gc->isDirect = GL_TRUE;
245 gc->currentContextTag = -1;
252 * Create a new context. Exactly one of \c vis and \c fbconfig should be
255 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
256 * SGIX_fbconfig protocol be used?
257 * \param renderType For FBConfigs, what is the rendering type?
261 CreateContext(Display * dpy, int generic_id,
262 struct glx_config *config,
263 GLXContext shareList_user,
265 unsigned code, int renderType, int screen)
267 struct glx_context *gc = NULL;
268 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, screen);
269 struct glx_context *shareList = (struct glx_context *) shareList_user;
273 if (generic_id == None)
277 if (allowDirect && psc->vtable->create_context)
278 gc = psc->vtable->create_context(psc, config, shareList, renderType);
280 gc = indirect_create_context(psc, config, shareList, renderType);
286 case X_GLXCreateContext: {
287 xGLXCreateContextReq *req;
289 /* Send the glXCreateContext request */
290 GetReq(GLXCreateContext, req);
291 req->reqType = gc->majorOpcode;
292 req->glxCode = X_GLXCreateContext;
293 req->context = gc->xid = XAllocID(dpy);
294 req->visual = generic_id;
295 req->screen = screen;
296 req->shareList = shareList ? shareList->xid : None;
297 req->isDirect = gc->isDirect;
301 case X_GLXCreateNewContext: {
302 xGLXCreateNewContextReq *req;
304 /* Send the glXCreateNewContext request */
305 GetReq(GLXCreateNewContext, req);
306 req->reqType = gc->majorOpcode;
307 req->glxCode = X_GLXCreateNewContext;
308 req->context = gc->xid = XAllocID(dpy);
309 req->fbconfig = generic_id;
310 req->screen = screen;
311 req->renderType = renderType;
312 req->shareList = shareList ? shareList->xid : None;
313 req->isDirect = gc->isDirect;
317 case X_GLXvop_CreateContextWithConfigSGIX: {
318 xGLXVendorPrivateWithReplyReq *vpreq;
319 xGLXCreateContextWithConfigSGIXReq *req;
321 /* Send the glXCreateNewContext request */
322 GetReqExtra(GLXVendorPrivateWithReply,
323 sz_xGLXCreateContextWithConfigSGIXReq -
324 sz_xGLXVendorPrivateWithReplyReq, vpreq);
325 req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
326 req->reqType = gc->majorOpcode;
327 req->glxCode = X_GLXVendorPrivateWithReply;
328 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
329 req->context = gc->xid = XAllocID(dpy);
330 req->fbconfig = generic_id;
331 req->screen = screen;
332 req->renderType = renderType;
333 req->shareList = shareList ? shareList->xid : None;
334 req->isDirect = gc->isDirect;
339 /* What to do here? This case is the sign of an internal error. It
340 * should never be reachable.
348 gc->imported = GL_FALSE;
349 gc->renderType = renderType;
351 return (GLXContext) gc;
355 glXCreateContext(Display * dpy, XVisualInfo * vis,
356 GLXContext shareList, Bool allowDirect)
358 struct glx_config *config = NULL;
361 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
362 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, vis->screen);
364 config = glx_config_find_visual(psc->visuals, vis->visualid);
365 if (config == NULL) {
368 error.errorCode = BadValue;
369 error.resourceID = vis->visualid;
370 error.sequenceNumber = dpy->request;
371 error.type = X_Error;
372 error.majorCode = __glXSetupForCommand(dpy);
373 error.minorCode = X_GLXCreateContext;
374 _XError(dpy, &error);
378 renderType = config->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE;
381 return CreateContext(dpy, vis->visualid, config, shareList, allowDirect,
382 X_GLXCreateContext, renderType, vis->screen);
386 glx_send_destroy_context(Display *dpy, XID xid)
388 CARD8 opcode = __glXSetupForCommand(dpy);
389 xGLXDestroyContextReq *req;
392 GetReq(GLXDestroyContext, req);
393 req->reqType = opcode;
394 req->glxCode = X_GLXDestroyContext;
401 ** Destroy the named context
404 DestroyContext(Display * dpy, GLXContext ctx)
406 struct glx_context *gc = (struct glx_context *) ctx;
412 if (gc->currentDpy) {
413 /* This context is bound to some thread. According to the man page,
414 * we should not actually delete the context until it's unbound.
415 * Note that we set gc->xid = None above. In MakeContextCurrent()
416 * we check for that and delete the context there.
419 glx_send_destroy_context(dpy, gc->xid);
426 if (gc->vtable->destroy)
427 gc->vtable->destroy(gc);
431 glXDestroyContext(Display * dpy, GLXContext gc)
433 DestroyContext(dpy, gc);
437 ** Return the major and minor version #s for the GLX extension
440 glXQueryVersion(Display * dpy, int *major, int *minor)
442 struct glx_display *priv;
444 /* Init the extension. This fetches the major and minor version. */
445 priv = __glXInitialize(dpy);
450 *major = priv->majorVersion;
452 *minor = priv->minorVersion;
457 ** Query the existance of the GLX extension
460 glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
462 int major_op, erb, evb;
465 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
476 ** Put a barrier in the token stream that forces the GL to finish its
477 ** work before X can proceed.
482 struct glx_context *gc = __glXGetCurrentContext();
484 if (gc && gc->vtable && gc->vtable->wait_gl)
485 gc->vtable->wait_gl(gc);
489 ** Put a barrier in the token stream that forces X to finish its
490 ** work before GL can proceed.
495 struct glx_context *gc = __glXGetCurrentContext();
497 if (gc && gc->vtable && gc->vtable->wait_x)
498 gc->vtable->wait_x(gc);
502 glXUseXFont(Font font, int first, int count, int listBase)
504 struct glx_context *gc = __glXGetCurrentContext();
506 if (gc && gc->vtable && gc->vtable->use_x_font)
507 gc->vtable->use_x_font(gc, font, first, count, listBase);
510 /************************************************************************/
513 ** Copy the source context to the destination context using the
517 glXCopyContext(Display * dpy, GLXContext source_user,
518 GLXContext dest_user, unsigned long mask)
520 struct glx_context *source = (struct glx_context *) source_user;
521 struct glx_context *dest = (struct glx_context *) dest_user;
522 #ifdef GLX_USE_APPLEGL
523 struct glx_context *gc = __glXGetCurrentContext();
527 if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
528 mask, &errorcode, &x11error)) {
529 __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
533 xGLXCopyContextReq *req;
534 struct glx_context *gc = __glXGetCurrentContext();
538 opcode = __glXSetupForCommand(dpy);
543 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
545 /* NOT_DONE: This does not work yet */
550 ** If the source is the current context, send its tag so that the context
551 ** can be flushed before the copy.
553 if (source == gc && dpy == gc->currentDpy) {
554 tag = gc->currentContextTag;
560 /* Send the glXCopyContext request */
562 GetReq(GLXCopyContext, req);
563 req->reqType = opcode;
564 req->glxCode = X_GLXCopyContext;
565 req->source = source ? source->xid : None;
566 req->dest = dest ? dest->xid : None;
568 req->contextTag = tag;
571 #endif /* GLX_USE_APPLEGL */
576 * Determine if a context uses direct rendering.
578 * \param dpy Display where the context was created.
579 * \param contextID ID of the context to be tested.
581 * \returns \c GL_TRUE if the context is direct rendering or not.
584 __glXIsDirect(Display * dpy, GLXContextID contextID)
586 #if !defined(USE_XCB)
587 xGLXIsDirectReq *req;
588 xGLXIsDirectReply reply;
592 opcode = __glXSetupForCommand(dpy);
598 xcb_connection_t *c = XGetXCBConnection(dpy);
599 xcb_glx_is_direct_reply_t *reply = xcb_glx_is_direct_reply(c,
604 const Bool is_direct = reply->is_direct ? True : False;
609 /* Send the glXIsDirect request */
611 GetReq(GLXIsDirect, req);
612 req->reqType = opcode;
613 req->glxCode = X_GLXIsDirect;
614 req->context = contextID;
615 _XReply(dpy, (xReply *) & reply, 0, False);
619 return reply.isDirect;
625 * Shouldn't this function \b always return \c GL_FALSE when
626 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
627 * the GLX protocol here at all?
630 glXIsDirect(Display * dpy, GLXContext gc_user)
632 struct glx_context *gc = (struct glx_context *) gc_user;
637 else if (gc->isDirect) {
640 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
643 return __glXIsDirect(dpy, gc->xid);
648 glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
650 #ifdef GLX_USE_APPLEGL
651 int screen = vis->screen;
652 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, screen);
653 const struct glx_config *config;
655 config = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
657 if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, config))
662 xGLXCreateGLXPixmapReq *req;
666 opcode = __glXSetupForCommand(dpy);
671 /* Send the glXCreateGLXPixmap request */
673 GetReq(GLXCreateGLXPixmap, req);
674 req->reqType = opcode;
675 req->glxCode = X_GLXCreateGLXPixmap;
676 req->screen = vis->screen;
677 req->visual = vis->visualid;
678 req->pixmap = pixmap;
679 req->glxpixmap = xid = XAllocID(dpy);
683 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
685 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
686 * is actually bound to a context... */
688 struct glx_display *const priv = __glXInitialize(dpy);
689 __GLXDRIdrawable *pdraw;
690 struct glx_screen *psc;
691 struct glx_config *config;
693 psc = priv->screens[vis->screen];
694 if (psc->driScreen == NULL)
696 config = glx_config_find_visual(psc->visuals, vis->visualid);
697 pdraw = psc->driScreen->createDrawable(psc, pixmap, req->glxpixmap, config);
699 fprintf(stderr, "failed to create pixmap\n");
703 if (__glxHashInsert(priv->drawHash, req->glxpixmap, pdraw)) {
704 (*pdraw->destroyDrawable) (pdraw);
705 return None; /* FIXME: Check what we're supposed to do here... */
715 ** Destroy the named pixmap
718 glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
720 #ifdef GLX_USE_APPLEGL
721 if(apple_glx_pixmap_destroy(dpy, glxpixmap))
722 __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
724 xGLXDestroyGLXPixmapReq *req;
727 opcode = __glXSetupForCommand(dpy);
732 /* Send the glXDestroyGLXPixmap request */
734 GetReq(GLXDestroyGLXPixmap, req);
735 req->reqType = opcode;
736 req->glxCode = X_GLXDestroyGLXPixmap;
737 req->glxpixmap = glxpixmap;
741 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
743 struct glx_display *const priv = __glXInitialize(dpy);
744 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
747 (*pdraw->destroyDrawable) (pdraw);
748 __glxHashDelete(priv->drawHash, glxpixmap);
752 #endif /* GLX_USE_APPLEGL */
756 glXSwapBuffers(Display * dpy, GLXDrawable drawable)
758 #ifdef GLX_USE_APPLEGL
759 GLXContext gc = glXGetCurrentContext();
760 if(gc && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
761 apple_glx_swap_buffers(gc->driContext);
763 __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
766 struct glx_context *gc;
772 xGLXSwapBuffersReq *req;
775 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
776 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
780 (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0);
785 opcode = __glXSetupForCommand(dpy);
791 ** The calling thread may or may not have a current context. If it
792 ** does, send the context tag so the server can do a flush.
794 gc = __glXGetCurrentContext();
795 if ((gc != NULL) && (dpy == gc->currentDpy) &&
796 ((drawable == gc->currentDrawable)
797 || (drawable == gc->currentReadable))) {
798 tag = gc->currentContextTag;
805 c = XGetXCBConnection(dpy);
806 xcb_glx_swap_buffers(c, tag, drawable);
809 /* Send the glXSwapBuffers request */
811 GetReq(GLXSwapBuffers, req);
812 req->reqType = opcode;
813 req->glxCode = X_GLXSwapBuffers;
814 req->drawable = drawable;
815 req->contextTag = tag;
820 #endif /* GLX_USE_APPLEGL */
825 ** Return configuration information for the given display, screen and
826 ** visual combination.
829 glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
832 struct glx_display *priv;
833 struct glx_screen *psc;
834 struct glx_config *config;
837 status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
838 if (status == Success) {
839 config = glx_config_find_visual(psc->visuals, vis->visualid);
841 /* Lookup attribute after first finding a match on the visual */
842 if (config != NULL) {
843 return glx_config_get(config, attribute, value_return);
846 status = GLX_BAD_VISUAL;
850 ** If we can't find the config for this visual, this visual is not
851 ** supported by the OpenGL implementation on the server.
853 if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
854 *value_return = GL_FALSE;
861 /************************************************************************/
864 init_fbconfig_for_chooser(struct glx_config * config,
865 GLboolean fbconfig_style_tags)
867 memset(config, 0, sizeof(struct glx_config));
868 config->visualID = (XID) GLX_DONT_CARE;
869 config->visualType = GLX_DONT_CARE;
871 /* glXChooseFBConfig specifies different defaults for these two than
874 if (fbconfig_style_tags) {
875 config->rgbMode = GL_TRUE;
876 config->doubleBufferMode = GLX_DONT_CARE;
879 config->visualRating = GLX_DONT_CARE;
880 config->transparentPixel = GLX_NONE;
881 config->transparentRed = GLX_DONT_CARE;
882 config->transparentGreen = GLX_DONT_CARE;
883 config->transparentBlue = GLX_DONT_CARE;
884 config->transparentAlpha = GLX_DONT_CARE;
885 config->transparentIndex = GLX_DONT_CARE;
887 config->drawableType = GLX_WINDOW_BIT;
889 (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
890 config->xRenderable = GLX_DONT_CARE;
891 config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
893 config->swapMethod = GLX_DONT_CARE;
896 #define MATCH_DONT_CARE( param ) \
898 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
899 && (a-> param != b-> param) ) { \
904 #define MATCH_MINIMUM( param ) \
906 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
907 && (a-> param > b-> param) ) { \
912 #define MATCH_EXACT( param ) \
914 if ( a-> param != b-> param) { \
919 /* Test that all bits from a are contained in b */
920 #define MATCH_MASK(param) \
922 if ((a->param & ~b->param) != 0) \
927 * Determine if two GLXFBConfigs are compatible.
929 * \param a Application specified config to test.
930 * \param b Server specified config to test against \c a.
933 fbconfigs_compatible(const struct glx_config * const a,
934 const struct glx_config * const b)
936 MATCH_DONT_CARE(doubleBufferMode);
937 MATCH_DONT_CARE(visualType);
938 MATCH_DONT_CARE(visualRating);
939 MATCH_DONT_CARE(xRenderable);
940 MATCH_DONT_CARE(fbconfigID);
941 MATCH_DONT_CARE(swapMethod);
943 MATCH_MINIMUM(rgbBits);
944 MATCH_MINIMUM(numAuxBuffers);
945 MATCH_MINIMUM(redBits);
946 MATCH_MINIMUM(greenBits);
947 MATCH_MINIMUM(blueBits);
948 MATCH_MINIMUM(alphaBits);
949 MATCH_MINIMUM(depthBits);
950 MATCH_MINIMUM(stencilBits);
951 MATCH_MINIMUM(accumRedBits);
952 MATCH_MINIMUM(accumGreenBits);
953 MATCH_MINIMUM(accumBlueBits);
954 MATCH_MINIMUM(accumAlphaBits);
955 MATCH_MINIMUM(sampleBuffers);
956 MATCH_MINIMUM(maxPbufferWidth);
957 MATCH_MINIMUM(maxPbufferHeight);
958 MATCH_MINIMUM(maxPbufferPixels);
959 MATCH_MINIMUM(samples);
961 MATCH_DONT_CARE(stereoMode);
964 MATCH_MASK(drawableType);
965 MATCH_MASK(renderType);
967 /* There is a bug in a few of the XFree86 DDX drivers. They contain
968 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
969 * Technically speaking, it is a bug in the DDX driver, but there is
970 * enough of an installed base to work around the problem here. In any
971 * case, 0 is not a valid value of the transparent type, so we'll treat 0
972 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
973 * 0 from the server to be a match to maintain backward compatibility with
974 * the (broken) drivers.
977 if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) {
978 if (a->transparentPixel == GLX_NONE) {
979 if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0)
983 MATCH_EXACT(transparentPixel);
986 switch (a->transparentPixel) {
987 case GLX_TRANSPARENT_RGB:
988 MATCH_DONT_CARE(transparentRed);
989 MATCH_DONT_CARE(transparentGreen);
990 MATCH_DONT_CARE(transparentBlue);
991 MATCH_DONT_CARE(transparentAlpha);
994 case GLX_TRANSPARENT_INDEX:
995 MATCH_DONT_CARE(transparentIndex);
1007 /* There's some trickly language in the GLX spec about how this is supposed
1008 * to work. Basically, if a given component size is either not specified
1009 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1010 * Well, that's really hard to do with the code as-is. This behavior is
1011 * closer to correct, but still not technically right.
1013 #define PREFER_LARGER_OR_ZERO(comp) \
1015 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1016 if ( ((*a)-> comp) == 0 ) { \
1019 else if ( ((*b)-> comp) == 0 ) { \
1023 return ((*b)-> comp) - ((*a)-> comp) ; \
1028 #define PREFER_LARGER(comp) \
1030 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1031 return ((*b)-> comp) - ((*a)-> comp) ; \
1035 #define PREFER_SMALLER(comp) \
1037 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1038 return ((*a)-> comp) - ((*b)-> comp) ; \
1043 * Compare two GLXFBConfigs. This function is intended to be used as the
1044 * compare function passed in to qsort.
1046 * \returns If \c a is a "better" config, according to the specification of
1047 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1048 * better, then a number greater than zero is return. If both are
1049 * equal, zero is returned.
1050 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1053 fbconfig_compare(struct glx_config **a, struct glx_config **b)
1055 /* The order of these comparisons must NOT change. It is defined by
1056 * the GLX 1.3 spec and ARB_multisample.
1059 PREFER_SMALLER(visualSelectGroup);
1061 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1062 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1063 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1065 PREFER_SMALLER(visualRating);
1067 /* This isn't quite right. It is supposed to compare the sum of the
1068 * components the user specifically set minimums for.
1070 PREFER_LARGER_OR_ZERO(redBits);
1071 PREFER_LARGER_OR_ZERO(greenBits);
1072 PREFER_LARGER_OR_ZERO(blueBits);
1073 PREFER_LARGER_OR_ZERO(alphaBits);
1075 PREFER_SMALLER(rgbBits);
1077 if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) {
1078 /* Prefer single-buffer.
1080 return (!(*a)->doubleBufferMode) ? -1 : 1;
1083 PREFER_SMALLER(numAuxBuffers);
1085 PREFER_LARGER_OR_ZERO(depthBits);
1086 PREFER_SMALLER(stencilBits);
1088 /* This isn't quite right. It is supposed to compare the sum of the
1089 * components the user specifically set minimums for.
1091 PREFER_LARGER_OR_ZERO(accumRedBits);
1092 PREFER_LARGER_OR_ZERO(accumGreenBits);
1093 PREFER_LARGER_OR_ZERO(accumBlueBits);
1094 PREFER_LARGER_OR_ZERO(accumAlphaBits);
1096 PREFER_SMALLER(visualType);
1098 /* None of the multisample specs say where this comparison should happen,
1099 * so I put it near the end.
1101 PREFER_SMALLER(sampleBuffers);
1102 PREFER_SMALLER(samples);
1104 /* None of the pbuffer or fbconfig specs say that this comparison needs
1105 * to happen at all, but it seems like it should.
1107 PREFER_LARGER(maxPbufferWidth);
1108 PREFER_LARGER(maxPbufferHeight);
1109 PREFER_LARGER(maxPbufferPixels);
1116 * Selects and sorts a subset of the supplied configs based on the attributes.
1117 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1118 * and \c glXChooseFBConfigSGIX.
1120 * \param configs Array of pointers to possible configs. The elements of
1121 * this array that do not meet the criteria will be set to
1122 * NULL. The remaining elements will be sorted according to
1123 * the various visual / FBConfig selection rules.
1124 * \param num_configs Number of elements in the \c configs array.
1125 * \param attribList Attributes used select from \c configs. This array is
1126 * terminated by a \c None tag. The array can either take
1127 * the form expected by \c glXChooseVisual (where boolean
1128 * tags do not have a value) or by \c glXChooseFBConfig
1129 * (where every tag has a value).
1130 * \param fbconfig_style_tags Selects whether \c attribList is in
1131 * \c glXChooseVisual style or
1132 * \c glXChooseFBConfig style.
1133 * \returns The number of valid elements left in \c configs.
1135 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1138 choose_visual(struct glx_config ** configs, int num_configs,
1139 const int *attribList, GLboolean fbconfig_style_tags)
1141 struct glx_config test_config;
1145 /* This is a fairly direct implementation of the selection method
1146 * described by GLX_SGIX_fbconfig. Start by culling out all the
1147 * configs that are not compatible with the selected parameter
1151 init_fbconfig_for_chooser(&test_config, fbconfig_style_tags);
1152 __glXInitializeVisualConfigFromTags(&test_config, 512,
1153 (const INT32 *) attribList,
1154 GL_TRUE, fbconfig_style_tags);
1157 for (i = 0; i < num_configs; i++) {
1158 if (fbconfigs_compatible(&test_config, configs[i])) {
1159 configs[base] = configs[i];
1168 if (base < num_configs) {
1169 (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base));
1172 /* After the incompatible configs are removed, the resulting
1173 * list is sorted according to the rules set out in the various
1177 qsort(configs, base, sizeof(struct glx_config *),
1178 (int (*)(const void *, const void *)) fbconfig_compare);
1186 ** Return the visual that best matches the template. Return None if no
1187 ** visual matches the template.
1189 _X_EXPORT XVisualInfo *
1190 glXChooseVisual(Display * dpy, int screen, int *attribList)
1192 XVisualInfo *visualList = NULL;
1193 struct glx_display *priv;
1194 struct glx_screen *psc;
1195 struct glx_config test_config;
1196 struct glx_config *config;
1197 struct glx_config *best_config = NULL;
1200 ** Get a list of all visuals, return if list is empty
1202 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1208 ** Build a template from the defaults and the attribute list
1209 ** Free visual list and return if an unexpected token is encountered
1211 init_fbconfig_for_chooser(&test_config, GL_FALSE);
1212 __glXInitializeVisualConfigFromTags(&test_config, 512,
1213 (const INT32 *) attribList,
1217 ** Eliminate visuals that don't meet minimum requirements
1218 ** Compute a score for those that do
1219 ** Remember which visual, if any, got the highest score
1220 ** If no visual is acceptable, return None
1221 ** Otherwise, create an XVisualInfo list with just the selected X visual
1224 for (config = psc->visuals; config != NULL; config = config->next) {
1225 if (fbconfigs_compatible(&test_config, config)
1226 && ((best_config == NULL) ||
1227 (fbconfig_compare (&config, &best_config) < 0))) {
1228 XVisualInfo visualTemplate;
1229 XVisualInfo *newList;
1232 visualTemplate.screen = screen;
1233 visualTemplate.visualid = config->visualID;
1234 newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask,
1235 &visualTemplate, &i);
1239 visualList = newList;
1240 best_config = config;
1245 #ifdef GLX_USE_APPLEGL
1246 if(visualList && getenv("LIBGL_DUMP_VISUALID")) {
1247 printf("visualid 0x%lx\n", visualList[0].visualid);
1255 _X_EXPORT const char *
1256 glXQueryExtensionsString(Display * dpy, int screen)
1258 struct glx_screen *psc;
1259 struct glx_display *priv;
1261 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1265 if (!psc->effectiveGLXexts) {
1266 if (!psc->serverGLXexts) {
1267 psc->serverGLXexts =
1268 __glXQueryServerString(dpy, priv->majorOpcode, screen,
1272 __glXCalculateUsableExtensions(psc,
1273 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1274 (psc->driScreen != NULL),
1278 priv->minorVersion);
1281 return psc->effectiveGLXexts;
1284 _X_EXPORT const char *
1285 glXGetClientString(Display * dpy, int name)
1291 return (__glXGLXClientVendorName);
1293 return (__glXGLXClientVersion);
1294 case GLX_EXTENSIONS:
1295 return (__glXGetClientExtensions());
1301 _X_EXPORT const char *
1302 glXQueryServerString(Display * dpy, int screen, int name)
1304 struct glx_screen *psc;
1305 struct glx_display *priv;
1309 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1315 str = &priv->serverGLXvendor;
1318 str = &priv->serverGLXversion;
1320 case GLX_EXTENSIONS:
1321 str = &psc->serverGLXexts;
1328 *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name);
1335 __glXClientInfo(Display * dpy, int opcode)
1337 char *ext_str = __glXGetClientGLExtensionString();
1338 int size = strlen(ext_str) + 1;
1341 xcb_connection_t *c = XGetXCBConnection(dpy);
1342 xcb_glx_client_info(c,
1343 GLX_MAJOR_VERSION, GLX_MINOR_VERSION, size, ext_str);
1345 xGLXClientInfoReq *req;
1347 /* Send the glXClientInfo request */
1349 GetReq(GLXClientInfo, req);
1350 req->reqType = opcode;
1351 req->glxCode = X_GLXClientInfo;
1352 req->major = GLX_MAJOR_VERSION;
1353 req->minor = GLX_MINOR_VERSION;
1355 req->length += (size + 3) >> 2;
1356 req->numbytes = size;
1357 Data(dpy, ext_str, size);
1361 #endif /* USE_XCB */
1368 ** EXT_import_context
1372 glXGetCurrentDisplay(void)
1374 struct glx_context *gc = __glXGetCurrentContext();
1377 return gc->currentDpy;
1381 GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1382 glXGetCurrentDisplay)
1384 #ifndef GLX_USE_APPLEGL
1385 _X_EXPORT GLXContext
1386 glXImportContextEXT(Display *dpy, GLXContextID contextID)
1388 struct glx_display *priv = __glXInitialize(dpy);
1389 struct glx_screen *psc;
1390 xGLXQueryContextReply reply;
1392 struct glx_context *ctx;
1393 int propList[__GLX_MAX_CONTEXT_PROPS * 2], *pProp, nPropListBytes;
1396 struct glx_config *mode;
1398 if (contextID == None || __glXIsDirect(dpy, contextID))
1401 opcode = __glXSetupForCommand(dpy);
1405 /* Send the glXQueryContextInfoEXT request */
1408 if (priv->majorVersion > 1 || priv->minorVersion >= 3) {
1409 xGLXQueryContextReq *req;
1411 GetReq(GLXQueryContext, req);
1413 req->reqType = opcode;
1414 req->glxCode = X_GLXQueryContext;
1415 req->context = contextID;
1418 xGLXVendorPrivateReq *vpreq;
1419 xGLXQueryContextInfoEXTReq *req;
1421 GetReqExtra(GLXVendorPrivate,
1422 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1424 req = (xGLXQueryContextInfoEXTReq *) vpreq;
1425 req->reqType = opcode;
1426 req->glxCode = X_GLXVendorPrivateWithReply;
1427 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1428 req->context = contextID;
1431 _XReply(dpy, (xReply *) & reply, 0, False);
1433 if (reply.n <= __GLX_MAX_CONTEXT_PROPS)
1434 nPropListBytes = reply.n * 2 * sizeof propList[0];
1437 _XRead(dpy, (char *) propList, nPropListBytes);
1441 /* Look up screen first so we can look up visuals/fbconfigs later */
1443 for (i = 0, pProp = propList; i < reply.n; i++, pProp += 2)
1444 if (pProp[0] == GLX_SCREEN)
1445 psc = GetGLXScreenConfigs(dpy, pProp[1]);
1454 for (i = 0, pProp = propList; i < reply.n; i++, pProp += 2)
1456 case GLX_SHARE_CONTEXT_EXT:
1459 case GLX_VISUAL_ID_EXT:
1460 mode = glx_config_find_visual(psc->visuals, pProp[1]);
1462 case GLX_FBCONFIG_ID:
1463 mode = glx_config_find_fbconfig(psc->configs, pProp[1]);
1465 case GLX_RENDER_TYPE:
1466 renderType = pProp[1];
1473 ctx = indirect_create_context(psc, mode, NULL, renderType);
1477 ctx->xid = contextID;
1478 ctx->imported = GL_TRUE;
1479 ctx->share_xid = share;
1481 return (GLXContext) ctx;
1487 glXQueryContext(Display * dpy, GLXContext ctx_user, int attribute, int *value)
1489 struct glx_context *ctx = (struct glx_context *) ctx_user;
1491 switch (attribute) {
1492 case GLX_SHARE_CONTEXT_EXT:
1493 *value = ctx->share_xid;
1495 case GLX_VISUAL_ID_EXT:
1496 *value = ctx->config ? ctx->config->visualID : None;
1499 *value = ctx->screen;
1501 case GLX_FBCONFIG_ID:
1502 *value = ctx->config ? ctx->config->fbconfigID : None;
1504 case GLX_RENDER_TYPE:
1505 *value = ctx->renderType;
1508 return GLX_BAD_ATTRIBUTE;
1514 GLX_ALIAS(int, glXQueryContextInfoEXT,
1515 (Display * dpy, GLXContext ctx, int attribute, int *value),
1516 (dpy, ctx, attribute, value), glXQueryContext)
1518 _X_EXPORT GLXContextID glXGetContextIDEXT(const GLXContext ctx_user)
1520 struct glx_context *ctx = (struct glx_context *) ctx_user;
1526 glXFreeContextEXT(Display * dpy, GLXContext ctx)
1528 DestroyContext(dpy, ctx);
1532 _X_EXPORT GLXFBConfig *
1533 glXChooseFBConfig(Display * dpy, int screen,
1534 const int *attribList, int *nitems)
1536 struct glx_config **config_list;
1540 config_list = (struct glx_config **)
1541 glXGetFBConfigs(dpy, screen, &list_size);
1543 if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
1544 list_size = choose_visual(config_list, list_size, attribList, GL_TRUE);
1545 if (list_size == 0) {
1551 *nitems = list_size;
1552 return (GLXFBConfig *) config_list;
1556 _X_EXPORT GLXContext
1557 glXCreateNewContext(Display * dpy, GLXFBConfig fbconfig,
1558 int renderType, GLXContext shareList, Bool allowDirect)
1560 struct glx_config *config = (struct glx_config *) fbconfig;
1562 return CreateContext(dpy, config->fbconfigID, config, shareList,
1563 allowDirect, X_GLXCreateNewContext, renderType,
1568 _X_EXPORT GLXDrawable
1569 glXGetCurrentReadDrawable(void)
1571 struct glx_context *gc = __glXGetCurrentContext();
1573 return gc->currentReadable;
1577 _X_EXPORT GLXFBConfig *
1578 glXGetFBConfigs(Display * dpy, int screen, int *nelements)
1580 struct glx_display *priv = __glXInitialize(dpy);
1581 struct glx_config **config_list = NULL;
1582 struct glx_config *config;
1583 unsigned num_configs = 0;
1587 if (priv && (priv->screens != NULL)
1588 && (screen >= 0) && (screen <= ScreenCount(dpy))
1589 && (priv->screens[screen]->configs != NULL)
1590 && (priv->screens[screen]->configs->fbconfigID
1591 != (int) GLX_DONT_CARE)) {
1593 for (config = priv->screens[screen]->configs; config != NULL;
1594 config = config->next) {
1595 if (config->fbconfigID != (int) GLX_DONT_CARE) {
1600 config_list = Xmalloc(num_configs * sizeof *config_list);
1601 if (config_list != NULL) {
1602 *nelements = num_configs;
1604 for (config = priv->screens[screen]->configs; config != NULL;
1605 config = config->next) {
1606 if (config->fbconfigID != (int) GLX_DONT_CARE) {
1607 config_list[i] = config;
1614 return (GLXFBConfig *) config_list;
1619 glXGetFBConfigAttrib(Display * dpy, GLXFBConfig fbconfig,
1620 int attribute, int *value)
1622 struct glx_config *config = ValidateGLXFBConfig(dpy, fbconfig);
1625 return GLXBadFBConfig;
1627 return glx_config_get(config, attribute, value);
1631 _X_EXPORT XVisualInfo *
1632 glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig fbconfig)
1634 XVisualInfo visualTemplate;
1635 struct glx_config *config = (struct glx_config *) fbconfig;
1639 ** Get a list of all visuals, return if list is empty
1641 visualTemplate.visualid = config->visualID;
1642 return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
1645 #ifndef GLX_USE_APPLEGL
1647 ** GLX_SGI_swap_control
1650 __glXSwapIntervalSGI(int interval)
1652 xGLXVendorPrivateReq *req;
1653 struct glx_context *gc = __glXGetCurrentContext();
1654 struct glx_screen *psc;
1656 CARD32 *interval_ptr;
1660 return GLX_BAD_CONTEXT;
1663 if (interval <= 0) {
1664 return GLX_BAD_VALUE;
1667 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1669 #ifdef GLX_DIRECT_RENDERING
1670 if (gc->isDirect && psc->driScreen && psc->driScreen->setSwapInterval) {
1671 __GLXDRIdrawable *pdraw =
1672 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1673 psc->driScreen->setSwapInterval(pdraw, interval);
1678 dpy = gc->currentDpy;
1679 opcode = __glXSetupForCommand(dpy);
1684 /* Send the glXSwapIntervalSGI request */
1686 GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req);
1687 req->reqType = opcode;
1688 req->glxCode = X_GLXVendorPrivate;
1689 req->vendorCode = X_GLXvop_SwapIntervalSGI;
1690 req->contextTag = gc->currentContextTag;
1692 interval_ptr = (CARD32 *) (req + 1);
1693 *interval_ptr = interval;
1704 ** GLX_MESA_swap_control
1707 __glXSwapIntervalMESA(unsigned int interval)
1709 #ifdef GLX_DIRECT_RENDERING
1710 struct glx_context *gc = __glXGetCurrentContext();
1712 if (gc != NULL && gc->isDirect) {
1713 struct glx_screen *psc;
1715 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1716 if (psc->driScreen && psc->driScreen->setSwapInterval) {
1717 __GLXDRIdrawable *pdraw =
1718 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1719 return psc->driScreen->setSwapInterval(pdraw, interval);
1724 return GLX_BAD_CONTEXT;
1729 __glXGetSwapIntervalMESA(void)
1731 #ifdef GLX_DIRECT_RENDERING
1732 struct glx_context *gc = __glXGetCurrentContext();
1734 if (gc != NULL && gc->isDirect) {
1735 struct glx_screen *psc;
1737 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1738 if (psc->driScreen && psc->driScreen->getSwapInterval) {
1739 __GLXDRIdrawable *pdraw =
1740 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1741 return psc->driScreen->getSwapInterval(pdraw);
1751 ** GLX_SGI_video_sync
1754 __glXGetVideoSyncSGI(unsigned int *count)
1756 int64_t ust, msc, sbc;
1758 struct glx_context *gc = __glXGetCurrentContext();
1759 struct glx_screen *psc;
1760 #ifdef GLX_DIRECT_RENDERING
1761 __GLXDRIdrawable *pdraw;
1765 return GLX_BAD_CONTEXT;
1767 #ifdef GLX_DIRECT_RENDERING
1769 return GLX_BAD_CONTEXT;
1772 psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
1773 #ifdef GLX_DIRECT_RENDERING
1774 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1777 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1778 * FIXME: there should be a GLX encoding for this call. I can find no
1779 * FIXME: documentation for the GLX encoding.
1781 #ifdef GLX_DIRECT_RENDERING
1782 if (psc->driScreen && psc->driScreen->getDrawableMSC) {
1783 ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
1784 *count = (unsigned) msc;
1785 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1789 return GLX_BAD_CONTEXT;
1793 __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
1795 struct glx_context *gc = __glXGetCurrentContext();
1796 struct glx_screen *psc;
1797 #ifdef GLX_DIRECT_RENDERING
1798 __GLXDRIdrawable *pdraw;
1800 int64_t ust, msc, sbc;
1803 if (divisor <= 0 || remainder < 0)
1804 return GLX_BAD_VALUE;
1807 return GLX_BAD_CONTEXT;
1809 #ifdef GLX_DIRECT_RENDERING
1811 return GLX_BAD_CONTEXT;
1814 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1815 #ifdef GLX_DIRECT_RENDERING
1816 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1819 #ifdef GLX_DIRECT_RENDERING
1820 if (psc->driScreen && psc->driScreen->waitForMSC) {
1821 ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
1823 *count = (unsigned) msc;
1824 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1828 return GLX_BAD_CONTEXT;
1831 #endif /* GLX_USE_APPLEGL */
1834 ** GLX_SGIX_fbconfig
1835 ** Many of these functions are aliased to GLX 1.3 entry points in the
1836 ** GLX_functions table.
1840 GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
1841 (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
1842 (dpy, config, attribute, value), glXGetFBConfigAttrib)
1844 _X_EXPORT GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
1845 (Display * dpy, int screen, int *attrib_list,
1846 int *nelements), (dpy, screen, attrib_list, nelements),
1849 _X_EXPORT GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
1850 (Display * dpy, GLXFBConfigSGIX config),
1851 (dpy, config), glXGetVisualFromFBConfig)
1854 glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
1855 GLXFBConfigSGIX fbconfig,
1858 #ifndef GLX_USE_APPLEGL
1859 xGLXVendorPrivateWithReplyReq *vpreq;
1860 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
1861 GLXPixmap xid = None;
1863 struct glx_screen *psc;
1865 struct glx_config *config = (struct glx_config *) fbconfig;
1868 if ((dpy == NULL) || (config == NULL)) {
1871 #ifdef GLX_USE_APPLEGL
1872 if(apple_glx_pixmap_create(dpy, config->screen, pixmap, config))
1877 psc = GetGLXScreenConfigs(dpy, config->screen);
1879 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
1880 opcode = __glXSetupForCommand(dpy);
1885 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1887 GetReqExtra(GLXVendorPrivateWithReply,
1888 sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
1889 sz_xGLXVendorPrivateWithReplyReq, vpreq);
1890 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
1891 req->reqType = opcode;
1892 req->glxCode = X_GLXVendorPrivateWithReply;
1893 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
1894 req->screen = config->screen;
1895 req->fbconfig = config->fbconfigID;
1896 req->pixmap = pixmap;
1897 req->glxpixmap = xid = XAllocID(dpy);
1906 _X_EXPORT GLXContext
1907 glXCreateContextWithConfigSGIX(Display * dpy,
1908 GLXFBConfigSGIX fbconfig, int renderType,
1909 GLXContext shareList, Bool allowDirect)
1911 GLXContext gc = NULL;
1912 struct glx_config *config = (struct glx_config *) fbconfig;
1913 struct glx_screen *psc;
1916 if ((dpy == NULL) || (config == NULL)) {
1920 psc = GetGLXScreenConfigs(dpy, config->screen);
1922 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
1923 gc = CreateContext(dpy, config->fbconfigID, config, shareList,
1925 X_GLXvop_CreateContextWithConfigSGIX, renderType,
1933 _X_EXPORT GLXFBConfigSGIX
1934 glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis)
1936 struct glx_display *priv;
1937 struct glx_screen *psc = NULL;
1939 if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) != Success)
1940 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)
1941 && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) {
1942 return (GLXFBConfigSGIX) glx_config_find_visual(psc->configs,
1949 #ifndef GLX_USE_APPLEGL
1951 ** GLX_SGIX_swap_group
1954 __glXJoinSwapGroupSGIX(Display * dpy, GLXDrawable drawable,
1964 ** GLX_SGIX_swap_barrier
1967 __glXBindSwapBarrierSGIX(Display * dpy, GLXDrawable drawable, int barrier)
1975 __glXQueryMaxSwapBarriersSGIX(Display * dpy, int screen, int *max)
1985 ** GLX_OML_sync_control
1988 __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
1989 int64_t * ust, int64_t * msc, int64_t * sbc)
1991 struct glx_display * const priv = __glXInitialize(dpy);
1993 #ifdef GLX_DIRECT_RENDERING
1994 __GLXDRIdrawable *pdraw;
1996 struct glx_screen *psc;
2001 #ifdef GLX_DIRECT_RENDERING
2002 pdraw = GetGLXDRIDrawable(dpy, drawable);
2003 psc = pdraw ? pdraw->psc : NULL;
2004 if (pdraw && psc->driScreen->getDrawableMSC) {
2005 ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
2013 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2015 __glxGetMscRate(__GLXDRIdrawable *glxDraw,
2016 int32_t * numerator, int32_t * denominator)
2019 struct glx_screen *psc;
2020 XF86VidModeModeLine mode_line;
2025 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2026 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
2027 unsigned n = dot_clock * 1000;
2028 unsigned d = mode_line.vtotal * mode_line.htotal;
2030 # define V_INTERLACE 0x010
2031 # define V_DBLSCAN 0x020
2033 if (mode_line.flags & V_INTERLACE)
2035 else if (mode_line.flags & V_DBLSCAN)
2038 /* The OML_sync_control spec requires that if the refresh rate is a
2039 * whole number, that the returned numerator be equal to the refresh
2040 * rate and the denominator be 1.
2048 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2050 /* This is a poor man's way to reduce a fraction. It's far from
2051 * perfect, but it will work well enough for this situation.
2054 for (i = 0; f[i] != 0; i++) {
2055 while (n % f[i] == 0 && d % f[i] == 0) {
2075 * Determine the refresh rate of the specified drawable and display.
2077 * \param dpy Display whose refresh rate is to be determined.
2078 * \param drawable Drawable whose refresh rate is to be determined.
2079 * \param numerator Numerator of the refresh rate.
2080 * \param demoninator Denominator of the refresh rate.
2081 * \return If the refresh rate for the specified display and drawable could
2082 * be calculated, True is returned. Otherwise False is returned.
2084 * \note This function is implemented entirely client-side. A lot of other
2085 * functionality is required to export GLX_OML_sync_control, so on
2086 * XFree86 this function can be called for direct-rendering contexts
2087 * when GLX_OML_sync_control appears in the client extension string.
2091 __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2092 int32_t * numerator, int32_t * denominator)
2094 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2095 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
2100 return __glxGetMscRate(draw, numerator, denominator);
2112 __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
2113 int64_t target_msc, int64_t divisor, int64_t remainder)
2115 struct glx_context *gc = __glXGetCurrentContext();
2116 #ifdef GLX_DIRECT_RENDERING
2117 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2118 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
2121 if (!gc) /* no GLX for this */
2124 #ifdef GLX_DIRECT_RENDERING
2125 if (!pdraw || !gc->isDirect)
2129 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2130 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2131 * of -1 if the function failed because of errors detected in the input
2134 if (divisor < 0 || remainder < 0 || target_msc < 0)
2136 if (divisor > 0 && remainder >= divisor)
2139 if (target_msc == 0 && divisor == 0 && remainder == 0)
2142 #ifdef GLX_DIRECT_RENDERING
2143 if (psc->driScreen && psc->driScreen->swapBuffers)
2144 return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor,
2153 __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2154 int64_t target_msc, int64_t divisor,
2155 int64_t remainder, int64_t * ust,
2156 int64_t * msc, int64_t * sbc)
2158 #ifdef GLX_DIRECT_RENDERING
2159 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2160 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
2165 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2166 * error", but the return type in the spec is Bool.
2168 if (divisor < 0 || remainder < 0 || target_msc < 0)
2170 if (divisor > 0 && remainder >= divisor)
2173 #ifdef GLX_DIRECT_RENDERING
2174 if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
2175 ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
2186 __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2187 int64_t target_sbc, int64_t * ust,
2188 int64_t * msc, int64_t * sbc)
2190 #ifdef GLX_DIRECT_RENDERING
2191 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2192 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
2196 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2197 * error", but the return type in the spec is Bool.
2202 #ifdef GLX_DIRECT_RENDERING
2203 if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
2204 ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
2216 * Mesa extension stubs. These will help reduce portability problems.
2221 * Release all buffers associated with the specified GLX drawable.
2224 * This function was intended for stand-alone Mesa. The issue there is that
2225 * the library doesn't get any notification when a window is closed. In
2226 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2227 * supported, there are 3 different functions to destroy a drawable. It
2228 * should be possible to create GLX protocol (or have it determine which
2229 * protocol to use based on the type of the drawable) to have one function
2230 * do the work of 3. For the direct-rendering case, this function could
2231 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2232 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2233 * would need to be used. This really should be done as part of the new DRI
2236 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2237 * __driGarbageCollectDrawables
2238 * glXDestroyGLXPixmap
2239 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2240 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2243 __glXReleaseBuffersMESA(Display * dpy, GLXDrawable d)
2252 glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual,
2253 Pixmap pixmap, Colormap cmap)
2266 * GLX_MESA_copy_sub_buffer
2268 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2270 __glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
2271 int x, int y, int width, int height)
2273 xGLXVendorPrivateReq *req;
2274 struct glx_context *gc;
2276 CARD32 *drawable_ptr;
2277 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2280 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2281 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2282 if (pdraw != NULL) {
2283 struct glx_screen *psc = pdraw->psc;
2284 if (psc->driScreen->copySubBuffer != NULL) {
2286 (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height);
2293 opcode = __glXSetupForCommand(dpy);
2298 ** The calling thread may or may not have a current context. If it
2299 ** does, send the context tag so the server can do a flush.
2301 gc = __glXGetCurrentContext();
2302 if ((gc != NULL) && (dpy == gc->currentDpy) &&
2303 ((drawable == gc->currentDrawable) ||
2304 (drawable == gc->currentReadable))) {
2305 tag = gc->currentContextTag;
2312 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req);
2313 req->reqType = opcode;
2314 req->glxCode = X_GLXVendorPrivate;
2315 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2316 req->contextTag = tag;
2318 drawable_ptr = (CARD32 *) (req + 1);
2319 x_ptr = (INT32 *) (drawable_ptr + 1);
2320 y_ptr = (INT32 *) (drawable_ptr + 2);
2321 w_ptr = (INT32 *) (drawable_ptr + 3);
2322 h_ptr = (INT32 *) (drawable_ptr + 4);
2324 *drawable_ptr = drawable;
2336 __glXBindTexImageEXT(Display * dpy,
2337 GLXDrawable drawable, int buffer, const int *attrib_list)
2339 struct glx_context *gc = __glXGetCurrentContext();
2341 if (gc == NULL || gc->vtable == NULL || gc->vtable->bind_tex_image == NULL)
2344 gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
2348 __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
2350 struct glx_context *gc = __glXGetCurrentContext();
2352 if (gc == NULL || gc->vtable == NULL || gc->vtable->release_tex_image == NULL)
2355 gc->vtable->release_tex_image(dpy, drawable, buffer);
2360 #endif /* GLX_USE_APPLEGL */
2363 * \c strdup is actually not a standard ANSI C or POSIX routine.
2364 * Irix will not define it if ANSI mode is in effect.
2369 __glXstrdup(const char *str)
2372 copy = (char *) Xmalloc(strlen(str) + 1);
2380 ** glXGetProcAddress support
2383 struct name_address_pair
2389 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2390 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2392 static const struct name_address_pair GLX_functions[] = {
2393 /*** GLX_VERSION_1_0 ***/
2394 GLX_FUNCTION(glXChooseVisual),
2395 GLX_FUNCTION(glXCopyContext),
2396 GLX_FUNCTION(glXCreateContext),
2397 GLX_FUNCTION(glXCreateGLXPixmap),
2398 GLX_FUNCTION(glXDestroyContext),
2399 GLX_FUNCTION(glXDestroyGLXPixmap),
2400 GLX_FUNCTION(glXGetConfig),
2401 GLX_FUNCTION(glXGetCurrentContext),
2402 GLX_FUNCTION(glXGetCurrentDrawable),
2403 GLX_FUNCTION(glXIsDirect),
2404 GLX_FUNCTION(glXMakeCurrent),
2405 GLX_FUNCTION(glXQueryExtension),
2406 GLX_FUNCTION(glXQueryVersion),
2407 GLX_FUNCTION(glXSwapBuffers),
2408 GLX_FUNCTION(glXUseXFont),
2409 GLX_FUNCTION(glXWaitGL),
2410 GLX_FUNCTION(glXWaitX),
2412 /*** GLX_VERSION_1_1 ***/
2413 GLX_FUNCTION(glXGetClientString),
2414 GLX_FUNCTION(glXQueryExtensionsString),
2415 GLX_FUNCTION(glXQueryServerString),
2417 /*** GLX_VERSION_1_2 ***/
2418 GLX_FUNCTION(glXGetCurrentDisplay),
2420 /*** GLX_VERSION_1_3 ***/
2421 GLX_FUNCTION(glXChooseFBConfig),
2422 GLX_FUNCTION(glXCreateNewContext),
2423 GLX_FUNCTION(glXCreatePbuffer),
2424 GLX_FUNCTION(glXCreatePixmap),
2425 GLX_FUNCTION(glXCreateWindow),
2426 GLX_FUNCTION(glXDestroyPbuffer),
2427 GLX_FUNCTION(glXDestroyPixmap),
2428 GLX_FUNCTION(glXDestroyWindow),
2429 GLX_FUNCTION(glXGetCurrentReadDrawable),
2430 GLX_FUNCTION(glXGetFBConfigAttrib),
2431 GLX_FUNCTION(glXGetFBConfigs),
2432 GLX_FUNCTION(glXGetSelectedEvent),
2433 GLX_FUNCTION(glXGetVisualFromFBConfig),
2434 GLX_FUNCTION(glXMakeContextCurrent),
2435 GLX_FUNCTION(glXQueryContext),
2436 GLX_FUNCTION(glXQueryDrawable),
2437 GLX_FUNCTION(glXSelectEvent),
2439 #ifndef GLX_USE_APPLEGL
2440 /*** GLX_SGI_swap_control ***/
2441 GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI),
2443 /*** GLX_SGI_video_sync ***/
2444 GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI),
2445 GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI),
2447 /*** GLX_SGI_make_current_read ***/
2448 GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent),
2449 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable),
2451 /*** GLX_EXT_import_context ***/
2452 GLX_FUNCTION(glXFreeContextEXT),
2453 GLX_FUNCTION(glXGetContextIDEXT),
2454 GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
2455 GLX_FUNCTION(glXImportContextEXT),
2456 GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
2459 /*** GLX_SGIX_fbconfig ***/
2460 GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
2461 GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig),
2462 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX),
2463 GLX_FUNCTION(glXCreateContextWithConfigSGIX),
2464 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
2465 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
2467 #ifndef GLX_USE_APPLEGL
2468 /*** GLX_SGIX_pbuffer ***/
2469 GLX_FUNCTION(glXCreateGLXPbufferSGIX),
2470 GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
2471 GLX_FUNCTION(glXQueryGLXPbufferSGIX),
2472 GLX_FUNCTION(glXSelectEventSGIX),
2473 GLX_FUNCTION(glXGetSelectedEventSGIX),
2475 /*** GLX_SGIX_swap_group ***/
2476 GLX_FUNCTION2(glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX),
2478 /*** GLX_SGIX_swap_barrier ***/
2479 GLX_FUNCTION2(glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX),
2480 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX),
2482 /*** GLX_MESA_copy_sub_buffer ***/
2483 GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA),
2485 /*** GLX_MESA_pixmap_colormap ***/
2486 GLX_FUNCTION(glXCreateGLXPixmapMESA),
2488 /*** GLX_MESA_release_buffers ***/
2489 GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA),
2491 /*** GLX_MESA_swap_control ***/
2492 GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA),
2493 GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA),
2496 /*** GLX_ARB_get_proc_address ***/
2497 GLX_FUNCTION(glXGetProcAddressARB),
2500 GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
2502 #ifndef GLX_USE_APPLEGL
2503 /*** GLX_OML_sync_control ***/
2504 GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML),
2505 GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML),
2506 GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML),
2507 GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML),
2508 GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML),
2510 /*** GLX_EXT_texture_from_pixmap ***/
2511 GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT),
2512 GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT),
2515 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2516 /*** DRI configuration ***/
2517 GLX_FUNCTION(glXGetScreenDriver),
2518 GLX_FUNCTION(glXGetDriverConfig),
2521 {NULL, NULL} /* end of list */
2524 #ifndef GLX_USE_APPLEGL
2525 static const GLvoid *
2526 get_glx_proc_address(const char *funcName)
2530 /* try static functions */
2531 for (i = 0; GLX_functions[i].Name; i++) {
2532 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2533 return GLX_functions[i].Address;
2541 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2542 * \c glXGetProcAddress.
2544 * \param procName Name of a GL or GLX function.
2545 * \returns A pointer to the named function
2547 * \sa glXGetProcAddress
2549 _X_EXPORT void (*glXGetProcAddressARB(const GLubyte * procName)) (void)
2551 typedef void (*gl_function) (void);
2555 /* Search the table of GLX and internal functions first. If that
2556 * fails and the supplied name could be a valid core GL name, try
2557 * searching the core GL function table. This check is done to prevent
2558 * DRI based drivers from searching the core GL function table for
2559 * internal API functions.
2561 #ifdef GLX_USE_APPLEGL
2562 f = (gl_function) apple_glx_get_proc_address(procName);
2564 f = (gl_function) get_glx_proc_address((const char *) procName);
2565 if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2566 && (procName[2] != 'X')) {
2567 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2574 * Get the address of a named GL function. This is the GLX 1.4 name for
2575 * \c glXGetProcAddressARB.
2577 * \param procName Name of a GL or GLX function.
2578 * \returns A pointer to the named function
2580 * \sa glXGetProcAddressARB
2582 _X_EXPORT void (*glXGetProcAddress(const GLubyte * procName)) (void)
2583 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2584 __attribute__ ((alias("glXGetProcAddressARB")));
2587 return glXGetProcAddressARB(procName);
2589 #endif /* __GNUC__ */
2592 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2594 * Get the unadjusted system time (UST). Currently, the UST is measured in
2595 * microseconds since Epoc. The actual resolution of the UST may vary from
2596 * system to system, and the units may vary from release to release.
2597 * Drivers should not call this function directly. They should instead use
2598 * \c glXGetProcAddress to obtain a pointer to the function.
2600 * \param ust Location to store the 64-bit UST
2601 * \returns Zero on success or a negative errno value on failure.
2603 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2605 * \since Internal API version 20030317.
2608 __glXGetUST(int64_t * ust)
2616 if (gettimeofday(&tv, NULL) == 0) {
2617 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
2624 #endif /* GLX_DIRECT_RENDERING */