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>
45 #define GC_IS_DIRECT(gc) ((gc)->driContext != NULL)
47 #define GC_IS_DIRECT(gc) (0)
51 #include <X11/Xlib-xcb.h>
56 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
57 static const char __glXGLXClientVersion
[] = "1.4";
60 /****************************************************************************/
62 #ifdef GLX_DIRECT_RENDERING
64 static Bool windowExistsFlag
;
66 windowExistsErrorHandler(Display
* dpy
, XErrorEvent
* xerr
)
70 if (xerr
->error_code
== BadWindow
) {
71 windowExistsFlag
= GL_FALSE
;
77 * Find drawables in the local hash that have been destroyed on the
80 * \param dpy Display to destroy drawables for
81 * \param screen Screen number to destroy drawables for
84 GarbageCollectDRIDrawables(Display
* dpy
, __GLXscreenConfigs
* sc
)
87 __GLXDRIdrawable
*pdraw
;
88 XWindowAttributes xwa
;
89 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
91 /* Set no-op error handler so Xlib doesn't bail out if the windows
92 * has alreay been destroyed on the server. */
94 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
96 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
98 windowExistsFlag
= GL_TRUE
;
99 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
100 if (!windowExistsFlag
) {
101 /* Destroy the local drawable data, if the drawable no
102 longer exists in the Xserver */
103 (*pdraw
->destroyDrawable
) (pdraw
);
104 __glxHashDelete(sc
->drawHash
, draw
);
106 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1);
109 XSync(dpy
, GL_FALSE
);
110 XSetErrorHandler(oldXErrorHandler
);
114 * Get the __DRIdrawable for the drawable associated with a GLXContext
116 * \param dpy The display associated with \c drawable.
117 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
118 * \param scrn_num If non-NULL, the drawables screen is stored there
119 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
120 * the drawable is not associated with a direct-rendering context.
122 _X_HIDDEN __GLXDRIdrawable
*
123 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
, int *const scrn_num
)
125 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
126 __GLXDRIdrawable
*pdraw
;
127 const unsigned screen_count
= ScreenCount(dpy
);
129 __GLXscreenConfigs
*psc
;
134 for (i
= 0; i
< screen_count
; i
++) {
135 psc
= &priv
->screenConfigs
[i
];
136 if (psc
->drawHash
== NULL
)
139 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
140 if (scrn_num
!= NULL
)
153 * Get the GLX per-screen data structure associated with a GLX context.
155 * \param dpy Display for which the GLX per-screen information is to be
157 * \param scrn Screen on \c dpy for which the GLX per-screen information is
159 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
160 * specify a valid GLX screen, or NULL otherwise.
162 * \todo Should this function validate that \c scrn is within the screen
163 * number range for \c dpy?
166 static __GLXscreenConfigs
*
167 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
169 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
172 && priv
->screenConfigs
!=
173 NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
178 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
179 __GLXscreenConfigs
** ppsc
)
181 /* Initialize the extension, if needed . This has the added value
182 * of initializing/allocating the display private
186 return GLX_NO_EXTENSION
;
189 *ppriv
= __glXInitialize(dpy
);
190 if (*ppriv
== NULL
) {
191 return GLX_NO_EXTENSION
;
194 /* Check screen number to see if its valid */
195 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
196 return GLX_BAD_SCREEN
;
199 /* Check to see if the GL is supported on this screen */
200 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
201 if ((*ppsc
)->configs
== NULL
) {
202 /* No support for GL on this screen regardless of visual */
203 return GLX_BAD_VISUAL
;
211 * Determine if a \c GLXFBConfig supplied by the application is valid.
213 * \param dpy Application supplied \c Display pointer.
214 * \param config Application supplied \c GLXFBConfig.
216 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
217 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
220 static __GLcontextModes
*
221 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig config
)
223 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
224 const unsigned num_screens
= ScreenCount(dpy
);
226 const __GLcontextModes
*modes
;
230 for (i
= 0; i
< num_screens
; i
++) {
231 for (modes
= priv
->screenConfigs
[i
].configs
; modes
!= NULL
;
232 modes
= modes
->next
) {
233 if (modes
== (__GLcontextModes
*) config
) {
234 return (__GLcontextModes
*) config
;
245 * \todo It should be possible to move the allocate of \c client_state_private
246 * later in the function for direct-rendering contexts. Direct-rendering
247 * contexts don't need to track client state, so they don't need that memory
250 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
251 * function called \c __glXAllocateClientState that allocates the memory and
252 * does all the initialization (including the pixel pack / unpack).
255 AllocateGLXContext(Display
* dpy
)
260 __GLXattribute
*state
;
265 opcode
= __glXSetupForCommand(dpy
);
270 /* Allocate our context record */
271 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
276 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
278 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
284 gc
->client_state_private
= state
;
285 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
286 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
289 ** Create a temporary buffer to hold GLX rendering commands. The size
290 ** of the buffer is selected so that the maximum number of GLX rendering
291 ** commands can fit in a single X packet and still have room in the X
292 ** packet for the GLXRenderReq header.
295 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
296 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
298 Xfree(gc
->client_state_private
);
302 gc
->bufSize
= bufSize
;
304 /* Fill in the new context */
305 gc
->renderMode
= GL_RENDER
;
307 state
->storePack
.alignment
= 4;
308 state
->storeUnpack
.alignment
= 4;
310 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
313 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
314 ** Other code uses the fastImageUnpack bit, but it is never set
317 gc
->fastImageUnpack
= GL_FALSE
;
318 gc
->fillImage
= __glFillImage
;
320 gc
->bufEnd
= gc
->buf
+ bufSize
;
321 gc
->isDirect
= GL_FALSE
;
324 ** Set limit register so that there will be one command per packet
329 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
332 gc
->majorOpcode
= opcode
;
335 ** Constrain the maximum drawing command size allowed to be
336 ** transfered using the X_GLXRender protocol request. First
337 ** constrain by a software limit, then constrain by the protocl
340 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
341 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
343 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
344 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
346 gc
->maxSmallRenderCommandSize
= bufSize
;
352 * Create a new context. Exactly one of \c vis and \c fbconfig should be
355 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
356 * SGIX_fbconfig protocol be used?
357 * \param renderType For FBConfigs, what is the rendering type?
361 CreateContext(Display
* dpy
, int generic_id
,
362 const __GLcontextModes
* const fbconfig
,
363 GLXContext shareList
,
365 unsigned code
, int renderType
, int screen
)
368 #ifdef GLX_DIRECT_RENDERING
369 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
375 if (generic_id
== None
)
378 gc
= AllocateGLXContext(dpy
);
382 #ifdef GLX_DIRECT_RENDERING
383 if (allowDirect
&& psc
->driScreen
) {
384 gc
->driContext
= psc
->driScreen
->createContext(psc
, fbconfig
, gc
,
385 shareList
, renderType
);
386 if (gc
->driContext
!= NULL
) {
390 gc
->isDirect
= GL_TRUE
;
397 case X_GLXCreateContext
: {
398 xGLXCreateContextReq
*req
;
400 /* Send the glXCreateContext request */
401 GetReq(GLXCreateContext
, req
);
402 req
->reqType
= gc
->majorOpcode
;
403 req
->glxCode
= X_GLXCreateContext
;
404 req
->context
= gc
->xid
= XAllocID(dpy
);
405 req
->visual
= generic_id
;
406 req
->screen
= screen
;
407 req
->shareList
= shareList
? shareList
->xid
: None
;
408 req
->isDirect
= GC_IS_DIRECT(gc
);
412 case X_GLXCreateNewContext
: {
413 xGLXCreateNewContextReq
*req
;
415 /* Send the glXCreateNewContext request */
416 GetReq(GLXCreateNewContext
, req
);
417 req
->reqType
= gc
->majorOpcode
;
418 req
->glxCode
= X_GLXCreateNewContext
;
419 req
->context
= gc
->xid
= XAllocID(dpy
);
420 req
->fbconfig
= generic_id
;
421 req
->screen
= screen
;
422 req
->renderType
= renderType
;
423 req
->shareList
= shareList
? shareList
->xid
: None
;
424 req
->isDirect
= GC_IS_DIRECT(gc
);
428 case X_GLXvop_CreateContextWithConfigSGIX
: {
429 xGLXVendorPrivateWithReplyReq
*vpreq
;
430 xGLXCreateContextWithConfigSGIXReq
*req
;
432 /* Send the glXCreateNewContext request */
433 GetReqExtra(GLXVendorPrivateWithReply
,
434 sz_xGLXCreateContextWithConfigSGIXReq
-
435 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
436 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
437 req
->reqType
= gc
->majorOpcode
;
438 req
->glxCode
= X_GLXVendorPrivateWithReply
;
439 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
440 req
->context
= gc
->xid
= XAllocID(dpy
);
441 req
->fbconfig
= generic_id
;
442 req
->screen
= screen
;
443 req
->renderType
= renderType
;
444 req
->shareList
= shareList
? shareList
->xid
: None
;
445 req
->isDirect
= GC_IS_DIRECT(gc
);
450 /* What to do here? This case is the sign of an internal error. It
451 * should never be reachable.
459 gc
->imported
= GL_FALSE
;
460 gc
->renderType
= renderType
;
466 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
467 GLXContext shareList
, Bool allowDirect
)
469 const __GLcontextModes
*mode
= NULL
;
472 #ifdef GLX_DIRECT_RENDERING
473 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
475 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
479 error
.errorCode
= BadValue
;
480 error
.resourceID
= vis
->visualid
;
481 error
.sequenceNumber
= dpy
->request
;
482 error
.type
= X_Error
;
483 error
.majorCode
= __glXSetupForCommand(dpy
);
484 error
.minorCode
= X_GLXCreateContext
;
485 _XError(dpy
, &error
);
489 renderType
= mode
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
492 return CreateContext(dpy
, vis
->visualid
, mode
, shareList
, allowDirect
,
493 X_GLXCreateContext
, renderType
, vis
->screen
);
497 __glXFreeContext(__GLXcontext
* gc
)
500 XFree((char *) gc
->vendor
);
502 XFree((char *) gc
->renderer
);
504 XFree((char *) gc
->version
);
506 XFree((char *) gc
->extensions
);
507 __glFreeAttributeState(gc
);
508 XFree((char *) gc
->buf
);
509 Xfree((char *) gc
->client_state_private
);
515 ** Destroy the named context
518 DestroyContext(Display
* dpy
, GLXContext gc
)
520 xGLXDestroyContextReq
*req
;
525 opcode
= __glXSetupForCommand(dpy
);
526 if (!opcode
|| !gc
) {
532 imported
= gc
->imported
;
535 if (gc
->currentDpy
) {
536 /* This context is bound to some thread. According to the man page,
537 * we should not actually delete the context until it's unbound.
538 * Note that we set gc->xid = None above. In MakeContextCurrent()
539 * we check for that and delete the context there.
545 #ifdef GLX_DIRECT_RENDERING
546 /* Destroy the direct rendering context */
547 if (gc
->driContext
) {
548 (*gc
->driContext
->destroyContext
) (gc
->driContext
, gc
->psc
, dpy
);
549 gc
->driContext
= NULL
;
550 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
554 __glXFreeVertexArrayState(gc
);
556 if (gc
->currentDpy
) {
557 /* Have to free later cuz it's in use now */
561 /* Destroy the handle if not current to anybody */
563 __glXFreeContext(gc
);
568 ** This dpy also created the server side part of the context.
569 ** Send the glXDestroyContext request.
572 GetReq(GLXDestroyContext
, req
);
573 req
->reqType
= opcode
;
574 req
->glxCode
= X_GLXDestroyContext
;
582 glXDestroyContext(Display
* dpy
, GLXContext gc
)
584 DestroyContext(dpy
, gc
);
588 ** Return the major and minor version #s for the GLX extension
591 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
593 __GLXdisplayPrivate
*priv
;
595 /* Init the extension. This fetches the major and minor version. */
596 priv
= __glXInitialize(dpy
);
601 *major
= priv
->majorVersion
;
603 *minor
= priv
->minorVersion
;
608 ** Query the existance of the GLX extension
611 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
613 int major_op
, erb
, evb
;
616 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
627 ** Put a barrier in the token stream that forces the GL to finish its
628 ** work before X can proceed.
634 GLXContext gc
= __glXGetCurrentContext();
635 Display
*dpy
= gc
->currentDpy
;
640 /* Flush any pending commands out */
641 __glXFlushRenderBuffer(gc
, gc
->pc
);
643 #ifdef GLX_DIRECT_RENDERING
644 if (gc
->driContext
) {
646 __GLXDRIdrawable
*pdraw
=
647 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
650 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
652 if (psc
->driScreen
->waitGL
!= NULL
)
653 (*psc
->driScreen
->waitGL
) (pdraw
);
659 /* Send the glXWaitGL request */
661 GetReq(GLXWaitGL
, req
);
662 req
->reqType
= gc
->majorOpcode
;
663 req
->glxCode
= X_GLXWaitGL
;
664 req
->contextTag
= gc
->currentContextTag
;
670 ** Put a barrier in the token stream that forces X to finish its
671 ** work before GL can proceed.
677 GLXContext gc
= __glXGetCurrentContext();
678 Display
*dpy
= gc
->currentDpy
;
683 /* Flush any pending commands out */
684 __glXFlushRenderBuffer(gc
, gc
->pc
);
686 #ifdef GLX_DIRECT_RENDERING
687 if (gc
->driContext
) {
689 __GLXDRIdrawable
*pdraw
=
690 GetGLXDRIDrawable(dpy
, gc
->currentDrawable
, &screen
);
693 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
694 if (psc
->driScreen
->waitX
!= NULL
)
695 (*psc
->driScreen
->waitX
) (pdraw
);
704 ** Send the glXWaitX request.
707 GetReq(GLXWaitX
, req
);
708 req
->reqType
= gc
->majorOpcode
;
709 req
->glxCode
= X_GLXWaitX
;
710 req
->contextTag
= gc
->currentContextTag
;
716 glXUseXFont(Font font
, int first
, int count
, int listBase
)
718 xGLXUseXFontReq
*req
;
719 GLXContext gc
= __glXGetCurrentContext();
720 Display
*dpy
= gc
->currentDpy
;
725 /* Flush any pending commands out */
726 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
728 #ifdef GLX_DIRECT_RENDERING
729 if (gc
->driContext
) {
730 DRI_glXUseXFont(font
, first
, count
, listBase
);
735 /* Send the glXUseFont request */
737 GetReq(GLXUseXFont
, req
);
738 req
->reqType
= gc
->majorOpcode
;
739 req
->glxCode
= X_GLXUseXFont
;
740 req
->contextTag
= gc
->currentContextTag
;
744 req
->listBase
= listBase
;
749 /************************************************************************/
752 ** Copy the source context to the destination context using the
756 glXCopyContext(Display
* dpy
, GLXContext source
,
757 GLXContext dest
, unsigned long mask
)
759 xGLXCopyContextReq
*req
;
760 GLXContext gc
= __glXGetCurrentContext();
764 opcode
= __glXSetupForCommand(dpy
);
769 #ifdef GLX_DIRECT_RENDERING
770 if (gc
->driContext
) {
771 /* NOT_DONE: This does not work yet */
776 ** If the source is the current context, send its tag so that the context
777 ** can be flushed before the copy.
779 if (source
== gc
&& dpy
== gc
->currentDpy
) {
780 tag
= gc
->currentContextTag
;
786 /* Send the glXCopyContext request */
788 GetReq(GLXCopyContext
, req
);
789 req
->reqType
= opcode
;
790 req
->glxCode
= X_GLXCopyContext
;
791 req
->source
= source
? source
->xid
: None
;
792 req
->dest
= dest
? dest
->xid
: None
;
794 req
->contextTag
= tag
;
801 * Determine if a context uses direct rendering.
803 * \param dpy Display where the context was created.
804 * \param contextID ID of the context to be tested.
806 * \returns \c GL_TRUE if the context is direct rendering or not.
809 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
811 #if !defined(USE_XCB)
812 xGLXIsDirectReq
*req
;
813 xGLXIsDirectReply reply
;
817 opcode
= __glXSetupForCommand(dpy
);
823 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
824 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
829 const Bool is_direct
= reply
->is_direct
? True
: False
;
834 /* Send the glXIsDirect request */
836 GetReq(GLXIsDirect
, req
);
837 req
->reqType
= opcode
;
838 req
->glxCode
= X_GLXIsDirect
;
839 req
->context
= contextID
;
840 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
844 return reply
.isDirect
;
850 * Shouldn't this function \b always return \c GL_FALSE when
851 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
852 * the GLX protocol here at all?
855 glXIsDirect(Display
* dpy
, GLXContext gc
)
860 else if (GC_IS_DIRECT(gc
)) {
863 return __glXIsDirect(dpy
, gc
->xid
);
867 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
869 xGLXCreateGLXPixmapReq
*req
;
873 opcode
= __glXSetupForCommand(dpy
);
878 /* Send the glXCreateGLXPixmap request */
880 GetReq(GLXCreateGLXPixmap
, req
);
881 req
->reqType
= opcode
;
882 req
->glxCode
= X_GLXCreateGLXPixmap
;
883 req
->screen
= vis
->screen
;
884 req
->visual
= vis
->visualid
;
885 req
->pixmap
= pixmap
;
886 req
->glxpixmap
= xid
= XAllocID(dpy
);
890 #ifdef GLX_DIRECT_RENDERING
892 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
893 * is actually bound to a context... */
895 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
896 __GLXDRIdrawable
*pdraw
;
897 __GLXscreenConfigs
*psc
;
898 __GLcontextModes
*modes
;
900 psc
= &priv
->screenConfigs
[vis
->screen
];
901 if (psc
->driScreen
== NULL
)
903 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
904 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, modes
);
906 fprintf(stderr
, "failed to create pixmap\n");
910 if (__glxHashInsert(psc
->drawHash
, req
->glxpixmap
, pdraw
)) {
911 (*pdraw
->destroyDrawable
) (pdraw
);
912 return None
; /* FIXME: Check what we're supposed to do here... */
921 ** Destroy the named pixmap
924 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
926 xGLXDestroyGLXPixmapReq
*req
;
929 opcode
= __glXSetupForCommand(dpy
);
934 /* Send the glXDestroyGLXPixmap request */
936 GetReq(GLXDestroyGLXPixmap
, req
);
937 req
->reqType
= opcode
;
938 req
->glxCode
= X_GLXDestroyGLXPixmap
;
939 req
->glxpixmap
= glxpixmap
;
943 #ifdef GLX_DIRECT_RENDERING
946 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
947 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
, &screen
);
948 __GLXscreenConfigs
*psc
= &priv
->screenConfigs
[screen
];
951 (*pdraw
->destroyDrawable
) (pdraw
);
952 __glxHashDelete(psc
->drawHash
, glxpixmap
);
959 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
967 xGLXSwapBuffersReq
*req
;
970 #ifdef GLX_DIRECT_RENDERING
971 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
975 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
980 opcode
= __glXSetupForCommand(dpy
);
986 ** The calling thread may or may not have a current context. If it
987 ** does, send the context tag so the server can do a flush.
989 gc
= __glXGetCurrentContext();
990 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
991 ((drawable
== gc
->currentDrawable
)
992 || (drawable
== gc
->currentReadable
))) {
993 tag
= gc
->currentContextTag
;
1000 c
= XGetXCBConnection(dpy
);
1001 xcb_glx_swap_buffers(c
, tag
, drawable
);
1004 /* Send the glXSwapBuffers request */
1006 GetReq(GLXSwapBuffers
, req
);
1007 req
->reqType
= opcode
;
1008 req
->glxCode
= X_GLXSwapBuffers
;
1009 req
->drawable
= drawable
;
1010 req
->contextTag
= tag
;
1014 #endif /* USE_XCB */
1019 ** Return configuration information for the given display, screen and
1020 ** visual combination.
1023 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1026 __GLXdisplayPrivate
*priv
;
1027 __GLXscreenConfigs
*psc
;
1028 __GLcontextModes
*modes
;
1031 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1032 if (status
== Success
) {
1033 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
1035 /* Lookup attribute after first finding a match on the visual */
1036 if (modes
!= NULL
) {
1037 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
1040 status
= GLX_BAD_VISUAL
;
1044 ** If we can't find the config for this visual, this visual is not
1045 ** supported by the OpenGL implementation on the server.
1047 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1048 *value_return
= GL_FALSE
;
1055 /************************************************************************/
1058 init_fbconfig_for_chooser(__GLcontextModes
* config
,
1059 GLboolean fbconfig_style_tags
)
1061 memset(config
, 0, sizeof(__GLcontextModes
));
1062 config
->visualID
= (XID
) GLX_DONT_CARE
;
1063 config
->visualType
= GLX_DONT_CARE
;
1065 /* glXChooseFBConfig specifies different defaults for these two than
1068 if (fbconfig_style_tags
) {
1069 config
->rgbMode
= GL_TRUE
;
1070 config
->doubleBufferMode
= GLX_DONT_CARE
;
1073 config
->visualRating
= GLX_DONT_CARE
;
1074 config
->transparentPixel
= GLX_NONE
;
1075 config
->transparentRed
= GLX_DONT_CARE
;
1076 config
->transparentGreen
= GLX_DONT_CARE
;
1077 config
->transparentBlue
= GLX_DONT_CARE
;
1078 config
->transparentAlpha
= GLX_DONT_CARE
;
1079 config
->transparentIndex
= GLX_DONT_CARE
;
1081 config
->drawableType
= GLX_WINDOW_BIT
;
1082 config
->renderType
=
1083 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1084 config
->xRenderable
= GLX_DONT_CARE
;
1085 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1087 config
->swapMethod
= GLX_DONT_CARE
;
1090 #define MATCH_DONT_CARE( param ) \
1092 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1093 && (a-> param != b-> param) ) { \
1098 #define MATCH_MINIMUM( param ) \
1100 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1101 && (a-> param > b-> param) ) { \
1106 #define MATCH_EXACT( param ) \
1108 if ( a-> param != b-> param) { \
1114 * Determine if two GLXFBConfigs are compatible.
1116 * \param a Application specified config to test.
1117 * \param b Server specified config to test against \c a.
1120 fbconfigs_compatible(const __GLcontextModes
* const a
,
1121 const __GLcontextModes
* const b
)
1123 MATCH_DONT_CARE(doubleBufferMode
);
1124 MATCH_DONT_CARE(visualType
);
1125 MATCH_DONT_CARE(visualRating
);
1126 MATCH_DONT_CARE(xRenderable
);
1127 MATCH_DONT_CARE(fbconfigID
);
1128 MATCH_DONT_CARE(swapMethod
);
1130 MATCH_MINIMUM(rgbBits
);
1131 MATCH_MINIMUM(numAuxBuffers
);
1132 MATCH_MINIMUM(redBits
);
1133 MATCH_MINIMUM(greenBits
);
1134 MATCH_MINIMUM(blueBits
);
1135 MATCH_MINIMUM(alphaBits
);
1136 MATCH_MINIMUM(depthBits
);
1137 MATCH_MINIMUM(stencilBits
);
1138 MATCH_MINIMUM(accumRedBits
);
1139 MATCH_MINIMUM(accumGreenBits
);
1140 MATCH_MINIMUM(accumBlueBits
);
1141 MATCH_MINIMUM(accumAlphaBits
);
1142 MATCH_MINIMUM(sampleBuffers
);
1143 MATCH_MINIMUM(maxPbufferWidth
);
1144 MATCH_MINIMUM(maxPbufferHeight
);
1145 MATCH_MINIMUM(maxPbufferPixels
);
1146 MATCH_MINIMUM(samples
);
1148 MATCH_DONT_CARE(stereoMode
);
1151 if (((a
->drawableType
& b
->drawableType
) == 0)
1152 || ((a
->renderType
& b
->renderType
) == 0)) {
1157 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1158 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1159 * Technically speaking, it is a bug in the DDX driver, but there is
1160 * enough of an installed base to work around the problem here. In any
1161 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1162 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1163 * 0 from the server to be a match to maintain backward compatibility with
1164 * the (broken) drivers.
1167 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1168 if (a
->transparentPixel
== GLX_NONE
) {
1169 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1173 MATCH_EXACT(transparentPixel
);
1176 switch (a
->transparentPixel
) {
1177 case GLX_TRANSPARENT_RGB
:
1178 MATCH_DONT_CARE(transparentRed
);
1179 MATCH_DONT_CARE(transparentGreen
);
1180 MATCH_DONT_CARE(transparentBlue
);
1181 MATCH_DONT_CARE(transparentAlpha
);
1184 case GLX_TRANSPARENT_INDEX
:
1185 MATCH_DONT_CARE(transparentIndex
);
1197 /* There's some trickly language in the GLX spec about how this is supposed
1198 * to work. Basically, if a given component size is either not specified
1199 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1200 * Well, that's really hard to do with the code as-is. This behavior is
1201 * closer to correct, but still not technically right.
1203 #define PREFER_LARGER_OR_ZERO(comp) \
1205 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1206 if ( ((*a)-> comp) == 0 ) { \
1209 else if ( ((*b)-> comp) == 0 ) { \
1213 return ((*b)-> comp) - ((*a)-> comp) ; \
1218 #define PREFER_LARGER(comp) \
1220 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1221 return ((*b)-> comp) - ((*a)-> comp) ; \
1225 #define PREFER_SMALLER(comp) \
1227 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1228 return ((*a)-> comp) - ((*b)-> comp) ; \
1233 * Compare two GLXFBConfigs. This function is intended to be used as the
1234 * compare function passed in to qsort.
1236 * \returns If \c a is a "better" config, according to the specification of
1237 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1238 * better, then a number greater than zero is return. If both are
1239 * equal, zero is returned.
1240 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1243 fbconfig_compare(const __GLcontextModes
* const *const a
,
1244 const __GLcontextModes
* const *const b
)
1246 /* The order of these comparisons must NOT change. It is defined by
1247 * the GLX 1.3 spec and ARB_multisample.
1250 PREFER_SMALLER(visualSelectGroup
);
1252 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1253 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1254 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1256 PREFER_SMALLER(visualRating
);
1258 /* This isn't quite right. It is supposed to compare the sum of the
1259 * components the user specifically set minimums for.
1261 PREFER_LARGER_OR_ZERO(redBits
);
1262 PREFER_LARGER_OR_ZERO(greenBits
);
1263 PREFER_LARGER_OR_ZERO(blueBits
);
1264 PREFER_LARGER_OR_ZERO(alphaBits
);
1266 PREFER_SMALLER(rgbBits
);
1268 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1269 /* Prefer single-buffer.
1271 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1274 PREFER_SMALLER(numAuxBuffers
);
1276 PREFER_LARGER_OR_ZERO(depthBits
);
1277 PREFER_SMALLER(stencilBits
);
1279 /* This isn't quite right. It is supposed to compare the sum of the
1280 * components the user specifically set minimums for.
1282 PREFER_LARGER_OR_ZERO(accumRedBits
);
1283 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1284 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1285 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1287 PREFER_SMALLER(visualType
);
1289 /* None of the multisample specs say where this comparison should happen,
1290 * so I put it near the end.
1292 PREFER_SMALLER(sampleBuffers
);
1293 PREFER_SMALLER(samples
);
1295 /* None of the pbuffer or fbconfig specs say that this comparison needs
1296 * to happen at all, but it seems like it should.
1298 PREFER_LARGER(maxPbufferWidth
);
1299 PREFER_LARGER(maxPbufferHeight
);
1300 PREFER_LARGER(maxPbufferPixels
);
1307 * Selects and sorts a subset of the supplied configs based on the attributes.
1308 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1309 * and \c glXChooseFBConfigSGIX.
1311 * \param configs Array of pointers to possible configs. The elements of
1312 * this array that do not meet the criteria will be set to
1313 * NULL. The remaining elements will be sorted according to
1314 * the various visual / FBConfig selection rules.
1315 * \param num_configs Number of elements in the \c configs array.
1316 * \param attribList Attributes used select from \c configs. This array is
1317 * terminated by a \c None tag. The array can either take
1318 * the form expected by \c glXChooseVisual (where boolean
1319 * tags do not have a value) or by \c glXChooseFBConfig
1320 * (where every tag has a value).
1321 * \param fbconfig_style_tags Selects whether \c attribList is in
1322 * \c glXChooseVisual style or
1323 * \c glXChooseFBConfig style.
1324 * \returns The number of valid elements left in \c configs.
1326 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1329 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1330 const int *attribList
, GLboolean fbconfig_style_tags
)
1332 __GLcontextModes test_config
;
1336 /* This is a fairly direct implementation of the selection method
1337 * described by GLX_SGIX_fbconfig. Start by culling out all the
1338 * configs that are not compatible with the selected parameter
1342 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1343 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1344 (const INT32
*) attribList
,
1345 GL_TRUE
, fbconfig_style_tags
);
1348 for (i
= 0; i
< num_configs
; i
++) {
1349 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1350 configs
[base
] = configs
[i
];
1359 if (base
< num_configs
) {
1360 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1363 /* After the incompatible configs are removed, the resulting
1364 * list is sorted according to the rules set out in the various
1368 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1369 (int (*)(const void *, const void *)) fbconfig_compare
);
1377 ** Return the visual that best matches the template. Return None if no
1378 ** visual matches the template.
1380 PUBLIC XVisualInfo
*
1381 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1383 XVisualInfo
*visualList
= NULL
;
1384 __GLXdisplayPrivate
*priv
;
1385 __GLXscreenConfigs
*psc
;
1386 __GLcontextModes test_config
;
1387 __GLcontextModes
*modes
;
1388 const __GLcontextModes
*best_config
= NULL
;
1391 ** Get a list of all visuals, return if list is empty
1393 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1399 ** Build a template from the defaults and the attribute list
1400 ** Free visual list and return if an unexpected token is encountered
1402 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1403 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1404 (const INT32
*) attribList
,
1408 ** Eliminate visuals that don't meet minimum requirements
1409 ** Compute a score for those that do
1410 ** Remember which visual, if any, got the highest score
1411 ** If no visual is acceptable, return None
1412 ** Otherwise, create an XVisualInfo list with just the selected X visual
1415 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1416 if (fbconfigs_compatible(&test_config
, modes
)
1417 && ((best_config
== NULL
)
1420 ((const __GLcontextModes
* const *const) &modes
,
1421 &best_config
) < 0))) {
1422 XVisualInfo visualTemplate
;
1423 XVisualInfo
*newList
;
1426 visualTemplate
.screen
= screen
;
1427 visualTemplate
.visualid
= modes
->visualID
;
1428 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1429 &visualTemplate
, &i
);
1433 visualList
= newList
;
1434 best_config
= modes
;
1444 glXQueryExtensionsString(Display
* dpy
, int screen
)
1446 __GLXscreenConfigs
*psc
;
1447 __GLXdisplayPrivate
*priv
;
1449 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1453 if (!psc
->effectiveGLXexts
) {
1454 if (!psc
->serverGLXexts
) {
1455 psc
->serverGLXexts
=
1456 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1460 __glXCalculateUsableExtensions(psc
,
1461 #ifdef GLX_DIRECT_RENDERING
1462 (psc
->driScreen
!= NULL
),
1466 priv
->minorVersion
);
1469 return psc
->effectiveGLXexts
;
1473 glXGetClientString(Display
* dpy
, int name
)
1479 return (__glXGLXClientVendorName
);
1481 return (__glXGLXClientVersion
);
1482 case GLX_EXTENSIONS
:
1483 return (__glXGetClientExtensions());
1490 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1492 __GLXscreenConfigs
*psc
;
1493 __GLXdisplayPrivate
*priv
;
1497 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1503 str
= &priv
->serverGLXvendor
;
1506 str
= &priv
->serverGLXversion
;
1508 case GLX_EXTENSIONS
:
1509 str
= &psc
->serverGLXexts
;
1516 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1523 __glXClientInfo(Display
* dpy
, int opcode
)
1525 char *ext_str
= __glXGetClientGLExtensionString();
1526 int size
= strlen(ext_str
) + 1;
1529 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1530 xcb_glx_client_info(c
,
1531 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1533 xGLXClientInfoReq
*req
;
1535 /* Send the glXClientInfo request */
1537 GetReq(GLXClientInfo
, req
);
1538 req
->reqType
= opcode
;
1539 req
->glxCode
= X_GLXClientInfo
;
1540 req
->major
= GLX_MAJOR_VERSION
;
1541 req
->minor
= GLX_MINOR_VERSION
;
1543 req
->length
+= (size
+ 3) >> 2;
1544 req
->numbytes
= size
;
1545 Data(dpy
, ext_str
, size
);
1549 #endif /* USE_XCB */
1556 ** EXT_import_context
1560 glXGetCurrentDisplay(void)
1562 GLXContext gc
= __glXGetCurrentContext();
1565 return gc
->currentDpy
;
1569 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1570 glXGetCurrentDisplay
)
1573 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1576 * \param dpy Display where \c ctx was created.
1577 * \param ctx Context to query.
1578 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1579 * or zero if the request failed due to internal problems (i.e.,
1580 * unable to allocate temporary memory, etc.)
1583 * This function dynamically determines whether to use the EXT_import_context
1584 * version of the protocol or the GLX 1.3 version of the protocol.
1586 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1588 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1589 xGLXQueryContextReply reply
;
1595 return GLX_BAD_CONTEXT
;
1597 opcode
= __glXSetupForCommand(dpy
);
1602 /* Send the glXQueryContextInfoEXT request */
1605 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1606 xGLXQueryContextReq
*req
;
1608 GetReq(GLXQueryContext
, req
);
1610 req
->reqType
= opcode
;
1611 req
->glxCode
= X_GLXQueryContext
;
1612 req
->context
= (unsigned int) (ctx
->xid
);
1615 xGLXVendorPrivateReq
*vpreq
;
1616 xGLXQueryContextInfoEXTReq
*req
;
1618 GetReqExtra(GLXVendorPrivate
,
1619 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1621 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1622 req
->reqType
= opcode
;
1623 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1624 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1625 req
->context
= (unsigned int) (ctx
->xid
);
1628 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1630 numValues
= reply
.n
;
1633 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1636 int *propList
, *pProp
;
1639 nPropListBytes
= numValues
<< 3;
1640 propList
= (int *) Xmalloc(nPropListBytes
);
1641 if (NULL
== propList
) {
1647 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1649 for (i
= 0; i
< numValues
; i
++) {
1651 case GLX_SHARE_CONTEXT_EXT
:
1652 ctx
->share_xid
= *pProp
++;
1654 case GLX_VISUAL_ID_EXT
:
1656 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1659 ctx
->screen
= *pProp
++;
1661 case GLX_FBCONFIG_ID
:
1663 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1666 case GLX_RENDER_TYPE
:
1667 ctx
->renderType
= *pProp
++;
1674 Xfree((char *) propList
);
1684 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1688 /* get the information from the server if we don't have it already */
1689 #ifdef GLX_DIRECT_RENDERING
1690 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1692 if (ctx
->mode
== NULL
) {
1694 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1695 if (Success
!= retVal
)
1698 switch (attribute
) {
1699 case GLX_SHARE_CONTEXT_EXT
:
1700 *value
= (int) (ctx
->share_xid
);
1702 case GLX_VISUAL_ID_EXT
:
1703 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1706 *value
= (int) (ctx
->screen
);
1708 case GLX_FBCONFIG_ID
:
1709 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1711 case GLX_RENDER_TYPE
:
1712 *value
= (int) (ctx
->renderType
);
1715 return GLX_BAD_ATTRIBUTE
;
1721 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1722 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1723 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1725 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1731 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1735 if (contextID
== None
) {
1738 if (__glXIsDirect(dpy
, contextID
)) {
1742 ctx
= AllocateGLXContext(dpy
);
1744 ctx
->xid
= contextID
;
1745 ctx
->imported
= GL_TRUE
;
1747 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1748 __glXFreeContext(ctx
);
1756 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1758 DestroyContext(dpy
, ctx
);
1764 * GLX 1.3 functions - these are just stubs for now!
1767 PUBLIC GLXFBConfig
*
1768 glXChooseFBConfig(Display
* dpy
, int screen
,
1769 const int *attribList
, int *nitems
)
1771 __GLcontextModes
**config_list
;
1775 config_list
= (__GLcontextModes
**)
1776 glXGetFBConfigs(dpy
, screen
, &list_size
);
1778 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1779 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1780 if (list_size
== 0) {
1786 *nitems
= list_size
;
1787 return (GLXFBConfig
*) config_list
;
1792 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1793 int renderType
, GLXContext shareList
, Bool allowDirect
)
1795 const __GLcontextModes
*const fbconfig
=
1796 (const __GLcontextModes
*const) config
;
1798 return CreateContext(dpy
, fbconfig
->fbconfigID
, fbconfig
, shareList
,
1799 allowDirect
, X_GLXCreateNewContext
, renderType
,
1805 glXGetCurrentReadDrawable(void)
1807 GLXContext gc
= __glXGetCurrentContext();
1808 return gc
->currentReadable
;
1812 PUBLIC GLXFBConfig
*
1813 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1815 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1816 __GLcontextModes
**config
= NULL
;
1820 if (priv
&& (priv
->screenConfigs
!= NULL
)
1821 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1822 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1823 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
1824 != (int) GLX_DONT_CARE
)) {
1825 unsigned num_configs
= 0;
1826 __GLcontextModes
*modes
;
1829 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1830 modes
= modes
->next
) {
1831 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1836 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1838 if (config
!= NULL
) {
1839 *nelements
= num_configs
;
1841 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1842 modes
= modes
->next
) {
1843 if (modes
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1850 return (GLXFBConfig
*) config
;
1855 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1856 int attribute
, int *value
)
1858 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1860 return (modes
!= NULL
)
1861 ? _gl_get_context_mode_data(modes
, attribute
, value
)
1866 PUBLIC XVisualInfo
*
1867 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
1869 XVisualInfo visualTemplate
;
1870 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
1874 ** Get a list of all visuals, return if list is empty
1876 visualTemplate
.visualid
= fbconfig
->visualID
;
1877 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1882 ** GLX_SGI_swap_control
1885 __glXSwapIntervalSGI(int interval
)
1887 xGLXVendorPrivateReq
*req
;
1888 GLXContext gc
= __glXGetCurrentContext();
1889 __GLXscreenConfigs
*psc
;
1891 CARD32
*interval_ptr
;
1895 return GLX_BAD_CONTEXT
;
1898 if (interval
<= 0) {
1899 return GLX_BAD_VALUE
;
1902 #ifdef __DRI_SWAP_CONTROL
1903 if (gc
->driContext
) {
1904 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1906 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1907 gc
->currentDrawable
,
1909 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1910 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1913 else if (pdraw
== NULL
) {
1914 return GLX_BAD_CONTEXT
;
1918 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1920 #ifdef GLX_DIRECT_RENDERING
1921 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1922 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1923 gc
->currentDrawable
,
1925 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1930 dpy
= gc
->currentDpy
;
1931 opcode
= __glXSetupForCommand(dpy
);
1936 /* Send the glXSwapIntervalSGI request */
1938 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1939 req
->reqType
= opcode
;
1940 req
->glxCode
= X_GLXVendorPrivate
;
1941 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1942 req
->contextTag
= gc
->currentContextTag
;
1944 interval_ptr
= (CARD32
*) (req
+ 1);
1945 *interval_ptr
= interval
;
1956 ** GLX_MESA_swap_control
1959 __glXSwapIntervalMESA(unsigned int interval
)
1961 GLXContext gc
= __glXGetCurrentContext();
1963 #ifdef __DRI_SWAP_CONTROL
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 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1979 #ifdef GLX_DIRECT_RENDERING
1980 if (gc
!= NULL
&& gc
->driContext
) {
1981 __GLXscreenConfigs
*psc
;
1983 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1984 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1985 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1986 gc
->currentDrawable
, NULL
);
1987 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1993 return GLX_BAD_CONTEXT
;
1998 __glXGetSwapIntervalMESA(void)
2000 #ifdef __DRI_SWAP_CONTROL
2001 GLXContext gc
= __glXGetCurrentContext();
2003 if (gc
!= NULL
&& gc
->driContext
) {
2004 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2007 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
2008 __GLXDRIdrawable
*pdraw
=
2009 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2010 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2011 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
2017 #ifdef GLX_DIRECT_RENDERING
2018 if (gc
!= NULL
&& gc
->driContext
) {
2019 __GLXscreenConfigs
*psc
;
2021 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2022 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2023 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2024 gc
->currentDrawable
, NULL
);
2025 return psc
->driScreen
->getSwapInterval(pdraw
);
2035 ** GLX_MESA_swap_frame_usage
2039 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2041 int status
= GLX_BAD_CONTEXT
;
2042 #ifdef __DRI_FRAME_TRACKING
2044 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2045 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2047 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2048 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
2058 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2060 int status
= GLX_BAD_CONTEXT
;
2061 #ifdef __DRI_FRAME_TRACKING
2063 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2064 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
2066 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2067 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
2078 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
2080 int status
= GLX_BAD_CONTEXT
;
2081 #ifdef __DRI_FRAME_TRACKING
2083 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2084 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2086 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2087 int64_t sbc
, missedFrames
;
2088 float lastMissedUsage
;
2090 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2106 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
2107 int64_t * sbc
, int64_t * missedFrames
,
2108 GLfloat
* lastMissedUsage
)
2110 int status
= GLX_BAD_CONTEXT
;
2111 #ifdef __DRI_FRAME_TRACKING
2113 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2114 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2116 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2119 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2128 (void) missedFrames
;
2129 (void) lastMissedUsage
;
2136 ** GLX_SGI_video_sync
2139 __glXGetVideoSyncSGI(unsigned int *count
)
2141 int64_t ust
, msc
, sbc
;
2143 GLXContext gc
= __glXGetCurrentContext();
2144 __GLXscreenConfigs
*psc
;
2145 #ifdef GLX_DIRECT_RENDERING
2146 __GLXDRIdrawable
*pdraw
;
2150 return GLX_BAD_CONTEXT
;
2152 #ifdef GLX_DIRECT_RENDERING
2153 if (!gc
->driContext
)
2154 return GLX_BAD_CONTEXT
;
2157 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2158 #ifdef GLX_DIRECT_RENDERING
2159 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2162 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2163 * FIXME: there should be a GLX encoding for this call. I can find no
2164 * FIXME: documentation for the GLX encoding.
2166 #ifdef __DRI_MEDIA_STREAM_COUNTER
2167 if ( psc
->msc
&& psc
->driScreen
) {
2168 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
2169 pdraw
->driDrawable
, &msc
);
2170 *count
= (unsigned) msc
;
2172 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2176 #ifdef GLX_DIRECT_RENDERING
2177 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2178 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2179 *count
= (unsigned) msc
;
2180 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2184 return GLX_BAD_CONTEXT
;
2188 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2190 GLXContext gc
= __glXGetCurrentContext();
2191 __GLXscreenConfigs
*psc
;
2192 #ifdef GLX_DIRECT_RENDERING
2193 __GLXDRIdrawable
*pdraw
;
2195 int64_t ust
, msc
, sbc
;
2198 if (divisor
<= 0 || remainder
< 0)
2199 return GLX_BAD_VALUE
;
2202 return GLX_BAD_CONTEXT
;
2204 #ifdef GLX_DIRECT_RENDERING
2205 if (!gc
->driContext
)
2206 return GLX_BAD_CONTEXT
;
2209 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2210 #ifdef GLX_DIRECT_RENDERING
2211 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2214 #ifdef __DRI_MEDIA_STREAM_COUNTER
2215 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2216 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
2217 divisor
, remainder
, &msc
, &sbc
);
2218 *count
= (unsigned) msc
;
2219 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2223 #ifdef GLX_DIRECT_RENDERING
2224 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2225 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2227 *count
= (unsigned) msc
;
2228 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2232 return GLX_BAD_CONTEXT
;
2237 ** GLX_SGIX_fbconfig
2238 ** Many of these functions are aliased to GLX 1.3 entry points in the
2239 ** GLX_functions table.
2243 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2244 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2245 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2247 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2248 (Display
* dpy
, int screen
, int *attrib_list
,
2249 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2252 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2253 (Display
* dpy
, GLXFBConfigSGIX config
),
2254 (dpy
, config
), glXGetVisualFromFBConfig
)
2257 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2258 GLXFBConfigSGIX config
,
2261 xGLXVendorPrivateWithReplyReq
*vpreq
;
2262 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2263 GLXPixmap xid
= None
;
2265 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2266 __GLXscreenConfigs
*psc
;
2269 if ((dpy
== NULL
) || (config
== NULL
)) {
2273 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2275 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2276 opcode
= __glXSetupForCommand(dpy
);
2281 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2283 GetReqExtra(GLXVendorPrivateWithReply
,
2284 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2285 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2286 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2287 req
->reqType
= opcode
;
2288 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2289 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2290 req
->screen
= fbconfig
->screen
;
2291 req
->fbconfig
= fbconfig
->fbconfigID
;
2292 req
->pixmap
= pixmap
;
2293 req
->glxpixmap
= xid
= XAllocID(dpy
);
2302 glXCreateContextWithConfigSGIX(Display
* dpy
,
2303 GLXFBConfigSGIX config
, int renderType
,
2304 GLXContext shareList
, Bool allowDirect
)
2306 GLXContext gc
= NULL
;
2307 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2308 __GLXscreenConfigs
*psc
;
2311 if ((dpy
== NULL
) || (config
== NULL
)) {
2315 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2317 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2318 gc
= CreateContext(dpy
, fbconfig
->fbconfigID
, fbconfig
, shareList
,
2320 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2328 PUBLIC GLXFBConfigSGIX
2329 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2331 __GLXdisplayPrivate
*priv
;
2332 __GLXscreenConfigs
*psc
= NULL
;
2334 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2335 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2336 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2337 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2346 ** GLX_SGIX_swap_group
2349 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2359 ** GLX_SGIX_swap_barrier
2362 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2370 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2380 ** GLX_OML_sync_control
2383 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2384 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2386 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2388 #ifdef GLX_DIRECT_RENDERING
2389 __GLXDRIdrawable
*pdraw
;
2391 __GLXscreenConfigs
*psc
;
2396 #ifdef GLX_DIRECT_RENDERING
2397 pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2399 psc
= &priv
->screenConfigs
[i
];
2401 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2402 if (pdraw
&& psc
->sbc
&& psc
->msc
)
2403 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2404 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2405 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2406 && (__glXGetUST(ust
) == 0) );
2409 #ifdef GLX_DIRECT_RENDERING
2410 if (pdraw
&& psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2411 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2419 #ifdef GLX_DIRECT_RENDERING
2421 __driGetMscRateOML(__DRIdrawable
* draw
,
2422 int32_t * numerator
, int32_t * denominator
, void *private)
2425 __GLXscreenConfigs
*psc
;
2426 XF86VidModeModeLine mode_line
;
2429 __GLXDRIdrawable
*glxDraw
= private;
2434 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2435 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2436 unsigned n
= dot_clock
* 1000;
2437 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2439 # define V_INTERLACE 0x010
2440 # define V_DBLSCAN 0x020
2442 if (mode_line
.flags
& V_INTERLACE
)
2444 else if (mode_line
.flags
& V_DBLSCAN
)
2447 /* The OML_sync_control spec requires that if the refresh rate is a
2448 * whole number, that the returned numerator be equal to the refresh
2449 * rate and the denominator be 1.
2457 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2459 /* This is a poor man's way to reduce a fraction. It's far from
2460 * perfect, but it will work well enough for this situation.
2463 for (i
= 0; f
[i
] != 0; i
++) {
2464 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2490 * Determine the refresh rate of the specified drawable and display.
2492 * \param dpy Display whose refresh rate is to be determined.
2493 * \param drawable Drawable whose refresh rate is to be determined.
2494 * \param numerator Numerator of the refresh rate.
2495 * \param demoninator Denominator of the refresh rate.
2496 * \return If the refresh rate for the specified display and drawable could
2497 * be calculated, True is returned. Otherwise False is returned.
2499 * \note This function is implemented entirely client-side. A lot of other
2500 * functionality is required to export GLX_OML_sync_control, so on
2501 * XFree86 this function can be called for direct-rendering contexts
2502 * when GLX_OML_sync_control appears in the client extension string.
2506 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2507 int32_t * numerator
, int32_t * denominator
)
2509 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2510 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2515 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2527 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2528 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2530 GLXContext gc
= __glXGetCurrentContext();
2532 #ifdef GLX_DIRECT_RENDERING
2533 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2535 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2537 if (!gc
) /* no GLX for this */
2540 #ifdef GLX_DIRECT_RENDERING
2541 if (!pdraw
|| !gc
->driContext
)
2545 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2546 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2547 * of -1 if the function failed because of errors detected in the input
2550 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2552 if (divisor
> 0 && remainder
>= divisor
)
2555 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2558 #ifdef __DRI_SWAP_BUFFER_COUNTER
2559 if (psc
->counters
!= NULL
)
2560 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2561 divisor
, remainder
);
2564 #ifdef GLX_DIRECT_RENDERING
2565 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2566 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2575 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2576 int64_t target_msc
, int64_t divisor
,
2577 int64_t remainder
, int64_t * ust
,
2578 int64_t * msc
, int64_t * sbc
)
2581 #ifdef GLX_DIRECT_RENDERING
2582 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2584 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2588 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2589 * error", but the return type in the spec is Bool.
2591 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2593 if (divisor
> 0 && remainder
>= divisor
)
2596 #ifdef __DRI_MEDIA_STREAM_COUNTER
2597 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2598 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2599 divisor
, remainder
, msc
, sbc
);
2601 /* __glXGetUST returns zero on success and non-zero on failure.
2602 * This function returns True on success and False on failure.
2604 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2608 #ifdef GLX_DIRECT_RENDERING
2609 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2610 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2621 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2622 int64_t target_sbc
, int64_t * ust
,
2623 int64_t * msc
, int64_t * sbc
)
2626 #ifdef GLX_DIRECT_RENDERING
2627 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2629 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2632 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2633 * error", but the return type in the spec is Bool.
2637 #ifdef __DRI_SWAP_BUFFER_COUNTER
2638 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2640 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2642 /* __glXGetUST returns zero on success and non-zero on failure.
2643 * This function returns True on success and False on failure.
2645 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2649 #ifdef GLX_DIRECT_RENDERING
2650 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2651 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2661 * GLX_MESA_allocate_memory
2666 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2667 size_t size
, float readFreq
,
2668 float writeFreq
, float priority
)
2670 #ifdef __DRI_ALLOCATE
2671 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2673 if (psc
&& psc
->allocate
)
2674 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2675 readFreq
, writeFreq
, priority
);
2684 #endif /* __DRI_ALLOCATE */
2691 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2693 #ifdef __DRI_ALLOCATE
2694 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2696 if (psc
&& psc
->allocate
)
2697 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2703 #endif /* __DRI_ALLOCATE */
2708 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2710 #ifdef __DRI_ALLOCATE
2711 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2713 if (psc
&& psc
->allocate
)
2714 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2720 #endif /* GLX_DIRECT_RENDERING */
2729 * Mesa extension stubs. These will help reduce portability problems.
2734 * Release all buffers associated with the specified GLX drawable.
2737 * This function was intended for stand-alone Mesa. The issue there is that
2738 * the library doesn't get any notification when a window is closed. In
2739 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2740 * supported, there are 3 different functions to destroy a drawable. It
2741 * should be possible to create GLX protocol (or have it determine which
2742 * protocol to use based on the type of the drawable) to have one function
2743 * do the work of 3. For the direct-rendering case, this function could
2744 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2745 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2746 * would need to be used. This really should be done as part of the new DRI
2749 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2750 * __driGarbageCollectDrawables
2751 * glXDestroyGLXPixmap
2752 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2753 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2756 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2765 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2766 Pixmap pixmap
, Colormap cmap
)
2779 * GLX_MESA_copy_sub_buffer
2781 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2783 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2784 int x
, int y
, int width
, int height
)
2786 xGLXVendorPrivateReq
*req
;
2789 CARD32
*drawable_ptr
;
2790 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2793 #ifdef __DRI_COPY_SUB_BUFFER
2795 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2796 if (pdraw
!= NULL
) {
2797 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2798 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2800 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2807 opcode
= __glXSetupForCommand(dpy
);
2812 ** The calling thread may or may not have a current context. If it
2813 ** does, send the context tag so the server can do a flush.
2815 gc
= __glXGetCurrentContext();
2816 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2817 ((drawable
== gc
->currentDrawable
) ||
2818 (drawable
== gc
->currentReadable
))) {
2819 tag
= gc
->currentContextTag
;
2826 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2827 req
->reqType
= opcode
;
2828 req
->glxCode
= X_GLXVendorPrivate
;
2829 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2830 req
->contextTag
= tag
;
2832 drawable_ptr
= (CARD32
*) (req
+ 1);
2833 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2834 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2835 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2836 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2838 *drawable_ptr
= drawable
;
2850 * GLX_EXT_texture_from_pixmap
2854 __glXBindTexImageEXT(Display
* dpy
,
2855 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2857 xGLXVendorPrivateReq
*req
;
2858 GLXContext gc
= __glXGetCurrentContext();
2859 CARD32
*drawable_ptr
;
2861 CARD32
*num_attrib_ptr
;
2871 while (attrib_list
[i
* 2] != None
)
2875 #ifdef GLX_DIRECT_RENDERING
2876 if (gc
->driContext
) {
2877 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2879 if (pdraw
!= NULL
) {
2880 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
2881 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
2882 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
2883 pdraw
->textureTarget
,
2884 pdraw
->textureFormat
,
2885 pdraw
->driDrawable
);
2888 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
2889 pdraw
->textureTarget
,
2890 pdraw
->driDrawable
);
2897 opcode
= __glXSetupForCommand(dpy
);
2902 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2903 req
->reqType
= opcode
;
2904 req
->glxCode
= X_GLXVendorPrivate
;
2905 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2906 req
->contextTag
= gc
->currentContextTag
;
2908 drawable_ptr
= (CARD32
*) (req
+ 1);
2909 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2910 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2911 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2913 *drawable_ptr
= drawable
;
2914 *buffer_ptr
= buffer
;
2915 *num_attrib_ptr
= (CARD32
) i
;
2919 while (attrib_list
[i
* 2] != None
) {
2920 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2921 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2931 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2933 xGLXVendorPrivateReq
*req
;
2934 GLXContext gc
= __glXGetCurrentContext();
2935 CARD32
*drawable_ptr
;
2939 if ((gc
== NULL
) || GC_IS_DIRECT(gc
))
2942 opcode
= __glXSetupForCommand(dpy
);
2947 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2948 req
->reqType
= opcode
;
2949 req
->glxCode
= X_GLXVendorPrivate
;
2950 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2951 req
->contextTag
= gc
->currentContextTag
;
2953 drawable_ptr
= (CARD32
*) (req
+ 1);
2954 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2956 *drawable_ptr
= drawable
;
2957 *buffer_ptr
= buffer
;
2966 * \c strdup is actually not a standard ANSI C or POSIX routine.
2967 * Irix will not define it if ANSI mode is in effect.
2972 __glXstrdup(const char *str
)
2975 copy
= (char *) Xmalloc(strlen(str
) + 1);
2983 ** glXGetProcAddress support
2986 struct name_address_pair
2992 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2993 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2995 static const struct name_address_pair GLX_functions
[] = {
2996 /*** GLX_VERSION_1_0 ***/
2997 GLX_FUNCTION(glXChooseVisual
),
2998 GLX_FUNCTION(glXCopyContext
),
2999 GLX_FUNCTION(glXCreateContext
),
3000 GLX_FUNCTION(glXCreateGLXPixmap
),
3001 GLX_FUNCTION(glXDestroyContext
),
3002 GLX_FUNCTION(glXDestroyGLXPixmap
),
3003 GLX_FUNCTION(glXGetConfig
),
3004 GLX_FUNCTION(glXGetCurrentContext
),
3005 GLX_FUNCTION(glXGetCurrentDrawable
),
3006 GLX_FUNCTION(glXIsDirect
),
3007 GLX_FUNCTION(glXMakeCurrent
),
3008 GLX_FUNCTION(glXQueryExtension
),
3009 GLX_FUNCTION(glXQueryVersion
),
3010 GLX_FUNCTION(glXSwapBuffers
),
3011 GLX_FUNCTION(glXUseXFont
),
3012 GLX_FUNCTION(glXWaitGL
),
3013 GLX_FUNCTION(glXWaitX
),
3015 /*** GLX_VERSION_1_1 ***/
3016 GLX_FUNCTION(glXGetClientString
),
3017 GLX_FUNCTION(glXQueryExtensionsString
),
3018 GLX_FUNCTION(glXQueryServerString
),
3020 /*** GLX_VERSION_1_2 ***/
3021 GLX_FUNCTION(glXGetCurrentDisplay
),
3023 /*** GLX_VERSION_1_3 ***/
3024 GLX_FUNCTION(glXChooseFBConfig
),
3025 GLX_FUNCTION(glXCreateNewContext
),
3026 GLX_FUNCTION(glXCreatePbuffer
),
3027 GLX_FUNCTION(glXCreatePixmap
),
3028 GLX_FUNCTION(glXCreateWindow
),
3029 GLX_FUNCTION(glXDestroyPbuffer
),
3030 GLX_FUNCTION(glXDestroyPixmap
),
3031 GLX_FUNCTION(glXDestroyWindow
),
3032 GLX_FUNCTION(glXGetCurrentReadDrawable
),
3033 GLX_FUNCTION(glXGetFBConfigAttrib
),
3034 GLX_FUNCTION(glXGetFBConfigs
),
3035 GLX_FUNCTION(glXGetSelectedEvent
),
3036 GLX_FUNCTION(glXGetVisualFromFBConfig
),
3037 GLX_FUNCTION(glXMakeContextCurrent
),
3038 GLX_FUNCTION(glXQueryContext
),
3039 GLX_FUNCTION(glXQueryDrawable
),
3040 GLX_FUNCTION(glXSelectEvent
),
3042 /*** GLX_SGI_swap_control ***/
3043 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
3045 /*** GLX_SGI_video_sync ***/
3046 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
3047 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
3049 /*** GLX_SGI_make_current_read ***/
3050 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
3051 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
3053 /*** GLX_EXT_import_context ***/
3054 GLX_FUNCTION(glXFreeContextEXT
),
3055 GLX_FUNCTION(glXGetContextIDEXT
),
3056 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
3057 GLX_FUNCTION(glXImportContextEXT
),
3058 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
3060 /*** GLX_SGIX_fbconfig ***/
3061 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
3062 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
3063 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
3064 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
3065 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
3066 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
3068 /*** GLX_SGIX_pbuffer ***/
3069 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
3070 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
3071 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
3072 GLX_FUNCTION(glXSelectEventSGIX
),
3073 GLX_FUNCTION(glXGetSelectedEventSGIX
),
3075 /*** GLX_SGIX_swap_group ***/
3076 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
3078 /*** GLX_SGIX_swap_barrier ***/
3079 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
3080 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
3082 /*** GLX_MESA_allocate_memory ***/
3083 GLX_FUNCTION(glXAllocateMemoryMESA
),
3084 GLX_FUNCTION(glXFreeMemoryMESA
),
3085 GLX_FUNCTION(glXGetMemoryOffsetMESA
),
3087 /*** GLX_MESA_copy_sub_buffer ***/
3088 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
3090 /*** GLX_MESA_pixmap_colormap ***/
3091 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
3093 /*** GLX_MESA_release_buffers ***/
3094 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
3096 /*** GLX_MESA_swap_control ***/
3097 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
3098 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
3100 /*** GLX_MESA_swap_frame_usage ***/
3101 GLX_FUNCTION2(glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
3102 GLX_FUNCTION2(glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
3103 GLX_FUNCTION2(glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
3104 GLX_FUNCTION2(glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
3106 /*** GLX_ARB_get_proc_address ***/
3107 GLX_FUNCTION(glXGetProcAddressARB
),
3110 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
3112 /*** GLX_OML_sync_control ***/
3113 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
3114 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
3115 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
3116 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
3117 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
3119 /*** GLX_EXT_texture_from_pixmap ***/
3120 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
3121 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
3123 #ifdef GLX_DIRECT_RENDERING
3124 /*** DRI configuration ***/
3125 GLX_FUNCTION(glXGetScreenDriver
),
3126 GLX_FUNCTION(glXGetDriverConfig
),
3129 {NULL
, NULL
} /* end of list */
3133 static const GLvoid
*
3134 get_glx_proc_address(const char *funcName
)
3138 /* try static functions */
3139 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
3140 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
3141 return GLX_functions
[i
].Address
;
3149 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3150 * \c glXGetProcAddress.
3152 * \param procName Name of a GL or GLX function.
3153 * \returns A pointer to the named function
3155 * \sa glXGetProcAddress
3157 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3159 typedef void (*gl_function
) (void);
3163 /* Search the table of GLX and internal functions first. If that
3164 * fails and the supplied name could be a valid core GL name, try
3165 * searching the core GL function table. This check is done to prevent
3166 * DRI based drivers from searching the core GL function table for
3167 * internal API functions.
3170 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3171 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3172 && (procName
[2] != 'X')) {
3173 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3180 * Get the address of a named GL function. This is the GLX 1.4 name for
3181 * \c glXGetProcAddressARB.
3183 * \param procName Name of a GL or GLX function.
3184 * \returns A pointer to the named function
3186 * \sa glXGetProcAddressARB
3188 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3189 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3190 __attribute__ ((alias("glXGetProcAddressARB")));
3193 return glXGetProcAddressARB(procName
);
3195 #endif /* __GNUC__ */
3198 #ifdef GLX_DIRECT_RENDERING
3200 * Get the unadjusted system time (UST). Currently, the UST is measured in
3201 * microseconds since Epoc. The actual resolution of the UST may vary from
3202 * system to system, and the units may vary from release to release.
3203 * Drivers should not call this function directly. They should instead use
3204 * \c glXGetProcAddress to obtain a pointer to the function.
3206 * \param ust Location to store the 64-bit UST
3207 * \returns Zero on success or a negative errno value on failure.
3209 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3211 * \since Internal API version 20030317.
3214 __glXGetUST(int64_t * ust
)
3222 if (gettimeofday(&tv
, NULL
) == 0) {
3223 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3230 #endif /* GLX_DIRECT_RENDERING */