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
);
887 ** Destroy the named pixmap
890 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
892 xGLXDestroyGLXPixmapReq
*req
;
895 opcode
= __glXSetupForCommand(dpy
);
900 /* Send the glXDestroyGLXPixmap request */
902 GetReq(GLXDestroyGLXPixmap
, req
);
903 req
->reqType
= opcode
;
904 req
->glxCode
= X_GLXDestroyGLXPixmap
;
905 req
->glxpixmap
= glxpixmap
;
909 #ifdef GLX_DIRECT_RENDERING
912 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
913 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
, &screen
);
914 __GLXscreenConfigs
*psc
= &priv
->screenConfigs
[screen
];
917 (*pdraw
->destroyDrawable
) (pdraw
);
918 __glxHashDelete(psc
->drawHash
, glxpixmap
);
925 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
933 xGLXSwapBuffersReq
*req
;
936 #ifdef GLX_DIRECT_RENDERING
937 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
941 (*pdraw
->psc
->driScreen
->swapBuffers
) (pdraw
);
946 opcode
= __glXSetupForCommand(dpy
);
952 ** The calling thread may or may not have a current context. If it
953 ** does, send the context tag so the server can do a flush.
955 gc
= __glXGetCurrentContext();
956 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
957 ((drawable
== gc
->currentDrawable
)
958 || (drawable
== gc
->currentReadable
))) {
959 tag
= gc
->currentContextTag
;
966 c
= XGetXCBConnection(dpy
);
967 xcb_glx_swap_buffers(c
, tag
, drawable
);
970 /* Send the glXSwapBuffers request */
972 GetReq(GLXSwapBuffers
, req
);
973 req
->reqType
= opcode
;
974 req
->glxCode
= X_GLXSwapBuffers
;
975 req
->drawable
= drawable
;
976 req
->contextTag
= tag
;
985 ** Return configuration information for the given display, screen and
986 ** visual combination.
989 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
992 __GLXdisplayPrivate
*priv
;
993 __GLXscreenConfigs
*psc
;
994 __GLcontextModes
*modes
;
997 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
998 if (status
== Success
) {
999 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1001 /* Lookup attribute after first finding a match on the visual */
1002 if (modes
!= NULL
) {
1003 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
1006 status
= GLX_BAD_VISUAL
;
1010 ** If we can't find the config for this visual, this visual is not
1011 ** supported by the OpenGL implementation on the server.
1013 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1014 *value_return
= GL_FALSE
;
1021 /************************************************************************/
1024 init_fbconfig_for_chooser(__GLcontextModes
* config
,
1025 GLboolean fbconfig_style_tags
)
1027 memset(config
, 0, sizeof(__GLcontextModes
));
1028 config
->visualID
= (XID
) GLX_DONT_CARE
;
1029 config
->visualType
= GLX_DONT_CARE
;
1031 /* glXChooseFBConfig specifies different defaults for these two than
1034 if (fbconfig_style_tags
) {
1035 config
->rgbMode
= GL_TRUE
;
1036 config
->doubleBufferMode
= GLX_DONT_CARE
;
1039 config
->visualRating
= GLX_DONT_CARE
;
1040 config
->transparentPixel
= GLX_NONE
;
1041 config
->transparentRed
= GLX_DONT_CARE
;
1042 config
->transparentGreen
= GLX_DONT_CARE
;
1043 config
->transparentBlue
= GLX_DONT_CARE
;
1044 config
->transparentAlpha
= GLX_DONT_CARE
;
1045 config
->transparentIndex
= GLX_DONT_CARE
;
1047 config
->drawableType
= GLX_WINDOW_BIT
;
1048 config
->renderType
=
1049 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1050 config
->xRenderable
= GLX_DONT_CARE
;
1051 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1053 config
->swapMethod
= GLX_DONT_CARE
;
1056 #define MATCH_DONT_CARE( param ) \
1058 if ( (a-> param != GLX_DONT_CARE) \
1059 && (a-> param != b-> param) ) { \
1064 #define MATCH_MINIMUM( param ) \
1066 if ( (a-> param != GLX_DONT_CARE) \
1067 && (a-> param > b-> param) ) { \
1072 #define MATCH_EXACT( param ) \
1074 if ( a-> param != b-> param) { \
1080 * Determine if two GLXFBConfigs are compatible.
1082 * \param a Application specified config to test.
1083 * \param b Server specified config to test against \c a.
1086 fbconfigs_compatible(const __GLcontextModes
* const a
,
1087 const __GLcontextModes
* const b
)
1089 MATCH_DONT_CARE(doubleBufferMode
);
1090 MATCH_DONT_CARE(visualType
);
1091 MATCH_DONT_CARE(visualRating
);
1092 MATCH_DONT_CARE(xRenderable
);
1093 MATCH_DONT_CARE(fbconfigID
);
1094 MATCH_DONT_CARE(swapMethod
);
1096 MATCH_MINIMUM(rgbBits
);
1097 MATCH_MINIMUM(numAuxBuffers
);
1098 MATCH_MINIMUM(redBits
);
1099 MATCH_MINIMUM(greenBits
);
1100 MATCH_MINIMUM(blueBits
);
1101 MATCH_MINIMUM(alphaBits
);
1102 MATCH_MINIMUM(depthBits
);
1103 MATCH_MINIMUM(stencilBits
);
1104 MATCH_MINIMUM(accumRedBits
);
1105 MATCH_MINIMUM(accumGreenBits
);
1106 MATCH_MINIMUM(accumBlueBits
);
1107 MATCH_MINIMUM(accumAlphaBits
);
1108 MATCH_MINIMUM(sampleBuffers
);
1109 MATCH_MINIMUM(maxPbufferWidth
);
1110 MATCH_MINIMUM(maxPbufferHeight
);
1111 MATCH_MINIMUM(maxPbufferPixels
);
1112 MATCH_MINIMUM(samples
);
1114 MATCH_DONT_CARE(stereoMode
);
1117 if (((a
->drawableType
& b
->drawableType
) == 0)
1118 || ((a
->renderType
& b
->renderType
) == 0)) {
1123 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1124 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1125 * Technically speaking, it is a bug in the DDX driver, but there is
1126 * enough of an installed base to work around the problem here. In any
1127 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1128 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1129 * 0 from the server to be a match to maintain backward compatibility with
1130 * the (broken) drivers.
1133 if (a
->transparentPixel
!= GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1134 if (a
->transparentPixel
== GLX_NONE
) {
1135 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1139 MATCH_EXACT(transparentPixel
);
1142 switch (a
->transparentPixel
) {
1143 case GLX_TRANSPARENT_RGB
:
1144 MATCH_DONT_CARE(transparentRed
);
1145 MATCH_DONT_CARE(transparentGreen
);
1146 MATCH_DONT_CARE(transparentBlue
);
1147 MATCH_DONT_CARE(transparentAlpha
);
1150 case GLX_TRANSPARENT_INDEX
:
1151 MATCH_DONT_CARE(transparentIndex
);
1163 /* There's some trickly language in the GLX spec about how this is supposed
1164 * to work. Basically, if a given component size is either not specified
1165 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1166 * Well, that's really hard to do with the code as-is. This behavior is
1167 * closer to correct, but still not technically right.
1169 #define PREFER_LARGER_OR_ZERO(comp) \
1171 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1172 if ( ((*a)-> comp) == 0 ) { \
1175 else if ( ((*b)-> comp) == 0 ) { \
1179 return ((*b)-> comp) - ((*a)-> comp) ; \
1184 #define PREFER_LARGER(comp) \
1186 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1187 return ((*b)-> comp) - ((*a)-> comp) ; \
1191 #define PREFER_SMALLER(comp) \
1193 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1194 return ((*a)-> comp) - ((*b)-> comp) ; \
1199 * Compare two GLXFBConfigs. This function is intended to be used as the
1200 * compare function passed in to qsort.
1202 * \returns If \c a is a "better" config, according to the specification of
1203 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1204 * better, then a number greater than zero is return. If both are
1205 * equal, zero is returned.
1206 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1209 fbconfig_compare(const __GLcontextModes
* const *const a
,
1210 const __GLcontextModes
* const *const b
)
1212 /* The order of these comparisons must NOT change. It is defined by
1213 * the GLX 1.3 spec and ARB_multisample.
1216 PREFER_SMALLER(visualSelectGroup
);
1218 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1219 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1220 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1222 PREFER_SMALLER(visualRating
);
1224 /* This isn't quite right. It is supposed to compare the sum of the
1225 * components the user specifically set minimums for.
1227 PREFER_LARGER_OR_ZERO(redBits
);
1228 PREFER_LARGER_OR_ZERO(greenBits
);
1229 PREFER_LARGER_OR_ZERO(blueBits
);
1230 PREFER_LARGER_OR_ZERO(alphaBits
);
1232 PREFER_SMALLER(rgbBits
);
1234 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1235 /* Prefer single-buffer.
1237 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1240 PREFER_SMALLER(numAuxBuffers
);
1242 PREFER_LARGER_OR_ZERO(depthBits
);
1243 PREFER_SMALLER(stencilBits
);
1245 /* This isn't quite right. It is supposed to compare the sum of the
1246 * components the user specifically set minimums for.
1248 PREFER_LARGER_OR_ZERO(accumRedBits
);
1249 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1250 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1251 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1253 PREFER_SMALLER(visualType
);
1255 /* None of the multisample specs say where this comparison should happen,
1256 * so I put it near the end.
1258 PREFER_SMALLER(sampleBuffers
);
1259 PREFER_SMALLER(samples
);
1261 /* None of the pbuffer or fbconfig specs say that this comparison needs
1262 * to happen at all, but it seems like it should.
1264 PREFER_LARGER(maxPbufferWidth
);
1265 PREFER_LARGER(maxPbufferHeight
);
1266 PREFER_LARGER(maxPbufferPixels
);
1273 * Selects and sorts a subset of the supplied configs based on the attributes.
1274 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1275 * and \c glXChooseFBConfigSGIX.
1277 * \param configs Array of pointers to possible configs. The elements of
1278 * this array that do not meet the criteria will be set to
1279 * NULL. The remaining elements will be sorted according to
1280 * the various visual / FBConfig selection rules.
1281 * \param num_configs Number of elements in the \c configs array.
1282 * \param attribList Attributes used select from \c configs. This array is
1283 * terminated by a \c None tag. The array can either take
1284 * the form expected by \c glXChooseVisual (where boolean
1285 * tags do not have a value) or by \c glXChooseFBConfig
1286 * (where every tag has a value).
1287 * \param fbconfig_style_tags Selects whether \c attribList is in
1288 * \c glXChooseVisual style or
1289 * \c glXChooseFBConfig style.
1290 * \returns The number of valid elements left in \c configs.
1292 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1295 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1296 const int *attribList
, GLboolean fbconfig_style_tags
)
1298 __GLcontextModes test_config
;
1302 /* This is a fairly direct implementation of the selection method
1303 * described by GLX_SGIX_fbconfig. Start by culling out all the
1304 * configs that are not compatible with the selected parameter
1308 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1309 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1310 (const INT32
*) attribList
,
1311 GL_TRUE
, fbconfig_style_tags
);
1314 for (i
= 0; i
< num_configs
; i
++) {
1315 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1316 configs
[base
] = configs
[i
];
1325 if (base
< num_configs
) {
1326 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1329 /* After the incompatible configs are removed, the resulting
1330 * list is sorted according to the rules set out in the various
1334 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1335 (int (*)(const void *, const void *)) fbconfig_compare
);
1343 ** Return the visual that best matches the template. Return None if no
1344 ** visual matches the template.
1346 PUBLIC XVisualInfo
*
1347 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1349 XVisualInfo
*visualList
= NULL
;
1350 __GLXdisplayPrivate
*priv
;
1351 __GLXscreenConfigs
*psc
;
1352 __GLcontextModes test_config
;
1353 __GLcontextModes
*modes
;
1354 const __GLcontextModes
*best_config
= NULL
;
1357 ** Get a list of all visuals, return if list is empty
1359 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1365 ** Build a template from the defaults and the attribute list
1366 ** Free visual list and return if an unexpected token is encountered
1368 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1369 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1370 (const INT32
*) attribList
,
1374 ** Eliminate visuals that don't meet minimum requirements
1375 ** Compute a score for those that do
1376 ** Remember which visual, if any, got the highest score
1377 ** If no visual is acceptable, return None
1378 ** Otherwise, create an XVisualInfo list with just the selected X visual
1381 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1382 if (fbconfigs_compatible(&test_config
, modes
)
1383 && ((best_config
== NULL
)
1386 ((const __GLcontextModes
* const *const) &modes
,
1387 &best_config
) < 0))) {
1388 XVisualInfo visualTemplate
;
1389 XVisualInfo
*newList
;
1392 visualTemplate
.screen
= screen
;
1393 visualTemplate
.visualid
= modes
->visualID
;
1394 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1395 &visualTemplate
, &i
);
1399 visualList
= newList
;
1400 best_config
= modes
;
1410 glXQueryExtensionsString(Display
* dpy
, int screen
)
1412 __GLXscreenConfigs
*psc
;
1413 __GLXdisplayPrivate
*priv
;
1415 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1419 if (!psc
->effectiveGLXexts
) {
1420 if (!psc
->serverGLXexts
) {
1421 psc
->serverGLXexts
=
1422 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1426 __glXCalculateUsableExtensions(psc
,
1427 #ifdef GLX_DIRECT_RENDERING
1428 (psc
->driScreen
!= NULL
),
1432 priv
->minorVersion
);
1435 return psc
->effectiveGLXexts
;
1439 glXGetClientString(Display
* dpy
, int name
)
1443 return (__glXGLXClientVendorName
);
1445 return (__glXGLXClientVersion
);
1446 case GLX_EXTENSIONS
:
1447 return (__glXGetClientExtensions());
1454 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1456 __GLXscreenConfigs
*psc
;
1457 __GLXdisplayPrivate
*priv
;
1461 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1467 str
= &priv
->serverGLXvendor
;
1470 str
= &priv
->serverGLXversion
;
1472 case GLX_EXTENSIONS
:
1473 str
= &psc
->serverGLXexts
;
1480 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1487 __glXClientInfo(Display
* dpy
, int opcode
)
1489 char *ext_str
= __glXGetClientGLExtensionString();
1490 int size
= strlen(ext_str
) + 1;
1493 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1494 xcb_glx_client_info(c
,
1495 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1497 xGLXClientInfoReq
*req
;
1499 /* Send the glXClientInfo request */
1501 GetReq(GLXClientInfo
, req
);
1502 req
->reqType
= opcode
;
1503 req
->glxCode
= X_GLXClientInfo
;
1504 req
->major
= GLX_MAJOR_VERSION
;
1505 req
->minor
= GLX_MINOR_VERSION
;
1507 req
->length
+= (size
+ 3) >> 2;
1508 req
->numbytes
= size
;
1509 Data(dpy
, ext_str
, size
);
1513 #endif /* USE_XCB */
1520 ** EXT_import_context
1524 glXGetCurrentDisplay(void)
1526 GLXContext gc
= __glXGetCurrentContext();
1529 return gc
->currentDpy
;
1533 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1534 glXGetCurrentDisplay
)
1537 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1540 * \param dpy Display where \c ctx was created.
1541 * \param ctx Context to query.
1542 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1543 * or zero if the request failed due to internal problems (i.e.,
1544 * unable to allocate temporary memory, etc.)
1547 * This function dynamically determines whether to use the EXT_import_context
1548 * version of the protocol or the GLX 1.3 version of the protocol.
1550 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1552 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1553 xGLXQueryContextReply reply
;
1559 return GLX_BAD_CONTEXT
;
1561 opcode
= __glXSetupForCommand(dpy
);
1566 /* Send the glXQueryContextInfoEXT request */
1569 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1570 xGLXQueryContextReq
*req
;
1572 GetReq(GLXQueryContext
, req
);
1574 req
->reqType
= opcode
;
1575 req
->glxCode
= X_GLXQueryContext
;
1576 req
->context
= (unsigned int) (ctx
->xid
);
1579 xGLXVendorPrivateReq
*vpreq
;
1580 xGLXQueryContextInfoEXTReq
*req
;
1582 GetReqExtra(GLXVendorPrivate
,
1583 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1585 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1586 req
->reqType
= opcode
;
1587 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1588 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1589 req
->context
= (unsigned int) (ctx
->xid
);
1592 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1594 numValues
= reply
.n
;
1597 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1600 int *propList
, *pProp
;
1604 nPropListBytes
= numValues
<< 3;
1605 propList
= (int *) Xmalloc(nPropListBytes
);
1606 if (NULL
== propList
) {
1610 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1612 for (i
= 0; i
< numValues
; i
++) {
1614 case GLX_SHARE_CONTEXT_EXT
:
1615 ctx
->share_xid
= *pProp
++;
1617 case GLX_VISUAL_ID_EXT
:
1619 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1622 ctx
->screen
= *pProp
++;
1624 case GLX_FBCONFIG_ID
:
1626 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1629 case GLX_RENDER_TYPE
:
1630 ctx
->renderType
= *pProp
++;
1637 Xfree((char *) propList
);
1647 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1651 /* get the information from the server if we don't have it already */
1652 #ifdef GLX_DIRECT_RENDERING
1653 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1655 if (ctx
->mode
== NULL
) {
1657 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1658 if (Success
!= retVal
)
1661 switch (attribute
) {
1662 case GLX_SHARE_CONTEXT_EXT
:
1663 *value
= (int) (ctx
->share_xid
);
1665 case GLX_VISUAL_ID_EXT
:
1666 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1669 *value
= (int) (ctx
->screen
);
1671 case GLX_FBCONFIG_ID
:
1672 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1674 case GLX_RENDER_TYPE
:
1675 *value
= (int) (ctx
->renderType
);
1678 return GLX_BAD_ATTRIBUTE
;
1684 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1685 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1686 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1688 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1694 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1698 if (contextID
== None
) {
1701 if (__glXIsDirect(dpy
, contextID
)) {
1705 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1707 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1715 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1717 DestroyContext(dpy
, ctx
);
1723 * GLX 1.3 functions - these are just stubs for now!
1726 PUBLIC GLXFBConfig
*
1727 glXChooseFBConfig(Display
* dpy
, int screen
,
1728 const int *attribList
, int *nitems
)
1730 __GLcontextModes
**config_list
;
1734 config_list
= (__GLcontextModes
**)
1735 glXGetFBConfigs(dpy
, screen
, &list_size
);
1737 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1738 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1739 if (list_size
== 0) {
1745 *nitems
= list_size
;
1746 return (GLXFBConfig
*) config_list
;
1751 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1752 int renderType
, GLXContext shareList
, Bool allowDirect
)
1754 return CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1755 allowDirect
, None
, True
, renderType
);
1760 glXGetCurrentReadDrawable(void)
1762 GLXContext gc
= __glXGetCurrentContext();
1763 return gc
->currentReadable
;
1767 PUBLIC GLXFBConfig
*
1768 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1770 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1771 __GLcontextModes
**config
= NULL
;
1775 if (priv
&& (priv
->screenConfigs
!= NULL
)
1776 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1777 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1778 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
)) {
1779 unsigned num_configs
= 0;
1780 __GLcontextModes
*modes
;
1783 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1784 modes
= modes
->next
) {
1785 if (modes
->fbconfigID
!= GLX_DONT_CARE
) {
1790 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1792 if (config
!= NULL
) {
1793 *nelements
= num_configs
;
1795 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1796 modes
= modes
->next
) {
1797 if (modes
->fbconfigID
!= GLX_DONT_CARE
) {
1804 return (GLXFBConfig
*) config
;
1809 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1810 int attribute
, int *value
)
1812 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1814 return (modes
!= NULL
)
1815 ? _gl_get_context_mode_data(modes
, attribute
, value
)
1820 PUBLIC XVisualInfo
*
1821 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
1823 XVisualInfo visualTemplate
;
1824 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
1828 ** Get a list of all visuals, return if list is empty
1830 visualTemplate
.visualid
= fbconfig
->visualID
;
1831 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1836 ** GLX_SGI_swap_control
1839 __glXSwapIntervalSGI(int interval
)
1841 xGLXVendorPrivateReq
*req
;
1842 GLXContext gc
= __glXGetCurrentContext();
1844 CARD32
*interval_ptr
;
1848 return GLX_BAD_CONTEXT
;
1851 if (interval
<= 0) {
1852 return GLX_BAD_VALUE
;
1855 #ifdef __DRI_SWAP_CONTROL
1856 if (gc
->driContext
) {
1857 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1859 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1860 gc
->currentDrawable
,
1862 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1863 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1867 return GLX_BAD_CONTEXT
;
1871 dpy
= gc
->currentDpy
;
1872 opcode
= __glXSetupForCommand(dpy
);
1877 /* Send the glXSwapIntervalSGI request */
1879 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1880 req
->reqType
= opcode
;
1881 req
->glxCode
= X_GLXVendorPrivate
;
1882 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1883 req
->contextTag
= gc
->currentContextTag
;
1885 interval_ptr
= (CARD32
*) (req
+ 1);
1886 *interval_ptr
= interval
;
1897 ** GLX_MESA_swap_control
1900 __glXSwapIntervalMESA(unsigned int interval
)
1902 #ifdef __DRI_SWAP_CONTROL
1903 GLXContext gc
= __glXGetCurrentContext();
1906 return GLX_BAD_VALUE
;
1909 if (gc
!= NULL
&& gc
->driContext
) {
1910 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1913 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1914 __GLXDRIdrawable
*pdraw
=
1915 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1916 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1917 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1926 return GLX_BAD_CONTEXT
;
1931 __glXGetSwapIntervalMESA(void)
1933 #ifdef __DRI_SWAP_CONTROL
1934 GLXContext gc
= __glXGetCurrentContext();
1936 if (gc
!= NULL
&& gc
->driContext
) {
1937 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1940 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1941 __GLXDRIdrawable
*pdraw
=
1942 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1943 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1944 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
1955 ** GLX_MESA_swap_frame_usage
1959 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
1961 int status
= GLX_BAD_CONTEXT
;
1962 #ifdef __DRI_FRAME_TRACKING
1964 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1965 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
1967 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1968 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
1978 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
1980 int status
= GLX_BAD_CONTEXT
;
1981 #ifdef __DRI_FRAME_TRACKING
1983 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1984 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
1986 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1987 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
1998 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
2000 int status
= GLX_BAD_CONTEXT
;
2001 #ifdef __DRI_FRAME_TRACKING
2003 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2004 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2006 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2007 int64_t sbc
, missedFrames
;
2008 float lastMissedUsage
;
2010 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2026 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
2027 int64_t * sbc
, int64_t * missedFrames
,
2028 GLfloat
* lastMissedUsage
)
2030 int status
= GLX_BAD_CONTEXT
;
2031 #ifdef __DRI_FRAME_TRACKING
2033 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2034 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2036 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2039 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2048 (void) missedFrames
;
2049 (void) lastMissedUsage
;
2056 ** GLX_SGI_video_sync
2059 __glXGetVideoSyncSGI(unsigned int *count
)
2061 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2062 * FIXME: there should be a GLX encoding for this call. I can find no
2063 * FIXME: documentation for the GLX encoding.
2065 #ifdef __DRI_MEDIA_STREAM_COUNTER
2066 GLXContext gc
= __glXGetCurrentContext();
2069 if (gc
!= NULL
&& gc
->driContext
) {
2070 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2072 if (psc
->msc
&& psc
->driScreen
) {
2073 __GLXDRIdrawable
*pdraw
=
2074 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2078 ret
= (*psc
->msc
->getDrawableMSC
) (psc
->__driScreen
,
2079 pdraw
->driDrawable
, &temp
);
2080 *count
= (unsigned) temp
;
2082 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2088 return GLX_BAD_CONTEXT
;
2092 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2094 #ifdef __DRI_MEDIA_STREAM_COUNTER
2095 GLXContext gc
= __glXGetCurrentContext();
2097 if (divisor
<= 0 || remainder
< 0)
2098 return GLX_BAD_VALUE
;
2100 if (gc
!= NULL
&& gc
->driContext
) {
2101 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2103 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2104 __GLXDRIdrawable
*pdraw
=
2105 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2110 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, 0,
2111 divisor
, remainder
, &msc
, &sbc
);
2112 *count
= (unsigned) msc
;
2113 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2119 return GLX_BAD_CONTEXT
;
2124 ** GLX_SGIX_fbconfig
2125 ** Many of these functions are aliased to GLX 1.3 entry points in the
2126 ** GLX_functions table.
2130 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2131 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2132 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2134 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2135 (Display
* dpy
, int screen
, int *attrib_list
,
2136 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2139 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2140 (Display
* dpy
, GLXFBConfigSGIX config
),
2141 (dpy
, config
), glXGetVisualFromFBConfig
)
2143 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2144 GLXFBConfigSGIX config
,
2147 xGLXVendorPrivateWithReplyReq
*vpreq
;
2148 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2149 GLXPixmap xid
= None
;
2151 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2152 __GLXscreenConfigs
*psc
;
2155 if ((dpy
== NULL
) || (config
== NULL
)) {
2159 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2161 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2162 opcode
= __glXSetupForCommand(dpy
);
2167 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2169 GetReqExtra(GLXVendorPrivateWithReply
,
2170 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2171 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2172 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2173 req
->reqType
= opcode
;
2174 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2175 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2176 req
->screen
= fbconfig
->screen
;
2177 req
->fbconfig
= fbconfig
->fbconfigID
;
2178 req
->pixmap
= pixmap
;
2179 req
->glxpixmap
= xid
= XAllocID(dpy
);
2188 glXCreateContextWithConfigSGIX(Display
* dpy
,
2189 GLXFBConfigSGIX config
, int renderType
,
2190 GLXContext shareList
, Bool allowDirect
)
2192 GLXContext gc
= NULL
;
2193 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2194 __GLXscreenConfigs
*psc
;
2197 if ((dpy
== NULL
) || (config
== NULL
)) {
2201 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2203 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2204 gc
= CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2205 allowDirect
, None
, False
, renderType
);
2212 PUBLIC GLXFBConfigSGIX
2213 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2215 __GLXdisplayPrivate
*priv
;
2216 __GLXscreenConfigs
*psc
= NULL
;
2218 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2219 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2220 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
)) {
2221 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2230 ** GLX_SGIX_swap_group
2233 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2243 ** GLX_SGIX_swap_barrier
2246 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2254 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2264 ** GLX_OML_sync_control
2267 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2268 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2270 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2271 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
2275 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2276 __GLXscreenConfigs
*const psc
= &priv
->screenConfigs
[i
];
2278 assert((pdraw
== NULL
) || (i
!= -1));
2279 return ((pdraw
&& psc
->sbc
&& psc
->msc
)
2280 && ((*psc
->msc
->getMSC
) (psc
->driScreen
, msc
) == 0)
2281 && ((*psc
->sbc
->getSBC
) (pdraw
->driDrawable
, sbc
) == 0)
2282 && (__glXGetUST(ust
) == 0));
2294 #ifdef GLX_DIRECT_RENDERING
2296 __driGetMscRateOML(__DRIdrawable
* draw
,
2297 int32_t * numerator
, int32_t * denominator
, void *private)
2300 __GLXscreenConfigs
*psc
;
2301 XF86VidModeModeLine mode_line
;
2304 __GLXDRIdrawable
*glxDraw
= private;
2307 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2308 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2309 unsigned n
= dot_clock
* 1000;
2310 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2312 # define V_INTERLACE 0x010
2313 # define V_DBLSCAN 0x020
2315 if (mode_line
.flags
& V_INTERLACE
)
2317 else if (mode_line
.flags
& V_DBLSCAN
)
2320 /* The OML_sync_control spec requires that if the refresh rate is a
2321 * whole number, that the returned numerator be equal to the refresh
2322 * rate and the denominator be 1.
2330 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2332 /* This is a poor man's way to reduce a fraction. It's far from
2333 * perfect, but it will work well enough for this situation.
2336 for (i
= 0; f
[i
] != 0; i
++) {
2337 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2358 * Determine the refresh rate of the specified drawable and display.
2360 * \param dpy Display whose refresh rate is to be determined.
2361 * \param drawable Drawable whose refresh rate is to be determined.
2362 * \param numerator Numerator of the refresh rate.
2363 * \param demoninator Denominator of the refresh rate.
2364 * \return If the refresh rate for the specified display and drawable could
2365 * be calculated, True is returned. Otherwise False is returned.
2367 * \note This function is implemented entirely client-side. A lot of other
2368 * functionality is required to export GLX_OML_sync_control, so on
2369 * XFree86 this function can be called for direct-rendering contexts
2370 * when GLX_OML_sync_control appears in the client extension string.
2374 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2375 int32_t * numerator
, int32_t * denominator
)
2377 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2378 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2383 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2395 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2396 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2398 #ifdef __DRI_SWAP_BUFFER_COUNTER
2400 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2401 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2403 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2404 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2405 * of -1 if the function failed because of errors detected in the input
2408 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2410 if (divisor
> 0 && remainder
>= divisor
)
2413 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2414 return (*psc
->sbc
->swapBuffersMSC
) (pdraw
->driDrawable
, target_msc
,
2415 divisor
, remainder
);
2429 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2430 int64_t target_msc
, int64_t divisor
,
2431 int64_t remainder
, int64_t * ust
,
2432 int64_t * msc
, int64_t * sbc
)
2434 #ifdef __DRI_MEDIA_STREAM_COUNTER
2436 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2437 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2440 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2441 * error", but the return type in the spec is Bool.
2443 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2445 if (divisor
> 0 && remainder
>= divisor
)
2448 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2449 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2450 divisor
, remainder
, msc
, sbc
);
2452 /* __glXGetUST returns zero on success and non-zero on failure.
2453 * This function returns True on success and False on failure.
2455 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2472 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2473 int64_t target_sbc
, int64_t * ust
,
2474 int64_t * msc
, int64_t * sbc
)
2476 #ifdef __DRI_SWAP_BUFFER_COUNTER
2478 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2479 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2482 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2483 * error", but the return type in the spec is Bool.
2488 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2490 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2492 /* __glXGetUST returns zero on success and non-zero on failure.
2493 * This function returns True on success and False on failure.
2495 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2510 * GLX_MESA_allocate_memory
2515 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2516 size_t size
, float readFreq
,
2517 float writeFreq
, float priority
)
2519 #ifdef __DRI_ALLOCATE
2520 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2522 if (psc
&& psc
->allocate
)
2523 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2524 readFreq
, writeFreq
, priority
);
2533 #endif /* GLX_DIRECT_RENDERING */
2540 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2542 #ifdef __DRI_ALLOCATE
2543 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2545 if (psc
&& psc
->allocate
)
2546 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2552 #endif /* GLX_DIRECT_RENDERING */
2557 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2559 #ifdef __DRI_ALLOCATE
2560 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2562 if (psc
&& psc
->allocate
)
2563 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2569 #endif /* GLX_DIRECT_RENDERING */
2578 * Mesa extension stubs. These will help reduce portability problems.
2583 * Release all buffers associated with the specified GLX drawable.
2586 * This function was intended for stand-alone Mesa. The issue there is that
2587 * the library doesn't get any notification when a window is closed. In
2588 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2589 * supported, there are 3 different functions to destroy a drawable. It
2590 * should be possible to create GLX protocol (or have it determine which
2591 * protocol to use based on the type of the drawable) to have one function
2592 * do the work of 3. For the direct-rendering case, this function could
2593 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2594 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2595 * would need to be used. This really should be done as part of the new DRI
2598 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2599 * __driGarbageCollectDrawables
2600 * glXDestroyGLXPixmap
2601 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2602 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2605 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2614 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2615 Pixmap pixmap
, Colormap cmap
)
2628 * GLX_MESA_copy_sub_buffer
2630 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2632 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2633 int x
, int y
, int width
, int height
)
2635 xGLXVendorPrivateReq
*req
;
2638 CARD32
*drawable_ptr
;
2639 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2642 #ifdef __DRI_COPY_SUB_BUFFER
2644 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2645 if (pdraw
!= NULL
) {
2646 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2647 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2649 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2656 opcode
= __glXSetupForCommand(dpy
);
2661 ** The calling thread may or may not have a current context. If it
2662 ** does, send the context tag so the server can do a flush.
2664 gc
= __glXGetCurrentContext();
2665 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2666 ((drawable
== gc
->currentDrawable
) ||
2667 (drawable
== gc
->currentReadable
))) {
2668 tag
= gc
->currentContextTag
;
2675 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2676 req
->reqType
= opcode
;
2677 req
->glxCode
= X_GLXVendorPrivate
;
2678 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2679 req
->contextTag
= tag
;
2681 drawable_ptr
= (CARD32
*) (req
+ 1);
2682 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2683 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2684 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2685 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2687 *drawable_ptr
= drawable
;
2699 * GLX_EXT_texture_from_pixmap
2703 __glXBindTexImageEXT(Display
* dpy
,
2704 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2706 xGLXVendorPrivateReq
*req
;
2707 GLXContext gc
= __glXGetCurrentContext();
2708 CARD32
*drawable_ptr
;
2710 CARD32
*num_attrib_ptr
;
2720 while (attrib_list
[i
* 2] != None
)
2724 #ifdef GLX_DIRECT_RENDERING
2725 if (gc
->driContext
) {
2726 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2728 if (pdraw
!= NULL
) {
2729 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
2730 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
2731 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
2732 pdraw
->textureTarget
,
2733 pdraw
->textureFormat
,
2734 pdraw
->driDrawable
);
2737 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
2738 pdraw
->textureTarget
,
2739 pdraw
->driDrawable
);
2746 opcode
= __glXSetupForCommand(dpy
);
2751 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2752 req
->reqType
= opcode
;
2753 req
->glxCode
= X_GLXVendorPrivate
;
2754 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2755 req
->contextTag
= gc
->currentContextTag
;
2757 drawable_ptr
= (CARD32
*) (req
+ 1);
2758 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2759 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2760 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2762 *drawable_ptr
= drawable
;
2763 *buffer_ptr
= buffer
;
2764 *num_attrib_ptr
= (CARD32
) i
;
2768 while (attrib_list
[i
* 2] != None
) {
2769 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2770 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2780 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2782 xGLXVendorPrivateReq
*req
;
2783 GLXContext gc
= __glXGetCurrentContext();
2784 CARD32
*drawable_ptr
;
2791 #ifdef GLX_DIRECT_RENDERING
2796 opcode
= __glXSetupForCommand(dpy
);
2801 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2802 req
->reqType
= opcode
;
2803 req
->glxCode
= X_GLXVendorPrivate
;
2804 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2805 req
->contextTag
= gc
->currentContextTag
;
2807 drawable_ptr
= (CARD32
*) (req
+ 1);
2808 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2810 *drawable_ptr
= drawable
;
2811 *buffer_ptr
= buffer
;
2820 * \c strdup is actually not a standard ANSI C or POSIX routine.
2821 * Irix will not define it if ANSI mode is in effect.
2826 __glXstrdup(const char *str
)
2829 copy
= (char *) Xmalloc(strlen(str
) + 1);
2837 ** glXGetProcAddress support
2840 struct name_address_pair
2846 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2847 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2849 static const struct name_address_pair GLX_functions
[] = {
2850 /*** GLX_VERSION_1_0 ***/
2851 GLX_FUNCTION(glXChooseVisual
),
2852 GLX_FUNCTION(glXCopyContext
),
2853 GLX_FUNCTION(glXCreateContext
),
2854 GLX_FUNCTION(glXCreateGLXPixmap
),
2855 GLX_FUNCTION(glXDestroyContext
),
2856 GLX_FUNCTION(glXDestroyGLXPixmap
),
2857 GLX_FUNCTION(glXGetConfig
),
2858 GLX_FUNCTION(glXGetCurrentContext
),
2859 GLX_FUNCTION(glXGetCurrentDrawable
),
2860 GLX_FUNCTION(glXIsDirect
),
2861 GLX_FUNCTION(glXMakeCurrent
),
2862 GLX_FUNCTION(glXQueryExtension
),
2863 GLX_FUNCTION(glXQueryVersion
),
2864 GLX_FUNCTION(glXSwapBuffers
),
2865 GLX_FUNCTION(glXUseXFont
),
2866 GLX_FUNCTION(glXWaitGL
),
2867 GLX_FUNCTION(glXWaitX
),
2869 /*** GLX_VERSION_1_1 ***/
2870 GLX_FUNCTION(glXGetClientString
),
2871 GLX_FUNCTION(glXQueryExtensionsString
),
2872 GLX_FUNCTION(glXQueryServerString
),
2874 /*** GLX_VERSION_1_2 ***/
2875 GLX_FUNCTION(glXGetCurrentDisplay
),
2877 /*** GLX_VERSION_1_3 ***/
2878 GLX_FUNCTION(glXChooseFBConfig
),
2879 GLX_FUNCTION(glXCreateNewContext
),
2880 GLX_FUNCTION(glXCreatePbuffer
),
2881 GLX_FUNCTION(glXCreatePixmap
),
2882 GLX_FUNCTION(glXCreateWindow
),
2883 GLX_FUNCTION(glXDestroyPbuffer
),
2884 GLX_FUNCTION(glXDestroyPixmap
),
2885 GLX_FUNCTION(glXDestroyWindow
),
2886 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2887 GLX_FUNCTION(glXGetFBConfigAttrib
),
2888 GLX_FUNCTION(glXGetFBConfigs
),
2889 GLX_FUNCTION(glXGetSelectedEvent
),
2890 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2891 GLX_FUNCTION(glXMakeContextCurrent
),
2892 GLX_FUNCTION(glXQueryContext
),
2893 GLX_FUNCTION(glXQueryDrawable
),
2894 GLX_FUNCTION(glXSelectEvent
),
2896 /*** GLX_SGI_swap_control ***/
2897 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2899 /*** GLX_SGI_video_sync ***/
2900 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2901 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2903 /*** GLX_SGI_make_current_read ***/
2904 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2905 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2907 /*** GLX_EXT_import_context ***/
2908 GLX_FUNCTION(glXFreeContextEXT
),
2909 GLX_FUNCTION(glXGetContextIDEXT
),
2910 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2911 GLX_FUNCTION(glXImportContextEXT
),
2912 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2914 /*** GLX_SGIX_fbconfig ***/
2915 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2916 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2917 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2918 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2919 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2920 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2922 /*** GLX_SGIX_pbuffer ***/
2923 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2924 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2925 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2926 GLX_FUNCTION(glXSelectEventSGIX
),
2927 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2929 /*** GLX_SGIX_swap_group ***/
2930 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2932 /*** GLX_SGIX_swap_barrier ***/
2933 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2934 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2936 /*** GLX_MESA_allocate_memory ***/
2937 GLX_FUNCTION(glXAllocateMemoryMESA
),
2938 GLX_FUNCTION(glXFreeMemoryMESA
),
2939 GLX_FUNCTION(glXGetMemoryOffsetMESA
),
2941 /*** GLX_MESA_copy_sub_buffer ***/
2942 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2944 /*** GLX_MESA_pixmap_colormap ***/
2945 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2947 /*** GLX_MESA_release_buffers ***/
2948 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2950 /*** GLX_MESA_swap_control ***/
2951 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2952 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2954 /*** GLX_MESA_swap_frame_usage ***/
2955 GLX_FUNCTION2(glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2956 GLX_FUNCTION2(glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2957 GLX_FUNCTION2(glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2958 GLX_FUNCTION2(glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2960 /*** GLX_ARB_get_proc_address ***/
2961 GLX_FUNCTION(glXGetProcAddressARB
),
2964 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2966 /*** GLX_OML_sync_control ***/
2967 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2968 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2969 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2970 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2971 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2973 /*** GLX_EXT_texture_from_pixmap ***/
2974 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2975 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2977 #ifdef GLX_DIRECT_RENDERING
2978 /*** DRI configuration ***/
2979 GLX_FUNCTION(glXGetScreenDriver
),
2980 GLX_FUNCTION(glXGetDriverConfig
),
2983 {NULL
, NULL
} /* end of list */
2987 static const GLvoid
*
2988 get_glx_proc_address(const char *funcName
)
2992 /* try static functions */
2993 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2994 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2995 return GLX_functions
[i
].Address
;
3003 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3004 * \c glXGetProcAddress.
3006 * \param procName Name of a GL or GLX function.
3007 * \returns A pointer to the named function
3009 * \sa glXGetProcAddress
3011 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3013 typedef void (*gl_function
) (void);
3017 /* Search the table of GLX and internal functions first. If that
3018 * fails and the supplied name could be a valid core GL name, try
3019 * searching the core GL function table. This check is done to prevent
3020 * DRI based drivers from searching the core GL function table for
3021 * internal API functions.
3024 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3025 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3026 && (procName
[2] != 'X')) {
3027 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3034 * Get the address of a named GL function. This is the GLX 1.4 name for
3035 * \c glXGetProcAddressARB.
3037 * \param procName Name of a GL or GLX function.
3038 * \returns A pointer to the named function
3040 * \sa glXGetProcAddressARB
3042 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3043 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3044 __attribute__ ((alias("glXGetProcAddressARB")));
3047 return glXGetProcAddressARB(procName
);
3049 #endif /* __GNUC__ */
3052 #ifdef GLX_DIRECT_RENDERING
3054 * Get the unadjusted system time (UST). Currently, the UST is measured in
3055 * microseconds since Epoc. The actual resolution of the UST may vary from
3056 * system to system, and the units may vary from release to release.
3057 * Drivers should not call this function directly. They should instead use
3058 * \c glXGetProcAddress to obtain a pointer to the function.
3060 * \param ust Location to store the 64-bit UST
3061 * \returns Zero on success or a negative errno value on failure.
3063 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3065 * \since Internal API version 20030317.
3068 __glXGetUST(int64_t * ust
)
3076 if (gettimeofday(&tv
, NULL
) == 0) {
3077 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3084 #endif /* GLX_DIRECT_RENDERING */