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 gc->vtable->destroy(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 glx_send_destroy_context(Display *dpy, XID xid)
529 CARD8 opcode = __glXSetupForCommand(dpy);
530 xGLXDestroyContextReq *req;
533 GetReq(GLXDestroyContext, req);
534 req->reqType = opcode;
535 req->glxCode = X_GLXDestroyContext;
542 indirect_destroy_context(__GLXcontext *gc)
545 glx_send_destroy_context(gc->psc->dpy, gc->xid);
547 __glXFreeVertexArrayState(gc);
550 XFree((char *) gc->vendor);
552 XFree((char *) gc->renderer);
554 XFree((char *) gc->version);
556 XFree((char *) gc->extensions);
557 __glFreeAttributeState(gc);
558 XFree((char *) gc->buf);
559 Xfree((char *) gc->client_state_private);
564 ** Destroy the named context
567 DestroyContext(Display * dpy, GLXContext gc)
573 if (gc->currentDpy) {
574 /* This context is bound to some thread. According to the man page,
575 * we should not actually delete the context until it's unbound.
576 * Note that we set gc->xid = None above. In MakeContextCurrent()
577 * we check for that and delete the context there.
585 if (gc->vtable->destroy)
586 gc->vtable->destroy(gc);
590 glXDestroyContext(Display * dpy, GLXContext gc)
592 DestroyContext(dpy, gc);
596 ** Return the major and minor version #s for the GLX extension
599 glXQueryVersion(Display * dpy, int *major, int *minor)
601 __GLXdisplayPrivate *priv;
603 /* Init the extension. This fetches the major and minor version. */
604 priv = __glXInitialize(dpy);
609 *major = priv->majorVersion;
611 *minor = priv->minorVersion;
616 ** Query the existance of the GLX extension
619 glXQueryExtension(Display * dpy, int *errorBase, int *eventBase)
621 int major_op, erb, evb;
624 rv = XQueryExtension(dpy, GLX_EXTENSION_NAME, &major_op, &evb, &erb);
635 indirect_wait_gl(__GLXcontext *gc)
638 Display *dpy = gc->currentDpy;
640 /* Flush any pending commands out */
641 __glXFlushRenderBuffer(gc, gc->pc);
643 /* Send the glXWaitGL request */
645 GetReq(GLXWaitGL, req);
646 req->reqType = gc->majorOpcode;
647 req->glxCode = X_GLXWaitGL;
648 req->contextTag = gc->currentContextTag;
654 ** Put a barrier in the token stream that forces the GL to finish its
655 ** work before X can proceed.
660 GLXContext gc = __glXGetCurrentContext();
662 if (gc && gc->vtable->use_x_font)
663 gc->vtable->wait_gl(gc);
667 indirect_wait_x(__GLXcontext *gc)
670 Display *dpy = gc->currentDpy;
672 /* Flush any pending commands out */
673 __glXFlushRenderBuffer(gc, gc->pc);
676 GetReq(GLXWaitX, req);
677 req->reqType = gc->majorOpcode;
678 req->glxCode = X_GLXWaitX;
679 req->contextTag = gc->currentContextTag;
685 ** Put a barrier in the token stream that forces X to finish its
686 ** work before GL can proceed.
691 GLXContext gc = __glXGetCurrentContext();
693 if (gc && gc->vtable->use_x_font)
694 gc->vtable->wait_x(gc);
698 indirect_use_x_font(__GLXcontext *gc,
699 Font font, int first, int count, int listBase)
701 xGLXUseXFontReq *req;
702 Display *dpy = gc->currentDpy;
704 /* Flush any pending commands out */
705 __glXFlushRenderBuffer(gc, gc->pc);
707 /* Send the glXUseFont request */
709 GetReq(GLXUseXFont, req);
710 req->reqType = gc->majorOpcode;
711 req->glxCode = X_GLXUseXFont;
712 req->contextTag = gc->currentContextTag;
716 req->listBase = listBase;
721 #ifdef GLX_USE_APPLEGL
724 applegl_destroy_context(__GLXcontext *gc)
726 apple_glx_destroy_context(&gc->driContext, gc->currentDpy);
730 applegl_wait_gl(__GLXcontext *gc)
736 applegl_wait_x(__GLXcontext *gc)
738 apple_glx_waitx(gc->dpy, gc->driContext);
741 static const struct glx_context_vtable applegl_context_vtable = {
742 applegl_destroy_context,
746 NULL, /* bind_tex_image, */
747 NULL, /* release_tex_image, */
753 glXUseXFont(Font font, int first, int count, int listBase)
755 GLXContext gc = __glXGetCurrentContext();
757 if (gc && gc->vtable->use_x_font)
758 gc->vtable->use_x_font(gc, font, first, count, listBase);
761 /************************************************************************/
764 ** Copy the source context to the destination context using the
768 glXCopyContext(Display * dpy, GLXContext source,
769 GLXContext dest, unsigned long mask)
771 #ifdef GLX_USE_APPLEGL
772 GLXContext gc = __glXGetCurrentContext();
776 if(apple_glx_copy_context(gc->driContext, source->driContext, dest->driContext,
777 mask, &errorcode, &x11error)) {
778 __glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
782 xGLXCopyContextReq *req;
783 GLXContext gc = __glXGetCurrentContext();
787 opcode = __glXSetupForCommand(dpy);
792 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
793 if (gc->driContext) {
794 /* NOT_DONE: This does not work yet */
799 ** If the source is the current context, send its tag so that the context
800 ** can be flushed before the copy.
802 if (source == gc && dpy == gc->currentDpy) {
803 tag = gc->currentContextTag;
809 /* Send the glXCopyContext request */
811 GetReq(GLXCopyContext, req);
812 req->reqType = opcode;
813 req->glxCode = X_GLXCopyContext;
814 req->source = source ? source->xid : None;
815 req->dest = dest ? dest->xid : None;
817 req->contextTag = tag;
820 #endif /* GLX_USE_APPLEGL */
825 * Determine if a context uses direct rendering.
827 * \param dpy Display where the context was created.
828 * \param contextID ID of the context to be tested.
830 * \returns \c GL_TRUE if the context is direct rendering or not.
833 __glXIsDirect(Display * dpy, GLXContextID contextID)
835 #if !defined(USE_XCB)
836 xGLXIsDirectReq *req;
837 xGLXIsDirectReply reply;
841 opcode = __glXSetupForCommand(dpy);
847 xcb_connection_t *c = XGetXCBConnection(dpy);
848 xcb_glx_is_direct_reply_t *reply = xcb_glx_is_direct_reply(c,
853 const Bool is_direct = reply->is_direct ? True : False;
858 /* Send the glXIsDirect request */
860 GetReq(GLXIsDirect, req);
861 req->reqType = opcode;
862 req->glxCode = X_GLXIsDirect;
863 req->context = contextID;
864 _XReply(dpy, (xReply *) & reply, 0, False);
868 return reply.isDirect;
874 * Shouldn't this function \b always return \c GL_FALSE when
875 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
876 * the GLX protocol here at all?
879 glXIsDirect(Display * dpy, GLXContext gc)
884 else if (GC_IS_DIRECT(gc)) {
887 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
890 return __glXIsDirect(dpy, gc->xid);
895 glXCreateGLXPixmap(Display * dpy, XVisualInfo * vis, Pixmap pixmap)
897 #ifdef GLX_USE_APPLEGL
898 int screen = vis->screen;
899 __GLXscreenConfigs *const psc = GetGLXScreenConfigs(dpy, screen);
900 const __GLcontextModes *modes;
902 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
904 if(apple_glx_pixmap_create(dpy, vis->screen, pixmap, modes))
909 xGLXCreateGLXPixmapReq *req;
913 opcode = __glXSetupForCommand(dpy);
918 /* Send the glXCreateGLXPixmap request */
920 GetReq(GLXCreateGLXPixmap, req);
921 req->reqType = opcode;
922 req->glxCode = X_GLXCreateGLXPixmap;
923 req->screen = vis->screen;
924 req->visual = vis->visualid;
925 req->pixmap = pixmap;
926 req->glxpixmap = xid = XAllocID(dpy);
930 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
932 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
933 * is actually bound to a context... */
935 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
936 __GLXDRIdrawable *pdraw;
937 __GLXscreenConfigs *psc;
938 __GLcontextModes *modes;
940 psc = priv->screenConfigs[vis->screen];
941 if (psc->driScreen == NULL)
943 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
944 pdraw = psc->driScreen->createDrawable(psc, pixmap, req->glxpixmap, modes);
946 fprintf(stderr, "failed to create pixmap\n");
950 if (__glxHashInsert(priv->drawHash, req->glxpixmap, pdraw)) {
951 (*pdraw->destroyDrawable) (pdraw);
952 return None; /* FIXME: Check what we're supposed to do here... */
962 ** Destroy the named pixmap
965 glXDestroyGLXPixmap(Display * dpy, GLXPixmap glxpixmap)
967 #ifdef GLX_USE_APPLEGL
968 if(apple_glx_pixmap_destroy(dpy, glxpixmap))
969 __glXSendError(dpy, GLXBadPixmap, glxpixmap, X_GLXDestroyPixmap, false);
971 xGLXDestroyGLXPixmapReq *req;
974 opcode = __glXSetupForCommand(dpy);
979 /* Send the glXDestroyGLXPixmap request */
981 GetReq(GLXDestroyGLXPixmap, req);
982 req->reqType = opcode;
983 req->glxCode = X_GLXDestroyGLXPixmap;
984 req->glxpixmap = glxpixmap;
988 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
990 __GLXdisplayPrivate *const priv = __glXInitialize(dpy);
991 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, glxpixmap);
994 (*pdraw->destroyDrawable) (pdraw);
995 __glxHashDelete(priv->drawHash, glxpixmap);
999 #endif /* GLX_USE_APPLEGL */
1003 glXSwapBuffers(Display * dpy, GLXDrawable drawable)
1005 #ifdef GLX_USE_APPLEGL
1006 GLXContext gc = glXGetCurrentContext();
1007 if(gc && apple_glx_is_current_drawable(dpy, gc->driContext, drawable)) {
1008 apple_glx_swap_buffers(gc->driContext);
1010 __glXSendError(dpy, GLXBadCurrentWindow, 0, X_GLXSwapBuffers, false);
1017 xcb_connection_t *c;
1019 xGLXSwapBuffersReq *req;
1022 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1023 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
1025 if (pdraw != NULL) {
1027 (*pdraw->psc->driScreen->swapBuffers)(pdraw, 0, 0, 0);
1032 opcode = __glXSetupForCommand(dpy);
1038 ** The calling thread may or may not have a current context. If it
1039 ** does, send the context tag so the server can do a flush.
1041 gc = __glXGetCurrentContext();
1042 if ((gc != NULL) && (dpy == gc->currentDpy) &&
1043 ((drawable == gc->currentDrawable)
1044 || (drawable == gc->currentReadable))) {
1045 tag = gc->currentContextTag;
1052 c = XGetXCBConnection(dpy);
1053 xcb_glx_swap_buffers(c, tag, drawable);
1056 /* Send the glXSwapBuffers request */
1058 GetReq(GLXSwapBuffers, req);
1059 req->reqType = opcode;
1060 req->glxCode = X_GLXSwapBuffers;
1061 req->drawable = drawable;
1062 req->contextTag = tag;
1066 #endif /* USE_XCB */
1067 #endif /* GLX_USE_APPLEGL */
1072 ** Return configuration information for the given display, screen and
1073 ** visual combination.
1076 glXGetConfig(Display * dpy, XVisualInfo * vis, int attribute,
1079 __GLXdisplayPrivate *priv;
1080 __GLXscreenConfigs *psc;
1081 __GLcontextModes *modes;
1084 status = GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc);
1085 if (status == Success) {
1086 modes = _gl_context_modes_find_visual(psc->visuals, vis->visualid);
1088 /* Lookup attribute after first finding a match on the visual */
1089 if (modes != NULL) {
1090 return _gl_get_context_mode_data(modes, attribute, value_return);
1093 status = GLX_BAD_VISUAL;
1097 ** If we can't find the config for this visual, this visual is not
1098 ** supported by the OpenGL implementation on the server.
1100 if ((status == GLX_BAD_VISUAL) && (attribute == GLX_USE_GL)) {
1101 *value_return = GL_FALSE;
1108 /************************************************************************/
1111 init_fbconfig_for_chooser(__GLcontextModes * config,
1112 GLboolean fbconfig_style_tags)
1114 memset(config, 0, sizeof(__GLcontextModes));
1115 config->visualID = (XID) GLX_DONT_CARE;
1116 config->visualType = GLX_DONT_CARE;
1118 /* glXChooseFBConfig specifies different defaults for these two than
1121 if (fbconfig_style_tags) {
1122 config->rgbMode = GL_TRUE;
1123 config->doubleBufferMode = GLX_DONT_CARE;
1126 config->visualRating = GLX_DONT_CARE;
1127 config->transparentPixel = GLX_NONE;
1128 config->transparentRed = GLX_DONT_CARE;
1129 config->transparentGreen = GLX_DONT_CARE;
1130 config->transparentBlue = GLX_DONT_CARE;
1131 config->transparentAlpha = GLX_DONT_CARE;
1132 config->transparentIndex = GLX_DONT_CARE;
1134 config->drawableType = GLX_WINDOW_BIT;
1135 config->renderType =
1136 (config->rgbMode) ? GLX_RGBA_BIT : GLX_COLOR_INDEX_BIT;
1137 config->xRenderable = GLX_DONT_CARE;
1138 config->fbconfigID = (GLXFBConfigID) (GLX_DONT_CARE);
1140 config->swapMethod = GLX_DONT_CARE;
1143 #define MATCH_DONT_CARE( param ) \
1145 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1146 && (a-> param != b-> param) ) { \
1151 #define MATCH_MINIMUM( param ) \
1153 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1154 && (a-> param > b-> param) ) { \
1159 #define MATCH_EXACT( param ) \
1161 if ( a-> param != b-> param) { \
1166 /* Test that all bits from a are contained in b */
1167 #define MATCH_MASK(param) \
1169 if ((a->param & ~b->param) != 0) \
1174 * Determine if two GLXFBConfigs are compatible.
1176 * \param a Application specified config to test.
1177 * \param b Server specified config to test against \c a.
1180 fbconfigs_compatible(const __GLcontextModes * const a,
1181 const __GLcontextModes * const b)
1183 MATCH_DONT_CARE(doubleBufferMode);
1184 MATCH_DONT_CARE(visualType);
1185 MATCH_DONT_CARE(visualRating);
1186 MATCH_DONT_CARE(xRenderable);
1187 MATCH_DONT_CARE(fbconfigID);
1188 MATCH_DONT_CARE(swapMethod);
1190 MATCH_MINIMUM(rgbBits);
1191 MATCH_MINIMUM(numAuxBuffers);
1192 MATCH_MINIMUM(redBits);
1193 MATCH_MINIMUM(greenBits);
1194 MATCH_MINIMUM(blueBits);
1195 MATCH_MINIMUM(alphaBits);
1196 MATCH_MINIMUM(depthBits);
1197 MATCH_MINIMUM(stencilBits);
1198 MATCH_MINIMUM(accumRedBits);
1199 MATCH_MINIMUM(accumGreenBits);
1200 MATCH_MINIMUM(accumBlueBits);
1201 MATCH_MINIMUM(accumAlphaBits);
1202 MATCH_MINIMUM(sampleBuffers);
1203 MATCH_MINIMUM(maxPbufferWidth);
1204 MATCH_MINIMUM(maxPbufferHeight);
1205 MATCH_MINIMUM(maxPbufferPixels);
1206 MATCH_MINIMUM(samples);
1208 MATCH_DONT_CARE(stereoMode);
1211 MATCH_MASK(drawableType);
1212 MATCH_MASK(renderType);
1214 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1215 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1216 * Technically speaking, it is a bug in the DDX driver, but there is
1217 * enough of an installed base to work around the problem here. In any
1218 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1219 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1220 * 0 from the server to be a match to maintain backward compatibility with
1221 * the (broken) drivers.
1224 if (a->transparentPixel != (int) GLX_DONT_CARE && a->transparentPixel != 0) {
1225 if (a->transparentPixel == GLX_NONE) {
1226 if (b->transparentPixel != GLX_NONE && b->transparentPixel != 0)
1230 MATCH_EXACT(transparentPixel);
1233 switch (a->transparentPixel) {
1234 case GLX_TRANSPARENT_RGB:
1235 MATCH_DONT_CARE(transparentRed);
1236 MATCH_DONT_CARE(transparentGreen);
1237 MATCH_DONT_CARE(transparentBlue);
1238 MATCH_DONT_CARE(transparentAlpha);
1241 case GLX_TRANSPARENT_INDEX:
1242 MATCH_DONT_CARE(transparentIndex);
1254 /* There's some trickly language in the GLX spec about how this is supposed
1255 * to work. Basically, if a given component size is either not specified
1256 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1257 * Well, that's really hard to do with the code as-is. This behavior is
1258 * closer to correct, but still not technically right.
1260 #define PREFER_LARGER_OR_ZERO(comp) \
1262 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1263 if ( ((*a)-> comp) == 0 ) { \
1266 else if ( ((*b)-> comp) == 0 ) { \
1270 return ((*b)-> comp) - ((*a)-> comp) ; \
1275 #define PREFER_LARGER(comp) \
1277 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1278 return ((*b)-> comp) - ((*a)-> comp) ; \
1282 #define PREFER_SMALLER(comp) \
1284 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1285 return ((*a)-> comp) - ((*b)-> comp) ; \
1290 * Compare two GLXFBConfigs. This function is intended to be used as the
1291 * compare function passed in to qsort.
1293 * \returns If \c a is a "better" config, according to the specification of
1294 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1295 * better, then a number greater than zero is return. If both are
1296 * equal, zero is returned.
1297 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1300 fbconfig_compare(const __GLcontextModes * const *const a,
1301 const __GLcontextModes * const *const b)
1303 /* The order of these comparisons must NOT change. It is defined by
1304 * the GLX 1.3 spec and ARB_multisample.
1307 PREFER_SMALLER(visualSelectGroup);
1309 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1310 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1311 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1313 PREFER_SMALLER(visualRating);
1315 /* This isn't quite right. It is supposed to compare the sum of the
1316 * components the user specifically set minimums for.
1318 PREFER_LARGER_OR_ZERO(redBits);
1319 PREFER_LARGER_OR_ZERO(greenBits);
1320 PREFER_LARGER_OR_ZERO(blueBits);
1321 PREFER_LARGER_OR_ZERO(alphaBits);
1323 PREFER_SMALLER(rgbBits);
1325 if (((*a)->doubleBufferMode != (*b)->doubleBufferMode)) {
1326 /* Prefer single-buffer.
1328 return (!(*a)->doubleBufferMode) ? -1 : 1;
1331 PREFER_SMALLER(numAuxBuffers);
1333 PREFER_LARGER_OR_ZERO(depthBits);
1334 PREFER_SMALLER(stencilBits);
1336 /* This isn't quite right. It is supposed to compare the sum of the
1337 * components the user specifically set minimums for.
1339 PREFER_LARGER_OR_ZERO(accumRedBits);
1340 PREFER_LARGER_OR_ZERO(accumGreenBits);
1341 PREFER_LARGER_OR_ZERO(accumBlueBits);
1342 PREFER_LARGER_OR_ZERO(accumAlphaBits);
1344 PREFER_SMALLER(visualType);
1346 /* None of the multisample specs say where this comparison should happen,
1347 * so I put it near the end.
1349 PREFER_SMALLER(sampleBuffers);
1350 PREFER_SMALLER(samples);
1352 /* None of the pbuffer or fbconfig specs say that this comparison needs
1353 * to happen at all, but it seems like it should.
1355 PREFER_LARGER(maxPbufferWidth);
1356 PREFER_LARGER(maxPbufferHeight);
1357 PREFER_LARGER(maxPbufferPixels);
1364 * Selects and sorts a subset of the supplied configs based on the attributes.
1365 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1366 * and \c glXChooseFBConfigSGIX.
1368 * \param configs Array of pointers to possible configs. The elements of
1369 * this array that do not meet the criteria will be set to
1370 * NULL. The remaining elements will be sorted according to
1371 * the various visual / FBConfig selection rules.
1372 * \param num_configs Number of elements in the \c configs array.
1373 * \param attribList Attributes used select from \c configs. This array is
1374 * terminated by a \c None tag. The array can either take
1375 * the form expected by \c glXChooseVisual (where boolean
1376 * tags do not have a value) or by \c glXChooseFBConfig
1377 * (where every tag has a value).
1378 * \param fbconfig_style_tags Selects whether \c attribList is in
1379 * \c glXChooseVisual style or
1380 * \c glXChooseFBConfig style.
1381 * \returns The number of valid elements left in \c configs.
1383 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1386 choose_visual(__GLcontextModes ** configs, int num_configs,
1387 const int *attribList, GLboolean fbconfig_style_tags)
1389 __GLcontextModes test_config;
1393 /* This is a fairly direct implementation of the selection method
1394 * described by GLX_SGIX_fbconfig. Start by culling out all the
1395 * configs that are not compatible with the selected parameter
1399 init_fbconfig_for_chooser(&test_config, fbconfig_style_tags);
1400 __glXInitializeVisualConfigFromTags(&test_config, 512,
1401 (const INT32 *) attribList,
1402 GL_TRUE, fbconfig_style_tags);
1405 for (i = 0; i < num_configs; i++) {
1406 if (fbconfigs_compatible(&test_config, configs[i])) {
1407 configs[base] = configs[i];
1416 if (base < num_configs) {
1417 (void) memset(&configs[base], 0, sizeof(void *) * (num_configs - base));
1420 /* After the incompatible configs are removed, the resulting
1421 * list is sorted according to the rules set out in the various
1425 qsort(configs, base, sizeof(__GLcontextModes *),
1426 (int (*)(const void *, const void *)) fbconfig_compare);
1434 ** Return the visual that best matches the template. Return None if no
1435 ** visual matches the template.
1437 PUBLIC XVisualInfo *
1438 glXChooseVisual(Display * dpy, int screen, int *attribList)
1440 XVisualInfo *visualList = NULL;
1441 __GLXdisplayPrivate *priv;
1442 __GLXscreenConfigs *psc;
1443 __GLcontextModes test_config;
1444 __GLcontextModes *modes;
1445 const __GLcontextModes *best_config = NULL;
1448 ** Get a list of all visuals, return if list is empty
1450 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1456 ** Build a template from the defaults and the attribute list
1457 ** Free visual list and return if an unexpected token is encountered
1459 init_fbconfig_for_chooser(&test_config, GL_FALSE);
1460 __glXInitializeVisualConfigFromTags(&test_config, 512,
1461 (const INT32 *) attribList,
1465 ** Eliminate visuals that don't meet minimum requirements
1466 ** Compute a score for those that do
1467 ** Remember which visual, if any, got the highest score
1468 ** If no visual is acceptable, return None
1469 ** Otherwise, create an XVisualInfo list with just the selected X visual
1472 for (modes = psc->visuals; modes != NULL; modes = modes->next) {
1473 if (fbconfigs_compatible(&test_config, modes)
1474 && ((best_config == NULL)
1477 ((const __GLcontextModes * const *const) &modes,
1478 &best_config) < 0))) {
1479 XVisualInfo visualTemplate;
1480 XVisualInfo *newList;
1483 visualTemplate.screen = screen;
1484 visualTemplate.visualid = modes->visualID;
1485 newList = XGetVisualInfo(dpy, VisualScreenMask | VisualIDMask,
1486 &visualTemplate, &i);
1490 visualList = newList;
1491 best_config = modes;
1496 #ifdef GLX_USE_APPLEGL
1497 if(visualList && getenv("LIBGL_DUMP_VISUALID")) {
1498 printf("visualid 0x%lx\n", visualList[0].visualid);
1507 glXQueryExtensionsString(Display * dpy, int screen)
1509 __GLXscreenConfigs *psc;
1510 __GLXdisplayPrivate *priv;
1512 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1516 if (!psc->effectiveGLXexts) {
1517 if (!psc->serverGLXexts) {
1518 psc->serverGLXexts =
1519 __glXQueryServerString(dpy, priv->majorOpcode, screen,
1523 __glXCalculateUsableExtensions(psc,
1524 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1525 (psc->driScreen != NULL),
1529 priv->minorVersion);
1532 return psc->effectiveGLXexts;
1536 glXGetClientString(Display * dpy, int name)
1542 return (__glXGLXClientVendorName);
1544 return (__glXGLXClientVersion);
1545 case GLX_EXTENSIONS:
1546 return (__glXGetClientExtensions());
1553 glXQueryServerString(Display * dpy, int screen, int name)
1555 __GLXscreenConfigs *psc;
1556 __GLXdisplayPrivate *priv;
1560 if (GetGLXPrivScreenConfig(dpy, screen, &priv, &psc) != Success) {
1566 str = &priv->serverGLXvendor;
1569 str = &priv->serverGLXversion;
1571 case GLX_EXTENSIONS:
1572 str = &psc->serverGLXexts;
1579 *str = __glXQueryServerString(dpy, priv->majorOpcode, screen, name);
1586 __glXClientInfo(Display * dpy, int opcode)
1588 char *ext_str = __glXGetClientGLExtensionString();
1589 int size = strlen(ext_str) + 1;
1592 xcb_connection_t *c = XGetXCBConnection(dpy);
1593 xcb_glx_client_info(c,
1594 GLX_MAJOR_VERSION, GLX_MINOR_VERSION, size, ext_str);
1596 xGLXClientInfoReq *req;
1598 /* Send the glXClientInfo request */
1600 GetReq(GLXClientInfo, req);
1601 req->reqType = opcode;
1602 req->glxCode = X_GLXClientInfo;
1603 req->major = GLX_MAJOR_VERSION;
1604 req->minor = GLX_MINOR_VERSION;
1606 req->length += (size + 3) >> 2;
1607 req->numbytes = size;
1608 Data(dpy, ext_str, size);
1612 #endif /* USE_XCB */
1619 ** EXT_import_context
1623 glXGetCurrentDisplay(void)
1625 GLXContext gc = __glXGetCurrentContext();
1628 return gc->currentDpy;
1632 GLX_ALIAS(Display *, glXGetCurrentDisplayEXT, (void), (),
1633 glXGetCurrentDisplay)
1635 #ifndef GLX_USE_APPLEGL
1637 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1640 * \param dpy Display where \c ctx was created.
1641 * \param ctx Context to query.
1642 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1643 * or zero if the request failed due to internal problems (i.e.,
1644 * unable to allocate temporary memory, etc.)
1647 * This function dynamically determines whether to use the EXT_import_context
1648 * version of the protocol or the GLX 1.3 version of the protocol.
1650 static int __glXQueryContextInfo(Display * dpy, GLXContext ctx)
1652 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1653 xGLXQueryContextReply reply;
1659 return GLX_BAD_CONTEXT;
1661 opcode = __glXSetupForCommand(dpy);
1666 /* Send the glXQueryContextInfoEXT request */
1669 if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
1670 xGLXQueryContextReq *req;
1672 GetReq(GLXQueryContext, req);
1674 req->reqType = opcode;
1675 req->glxCode = X_GLXQueryContext;
1676 req->context = (unsigned int) (ctx->xid);
1679 xGLXVendorPrivateReq *vpreq;
1680 xGLXQueryContextInfoEXTReq *req;
1682 GetReqExtra(GLXVendorPrivate,
1683 sz_xGLXQueryContextInfoEXTReq - sz_xGLXVendorPrivateReq,
1685 req = (xGLXQueryContextInfoEXTReq *) vpreq;
1686 req->reqType = opcode;
1687 req->glxCode = X_GLXVendorPrivateWithReply;
1688 req->vendorCode = X_GLXvop_QueryContextInfoEXT;
1689 req->context = (unsigned int) (ctx->xid);
1692 _XReply(dpy, (xReply *) & reply, 0, False);
1694 numValues = reply.n;
1697 else if (numValues > __GLX_MAX_CONTEXT_PROPS)
1700 int *propList, *pProp;
1703 nPropListBytes = numValues << 3;
1704 propList = (int *) Xmalloc(nPropListBytes);
1705 if (NULL == propList) {
1711 _XRead(dpy, (char *) propList, nPropListBytes);
1713 /* Look up screen first so we can look up visuals/fbconfigs later */
1715 for (i = 0; i < numValues; i++, pProp += 2)
1716 if (pProp[0] == GLX_SCREEN) {
1717 ctx->screen = pProp[1];
1718 ctx->psc = GetGLXScreenConfigs(dpy, ctx->screen);
1722 for (i = 0; i < numValues; i++) {
1724 case GLX_SHARE_CONTEXT_EXT:
1725 ctx->share_xid = *pProp++;
1727 case GLX_VISUAL_ID_EXT:
1729 _gl_context_modes_find_visual(ctx->psc->visuals, *pProp++);
1731 case GLX_FBCONFIG_ID:
1733 _gl_context_modes_find_fbconfig(ctx->psc->configs,
1736 case GLX_RENDER_TYPE:
1737 ctx->renderType = *pProp++;
1745 Xfree((char *) propList);
1757 glXQueryContext(Display * dpy, GLXContext ctx, int attribute, int *value)
1759 #ifndef GLX_USE_APPLEGL
1762 /* get the information from the server if we don't have it already */
1763 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1764 if (!ctx->driContext && (ctx->mode == NULL)) {
1766 if (ctx->mode == NULL) {
1768 retVal = __glXQueryContextInfo(dpy, ctx);
1769 if (Success != retVal)
1774 switch (attribute) {
1775 #ifndef GLX_USE_APPLEGL
1776 case GLX_SHARE_CONTEXT_EXT:
1777 *value = (int) (ctx->share_xid);
1779 case GLX_VISUAL_ID_EXT:
1780 *value = ctx->mode ? ctx->mode->visualID : None;
1784 *value = (int) (ctx->screen);
1786 case GLX_FBCONFIG_ID:
1787 *value = ctx->mode ? ctx->mode->fbconfigID : None;
1789 case GLX_RENDER_TYPE:
1790 *value = (int) (ctx->renderType);
1793 return GLX_BAD_ATTRIBUTE;
1799 GLX_ALIAS(int, glXQueryContextInfoEXT,
1800 (Display * dpy, GLXContext ctx, int attribute, int *value),
1801 (dpy, ctx, attribute, value), glXQueryContext)
1803 PUBLIC GLXContextID glXGetContextIDEXT(const GLXContext ctx)
1809 glXImportContextEXT(Display * dpy, GLXContextID contextID)
1811 #ifdef GLX_USE_APPLEGL
1816 if (contextID == None) {
1819 if (__glXIsDirect(dpy, contextID)) {
1823 ctx = AllocateGLXContext(dpy);
1825 ctx->xid = contextID;
1826 ctx->imported = GL_TRUE;
1828 if (Success != __glXQueryContextInfo(dpy, ctx)) {
1829 ctx->vtable->destroy(ctx);
1838 glXFreeContextEXT(Display * dpy, GLXContext ctx)
1840 DestroyContext(dpy, ctx);
1846 * GLX 1.3 functions - these are just stubs for now!
1849 PUBLIC GLXFBConfig *
1850 glXChooseFBConfig(Display * dpy, int screen,
1851 const int *attribList, int *nitems)
1853 __GLcontextModes **config_list;
1857 config_list = (__GLcontextModes **)
1858 glXGetFBConfigs(dpy, screen, &list_size);
1860 if ((config_list != NULL) && (list_size > 0) && (attribList != NULL)) {
1861 list_size = choose_visual(config_list, list_size, attribList, GL_TRUE);
1862 if (list_size == 0) {
1868 *nitems = list_size;
1869 return (GLXFBConfig *) config_list;
1874 glXCreateNewContext(Display * dpy, GLXFBConfig config,
1875 int renderType, GLXContext shareList, Bool allowDirect)
1877 const __GLcontextModes *const fbconfig =
1878 (const __GLcontextModes *const) config;
1880 return CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList,
1881 allowDirect, X_GLXCreateNewContext, renderType,
1887 glXGetCurrentReadDrawable(void)
1889 GLXContext gc = __glXGetCurrentContext();
1890 return gc->currentReadable;
1894 PUBLIC GLXFBConfig *
1895 glXGetFBConfigs(Display * dpy, int screen, int *nelements)
1897 __GLXdisplayPrivate *priv = __glXInitialize(dpy);
1898 __GLcontextModes **config = NULL;
1902 if (priv && (priv->screenConfigs != NULL)
1903 && (screen >= 0) && (screen <= ScreenCount(dpy))
1904 && (priv->screenConfigs[screen]->configs != NULL)
1905 && (priv->screenConfigs[screen]->configs->fbconfigID
1906 != (int) GLX_DONT_CARE)) {
1907 unsigned num_configs = 0;
1908 __GLcontextModes *modes;
1911 for (modes = priv->screenConfigs[screen]->configs; modes != NULL;
1912 modes = modes->next) {
1913 if (modes->fbconfigID != (int) GLX_DONT_CARE) {
1918 config = (__GLcontextModes **) Xmalloc(sizeof(__GLcontextModes *)
1920 if (config != NULL) {
1921 *nelements = num_configs;
1923 for (modes = priv->screenConfigs[screen]->configs; modes != NULL;
1924 modes = modes->next) {
1925 if (modes->fbconfigID != (int) GLX_DONT_CARE) {
1932 return (GLXFBConfig *) config;
1937 glXGetFBConfigAttrib(Display * dpy, GLXFBConfig config,
1938 int attribute, int *value)
1940 __GLcontextModes *const modes = ValidateGLXFBConfig(dpy, config);
1942 return (modes != NULL)
1943 ? _gl_get_context_mode_data(modes, attribute, value)
1948 PUBLIC XVisualInfo *
1949 glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig config)
1951 XVisualInfo visualTemplate;
1952 __GLcontextModes *fbconfig = (__GLcontextModes *) config;
1956 ** Get a list of all visuals, return if list is empty
1958 visualTemplate.visualid = fbconfig->visualID;
1959 return XGetVisualInfo(dpy, VisualIDMask, &visualTemplate, &count);
1962 #ifndef GLX_USE_APPLEGL
1964 ** GLX_SGI_swap_control
1967 __glXSwapIntervalSGI(int interval)
1969 xGLXVendorPrivateReq *req;
1970 GLXContext gc = __glXGetCurrentContext();
1971 __GLXscreenConfigs *psc;
1973 CARD32 *interval_ptr;
1977 return GLX_BAD_CONTEXT;
1980 if (interval <= 0) {
1981 return GLX_BAD_VALUE;
1984 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
1986 #ifdef GLX_DIRECT_RENDERING
1987 if (gc->driContext && psc->driScreen && psc->driScreen->setSwapInterval) {
1988 __GLXDRIdrawable *pdraw =
1989 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
1990 psc->driScreen->setSwapInterval(pdraw, interval);
1995 dpy = gc->currentDpy;
1996 opcode = __glXSetupForCommand(dpy);
2001 /* Send the glXSwapIntervalSGI request */
2003 GetReqExtra(GLXVendorPrivate, sizeof(CARD32), req);
2004 req->reqType = opcode;
2005 req->glxCode = X_GLXVendorPrivate;
2006 req->vendorCode = X_GLXvop_SwapIntervalSGI;
2007 req->contextTag = gc->currentContextTag;
2009 interval_ptr = (CARD32 *) (req + 1);
2010 *interval_ptr = interval;
2021 ** GLX_MESA_swap_control
2024 __glXSwapIntervalMESA(unsigned int interval)
2026 #ifdef GLX_DIRECT_RENDERING
2027 GLXContext gc = __glXGetCurrentContext();
2029 if (gc != NULL && gc->driContext) {
2030 __GLXscreenConfigs *psc;
2032 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2033 if (psc->driScreen && psc->driScreen->setSwapInterval) {
2034 __GLXDRIdrawable *pdraw =
2035 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2036 return psc->driScreen->setSwapInterval(pdraw, interval);
2041 return GLX_BAD_CONTEXT;
2046 __glXGetSwapIntervalMESA(void)
2048 #ifdef GLX_DIRECT_RENDERING
2049 GLXContext gc = __glXGetCurrentContext();
2051 if (gc != NULL && gc->driContext) {
2052 __GLXscreenConfigs *psc;
2054 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2055 if (psc->driScreen && psc->driScreen->getSwapInterval) {
2056 __GLXDRIdrawable *pdraw =
2057 GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2058 return psc->driScreen->getSwapInterval(pdraw);
2068 ** GLX_SGI_video_sync
2071 __glXGetVideoSyncSGI(unsigned int *count)
2073 int64_t ust, msc, sbc;
2075 GLXContext gc = __glXGetCurrentContext();
2076 __GLXscreenConfigs *psc;
2077 #ifdef GLX_DIRECT_RENDERING
2078 __GLXDRIdrawable *pdraw;
2082 return GLX_BAD_CONTEXT;
2084 #ifdef GLX_DIRECT_RENDERING
2085 if (!gc->driContext)
2086 return GLX_BAD_CONTEXT;
2089 psc = GetGLXScreenConfigs(gc->currentDpy, gc->screen);
2090 #ifdef GLX_DIRECT_RENDERING
2091 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2094 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2095 * FIXME: there should be a GLX encoding for this call. I can find no
2096 * FIXME: documentation for the GLX encoding.
2098 #ifdef GLX_DIRECT_RENDERING
2099 if (psc->driScreen && psc->driScreen->getDrawableMSC) {
2100 ret = psc->driScreen->getDrawableMSC(psc, pdraw, &ust, &msc, &sbc);
2101 *count = (unsigned) msc;
2102 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
2106 return GLX_BAD_CONTEXT;
2110 __glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
2112 GLXContext gc = __glXGetCurrentContext();
2113 __GLXscreenConfigs *psc;
2114 #ifdef GLX_DIRECT_RENDERING
2115 __GLXDRIdrawable *pdraw;
2117 int64_t ust, msc, sbc;
2120 if (divisor <= 0 || remainder < 0)
2121 return GLX_BAD_VALUE;
2124 return GLX_BAD_CONTEXT;
2126 #ifdef GLX_DIRECT_RENDERING
2127 if (!gc->driContext)
2128 return GLX_BAD_CONTEXT;
2131 psc = GetGLXScreenConfigs( gc->currentDpy, gc->screen);
2132 #ifdef GLX_DIRECT_RENDERING
2133 pdraw = GetGLXDRIDrawable(gc->currentDpy, gc->currentDrawable);
2136 #ifdef GLX_DIRECT_RENDERING
2137 if (psc->driScreen && psc->driScreen->waitForMSC) {
2138 ret = psc->driScreen->waitForMSC(pdraw, 0, divisor, remainder, &ust, &msc,
2140 *count = (unsigned) msc;
2141 return (ret == True) ? 0 : GLX_BAD_CONTEXT;
2145 return GLX_BAD_CONTEXT;
2148 #endif /* GLX_USE_APPLEGL */
2151 ** GLX_SGIX_fbconfig
2152 ** Many of these functions are aliased to GLX 1.3 entry points in the
2153 ** GLX_functions table.
2157 GLX_ALIAS(int, glXGetFBConfigAttribSGIX,
2158 (Display * dpy, GLXFBConfigSGIX config, int attribute, int *value),
2159 (dpy, config, attribute, value), glXGetFBConfigAttrib)
2161 PUBLIC GLX_ALIAS(GLXFBConfigSGIX *, glXChooseFBConfigSGIX,
2162 (Display * dpy, int screen, int *attrib_list,
2163 int *nelements), (dpy, screen, attrib_list, nelements),
2166 PUBLIC GLX_ALIAS(XVisualInfo *, glXGetVisualFromFBConfigSGIX,
2167 (Display * dpy, GLXFBConfigSGIX config),
2168 (dpy, config), glXGetVisualFromFBConfig)
2171 glXCreateGLXPixmapWithConfigSGIX(Display * dpy,
2172 GLXFBConfigSGIX config,
2175 #ifndef GLX_USE_APPLEGL
2176 xGLXVendorPrivateWithReplyReq *vpreq;
2177 xGLXCreateGLXPixmapWithConfigSGIXReq *req;
2178 GLXPixmap xid = None;
2180 __GLXscreenConfigs *psc;
2182 const __GLcontextModes *const fbconfig = (__GLcontextModes *) config;
2185 if ((dpy == NULL) || (config == NULL)) {
2188 #ifdef GLX_USE_APPLEGL
2189 if(apple_glx_pixmap_create(dpy, fbconfig->screen, pixmap, fbconfig))
2194 psc = GetGLXScreenConfigs(dpy, fbconfig->screen);
2196 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
2197 opcode = __glXSetupForCommand(dpy);
2202 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2204 GetReqExtra(GLXVendorPrivateWithReply,
2205 sz_xGLXCreateGLXPixmapWithConfigSGIXReq -
2206 sz_xGLXVendorPrivateWithReplyReq, vpreq);
2207 req = (xGLXCreateGLXPixmapWithConfigSGIXReq *) vpreq;
2208 req->reqType = opcode;
2209 req->glxCode = X_GLXVendorPrivateWithReply;
2210 req->vendorCode = X_GLXvop_CreateGLXPixmapWithConfigSGIX;
2211 req->screen = fbconfig->screen;
2212 req->fbconfig = fbconfig->fbconfigID;
2213 req->pixmap = pixmap;
2214 req->glxpixmap = xid = XAllocID(dpy);
2224 glXCreateContextWithConfigSGIX(Display * dpy,
2225 GLXFBConfigSGIX config, int renderType,
2226 GLXContext shareList, Bool allowDirect)
2228 GLXContext gc = NULL;
2229 const __GLcontextModes *const fbconfig = (__GLcontextModes *) config;
2230 __GLXscreenConfigs *psc;
2233 if ((dpy == NULL) || (config == NULL)) {
2237 psc = GetGLXScreenConfigs(dpy, fbconfig->screen);
2239 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)) {
2240 gc = CreateContext(dpy, fbconfig->fbconfigID, fbconfig, shareList,
2242 X_GLXvop_CreateContextWithConfigSGIX, renderType,
2250 PUBLIC GLXFBConfigSGIX
2251 glXGetFBConfigFromVisualSGIX(Display * dpy, XVisualInfo * vis)
2253 __GLXdisplayPrivate *priv;
2254 __GLXscreenConfigs *psc = NULL;
2256 if ((GetGLXPrivScreenConfig(dpy, vis->screen, &priv, &psc) != Success)
2257 && __glXExtensionBitIsEnabled(psc, SGIX_fbconfig_bit)
2258 && (psc->configs->fbconfigID != (int) GLX_DONT_CARE)) {
2259 return (GLXFBConfigSGIX) _gl_context_modes_find_visual(psc->configs,
2266 #ifndef GLX_USE_APPLEGL
2268 ** GLX_SGIX_swap_group
2271 __glXJoinSwapGroupSGIX(Display * dpy, GLXDrawable drawable,
2281 ** GLX_SGIX_swap_barrier
2284 __glXBindSwapBarrierSGIX(Display * dpy, GLXDrawable drawable, int barrier)
2292 __glXQueryMaxSwapBarriersSGIX(Display * dpy, int screen, int *max)
2302 ** GLX_OML_sync_control
2305 __glXGetSyncValuesOML(Display * dpy, GLXDrawable drawable,
2306 int64_t * ust, int64_t * msc, int64_t * sbc)
2308 __GLXdisplayPrivate * const priv = __glXInitialize(dpy);
2310 #ifdef GLX_DIRECT_RENDERING
2311 __GLXDRIdrawable *pdraw;
2313 __GLXscreenConfigs *psc;
2318 #ifdef GLX_DIRECT_RENDERING
2319 pdraw = GetGLXDRIDrawable(dpy, drawable);
2320 psc = pdraw ? pdraw->psc : NULL;
2321 if (pdraw && psc->driScreen->getDrawableMSC) {
2322 ret = psc->driScreen->getDrawableMSC(psc, pdraw, ust, msc, sbc);
2330 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2332 __glxGetMscRate(__GLXDRIdrawable *glxDraw,
2333 int32_t * numerator, int32_t * denominator)
2336 __GLXscreenConfigs *psc;
2337 XF86VidModeModeLine mode_line;
2342 if (XF86VidModeQueryVersion(psc->dpy, &i, &i) &&
2343 XF86VidModeGetModeLine(psc->dpy, psc->scr, &dot_clock, &mode_line)) {
2344 unsigned n = dot_clock * 1000;
2345 unsigned d = mode_line.vtotal * mode_line.htotal;
2347 # define V_INTERLACE 0x010
2348 # define V_DBLSCAN 0x020
2350 if (mode_line.flags & V_INTERLACE)
2352 else if (mode_line.flags & V_DBLSCAN)
2355 /* The OML_sync_control spec requires that if the refresh rate is a
2356 * whole number, that the returned numerator be equal to the refresh
2357 * rate and the denominator be 1.
2365 static const unsigned f[] = { 13, 11, 7, 5, 3, 2, 0 };
2367 /* This is a poor man's way to reduce a fraction. It's far from
2368 * perfect, but it will work well enough for this situation.
2371 for (i = 0; f[i] != 0; i++) {
2372 while (n % f[i] == 0 && d % f[i] == 0) {
2398 * Determine the refresh rate of the specified drawable and display.
2400 * \param dpy Display whose refresh rate is to be determined.
2401 * \param drawable Drawable whose refresh rate is to be determined.
2402 * \param numerator Numerator of the refresh rate.
2403 * \param demoninator Denominator of the refresh rate.
2404 * \return If the refresh rate for the specified display and drawable could
2405 * be calculated, True is returned. Otherwise False is returned.
2407 * \note This function is implemented entirely client-side. A lot of other
2408 * functionality is required to export GLX_OML_sync_control, so on
2409 * XFree86 this function can be called for direct-rendering contexts
2410 * when GLX_OML_sync_control appears in the client extension string.
2414 __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
2415 int32_t * numerator, int32_t * denominator)
2417 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2418 __GLXDRIdrawable *draw = GetGLXDRIDrawable(dpy, drawable);
2423 return __glxGetMscRate(draw, numerator, denominator);
2435 __glXSwapBuffersMscOML(Display * dpy, GLXDrawable drawable,
2436 int64_t target_msc, int64_t divisor, int64_t remainder)
2438 GLXContext gc = __glXGetCurrentContext();
2439 #ifdef GLX_DIRECT_RENDERING
2440 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2441 __GLXscreenConfigs *psc = pdraw ? pdraw->psc : NULL;
2444 if (!gc) /* no GLX for this */
2447 #ifdef GLX_DIRECT_RENDERING
2448 if (!pdraw || !gc->driContext)
2452 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2453 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2454 * of -1 if the function failed because of errors detected in the input
2457 if (divisor < 0 || remainder < 0 || target_msc < 0)
2459 if (divisor > 0 && remainder >= divisor)
2462 if (target_msc == 0 && divisor == 0 && remainder == 0)
2465 #ifdef GLX_DIRECT_RENDERING
2466 if (psc->driScreen && psc->driScreen->swapBuffers)
2467 return (*psc->driScreen->swapBuffers)(pdraw, target_msc, divisor,
2476 __glXWaitForMscOML(Display * dpy, GLXDrawable drawable,
2477 int64_t target_msc, int64_t divisor,
2478 int64_t remainder, int64_t * ust,
2479 int64_t * msc, int64_t * sbc)
2481 #ifdef GLX_DIRECT_RENDERING
2482 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2484 __GLXscreenConfigs *psc = pdraw ? pdraw->psc : NULL;
2488 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2489 * error", but the return type in the spec is Bool.
2491 if (divisor < 0 || remainder < 0 || target_msc < 0)
2493 if (divisor > 0 && remainder >= divisor)
2496 #ifdef GLX_DIRECT_RENDERING
2497 if (pdraw && psc->driScreen && psc->driScreen->waitForMSC) {
2498 ret = psc->driScreen->waitForMSC(pdraw, target_msc, divisor, remainder,
2509 __glXWaitForSbcOML(Display * dpy, GLXDrawable drawable,
2510 int64_t target_sbc, int64_t * ust,
2511 int64_t * msc, int64_t * sbc)
2513 #ifdef GLX_DIRECT_RENDERING
2514 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2516 __GLXscreenConfigs *psc = pdraw ? pdraw->psc : NULL;
2519 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2520 * error", but the return type in the spec is Bool.
2525 #ifdef GLX_DIRECT_RENDERING
2526 if (pdraw && psc->driScreen && psc->driScreen->waitForSBC) {
2527 ret = psc->driScreen->waitForSBC(pdraw, target_sbc, ust, msc, sbc);
2539 * Mesa extension stubs. These will help reduce portability problems.
2544 * Release all buffers associated with the specified GLX drawable.
2547 * This function was intended for stand-alone Mesa. The issue there is that
2548 * the library doesn't get any notification when a window is closed. In
2549 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2550 * supported, there are 3 different functions to destroy a drawable. It
2551 * should be possible to create GLX protocol (or have it determine which
2552 * protocol to use based on the type of the drawable) to have one function
2553 * do the work of 3. For the direct-rendering case, this function could
2554 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2555 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2556 * would need to be used. This really should be done as part of the new DRI
2559 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2560 * __driGarbageCollectDrawables
2561 * glXDestroyGLXPixmap
2562 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2563 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2566 __glXReleaseBuffersMESA(Display * dpy, GLXDrawable d)
2575 glXCreateGLXPixmapMESA(Display * dpy, XVisualInfo * visual,
2576 Pixmap pixmap, Colormap cmap)
2589 * GLX_MESA_copy_sub_buffer
2591 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2593 __glXCopySubBufferMESA(Display * dpy, GLXDrawable drawable,
2594 int x, int y, int width, int height)
2596 xGLXVendorPrivateReq *req;
2599 CARD32 *drawable_ptr;
2600 INT32 *x_ptr, *y_ptr, *w_ptr, *h_ptr;
2603 #ifdef __DRI_COPY_SUB_BUFFER
2604 __GLXDRIdrawable *pdraw = GetGLXDRIDrawable(dpy, drawable);
2605 if (pdraw != NULL) {
2606 __GLXscreenConfigs *psc = pdraw->psc;
2607 if (psc->driScreen->copySubBuffer != NULL) {
2609 (*psc->driScreen->copySubBuffer) (pdraw, x, y, width, height);
2616 opcode = __glXSetupForCommand(dpy);
2621 ** The calling thread may or may not have a current context. If it
2622 ** does, send the context tag so the server can do a flush.
2624 gc = __glXGetCurrentContext();
2625 if ((gc != NULL) && (dpy == gc->currentDpy) &&
2626 ((drawable == gc->currentDrawable) ||
2627 (drawable == gc->currentReadable))) {
2628 tag = gc->currentContextTag;
2635 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32) * 4, req);
2636 req->reqType = opcode;
2637 req->glxCode = X_GLXVendorPrivate;
2638 req->vendorCode = X_GLXvop_CopySubBufferMESA;
2639 req->contextTag = tag;
2641 drawable_ptr = (CARD32 *) (req + 1);
2642 x_ptr = (INT32 *) (drawable_ptr + 1);
2643 y_ptr = (INT32 *) (drawable_ptr + 2);
2644 w_ptr = (INT32 *) (drawable_ptr + 3);
2645 h_ptr = (INT32 *) (drawable_ptr + 4);
2647 *drawable_ptr = drawable;
2659 * GLX_EXT_texture_from_pixmap
2662 indirect_bind_tex_image(Display * dpy,
2663 GLXDrawable drawable,
2664 int buffer, const int *attrib_list)
2666 xGLXVendorPrivateReq *req;
2667 GLXContext gc = __glXGetCurrentContext();
2668 CARD32 *drawable_ptr;
2670 CARD32 *num_attrib_ptr;
2677 while (attrib_list[i * 2] != None)
2681 opcode = __glXSetupForCommand(dpy);
2686 GetReqExtra(GLXVendorPrivate, 12 + 8 * i, req);
2687 req->reqType = opcode;
2688 req->glxCode = X_GLXVendorPrivate;
2689 req->vendorCode = X_GLXvop_BindTexImageEXT;
2690 req->contextTag = gc->currentContextTag;
2692 drawable_ptr = (CARD32 *) (req + 1);
2693 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2694 num_attrib_ptr = (CARD32 *) (buffer_ptr + 1);
2695 attrib_ptr = (CARD32 *) (num_attrib_ptr + 1);
2697 *drawable_ptr = drawable;
2698 *buffer_ptr = buffer;
2699 *num_attrib_ptr = (CARD32) i;
2703 while (attrib_list[i * 2] != None) {
2704 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 0];
2705 *attrib_ptr++ = (CARD32) attrib_list[i * 2 + 1];
2715 indirect_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
2717 xGLXVendorPrivateReq *req;
2718 GLXContext gc = __glXGetCurrentContext();
2719 CARD32 *drawable_ptr;
2723 opcode = __glXSetupForCommand(dpy);
2728 GetReqExtra(GLXVendorPrivate, sizeof(CARD32) + sizeof(INT32), req);
2729 req->reqType = opcode;
2730 req->glxCode = X_GLXVendorPrivate;
2731 req->vendorCode = X_GLXvop_ReleaseTexImageEXT;
2732 req->contextTag = gc->currentContextTag;
2734 drawable_ptr = (CARD32 *) (req + 1);
2735 buffer_ptr = (INT32 *) (drawable_ptr + 1);
2737 *drawable_ptr = drawable;
2738 *buffer_ptr = buffer;
2744 static const struct glx_context_vtable indirect_context_vtable = {
2745 indirect_destroy_context,
2748 indirect_use_x_font,
2749 indirect_bind_tex_image,
2750 indirect_release_tex_image,
2755 __glXBindTexImageEXT(Display * dpy,
2756 GLXDrawable drawable, int buffer, const int *attrib_list)
2758 GLXContext gc = __glXGetCurrentContext();
2760 if (gc == NULL || gc->vtable->bind_tex_image == NULL)
2763 gc->vtable->bind_tex_image(dpy, drawable, buffer, attrib_list);
2767 __glXReleaseTexImageEXT(Display * dpy, GLXDrawable drawable, int buffer)
2769 GLXContext gc = __glXGetCurrentContext();
2771 if (gc == NULL || gc->vtable->release_tex_image == NULL)
2774 gc->vtable->release_tex_image(dpy, drawable, buffer);
2779 #endif /* GLX_USE_APPLEGL */
2782 * \c strdup is actually not a standard ANSI C or POSIX routine.
2783 * Irix will not define it if ANSI mode is in effect.
2788 __glXstrdup(const char *str)
2791 copy = (char *) Xmalloc(strlen(str) + 1);
2799 ** glXGetProcAddress support
2802 struct name_address_pair
2808 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2809 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2811 static const struct name_address_pair GLX_functions[] = {
2812 /*** GLX_VERSION_1_0 ***/
2813 GLX_FUNCTION(glXChooseVisual),
2814 GLX_FUNCTION(glXCopyContext),
2815 GLX_FUNCTION(glXCreateContext),
2816 GLX_FUNCTION(glXCreateGLXPixmap),
2817 GLX_FUNCTION(glXDestroyContext),
2818 GLX_FUNCTION(glXDestroyGLXPixmap),
2819 GLX_FUNCTION(glXGetConfig),
2820 GLX_FUNCTION(glXGetCurrentContext),
2821 GLX_FUNCTION(glXGetCurrentDrawable),
2822 GLX_FUNCTION(glXIsDirect),
2823 GLX_FUNCTION(glXMakeCurrent),
2824 GLX_FUNCTION(glXQueryExtension),
2825 GLX_FUNCTION(glXQueryVersion),
2826 GLX_FUNCTION(glXSwapBuffers),
2827 GLX_FUNCTION(glXUseXFont),
2828 GLX_FUNCTION(glXWaitGL),
2829 GLX_FUNCTION(glXWaitX),
2831 /*** GLX_VERSION_1_1 ***/
2832 GLX_FUNCTION(glXGetClientString),
2833 GLX_FUNCTION(glXQueryExtensionsString),
2834 GLX_FUNCTION(glXQueryServerString),
2836 /*** GLX_VERSION_1_2 ***/
2837 GLX_FUNCTION(glXGetCurrentDisplay),
2839 /*** GLX_VERSION_1_3 ***/
2840 GLX_FUNCTION(glXChooseFBConfig),
2841 GLX_FUNCTION(glXCreateNewContext),
2842 GLX_FUNCTION(glXCreatePbuffer),
2843 GLX_FUNCTION(glXCreatePixmap),
2844 GLX_FUNCTION(glXCreateWindow),
2845 GLX_FUNCTION(glXDestroyPbuffer),
2846 GLX_FUNCTION(glXDestroyPixmap),
2847 GLX_FUNCTION(glXDestroyWindow),
2848 GLX_FUNCTION(glXGetCurrentReadDrawable),
2849 GLX_FUNCTION(glXGetFBConfigAttrib),
2850 GLX_FUNCTION(glXGetFBConfigs),
2851 GLX_FUNCTION(glXGetSelectedEvent),
2852 GLX_FUNCTION(glXGetVisualFromFBConfig),
2853 GLX_FUNCTION(glXMakeContextCurrent),
2854 GLX_FUNCTION(glXQueryContext),
2855 GLX_FUNCTION(glXQueryDrawable),
2856 GLX_FUNCTION(glXSelectEvent),
2858 #ifndef GLX_USE_APPLEGL
2859 /*** GLX_SGI_swap_control ***/
2860 GLX_FUNCTION2(glXSwapIntervalSGI, __glXSwapIntervalSGI),
2862 /*** GLX_SGI_video_sync ***/
2863 GLX_FUNCTION2(glXGetVideoSyncSGI, __glXGetVideoSyncSGI),
2864 GLX_FUNCTION2(glXWaitVideoSyncSGI, __glXWaitVideoSyncSGI),
2866 /*** GLX_SGI_make_current_read ***/
2867 GLX_FUNCTION2(glXMakeCurrentReadSGI, glXMakeContextCurrent),
2868 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI, glXGetCurrentReadDrawable),
2870 /*** GLX_EXT_import_context ***/
2871 GLX_FUNCTION(glXFreeContextEXT),
2872 GLX_FUNCTION(glXGetContextIDEXT),
2873 GLX_FUNCTION2(glXGetCurrentDisplayEXT, glXGetCurrentDisplay),
2874 GLX_FUNCTION(glXImportContextEXT),
2875 GLX_FUNCTION2(glXQueryContextInfoEXT, glXQueryContext),
2878 /*** GLX_SGIX_fbconfig ***/
2879 GLX_FUNCTION2(glXGetFBConfigAttribSGIX, glXGetFBConfigAttrib),
2880 GLX_FUNCTION2(glXChooseFBConfigSGIX, glXChooseFBConfig),
2881 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX),
2882 GLX_FUNCTION(glXCreateContextWithConfigSGIX),
2883 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig),
2884 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX),
2886 #ifndef GLX_USE_APPLEGL
2887 /*** GLX_SGIX_pbuffer ***/
2888 GLX_FUNCTION(glXCreateGLXPbufferSGIX),
2889 GLX_FUNCTION(glXDestroyGLXPbufferSGIX),
2890 GLX_FUNCTION(glXQueryGLXPbufferSGIX),
2891 GLX_FUNCTION(glXSelectEventSGIX),
2892 GLX_FUNCTION(glXGetSelectedEventSGIX),
2894 /*** GLX_SGIX_swap_group ***/
2895 GLX_FUNCTION2(glXJoinSwapGroupSGIX, __glXJoinSwapGroupSGIX),
2897 /*** GLX_SGIX_swap_barrier ***/
2898 GLX_FUNCTION2(glXBindSwapBarrierSGIX, __glXBindSwapBarrierSGIX),
2899 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX, __glXQueryMaxSwapBarriersSGIX),
2901 /*** GLX_MESA_copy_sub_buffer ***/
2902 GLX_FUNCTION2(glXCopySubBufferMESA, __glXCopySubBufferMESA),
2904 /*** GLX_MESA_pixmap_colormap ***/
2905 GLX_FUNCTION(glXCreateGLXPixmapMESA),
2907 /*** GLX_MESA_release_buffers ***/
2908 GLX_FUNCTION2(glXReleaseBuffersMESA, __glXReleaseBuffersMESA),
2910 /*** GLX_MESA_swap_control ***/
2911 GLX_FUNCTION2(glXSwapIntervalMESA, __glXSwapIntervalMESA),
2912 GLX_FUNCTION2(glXGetSwapIntervalMESA, __glXGetSwapIntervalMESA),
2915 /*** GLX_ARB_get_proc_address ***/
2916 GLX_FUNCTION(glXGetProcAddressARB),
2919 GLX_FUNCTION2(glXGetProcAddress, glXGetProcAddressARB),
2921 #ifndef GLX_USE_APPLEGL
2922 /*** GLX_OML_sync_control ***/
2923 GLX_FUNCTION2(glXWaitForSbcOML, __glXWaitForSbcOML),
2924 GLX_FUNCTION2(glXWaitForMscOML, __glXWaitForMscOML),
2925 GLX_FUNCTION2(glXSwapBuffersMscOML, __glXSwapBuffersMscOML),
2926 GLX_FUNCTION2(glXGetMscRateOML, __glXGetMscRateOML),
2927 GLX_FUNCTION2(glXGetSyncValuesOML, __glXGetSyncValuesOML),
2929 /*** GLX_EXT_texture_from_pixmap ***/
2930 GLX_FUNCTION2(glXBindTexImageEXT, __glXBindTexImageEXT),
2931 GLX_FUNCTION2(glXReleaseTexImageEXT, __glXReleaseTexImageEXT),
2934 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2935 /*** DRI configuration ***/
2936 GLX_FUNCTION(glXGetScreenDriver),
2937 GLX_FUNCTION(glXGetDriverConfig),
2940 {NULL, NULL} /* end of list */
2943 #ifndef GLX_USE_APPLEGL
2944 static const GLvoid *
2945 get_glx_proc_address(const char *funcName)
2949 /* try static functions */
2950 for (i = 0; GLX_functions[i].Name; i++) {
2951 if (strcmp(GLX_functions[i].Name, funcName) == 0)
2952 return GLX_functions[i].Address;
2960 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2961 * \c glXGetProcAddress.
2963 * \param procName Name of a GL or GLX function.
2964 * \returns A pointer to the named function
2966 * \sa glXGetProcAddress
2968 PUBLIC void (*glXGetProcAddressARB(const GLubyte * procName)) (void)
2970 typedef void (*gl_function) (void);
2974 /* Search the table of GLX and internal functions first. If that
2975 * fails and the supplied name could be a valid core GL name, try
2976 * searching the core GL function table. This check is done to prevent
2977 * DRI based drivers from searching the core GL function table for
2978 * internal API functions.
2980 #ifdef GLX_USE_APPLEGL
2981 f = (gl_function) apple_glx_get_proc_address(procName);
2983 f = (gl_function) get_glx_proc_address((const char *) procName);
2984 if ((f == NULL) && (procName[0] == 'g') && (procName[1] == 'l')
2985 && (procName[2] != 'X')) {
2986 f = (gl_function) _glapi_get_proc_address((const char *) procName);
2993 * Get the address of a named GL function. This is the GLX 1.4 name for
2994 * \c glXGetProcAddressARB.
2996 * \param procName Name of a GL or GLX function.
2997 * \returns A pointer to the named function
2999 * \sa glXGetProcAddressARB
3001 PUBLIC void (*glXGetProcAddress(const GLubyte * procName)) (void)
3002 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3003 __attribute__ ((alias("glXGetProcAddressARB")));
3006 return glXGetProcAddressARB(procName);
3008 #endif /* __GNUC__ */
3011 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
3013 * Get the unadjusted system time (UST). Currently, the UST is measured in
3014 * microseconds since Epoc. The actual resolution of the UST may vary from
3015 * system to system, and the units may vary from release to release.
3016 * Drivers should not call this function directly. They should instead use
3017 * \c glXGetProcAddress to obtain a pointer to the function.
3019 * \param ust Location to store the 64-bit UST
3020 * \returns Zero on success or a negative errno value on failure.
3022 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3024 * \since Internal API version 20030317.
3027 __glXGetUST(int64_t * ust)
3035 if (gettimeofday(&tv, NULL) == 0) {
3036 ust[0] = (tv.tv_sec * 1000000) + tv.tv_usec;
3043 #endif /* GLX_DIRECT_RENDERING */