1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
3 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice including the dates of first publication and
14 * either this permission notice or a reference to
15 * http://oss.sgi.com/projects/FreeB/
16 * shall be included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Except as contained in this notice, the name of Silicon Graphics, Inc.
27 * shall not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization from
29 * Silicon Graphics, Inc.
34 * Client-side GLX interface.
37 #include "glxclient.h"
39 #include "glxextensions.h"
40 #include "glcontextmodes.h"
42 #ifdef GLX_DIRECT_RENDERING
44 #include <X11/extensions/xf86vmode.h>
48 static const char __glXGLXClientVendorName
[] = "SGI";
49 static const char __glXGLXClientVersion
[] = "1.4";
52 /****************************************************************************/
54 #ifdef GLX_DIRECT_RENDERING
56 static Bool windowExistsFlag
;
57 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
59 if (xerr
->error_code
== BadWindow
) {
60 windowExistsFlag
= GL_FALSE
;
66 * Find drawables in the local hash that have been destroyed on the
69 * \param dpy Display to destroy drawables for
70 * \param screen Screen number to destroy drawables for
72 static void GarbageCollectDRIDrawables(Display
*dpy
, __GLXscreenConfigs
*sc
)
75 __GLXDRIdrawable
*pdraw
;
76 XWindowAttributes xwa
;
77 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
79 /* Set no-op error handler so Xlib doesn't bail out if the windows
80 * has alreay been destroyed on the server. */
82 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
84 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1) {
86 windowExistsFlag
= GL_TRUE
;
87 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
88 if (!windowExistsFlag
) {
89 /* Destroy the local drawable data, if the drawable no
90 longer exists in the Xserver */
91 (*pdraw
->destroyDrawable
)(pdraw
);
92 __glxHashDelete(sc
->drawHash
, draw
);
94 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1);
98 XSetErrorHandler(oldXErrorHandler
);
101 extern __GLXDRIdrawable
*
102 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
);
105 * Get the __DRIdrawable for the drawable associated with a GLXContext
107 * \param dpy The display associated with \c drawable.
108 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
109 * \param scrn_num If non-NULL, the drawables screen is stored there
110 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
111 * the drawable is not associated with a direct-rendering context.
113 _X_HIDDEN __GLXDRIdrawable
*
114 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
116 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
117 __GLXDRIdrawable
*pdraw
;
118 const unsigned screen_count
= ScreenCount(dpy
);
120 __GLXscreenConfigs
*psc
;
125 for (i
= 0; i
< screen_count
; i
++) {
126 psc
= &priv
->screenConfigs
[i
];
127 if (psc
->drawHash
== NULL
)
130 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
131 if (scrn_num
!= NULL
)
144 * Get the GLX per-screen data structure associated with a GLX context.
146 * \param dpy Display for which the GLX per-screen information is to be
148 * \param scrn Screen on \c dpy for which the GLX per-screen information is
150 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
151 * specify a valid GLX screen, or NULL otherwise.
153 * \todo Should this function validate that \c scrn is within the screen
154 * number range for \c dpy?
157 static __GLXscreenConfigs
*
158 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
160 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
162 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
167 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
168 __GLXscreenConfigs
** ppsc
)
170 /* Initialize the extension, if needed . This has the added value
171 * of initializing/allocating the display private
175 return GLX_NO_EXTENSION
;
178 *ppriv
= __glXInitialize(dpy
);
179 if ( *ppriv
== NULL
) {
180 return GLX_NO_EXTENSION
;
183 /* Check screen number to see if its valid */
184 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
185 return GLX_BAD_SCREEN
;
188 /* Check to see if the GL is supported on this screen */
189 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
190 if ( (*ppsc
)->configs
== NULL
) {
191 /* No support for GL on this screen regardless of visual */
192 return GLX_BAD_VISUAL
;
200 * Determine if a \c GLXFBConfig supplied by the application is valid.
202 * \param dpy Application supplied \c Display pointer.
203 * \param config Application supplied \c GLXFBConfig.
205 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
206 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
209 static __GLcontextModes
*
210 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
212 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
213 const unsigned num_screens
= ScreenCount(dpy
);
215 const __GLcontextModes
* modes
;
218 if ( priv
!= NULL
) {
219 for ( i
= 0 ; i
< num_screens
; i
++ ) {
220 for ( modes
= priv
->screenConfigs
[i
].configs
222 ; modes
= modes
->next
) {
223 if ( modes
== (__GLcontextModes
*) config
) {
224 return (__GLcontextModes
*) config
;
235 * \todo It should be possible to move the allocate of \c client_state_private
236 * later in the function for direct-rendering contexts. Direct-rendering
237 * contexts don't need to track client state, so they don't need that memory
240 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
241 * function called \c __glXAllocateClientState that allocates the memory and
242 * does all the initialization (including the pixel pack / unpack).
245 GLXContext
AllocateGLXContext( Display
*dpy
)
250 __GLXattribute
*state
;
255 opcode
= __glXSetupForCommand(dpy
);
260 /* Allocate our context record */
261 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
266 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
268 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
274 gc
->client_state_private
= state
;
275 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
276 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
279 ** Create a temporary buffer to hold GLX rendering commands. The size
280 ** of the buffer is selected so that the maximum number of GLX rendering
281 ** commands can fit in a single X packet and still have room in the X
282 ** packet for the GLXRenderReq header.
285 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
286 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
288 Xfree(gc
->client_state_private
);
292 gc
->bufSize
= bufSize
;
294 /* Fill in the new context */
295 gc
->renderMode
= GL_RENDER
;
297 state
->storePack
.alignment
= 4;
298 state
->storeUnpack
.alignment
= 4;
300 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
303 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
304 ** Other code uses the fastImageUnpack bit, but it is never set
307 gc
->fastImageUnpack
= GL_FALSE
;
308 gc
->fillImage
= __glFillImage
;
310 gc
->bufEnd
= gc
->buf
+ bufSize
;
311 gc
->isDirect
= GL_FALSE
;
314 ** Set limit register so that there will be one command per packet
318 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
321 gc
->majorOpcode
= opcode
;
324 ** Constrain the maximum drawing command size allowed to be
325 ** transfered using the X_GLXRender protocol request. First
326 ** constrain by a software limit, then constrain by the protocl
329 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
330 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
332 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
333 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
335 gc
->maxSmallRenderCommandSize
= bufSize
;
341 * Create a new context. Exactly one of \c vis and \c fbconfig should be
344 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
345 * SGIX_fbconfig protocol be used?
346 * \param renderType For FBConfigs, what is the rendering type?
350 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
351 const __GLcontextModes
* const fbconfig
,
352 GLXContext shareList
,
353 Bool allowDirect
, GLXContextID contextID
,
354 Bool use_glx_1_3
, int renderType
)
357 #ifdef GLX_DIRECT_RENDERING
358 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
359 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
365 gc
= AllocateGLXContext(dpy
);
369 if (None
== contextID
) {
370 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
373 #ifdef GLX_DIRECT_RENDERING
374 if (allowDirect
&& psc
->driScreen
) {
375 const __GLcontextModes
* mode
;
377 if (fbconfig
== NULL
) {
378 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
382 error
.errorCode
= BadValue
;
383 error
.resourceID
= vis
->visualid
;
384 error
.sequenceNumber
= dpy
->request
;
385 error
.type
= X_Error
;
386 error
.majorCode
= gc
->majorOpcode
;
387 error
.minorCode
= X_GLXCreateContext
;
388 _XError(dpy
, &error
);
396 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
399 if (gc
->driContext
!= NULL
) {
400 gc
->screen
= mode
->screen
;
403 gc
->isDirect
= GL_TRUE
;
409 if ( fbconfig
== NULL
) {
410 xGLXCreateContextReq
*req
;
412 /* Send the glXCreateContext request */
413 GetReq(GLXCreateContext
,req
);
414 req
->reqType
= gc
->majorOpcode
;
415 req
->glxCode
= X_GLXCreateContext
;
416 req
->context
= gc
->xid
= XAllocID(dpy
);
417 req
->visual
= vis
->visualid
;
418 req
->screen
= vis
->screen
;
419 req
->shareList
= shareList
? shareList
->xid
: None
;
420 #ifdef GLX_DIRECT_RENDERING
421 req
->isDirect
= gc
->driContext
!= NULL
;
426 else if ( use_glx_1_3
) {
427 xGLXCreateNewContextReq
*req
;
429 /* Send the glXCreateNewContext request */
430 GetReq(GLXCreateNewContext
,req
);
431 req
->reqType
= gc
->majorOpcode
;
432 req
->glxCode
= X_GLXCreateNewContext
;
433 req
->context
= gc
->xid
= XAllocID(dpy
);
434 req
->fbconfig
= fbconfig
->fbconfigID
;
435 req
->screen
= fbconfig
->screen
;
436 req
->renderType
= renderType
;
437 req
->shareList
= shareList
? shareList
->xid
: None
;
438 #ifdef GLX_DIRECT_RENDERING
439 req
->isDirect
= gc
->driContext
!= NULL
;
445 xGLXVendorPrivateWithReplyReq
*vpreq
;
446 xGLXCreateContextWithConfigSGIXReq
*req
;
448 /* Send the glXCreateNewContext request */
449 GetReqExtra(GLXVendorPrivateWithReply
,
450 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
451 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
452 req
->reqType
= gc
->majorOpcode
;
453 req
->glxCode
= X_GLXVendorPrivateWithReply
;
454 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
455 req
->context
= gc
->xid
= XAllocID(dpy
);
456 req
->fbconfig
= fbconfig
->fbconfigID
;
457 req
->screen
= fbconfig
->screen
;
458 req
->renderType
= renderType
;
459 req
->shareList
= shareList
? shareList
->xid
: None
;
460 #ifdef GLX_DIRECT_RENDERING
461 req
->isDirect
= gc
->driContext
!= NULL
;
469 gc
->imported
= GL_FALSE
;
473 gc
->imported
= GL_TRUE
;
479 PUBLIC GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*vis
,
480 GLXContext shareList
, Bool allowDirect
)
482 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
486 _X_HIDDEN
void __glXFreeContext(__GLXcontext
*gc
)
488 if (gc
->vendor
) XFree((char *) gc
->vendor
);
489 if (gc
->renderer
) XFree((char *) gc
->renderer
);
490 if (gc
->version
) XFree((char *) gc
->version
);
491 if (gc
->extensions
) XFree((char *) gc
->extensions
);
492 __glFreeAttributeState(gc
);
493 XFree((char *) gc
->buf
);
494 Xfree((char *) gc
->client_state_private
);
500 ** Destroy the named context
503 DestroyContext(Display
*dpy
, GLXContext gc
)
505 xGLXDestroyContextReq
*req
;
510 opcode
= __glXSetupForCommand(dpy
);
511 if (!opcode
|| !gc
) {
517 imported
= gc
->imported
;
520 #ifdef GLX_DIRECT_RENDERING
521 /* Destroy the direct rendering context */
522 if (gc
->driContext
) {
523 (*gc
->driContext
->destroyContext
)(gc
->driContext
, gc
->psc
, dpy
);
524 gc
->driContext
= NULL
;
525 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
529 __glXFreeVertexArrayState(gc
);
531 if (gc
->currentDpy
) {
532 /* Have to free later cuz it's in use now */
535 /* Destroy the handle if not current to anybody */
537 __glXFreeContext(gc
);
542 ** This dpy also created the server side part of the context.
543 ** Send the glXDestroyContext request.
546 GetReq(GLXDestroyContext
,req
);
547 req
->reqType
= opcode
;
548 req
->glxCode
= X_GLXDestroyContext
;
555 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
557 DestroyContext(dpy
, gc
);
561 ** Return the major and minor version #s for the GLX extension
563 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
565 __GLXdisplayPrivate
*priv
;
567 /* Init the extension. This fetches the major and minor version. */
568 priv
= __glXInitialize(dpy
);
569 if (!priv
) return GL_FALSE
;
571 if (major
) *major
= priv
->majorVersion
;
572 if (minor
) *minor
= priv
->minorVersion
;
577 ** Query the existance of the GLX extension
579 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
581 int major_op
, erb
, evb
;
584 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
586 if (errorBase
) *errorBase
= erb
;
587 if (eventBase
) *eventBase
= evb
;
593 ** Put a barrier in the token stream that forces the GL to finish its
594 ** work before X can proceed.
596 PUBLIC
void glXWaitGL(void)
599 GLXContext gc
= __glXGetCurrentContext();
600 Display
*dpy
= gc
->currentDpy
;
604 /* Flush any pending commands out */
605 __glXFlushRenderBuffer(gc
, gc
->pc
);
607 #ifdef GLX_DIRECT_RENDERING
608 if (gc
->driContext
) {
609 /* This bit of ugliness unwraps the glFinish function */
618 /* Send the glXWaitGL request */
620 GetReq(GLXWaitGL
,req
);
621 req
->reqType
= gc
->majorOpcode
;
622 req
->glxCode
= X_GLXWaitGL
;
623 req
->contextTag
= gc
->currentContextTag
;
629 ** Put a barrier in the token stream that forces X to finish its
630 ** work before GL can proceed.
632 PUBLIC
void glXWaitX(void)
635 GLXContext gc
= __glXGetCurrentContext();
636 Display
*dpy
= gc
->currentDpy
;
640 /* Flush any pending commands out */
641 __glXFlushRenderBuffer(gc
, gc
->pc
);
643 #ifdef GLX_DIRECT_RENDERING
644 if (gc
->driContext
) {
651 ** Send the glXWaitX request.
654 GetReq(GLXWaitX
,req
);
655 req
->reqType
= gc
->majorOpcode
;
656 req
->glxCode
= X_GLXWaitX
;
657 req
->contextTag
= gc
->currentContextTag
;
662 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
664 xGLXUseXFontReq
*req
;
665 GLXContext gc
= __glXGetCurrentContext();
666 Display
*dpy
= gc
->currentDpy
;
670 /* Flush any pending commands out */
671 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
673 #ifdef GLX_DIRECT_RENDERING
674 if (gc
->driContext
) {
675 DRI_glXUseXFont(font
, first
, count
, listBase
);
680 /* Send the glXUseFont request */
682 GetReq(GLXUseXFont
,req
);
683 req
->reqType
= gc
->majorOpcode
;
684 req
->glxCode
= X_GLXUseXFont
;
685 req
->contextTag
= gc
->currentContextTag
;
689 req
->listBase
= listBase
;
694 /************************************************************************/
697 ** Copy the source context to the destination context using the
700 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
701 GLXContext dest
, unsigned long mask
)
703 xGLXCopyContextReq
*req
;
704 GLXContext gc
= __glXGetCurrentContext();
708 opcode
= __glXSetupForCommand(dpy
);
713 #ifdef GLX_DIRECT_RENDERING
714 if (gc
->driContext
) {
715 /* NOT_DONE: This does not work yet */
720 ** If the source is the current context, send its tag so that the context
721 ** can be flushed before the copy.
723 if (source
== gc
&& dpy
== gc
->currentDpy
) {
724 tag
= gc
->currentContextTag
;
729 /* Send the glXCopyContext request */
731 GetReq(GLXCopyContext
,req
);
732 req
->reqType
= opcode
;
733 req
->glxCode
= X_GLXCopyContext
;
734 req
->source
= source
? source
->xid
: None
;
735 req
->dest
= dest
? dest
->xid
: None
;
737 req
->contextTag
= tag
;
744 * Determine if a context uses direct rendering.
746 * \param dpy Display where the context was created.
747 * \param contextID ID of the context to be tested.
749 * \returns \c GL_TRUE if the context is direct rendering or not.
751 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
753 xGLXIsDirectReq
*req
;
754 xGLXIsDirectReply reply
;
757 opcode
= __glXSetupForCommand(dpy
);
762 /* Send the glXIsDirect request */
764 GetReq(GLXIsDirect
,req
);
765 req
->reqType
= opcode
;
766 req
->glxCode
= X_GLXIsDirect
;
767 req
->context
= contextID
;
768 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
772 return reply
.isDirect
;
777 * Shouldn't this function \b always return \c GL_FALSE when
778 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
779 * the GLX protocol here at all?
781 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
785 #ifdef GLX_DIRECT_RENDERING
786 } else if (gc
->driContext
) {
790 return __glXIsDirect(dpy
, gc
->xid
);
793 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
796 xGLXCreateGLXPixmapReq
*req
;
800 opcode
= __glXSetupForCommand(dpy
);
805 /* Send the glXCreateGLXPixmap request */
807 GetReq(GLXCreateGLXPixmap
,req
);
808 req
->reqType
= opcode
;
809 req
->glxCode
= X_GLXCreateGLXPixmap
;
810 req
->screen
= vis
->screen
;
811 req
->visual
= vis
->visualid
;
812 req
->pixmap
= pixmap
;
813 req
->glxpixmap
= xid
= XAllocID(dpy
);
820 ** Destroy the named pixmap
822 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
824 xGLXDestroyGLXPixmapReq
*req
;
827 opcode
= __glXSetupForCommand(dpy
);
832 /* Send the glXDestroyGLXPixmap request */
834 GetReq(GLXDestroyGLXPixmap
,req
);
835 req
->reqType
= opcode
;
836 req
->glxCode
= X_GLXDestroyGLXPixmap
;
837 req
->glxpixmap
= glxpixmap
;
842 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
844 xGLXSwapBuffersReq
*req
;
848 #ifdef GLX_DIRECT_RENDERING
849 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
853 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
);
858 opcode
= __glXSetupForCommand(dpy
);
864 ** The calling thread may or may not have a current context. If it
865 ** does, send the context tag so the server can do a flush.
867 gc
= __glXGetCurrentContext();
868 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
869 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
870 tag
= gc
->currentContextTag
;
875 /* Send the glXSwapBuffers request */
877 GetReq(GLXSwapBuffers
,req
);
878 req
->reqType
= opcode
;
879 req
->glxCode
= X_GLXSwapBuffers
;
880 req
->drawable
= drawable
;
881 req
->contextTag
= tag
;
889 ** Return configuration information for the given display, screen and
890 ** visual combination.
892 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
895 __GLXdisplayPrivate
*priv
;
896 __GLXscreenConfigs
*psc
;
897 __GLcontextModes
*modes
;
900 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
901 if ( status
== Success
) {
902 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
904 /* Lookup attribute after first finding a match on the visual */
905 if ( modes
!= NULL
) {
906 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
909 status
= GLX_BAD_VISUAL
;
913 ** If we can't find the config for this visual, this visual is not
914 ** supported by the OpenGL implementation on the server.
916 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
917 *value_return
= GL_FALSE
;
924 /************************************************************************/
927 init_fbconfig_for_chooser( __GLcontextModes
* config
,
928 GLboolean fbconfig_style_tags
)
930 memset( config
, 0, sizeof( __GLcontextModes
) );
931 config
->visualID
= (XID
) GLX_DONT_CARE
;
932 config
->visualType
= GLX_DONT_CARE
;
934 /* glXChooseFBConfig specifies different defaults for these two than
937 if ( fbconfig_style_tags
) {
938 config
->rgbMode
= GL_TRUE
;
939 config
->doubleBufferMode
= GLX_DONT_CARE
;
942 config
->visualRating
= GLX_DONT_CARE
;
943 config
->transparentPixel
= GLX_NONE
;
944 config
->transparentRed
= GLX_DONT_CARE
;
945 config
->transparentGreen
= GLX_DONT_CARE
;
946 config
->transparentBlue
= GLX_DONT_CARE
;
947 config
->transparentAlpha
= GLX_DONT_CARE
;
948 config
->transparentIndex
= GLX_DONT_CARE
;
950 config
->drawableType
= GLX_WINDOW_BIT
;
951 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
952 config
->xRenderable
= GLX_DONT_CARE
;
953 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
955 config
->swapMethod
= GLX_DONT_CARE
;
958 #define MATCH_DONT_CARE( param ) \
960 if ( (a-> param != GLX_DONT_CARE) \
961 && (a-> param != b-> param) ) { \
966 #define MATCH_MINIMUM( param ) \
968 if ( (a-> param != GLX_DONT_CARE) \
969 && (a-> param > b-> param) ) { \
974 #define MATCH_EXACT( param ) \
976 if ( a-> param != b-> param) { \
982 * Determine if two GLXFBConfigs are compatible.
984 * \param a Application specified config to test.
985 * \param b Server specified config to test against \c a.
988 fbconfigs_compatible( const __GLcontextModes
* const a
,
989 const __GLcontextModes
* const b
)
991 MATCH_DONT_CARE( doubleBufferMode
);
992 MATCH_DONT_CARE( visualType
);
993 MATCH_DONT_CARE( visualRating
);
994 MATCH_DONT_CARE( xRenderable
);
995 MATCH_DONT_CARE( fbconfigID
);
996 MATCH_DONT_CARE( swapMethod
);
998 MATCH_MINIMUM( rgbBits
);
999 MATCH_MINIMUM( numAuxBuffers
);
1000 MATCH_MINIMUM( redBits
);
1001 MATCH_MINIMUM( greenBits
);
1002 MATCH_MINIMUM( blueBits
);
1003 MATCH_MINIMUM( alphaBits
);
1004 MATCH_MINIMUM( depthBits
);
1005 MATCH_MINIMUM( stencilBits
);
1006 MATCH_MINIMUM( accumRedBits
);
1007 MATCH_MINIMUM( accumGreenBits
);
1008 MATCH_MINIMUM( accumBlueBits
);
1009 MATCH_MINIMUM( accumAlphaBits
);
1010 MATCH_MINIMUM( sampleBuffers
);
1011 MATCH_MINIMUM( maxPbufferWidth
);
1012 MATCH_MINIMUM( maxPbufferHeight
);
1013 MATCH_MINIMUM( maxPbufferPixels
);
1014 MATCH_MINIMUM( samples
);
1016 MATCH_DONT_CARE( stereoMode
);
1017 MATCH_EXACT( level
);
1019 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1020 || ((a
->renderType
& b
->renderType
) == 0) ) {
1025 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1026 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1027 * Technically speaking, it is a bug in the DDX driver, but there is
1028 * enough of an installed base to work around the problem here. In any
1029 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1030 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1031 * 0 from the server to be a match to maintain backward compatibility with
1032 * the (broken) drivers.
1035 if ( a
->transparentPixel
!= GLX_DONT_CARE
1036 && a
->transparentPixel
!= 0 ) {
1037 if ( a
->transparentPixel
== GLX_NONE
) {
1038 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1041 MATCH_EXACT( transparentPixel
);
1044 switch ( a
->transparentPixel
) {
1045 case GLX_TRANSPARENT_RGB
:
1046 MATCH_DONT_CARE( transparentRed
);
1047 MATCH_DONT_CARE( transparentGreen
);
1048 MATCH_DONT_CARE( transparentBlue
);
1049 MATCH_DONT_CARE( transparentAlpha
);
1052 case GLX_TRANSPARENT_INDEX
:
1053 MATCH_DONT_CARE( transparentIndex
);
1065 /* There's some trickly language in the GLX spec about how this is supposed
1066 * to work. Basically, if a given component size is either not specified
1067 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1068 * Well, that's really hard to do with the code as-is. This behavior is
1069 * closer to correct, but still not technically right.
1071 #define PREFER_LARGER_OR_ZERO(comp) \
1073 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1074 if ( ((*a)-> comp) == 0 ) { \
1077 else if ( ((*b)-> comp) == 0 ) { \
1081 return ((*b)-> comp) - ((*a)-> comp) ; \
1086 #define PREFER_LARGER(comp) \
1088 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1089 return ((*b)-> comp) - ((*a)-> comp) ; \
1093 #define PREFER_SMALLER(comp) \
1095 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1096 return ((*a)-> comp) - ((*b)-> comp) ; \
1101 * Compare two GLXFBConfigs. This function is intended to be used as the
1102 * compare function passed in to qsort.
1104 * \returns If \c a is a "better" config, according to the specification of
1105 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1106 * better, then a number greater than zero is return. If both are
1107 * equal, zero is returned.
1108 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1111 fbconfig_compare( const __GLcontextModes
* const * const a
,
1112 const __GLcontextModes
* const * const b
)
1114 /* The order of these comparisons must NOT change. It is defined by
1115 * the GLX 1.3 spec and ARB_multisample.
1118 PREFER_SMALLER( visualSelectGroup
);
1120 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1121 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1122 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1124 PREFER_SMALLER( visualRating
);
1126 /* This isn't quite right. It is supposed to compare the sum of the
1127 * components the user specifically set minimums for.
1129 PREFER_LARGER_OR_ZERO( redBits
);
1130 PREFER_LARGER_OR_ZERO( greenBits
);
1131 PREFER_LARGER_OR_ZERO( blueBits
);
1132 PREFER_LARGER_OR_ZERO( alphaBits
);
1134 PREFER_SMALLER( rgbBits
);
1136 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1137 /* Prefer single-buffer.
1139 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1142 PREFER_SMALLER( numAuxBuffers
);
1144 PREFER_LARGER_OR_ZERO( depthBits
);
1145 PREFER_SMALLER( stencilBits
);
1147 /* This isn't quite right. It is supposed to compare the sum of the
1148 * components the user specifically set minimums for.
1150 PREFER_LARGER_OR_ZERO( accumRedBits
);
1151 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1152 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1153 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1155 PREFER_SMALLER( visualType
);
1157 /* None of the multisample specs say where this comparison should happen,
1158 * so I put it near the end.
1160 PREFER_SMALLER( sampleBuffers
);
1161 PREFER_SMALLER( samples
);
1163 /* None of the pbuffer or fbconfig specs say that this comparison needs
1164 * to happen at all, but it seems like it should.
1166 PREFER_LARGER( maxPbufferWidth
);
1167 PREFER_LARGER( maxPbufferHeight
);
1168 PREFER_LARGER( maxPbufferPixels
);
1175 * Selects and sorts a subset of the supplied configs based on the attributes.
1176 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1177 * and \c glXChooseFBConfigSGIX.
1179 * \param configs Array of pointers to possible configs. The elements of
1180 * this array that do not meet the criteria will be set to
1181 * NULL. The remaining elements will be sorted according to
1182 * the various visual / FBConfig selection rules.
1183 * \param num_configs Number of elements in the \c configs array.
1184 * \param attribList Attributes used select from \c configs. This array is
1185 * terminated by a \c None tag. The array can either take
1186 * the form expected by \c glXChooseVisual (where boolean
1187 * tags do not have a value) or by \c glXChooseFBConfig
1188 * (where every tag has a value).
1189 * \param fbconfig_style_tags Selects whether \c attribList is in
1190 * \c glXChooseVisual style or
1191 * \c glXChooseFBConfig style.
1192 * \returns The number of valid elements left in \c configs.
1194 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1197 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1198 const int *attribList
, GLboolean fbconfig_style_tags
)
1200 __GLcontextModes test_config
;
1204 /* This is a fairly direct implementation of the selection method
1205 * described by GLX_SGIX_fbconfig. Start by culling out all the
1206 * configs that are not compatible with the selected parameter
1210 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1211 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1212 (const INT32
*) attribList
,
1213 GL_TRUE
, fbconfig_style_tags
);
1216 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1217 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1218 configs
[ base
] = configs
[ i
];
1227 if ( base
< num_configs
) {
1228 (void) memset( & configs
[ base
], 0,
1229 sizeof( void * ) * (num_configs
- base
) );
1232 /* After the incompatible configs are removed, the resulting
1233 * list is sorted according to the rules set out in the various
1237 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1238 (int (*)(const void*, const void*)) fbconfig_compare
);
1246 ** Return the visual that best matches the template. Return None if no
1247 ** visual matches the template.
1249 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1251 XVisualInfo
*visualList
= NULL
;
1252 __GLXdisplayPrivate
*priv
;
1253 __GLXscreenConfigs
*psc
;
1254 __GLcontextModes test_config
;
1255 __GLcontextModes
*modes
;
1256 const __GLcontextModes
*best_config
= NULL
;
1259 ** Get a list of all visuals, return if list is empty
1261 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1267 ** Build a template from the defaults and the attribute list
1268 ** Free visual list and return if an unexpected token is encountered
1270 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1271 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1272 (const INT32
*) attribList
,
1273 GL_TRUE
, GL_FALSE
);
1276 ** Eliminate visuals that don't meet minimum requirements
1277 ** Compute a score for those that do
1278 ** Remember which visual, if any, got the highest score
1280 for ( modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1281 if ( fbconfigs_compatible( & test_config
, modes
)
1282 && ((best_config
== NULL
)
1283 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1284 best_config
= modes
;
1289 ** If no visual is acceptable, return None
1290 ** Otherwise, create an XVisualInfo list with just the selected X visual
1293 if (best_config
!= NULL
) {
1294 XVisualInfo visualTemplate
;
1297 visualTemplate
.screen
= screen
;
1298 visualTemplate
.visualid
= best_config
->visualID
;
1299 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1300 &visualTemplate
, &i
);
1307 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1309 __GLXscreenConfigs
*psc
;
1310 __GLXdisplayPrivate
*priv
;
1312 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1316 if (!psc
->effectiveGLXexts
) {
1317 if (!psc
->serverGLXexts
) {
1318 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1319 X_GLXQueryServerString
,
1320 screen
, GLX_EXTENSIONS
);
1323 __glXCalculateUsableExtensions(psc
,
1324 #ifdef GLX_DIRECT_RENDERING
1325 (psc
->driScreen
!= NULL
),
1329 priv
->minorVersion
);
1332 return psc
->effectiveGLXexts
;
1335 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1339 return (__glXGLXClientVendorName
);
1341 return (__glXGLXClientVersion
);
1342 case GLX_EXTENSIONS
:
1343 return (__glXGetClientExtensions());
1349 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1351 __GLXscreenConfigs
*psc
;
1352 __GLXdisplayPrivate
*priv
;
1356 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1362 str
= & priv
->serverGLXvendor
;
1365 str
= & priv
->serverGLXversion
;
1367 case GLX_EXTENSIONS
:
1368 str
= & psc
->serverGLXexts
;
1374 if ( *str
== NULL
) {
1375 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1376 X_GLXQueryServerString
, screen
, name
);
1382 void __glXClientInfo ( Display
*dpy
, int opcode
)
1384 xGLXClientInfoReq
*req
;
1386 char * ext_str
= __glXGetClientGLExtensionString();
1388 /* Send the glXClientInfo request */
1390 GetReq(GLXClientInfo
,req
);
1391 req
->reqType
= opcode
;
1392 req
->glxCode
= X_GLXClientInfo
;
1393 req
->major
= GLX_MAJOR_VERSION
;
1394 req
->minor
= GLX_MINOR_VERSION
;
1396 size
= strlen( ext_str
) + 1;
1397 req
->length
+= (size
+ 3) >> 2;
1398 req
->numbytes
= size
;
1399 Data(dpy
, ext_str
, size
);
1409 ** EXT_import_context
1412 PUBLIC Display
*glXGetCurrentDisplay(void)
1414 GLXContext gc
= __glXGetCurrentContext();
1415 if (NULL
== gc
) return NULL
;
1416 return gc
->currentDpy
;
1419 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1420 glXGetCurrentDisplay
)
1423 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1426 * \param dpy Display where \c ctx was created.
1427 * \param ctx Context to query.
1428 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1429 * or zero if the request failed due to internal problems (i.e.,
1430 * unable to allocate temporary memory, etc.)
1433 * This function dynamically determines whether to use the EXT_import_context
1434 * version of the protocol or the GLX 1.3 version of the protocol.
1436 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1438 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1439 xGLXQueryContextReply reply
;
1445 return GLX_BAD_CONTEXT
;
1447 opcode
= __glXSetupForCommand(dpy
);
1452 /* Send the glXQueryContextInfoEXT request */
1455 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1456 xGLXQueryContextReq
*req
;
1458 GetReq(GLXQueryContext
, req
);
1460 req
->reqType
= opcode
;
1461 req
->glxCode
= X_GLXQueryContext
;
1462 req
->context
= (unsigned int)(ctx
->xid
);
1465 xGLXVendorPrivateReq
*vpreq
;
1466 xGLXQueryContextInfoEXTReq
*req
;
1468 GetReqExtra( GLXVendorPrivate
,
1469 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1471 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1472 req
->reqType
= opcode
;
1473 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1474 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1475 req
->context
= (unsigned int)(ctx
->xid
);
1478 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1480 numValues
= reply
.n
;
1483 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1487 int *propList
, *pProp
;
1491 nPropListBytes
= numValues
<< 3;
1492 propList
= (int *) Xmalloc(nPropListBytes
);
1493 if (NULL
== propList
) {
1496 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1498 for (i
=0; i
< numValues
; i
++) {
1500 case GLX_SHARE_CONTEXT_EXT
:
1501 ctx
->share_xid
= *pProp
++;
1503 case GLX_VISUAL_ID_EXT
:
1505 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1508 ctx
->screen
= *pProp
++;
1510 case GLX_FBCONFIG_ID
:
1512 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
, *pProp
++);
1514 case GLX_RENDER_TYPE
:
1515 ctx
->renderType
= *pProp
++;
1522 Xfree((char *)propList
);
1532 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1536 /* get the information from the server if we don't have it already */
1537 #ifdef GLX_DIRECT_RENDERING
1538 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1540 if (ctx
->mode
== NULL
) {
1542 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1543 if (Success
!= retVal
) return retVal
;
1545 switch (attribute
) {
1546 case GLX_SHARE_CONTEXT_EXT
:
1547 *value
= (int)(ctx
->share_xid
);
1549 case GLX_VISUAL_ID_EXT
:
1550 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1553 *value
= (int)(ctx
->screen
);
1555 case GLX_FBCONFIG_ID
:
1556 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1558 case GLX_RENDER_TYPE
:
1559 *value
= (int)(ctx
->renderType
);
1562 return GLX_BAD_ATTRIBUTE
;
1567 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1568 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1569 (dpy
, ctx
, attribute
, value
),
1572 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1577 PUBLIC GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1581 if (contextID
== None
) {
1584 if (__glXIsDirect(dpy
, contextID
)) {
1588 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1590 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1597 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1599 DestroyContext(dpy
, ctx
);
1605 * GLX 1.3 functions - these are just stubs for now!
1608 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1609 const int *attribList
, int *nitems
)
1611 __GLcontextModes
** config_list
;
1615 config_list
= (__GLcontextModes
**)
1616 glXGetFBConfigs( dpy
, screen
, & list_size
);
1618 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1619 list_size
= choose_visual( config_list
, list_size
, attribList
,
1621 if ( list_size
== 0 ) {
1622 XFree( config_list
);
1627 *nitems
= list_size
;
1628 return (GLXFBConfig
*) config_list
;
1632 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1633 int renderType
, GLXContext shareList
,
1636 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1637 allowDirect
, None
, True
, renderType
);
1641 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1643 GLXContext gc
= __glXGetCurrentContext();
1644 return gc
->currentReadable
;
1648 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1650 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1651 __GLcontextModes
** config
= NULL
;
1655 if ( (priv
->screenConfigs
!= NULL
)
1656 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1657 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1658 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1659 unsigned num_configs
= 0;
1660 __GLcontextModes
* modes
;
1663 for ( modes
= priv
->screenConfigs
[screen
].configs
1665 ; modes
= modes
->next
) {
1666 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1671 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1673 if ( config
!= NULL
) {
1674 *nelements
= num_configs
;
1676 for ( modes
= priv
->screenConfigs
[screen
].configs
1678 ; modes
= modes
->next
) {
1679 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1686 return (GLXFBConfig
*) config
;
1690 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1691 int attribute
, int *value
)
1693 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1695 return (modes
!= NULL
)
1696 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1701 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1703 XVisualInfo visualTemplate
;
1704 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1708 ** Get a list of all visuals, return if list is empty
1710 visualTemplate
.visualid
= fbconfig
->visualID
;
1711 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1716 ** GLX_SGI_swap_control
1718 static int __glXSwapIntervalSGI(int interval
)
1720 xGLXVendorPrivateReq
*req
;
1721 GLXContext gc
= __glXGetCurrentContext();
1723 CARD32
* interval_ptr
;
1727 return GLX_BAD_CONTEXT
;
1730 if ( interval
<= 0 ) {
1731 return GLX_BAD_VALUE
;
1734 #ifdef __DRI_SWAP_CONTROL
1735 if (gc
->driContext
) {
1736 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1738 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1739 gc
->currentDrawable
,
1741 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1742 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1746 return GLX_BAD_CONTEXT
;
1750 dpy
= gc
->currentDpy
;
1751 opcode
= __glXSetupForCommand(dpy
);
1756 /* Send the glXSwapIntervalSGI request */
1758 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1759 req
->reqType
= opcode
;
1760 req
->glxCode
= X_GLXVendorPrivate
;
1761 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1762 req
->contextTag
= gc
->currentContextTag
;
1764 interval_ptr
= (CARD32
*) (req
+ 1);
1765 *interval_ptr
= interval
;
1776 ** GLX_MESA_swap_control
1778 static int __glXSwapIntervalMESA(unsigned int interval
)
1780 #ifdef __DRI_SWAP_CONTROL
1781 GLXContext gc
= __glXGetCurrentContext();
1783 if ( interval
< 0 ) {
1784 return GLX_BAD_VALUE
;
1787 if (gc
!= NULL
&& gc
->driContext
) {
1788 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1791 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1792 __GLXDRIdrawable
*pdraw
=
1793 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1794 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1795 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1804 return GLX_BAD_CONTEXT
;
1808 static int __glXGetSwapIntervalMESA(void)
1810 #ifdef __DRI_SWAP_CONTROL
1811 GLXContext gc
= __glXGetCurrentContext();
1813 if (gc
!= NULL
&& gc
->driContext
) {
1814 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1817 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1818 __GLXDRIdrawable
*pdraw
=
1819 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1820 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1821 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
1832 ** GLX_MESA_swap_frame_usage
1835 static GLint
__glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1837 int status
= GLX_BAD_CONTEXT
;
1838 #ifdef __DRI_FRAME_TRACKING
1840 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1841 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1843 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1844 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
1853 static GLint
__glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1855 int status
= GLX_BAD_CONTEXT
;
1856 #ifdef __DRI_FRAME_TRACKING
1858 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1859 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
1861 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1862 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
1872 static GLint
__glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1875 int status
= GLX_BAD_CONTEXT
;
1876 #ifdef __DRI_FRAME_TRACKING
1878 __GLXDRIdrawable
* const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1879 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1881 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1882 int64_t sbc
, missedFrames
;
1883 float lastMissedUsage
;
1885 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1900 static GLint
__glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1901 int64_t *sbc
, int64_t *missedFrames
,
1902 GLfloat
*lastMissedUsage
)
1904 int status
= GLX_BAD_CONTEXT
;
1905 #ifdef __DRI_FRAME_TRACKING
1907 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1908 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1910 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1913 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1915 lastMissedUsage
, &usage
);
1921 (void) missedFrames
;
1922 (void) lastMissedUsage
;
1929 ** GLX_SGI_video_sync
1931 static int __glXGetVideoSyncSGI(unsigned int *count
)
1933 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1934 * FIXME: there should be a GLX encoding for this call. I can find no
1935 * FIXME: documentation for the GLX encoding.
1937 #ifdef __DRI_MEDIA_STREAM_COUNTER
1938 GLXContext gc
= __glXGetCurrentContext();
1941 if (gc
!= NULL
&& gc
->driContext
) {
1942 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1944 if ( psc
->msc
&& psc
->driScreen
) {
1945 __GLXDRIdrawable
*pdraw
=
1946 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1950 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
1951 pdraw
->driDrawable
, &temp
);
1952 *count
= (unsigned) temp
;
1954 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1960 return GLX_BAD_CONTEXT
;
1963 static int __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1965 #ifdef __DRI_MEDIA_STREAM_COUNTER
1966 GLXContext gc
= __glXGetCurrentContext();
1968 if ( divisor
<= 0 || remainder
< 0 )
1969 return GLX_BAD_VALUE
;
1971 if (gc
!= NULL
&& gc
->driContext
) {
1972 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1974 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
1975 __GLXDRIdrawable
*pdraw
=
1976 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1981 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
1982 divisor
, remainder
, &msc
, &sbc
);
1983 *count
= (unsigned) msc
;
1984 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1990 return GLX_BAD_CONTEXT
;
1995 ** GLX_SGIX_fbconfig
1996 ** Many of these functions are aliased to GLX 1.3 entry points in the
1997 ** GLX_functions table.
2000 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2001 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2002 (dpy
, config
, attribute
, value
),
2003 glXGetFBConfigAttrib
)
2005 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2006 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2007 (dpy
, screen
, attrib_list
, nelements
),
2010 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2011 (Display
* dpy
, GLXFBConfigSGIX config
),
2013 glXGetVisualFromFBConfig
)
2015 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
2016 GLXFBConfigSGIX config
, Pixmap pixmap
)
2018 xGLXVendorPrivateWithReplyReq
*vpreq
;
2019 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2020 GLXPixmap xid
= None
;
2022 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2023 __GLXscreenConfigs
* psc
;
2026 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2030 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2032 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2033 opcode
= __glXSetupForCommand(dpy
);
2038 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2040 GetReqExtra(GLXVendorPrivateWithReply
,
2041 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2042 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2043 req
->reqType
= opcode
;
2044 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2045 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2046 req
->screen
= fbconfig
->screen
;
2047 req
->fbconfig
= fbconfig
->fbconfigID
;
2048 req
->pixmap
= pixmap
;
2049 req
->glxpixmap
= xid
= XAllocID(dpy
);
2057 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2058 GLXFBConfigSGIX config
, int renderType
,
2059 GLXContext shareList
, Bool allowDirect
)
2061 GLXContext gc
= NULL
;
2062 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2063 __GLXscreenConfigs
* psc
;
2066 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2070 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2072 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2073 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2074 allowDirect
, None
, False
, renderType
);
2081 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2084 __GLXdisplayPrivate
*priv
;
2085 __GLXscreenConfigs
*psc
;
2087 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2088 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2089 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2090 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2099 ** GLX_SGIX_swap_group
2101 static void __glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2111 ** GLX_SGIX_swap_barrier
2113 static void __glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2121 static Bool
__glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2131 ** GLX_OML_sync_control
2133 static Bool
__glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2134 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2136 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2137 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2139 if ( priv
!= NULL
) {
2141 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2142 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2144 assert( (pdraw
== NULL
) || (i
!= -1) );
2145 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2146 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2147 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2148 && (__glXGetUST(ust
) == 0) );
2160 #ifdef GLX_DIRECT_RENDERING
2162 __driGetMscRateOML(__DRIdrawable
*draw
,
2163 int32_t *numerator
, int32_t *denominator
, void *private)
2166 __GLXscreenConfigs
*psc
;
2167 XF86VidModeModeLine mode_line
;
2170 __GLXDRIdrawable
*glxDraw
= private;
2173 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2174 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
) ) {
2175 unsigned n
= dot_clock
* 1000;
2176 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2178 # define V_INTERLACE 0x010
2179 # define V_DBLSCAN 0x020
2181 if (mode_line
.flags
& V_INTERLACE
)
2183 else if (mode_line
.flags
& V_DBLSCAN
)
2186 /* The OML_sync_control spec requires that if the refresh rate is a
2187 * whole number, that the returned numerator be equal to the refresh
2188 * rate and the denominator be 1.
2196 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2198 /* This is a poor man's way to reduce a fraction. It's far from
2199 * perfect, but it will work well enough for this situation.
2202 for (i
= 0; f
[i
] != 0; i
++) {
2203 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2224 * Determine the refresh rate of the specified drawable and display.
2226 * \param dpy Display whose refresh rate is to be determined.
2227 * \param drawable Drawable whose refresh rate is to be determined.
2228 * \param numerator Numerator of the refresh rate.
2229 * \param demoninator Denominator of the refresh rate.
2230 * \return If the refresh rate for the specified display and drawable could
2231 * be calculated, True is returned. Otherwise False is returned.
2233 * \note This function is implemented entirely client-side. A lot of other
2234 * functionality is required to export GLX_OML_sync_control, so on
2235 * XFree86 this function can be called for direct-rendering contexts
2236 * when GLX_OML_sync_control appears in the client extension string.
2239 _X_HIDDEN GLboolean
__glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2240 int32_t * numerator
,
2241 int32_t * denominator
)
2243 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2244 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2249 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2260 static int64_t __glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2261 int64_t target_msc
, int64_t divisor
,
2264 #ifdef __DRI_SWAP_BUFFER_COUNTER
2266 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2267 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2269 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2270 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2271 * of -1 if the function failed because of errors detected in the input
2274 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2276 if ( divisor
> 0 && remainder
>= divisor
)
2279 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2280 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2281 divisor
, remainder
);
2294 static Bool
__glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2295 int64_t target_msc
, int64_t divisor
,
2296 int64_t remainder
, int64_t *ust
,
2297 int64_t *msc
, int64_t *sbc
)
2299 #ifdef __DRI_MEDIA_STREAM_COUNTER
2301 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2302 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2305 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2306 * error", but the return type in the spec is Bool.
2308 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2310 if ( divisor
> 0 && remainder
>= divisor
)
2313 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2314 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, target_msc
,
2315 divisor
, remainder
, msc
, sbc
);
2317 /* __glXGetUST returns zero on success and non-zero on failure.
2318 * This function returns True on success and False on failure.
2320 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2336 static Bool
__glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2337 int64_t target_sbc
, int64_t *ust
,
2338 int64_t *msc
, int64_t *sbc
)
2340 #ifdef __DRI_SWAP_BUFFER_COUNTER
2342 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2343 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2346 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2347 * error", but the return type in the spec is Bool.
2349 if ( target_sbc
< 0 )
2352 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2353 ret
= (*psc
->sbc
->waitForSBC
)(pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2355 /* __glXGetUST returns zero on success and non-zero on failure.
2356 * This function returns True on success and False on failure.
2358 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2373 * GLX_MESA_allocate_memory
2377 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2378 size_t size
, float readFreq
,
2379 float writeFreq
, float priority
)
2381 #ifdef __DRI_ALLOCATE
2382 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2384 if (psc
&& psc
->allocate
)
2385 return (*psc
->allocate
->allocateMemory
)(psc
->__driScreen
, size
,
2386 readFreq
, writeFreq
, priority
);
2395 #endif /* GLX_DIRECT_RENDERING */
2401 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2403 #ifdef __DRI_ALLOCATE
2404 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2406 if (psc
&& psc
->allocate
)
2407 (*psc
->allocate
->freeMemory
)(psc
->__driScreen
, pointer
);
2413 #endif /* GLX_DIRECT_RENDERING */
2417 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2418 const void *pointer
)
2420 #ifdef __DRI_ALLOCATE
2421 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2423 if (psc
&& psc
->allocate
)
2424 return (*psc
->allocate
->memoryOffset
)(psc
->__driScreen
, pointer
);
2430 #endif /* GLX_DIRECT_RENDERING */
2438 * Mesa extension stubs. These will help reduce portability problems.
2443 * Release all buffers associated with the specified GLX drawable.
2446 * This function was intended for stand-alone Mesa. The issue there is that
2447 * the library doesn't get any notification when a window is closed. In
2448 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2449 * supported, there are 3 different functions to destroy a drawable. It
2450 * should be possible to create GLX protocol (or have it determine which
2451 * protocol to use based on the type of the drawable) to have one function
2452 * do the work of 3. For the direct-rendering case, this function could
2453 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2454 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2455 * would need to be used. This really should be done as part of the new DRI
2458 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2459 * __driGarbageCollectDrawables
2460 * glXDestroyGLXPixmap
2461 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2462 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2464 static Bool
__glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2472 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2473 Pixmap pixmap
, Colormap cmap
)
2485 * GLX_MESA_copy_sub_buffer
2487 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2488 static void __glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2489 int x
, int y
, int width
, int height
)
2491 xGLXVendorPrivateReq
*req
;
2494 CARD32
*drawable_ptr
;
2495 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2498 #ifdef __DRI_COPY_SUB_BUFFER
2500 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2501 if ( pdraw
!= NULL
) {
2502 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
2503 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2504 (*psc
->driScreen
->copySubBuffer
)(pdraw
, x
, y
, width
, height
);
2511 opcode
= __glXSetupForCommand(dpy
);
2516 ** The calling thread may or may not have a current context. If it
2517 ** does, send the context tag so the server can do a flush.
2519 gc
= __glXGetCurrentContext();
2520 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2521 ((drawable
== gc
->currentDrawable
) ||
2522 (drawable
== gc
->currentReadable
)) ) {
2523 tag
= gc
->currentContextTag
;
2529 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4,req
);
2530 req
->reqType
= opcode
;
2531 req
->glxCode
= X_GLXVendorPrivate
;
2532 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2533 req
->contextTag
= tag
;
2535 drawable_ptr
= (CARD32
*) (req
+ 1);
2536 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2537 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2538 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2539 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2541 *drawable_ptr
= drawable
;
2553 * GLX_EXT_texture_from_pixmap
2556 static void __glXBindTexImageEXT(Display
*dpy
,
2557 GLXDrawable drawable
,
2559 const int *attrib_list
)
2561 xGLXVendorPrivateReq
*req
;
2562 GLXContext gc
= __glXGetCurrentContext();
2563 CARD32
*drawable_ptr
;
2565 CARD32
*num_attrib_ptr
;
2575 while (attrib_list
[i
* 2] != None
)
2579 #ifdef GLX_DIRECT_RENDERING
2580 if (gc
->driContext
) {
2581 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2584 (*pdraw
->psc
->texBuffer
->setTexBuffer
)(gc
->__driContext
,
2585 pdraw
->textureTarget
,
2586 pdraw
->driDrawable
);
2592 opcode
= __glXSetupForCommand(dpy
);
2597 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
,req
);
2598 req
->reqType
= opcode
;
2599 req
->glxCode
= X_GLXVendorPrivate
;
2600 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2601 req
->contextTag
= gc
->currentContextTag
;
2603 drawable_ptr
= (CARD32
*) (req
+ 1);
2604 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2605 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2606 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2608 *drawable_ptr
= drawable
;
2609 *buffer_ptr
= buffer
;
2610 *num_attrib_ptr
= (CARD32
) i
;
2614 while (attrib_list
[i
* 2] != None
)
2616 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2617 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2626 static void __glXReleaseTexImageEXT(Display
*dpy
,
2627 GLXDrawable drawable
,
2630 xGLXVendorPrivateReq
*req
;
2631 GLXContext gc
= __glXGetCurrentContext();
2632 CARD32
*drawable_ptr
;
2639 #ifdef GLX_DIRECT_RENDERING
2644 opcode
= __glXSetupForCommand(dpy
);
2649 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
)+sizeof(INT32
),req
);
2650 req
->reqType
= opcode
;
2651 req
->glxCode
= X_GLXVendorPrivate
;
2652 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2653 req
->contextTag
= gc
->currentContextTag
;
2655 drawable_ptr
= (CARD32
*) (req
+ 1);
2656 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2658 *drawable_ptr
= drawable
;
2659 *buffer_ptr
= buffer
;
2667 * \c strdup is actually not a standard ANSI C or POSIX routine.
2668 * Irix will not define it if ANSI mode is in effect.
2673 __glXstrdup(const char *str
)
2676 copy
= (char *) Xmalloc(strlen(str
) + 1);
2684 ** glXGetProcAddress support
2687 struct name_address_pair
{
2692 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2693 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2695 static const struct name_address_pair GLX_functions
[] = {
2696 /*** GLX_VERSION_1_0 ***/
2697 GLX_FUNCTION( glXChooseVisual
),
2698 GLX_FUNCTION( glXCopyContext
),
2699 GLX_FUNCTION( glXCreateContext
),
2700 GLX_FUNCTION( glXCreateGLXPixmap
),
2701 GLX_FUNCTION( glXDestroyContext
),
2702 GLX_FUNCTION( glXDestroyGLXPixmap
),
2703 GLX_FUNCTION( glXGetConfig
),
2704 GLX_FUNCTION( glXGetCurrentContext
),
2705 GLX_FUNCTION( glXGetCurrentDrawable
),
2706 GLX_FUNCTION( glXIsDirect
),
2707 GLX_FUNCTION( glXMakeCurrent
),
2708 GLX_FUNCTION( glXQueryExtension
),
2709 GLX_FUNCTION( glXQueryVersion
),
2710 GLX_FUNCTION( glXSwapBuffers
),
2711 GLX_FUNCTION( glXUseXFont
),
2712 GLX_FUNCTION( glXWaitGL
),
2713 GLX_FUNCTION( glXWaitX
),
2715 /*** GLX_VERSION_1_1 ***/
2716 GLX_FUNCTION( glXGetClientString
),
2717 GLX_FUNCTION( glXQueryExtensionsString
),
2718 GLX_FUNCTION( glXQueryServerString
),
2720 /*** GLX_VERSION_1_2 ***/
2721 GLX_FUNCTION( glXGetCurrentDisplay
),
2723 /*** GLX_VERSION_1_3 ***/
2724 GLX_FUNCTION( glXChooseFBConfig
),
2725 GLX_FUNCTION( glXCreateNewContext
),
2726 GLX_FUNCTION( glXCreatePbuffer
),
2727 GLX_FUNCTION( glXCreatePixmap
),
2728 GLX_FUNCTION( glXCreateWindow
),
2729 GLX_FUNCTION( glXDestroyPbuffer
),
2730 GLX_FUNCTION( glXDestroyPixmap
),
2731 GLX_FUNCTION( glXDestroyWindow
),
2732 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2733 GLX_FUNCTION( glXGetFBConfigAttrib
),
2734 GLX_FUNCTION( glXGetFBConfigs
),
2735 GLX_FUNCTION( glXGetSelectedEvent
),
2736 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2737 GLX_FUNCTION( glXMakeContextCurrent
),
2738 GLX_FUNCTION( glXQueryContext
),
2739 GLX_FUNCTION( glXQueryDrawable
),
2740 GLX_FUNCTION( glXSelectEvent
),
2742 /*** GLX_SGI_swap_control ***/
2743 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2745 /*** GLX_SGI_video_sync ***/
2746 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2747 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2749 /*** GLX_SGI_make_current_read ***/
2750 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2751 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2753 /*** GLX_EXT_import_context ***/
2754 GLX_FUNCTION( glXFreeContextEXT
),
2755 GLX_FUNCTION( glXGetContextIDEXT
),
2756 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2757 GLX_FUNCTION( glXImportContextEXT
),
2758 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2760 /*** GLX_SGIX_fbconfig ***/
2761 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2762 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2763 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2764 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2765 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2766 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2768 /*** GLX_SGIX_pbuffer ***/
2769 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2770 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2771 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2772 GLX_FUNCTION( glXSelectEventSGIX
),
2773 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2775 /*** GLX_SGIX_swap_group ***/
2776 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2778 /*** GLX_SGIX_swap_barrier ***/
2779 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2780 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2782 /*** GLX_MESA_allocate_memory ***/
2783 GLX_FUNCTION( glXAllocateMemoryMESA
),
2784 GLX_FUNCTION( glXFreeMemoryMESA
),
2785 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2787 /*** GLX_MESA_copy_sub_buffer ***/
2788 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2790 /*** GLX_MESA_pixmap_colormap ***/
2791 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2793 /*** GLX_MESA_release_buffers ***/
2794 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2796 /*** GLX_MESA_swap_control ***/
2797 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2798 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2800 /*** GLX_MESA_swap_frame_usage ***/
2801 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2802 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2803 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2804 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2806 /*** GLX_ARB_get_proc_address ***/
2807 GLX_FUNCTION( glXGetProcAddressARB
),
2810 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2812 /*** GLX_OML_sync_control ***/
2813 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2814 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2815 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2816 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2817 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2819 /*** GLX_EXT_texture_from_pixmap ***/
2820 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2821 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2823 #ifdef GLX_DIRECT_RENDERING
2824 /*** DRI configuration ***/
2825 GLX_FUNCTION( glXGetScreenDriver
),
2826 GLX_FUNCTION( glXGetDriverConfig
),
2829 { NULL
, NULL
} /* end of list */
2833 static const GLvoid
*
2834 get_glx_proc_address(const char *funcName
)
2838 /* try static functions */
2839 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2840 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2841 return GLX_functions
[i
].Address
;
2849 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2850 * \c glXGetProcAddress.
2852 * \param procName Name of a GL or GLX function.
2853 * \returns A pointer to the named function
2855 * \sa glXGetProcAddress
2857 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2859 typedef void (*gl_function
)( void );
2863 /* Search the table of GLX and internal functions first. If that
2864 * fails and the supplied name could be a valid core GL name, try
2865 * searching the core GL function table. This check is done to prevent
2866 * DRI based drivers from searching the core GL function table for
2867 * internal API functions.
2870 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2871 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2872 && (procName
[2] != 'X') ) {
2873 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2880 * Get the address of a named GL function. This is the GLX 1.4 name for
2881 * \c glXGetProcAddressARB.
2883 * \param procName Name of a GL or GLX function.
2884 * \returns A pointer to the named function
2886 * \sa glXGetProcAddressARB
2888 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2889 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2890 __attribute__ ((alias ("glXGetProcAddressARB")));
2893 return glXGetProcAddressARB(procName
);
2895 #endif /* __GNUC__ */
2898 #ifdef GLX_DIRECT_RENDERING
2900 * Get the unadjusted system time (UST). Currently, the UST is measured in
2901 * microseconds since Epoc. The actual resolution of the UST may vary from
2902 * system to system, and the units may vary from release to release.
2903 * Drivers should not call this function directly. They should instead use
2904 * \c glXGetProcAddress to obtain a pointer to the function.
2906 * \param ust Location to store the 64-bit UST
2907 * \returns Zero on success or a negative errno value on failure.
2909 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2911 * \since Internal API version 20030317.
2913 _X_HIDDEN
int __glXGetUST( int64_t * ust
)
2917 if ( ust
== NULL
) {
2921 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2922 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2928 #endif /* GLX_DIRECT_RENDERING */