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 if (gc
->driContext
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1921 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1922 gc
->currentDrawable
,
1924 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1928 dpy
= gc
->currentDpy
;
1929 opcode
= __glXSetupForCommand(dpy
);
1934 /* Send the glXSwapIntervalSGI request */
1936 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1937 req
->reqType
= opcode
;
1938 req
->glxCode
= X_GLXVendorPrivate
;
1939 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1940 req
->contextTag
= gc
->currentContextTag
;
1942 interval_ptr
= (CARD32
*) (req
+ 1);
1943 *interval_ptr
= interval
;
1954 ** GLX_MESA_swap_control
1957 __glXSwapIntervalMESA(unsigned int interval
)
1959 GLXContext gc
= __glXGetCurrentContext();
1961 #ifdef __DRI_SWAP_CONTROL
1962 if (gc
!= NULL
&& gc
->driContext
) {
1963 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1966 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1967 __GLXDRIdrawable
*pdraw
=
1968 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1969 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1970 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1977 if (gc
!= NULL
&& gc
->driContext
) {
1978 __GLXscreenConfigs
*psc
;
1980 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1981 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1982 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1983 gc
->currentDrawable
, NULL
);
1984 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1989 return GLX_BAD_CONTEXT
;
1994 __glXGetSwapIntervalMESA(void)
1996 #ifdef __DRI_SWAP_CONTROL
1997 GLXContext gc
= __glXGetCurrentContext();
1999 if (gc
!= NULL
&& gc
->driContext
) {
2000 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2003 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
2004 __GLXDRIdrawable
*pdraw
=
2005 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2006 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
2007 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
2012 if (gc
!= NULL
&& gc
->driContext
) {
2013 __GLXscreenConfigs
*psc
;
2015 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2016 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2017 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
2018 gc
->currentDrawable
, NULL
);
2019 return psc
->driScreen
->getSwapInterval(pdraw
);
2028 ** GLX_MESA_swap_frame_usage
2032 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2034 int status
= GLX_BAD_CONTEXT
;
2035 #ifdef __DRI_FRAME_TRACKING
2037 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2038 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2040 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2041 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
2051 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
2053 int status
= GLX_BAD_CONTEXT
;
2054 #ifdef __DRI_FRAME_TRACKING
2056 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2057 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
2059 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
2060 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
2071 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
2073 int status
= GLX_BAD_CONTEXT
;
2074 #ifdef __DRI_FRAME_TRACKING
2076 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2077 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2079 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2080 int64_t sbc
, missedFrames
;
2081 float lastMissedUsage
;
2083 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2099 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
2100 int64_t * sbc
, int64_t * missedFrames
,
2101 GLfloat
* lastMissedUsage
)
2103 int status
= GLX_BAD_CONTEXT
;
2104 #ifdef __DRI_FRAME_TRACKING
2106 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2107 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2109 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
2112 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
2121 (void) missedFrames
;
2122 (void) lastMissedUsage
;
2129 ** GLX_SGI_video_sync
2132 __glXGetVideoSyncSGI(unsigned int *count
)
2134 int64_t ust
, msc
, sbc
;
2136 GLXContext gc
= __glXGetCurrentContext();
2137 __GLXscreenConfigs
*psc
;
2138 __GLXDRIdrawable
*pdraw
;
2140 if (!gc
|| !gc
->driContext
)
2141 return GLX_BAD_CONTEXT
;
2143 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2144 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2146 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2147 * FIXME: there should be a GLX encoding for this call. I can find no
2148 * FIXME: documentation for the GLX encoding.
2150 #ifdef __DRI_MEDIA_STREAM_COUNTER
2151 if ( psc
->msc
&& psc
->driScreen
) {
2152 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
2153 pdraw
->driDrawable
, &msc
);
2154 *count
= (unsigned) msc
;
2156 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2159 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2160 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2161 *count
= (unsigned) msc
;
2162 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2165 return GLX_BAD_CONTEXT
;
2169 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2171 GLXContext gc
= __glXGetCurrentContext();
2172 __GLXscreenConfigs
*psc
;
2173 __GLXDRIdrawable
*pdraw
;
2174 int64_t ust
, msc
, sbc
;
2177 if (divisor
<= 0 || remainder
< 0)
2178 return GLX_BAD_VALUE
;
2180 if (!gc
|| !gc
->driContext
)
2181 return GLX_BAD_CONTEXT
;
2183 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2184 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2186 #ifdef __DRI_MEDIA_STREAM_COUNTER
2187 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2188 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
2189 divisor
, remainder
, &msc
, &sbc
);
2190 *count
= (unsigned) msc
;
2191 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2194 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2195 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2197 *count
= (unsigned) msc
;
2198 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2201 return GLX_BAD_CONTEXT
;
2206 ** GLX_SGIX_fbconfig
2207 ** Many of these functions are aliased to GLX 1.3 entry points in the
2208 ** GLX_functions table.
2212 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2213 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2214 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2216 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2217 (Display
* dpy
, int screen
, int *attrib_list
,
2218 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2221 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2222 (Display
* dpy
, GLXFBConfigSGIX config
),
2223 (dpy
, config
), glXGetVisualFromFBConfig
)
2226 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2227 GLXFBConfigSGIX config
,
2230 xGLXVendorPrivateWithReplyReq
*vpreq
;
2231 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2232 GLXPixmap xid
= None
;
2234 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2235 __GLXscreenConfigs
*psc
;
2238 if ((dpy
== NULL
) || (config
== NULL
)) {
2242 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2244 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2245 opcode
= __glXSetupForCommand(dpy
);
2250 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2252 GetReqExtra(GLXVendorPrivateWithReply
,
2253 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2254 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2255 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2256 req
->reqType
= opcode
;
2257 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2258 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2259 req
->screen
= fbconfig
->screen
;
2260 req
->fbconfig
= fbconfig
->fbconfigID
;
2261 req
->pixmap
= pixmap
;
2262 req
->glxpixmap
= xid
= XAllocID(dpy
);
2271 glXCreateContextWithConfigSGIX(Display
* dpy
,
2272 GLXFBConfigSGIX config
, int renderType
,
2273 GLXContext shareList
, Bool allowDirect
)
2275 GLXContext gc
= NULL
;
2276 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2277 __GLXscreenConfigs
*psc
;
2280 if ((dpy
== NULL
) || (config
== NULL
)) {
2284 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2286 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2287 gc
= CreateContext(dpy
, fbconfig
->fbconfigID
, fbconfig
, shareList
,
2289 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2297 PUBLIC GLXFBConfigSGIX
2298 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2300 __GLXdisplayPrivate
*priv
;
2301 __GLXscreenConfigs
*psc
= NULL
;
2303 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2304 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2305 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2306 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2315 ** GLX_SGIX_swap_group
2318 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2328 ** GLX_SGIX_swap_barrier
2331 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2339 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2349 ** GLX_OML_sync_control
2352 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2353 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2355 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2357 __GLXDRIdrawable
*pdraw
;
2358 __GLXscreenConfigs
*psc
;
2363 pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2364 psc
= &priv
->screenConfigs
[i
];
2366 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2367 if (pdraw
&& psc
->sbc
&& psc
->msc
)
2368 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2369 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2370 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2371 && (__glXGetUST(ust
) == 0) );
2373 if (pdraw
&& psc
&& psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2374 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2381 #ifdef GLX_DIRECT_RENDERING
2383 __driGetMscRateOML(__DRIdrawable
* draw
,
2384 int32_t * numerator
, int32_t * denominator
, void *private)
2387 __GLXscreenConfigs
*psc
;
2388 XF86VidModeModeLine mode_line
;
2391 __GLXDRIdrawable
*glxDraw
= private;
2396 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2397 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2398 unsigned n
= dot_clock
* 1000;
2399 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2401 # define V_INTERLACE 0x010
2402 # define V_DBLSCAN 0x020
2404 if (mode_line
.flags
& V_INTERLACE
)
2406 else if (mode_line
.flags
& V_DBLSCAN
)
2409 /* The OML_sync_control spec requires that if the refresh rate is a
2410 * whole number, that the returned numerator be equal to the refresh
2411 * rate and the denominator be 1.
2419 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2421 /* This is a poor man's way to reduce a fraction. It's far from
2422 * perfect, but it will work well enough for this situation.
2425 for (i
= 0; f
[i
] != 0; i
++) {
2426 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2452 * Determine the refresh rate of the specified drawable and display.
2454 * \param dpy Display whose refresh rate is to be determined.
2455 * \param drawable Drawable whose refresh rate is to be determined.
2456 * \param numerator Numerator of the refresh rate.
2457 * \param demoninator Denominator of the refresh rate.
2458 * \return If the refresh rate for the specified display and drawable could
2459 * be calculated, True is returned. Otherwise False is returned.
2461 * \note This function is implemented entirely client-side. A lot of other
2462 * functionality is required to export GLX_OML_sync_control, so on
2463 * XFree86 this function can be called for direct-rendering contexts
2464 * when GLX_OML_sync_control appears in the client extension string.
2468 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2469 int32_t * numerator
, int32_t * denominator
)
2471 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2472 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2477 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2489 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2490 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2492 GLXContext gc
= __glXGetCurrentContext();
2494 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2495 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2497 if (!pdraw
|| !gc
|| !gc
->driContext
) /* no GLX for this */
2500 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2501 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2502 * of -1 if the function failed because of errors detected in the input
2505 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2507 if (divisor
> 0 && remainder
>= divisor
)
2510 #ifdef __DRI_SWAP_BUFFER_COUNTER
2511 if (psc
->counters
!= NULL
)
2512 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2513 divisor
, remainder
);
2516 #ifdef GLX_DIRECT_RENDERING
2517 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2518 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2527 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2528 int64_t target_msc
, int64_t divisor
,
2529 int64_t remainder
, int64_t * ust
,
2530 int64_t * msc
, int64_t * sbc
)
2533 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2534 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2538 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2539 * error", but the return type in the spec is Bool.
2541 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2543 if (divisor
> 0 && remainder
>= divisor
)
2546 #ifdef __DRI_MEDIA_STREAM_COUNTER
2547 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2548 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2549 divisor
, remainder
, msc
, sbc
);
2551 /* __glXGetUST returns zero on success and non-zero on failure.
2552 * This function returns True on success and False on failure.
2554 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2557 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2558 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2568 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2569 int64_t target_sbc
, int64_t * ust
,
2570 int64_t * msc
, int64_t * sbc
)
2573 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2574 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2577 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2578 * error", but the return type in the spec is Bool.
2582 #ifdef __DRI_SWAP_BUFFER_COUNTER
2583 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2585 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2587 /* __glXGetUST returns zero on success and non-zero on failure.
2588 * This function returns True on success and False on failure.
2590 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2593 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2594 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2602 * GLX_MESA_allocate_memory
2607 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2608 size_t size
, float readFreq
,
2609 float writeFreq
, float priority
)
2611 #ifdef __DRI_ALLOCATE
2612 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2614 if (psc
&& psc
->allocate
)
2615 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2616 readFreq
, writeFreq
, priority
);
2625 #endif /* __DRI_ALLOCATE */
2632 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2634 #ifdef __DRI_ALLOCATE
2635 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2637 if (psc
&& psc
->allocate
)
2638 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2644 #endif /* __DRI_ALLOCATE */
2649 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2651 #ifdef __DRI_ALLOCATE
2652 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2654 if (psc
&& psc
->allocate
)
2655 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2661 #endif /* GLX_DIRECT_RENDERING */
2670 * Mesa extension stubs. These will help reduce portability problems.
2675 * Release all buffers associated with the specified GLX drawable.
2678 * This function was intended for stand-alone Mesa. The issue there is that
2679 * the library doesn't get any notification when a window is closed. In
2680 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2681 * supported, there are 3 different functions to destroy a drawable. It
2682 * should be possible to create GLX protocol (or have it determine which
2683 * protocol to use based on the type of the drawable) to have one function
2684 * do the work of 3. For the direct-rendering case, this function could
2685 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2686 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2687 * would need to be used. This really should be done as part of the new DRI
2690 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2691 * __driGarbageCollectDrawables
2692 * glXDestroyGLXPixmap
2693 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2694 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2697 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2706 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2707 Pixmap pixmap
, Colormap cmap
)
2720 * GLX_MESA_copy_sub_buffer
2722 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2724 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2725 int x
, int y
, int width
, int height
)
2727 xGLXVendorPrivateReq
*req
;
2730 CARD32
*drawable_ptr
;
2731 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2734 #ifdef __DRI_COPY_SUB_BUFFER
2736 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2737 if (pdraw
!= NULL
) {
2738 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2739 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2741 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2748 opcode
= __glXSetupForCommand(dpy
);
2753 ** The calling thread may or may not have a current context. If it
2754 ** does, send the context tag so the server can do a flush.
2756 gc
= __glXGetCurrentContext();
2757 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2758 ((drawable
== gc
->currentDrawable
) ||
2759 (drawable
== gc
->currentReadable
))) {
2760 tag
= gc
->currentContextTag
;
2767 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2768 req
->reqType
= opcode
;
2769 req
->glxCode
= X_GLXVendorPrivate
;
2770 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2771 req
->contextTag
= tag
;
2773 drawable_ptr
= (CARD32
*) (req
+ 1);
2774 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2775 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2776 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2777 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2779 *drawable_ptr
= drawable
;
2791 * GLX_EXT_texture_from_pixmap
2795 __glXBindTexImageEXT(Display
* dpy
,
2796 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2798 xGLXVendorPrivateReq
*req
;
2799 GLXContext gc
= __glXGetCurrentContext();
2800 CARD32
*drawable_ptr
;
2802 CARD32
*num_attrib_ptr
;
2812 while (attrib_list
[i
* 2] != None
)
2816 #ifdef GLX_DIRECT_RENDERING
2817 if (gc
->driContext
) {
2818 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2820 if (pdraw
!= NULL
) {
2821 if (pdraw
->psc
->texBuffer
->base
.version
>= 2 &&
2822 pdraw
->psc
->texBuffer
->setTexBuffer2
!= NULL
) {
2823 (*pdraw
->psc
->texBuffer
->setTexBuffer2
) (gc
->__driContext
,
2824 pdraw
->textureTarget
,
2825 pdraw
->textureFormat
,
2826 pdraw
->driDrawable
);
2829 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
2830 pdraw
->textureTarget
,
2831 pdraw
->driDrawable
);
2838 opcode
= __glXSetupForCommand(dpy
);
2843 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2844 req
->reqType
= opcode
;
2845 req
->glxCode
= X_GLXVendorPrivate
;
2846 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2847 req
->contextTag
= gc
->currentContextTag
;
2849 drawable_ptr
= (CARD32
*) (req
+ 1);
2850 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2851 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2852 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2854 *drawable_ptr
= drawable
;
2855 *buffer_ptr
= buffer
;
2856 *num_attrib_ptr
= (CARD32
) i
;
2860 while (attrib_list
[i
* 2] != None
) {
2861 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2862 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2872 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2874 xGLXVendorPrivateReq
*req
;
2875 GLXContext gc
= __glXGetCurrentContext();
2876 CARD32
*drawable_ptr
;
2880 if ((gc
== NULL
) || GC_IS_DIRECT(gc
))
2883 opcode
= __glXSetupForCommand(dpy
);
2888 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2889 req
->reqType
= opcode
;
2890 req
->glxCode
= X_GLXVendorPrivate
;
2891 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2892 req
->contextTag
= gc
->currentContextTag
;
2894 drawable_ptr
= (CARD32
*) (req
+ 1);
2895 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2897 *drawable_ptr
= drawable
;
2898 *buffer_ptr
= buffer
;
2907 * \c strdup is actually not a standard ANSI C or POSIX routine.
2908 * Irix will not define it if ANSI mode is in effect.
2913 __glXstrdup(const char *str
)
2916 copy
= (char *) Xmalloc(strlen(str
) + 1);
2924 ** glXGetProcAddress support
2927 struct name_address_pair
2933 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2934 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2936 static const struct name_address_pair GLX_functions
[] = {
2937 /*** GLX_VERSION_1_0 ***/
2938 GLX_FUNCTION(glXChooseVisual
),
2939 GLX_FUNCTION(glXCopyContext
),
2940 GLX_FUNCTION(glXCreateContext
),
2941 GLX_FUNCTION(glXCreateGLXPixmap
),
2942 GLX_FUNCTION(glXDestroyContext
),
2943 GLX_FUNCTION(glXDestroyGLXPixmap
),
2944 GLX_FUNCTION(glXGetConfig
),
2945 GLX_FUNCTION(glXGetCurrentContext
),
2946 GLX_FUNCTION(glXGetCurrentDrawable
),
2947 GLX_FUNCTION(glXIsDirect
),
2948 GLX_FUNCTION(glXMakeCurrent
),
2949 GLX_FUNCTION(glXQueryExtension
),
2950 GLX_FUNCTION(glXQueryVersion
),
2951 GLX_FUNCTION(glXSwapBuffers
),
2952 GLX_FUNCTION(glXUseXFont
),
2953 GLX_FUNCTION(glXWaitGL
),
2954 GLX_FUNCTION(glXWaitX
),
2956 /*** GLX_VERSION_1_1 ***/
2957 GLX_FUNCTION(glXGetClientString
),
2958 GLX_FUNCTION(glXQueryExtensionsString
),
2959 GLX_FUNCTION(glXQueryServerString
),
2961 /*** GLX_VERSION_1_2 ***/
2962 GLX_FUNCTION(glXGetCurrentDisplay
),
2964 /*** GLX_VERSION_1_3 ***/
2965 GLX_FUNCTION(glXChooseFBConfig
),
2966 GLX_FUNCTION(glXCreateNewContext
),
2967 GLX_FUNCTION(glXCreatePbuffer
),
2968 GLX_FUNCTION(glXCreatePixmap
),
2969 GLX_FUNCTION(glXCreateWindow
),
2970 GLX_FUNCTION(glXDestroyPbuffer
),
2971 GLX_FUNCTION(glXDestroyPixmap
),
2972 GLX_FUNCTION(glXDestroyWindow
),
2973 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2974 GLX_FUNCTION(glXGetFBConfigAttrib
),
2975 GLX_FUNCTION(glXGetFBConfigs
),
2976 GLX_FUNCTION(glXGetSelectedEvent
),
2977 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2978 GLX_FUNCTION(glXMakeContextCurrent
),
2979 GLX_FUNCTION(glXQueryContext
),
2980 GLX_FUNCTION(glXQueryDrawable
),
2981 GLX_FUNCTION(glXSelectEvent
),
2983 /*** GLX_SGI_swap_control ***/
2984 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2986 /*** GLX_SGI_video_sync ***/
2987 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2988 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2990 /*** GLX_SGI_make_current_read ***/
2991 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2992 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2994 /*** GLX_EXT_import_context ***/
2995 GLX_FUNCTION(glXFreeContextEXT
),
2996 GLX_FUNCTION(glXGetContextIDEXT
),
2997 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2998 GLX_FUNCTION(glXImportContextEXT
),
2999 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
3001 /*** GLX_SGIX_fbconfig ***/
3002 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
3003 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
3004 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
3005 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
3006 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
3007 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
3009 /*** GLX_SGIX_pbuffer ***/
3010 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
3011 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
3012 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
3013 GLX_FUNCTION(glXSelectEventSGIX
),
3014 GLX_FUNCTION(glXGetSelectedEventSGIX
),
3016 /*** GLX_SGIX_swap_group ***/
3017 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
3019 /*** GLX_SGIX_swap_barrier ***/
3020 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
3021 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
3023 /*** GLX_MESA_allocate_memory ***/
3024 GLX_FUNCTION(glXAllocateMemoryMESA
),
3025 GLX_FUNCTION(glXFreeMemoryMESA
),
3026 GLX_FUNCTION(glXGetMemoryOffsetMESA
),
3028 /*** GLX_MESA_copy_sub_buffer ***/
3029 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
3031 /*** GLX_MESA_pixmap_colormap ***/
3032 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
3034 /*** GLX_MESA_release_buffers ***/
3035 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
3037 /*** GLX_MESA_swap_control ***/
3038 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
3039 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
3041 /*** GLX_MESA_swap_frame_usage ***/
3042 GLX_FUNCTION2(glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
3043 GLX_FUNCTION2(glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
3044 GLX_FUNCTION2(glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
3045 GLX_FUNCTION2(glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
3047 /*** GLX_ARB_get_proc_address ***/
3048 GLX_FUNCTION(glXGetProcAddressARB
),
3051 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
3053 /*** GLX_OML_sync_control ***/
3054 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
3055 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
3056 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
3057 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
3058 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
3060 /*** GLX_EXT_texture_from_pixmap ***/
3061 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
3062 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
3064 #ifdef GLX_DIRECT_RENDERING
3065 /*** DRI configuration ***/
3066 GLX_FUNCTION(glXGetScreenDriver
),
3067 GLX_FUNCTION(glXGetDriverConfig
),
3070 {NULL
, NULL
} /* end of list */
3074 static const GLvoid
*
3075 get_glx_proc_address(const char *funcName
)
3079 /* try static functions */
3080 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
3081 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
3082 return GLX_functions
[i
].Address
;
3090 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
3091 * \c glXGetProcAddress.
3093 * \param procName Name of a GL or GLX function.
3094 * \returns A pointer to the named function
3096 * \sa glXGetProcAddress
3098 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
3100 typedef void (*gl_function
) (void);
3104 /* Search the table of GLX and internal functions first. If that
3105 * fails and the supplied name could be a valid core GL name, try
3106 * searching the core GL function table. This check is done to prevent
3107 * DRI based drivers from searching the core GL function table for
3108 * internal API functions.
3111 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
3112 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
3113 && (procName
[2] != 'X')) {
3114 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
3121 * Get the address of a named GL function. This is the GLX 1.4 name for
3122 * \c glXGetProcAddressARB.
3124 * \param procName Name of a GL or GLX function.
3125 * \returns A pointer to the named function
3127 * \sa glXGetProcAddressARB
3129 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
3130 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
3131 __attribute__ ((alias("glXGetProcAddressARB")));
3134 return glXGetProcAddressARB(procName
);
3136 #endif /* __GNUC__ */
3139 #ifdef GLX_DIRECT_RENDERING
3141 * Get the unadjusted system time (UST). Currently, the UST is measured in
3142 * microseconds since Epoc. The actual resolution of the UST may vary from
3143 * system to system, and the units may vary from release to release.
3144 * Drivers should not call this function directly. They should instead use
3145 * \c glXGetProcAddress to obtain a pointer to the function.
3147 * \param ust Location to store the 64-bit UST
3148 * \returns Zero on success or a negative errno value on failure.
3150 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3152 * \since Internal API version 20030317.
3155 __glXGetUST(int64_t * ust
)
3163 if (gettimeofday(&tv
, NULL
) == 0) {
3164 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3171 #endif /* GLX_DIRECT_RENDERING */