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 #include "glx_error.h"
42 #ifdef GLX_DIRECT_RENDERING
43 #ifdef GLX_USE_APPLEGL
44 #include "apple/apple_glx_context.h"
45 #include "apple/apple_glx.h"
49 #include <X11/extensions/xf86vmode.h>
54 #include <X11/Xlib-xcb.h>
58 static const char __glXGLXClientVendorName[] = "Mesa Project and SGI";
59 static const char __glXGLXClientVersion[] = "1.4";
61 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
64 * Get the __DRIdrawable for the drawable associated with a GLXContext
66 * \param dpy The display associated with \c drawable.
67 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
68 * \param scrn_num If non-NULL, the drawables screen is stored there
69 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
70 * the drawable is not associated with a direct-rendering context.
72 _X_HIDDEN __GLXDRIdrawable *
73 GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable)
75 struct glx_display *priv = __glXInitialize(dpy);
76 __GLXDRIdrawable *pdraw;
81 if (__glxHashLookup(priv->drawHash, drawable, (void *) &pdraw) == 0)
89 _X_HIDDEN struct glx_drawable *
90 GetGLXDrawable(Display *dpy, GLXDrawable drawable)
92 struct glx_display *priv = __glXInitialize(dpy);
93 struct glx_drawable *glxDraw;
98 if (__glxHashLookup(priv->glXDrawHash, drawable, (void *) &glxDraw) == 0)
105 InitGLXDrawable(Display *dpy, struct glx_drawable *glxDraw, XID xDrawable,
106 GLXDrawable drawable)
108 struct glx_display *priv = __glXInitialize(dpy);
113 glxDraw->xDrawable = xDrawable;
114 glxDraw->drawable = drawable;
115 glxDraw->lastEventSbc = 0;
116 glxDraw->eventSbcWrap = 0;
118 return __glxHashInsert(priv->glXDrawHash, drawable, glxDraw);
122 DestroyGLXDrawable(Display *dpy, GLXDrawable drawable)
124 struct glx_display *priv = __glXInitialize(dpy);
125 struct glx_drawable *glxDraw;
130 glxDraw = GetGLXDrawable(dpy, drawable);
131 __glxHashDelete(priv->glXDrawHash, drawable);
136 * Get the GLX per-screen data structure associated with a GLX context.
138 * \param dpy Display for which the GLX per-screen information is to be
140 * \param scrn Screen on \c dpy for which the GLX per-screen information is
142 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
143 * specify a valid GLX screen, or NULL otherwise.
145 * \todo Should this function validate that \c scrn is within the screen
146 * number range for \c dpy?
149 _X_HIDDEN struct glx_screen *
150 GetGLXScreenConfigs(Display * dpy, int scrn)
152 struct glx_display *const priv = __glXInitialize(dpy);
156 NULL) ? priv->screens[scrn] : NULL;
161 GetGLXPrivScreenConfig(Display * dpy, int scrn, struct glx_display ** ppriv,
162 struct glx_screen ** ppsc)
164 /* Initialize the extension, if needed . This has the added value
165 * of initializing/allocating the display private
169 return GLX_NO_EXTENSION;
172 *ppriv = __glXInitialize(dpy);
173 if (*ppriv == NULL) {
174 return GLX_NO_EXTENSION;
177 /* Check screen number to see if its valid */
178 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
179 return GLX_BAD_SCREEN;
182 /* Check to see if the GL is supported on this screen */
183 *ppsc = (*ppriv)->screens[scrn];
184 if ((*ppsc)->configs == NULL && (*ppsc)->visuals == NULL) {
185 /* No support for GL on this screen regardless of visual */
186 return GLX_BAD_VISUAL;
194 * Determine if a \c GLXFBConfig supplied by the application is valid.
196 * \param dpy Application supplied \c Display pointer.
197 * \param config Application supplied \c GLXFBConfig.
199 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
200 * \c struct glx_config structure is returned. Otherwise, \c NULL
203 static struct glx_config *
204 ValidateGLXFBConfig(Display * dpy, GLXFBConfig fbconfig)
206 struct glx_display *const priv = __glXInitialize(dpy);
207 int num_screens = ScreenCount(dpy);
209 struct glx_config *config;
212 for (i = 0; i < num_screens; i++) {
213 for (config = priv->screens[i]->configs; config != NULL;
214 config = config->next) {
215 if (config == (struct glx_config *) fbconfig) {
226 * Verifies context's GLX_RENDER_TYPE value with config.
228 * \param config GLX FBConfig which will support the returned renderType.
229 * \param renderType The context render type to be verified.
230 * \return True if the value of context renderType was approved, or 0 if no
231 * valid value was found.
234 validate_renderType_against_config(const struct glx_config *config,
237 switch (renderType) {
239 return (config->renderType & GLX_RGBA_BIT) != 0;
240 case GLX_COLOR_INDEX_TYPE:
241 return (config->renderType & GLX_COLOR_INDEX_BIT) != 0;
242 case GLX_RGBA_FLOAT_TYPE_ARB:
243 return (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) != 0;
244 case GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT:
245 return (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) != 0;
253 glx_context_init(struct glx_context *gc,
254 struct glx_screen *psc, struct glx_config *config)
256 gc->majorOpcode = __glXSetupForCommand(psc->display->dpy);
257 if (!gc->majorOpcode)
260 gc->screen = psc->scr;
263 gc->isDirect = GL_TRUE;
264 gc->currentContextTag = -1;
271 * Create a new context.
273 * \param renderType For FBConfigs, what is the rendering type?
277 CreateContext(Display *dpy, int generic_id, struct glx_config *config,
278 GLXContext shareList_user, Bool allowDirect,
279 unsigned code, int renderType, int screen)
281 struct glx_context *gc;
282 struct glx_screen *psc;
283 struct glx_context *shareList = (struct glx_context *) shareList_user;
287 psc = GetGLXScreenConfigs(dpy, screen);
291 if (generic_id == None)
295 #ifdef GLX_USE_APPLEGL
296 gc = applegl_create_context(psc, config, shareList, renderType);
298 if (allowDirect && psc->vtable->create_context)
299 gc = psc->vtable->create_context(psc, config, shareList, renderType);
301 gc = indirect_create_context(psc, config, shareList, renderType);
308 case X_GLXCreateContext: {
309 xGLXCreateContextReq *req;
311 /* Send the glXCreateContext request */
312 GetReq(GLXCreateContext, req);
313 req->reqType = gc->majorOpcode;
314 req->glxCode = X_GLXCreateContext;
315 req->context = gc->xid = XAllocID(dpy);
316 req->visual = generic_id;
317 req->screen = screen;
318 req->shareList = shareList ? shareList->xid : None;
319 req->isDirect = gc->isDirect;
323 case X_GLXCreateNewContext: {
324 xGLXCreateNewContextReq *req;
326 /* Send the glXCreateNewContext request */
327 GetReq(GLXCreateNewContext, req);
328 req->reqType = gc->majorOpcode;
329 req->glxCode = X_GLXCreateNewContext;
330 req->context = gc->xid = XAllocID(dpy);
331 req->fbconfig = generic_id;
332 req->screen = screen;
333 req->renderType = renderType;
334 req->shareList = shareList ? shareList->xid : None;
335 req->isDirect = gc->isDirect;
339 case X_GLXvop_CreateContextWithConfigSGIX: {
340 xGLXVendorPrivateWithReplyReq *vpreq;
341 xGLXCreateContextWithConfigSGIXReq *req;
343 /* Send the glXCreateNewContext request */
344 GetReqExtra(GLXVendorPrivateWithReply,
345 sz_xGLXCreateContextWithConfigSGIXReq -
346 sz_xGLXVendorPrivateWithReplyReq, vpreq);
347 req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
348 req->reqType = gc->majorOpcode;
349 req->glxCode = X_GLXVendorPrivateWithReply;
350 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
351 req->context = gc->xid = XAllocID(dpy);
352 req->fbconfig = generic_id;
353 req->screen = screen;
354 req->renderType = renderType;
355 req->shareList = shareList ? shareList->xid : None;
356 req->isDirect = gc->isDirect;
361 /* What to do here? This case is the sign of an internal error. It
362 * should never be reachable.
370 gc->share_xid = shareList ? shareList->xid : None;
371 gc->imported = GL_FALSE;
373 return (GLXContext) gc;
377 glXCreateContext(Display * dpy, XVisualInfo * vis,
378 GLXContext shareList, Bool allowDirect)
380 struct glx_config *config = NULL;
381 int renderType = GLX_RGBA_TYPE;
383 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
384 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, vis->screen);
387 config = glx_config_find_visual(psc->visuals, vis->visualid);
389 if (config == NULL) {
392 error.errorCode = BadValue;
393 error.resourceID = vis->visualid;
394 error.sequenceNumber = dpy->request;
395 error.type = X_Error;
396 error.majorCode = __glXSetupForCommand(dpy);
397 error.minorCode = X_GLXCreateContext;
398 _XError(dpy, &error);
402 /* Choose the context render type based on DRI config values. It is
403 * unusual to set this type from config, but we have no other choice, as
404 * this old API does not provide renderType parameter.
406 if (config->renderType & GLX_RGBA_FLOAT_BIT_ARB) {
407 renderType = GLX_RGBA_FLOAT_TYPE_ARB;
408 } else if (config->renderType & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) {
409 renderType = GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT;
410 } else if (config->renderType & GLX_RGBA_BIT) {
411 renderType = GLX_RGBA_TYPE;
412 } else if (config->renderType & GLX_COLOR_INDEX_BIT) {
413 renderType = GLX_COLOR_INDEX_TYPE;
414 } else if (config->rgbMode) {
415 /* If we're here, then renderType is not set correctly. Let's use a
416 * safeguard - any TrueColor or DirectColor mode is RGB mode. Such
417 * default value is needed by old DRI drivers, which didn't set
418 * renderType correctly as the value was just ignored.
420 renderType = GLX_RGBA_TYPE;
422 /* Safeguard - only one option left, all non-RGB modes are indexed
423 * modes. Again, this allows drivers with invalid renderType to work
426 renderType = GLX_COLOR_INDEX_TYPE;
430 return CreateContext(dpy, vis->visualid, config, shareList, allowDirect,
431 X_GLXCreateContext, renderType, vis->screen);
435 glx_send_destroy_context(Display *dpy, XID xid)
437 CARD8 opcode = __glXSetupForCommand(dpy);
438 xGLXDestroyContextReq *req;
441 GetReq(GLXDestroyContext, req);
442 req->reqType = opcode;
443 req->glxCode = X_GLXDestroyContext;
450 ** Destroy the named context
454 glXDestroyContext(Display * dpy, GLXContext ctx)
456 struct glx_context *gc = (struct glx_context *) ctx;
458 if (gc == NULL || gc->xid == None)
463 glx_send_destroy_context(dpy, gc->xid);
465 if (gc->currentDpy) {
466 /* This context is bound to some thread. According to the man page,
467 * we should not actually delete the context until it's unbound.
468 * Note that we set gc->xid = None above. In MakeContextCurrent()
469 * we check for that and delete the context there.
473 gc->vtable->destroy(gc);
479 ** Return the major and minor version #s for the GLX extension
482 glXQueryVersion(Display * dpy, int *major, int *minor)
484 struct glx_display *priv;
486 /* Init the extension. This fetches the major and minor version. */
487 priv = __glXInitialize(dpy);
492 *major = priv->majorVersion;
494 *minor = priv->minorVersion;
499 ** Query the existence of the GLX extension
502 glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
504 int major_op, erb, evb;
507 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
518 ** Put a barrier in the token stream that forces the GL to finish its
519 ** work before X can proceed.
524 struct glx_context *gc = __glXGetCurrentContext();
526 if (gc && gc->vtable->wait_gl)
527 gc->vtable->wait_gl(gc);
531 ** Put a barrier in the token stream that forces X to finish its
532 ** work before GL can proceed.
537 struct glx_context *gc = __glXGetCurrentContext();
539 if (gc && gc->vtable->wait_x)
540 gc->vtable->wait_x(gc);
544 glXUseXFont(Font font, int first, int count, int listBase)
546 struct glx_context *gc = __glXGetCurrentContext();
548 if (gc && gc->vtable->use_x_font)
549 gc->vtable->use_x_font(gc, font, first, count, listBase);
552 /************************************************************************/
555 ** Copy the source context to the destination context using the
559 glXCopyContext(Display * dpy, GLXContext source_user,
560 GLXContext dest_user, unsigned long mask)
562 struct glx_context *source = (struct glx_context *) source_user;
563 struct glx_context *dest = (struct glx_context *) dest_user;
564 #ifdef GLX_USE_APPLEGL
565 struct glx_context *gc = __glXGetCurrentContext();
569 if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
570 mask, &errorcode, &x11error)) {
571 __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
575 xGLXCopyContextReq *req;
576 struct glx_context *gc = __glXGetCurrentContext();
580 opcode = __glXSetupForCommand(dpy);
585 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
587 /* NOT_DONE: This does not work yet */
592 ** If the source is the current context, send its tag so that the context
593 ** can be flushed before the copy.
595 if (source == gc && dpy == gc->currentDpy) {
596 tag = gc->currentContextTag;
602 /* Send the glXCopyContext request */
604 GetReq(GLXCopyContext, req);
605 req->reqType = opcode;
606 req->glxCode = X_GLXCopyContext;
607 req->source = source ? source->xid : None;
608 req->dest = dest ? dest->xid : None;
610 req->contextTag = tag;
613 #endif /* GLX_USE_APPLEGL */
618 * Determine if a context uses direct rendering.
620 * \param dpy Display where the context was created.
621 * \param contextID ID of the context to be tested.
623 * \returns \c True if the context is direct rendering or not.
626 __glXIsDirect(Display * dpy, GLXContextID contextID)
630 xcb_generic_error_t *err;
631 xcb_glx_is_direct_reply_t *reply;
634 opcode = __glXSetupForCommand(dpy);
639 c = XGetXCBConnection(dpy);
640 reply = xcb_glx_is_direct_reply(c, xcb_glx_is_direct(c, contextID), &err);
641 is_direct = (reply != NULL && reply->is_direct) ? True : False;
644 __glXSendErrorForXcb(dpy, err);
655 * Shouldn't this function \b always return \c False when
656 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
657 * the GLX protocol here at all?
660 glXIsDirect(Display * dpy, GLXContext gc_user)
662 struct glx_context *gc = (struct glx_context *) gc_user;
667 else if (gc->isDirect) {
670 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
673 return __glXIsDirect(dpy, gc->xid);
678 glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
680 #ifdef GLX_USE_APPLEGL
681 int screen = vis->screen;
682 struct glx_screen *const psc = GetGLXScreenConfigs(dpy, screen);
683 const struct glx_config *config;
685 config = glx_config_find_visual(psc->visuals, vis->visualid);
687 if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, config))
692 xGLXCreateGLXPixmapReq *req;
693 struct glx_drawable *glxDraw;
697 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
698 struct glx_display *const priv = __glXInitialize(dpy);
704 opcode = __glXSetupForCommand(dpy);
709 glxDraw = malloc(sizeof(*glxDraw));
713 /* Send the glXCreateGLXPixmap request */
715 GetReq(GLXCreateGLXPixmap, req);
716 req->reqType = opcode;
717 req->glxCode = X_GLXCreateGLXPixmap;
718 req->screen = vis->screen;
719 req->visual = vis->visualid;
720 req->pixmap = pixmap;
721 req->glxpixmap = xid = XAllocID(dpy);
725 if (InitGLXDrawable(dpy, glxDraw, pixmap, req->glxpixmap)) {
730 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
732 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
733 * is actually bound to a context... */
735 __GLXDRIdrawable *pdraw;
736 struct glx_screen *psc;
737 struct glx_config *config;
739 psc = priv->screens[vis->screen];
740 if (psc->driScreen == NULL)
743 config = glx_config_find_visual(psc->visuals, vis->visualid);
744 pdraw = psc->driScreen->createDrawable(psc, pixmap, xid, config);
746 fprintf(stderr, "failed to create pixmap\n");
751 if (__glxHashInsert(priv->drawHash, xid, pdraw)) {
752 (*pdraw->destroyDrawable) (pdraw);
759 xGLXDestroyGLXPixmapReq *dreq;
761 GetReq(GLXDestroyGLXPixmap, dreq);
762 dreq->reqType = opcode;
763 dreq->glxCode = X_GLXDestroyGLXPixmap;
764 dreq->glxpixmap = xid;
775 ** Destroy the named pixmap
778 glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
780 #ifdef GLX_USE_APPLEGL
781 if(apple_glx_pixmap_destroy(dpy, glxpixmap))
782 __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
784 xGLXDestroyGLXPixmapReq *req;
787 opcode = __glXSetupForCommand(dpy);
792 /* Send the glXDestroyGLXPixmap request */
794 GetReq(GLXDestroyGLXPixmap, req);
795 req->reqType = opcode;
796 req->glxCode = X_GLXDestroyGLXPixmap;
797 req->glxpixmap = glxpixmap;
801 DestroyGLXDrawable(dpy, glxpixmap);
803 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
805 struct glx_display *const priv = __glXInitialize(dpy);
806 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
808 if (priv != NULL && pdraw != NULL) {
809 (*pdraw->destroyDrawable) (pdraw);
810 __glxHashDelete(priv->drawHash, glxpixmap);
814 #endif /* GLX_USE_APPLEGL */
818 glXSwapBuffers(Display * dpy, GLXDrawable drawable)
820 #ifdef GLX_USE_APPLEGL
821 struct glx_context * gc = __glXGetCurrentContext();
822 if(gc && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
823 apple_glx_swap_buffers(gc->driContext);
825 __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
828 struct glx_context *gc;
833 gc = __glXGetCurrentContext();
835 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
837 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
840 Bool flush = gc && drawable == gc->currentDrawable;
842 (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0, flush);
848 opcode = __glXSetupForCommand(dpy);
854 ** The calling thread may or may not have a current context. If it
855 ** does, send the context tag so the server can do a flush.
857 if ((gc != NULL) && (dpy == gc->currentDpy) &&
858 ((drawable == gc->currentDrawable)
859 || (drawable == gc->currentReadable))) {
860 tag = gc->currentContextTag;
866 c = XGetXCBConnection(dpy);
867 xcb_glx_swap_buffers(c, tag, drawable);
869 #endif /* GLX_USE_APPLEGL */
874 ** Return configuration information for the given display, screen and
875 ** visual combination.
878 glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
881 struct glx_display *priv;
882 struct glx_screen *psc;
883 struct glx_config *config;
886 status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
887 if (status == Success) {
888 config = glx_config_find_visual(psc->visuals, vis->visualid);
890 /* Lookup attribute after first finding a match on the visual */
891 if (config != NULL) {
892 return glx_config_get(config, attribute, value_return);
895 status = GLX_BAD_VISUAL;
899 ** If we can't find the config for this visual, this visual is not
900 ** supported by the OpenGL implementation on the server.
902 if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
903 *value_return = False;
910 /************************************************************************/
913 init_fbconfig_for_chooser(struct glx_config * config,
914 GLboolean fbconfig_style_tags)
916 memset(config, 0, sizeof(struct glx_config));
917 config->visualID = (XID) GLX_DONT_CARE;
918 config->visualType = GLX_DONT_CARE;
920 /* glXChooseFBConfig specifies different defaults for these properties than
923 if (fbconfig_style_tags) {
924 config->rgbMode = GL_TRUE;
925 config->doubleBufferMode = GLX_DONT_CARE;
926 config->renderType = GLX_RGBA_BIT;
929 config->drawableType = GLX_WINDOW_BIT;
930 config->visualRating = GLX_DONT_CARE;
931 config->transparentPixel = GLX_NONE;
932 config->transparentRed = GLX_DONT_CARE;
933 config->transparentGreen = GLX_DONT_CARE;
934 config->transparentBlue = GLX_DONT_CARE;
935 config->transparentAlpha = GLX_DONT_CARE;
936 config->transparentIndex = GLX_DONT_CARE;
938 config->xRenderable = GLX_DONT_CARE;
939 config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
941 config->swapMethod = GLX_DONT_CARE;
944 #define MATCH_DONT_CARE( param ) \
946 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
947 && (a-> param != b-> param) ) { \
952 #define MATCH_MINIMUM( param ) \
954 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
955 && (a-> param > b-> param) ) { \
960 #define MATCH_EXACT( param ) \
962 if ( a-> param != b-> param) { \
967 /* Test that all bits from a are contained in b */
968 #define MATCH_MASK(param) \
970 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
971 && ((a->param & ~b->param) != 0) ) { \
977 * Determine if two GLXFBConfigs are compatible.
979 * \param a Application specified config to test.
980 * \param b Server specified config to test against \c a.
983 fbconfigs_compatible(const struct glx_config * const a,
984 const struct glx_config * const b)
986 MATCH_DONT_CARE(doubleBufferMode);
987 MATCH_DONT_CARE(visualType);
988 MATCH_DONT_CARE(visualRating);
989 MATCH_DONT_CARE(xRenderable);
990 MATCH_DONT_CARE(fbconfigID);
991 MATCH_DONT_CARE(swapMethod);
993 MATCH_MINIMUM(rgbBits);
994 MATCH_MINIMUM(numAuxBuffers);
995 MATCH_MINIMUM(redBits);
996 MATCH_MINIMUM(greenBits);
997 MATCH_MINIMUM(blueBits);
998 MATCH_MINIMUM(alphaBits);
999 MATCH_MINIMUM(depthBits);
1000 MATCH_MINIMUM(stencilBits);
1001 MATCH_MINIMUM(accumRedBits);
1002 MATCH_MINIMUM(accumGreenBits);
1003 MATCH_MINIMUM(accumBlueBits);
1004 MATCH_MINIMUM(accumAlphaBits);
1005 MATCH_MINIMUM(sampleBuffers);
1006 MATCH_MINIMUM(maxPbufferWidth);
1007 MATCH_MINIMUM(maxPbufferHeight);
1008 MATCH_MINIMUM(maxPbufferPixels);
1009 MATCH_MINIMUM(samples);
1011 MATCH_DONT_CARE(stereoMode);
1014 MATCH_MASK(drawableType);
1015 MATCH_MASK(renderType);
1017 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1018 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1019 * Technically speaking, it is a bug in the DDX driver, but there is
1020 * enough of an installed base to work around the problem here. In any
1021 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1022 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1023 * 0 from the server to be a match to maintain backward compatibility with
1024 * the (broken) drivers.
1027 if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) {
1028 if (a->transparentPixel == GLX_NONE) {
1029 if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0)
1033 MATCH_EXACT(transparentPixel);
1036 switch (a->transparentPixel) {
1037 case GLX_TRANSPARENT_RGB:
1038 MATCH_DONT_CARE(transparentRed);
1039 MATCH_DONT_CARE(transparentGreen);
1040 MATCH_DONT_CARE(transparentBlue);
1041 MATCH_DONT_CARE(transparentAlpha);
1044 case GLX_TRANSPARENT_INDEX:
1045 MATCH_DONT_CARE(transparentIndex);
1057 /* There's some trickly language in the GLX spec about how this is supposed
1058 * to work. Basically, if a given component size is either not specified
1059 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1060 * Well, that's really hard to do with the code as-is. This behavior is
1061 * closer to correct, but still not technically right.
1063 #define PREFER_LARGER_OR_ZERO(comp) \
1065 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1066 if ( ((*a)-> comp) == 0 ) { \
1069 else if ( ((*b)-> comp) == 0 ) { \
1073 return ((*b)-> comp) - ((*a)-> comp) ; \
1078 #define PREFER_LARGER(comp) \
1080 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1081 return ((*b)-> comp) - ((*a)-> comp) ; \
1085 #define PREFER_SMALLER(comp) \
1087 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1088 return ((*a)-> comp) - ((*b)-> comp) ; \
1093 * Compare two GLXFBConfigs. This function is intended to be used as the
1094 * compare function passed in to qsort.
1096 * \returns If \c a is a "better" config, according to the specification of
1097 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1098 * better, then a number greater than zero is return. If both are
1099 * equal, zero is returned.
1100 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1103 fbconfig_compare(struct glx_config **a, struct glx_config **b)
1105 /* The order of these comparisons must NOT change. It is defined by
1106 * the GLX 1.4 specification.
1109 PREFER_SMALLER(visualSelectGroup);
1111 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1112 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1113 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1115 PREFER_SMALLER(visualRating);
1117 /* This isn't quite right. It is supposed to compare the sum of the
1118 * components the user specifically set minimums for.
1120 PREFER_LARGER_OR_ZERO(redBits);
1121 PREFER_LARGER_OR_ZERO(greenBits);
1122 PREFER_LARGER_OR_ZERO(blueBits);
1123 PREFER_LARGER_OR_ZERO(alphaBits);
1125 PREFER_SMALLER(rgbBits);
1127 if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) {
1128 /* Prefer single-buffer.
1130 return (!(*a)->doubleBufferMode) ? -1 : 1;
1133 PREFER_SMALLER(numAuxBuffers);
1135 PREFER_SMALLER(sampleBuffers);
1136 PREFER_SMALLER(samples);
1138 PREFER_LARGER_OR_ZERO(depthBits);
1139 PREFER_SMALLER(stencilBits);
1141 /* This isn't quite right. It is supposed to compare the sum of the
1142 * components the user specifically set minimums for.
1144 PREFER_LARGER_OR_ZERO(accumRedBits);
1145 PREFER_LARGER_OR_ZERO(accumGreenBits);
1146 PREFER_LARGER_OR_ZERO(accumBlueBits);
1147 PREFER_LARGER_OR_ZERO(accumAlphaBits);
1149 PREFER_SMALLER(visualType);
1151 /* None of the pbuffer or fbconfig specs say that this comparison needs
1152 * to happen at all, but it seems like it should.
1154 PREFER_LARGER(maxPbufferWidth);
1155 PREFER_LARGER(maxPbufferHeight);
1156 PREFER_LARGER(maxPbufferPixels);
1163 * Selects and sorts a subset of the supplied configs based on the attributes.
1164 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1165 * and \c glXChooseFBConfigSGIX.
1167 * \param configs Array of pointers to possible configs. The elements of
1168 * this array that do not meet the criteria will be set to
1169 * NULL. The remaining elements will be sorted according to
1170 * the various visual / FBConfig selection rules.
1171 * \param num_configs Number of elements in the \c configs array.
1172 * \param attribList Attributes used select from \c configs. This array is
1173 * terminated by a \c None tag. The array can either take
1174 * the form expected by \c glXChooseVisual (where boolean
1175 * tags do not have a value) or by \c glXChooseFBConfig
1176 * (where every tag has a value).
1177 * \param fbconfig_style_tags Selects whether \c attribList is in
1178 * \c glXChooseVisual style or
1179 * \c glXChooseFBConfig style.
1180 * \returns The number of valid elements left in \c configs.
1182 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1185 choose_visual(struct glx_config ** configs, int num_configs,
1186 const int *attribList, GLboolean fbconfig_style_tags)
1188 struct glx_config test_config;
1192 /* This is a fairly direct implementation of the selection method
1193 * described by GLX_SGIX_fbconfig. Start by culling out all the
1194 * configs that are not compatible with the selected parameter
1198 init_fbconfig_for_chooser(&test_config, fbconfig_style_tags);
1199 __glXInitializeVisualConfigFromTags(&test_config, 512,
1200 (const INT32 *) attribList,
1201 GL_TRUE, fbconfig_style_tags);
1204 for (i = 0; i < num_configs; i++) {
1205 if (fbconfigs_compatible(&test_config, configs[i])) {
1206 configs[base] = configs[i];
1215 if (base < num_configs) {
1216 (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base));
1219 /* After the incompatible configs are removed, the resulting
1220 * list is sorted according to the rules set out in the various
1224 qsort(configs, base, sizeof(struct glx_config *),
1225 (int (*)(const void *, const void *)) fbconfig_compare);
1233 ** Return the visual that best matches the template. Return None if no
1234 ** visual matches the template.
1236 _X_EXPORT XVisualInfo *
1237 glXChooseVisual(Display * dpy, int screen, int *attribList)
1239 XVisualInfo *visualList = NULL;
1240 struct glx_display *priv;
1241 struct glx_screen *psc;
1242 struct glx_config test_config;
1243 struct glx_config *config;
1244 struct glx_config *best_config = NULL;
1247 ** Get a list of all visuals, return if list is empty
1249 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1255 ** Build a template from the defaults and the attribute list
1256 ** Free visual list and return if an unexpected token is encountered
1258 init_fbconfig_for_chooser(&test_config, GL_FALSE);
1259 __glXInitializeVisualConfigFromTags(&test_config, 512,
1260 (const INT32 *) attribList,
1264 ** Eliminate visuals that don't meet minimum requirements
1265 ** Compute a score for those that do
1266 ** Remember which visual, if any, got the highest score
1267 ** If no visual is acceptable, return None
1268 ** Otherwise, create an XVisualInfo list with just the selected X visual
1271 for (config = psc->visuals; config != NULL; config = config->next) {
1272 if (fbconfigs_compatible(&test_config, config)
1273 && ((best_config == NULL) ||
1274 (fbconfig_compare (&config, &best_config) < 0))) {
1275 XVisualInfo visualTemplate;
1276 XVisualInfo *newList;
1279 visualTemplate.screen = screen;
1280 visualTemplate.visualid = config->visualID;
1281 newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask,
1282 &visualTemplate, &i);
1286 visualList = newList;
1287 best_config = config;
1292 #ifdef GLX_USE_APPLEGL
1293 if(visualList && getenv("LIBGL_DUMP_VISUALID")) {
1294 printf("visualid 0x%lx\n", visualList[0].visualid);
1302 _X_EXPORT const char *
1303 glXQueryExtensionsString(Display * dpy, int screen)
1305 struct glx_screen *psc;
1306 struct glx_display *priv;
1308 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1312 if (!psc->effectiveGLXexts) {
1313 if (!psc->serverGLXexts) {
1314 psc->serverGLXexts =
1315 __glXQueryServerString(dpy, priv->majorOpcode, screen,
1319 __glXCalculateUsableExtensions(psc,
1320 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1321 (psc->driScreen != NULL),
1325 priv->minorVersion);
1328 return psc->effectiveGLXexts;
1331 _X_EXPORT const char *
1332 glXGetClientString(Display * dpy, int name)
1338 return (__glXGLXClientVendorName);
1340 return (__glXGLXClientVersion);
1341 case GLX_EXTENSIONS:
1342 return (__glXGetClientExtensions());
1348 _X_EXPORT const char *
1349 glXQueryServerString(Display * dpy, int screen, int name)
1351 struct glx_screen *psc;
1352 struct glx_display *priv;
1356 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1362 str = &priv->serverGLXvendor;
1365 str = &priv->serverGLXversion;
1367 case GLX_EXTENSIONS:
1368 str = &psc->serverGLXexts;
1375 *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name);
1383 ** EXT_import_context
1387 glXGetCurrentDisplay(void)
1389 struct glx_context *gc = __glXGetCurrentContext();
1392 return gc->currentDpy;
1396 GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1397 glXGetCurrentDisplay)
1399 #ifndef GLX_USE_APPLEGL
1400 _X_EXPORT GLXContext
1401 glXImportContextEXT(Display *dpy, GLXContextID contextID)
1403 struct glx_display *priv = __glXInitialize(dpy);
1404 struct glx_screen *psc = NULL;
1405 xGLXQueryContextReply reply;
1407 struct glx_context *ctx;
1409 /* This GLX implementation knows about 5 different properties, so
1410 * allow the server to send us one of each.
1412 int propList[5 * 2], *pProp, nPropListBytes;
1416 struct glx_config *mode;
1417 uint32_t fbconfigID = 0;
1418 uint32_t visualID = 0;
1419 uint32_t screen = 0;
1420 Bool got_screen = False;
1425 /* The GLX_EXT_import_context spec says:
1427 * "If <contextID> does not refer to a valid context, then a BadContext
1428 * error is generated; if <contextID> refers to direct rendering
1429 * context then no error is generated but glXImportContextEXT returns
1432 * If contextID is None, generate BadContext on the client-side. Other
1433 * sorts of invalid contexts will be detected by the server in the
1434 * __glXIsDirect call.
1436 if (contextID == None) {
1437 __glXSendError(dpy, GLXBadContext, contextID, X_GLXIsDirect, false);
1441 if (__glXIsDirect(dpy, contextID))
1444 opcode = __glXSetupForCommand(dpy);
1448 /* Send the glXQueryContextInfoEXT request */
1451 if (priv->majorVersion > 1 || priv->minorVersion >= 3) {
1452 xGLXQueryContextReq *req;
1454 GetReq(GLXQueryContext, req);
1456 req->reqType = opcode;
1457 req->glxCode = X_GLXQueryContext;
1458 req->context = contextID;
1461 xGLXVendorPrivateReq *vpreq;
1462 xGLXQueryContextInfoEXTReq *req;
1464 GetReqExtra(GLXVendorPrivate,
1465 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1467 req = (xGLXQueryContextInfoEXTReq *) vpreq;
1468 req->reqType = opcode;
1469 req->glxCode = X_GLXVendorPrivateWithReply;
1470 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1471 req->context = contextID;
1474 _XReply(dpy, (xReply *) & reply, 0, False);
1476 if (reply.n <= __GLX_MAX_CONTEXT_PROPS)
1477 nPropListBytes = reply.n * 2 * sizeof propList[0];
1480 _XRead(dpy, (char *) propList, nPropListBytes);
1484 numProps = nPropListBytes / (2 * sizeof(propList[0]));
1487 renderType = GLX_RGBA_TYPE; /* By default, assume RGBA context */
1490 for (i = 0, pProp = propList; i < numProps; i++, pProp += 2)
1496 case GLX_SHARE_CONTEXT_EXT:
1499 case GLX_VISUAL_ID_EXT:
1500 visualID = pProp[1];
1502 case GLX_FBCONFIG_ID:
1503 fbconfigID = pProp[1];
1505 case GLX_RENDER_TYPE:
1506 renderType = pProp[1];
1513 psc = GetGLXScreenConfigs(dpy, screen);
1517 if (fbconfigID != 0) {
1518 mode = glx_config_find_fbconfig(psc->configs, fbconfigID);
1519 } else if (visualID != 0) {
1520 mode = glx_config_find_visual(psc->visuals, visualID);
1526 ctx = indirect_create_context(psc, mode, NULL, renderType);
1530 ctx->xid = contextID;
1531 ctx->imported = GL_TRUE;
1532 ctx->share_xid = share;
1534 return (GLXContext) ctx;
1540 glXQueryContext(Display * dpy, GLXContext ctx_user, int attribute, int *value)
1542 struct glx_context *ctx = (struct glx_context *) ctx_user;
1544 switch (attribute) {
1545 case GLX_SHARE_CONTEXT_EXT:
1546 *value = ctx->share_xid;
1548 case GLX_VISUAL_ID_EXT:
1549 *value = ctx->config ? ctx->config->visualID : None;
1552 *value = ctx->screen;
1554 case GLX_FBCONFIG_ID:
1555 *value = ctx->config ? ctx->config->fbconfigID : None;
1557 case GLX_RENDER_TYPE:
1558 *value = ctx->renderType;
1561 return GLX_BAD_ATTRIBUTE;
1567 GLX_ALIAS(int, glXQueryContextInfoEXT,
1568 (Display * dpy, GLXContext ctx, int attribute, int *value),
1569 (dpy, ctx, attribute, value), glXQueryContext)
1571 _X_EXPORT GLXContextID glXGetContextIDEXT(const GLXContext ctx_user)
1573 struct glx_context *ctx = (struct glx_context *) ctx_user;
1575 return (ctx == NULL) ? None : ctx->xid;
1579 glXFreeContextEXT(Display *dpy, GLXContext ctx)
1581 struct glx_context *gc = (struct glx_context *) ctx;
1583 if (gc == NULL || gc->xid == None)
1586 /* The GLX_EXT_import_context spec says:
1588 * "glXFreeContext does not free the server-side context information or
1589 * the XID associated with the server-side context."
1591 * Don't send any protocol. Just destroy the client-side tracking of the
1592 * context. Also, only release the context structure if it's not current.
1595 if (gc->currentDpy) {
1598 gc->vtable->destroy(gc);
1603 _X_EXPORT GLXFBConfig *
1604 glXChooseFBConfig(Display * dpy, int screen,
1605 const int *attribList, int *nitems)
1607 struct glx_config **config_list;
1611 config_list = (struct glx_config **)
1612 glXGetFBConfigs(dpy, screen, &list_size);
1614 if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
1615 list_size = choose_visual(config_list, list_size, attribList, GL_TRUE);
1616 if (list_size == 0) {
1622 *nitems = list_size;
1623 return (GLXFBConfig *) config_list;
1627 _X_EXPORT GLXContext
1628 glXCreateNewContext(Display * dpy, GLXFBConfig fbconfig,
1629 int renderType, GLXContext shareList, Bool allowDirect)
1631 struct glx_config *config = (struct glx_config *) fbconfig;
1633 return CreateContext(dpy, config->fbconfigID, config, shareList,
1634 allowDirect, X_GLXCreateNewContext, renderType,
1639 _X_EXPORT GLXDrawable
1640 glXGetCurrentReadDrawable(void)
1642 struct glx_context *gc = __glXGetCurrentContext();
1644 return gc->currentReadable;
1648 _X_EXPORT GLXFBConfig *
1649 glXGetFBConfigs(Display * dpy, int screen, int *nelements)
1651 struct glx_display *priv = __glXInitialize(dpy);
1652 struct glx_config **config_list = NULL;
1653 struct glx_config *config;
1654 unsigned num_configs = 0;
1658 if (priv && (priv->screens != NULL)
1659 && (screen >= 0) && (screen <= ScreenCount(dpy))
1660 && (priv->screens[screen]->configs != NULL)
1661 && (priv->screens[screen]->configs->fbconfigID
1662 != (int) GLX_DONT_CARE)) {
1664 for (config = priv->screens[screen]->configs; config != NULL;
1665 config = config->next) {
1666 if (config->fbconfigID != (int) GLX_DONT_CARE) {
1671 config_list = malloc(num_configs * sizeof *config_list);
1672 if (config_list != NULL) {
1673 *nelements = num_configs;
1675 for (config = priv->screens[screen]->configs; config != NULL;
1676 config = config->next) {
1677 if (config->fbconfigID != (int) GLX_DONT_CARE) {
1678 config_list[i] = config;
1685 return (GLXFBConfig *) config_list;
1690 glXGetFBConfigAttrib(Display * dpy, GLXFBConfig fbconfig,
1691 int attribute, int *value)
1693 struct glx_config *config = ValidateGLXFBConfig(dpy, fbconfig);
1696 return GLXBadFBConfig;
1698 return glx_config_get(config, attribute, value);
1702 _X_EXPORT XVisualInfo *
1703 glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig fbconfig)
1705 XVisualInfo visualTemplate;
1706 struct glx_config *config = (struct glx_config *) fbconfig;
1710 ** Get a list of all visuals, return if list is empty
1712 visualTemplate.visualid = config->visualID;
1713 return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
1716 #ifndef GLX_USE_APPLEGL
1718 ** GLX_SGI_swap_control
1721 __glXSwapIntervalSGI(int interval)
1723 xGLXVendorPrivateReq *req;
1724 struct glx_context *gc = __glXGetCurrentContext();
1725 struct glx_screen *psc;
1727 CARD32 *interval_ptr;
1731 return GLX_BAD_CONTEXT;
1734 if (interval <= 0) {
1735 return GLX_BAD_VALUE;
1738 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1740 #ifdef GLX_DIRECT_RENDERING
1741 if (gc->isDirect && psc && psc->driScreen &&
1742 psc->driScreen->setSwapInterval) {
1743 __GLXDRIdrawable *pdraw =
1744 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1745 psc->driScreen->setSwapInterval(pdraw, interval);
1750 dpy = gc->currentDpy;
1751 opcode = __glXSetupForCommand(dpy);
1756 /* Send the glXSwapIntervalSGI request */
1758 GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req);
1759 req->reqType = opcode;
1760 req->glxCode = X_GLXVendorPrivate;
1761 req->vendorCode = X_GLXvop_SwapIntervalSGI;
1762 req->contextTag = gc->currentContextTag;
1764 interval_ptr = (CARD32 *) (req + 1);
1765 *interval_ptr = interval;
1776 ** GLX_MESA_swap_control
1779 __glXSwapIntervalMESA(unsigned int interval)
1781 #ifdef GLX_DIRECT_RENDERING
1782 struct glx_context *gc = __glXGetCurrentContext();
1784 if (gc != NULL && gc->isDirect) {
1785 struct glx_screen *psc;
1787 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1788 if (psc && psc->driScreen && psc->driScreen->setSwapInterval) {
1789 __GLXDRIdrawable *pdraw =
1790 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1791 return psc->driScreen->setSwapInterval(pdraw, interval);
1796 return GLX_BAD_CONTEXT;
1801 __glXGetSwapIntervalMESA(void)
1803 #ifdef GLX_DIRECT_RENDERING
1804 struct glx_context *gc = __glXGetCurrentContext();
1806 if (gc != NULL && gc->isDirect) {
1807 struct glx_screen *psc;
1809 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1810 if (psc && psc->driScreen && psc->driScreen->getSwapInterval) {
1811 __GLXDRIdrawable *pdraw =
1812 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1813 return psc->driScreen->getSwapInterval(pdraw);
1823 ** GLX_SGI_video_sync
1826 __glXGetVideoSyncSGI(unsigned int *count)
1828 int64_t ust, msc, sbc;
1830 struct glx_context *gc = __glXGetCurrentContext();
1831 struct glx_screen *psc;
1832 #ifdef GLX_DIRECT_RENDERING
1833 __GLXDRIdrawable *pdraw;
1837 return GLX_BAD_CONTEXT;
1839 #ifdef GLX_DIRECT_RENDERING
1841 return GLX_BAD_CONTEXT;
1844 psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
1845 #ifdef GLX_DIRECT_RENDERING
1846 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1849 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1850 * FIXME: there should be a GLX encoding for this call. I can find no
1851 * FIXME: documentation for the GLX encoding.
1853 #ifdef GLX_DIRECT_RENDERING
1854 if (psc && psc->driScreen && psc->driScreen->getDrawableMSC) {
1855 ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
1856 *count = (unsigned) msc;
1857 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1861 return GLX_BAD_CONTEXT;
1865 __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
1867 struct glx_context *gc = __glXGetCurrentContext();
1868 struct glx_screen *psc;
1869 #ifdef GLX_DIRECT_RENDERING
1870 __GLXDRIdrawable *pdraw;
1872 int64_t ust, msc, sbc;
1875 if (divisor <= 0 || remainder < 0)
1876 return GLX_BAD_VALUE;
1879 return GLX_BAD_CONTEXT;
1881 #ifdef GLX_DIRECT_RENDERING
1883 return GLX_BAD_CONTEXT;
1886 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1887 #ifdef GLX_DIRECT_RENDERING
1888 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1891 #ifdef GLX_DIRECT_RENDERING
1892 if (psc && psc->driScreen && psc->driScreen->waitForMSC) {
1893 ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
1895 *count = (unsigned) msc;
1896 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
1900 return GLX_BAD_CONTEXT;
1903 #endif /* GLX_USE_APPLEGL */
1906 ** GLX_SGIX_fbconfig
1907 ** Many of these functions are aliased to GLX 1.3 entry points in the
1908 ** GLX_functions table.
1912 GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
1913 (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
1914 (dpy, config, attribute, value), glXGetFBConfigAttrib)
1916 _X_EXPORT GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
1917 (Display * dpy, int screen, int *attrib_list,
1918 int *nelements), (dpy, screen, attrib_list, nelements),
1921 _X_EXPORT GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
1922 (Display * dpy, GLXFBConfigSGIX config),
1923 (dpy, config), glXGetVisualFromFBConfig)
1926 glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
1927 GLXFBConfigSGIX fbconfig,
1930 #ifndef GLX_USE_APPLEGL
1931 xGLXVendorPrivateWithReplyReq *vpreq;
1932 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
1933 GLXPixmap xid = None;
1935 struct glx_screen *psc;
1937 struct glx_config *config = (struct glx_config *) fbconfig;
1940 if ((dpy == NULL) || (config == NULL)) {
1943 #ifdef GLX_USE_APPLEGL
1944 if(apple_glx_pixmap_create(dpy, config->screen, pixmap, config))
1949 psc = GetGLXScreenConfigs(dpy, config->screen);
1951 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
1952 opcode = __glXSetupForCommand(dpy);
1957 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1959 GetReqExtra(GLXVendorPrivateWithReply,
1960 sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
1961 sz_xGLXVendorPrivateWithReplyReq, vpreq);
1962 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
1963 req->reqType = opcode;
1964 req->glxCode = X_GLXVendorPrivateWithReply;
1965 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
1966 req->screen = config->screen;
1967 req->fbconfig = config->fbconfigID;
1968 req->pixmap = pixmap;
1969 req->glxpixmap = xid = XAllocID(dpy);
1978 _X_EXPORT GLXContext
1979 glXCreateContextWithConfigSGIX(Display * dpy,
1980 GLXFBConfigSGIX fbconfig, int renderType,
1981 GLXContext shareList, Bool allowDirect)
1983 GLXContext gc = NULL;
1984 struct glx_config *config = (struct glx_config *) fbconfig;
1985 struct glx_screen *psc;
1988 if ((dpy == NULL) || (config == NULL)) {
1992 psc = GetGLXScreenConfigs(dpy, config->screen);
1994 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
1995 gc = CreateContext(dpy, config->fbconfigID, config, shareList,
1997 X_GLXvop_CreateContextWithConfigSGIX, renderType,
2005 _X_EXPORT GLXFBConfigSGIX
2006 glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis)
2008 struct glx_display *priv;
2009 struct glx_screen *psc = NULL;
2011 if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) == Success)
2012 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)
2013 && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) {
2014 return (GLXFBConfigSGIX) glx_config_find_visual(psc->configs,
2021 #ifndef GLX_USE_APPLEGL
2023 ** GLX_SGIX_swap_group
2026 __glXJoinSwapGroupSGIX(Display * dpy, GLXDrawable drawable,
2036 ** GLX_SGIX_swap_barrier
2039 __glXBindSwapBarrierSGIX(Display * dpy, GLXDrawable drawable, int barrier)
2047 __glXQueryMaxSwapBarriersSGIX(Display * dpy, int screen, int *max)
2057 ** GLX_OML_sync_control
2060 __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
2061 int64_t * ust, int64_t * msc, int64_t * sbc)
2063 struct glx_display * const priv = __glXInitialize(dpy);
2065 #ifdef GLX_DIRECT_RENDERING
2066 __GLXDRIdrawable *pdraw;
2068 struct glx_screen *psc;
2073 #ifdef GLX_DIRECT_RENDERING
2074 pdraw = GetGLXDRIDrawable(dpy, drawable);
2075 psc = pdraw ? pdraw->psc : NULL;
2076 if (pdraw && psc->driScreen->getDrawableMSC) {
2077 ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
2085 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2087 __glxGetMscRate(struct glx_screen *psc,
2088 int32_t * numerator, int32_t * denominator)
2091 XF86VidModeModeLine mode_line;
2095 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2096 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
2097 unsigned n = dot_clock * 1000;
2098 unsigned d = mode_line.vtotal * mode_line.htotal;
2100 # define V_INTERLACE 0x010
2101 # define V_DBLSCAN 0x020
2103 if (mode_line.flags & V_INTERLACE)
2105 else if (mode_line.flags & V_DBLSCAN)
2108 /* The OML_sync_control spec requires that if the refresh rate is a
2109 * whole number, that the returned numerator be equal to the refresh
2110 * rate and the denominator be 1.
2118 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2120 /* This is a poor man's way to reduce a fraction. It's far from
2121 * perfect, but it will work well enough for this situation.
2124 for (i = 0; f[i] != 0; i++) {
2125 while (n % f[i] == 0 && d % f[i] == 0) {
2145 * Determine the refresh rate of the specified drawable and display.
2147 * \param dpy Display whose refresh rate is to be determined.
2148 * \param drawable Drawable whose refresh rate is to be determined.
2149 * \param numerator Numerator of the refresh rate.
2150 * \param demoninator Denominator of the refresh rate.
2151 * \return If the refresh rate for the specified display and drawable could
2152 * be calculated, True is returned. Otherwise False is returned.
2154 * \note This function is implemented entirely client-side. A lot of other
2155 * functionality is required to export GLX_OML_sync_control, so on
2156 * XFree86 this function can be called for direct-rendering contexts
2157 * when GLX_OML_sync_control appears in the client extension string.
2161 __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2162 int32_t * numerator, int32_t * denominator)
2164 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2165 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
2170 return __glxGetMscRate(draw->psc, numerator, denominator);
2182 __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
2183 int64_t target_msc, int64_t divisor, int64_t remainder)
2185 struct glx_context *gc = __glXGetCurrentContext();
2186 #ifdef GLX_DIRECT_RENDERING
2187 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2188 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
2191 if (!gc) /* no GLX for this */
2194 #ifdef GLX_DIRECT_RENDERING
2195 if (!pdraw || !gc->isDirect)
2199 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2200 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2201 * of -1 if the function failed because of errors detected in the input
2204 if (divisor < 0 || remainder < 0 || target_msc < 0)
2206 if (divisor > 0 && remainder >= divisor)
2209 if (target_msc == 0 && divisor == 0 && remainder == 0)
2212 #ifdef GLX_DIRECT_RENDERING
2213 if (psc->driScreen && psc->driScreen->swapBuffers)
2214 return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor,
2223 __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2224 int64_t target_msc, int64_t divisor,
2225 int64_t remainder, int64_t * ust,
2226 int64_t * msc, int64_t * sbc)
2228 #ifdef GLX_DIRECT_RENDERING
2229 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2230 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
2235 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2236 * error", but the return type in the spec is Bool.
2238 if (divisor < 0 || remainder < 0 || target_msc < 0)
2240 if (divisor > 0 && remainder >= divisor)
2243 #ifdef GLX_DIRECT_RENDERING
2244 if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
2245 ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
2256 __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2257 int64_t target_sbc, int64_t * ust,
2258 int64_t * msc, int64_t * sbc)
2260 #ifdef GLX_DIRECT_RENDERING
2261 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2262 struct glx_screen *psc = pdraw ? pdraw->psc : NULL;
2266 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2267 * error", but the return type in the spec is Bool.
2272 #ifdef GLX_DIRECT_RENDERING
2273 if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
2274 ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
2286 * Mesa extension stubs. These will help reduce portability problems.
2291 * Release all buffers associated with the specified GLX drawable.
2294 * This function was intended for stand-alone Mesa. The issue there is that
2295 * the library doesn't get any notification when a window is closed. In
2296 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2297 * supported, there are 3 different functions to destroy a drawable. It
2298 * should be possible to create GLX protocol (or have it determine which
2299 * protocol to use based on the type of the drawable) to have one function
2300 * do the work of 3. For the direct-rendering case, this function could
2301 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2302 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2303 * would need to be used. This really should be done as part of the new DRI
2306 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2307 * __driGarbageCollectDrawables
2308 * glXDestroyGLXPixmap
2309 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2310 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2313 __glXReleaseBuffersMESA(Display * dpy, GLXDrawable d)
2322 glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual,
2323 Pixmap pixmap, Colormap cmap)
2336 * GLX_MESA_copy_sub_buffer
2338 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2340 __glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
2341 int x, int y, int width, int height)
2343 xGLXVendorPrivateReq *req;
2344 struct glx_context *gc;
2346 CARD32 *drawable_ptr;
2347 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2350 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2351 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2352 if (pdraw != NULL) {
2353 struct glx_screen *psc = pdraw->psc;
2354 if (psc->driScreen->copySubBuffer != NULL) {
2355 (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height, True);
2362 opcode = __glXSetupForCommand(dpy);
2367 ** The calling thread may or may not have a current context. If it
2368 ** does, send the context tag so the server can do a flush.
2370 gc = __glXGetCurrentContext();
2371 if ((gc != NULL) && (dpy == gc->currentDpy) &&
2372 ((drawable == gc->currentDrawable) ||
2373 (drawable == gc->currentReadable))) {
2374 tag = gc->currentContextTag;
2381 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req);
2382 req->reqType = opcode;
2383 req->glxCode = X_GLXVendorPrivate;
2384 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2385 req->contextTag = tag;
2387 drawable_ptr = (CARD32 *) (req + 1);
2388 x_ptr = (INT32 *) (drawable_ptr + 1);
2389 y_ptr = (INT32 *) (drawable_ptr + 2);
2390 w_ptr = (INT32 *) (drawable_ptr + 3);
2391 h_ptr = (INT32 *) (drawable_ptr + 4);
2393 *drawable_ptr = drawable;
2405 __glXBindTexImageEXT(Display * dpy,
2406 GLXDrawable drawable, int buffer, const int *attrib_list)
2408 struct glx_context *gc = __glXGetCurrentContext();
2410 if (gc == NULL || gc->vtable->bind_tex_image == NULL)
2413 gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
2417 __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
2419 struct glx_context *gc = __glXGetCurrentContext();
2421 if (gc == NULL || gc->vtable->release_tex_image == NULL)
2424 gc->vtable->release_tex_image(dpy, drawable, buffer);
2429 #endif /* GLX_USE_APPLEGL */
2432 ** glXGetProcAddress support
2435 struct name_address_pair
2441 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2442 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2444 static const struct name_address_pair GLX_functions[] = {
2445 /*** GLX_VERSION_1_0 ***/
2446 GLX_FUNCTION(glXChooseVisual),
2447 GLX_FUNCTION(glXCopyContext),
2448 GLX_FUNCTION(glXCreateContext),
2449 GLX_FUNCTION(glXCreateGLXPixmap),
2450 GLX_FUNCTION(glXDestroyContext),
2451 GLX_FUNCTION(glXDestroyGLXPixmap),
2452 GLX_FUNCTION(glXGetConfig),
2453 GLX_FUNCTION(glXGetCurrentContext),
2454 GLX_FUNCTION(glXGetCurrentDrawable),
2455 GLX_FUNCTION(glXIsDirect),
2456 GLX_FUNCTION(glXMakeCurrent),
2457 GLX_FUNCTION(glXQueryExtension),
2458 GLX_FUNCTION(glXQueryVersion),
2459 GLX_FUNCTION(glXSwapBuffers),
2460 GLX_FUNCTION(glXUseXFont),
2461 GLX_FUNCTION(glXWaitGL),
2462 GLX_FUNCTION(glXWaitX),
2464 /*** GLX_VERSION_1_1 ***/
2465 GLX_FUNCTION(glXGetClientString),
2466 GLX_FUNCTION(glXQueryExtensionsString),
2467 GLX_FUNCTION(glXQueryServerString),
2469 /*** GLX_VERSION_1_2 ***/
2470 GLX_FUNCTION(glXGetCurrentDisplay),
2472 /*** GLX_VERSION_1_3 ***/
2473 GLX_FUNCTION(glXChooseFBConfig),
2474 GLX_FUNCTION(glXCreateNewContext),
2475 GLX_FUNCTION(glXCreatePbuffer),
2476 GLX_FUNCTION(glXCreatePixmap),
2477 GLX_FUNCTION(glXCreateWindow),
2478 GLX_FUNCTION(glXDestroyPbuffer),
2479 GLX_FUNCTION(glXDestroyPixmap),
2480 GLX_FUNCTION(glXDestroyWindow),
2481 GLX_FUNCTION(glXGetCurrentReadDrawable),
2482 GLX_FUNCTION(glXGetFBConfigAttrib),
2483 GLX_FUNCTION(glXGetFBConfigs),
2484 GLX_FUNCTION(glXGetSelectedEvent),
2485 GLX_FUNCTION(glXGetVisualFromFBConfig),
2486 GLX_FUNCTION(glXMakeContextCurrent),
2487 GLX_FUNCTION(glXQueryContext),
2488 GLX_FUNCTION(glXQueryDrawable),
2489 GLX_FUNCTION(glXSelectEvent),
2491 #ifndef GLX_USE_APPLEGL
2492 /*** GLX_SGI_swap_control ***/
2493 GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI),
2495 /*** GLX_SGI_video_sync ***/
2496 GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI),
2497 GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI),
2499 /*** GLX_SGI_make_current_read ***/
2500 GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent),
2501 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable),
2503 /*** GLX_EXT_import_context ***/
2504 GLX_FUNCTION(glXFreeContextEXT),
2505 GLX_FUNCTION(glXGetContextIDEXT),
2506 GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
2507 GLX_FUNCTION(glXImportContextEXT),
2508 GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
2511 /*** GLX_SGIX_fbconfig ***/
2512 GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
2513 GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig),
2514 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX),
2515 GLX_FUNCTION(glXCreateContextWithConfigSGIX),
2516 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
2517 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
2519 #ifndef GLX_USE_APPLEGL
2520 /*** GLX_SGIX_pbuffer ***/
2521 GLX_FUNCTION(glXCreateGLXPbufferSGIX),
2522 GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
2523 GLX_FUNCTION(glXQueryGLXPbufferSGIX),
2524 GLX_FUNCTION(glXSelectEventSGIX),
2525 GLX_FUNCTION(glXGetSelectedEventSGIX),
2527 /*** GLX_SGIX_swap_group ***/
2528 GLX_FUNCTION2(glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX),
2530 /*** GLX_SGIX_swap_barrier ***/
2531 GLX_FUNCTION2(glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX),
2532 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX),
2534 /*** GLX_MESA_copy_sub_buffer ***/
2535 GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA),
2537 /*** GLX_MESA_pixmap_colormap ***/
2538 GLX_FUNCTION(glXCreateGLXPixmapMESA),
2540 /*** GLX_MESA_release_buffers ***/
2541 GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA),
2543 /*** GLX_MESA_swap_control ***/
2544 GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA),
2545 GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA),
2548 /*** GLX_ARB_get_proc_address ***/
2549 GLX_FUNCTION(glXGetProcAddressARB),
2552 GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
2554 #ifndef GLX_USE_APPLEGL
2555 /*** GLX_OML_sync_control ***/
2556 GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML),
2557 GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML),
2558 GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML),
2559 GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML),
2560 GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML),
2562 /*** GLX_EXT_texture_from_pixmap ***/
2563 GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT),
2564 GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT),
2567 #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_DRM)
2568 /*** DRI configuration ***/
2569 GLX_FUNCTION(glXGetScreenDriver),
2570 GLX_FUNCTION(glXGetDriverConfig),
2573 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2574 GLX_FUNCTION(glXCreateContextAttribsARB),
2576 /*** GLX_MESA_query_renderer ***/
2577 GLX_FUNCTION(glXQueryRendererIntegerMESA),
2578 GLX_FUNCTION(glXQueryRendererStringMESA),
2579 GLX_FUNCTION(glXQueryCurrentRendererIntegerMESA),
2580 GLX_FUNCTION(glXQueryCurrentRendererStringMESA),
2582 {NULL, NULL} /* end of list */
2585 static const GLvoid *
2586 get_glx_proc_address(const char *funcName)
2590 /* try static functions */
2591 for (i = 0; GLX_functions[i].Name; i++) {
2592 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2593 return GLX_functions[i].Address;
2600 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2601 * \c glXGetProcAddress.
2603 * \param procName Name of a GL or GLX function.
2604 * \returns A pointer to the named function
2606 * \sa glXGetProcAddress
2608 _X_EXPORT void (*glXGetProcAddressARB(const GLubyte * procName)) (void)
2610 typedef void (*gl_function) (void);
2614 /* Search the table of GLX and internal functions first. If that
2615 * fails and the supplied name could be a valid core GL name, try
2616 * searching the core GL function table. This check is done to prevent
2617 * DRI based drivers from searching the core GL function table for
2618 * internal API functions.
2620 f = (gl_function) get_glx_proc_address((const char *) procName);
2621 if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2622 && (procName[2] != 'X')) {
2623 #ifdef GLX_SHARED_GLAPI
2624 f = (gl_function) __indirect_get_proc_address((const char *) procName);
2627 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2629 struct glx_context *gc = __glXGetCurrentContext();
2631 if (gc != NULL && gc->vtable->get_proc_address != NULL)
2632 f = gc->vtable->get_proc_address((const char *) procName);
2639 * Get the address of a named GL function. This is the GLX 1.4 name for
2640 * \c glXGetProcAddressARB.
2642 * \param procName Name of a GL or GLX function.
2643 * \returns A pointer to the named function
2645 * \sa glXGetProcAddressARB
2647 _X_EXPORT void (*glXGetProcAddress(const GLubyte * procName)) (void)
2648 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2649 # if defined(USE_MGL_NAMESPACE)
2650 __attribute__ ((alias("mglXGetProcAddressARB")));
2652 __attribute__ ((alias("glXGetProcAddressARB")));
2656 return glXGetProcAddressARB(procName);
2658 #endif /* __GNUC__ */
2661 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2663 * Get the unadjusted system time (UST). Currently, the UST is measured in
2664 * microseconds since Epoc. The actual resolution of the UST may vary from
2665 * system to system, and the units may vary from release to release.
2666 * Drivers should not call this function directly. They should instead use
2667 * \c glXGetProcAddress to obtain a pointer to the function.
2669 * \param ust Location to store the 64-bit UST
2670 * \returns Zero on success or a negative errno value on failure.
2672 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2674 * \since Internal API version 20030317.
2677 __glXGetUST(int64_t * ust)
2685 if (gettimeofday(&tv, NULL) == 0) {
2686 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
2693 #endif /* GLX_DIRECT_RENDERING */