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"
39 #include "glcontextmodes.h"
41 #ifdef GLX_DIRECT_RENDERING
42 #ifdef GLX_USE_APPLEGL
43 #include "apple_glx_context.h"
44 #include "apple_glx.h"
45 #include "glx_error.h"
46 #define GC_IS_DIRECT(gc) ((gc)->isDirect)
49 #include <X11/extensions/xf86vmode.h>
51 #define GC_IS_DIRECT(gc) ((gc)->driContext != NULL)
54 #define GC_IS_DIRECT(gc) (0)
58 #include <X11/Xlib-xcb.h>
63 static const char __glXGLXClientVendorName[] = "Mesa Project and SGI";
64 static const char __glXGLXClientVersion[] = "1.4";
65 static const struct glx_context_vtable indirect_context_vtable;
67 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
69 static Bool windowExistsFlag;
71 windowExistsErrorHandler(Display * dpy, XErrorEvent * xerr)
75 if (xerr->error_code == BadWindow) {
76 windowExistsFlag = GL_FALSE;
82 * Find drawables in the local hash that have been destroyed on the
85 * \param dpy Display to destroy drawables for
86 * \param screen Screen number to destroy drawables for
89 GarbageCollectDRIDrawables(__GLXscreenConfigs * sc)
92 __GLXDRIdrawable *pdraw;
93 __GLXdisplayPrivate *priv = sc->display;
94 XWindowAttributes xwa;
95 int (*oldXErrorHandler) (Display *, XErrorEvent *);
97 /* Set no-op error handler so Xlib doesn't bail out if the windows
98 * has alreay been destroyed on the server. */
99 XSync(priv->dpy, GL_FALSE);
100 oldXErrorHandler = XSetErrorHandler(windowExistsErrorHandler);
102 if (__glxHashFirst(priv->drawHash, &draw, (void *) &pdraw) == 1) {
104 windowExistsFlag = GL_TRUE;
105 XGetWindowAttributes(priv->dpy, draw, &xwa); /* dummy request */
106 if (!windowExistsFlag) {
107 /* Destroy the local drawable data, if the drawable no
108 longer exists in the Xserver */
109 (*pdraw->destroyDrawable) (pdraw);
110 __glxHashDelete(priv->drawHash, draw);
112 } while (__glxHashNext(priv->drawHash, &draw, (void *) &pdraw) == 1);
115 XSync(priv->dpy, GL_FALSE);
116 XSetErrorHandler(oldXErrorHandler);
120 * Get the __DRIdrawable for the drawable associated with a GLXContext
122 * \param dpy The display associated with \c drawable.
123 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
124 * \param scrn_num If non-NULL, the drawables screen is stored there
125 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
126 * the drawable is not associated with a direct-rendering context.
128 _X_HIDDEN __GLXDRIdrawable *
129 GetGLXDRIDrawable(Display * dpy, GLXDrawable drawable)
131 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
132 __GLXDRIdrawable *pdraw;
137 if (__glxHashLookup(priv->drawHash, drawable, (void *) &pdraw) == 0)
147 * Get the GLX per-screen data structure associated with a GLX context.
149 * \param dpy Display for which the GLX per-screen information is to be
151 * \param scrn Screen on \c dpy for which the GLX per-screen information is
153 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
154 * specify a valid GLX screen, or NULL otherwise.
156 * \todo Should this function validate that \c scrn is within the screen
157 * number range for \c dpy?
160 static __GLXscreenConfigs *
161 GetGLXScreenConfigs(Display * dpy, int scrn)
163 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
166 && priv->screenConfigs !=
167 NULL) ? priv->screenConfigs[scrn] : NULL;
172 GetGLXPrivScreenConfig(Display * dpy, int scrn, __GLXdisplayPrivate ** ppriv,
173 __GLXscreenConfigs ** ppsc)
175 /* Initialize the extension, if needed . This has the added value
176 * of initializing/allocating the display private
180 return GLX_NO_EXTENSION;
183 *ppriv = __glXInitialize(dpy);
184 if (*ppriv == NULL) {
185 return GLX_NO_EXTENSION;
188 /* Check screen number to see if its valid */
189 if ((scrn < 0) || (scrn >= ScreenCount(dpy))) {
190 return GLX_BAD_SCREEN;
193 /* Check to see if the GL is supported on this screen */
194 *ppsc = (*ppriv)->screenConfigs[scrn];
195 if ((*ppsc)->configs == NULL) {
196 /* No support for GL on this screen regardless of visual */
197 return GLX_BAD_VISUAL;
205 * Determine if a \c GLXFBConfig supplied by the application is valid.
207 * \param dpy Application supplied \c Display pointer.
208 * \param config Application supplied \c GLXFBConfig.
210 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
211 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
214 static __GLcontextModes *
215 ValidateGLXFBConfig(Display * dpy, GLXFBConfig config)
217 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
218 const unsigned num_screens = ScreenCount(dpy);
220 const __GLcontextModes *modes;
224 for (i = 0; i < num_screens; i++) {
225 for (modes = priv->screenConfigs[i]->configs; modes != NULL;
226 modes = modes->next) {
227 if (modes == (__GLcontextModes *) config) {
228 return (__GLcontextModes *) config;
237 #ifdef GLX_USE_APPLEGL
239 static const struct glx_context_vtable applegl_context_vtable;
242 applegl_create_context(__GLXscreenConfigs *psc,
243 const __GLcontextModes *mode,
244 GLXContext shareList, int renderType)
250 /* TODO: Integrate this with apple_glx_create_context and make
251 * struct apple_glx_context inherit from __GLXcontext. */
253 gc = Xmalloc(sizeof *gc);
257 memset(gc, 0, sizeof *gc);
258 if (!glx_context_init(&gc->base, &psc->base, mode)) {
263 gc->vtable = &applegl_context_vtable;
264 gc->driContext = NULL;
265 gc->do_destroy = False;
267 /* TODO: darwin: Integrate with above to do indirect */
268 if(apple_glx_create_context(&gc->driContext, dpy, screen, fbconfig,
269 shareList ? shareList->driContext : NULL,
270 &errorcode, &x11error)) {
271 __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error);
272 gc->vtable->destroy(gc);
276 gc->currentContextTag = -1;
278 gc->isDirect = allowDirect;
279 gc->xid = 1; /* Just something not None, so we know when to destroy
280 * it in MakeContextCurrent. */
288 * \todo It should be possible to move the allocate of \c client_state_private
289 * later in the function for direct-rendering contexts. Direct-rendering
290 * contexts don't need to track client state, so they don't need that memory
293 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
294 * function called \c __glXAllocateClientState that allocates the memory and
295 * does all the initialization (including the pixel pack / unpack).
298 indirect_create_context(__GLXscreenConfigs *psc,
299 const __GLcontextModes *mode,
300 GLXContext shareList, int renderType)
305 __GLXattribute *state;
307 opcode = __glXSetupForCommand(psc->dpy);
312 /* Allocate our context record */
313 gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec));
318 memset(gc, 0, sizeof(struct __GLXcontextRec));
320 glx_context_init(gc, psc, mode);
321 gc->isDirect = GL_FALSE;
322 gc->vtable = &indirect_context_vtable;
323 state = Xmalloc(sizeof(struct __GLXattributeRec));
329 gc->client_state_private = state;
330 memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec));
331 state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL);
334 ** Create a temporary buffer to hold GLX rendering commands. The size
335 ** of the buffer is selected so that the maximum number of GLX rendering
336 ** commands can fit in a single X packet and still have room in the X
337 ** packet for the GLXRenderReq header.
340 bufSize = (XMaxRequestSize(psc->dpy) * 4) - sz_xGLXRenderReq;
341 gc->buf = (GLubyte *) Xmalloc(bufSize);
343 Xfree(gc->client_state_private);
347 gc->bufSize = bufSize;
349 /* Fill in the new context */
350 gc->renderMode = GL_RENDER;
352 state->storePack.alignment = 4;
353 state->storeUnpack.alignment = 4;
355 gc->attributes.stackPointer = &gc->attributes.stack[0];
358 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
359 ** Other code uses the fastImageUnpack bit, but it is never set
362 gc->fastImageUnpack = GL_FALSE;
363 gc->fillImage = __glFillImage;
365 gc->bufEnd = gc->buf + bufSize;
366 gc->isDirect = GL_FALSE;
369 ** Set limit register so that there will be one command per packet
374 gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE;
376 gc->majorOpcode = opcode;
379 ** Constrain the maximum drawing command size allowed to be
380 ** transfered using the X_GLXRender protocol request. First
381 ** constrain by a software limit, then constrain by the protocl
384 if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) {
385 bufSize = __GLX_RENDER_CMD_SIZE_LIMIT;
387 if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) {
388 bufSize = __GLX_MAX_RENDER_CMD_SIZE;
390 gc->maxSmallRenderCommandSize = bufSize;
396 struct glx_screen_vtable indirect_screen_vtable = {
397 indirect_create_context
400 _X_HIDDEN __GLXscreenConfigs *
401 indirect_create_screen(int screen, __GLXdisplayPrivate * priv)
403 __GLXscreenConfigs *psc;
405 psc = Xmalloc(sizeof *psc);
409 memset(psc, 0, sizeof *psc);
410 glx_screen_init(psc, screen, priv);
411 psc->vtable = &indirect_screen_vtable;
418 glx_context_init(__GLXcontext *gc,
419 __GLXscreenConfigs *psc, const __GLcontextModes *fbconfig)
421 gc->majorOpcode = __glXSetupForCommand(psc->display->dpy);
422 if (!gc->majorOpcode)
425 gc->screen = psc->scr;
428 gc->isDirect = GL_TRUE;
435 * Create a new context. Exactly one of \c vis and \c fbconfig should be
438 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
439 * SGIX_fbconfig protocol be used?
440 * \param renderType For FBConfigs, what is the rendering type?
444 CreateContext(Display * dpy, int generic_id,
445 const __GLcontextModes * const fbconfig,
446 GLXContext shareList,
448 unsigned code, int renderType, int screen)
450 GLXContext gc = NULL;
451 __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
456 if (generic_id == None)
460 if (allowDirect && psc->vtable->create_context)
461 gc = psc->vtable->create_context(psc, fbconfig,
462 shareList, renderType);
464 gc = indirect_create_context(psc, fbconfig, shareList, renderType);
470 case X_GLXCreateContext: {
471 xGLXCreateContextReq *req;
473 /* Send the glXCreateContext request */
474 GetReq(GLXCreateContext, req);
475 req->reqType = gc->majorOpcode;
476 req->glxCode = X_GLXCreateContext;
477 req->context = gc->xid = XAllocID(dpy);
478 req->visual = generic_id;
479 req->screen = screen;
480 req->shareList = shareList ? shareList->xid : None;
481 req->isDirect = GC_IS_DIRECT(gc);
485 case X_GLXCreateNewContext: {
486 xGLXCreateNewContextReq *req;
488 /* Send the glXCreateNewContext request */
489 GetReq(GLXCreateNewContext, req);
490 req->reqType = gc->majorOpcode;
491 req->glxCode = X_GLXCreateNewContext;
492 req->context = gc->xid = XAllocID(dpy);
493 req->fbconfig = generic_id;
494 req->screen = screen;
495 req->renderType = renderType;
496 req->shareList = shareList ? shareList->xid : None;
497 req->isDirect = GC_IS_DIRECT(gc);
501 case X_GLXvop_CreateContextWithConfigSGIX: {
502 xGLXVendorPrivateWithReplyReq *vpreq;
503 xGLXCreateContextWithConfigSGIXReq *req;
505 /* Send the glXCreateNewContext request */
506 GetReqExtra(GLXVendorPrivateWithReply,
507 sz_xGLXCreateContextWithConfigSGIXReq -
508 sz_xGLXVendorPrivateWithReplyReq, vpreq);
509 req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
510 req->reqType = gc->majorOpcode;
511 req->glxCode = X_GLXVendorPrivateWithReply;
512 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
513 req->context = gc->xid = XAllocID(dpy);
514 req->fbconfig = generic_id;
515 req->screen = screen;
516 req->renderType = renderType;
517 req->shareList = shareList ? shareList->xid : None;
518 req->isDirect = GC_IS_DIRECT(gc);
523 /* What to do here? This case is the sign of an internal error. It
524 * should never be reachable.
532 gc->imported = GL_FALSE;
533 gc->renderType = renderType;
539 glXCreateContext(Display * dpy, XVisualInfo * vis,
540 GLXContext shareList, Bool allowDirect)
542 const __GLcontextModes *mode = NULL;
545 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
546 __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, vis->screen);
548 mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
552 error.errorCode = BadValue;
553 error.resourceID = vis->visualid;
554 error.sequenceNumber = dpy->request;
555 error.type = X_Error;
556 error.majorCode = __glXSetupForCommand(dpy);
557 error.minorCode = X_GLXCreateContext;
558 _XError(dpy, &error);
562 renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE;
565 return CreateContext(dpy, vis->visualid, mode, shareList, allowDirect,
566 X_GLXCreateContext, renderType, vis->screen);
570 glx_send_destroy_context(Display *dpy, XID xid)
572 CARD8 opcode = __glXSetupForCommand(dpy);
573 xGLXDestroyContextReq *req;
576 GetReq(GLXDestroyContext, req);
577 req->reqType = opcode;
578 req->glxCode = X_GLXDestroyContext;
585 indirect_destroy_context(__GLXcontext *gc)
587 if (!gc->imported && gc->xid)
588 glx_send_destroy_context(gc->psc->dpy, gc->xid);
590 __glXFreeVertexArrayState(gc);
593 XFree((char *) gc->vendor);
595 XFree((char *) gc->renderer);
597 XFree((char *) gc->version);
599 XFree((char *) gc->extensions);
600 __glFreeAttributeState(gc);
601 XFree((char *) gc->buf);
602 Xfree((char *) gc->client_state_private);
607 ** Destroy the named context
610 DestroyContext(Display * dpy, GLXContext gc)
616 if (gc->currentDpy) {
617 /* This context is bound to some thread. According to the man page,
618 * we should not actually delete the context until it's unbound.
619 * Note that we set gc->xid = None above. In MakeContextCurrent()
620 * we check for that and delete the context there.
623 glx_send_destroy_context(dpy, gc->xid);
630 if (gc->vtable->destroy)
631 gc->vtable->destroy(gc);
635 glXDestroyContext(Display * dpy, GLXContext gc)
637 DestroyContext(dpy, gc);
641 ** Return the major and minor version #s for the GLX extension
644 glXQueryVersion(Display * dpy, int *major, int *minor)
646 __GLXdisplayPrivate *priv;
648 /* Init the extension. This fetches the major and minor version. */
649 priv = __glXInitialize(dpy);
654 *major = priv->majorVersion;
656 *minor = priv->minorVersion;
661 ** Query the existance of the GLX extension
664 glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
666 int major_op, erb, evb;
669 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
680 indirect_wait_gl(__GLXcontext *gc)
683 Display *dpy = gc->currentDpy;
685 /* Flush any pending commands out */
686 __glXFlushRenderBuffer(gc, gc->pc);
688 /* Send the glXWaitGL request */
690 GetReq(GLXWaitGL, req);
691 req->reqType = gc->majorOpcode;
692 req->glxCode = X_GLXWaitGL;
693 req->contextTag = gc->currentContextTag;
699 ** Put a barrier in the token stream that forces the GL to finish its
700 ** work before X can proceed.
705 GLXContext gc = __glXGetCurrentContext();
707 if (gc && gc->vtable->use_x_font)
708 gc->vtable->wait_gl(gc);
712 indirect_wait_x(__GLXcontext *gc)
715 Display *dpy = gc->currentDpy;
717 /* Flush any pending commands out */
718 __glXFlushRenderBuffer(gc, gc->pc);
721 GetReq(GLXWaitX, req);
722 req->reqType = gc->majorOpcode;
723 req->glxCode = X_GLXWaitX;
724 req->contextTag = gc->currentContextTag;
730 ** Put a barrier in the token stream that forces X to finish its
731 ** work before GL can proceed.
736 GLXContext gc = __glXGetCurrentContext();
738 if (gc && gc->vtable->use_x_font)
739 gc->vtable->wait_x(gc);
743 indirect_use_x_font(__GLXcontext *gc,
744 Font font, int first, int count, int listBase)
746 xGLXUseXFontReq *req;
747 Display *dpy = gc->currentDpy;
749 /* Flush any pending commands out */
750 __glXFlushRenderBuffer(gc, gc->pc);
752 /* Send the glXUseFont request */
754 GetReq(GLXUseXFont, req);
755 req->reqType = gc->majorOpcode;
756 req->glxCode = X_GLXUseXFont;
757 req->contextTag = gc->currentContextTag;
761 req->listBase = listBase;
766 #ifdef GLX_USE_APPLEGL
769 applegl_destroy_context(__GLXcontext *gc)
771 apple_glx_destroy_context(&gc->driContext, gc->currentDpy);
775 applegl_wait_gl(__GLXcontext *gc)
781 applegl_wait_x(__GLXcontext *gc)
783 apple_glx_waitx(gc->dpy, gc->driContext);
786 static const struct glx_context_vtable applegl_context_vtable = {
787 applegl_destroy_context,
791 NULL, /* bind_tex_image, */
792 NULL, /* release_tex_image, */
798 glXUseXFont(Font font, int first, int count, int listBase)
800 GLXContext gc = __glXGetCurrentContext();
802 if (gc && gc->vtable->use_x_font)
803 gc->vtable->use_x_font(gc, font, first, count, listBase);
806 /************************************************************************/
809 ** Copy the source context to the destination context using the
813 glXCopyContext(Display * dpy, GLXContext source,
814 GLXContext dest, unsigned long mask)
816 #ifdef GLX_USE_APPLEGL
817 GLXContext gc = __glXGetCurrentContext();
821 if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
822 mask, &errorcode, &x11error)) {
823 __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
827 xGLXCopyContextReq *req;
828 GLXContext gc = __glXGetCurrentContext();
832 opcode = __glXSetupForCommand(dpy);
837 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
838 if (gc->driContext) {
839 /* NOT_DONE: This does not work yet */
844 ** If the source is the current context, send its tag so that the context
845 ** can be flushed before the copy.
847 if (source == gc && dpy == gc->currentDpy) {
848 tag = gc->currentContextTag;
854 /* Send the glXCopyContext request */
856 GetReq(GLXCopyContext, req);
857 req->reqType = opcode;
858 req->glxCode = X_GLXCopyContext;
859 req->source = source ? source->xid : None;
860 req->dest = dest ? dest->xid : None;
862 req->contextTag = tag;
865 #endif /* GLX_USE_APPLEGL */
870 * Determine if a context uses direct rendering.
872 * \param dpy Display where the context was created.
873 * \param contextID ID of the context to be tested.
875 * \returns \c GL_TRUE if the context is direct rendering or not.
878 __glXIsDirect(Display * dpy, GLXContextID contextID)
880 #if !defined(USE_XCB)
881 xGLXIsDirectReq *req;
882 xGLXIsDirectReply reply;
886 opcode = __glXSetupForCommand(dpy);
892 xcb_connection_t *c = XGetXCBConnection(dpy);
893 xcb_glx_is_direct_reply_t *reply = xcb_glx_is_direct_reply(c,
898 const Bool is_direct = reply->is_direct ? True : False;
903 /* Send the glXIsDirect request */
905 GetReq(GLXIsDirect, req);
906 req->reqType = opcode;
907 req->glxCode = X_GLXIsDirect;
908 req->context = contextID;
909 _XReply(dpy, (xReply *) & reply, 0, False);
913 return reply.isDirect;
919 * Shouldn't this function \b always return \c GL_FALSE when
920 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
921 * the GLX protocol here at all?
924 glXIsDirect(Display * dpy, GLXContext gc)
929 else if (GC_IS_DIRECT(gc)) {
932 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
935 return __glXIsDirect(dpy, gc->xid);
940 glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
942 #ifdef GLX_USE_APPLEGL
943 int screen = vis->screen;
944 __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
945 const __GLcontextModes *modes;
947 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
949 if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, modes))
954 xGLXCreateGLXPixmapReq *req;
958 opcode = __glXSetupForCommand(dpy);
963 /* Send the glXCreateGLXPixmap request */
965 GetReq(GLXCreateGLXPixmap, req);
966 req->reqType = opcode;
967 req->glxCode = X_GLXCreateGLXPixmap;
968 req->screen = vis->screen;
969 req->visual = vis->visualid;
970 req->pixmap = pixmap;
971 req->glxpixmap = xid = XAllocID(dpy);
975 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
977 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
978 * is actually bound to a context... */
980 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
981 __GLXDRIdrawable *pdraw;
982 __GLXscreenConfigs *psc;
983 __GLcontextModes *modes;
985 psc = priv->screenConfigs[vis->screen];
986 if (psc->driScreen == NULL)
988 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
989 pdraw = psc->driScreen->createDrawable(psc, pixmap, req->glxpixmap, modes);
991 fprintf(stderr, "failed to create pixmap\n");
995 if (__glxHashInsert(priv->drawHash, req->glxpixmap, pdraw)) {
996 (*pdraw->destroyDrawable) (pdraw);
997 return None; /* FIXME: Check what we're supposed to do here... */
1007 ** Destroy the named pixmap
1010 glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
1012 #ifdef GLX_USE_APPLEGL
1013 if(apple_glx_pixmap_destroy(dpy, glxpixmap))
1014 __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
1016 xGLXDestroyGLXPixmapReq *req;
1019 opcode = __glXSetupForCommand(dpy);
1024 /* Send the glXDestroyGLXPixmap request */
1026 GetReq(GLXDestroyGLXPixmap, req);
1027 req->reqType = opcode;
1028 req->glxCode = X_GLXDestroyGLXPixmap;
1029 req->glxpixmap = glxpixmap;
1033 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1035 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
1036 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
1038 if (pdraw != NULL) {
1039 (*pdraw->destroyDrawable) (pdraw);
1040 __glxHashDelete(priv->drawHash, glxpixmap);
1044 #endif /* GLX_USE_APPLEGL */
1048 glXSwapBuffers(Display * dpy, GLXDrawable drawable)
1050 #ifdef GLX_USE_APPLEGL
1051 GLXContext gc = glXGetCurrentContext();
1052 if(gc && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
1053 apple_glx_swap_buffers(gc->driContext);
1055 __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
1062 xcb_connection_t *c;
1064 xGLXSwapBuffersReq *req;
1067 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1068 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
1070 if (pdraw != NULL) {
1072 (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0);
1077 opcode = __glXSetupForCommand(dpy);
1083 ** The calling thread may or may not have a current context. If it
1084 ** does, send the context tag so the server can do a flush.
1086 gc = __glXGetCurrentContext();
1087 if ((gc != NULL) && (dpy == gc->currentDpy) &&
1088 ((drawable == gc->currentDrawable)
1089 || (drawable == gc->currentReadable))) {
1090 tag = gc->currentContextTag;
1097 c = XGetXCBConnection(dpy);
1098 xcb_glx_swap_buffers(c, tag, drawable);
1101 /* Send the glXSwapBuffers request */
1103 GetReq(GLXSwapBuffers, req);
1104 req->reqType = opcode;
1105 req->glxCode = X_GLXSwapBuffers;
1106 req->drawable = drawable;
1107 req->contextTag = tag;
1111 #endif /* USE_XCB */
1112 #endif /* GLX_USE_APPLEGL */
1117 ** Return configuration information for the given display, screen and
1118 ** visual combination.
1121 glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
1124 __GLXdisplayPrivate *priv;
1125 __GLXscreenConfigs *psc;
1126 __GLcontextModes *modes;
1129 status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
1130 if (status == Success) {
1131 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
1133 /* Lookup attribute after first finding a match on the visual */
1134 if (modes != NULL) {
1135 return _gl_get_context_mode_data(modes, attribute, value_return);
1138 status = GLX_BAD_VISUAL;
1142 ** If we can't find the config for this visual, this visual is not
1143 ** supported by the OpenGL implementation on the server.
1145 if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
1146 *value_return = GL_FALSE;
1153 /************************************************************************/
1156 init_fbconfig_for_chooser(__GLcontextModes * config,
1157 GLboolean fbconfig_style_tags)
1159 memset(config, 0, sizeof(__GLcontextModes));
1160 config->visualID = (XID) GLX_DONT_CARE;
1161 config->visualType = GLX_DONT_CARE;
1163 /* glXChooseFBConfig specifies different defaults for these two than
1166 if (fbconfig_style_tags) {
1167 config->rgbMode = GL_TRUE;
1168 config->doubleBufferMode = GLX_DONT_CARE;
1171 config->visualRating = GLX_DONT_CARE;
1172 config->transparentPixel = GLX_NONE;
1173 config->transparentRed = GLX_DONT_CARE;
1174 config->transparentGreen = GLX_DONT_CARE;
1175 config->transparentBlue = GLX_DONT_CARE;
1176 config->transparentAlpha = GLX_DONT_CARE;
1177 config->transparentIndex = GLX_DONT_CARE;
1179 config->drawableType = GLX_WINDOW_BIT;
1180 config->renderType =
1181 (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
1182 config->xRenderable = GLX_DONT_CARE;
1183 config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
1185 config->swapMethod = GLX_DONT_CARE;
1188 #define MATCH_DONT_CARE( param ) \
1190 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1191 && (a-> param != b-> param) ) { \
1196 #define MATCH_MINIMUM( param ) \
1198 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1199 && (a-> param > b-> param) ) { \
1204 #define MATCH_EXACT( param ) \
1206 if ( a-> param != b-> param) { \
1211 /* Test that all bits from a are contained in b */
1212 #define MATCH_MASK(param) \
1214 if ((a->param & ~b->param) != 0) \
1219 * Determine if two GLXFBConfigs are compatible.
1221 * \param a Application specified config to test.
1222 * \param b Server specified config to test against \c a.
1225 fbconfigs_compatible(const __GLcontextModes * const a,
1226 const __GLcontextModes * const b)
1228 MATCH_DONT_CARE(doubleBufferMode);
1229 MATCH_DONT_CARE(visualType);
1230 MATCH_DONT_CARE(visualRating);
1231 MATCH_DONT_CARE(xRenderable);
1232 MATCH_DONT_CARE(fbconfigID);
1233 MATCH_DONT_CARE(swapMethod);
1235 MATCH_MINIMUM(rgbBits);
1236 MATCH_MINIMUM(numAuxBuffers);
1237 MATCH_MINIMUM(redBits);
1238 MATCH_MINIMUM(greenBits);
1239 MATCH_MINIMUM(blueBits);
1240 MATCH_MINIMUM(alphaBits);
1241 MATCH_MINIMUM(depthBits);
1242 MATCH_MINIMUM(stencilBits);
1243 MATCH_MINIMUM(accumRedBits);
1244 MATCH_MINIMUM(accumGreenBits);
1245 MATCH_MINIMUM(accumBlueBits);
1246 MATCH_MINIMUM(accumAlphaBits);
1247 MATCH_MINIMUM(sampleBuffers);
1248 MATCH_MINIMUM(maxPbufferWidth);
1249 MATCH_MINIMUM(maxPbufferHeight);
1250 MATCH_MINIMUM(maxPbufferPixels);
1251 MATCH_MINIMUM(samples);
1253 MATCH_DONT_CARE(stereoMode);
1256 MATCH_MASK(drawableType);
1257 MATCH_MASK(renderType);
1259 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1260 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1261 * Technically speaking, it is a bug in the DDX driver, but there is
1262 * enough of an installed base to work around the problem here. In any
1263 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1264 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1265 * 0 from the server to be a match to maintain backward compatibility with
1266 * the (broken) drivers.
1269 if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) {
1270 if (a->transparentPixel == GLX_NONE) {
1271 if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0)
1275 MATCH_EXACT(transparentPixel);
1278 switch (a->transparentPixel) {
1279 case GLX_TRANSPARENT_RGB:
1280 MATCH_DONT_CARE(transparentRed);
1281 MATCH_DONT_CARE(transparentGreen);
1282 MATCH_DONT_CARE(transparentBlue);
1283 MATCH_DONT_CARE(transparentAlpha);
1286 case GLX_TRANSPARENT_INDEX:
1287 MATCH_DONT_CARE(transparentIndex);
1299 /* There's some trickly language in the GLX spec about how this is supposed
1300 * to work. Basically, if a given component size is either not specified
1301 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1302 * Well, that's really hard to do with the code as-is. This behavior is
1303 * closer to correct, but still not technically right.
1305 #define PREFER_LARGER_OR_ZERO(comp) \
1307 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1308 if ( ((*a)-> comp) == 0 ) { \
1311 else if ( ((*b)-> comp) == 0 ) { \
1315 return ((*b)-> comp) - ((*a)-> comp) ; \
1320 #define PREFER_LARGER(comp) \
1322 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1323 return ((*b)-> comp) - ((*a)-> comp) ; \
1327 #define PREFER_SMALLER(comp) \
1329 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1330 return ((*a)-> comp) - ((*b)-> comp) ; \
1335 * Compare two GLXFBConfigs. This function is intended to be used as the
1336 * compare function passed in to qsort.
1338 * \returns If \c a is a "better" config, according to the specification of
1339 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1340 * better, then a number greater than zero is return. If both are
1341 * equal, zero is returned.
1342 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1345 fbconfig_compare(const __GLcontextModes * const *const a,
1346 const __GLcontextModes * const *const b)
1348 /* The order of these comparisons must NOT change. It is defined by
1349 * the GLX 1.3 spec and ARB_multisample.
1352 PREFER_SMALLER(visualSelectGroup);
1354 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1355 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1356 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1358 PREFER_SMALLER(visualRating);
1360 /* This isn't quite right. It is supposed to compare the sum of the
1361 * components the user specifically set minimums for.
1363 PREFER_LARGER_OR_ZERO(redBits);
1364 PREFER_LARGER_OR_ZERO(greenBits);
1365 PREFER_LARGER_OR_ZERO(blueBits);
1366 PREFER_LARGER_OR_ZERO(alphaBits);
1368 PREFER_SMALLER(rgbBits);
1370 if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) {
1371 /* Prefer single-buffer.
1373 return (!(*a)->doubleBufferMode) ? -1 : 1;
1376 PREFER_SMALLER(numAuxBuffers);
1378 PREFER_LARGER_OR_ZERO(depthBits);
1379 PREFER_SMALLER(stencilBits);
1381 /* This isn't quite right. It is supposed to compare the sum of the
1382 * components the user specifically set minimums for.
1384 PREFER_LARGER_OR_ZERO(accumRedBits);
1385 PREFER_LARGER_OR_ZERO(accumGreenBits);
1386 PREFER_LARGER_OR_ZERO(accumBlueBits);
1387 PREFER_LARGER_OR_ZERO(accumAlphaBits);
1389 PREFER_SMALLER(visualType);
1391 /* None of the multisample specs say where this comparison should happen,
1392 * so I put it near the end.
1394 PREFER_SMALLER(sampleBuffers);
1395 PREFER_SMALLER(samples);
1397 /* None of the pbuffer or fbconfig specs say that this comparison needs
1398 * to happen at all, but it seems like it should.
1400 PREFER_LARGER(maxPbufferWidth);
1401 PREFER_LARGER(maxPbufferHeight);
1402 PREFER_LARGER(maxPbufferPixels);
1409 * Selects and sorts a subset of the supplied configs based on the attributes.
1410 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1411 * and \c glXChooseFBConfigSGIX.
1413 * \param configs Array of pointers to possible configs. The elements of
1414 * this array that do not meet the criteria will be set to
1415 * NULL. The remaining elements will be sorted according to
1416 * the various visual / FBConfig selection rules.
1417 * \param num_configs Number of elements in the \c configs array.
1418 * \param attribList Attributes used select from \c configs. This array is
1419 * terminated by a \c None tag. The array can either take
1420 * the form expected by \c glXChooseVisual (where boolean
1421 * tags do not have a value) or by \c glXChooseFBConfig
1422 * (where every tag has a value).
1423 * \param fbconfig_style_tags Selects whether \c attribList is in
1424 * \c glXChooseVisual style or
1425 * \c glXChooseFBConfig style.
1426 * \returns The number of valid elements left in \c configs.
1428 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1431 choose_visual(__GLcontextModes ** configs, int num_configs,
1432 const int *attribList, GLboolean fbconfig_style_tags)
1434 __GLcontextModes test_config;
1438 /* This is a fairly direct implementation of the selection method
1439 * described by GLX_SGIX_fbconfig. Start by culling out all the
1440 * configs that are not compatible with the selected parameter
1444 init_fbconfig_for_chooser(&test_config, fbconfig_style_tags);
1445 __glXInitializeVisualConfigFromTags(&test_config, 512,
1446 (const INT32 *) attribList,
1447 GL_TRUE, fbconfig_style_tags);
1450 for (i = 0; i < num_configs; i++) {
1451 if (fbconfigs_compatible(&test_config, configs[i])) {
1452 configs[base] = configs[i];
1461 if (base < num_configs) {
1462 (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base));
1465 /* After the incompatible configs are removed, the resulting
1466 * list is sorted according to the rules set out in the various
1470 qsort(configs, base, sizeof(__GLcontextModes *),
1471 (int (*)(const void *, const void *)) fbconfig_compare);
1479 ** Return the visual that best matches the template. Return None if no
1480 ** visual matches the template.
1482 PUBLIC XVisualInfo *
1483 glXChooseVisual(Display * dpy, int screen, int *attribList)
1485 XVisualInfo *visualList = NULL;
1486 __GLXdisplayPrivate *priv;
1487 __GLXscreenConfigs *psc;
1488 __GLcontextModes test_config;
1489 __GLcontextModes *modes;
1490 const __GLcontextModes *best_config = NULL;
1493 ** Get a list of all visuals, return if list is empty
1495 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1501 ** Build a template from the defaults and the attribute list
1502 ** Free visual list and return if an unexpected token is encountered
1504 init_fbconfig_for_chooser(&test_config, GL_FALSE);
1505 __glXInitializeVisualConfigFromTags(&test_config, 512,
1506 (const INT32 *) attribList,
1510 ** Eliminate visuals that don't meet minimum requirements
1511 ** Compute a score for those that do
1512 ** Remember which visual, if any, got the highest score
1513 ** If no visual is acceptable, return None
1514 ** Otherwise, create an XVisualInfo list with just the selected X visual
1517 for (modes = psc->visuals; modes != NULL; modes = modes->next) {
1518 if (fbconfigs_compatible(&test_config, modes)
1519 && ((best_config == NULL)
1522 ((const __GLcontextModes * const *const) &modes,
1523 &best_config) < 0))) {
1524 XVisualInfo visualTemplate;
1525 XVisualInfo *newList;
1528 visualTemplate.screen = screen;
1529 visualTemplate.visualid = modes->visualID;
1530 newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask,
1531 &visualTemplate, &i);
1535 visualList = newList;
1536 best_config = modes;
1541 #ifdef GLX_USE_APPLEGL
1542 if(visualList && getenv("LIBGL_DUMP_VISUALID")) {
1543 printf("visualid 0x%lx\n", visualList[0].visualid);
1552 glXQueryExtensionsString(Display * dpy, int screen)
1554 __GLXscreenConfigs *psc;
1555 __GLXdisplayPrivate *priv;
1557 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1561 if (!psc->effectiveGLXexts) {
1562 if (!psc->serverGLXexts) {
1563 psc->serverGLXexts =
1564 __glXQueryServerString(dpy, priv->majorOpcode, screen,
1568 __glXCalculateUsableExtensions(psc,
1569 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1570 (psc->driScreen != NULL),
1574 priv->minorVersion);
1577 return psc->effectiveGLXexts;
1581 glXGetClientString(Display * dpy, int name)
1587 return (__glXGLXClientVendorName);
1589 return (__glXGLXClientVersion);
1590 case GLX_EXTENSIONS:
1591 return (__glXGetClientExtensions());
1598 glXQueryServerString(Display * dpy, int screen, int name)
1600 __GLXscreenConfigs *psc;
1601 __GLXdisplayPrivate *priv;
1605 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1611 str = &priv->serverGLXvendor;
1614 str = &priv->serverGLXversion;
1616 case GLX_EXTENSIONS:
1617 str = &psc->serverGLXexts;
1624 *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name);
1631 __glXClientInfo(Display * dpy, int opcode)
1633 char *ext_str = __glXGetClientGLExtensionString();
1634 int size = strlen(ext_str) + 1;
1637 xcb_connection_t *c = XGetXCBConnection(dpy);
1638 xcb_glx_client_info(c,
1639 GLX_MAJOR_VERSION, GLX_MINOR_VERSION, size, ext_str);
1641 xGLXClientInfoReq *req;
1643 /* Send the glXClientInfo request */
1645 GetReq(GLXClientInfo, req);
1646 req->reqType = opcode;
1647 req->glxCode = X_GLXClientInfo;
1648 req->major = GLX_MAJOR_VERSION;
1649 req->minor = GLX_MINOR_VERSION;
1651 req->length += (size + 3) >> 2;
1652 req->numbytes = size;
1653 Data(dpy, ext_str, size);
1657 #endif /* USE_XCB */
1664 ** EXT_import_context
1668 glXGetCurrentDisplay(void)
1670 GLXContext gc = __glXGetCurrentContext();
1673 return gc->currentDpy;
1677 GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1678 glXGetCurrentDisplay)
1680 #ifndef GLX_USE_APPLEGL
1682 glXImportContextEXT(Display *dpy, GLXContextID contextID)
1684 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1685 __GLXscreenConfigs *psc;
1686 xGLXQueryContextReply reply;
1689 int propList[__GLX_MAX_CONTEXT_PROPS * 2], *pProp, nPropListBytes;
1692 __GLcontextModes *mode;
1694 if (contextID == None || __glXIsDirect(dpy, contextID))
1697 opcode = __glXSetupForCommand(dpy);
1701 /* Send the glXQueryContextInfoEXT request */
1704 if (priv->majorVersion > 1 || priv->minorVersion >= 3) {
1705 xGLXQueryContextReq *req;
1707 GetReq(GLXQueryContext, req);
1709 req->reqType = opcode;
1710 req->glxCode = X_GLXQueryContext;
1711 req->context = contextID;
1714 xGLXVendorPrivateReq *vpreq;
1715 xGLXQueryContextInfoEXTReq *req;
1717 GetReqExtra(GLXVendorPrivate,
1718 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1720 req = (xGLXQueryContextInfoEXTReq *) vpreq;
1721 req->reqType = opcode;
1722 req->glxCode = X_GLXVendorPrivateWithReply;
1723 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1724 req->context = contextID;
1727 _XReply(dpy, (xReply *) & reply, 0, False);
1729 if (reply.n <= __GLX_MAX_CONTEXT_PROPS)
1730 nPropListBytes = reply.n * 2 * sizeof propList[0];
1733 _XRead(dpy, (char *) propList, nPropListBytes);
1737 /* Look up screen first so we can look up visuals/fbconfigs later */
1739 for (i = 0, pProp = propList; i < reply.n; i++, pProp += 2)
1740 if (pProp[0] == GLX_SCREEN)
1741 psc = GetGLXScreenConfigs(dpy, pProp[1]);
1750 for (i = 0, pProp = propList; i < reply.n; i++, pProp += 2)
1752 case GLX_SHARE_CONTEXT_EXT:
1755 case GLX_VISUAL_ID_EXT:
1756 mode = _gl_context_modes_find_visual(psc->visuals, pProp[1]);
1758 case GLX_FBCONFIG_ID:
1759 mode = _gl_context_modes_find_fbconfig(psc->configs, pProp[1]);
1761 case GLX_RENDER_TYPE:
1762 renderType = pProp[1];
1769 ctx = indirect_create_context(psc, mode, NULL, renderType);
1773 ctx->xid = contextID;
1774 ctx->imported = GL_TRUE;
1775 ctx->share_xid = share;
1783 glXQueryContext(Display * dpy, GLXContext ctx, int attribute, int *value)
1785 switch (attribute) {
1786 case GLX_SHARE_CONTEXT_EXT:
1787 *value = ctx->share_xid;
1789 case GLX_VISUAL_ID_EXT:
1790 *value = ctx->mode ? ctx->mode->visualID : None;
1793 *value = ctx->screen;
1795 case GLX_FBCONFIG_ID:
1796 *value = ctx->mode ? ctx->mode->fbconfigID : None;
1798 case GLX_RENDER_TYPE:
1799 *value = ctx->renderType;
1802 return GLX_BAD_ATTRIBUTE;
1808 GLX_ALIAS(int, glXQueryContextInfoEXT,
1809 (Display * dpy, GLXContext ctx, int attribute, int *value),
1810 (dpy, ctx, attribute, value), glXQueryContext)
1812 PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx)
1818 glXFreeContextEXT(Display * dpy, GLXContext ctx)
1820 DestroyContext(dpy, ctx);
1824 PUBLIC GLXFBConfig *
1825 glXChooseFBConfig(Display * dpy, int screen,
1826 const int *attribList, int *nitems)
1828 __GLcontextModes **config_list;
1832 config_list = (__GLcontextModes **)
1833 glXGetFBConfigs(dpy, screen, &list_size);
1835 if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
1836 list_size = choose_visual(config_list, list_size, attribList, GL_TRUE);
1837 if (list_size == 0) {
1843 *nitems = list_size;
1844 return (GLXFBConfig *) config_list;
1849 glXCreateNewContext(Display * dpy, GLXFBConfig config,
1850 int renderType, GLXContext shareList, Bool allowDirect)
1852 const __GLcontextModes *const fbconfig =
1853 (const __GLcontextModes *const) config;
1855 return CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList,
1856 allowDirect, X_GLXCreateNewContext, renderType,
1862 glXGetCurrentReadDrawable(void)
1864 GLXContext gc = __glXGetCurrentContext();
1865 return gc->currentReadable;
1869 PUBLIC GLXFBConfig *
1870 glXGetFBConfigs(Display * dpy, int screen, int *nelements)
1872 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1873 __GLcontextModes **config = NULL;
1877 if (priv && (priv->screenConfigs != NULL)
1878 && (screen >= 0) && (screen <= ScreenCount(dpy))
1879 && (priv->screenConfigs[screen]->configs != NULL)
1880 && (priv->screenConfigs[screen]->configs->fbconfigID
1881 != (int) GLX_DONT_CARE)) {
1882 unsigned num_configs = 0;
1883 __GLcontextModes *modes;
1886 for (modes = priv->screenConfigs[screen]->configs; modes != NULL;
1887 modes = modes->next) {
1888 if (modes->fbconfigID != (int) GLX_DONT_CARE) {
1893 config = (__GLcontextModes **) Xmalloc(sizeof(__GLcontextModes *)
1895 if (config != NULL) {
1896 *nelements = num_configs;
1898 for (modes = priv->screenConfigs[screen]->configs; modes != NULL;
1899 modes = modes->next) {
1900 if (modes->fbconfigID != (int) GLX_DONT_CARE) {
1907 return (GLXFBConfig *) config;
1912 glXGetFBConfigAttrib(Display * dpy, GLXFBConfig config,
1913 int attribute, int *value)
1915 __GLcontextModes *const modes = ValidateGLXFBConfig(dpy, config);
1917 return (modes != NULL)
1918 ? _gl_get_context_mode_data(modes, attribute, value)
1923 PUBLIC XVisualInfo *
1924 glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig config)
1926 XVisualInfo visualTemplate;
1927 __GLcontextModes *fbconfig = (__GLcontextModes *) config;
1931 ** Get a list of all visuals, return if list is empty
1933 visualTemplate.visualid = fbconfig->visualID;
1934 return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
1937 #ifndef GLX_USE_APPLEGL
1939 ** GLX_SGI_swap_control
1942 __glXSwapIntervalSGI(int interval)
1944 xGLXVendorPrivateReq *req;
1945 GLXContext gc = __glXGetCurrentContext();
1946 __GLXscreenConfigs *psc;
1948 CARD32 *interval_ptr;
1952 return GLX_BAD_CONTEXT;
1955 if (interval <= 0) {
1956 return GLX_BAD_VALUE;
1959 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1961 #ifdef GLX_DIRECT_RENDERING
1962 if (gc->driContext && psc->driScreen && psc->driScreen->setSwapInterval) {
1963 __GLXDRIdrawable *pdraw =
1964 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1965 psc->driScreen->setSwapInterval(pdraw, interval);
1970 dpy = gc->currentDpy;
1971 opcode = __glXSetupForCommand(dpy);
1976 /* Send the glXSwapIntervalSGI request */
1978 GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req);
1979 req->reqType = opcode;
1980 req->glxCode = X_GLXVendorPrivate;
1981 req->vendorCode = X_GLXvop_SwapIntervalSGI;
1982 req->contextTag = gc->currentContextTag;
1984 interval_ptr = (CARD32 *) (req + 1);
1985 *interval_ptr = interval;
1996 ** GLX_MESA_swap_control
1999 __glXSwapIntervalMESA(unsigned int interval)
2001 #ifdef GLX_DIRECT_RENDERING
2002 GLXContext gc = __glXGetCurrentContext();
2004 if (gc != NULL && gc->driContext) {
2005 __GLXscreenConfigs *psc;
2007 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2008 if (psc->driScreen && psc->driScreen->setSwapInterval) {
2009 __GLXDRIdrawable *pdraw =
2010 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2011 return psc->driScreen->setSwapInterval(pdraw, interval);
2016 return GLX_BAD_CONTEXT;
2021 __glXGetSwapIntervalMESA(void)
2023 #ifdef GLX_DIRECT_RENDERING
2024 GLXContext gc = __glXGetCurrentContext();
2026 if (gc != NULL && gc->driContext) {
2027 __GLXscreenConfigs *psc;
2029 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2030 if (psc->driScreen && psc->driScreen->getSwapInterval) {
2031 __GLXDRIdrawable *pdraw =
2032 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2033 return psc->driScreen->getSwapInterval(pdraw);
2043 ** GLX_SGI_video_sync
2046 __glXGetVideoSyncSGI(unsigned int *count)
2048 int64_t ust, msc, sbc;
2050 GLXContext gc = __glXGetCurrentContext();
2051 __GLXscreenConfigs *psc;
2052 #ifdef GLX_DIRECT_RENDERING
2053 __GLXDRIdrawable *pdraw;
2057 return GLX_BAD_CONTEXT;
2059 #ifdef GLX_DIRECT_RENDERING
2060 if (!gc->driContext)
2061 return GLX_BAD_CONTEXT;
2064 psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
2065 #ifdef GLX_DIRECT_RENDERING
2066 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2069 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2070 * FIXME: there should be a GLX encoding for this call. I can find no
2071 * FIXME: documentation for the GLX encoding.
2073 #ifdef GLX_DIRECT_RENDERING
2074 if (psc->driScreen && psc->driScreen->getDrawableMSC) {
2075 ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
2076 *count = (unsigned) msc;
2077 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
2081 return GLX_BAD_CONTEXT;
2085 __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2087 GLXContext gc = __glXGetCurrentContext();
2088 __GLXscreenConfigs *psc;
2089 #ifdef GLX_DIRECT_RENDERING
2090 __GLXDRIdrawable *pdraw;
2092 int64_t ust, msc, sbc;
2095 if (divisor <= 0 || remainder < 0)
2096 return GLX_BAD_VALUE;
2099 return GLX_BAD_CONTEXT;
2101 #ifdef GLX_DIRECT_RENDERING
2102 if (!gc->driContext)
2103 return GLX_BAD_CONTEXT;
2106 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2107 #ifdef GLX_DIRECT_RENDERING
2108 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2111 #ifdef GLX_DIRECT_RENDERING
2112 if (psc->driScreen && psc->driScreen->waitForMSC) {
2113 ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
2115 *count = (unsigned) msc;
2116 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
2120 return GLX_BAD_CONTEXT;
2123 #endif /* GLX_USE_APPLEGL */
2126 ** GLX_SGIX_fbconfig
2127 ** Many of these functions are aliased to GLX 1.3 entry points in the
2128 ** GLX_functions table.
2132 GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
2133 (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
2134 (dpy, config, attribute, value), glXGetFBConfigAttrib)
2136 PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
2137 (Display * dpy, int screen, int *attrib_list,
2138 int *nelements), (dpy, screen, attrib_list, nelements),
2141 PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
2142 (Display * dpy, GLXFBConfigSGIX config),
2143 (dpy, config), glXGetVisualFromFBConfig)
2146 glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
2147 GLXFBConfigSGIX config,
2150 #ifndef GLX_USE_APPLEGL
2151 xGLXVendorPrivateWithReplyReq *vpreq;
2152 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
2153 GLXPixmap xid = None;
2155 __GLXscreenConfigs *psc;
2157 const __GLcontextModes *const fbconfig = (__GLcontextModes *) config;
2160 if ((dpy == NULL) || (config == NULL)) {
2163 #ifdef GLX_USE_APPLEGL
2164 if(apple_glx_pixmap_create(dpy, fbconfig->screen, pixmap, fbconfig))
2169 psc = GetGLXScreenConfigs(dpy, fbconfig->screen);
2171 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
2172 opcode = __glXSetupForCommand(dpy);
2177 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2179 GetReqExtra(GLXVendorPrivateWithReply,
2180 sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
2181 sz_xGLXVendorPrivateWithReplyReq, vpreq);
2182 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
2183 req->reqType = opcode;
2184 req->glxCode = X_GLXVendorPrivateWithReply;
2185 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
2186 req->screen = fbconfig->screen;
2187 req->fbconfig = fbconfig->fbconfigID;
2188 req->pixmap = pixmap;
2189 req->glxpixmap = xid = XAllocID(dpy);
2199 glXCreateContextWithConfigSGIX(Display * dpy,
2200 GLXFBConfigSGIX config, int renderType,
2201 GLXContext shareList, Bool allowDirect)
2203 GLXContext gc = NULL;
2204 const __GLcontextModes *const fbconfig = (__GLcontextModes *) config;
2205 __GLXscreenConfigs *psc;
2208 if ((dpy == NULL) || (config == NULL)) {
2212 psc = GetGLXScreenConfigs(dpy, fbconfig->screen);
2214 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
2215 gc = CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList,
2217 X_GLXvop_CreateContextWithConfigSGIX, renderType,
2225 PUBLIC GLXFBConfigSGIX
2226 glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis)
2228 __GLXdisplayPrivate *priv;
2229 __GLXscreenConfigs *psc = NULL;
2231 if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) != Success)
2232 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)
2233 && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) {
2234 return (GLXFBConfigSGIX) _gl_context_modes_find_visual(psc->configs,
2241 #ifndef GLX_USE_APPLEGL
2243 ** GLX_SGIX_swap_group
2246 __glXJoinSwapGroupSGIX(Display * dpy, GLXDrawable drawable,
2256 ** GLX_SGIX_swap_barrier
2259 __glXBindSwapBarrierSGIX(Display * dpy, GLXDrawable drawable, int barrier)
2267 __glXQueryMaxSwapBarriersSGIX(Display * dpy, int screen, int *max)
2277 ** GLX_OML_sync_control
2280 __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
2281 int64_t * ust, int64_t * msc, int64_t * sbc)
2283 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2285 #ifdef GLX_DIRECT_RENDERING
2286 __GLXDRIdrawable *pdraw;
2288 __GLXscreenConfigs *psc;
2293 #ifdef GLX_DIRECT_RENDERING
2294 pdraw = GetGLXDRIDrawable(dpy, drawable);
2295 psc = pdraw ? pdraw->psc : NULL;
2296 if (pdraw && psc->driScreen->getDrawableMSC) {
2297 ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
2305 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2307 __glxGetMscRate(__GLXDRIdrawable *glxDraw,
2308 int32_t * numerator, int32_t * denominator)
2311 __GLXscreenConfigs *psc;
2312 XF86VidModeModeLine mode_line;
2317 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2318 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
2319 unsigned n = dot_clock * 1000;
2320 unsigned d = mode_line.vtotal * mode_line.htotal;
2322 # define V_INTERLACE 0x010
2323 # define V_DBLSCAN 0x020
2325 if (mode_line.flags & V_INTERLACE)
2327 else if (mode_line.flags & V_DBLSCAN)
2330 /* The OML_sync_control spec requires that if the refresh rate is a
2331 * whole number, that the returned numerator be equal to the refresh
2332 * rate and the denominator be 1.
2340 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2342 /* This is a poor man's way to reduce a fraction. It's far from
2343 * perfect, but it will work well enough for this situation.
2346 for (i = 0; f[i] != 0; i++) {
2347 while (n % f[i] == 0 && d % f[i] == 0) {
2373 * Determine the refresh rate of the specified drawable and display.
2375 * \param dpy Display whose refresh rate is to be determined.
2376 * \param drawable Drawable whose refresh rate is to be determined.
2377 * \param numerator Numerator of the refresh rate.
2378 * \param demoninator Denominator of the refresh rate.
2379 * \return If the refresh rate for the specified display and drawable could
2380 * be calculated, True is returned. Otherwise False is returned.
2382 * \note This function is implemented entirely client-side. A lot of other
2383 * functionality is required to export GLX_OML_sync_control, so on
2384 * XFree86 this function can be called for direct-rendering contexts
2385 * when GLX_OML_sync_control appears in the client extension string.
2389 __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2390 int32_t * numerator, int32_t * denominator)
2392 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2393 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
2398 return __glxGetMscRate(draw, numerator, denominator);
2410 __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
2411 int64_t target_msc, int64_t divisor, int64_t remainder)
2413 GLXContext gc = __glXGetCurrentContext();
2414 #ifdef GLX_DIRECT_RENDERING
2415 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2416 __GLXscreenConfigs *psc = pdraw ? pdraw->psc : NULL;
2419 if (!gc) /* no GLX for this */
2422 #ifdef GLX_DIRECT_RENDERING
2423 if (!pdraw || !gc->driContext)
2427 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2428 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2429 * of -1 if the function failed because of errors detected in the input
2432 if (divisor < 0 || remainder < 0 || target_msc < 0)
2434 if (divisor > 0 && remainder >= divisor)
2437 if (target_msc == 0 && divisor == 0 && remainder == 0)
2440 #ifdef GLX_DIRECT_RENDERING
2441 if (psc->driScreen && psc->driScreen->swapBuffers)
2442 return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor,
2451 __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2452 int64_t target_msc, int64_t divisor,
2453 int64_t remainder, int64_t * ust,
2454 int64_t * msc, int64_t * sbc)
2456 #ifdef GLX_DIRECT_RENDERING
2457 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2459 __GLXscreenConfigs *psc = pdraw ? pdraw->psc : NULL;
2463 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2464 * error", but the return type in the spec is Bool.
2466 if (divisor < 0 || remainder < 0 || target_msc < 0)
2468 if (divisor > 0 && remainder >= divisor)
2471 #ifdef GLX_DIRECT_RENDERING
2472 if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
2473 ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
2484 __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2485 int64_t target_sbc, int64_t * ust,
2486 int64_t * msc, int64_t * sbc)
2488 #ifdef GLX_DIRECT_RENDERING
2489 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2491 __GLXscreenConfigs *psc = pdraw ? pdraw->psc : NULL;
2494 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2495 * error", but the return type in the spec is Bool.
2500 #ifdef GLX_DIRECT_RENDERING
2501 if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
2502 ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
2514 * Mesa extension stubs. These will help reduce portability problems.
2519 * Release all buffers associated with the specified GLX drawable.
2522 * This function was intended for stand-alone Mesa. The issue there is that
2523 * the library doesn't get any notification when a window is closed. In
2524 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2525 * supported, there are 3 different functions to destroy a drawable. It
2526 * should be possible to create GLX protocol (or have it determine which
2527 * protocol to use based on the type of the drawable) to have one function
2528 * do the work of 3. For the direct-rendering case, this function could
2529 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2530 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2531 * would need to be used. This really should be done as part of the new DRI
2534 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2535 * __driGarbageCollectDrawables
2536 * glXDestroyGLXPixmap
2537 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2538 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2541 __glXReleaseBuffersMESA(Display * dpy, GLXDrawable d)
2550 glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual,
2551 Pixmap pixmap, Colormap cmap)
2564 * GLX_MESA_copy_sub_buffer
2566 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2568 __glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
2569 int x, int y, int width, int height)
2571 xGLXVendorPrivateReq *req;
2574 CARD32 *drawable_ptr;
2575 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2578 #ifdef __DRI_COPY_SUB_BUFFER
2579 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2580 if (pdraw != NULL) {
2581 __GLXscreenConfigs *psc = pdraw->psc;
2582 if (psc->driScreen->copySubBuffer != NULL) {
2584 (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height);
2591 opcode = __glXSetupForCommand(dpy);
2596 ** The calling thread may or may not have a current context. If it
2597 ** does, send the context tag so the server can do a flush.
2599 gc = __glXGetCurrentContext();
2600 if ((gc != NULL) && (dpy == gc->currentDpy) &&
2601 ((drawable == gc->currentDrawable) ||
2602 (drawable == gc->currentReadable))) {
2603 tag = gc->currentContextTag;
2610 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req);
2611 req->reqType = opcode;
2612 req->glxCode = X_GLXVendorPrivate;
2613 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2614 req->contextTag = tag;
2616 drawable_ptr = (CARD32 *) (req + 1);
2617 x_ptr = (INT32 *) (drawable_ptr + 1);
2618 y_ptr = (INT32 *) (drawable_ptr + 2);
2619 w_ptr = (INT32 *) (drawable_ptr + 3);
2620 h_ptr = (INT32 *) (drawable_ptr + 4);
2622 *drawable_ptr = drawable;
2634 * GLX_EXT_texture_from_pixmap
2637 indirect_bind_tex_image(Display * dpy,
2638 GLXDrawable drawable,
2639 int buffer, const int *attrib_list)
2641 xGLXVendorPrivateReq *req;
2642 GLXContext gc = __glXGetCurrentContext();
2643 CARD32 *drawable_ptr;
2645 CARD32 *num_attrib_ptr;
2652 while (attrib_list[i * 2] != None)
2656 opcode = __glXSetupForCommand(dpy);
2661 GetReqExtra(GLXVendorPrivate, 12 + 8 * i, req);
2662 req->reqType = opcode;
2663 req->glxCode = X_GLXVendorPrivate;
2664 req->vendorCode = X_GLXvop_BindTexImageEXT;
2665 req->contextTag = gc->currentContextTag;
2667 drawable_ptr = (CARD32 *) (req + 1);
2668 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2669 num_attrib_ptr = (CARD32 *) (buffer_ptr + 1);
2670 attrib_ptr = (CARD32 *) (num_attrib_ptr + 1);
2672 *drawable_ptr = drawable;
2673 *buffer_ptr = buffer;
2674 *num_attrib_ptr = (CARD32) i;
2678 while (attrib_list[i * 2] != None) {
2679 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0];
2680 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1];
2690 indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
2692 xGLXVendorPrivateReq *req;
2693 GLXContext gc = __glXGetCurrentContext();
2694 CARD32 *drawable_ptr;
2698 opcode = __glXSetupForCommand(dpy);
2703 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32), req);
2704 req->reqType = opcode;
2705 req->glxCode = X_GLXVendorPrivate;
2706 req->vendorCode = X_GLXvop_ReleaseTexImageEXT;
2707 req->contextTag = gc->currentContextTag;
2709 drawable_ptr = (CARD32 *) (req + 1);
2710 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2712 *drawable_ptr = drawable;
2713 *buffer_ptr = buffer;
2719 static const struct glx_context_vtable indirect_context_vtable = {
2720 indirect_destroy_context,
2723 indirect_use_x_font,
2724 indirect_bind_tex_image,
2725 indirect_release_tex_image,
2730 __glXBindTexImageEXT(Display * dpy,
2731 GLXDrawable drawable, int buffer, const int *attrib_list)
2733 GLXContext gc = __glXGetCurrentContext();
2735 if (gc == NULL || gc->vtable->bind_tex_image == NULL)
2738 gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
2742 __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
2744 GLXContext gc = __glXGetCurrentContext();
2746 if (gc == NULL || gc->vtable->release_tex_image == NULL)
2749 gc->vtable->release_tex_image(dpy, drawable, buffer);
2754 #endif /* GLX_USE_APPLEGL */
2757 * \c strdup is actually not a standard ANSI C or POSIX routine.
2758 * Irix will not define it if ANSI mode is in effect.
2763 __glXstrdup(const char *str)
2766 copy = (char *) Xmalloc(strlen(str) + 1);
2774 ** glXGetProcAddress support
2777 struct name_address_pair
2783 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2784 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2786 static const struct name_address_pair GLX_functions[] = {
2787 /*** GLX_VERSION_1_0 ***/
2788 GLX_FUNCTION(glXChooseVisual),
2789 GLX_FUNCTION(glXCopyContext),
2790 GLX_FUNCTION(glXCreateContext),
2791 GLX_FUNCTION(glXCreateGLXPixmap),
2792 GLX_FUNCTION(glXDestroyContext),
2793 GLX_FUNCTION(glXDestroyGLXPixmap),
2794 GLX_FUNCTION(glXGetConfig),
2795 GLX_FUNCTION(glXGetCurrentContext),
2796 GLX_FUNCTION(glXGetCurrentDrawable),
2797 GLX_FUNCTION(glXIsDirect),
2798 GLX_FUNCTION(glXMakeCurrent),
2799 GLX_FUNCTION(glXQueryExtension),
2800 GLX_FUNCTION(glXQueryVersion),
2801 GLX_FUNCTION(glXSwapBuffers),
2802 GLX_FUNCTION(glXUseXFont),
2803 GLX_FUNCTION(glXWaitGL),
2804 GLX_FUNCTION(glXWaitX),
2806 /*** GLX_VERSION_1_1 ***/
2807 GLX_FUNCTION(glXGetClientString),
2808 GLX_FUNCTION(glXQueryExtensionsString),
2809 GLX_FUNCTION(glXQueryServerString),
2811 /*** GLX_VERSION_1_2 ***/
2812 GLX_FUNCTION(glXGetCurrentDisplay),
2814 /*** GLX_VERSION_1_3 ***/
2815 GLX_FUNCTION(glXChooseFBConfig),
2816 GLX_FUNCTION(glXCreateNewContext),
2817 GLX_FUNCTION(glXCreatePbuffer),
2818 GLX_FUNCTION(glXCreatePixmap),
2819 GLX_FUNCTION(glXCreateWindow),
2820 GLX_FUNCTION(glXDestroyPbuffer),
2821 GLX_FUNCTION(glXDestroyPixmap),
2822 GLX_FUNCTION(glXDestroyWindow),
2823 GLX_FUNCTION(glXGetCurrentReadDrawable),
2824 GLX_FUNCTION(glXGetFBConfigAttrib),
2825 GLX_FUNCTION(glXGetFBConfigs),
2826 GLX_FUNCTION(glXGetSelectedEvent),
2827 GLX_FUNCTION(glXGetVisualFromFBConfig),
2828 GLX_FUNCTION(glXMakeContextCurrent),
2829 GLX_FUNCTION(glXQueryContext),
2830 GLX_FUNCTION(glXQueryDrawable),
2831 GLX_FUNCTION(glXSelectEvent),
2833 #ifndef GLX_USE_APPLEGL
2834 /*** GLX_SGI_swap_control ***/
2835 GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI),
2837 /*** GLX_SGI_video_sync ***/
2838 GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI),
2839 GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI),
2841 /*** GLX_SGI_make_current_read ***/
2842 GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent),
2843 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable),
2845 /*** GLX_EXT_import_context ***/
2846 GLX_FUNCTION(glXFreeContextEXT),
2847 GLX_FUNCTION(glXGetContextIDEXT),
2848 GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
2849 GLX_FUNCTION(glXImportContextEXT),
2850 GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
2853 /*** GLX_SGIX_fbconfig ***/
2854 GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
2855 GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig),
2856 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX),
2857 GLX_FUNCTION(glXCreateContextWithConfigSGIX),
2858 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
2859 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
2861 #ifndef GLX_USE_APPLEGL
2862 /*** GLX_SGIX_pbuffer ***/
2863 GLX_FUNCTION(glXCreateGLXPbufferSGIX),
2864 GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
2865 GLX_FUNCTION(glXQueryGLXPbufferSGIX),
2866 GLX_FUNCTION(glXSelectEventSGIX),
2867 GLX_FUNCTION(glXGetSelectedEventSGIX),
2869 /*** GLX_SGIX_swap_group ***/
2870 GLX_FUNCTION2(glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX),
2872 /*** GLX_SGIX_swap_barrier ***/
2873 GLX_FUNCTION2(glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX),
2874 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX),
2876 /*** GLX_MESA_copy_sub_buffer ***/
2877 GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA),
2879 /*** GLX_MESA_pixmap_colormap ***/
2880 GLX_FUNCTION(glXCreateGLXPixmapMESA),
2882 /*** GLX_MESA_release_buffers ***/
2883 GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA),
2885 /*** GLX_MESA_swap_control ***/
2886 GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA),
2887 GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA),
2890 /*** GLX_ARB_get_proc_address ***/
2891 GLX_FUNCTION(glXGetProcAddressARB),
2894 GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
2896 #ifndef GLX_USE_APPLEGL
2897 /*** GLX_OML_sync_control ***/
2898 GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML),
2899 GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML),
2900 GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML),
2901 GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML),
2902 GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML),
2904 /*** GLX_EXT_texture_from_pixmap ***/
2905 GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT),
2906 GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT),
2909 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2910 /*** DRI configuration ***/
2911 GLX_FUNCTION(glXGetScreenDriver),
2912 GLX_FUNCTION(glXGetDriverConfig),
2915 {NULL, NULL} /* end of list */
2918 #ifndef GLX_USE_APPLEGL
2919 static const GLvoid *
2920 get_glx_proc_address(const char *funcName)
2924 /* try static functions */
2925 for (i = 0; GLX_functions[i].Name; i++) {
2926 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2927 return GLX_functions[i].Address;
2935 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2936 * \c glXGetProcAddress.
2938 * \param procName Name of a GL or GLX function.
2939 * \returns A pointer to the named function
2941 * \sa glXGetProcAddress
2943 PUBLIC void (*glXGetProcAddressARB(const GLubyte * procName)) (void)
2945 typedef void (*gl_function) (void);
2949 /* Search the table of GLX and internal functions first. If that
2950 * fails and the supplied name could be a valid core GL name, try
2951 * searching the core GL function table. This check is done to prevent
2952 * DRI based drivers from searching the core GL function table for
2953 * internal API functions.
2955 #ifdef GLX_USE_APPLEGL
2956 f = (gl_function) apple_glx_get_proc_address(procName);
2958 f = (gl_function) get_glx_proc_address((const char *) procName);
2959 if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2960 && (procName[2] != 'X')) {
2961 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2968 * Get the address of a named GL function. This is the GLX 1.4 name for
2969 * \c glXGetProcAddressARB.
2971 * \param procName Name of a GL or GLX function.
2972 * \returns A pointer to the named function
2974 * \sa glXGetProcAddressARB
2976 PUBLIC void (*glXGetProcAddress(const GLubyte * procName)) (void)
2977 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2978 __attribute__ ((alias("glXGetProcAddressARB")));
2981 return glXGetProcAddressARB(procName);
2983 #endif /* __GNUC__ */
2986 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2988 * Get the unadjusted system time (UST). Currently, the UST is measured in
2989 * microseconds since Epoc. The actual resolution of the UST may vary from
2990 * system to system, and the units may vary from release to release.
2991 * Drivers should not call this function directly. They should instead use
2992 * \c glXGetProcAddress to obtain a pointer to the function.
2994 * \param ust Location to store the 64-bit UST
2995 * \returns Zero on success or a negative errno value on failure.
2997 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2999 * \since Internal API version 20030317.
3002 __glXGetUST(int64_t * ust)
3010 if (gettimeofday(&tv, NULL) == 0) {
3011 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
3018 #endif /* GLX_DIRECT_RENDERING */