2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
38 * Client-side GLX interface.
41 #include "glxclient.h"
43 #include "glxextensions.h"
44 #include "glcontextmodes.h"
47 #ifdef GLX_DIRECT_RENDERING
49 #include <X11/extensions/xf86vmode.h>
53 static const char __glXGLXClientVendorName
[] = "SGI";
54 static const char __glXGLXClientVersion
[] = "1.4";
57 /****************************************************************************/
59 #ifdef GLX_DIRECT_RENDERING
61 static Bool windowExistsFlag
;
62 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
64 if (xerr
->error_code
== BadWindow
) {
65 windowExistsFlag
= GL_FALSE
;
71 * Find drawables in the local hash that have been destroyed on the
74 * \param dpy Display to destroy drawables for
75 * \param screen Screen number to destroy drawables for
77 static void GarbageCollectDRIDrawables(Display
*dpy
, __GLXscreenConfigs
*sc
)
80 __GLXDRIdrawable
*pdraw
;
81 XWindowAttributes xwa
;
82 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
84 /* Set no-op error handler so Xlib doesn't bail out if the windows
85 * has alreay been destroyed on the server. */
87 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
89 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1) {
91 windowExistsFlag
= GL_TRUE
;
92 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
93 if (!windowExistsFlag
) {
94 /* Destroy the local drawable data, if the drawable no
95 longer exists in the Xserver */
96 (*pdraw
->destroyDrawable
)(pdraw
);
97 __glxHashDelete(sc
->drawHash
, draw
);
99 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1);
102 XSync(dpy
, GL_FALSE
);
103 XSetErrorHandler(oldXErrorHandler
);
106 extern __GLXDRIdrawable
*
107 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
);
110 * Get the __DRIdrawable for the drawable associated with a GLXContext
112 * \param dpy The display associated with \c drawable.
113 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
114 * \param scrn_num If non-NULL, the drawables screen is stored there
115 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
116 * the drawable is not associated with a direct-rendering context.
118 _X_HIDDEN __GLXDRIdrawable
*
119 GetGLXDRIDrawable(Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
121 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
122 __GLXDRIdrawable
*pdraw
;
123 const unsigned screen_count
= ScreenCount(dpy
);
125 __GLXscreenConfigs
*psc
;
130 for (i
= 0; i
< screen_count
; i
++) {
131 psc
= &priv
->screenConfigs
[i
];
132 if (psc
->drawHash
== NULL
)
135 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
136 if (scrn_num
!= NULL
)
149 * Get the GLX per-screen data structure associated with a GLX context.
151 * \param dpy Display for which the GLX per-screen information is to be
153 * \param scrn Screen on \c dpy for which the GLX per-screen information is
155 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
156 * specify a valid GLX screen, or NULL otherwise.
158 * \todo Should this function validate that \c scrn is within the screen
159 * number range for \c dpy?
162 static __GLXscreenConfigs
*
163 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
165 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
167 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
172 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
173 __GLXscreenConfigs
** ppsc
)
175 /* Initialize the extension, if needed . This has the added value
176 * of initializing/allocating the display private
180 return GLX_NO_EXTENSION
;
183 *ppriv
= __glXInitialize(dpy
);
184 if ( *ppriv
== NULL
) {
185 return GLX_NO_EXTENSION
;
188 /* Check screen number to see if its valid */
189 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
190 return GLX_BAD_SCREEN
;
193 /* Check to see if the GL is supported on this screen */
194 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
195 if ( (*ppsc
)->configs
== NULL
) {
196 /* No support for GL on this screen regardless of visual */
197 return GLX_BAD_VISUAL
;
205 * Determine if a \c GLXFBConfig supplied by the application is valid.
207 * \param dpy Application supplied \c Display pointer.
208 * \param config Application supplied \c GLXFBConfig.
210 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
211 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
214 static __GLcontextModes
*
215 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
217 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
218 const unsigned num_screens
= ScreenCount(dpy
);
220 const __GLcontextModes
* modes
;
223 if ( priv
!= NULL
) {
224 for ( i
= 0 ; i
< num_screens
; i
++ ) {
225 for ( modes
= priv
->screenConfigs
[i
].configs
227 ; modes
= modes
->next
) {
228 if ( modes
== (__GLcontextModes
*) config
) {
229 return (__GLcontextModes
*) config
;
240 * \todo It should be possible to move the allocate of \c client_state_private
241 * later in the function for direct-rendering contexts. Direct-rendering
242 * contexts don't need to track client state, so they don't need that memory
245 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
246 * function called \c __glXAllocateClientState that allocates the memory and
247 * does all the initialization (including the pixel pack / unpack).
250 GLXContext
AllocateGLXContext( Display
*dpy
)
255 __GLXattribute
*state
;
260 opcode
= __glXSetupForCommand(dpy
);
265 /* Allocate our context record */
266 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
271 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
273 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
279 gc
->client_state_private
= state
;
280 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
281 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
284 ** Create a temporary buffer to hold GLX rendering commands. The size
285 ** of the buffer is selected so that the maximum number of GLX rendering
286 ** commands can fit in a single X packet and still have room in the X
287 ** packet for the GLXRenderReq header.
290 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
291 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
293 Xfree(gc
->client_state_private
);
297 gc
->bufSize
= bufSize
;
299 /* Fill in the new context */
300 gc
->renderMode
= GL_RENDER
;
302 state
->storePack
.alignment
= 4;
303 state
->storeUnpack
.alignment
= 4;
305 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
308 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
309 ** Other code uses the fastImageUnpack bit, but it is never set
312 gc
->fastImageUnpack
= GL_FALSE
;
313 gc
->fillImage
= __glFillImage
;
315 gc
->bufEnd
= gc
->buf
+ bufSize
;
316 gc
->isDirect
= GL_FALSE
;
319 ** Set limit register so that there will be one command per packet
323 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
326 gc
->majorOpcode
= opcode
;
329 ** Constrain the maximum drawing command size allowed to be
330 ** transfered using the X_GLXRender protocol request. First
331 ** constrain by a software limit, then constrain by the protocl
334 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
335 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
337 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
338 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
340 gc
->maxSmallRenderCommandSize
= bufSize
;
346 * Create a new context. Exactly one of \c vis and \c fbconfig should be
349 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
350 * SGIX_fbconfig protocol be used?
351 * \param renderType For FBConfigs, what is the rendering type?
355 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
356 const __GLcontextModes
* const fbconfig
,
357 GLXContext shareList
,
358 Bool allowDirect
, GLXContextID contextID
,
359 Bool use_glx_1_3
, int renderType
)
362 #ifdef GLX_DIRECT_RENDERING
363 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
364 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
370 gc
= AllocateGLXContext(dpy
);
374 if (None
== contextID
) {
375 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
378 #ifdef GLX_DIRECT_RENDERING
379 if (allowDirect
&& psc
->driScreen
) {
380 const __GLcontextModes
* mode
;
382 if (fbconfig
== NULL
) {
383 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
387 error
.errorCode
= BadValue
;
388 error
.resourceID
= vis
->visualid
;
389 error
.sequenceNumber
= dpy
->request
;
390 error
.type
= X_Error
;
391 error
.majorCode
= gc
->majorOpcode
;
392 error
.minorCode
= X_GLXCreateContext
;
393 _XError(dpy
, &error
);
401 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
404 if (gc
->driContext
!= NULL
) {
405 gc
->screen
= mode
->screen
;
408 gc
->isDirect
= GL_TRUE
;
414 if ( fbconfig
== NULL
) {
415 xGLXCreateContextReq
*req
;
417 /* Send the glXCreateContext request */
418 GetReq(GLXCreateContext
,req
);
419 req
->reqType
= gc
->majorOpcode
;
420 req
->glxCode
= X_GLXCreateContext
;
421 req
->context
= gc
->xid
= XAllocID(dpy
);
422 req
->visual
= vis
->visualid
;
423 req
->screen
= vis
->screen
;
424 req
->shareList
= shareList
? shareList
->xid
: None
;
425 req
->isDirect
= gc
->driContext
!= NULL
;
427 else if ( use_glx_1_3
) {
428 xGLXCreateNewContextReq
*req
;
430 /* Send the glXCreateNewContext request */
431 GetReq(GLXCreateNewContext
,req
);
432 req
->reqType
= gc
->majorOpcode
;
433 req
->glxCode
= X_GLXCreateNewContext
;
434 req
->context
= gc
->xid
= XAllocID(dpy
);
435 req
->fbconfig
= fbconfig
->fbconfigID
;
436 req
->screen
= fbconfig
->screen
;
437 req
->renderType
= renderType
;
438 req
->shareList
= shareList
? shareList
->xid
: None
;
439 req
->isDirect
= gc
->driContext
!= NULL
;
442 xGLXVendorPrivateWithReplyReq
*vpreq
;
443 xGLXCreateContextWithConfigSGIXReq
*req
;
445 /* Send the glXCreateNewContext request */
446 GetReqExtra(GLXVendorPrivateWithReply
,
447 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
448 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
449 req
->reqType
= gc
->majorOpcode
;
450 req
->glxCode
= X_GLXVendorPrivateWithReply
;
451 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
452 req
->context
= gc
->xid
= XAllocID(dpy
);
453 req
->fbconfig
= fbconfig
->fbconfigID
;
454 req
->screen
= fbconfig
->screen
;
455 req
->renderType
= renderType
;
456 req
->shareList
= shareList
? shareList
->xid
: None
;
457 req
->isDirect
= gc
->driContext
!= NULL
;
462 gc
->imported
= GL_FALSE
;
466 gc
->imported
= GL_TRUE
;
472 PUBLIC GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*vis
,
473 GLXContext shareList
, Bool allowDirect
)
475 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
479 _X_HIDDEN
void __glXFreeContext(__GLXcontext
*gc
)
481 if (gc
->vendor
) XFree((char *) gc
->vendor
);
482 if (gc
->renderer
) XFree((char *) gc
->renderer
);
483 if (gc
->version
) XFree((char *) gc
->version
);
484 if (gc
->extensions
) XFree((char *) gc
->extensions
);
485 __glFreeAttributeState(gc
);
486 XFree((char *) gc
->buf
);
487 Xfree((char *) gc
->client_state_private
);
493 ** Destroy the named context
496 DestroyContext(Display
*dpy
, GLXContext gc
)
498 xGLXDestroyContextReq
*req
;
503 opcode
= __glXSetupForCommand(dpy
);
504 if (!opcode
|| !gc
) {
510 imported
= gc
->imported
;
513 #ifdef GLX_DIRECT_RENDERING
514 /* Destroy the direct rendering context */
515 if (gc
->driContext
) {
516 (*gc
->driContext
->destroyContext
)(gc
->driContext
, gc
->psc
, dpy
);
517 gc
->driContext
= NULL
;
518 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
522 if (gc
->currentDpy
) {
523 /* Have to free later cuz it's in use now */
526 /* Destroy the handle if not current to anybody */
528 __glXFreeContext(gc
);
533 ** This dpy also created the server side part of the context.
534 ** Send the glXDestroyContext request.
537 GetReq(GLXDestroyContext
,req
);
538 req
->reqType
= opcode
;
539 req
->glxCode
= X_GLXDestroyContext
;
546 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
548 DestroyContext(dpy
, gc
);
552 ** Return the major and minor version #s for the GLX extension
554 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
556 __GLXdisplayPrivate
*priv
;
558 /* Init the extension. This fetches the major and minor version. */
559 priv
= __glXInitialize(dpy
);
560 if (!priv
) return GL_FALSE
;
562 if (major
) *major
= priv
->majorVersion
;
563 if (minor
) *minor
= priv
->minorVersion
;
568 ** Query the existance of the GLX extension
570 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
572 int major_op
, erb
, evb
;
575 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
577 if (errorBase
) *errorBase
= erb
;
578 if (eventBase
) *eventBase
= evb
;
584 ** Put a barrier in the token stream that forces the GL to finish its
585 ** work before X can proceed.
587 PUBLIC
void glXWaitGL(void)
590 GLXContext gc
= __glXGetCurrentContext();
591 Display
*dpy
= gc
->currentDpy
;
595 /* Flush any pending commands out */
596 __glXFlushRenderBuffer(gc
, gc
->pc
);
598 #ifdef GLX_DIRECT_RENDERING
599 if (gc
->driContext
) {
600 /* This bit of ugliness unwraps the glFinish function */
609 /* Send the glXWaitGL request */
611 GetReq(GLXWaitGL
,req
);
612 req
->reqType
= gc
->majorOpcode
;
613 req
->glxCode
= X_GLXWaitGL
;
614 req
->contextTag
= gc
->currentContextTag
;
620 ** Put a barrier in the token stream that forces X to finish its
621 ** work before GL can proceed.
623 PUBLIC
void glXWaitX(void)
626 GLXContext gc
= __glXGetCurrentContext();
627 Display
*dpy
= gc
->currentDpy
;
631 /* Flush any pending commands out */
632 __glXFlushRenderBuffer(gc
, gc
->pc
);
634 #ifdef GLX_DIRECT_RENDERING
635 if (gc
->driContext
) {
642 ** Send the glXWaitX request.
645 GetReq(GLXWaitX
,req
);
646 req
->reqType
= gc
->majorOpcode
;
647 req
->glxCode
= X_GLXWaitX
;
648 req
->contextTag
= gc
->currentContextTag
;
653 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
655 xGLXUseXFontReq
*req
;
656 GLXContext gc
= __glXGetCurrentContext();
657 Display
*dpy
= gc
->currentDpy
;
661 /* Flush any pending commands out */
662 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
664 #ifdef GLX_DIRECT_RENDERING
665 if (gc
->driContext
) {
666 DRI_glXUseXFont(font
, first
, count
, listBase
);
671 /* Send the glXUseFont request */
673 GetReq(GLXUseXFont
,req
);
674 req
->reqType
= gc
->majorOpcode
;
675 req
->glxCode
= X_GLXUseXFont
;
676 req
->contextTag
= gc
->currentContextTag
;
680 req
->listBase
= listBase
;
685 /************************************************************************/
688 ** Copy the source context to the destination context using the
691 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
692 GLXContext dest
, unsigned long mask
)
694 xGLXCopyContextReq
*req
;
695 GLXContext gc
= __glXGetCurrentContext();
699 opcode
= __glXSetupForCommand(dpy
);
704 #ifdef GLX_DIRECT_RENDERING
705 if (gc
->driContext
) {
706 /* NOT_DONE: This does not work yet */
711 ** If the source is the current context, send its tag so that the context
712 ** can be flushed before the copy.
714 if (source
== gc
&& dpy
== gc
->currentDpy
) {
715 tag
= gc
->currentContextTag
;
720 /* Send the glXCopyContext request */
722 GetReq(GLXCopyContext
,req
);
723 req
->reqType
= opcode
;
724 req
->glxCode
= X_GLXCopyContext
;
725 req
->source
= source
? source
->xid
: None
;
726 req
->dest
= dest
? dest
->xid
: None
;
728 req
->contextTag
= tag
;
735 * Determine if a context uses direct rendering.
737 * \param dpy Display where the context was created.
738 * \param contextID ID of the context to be tested.
740 * \returns \c GL_TRUE if the context is direct rendering or not.
742 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
744 xGLXIsDirectReq
*req
;
745 xGLXIsDirectReply reply
;
748 opcode
= __glXSetupForCommand(dpy
);
753 /* Send the glXIsDirect request */
755 GetReq(GLXIsDirect
,req
);
756 req
->reqType
= opcode
;
757 req
->glxCode
= X_GLXIsDirect
;
758 req
->context
= contextID
;
759 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
763 return reply
.isDirect
;
768 * Shouldn't this function \b always return \c GL_FALSE when
769 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
770 * the GLX protocol here at all?
772 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
776 #ifdef GLX_DIRECT_RENDERING
777 } else if (gc
->driContext
) {
781 return __glXIsDirect(dpy
, gc
->xid
);
784 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
787 xGLXCreateGLXPixmapReq
*req
;
791 opcode
= __glXSetupForCommand(dpy
);
796 /* Send the glXCreateGLXPixmap request */
798 GetReq(GLXCreateGLXPixmap
,req
);
799 req
->reqType
= opcode
;
800 req
->glxCode
= X_GLXCreateGLXPixmap
;
801 req
->screen
= vis
->screen
;
802 req
->visual
= vis
->visualid
;
803 req
->pixmap
= pixmap
;
804 req
->glxpixmap
= xid
= XAllocID(dpy
);
811 ** Destroy the named pixmap
813 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
815 xGLXDestroyGLXPixmapReq
*req
;
818 opcode
= __glXSetupForCommand(dpy
);
823 /* Send the glXDestroyGLXPixmap request */
825 GetReq(GLXDestroyGLXPixmap
,req
);
826 req
->reqType
= opcode
;
827 req
->glxCode
= X_GLXDestroyGLXPixmap
;
828 req
->glxpixmap
= glxpixmap
;
833 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
835 xGLXSwapBuffersReq
*req
;
839 #ifdef GLX_DIRECT_RENDERING
840 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
843 (*pdraw
->psc
->core
->swapBuffers
)(pdraw
->driDrawable
);
848 opcode
= __glXSetupForCommand(dpy
);
854 ** The calling thread may or may not have a current context. If it
855 ** does, send the context tag so the server can do a flush.
857 gc
= __glXGetCurrentContext();
858 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
859 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
860 tag
= gc
->currentContextTag
;
865 /* Send the glXSwapBuffers request */
867 GetReq(GLXSwapBuffers
,req
);
868 req
->reqType
= opcode
;
869 req
->glxCode
= X_GLXSwapBuffers
;
870 req
->drawable
= drawable
;
871 req
->contextTag
= tag
;
879 ** Return configuration information for the given display, screen and
880 ** visual combination.
882 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
885 __GLXdisplayPrivate
*priv
;
886 __GLXscreenConfigs
*psc
;
887 __GLcontextModes
*modes
;
890 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
891 if ( status
== Success
) {
892 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
894 /* Lookup attribute after first finding a match on the visual */
895 if ( modes
!= NULL
) {
896 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
899 status
= GLX_BAD_VISUAL
;
903 ** If we can't find the config for this visual, this visual is not
904 ** supported by the OpenGL implementation on the server.
906 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
907 *value_return
= GL_FALSE
;
914 /************************************************************************/
917 init_fbconfig_for_chooser( __GLcontextModes
* config
,
918 GLboolean fbconfig_style_tags
)
920 memset( config
, 0, sizeof( __GLcontextModes
) );
921 config
->visualID
= (XID
) GLX_DONT_CARE
;
922 config
->visualType
= GLX_DONT_CARE
;
924 /* glXChooseFBConfig specifies different defaults for these two than
927 if ( fbconfig_style_tags
) {
928 config
->rgbMode
= GL_TRUE
;
929 config
->doubleBufferMode
= GLX_DONT_CARE
;
932 config
->visualRating
= GLX_DONT_CARE
;
933 config
->transparentPixel
= GLX_NONE
;
934 config
->transparentRed
= GLX_DONT_CARE
;
935 config
->transparentGreen
= GLX_DONT_CARE
;
936 config
->transparentBlue
= GLX_DONT_CARE
;
937 config
->transparentAlpha
= GLX_DONT_CARE
;
938 config
->transparentIndex
= GLX_DONT_CARE
;
940 config
->drawableType
= GLX_WINDOW_BIT
;
941 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
942 config
->xRenderable
= GLX_DONT_CARE
;
943 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
945 config
->swapMethod
= GLX_DONT_CARE
;
948 #define MATCH_DONT_CARE( param ) \
950 if ( (a-> param != GLX_DONT_CARE) \
951 && (a-> param != b-> param) ) { \
956 #define MATCH_MINIMUM( param ) \
958 if ( (a-> param != GLX_DONT_CARE) \
959 && (a-> param > b-> param) ) { \
964 #define MATCH_EXACT( param ) \
966 if ( a-> param != b-> param) { \
972 * Determine if two GLXFBConfigs are compatible.
974 * \param a Application specified config to test.
975 * \param b Server specified config to test against \c a.
978 fbconfigs_compatible( const __GLcontextModes
* const a
,
979 const __GLcontextModes
* const b
)
981 MATCH_DONT_CARE( doubleBufferMode
);
982 MATCH_DONT_CARE( visualType
);
983 MATCH_DONT_CARE( visualRating
);
984 MATCH_DONT_CARE( xRenderable
);
985 MATCH_DONT_CARE( fbconfigID
);
986 MATCH_DONT_CARE( swapMethod
);
988 MATCH_MINIMUM( rgbBits
);
989 MATCH_MINIMUM( numAuxBuffers
);
990 MATCH_MINIMUM( redBits
);
991 MATCH_MINIMUM( greenBits
);
992 MATCH_MINIMUM( blueBits
);
993 MATCH_MINIMUM( alphaBits
);
994 MATCH_MINIMUM( depthBits
);
995 MATCH_MINIMUM( stencilBits
);
996 MATCH_MINIMUM( accumRedBits
);
997 MATCH_MINIMUM( accumGreenBits
);
998 MATCH_MINIMUM( accumBlueBits
);
999 MATCH_MINIMUM( accumAlphaBits
);
1000 MATCH_MINIMUM( sampleBuffers
);
1001 MATCH_MINIMUM( maxPbufferWidth
);
1002 MATCH_MINIMUM( maxPbufferHeight
);
1003 MATCH_MINIMUM( maxPbufferPixels
);
1004 MATCH_MINIMUM( samples
);
1006 MATCH_DONT_CARE( stereoMode
);
1007 MATCH_EXACT( level
);
1009 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1010 || ((a
->renderType
& b
->renderType
) == 0) ) {
1015 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1016 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1017 * Technically speaking, it is a bug in the DDX driver, but there is
1018 * enough of an installed base to work around the problem here. In any
1019 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1020 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1021 * 0 from the server to be a match to maintain backward compatibility with
1022 * the (broken) drivers.
1025 if ( a
->transparentPixel
!= GLX_DONT_CARE
1026 && a
->transparentPixel
!= 0 ) {
1027 if ( a
->transparentPixel
== GLX_NONE
) {
1028 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1031 MATCH_EXACT( transparentPixel
);
1034 switch ( a
->transparentPixel
) {
1035 case GLX_TRANSPARENT_RGB
:
1036 MATCH_DONT_CARE( transparentRed
);
1037 MATCH_DONT_CARE( transparentGreen
);
1038 MATCH_DONT_CARE( transparentBlue
);
1039 MATCH_DONT_CARE( transparentAlpha
);
1042 case GLX_TRANSPARENT_INDEX
:
1043 MATCH_DONT_CARE( transparentIndex
);
1055 /* There's some trickly language in the GLX spec about how this is supposed
1056 * to work. Basically, if a given component size is either not specified
1057 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1058 * Well, that's really hard to do with the code as-is. This behavior is
1059 * closer to correct, but still not technically right.
1061 #define PREFER_LARGER_OR_ZERO(comp) \
1063 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1064 if ( ((*a)-> comp) == 0 ) { \
1067 else if ( ((*b)-> comp) == 0 ) { \
1071 return ((*b)-> comp) - ((*a)-> comp) ; \
1076 #define PREFER_LARGER(comp) \
1078 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1079 return ((*b)-> comp) - ((*a)-> comp) ; \
1083 #define PREFER_SMALLER(comp) \
1085 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1086 return ((*a)-> comp) - ((*b)-> comp) ; \
1091 * Compare two GLXFBConfigs. This function is intended to be used as the
1092 * compare function passed in to qsort.
1094 * \returns If \c a is a "better" config, according to the specification of
1095 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1096 * better, then a number greater than zero is return. If both are
1097 * equal, zero is returned.
1098 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1101 fbconfig_compare( const __GLcontextModes
* const * const a
,
1102 const __GLcontextModes
* const * const b
)
1104 /* The order of these comparisons must NOT change. It is defined by
1105 * the GLX 1.3 spec and ARB_multisample.
1108 PREFER_SMALLER( visualSelectGroup
);
1110 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1111 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1112 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1114 PREFER_SMALLER( visualRating
);
1116 /* This isn't quite right. It is supposed to compare the sum of the
1117 * components the user specifically set minimums for.
1119 PREFER_LARGER_OR_ZERO( redBits
);
1120 PREFER_LARGER_OR_ZERO( greenBits
);
1121 PREFER_LARGER_OR_ZERO( blueBits
);
1122 PREFER_LARGER_OR_ZERO( alphaBits
);
1124 PREFER_SMALLER( rgbBits
);
1126 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1127 /* Prefer single-buffer.
1129 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1132 PREFER_SMALLER( numAuxBuffers
);
1134 PREFER_LARGER_OR_ZERO( depthBits
);
1135 PREFER_SMALLER( stencilBits
);
1137 /* This isn't quite right. It is supposed to compare the sum of the
1138 * components the user specifically set minimums for.
1140 PREFER_LARGER_OR_ZERO( accumRedBits
);
1141 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1142 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1143 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1145 PREFER_SMALLER( visualType
);
1147 /* None of the multisample specs say where this comparison should happen,
1148 * so I put it near the end.
1150 PREFER_SMALLER( sampleBuffers
);
1151 PREFER_SMALLER( samples
);
1153 /* None of the pbuffer or fbconfig specs say that this comparison needs
1154 * to happen at all, but it seems like it should.
1156 PREFER_LARGER( maxPbufferWidth
);
1157 PREFER_LARGER( maxPbufferHeight
);
1158 PREFER_LARGER( maxPbufferPixels
);
1165 * Selects and sorts a subset of the supplied configs based on the attributes.
1166 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1167 * and \c glXChooseFBConfigSGIX.
1169 * \param configs Array of pointers to possible configs. The elements of
1170 * this array that do not meet the criteria will be set to
1171 * NULL. The remaining elements will be sorted according to
1172 * the various visual / FBConfig selection rules.
1173 * \param num_configs Number of elements in the \c configs array.
1174 * \param attribList Attributes used select from \c configs. This array is
1175 * terminated by a \c None tag. The array can either take
1176 * the form expected by \c glXChooseVisual (where boolean
1177 * tags do not have a value) or by \c glXChooseFBConfig
1178 * (where every tag has a value).
1179 * \param fbconfig_style_tags Selects whether \c attribList is in
1180 * \c glXChooseVisual style or
1181 * \c glXChooseFBConfig style.
1182 * \returns The number of valid elements left in \c configs.
1184 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1187 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1188 const int *attribList
, GLboolean fbconfig_style_tags
)
1190 __GLcontextModes test_config
;
1194 /* This is a fairly direct implementation of the selection method
1195 * described by GLX_SGIX_fbconfig. Start by culling out all the
1196 * configs that are not compatible with the selected parameter
1200 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1201 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1202 (const INT32
*) attribList
,
1203 GL_TRUE
, fbconfig_style_tags
);
1206 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1207 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1208 configs
[ base
] = configs
[ i
];
1217 if ( base
< num_configs
) {
1218 (void) memset( & configs
[ base
], 0,
1219 sizeof( void * ) * (num_configs
- base
) );
1222 /* After the incompatible configs are removed, the resulting
1223 * list is sorted according to the rules set out in the various
1227 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1228 (int (*)(const void*, const void*)) fbconfig_compare
);
1236 ** Return the visual that best matches the template. Return None if no
1237 ** visual matches the template.
1239 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1241 XVisualInfo
*visualList
= NULL
;
1242 __GLXdisplayPrivate
*priv
;
1243 __GLXscreenConfigs
*psc
;
1244 __GLcontextModes test_config
;
1245 __GLcontextModes
*modes
;
1246 const __GLcontextModes
*best_config
= NULL
;
1249 ** Get a list of all visuals, return if list is empty
1251 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1257 ** Build a template from the defaults and the attribute list
1258 ** Free visual list and return if an unexpected token is encountered
1260 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1261 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1262 (const INT32
*) attribList
,
1263 GL_TRUE
, GL_FALSE
);
1266 ** Eliminate visuals that don't meet minimum requirements
1267 ** Compute a score for those that do
1268 ** Remember which visual, if any, got the highest score
1270 for ( modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1271 if ( fbconfigs_compatible( & test_config
, modes
)
1272 && ((best_config
== NULL
)
1273 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1274 best_config
= modes
;
1279 ** If no visual is acceptable, return None
1280 ** Otherwise, create an XVisualInfo list with just the selected X visual
1283 if (best_config
!= NULL
) {
1284 XVisualInfo visualTemplate
;
1287 visualTemplate
.screen
= screen
;
1288 visualTemplate
.visualid
= best_config
->visualID
;
1289 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1290 &visualTemplate
, &i
);
1297 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1299 __GLXscreenConfigs
*psc
;
1300 __GLXdisplayPrivate
*priv
;
1302 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1306 if (!psc
->effectiveGLXexts
) {
1307 if (!psc
->serverGLXexts
) {
1308 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1309 X_GLXQueryServerString
,
1310 screen
, GLX_EXTENSIONS
);
1313 __glXCalculateUsableExtensions(psc
,
1314 #ifdef GLX_DIRECT_RENDERING
1315 (psc
->driScreen
!= NULL
),
1319 priv
->minorVersion
);
1322 return psc
->effectiveGLXexts
;
1325 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1329 return (__glXGLXClientVendorName
);
1331 return (__glXGLXClientVersion
);
1332 case GLX_EXTENSIONS
:
1333 return (__glXGetClientExtensions());
1339 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1341 __GLXscreenConfigs
*psc
;
1342 __GLXdisplayPrivate
*priv
;
1346 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1352 str
= & priv
->serverGLXvendor
;
1355 str
= & priv
->serverGLXversion
;
1357 case GLX_EXTENSIONS
:
1358 str
= & psc
->serverGLXexts
;
1364 if ( *str
== NULL
) {
1365 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1366 X_GLXQueryServerString
, screen
, name
);
1372 void __glXClientInfo ( Display
*dpy
, int opcode
)
1374 xGLXClientInfoReq
*req
;
1376 char * ext_str
= __glXGetClientGLExtensionString();
1378 /* Send the glXClientInfo request */
1380 GetReq(GLXClientInfo
,req
);
1381 req
->reqType
= opcode
;
1382 req
->glxCode
= X_GLXClientInfo
;
1383 req
->major
= GLX_MAJOR_VERSION
;
1384 req
->minor
= GLX_MINOR_VERSION
;
1386 size
= strlen( ext_str
) + 1;
1387 req
->length
+= (size
+ 3) >> 2;
1388 req
->numbytes
= size
;
1389 Data(dpy
, ext_str
, size
);
1399 ** EXT_import_context
1402 PUBLIC Display
*glXGetCurrentDisplay(void)
1404 GLXContext gc
= __glXGetCurrentContext();
1405 if (NULL
== gc
) return NULL
;
1406 return gc
->currentDpy
;
1409 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1410 glXGetCurrentDisplay
)
1413 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1416 * \param dpy Display where \c ctx was created.
1417 * \param ctx Context to query.
1418 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1419 * or zero if the request failed due to internal problems (i.e.,
1420 * unable to allocate temporary memory, etc.)
1423 * This function dynamically determines whether to use the EXT_import_context
1424 * version of the protocol or the GLX 1.3 version of the protocol.
1426 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1428 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1429 xGLXQueryContextReply reply
;
1435 return GLX_BAD_CONTEXT
;
1437 opcode
= __glXSetupForCommand(dpy
);
1442 /* Send the glXQueryContextInfoEXT request */
1445 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1446 xGLXQueryContextReq
*req
;
1448 GetReq(GLXQueryContext
, req
);
1450 req
->reqType
= opcode
;
1451 req
->glxCode
= X_GLXQueryContext
;
1452 req
->context
= (unsigned int)(ctx
->xid
);
1455 xGLXVendorPrivateReq
*vpreq
;
1456 xGLXQueryContextInfoEXTReq
*req
;
1458 GetReqExtra( GLXVendorPrivate
,
1459 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1461 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1462 req
->reqType
= opcode
;
1463 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1464 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1465 req
->context
= (unsigned int)(ctx
->xid
);
1468 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1470 numValues
= reply
.n
;
1473 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1477 int *propList
, *pProp
;
1481 nPropListBytes
= numValues
<< 3;
1482 propList
= (int *) Xmalloc(nPropListBytes
);
1483 if (NULL
== propList
) {
1486 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1488 for (i
=0; i
< numValues
; i
++) {
1490 case GLX_SHARE_CONTEXT_EXT
:
1491 ctx
->share_xid
= *pProp
++;
1493 case GLX_VISUAL_ID_EXT
:
1495 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1498 ctx
->screen
= *pProp
++;
1500 case GLX_FBCONFIG_ID
:
1502 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
, *pProp
++);
1504 case GLX_RENDER_TYPE
:
1505 ctx
->renderType
= *pProp
++;
1512 Xfree((char *)propList
);
1522 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1526 /* get the information from the server if we don't have it already */
1527 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1528 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1529 if (Success
!= retVal
) return retVal
;
1531 switch (attribute
) {
1532 case GLX_SHARE_CONTEXT_EXT
:
1533 *value
= (int)(ctx
->share_xid
);
1535 case GLX_VISUAL_ID_EXT
:
1536 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1539 *value
= (int)(ctx
->screen
);
1541 case GLX_FBCONFIG_ID
:
1542 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1544 case GLX_RENDER_TYPE
:
1545 *value
= (int)(ctx
->renderType
);
1548 return GLX_BAD_ATTRIBUTE
;
1553 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1554 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1555 (dpy
, ctx
, attribute
, value
),
1558 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1563 PUBLIC GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1567 if (contextID
== None
) {
1570 if (__glXIsDirect(dpy
, contextID
)) {
1574 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1576 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1583 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1585 DestroyContext(dpy
, ctx
);
1591 * GLX 1.3 functions - these are just stubs for now!
1594 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1595 const int *attribList
, int *nitems
)
1597 __GLcontextModes
** config_list
;
1601 config_list
= (__GLcontextModes
**)
1602 glXGetFBConfigs( dpy
, screen
, & list_size
);
1604 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1605 list_size
= choose_visual( config_list
, list_size
, attribList
,
1607 if ( list_size
== 0 ) {
1608 XFree( config_list
);
1613 *nitems
= list_size
;
1614 return (GLXFBConfig
*) config_list
;
1618 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1619 int renderType
, GLXContext shareList
,
1622 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1623 allowDirect
, None
, True
, renderType
);
1627 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1629 GLXContext gc
= __glXGetCurrentContext();
1630 return gc
->currentReadable
;
1634 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1636 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1637 __GLcontextModes
** config
= NULL
;
1641 if ( (priv
->screenConfigs
!= NULL
)
1642 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1643 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1644 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1645 unsigned num_configs
= 0;
1646 __GLcontextModes
* modes
;
1649 for ( modes
= priv
->screenConfigs
[screen
].configs
1651 ; modes
= modes
->next
) {
1652 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1657 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1659 if ( config
!= NULL
) {
1660 *nelements
= num_configs
;
1662 for ( modes
= priv
->screenConfigs
[screen
].configs
1664 ; modes
= modes
->next
) {
1665 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1672 return (GLXFBConfig
*) config
;
1676 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1677 int attribute
, int *value
)
1679 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1681 return (modes
!= NULL
)
1682 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1687 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1689 XVisualInfo visualTemplate
;
1690 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1694 ** Get a list of all visuals, return if list is empty
1696 visualTemplate
.visualid
= fbconfig
->visualID
;
1697 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1702 ** GLX_SGI_swap_control
1704 static int __glXSwapIntervalSGI(int interval
)
1706 xGLXVendorPrivateReq
*req
;
1707 GLXContext gc
= __glXGetCurrentContext();
1709 CARD32
* interval_ptr
;
1713 return GLX_BAD_CONTEXT
;
1716 if ( interval
<= 0 ) {
1717 return GLX_BAD_VALUE
;
1720 #ifdef __DRI_SWAP_CONTROL
1721 if (gc
->driContext
) {
1722 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1724 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1725 gc
->currentDrawable
,
1727 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1728 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1732 return GLX_BAD_CONTEXT
;
1736 dpy
= gc
->currentDpy
;
1737 opcode
= __glXSetupForCommand(dpy
);
1742 /* Send the glXSwapIntervalSGI request */
1744 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1745 req
->reqType
= opcode
;
1746 req
->glxCode
= X_GLXVendorPrivate
;
1747 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1748 req
->contextTag
= gc
->currentContextTag
;
1750 interval_ptr
= (CARD32
*) (req
+ 1);
1751 *interval_ptr
= interval
;
1762 ** GLX_MESA_swap_control
1764 static int __glXSwapIntervalMESA(unsigned int interval
)
1766 #ifdef __DRI_SWAP_CONTROL
1767 GLXContext gc
= __glXGetCurrentContext();
1769 if ( interval
< 0 ) {
1770 return GLX_BAD_VALUE
;
1773 if (gc
!= NULL
&& gc
->driContext
) {
1774 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1777 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1778 __GLXDRIdrawable
*pdraw
=
1779 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1780 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1781 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1790 return GLX_BAD_CONTEXT
;
1794 static int __glXGetSwapIntervalMESA(void)
1796 #ifdef __DRI_SWAP_CONTROL
1797 GLXContext gc
= __glXGetCurrentContext();
1799 if (gc
!= NULL
&& gc
->driContext
) {
1800 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1803 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1804 __GLXDRIdrawable
*pdraw
=
1805 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1806 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1807 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
1818 ** GLX_MESA_swap_frame_usage
1821 static GLint
__glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1823 int status
= GLX_BAD_CONTEXT
;
1824 #ifdef __DRI_FRAME_TRACKING
1826 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1827 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1829 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1830 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
1839 static GLint
__glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1841 int status
= GLX_BAD_CONTEXT
;
1842 #ifdef __DRI_FRAME_TRACKING
1844 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1845 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
1847 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1848 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
1858 static GLint
__glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1861 int status
= GLX_BAD_CONTEXT
;
1862 #ifdef __DRI_FRAME_TRACKING
1864 __GLXDRIdrawable
* const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1865 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1867 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1868 int64_t sbc
, missedFrames
;
1869 float lastMissedUsage
;
1871 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1886 static GLint
__glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1887 int64_t *sbc
, int64_t *missedFrames
,
1888 GLfloat
*lastMissedUsage
)
1890 int status
= GLX_BAD_CONTEXT
;
1891 #ifdef __DRI_FRAME_TRACKING
1893 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, & screen
);
1894 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1896 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1899 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1901 lastMissedUsage
, &usage
);
1907 (void) missedFrames
;
1908 (void) lastMissedUsage
;
1915 ** GLX_SGI_video_sync
1917 static int __glXGetVideoSyncSGI(unsigned int *count
)
1919 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1920 * FIXME: there should be a GLX encoding for this call. I can find no
1921 * FIXME: documentation for the GLX encoding.
1923 #ifdef __DRI_MEDIA_STREAM_COUNTER
1924 GLXContext gc
= __glXGetCurrentContext();
1927 if (gc
!= NULL
&& gc
->driContext
) {
1928 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1930 if ( psc
->msc
&& psc
->driScreen
) {
1931 __GLXDRIdrawable
*pdraw
=
1932 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1936 ret
= (*psc
->msc
->getDrawableMSC
)(psc
->__driScreen
,
1937 pdraw
->driDrawable
, &temp
);
1938 *count
= (unsigned) temp
;
1940 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1946 return GLX_BAD_CONTEXT
;
1949 static int __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1951 #ifdef __DRI_MEDIA_STREAM_COUNTER
1952 GLXContext gc
= __glXGetCurrentContext();
1954 if ( divisor
<= 0 || remainder
< 0 )
1955 return GLX_BAD_VALUE
;
1957 if (gc
!= NULL
&& gc
->driContext
) {
1958 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1960 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
1961 __GLXDRIdrawable
*pdraw
=
1962 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1967 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, 0,
1968 divisor
, remainder
, &msc
, &sbc
);
1969 *count
= (unsigned) msc
;
1970 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1976 return GLX_BAD_CONTEXT
;
1981 ** GLX_SGIX_fbconfig
1982 ** Many of these functions are aliased to GLX 1.3 entry points in the
1983 ** GLX_functions table.
1986 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1987 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1988 (dpy
, config
, attribute
, value
),
1989 glXGetFBConfigAttrib
)
1991 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1992 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
1993 (dpy
, screen
, attrib_list
, nelements
),
1996 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1997 (Display
* dpy
, GLXFBConfigSGIX config
),
1999 glXGetVisualFromFBConfig
)
2001 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
2002 GLXFBConfigSGIX config
, Pixmap pixmap
)
2004 xGLXVendorPrivateWithReplyReq
*vpreq
;
2005 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2006 GLXPixmap xid
= None
;
2008 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2009 __GLXscreenConfigs
* psc
;
2012 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2016 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2018 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2019 opcode
= __glXSetupForCommand(dpy
);
2024 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2026 GetReqExtra(GLXVendorPrivateWithReply
,
2027 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2028 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2029 req
->reqType
= opcode
;
2030 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2031 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2032 req
->screen
= fbconfig
->screen
;
2033 req
->fbconfig
= fbconfig
->fbconfigID
;
2034 req
->pixmap
= pixmap
;
2035 req
->glxpixmap
= xid
= XAllocID(dpy
);
2043 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2044 GLXFBConfigSGIX config
, int renderType
,
2045 GLXContext shareList
, Bool allowDirect
)
2047 GLXContext gc
= NULL
;
2048 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2049 __GLXscreenConfigs
* psc
;
2052 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2056 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2058 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2059 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2060 allowDirect
, None
, False
, renderType
);
2067 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2070 __GLXdisplayPrivate
*priv
;
2071 __GLXscreenConfigs
*psc
;
2073 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2074 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2075 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2076 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2085 ** GLX_SGIX_swap_group
2087 static void __glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2097 ** GLX_SGIX_swap_barrier
2099 static void __glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2107 static Bool
__glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2117 ** GLX_OML_sync_control
2119 static Bool
__glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2120 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2122 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2123 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2125 if ( priv
!= NULL
) {
2127 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2128 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2130 assert( (pdraw
== NULL
) || (i
!= -1) );
2131 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2132 && ((*psc
->msc
->getMSC
)(psc
->driScreen
, msc
) == 0)
2133 && ((*psc
->sbc
->getSBC
)(pdraw
->driDrawable
, sbc
) == 0)
2134 && (__glXGetUST(ust
) == 0) );
2146 #ifdef GLX_DIRECT_RENDERING
2148 __driGetMscRateOML(__DRIdrawable
*draw
,
2149 int32_t *numerator
, int32_t *denominator
, void *private)
2152 __GLXscreenConfigs
*psc
;
2153 XF86VidModeModeLine mode_line
;
2156 __GLXDRIdrawable
*glxDraw
= private;
2159 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2160 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
) ) {
2161 unsigned n
= dot_clock
* 1000;
2162 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2164 # define V_INTERLACE 0x010
2165 # define V_DBLSCAN 0x020
2167 if (mode_line
.flags
& V_INTERLACE
)
2169 else if (mode_line
.flags
& V_DBLSCAN
)
2172 /* The OML_sync_control spec requires that if the refresh rate is a
2173 * whole number, that the returned numerator be equal to the refresh
2174 * rate and the denominator be 1.
2182 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2184 /* This is a poor man's way to reduce a fraction. It's far from
2185 * perfect, but it will work well enough for this situation.
2188 for (i
= 0; f
[i
] != 0; i
++) {
2189 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2210 * Determine the refresh rate of the specified drawable and display.
2212 * \param dpy Display whose refresh rate is to be determined.
2213 * \param drawable Drawable whose refresh rate is to be determined.
2214 * \param numerator Numerator of the refresh rate.
2215 * \param demoninator Denominator of the refresh rate.
2216 * \return If the refresh rate for the specified display and drawable could
2217 * be calculated, True is returned. Otherwise False is returned.
2219 * \note This function is implemented entirely client-side. A lot of other
2220 * functionality is required to export GLX_OML_sync_control, so on
2221 * XFree86 this function can be called for direct-rendering contexts
2222 * when GLX_OML_sync_control appears in the client extension string.
2225 _X_HIDDEN GLboolean
__glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2226 int32_t * numerator
,
2227 int32_t * denominator
)
2229 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2230 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2235 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2246 static int64_t __glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2247 int64_t target_msc
, int64_t divisor
,
2250 #ifdef __DRI_SWAP_BUFFER_COUNTER
2252 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2253 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2255 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2256 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2257 * of -1 if the function failed because of errors detected in the input
2260 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2262 if ( divisor
> 0 && remainder
>= divisor
)
2265 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2266 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
->driDrawable
, target_msc
,
2267 divisor
, remainder
);
2280 static Bool
__glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2281 int64_t target_msc
, int64_t divisor
,
2282 int64_t remainder
, int64_t *ust
,
2283 int64_t *msc
, int64_t *sbc
)
2285 #ifdef __DRI_MEDIA_STREAM_COUNTER
2287 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2288 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2291 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2292 * error", but the return type in the spec is Bool.
2294 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2296 if ( divisor
> 0 && remainder
>= divisor
)
2299 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2300 ret
= (*psc
->msc
->waitForMSC
)(pdraw
->driDrawable
, target_msc
,
2301 divisor
, remainder
, msc
, sbc
);
2303 /* __glXGetUST returns zero on success and non-zero on failure.
2304 * This function returns True on success and False on failure.
2306 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2322 static Bool
__glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2323 int64_t target_sbc
, int64_t *ust
,
2324 int64_t *msc
, int64_t *sbc
)
2326 #ifdef __DRI_SWAP_BUFFER_COUNTER
2328 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2329 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2332 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2333 * error", but the return type in the spec is Bool.
2335 if ( target_sbc
< 0 )
2338 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2339 ret
= (*psc
->sbc
->waitForSBC
)(pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2341 /* __glXGetUST returns zero on success and non-zero on failure.
2342 * This function returns True on success and False on failure.
2344 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2359 * GLX_MESA_allocate_memory
2363 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2364 size_t size
, float readFreq
,
2365 float writeFreq
, float priority
)
2367 #ifdef __DRI_ALLOCATE
2368 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2370 if (psc
&& psc
->allocate
)
2371 return (*psc
->allocate
->allocateMemory
)(psc
->__driScreen
, size
,
2372 readFreq
, writeFreq
, priority
);
2381 #endif /* GLX_DIRECT_RENDERING */
2387 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2389 #ifdef __DRI_ALLOCATE
2390 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2392 if (psc
&& psc
->allocate
)
2393 (*psc
->allocate
->freeMemory
)(psc
->__driScreen
, pointer
);
2399 #endif /* GLX_DIRECT_RENDERING */
2403 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2404 const void *pointer
)
2406 #ifdef __DRI_ALLOCATE
2407 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2409 if (psc
&& psc
->allocate
)
2410 return (*psc
->allocate
->memoryOffset
)(psc
->__driScreen
, pointer
);
2416 #endif /* GLX_DIRECT_RENDERING */
2424 * Mesa extension stubs. These will help reduce portability problems.
2429 * Release all buffers associated with the specified GLX drawable.
2432 * This function was intended for stand-alone Mesa. The issue there is that
2433 * the library doesn't get any notification when a window is closed. In
2434 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2435 * supported, there are 3 different functions to destroy a drawable. It
2436 * should be possible to create GLX protocol (or have it determine which
2437 * protocol to use based on the type of the drawable) to have one function
2438 * do the work of 3. For the direct-rendering case, this function could
2439 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2440 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2441 * would need to be used. This really should be done as part of the new DRI
2444 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2445 * __driGarbageCollectDrawables
2446 * glXDestroyGLXPixmap
2447 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2448 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2450 static Bool
__glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2458 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2459 Pixmap pixmap
, Colormap cmap
)
2471 * GLX_MESA_copy_sub_buffer
2473 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2474 static void __glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2475 int x
, int y
, int width
, int height
)
2477 xGLXVendorPrivateReq
*req
;
2480 CARD32
*drawable_ptr
;
2481 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2484 #ifdef __DRI_COPY_SUB_BUFFER
2486 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2487 if ( pdraw
!= NULL
) {
2488 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2489 if (psc
->copySubBuffer
!= NULL
) {
2490 (*psc
->copySubBuffer
->copySubBuffer
)(pdraw
->driDrawable
,
2491 x
, y
, width
, height
);
2498 opcode
= __glXSetupForCommand(dpy
);
2503 ** The calling thread may or may not have a current context. If it
2504 ** does, send the context tag so the server can do a flush.
2506 gc
= __glXGetCurrentContext();
2507 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2508 ((drawable
== gc
->currentDrawable
) ||
2509 (drawable
== gc
->currentReadable
)) ) {
2510 tag
= gc
->currentContextTag
;
2516 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4,req
);
2517 req
->reqType
= opcode
;
2518 req
->glxCode
= X_GLXVendorPrivate
;
2519 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2520 req
->contextTag
= tag
;
2522 drawable_ptr
= (CARD32
*) (req
+ 1);
2523 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2524 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2525 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2526 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2528 *drawable_ptr
= drawable
;
2540 * GLX_EXT_texture_from_pixmap
2543 static void __glXBindTexImageEXT(Display
*dpy
,
2544 GLXDrawable drawable
,
2546 const int *attrib_list
)
2548 xGLXVendorPrivateReq
*req
;
2549 GLXContext gc
= __glXGetCurrentContext();
2550 CARD32
*drawable_ptr
;
2552 CARD32
*num_attrib_ptr
;
2562 while (attrib_list
[i
* 2] != None
)
2566 #ifdef GLX_DIRECT_RENDERING
2567 if (gc
->driContext
) {
2568 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2571 (*pdraw
->psc
->texBuffer
->setTexBuffer
)(gc
->__driContext
,
2572 pdraw
->textureTarget
,
2573 pdraw
->driDrawable
);
2579 opcode
= __glXSetupForCommand(dpy
);
2584 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
,req
);
2585 req
->reqType
= opcode
;
2586 req
->glxCode
= X_GLXVendorPrivate
;
2587 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2588 req
->contextTag
= gc
->currentContextTag
;
2590 drawable_ptr
= (CARD32
*) (req
+ 1);
2591 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2592 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2593 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2595 *drawable_ptr
= drawable
;
2596 *buffer_ptr
= buffer
;
2597 *num_attrib_ptr
= (CARD32
) i
;
2601 while (attrib_list
[i
* 2] != None
)
2603 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2604 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2613 static void __glXReleaseTexImageEXT(Display
*dpy
,
2614 GLXDrawable drawable
,
2617 xGLXVendorPrivateReq
*req
;
2618 GLXContext gc
= __glXGetCurrentContext();
2619 CARD32
*drawable_ptr
;
2626 #ifdef GLX_DIRECT_RENDERING
2631 opcode
= __glXSetupForCommand(dpy
);
2636 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
)+sizeof(INT32
),req
);
2637 req
->reqType
= opcode
;
2638 req
->glxCode
= X_GLXVendorPrivate
;
2639 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2640 req
->contextTag
= gc
->currentContextTag
;
2642 drawable_ptr
= (CARD32
*) (req
+ 1);
2643 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2645 *drawable_ptr
= drawable
;
2646 *buffer_ptr
= buffer
;
2654 * \c strdup is actually not a standard ANSI C or POSIX routine.
2655 * Irix will not define it if ANSI mode is in effect.
2660 __glXstrdup(const char *str
)
2663 copy
= (char *) Xmalloc(strlen(str
) + 1);
2671 ** glXGetProcAddress support
2674 struct name_address_pair
{
2679 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2680 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2682 static const struct name_address_pair GLX_functions
[] = {
2683 /*** GLX_VERSION_1_0 ***/
2684 GLX_FUNCTION( glXChooseVisual
),
2685 GLX_FUNCTION( glXCopyContext
),
2686 GLX_FUNCTION( glXCreateContext
),
2687 GLX_FUNCTION( glXCreateGLXPixmap
),
2688 GLX_FUNCTION( glXDestroyContext
),
2689 GLX_FUNCTION( glXDestroyGLXPixmap
),
2690 GLX_FUNCTION( glXGetConfig
),
2691 GLX_FUNCTION( glXGetCurrentContext
),
2692 GLX_FUNCTION( glXGetCurrentDrawable
),
2693 GLX_FUNCTION( glXIsDirect
),
2694 GLX_FUNCTION( glXMakeCurrent
),
2695 GLX_FUNCTION( glXQueryExtension
),
2696 GLX_FUNCTION( glXQueryVersion
),
2697 GLX_FUNCTION( glXSwapBuffers
),
2698 GLX_FUNCTION( glXUseXFont
),
2699 GLX_FUNCTION( glXWaitGL
),
2700 GLX_FUNCTION( glXWaitX
),
2702 /*** GLX_VERSION_1_1 ***/
2703 GLX_FUNCTION( glXGetClientString
),
2704 GLX_FUNCTION( glXQueryExtensionsString
),
2705 GLX_FUNCTION( glXQueryServerString
),
2707 /*** GLX_VERSION_1_2 ***/
2708 GLX_FUNCTION( glXGetCurrentDisplay
),
2710 /*** GLX_VERSION_1_3 ***/
2711 GLX_FUNCTION( glXChooseFBConfig
),
2712 GLX_FUNCTION( glXCreateNewContext
),
2713 GLX_FUNCTION( glXCreatePbuffer
),
2714 GLX_FUNCTION( glXCreatePixmap
),
2715 GLX_FUNCTION( glXCreateWindow
),
2716 GLX_FUNCTION( glXDestroyPbuffer
),
2717 GLX_FUNCTION( glXDestroyPixmap
),
2718 GLX_FUNCTION( glXDestroyWindow
),
2719 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2720 GLX_FUNCTION( glXGetFBConfigAttrib
),
2721 GLX_FUNCTION( glXGetFBConfigs
),
2722 GLX_FUNCTION( glXGetSelectedEvent
),
2723 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2724 GLX_FUNCTION( glXMakeContextCurrent
),
2725 GLX_FUNCTION( glXQueryContext
),
2726 GLX_FUNCTION( glXQueryDrawable
),
2727 GLX_FUNCTION( glXSelectEvent
),
2729 /*** GLX_SGI_swap_control ***/
2730 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2732 /*** GLX_SGI_video_sync ***/
2733 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2734 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2736 /*** GLX_SGI_make_current_read ***/
2737 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2738 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2740 /*** GLX_EXT_import_context ***/
2741 GLX_FUNCTION( glXFreeContextEXT
),
2742 GLX_FUNCTION( glXGetContextIDEXT
),
2743 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2744 GLX_FUNCTION( glXImportContextEXT
),
2745 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2747 /*** GLX_SGIX_fbconfig ***/
2748 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2749 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2750 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2751 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2752 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2753 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2755 /*** GLX_SGIX_pbuffer ***/
2756 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2757 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2758 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2759 GLX_FUNCTION( glXSelectEventSGIX
),
2760 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2762 /*** GLX_SGIX_swap_group ***/
2763 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2765 /*** GLX_SGIX_swap_barrier ***/
2766 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2767 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2769 /*** GLX_MESA_allocate_memory ***/
2770 GLX_FUNCTION( glXAllocateMemoryMESA
),
2771 GLX_FUNCTION( glXFreeMemoryMESA
),
2772 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2774 /*** GLX_MESA_copy_sub_buffer ***/
2775 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2777 /*** GLX_MESA_pixmap_colormap ***/
2778 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2780 /*** GLX_MESA_release_buffers ***/
2781 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2783 /*** GLX_MESA_swap_control ***/
2784 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2785 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2787 /*** GLX_MESA_swap_frame_usage ***/
2788 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2789 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2790 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2791 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2793 /*** GLX_ARB_get_proc_address ***/
2794 GLX_FUNCTION( glXGetProcAddressARB
),
2797 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2799 /*** GLX_OML_sync_control ***/
2800 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2801 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2802 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2803 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2804 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2806 /*** GLX_EXT_texture_from_pixmap ***/
2807 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2808 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2810 #ifdef GLX_DIRECT_RENDERING
2811 /*** DRI configuration ***/
2812 GLX_FUNCTION( glXGetScreenDriver
),
2813 GLX_FUNCTION( glXGetDriverConfig
),
2816 { NULL
, NULL
} /* end of list */
2820 static const GLvoid
*
2821 get_glx_proc_address(const char *funcName
)
2825 /* try static functions */
2826 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2827 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2828 return GLX_functions
[i
].Address
;
2836 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2837 * \c glXGetProcAddress.
2839 * \param procName Name of a GL or GLX function.
2840 * \returns A pointer to the named function
2842 * \sa glXGetProcAddress
2844 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2846 typedef void (*gl_function
)( void );
2850 /* Search the table of GLX and internal functions first. If that
2851 * fails and the supplied name could be a valid core GL name, try
2852 * searching the core GL function table. This check is done to prevent
2853 * DRI based drivers from searching the core GL function table for
2854 * internal API functions.
2857 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2858 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2859 && (procName
[2] != 'X') ) {
2860 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2867 * Get the address of a named GL function. This is the GLX 1.4 name for
2868 * \c glXGetProcAddressARB.
2870 * \param procName Name of a GL or GLX function.
2871 * \returns A pointer to the named function
2873 * \sa glXGetProcAddressARB
2875 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2876 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2877 __attribute__ ((alias ("glXGetProcAddressARB")));
2880 return glXGetProcAddressARB(procName
);
2882 #endif /* __GNUC__ */
2885 #ifdef GLX_DIRECT_RENDERING
2887 * Get the unadjusted system time (UST). Currently, the UST is measured in
2888 * microseconds since Epoc. The actual resolution of the UST may vary from
2889 * system to system, and the units may vary from release to release.
2890 * Drivers should not call this function directly. They should instead use
2891 * \c glXGetProcAddress to obtain a pointer to the function.
2893 * \param ust Location to store the 64-bit UST
2894 * \returns Zero on success or a negative errno value on failure.
2896 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2898 * \since Internal API version 20030317.
2900 _X_HIDDEN
int __glXGetUST( int64_t * ust
)
2904 if ( ust
== NULL
) {
2908 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2909 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2915 #endif /* GLX_DIRECT_RENDERING */