1 /* $XFree86: xc/lib/GL/glx/glxcmds.c,v 1.30 2004/01/30 20:33:06 alanh Exp $ */
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
11 ** http://oss.sgi.com/projects/FreeB
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
39 * Client-side GLX interface.
43 #include "glxclient.h"
44 #include <X11/extensions/extutil.h>
45 #include <X11/extensions/Xext.h>
49 #ifdef GLX_DIRECT_RENDERING
50 #include "indirect_init.h"
51 #include <X11/extensions/xf86vmode.h>
54 #include "glxextensions.h"
55 #include "glcontextmodes.h"
59 static const char __glXGLXClientVendorName
[] = "SGI";
60 static const char __glXGLXClientVersion
[] = "1.4";
63 /****************************************************************************/
65 * Get the __DRIdrawable for the drawable associated with a GLXContext
67 * \param dpy The display associated with \c drawable.
68 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
69 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
70 * the drawable is not associated with a direct-rendering context.
73 #ifdef GLX_DIRECT_RENDERING
74 static __DRIdrawable
*
75 GetDRIDrawable( Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
77 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
79 if ( (priv
!= NULL
) && (priv
->driDisplay
.private != NULL
) ) {
80 const unsigned screen_count
= ScreenCount(dpy
);
83 for ( i
= 0 ; i
< screen_count
; i
++ ) {
84 __DRIscreen
* const psc
= &priv
->screenConfigs
[i
].driScreen
;
85 __DRIdrawable
* const pdraw
= (psc
->private != NULL
)
86 ? (*psc
->getDrawable
)(dpy
, drawable
, psc
->private) : NULL
;
88 if ( pdraw
!= NULL
) {
89 if ( scrn_num
!= NULL
) {
103 * Get the GLX per-screen data structure associated with a GLX context.
105 * \param dpy Display for which the GLX per-screen information is to be
107 * \param scrn Screen on \c dpy for which the GLX per-screen information is
109 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
110 * specify a valid GLX screen, or NULL otherwise.
112 * \todo Should this function validate that \c scrn is within the screen
113 * number range for \c dpy?
116 static __GLXscreenConfigs
*
117 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
119 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
121 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
126 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
127 __GLXscreenConfigs
** ppsc
)
129 /* Initialize the extension, if needed . This has the added value
130 * of initializing/allocating the display private
134 return GLX_NO_EXTENSION
;
137 *ppriv
= __glXInitialize(dpy
);
138 if ( *ppriv
== NULL
) {
139 return GLX_NO_EXTENSION
;
142 /* Check screen number to see if its valid */
143 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
144 return GLX_BAD_SCREEN
;
147 /* Check to see if the GL is supported on this screen */
148 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
149 if ( (*ppsc
)->configs
== NULL
) {
150 /* No support for GL on this screen regardless of visual */
151 return GLX_BAD_VISUAL
;
159 * Determine if a \c GLXFBConfig supplied by the application is valid.
161 * \param dpy Application supplied \c Display pointer.
162 * \param config Application supplied \c GLXFBConfig.
164 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
165 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
168 static __GLcontextModes
*
169 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
171 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
172 const unsigned num_screens
= ScreenCount(dpy
);
174 const __GLcontextModes
* modes
;
177 if ( priv
!= NULL
) {
178 for ( i
= 0 ; i
< num_screens
; i
++ ) {
179 for ( modes
= priv
->screenConfigs
[i
].configs
181 ; modes
= modes
->next
) {
182 if ( modes
== (__GLcontextModes
*) config
) {
183 return (__GLcontextModes
*) config
;
194 * \todo It should be possible to move the allocate of \c client_state_private
195 * later in the function for direct-rendering contexts. Direct-rendering
196 * contexts don't need to track client state, so they don't need that memory
199 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
200 * function called \c __glXAllocateClientState that allocates the memory and
201 * does all the initialization (including the pixel pack / unpack).
204 GLXContext
AllocateGLXContext( Display
*dpy
)
209 __GLXattribute
*state
;
214 opcode
= __glXSetupForCommand(dpy
);
219 /* Allocate our context record */
220 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
225 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
227 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
233 gc
->client_state_private
= state
;
234 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
235 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
238 ** Create a temporary buffer to hold GLX rendering commands. The size
239 ** of the buffer is selected so that the maximum number of GLX rendering
240 ** commands can fit in a single X packet and still have room in the X
241 ** packet for the GLXRenderReq header.
244 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
245 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
247 Xfree(gc
->client_state_private
);
251 gc
->bufSize
= bufSize
;
253 /* Fill in the new context */
254 gc
->renderMode
= GL_RENDER
;
256 state
->storePack
.alignment
= 4;
257 state
->storeUnpack
.alignment
= 4;
259 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
262 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
263 ** Other code uses the fastImageUnpack bit, but it is never set
266 gc
->fastImageUnpack
= GL_FALSE
;
267 gc
->fillImage
= __glFillImage
;
268 gc
->isDirect
= GL_FALSE
;
270 gc
->bufEnd
= gc
->buf
+ bufSize
;
273 ** Set limit register so that there will be one command per packet
277 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
280 gc
->majorOpcode
= opcode
;
283 ** Constrain the maximum drawing command size allowed to be
284 ** transfered using the X_GLXRender protocol request. First
285 ** constrain by a software limit, then constrain by the protocl
288 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
289 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
291 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
292 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
294 gc
->maxSmallRenderCommandSize
= bufSize
;
300 * Create a new context. Exactly one of \c vis and \c fbconfig should be
303 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
304 * SGIX_fbconfig protocol be used?
305 * \param renderType For FBConfigs, what is the rendering type?
309 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
310 const __GLcontextModes
* const fbconfig
,
311 GLXContext shareList
,
312 Bool allowDirect
, GLXContextID contextID
,
313 Bool use_glx_1_3
, int renderType
)
320 gc
= AllocateGLXContext(dpy
);
324 if (None
== contextID
) {
325 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
328 #ifdef GLX_DIRECT_RENDERING
330 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
331 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
332 const __GLcontextModes
* mode
;
334 /* The value of fbconfig cannot change because it is tested
335 * later in the function.
337 if ( fbconfig
== NULL
) {
338 /* FIXME: Is it possible for the __GLcontextModes structure
339 * FIXME: to not be found?
341 mode
= _gl_context_modes_find_visual( psc
->configs
,
343 assert( mode
!= NULL
);
344 assert( mode
->screen
== screen
);
350 if (psc
&& psc
->driScreen
.private) {
351 void * const shared
= (shareList
!= NULL
)
352 ? shareList
->driContext
.private : NULL
;
353 gc
->driContext
.private =
354 (*psc
->driScreen
.createNewContext
)( dpy
, mode
, renderType
,
357 if (gc
->driContext
.private) {
358 gc
->isDirect
= GL_TRUE
;
359 gc
->screen
= mode
->screen
;
360 gc
->vid
= mode
->visualID
;
361 gc
->fbconfigID
= mode
->fbconfigID
;
362 gc
->driContext
.mode
= mode
;
369 if ( fbconfig
== NULL
) {
370 xGLXCreateContextReq
*req
;
372 /* Send the glXCreateContext request */
373 GetReq(GLXCreateContext
,req
);
374 req
->reqType
= gc
->majorOpcode
;
375 req
->glxCode
= X_GLXCreateContext
;
376 req
->context
= gc
->xid
= XAllocID(dpy
);
377 req
->visual
= vis
->visualid
;
378 req
->screen
= vis
->screen
;
379 req
->shareList
= shareList
? shareList
->xid
: None
;
380 req
->isDirect
= gc
->isDirect
;
382 else if ( use_glx_1_3
) {
383 xGLXCreateNewContextReq
*req
;
385 /* Send the glXCreateNewContext request */
386 GetReq(GLXCreateNewContext
,req
);
387 req
->reqType
= gc
->majorOpcode
;
388 req
->glxCode
= X_GLXCreateNewContext
;
389 req
->context
= gc
->xid
= XAllocID(dpy
);
390 req
->fbconfig
= fbconfig
->fbconfigID
;
391 req
->screen
= fbconfig
->screen
;
392 req
->renderType
= renderType
;
393 req
->shareList
= shareList
? shareList
->xid
: None
;
394 req
->isDirect
= gc
->isDirect
;
397 xGLXVendorPrivateWithReplyReq
*vpreq
;
398 xGLXCreateContextWithConfigSGIXReq
*req
;
400 /* Send the glXCreateNewContext request */
401 GetReqExtra(GLXVendorPrivateWithReply
,
402 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
403 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
404 req
->reqType
= gc
->majorOpcode
;
405 req
->glxCode
= X_GLXVendorPrivateWithReply
;
406 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
407 req
->context
= gc
->xid
= XAllocID(dpy
);
408 req
->fbconfig
= fbconfig
->fbconfigID
;
409 req
->screen
= fbconfig
->screen
;
410 req
->renderType
= renderType
;
411 req
->shareList
= shareList
? shareList
->xid
: None
;
412 req
->isDirect
= gc
->isDirect
;
417 gc
->imported
= GL_FALSE
;
421 gc
->imported
= GL_TRUE
;
427 PUBLIC GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*vis
,
428 GLXContext shareList
, Bool allowDirect
)
430 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
434 void __glXFreeContext(__GLXcontext
*gc
)
436 if (gc
->vendor
) XFree((char *) gc
->vendor
);
437 if (gc
->renderer
) XFree((char *) gc
->renderer
);
438 if (gc
->version
) XFree((char *) gc
->version
);
439 if (gc
->extensions
) XFree((char *) gc
->extensions
);
440 __glFreeAttributeState(gc
);
441 XFree((char *) gc
->buf
);
442 Xfree((char *) gc
->client_state_private
);
448 ** Destroy the named context
451 DestroyContext(Display
*dpy
, GLXContext gc
)
453 xGLXDestroyContextReq
*req
;
458 opcode
= __glXSetupForCommand(dpy
);
459 if (!opcode
|| !gc
) {
465 imported
= gc
->imported
;
468 #ifdef GLX_DIRECT_RENDERING
469 /* Destroy the direct rendering context */
471 if (gc
->driContext
.private) {
472 (*gc
->driContext
.destroyContext
)(dpy
, gc
->screen
,
473 gc
->driContext
.private);
474 gc
->driContext
.private = NULL
;
479 if (gc
->currentDpy
) {
480 /* Have to free later cuz it's in use now */
483 /* Destroy the handle if not current to anybody */
485 __glXFreeContext(gc
);
490 ** This dpy also created the server side part of the context.
491 ** Send the glXDestroyContext request.
494 GetReq(GLXDestroyContext
,req
);
495 req
->reqType
= opcode
;
496 req
->glxCode
= X_GLXDestroyContext
;
503 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
505 DestroyContext(dpy
, gc
);
509 ** Return the major and minor version #s for the GLX extension
511 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
513 __GLXdisplayPrivate
*priv
;
515 /* Init the extension. This fetches the major and minor version. */
516 priv
= __glXInitialize(dpy
);
517 if (!priv
) return GL_FALSE
;
519 if (major
) *major
= priv
->majorVersion
;
520 if (minor
) *minor
= priv
->minorVersion
;
525 ** Query the existance of the GLX extension
527 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
529 int major_op
, erb
, evb
;
532 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
534 if (errorBase
) *errorBase
= erb
;
535 if (eventBase
) *eventBase
= evb
;
541 ** Put a barrier in the token stream that forces the GL to finish its
542 ** work before X can proceed.
544 PUBLIC
void glXWaitGL(void)
547 GLXContext gc
= __glXGetCurrentContext();
548 Display
*dpy
= gc
->currentDpy
;
552 /* Flush any pending commands out */
553 __glXFlushRenderBuffer(gc
, gc
->pc
);
555 #ifdef GLX_DIRECT_RENDERING
557 /* This bit of ugliness unwraps the glFinish function */
566 /* Send the glXWaitGL request */
568 GetReq(GLXWaitGL
,req
);
569 req
->reqType
= gc
->majorOpcode
;
570 req
->glxCode
= X_GLXWaitGL
;
571 req
->contextTag
= gc
->currentContextTag
;
577 ** Put a barrier in the token stream that forces X to finish its
578 ** work before GL can proceed.
580 PUBLIC
void glXWaitX(void)
583 GLXContext gc
= __glXGetCurrentContext();
584 Display
*dpy
= gc
->currentDpy
;
588 /* Flush any pending commands out */
589 __glXFlushRenderBuffer(gc
, gc
->pc
);
591 #ifdef GLX_DIRECT_RENDERING
599 ** Send the glXWaitX request.
602 GetReq(GLXWaitX
,req
);
603 req
->reqType
= gc
->majorOpcode
;
604 req
->glxCode
= X_GLXWaitX
;
605 req
->contextTag
= gc
->currentContextTag
;
610 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
612 xGLXUseXFontReq
*req
;
613 GLXContext gc
= __glXGetCurrentContext();
614 Display
*dpy
= gc
->currentDpy
;
618 /* Flush any pending commands out */
619 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
621 #ifdef GLX_DIRECT_RENDERING
623 DRI_glXUseXFont(font
, first
, count
, listBase
);
628 /* Send the glXUseFont request */
630 GetReq(GLXUseXFont
,req
);
631 req
->reqType
= gc
->majorOpcode
;
632 req
->glxCode
= X_GLXUseXFont
;
633 req
->contextTag
= gc
->currentContextTag
;
637 req
->listBase
= listBase
;
642 /************************************************************************/
645 ** Copy the source context to the destination context using the
648 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
649 GLXContext dest
, unsigned long mask
)
651 xGLXCopyContextReq
*req
;
652 GLXContext gc
= __glXGetCurrentContext();
656 opcode
= __glXSetupForCommand(dpy
);
661 #ifdef GLX_DIRECT_RENDERING
663 /* NOT_DONE: This does not work yet */
668 ** If the source is the current context, send its tag so that the context
669 ** can be flushed before the copy.
671 if (source
== gc
&& dpy
== gc
->currentDpy
) {
672 tag
= gc
->currentContextTag
;
677 /* Send the glXCopyContext request */
679 GetReq(GLXCopyContext
,req
);
680 req
->reqType
= opcode
;
681 req
->glxCode
= X_GLXCopyContext
;
682 req
->source
= source
? source
->xid
: None
;
683 req
->dest
= dest
? dest
->xid
: None
;
685 req
->contextTag
= tag
;
692 * Determine if a context uses direct rendering.
694 * \param dpy Display where the context was created.
695 * \param contextID ID of the context to be tested.
697 * \returns \c GL_TRUE if the context is direct rendering or not.
699 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
701 xGLXIsDirectReq
*req
;
702 xGLXIsDirectReply reply
;
705 opcode
= __glXSetupForCommand(dpy
);
710 /* Send the glXIsDirect request */
712 GetReq(GLXIsDirect
,req
);
713 req
->reqType
= opcode
;
714 req
->glxCode
= X_GLXIsDirect
;
715 req
->context
= contextID
;
716 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
720 return reply
.isDirect
;
725 * Shouldn't this function \b always return \c GL_FALSE when
726 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
727 * the GLX protocol here at all?
729 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
733 #ifdef GLX_DIRECT_RENDERING
734 } else if (gc
->isDirect
) {
738 return __glXIsDirect(dpy
, gc
->xid
);
741 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
744 xGLXCreateGLXPixmapReq
*req
;
748 opcode
= __glXSetupForCommand(dpy
);
753 /* Send the glXCreateGLXPixmap request */
755 GetReq(GLXCreateGLXPixmap
,req
);
756 req
->reqType
= opcode
;
757 req
->glxCode
= X_GLXCreateGLXPixmap
;
758 req
->screen
= vis
->screen
;
759 req
->visual
= vis
->visualid
;
760 req
->pixmap
= pixmap
;
761 req
->glxpixmap
= xid
= XAllocID(dpy
);
768 ** Destroy the named pixmap
770 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
772 xGLXDestroyGLXPixmapReq
*req
;
775 opcode
= __glXSetupForCommand(dpy
);
780 /* Send the glXDestroyGLXPixmap request */
782 GetReq(GLXDestroyGLXPixmap
,req
);
783 req
->reqType
= opcode
;
784 req
->glxCode
= X_GLXDestroyGLXPixmap
;
785 req
->glxpixmap
= glxpixmap
;
790 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
792 xGLXSwapBuffersReq
*req
;
796 #ifdef GLX_DIRECT_RENDERING
797 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, NULL
);
799 if ( pdraw
!= NULL
) {
800 (*pdraw
->swapBuffers
)(dpy
, pdraw
->private);
805 opcode
= __glXSetupForCommand(dpy
);
811 ** The calling thread may or may not have a current context. If it
812 ** does, send the context tag so the server can do a flush.
814 gc
= __glXGetCurrentContext();
815 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
816 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
817 tag
= gc
->currentContextTag
;
822 /* Send the glXSwapBuffers request */
824 GetReq(GLXSwapBuffers
,req
);
825 req
->reqType
= opcode
;
826 req
->glxCode
= X_GLXSwapBuffers
;
827 req
->drawable
= drawable
;
828 req
->contextTag
= tag
;
836 ** Return configuration information for the given display, screen and
837 ** visual combination.
839 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
842 __GLXdisplayPrivate
*priv
;
843 __GLXscreenConfigs
*psc
;
846 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
847 if ( status
== Success
) {
848 const __GLcontextModes
* const modes
= _gl_context_modes_find_visual(
849 psc
->configs
, vis
->visualid
);
851 /* Lookup attribute after first finding a match on the visual */
852 if ( modes
!= NULL
) {
853 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
856 status
= GLX_BAD_VISUAL
;
860 ** If we can't find the config for this visual, this visual is not
861 ** supported by the OpenGL implementation on the server.
863 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
864 *value_return
= GL_FALSE
;
871 /************************************************************************/
874 init_fbconfig_for_chooser( __GLcontextModes
* config
,
875 GLboolean fbconfig_style_tags
)
877 memset( config
, 0, sizeof( __GLcontextModes
) );
878 config
->visualID
= (XID
) GLX_DONT_CARE
;
879 config
->visualType
= GLX_DONT_CARE
;
881 /* glXChooseFBConfig specifies different defaults for these two than
884 if ( fbconfig_style_tags
) {
885 config
->rgbMode
= GL_TRUE
;
886 config
->doubleBufferMode
= GLX_DONT_CARE
;
889 config
->visualRating
= GLX_DONT_CARE
;
890 config
->transparentPixel
= GLX_NONE
;
891 config
->transparentRed
= GLX_DONT_CARE
;
892 config
->transparentGreen
= GLX_DONT_CARE
;
893 config
->transparentBlue
= GLX_DONT_CARE
;
894 config
->transparentAlpha
= GLX_DONT_CARE
;
895 config
->transparentIndex
= GLX_DONT_CARE
;
897 config
->drawableType
= GLX_WINDOW_BIT
;
898 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
899 config
->xRenderable
= GLX_DONT_CARE
;
900 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
902 config
->swapMethod
= GLX_DONT_CARE
;
905 #define MATCH_DONT_CARE( param ) \
907 if ( (a-> param != GLX_DONT_CARE) \
908 && (a-> param != b-> param) ) { \
913 #define MATCH_MINIMUM( param ) \
915 if ( (a-> param != GLX_DONT_CARE) \
916 && (a-> param > b-> param) ) { \
921 #define MATCH_EXACT( param ) \
923 if ( a-> param != b-> param) { \
929 * Determine if two GLXFBConfigs are compatible.
931 * \param a Application specified config to test.
932 * \param b Server specified config to test against \c a.
935 fbconfigs_compatible( const __GLcontextModes
* const a
,
936 const __GLcontextModes
* const b
)
938 MATCH_DONT_CARE( doubleBufferMode
);
939 MATCH_DONT_CARE( visualType
);
940 MATCH_DONT_CARE( visualRating
);
941 MATCH_DONT_CARE( xRenderable
);
942 MATCH_DONT_CARE( fbconfigID
);
943 MATCH_DONT_CARE( swapMethod
);
945 MATCH_MINIMUM( rgbBits
);
946 MATCH_MINIMUM( numAuxBuffers
);
947 MATCH_MINIMUM( redBits
);
948 MATCH_MINIMUM( greenBits
);
949 MATCH_MINIMUM( blueBits
);
950 MATCH_MINIMUM( alphaBits
);
951 MATCH_MINIMUM( depthBits
);
952 MATCH_MINIMUM( stencilBits
);
953 MATCH_MINIMUM( accumRedBits
);
954 MATCH_MINIMUM( accumGreenBits
);
955 MATCH_MINIMUM( accumBlueBits
);
956 MATCH_MINIMUM( accumAlphaBits
);
957 MATCH_MINIMUM( sampleBuffers
);
958 MATCH_MINIMUM( maxPbufferWidth
);
959 MATCH_MINIMUM( maxPbufferHeight
);
960 MATCH_MINIMUM( maxPbufferPixels
);
961 MATCH_MINIMUM( samples
);
963 MATCH_DONT_CARE( stereoMode
);
964 MATCH_EXACT( level
);
966 if ( ((a
->drawableType
& b
->drawableType
) == 0)
967 || ((a
->renderType
& b
->renderType
) == 0) ) {
972 /* There is a bug in a few of the XFree86 DDX drivers. They contain
973 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
974 * Technically speaking, it is a bug in the DDX driver, but there is
975 * enough of an installed base to work around the problem here. In any
976 * case, 0 is not a valid value of the transparent type, so we'll treat 0
977 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
978 * 0 from the server to be a match to maintain backward compatibility with
979 * the (broken) drivers.
982 if ( a
->transparentPixel
!= GLX_DONT_CARE
983 && a
->transparentPixel
!= 0 ) {
984 if ( a
->transparentPixel
== GLX_NONE
) {
985 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
988 MATCH_EXACT( transparentPixel
);
991 switch ( a
->transparentPixel
) {
992 case GLX_TRANSPARENT_RGB
:
993 MATCH_DONT_CARE( transparentRed
);
994 MATCH_DONT_CARE( transparentGreen
);
995 MATCH_DONT_CARE( transparentBlue
);
996 MATCH_DONT_CARE( transparentAlpha
);
999 case GLX_TRANSPARENT_INDEX
:
1000 MATCH_DONT_CARE( transparentIndex
);
1012 /* There's some trickly language in the GLX spec about how this is supposed
1013 * to work. Basically, if a given component size is either not specified
1014 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1015 * Well, that's really hard to do with the code as-is. This behavior is
1016 * closer to correct, but still not technically right.
1018 #define PREFER_LARGER_OR_ZERO(comp) \
1020 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1021 if ( ((*a)-> comp) == 0 ) { \
1024 else if ( ((*b)-> comp) == 0 ) { \
1028 return ((*b)-> comp) - ((*a)-> comp) ; \
1033 #define PREFER_LARGER(comp) \
1035 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1036 return ((*b)-> comp) - ((*a)-> comp) ; \
1040 #define PREFER_SMALLER(comp) \
1042 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1043 return ((*a)-> comp) - ((*b)-> comp) ; \
1048 * Compare two GLXFBConfigs. This function is intended to be used as the
1049 * compare function passed in to qsort.
1051 * \returns If \c a is a "better" config, according to the specification of
1052 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1053 * better, then a number greater than zero is return. If both are
1054 * equal, zero is returned.
1055 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1058 fbconfig_compare( const __GLcontextModes
* const * const a
,
1059 const __GLcontextModes
* const * const b
)
1061 /* The order of these comparisons must NOT change. It is defined by
1062 * the GLX 1.3 spec and ARB_multisample.
1065 PREFER_SMALLER( visualSelectGroup
);
1067 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1068 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1069 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1071 PREFER_SMALLER( visualRating
);
1073 /* This isn't quite right. It is supposed to compare the sum of the
1074 * components the user specifically set minimums for.
1076 PREFER_LARGER_OR_ZERO( redBits
);
1077 PREFER_LARGER_OR_ZERO( greenBits
);
1078 PREFER_LARGER_OR_ZERO( blueBits
);
1079 PREFER_LARGER_OR_ZERO( alphaBits
);
1081 PREFER_SMALLER( rgbBits
);
1083 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1084 /* Prefer single-buffer.
1086 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1089 PREFER_SMALLER( numAuxBuffers
);
1091 PREFER_LARGER_OR_ZERO( depthBits
);
1092 PREFER_SMALLER( stencilBits
);
1094 /* This isn't quite right. It is supposed to compare the sum of the
1095 * components the user specifically set minimums for.
1097 PREFER_LARGER_OR_ZERO( accumRedBits
);
1098 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1099 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1100 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1102 PREFER_SMALLER( visualType
);
1104 /* None of the multisample specs say where this comparison should happen,
1105 * so I put it near the end.
1107 PREFER_SMALLER( sampleBuffers
);
1108 PREFER_SMALLER( samples
);
1110 /* None of the pbuffer or fbconfig specs say that this comparison needs
1111 * to happen at all, but it seems like it should.
1113 PREFER_LARGER( maxPbufferWidth
);
1114 PREFER_LARGER( maxPbufferHeight
);
1115 PREFER_LARGER( maxPbufferPixels
);
1122 * Selects and sorts a subset of the supplied configs based on the attributes.
1123 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1124 * and \c glXChooseFBConfigSGIX.
1126 * \param configs Array of pointers to possible configs. The elements of
1127 * this array that do not meet the criteria will be set to
1128 * NULL. The remaining elements will be sorted according to
1129 * the various visual / FBConfig selection rules.
1130 * \param num_configs Number of elements in the \c configs array.
1131 * \param attribList Attributes used select from \c configs. This array is
1132 * terminated by a \c None tag. The array can either take
1133 * the form expected by \c glXChooseVisual (where boolean
1134 * tags do not have a value) or by \c glXChooseFBConfig
1135 * (where every tag has a value).
1136 * \param fbconfig_style_tags Selects whether \c attribList is in
1137 * \c glXChooseVisual style or
1138 * \c glXChooseFBConfig style.
1139 * \returns The number of valid elements left in \c configs.
1141 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1144 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1145 const int *attribList
, GLboolean fbconfig_style_tags
)
1147 __GLcontextModes test_config
;
1151 /* This is a fairly direct implementation of the selection method
1152 * described by GLX_SGIX_fbconfig. Start by culling out all the
1153 * configs that are not compatible with the selected parameter
1157 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1158 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1159 (const INT32
*) attribList
,
1160 GL_TRUE
, fbconfig_style_tags
);
1163 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1164 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1165 configs
[ base
] = configs
[ i
];
1174 if ( base
< num_configs
) {
1175 (void) memset( & configs
[ base
], 0,
1176 sizeof( void * ) * (num_configs
- base
) );
1179 /* After the incompatible configs are removed, the resulting
1180 * list is sorted according to the rules set out in the various
1184 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1185 (int (*)(const void*, const void*)) fbconfig_compare
);
1193 ** Return the visual that best matches the template. Return None if no
1194 ** visual matches the template.
1196 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1198 XVisualInfo
*visualList
= NULL
;
1199 __GLXdisplayPrivate
*priv
;
1200 __GLXscreenConfigs
*psc
;
1201 __GLcontextModes test_config
;
1202 __GLcontextModes
*modes
;
1203 const __GLcontextModes
*best_config
= NULL
;
1206 ** Get a list of all visuals, return if list is empty
1208 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1214 ** Build a template from the defaults and the attribute list
1215 ** Free visual list and return if an unexpected token is encountered
1217 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1218 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1219 (const INT32
*) attribList
,
1220 GL_TRUE
, GL_FALSE
);
1223 ** Eliminate visuals that don't meet minimum requirements
1224 ** Compute a score for those that do
1225 ** Remember which visual, if any, got the highest score
1227 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
1228 if ( fbconfigs_compatible( & test_config
, modes
)
1229 && ((best_config
== NULL
)
1230 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1231 best_config
= modes
;
1236 ** If no visual is acceptable, return None
1237 ** Otherwise, create an XVisualInfo list with just the selected X visual
1240 if (best_config
!= NULL
) {
1241 XVisualInfo visualTemplate
;
1244 visualTemplate
.screen
= screen
;
1245 visualTemplate
.visualid
= best_config
->visualID
;
1246 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1247 &visualTemplate
, &i
);
1254 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1256 __GLXscreenConfigs
*psc
;
1257 __GLXdisplayPrivate
*priv
;
1259 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1263 if (!psc
->effectiveGLXexts
) {
1264 if (!psc
->serverGLXexts
) {
1265 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1266 X_GLXQueryServerString
,
1267 screen
, GLX_EXTENSIONS
);
1270 __glXCalculateUsableExtensions(psc
,
1271 #ifdef GLX_DIRECT_RENDERING
1272 (psc
->driScreen
.private != NULL
),
1276 priv
->minorVersion
);
1279 return psc
->effectiveGLXexts
;
1282 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1286 return (__glXGLXClientVendorName
);
1288 return (__glXGLXClientVersion
);
1289 case GLX_EXTENSIONS
:
1290 return (__glXGetClientExtensions());
1296 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1298 __GLXscreenConfigs
*psc
;
1299 __GLXdisplayPrivate
*priv
;
1303 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1309 str
= & priv
->serverGLXvendor
;
1312 str
= & priv
->serverGLXversion
;
1314 case GLX_EXTENSIONS
:
1315 str
= & psc
->serverGLXexts
;
1321 if ( *str
== NULL
) {
1322 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1323 X_GLXQueryServerString
, screen
, name
);
1329 void __glXClientInfo ( Display
*dpy
, int opcode
)
1331 xGLXClientInfoReq
*req
;
1333 char * ext_str
= __glXGetClientGLExtensionString();
1335 /* Send the glXClientInfo request */
1337 GetReq(GLXClientInfo
,req
);
1338 req
->reqType
= opcode
;
1339 req
->glxCode
= X_GLXClientInfo
;
1340 req
->major
= GLX_MAJOR_VERSION
;
1341 req
->minor
= GLX_MINOR_VERSION
;
1343 size
= strlen( ext_str
) + 1;
1344 req
->length
+= (size
+ 3) >> 2;
1345 req
->numbytes
= size
;
1346 Data(dpy
, ext_str
, size
);
1356 ** EXT_import_context
1359 PUBLIC Display
*glXGetCurrentDisplay(void)
1361 GLXContext gc
= __glXGetCurrentContext();
1362 if (NULL
== gc
) return NULL
;
1363 return gc
->currentDpy
;
1366 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1367 glXGetCurrentDisplay
)
1370 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1373 * \param dpy Display where \c ctx was created.
1374 * \param ctx Context to query.
1375 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1376 * or zero if the request failed due to internal problems (i.e.,
1377 * unable to allocate temporary memory, etc.)
1380 * This function dynamically determines whether to use the EXT_import_context
1381 * version of the protocol or the GLX 1.3 version of the protocol.
1383 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1385 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1386 xGLXQueryContextReply reply
;
1392 return GLX_BAD_CONTEXT
;
1394 opcode
= __glXSetupForCommand(dpy
);
1399 /* Send the glXQueryContextInfoEXT request */
1402 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1403 xGLXQueryContextReq
*req
;
1405 GetReq(GLXQueryContext
, req
);
1407 req
->reqType
= opcode
;
1408 req
->glxCode
= X_GLXQueryContext
;
1409 req
->context
= (unsigned int)(ctx
->xid
);
1412 xGLXVendorPrivateReq
*vpreq
;
1413 xGLXQueryContextInfoEXTReq
*req
;
1415 GetReqExtra( GLXVendorPrivate
,
1416 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1418 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1419 req
->reqType
= opcode
;
1420 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1421 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1422 req
->context
= (unsigned int)(ctx
->xid
);
1425 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1427 numValues
= reply
.n
;
1430 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1434 int *propList
, *pProp
;
1438 nPropListBytes
= numValues
<< 3;
1439 propList
= (int *) Xmalloc(nPropListBytes
);
1440 if (NULL
== propList
) {
1443 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1445 for (i
=0; i
< numValues
; i
++) {
1447 case GLX_SHARE_CONTEXT_EXT
:
1448 ctx
->share_xid
= *pProp
++;
1450 case GLX_VISUAL_ID_EXT
:
1451 ctx
->vid
= *pProp
++;
1454 ctx
->screen
= *pProp
++;
1456 case GLX_FBCONFIG_ID
:
1457 ctx
->fbconfigID
= *pProp
++;
1459 case GLX_RENDER_TYPE
:
1460 ctx
->renderType
= *pProp
++;
1467 Xfree((char *)propList
);
1477 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1481 /* get the information from the server if we don't have it already */
1482 if (!ctx
->isDirect
&& (ctx
->vid
== None
)) {
1483 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1484 if (Success
!= retVal
) return retVal
;
1486 switch (attribute
) {
1487 case GLX_SHARE_CONTEXT_EXT
:
1488 *value
= (int)(ctx
->share_xid
);
1490 case GLX_VISUAL_ID_EXT
:
1491 *value
= (int)(ctx
->vid
);
1494 *value
= (int)(ctx
->screen
);
1496 case GLX_FBCONFIG_ID
:
1497 *value
= (int)(ctx
->fbconfigID
);
1499 case GLX_RENDER_TYPE
:
1500 *value
= (int)(ctx
->renderType
);
1503 return GLX_BAD_ATTRIBUTE
;
1508 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1509 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1510 (dpy
, ctx
, attribute
, value
),
1513 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1518 PUBLIC GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1522 if (contextID
== None
) {
1525 if (__glXIsDirect(dpy
, contextID
)) {
1529 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1531 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1538 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1540 DestroyContext(dpy
, ctx
);
1546 * GLX 1.3 functions - these are just stubs for now!
1549 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1550 const int *attribList
, int *nitems
)
1552 __GLcontextModes
** config_list
;
1556 config_list
= (__GLcontextModes
**)
1557 glXGetFBConfigs( dpy
, screen
, & list_size
);
1559 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1560 list_size
= choose_visual( config_list
, list_size
, attribList
,
1562 if ( list_size
== 0 ) {
1563 XFree( config_list
);
1568 *nitems
= list_size
;
1569 return (GLXFBConfig
*) config_list
;
1573 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1574 int renderType
, GLXContext shareList
,
1577 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1578 allowDirect
, None
, True
, renderType
);
1582 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1584 GLXContext gc
= __glXGetCurrentContext();
1585 return gc
->currentReadable
;
1589 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1591 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1592 __GLcontextModes
** config
= NULL
;
1595 if ( (priv
->screenConfigs
!= NULL
)
1596 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1597 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1598 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1599 unsigned num_configs
= 0;
1600 __GLcontextModes
* modes
;
1603 for ( modes
= priv
->screenConfigs
[screen
].configs
1605 ; modes
= modes
->next
) {
1606 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1611 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1613 if ( config
!= NULL
) {
1614 *nelements
= num_configs
;
1616 for ( modes
= priv
->screenConfigs
[screen
].configs
1618 ; modes
= modes
->next
) {
1624 return (GLXFBConfig
*) config
;
1628 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1629 int attribute
, int *value
)
1631 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1633 return (modes
!= NULL
)
1634 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1639 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1641 XVisualInfo visualTemplate
;
1642 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1646 ** Get a list of all visuals, return if list is empty
1648 visualTemplate
.visualid
= fbconfig
->visualID
;
1649 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1654 ** GLX_SGI_make_current_read
1657 PUBLIC
GLX_ALIAS(GLXDrawable
, glXGetCurrentReadDrawableSGI
, (void), (),
1658 glXGetCurrentReadDrawable
)
1662 ** GLX_SGI_swap_control
1664 PUBLIC
int glXSwapIntervalSGI(int interval
)
1666 xGLXVendorPrivateReq
*req
;
1667 GLXContext gc
= __glXGetCurrentContext();
1669 CARD32
* interval_ptr
;
1673 return GLX_BAD_CONTEXT
;
1676 if ( interval
<= 0 ) {
1677 return GLX_BAD_VALUE
;
1680 #ifdef GLX_DIRECT_RENDERING
1681 if ( gc
->isDirect
) {
1682 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1684 __DRIdrawable
* const pdraw
= GetDRIDrawable( gc
->currentDpy
,
1685 gc
->currentDrawable
,
1687 if ( __glXExtensionBitIsEnabled( psc
, SGI_swap_control_bit
)
1688 && (pdraw
!= NULL
) ) {
1689 pdraw
->swap_interval
= interval
;
1693 return GLX_BAD_CONTEXT
;
1697 dpy
= gc
->currentDpy
;
1698 opcode
= __glXSetupForCommand(dpy
);
1703 /* Send the glXSwapIntervalSGI request */
1705 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1706 req
->reqType
= opcode
;
1707 req
->glxCode
= X_GLXVendorPrivate
;
1708 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1709 req
->contextTag
= gc
->currentContextTag
;
1711 interval_ptr
= (CARD32
*) req
+ 1;
1712 *interval_ptr
= interval
;
1723 ** GLX_MESA_swap_control
1725 PUBLIC GLint
glXSwapIntervalMESA(unsigned interval
)
1727 #ifdef GLX_DIRECT_RENDERING
1728 GLXContext gc
= __glXGetCurrentContext();
1730 if ( interval
< 0 ) {
1731 return GLX_BAD_VALUE
;
1734 if ( (gc
!= NULL
) && gc
->isDirect
) {
1735 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1738 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1739 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1740 __DRIdrawable
* const pdraw
=
1741 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1742 gc
->currentDrawable
,
1743 psc
->driScreen
.private);
1744 if ( pdraw
!= NULL
) {
1745 pdraw
->swap_interval
= interval
;
1754 return GLX_BAD_CONTEXT
;
1757 PUBLIC GLint
glXGetSwapIntervalMESA( void )
1759 #ifdef GLX_DIRECT_RENDERING
1760 GLXContext gc
= __glXGetCurrentContext();
1762 if ( (gc
!= NULL
) && gc
->isDirect
) {
1763 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1766 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1767 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1768 __DRIdrawable
* const pdraw
=
1769 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1770 gc
->currentDrawable
,
1771 psc
->driScreen
.private);
1772 if ( pdraw
!= NULL
) {
1773 return pdraw
->swap_interval
;
1784 ** GLX_MESA_swap_frame_usage
1787 PUBLIC GLint
glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1789 int status
= GLX_BAD_CONTEXT
;
1790 #ifdef GLX_DIRECT_RENDERING
1792 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1793 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1795 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1796 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1797 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_TRUE
);
1807 PUBLIC GLint
glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1809 int status
= GLX_BAD_CONTEXT
;
1810 #ifdef GLX_DIRECT_RENDERING
1812 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1813 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1815 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1816 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1817 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_FALSE
);
1827 PUBLIC GLint
glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1830 int status
= GLX_BAD_CONTEXT
;
1831 #ifdef GLX_DIRECT_RENDERING
1833 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1834 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1836 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1837 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1838 int64_t sbc
, missedFrames
;
1839 float lastMissedUsage
;
1841 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, &sbc
,
1842 &missedFrames
, &lastMissedUsage
,
1854 PUBLIC GLint
glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1855 int64_t *sbc
, int64_t *missedFrames
,
1856 GLfloat
*lastMissedUsage
)
1858 int status
= GLX_BAD_CONTEXT
;
1859 #ifdef GLX_DIRECT_RENDERING
1861 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1862 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1864 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1865 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1868 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, sbc
,
1869 missedFrames
, lastMissedUsage
,
1876 (void) missedFrames
;
1877 (void) lastMissedUsage
;
1884 ** GLX_SGI_video_sync
1886 PUBLIC
int glXGetVideoSyncSGI(unsigned int *count
)
1888 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1889 * FIXME: there should be a GLX encoding for this call. I can find no
1890 * FIXME: documentation for the GLX encoding.
1892 #ifdef GLX_DIRECT_RENDERING
1893 GLXContext gc
= __glXGetCurrentContext();
1896 if ( (gc
!= NULL
) && gc
->isDirect
) {
1897 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1899 if ( __glXExtensionBitIsEnabled( psc
, SGI_video_sync_bit
)
1900 && psc
->driScreen
.private && psc
->driScreen
.getMSC
) {
1904 ret
= psc
->driScreen
.getMSC( psc
->driScreen
.private, & temp
);
1905 *count
= (unsigned) temp
;
1906 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1912 return GLX_BAD_CONTEXT
;
1915 PUBLIC
int glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1917 #ifdef GLX_DIRECT_RENDERING
1918 GLXContext gc
= __glXGetCurrentContext();
1920 if ( divisor
<= 0 || remainder
< 0 )
1921 return GLX_BAD_VALUE
;
1923 if ( (gc
!= NULL
) && gc
->isDirect
) {
1924 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1926 if ( __glXExtensionBitIsEnabled( psc
, SGI_video_sync_bit
)
1927 && psc
->driScreen
.private ) {
1928 __DRIdrawable
* const pdraw
=
1929 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1930 gc
->currentDrawable
,
1931 psc
->driScreen
.private);
1932 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
) ) {
1937 ret
= (*pdraw
->waitForMSC
)( gc
->currentDpy
, pdraw
->private,
1938 0, divisor
, remainder
,
1940 *count
= (unsigned) msc
;
1941 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1948 return GLX_BAD_CONTEXT
;
1953 ** GLX_SGIS_video_source
1957 PUBLIC GLXVideoSourceSGIX
glXCreateGLXVideoSourceSGIX(Display
*dpy
,
1958 int screen
, VLServer server
, VLPath path
,
1959 int nodeClass
, VLNode drainNode
)
1970 PUBLIC
void glXDestroyGLXVideoSourceSGIX(Display
*dpy
, GLXVideoSourceSGIX src
)
1980 ** GLX_SGIX_fbconfig
1981 ** Many of these functions are aliased to GLX 1.3 entry points in the
1982 ** GLX_functions table.
1985 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1986 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1987 (dpy
, config
, attribute
, value
),
1988 glXGetFBConfigAttrib
)
1990 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1991 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
1992 (dpy
, screen
, attrib_list
, nelements
),
1995 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1996 (Display
* dpy
, GLXFBConfigSGIX config
),
1998 glXGetVisualFromFBConfig
)
2000 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
2001 GLXFBConfigSGIX config
, Pixmap pixmap
)
2003 xGLXVendorPrivateWithReplyReq
*vpreq
;
2004 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2005 GLXPixmap xid
= None
;
2007 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2008 __GLXscreenConfigs
* psc
;
2011 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2015 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2017 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2018 opcode
= __glXSetupForCommand(dpy
);
2023 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2025 GetReqExtra(GLXVendorPrivateWithReply
,
2026 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2027 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2028 req
->reqType
= opcode
;
2029 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2030 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2031 req
->screen
= fbconfig
->screen
;
2032 req
->fbconfig
= fbconfig
->fbconfigID
;
2033 req
->pixmap
= pixmap
;
2034 req
->glxpixmap
= xid
= XAllocID(dpy
);
2042 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2043 GLXFBConfigSGIX config
, int renderType
,
2044 GLXContext shareList
, Bool allowDirect
)
2046 GLXContext gc
= NULL
;
2047 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2048 __GLXscreenConfigs
* psc
;
2051 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2055 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2057 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2058 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2059 allowDirect
, None
, False
, renderType
);
2066 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2069 __GLXdisplayPrivate
*priv
;
2070 __GLXscreenConfigs
*psc
;
2072 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2073 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2074 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2075 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2086 PUBLIC
void glXCushionSGI(Display
*dpy
, Window win
, float cushion
)
2095 ** GLX_SGIX_video_resize
2097 PUBLIC
int glXBindChannelToWindowSGIX(Display
*dpy
, int screen
,
2098 int channel
, Window window
)
2107 PUBLIC
int glXChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2108 int x
, int y
, int w
, int h
)
2120 PUBLIC
int glXQueryChannelRectSGIX(Display
*dpy
, int screen
, int channel
,
2121 int *x
, int *y
, int *w
, int *h
)
2133 int glXQueryChannelDeltasSGIX(Display
*dpy
, int screen
, int channel
,
2134 int *dx
, int *dy
, int *dw
, int *dh
)
2146 PUBLIC
int glXChannelRectSyncSGIX(Display
*dpy
, int screen
,
2147 int channel
, GLenum synctype
)
2157 #if defined(_DM_BUFFER_H_)
2159 PUBLIC Bool
glXAssociateDMPbufferSGIX(Display
*dpy
, GLXPbufferSGIX pbuffer
,
2160 DMparams
*params
, DMbuffer dmbuffer
)
2173 ** GLX_SGIX_swap_group
2175 PUBLIC
void glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2185 ** GLX_SGIX_swap_barrier
2187 PUBLIC
void glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2195 PUBLIC Bool
glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2205 ** GLX_SUN_get_transparent_index
2207 PUBLIC Status
glXGetTransparentIndexSUN(Display
*dpy
, Window overlay
,
2208 Window underlay
, long *pTransparent
)
2213 (void) pTransparent
;
2219 ** GLX_OML_sync_control
2221 PUBLIC Bool
glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2222 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2224 #ifdef GLX_DIRECT_RENDERING
2225 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2227 if ( priv
!= NULL
) {
2229 __DRIdrawable
* const pdraw
= GetDRIDrawable( dpy
, drawable
, & i
);
2230 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2232 assert( (pdraw
== NULL
) || (i
!= -1) );
2233 return ( (pdraw
&& pdraw
->getSBC
&& psc
->driScreen
.getMSC
)
2234 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)
2235 && ((*psc
->driScreen
.getMSC
)( psc
->driScreen
.private, msc
) == 0)
2236 && ((*pdraw
->getSBC
)( dpy
, psc
->driScreen
.private, sbc
) == 0)
2237 && (__glXGetUST( ust
) == 0) );
2251 * Determine the refresh rate of the specified drawable and display.
2253 * \param dpy Display whose refresh rate is to be determined.
2254 * \param drawable Drawable whose refresh rate is to be determined.
2255 * \param numerator Numerator of the refresh rate.
2256 * \param demoninator Denominator of the refresh rate.
2257 * \return If the refresh rate for the specified display and drawable could
2258 * be calculated, True is returned. Otherwise False is returned.
2260 * \note This function is implemented entirely client-side. A lot of other
2261 * functionality is required to export GLX_OML_sync_control, so on
2262 * XFree86 this function can be called for direct-rendering contexts
2263 * when GLX_OML_sync_control appears in the client extension string.
2266 PUBLIC Bool
glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2267 int32_t * numerator
, int32_t * denominator
)
2269 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2270 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2273 if ( priv
!= NULL
) {
2274 XF86VidModeModeLine mode_line
;
2280 GetDRIDrawable( dpy
, drawable
, & screen_num
);
2281 if ( (screen_num
!= -1)
2282 && XF86VidModeQueryVersion( dpy
, & i
, & i
)
2283 && XF86VidModeGetModeLine( dpy
, screen_num
, & dot_clock
,
2285 unsigned n
= dot_clock
* 1000;
2286 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2288 # define V_INTERLACE 0x010
2289 # define V_DBLSCAN 0x020
2291 if ( (mode_line
.flags
& V_INTERLACE
) ) {
2294 else if ( (mode_line
.flags
& V_DBLSCAN
) ) {
2298 /* The OML_sync_control spec requires that if the refresh rate is a
2299 * whole number, that the returned numerator be equal to the refresh
2300 * rate and the denominator be 1.
2303 if ( (n
% d
) == 0 ) {
2308 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2311 /* This is a poor man's way to reduce a fraction. It's far from
2312 * perfect, but it will work well enough for this situation.
2315 for ( i
= 0 ; f
[i
] != 0 ; i
++ ) {
2316 while ( ((n
% f
[i
]) == 0) && ((d
% f
[i
]) == 0) ) {
2340 PUBLIC
int64_t glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2341 int64_t target_msc
, int64_t divisor
,
2344 #ifdef GLX_DIRECT_RENDERING
2346 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2347 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2349 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2350 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2351 * of -1 if the function failed because of errors detected in the input
2354 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2356 if ( divisor
> 0 && remainder
>= divisor
)
2359 if ( (pdraw
!= NULL
) && (pdraw
->swapBuffersMSC
!= NULL
)
2360 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2361 return (*pdraw
->swapBuffersMSC
)(dpy
, pdraw
->private, target_msc
,
2362 divisor
, remainder
);
2375 PUBLIC Bool
glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2376 int64_t target_msc
, int64_t divisor
,
2377 int64_t remainder
, int64_t *ust
,
2378 int64_t *msc
, int64_t *sbc
)
2380 #ifdef GLX_DIRECT_RENDERING
2382 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2383 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2386 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2387 * error", but the return type in the spec is Bool.
2389 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2391 if ( divisor
> 0 && remainder
>= divisor
)
2394 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
)
2395 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2396 ret
= (*pdraw
->waitForMSC
)( dpy
, pdraw
->private, target_msc
,
2397 divisor
, remainder
, msc
, sbc
);
2399 /* __glXGetUST returns zero on success and non-zero on failure.
2400 * This function returns True on success and False on failure.
2402 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2418 PUBLIC Bool
glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2419 int64_t target_sbc
, int64_t *ust
,
2420 int64_t *msc
, int64_t *sbc
)
2422 #ifdef GLX_DIRECT_RENDERING
2424 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2425 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2428 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2429 * error", but the return type in the spec is Bool.
2431 if ( target_sbc
< 0 )
2434 if ( (pdraw
!= NULL
) && (pdraw
->waitForSBC
!= NULL
)
2435 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)) {
2436 ret
= (*pdraw
->waitForSBC
)( dpy
, pdraw
->private, target_sbc
, msc
, sbc
);
2438 /* __glXGetUST returns zero on success and non-zero on failure.
2439 * This function returns True on success and False on failure.
2441 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2456 * GLX_MESA_allocate_memory
2460 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2461 size_t size
, float readFreq
,
2462 float writeFreq
, float priority
)
2464 #ifdef GLX_DIRECT_RENDERING
2465 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2467 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2468 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.allocateMemory
) {
2469 return (*psc
->driScreen
.allocateMemory
)( dpy
, scrn
, size
,
2470 readFreq
, writeFreq
,
2481 #endif /* GLX_DIRECT_RENDERING */
2487 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2489 #ifdef GLX_DIRECT_RENDERING
2490 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2492 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2493 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.freeMemory
) {
2494 (*psc
->driScreen
.freeMemory
)( dpy
, scrn
, pointer
);
2501 #endif /* GLX_DIRECT_RENDERING */
2505 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2506 const void *pointer
)
2508 #ifdef GLX_DIRECT_RENDERING
2509 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2511 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2512 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.memoryOffset
) {
2513 return (*psc
->driScreen
.memoryOffset
)( dpy
, scrn
, pointer
);
2520 #endif /* GLX_DIRECT_RENDERING */
2528 * Mesa extension stubs. These will help reduce portability problems.
2533 * Release all buffers associated with the specified GLX drawable.
2536 * This function was intended for stand-alone Mesa. The issue there is that
2537 * the library doesn't get any notification when a window is closed. In
2538 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2539 * supported, there are 3 different functions to destroy a drawable. It
2540 * should be possible to create GLX protocol (or have it determine which
2541 * protocol to use based on the type of the drawable) to have one function
2542 * do the work of 3. For the direct-rendering case, this function could
2543 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2544 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2545 * would need to be used. This really should be done as part of the new DRI
2548 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2549 * __driGarbageCollectDrawables
2550 * glXDestroyGLXPixmap
2551 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2552 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2554 PUBLIC Bool
glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2562 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2563 Pixmap pixmap
, Colormap cmap
)
2573 PUBLIC
void glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2574 int x
, int y
, int width
, int height
)
2585 PUBLIC Bool
glXSet3DfxModeMESA( int mode
)
2595 * \c strdup is actually not a standard ANSI C or POSIX routine.
2596 * Irix will not define it if ANSI mode is in effect.
2601 __glXstrdup(const char *str
)
2604 copy
= (char *) Xmalloc(strlen(str
) + 1);
2612 ** glXGetProcAddress support
2615 struct name_address_pair
{
2620 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2621 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2623 static const struct name_address_pair GLX_functions
[] = {
2624 /*** GLX_VERSION_1_0 ***/
2625 GLX_FUNCTION( glXChooseVisual
),
2626 GLX_FUNCTION( glXCopyContext
),
2627 GLX_FUNCTION( glXCreateContext
),
2628 GLX_FUNCTION( glXCreateGLXPixmap
),
2629 GLX_FUNCTION( glXDestroyContext
),
2630 GLX_FUNCTION( glXDestroyGLXPixmap
),
2631 GLX_FUNCTION( glXGetConfig
),
2632 GLX_FUNCTION( glXGetCurrentContext
),
2633 GLX_FUNCTION( glXGetCurrentDrawable
),
2634 GLX_FUNCTION( glXIsDirect
),
2635 GLX_FUNCTION( glXMakeCurrent
),
2636 GLX_FUNCTION( glXQueryExtension
),
2637 GLX_FUNCTION( glXQueryVersion
),
2638 GLX_FUNCTION( glXSwapBuffers
),
2639 GLX_FUNCTION( glXUseXFont
),
2640 GLX_FUNCTION( glXWaitGL
),
2641 GLX_FUNCTION( glXWaitX
),
2643 /*** GLX_VERSION_1_1 ***/
2644 GLX_FUNCTION( glXGetClientString
),
2645 GLX_FUNCTION( glXQueryExtensionsString
),
2646 GLX_FUNCTION( glXQueryServerString
),
2648 /*** GLX_VERSION_1_2 ***/
2649 GLX_FUNCTION( glXGetCurrentDisplay
),
2651 /*** GLX_VERSION_1_3 ***/
2652 GLX_FUNCTION( glXChooseFBConfig
),
2653 GLX_FUNCTION( glXCreateNewContext
),
2654 GLX_FUNCTION( glXCreatePbuffer
),
2655 GLX_FUNCTION( glXCreatePixmap
),
2656 GLX_FUNCTION( glXCreateWindow
),
2657 GLX_FUNCTION( glXDestroyPbuffer
),
2658 GLX_FUNCTION( glXDestroyPixmap
),
2659 GLX_FUNCTION( glXDestroyWindow
),
2660 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2661 GLX_FUNCTION( glXGetFBConfigAttrib
),
2662 GLX_FUNCTION( glXGetFBConfigs
),
2663 GLX_FUNCTION( glXGetSelectedEvent
),
2664 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2665 GLX_FUNCTION( glXMakeContextCurrent
),
2666 GLX_FUNCTION( glXQueryContext
),
2667 GLX_FUNCTION( glXQueryDrawable
),
2668 GLX_FUNCTION( glXSelectEvent
),
2670 /*** GLX_SGI_swap_control ***/
2671 GLX_FUNCTION( glXSwapIntervalSGI
),
2673 /*** GLX_SGI_video_sync ***/
2674 GLX_FUNCTION( glXGetVideoSyncSGI
),
2675 GLX_FUNCTION( glXWaitVideoSyncSGI
),
2677 /*** GLX_SGI_make_current_read ***/
2678 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2679 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2681 /*** GLX_SGIX_video_source ***/
2683 GLX_FUNCTION( glXCreateGLXVideoSourceSGIX
),
2684 GLX_FUNCTION( glXDestroyGLXVideoSourceSGIX
),
2687 /*** GLX_EXT_import_context ***/
2688 GLX_FUNCTION( glXFreeContextEXT
),
2689 GLX_FUNCTION( glXGetContextIDEXT
),
2690 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2691 GLX_FUNCTION( glXImportContextEXT
),
2692 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2694 /*** GLX_SGIX_fbconfig ***/
2695 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2696 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2697 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2698 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2699 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2700 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2702 /*** GLX_SGIX_pbuffer ***/
2703 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2704 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2705 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2706 GLX_FUNCTION( glXSelectEventSGIX
),
2707 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2709 /*** GLX_SGI_cushion ***/
2710 GLX_FUNCTION( glXCushionSGI
),
2712 /*** GLX_SGIX_video_resize ***/
2713 GLX_FUNCTION( glXBindChannelToWindowSGIX
),
2714 GLX_FUNCTION( glXChannelRectSGIX
),
2715 GLX_FUNCTION( glXQueryChannelRectSGIX
),
2716 GLX_FUNCTION( glXQueryChannelDeltasSGIX
),
2717 GLX_FUNCTION( glXChannelRectSyncSGIX
),
2719 /*** GLX_SGIX_dmbuffer **/
2720 #if defined(_DM_BUFFER_H_)
2721 GLX_FUNCTION( glXAssociateDMPbufferSGIX
),
2724 /*** GLX_SGIX_swap_group ***/
2725 GLX_FUNCTION( glXJoinSwapGroupSGIX
),
2727 /*** GLX_SGIX_swap_barrier ***/
2728 GLX_FUNCTION( glXBindSwapBarrierSGIX
),
2729 GLX_FUNCTION( glXQueryMaxSwapBarriersSGIX
),
2731 /*** GLX_SUN_get_transparent_index ***/
2732 GLX_FUNCTION( glXGetTransparentIndexSUN
),
2734 /*** GLX_MESA_allocate_memory ***/
2735 GLX_FUNCTION( glXAllocateMemoryMESA
),
2736 GLX_FUNCTION( glXFreeMemoryMESA
),
2737 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2739 /*** GLX_MESA_copy_sub_buffer ***/
2740 GLX_FUNCTION( glXCopySubBufferMESA
),
2742 /*** GLX_MESA_pixmap_colormap ***/
2743 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2745 /*** GLX_MESA_release_buffers ***/
2746 GLX_FUNCTION( glXReleaseBuffersMESA
),
2748 /*** GLX_MESA_set_3dfx_mode ***/
2749 GLX_FUNCTION( glXSet3DfxModeMESA
),
2751 /*** GLX_MESA_swap_control ***/
2752 GLX_FUNCTION( glXSwapIntervalMESA
),
2753 GLX_FUNCTION( glXGetSwapIntervalMESA
),
2755 /*** GLX_MESA_swap_frame_usage ***/
2756 GLX_FUNCTION( glXBeginFrameTrackingMESA
),
2757 GLX_FUNCTION( glXEndFrameTrackingMESA
),
2758 GLX_FUNCTION( glXGetFrameUsageMESA
),
2759 GLX_FUNCTION( glXQueryFrameTrackingMESA
),
2761 /*** GLX_ARB_get_proc_address ***/
2762 GLX_FUNCTION( glXGetProcAddressARB
),
2765 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2767 /*** GLX_OML_sync_control ***/
2768 GLX_FUNCTION( glXWaitForSbcOML
),
2769 GLX_FUNCTION( glXWaitForMscOML
),
2770 GLX_FUNCTION( glXSwapBuffersMscOML
),
2771 GLX_FUNCTION( glXGetMscRateOML
),
2772 GLX_FUNCTION( glXGetSyncValuesOML
),
2774 #ifdef GLX_DIRECT_RENDERING
2775 /*** DRI configuration ***/
2776 GLX_FUNCTION( glXGetScreenDriver
),
2777 GLX_FUNCTION( glXGetDriverConfig
),
2780 { NULL
, NULL
} /* end of list */
2784 static const GLvoid
*
2785 get_glx_proc_address(const char *funcName
)
2789 /* try static functions */
2790 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2791 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2792 return GLX_functions
[i
].Address
;
2800 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2801 * \c glXGetProcAddress.
2803 * \param procName Name of a GL or GLX function.
2804 * \returns A pointer to the named function
2806 * \sa glXGetProcAddress
2808 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2810 typedef void (*gl_function
)( void );
2814 /* Search the table of GLX and internal functions first. If that
2815 * fails and the supplied name could be a valid core GL name, try
2816 * searching the core GL function table. This check is done to prevent
2817 * DRI based drivers from searching the core GL function table for
2818 * internal API functions.
2821 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2822 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2823 && (procName
[2] != 'X') ) {
2824 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2831 * Get the address of a named GL function. This is the GLX 1.4 name for
2832 * \c glXGetProcAddressARB.
2834 * \param procName Name of a GL or GLX function.
2835 * \returns A pointer to the named function
2837 * \sa glXGetProcAddressARB
2839 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2840 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2841 __attribute__ ((alias ("glXGetProcAddressARB")));
2844 return glXGetProcAddressARB(procName
);
2846 #endif /* __GNUC__ */
2849 #ifdef GLX_DIRECT_RENDERING
2851 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
2852 * might be used by the DRI drivers to determine how new libGL is at runtime.
2853 * Drivers should not call this function directly. They should instead use
2854 * \c glXGetProcAddress to obtain a pointer to the function.
2856 * \returns An 8-digit decimal number representing the internal libGL API in
2859 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
2861 * \since Internal API version 20021121.
2863 int __glXGetInternalVersion(void)
2866 * 20021121 - Initial version
2867 * 20021128 - Added __glXWindowExists() function
2868 * 20021207 - Added support for dynamic GLX extensions,
2869 * GLX_SGI_swap_control, GLX_SGI_video_sync,
2870 * GLX_OML_sync_control, and GLX_MESA_swap_control.
2871 * Never officially released. Do NOT test against
2872 * this version. Use 20030317 instead.
2873 * 20030317 - Added support GLX_SGIX_fbconfig,
2874 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
2875 * GLX_{ARB,SGIS}_multisample, and
2876 * GLX_SGIX_visual_select_group.
2877 * 20030606 - Added support for GLX_SGI_make_current_read.
2878 * 20030813 - Made support for dynamic extensions multi-head aware.
2879 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
2880 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
2882 * 20031201 - Added support for the first round of DRI interface changes.
2883 * Do NOT test against this version! It has binary
2884 * compatibility bugs, use 20040317 instead.
2885 * 20040317 - Added the 'mode' field to __DRIcontextRec.
2886 * 20040415 - Added support for bindContext3 and unbindContext3.
2887 * 20040602 - Add __glXGetDrawableInfo. I though that was there
2889 * 20050727 - Gut all the old interfaces. This breaks compatability with
2890 * any DRI driver built to any previous version.
2897 static Bool windowExistsFlag
;
2899 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
2901 if (xerr
->error_code
== BadWindow
) {
2902 windowExistsFlag
= GL_FALSE
;
2908 * Determine if a window associated with a \c GLXDrawable exists on the
2909 * X-server. This function is not used internally by libGL. It is provided
2910 * as a utility function for DRI drivers.
2911 * Drivers should not call this function directly. They should instead use
2912 * \c glXGetProcAddress to obtain a pointer to the function.
2914 * \param dpy Display associated with the drawable to be queried.
2915 * \param draw \c GLXDrawable to test.
2917 * \returns \c GL_TRUE if a window exists that is associated with \c draw,
2918 * otherwise \c GL_FALSE is returned.
2920 * \warning This function is not currently thread-safe.
2922 * \sa glXGetProcAddress
2924 * \since Internal API version 20021128.
2926 Bool
__glXWindowExists(Display
*dpy
, GLXDrawable draw
)
2928 XWindowAttributes xwa
;
2929 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
2931 XSync(dpy
, GL_FALSE
);
2932 windowExistsFlag
= GL_TRUE
;
2933 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
2934 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
2935 XSetErrorHandler(oldXErrorHandler
);
2936 return windowExistsFlag
;
2941 * Get the unadjusted system time (UST). Currently, the UST is measured in
2942 * microseconds since Epoc. The actual resolution of the UST may vary from
2943 * system to system, and the units may vary from release to release.
2944 * Drivers should not call this function directly. They should instead use
2945 * \c glXGetProcAddress to obtain a pointer to the function.
2947 * \param ust Location to store the 64-bit UST
2948 * \returns Zero on success or a negative errno value on failure.
2950 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2952 * \since Internal API version 20030317.
2954 int __glXGetUST( int64_t * ust
)
2958 if ( ust
== NULL
) {
2962 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2963 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2969 #endif /* GLX_DIRECT_RENDERING */