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;
239 * \todo It should be possible to move the allocate of \c client_state_private
240 * later in the function for direct-rendering contexts. Direct-rendering
241 * contexts don't need to track client state, so they don't need that memory
244 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
245 * function called \c __glXAllocateClientState that allocates the memory and
246 * does all the initialization (including the pixel pack / unpack).
249 AllocateGLXContext(Display * dpy)
254 __GLXattribute *state;
259 opcode = __glXSetupForCommand(dpy);
264 /* Allocate our context record */
265 gc = (GLXContext) Xmalloc(sizeof(struct __GLXcontextRec));
270 memset(gc, 0, sizeof(struct __GLXcontextRec));
272 gc->vtable = &indirect_context_vtable;
273 state = Xmalloc(sizeof(struct __GLXattributeRec));
279 gc->client_state_private = state;
280 memset(gc->client_state_private, 0, sizeof(struct __GLXattributeRec));
281 state->NoDrawArraysProtocol = (getenv("LIBGL_NO_DRAWARRAYS") != NULL);
284 ** Create a temporary buffer to hold GLX rendering commands. The size
285 ** of the buffer is selected so that the maximum number of GLX rendering
286 ** commands can fit in a single X packet and still have room in the X
287 ** packet for the GLXRenderReq header.
290 bufSize = (XMaxRequestSize(dpy) * 4) - sz_xGLXRenderReq;
291 gc->buf = (GLubyte *) Xmalloc(bufSize);
293 Xfree(gc->client_state_private);
297 gc->bufSize = bufSize;
299 /* Fill in the new context */
300 gc->renderMode = GL_RENDER;
302 state->storePack.alignment = 4;
303 state->storeUnpack.alignment = 4;
305 gc->attributes.stackPointer = &gc->attributes.stack[0];
308 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
309 ** Other code uses the fastImageUnpack bit, but it is never set
312 gc->fastImageUnpack = GL_FALSE;
313 gc->fillImage = __glFillImage;
315 gc->bufEnd = gc->buf + bufSize;
316 gc->isDirect = GL_FALSE;
319 ** Set limit register so that there will be one command per packet
324 gc->limit = gc->buf + bufSize - __GLX_BUFFER_LIMIT_SIZE;
326 gc->majorOpcode = opcode;
329 ** Constrain the maximum drawing command size allowed to be
330 ** transfered using the X_GLXRender protocol request. First
331 ** constrain by a software limit, then constrain by the protocl
334 if (bufSize > __GLX_RENDER_CMD_SIZE_LIMIT) {
335 bufSize = __GLX_RENDER_CMD_SIZE_LIMIT;
337 if (bufSize > __GLX_MAX_RENDER_CMD_SIZE) {
338 bufSize = __GLX_MAX_RENDER_CMD_SIZE;
340 gc->maxSmallRenderCommandSize = bufSize;
342 #ifdef GLX_USE_APPLEGL
343 gc->driContext = NULL;
344 gc->do_destroy = False;
351 glx_context_init(__GLXcontext *gc,
352 __GLXscreenConfigs *psc, const __GLcontextModes *fbconfig)
354 gc->majorOpcode = __glXSetupForCommand(psc->display->dpy);
355 if (!gc->majorOpcode)
358 gc->screen = psc->scr;
361 gc->isDirect = GL_TRUE;
368 * Create a new context. Exactly one of \c vis and \c fbconfig should be
371 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
372 * SGIX_fbconfig protocol be used?
373 * \param renderType For FBConfigs, what is the rendering type?
377 CreateContext(Display * dpy, int generic_id,
378 const __GLcontextModes * const fbconfig,
379 GLXContext shareList,
381 unsigned code, int renderType, int screen)
383 GLXContext gc = NULL;
384 __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
385 #if defined(GLX_DIRECT_RENDERING) && defined(GLX_USE_APPLEGL)
393 if (generic_id == None)
396 #ifndef GLX_USE_APPLEGL /* TODO: darwin indirect */
397 #ifdef GLX_DIRECT_RENDERING
398 if (allowDirect && psc->driScreen) {
399 gc = psc->driScreen->createContext(psc, fbconfig,
400 shareList, renderType);
405 gc = AllocateGLXContext(dpy);
411 case X_GLXCreateContext: {
412 xGLXCreateContextReq *req;
414 /* Send the glXCreateContext request */
415 GetReq(GLXCreateContext, req);
416 req->reqType = gc->majorOpcode;
417 req->glxCode = X_GLXCreateContext;
418 req->context = gc->xid = XAllocID(dpy);
419 req->visual = generic_id;
420 req->screen = screen;
421 req->shareList = shareList ? shareList->xid : None;
422 req->isDirect = GC_IS_DIRECT(gc);
426 case X_GLXCreateNewContext: {
427 xGLXCreateNewContextReq *req;
429 /* Send the glXCreateNewContext request */
430 GetReq(GLXCreateNewContext, req);
431 req->reqType = gc->majorOpcode;
432 req->glxCode = X_GLXCreateNewContext;
433 req->context = gc->xid = XAllocID(dpy);
434 req->fbconfig = generic_id;
435 req->screen = screen;
436 req->renderType = renderType;
437 req->shareList = shareList ? shareList->xid : None;
438 req->isDirect = GC_IS_DIRECT(gc);
442 case X_GLXvop_CreateContextWithConfigSGIX: {
443 xGLXVendorPrivateWithReplyReq *vpreq;
444 xGLXCreateContextWithConfigSGIXReq *req;
446 /* Send the glXCreateNewContext request */
447 GetReqExtra(GLXVendorPrivateWithReply,
448 sz_xGLXCreateContextWithConfigSGIXReq -
449 sz_xGLXVendorPrivateWithReplyReq, vpreq);
450 req = (xGLXCreateContextWithConfigSGIXReq *) vpreq;
451 req->reqType = gc->majorOpcode;
452 req->glxCode = X_GLXVendorPrivateWithReply;
453 req->vendorCode = X_GLXvop_CreateContextWithConfigSGIX;
454 req->context = gc->xid = XAllocID(dpy);
455 req->fbconfig = generic_id;
456 req->screen = screen;
457 req->renderType = renderType;
458 req->shareList = shareList ? shareList->xid : None;
459 req->isDirect = GC_IS_DIRECT(gc);
464 /* What to do here? This case is the sign of an internal error. It
465 * should never be reachable.
474 gc->imported = GL_FALSE;
475 gc->renderType = renderType;
477 /* TODO: darwin: Integrate with above to do indirect */
478 #ifdef GLX_USE_APPLEGL
479 if(apple_glx_create_context(&gc->driContext, dpy, screen, fbconfig,
480 shareList ? shareList->driContext : NULL,
481 &errorcode, &x11error)) {
482 __glXSendError(dpy, errorcode, 0, X_GLXCreateContext, x11error);
483 __glXFreeContext(gc);
487 gc->currentContextTag = -1;
489 gc->isDirect = allowDirect;
496 glXCreateContext(Display * dpy, XVisualInfo * vis,
497 GLXContext shareList, Bool allowDirect)
499 const __GLcontextModes *mode = NULL;
502 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
503 __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, vis->screen);
505 mode = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
509 error.errorCode = BadValue;
510 error.resourceID = vis->visualid;
511 error.sequenceNumber = dpy->request;
512 error.type = X_Error;
513 error.majorCode = __glXSetupForCommand(dpy);
514 error.minorCode = X_GLXCreateContext;
515 _XError(dpy, &error);
519 renderType = mode->rgbMode ? GLX_RGBA_TYPE : GLX_COLOR_INDEX_TYPE;
522 return CreateContext(dpy, vis->visualid, mode, shareList, allowDirect,
523 X_GLXCreateContext, renderType, vis->screen);
527 __glXFreeContext(__GLXcontext * gc)
530 XFree((char *) gc->vendor);
532 XFree((char *) gc->renderer);
534 XFree((char *) gc->version);
536 XFree((char *) gc->extensions);
537 __glFreeAttributeState(gc);
538 XFree((char *) gc->buf);
539 Xfree((char *) gc->client_state_private);
545 ** Destroy the named context
548 DestroyContext(Display * dpy, GLXContext gc)
550 #ifndef GLX_USE_APPLEGL /* TODO: darwin: indirect */
551 xGLXDestroyContextReq *req;
556 opcode = __glXSetupForCommand(dpy);
557 if (!opcode || !gc) {
563 imported = gc->imported;
566 if (gc->currentDpy) {
567 /* This context is bound to some thread. According to the man page,
568 * we should not actually delete the context until it's unbound.
569 * Note that we set gc->xid = None above. In MakeContextCurrent()
570 * we check for that and delete the context there.
576 #if defined(GLX_DIRECT_RENDERING)
577 /* Destroy the direct rendering context */
578 if (gc->driContext) {
579 GarbageCollectDRIDrawables(gc->psc);
581 XFree((char *) gc->extensions);
582 (*gc->driContext->destroyContext) (gc);
587 __glXFreeVertexArrayState(gc);
588 __glXFreeContext(gc);
593 ** This dpy also created the server side part of the context.
594 ** Send the glXDestroyContext request.
597 GetReq(GLXDestroyContext, req);
598 req->reqType = opcode;
599 req->glxCode = X_GLXDestroyContext;
608 if (gc->currentDpy) {
610 * Set the Bool that indicates that we should destroy this GLX context
611 * when the context is no longer current.
613 gc->do_destroy = True;
614 /* Have to free later cuz it's in use now */
618 /* Destroy the handle if not current to anybody */
621 apple_glx_destroy_context(&gc->driContext, dpy);
622 __glXFreeContext(gc);
628 glXDestroyContext(Display * dpy, GLXContext gc)
630 DestroyContext(dpy, gc);
634 ** Return the major and minor version #s for the GLX extension
637 glXQueryVersion(Display * dpy, int *major, int *minor)
639 __GLXdisplayPrivate *priv;
641 /* Init the extension. This fetches the major and minor version. */
642 priv = __glXInitialize(dpy);
647 *major = priv->majorVersion;
649 *minor = priv->minorVersion;
654 ** Query the existance of the GLX extension
657 glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
659 int major_op, erb, evb;
662 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
673 indirect_wait_gl(__GLXcontext *gc)
676 Display *dpy = gc->currentDpy;
678 /* Flush any pending commands out */
679 __glXFlushRenderBuffer(gc, gc->pc);
681 /* Send the glXWaitGL request */
683 GetReq(GLXWaitGL, req);
684 req->reqType = gc->majorOpcode;
685 req->glxCode = X_GLXWaitGL;
686 req->contextTag = gc->currentContextTag;
692 ** Put a barrier in the token stream that forces the GL to finish its
693 ** work before X can proceed.
698 GLXContext gc = __glXGetCurrentContext();
700 if (gc && gc->vtable->use_x_font)
701 gc->vtable->wait_gl(gc);
705 indirect_wait_x(__GLXcontext *gc)
708 Display *dpy = gc->currentDpy;
710 /* Flush any pending commands out */
711 __glXFlushRenderBuffer(gc, gc->pc);
714 GetReq(GLXWaitX, req);
715 req->reqType = gc->majorOpcode;
716 req->glxCode = X_GLXWaitX;
717 req->contextTag = gc->currentContextTag;
723 ** Put a barrier in the token stream that forces X to finish its
724 ** work before GL can proceed.
729 GLXContext gc = __glXGetCurrentContext();
731 if (gc && gc->vtable->use_x_font)
732 gc->vtable->wait_x(gc);
736 indirect_use_x_font(__GLXcontext *gc,
737 Font font, int first, int count, int listBase)
739 xGLXUseXFontReq *req;
740 Display *dpy = gc->currentDpy;
742 /* Flush any pending commands out */
743 __glXFlushRenderBuffer(gc, gc->pc);
745 /* Send the glXUseFont request */
747 GetReq(GLXUseXFont, req);
748 req->reqType = gc->majorOpcode;
749 req->glxCode = X_GLXUseXFont;
750 req->contextTag = gc->currentContextTag;
754 req->listBase = listBase;
759 #ifdef GLX_USE_APPLEGL
762 applegl_wait_gl(__GLXcontext *gc)
768 applegl_wait_x(__GLXcontext *gc)
770 apple_glx_waitx(gc->dpy, gc->driContext);
773 static const struct glx_context_vtable applegl_context_vtable = {
777 NULL, /* bind_tex_image, */
778 NULL, /* release_tex_image, */
784 glXUseXFont(Font font, int first, int count, int listBase)
786 GLXContext gc = __glXGetCurrentContext();
788 if (gc && gc->vtable->use_x_font)
789 gc->vtable->use_x_font(gc, font, first, count, listBase);
792 /************************************************************************/
795 ** Copy the source context to the destination context using the
799 glXCopyContext(Display * dpy, GLXContext source,
800 GLXContext dest, unsigned long mask)
802 #ifdef GLX_USE_APPLEGL
803 GLXContext gc = __glXGetCurrentContext();
807 if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
808 mask, &errorcode, &x11error)) {
809 __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
813 xGLXCopyContextReq *req;
814 GLXContext gc = __glXGetCurrentContext();
818 opcode = __glXSetupForCommand(dpy);
823 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
824 if (gc->driContext) {
825 /* NOT_DONE: This does not work yet */
830 ** If the source is the current context, send its tag so that the context
831 ** can be flushed before the copy.
833 if (source == gc && dpy == gc->currentDpy) {
834 tag = gc->currentContextTag;
840 /* Send the glXCopyContext request */
842 GetReq(GLXCopyContext, req);
843 req->reqType = opcode;
844 req->glxCode = X_GLXCopyContext;
845 req->source = source ? source->xid : None;
846 req->dest = dest ? dest->xid : None;
848 req->contextTag = tag;
851 #endif /* GLX_USE_APPLEGL */
856 * Determine if a context uses direct rendering.
858 * \param dpy Display where the context was created.
859 * \param contextID ID of the context to be tested.
861 * \returns \c GL_TRUE if the context is direct rendering or not.
864 __glXIsDirect(Display * dpy, GLXContextID contextID)
866 #if !defined(USE_XCB)
867 xGLXIsDirectReq *req;
868 xGLXIsDirectReply reply;
872 opcode = __glXSetupForCommand(dpy);
878 xcb_connection_t *c = XGetXCBConnection(dpy);
879 xcb_glx_is_direct_reply_t *reply = xcb_glx_is_direct_reply(c,
884 const Bool is_direct = reply->is_direct ? True : False;
889 /* Send the glXIsDirect request */
891 GetReq(GLXIsDirect, req);
892 req->reqType = opcode;
893 req->glxCode = X_GLXIsDirect;
894 req->context = contextID;
895 _XReply(dpy, (xReply *) & reply, 0, False);
899 return reply.isDirect;
905 * Shouldn't this function \b always return \c GL_FALSE when
906 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
907 * the GLX protocol here at all?
910 glXIsDirect(Display * dpy, GLXContext gc)
915 else if (GC_IS_DIRECT(gc)) {
918 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
921 return __glXIsDirect(dpy, gc->xid);
926 glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
928 #ifdef GLX_USE_APPLEGL
929 int screen = vis->screen;
930 __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
931 const __GLcontextModes *modes;
933 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
935 if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, modes))
940 xGLXCreateGLXPixmapReq *req;
944 opcode = __glXSetupForCommand(dpy);
949 /* Send the glXCreateGLXPixmap request */
951 GetReq(GLXCreateGLXPixmap, req);
952 req->reqType = opcode;
953 req->glxCode = X_GLXCreateGLXPixmap;
954 req->screen = vis->screen;
955 req->visual = vis->visualid;
956 req->pixmap = pixmap;
957 req->glxpixmap = xid = XAllocID(dpy);
961 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
963 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
964 * is actually bound to a context... */
966 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
967 __GLXDRIdrawable *pdraw;
968 __GLXscreenConfigs *psc;
969 __GLcontextModes *modes;
971 psc = priv->screenConfigs[vis->screen];
972 if (psc->driScreen == NULL)
974 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
975 pdraw = psc->driScreen->createDrawable(psc, pixmap, req->glxpixmap, modes);
977 fprintf(stderr, "failed to create pixmap\n");
981 if (__glxHashInsert(priv->drawHash, req->glxpixmap, pdraw)) {
982 (*pdraw->destroyDrawable) (pdraw);
983 return None; /* FIXME: Check what we're supposed to do here... */
993 ** Destroy the named pixmap
996 glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
998 #ifdef GLX_USE_APPLEGL
999 if(apple_glx_pixmap_destroy(dpy, glxpixmap))
1000 __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
1002 xGLXDestroyGLXPixmapReq *req;
1005 opcode = __glXSetupForCommand(dpy);
1010 /* Send the glXDestroyGLXPixmap request */
1012 GetReq(GLXDestroyGLXPixmap, req);
1013 req->reqType = opcode;
1014 req->glxCode = X_GLXDestroyGLXPixmap;
1015 req->glxpixmap = glxpixmap;
1019 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1021 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
1022 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
1024 if (pdraw != NULL) {
1025 (*pdraw->destroyDrawable) (pdraw);
1026 __glxHashDelete(priv->drawHash, glxpixmap);
1030 #endif /* GLX_USE_APPLEGL */
1034 glXSwapBuffers(Display * dpy, GLXDrawable drawable)
1036 #ifdef GLX_USE_APPLEGL
1037 GLXContext gc = glXGetCurrentContext();
1038 if(gc && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
1039 apple_glx_swap_buffers(gc->driContext);
1041 __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
1048 xcb_connection_t *c;
1050 xGLXSwapBuffersReq *req;
1053 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1054 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
1056 if (pdraw != NULL) {
1058 (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0);
1063 opcode = __glXSetupForCommand(dpy);
1069 ** The calling thread may or may not have a current context. If it
1070 ** does, send the context tag so the server can do a flush.
1072 gc = __glXGetCurrentContext();
1073 if ((gc != NULL) && (dpy == gc->currentDpy) &&
1074 ((drawable == gc->currentDrawable)
1075 || (drawable == gc->currentReadable))) {
1076 tag = gc->currentContextTag;
1083 c = XGetXCBConnection(dpy);
1084 xcb_glx_swap_buffers(c, tag, drawable);
1087 /* Send the glXSwapBuffers request */
1089 GetReq(GLXSwapBuffers, req);
1090 req->reqType = opcode;
1091 req->glxCode = X_GLXSwapBuffers;
1092 req->drawable = drawable;
1093 req->contextTag = tag;
1097 #endif /* USE_XCB */
1098 #endif /* GLX_USE_APPLEGL */
1103 ** Return configuration information for the given display, screen and
1104 ** visual combination.
1107 glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
1110 __GLXdisplayPrivate *priv;
1111 __GLXscreenConfigs *psc;
1112 __GLcontextModes *modes;
1115 status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
1116 if (status == Success) {
1117 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
1119 /* Lookup attribute after first finding a match on the visual */
1120 if (modes != NULL) {
1121 return _gl_get_context_mode_data(modes, attribute, value_return);
1124 status = GLX_BAD_VISUAL;
1128 ** If we can't find the config for this visual, this visual is not
1129 ** supported by the OpenGL implementation on the server.
1131 if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
1132 *value_return = GL_FALSE;
1139 /************************************************************************/
1142 init_fbconfig_for_chooser(__GLcontextModes * config,
1143 GLboolean fbconfig_style_tags)
1145 memset(config, 0, sizeof(__GLcontextModes));
1146 config->visualID = (XID) GLX_DONT_CARE;
1147 config->visualType = GLX_DONT_CARE;
1149 /* glXChooseFBConfig specifies different defaults for these two than
1152 if (fbconfig_style_tags) {
1153 config->rgbMode = GL_TRUE;
1154 config->doubleBufferMode = GLX_DONT_CARE;
1157 config->visualRating = GLX_DONT_CARE;
1158 config->transparentPixel = GLX_NONE;
1159 config->transparentRed = GLX_DONT_CARE;
1160 config->transparentGreen = GLX_DONT_CARE;
1161 config->transparentBlue = GLX_DONT_CARE;
1162 config->transparentAlpha = GLX_DONT_CARE;
1163 config->transparentIndex = GLX_DONT_CARE;
1165 config->drawableType = GLX_WINDOW_BIT;
1166 config->renderType =
1167 (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
1168 config->xRenderable = GLX_DONT_CARE;
1169 config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
1171 config->swapMethod = GLX_DONT_CARE;
1174 #define MATCH_DONT_CARE( param ) \
1176 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1177 && (a-> param != b-> param) ) { \
1182 #define MATCH_MINIMUM( param ) \
1184 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1185 && (a-> param > b-> param) ) { \
1190 #define MATCH_EXACT( param ) \
1192 if ( a-> param != b-> param) { \
1197 /* Test that all bits from a are contained in b */
1198 #define MATCH_MASK(param) \
1200 if ((a->param & ~b->param) != 0) \
1205 * Determine if two GLXFBConfigs are compatible.
1207 * \param a Application specified config to test.
1208 * \param b Server specified config to test against \c a.
1211 fbconfigs_compatible(const __GLcontextModes * const a,
1212 const __GLcontextModes * const b)
1214 MATCH_DONT_CARE(doubleBufferMode);
1215 MATCH_DONT_CARE(visualType);
1216 MATCH_DONT_CARE(visualRating);
1217 MATCH_DONT_CARE(xRenderable);
1218 MATCH_DONT_CARE(fbconfigID);
1219 MATCH_DONT_CARE(swapMethod);
1221 MATCH_MINIMUM(rgbBits);
1222 MATCH_MINIMUM(numAuxBuffers);
1223 MATCH_MINIMUM(redBits);
1224 MATCH_MINIMUM(greenBits);
1225 MATCH_MINIMUM(blueBits);
1226 MATCH_MINIMUM(alphaBits);
1227 MATCH_MINIMUM(depthBits);
1228 MATCH_MINIMUM(stencilBits);
1229 MATCH_MINIMUM(accumRedBits);
1230 MATCH_MINIMUM(accumGreenBits);
1231 MATCH_MINIMUM(accumBlueBits);
1232 MATCH_MINIMUM(accumAlphaBits);
1233 MATCH_MINIMUM(sampleBuffers);
1234 MATCH_MINIMUM(maxPbufferWidth);
1235 MATCH_MINIMUM(maxPbufferHeight);
1236 MATCH_MINIMUM(maxPbufferPixels);
1237 MATCH_MINIMUM(samples);
1239 MATCH_DONT_CARE(stereoMode);
1242 MATCH_MASK(drawableType);
1243 MATCH_MASK(renderType);
1245 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1246 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1247 * Technically speaking, it is a bug in the DDX driver, but there is
1248 * enough of an installed base to work around the problem here. In any
1249 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1250 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1251 * 0 from the server to be a match to maintain backward compatibility with
1252 * the (broken) drivers.
1255 if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) {
1256 if (a->transparentPixel == GLX_NONE) {
1257 if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0)
1261 MATCH_EXACT(transparentPixel);
1264 switch (a->transparentPixel) {
1265 case GLX_TRANSPARENT_RGB:
1266 MATCH_DONT_CARE(transparentRed);
1267 MATCH_DONT_CARE(transparentGreen);
1268 MATCH_DONT_CARE(transparentBlue);
1269 MATCH_DONT_CARE(transparentAlpha);
1272 case GLX_TRANSPARENT_INDEX:
1273 MATCH_DONT_CARE(transparentIndex);
1285 /* There's some trickly language in the GLX spec about how this is supposed
1286 * to work. Basically, if a given component size is either not specified
1287 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1288 * Well, that's really hard to do with the code as-is. This behavior is
1289 * closer to correct, but still not technically right.
1291 #define PREFER_LARGER_OR_ZERO(comp) \
1293 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1294 if ( ((*a)-> comp) == 0 ) { \
1297 else if ( ((*b)-> comp) == 0 ) { \
1301 return ((*b)-> comp) - ((*a)-> comp) ; \
1306 #define PREFER_LARGER(comp) \
1308 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1309 return ((*b)-> comp) - ((*a)-> comp) ; \
1313 #define PREFER_SMALLER(comp) \
1315 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1316 return ((*a)-> comp) - ((*b)-> comp) ; \
1321 * Compare two GLXFBConfigs. This function is intended to be used as the
1322 * compare function passed in to qsort.
1324 * \returns If \c a is a "better" config, according to the specification of
1325 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1326 * better, then a number greater than zero is return. If both are
1327 * equal, zero is returned.
1328 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1331 fbconfig_compare(const __GLcontextModes * const *const a,
1332 const __GLcontextModes * const *const b)
1334 /* The order of these comparisons must NOT change. It is defined by
1335 * the GLX 1.3 spec and ARB_multisample.
1338 PREFER_SMALLER(visualSelectGroup);
1340 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1341 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1342 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1344 PREFER_SMALLER(visualRating);
1346 /* This isn't quite right. It is supposed to compare the sum of the
1347 * components the user specifically set minimums for.
1349 PREFER_LARGER_OR_ZERO(redBits);
1350 PREFER_LARGER_OR_ZERO(greenBits);
1351 PREFER_LARGER_OR_ZERO(blueBits);
1352 PREFER_LARGER_OR_ZERO(alphaBits);
1354 PREFER_SMALLER(rgbBits);
1356 if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) {
1357 /* Prefer single-buffer.
1359 return (!(*a)->doubleBufferMode) ? -1 : 1;
1362 PREFER_SMALLER(numAuxBuffers);
1364 PREFER_LARGER_OR_ZERO(depthBits);
1365 PREFER_SMALLER(stencilBits);
1367 /* This isn't quite right. It is supposed to compare the sum of the
1368 * components the user specifically set minimums for.
1370 PREFER_LARGER_OR_ZERO(accumRedBits);
1371 PREFER_LARGER_OR_ZERO(accumGreenBits);
1372 PREFER_LARGER_OR_ZERO(accumBlueBits);
1373 PREFER_LARGER_OR_ZERO(accumAlphaBits);
1375 PREFER_SMALLER(visualType);
1377 /* None of the multisample specs say where this comparison should happen,
1378 * so I put it near the end.
1380 PREFER_SMALLER(sampleBuffers);
1381 PREFER_SMALLER(samples);
1383 /* None of the pbuffer or fbconfig specs say that this comparison needs
1384 * to happen at all, but it seems like it should.
1386 PREFER_LARGER(maxPbufferWidth);
1387 PREFER_LARGER(maxPbufferHeight);
1388 PREFER_LARGER(maxPbufferPixels);
1395 * Selects and sorts a subset of the supplied configs based on the attributes.
1396 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1397 * and \c glXChooseFBConfigSGIX.
1399 * \param configs Array of pointers to possible configs. The elements of
1400 * this array that do not meet the criteria will be set to
1401 * NULL. The remaining elements will be sorted according to
1402 * the various visual / FBConfig selection rules.
1403 * \param num_configs Number of elements in the \c configs array.
1404 * \param attribList Attributes used select from \c configs. This array is
1405 * terminated by a \c None tag. The array can either take
1406 * the form expected by \c glXChooseVisual (where boolean
1407 * tags do not have a value) or by \c glXChooseFBConfig
1408 * (where every tag has a value).
1409 * \param fbconfig_style_tags Selects whether \c attribList is in
1410 * \c glXChooseVisual style or
1411 * \c glXChooseFBConfig style.
1412 * \returns The number of valid elements left in \c configs.
1414 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1417 choose_visual(__GLcontextModes ** configs, int num_configs,
1418 const int *attribList, GLboolean fbconfig_style_tags)
1420 __GLcontextModes test_config;
1424 /* This is a fairly direct implementation of the selection method
1425 * described by GLX_SGIX_fbconfig. Start by culling out all the
1426 * configs that are not compatible with the selected parameter
1430 init_fbconfig_for_chooser(&test_config, fbconfig_style_tags);
1431 __glXInitializeVisualConfigFromTags(&test_config, 512,
1432 (const INT32 *) attribList,
1433 GL_TRUE, fbconfig_style_tags);
1436 for (i = 0; i < num_configs; i++) {
1437 if (fbconfigs_compatible(&test_config, configs[i])) {
1438 configs[base] = configs[i];
1447 if (base < num_configs) {
1448 (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base));
1451 /* After the incompatible configs are removed, the resulting
1452 * list is sorted according to the rules set out in the various
1456 qsort(configs, base, sizeof(__GLcontextModes *),
1457 (int (*)(const void *, const void *)) fbconfig_compare);
1465 ** Return the visual that best matches the template. Return None if no
1466 ** visual matches the template.
1468 PUBLIC XVisualInfo *
1469 glXChooseVisual(Display * dpy, int screen, int *attribList)
1471 XVisualInfo *visualList = NULL;
1472 __GLXdisplayPrivate *priv;
1473 __GLXscreenConfigs *psc;
1474 __GLcontextModes test_config;
1475 __GLcontextModes *modes;
1476 const __GLcontextModes *best_config = NULL;
1479 ** Get a list of all visuals, return if list is empty
1481 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1487 ** Build a template from the defaults and the attribute list
1488 ** Free visual list and return if an unexpected token is encountered
1490 init_fbconfig_for_chooser(&test_config, GL_FALSE);
1491 __glXInitializeVisualConfigFromTags(&test_config, 512,
1492 (const INT32 *) attribList,
1496 ** Eliminate visuals that don't meet minimum requirements
1497 ** Compute a score for those that do
1498 ** Remember which visual, if any, got the highest score
1499 ** If no visual is acceptable, return None
1500 ** Otherwise, create an XVisualInfo list with just the selected X visual
1503 for (modes = psc->visuals; modes != NULL; modes = modes->next) {
1504 if (fbconfigs_compatible(&test_config, modes)
1505 && ((best_config == NULL)
1508 ((const __GLcontextModes * const *const) &modes,
1509 &best_config) < 0))) {
1510 XVisualInfo visualTemplate;
1511 XVisualInfo *newList;
1514 visualTemplate.screen = screen;
1515 visualTemplate.visualid = modes->visualID;
1516 newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask,
1517 &visualTemplate, &i);
1521 visualList = newList;
1522 best_config = modes;
1527 #ifdef GLX_USE_APPLEGL
1528 if(visualList && getenv("LIBGL_DUMP_VISUALID")) {
1529 printf("visualid 0x%lx\n", visualList[0].visualid);
1538 glXQueryExtensionsString(Display * dpy, int screen)
1540 __GLXscreenConfigs *psc;
1541 __GLXdisplayPrivate *priv;
1543 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1547 if (!psc->effectiveGLXexts) {
1548 if (!psc->serverGLXexts) {
1549 psc->serverGLXexts =
1550 __glXQueryServerString(dpy, priv->majorOpcode, screen,
1554 __glXCalculateUsableExtensions(psc,
1555 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1556 (psc->driScreen != NULL),
1560 priv->minorVersion);
1563 return psc->effectiveGLXexts;
1567 glXGetClientString(Display * dpy, int name)
1573 return (__glXGLXClientVendorName);
1575 return (__glXGLXClientVersion);
1576 case GLX_EXTENSIONS:
1577 return (__glXGetClientExtensions());
1584 glXQueryServerString(Display * dpy, int screen, int name)
1586 __GLXscreenConfigs *psc;
1587 __GLXdisplayPrivate *priv;
1591 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1597 str = &priv->serverGLXvendor;
1600 str = &priv->serverGLXversion;
1602 case GLX_EXTENSIONS:
1603 str = &psc->serverGLXexts;
1610 *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name);
1617 __glXClientInfo(Display * dpy, int opcode)
1619 char *ext_str = __glXGetClientGLExtensionString();
1620 int size = strlen(ext_str) + 1;
1623 xcb_connection_t *c = XGetXCBConnection(dpy);
1624 xcb_glx_client_info(c,
1625 GLX_MAJOR_VERSION, GLX_MINOR_VERSION, size, ext_str);
1627 xGLXClientInfoReq *req;
1629 /* Send the glXClientInfo request */
1631 GetReq(GLXClientInfo, req);
1632 req->reqType = opcode;
1633 req->glxCode = X_GLXClientInfo;
1634 req->major = GLX_MAJOR_VERSION;
1635 req->minor = GLX_MINOR_VERSION;
1637 req->length += (size + 3) >> 2;
1638 req->numbytes = size;
1639 Data(dpy, ext_str, size);
1643 #endif /* USE_XCB */
1650 ** EXT_import_context
1654 glXGetCurrentDisplay(void)
1656 GLXContext gc = __glXGetCurrentContext();
1659 return gc->currentDpy;
1663 GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1664 glXGetCurrentDisplay)
1666 #ifndef GLX_USE_APPLEGL
1668 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1671 * \param dpy Display where \c ctx was created.
1672 * \param ctx Context to query.
1673 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1674 * or zero if the request failed due to internal problems (i.e.,
1675 * unable to allocate temporary memory, etc.)
1678 * This function dynamically determines whether to use the EXT_import_context
1679 * version of the protocol or the GLX 1.3 version of the protocol.
1681 static int __glXQueryContextInfo(Display * dpy, GLXContext ctx)
1683 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1684 xGLXQueryContextReply reply;
1690 return GLX_BAD_CONTEXT;
1692 opcode = __glXSetupForCommand(dpy);
1697 /* Send the glXQueryContextInfoEXT request */
1700 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
1701 xGLXQueryContextReq *req;
1703 GetReq(GLXQueryContext, req);
1705 req->reqType = opcode;
1706 req->glxCode = X_GLXQueryContext;
1707 req->context = (unsigned int) (ctx->xid);
1710 xGLXVendorPrivateReq *vpreq;
1711 xGLXQueryContextInfoEXTReq *req;
1713 GetReqExtra(GLXVendorPrivate,
1714 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1716 req = (xGLXQueryContextInfoEXTReq *) vpreq;
1717 req->reqType = opcode;
1718 req->glxCode = X_GLXVendorPrivateWithReply;
1719 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1720 req->context = (unsigned int) (ctx->xid);
1723 _XReply(dpy, (xReply *) & reply, 0, False);
1725 numValues = reply.n;
1728 else if (numValues > __GLX_MAX_CONTEXT_PROPS)
1731 int *propList, *pProp;
1734 nPropListBytes = numValues << 3;
1735 propList = (int *) Xmalloc(nPropListBytes);
1736 if (NULL == propList) {
1742 _XRead(dpy, (char *) propList, nPropListBytes);
1744 /* Look up screen first so we can look up visuals/fbconfigs later */
1746 for (i = 0; i < numValues; i++, pProp += 2)
1747 if (pProp[0] == GLX_SCREEN) {
1748 ctx->screen = pProp[1];
1749 ctx->psc = GetGLXScreenConfigs(dpy, ctx->screen);
1753 for (i = 0; i < numValues; i++) {
1755 case GLX_SHARE_CONTEXT_EXT:
1756 ctx->share_xid = *pProp++;
1758 case GLX_VISUAL_ID_EXT:
1760 _gl_context_modes_find_visual(ctx->psc->visuals, *pProp++);
1762 case GLX_FBCONFIG_ID:
1764 _gl_context_modes_find_fbconfig(ctx->psc->configs,
1767 case GLX_RENDER_TYPE:
1768 ctx->renderType = *pProp++;
1776 Xfree((char *) propList);
1788 glXQueryContext(Display * dpy, GLXContext ctx, int attribute, int *value)
1790 #ifndef GLX_USE_APPLEGL
1793 /* get the information from the server if we don't have it already */
1794 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1795 if (!ctx->driContext && (ctx->mode == NULL)) {
1797 if (ctx->mode == NULL) {
1799 retVal = __glXQueryContextInfo(dpy, ctx);
1800 if (Success != retVal)
1805 switch (attribute) {
1806 #ifndef GLX_USE_APPLEGL
1807 case GLX_SHARE_CONTEXT_EXT:
1808 *value = (int) (ctx->share_xid);
1810 case GLX_VISUAL_ID_EXT:
1811 *value = ctx->mode ? ctx->mode->visualID : None;
1815 *value = (int) (ctx->screen);
1817 case GLX_FBCONFIG_ID:
1818 *value = ctx->mode ? ctx->mode->fbconfigID : None;
1820 case GLX_RENDER_TYPE:
1821 *value = (int) (ctx->renderType);
1824 return GLX_BAD_ATTRIBUTE;
1830 GLX_ALIAS(int, glXQueryContextInfoEXT,
1831 (Display * dpy, GLXContext ctx, int attribute, int *value),
1832 (dpy, ctx, attribute, value), glXQueryContext)
1834 PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx)
1840 glXImportContextEXT(Display * dpy, GLXContextID contextID)
1842 #ifdef GLX_USE_APPLEGL
1847 if (contextID == None) {
1850 if (__glXIsDirect(dpy, contextID)) {
1854 ctx = AllocateGLXContext(dpy);
1856 ctx->xid = contextID;
1857 ctx->imported = GL_TRUE;
1859 if (Success != __glXQueryContextInfo(dpy, ctx)) {
1860 __glXFreeContext(ctx);
1869 glXFreeContextEXT(Display * dpy, GLXContext ctx)
1871 DestroyContext(dpy, ctx);
1877 * GLX 1.3 functions - these are just stubs for now!
1880 PUBLIC GLXFBConfig *
1881 glXChooseFBConfig(Display * dpy, int screen,
1882 const int *attribList, int *nitems)
1884 __GLcontextModes **config_list;
1888 config_list = (__GLcontextModes **)
1889 glXGetFBConfigs(dpy, screen, &list_size);
1891 if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
1892 list_size = choose_visual(config_list, list_size, attribList, GL_TRUE);
1893 if (list_size == 0) {
1899 *nitems = list_size;
1900 return (GLXFBConfig *) config_list;
1905 glXCreateNewContext(Display * dpy, GLXFBConfig config,
1906 int renderType, GLXContext shareList, Bool allowDirect)
1908 const __GLcontextModes *const fbconfig =
1909 (const __GLcontextModes *const) config;
1911 return CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList,
1912 allowDirect, X_GLXCreateNewContext, renderType,
1918 glXGetCurrentReadDrawable(void)
1920 GLXContext gc = __glXGetCurrentContext();
1921 return gc->currentReadable;
1925 PUBLIC GLXFBConfig *
1926 glXGetFBConfigs(Display * dpy, int screen, int *nelements)
1928 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1929 __GLcontextModes **config = NULL;
1933 if (priv && (priv->screenConfigs != NULL)
1934 && (screen >= 0) && (screen <= ScreenCount(dpy))
1935 && (priv->screenConfigs[screen]->configs != NULL)
1936 && (priv->screenConfigs[screen]->configs->fbconfigID
1937 != (int) GLX_DONT_CARE)) {
1938 unsigned num_configs = 0;
1939 __GLcontextModes *modes;
1942 for (modes = priv->screenConfigs[screen]->configs; modes != NULL;
1943 modes = modes->next) {
1944 if (modes->fbconfigID != (int) GLX_DONT_CARE) {
1949 config = (__GLcontextModes **) Xmalloc(sizeof(__GLcontextModes *)
1951 if (config != NULL) {
1952 *nelements = num_configs;
1954 for (modes = priv->screenConfigs[screen]->configs; modes != NULL;
1955 modes = modes->next) {
1956 if (modes->fbconfigID != (int) GLX_DONT_CARE) {
1963 return (GLXFBConfig *) config;
1968 glXGetFBConfigAttrib(Display * dpy, GLXFBConfig config,
1969 int attribute, int *value)
1971 __GLcontextModes *const modes = ValidateGLXFBConfig(dpy, config);
1973 return (modes != NULL)
1974 ? _gl_get_context_mode_data(modes, attribute, value)
1979 PUBLIC XVisualInfo *
1980 glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig config)
1982 XVisualInfo visualTemplate;
1983 __GLcontextModes *fbconfig = (__GLcontextModes *) config;
1987 ** Get a list of all visuals, return if list is empty
1989 visualTemplate.visualid = fbconfig->visualID;
1990 return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
1993 #ifndef GLX_USE_APPLEGL
1995 ** GLX_SGI_swap_control
1998 __glXSwapIntervalSGI(int interval)
2000 xGLXVendorPrivateReq *req;
2001 GLXContext gc = __glXGetCurrentContext();
2002 __GLXscreenConfigs *psc;
2004 CARD32 *interval_ptr;
2008 return GLX_BAD_CONTEXT;
2011 if (interval <= 0) {
2012 return GLX_BAD_VALUE;
2015 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2017 #ifdef GLX_DIRECT_RENDERING
2018 if (gc->driContext && psc->driScreen && psc->driScreen->setSwapInterval) {
2019 __GLXDRIdrawable *pdraw =
2020 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2021 psc->driScreen->setSwapInterval(pdraw, interval);
2026 dpy = gc->currentDpy;
2027 opcode = __glXSetupForCommand(dpy);
2032 /* Send the glXSwapIntervalSGI request */
2034 GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req);
2035 req->reqType = opcode;
2036 req->glxCode = X_GLXVendorPrivate;
2037 req->vendorCode = X_GLXvop_SwapIntervalSGI;
2038 req->contextTag = gc->currentContextTag;
2040 interval_ptr = (CARD32 *) (req + 1);
2041 *interval_ptr = interval;
2052 ** GLX_MESA_swap_control
2055 __glXSwapIntervalMESA(unsigned int interval)
2057 #ifdef GLX_DIRECT_RENDERING
2058 GLXContext gc = __glXGetCurrentContext();
2060 if (gc != NULL && gc->driContext) {
2061 __GLXscreenConfigs *psc;
2063 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2064 if (psc->driScreen && psc->driScreen->setSwapInterval) {
2065 __GLXDRIdrawable *pdraw =
2066 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2067 return psc->driScreen->setSwapInterval(pdraw, interval);
2072 return GLX_BAD_CONTEXT;
2077 __glXGetSwapIntervalMESA(void)
2079 #ifdef GLX_DIRECT_RENDERING
2080 GLXContext gc = __glXGetCurrentContext();
2082 if (gc != NULL && gc->driContext) {
2083 __GLXscreenConfigs *psc;
2085 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2086 if (psc->driScreen && psc->driScreen->getSwapInterval) {
2087 __GLXDRIdrawable *pdraw =
2088 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2089 return psc->driScreen->getSwapInterval(pdraw);
2099 ** GLX_SGI_video_sync
2102 __glXGetVideoSyncSGI(unsigned int *count)
2104 int64_t ust, msc, sbc;
2106 GLXContext gc = __glXGetCurrentContext();
2107 __GLXscreenConfigs *psc;
2108 #ifdef GLX_DIRECT_RENDERING
2109 __GLXDRIdrawable *pdraw;
2113 return GLX_BAD_CONTEXT;
2115 #ifdef GLX_DIRECT_RENDERING
2116 if (!gc->driContext)
2117 return GLX_BAD_CONTEXT;
2120 psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
2121 #ifdef GLX_DIRECT_RENDERING
2122 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2125 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2126 * FIXME: there should be a GLX encoding for this call. I can find no
2127 * FIXME: documentation for the GLX encoding.
2129 #ifdef GLX_DIRECT_RENDERING
2130 if (psc->driScreen && psc->driScreen->getDrawableMSC) {
2131 ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
2132 *count = (unsigned) msc;
2133 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
2137 return GLX_BAD_CONTEXT;
2141 __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2143 GLXContext gc = __glXGetCurrentContext();
2144 __GLXscreenConfigs *psc;
2145 #ifdef GLX_DIRECT_RENDERING
2146 __GLXDRIdrawable *pdraw;
2148 int64_t ust, msc, sbc;
2151 if (divisor <= 0 || remainder < 0)
2152 return GLX_BAD_VALUE;
2155 return GLX_BAD_CONTEXT;
2157 #ifdef GLX_DIRECT_RENDERING
2158 if (!gc->driContext)
2159 return GLX_BAD_CONTEXT;
2162 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2163 #ifdef GLX_DIRECT_RENDERING
2164 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2167 #ifdef GLX_DIRECT_RENDERING
2168 if (psc->driScreen && psc->driScreen->waitForMSC) {
2169 ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
2171 *count = (unsigned) msc;
2172 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
2176 return GLX_BAD_CONTEXT;
2179 #endif /* GLX_USE_APPLEGL */
2182 ** GLX_SGIX_fbconfig
2183 ** Many of these functions are aliased to GLX 1.3 entry points in the
2184 ** GLX_functions table.
2188 GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
2189 (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
2190 (dpy, config, attribute, value), glXGetFBConfigAttrib)
2192 PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
2193 (Display * dpy, int screen, int *attrib_list,
2194 int *nelements), (dpy, screen, attrib_list, nelements),
2197 PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
2198 (Display * dpy, GLXFBConfigSGIX config),
2199 (dpy, config), glXGetVisualFromFBConfig)
2202 glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
2203 GLXFBConfigSGIX config,
2206 #ifndef GLX_USE_APPLEGL
2207 xGLXVendorPrivateWithReplyReq *vpreq;
2208 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
2209 GLXPixmap xid = None;
2211 __GLXscreenConfigs *psc;
2213 const __GLcontextModes *const fbconfig = (__GLcontextModes *) config;
2216 if ((dpy == NULL) || (config == NULL)) {
2219 #ifdef GLX_USE_APPLEGL
2220 if(apple_glx_pixmap_create(dpy, fbconfig->screen, pixmap, fbconfig))
2225 psc = GetGLXScreenConfigs(dpy, fbconfig->screen);
2227 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
2228 opcode = __glXSetupForCommand(dpy);
2233 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2235 GetReqExtra(GLXVendorPrivateWithReply,
2236 sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
2237 sz_xGLXVendorPrivateWithReplyReq, vpreq);
2238 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
2239 req->reqType = opcode;
2240 req->glxCode = X_GLXVendorPrivateWithReply;
2241 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
2242 req->screen = fbconfig->screen;
2243 req->fbconfig = fbconfig->fbconfigID;
2244 req->pixmap = pixmap;
2245 req->glxpixmap = xid = XAllocID(dpy);
2255 glXCreateContextWithConfigSGIX(Display * dpy,
2256 GLXFBConfigSGIX config, int renderType,
2257 GLXContext shareList, Bool allowDirect)
2259 GLXContext gc = NULL;
2260 const __GLcontextModes *const fbconfig = (__GLcontextModes *) config;
2261 __GLXscreenConfigs *psc;
2264 if ((dpy == NULL) || (config == NULL)) {
2268 psc = GetGLXScreenConfigs(dpy, fbconfig->screen);
2270 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
2271 gc = CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList,
2273 X_GLXvop_CreateContextWithConfigSGIX, renderType,
2281 PUBLIC GLXFBConfigSGIX
2282 glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis)
2284 __GLXdisplayPrivate *priv;
2285 __GLXscreenConfigs *psc = NULL;
2287 if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) != Success)
2288 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)
2289 && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) {
2290 return (GLXFBConfigSGIX) _gl_context_modes_find_visual(psc->configs,
2297 #ifndef GLX_USE_APPLEGL
2299 ** GLX_SGIX_swap_group
2302 __glXJoinSwapGroupSGIX(Display * dpy, GLXDrawable drawable,
2312 ** GLX_SGIX_swap_barrier
2315 __glXBindSwapBarrierSGIX(Display * dpy, GLXDrawable drawable, int barrier)
2323 __glXQueryMaxSwapBarriersSGIX(Display * dpy, int screen, int *max)
2333 ** GLX_OML_sync_control
2336 __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
2337 int64_t * ust, int64_t * msc, int64_t * sbc)
2339 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2341 #ifdef GLX_DIRECT_RENDERING
2342 __GLXDRIdrawable *pdraw;
2344 __GLXscreenConfigs *psc;
2349 #ifdef GLX_DIRECT_RENDERING
2350 pdraw = GetGLXDRIDrawable(dpy, drawable);
2351 psc = pdraw ? pdraw->psc : NULL;
2352 if (pdraw && psc->driScreen->getDrawableMSC) {
2353 ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
2361 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2363 __glxGetMscRate(__GLXDRIdrawable *glxDraw,
2364 int32_t * numerator, int32_t * denominator)
2367 __GLXscreenConfigs *psc;
2368 XF86VidModeModeLine mode_line;
2373 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2374 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
2375 unsigned n = dot_clock * 1000;
2376 unsigned d = mode_line.vtotal * mode_line.htotal;
2378 # define V_INTERLACE 0x010
2379 # define V_DBLSCAN 0x020
2381 if (mode_line.flags & V_INTERLACE)
2383 else if (mode_line.flags & V_DBLSCAN)
2386 /* The OML_sync_control spec requires that if the refresh rate is a
2387 * whole number, that the returned numerator be equal to the refresh
2388 * rate and the denominator be 1.
2396 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2398 /* This is a poor man's way to reduce a fraction. It's far from
2399 * perfect, but it will work well enough for this situation.
2402 for (i = 0; f[i] != 0; i++) {
2403 while (n % f[i] == 0 && d % f[i] == 0) {
2429 * Determine the refresh rate of the specified drawable and display.
2431 * \param dpy Display whose refresh rate is to be determined.
2432 * \param drawable Drawable whose refresh rate is to be determined.
2433 * \param numerator Numerator of the refresh rate.
2434 * \param demoninator Denominator of the refresh rate.
2435 * \return If the refresh rate for the specified display and drawable could
2436 * be calculated, True is returned. Otherwise False is returned.
2438 * \note This function is implemented entirely client-side. A lot of other
2439 * functionality is required to export GLX_OML_sync_control, so on
2440 * XFree86 this function can be called for direct-rendering contexts
2441 * when GLX_OML_sync_control appears in the client extension string.
2445 __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2446 int32_t * numerator, int32_t * denominator)
2448 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2449 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
2454 return __glxGetMscRate(draw, numerator, denominator);
2466 __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
2467 int64_t target_msc, int64_t divisor, int64_t remainder)
2469 GLXContext gc = __glXGetCurrentContext();
2470 #ifdef GLX_DIRECT_RENDERING
2471 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2472 __GLXscreenConfigs *psc = pdraw ? pdraw->psc : NULL;
2475 if (!gc) /* no GLX for this */
2478 #ifdef GLX_DIRECT_RENDERING
2479 if (!pdraw || !gc->driContext)
2483 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2484 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2485 * of -1 if the function failed because of errors detected in the input
2488 if (divisor < 0 || remainder < 0 || target_msc < 0)
2490 if (divisor > 0 && remainder >= divisor)
2493 if (target_msc == 0 && divisor == 0 && remainder == 0)
2496 #ifdef GLX_DIRECT_RENDERING
2497 if (psc->driScreen && psc->driScreen->swapBuffers)
2498 return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor,
2507 __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2508 int64_t target_msc, int64_t divisor,
2509 int64_t remainder, int64_t * ust,
2510 int64_t * msc, int64_t * sbc)
2512 #ifdef GLX_DIRECT_RENDERING
2513 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2515 __GLXscreenConfigs *psc = pdraw ? pdraw->psc : NULL;
2519 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2520 * error", but the return type in the spec is Bool.
2522 if (divisor < 0 || remainder < 0 || target_msc < 0)
2524 if (divisor > 0 && remainder >= divisor)
2527 #ifdef GLX_DIRECT_RENDERING
2528 if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
2529 ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
2540 __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2541 int64_t target_sbc, int64_t * ust,
2542 int64_t * msc, int64_t * sbc)
2544 #ifdef GLX_DIRECT_RENDERING
2545 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2547 __GLXscreenConfigs *psc = pdraw ? pdraw->psc : NULL;
2550 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2551 * error", but the return type in the spec is Bool.
2556 #ifdef GLX_DIRECT_RENDERING
2557 if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
2558 ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
2570 * Mesa extension stubs. These will help reduce portability problems.
2575 * Release all buffers associated with the specified GLX drawable.
2578 * This function was intended for stand-alone Mesa. The issue there is that
2579 * the library doesn't get any notification when a window is closed. In
2580 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2581 * supported, there are 3 different functions to destroy a drawable. It
2582 * should be possible to create GLX protocol (or have it determine which
2583 * protocol to use based on the type of the drawable) to have one function
2584 * do the work of 3. For the direct-rendering case, this function could
2585 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2586 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2587 * would need to be used. This really should be done as part of the new DRI
2590 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2591 * __driGarbageCollectDrawables
2592 * glXDestroyGLXPixmap
2593 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2594 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2597 __glXReleaseBuffersMESA(Display * dpy, GLXDrawable d)
2606 glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual,
2607 Pixmap pixmap, Colormap cmap)
2620 * GLX_MESA_copy_sub_buffer
2622 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2624 __glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
2625 int x, int y, int width, int height)
2627 xGLXVendorPrivateReq *req;
2630 CARD32 *drawable_ptr;
2631 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2634 #ifdef __DRI_COPY_SUB_BUFFER
2635 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2636 if (pdraw != NULL) {
2637 __GLXscreenConfigs *psc = pdraw->psc;
2638 if (psc->driScreen->copySubBuffer != NULL) {
2640 (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height);
2647 opcode = __glXSetupForCommand(dpy);
2652 ** The calling thread may or may not have a current context. If it
2653 ** does, send the context tag so the server can do a flush.
2655 gc = __glXGetCurrentContext();
2656 if ((gc != NULL) && (dpy == gc->currentDpy) &&
2657 ((drawable == gc->currentDrawable) ||
2658 (drawable == gc->currentReadable))) {
2659 tag = gc->currentContextTag;
2666 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req);
2667 req->reqType = opcode;
2668 req->glxCode = X_GLXVendorPrivate;
2669 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2670 req->contextTag = tag;
2672 drawable_ptr = (CARD32 *) (req + 1);
2673 x_ptr = (INT32 *) (drawable_ptr + 1);
2674 y_ptr = (INT32 *) (drawable_ptr + 2);
2675 w_ptr = (INT32 *) (drawable_ptr + 3);
2676 h_ptr = (INT32 *) (drawable_ptr + 4);
2678 *drawable_ptr = drawable;
2690 * GLX_EXT_texture_from_pixmap
2693 indirect_bind_tex_image(Display * dpy,
2694 GLXDrawable drawable,
2695 int buffer, const int *attrib_list)
2697 xGLXVendorPrivateReq *req;
2698 GLXContext gc = __glXGetCurrentContext();
2699 CARD32 *drawable_ptr;
2701 CARD32 *num_attrib_ptr;
2708 while (attrib_list[i * 2] != None)
2712 opcode = __glXSetupForCommand(dpy);
2717 GetReqExtra(GLXVendorPrivate, 12 + 8 * i, req);
2718 req->reqType = opcode;
2719 req->glxCode = X_GLXVendorPrivate;
2720 req->vendorCode = X_GLXvop_BindTexImageEXT;
2721 req->contextTag = gc->currentContextTag;
2723 drawable_ptr = (CARD32 *) (req + 1);
2724 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2725 num_attrib_ptr = (CARD32 *) (buffer_ptr + 1);
2726 attrib_ptr = (CARD32 *) (num_attrib_ptr + 1);
2728 *drawable_ptr = drawable;
2729 *buffer_ptr = buffer;
2730 *num_attrib_ptr = (CARD32) i;
2734 while (attrib_list[i * 2] != None) {
2735 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0];
2736 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1];
2746 indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
2748 xGLXVendorPrivateReq *req;
2749 GLXContext gc = __glXGetCurrentContext();
2750 CARD32 *drawable_ptr;
2754 opcode = __glXSetupForCommand(dpy);
2759 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32), req);
2760 req->reqType = opcode;
2761 req->glxCode = X_GLXVendorPrivate;
2762 req->vendorCode = X_GLXvop_ReleaseTexImageEXT;
2763 req->contextTag = gc->currentContextTag;
2765 drawable_ptr = (CARD32 *) (req + 1);
2766 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2768 *drawable_ptr = drawable;
2769 *buffer_ptr = buffer;
2775 static const struct glx_context_vtable indirect_context_vtable = {
2778 indirect_use_x_font,
2779 indirect_bind_tex_image,
2780 indirect_release_tex_image,
2785 __glXBindTexImageEXT(Display * dpy,
2786 GLXDrawable drawable, int buffer, const int *attrib_list)
2788 GLXContext gc = __glXGetCurrentContext();
2790 if (gc == NULL || gc->vtable->bind_tex_image == NULL)
2793 gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
2797 __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
2799 GLXContext gc = __glXGetCurrentContext();
2801 if (gc == NULL || gc->vtable->release_tex_image == NULL)
2804 gc->vtable->release_tex_image(dpy, drawable, buffer);
2809 #endif /* GLX_USE_APPLEGL */
2812 * \c strdup is actually not a standard ANSI C or POSIX routine.
2813 * Irix will not define it if ANSI mode is in effect.
2818 __glXstrdup(const char *str)
2821 copy = (char *) Xmalloc(strlen(str) + 1);
2829 ** glXGetProcAddress support
2832 struct name_address_pair
2838 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2839 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2841 static const struct name_address_pair GLX_functions[] = {
2842 /*** GLX_VERSION_1_0 ***/
2843 GLX_FUNCTION(glXChooseVisual),
2844 GLX_FUNCTION(glXCopyContext),
2845 GLX_FUNCTION(glXCreateContext),
2846 GLX_FUNCTION(glXCreateGLXPixmap),
2847 GLX_FUNCTION(glXDestroyContext),
2848 GLX_FUNCTION(glXDestroyGLXPixmap),
2849 GLX_FUNCTION(glXGetConfig),
2850 GLX_FUNCTION(glXGetCurrentContext),
2851 GLX_FUNCTION(glXGetCurrentDrawable),
2852 GLX_FUNCTION(glXIsDirect),
2853 GLX_FUNCTION(glXMakeCurrent),
2854 GLX_FUNCTION(glXQueryExtension),
2855 GLX_FUNCTION(glXQueryVersion),
2856 GLX_FUNCTION(glXSwapBuffers),
2857 GLX_FUNCTION(glXUseXFont),
2858 GLX_FUNCTION(glXWaitGL),
2859 GLX_FUNCTION(glXWaitX),
2861 /*** GLX_VERSION_1_1 ***/
2862 GLX_FUNCTION(glXGetClientString),
2863 GLX_FUNCTION(glXQueryExtensionsString),
2864 GLX_FUNCTION(glXQueryServerString),
2866 /*** GLX_VERSION_1_2 ***/
2867 GLX_FUNCTION(glXGetCurrentDisplay),
2869 /*** GLX_VERSION_1_3 ***/
2870 GLX_FUNCTION(glXChooseFBConfig),
2871 GLX_FUNCTION(glXCreateNewContext),
2872 GLX_FUNCTION(glXCreatePbuffer),
2873 GLX_FUNCTION(glXCreatePixmap),
2874 GLX_FUNCTION(glXCreateWindow),
2875 GLX_FUNCTION(glXDestroyPbuffer),
2876 GLX_FUNCTION(glXDestroyPixmap),
2877 GLX_FUNCTION(glXDestroyWindow),
2878 GLX_FUNCTION(glXGetCurrentReadDrawable),
2879 GLX_FUNCTION(glXGetFBConfigAttrib),
2880 GLX_FUNCTION(glXGetFBConfigs),
2881 GLX_FUNCTION(glXGetSelectedEvent),
2882 GLX_FUNCTION(glXGetVisualFromFBConfig),
2883 GLX_FUNCTION(glXMakeContextCurrent),
2884 GLX_FUNCTION(glXQueryContext),
2885 GLX_FUNCTION(glXQueryDrawable),
2886 GLX_FUNCTION(glXSelectEvent),
2888 #ifndef GLX_USE_APPLEGL
2889 /*** GLX_SGI_swap_control ***/
2890 GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI),
2892 /*** GLX_SGI_video_sync ***/
2893 GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI),
2894 GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI),
2896 /*** GLX_SGI_make_current_read ***/
2897 GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent),
2898 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable),
2900 /*** GLX_EXT_import_context ***/
2901 GLX_FUNCTION(glXFreeContextEXT),
2902 GLX_FUNCTION(glXGetContextIDEXT),
2903 GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
2904 GLX_FUNCTION(glXImportContextEXT),
2905 GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
2908 /*** GLX_SGIX_fbconfig ***/
2909 GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
2910 GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig),
2911 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX),
2912 GLX_FUNCTION(glXCreateContextWithConfigSGIX),
2913 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
2914 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
2916 #ifndef GLX_USE_APPLEGL
2917 /*** GLX_SGIX_pbuffer ***/
2918 GLX_FUNCTION(glXCreateGLXPbufferSGIX),
2919 GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
2920 GLX_FUNCTION(glXQueryGLXPbufferSGIX),
2921 GLX_FUNCTION(glXSelectEventSGIX),
2922 GLX_FUNCTION(glXGetSelectedEventSGIX),
2924 /*** GLX_SGIX_swap_group ***/
2925 GLX_FUNCTION2(glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX),
2927 /*** GLX_SGIX_swap_barrier ***/
2928 GLX_FUNCTION2(glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX),
2929 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX),
2931 /*** GLX_MESA_copy_sub_buffer ***/
2932 GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA),
2934 /*** GLX_MESA_pixmap_colormap ***/
2935 GLX_FUNCTION(glXCreateGLXPixmapMESA),
2937 /*** GLX_MESA_release_buffers ***/
2938 GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA),
2940 /*** GLX_MESA_swap_control ***/
2941 GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA),
2942 GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA),
2945 /*** GLX_ARB_get_proc_address ***/
2946 GLX_FUNCTION(glXGetProcAddressARB),
2949 GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
2951 #ifndef GLX_USE_APPLEGL
2952 /*** GLX_OML_sync_control ***/
2953 GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML),
2954 GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML),
2955 GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML),
2956 GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML),
2957 GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML),
2959 /*** GLX_EXT_texture_from_pixmap ***/
2960 GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT),
2961 GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT),
2964 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2965 /*** DRI configuration ***/
2966 GLX_FUNCTION(glXGetScreenDriver),
2967 GLX_FUNCTION(glXGetDriverConfig),
2970 {NULL, NULL} /* end of list */
2973 #ifndef GLX_USE_APPLEGL
2974 static const GLvoid *
2975 get_glx_proc_address(const char *funcName)
2979 /* try static functions */
2980 for (i = 0; GLX_functions[i].Name; i++) {
2981 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2982 return GLX_functions[i].Address;
2990 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2991 * \c glXGetProcAddress.
2993 * \param procName Name of a GL or GLX function.
2994 * \returns A pointer to the named function
2996 * \sa glXGetProcAddress
2998 PUBLIC void (*glXGetProcAddressARB(const GLubyte * procName)) (void)
3000 typedef void (*gl_function) (void);
3004 /* Search the table of GLX and internal functions first. If that
3005 * fails and the supplied name could be a valid core GL name, try
3006 * searching the core GL function table. This check is done to prevent
3007 * DRI based drivers from searching the core GL function table for
3008 * internal API functions.
3010 #ifdef GLX_USE_APPLEGL
3011 f = (gl_function) apple_glx_get_proc_address(procName);
3013 f = (gl_function) get_glx_proc_address((const char *) procName);
3014 if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
3015 && (procName[2] != 'X')) {
3016 f = (gl_function) _glapi_get_proc_address((const char *) procName);
3023 * Get the address of a named GL function. This is the GLX 1.4 name for
3024 * \c glXGetProcAddressARB.
3026 * \param procName Name of a GL or GLX function.
3027 * \returns A pointer to the named function
3029 * \sa glXGetProcAddressARB
3031 PUBLIC void (*glXGetProcAddress(const GLubyte * procName)) (void)
3032 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3033 __attribute__ ((alias("glXGetProcAddressARB")));
3036 return glXGetProcAddressARB(procName);
3038 #endif /* __GNUC__ */
3041 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
3043 * Get the unadjusted system time (UST). Currently, the UST is measured in
3044 * microseconds since Epoc. The actual resolution of the UST may vary from
3045 * system to system, and the units may vary from release to release.
3046 * Drivers should not call this function directly. They should instead use
3047 * \c glXGetProcAddress to obtain a pointer to the function.
3049 * \param ust Location to store the 64-bit UST
3050 * \returns Zero on success or a negative errno value on failure.
3052 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3054 * \since Internal API version 20030317.
3057 __glXGetUST(int64_t * ust)
3065 if (gettimeofday(&tv, NULL) == 0) {
3066 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
3073 #endif /* GLX_DIRECT_RENDERING */