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
43 #include <X11/extensions/xf86vmode.h>
48 #include <X11/Xlib-xcb.h>
53 static const char __glXGLXClientVendorName
[] = "SGI";
54 static const char __glXGLXClientVersion
[] = "1.4";
57 /****************************************************************************/
59 #ifdef GLX_DIRECT_RENDERING
61 static Bool windowExistsFlag
;
63 windowExistsErrorHandler(Display
* dpy
, XErrorEvent
* xerr
)
65 if (xerr
->error_code
== BadWindow
) {
66 windowExistsFlag
= GL_FALSE
;
72 * Find drawables in the local hash that have been destroyed on the
75 * \param dpy Display to destroy drawables for
76 * \param screen Screen number to destroy drawables for
79 GarbageCollectDRIDrawables(Display
* dpy
, __GLXscreenConfigs
* sc
)
82 __GLXDRIdrawable
*pdraw
;
83 XWindowAttributes xwa
;
84 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
86 /* Set no-op error handler so Xlib doesn't bail out if the windows
87 * has alreay been destroyed on the server. */
89 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
91 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
93 windowExistsFlag
= GL_TRUE
;
94 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
95 if (!windowExistsFlag
) {
96 /* Destroy the local drawable data, if the drawable no
97 longer exists in the Xserver */
98 (*pdraw
->destroyDrawable
) (pdraw
);
99 __glxHashDelete(sc
->drawHash
, draw
);
101 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1);
104 XSync(dpy
, GL_FALSE
);
105 XSetErrorHandler(oldXErrorHandler
);
108 extern __GLXDRIdrawable
*GetGLXDRIDrawable(Display
* dpy
,
109 GLXDrawable drawable
,
110 int *const scrn_num
);
113 * Get the __DRIdrawable for the drawable associated with a GLXContext
115 * \param dpy The display associated with \c drawable.
116 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
117 * \param scrn_num If non-NULL, the drawables screen is stored there
118 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
119 * the drawable is not associated with a direct-rendering context.
121 _X_HIDDEN __GLXDRIdrawable
*
122 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
, int *const scrn_num
)
124 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
125 __GLXDRIdrawable
*pdraw
;
126 const unsigned screen_count
= ScreenCount(dpy
);
128 __GLXscreenConfigs
*psc
;
133 for (i
= 0; i
< screen_count
; i
++) {
134 psc
= &priv
->screenConfigs
[i
];
135 if (psc
->drawHash
== NULL
)
138 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
139 if (scrn_num
!= NULL
)
152 * Get the GLX per-screen data structure associated with a GLX context.
154 * \param dpy Display for which the GLX per-screen information is to be
156 * \param scrn Screen on \c dpy for which the GLX per-screen information is
158 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
159 * specify a valid GLX screen, or NULL otherwise.
161 * \todo Should this function validate that \c scrn is within the screen
162 * number range for \c dpy?
165 static __GLXscreenConfigs
*
166 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
168 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
171 && priv
->screenConfigs
!=
172 NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
177 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
178 __GLXscreenConfigs
** ppsc
)
180 /* Initialize the extension, if needed . This has the added value
181 * of initializing/allocating the display private
185 return GLX_NO_EXTENSION
;
188 *ppriv
= __glXInitialize(dpy
);
189 if (*ppriv
== NULL
) {
190 return GLX_NO_EXTENSION
;
193 /* Check screen number to see if its valid */
194 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
195 return GLX_BAD_SCREEN
;
198 /* Check to see if the GL is supported on this screen */
199 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
200 if ((*ppsc
)->configs
== NULL
) {
201 /* No support for GL on this screen regardless of visual */
202 return GLX_BAD_VISUAL
;
210 * Determine if a \c GLXFBConfig supplied by the application is valid.
212 * \param dpy Application supplied \c Display pointer.
213 * \param config Application supplied \c GLXFBConfig.
215 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
216 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
219 static __GLcontextModes
*
220 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig config
)
222 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
223 const unsigned num_screens
= ScreenCount(dpy
);
225 const __GLcontextModes
*modes
;
229 for (i
= 0; i
< num_screens
; i
++) {
230 for (modes
= priv
->screenConfigs
[i
].configs
; modes
!= NULL
;
231 modes
= modes
->next
) {
232 if (modes
== (__GLcontextModes
*) config
) {
233 return (__GLcontextModes
*) config
;
244 * \todo It should be possible to move the allocate of \c client_state_private
245 * later in the function for direct-rendering contexts. Direct-rendering
246 * contexts don't need to track client state, so they don't need that memory
249 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
250 * function called \c __glXAllocateClientState that allocates the memory and
251 * does all the initialization (including the pixel pack / unpack).
254 AllocateGLXContext(Display
* dpy
)
259 __GLXattribute
*state
;
264 opcode
= __glXSetupForCommand(dpy
);
269 /* Allocate our context record */
270 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
275 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
277 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
283 gc
->client_state_private
= state
;
284 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
285 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
288 ** Create a temporary buffer to hold GLX rendering commands. The size
289 ** of the buffer is selected so that the maximum number of GLX rendering
290 ** commands can fit in a single X packet and still have room in the X
291 ** packet for the GLXRenderReq header.
294 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
295 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
297 Xfree(gc
->client_state_private
);
301 gc
->bufSize
= bufSize
;
303 /* Fill in the new context */
304 gc
->renderMode
= GL_RENDER
;
306 state
->storePack
.alignment
= 4;
307 state
->storeUnpack
.alignment
= 4;
309 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
312 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
313 ** Other code uses the fastImageUnpack bit, but it is never set
316 gc
->fastImageUnpack
= GL_FALSE
;
317 gc
->fillImage
= __glFillImage
;
319 gc
->bufEnd
= gc
->buf
+ bufSize
;
320 gc
->isDirect
= GL_FALSE
;
323 ** Set limit register so that there will be one command per packet
328 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
331 gc
->majorOpcode
= opcode
;
334 ** Constrain the maximum drawing command size allowed to be
335 ** transfered using the X_GLXRender protocol request. First
336 ** constrain by a software limit, then constrain by the protocl
339 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
340 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
342 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
343 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
345 gc
->maxSmallRenderCommandSize
= bufSize
;
351 * Create a new context. Exactly one of \c vis and \c fbconfig should be
354 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
355 * SGIX_fbconfig protocol be used?
356 * \param renderType For FBConfigs, what is the rendering type?
360 CreateContext(Display
* dpy
, XVisualInfo
* vis
,
361 const __GLcontextModes
* const fbconfig
,
362 GLXContext shareList
,
363 Bool allowDirect
, GLXContextID contextID
,
364 Bool use_glx_1_3
, int renderType
)
367 #ifdef GLX_DIRECT_RENDERING
368 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
369 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
375 gc
= AllocateGLXContext(dpy
);
379 if (None
== contextID
) {
380 if ((vis
== NULL
) && (fbconfig
== NULL
))
383 #ifdef GLX_DIRECT_RENDERING
384 if (allowDirect
&& psc
->driScreen
) {
385 const __GLcontextModes
*mode
;
387 if (fbconfig
== NULL
) {
388 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
392 error
.errorCode
= BadValue
;
393 error
.resourceID
= vis
->visualid
;
394 error
.sequenceNumber
= dpy
->request
;
395 error
.type
= X_Error
;
396 error
.majorCode
= gc
->majorOpcode
;
397 error
.minorCode
= X_GLXCreateContext
;
398 _XError(dpy
, &error
);
406 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
409 if (gc
->driContext
!= NULL
) {
410 gc
->screen
= mode
->screen
;
413 gc
->isDirect
= GL_TRUE
;
419 if (fbconfig
== NULL
) {
420 xGLXCreateContextReq
*req
;
422 /* Send the glXCreateContext request */
423 GetReq(GLXCreateContext
, req
);
424 req
->reqType
= gc
->majorOpcode
;
425 req
->glxCode
= X_GLXCreateContext
;
426 req
->context
= gc
->xid
= XAllocID(dpy
);
427 req
->visual
= vis
->visualid
;
428 req
->screen
= vis
->screen
;
429 req
->shareList
= shareList
? shareList
->xid
: None
;
430 #ifdef GLX_DIRECT_RENDERING
431 req
->isDirect
= gc
->driContext
!= NULL
;
436 else if (use_glx_1_3
) {
437 xGLXCreateNewContextReq
*req
;
439 /* Send the glXCreateNewContext request */
440 GetReq(GLXCreateNewContext
, req
);
441 req
->reqType
= gc
->majorOpcode
;
442 req
->glxCode
= X_GLXCreateNewContext
;
443 req
->context
= gc
->xid
= XAllocID(dpy
);
444 req
->fbconfig
= fbconfig
->fbconfigID
;
445 req
->screen
= fbconfig
->screen
;
446 req
->renderType
= renderType
;
447 req
->shareList
= shareList
? shareList
->xid
: None
;
448 #ifdef GLX_DIRECT_RENDERING
449 req
->isDirect
= gc
->driContext
!= NULL
;
455 xGLXVendorPrivateWithReplyReq
*vpreq
;
456 xGLXCreateContextWithConfigSGIXReq
*req
;
458 /* Send the glXCreateNewContext request */
459 GetReqExtra(GLXVendorPrivateWithReply
,
460 sz_xGLXCreateContextWithConfigSGIXReq
-
461 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
462 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
463 req
->reqType
= gc
->majorOpcode
;
464 req
->glxCode
= X_GLXVendorPrivateWithReply
;
465 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
466 req
->context
= gc
->xid
= XAllocID(dpy
);
467 req
->fbconfig
= fbconfig
->fbconfigID
;
468 req
->screen
= fbconfig
->screen
;
469 req
->renderType
= renderType
;
470 req
->shareList
= shareList
? shareList
->xid
: None
;
471 #ifdef GLX_DIRECT_RENDERING
472 req
->isDirect
= gc
->driContext
!= NULL
;
480 gc
->imported
= GL_FALSE
;
484 gc
->imported
= GL_TRUE
;
491 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
492 GLXContext shareList
, Bool allowDirect
)
494 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
499 __glXFreeContext(__GLXcontext
* gc
)
502 XFree((char *) gc
->vendor
);
504 XFree((char *) gc
->renderer
);
506 XFree((char *) gc
->version
);
508 XFree((char *) gc
->extensions
);
509 __glFreeAttributeState(gc
);
510 XFree((char *) gc
->buf
);
511 Xfree((char *) gc
->client_state_private
);
517 ** Destroy the named context
520 DestroyContext(Display
* dpy
, GLXContext gc
)
522 xGLXDestroyContextReq
*req
;
527 opcode
= __glXSetupForCommand(dpy
);
528 if (!opcode
|| !gc
) {
534 imported
= gc
->imported
;
537 #ifdef GLX_DIRECT_RENDERING
538 /* Destroy the direct rendering context */
539 if (gc
->driContext
) {
540 (*gc
->driContext
->destroyContext
) (gc
->driContext
, gc
->psc
, dpy
);
541 gc
->driContext
= NULL
;
542 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
546 __glXFreeVertexArrayState(gc
);
548 if (gc
->currentDpy
) {
549 /* Have to free later cuz it's in use now */
553 /* Destroy the handle if not current to anybody */
555 __glXFreeContext(gc
);
560 ** This dpy also created the server side part of the context.
561 ** Send the glXDestroyContext request.
564 GetReq(GLXDestroyContext
, req
);
565 req
->reqType
= opcode
;
566 req
->glxCode
= X_GLXDestroyContext
;
574 glXDestroyContext(Display
* dpy
, GLXContext gc
)
576 DestroyContext(dpy
, gc
);
580 ** Return the major and minor version #s for the GLX extension
583 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
585 __GLXdisplayPrivate
*priv
;
587 /* Init the extension. This fetches the major and minor version. */
588 priv
= __glXInitialize(dpy
);
593 *major
= priv
->majorVersion
;
595 *minor
= priv
->minorVersion
;
600 ** Query the existance of the GLX extension
603 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
605 int major_op
, erb
, evb
;
608 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
619 ** Put a barrier in the token stream that forces the GL to finish its
620 ** work before X can proceed.
626 GLXContext gc
= __glXGetCurrentContext();
627 Display
*dpy
= gc
->currentDpy
;
632 /* Flush any pending commands out */
633 __glXFlushRenderBuffer(gc
, gc
->pc
);
635 #ifdef GLX_DIRECT_RENDERING
636 if (gc
->driContext
) {
638 __GLXDRIdrawable
*pdraw
=
639 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
642 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
644 if (psc
->driScreen
->waitGL
!= NULL
)
645 (*psc
->driScreen
->waitGL
) (pdraw
);
651 /* Send the glXWaitGL request */
653 GetReq(GLXWaitGL
, req
);
654 req
->reqType
= gc
->majorOpcode
;
655 req
->glxCode
= X_GLXWaitGL
;
656 req
->contextTag
= gc
->currentContextTag
;
662 ** Put a barrier in the token stream that forces X to finish its
663 ** work before GL can proceed.
669 GLXContext gc
= __glXGetCurrentContext();
670 Display
*dpy
= gc
->currentDpy
;
675 /* Flush any pending commands out */
676 __glXFlushRenderBuffer(gc
, gc
->pc
);
678 #ifdef GLX_DIRECT_RENDERING
679 if (gc
->driContext
) {
681 __GLXDRIdrawable
*pdraw
=
682 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
685 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
686 if (psc
->driScreen
->waitX
!= NULL
)
687 (*psc
->driScreen
->waitX
) (pdraw
);
696 ** Send the glXWaitX request.
699 GetReq(GLXWaitX
, req
);
700 req
->reqType
= gc
->majorOpcode
;
701 req
->glxCode
= X_GLXWaitX
;
702 req
->contextTag
= gc
->currentContextTag
;
708 glXUseXFont(Font font
, int first
, int count
, int listBase
)
710 xGLXUseXFontReq
*req
;
711 GLXContext gc
= __glXGetCurrentContext();
712 Display
*dpy
= gc
->currentDpy
;
717 /* Flush any pending commands out */
718 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
720 #ifdef GLX_DIRECT_RENDERING
721 if (gc
->driContext
) {
722 DRI_glXUseXFont(font
, first
, count
, listBase
);
727 /* Send the glXUseFont request */
729 GetReq(GLXUseXFont
, req
);
730 req
->reqType
= gc
->majorOpcode
;
731 req
->glxCode
= X_GLXUseXFont
;
732 req
->contextTag
= gc
->currentContextTag
;
736 req
->listBase
= listBase
;
741 /************************************************************************/
744 ** Copy the source context to the destination context using the
748 glXCopyContext(Display
* dpy
, GLXContext source
,
749 GLXContext dest
, unsigned long mask
)
751 xGLXCopyContextReq
*req
;
752 GLXContext gc
= __glXGetCurrentContext();
756 opcode
= __glXSetupForCommand(dpy
);
761 #ifdef GLX_DIRECT_RENDERING
762 if (gc
->driContext
) {
763 /* NOT_DONE: This does not work yet */
768 ** If the source is the current context, send its tag so that the context
769 ** can be flushed before the copy.
771 if (source
== gc
&& dpy
== gc
->currentDpy
) {
772 tag
= gc
->currentContextTag
;
778 /* Send the glXCopyContext request */
780 GetReq(GLXCopyContext
, req
);
781 req
->reqType
= opcode
;
782 req
->glxCode
= X_GLXCopyContext
;
783 req
->source
= source
? source
->xid
: None
;
784 req
->dest
= dest
? dest
->xid
: None
;
786 req
->contextTag
= tag
;
793 * Determine if a context uses direct rendering.
795 * \param dpy Display where the context was created.
796 * \param contextID ID of the context to be tested.
798 * \returns \c GL_TRUE if the context is direct rendering or not.
801 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
803 #if !defined(USE_XCB)
804 xGLXIsDirectReq
*req
;
805 xGLXIsDirectReply reply
;
809 opcode
= __glXSetupForCommand(dpy
);
815 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
816 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
821 const Bool is_direct
= reply
->is_direct
? True
: False
;
826 /* Send the glXIsDirect request */
828 GetReq(GLXIsDirect
, req
);
829 req
->reqType
= opcode
;
830 req
->glxCode
= X_GLXIsDirect
;
831 req
->context
= contextID
;
832 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
836 return reply
.isDirect
;
842 * Shouldn't this function \b always return \c GL_FALSE when
843 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
844 * the GLX protocol here at all?
847 glXIsDirect(Display
* dpy
, GLXContext gc
)
851 #ifdef GLX_DIRECT_RENDERING
853 else if (gc
->driContext
) {
857 return __glXIsDirect(dpy
, gc
->xid
);
861 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
863 xGLXCreateGLXPixmapReq
*req
;
867 opcode
= __glXSetupForCommand(dpy
);
872 /* Send the glXCreateGLXPixmap request */
874 GetReq(GLXCreateGLXPixmap
, req
);
875 req
->reqType
= opcode
;
876 req
->glxCode
= X_GLXCreateGLXPixmap
;
877 req
->screen
= vis
->screen
;
878 req
->visual
= vis
->visualid
;
879 req
->pixmap
= pixmap
;
880 req
->glxpixmap
= xid
= XAllocID(dpy
);
884 #ifdef GLX_DIRECT_RENDERING
886 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
887 * is actually bound to a context... */
889 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
890 __GLXDRIdrawable
*pdraw
;
891 __GLXscreenConfigs
*psc
;
892 __GLcontextModes
*modes
;
894 psc
= &priv
->screenConfigs
[vis
->screen
];
895 if (psc
->driScreen
== NULL
)
897 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
898 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, modes
);
900 fprintf(stderr
, "failed to create pixmap\n");
904 if (__glxHashInsert(psc
->drawHash
, req
->glxpixmap
, pdraw
)) {
905 (*pdraw
->destroyDrawable
) (pdraw
);
906 return None
; /* FIXME: Check what we're supposed to do here... */
915 ** Destroy the named pixmap
918 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
920 xGLXDestroyGLXPixmapReq
*req
;
923 opcode
= __glXSetupForCommand(dpy
);
928 /* Send the glXDestroyGLXPixmap request */
930 GetReq(GLXDestroyGLXPixmap
, req
);
931 req
->reqType
= opcode
;
932 req
->glxCode
= X_GLXDestroyGLXPixmap
;
933 req
->glxpixmap
= glxpixmap
;
937 #ifdef GLX_DIRECT_RENDERING
940 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
941 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
, &screen
);
942 __GLXscreenConfigs
*psc
= &priv
->screenConfigs
[screen
];
945 (*pdraw
->destroyDrawable
) (pdraw
);
946 __glxHashDelete(psc
->drawHash
, glxpixmap
);
953 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
961 xGLXSwapBuffersReq
*req
;
964 #ifdef GLX_DIRECT_RENDERING
965 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
969 (*pdraw
->psc
->driScreen
->swapBuffers
) (pdraw
);
974 opcode
= __glXSetupForCommand(dpy
);
980 ** The calling thread may or may not have a current context. If it
981 ** does, send the context tag so the server can do a flush.
983 gc
= __glXGetCurrentContext();
984 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
985 ((drawable
== gc
->currentDrawable
)
986 || (drawable
== gc
->currentReadable
))) {
987 tag
= gc
->currentContextTag
;
994 c
= XGetXCBConnection(dpy
);
995 xcb_glx_swap_buffers(c
, tag
, drawable
);
998 /* Send the glXSwapBuffers request */
1000 GetReq(GLXSwapBuffers
, req
);
1001 req
->reqType
= opcode
;
1002 req
->glxCode
= X_GLXSwapBuffers
;
1003 req
->drawable
= drawable
;
1004 req
->contextTag
= tag
;
1008 #endif /* USE_XCB */
1013 ** Return configuration information for the given display, screen and
1014 ** visual combination.
1017 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1020 __GLXdisplayPrivate
*priv
;
1021 __GLXscreenConfigs
*psc
;
1022 __GLcontextModes
*modes
;
1025 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1026 if (status
== Success
) {
1027 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1029 /* Lookup attribute after first finding a match on the visual */
1030 if (modes
!= NULL
) {
1031 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
1034 status
= GLX_BAD_VISUAL
;
1038 ** If we can't find the config for this visual, this visual is not
1039 ** supported by the OpenGL implementation on the server.
1041 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1042 *value_return
= GL_FALSE
;
1049 /************************************************************************/
1052 init_fbconfig_for_chooser(__GLcontextModes
* config
,
1053 GLboolean fbconfig_style_tags
)
1055 memset(config
, 0, sizeof(__GLcontextModes
));
1056 config
->visualID
= (XID
) GLX_DONT_CARE
;
1057 config
->visualType
= GLX_DONT_CARE
;
1059 /* glXChooseFBConfig specifies different defaults for these two than
1062 if (fbconfig_style_tags
) {
1063 config
->rgbMode
= GL_TRUE
;
1064 config
->doubleBufferMode
= GLX_DONT_CARE
;
1067 config
->visualRating
= GLX_DONT_CARE
;
1068 config
->transparentPixel
= GLX_NONE
;
1069 config
->transparentRed
= GLX_DONT_CARE
;
1070 config
->transparentGreen
= GLX_DONT_CARE
;
1071 config
->transparentBlue
= GLX_DONT_CARE
;
1072 config
->transparentAlpha
= GLX_DONT_CARE
;
1073 config
->transparentIndex
= GLX_DONT_CARE
;
1075 config
->drawableType
= GLX_WINDOW_BIT
;
1076 config
->renderType
=
1077 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1078 config
->xRenderable
= GLX_DONT_CARE
;
1079 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1081 config
->swapMethod
= GLX_DONT_CARE
;
1084 #define MATCH_DONT_CARE( param ) \
1086 if ( (a-> param != GLX_DONT_CARE) \
1087 && (a-> param != b-> param) ) { \
1092 #define MATCH_MINIMUM( param ) \
1094 if ( (a-> param != GLX_DONT_CARE) \
1095 && (a-> param > b-> param) ) { \
1100 #define MATCH_EXACT( param ) \
1102 if ( a-> param != b-> param) { \
1108 * Determine if two GLXFBConfigs are compatible.
1110 * \param a Application specified config to test.
1111 * \param b Server specified config to test against \c a.
1114 fbconfigs_compatible(const __GLcontextModes
* const a
,
1115 const __GLcontextModes
* const b
)
1117 MATCH_DONT_CARE(doubleBufferMode
);
1118 MATCH_DONT_CARE(visualType
);
1119 MATCH_DONT_CARE(visualRating
);
1120 MATCH_DONT_CARE(xRenderable
);
1121 MATCH_DONT_CARE(fbconfigID
);
1122 MATCH_DONT_CARE(swapMethod
);
1124 MATCH_MINIMUM(rgbBits
);
1125 MATCH_MINIMUM(numAuxBuffers
);
1126 MATCH_MINIMUM(redBits
);
1127 MATCH_MINIMUM(greenBits
);
1128 MATCH_MINIMUM(blueBits
);
1129 MATCH_MINIMUM(alphaBits
);
1130 MATCH_MINIMUM(depthBits
);
1131 MATCH_MINIMUM(stencilBits
);
1132 MATCH_MINIMUM(accumRedBits
);
1133 MATCH_MINIMUM(accumGreenBits
);
1134 MATCH_MINIMUM(accumBlueBits
);
1135 MATCH_MINIMUM(accumAlphaBits
);
1136 MATCH_MINIMUM(sampleBuffers
);
1137 MATCH_MINIMUM(maxPbufferWidth
);
1138 MATCH_MINIMUM(maxPbufferHeight
);
1139 MATCH_MINIMUM(maxPbufferPixels
);
1140 MATCH_MINIMUM(samples
);
1142 MATCH_DONT_CARE(stereoMode
);
1145 if (((a
->drawableType
& b
->drawableType
) == 0)
1146 || ((a
->renderType
& b
->renderType
) == 0)) {
1151 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1152 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1153 * Technically speaking, it is a bug in the DDX driver, but there is
1154 * enough of an installed base to work around the problem here. In any
1155 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1156 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1157 * 0 from the server to be a match to maintain backward compatibility with
1158 * the (broken) drivers.
1161 if (a
->transparentPixel
!= GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1162 if (a
->transparentPixel
== GLX_NONE
) {
1163 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1167 MATCH_EXACT(transparentPixel
);
1170 switch (a
->transparentPixel
) {
1171 case GLX_TRANSPARENT_RGB
:
1172 MATCH_DONT_CARE(transparentRed
);
1173 MATCH_DONT_CARE(transparentGreen
);
1174 MATCH_DONT_CARE(transparentBlue
);
1175 MATCH_DONT_CARE(transparentAlpha
);
1178 case GLX_TRANSPARENT_INDEX
:
1179 MATCH_DONT_CARE(transparentIndex
);
1191 /* There's some trickly language in the GLX spec about how this is supposed
1192 * to work. Basically, if a given component size is either not specified
1193 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1194 * Well, that's really hard to do with the code as-is. This behavior is
1195 * closer to correct, but still not technically right.
1197 #define PREFER_LARGER_OR_ZERO(comp) \
1199 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1200 if ( ((*a)-> comp) == 0 ) { \
1203 else if ( ((*b)-> comp) == 0 ) { \
1207 return ((*b)-> comp) - ((*a)-> comp) ; \
1212 #define PREFER_LARGER(comp) \
1214 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1215 return ((*b)-> comp) - ((*a)-> comp) ; \
1219 #define PREFER_SMALLER(comp) \
1221 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1222 return ((*a)-> comp) - ((*b)-> comp) ; \
1227 * Compare two GLXFBConfigs. This function is intended to be used as the
1228 * compare function passed in to qsort.
1230 * \returns If \c a is a "better" config, according to the specification of
1231 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1232 * better, then a number greater than zero is return. If both are
1233 * equal, zero is returned.
1234 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1237 fbconfig_compare(const __GLcontextModes
* const *const a
,
1238 const __GLcontextModes
* const *const b
)
1240 /* The order of these comparisons must NOT change. It is defined by
1241 * the GLX 1.3 spec and ARB_multisample.
1244 PREFER_SMALLER(visualSelectGroup
);
1246 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1247 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1248 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1250 PREFER_SMALLER(visualRating
);
1252 /* This isn't quite right. It is supposed to compare the sum of the
1253 * components the user specifically set minimums for.
1255 PREFER_LARGER_OR_ZERO(redBits
);
1256 PREFER_LARGER_OR_ZERO(greenBits
);
1257 PREFER_LARGER_OR_ZERO(blueBits
);
1258 PREFER_LARGER_OR_ZERO(alphaBits
);
1260 PREFER_SMALLER(rgbBits
);
1262 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1263 /* Prefer single-buffer.
1265 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1268 PREFER_SMALLER(numAuxBuffers
);
1270 PREFER_LARGER_OR_ZERO(depthBits
);
1271 PREFER_SMALLER(stencilBits
);
1273 /* This isn't quite right. It is supposed to compare the sum of the
1274 * components the user specifically set minimums for.
1276 PREFER_LARGER_OR_ZERO(accumRedBits
);
1277 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1278 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1279 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1281 PREFER_SMALLER(visualType
);
1283 /* None of the multisample specs say where this comparison should happen,
1284 * so I put it near the end.
1286 PREFER_SMALLER(sampleBuffers
);
1287 PREFER_SMALLER(samples
);
1289 /* None of the pbuffer or fbconfig specs say that this comparison needs
1290 * to happen at all, but it seems like it should.
1292 PREFER_LARGER(maxPbufferWidth
);
1293 PREFER_LARGER(maxPbufferHeight
);
1294 PREFER_LARGER(maxPbufferPixels
);
1301 * Selects and sorts a subset of the supplied configs based on the attributes.
1302 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1303 * and \c glXChooseFBConfigSGIX.
1305 * \param configs Array of pointers to possible configs. The elements of
1306 * this array that do not meet the criteria will be set to
1307 * NULL. The remaining elements will be sorted according to
1308 * the various visual / FBConfig selection rules.
1309 * \param num_configs Number of elements in the \c configs array.
1310 * \param attribList Attributes used select from \c configs. This array is
1311 * terminated by a \c None tag. The array can either take
1312 * the form expected by \c glXChooseVisual (where boolean
1313 * tags do not have a value) or by \c glXChooseFBConfig
1314 * (where every tag has a value).
1315 * \param fbconfig_style_tags Selects whether \c attribList is in
1316 * \c glXChooseVisual style or
1317 * \c glXChooseFBConfig style.
1318 * \returns The number of valid elements left in \c configs.
1320 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1323 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1324 const int *attribList
, GLboolean fbconfig_style_tags
)
1326 __GLcontextModes test_config
;
1330 /* This is a fairly direct implementation of the selection method
1331 * described by GLX_SGIX_fbconfig. Start by culling out all the
1332 * configs that are not compatible with the selected parameter
1336 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1337 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1338 (const INT32
*) attribList
,
1339 GL_TRUE
, fbconfig_style_tags
);
1342 for (i
= 0; i
< num_configs
; i
++) {
1343 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1344 configs
[base
] = configs
[i
];
1353 if (base
< num_configs
) {
1354 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1357 /* After the incompatible configs are removed, the resulting
1358 * list is sorted according to the rules set out in the various
1362 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1363 (int (*)(const void *, const void *)) fbconfig_compare
);
1371 ** Return the visual that best matches the template. Return None if no
1372 ** visual matches the template.
1374 PUBLIC XVisualInfo
*
1375 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1377 XVisualInfo
*visualList
= NULL
;
1378 __GLXdisplayPrivate
*priv
;
1379 __GLXscreenConfigs
*psc
;
1380 __GLcontextModes test_config
;
1381 __GLcontextModes
*modes
;
1382 const __GLcontextModes
*best_config
= NULL
;
1385 ** Get a list of all visuals, return if list is empty
1387 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1393 ** Build a template from the defaults and the attribute list
1394 ** Free visual list and return if an unexpected token is encountered
1396 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1397 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1398 (const INT32
*) attribList
,
1402 ** Eliminate visuals that don't meet minimum requirements
1403 ** Compute a score for those that do
1404 ** Remember which visual, if any, got the highest score
1405 ** If no visual is acceptable, return None
1406 ** Otherwise, create an XVisualInfo list with just the selected X visual
1409 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1410 if (fbconfigs_compatible(&test_config
, modes
)
1411 && ((best_config
== NULL
)
1414 ((const __GLcontextModes
* const *const) &modes
,
1415 &best_config
) < 0))) {
1416 XVisualInfo visualTemplate
;
1417 XVisualInfo
*newList
;
1420 visualTemplate
.screen
= screen
;
1421 visualTemplate
.visualid
= modes
->visualID
;
1422 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1423 &visualTemplate
, &i
);
1427 visualList
= newList
;
1428 best_config
= modes
;
1438 glXQueryExtensionsString(Display
* dpy
, int screen
)
1440 __GLXscreenConfigs
*psc
;
1441 __GLXdisplayPrivate
*priv
;
1443 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1447 if (!psc
->effectiveGLXexts
) {
1448 if (!psc
->serverGLXexts
) {
1449 psc
->serverGLXexts
=
1450 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1454 __glXCalculateUsableExtensions(psc
,
1455 #ifdef GLX_DIRECT_RENDERING
1456 (psc
->driScreen
!= NULL
),
1460 priv
->minorVersion
);
1463 return psc
->effectiveGLXexts
;
1467 glXGetClientString(Display
* dpy
, int name
)
1471 return (__glXGLXClientVendorName
);
1473 return (__glXGLXClientVersion
);
1474 case GLX_EXTENSIONS
:
1475 return (__glXGetClientExtensions());
1482 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1484 __GLXscreenConfigs
*psc
;
1485 __GLXdisplayPrivate
*priv
;
1489 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1495 str
= &priv
->serverGLXvendor
;
1498 str
= &priv
->serverGLXversion
;
1500 case GLX_EXTENSIONS
:
1501 str
= &psc
->serverGLXexts
;
1508 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1515 __glXClientInfo(Display
* dpy
, int opcode
)
1517 char *ext_str
= __glXGetClientGLExtensionString();
1518 int size
= strlen(ext_str
) + 1;
1521 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1522 xcb_glx_client_info(c
,
1523 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1525 xGLXClientInfoReq
*req
;
1527 /* Send the glXClientInfo request */
1529 GetReq(GLXClientInfo
, req
);
1530 req
->reqType
= opcode
;
1531 req
->glxCode
= X_GLXClientInfo
;
1532 req
->major
= GLX_MAJOR_VERSION
;
1533 req
->minor
= GLX_MINOR_VERSION
;
1535 req
->length
+= (size
+ 3) >> 2;
1536 req
->numbytes
= size
;
1537 Data(dpy
, ext_str
, size
);
1541 #endif /* USE_XCB */
1548 ** EXT_import_context
1552 glXGetCurrentDisplay(void)
1554 GLXContext gc
= __glXGetCurrentContext();
1557 return gc
->currentDpy
;
1561 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1562 glXGetCurrentDisplay
)
1565 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1568 * \param dpy Display where \c ctx was created.
1569 * \param ctx Context to query.
1570 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1571 * or zero if the request failed due to internal problems (i.e.,
1572 * unable to allocate temporary memory, etc.)
1575 * This function dynamically determines whether to use the EXT_import_context
1576 * version of the protocol or the GLX 1.3 version of the protocol.
1578 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1580 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1581 xGLXQueryContextReply reply
;
1587 return GLX_BAD_CONTEXT
;
1589 opcode
= __glXSetupForCommand(dpy
);
1594 /* Send the glXQueryContextInfoEXT request */
1597 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1598 xGLXQueryContextReq
*req
;
1600 GetReq(GLXQueryContext
, req
);
1602 req
->reqType
= opcode
;
1603 req
->glxCode
= X_GLXQueryContext
;
1604 req
->context
= (unsigned int) (ctx
->xid
);
1607 xGLXVendorPrivateReq
*vpreq
;
1608 xGLXQueryContextInfoEXTReq
*req
;
1610 GetReqExtra(GLXVendorPrivate
,
1611 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1613 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1614 req
->reqType
= opcode
;
1615 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1616 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1617 req
->context
= (unsigned int) (ctx
->xid
);
1620 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1622 numValues
= reply
.n
;
1625 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1628 int *propList
, *pProp
;
1632 nPropListBytes
= numValues
<< 3;
1633 propList
= (int *) Xmalloc(nPropListBytes
);
1634 if (NULL
== propList
) {
1638 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1640 for (i
= 0; i
< numValues
; i
++) {
1642 case GLX_SHARE_CONTEXT_EXT
:
1643 ctx
->share_xid
= *pProp
++;
1645 case GLX_VISUAL_ID_EXT
:
1647 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1650 ctx
->screen
= *pProp
++;
1652 case GLX_FBCONFIG_ID
:
1654 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1657 case GLX_RENDER_TYPE
:
1658 ctx
->renderType
= *pProp
++;
1665 Xfree((char *) propList
);
1675 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1679 /* get the information from the server if we don't have it already */
1680 #ifdef GLX_DIRECT_RENDERING
1681 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1683 if (ctx
->mode
== NULL
) {
1685 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1686 if (Success
!= retVal
)
1689 switch (attribute
) {
1690 case GLX_SHARE_CONTEXT_EXT
:
1691 *value
= (int) (ctx
->share_xid
);
1693 case GLX_VISUAL_ID_EXT
:
1694 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1697 *value
= (int) (ctx
->screen
);
1699 case GLX_FBCONFIG_ID
:
1700 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1702 case GLX_RENDER_TYPE
:
1703 *value
= (int) (ctx
->renderType
);
1706 return GLX_BAD_ATTRIBUTE
;
1712 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1713 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1714 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1716 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1722 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1726 if (contextID
== None
) {
1729 if (__glXIsDirect(dpy
, contextID
)) {
1733 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1735 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1743 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1745 DestroyContext(dpy
, ctx
);
1751 * GLX 1.3 functions - these are just stubs for now!
1754 PUBLIC GLXFBConfig
*
1755 glXChooseFBConfig(Display
* dpy
, int screen
,
1756 const int *attribList
, int *nitems
)
1758 __GLcontextModes
**config_list
;
1762 config_list
= (__GLcontextModes
**)
1763 glXGetFBConfigs(dpy
, screen
, &list_size
);
1765 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1766 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1767 if (list_size
== 0) {
1773 *nitems
= list_size
;
1774 return (GLXFBConfig
*) config_list
;
1779 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1780 int renderType
, GLXContext shareList
, Bool allowDirect
)
1782 return CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1783 allowDirect
, None
, True
, renderType
);
1788 glXGetCurrentReadDrawable(void)
1790 GLXContext gc
= __glXGetCurrentContext();
1791 return gc
->currentReadable
;
1795 PUBLIC GLXFBConfig
*
1796 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1798 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1799 __GLcontextModes
**config
= NULL
;
1803 if (priv
&& (priv
->screenConfigs
!= NULL
)
1804 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1805 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1806 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
)) {
1807 unsigned num_configs
= 0;
1808 __GLcontextModes
*modes
;
1811 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1812 modes
= modes
->next
) {
1813 if (modes
->fbconfigID
!= GLX_DONT_CARE
) {
1818 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1820 if (config
!= NULL
) {
1821 *nelements
= num_configs
;
1823 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1824 modes
= modes
->next
) {
1825 if (modes
->fbconfigID
!= GLX_DONT_CARE
) {
1832 return (GLXFBConfig
*) config
;
1837 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1838 int attribute
, int *value
)
1840 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1842 return (modes
!= NULL
)
1843 ? _gl_get_context_mode_data(modes
, attribute
, value
)
1848 PUBLIC XVisualInfo
*
1849 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
1851 XVisualInfo visualTemplate
;
1852 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
1856 ** Get a list of all visuals, return if list is empty
1858 visualTemplate
.visualid
= fbconfig
->visualID
;
1859 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1864 ** GLX_SGI_swap_control
1867 __glXSwapIntervalSGI(int interval
)
1869 xGLXVendorPrivateReq
*req
;
1870 GLXContext gc
= __glXGetCurrentContext();
1872 CARD32
*interval_ptr
;
1876 return GLX_BAD_CONTEXT
;
1879 if (interval
<= 0) {
1880 return GLX_BAD_VALUE
;
1883 #ifdef __DRI_SWAP_CONTROL
1884 if (gc
->driContext
) {
1885 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1887 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1888 gc
->currentDrawable
,
1890 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1891 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1895 return GLX_BAD_CONTEXT
;
1899 dpy
= gc
->currentDpy
;
1900 opcode
= __glXSetupForCommand(dpy
);
1905 /* Send the glXSwapIntervalSGI request */
1907 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1908 req
->reqType
= opcode
;
1909 req
->glxCode
= X_GLXVendorPrivate
;
1910 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1911 req
->contextTag
= gc
->currentContextTag
;
1913 interval_ptr
= (CARD32
*) (req
+ 1);
1914 *interval_ptr
= interval
;
1925 ** GLX_MESA_swap_control
1928 __glXSwapIntervalMESA(unsigned int interval
)
1930 #ifdef __DRI_SWAP_CONTROL
1931 GLXContext gc
= __glXGetCurrentContext();
1934 return GLX_BAD_VALUE
;
1937 if (gc
!= NULL
&& gc
->driContext
) {
1938 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1941 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1942 __GLXDRIdrawable
*pdraw
=
1943 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1944 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1945 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1954 return GLX_BAD_CONTEXT
;
1959 __glXGetSwapIntervalMESA(void)
1961 #ifdef __DRI_SWAP_CONTROL
1962 GLXContext gc
= __glXGetCurrentContext();
1964 if (gc
!= NULL
&& gc
->driContext
) {
1965 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1968 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1969 __GLXDRIdrawable
*pdraw
=
1970 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1971 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1972 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
1983 ** GLX_MESA_swap_frame_usage
1987 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
1989 int status
= GLX_BAD_CONTEXT
;
1990 #ifdef __DRI_FRAME_TRACKING
1992 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1993 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
1995 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1996 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
2006 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2008 int status
= GLX_BAD_CONTEXT
;
2009 #ifdef __DRI_FRAME_TRACKING
2011 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2012 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
2014 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2015 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
2026 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
2028 int status
= GLX_BAD_CONTEXT
;
2029 #ifdef __DRI_FRAME_TRACKING
2031 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2032 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2034 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2035 int64_t sbc
, missedFrames
;
2036 float lastMissedUsage
;
2038 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2054 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
2055 int64_t * sbc
, int64_t * missedFrames
,
2056 GLfloat
* lastMissedUsage
)
2058 int status
= GLX_BAD_CONTEXT
;
2059 #ifdef __DRI_FRAME_TRACKING
2061 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2062 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2064 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2067 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2076 (void) missedFrames
;
2077 (void) lastMissedUsage
;
2084 ** GLX_SGI_video_sync
2087 __glXGetVideoSyncSGI(unsigned int *count
)
2089 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2090 * FIXME: there should be a GLX encoding for this call. I can find no
2091 * FIXME: documentation for the GLX encoding.
2093 #ifdef __DRI_MEDIA_STREAM_COUNTER
2094 GLXContext gc
= __glXGetCurrentContext();
2097 if (gc
!= NULL
&& gc
->driContext
) {
2098 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2100 if (psc
->msc
&& psc
->driScreen
) {
2101 __GLXDRIdrawable
*pdraw
=
2102 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2106 ret
= (*psc
->msc
->getDrawableMSC
) (psc
->__driScreen
,
2107 pdraw
->driDrawable
, &temp
);
2108 *count
= (unsigned) temp
;
2110 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2116 return GLX_BAD_CONTEXT
;
2120 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2122 #ifdef __DRI_MEDIA_STREAM_COUNTER
2123 GLXContext gc
= __glXGetCurrentContext();
2125 if (divisor
<= 0 || remainder
< 0)
2126 return GLX_BAD_VALUE
;
2128 if (gc
!= NULL
&& gc
->driContext
) {
2129 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2131 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2132 __GLXDRIdrawable
*pdraw
=
2133 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2138 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, 0,
2139 divisor
, remainder
, &msc
, &sbc
);
2140 *count
= (unsigned) msc
;
2141 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2147 return GLX_BAD_CONTEXT
;
2152 ** GLX_SGIX_fbconfig
2153 ** Many of these functions are aliased to GLX 1.3 entry points in the
2154 ** GLX_functions table.
2158 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2159 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2160 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2162 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2163 (Display
* dpy
, int screen
, int *attrib_list
,
2164 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2167 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2168 (Display
* dpy
, GLXFBConfigSGIX config
),
2169 (dpy
, config
), glXGetVisualFromFBConfig
)
2171 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2172 GLXFBConfigSGIX config
,
2175 xGLXVendorPrivateWithReplyReq
*vpreq
;
2176 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2177 GLXPixmap xid
= None
;
2179 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2180 __GLXscreenConfigs
*psc
;
2183 if ((dpy
== NULL
) || (config
== NULL
)) {
2187 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2189 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2190 opcode
= __glXSetupForCommand(dpy
);
2195 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2197 GetReqExtra(GLXVendorPrivateWithReply
,
2198 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2199 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2200 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2201 req
->reqType
= opcode
;
2202 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2203 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2204 req
->screen
= fbconfig
->screen
;
2205 req
->fbconfig
= fbconfig
->fbconfigID
;
2206 req
->pixmap
= pixmap
;
2207 req
->glxpixmap
= xid
= XAllocID(dpy
);
2216 glXCreateContextWithConfigSGIX(Display
* dpy
,
2217 GLXFBConfigSGIX config
, int renderType
,
2218 GLXContext shareList
, Bool allowDirect
)
2220 GLXContext gc
= NULL
;
2221 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2222 __GLXscreenConfigs
*psc
;
2225 if ((dpy
== NULL
) || (config
== NULL
)) {
2229 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2231 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2232 gc
= CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2233 allowDirect
, None
, False
, renderType
);
2240 PUBLIC GLXFBConfigSGIX
2241 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2243 __GLXdisplayPrivate
*priv
;
2244 __GLXscreenConfigs
*psc
= NULL
;
2246 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2247 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2248 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
)) {
2249 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2258 ** GLX_SGIX_swap_group
2261 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2271 ** GLX_SGIX_swap_barrier
2274 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2282 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2292 ** GLX_OML_sync_control
2295 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2296 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2298 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2299 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
2303 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2304 __GLXscreenConfigs
*const psc
= &priv
->screenConfigs
[i
];
2306 assert((pdraw
== NULL
) || (i
!= -1));
2307 return ((pdraw
&& psc
->sbc
&& psc
->msc
)
2308 && ((*psc
->msc
->getMSC
) (psc
->driScreen
, msc
) == 0)
2309 && ((*psc
->sbc
->getSBC
) (pdraw
->driDrawable
, sbc
) == 0)
2310 && (__glXGetUST(ust
) == 0));
2322 #ifdef GLX_DIRECT_RENDERING
2324 __driGetMscRateOML(__DRIdrawable
* draw
,
2325 int32_t * numerator
, int32_t * denominator
, void *private)
2328 __GLXscreenConfigs
*psc
;
2329 XF86VidModeModeLine mode_line
;
2332 __GLXDRIdrawable
*glxDraw
= private;
2335 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2336 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2337 unsigned n
= dot_clock
* 1000;
2338 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2340 # define V_INTERLACE 0x010
2341 # define V_DBLSCAN 0x020
2343 if (mode_line
.flags
& V_INTERLACE
)
2345 else if (mode_line
.flags
& V_DBLSCAN
)
2348 /* The OML_sync_control spec requires that if the refresh rate is a
2349 * whole number, that the returned numerator be equal to the refresh
2350 * rate and the denominator be 1.
2358 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2360 /* This is a poor man's way to reduce a fraction. It's far from
2361 * perfect, but it will work well enough for this situation.
2364 for (i
= 0; f
[i
] != 0; i
++) {
2365 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2386 * Determine the refresh rate of the specified drawable and display.
2388 * \param dpy Display whose refresh rate is to be determined.
2389 * \param drawable Drawable whose refresh rate is to be determined.
2390 * \param numerator Numerator of the refresh rate.
2391 * \param demoninator Denominator of the refresh rate.
2392 * \return If the refresh rate for the specified display and drawable could
2393 * be calculated, True is returned. Otherwise False is returned.
2395 * \note This function is implemented entirely client-side. A lot of other
2396 * functionality is required to export GLX_OML_sync_control, so on
2397 * XFree86 this function can be called for direct-rendering contexts
2398 * when GLX_OML_sync_control appears in the client extension string.
2402 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2403 int32_t * numerator
, int32_t * denominator
)
2405 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2406 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2411 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2423 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2424 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2426 #ifdef __DRI_SWAP_BUFFER_COUNTER
2428 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2429 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2431 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2432 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2433 * of -1 if the function failed because of errors detected in the input
2436 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2438 if (divisor
> 0 && remainder
>= divisor
)
2441 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2442 return (*psc
->sbc
->swapBuffersMSC
) (pdraw
->driDrawable
, target_msc
,
2443 divisor
, remainder
);
2457 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2458 int64_t target_msc
, int64_t divisor
,
2459 int64_t remainder
, int64_t * ust
,
2460 int64_t * msc
, int64_t * sbc
)
2462 #ifdef __DRI_MEDIA_STREAM_COUNTER
2464 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2465 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2468 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2469 * error", but the return type in the spec is Bool.
2471 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2473 if (divisor
> 0 && remainder
>= divisor
)
2476 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2477 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2478 divisor
, remainder
, msc
, sbc
);
2480 /* __glXGetUST returns zero on success and non-zero on failure.
2481 * This function returns True on success and False on failure.
2483 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2500 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2501 int64_t target_sbc
, int64_t * ust
,
2502 int64_t * msc
, int64_t * sbc
)
2504 #ifdef __DRI_SWAP_BUFFER_COUNTER
2506 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2507 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2510 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2511 * error", but the return type in the spec is Bool.
2516 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2518 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2520 /* __glXGetUST returns zero on success and non-zero on failure.
2521 * This function returns True on success and False on failure.
2523 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2538 * GLX_MESA_allocate_memory
2543 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2544 size_t size
, float readFreq
,
2545 float writeFreq
, float priority
)
2547 #ifdef __DRI_ALLOCATE
2548 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2550 if (psc
&& psc
->allocate
)
2551 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2552 readFreq
, writeFreq
, priority
);
2561 #endif /* GLX_DIRECT_RENDERING */
2568 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2570 #ifdef __DRI_ALLOCATE
2571 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2573 if (psc
&& psc
->allocate
)
2574 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2580 #endif /* GLX_DIRECT_RENDERING */
2585 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2587 #ifdef __DRI_ALLOCATE
2588 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2590 if (psc
&& psc
->allocate
)
2591 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2597 #endif /* GLX_DIRECT_RENDERING */
2606 * Mesa extension stubs. These will help reduce portability problems.
2611 * Release all buffers associated with the specified GLX drawable.
2614 * This function was intended for stand-alone Mesa. The issue there is that
2615 * the library doesn't get any notification when a window is closed. In
2616 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2617 * supported, there are 3 different functions to destroy a drawable. It
2618 * should be possible to create GLX protocol (or have it determine which
2619 * protocol to use based on the type of the drawable) to have one function
2620 * do the work of 3. For the direct-rendering case, this function could
2621 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2622 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2623 * would need to be used. This really should be done as part of the new DRI
2626 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2627 * __driGarbageCollectDrawables
2628 * glXDestroyGLXPixmap
2629 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2630 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2633 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2642 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2643 Pixmap pixmap
, Colormap cmap
)
2656 * GLX_MESA_copy_sub_buffer
2658 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2660 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2661 int x
, int y
, int width
, int height
)
2663 xGLXVendorPrivateReq
*req
;
2666 CARD32
*drawable_ptr
;
2667 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2670 #ifdef __DRI_COPY_SUB_BUFFER
2672 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2673 if (pdraw
!= NULL
) {
2674 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2675 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2677 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2684 opcode
= __glXSetupForCommand(dpy
);
2689 ** The calling thread may or may not have a current context. If it
2690 ** does, send the context tag so the server can do a flush.
2692 gc
= __glXGetCurrentContext();
2693 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2694 ((drawable
== gc
->currentDrawable
) ||
2695 (drawable
== gc
->currentReadable
))) {
2696 tag
= gc
->currentContextTag
;
2703 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2704 req
->reqType
= opcode
;
2705 req
->glxCode
= X_GLXVendorPrivate
;
2706 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2707 req
->contextTag
= tag
;
2709 drawable_ptr
= (CARD32
*) (req
+ 1);
2710 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2711 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2712 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2713 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2715 *drawable_ptr
= drawable
;
2727 * GLX_EXT_texture_from_pixmap
2731 __glXBindTexImageEXT(Display
* dpy
,
2732 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2734 xGLXVendorPrivateReq
*req
;
2735 GLXContext gc
= __glXGetCurrentContext();
2736 CARD32
*drawable_ptr
;
2738 CARD32
*num_attrib_ptr
;
2748 while (attrib_list
[i
* 2] != None
)
2752 #ifdef GLX_DIRECT_RENDERING
2753 if (gc
->driContext
) {
2754 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2756 if (pdraw
!= NULL
) {
2757 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
2758 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
2759 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
2760 pdraw
->textureTarget
,
2761 pdraw
->textureFormat
,
2762 pdraw
->driDrawable
);
2765 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
2766 pdraw
->textureTarget
,
2767 pdraw
->driDrawable
);
2774 opcode
= __glXSetupForCommand(dpy
);
2779 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2780 req
->reqType
= opcode
;
2781 req
->glxCode
= X_GLXVendorPrivate
;
2782 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2783 req
->contextTag
= gc
->currentContextTag
;
2785 drawable_ptr
= (CARD32
*) (req
+ 1);
2786 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2787 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2788 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2790 *drawable_ptr
= drawable
;
2791 *buffer_ptr
= buffer
;
2792 *num_attrib_ptr
= (CARD32
) i
;
2796 while (attrib_list
[i
* 2] != None
) {
2797 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2798 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2808 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2810 xGLXVendorPrivateReq
*req
;
2811 GLXContext gc
= __glXGetCurrentContext();
2812 CARD32
*drawable_ptr
;
2819 #ifdef GLX_DIRECT_RENDERING
2824 opcode
= __glXSetupForCommand(dpy
);
2829 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2830 req
->reqType
= opcode
;
2831 req
->glxCode
= X_GLXVendorPrivate
;
2832 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2833 req
->contextTag
= gc
->currentContextTag
;
2835 drawable_ptr
= (CARD32
*) (req
+ 1);
2836 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2838 *drawable_ptr
= drawable
;
2839 *buffer_ptr
= buffer
;
2848 * \c strdup is actually not a standard ANSI C or POSIX routine.
2849 * Irix will not define it if ANSI mode is in effect.
2854 __glXstrdup(const char *str
)
2857 copy
= (char *) Xmalloc(strlen(str
) + 1);
2865 ** glXGetProcAddress support
2868 struct name_address_pair
2874 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2875 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2877 static const struct name_address_pair GLX_functions
[] = {
2878 /*** GLX_VERSION_1_0 ***/
2879 GLX_FUNCTION(glXChooseVisual
),
2880 GLX_FUNCTION(glXCopyContext
),
2881 GLX_FUNCTION(glXCreateContext
),
2882 GLX_FUNCTION(glXCreateGLXPixmap
),
2883 GLX_FUNCTION(glXDestroyContext
),
2884 GLX_FUNCTION(glXDestroyGLXPixmap
),
2885 GLX_FUNCTION(glXGetConfig
),
2886 GLX_FUNCTION(glXGetCurrentContext
),
2887 GLX_FUNCTION(glXGetCurrentDrawable
),
2888 GLX_FUNCTION(glXIsDirect
),
2889 GLX_FUNCTION(glXMakeCurrent
),
2890 GLX_FUNCTION(glXQueryExtension
),
2891 GLX_FUNCTION(glXQueryVersion
),
2892 GLX_FUNCTION(glXSwapBuffers
),
2893 GLX_FUNCTION(glXUseXFont
),
2894 GLX_FUNCTION(glXWaitGL
),
2895 GLX_FUNCTION(glXWaitX
),
2897 /*** GLX_VERSION_1_1 ***/
2898 GLX_FUNCTION(glXGetClientString
),
2899 GLX_FUNCTION(glXQueryExtensionsString
),
2900 GLX_FUNCTION(glXQueryServerString
),
2902 /*** GLX_VERSION_1_2 ***/
2903 GLX_FUNCTION(glXGetCurrentDisplay
),
2905 /*** GLX_VERSION_1_3 ***/
2906 GLX_FUNCTION(glXChooseFBConfig
),
2907 GLX_FUNCTION(glXCreateNewContext
),
2908 GLX_FUNCTION(glXCreatePbuffer
),
2909 GLX_FUNCTION(glXCreatePixmap
),
2910 GLX_FUNCTION(glXCreateWindow
),
2911 GLX_FUNCTION(glXDestroyPbuffer
),
2912 GLX_FUNCTION(glXDestroyPixmap
),
2913 GLX_FUNCTION(glXDestroyWindow
),
2914 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2915 GLX_FUNCTION(glXGetFBConfigAttrib
),
2916 GLX_FUNCTION(glXGetFBConfigs
),
2917 GLX_FUNCTION(glXGetSelectedEvent
),
2918 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2919 GLX_FUNCTION(glXMakeContextCurrent
),
2920 GLX_FUNCTION(glXQueryContext
),
2921 GLX_FUNCTION(glXQueryDrawable
),
2922 GLX_FUNCTION(glXSelectEvent
),
2924 /*** GLX_SGI_swap_control ***/
2925 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2927 /*** GLX_SGI_video_sync ***/
2928 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2929 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2931 /*** GLX_SGI_make_current_read ***/
2932 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2933 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2935 /*** GLX_EXT_import_context ***/
2936 GLX_FUNCTION(glXFreeContextEXT
),
2937 GLX_FUNCTION(glXGetContextIDEXT
),
2938 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2939 GLX_FUNCTION(glXImportContextEXT
),
2940 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2942 /*** GLX_SGIX_fbconfig ***/
2943 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2944 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2945 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2946 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2947 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2948 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2950 /*** GLX_SGIX_pbuffer ***/
2951 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2952 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2953 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2954 GLX_FUNCTION(glXSelectEventSGIX
),
2955 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2957 /*** GLX_SGIX_swap_group ***/
2958 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2960 /*** GLX_SGIX_swap_barrier ***/
2961 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2962 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2964 /*** GLX_MESA_allocate_memory ***/
2965 GLX_FUNCTION(glXAllocateMemoryMESA
),
2966 GLX_FUNCTION(glXFreeMemoryMESA
),
2967 GLX_FUNCTION(glXGetMemoryOffsetMESA
),
2969 /*** GLX_MESA_copy_sub_buffer ***/
2970 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2972 /*** GLX_MESA_pixmap_colormap ***/
2973 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2975 /*** GLX_MESA_release_buffers ***/
2976 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2978 /*** GLX_MESA_swap_control ***/
2979 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2980 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2982 /*** GLX_MESA_swap_frame_usage ***/
2983 GLX_FUNCTION2(glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2984 GLX_FUNCTION2(glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2985 GLX_FUNCTION2(glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2986 GLX_FUNCTION2(glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2988 /*** GLX_ARB_get_proc_address ***/
2989 GLX_FUNCTION(glXGetProcAddressARB
),
2992 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2994 /*** GLX_OML_sync_control ***/
2995 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2996 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2997 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2998 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2999 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
3001 /*** GLX_EXT_texture_from_pixmap ***/
3002 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
3003 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
3005 #ifdef GLX_DIRECT_RENDERING
3006 /*** DRI configuration ***/
3007 GLX_FUNCTION(glXGetScreenDriver
),
3008 GLX_FUNCTION(glXGetDriverConfig
),
3011 {NULL
, NULL
} /* end of list */
3015 static const GLvoid
*
3016 get_glx_proc_address(const char *funcName
)
3020 /* try static functions */
3021 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
3022 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
3023 return GLX_functions
[i
].Address
;
3031 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3032 * \c glXGetProcAddress.
3034 * \param procName Name of a GL or GLX function.
3035 * \returns A pointer to the named function
3037 * \sa glXGetProcAddress
3039 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3041 typedef void (*gl_function
) (void);
3045 /* Search the table of GLX and internal functions first. If that
3046 * fails and the supplied name could be a valid core GL name, try
3047 * searching the core GL function table. This check is done to prevent
3048 * DRI based drivers from searching the core GL function table for
3049 * internal API functions.
3052 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3053 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3054 && (procName
[2] != 'X')) {
3055 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3062 * Get the address of a named GL function. This is the GLX 1.4 name for
3063 * \c glXGetProcAddressARB.
3065 * \param procName Name of a GL or GLX function.
3066 * \returns A pointer to the named function
3068 * \sa glXGetProcAddressARB
3070 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3071 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3072 __attribute__ ((alias("glXGetProcAddressARB")));
3075 return glXGetProcAddressARB(procName
);
3077 #endif /* __GNUC__ */
3080 #ifdef GLX_DIRECT_RENDERING
3082 * Get the unadjusted system time (UST). Currently, the UST is measured in
3083 * microseconds since Epoc. The actual resolution of the UST may vary from
3084 * system to system, and the units may vary from release to release.
3085 * Drivers should not call this function directly. They should instead use
3086 * \c glXGetProcAddress to obtain a pointer to the function.
3088 * \param ust Location to store the 64-bit UST
3089 * \returns Zero on success or a negative errno value on failure.
3091 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3093 * \since Internal API version 20030317.
3096 __glXGetUST(int64_t * ust
)
3104 if (gettimeofday(&tv
, NULL
) == 0) {
3105 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3112 #endif /* GLX_DIRECT_RENDERING */