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"
49 #ifdef GLX_DIRECT_RENDERING
50 #include "indirect_init.h"
51 #include "xf86vmode.h"
54 #include "glxextensions.h"
55 #include "glcontextmodes.h"
60 #define GLX_PREFIX(x) x
61 #endif /* IN_DOXYGEN */
63 static const char __glXGLXClientVendorName
[] = "SGI";
64 static const char __glXGLXClientVersion
[] = "1.4";
67 /****************************************************************************/
69 * Get the __DRIdrawable for the drawable associated with a GLXContext
71 * \param dpy The display associated with \c drawable.
72 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
73 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
74 * the drawable is not associated with a direct-rendering context.
77 #ifdef GLX_DIRECT_RENDERING
78 static __DRIdrawable
*
79 GetDRIDrawable( Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
81 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
83 if ( (priv
!= NULL
) && (priv
->driDisplay
.private != NULL
) ) {
84 const unsigned screen_count
= ScreenCount(dpy
);
87 for ( i
= 0 ; i
< screen_count
; i
++ ) {
88 __DRIscreen
* const psc
= &priv
->screenConfigs
[i
].driScreen
;
89 __DRIdrawable
* const pdraw
= (psc
->private != NULL
)
90 ? (*psc
->getDrawable
)(dpy
, drawable
, psc
->private) : NULL
;
92 if ( pdraw
!= NULL
) {
93 if ( scrn_num
!= NULL
) {
107 * Get the GLX per-screen data structure associated with a GLX context.
109 * \param dpy Display for which the GLX per-screen information is to be
111 * \param scrn Screen on \c dpy for which the GLX per-screen information is
113 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
114 * specify a valid GLX screen, or NULL otherwise.
116 * \todo Should this function validate that \c scrn is within the screen
117 * number range for \c dpy?
120 static __GLXscreenConfigs
*
121 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
123 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
125 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
130 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
131 __GLXscreenConfigs
** ppsc
)
133 /* Initialize the extension, if needed . This has the added value
134 * of initializing/allocating the display private
138 return GLX_NO_EXTENSION
;
141 *ppriv
= __glXInitialize(dpy
);
142 if ( *ppriv
== NULL
) {
143 return GLX_NO_EXTENSION
;
146 /* Check screen number to see if its valid */
147 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
148 return GLX_BAD_SCREEN
;
151 /* Check to see if the GL is supported on this screen */
152 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
153 if ( (*ppsc
)->configs
== NULL
) {
154 /* No support for GL on this screen regardless of visual */
155 return GLX_BAD_VISUAL
;
163 * Determine if a \c GLXFBConfig supplied by the application is valid.
165 * \param dpy Application supplied \c Display pointer.
166 * \param config Application supplied \c GLXFBConfig.
168 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
169 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
172 static __GLcontextModes
*
173 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
175 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
176 const unsigned num_screens
= ScreenCount(dpy
);
178 const __GLcontextModes
* modes
;
181 if ( priv
!= NULL
) {
182 for ( i
= 0 ; i
< num_screens
; i
++ ) {
183 for ( modes
= priv
->screenConfigs
[i
].configs
185 ; modes
= modes
->next
) {
186 if ( modes
== (__GLcontextModes
*) config
) {
187 return (__GLcontextModes
*) config
;
198 * \todo It should be possible to move the allocate of \c client_state_private
199 * later in the function for direct-rendering contexts. Direct-rendering
200 * contexts don't need to track client state, so they don't need that memory
203 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
204 * function called \c __glXAllocateClientState that allocates the memory and
205 * does all the initialization (including the pixel pack / unpack).
208 GLXContext
AllocateGLXContext( Display
*dpy
)
213 __GLXattribute
*state
;
218 opcode
= __glXSetupForCommand(dpy
);
223 /* Allocate our context record */
224 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
229 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
231 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
237 gc
->client_state_private
= state
;
238 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
239 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
242 ** Create a temporary buffer to hold GLX rendering commands. The size
243 ** of the buffer is selected so that the maximum number of GLX rendering
244 ** commands can fit in a single X packet and still have room in the X
245 ** packet for the GLXRenderReq header.
248 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
249 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
251 Xfree(gc
->client_state_private
);
255 gc
->bufSize
= bufSize
;
257 /* Fill in the new context */
258 gc
->renderMode
= GL_RENDER
;
260 state
->storePack
.alignment
= 4;
261 state
->storeUnpack
.alignment
= 4;
263 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
266 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
267 ** Other code uses the fastImageUnpack bit, but it is never set
270 gc
->fastImageUnpack
= GL_FALSE
;
271 gc
->fillImage
= __glFillImage
;
272 gc
->isDirect
= GL_FALSE
;
274 gc
->bufEnd
= gc
->buf
+ bufSize
;
277 ** Set limit register so that there will be one command per packet
281 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
284 gc
->majorOpcode
= opcode
;
287 ** Constrain the maximum drawing command size allowed to be
288 ** transfered using the X_GLXRender protocol request. First
289 ** constrain by a software limit, then constrain by the protocl
292 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
293 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
295 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
296 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
298 gc
->maxSmallRenderCommandSize
= bufSize
;
304 * Create a new context. Exactly one of \c vis and \c fbconfig should be
307 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
308 * SGIX_fbconfig protocol be used?
309 * \param renderType For FBConfigs, what is the rendering type?
313 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
314 const __GLcontextModes
* const fbconfig
,
315 GLXContext shareList
,
316 Bool allowDirect
, GLXContextID contextID
,
317 Bool use_glx_1_3
, int renderType
)
324 gc
= AllocateGLXContext(dpy
);
328 if (None
== contextID
) {
329 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
332 #ifdef GLX_DIRECT_RENDERING
334 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
335 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
336 const __GLcontextModes
* mode
;
338 /* The value of fbconfig cannot change because it is tested
339 * later in the function.
341 if ( fbconfig
== NULL
) {
342 /* FIXME: Is it possible for the __GLcontextModes structure
343 * FIXME: to not be found?
345 mode
= _gl_context_modes_find_visual( psc
->configs
,
347 assert( mode
!= NULL
);
348 assert( mode
->screen
== screen
);
354 if (psc
&& psc
->driScreen
.private) {
355 void * const shared
= (shareList
!= NULL
)
356 ? shareList
->driContext
.private : NULL
;
357 gc
->driContext
.private =
358 (*psc
->driScreen
.createNewContext
)( dpy
, mode
, renderType
,
361 if (gc
->driContext
.private) {
362 gc
->isDirect
= GL_TRUE
;
363 gc
->screen
= mode
->screen
;
364 gc
->vid
= mode
->visualID
;
365 gc
->fbconfigID
= mode
->fbconfigID
;
366 gc
->driContext
.mode
= mode
;
373 if ( fbconfig
== NULL
) {
374 xGLXCreateContextReq
*req
;
376 /* Send the glXCreateContext request */
377 GetReq(GLXCreateContext
,req
);
378 req
->reqType
= gc
->majorOpcode
;
379 req
->glxCode
= X_GLXCreateContext
;
380 req
->context
= gc
->xid
= XAllocID(dpy
);
381 req
->visual
= vis
->visualid
;
382 req
->screen
= vis
->screen
;
383 req
->shareList
= shareList
? shareList
->xid
: None
;
384 req
->isDirect
= gc
->isDirect
;
386 else if ( use_glx_1_3
) {
387 xGLXCreateNewContextReq
*req
;
389 /* Send the glXCreateNewContext request */
390 GetReq(GLXCreateNewContext
,req
);
391 req
->reqType
= gc
->majorOpcode
;
392 req
->glxCode
= X_GLXCreateNewContext
;
393 req
->context
= gc
->xid
= XAllocID(dpy
);
394 req
->fbconfig
= fbconfig
->fbconfigID
;
395 req
->screen
= fbconfig
->screen
;
396 req
->renderType
= renderType
;
397 req
->shareList
= shareList
? shareList
->xid
: None
;
398 req
->isDirect
= gc
->isDirect
;
401 xGLXVendorPrivateWithReplyReq
*vpreq
;
402 xGLXCreateContextWithConfigSGIXReq
*req
;
404 /* Send the glXCreateNewContext request */
405 GetReqExtra(GLXVendorPrivateWithReply
,
406 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
407 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
408 req
->reqType
= gc
->majorOpcode
;
409 req
->glxCode
= X_GLXVendorPrivateWithReply
;
410 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
411 req
->context
= gc
->xid
= XAllocID(dpy
);
412 req
->fbconfig
= fbconfig
->fbconfigID
;
413 req
->screen
= fbconfig
->screen
;
414 req
->renderType
= renderType
;
415 req
->shareList
= shareList
? shareList
->xid
: None
;
416 req
->isDirect
= gc
->isDirect
;
421 gc
->imported
= GL_FALSE
;
425 gc
->imported
= GL_TRUE
;
431 PUBLIC GLXContext
GLX_PREFIX(glXCreateContext
)(Display
*dpy
, XVisualInfo
*vis
,
432 GLXContext shareList
,
435 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
439 void __glXFreeContext(__GLXcontext
*gc
)
441 if (gc
->vendor
) XFree((char *) gc
->vendor
);
442 if (gc
->renderer
) XFree((char *) gc
->renderer
);
443 if (gc
->version
) XFree((char *) gc
->version
);
444 if (gc
->extensions
) XFree((char *) gc
->extensions
);
445 __glFreeAttributeState(gc
);
446 XFree((char *) gc
->buf
);
447 Xfree((char *) gc
->client_state_private
);
453 ** Destroy the named context
456 DestroyContext(Display
*dpy
, GLXContext gc
)
458 xGLXDestroyContextReq
*req
;
463 opcode
= __glXSetupForCommand(dpy
);
464 if (!opcode
|| !gc
) {
470 imported
= gc
->imported
;
473 #ifdef GLX_DIRECT_RENDERING
474 /* Destroy the direct rendering context */
476 if (gc
->driContext
.private) {
477 (*gc
->driContext
.destroyContext
)(dpy
, gc
->screen
,
478 gc
->driContext
.private);
479 gc
->driContext
.private = NULL
;
484 if (gc
->currentDpy
) {
485 /* Have to free later cuz it's in use now */
488 /* Destroy the handle if not current to anybody */
490 __glXFreeContext(gc
);
495 ** This dpy also created the server side part of the context.
496 ** Send the glXDestroyContext request.
499 GetReq(GLXDestroyContext
,req
);
500 req
->reqType
= opcode
;
501 req
->glxCode
= X_GLXDestroyContext
;
508 PUBLIC
void GLX_PREFIX(glXDestroyContext
)(Display
*dpy
, GLXContext gc
)
510 DestroyContext(dpy
, gc
);
514 ** Return the major and minor version #s for the GLX extension
516 PUBLIC Bool
GLX_PREFIX(glXQueryVersion
)(Display
*dpy
, int *major
, int *minor
)
518 __GLXdisplayPrivate
*priv
;
520 /* Init the extension. This fetches the major and minor version. */
521 priv
= __glXInitialize(dpy
);
522 if (!priv
) return GL_FALSE
;
524 if (major
) *major
= priv
->majorVersion
;
525 if (minor
) *minor
= priv
->minorVersion
;
530 ** Query the existance of the GLX extension
532 PUBLIC Bool
GLX_PREFIX(glXQueryExtension
)(Display
*dpy
, int *errorBase
,
535 int major_op
, erb
, evb
;
538 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
540 if (errorBase
) *errorBase
= erb
;
541 if (eventBase
) *eventBase
= evb
;
547 ** Put a barrier in the token stream that forces the GL to finish its
548 ** work before X can proceed.
550 PUBLIC
void GLX_PREFIX(glXWaitGL
)(void)
553 GLXContext gc
= __glXGetCurrentContext();
554 Display
*dpy
= gc
->currentDpy
;
558 /* Flush any pending commands out */
559 __glXFlushRenderBuffer(gc
, gc
->pc
);
561 #ifdef GLX_DIRECT_RENDERING
563 /* This bit of ugliness unwraps the glFinish function */
572 /* Send the glXWaitGL request */
574 GetReq(GLXWaitGL
,req
);
575 req
->reqType
= gc
->majorOpcode
;
576 req
->glxCode
= X_GLXWaitGL
;
577 req
->contextTag
= gc
->currentContextTag
;
583 ** Put a barrier in the token stream that forces X to finish its
584 ** work before GL can proceed.
586 PUBLIC
void GLX_PREFIX(glXWaitX
)(void)
589 GLXContext gc
= __glXGetCurrentContext();
590 Display
*dpy
= gc
->currentDpy
;
594 /* Flush any pending commands out */
595 __glXFlushRenderBuffer(gc
, gc
->pc
);
597 #ifdef GLX_DIRECT_RENDERING
605 ** Send the glXWaitX request.
608 GetReq(GLXWaitX
,req
);
609 req
->reqType
= gc
->majorOpcode
;
610 req
->glxCode
= X_GLXWaitX
;
611 req
->contextTag
= gc
->currentContextTag
;
616 PUBLIC
void GLX_PREFIX(glXUseXFont
)(Font font
, int first
, int count
,
619 xGLXUseXFontReq
*req
;
620 GLXContext gc
= __glXGetCurrentContext();
621 Display
*dpy
= gc
->currentDpy
;
625 /* Flush any pending commands out */
626 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
628 #ifdef GLX_DIRECT_RENDERING
630 DRI_glXUseXFont(font
, first
, count
, listBase
);
635 /* Send the glXUseFont request */
637 GetReq(GLXUseXFont
,req
);
638 req
->reqType
= gc
->majorOpcode
;
639 req
->glxCode
= X_GLXUseXFont
;
640 req
->contextTag
= gc
->currentContextTag
;
644 req
->listBase
= listBase
;
649 /************************************************************************/
652 ** Copy the source context to the destination context using the
655 PUBLIC
void GLX_PREFIX(glXCopyContext
)(Display
*dpy
, GLXContext source
,
656 GLXContext dest
, unsigned long mask
)
658 xGLXCopyContextReq
*req
;
659 GLXContext gc
= __glXGetCurrentContext();
663 opcode
= __glXSetupForCommand(dpy
);
668 #ifdef GLX_DIRECT_RENDERING
670 /* NOT_DONE: This does not work yet */
675 ** If the source is the current context, send its tag so that the context
676 ** can be flushed before the copy.
678 if (source
== gc
&& dpy
== gc
->currentDpy
) {
679 tag
= gc
->currentContextTag
;
684 /* Send the glXCopyContext request */
686 GetReq(GLXCopyContext
,req
);
687 req
->reqType
= opcode
;
688 req
->glxCode
= X_GLXCopyContext
;
689 req
->source
= source
? source
->xid
: None
;
690 req
->dest
= dest
? dest
->xid
: None
;
692 req
->contextTag
= tag
;
699 * Determine if a context uses direct rendering.
701 * \param dpy Display where the context was created.
702 * \param contextID ID of the context to be tested.
704 * \returns \c GL_TRUE if the context is direct rendering or not.
706 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
708 xGLXIsDirectReq
*req
;
709 xGLXIsDirectReply reply
;
712 opcode
= __glXSetupForCommand(dpy
);
717 /* Send the glXIsDirect request */
719 GetReq(GLXIsDirect
,req
);
720 req
->reqType
= opcode
;
721 req
->glxCode
= X_GLXIsDirect
;
722 req
->context
= contextID
;
723 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
727 return reply
.isDirect
;
732 * Shouldn't this function \b always return \c GL_FALSE when
733 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
734 * the GLX protocol here at all?
736 PUBLIC Bool
GLX_PREFIX(glXIsDirect
)(Display
*dpy
, GLXContext gc
)
740 #ifdef GLX_DIRECT_RENDERING
741 } else if (gc
->isDirect
) {
745 return __glXIsDirect(dpy
, gc
->xid
);
748 PUBLIC GLXPixmap
GLX_PREFIX(glXCreateGLXPixmap
)(Display
*dpy
, XVisualInfo
*vis
,
751 xGLXCreateGLXPixmapReq
*req
;
755 opcode
= __glXSetupForCommand(dpy
);
760 /* Send the glXCreateGLXPixmap request */
762 GetReq(GLXCreateGLXPixmap
,req
);
763 req
->reqType
= opcode
;
764 req
->glxCode
= X_GLXCreateGLXPixmap
;
765 req
->screen
= vis
->screen
;
766 req
->visual
= vis
->visualid
;
767 req
->pixmap
= pixmap
;
768 req
->glxpixmap
= xid
= XAllocID(dpy
);
775 ** Destroy the named pixmap
777 PUBLIC
void GLX_PREFIX(glXDestroyGLXPixmap
)(Display
*dpy
, GLXPixmap glxpixmap
)
779 xGLXDestroyGLXPixmapReq
*req
;
782 opcode
= __glXSetupForCommand(dpy
);
787 /* Send the glXDestroyGLXPixmap request */
789 GetReq(GLXDestroyGLXPixmap
,req
);
790 req
->reqType
= opcode
;
791 req
->glxCode
= X_GLXDestroyGLXPixmap
;
792 req
->glxpixmap
= glxpixmap
;
797 PUBLIC
void GLX_PREFIX(glXSwapBuffers
)(Display
*dpy
, GLXDrawable drawable
)
799 xGLXSwapBuffersReq
*req
;
803 #ifdef GLX_DIRECT_RENDERING
804 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, NULL
);
806 if ( pdraw
!= NULL
) {
807 (*pdraw
->swapBuffers
)(dpy
, pdraw
->private);
812 opcode
= __glXSetupForCommand(dpy
);
818 ** The calling thread may or may not have a current context. If it
819 ** does, send the context tag so the server can do a flush.
821 gc
= __glXGetCurrentContext();
822 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
823 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
824 tag
= gc
->currentContextTag
;
829 /* Send the glXSwapBuffers request */
831 GetReq(GLXSwapBuffers
,req
);
832 req
->reqType
= opcode
;
833 req
->glxCode
= X_GLXSwapBuffers
;
834 req
->drawable
= drawable
;
835 req
->contextTag
= tag
;
843 ** Return configuration information for the given display, screen and
844 ** visual combination.
846 PUBLIC
int GLX_PREFIX(glXGetConfig
)(Display
*dpy
, XVisualInfo
*vis
,
847 int attribute
, int *value_return
)
849 __GLXdisplayPrivate
*priv
;
850 __GLXscreenConfigs
*psc
;
853 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
854 if ( status
== Success
) {
855 const __GLcontextModes
* const modes
= _gl_context_modes_find_visual(
856 psc
->configs
, vis
->visualid
);
858 /* Lookup attribute after first finding a match on the visual */
859 if ( modes
!= NULL
) {
860 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
863 status
= GLX_BAD_VISUAL
;
867 ** If we can't find the config for this visual, this visual is not
868 ** supported by the OpenGL implementation on the server.
870 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
871 *value_return
= GL_FALSE
;
878 /************************************************************************/
881 init_fbconfig_for_chooser( __GLcontextModes
* config
,
882 GLboolean fbconfig_style_tags
)
884 memset( config
, 0, sizeof( __GLcontextModes
) );
885 config
->visualID
= (XID
) GLX_DONT_CARE
;
886 config
->visualType
= GLX_DONT_CARE
;
888 /* glXChooseFBConfig specifies different defaults for these two than
891 if ( fbconfig_style_tags
) {
892 config
->rgbMode
= GL_TRUE
;
893 config
->doubleBufferMode
= GLX_DONT_CARE
;
896 config
->visualRating
= GLX_DONT_CARE
;
897 config
->transparentPixel
= GLX_NONE
;
898 config
->transparentRed
= GLX_DONT_CARE
;
899 config
->transparentGreen
= GLX_DONT_CARE
;
900 config
->transparentBlue
= GLX_DONT_CARE
;
901 config
->transparentAlpha
= GLX_DONT_CARE
;
902 config
->transparentIndex
= GLX_DONT_CARE
;
904 config
->drawableType
= GLX_WINDOW_BIT
;
905 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
906 config
->xRenderable
= GLX_DONT_CARE
;
907 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
909 config
->swapMethod
= GLX_DONT_CARE
;
912 #define MATCH_DONT_CARE( param ) \
914 if ( (a-> param != GLX_DONT_CARE) \
915 && (a-> param != b-> param) ) { \
920 #define MATCH_MINIMUM( param ) \
922 if ( (a-> param != GLX_DONT_CARE) \
923 && (a-> param > b-> param) ) { \
928 #define MATCH_EXACT( param ) \
930 if ( a-> param != b-> param) { \
936 * Determine if two GLXFBConfigs are compatible.
938 * \param a Application specified config to test.
939 * \param b Server specified config to test against \c a.
942 fbconfigs_compatible( const __GLcontextModes
* const a
,
943 const __GLcontextModes
* const b
)
945 MATCH_DONT_CARE( doubleBufferMode
);
946 MATCH_DONT_CARE( visualType
);
947 MATCH_DONT_CARE( visualRating
);
948 MATCH_DONT_CARE( xRenderable
);
949 MATCH_DONT_CARE( fbconfigID
);
950 MATCH_DONT_CARE( swapMethod
);
952 MATCH_MINIMUM( rgbBits
);
953 MATCH_MINIMUM( numAuxBuffers
);
954 MATCH_MINIMUM( redBits
);
955 MATCH_MINIMUM( greenBits
);
956 MATCH_MINIMUM( blueBits
);
957 MATCH_MINIMUM( alphaBits
);
958 MATCH_MINIMUM( depthBits
);
959 MATCH_MINIMUM( stencilBits
);
960 MATCH_MINIMUM( accumRedBits
);
961 MATCH_MINIMUM( accumGreenBits
);
962 MATCH_MINIMUM( accumBlueBits
);
963 MATCH_MINIMUM( accumAlphaBits
);
964 MATCH_MINIMUM( sampleBuffers
);
965 MATCH_MINIMUM( maxPbufferWidth
);
966 MATCH_MINIMUM( maxPbufferHeight
);
967 MATCH_MINIMUM( maxPbufferPixels
);
968 MATCH_MINIMUM( samples
);
970 MATCH_DONT_CARE( stereoMode
);
971 MATCH_EXACT( level
);
973 if ( ((a
->drawableType
& b
->drawableType
) == 0)
974 || ((a
->renderType
& b
->renderType
) == 0) ) {
979 /* There is a bug in a few of the XFree86 DDX drivers. They contain
980 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
981 * Technically speaking, it is a bug in the DDX driver, but there is
982 * enough of an installed base to work around the problem here. In any
983 * case, 0 is not a valid value of the transparent type, so we'll treat 0
984 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
985 * 0 from the server to be a match to maintain backward compatibility with
986 * the (broken) drivers.
989 if ( a
->transparentPixel
!= GLX_DONT_CARE
990 && a
->transparentPixel
!= 0 ) {
991 if ( a
->transparentPixel
== GLX_NONE
) {
992 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
995 MATCH_EXACT( transparentPixel
);
998 switch ( a
->transparentPixel
) {
999 case GLX_TRANSPARENT_RGB
:
1000 MATCH_DONT_CARE( transparentRed
);
1001 MATCH_DONT_CARE( transparentGreen
);
1002 MATCH_DONT_CARE( transparentBlue
);
1003 MATCH_DONT_CARE( transparentAlpha
);
1006 case GLX_TRANSPARENT_INDEX
:
1007 MATCH_DONT_CARE( transparentIndex
);
1019 /* There's some trickly language in the GLX spec about how this is supposed
1020 * to work. Basically, if a given component size is either not specified
1021 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1022 * Well, that's really hard to do with the code as-is. This behavior is
1023 * closer to correct, but still not technically right.
1025 #define PREFER_LARGER_OR_ZERO(comp) \
1027 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1028 if ( ((*a)-> comp) == 0 ) { \
1031 else if ( ((*b)-> comp) == 0 ) { \
1035 return ((*b)-> comp) - ((*a)-> comp) ; \
1040 #define PREFER_LARGER(comp) \
1042 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1043 return ((*b)-> comp) - ((*a)-> comp) ; \
1047 #define PREFER_SMALLER(comp) \
1049 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1050 return ((*a)-> comp) - ((*b)-> comp) ; \
1055 * Compare two GLXFBConfigs. This function is intended to be used as the
1056 * compare function passed in to qsort.
1058 * \returns If \c a is a "better" config, according to the specification of
1059 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1060 * better, then a number greater than zero is return. If both are
1061 * equal, zero is returned.
1062 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1065 fbconfig_compare( const __GLcontextModes
* const * const a
,
1066 const __GLcontextModes
* const * const b
)
1068 /* The order of these comparisons must NOT change. It is defined by
1069 * the GLX 1.3 spec and ARB_multisample.
1072 PREFER_SMALLER( visualSelectGroup
);
1074 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1075 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1076 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1078 PREFER_SMALLER( visualRating
);
1080 /* This isn't quite right. It is supposed to compare the sum of the
1081 * components the user specifically set minimums for.
1083 PREFER_LARGER_OR_ZERO( redBits
);
1084 PREFER_LARGER_OR_ZERO( greenBits
);
1085 PREFER_LARGER_OR_ZERO( blueBits
);
1086 PREFER_LARGER_OR_ZERO( alphaBits
);
1088 PREFER_SMALLER( rgbBits
);
1090 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1091 /* Prefer single-buffer.
1093 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1096 PREFER_SMALLER( numAuxBuffers
);
1098 PREFER_LARGER_OR_ZERO( depthBits
);
1099 PREFER_SMALLER( stencilBits
);
1101 /* This isn't quite right. It is supposed to compare the sum of the
1102 * components the user specifically set minimums for.
1104 PREFER_LARGER_OR_ZERO( accumRedBits
);
1105 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1106 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1107 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1109 PREFER_SMALLER( visualType
);
1111 /* None of the multisample specs say where this comparison should happen,
1112 * so I put it near the end.
1114 PREFER_SMALLER( sampleBuffers
);
1115 PREFER_SMALLER( samples
);
1117 /* None of the pbuffer or fbconfig specs say that this comparison needs
1118 * to happen at all, but it seems like it should.
1120 PREFER_LARGER( maxPbufferWidth
);
1121 PREFER_LARGER( maxPbufferHeight
);
1122 PREFER_LARGER( maxPbufferPixels
);
1129 * Selects and sorts a subset of the supplied configs based on the attributes.
1130 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1131 * and \c glXChooseFBConfigSGIX.
1133 * \param configs Array of pointers to possible configs. The elements of
1134 * this array that do not meet the criteria will be set to
1135 * NULL. The remaining elements will be sorted according to
1136 * the various visual / FBConfig selection rules.
1137 * \param num_configs Number of elements in the \c configs array.
1138 * \param attribList Attributes used select from \c configs. This array is
1139 * terminated by a \c None tag. The array can either take
1140 * the form expected by \c glXChooseVisual (where boolean
1141 * tags do not have a value) or by \c glXChooseFBConfig
1142 * (where every tag has a value).
1143 * \param fbconfig_style_tags Selects whether \c attribList is in
1144 * \c glXChooseVisual style or
1145 * \c glXChooseFBConfig style.
1146 * \returns The number of valid elements left in \c configs.
1148 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1151 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1152 const int *attribList
, GLboolean fbconfig_style_tags
)
1154 __GLcontextModes test_config
;
1158 /* This is a fairly direct implementation of the selection method
1159 * described by GLX_SGIX_fbconfig. Start by culling out all the
1160 * configs that are not compatible with the selected parameter
1164 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1165 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1166 (const INT32
*) attribList
,
1167 GL_TRUE
, fbconfig_style_tags
);
1170 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1171 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1172 configs
[ base
] = configs
[ i
];
1181 if ( base
< num_configs
) {
1182 (void) memset( & configs
[ base
], 0,
1183 sizeof( void * ) * (num_configs
- base
) );
1186 /* After the incompatible configs are removed, the resulting
1187 * list is sorted according to the rules set out in the various
1191 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1192 (int (*)(const void*, const void*)) fbconfig_compare
);
1200 ** Return the visual that best matches the template. Return None if no
1201 ** visual matches the template.
1203 PUBLIC XVisualInfo
*GLX_PREFIX(glXChooseVisual
)(Display
*dpy
, int screen
,
1206 XVisualInfo
*visualList
= NULL
;
1207 __GLXdisplayPrivate
*priv
;
1208 __GLXscreenConfigs
*psc
;
1209 __GLcontextModes test_config
;
1210 __GLcontextModes
*modes
;
1211 const __GLcontextModes
*best_config
= NULL
;
1214 ** Get a list of all visuals, return if list is empty
1216 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1222 ** Build a template from the defaults and the attribute list
1223 ** Free visual list and return if an unexpected token is encountered
1225 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1226 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1227 (const INT32
*) attribList
,
1228 GL_TRUE
, GL_FALSE
);
1231 ** Eliminate visuals that don't meet minimum requirements
1232 ** Compute a score for those that do
1233 ** Remember which visual, if any, got the highest score
1235 for ( modes
= psc
->configs
; modes
!= NULL
; modes
= modes
->next
) {
1236 if ( fbconfigs_compatible( & test_config
, modes
)
1237 && ((best_config
== NULL
)
1238 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1239 best_config
= modes
;
1244 ** If no visual is acceptable, return None
1245 ** Otherwise, create an XVisualInfo list with just the selected X visual
1248 if (best_config
!= NULL
) {
1249 XVisualInfo visualTemplate
;
1252 visualTemplate
.screen
= screen
;
1253 visualTemplate
.visualid
= best_config
->visualID
;
1254 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1255 &visualTemplate
, &i
);
1262 PUBLIC
const char *GLX_PREFIX(glXQueryExtensionsString
)( Display
*dpy
,
1265 __GLXscreenConfigs
*psc
;
1266 __GLXdisplayPrivate
*priv
;
1268 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1272 if (!psc
->effectiveGLXexts
) {
1273 if (!psc
->serverGLXexts
) {
1274 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1275 X_GLXQueryServerString
,
1276 screen
, GLX_EXTENSIONS
);
1279 __glXCalculateUsableExtensions(psc
,
1280 #ifdef GLX_DIRECT_RENDERING
1281 (priv
->driDisplay
.private != NULL
),
1285 priv
->minorVersion
);
1288 return psc
->effectiveGLXexts
;
1291 PUBLIC
const char *GLX_PREFIX(glXGetClientString
)( Display
*dpy
, int name
)
1295 return (__glXGLXClientVendorName
);
1297 return (__glXGLXClientVersion
);
1298 case GLX_EXTENSIONS
:
1299 return (__glXGetClientExtensions());
1305 PUBLIC
const char *GLX_PREFIX(glXQueryServerString
)( Display
*dpy
, int screen
,
1308 __GLXscreenConfigs
*psc
;
1309 __GLXdisplayPrivate
*priv
;
1313 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1319 str
= & priv
->serverGLXvendor
;
1322 str
= & priv
->serverGLXversion
;
1324 case GLX_EXTENSIONS
:
1325 str
= & psc
->serverGLXexts
;
1331 if ( *str
== NULL
) {
1332 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1333 X_GLXQueryServerString
, screen
, name
);
1339 void __glXClientInfo ( Display
*dpy
, int opcode
)
1341 xGLXClientInfoReq
*req
;
1343 char * ext_str
= __glXGetClientGLExtensionString();
1345 /* Send the glXClientInfo request */
1347 GetReq(GLXClientInfo
,req
);
1348 req
->reqType
= opcode
;
1349 req
->glxCode
= X_GLXClientInfo
;
1350 req
->major
= GLX_MAJOR_VERSION
;
1351 req
->minor
= GLX_MINOR_VERSION
;
1353 size
= strlen( ext_str
) + 1;
1354 req
->length
+= (size
+ 3) >> 2;
1355 req
->numbytes
= size
;
1356 Data(dpy
, ext_str
, size
);
1366 ** EXT_import_context
1369 PUBLIC Display
*glXGetCurrentDisplay(void)
1371 GLXContext gc
= __glXGetCurrentContext();
1372 if (NULL
== gc
) return NULL
;
1373 return gc
->currentDpy
;
1376 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1377 glXGetCurrentDisplay
)
1380 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1383 * \param dpy Display where \c ctx was created.
1384 * \param ctx Context to query.
1385 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1386 * or zero if the request failed due to internal problems (i.e.,
1387 * unable to allocate temporary memory, etc.)
1390 * This function dynamically determines whether to use the EXT_import_context
1391 * version of the protocol or the GLX 1.3 version of the protocol.
1393 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1395 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1396 xGLXQueryContextReply reply
;
1402 return GLX_BAD_CONTEXT
;
1404 opcode
= __glXSetupForCommand(dpy
);
1409 /* Send the glXQueryContextInfoEXT request */
1412 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1413 xGLXQueryContextReq
*req
;
1415 GetReq(GLXQueryContext
, req
);
1417 req
->reqType
= opcode
;
1418 req
->glxCode
= X_GLXQueryContext
;
1419 req
->context
= (unsigned int)(ctx
->xid
);
1422 xGLXVendorPrivateReq
*vpreq
;
1423 xGLXQueryContextInfoEXTReq
*req
;
1425 GetReqExtra( GLXVendorPrivate
,
1426 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1428 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1429 req
->reqType
= opcode
;
1430 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1431 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1432 req
->context
= (unsigned int)(ctx
->xid
);
1435 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1437 numValues
= reply
.n
;
1440 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1444 int *propList
, *pProp
;
1448 nPropListBytes
= numValues
<< 3;
1449 propList
= (int *) Xmalloc(nPropListBytes
);
1450 if (NULL
== propList
) {
1453 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1455 for (i
=0; i
< numValues
; i
++) {
1457 case GLX_SHARE_CONTEXT_EXT
:
1458 ctx
->share_xid
= *pProp
++;
1460 case GLX_VISUAL_ID_EXT
:
1461 ctx
->vid
= *pProp
++;
1464 ctx
->screen
= *pProp
++;
1466 case GLX_FBCONFIG_ID
:
1467 ctx
->fbconfigID
= *pProp
++;
1469 case GLX_RENDER_TYPE
:
1470 ctx
->renderType
= *pProp
++;
1477 Xfree((char *)propList
);
1487 GLX_PREFIX(glXQueryContext
)(Display
*dpy
, GLXContext ctx
,
1488 int attribute
, int *value
)
1492 /* get the information from the server if we don't have it already */
1493 if (!ctx
->isDirect
&& (ctx
->vid
== None
)) {
1494 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1495 if (Success
!= retVal
) return retVal
;
1497 switch (attribute
) {
1498 case GLX_SHARE_CONTEXT_EXT
:
1499 *value
= (int)(ctx
->share_xid
);
1501 case GLX_VISUAL_ID_EXT
:
1502 *value
= (int)(ctx
->vid
);
1505 *value
= (int)(ctx
->screen
);
1507 case GLX_FBCONFIG_ID
:
1508 *value
= (int)(ctx
->fbconfigID
);
1510 case GLX_RENDER_TYPE
:
1511 *value
= (int)(ctx
->renderType
);
1514 return GLX_BAD_ATTRIBUTE
;
1519 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1520 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1521 (dpy
, ctx
, attribute
, value
),
1524 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1529 PUBLIC GLXContext
GLX_PREFIX(glXImportContextEXT
)(Display
*dpy
,
1530 GLXContextID contextID
)
1534 if (contextID
== None
) {
1537 if (__glXIsDirect(dpy
, contextID
)) {
1541 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1543 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1550 PUBLIC
void GLX_PREFIX(glXFreeContextEXT
)(Display
*dpy
, GLXContext ctx
)
1552 DestroyContext(dpy
, ctx
);
1558 * GLX 1.3 functions - these are just stubs for now!
1561 PUBLIC GLXFBConfig
*GLX_PREFIX(glXChooseFBConfig
)(Display
*dpy
, int screen
,
1562 const int *attribList
,
1565 __GLcontextModes
** config_list
;
1569 config_list
= (__GLcontextModes
**)
1570 GLX_PREFIX(glXGetFBConfigs
)( dpy
, screen
, & list_size
);
1572 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1573 list_size
= choose_visual( config_list
, list_size
, attribList
,
1575 if ( list_size
== 0 ) {
1576 XFree( config_list
);
1581 *nitems
= list_size
;
1582 return (GLXFBConfig
*) config_list
;
1586 PUBLIC GLXContext
GLX_PREFIX(glXCreateNewContext
)(Display
*dpy
,
1589 GLXContext shareList
,
1592 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1593 allowDirect
, None
, True
, renderType
);
1597 PUBLIC GLXDrawable
GLX_PREFIX(glXGetCurrentReadDrawable
)(void)
1599 GLXContext gc
= __glXGetCurrentContext();
1600 return gc
->currentReadable
;
1604 PUBLIC GLXFBConfig
*GLX_PREFIX(glXGetFBConfigs
)(Display
*dpy
, int screen
,
1607 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1608 __GLcontextModes
** config
= NULL
;
1611 if ( (priv
->screenConfigs
!= NULL
)
1612 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1613 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1614 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1615 unsigned num_configs
= 0;
1616 __GLcontextModes
* modes
;
1619 for ( modes
= priv
->screenConfigs
[screen
].configs
1621 ; modes
= modes
->next
) {
1622 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1627 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1629 if ( config
!= NULL
) {
1630 *nelements
= num_configs
;
1632 for ( modes
= priv
->screenConfigs
[screen
].configs
1634 ; modes
= modes
->next
) {
1640 return (GLXFBConfig
*) config
;
1644 PUBLIC
int GLX_PREFIX(glXGetFBConfigAttrib
)(Display
*dpy
, GLXFBConfig config
,
1645 int attribute
, int *value
)
1647 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1649 return (modes
!= NULL
)
1650 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1655 PUBLIC XVisualInfo
*GLX_PREFIX(glXGetVisualFromFBConfig
)(Display
*dpy
,
1658 XVisualInfo visualTemplate
;
1659 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1663 ** Get a list of all visuals, return if list is empty
1665 visualTemplate
.visualid
= fbconfig
->visualID
;
1666 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1671 ** GLX_SGI_make_current_read
1674 PUBLIC
GLX_ALIAS(GLXDrawable
, glXGetCurrentReadDrawableSGI
, (void), (),
1675 glXGetCurrentReadDrawable
)
1679 ** GLX_SGI_swap_control
1681 PUBLIC
int GLX_PREFIX(glXSwapIntervalSGI
)(int interval
)
1683 xGLXVendorPrivateReq
*req
;
1684 GLXContext gc
= __glXGetCurrentContext();
1686 CARD32
* interval_ptr
;
1690 return GLX_BAD_CONTEXT
;
1693 if ( interval
<= 0 ) {
1694 return GLX_BAD_VALUE
;
1697 #ifdef GLX_DIRECT_RENDERING
1698 if ( gc
->isDirect
) {
1699 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1701 __DRIdrawable
* const pdraw
= GetDRIDrawable( gc
->currentDpy
,
1702 gc
->currentDrawable
,
1704 if ( __glXExtensionBitIsEnabled( psc
, SGI_swap_control_bit
)
1705 && (pdraw
!= NULL
) ) {
1706 pdraw
->swap_interval
= interval
;
1710 return GLX_BAD_CONTEXT
;
1714 dpy
= gc
->currentDpy
;
1715 opcode
= __glXSetupForCommand(dpy
);
1720 /* Send the glXSwapIntervalSGI request */
1722 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1723 req
->reqType
= opcode
;
1724 req
->glxCode
= X_GLXVendorPrivate
;
1725 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1726 req
->contextTag
= gc
->currentContextTag
;
1728 interval_ptr
= (CARD32
*) req
+ 1;
1729 *interval_ptr
= interval
;
1740 ** GLX_MESA_swap_control
1742 PUBLIC GLint
GLX_PREFIX(glXSwapIntervalMESA
)(unsigned interval
)
1744 #ifdef GLX_DIRECT_RENDERING
1745 GLXContext gc
= __glXGetCurrentContext();
1747 if ( interval
< 0 ) {
1748 return GLX_BAD_VALUE
;
1751 if ( (gc
!= NULL
) && gc
->isDirect
) {
1752 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1755 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1756 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1757 __DRIdrawable
* const pdraw
=
1758 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1759 gc
->currentDrawable
,
1760 psc
->driScreen
.private);
1761 if ( pdraw
!= NULL
) {
1762 pdraw
->swap_interval
= interval
;
1771 return GLX_BAD_CONTEXT
;
1774 PUBLIC GLint
GLX_PREFIX(glXGetSwapIntervalMESA
)( void )
1776 #ifdef GLX_DIRECT_RENDERING
1777 GLXContext gc
= __glXGetCurrentContext();
1779 if ( (gc
!= NULL
) && gc
->isDirect
) {
1780 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1783 if ( (psc
!= NULL
) && (psc
->driScreen
.private != NULL
)
1784 && __glXExtensionBitIsEnabled( psc
, MESA_swap_control_bit
) ) {
1785 __DRIdrawable
* const pdraw
=
1786 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1787 gc
->currentDrawable
,
1788 psc
->driScreen
.private);
1789 if ( pdraw
!= NULL
) {
1790 return pdraw
->swap_interval
;
1801 ** GLX_MESA_swap_frame_usage
1804 PUBLIC GLint
GLX_PREFIX(glXBeginFrameTrackingMESA
)(Display
*dpy
,
1805 GLXDrawable drawable
)
1807 int status
= GLX_BAD_CONTEXT
;
1808 #ifdef GLX_DIRECT_RENDERING
1810 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1811 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1813 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1814 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1815 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_TRUE
);
1825 PUBLIC GLint
GLX_PREFIX(glXEndFrameTrackingMESA
)(Display
*dpy
,
1826 GLXDrawable drawable
)
1828 int status
= GLX_BAD_CONTEXT
;
1829 #ifdef GLX_DIRECT_RENDERING
1831 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1832 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1834 if ( (pdraw
!= NULL
) && (pdraw
->frameTracking
!= NULL
)
1835 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1836 status
= pdraw
->frameTracking( dpy
, pdraw
->private, GL_FALSE
);
1846 PUBLIC GLint
GLX_PREFIX(glXGetFrameUsageMESA
)(Display
*dpy
,
1847 GLXDrawable drawable
,
1850 int status
= GLX_BAD_CONTEXT
;
1851 #ifdef GLX_DIRECT_RENDERING
1853 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1854 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1856 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1857 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1858 int64_t sbc
, missedFrames
;
1859 float lastMissedUsage
;
1861 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, &sbc
,
1862 &missedFrames
, &lastMissedUsage
,
1874 PUBLIC GLint
GLX_PREFIX(glXQueryFrameTrackingMESA
)(Display
*dpy
,
1875 GLXDrawable drawable
,
1877 int64_t *missedFrames
,
1878 GLfloat
*lastMissedUsage
)
1880 int status
= GLX_BAD_CONTEXT
;
1881 #ifdef GLX_DIRECT_RENDERING
1883 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1884 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1886 if ( (pdraw
!= NULL
) && (pdraw
->queryFrameTracking
!= NULL
)
1887 && __glXExtensionBitIsEnabled( psc
, MESA_swap_frame_usage_bit
) ) {
1890 status
= pdraw
->queryFrameTracking( dpy
, pdraw
->private, sbc
,
1891 missedFrames
, lastMissedUsage
,
1898 (void) missedFrames
;
1899 (void) lastMissedUsage
;
1906 ** GLX_SGI_video_sync
1908 PUBLIC
int GLX_PREFIX(glXGetVideoSyncSGI
)(unsigned int *count
)
1910 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1911 * FIXME: there should be a GLX encoding for this call. I can find no
1912 * FIXME: documentation for the GLX encoding.
1914 #ifdef GLX_DIRECT_RENDERING
1915 GLXContext gc
= __glXGetCurrentContext();
1918 if ( (gc
!= NULL
) && gc
->isDirect
) {
1919 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1921 if ( __glXExtensionBitIsEnabled( psc
, SGI_video_sync_bit
)
1922 && psc
->driScreen
.private && psc
->driScreen
.getMSC
) {
1926 ret
= psc
->driScreen
.getMSC( psc
->driScreen
.private, & temp
);
1927 *count
= (unsigned) temp
;
1928 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1934 return GLX_BAD_CONTEXT
;
1937 PUBLIC
int GLX_PREFIX(glXWaitVideoSyncSGI
)(int divisor
, int remainder
,
1938 unsigned int *count
)
1940 #ifdef GLX_DIRECT_RENDERING
1941 GLXContext gc
= __glXGetCurrentContext();
1943 if ( divisor
<= 0 || remainder
< 0 )
1944 return GLX_BAD_VALUE
;
1946 if ( (gc
!= NULL
) && gc
->isDirect
) {
1947 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1949 if ( __glXExtensionBitIsEnabled( psc
, SGI_video_sync_bit
)
1950 && psc
->driScreen
.private ) {
1951 __DRIdrawable
* const pdraw
=
1952 (*psc
->driScreen
.getDrawable
)(gc
->currentDpy
,
1953 gc
->currentDrawable
,
1954 psc
->driScreen
.private);
1955 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
) ) {
1960 ret
= (*pdraw
->waitForMSC
)( gc
->currentDpy
, pdraw
->private,
1961 0, divisor
, remainder
,
1963 *count
= (unsigned) msc
;
1964 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1971 return GLX_BAD_CONTEXT
;
1976 ** GLX_SGIS_video_source
1980 PUBLIC GLXVideoSourceSGIX
GLX_PREFIX(glXCreateGLXVideoSourceSGIX
)(Display
*dpy
,
1981 int screen
, VLServer server
, VLPath path
,
1982 int nodeClass
, VLNode drainNode
)
1993 PUBLIC
void GLX_PREFIX(glXDestroyGLXVideoSourceSGIX
)(Display
*dpy
,
1994 GLXVideoSourceSGIX src
)
2004 ** GLX_SGIX_fbconfig
2005 ** Many of these functions are aliased to GLX 1.3 entry points in the
2006 ** GLX_functions table.
2009 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2010 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2011 (dpy
, config
, attribute
, value
),
2012 glXGetFBConfigAttrib
)
2014 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2015 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
2016 (dpy
, screen
, attrib_list
, nelements
),
2019 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2020 (Display
* dpy
, GLXFBConfigSGIX config
),
2022 glXGetVisualFromFBConfig
)
2024 PUBLIC GLXPixmap
GLX_PREFIX(glXCreateGLXPixmapWithConfigSGIX
)(Display
*dpy
,
2025 GLXFBConfigSGIX config
, Pixmap pixmap
)
2027 xGLXVendorPrivateWithReplyReq
*vpreq
;
2028 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2029 GLXPixmap xid
= None
;
2031 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2032 __GLXscreenConfigs
* psc
;
2035 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2039 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2041 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2042 opcode
= __glXSetupForCommand(dpy
);
2047 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2049 GetReqExtra(GLXVendorPrivateWithReply
,
2050 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2051 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2052 req
->reqType
= opcode
;
2053 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2054 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2055 req
->screen
= fbconfig
->screen
;
2056 req
->fbconfig
= fbconfig
->fbconfigID
;
2057 req
->pixmap
= pixmap
;
2058 req
->glxpixmap
= xid
= XAllocID(dpy
);
2066 PUBLIC GLXContext
GLX_PREFIX(glXCreateContextWithConfigSGIX
)(Display
*dpy
,
2067 GLXFBConfigSGIX config
, int renderType
,
2068 GLXContext shareList
, Bool allowDirect
)
2070 GLXContext gc
= NULL
;
2071 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2072 __GLXscreenConfigs
* psc
;
2075 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2079 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2081 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2082 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2083 allowDirect
, None
, False
, renderType
);
2090 PUBLIC GLXFBConfigSGIX
GLX_PREFIX(glXGetFBConfigFromVisualSGIX
)(Display
*dpy
,
2093 __GLXdisplayPrivate
*priv
;
2094 __GLXscreenConfigs
*psc
;
2096 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2097 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2098 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2099 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2110 PUBLIC
void GLX_PREFIX(glXCushionSGI
)(Display
*dpy
, Window win
, float cushion
)
2119 ** GLX_SGIX_video_resize
2121 PUBLIC
int GLX_PREFIX(glXBindChannelToWindowSGIX
)(Display
*dpy
, int screen
,
2122 int channel
, Window window
)
2131 PUBLIC
int GLX_PREFIX(glXChannelRectSGIX
)(Display
*dpy
, int screen
, int channel
,
2132 int x
, int y
, int w
, int h
)
2144 PUBLIC
int GLX_PREFIX(glXQueryChannelRectSGIX
)(Display
*dpy
, int screen
,
2145 int channel
, int *x
, int *y
,
2158 int GLX_PREFIX(glXQueryChannelDeltasSGIX
)(Display
*dpy
, int screen
, int channel
,
2159 int *dx
, int *dy
, int *dw
, int *dh
)
2171 PUBLIC
int GLX_PREFIX(glXChannelRectSyncSGIX
)(Display
*dpy
, int screen
,
2172 int channel
, GLenum synctype
)
2182 #if defined(_DM_BUFFER_H_)
2184 PUBLIC Bool
GLX_PREFIX(glXAssociateDMPbufferSGIX
)(Display
*dpy
,
2185 GLXPbufferSGIX pbuffer
,
2200 ** GLX_SGIX_swap_group
2202 PUBLIC
void GLX_PREFIX(glXJoinSwapGroupSGIX
)(Display
*dpy
, GLXDrawable drawable
,
2212 ** GLX_SGIX_swap_barrier
2214 PUBLIC
void GLX_PREFIX(glXBindSwapBarrierSGIX
)(Display
*dpy
,
2215 GLXDrawable drawable
,
2223 PUBLIC Bool
GLX_PREFIX(glXQueryMaxSwapBarriersSGIX
)(Display
*dpy
, int screen
,
2234 ** GLX_SUN_get_transparent_index
2236 PUBLIC Status
GLX_PREFIX(glXGetTransparentIndexSUN
)(Display
*dpy
,
2244 (void) pTransparent
;
2250 ** GLX_OML_sync_control
2252 PUBLIC Bool
GLX_PREFIX(glXGetSyncValuesOML
)(Display
*dpy
, GLXDrawable drawable
,
2253 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2255 #ifdef GLX_DIRECT_RENDERING
2256 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2258 if ( priv
!= NULL
) {
2260 __DRIdrawable
* const pdraw
= GetDRIDrawable( dpy
, drawable
, & i
);
2261 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2263 assert( (pdraw
== NULL
) || (i
!= -1) );
2264 return ( (pdraw
&& pdraw
->getSBC
&& psc
->driScreen
.getMSC
)
2265 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)
2266 && ((*psc
->driScreen
.getMSC
)( psc
->driScreen
.private, msc
) == 0)
2267 && ((*pdraw
->getSBC
)( dpy
, psc
->driScreen
.private, sbc
) == 0)
2268 && (__glXGetUST( ust
) == 0) );
2282 * Determine the refresh rate of the specified drawable and display.
2284 * \param dpy Display whose refresh rate is to be determined.
2285 * \param drawable Drawable whose refresh rate is to be determined.
2286 * \param numerator Numerator of the refresh rate.
2287 * \param demoninator Denominator of the refresh rate.
2288 * \return If the refresh rate for the specified display and drawable could
2289 * be calculated, True is returned. Otherwise False is returned.
2291 * \note This function is implemented entirely client-side. A lot of other
2292 * functionality is required to export GLX_OML_sync_control, so on
2293 * XFree86 this function can be called for direct-rendering contexts
2294 * when GLX_OML_sync_control appears in the client extension string.
2297 PUBLIC Bool
GLX_PREFIX(glXGetMscRateOML
)(Display
* dpy
, GLXDrawable drawable
,
2298 int32_t * numerator
, int32_t * denominator
)
2300 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2301 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2304 if ( priv
!= NULL
) {
2305 XF86VidModeModeLine mode_line
;
2311 GetDRIDrawable( dpy
, drawable
, & screen_num
);
2312 if ( (screen_num
!= -1)
2313 && XF86VidModeQueryVersion( dpy
, & i
, & i
)
2314 && XF86VidModeGetModeLine( dpy
, screen_num
, & dot_clock
,
2316 unsigned n
= dot_clock
* 1000;
2317 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2319 # define V_INTERLACE 0x010
2320 # define V_DBLSCAN 0x020
2322 if ( (mode_line
.flags
& V_INTERLACE
) ) {
2325 else if ( (mode_line
.flags
& V_DBLSCAN
) ) {
2329 /* The OML_sync_control spec requires that if the refresh rate is a
2330 * whole number, that the returned numerator be equal to the refresh
2331 * rate and the denominator be 1.
2334 if ( (n
% d
) == 0 ) {
2339 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2342 /* This is a poor man's way to reduce a fraction. It's far from
2343 * perfect, but it will work well enough for this situation.
2346 for ( i
= 0 ; f
[i
] != 0 ; i
++ ) {
2347 while ( ((n
% f
[i
]) == 0) && ((d
% f
[i
]) == 0) ) {
2371 PUBLIC
int64_t GLX_PREFIX(glXSwapBuffersMscOML
)(Display
*dpy
,
2372 GLXDrawable drawable
,
2377 #ifdef GLX_DIRECT_RENDERING
2379 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2380 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2382 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2383 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2384 * of -1 if the function failed because of errors detected in the input
2387 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2389 if ( divisor
> 0 && remainder
>= divisor
)
2392 if ( (pdraw
!= NULL
) && (pdraw
->swapBuffersMSC
!= NULL
)
2393 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2394 return (*pdraw
->swapBuffersMSC
)(dpy
, pdraw
->private, target_msc
,
2395 divisor
, remainder
);
2408 PUBLIC Bool
GLX_PREFIX(glXWaitForMscOML
)(Display
* dpy
, GLXDrawable drawable
,
2409 int64_t target_msc
, int64_t divisor
,
2410 int64_t remainder
, int64_t *ust
,
2411 int64_t *msc
, int64_t *sbc
)
2413 #ifdef GLX_DIRECT_RENDERING
2415 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2416 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2419 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2420 * error", but the return type in the spec is Bool.
2422 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2424 if ( divisor
> 0 && remainder
>= divisor
)
2427 if ( (pdraw
!= NULL
) && (pdraw
->waitForMSC
!= NULL
)
2428 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
) ) {
2429 ret
= (*pdraw
->waitForMSC
)( dpy
, pdraw
->private, target_msc
,
2430 divisor
, remainder
, msc
, sbc
);
2432 /* __glXGetUST returns zero on success and non-zero on failure.
2433 * This function returns True on success and False on failure.
2435 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2451 PUBLIC Bool
GLX_PREFIX(glXWaitForSbcOML
)(Display
* dpy
, GLXDrawable drawable
,
2452 int64_t target_sbc
, int64_t *ust
,
2453 int64_t *msc
, int64_t *sbc
)
2455 #ifdef GLX_DIRECT_RENDERING
2457 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2458 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2461 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2462 * error", but the return type in the spec is Bool.
2464 if ( target_sbc
< 0 )
2467 if ( (pdraw
!= NULL
) && (pdraw
->waitForSBC
!= NULL
)
2468 && __glXExtensionBitIsEnabled( psc
, OML_sync_control_bit
)) {
2469 ret
= (*pdraw
->waitForSBC
)( dpy
, pdraw
->private, target_sbc
, msc
, sbc
);
2471 /* __glXGetUST returns zero on success and non-zero on failure.
2472 * This function returns True on success and False on failure.
2474 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2489 * GLX_MESA_allocate_memory
2493 PUBLIC
void *GLX_PREFIX(glXAllocateMemoryMESA
)(Display
*dpy
, int scrn
,
2494 size_t size
, float readFreq
,
2495 float writeFreq
, float priority
)
2497 #ifdef GLX_DIRECT_RENDERING
2498 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2500 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2501 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.allocateMemory
) {
2502 return (*psc
->driScreen
.allocateMemory
)( dpy
, scrn
, size
,
2503 readFreq
, writeFreq
,
2514 #endif /* GLX_DIRECT_RENDERING */
2520 PUBLIC
void GLX_PREFIX(glXFreeMemoryMESA
)(Display
*dpy
, int scrn
, void *pointer
)
2522 #ifdef GLX_DIRECT_RENDERING
2523 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2525 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2526 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.freeMemory
) {
2527 (*psc
->driScreen
.freeMemory
)( dpy
, scrn
, pointer
);
2534 #endif /* GLX_DIRECT_RENDERING */
2538 PUBLIC GLuint
GLX_PREFIX(glXGetMemoryOffsetMESA
)( Display
*dpy
, int scrn
,
2539 const void *pointer
)
2541 #ifdef GLX_DIRECT_RENDERING
2542 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2544 if ( __glXExtensionBitIsEnabled( psc
, MESA_allocate_memory_bit
) ) {
2545 if (psc
&& psc
->driScreen
.private && psc
->driScreen
.memoryOffset
) {
2546 return (*psc
->driScreen
.memoryOffset
)( dpy
, scrn
, pointer
);
2553 #endif /* GLX_DIRECT_RENDERING */
2561 * Mesa extension stubs. These will help reduce portability problems.
2566 * Release all buffers associated with the specified GLX drawable.
2569 * This function was intended for stand-alone Mesa. The issue there is that
2570 * the library doesn't get any notification when a window is closed. In
2571 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2572 * supported, there are 3 different functions to destroy a drawable. It
2573 * should be possible to create GLX protocol (or have it determine which
2574 * protocol to use based on the type of the drawable) to have one function
2575 * do the work of 3. For the direct-rendering case, this function could
2576 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2577 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2578 * would need to be used. This really should be done as part of the new DRI
2581 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2582 * __driGarbageCollectDrawables
2583 * glXDestroyGLXPixmap
2584 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2585 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2587 PUBLIC Bool
GLX_PREFIX(glXReleaseBuffersMESA
)( Display
*dpy
, GLXDrawable d
)
2595 PUBLIC GLXPixmap
GLX_PREFIX(glXCreateGLXPixmapMESA
)( Display
*dpy
,
2596 XVisualInfo
*visual
,
2608 PUBLIC
void GLX_PREFIX(glXCopySubBufferMESA
)(Display
*dpy
, GLXDrawable drawable
,
2610 int width
, int height
)
2621 PUBLIC Bool
GLX_PREFIX(glXSet3DfxModeMESA
)( int mode
)
2631 * \c strdup is actually not a standard ANSI C or POSIX routine.
2632 * Irix will not define it if ANSI mode is in effect.
2637 __glXstrdup(const char *str
)
2640 copy
= (char *) Xmalloc(strlen(str
) + 1);
2648 ** glXGetProcAddress support
2651 struct name_address_pair
{
2656 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2657 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2659 static const struct name_address_pair GLX_functions
[] = {
2660 /*** GLX_VERSION_1_0 ***/
2661 GLX_FUNCTION( glXChooseVisual
),
2662 GLX_FUNCTION( glXCopyContext
),
2663 GLX_FUNCTION( glXCreateContext
),
2664 GLX_FUNCTION( glXCreateGLXPixmap
),
2665 GLX_FUNCTION( glXDestroyContext
),
2666 GLX_FUNCTION( glXDestroyGLXPixmap
),
2667 GLX_FUNCTION( glXGetConfig
),
2668 GLX_FUNCTION( glXGetCurrentContext
),
2669 GLX_FUNCTION( glXGetCurrentDrawable
),
2670 GLX_FUNCTION( glXIsDirect
),
2671 GLX_FUNCTION( glXMakeCurrent
),
2672 GLX_FUNCTION( glXQueryExtension
),
2673 GLX_FUNCTION( glXQueryVersion
),
2674 GLX_FUNCTION( glXSwapBuffers
),
2675 GLX_FUNCTION( glXUseXFont
),
2676 GLX_FUNCTION( glXWaitGL
),
2677 GLX_FUNCTION( glXWaitX
),
2679 /*** GLX_VERSION_1_1 ***/
2680 GLX_FUNCTION( glXGetClientString
),
2681 GLX_FUNCTION( glXQueryExtensionsString
),
2682 GLX_FUNCTION( glXQueryServerString
),
2684 /*** GLX_VERSION_1_2 ***/
2685 GLX_FUNCTION( glXGetCurrentDisplay
),
2687 /*** GLX_VERSION_1_3 ***/
2688 GLX_FUNCTION( glXChooseFBConfig
),
2689 GLX_FUNCTION( glXCreateNewContext
),
2690 GLX_FUNCTION( glXCreatePbuffer
),
2691 GLX_FUNCTION( glXCreatePixmap
),
2692 GLX_FUNCTION( glXCreateWindow
),
2693 GLX_FUNCTION( glXDestroyPbuffer
),
2694 GLX_FUNCTION( glXDestroyPixmap
),
2695 GLX_FUNCTION( glXDestroyWindow
),
2696 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2697 GLX_FUNCTION( glXGetFBConfigAttrib
),
2698 GLX_FUNCTION( glXGetFBConfigs
),
2699 GLX_FUNCTION( glXGetSelectedEvent
),
2700 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2701 GLX_FUNCTION( glXMakeContextCurrent
),
2702 GLX_FUNCTION( glXQueryContext
),
2703 GLX_FUNCTION( glXQueryDrawable
),
2704 GLX_FUNCTION( glXSelectEvent
),
2706 /*** GLX_SGI_swap_control ***/
2707 GLX_FUNCTION( glXSwapIntervalSGI
),
2709 /*** GLX_SGI_video_sync ***/
2710 GLX_FUNCTION( glXGetVideoSyncSGI
),
2711 GLX_FUNCTION( glXWaitVideoSyncSGI
),
2713 /*** GLX_SGI_make_current_read ***/
2714 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2715 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2717 /*** GLX_SGIX_video_source ***/
2719 GLX_FUNCTION( glXCreateGLXVideoSourceSGIX
),
2720 GLX_FUNCTION( glXDestroyGLXVideoSourceSGIX
),
2723 /*** GLX_EXT_import_context ***/
2724 GLX_FUNCTION( glXFreeContextEXT
),
2725 GLX_FUNCTION( glXGetContextIDEXT
),
2726 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2727 GLX_FUNCTION( glXImportContextEXT
),
2728 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2730 /*** GLX_SGIX_fbconfig ***/
2731 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2732 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2733 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2734 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2735 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2736 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2738 /*** GLX_SGIX_pbuffer ***/
2739 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2740 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2741 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2742 GLX_FUNCTION( glXSelectEventSGIX
),
2743 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2745 /*** GLX_SGI_cushion ***/
2746 GLX_FUNCTION( glXCushionSGI
),
2748 /*** GLX_SGIX_video_resize ***/
2749 GLX_FUNCTION( glXBindChannelToWindowSGIX
),
2750 GLX_FUNCTION( glXChannelRectSGIX
),
2751 GLX_FUNCTION( glXQueryChannelRectSGIX
),
2752 GLX_FUNCTION( glXQueryChannelDeltasSGIX
),
2753 GLX_FUNCTION( glXChannelRectSyncSGIX
),
2755 /*** GLX_SGIX_dmbuffer **/
2756 #if defined(_DM_BUFFER_H_)
2757 GLX_FUNCTION( glXAssociateDMPbufferSGIX
),
2760 /*** GLX_SGIX_swap_group ***/
2761 GLX_FUNCTION( glXJoinSwapGroupSGIX
),
2763 /*** GLX_SGIX_swap_barrier ***/
2764 GLX_FUNCTION( glXBindSwapBarrierSGIX
),
2765 GLX_FUNCTION( glXQueryMaxSwapBarriersSGIX
),
2767 /*** GLX_SUN_get_transparent_index ***/
2768 GLX_FUNCTION( glXGetTransparentIndexSUN
),
2770 /*** GLX_MESA_allocate_memory ***/
2771 GLX_FUNCTION( glXAllocateMemoryMESA
),
2772 GLX_FUNCTION( glXFreeMemoryMESA
),
2773 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2775 /*** GLX_MESA_copy_sub_buffer ***/
2776 GLX_FUNCTION( glXCopySubBufferMESA
),
2778 /*** GLX_MESA_pixmap_colormap ***/
2779 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2781 /*** GLX_MESA_release_buffers ***/
2782 GLX_FUNCTION( glXReleaseBuffersMESA
),
2784 /*** GLX_MESA_set_3dfx_mode ***/
2785 GLX_FUNCTION( glXSet3DfxModeMESA
),
2787 /*** GLX_MESA_swap_control ***/
2788 GLX_FUNCTION( glXSwapIntervalMESA
),
2789 GLX_FUNCTION( glXGetSwapIntervalMESA
),
2791 /*** GLX_MESA_swap_frame_usage ***/
2792 GLX_FUNCTION( glXBeginFrameTrackingMESA
),
2793 GLX_FUNCTION( glXEndFrameTrackingMESA
),
2794 GLX_FUNCTION( glXGetFrameUsageMESA
),
2795 GLX_FUNCTION( glXQueryFrameTrackingMESA
),
2797 /*** GLX_ARB_get_proc_address ***/
2798 GLX_FUNCTION( glXGetProcAddressARB
),
2801 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2803 /*** GLX_OML_sync_control ***/
2804 GLX_FUNCTION( glXWaitForSbcOML
),
2805 GLX_FUNCTION( glXWaitForMscOML
),
2806 GLX_FUNCTION( glXSwapBuffersMscOML
),
2807 GLX_FUNCTION( glXGetMscRateOML
),
2808 GLX_FUNCTION( glXGetSyncValuesOML
),
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
;
2835 #ifndef GLX_BUILT_IN_XMESA
2837 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2838 * \c glXGetProcAddress.
2840 * \param procName Name of a GL or GLX function.
2841 * \returns A pointer to the named function
2843 * \sa glXGetProcAddress
2845 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2847 typedef void (*gl_function
)( void );
2851 /* Search the table of GLX and internal functions first. If that
2852 * fails and the supplied name could be a valid core GL name, try
2853 * searching the core GL function table. This check is done to prevent
2854 * DRI based drivers from searching the core GL function table for
2855 * internal API functions.
2858 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2859 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2860 && (procName
[2] != 'X') ) {
2861 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2868 * Get the address of a named GL function. This is the GLX 1.4 name for
2869 * \c glXGetProcAddressARB.
2871 * \param procName Name of a GL or GLX function.
2872 * \returns A pointer to the named function
2874 * \sa glXGetProcAddressARB
2876 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2877 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2878 __attribute__ ((alias ("glXGetProcAddressARB")));
2881 return glXGetProcAddressARB(procName
);
2883 #endif /* __GNUC__ */
2884 #endif /* GLX_BUILT_IN_XMESA */
2887 #ifdef GLX_DIRECT_RENDERING
2889 * Retrieves the verion of the internal libGL API in YYYYMMDD format. This
2890 * might be used by the DRI drivers to determine how new libGL is at runtime.
2891 * Drivers should not call this function directly. They should instead use
2892 * \c glXGetProcAddress to obtain a pointer to the function.
2894 * \returns An 8-digit decimal number representing the internal libGL API in
2897 * \sa glXGetProcAddress, PFNGLXGETINTERNALVERSIONPROC
2899 * \since Internal API version 20021121.
2901 int __glXGetInternalVersion(void)
2904 * 20021121 - Initial version
2905 * 20021128 - Added __glXWindowExists() function
2906 * 20021207 - Added support for dynamic GLX extensions,
2907 * GLX_SGI_swap_control, GLX_SGI_video_sync,
2908 * GLX_OML_sync_control, and GLX_MESA_swap_control.
2909 * Never officially released. Do NOT test against
2910 * this version. Use 20030317 instead.
2911 * 20030317 - Added support GLX_SGIX_fbconfig,
2912 * GLX_MESA_swap_frame_usage, GLX_OML_swap_method,
2913 * GLX_{ARB,SGIS}_multisample, and
2914 * GLX_SGIX_visual_select_group.
2915 * 20030606 - Added support for GLX_SGI_make_current_read.
2916 * 20030813 - Made support for dynamic extensions multi-head aware.
2917 * 20030818 - Added support for GLX_MESA_allocate_memory in place of the
2918 * deprecated GLX_NV_vertex_array_range & GLX_MESA_agp_offset
2920 * 20031201 - Added support for the first round of DRI interface changes.
2921 * Do NOT test against this version! It has binary
2922 * compatibility bugs, use 20040317 instead.
2923 * 20040317 - Added the 'mode' field to __DRIcontextRec.
2924 * 20040415 - Added support for bindContext3 and unbindContext3.
2925 * 20040602 - Add __glXGetDrawableInfo. I though that was there
2927 * 20050725 - Gut all the old interfaces. This breaks compatability with
2928 * any DRI driver built to any previous version.
2935 static Bool windowExistsFlag
;
2937 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
2939 if (xerr
->error_code
== BadWindow
) {
2940 windowExistsFlag
= GL_FALSE
;
2946 * Determine if a window associated with a \c GLXDrawable exists on the
2947 * X-server. This function is not used internally by libGL. It is provided
2948 * as a utility function for DRI drivers.
2949 * Drivers should not call this function directly. They should instead use
2950 * \c glXGetProcAddress to obtain a pointer to the function.
2952 * \param dpy Display associated with the drawable to be queried.
2953 * \param draw \c GLXDrawable to test.
2955 * \returns \c GL_TRUE if a window exists that is associated with \c draw,
2956 * otherwise \c GL_FALSE is returned.
2958 * \warning This function is not currently thread-safe.
2960 * \sa glXGetProcAddress
2962 * \since Internal API version 20021128.
2964 Bool
__glXWindowExists(Display
*dpy
, GLXDrawable draw
)
2966 XWindowAttributes xwa
;
2967 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
2969 XSync(dpy
, GL_FALSE
);
2970 windowExistsFlag
= GL_TRUE
;
2971 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
2972 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
2973 XSetErrorHandler(oldXErrorHandler
);
2974 return windowExistsFlag
;
2979 * Get the unadjusted system time (UST). Currently, the UST is measured in
2980 * microseconds since Epoc. The actual resolution of the UST may vary from
2981 * system to system, and the units may vary from release to release.
2982 * Drivers should not call this function directly. They should instead use
2983 * \c glXGetProcAddress to obtain a pointer to the function.
2985 * \param ust Location to store the 64-bit UST
2986 * \returns Zero on success or a negative errno value on failure.
2988 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2990 * \since Internal API version 20030317.
2992 int __glXGetUST( int64_t * ust
)
2996 if ( ust
== NULL
) {
3000 if ( gettimeofday( & tv
, NULL
) == 0 ) {
3001 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3007 #endif /* GLX_DIRECT_RENDERING */