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 #ifdef GLX_DIRECT_RENDERING
67 static Bool windowExistsFlag
;
68 static int windowExistsErrorHandler(Display
*dpy
, XErrorEvent
*xerr
)
70 if (xerr
->error_code
== BadWindow
) {
71 windowExistsFlag
= GL_FALSE
;
77 * Find drawables in the local hash that have been destroyed on the
80 * \param dpy Display to destroy drawables for
81 * \param screen Screen number to destroy drawables for
83 static void GarbageCollectDRIDrawables(Display
*dpy
, __GLXscreenConfigs
*sc
)
87 XWindowAttributes xwa
;
88 int (*oldXErrorHandler
)(Display
*, XErrorEvent
*);
90 /* Set no-op error handler so Xlib doesn't bail out if the windows
91 * has alreay been destroyed on the server. */
93 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
95 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1) {
97 windowExistsFlag
= GL_TRUE
;
98 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
99 if (!windowExistsFlag
) {
100 /* Destroy the local drawable data, if the drawable no
101 longer exists in the Xserver */
102 (*pdraw
->driDrawable
.destroyDrawable
)(&pdraw
->driDrawable
);
103 XF86DRIDestroyDrawable(dpy
, sc
->scr
, draw
);
104 __glxHashDelete(sc
->drawHash
, draw
);
107 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *)&pdraw
) == 1);
110 XSync(dpy
, GL_FALSE
);
111 XSetErrorHandler(oldXErrorHandler
);
115 * Get the __DRIdrawable for the drawable associated with a GLXContext
117 * \param dpy The display associated with \c drawable.
118 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
119 * \param scrn_num If non-NULL, the drawables screen is stored there
120 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
121 * the drawable is not associated with a direct-rendering context.
123 static __DRIdrawable
*
124 GetDRIDrawable( Display
*dpy
, GLXDrawable drawable
, int * const scrn_num
)
126 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
127 __GLXdrawable
* const pdraw
;
128 const unsigned screen_count
= ScreenCount(dpy
);
130 __GLXscreenConfigs
*sc
;
132 if (priv
== NULL
|| priv
->driDisplay
== NULL
)
135 for (i
= 0; i
< screen_count
; i
++) {
136 sc
= &priv
->screenConfigs
[i
];
137 if (__glxHashLookup(sc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
138 if (scrn_num
!= NULL
)
140 return &pdraw
->driDrawable
;
151 * Get the GLX per-screen data structure associated with a GLX context.
153 * \param dpy Display for which the GLX per-screen information is to be
155 * \param scrn Screen on \c dpy for which the GLX per-screen information is
157 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
158 * specify a valid GLX screen, or NULL otherwise.
160 * \todo Should this function validate that \c scrn is within the screen
161 * number range for \c dpy?
164 static __GLXscreenConfigs
*
165 GetGLXScreenConfigs(Display
*dpy
, int scrn
)
167 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
169 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
174 GetGLXPrivScreenConfig( Display
*dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
175 __GLXscreenConfigs
** ppsc
)
177 /* Initialize the extension, if needed . This has the added value
178 * of initializing/allocating the display private
182 return GLX_NO_EXTENSION
;
185 *ppriv
= __glXInitialize(dpy
);
186 if ( *ppriv
== NULL
) {
187 return GLX_NO_EXTENSION
;
190 /* Check screen number to see if its valid */
191 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
192 return GLX_BAD_SCREEN
;
195 /* Check to see if the GL is supported on this screen */
196 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
197 if ( (*ppsc
)->configs
== NULL
) {
198 /* No support for GL on this screen regardless of visual */
199 return GLX_BAD_VISUAL
;
207 * Determine if a \c GLXFBConfig supplied by the application is valid.
209 * \param dpy Application supplied \c Display pointer.
210 * \param config Application supplied \c GLXFBConfig.
212 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
213 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
216 static __GLcontextModes
*
217 ValidateGLXFBConfig( Display
* dpy
, GLXFBConfig config
)
219 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
220 const unsigned num_screens
= ScreenCount(dpy
);
222 const __GLcontextModes
* modes
;
225 if ( priv
!= NULL
) {
226 for ( i
= 0 ; i
< num_screens
; i
++ ) {
227 for ( modes
= priv
->screenConfigs
[i
].configs
229 ; modes
= modes
->next
) {
230 if ( modes
== (__GLcontextModes
*) config
) {
231 return (__GLcontextModes
*) config
;
242 * \todo It should be possible to move the allocate of \c client_state_private
243 * later in the function for direct-rendering contexts. Direct-rendering
244 * contexts don't need to track client state, so they don't need that memory
247 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
248 * function called \c __glXAllocateClientState that allocates the memory and
249 * does all the initialization (including the pixel pack / unpack).
252 GLXContext
AllocateGLXContext( Display
*dpy
)
257 __GLXattribute
*state
;
262 opcode
= __glXSetupForCommand(dpy
);
267 /* Allocate our context record */
268 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
273 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
275 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
281 gc
->client_state_private
= state
;
282 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
283 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
286 ** Create a temporary buffer to hold GLX rendering commands. The size
287 ** of the buffer is selected so that the maximum number of GLX rendering
288 ** commands can fit in a single X packet and still have room in the X
289 ** packet for the GLXRenderReq header.
292 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
293 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
295 Xfree(gc
->client_state_private
);
299 gc
->bufSize
= bufSize
;
301 /* Fill in the new context */
302 gc
->renderMode
= GL_RENDER
;
304 state
->storePack
.alignment
= 4;
305 state
->storeUnpack
.alignment
= 4;
307 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
310 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
311 ** Other code uses the fastImageUnpack bit, but it is never set
314 gc
->fastImageUnpack
= GL_FALSE
;
315 gc
->fillImage
= __glFillImage
;
316 gc
->isDirect
= GL_FALSE
;
318 gc
->bufEnd
= gc
->buf
+ bufSize
;
321 ** Set limit register so that there will be one command per packet
325 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
328 gc
->majorOpcode
= opcode
;
331 ** Constrain the maximum drawing command size allowed to be
332 ** transfered using the X_GLXRender protocol request. First
333 ** constrain by a software limit, then constrain by the protocl
336 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
337 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
339 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
340 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
342 gc
->maxSmallRenderCommandSize
= bufSize
;
348 * Create a new context. Exactly one of \c vis and \c fbconfig should be
351 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
352 * SGIX_fbconfig protocol be used?
353 * \param renderType For FBConfigs, what is the rendering type?
357 CreateContext(Display
*dpy
, XVisualInfo
*vis
,
358 const __GLcontextModes
* const fbconfig
,
359 GLXContext shareList
,
360 Bool allowDirect
, GLXContextID contextID
,
361 Bool use_glx_1_3
, int renderType
)
368 gc
= AllocateGLXContext(dpy
);
372 if (None
== contextID
) {
373 if ( (vis
== NULL
) && (fbconfig
== NULL
) )
376 #ifdef GLX_DIRECT_RENDERING
378 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
379 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
380 const __GLcontextModes
* mode
;
382 if (fbconfig
== NULL
) {
383 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
387 error
.errorCode
= BadValue
;
388 error
.resourceID
= vis
->visualid
;
389 error
.sequenceNumber
= dpy
->request
;
390 error
.type
= X_Error
;
391 error
.majorCode
= gc
->majorOpcode
;
392 error
.minorCode
= X_GLXCreateContext
;
393 _XError(dpy
, &error
);
401 psc
->driScreen
->createContext(psc
, mode
, gc
, shareList
, renderType
);
406 if ( fbconfig
== NULL
) {
407 xGLXCreateContextReq
*req
;
409 /* Send the glXCreateContext request */
410 GetReq(GLXCreateContext
,req
);
411 req
->reqType
= gc
->majorOpcode
;
412 req
->glxCode
= X_GLXCreateContext
;
413 req
->context
= gc
->xid
= XAllocID(dpy
);
414 req
->visual
= vis
->visualid
;
415 req
->screen
= vis
->screen
;
416 req
->shareList
= shareList
? shareList
->xid
: None
;
417 req
->isDirect
= gc
->isDirect
;
419 else if ( use_glx_1_3
) {
420 xGLXCreateNewContextReq
*req
;
422 /* Send the glXCreateNewContext request */
423 GetReq(GLXCreateNewContext
,req
);
424 req
->reqType
= gc
->majorOpcode
;
425 req
->glxCode
= X_GLXCreateNewContext
;
426 req
->context
= gc
->xid
= XAllocID(dpy
);
427 req
->fbconfig
= fbconfig
->fbconfigID
;
428 req
->screen
= fbconfig
->screen
;
429 req
->renderType
= renderType
;
430 req
->shareList
= shareList
? shareList
->xid
: None
;
431 req
->isDirect
= gc
->isDirect
;
434 xGLXVendorPrivateWithReplyReq
*vpreq
;
435 xGLXCreateContextWithConfigSGIXReq
*req
;
437 /* Send the glXCreateNewContext request */
438 GetReqExtra(GLXVendorPrivateWithReply
,
439 sz_xGLXCreateContextWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
440 req
= (xGLXCreateContextWithConfigSGIXReq
*)vpreq
;
441 req
->reqType
= gc
->majorOpcode
;
442 req
->glxCode
= X_GLXVendorPrivateWithReply
;
443 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
444 req
->context
= gc
->xid
= XAllocID(dpy
);
445 req
->fbconfig
= fbconfig
->fbconfigID
;
446 req
->screen
= fbconfig
->screen
;
447 req
->renderType
= renderType
;
448 req
->shareList
= shareList
? shareList
->xid
: None
;
449 req
->isDirect
= gc
->isDirect
;
454 gc
->imported
= GL_FALSE
;
458 gc
->imported
= GL_TRUE
;
464 PUBLIC GLXContext
glXCreateContext(Display
*dpy
, XVisualInfo
*vis
,
465 GLXContext shareList
, Bool allowDirect
)
467 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
471 void __glXFreeContext(__GLXcontext
*gc
)
473 if (gc
->vendor
) XFree((char *) gc
->vendor
);
474 if (gc
->renderer
) XFree((char *) gc
->renderer
);
475 if (gc
->version
) XFree((char *) gc
->version
);
476 if (gc
->extensions
) XFree((char *) gc
->extensions
);
477 __glFreeAttributeState(gc
);
478 XFree((char *) gc
->buf
);
479 Xfree((char *) gc
->client_state_private
);
485 ** Destroy the named context
488 DestroyContext(Display
*dpy
, GLXContext gc
)
490 xGLXDestroyContextReq
*req
;
495 opcode
= __glXSetupForCommand(dpy
);
496 if (!opcode
|| !gc
) {
502 imported
= gc
->imported
;
505 #ifdef GLX_DIRECT_RENDERING
506 /* Destroy the direct rendering context */
508 if (gc
->driContext
.private) {
509 (*gc
->driContext
.destroyContext
)(&gc
->driContext
);
510 XF86DRIDestroyContext(dpy
, gc
->psc
->scr
, gc
->hwContextID
);
511 gc
->driContext
.private = NULL
;
513 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
517 if (gc
->currentDpy
) {
518 /* Have to free later cuz it's in use now */
521 /* Destroy the handle if not current to anybody */
523 __glXFreeContext(gc
);
528 ** This dpy also created the server side part of the context.
529 ** Send the glXDestroyContext request.
532 GetReq(GLXDestroyContext
,req
);
533 req
->reqType
= opcode
;
534 req
->glxCode
= X_GLXDestroyContext
;
541 PUBLIC
void glXDestroyContext(Display
*dpy
, GLXContext gc
)
543 DestroyContext(dpy
, gc
);
547 ** Return the major and minor version #s for the GLX extension
549 PUBLIC Bool
glXQueryVersion(Display
*dpy
, int *major
, int *minor
)
551 __GLXdisplayPrivate
*priv
;
553 /* Init the extension. This fetches the major and minor version. */
554 priv
= __glXInitialize(dpy
);
555 if (!priv
) return GL_FALSE
;
557 if (major
) *major
= priv
->majorVersion
;
558 if (minor
) *minor
= priv
->minorVersion
;
563 ** Query the existance of the GLX extension
565 PUBLIC Bool
glXQueryExtension(Display
*dpy
, int *errorBase
, int *eventBase
)
567 int major_op
, erb
, evb
;
570 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
572 if (errorBase
) *errorBase
= erb
;
573 if (eventBase
) *eventBase
= evb
;
579 ** Put a barrier in the token stream that forces the GL to finish its
580 ** work before X can proceed.
582 PUBLIC
void glXWaitGL(void)
585 GLXContext gc
= __glXGetCurrentContext();
586 Display
*dpy
= gc
->currentDpy
;
590 /* Flush any pending commands out */
591 __glXFlushRenderBuffer(gc
, gc
->pc
);
593 #ifdef GLX_DIRECT_RENDERING
595 /* This bit of ugliness unwraps the glFinish function */
604 /* Send the glXWaitGL request */
606 GetReq(GLXWaitGL
,req
);
607 req
->reqType
= gc
->majorOpcode
;
608 req
->glxCode
= X_GLXWaitGL
;
609 req
->contextTag
= gc
->currentContextTag
;
615 ** Put a barrier in the token stream that forces X to finish its
616 ** work before GL can proceed.
618 PUBLIC
void glXWaitX(void)
621 GLXContext gc
= __glXGetCurrentContext();
622 Display
*dpy
= gc
->currentDpy
;
626 /* Flush any pending commands out */
627 __glXFlushRenderBuffer(gc
, gc
->pc
);
629 #ifdef GLX_DIRECT_RENDERING
637 ** Send the glXWaitX request.
640 GetReq(GLXWaitX
,req
);
641 req
->reqType
= gc
->majorOpcode
;
642 req
->glxCode
= X_GLXWaitX
;
643 req
->contextTag
= gc
->currentContextTag
;
648 PUBLIC
void glXUseXFont(Font font
, int first
, int count
, int listBase
)
650 xGLXUseXFontReq
*req
;
651 GLXContext gc
= __glXGetCurrentContext();
652 Display
*dpy
= gc
->currentDpy
;
656 /* Flush any pending commands out */
657 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
659 #ifdef GLX_DIRECT_RENDERING
661 DRI_glXUseXFont(font
, first
, count
, listBase
);
666 /* Send the glXUseFont request */
668 GetReq(GLXUseXFont
,req
);
669 req
->reqType
= gc
->majorOpcode
;
670 req
->glxCode
= X_GLXUseXFont
;
671 req
->contextTag
= gc
->currentContextTag
;
675 req
->listBase
= listBase
;
680 /************************************************************************/
683 ** Copy the source context to the destination context using the
686 PUBLIC
void glXCopyContext(Display
*dpy
, GLXContext source
,
687 GLXContext dest
, unsigned long mask
)
689 xGLXCopyContextReq
*req
;
690 GLXContext gc
= __glXGetCurrentContext();
694 opcode
= __glXSetupForCommand(dpy
);
699 #ifdef GLX_DIRECT_RENDERING
701 /* NOT_DONE: This does not work yet */
706 ** If the source is the current context, send its tag so that the context
707 ** can be flushed before the copy.
709 if (source
== gc
&& dpy
== gc
->currentDpy
) {
710 tag
= gc
->currentContextTag
;
715 /* Send the glXCopyContext request */
717 GetReq(GLXCopyContext
,req
);
718 req
->reqType
= opcode
;
719 req
->glxCode
= X_GLXCopyContext
;
720 req
->source
= source
? source
->xid
: None
;
721 req
->dest
= dest
? dest
->xid
: None
;
723 req
->contextTag
= tag
;
730 * Determine if a context uses direct rendering.
732 * \param dpy Display where the context was created.
733 * \param contextID ID of the context to be tested.
735 * \returns \c GL_TRUE if the context is direct rendering or not.
737 static Bool
__glXIsDirect(Display
*dpy
, GLXContextID contextID
)
739 xGLXIsDirectReq
*req
;
740 xGLXIsDirectReply reply
;
743 opcode
= __glXSetupForCommand(dpy
);
748 /* Send the glXIsDirect request */
750 GetReq(GLXIsDirect
,req
);
751 req
->reqType
= opcode
;
752 req
->glxCode
= X_GLXIsDirect
;
753 req
->context
= contextID
;
754 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
758 return reply
.isDirect
;
763 * Shouldn't this function \b always return \c GL_FALSE when
764 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
765 * the GLX protocol here at all?
767 PUBLIC Bool
glXIsDirect(Display
*dpy
, GLXContext gc
)
771 #ifdef GLX_DIRECT_RENDERING
772 } else if (gc
->isDirect
) {
776 return __glXIsDirect(dpy
, gc
->xid
);
779 PUBLIC GLXPixmap
glXCreateGLXPixmap(Display
*dpy
, XVisualInfo
*vis
,
782 xGLXCreateGLXPixmapReq
*req
;
786 opcode
= __glXSetupForCommand(dpy
);
791 /* Send the glXCreateGLXPixmap request */
793 GetReq(GLXCreateGLXPixmap
,req
);
794 req
->reqType
= opcode
;
795 req
->glxCode
= X_GLXCreateGLXPixmap
;
796 req
->screen
= vis
->screen
;
797 req
->visual
= vis
->visualid
;
798 req
->pixmap
= pixmap
;
799 req
->glxpixmap
= xid
= XAllocID(dpy
);
806 ** Destroy the named pixmap
808 PUBLIC
void glXDestroyGLXPixmap(Display
*dpy
, GLXPixmap glxpixmap
)
810 xGLXDestroyGLXPixmapReq
*req
;
813 opcode
= __glXSetupForCommand(dpy
);
818 /* Send the glXDestroyGLXPixmap request */
820 GetReq(GLXDestroyGLXPixmap
,req
);
821 req
->reqType
= opcode
;
822 req
->glxCode
= X_GLXDestroyGLXPixmap
;
823 req
->glxpixmap
= glxpixmap
;
828 PUBLIC
void glXSwapBuffers(Display
*dpy
, GLXDrawable drawable
)
830 xGLXSwapBuffersReq
*req
;
834 #ifdef GLX_DIRECT_RENDERING
835 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, NULL
);
837 if ( pdraw
!= NULL
) {
838 (*pdraw
->swapBuffers
)(pdraw
);
843 opcode
= __glXSetupForCommand(dpy
);
849 ** The calling thread may or may not have a current context. If it
850 ** does, send the context tag so the server can do a flush.
852 gc
= __glXGetCurrentContext();
853 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
854 ((drawable
== gc
->currentDrawable
) || (drawable
== gc
->currentReadable
)) ) {
855 tag
= gc
->currentContextTag
;
860 /* Send the glXSwapBuffers request */
862 GetReq(GLXSwapBuffers
,req
);
863 req
->reqType
= opcode
;
864 req
->glxCode
= X_GLXSwapBuffers
;
865 req
->drawable
= drawable
;
866 req
->contextTag
= tag
;
874 ** Return configuration information for the given display, screen and
875 ** visual combination.
877 PUBLIC
int glXGetConfig(Display
*dpy
, XVisualInfo
*vis
, int attribute
,
880 __GLXdisplayPrivate
*priv
;
881 __GLXscreenConfigs
*psc
;
882 __GLcontextModes
*modes
;
885 status
= GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
);
886 if ( status
== Success
) {
887 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
889 /* Lookup attribute after first finding a match on the visual */
890 if ( modes
!= NULL
) {
891 return _gl_get_context_mode_data( modes
, attribute
, value_return
);
894 status
= GLX_BAD_VISUAL
;
898 ** If we can't find the config for this visual, this visual is not
899 ** supported by the OpenGL implementation on the server.
901 if ( (status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
) ) {
902 *value_return
= GL_FALSE
;
909 /************************************************************************/
912 init_fbconfig_for_chooser( __GLcontextModes
* config
,
913 GLboolean fbconfig_style_tags
)
915 memset( config
, 0, sizeof( __GLcontextModes
) );
916 config
->visualID
= (XID
) GLX_DONT_CARE
;
917 config
->visualType
= GLX_DONT_CARE
;
919 /* glXChooseFBConfig specifies different defaults for these two than
922 if ( fbconfig_style_tags
) {
923 config
->rgbMode
= GL_TRUE
;
924 config
->doubleBufferMode
= GLX_DONT_CARE
;
927 config
->visualRating
= GLX_DONT_CARE
;
928 config
->transparentPixel
= GLX_NONE
;
929 config
->transparentRed
= GLX_DONT_CARE
;
930 config
->transparentGreen
= GLX_DONT_CARE
;
931 config
->transparentBlue
= GLX_DONT_CARE
;
932 config
->transparentAlpha
= GLX_DONT_CARE
;
933 config
->transparentIndex
= GLX_DONT_CARE
;
935 config
->drawableType
= GLX_WINDOW_BIT
;
936 config
->renderType
= (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
937 config
->xRenderable
= GLX_DONT_CARE
;
938 config
->fbconfigID
= (GLXFBConfigID
)(GLX_DONT_CARE
);
940 config
->swapMethod
= GLX_DONT_CARE
;
943 #define MATCH_DONT_CARE( param ) \
945 if ( (a-> param != GLX_DONT_CARE) \
946 && (a-> param != b-> param) ) { \
951 #define MATCH_MINIMUM( param ) \
953 if ( (a-> param != GLX_DONT_CARE) \
954 && (a-> param > b-> param) ) { \
959 #define MATCH_EXACT( param ) \
961 if ( a-> param != b-> param) { \
967 * Determine if two GLXFBConfigs are compatible.
969 * \param a Application specified config to test.
970 * \param b Server specified config to test against \c a.
973 fbconfigs_compatible( const __GLcontextModes
* const a
,
974 const __GLcontextModes
* const b
)
976 MATCH_DONT_CARE( doubleBufferMode
);
977 MATCH_DONT_CARE( visualType
);
978 MATCH_DONT_CARE( visualRating
);
979 MATCH_DONT_CARE( xRenderable
);
980 MATCH_DONT_CARE( fbconfigID
);
981 MATCH_DONT_CARE( swapMethod
);
983 MATCH_MINIMUM( rgbBits
);
984 MATCH_MINIMUM( numAuxBuffers
);
985 MATCH_MINIMUM( redBits
);
986 MATCH_MINIMUM( greenBits
);
987 MATCH_MINIMUM( blueBits
);
988 MATCH_MINIMUM( alphaBits
);
989 MATCH_MINIMUM( depthBits
);
990 MATCH_MINIMUM( stencilBits
);
991 MATCH_MINIMUM( accumRedBits
);
992 MATCH_MINIMUM( accumGreenBits
);
993 MATCH_MINIMUM( accumBlueBits
);
994 MATCH_MINIMUM( accumAlphaBits
);
995 MATCH_MINIMUM( sampleBuffers
);
996 MATCH_MINIMUM( maxPbufferWidth
);
997 MATCH_MINIMUM( maxPbufferHeight
);
998 MATCH_MINIMUM( maxPbufferPixels
);
999 MATCH_MINIMUM( samples
);
1001 MATCH_DONT_CARE( stereoMode
);
1002 MATCH_EXACT( level
);
1004 if ( ((a
->drawableType
& b
->drawableType
) == 0)
1005 || ((a
->renderType
& b
->renderType
) == 0) ) {
1010 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1011 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1012 * Technically speaking, it is a bug in the DDX driver, but there is
1013 * enough of an installed base to work around the problem here. In any
1014 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1015 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1016 * 0 from the server to be a match to maintain backward compatibility with
1017 * the (broken) drivers.
1020 if ( a
->transparentPixel
!= GLX_DONT_CARE
1021 && a
->transparentPixel
!= 0 ) {
1022 if ( a
->transparentPixel
== GLX_NONE
) {
1023 if ( b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0 )
1026 MATCH_EXACT( transparentPixel
);
1029 switch ( a
->transparentPixel
) {
1030 case GLX_TRANSPARENT_RGB
:
1031 MATCH_DONT_CARE( transparentRed
);
1032 MATCH_DONT_CARE( transparentGreen
);
1033 MATCH_DONT_CARE( transparentBlue
);
1034 MATCH_DONT_CARE( transparentAlpha
);
1037 case GLX_TRANSPARENT_INDEX
:
1038 MATCH_DONT_CARE( transparentIndex
);
1050 /* There's some trickly language in the GLX spec about how this is supposed
1051 * to work. Basically, if a given component size is either not specified
1052 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1053 * Well, that's really hard to do with the code as-is. This behavior is
1054 * closer to correct, but still not technically right.
1056 #define PREFER_LARGER_OR_ZERO(comp) \
1058 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1059 if ( ((*a)-> comp) == 0 ) { \
1062 else if ( ((*b)-> comp) == 0 ) { \
1066 return ((*b)-> comp) - ((*a)-> comp) ; \
1071 #define PREFER_LARGER(comp) \
1073 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1074 return ((*b)-> comp) - ((*a)-> comp) ; \
1078 #define PREFER_SMALLER(comp) \
1080 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1081 return ((*a)-> comp) - ((*b)-> comp) ; \
1086 * Compare two GLXFBConfigs. This function is intended to be used as the
1087 * compare function passed in to qsort.
1089 * \returns If \c a is a "better" config, according to the specification of
1090 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1091 * better, then a number greater than zero is return. If both are
1092 * equal, zero is returned.
1093 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1096 fbconfig_compare( const __GLcontextModes
* const * const a
,
1097 const __GLcontextModes
* const * const b
)
1099 /* The order of these comparisons must NOT change. It is defined by
1100 * the GLX 1.3 spec and ARB_multisample.
1103 PREFER_SMALLER( visualSelectGroup
);
1105 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1106 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1107 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1109 PREFER_SMALLER( visualRating
);
1111 /* This isn't quite right. It is supposed to compare the sum of the
1112 * components the user specifically set minimums for.
1114 PREFER_LARGER_OR_ZERO( redBits
);
1115 PREFER_LARGER_OR_ZERO( greenBits
);
1116 PREFER_LARGER_OR_ZERO( blueBits
);
1117 PREFER_LARGER_OR_ZERO( alphaBits
);
1119 PREFER_SMALLER( rgbBits
);
1121 if ( ((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
) ) {
1122 /* Prefer single-buffer.
1124 return ( !(*a
)->doubleBufferMode
) ? -1 : 1;
1127 PREFER_SMALLER( numAuxBuffers
);
1129 PREFER_LARGER_OR_ZERO( depthBits
);
1130 PREFER_SMALLER( stencilBits
);
1132 /* This isn't quite right. It is supposed to compare the sum of the
1133 * components the user specifically set minimums for.
1135 PREFER_LARGER_OR_ZERO( accumRedBits
);
1136 PREFER_LARGER_OR_ZERO( accumGreenBits
);
1137 PREFER_LARGER_OR_ZERO( accumBlueBits
);
1138 PREFER_LARGER_OR_ZERO( accumAlphaBits
);
1140 PREFER_SMALLER( visualType
);
1142 /* None of the multisample specs say where this comparison should happen,
1143 * so I put it near the end.
1145 PREFER_SMALLER( sampleBuffers
);
1146 PREFER_SMALLER( samples
);
1148 /* None of the pbuffer or fbconfig specs say that this comparison needs
1149 * to happen at all, but it seems like it should.
1151 PREFER_LARGER( maxPbufferWidth
);
1152 PREFER_LARGER( maxPbufferHeight
);
1153 PREFER_LARGER( maxPbufferPixels
);
1160 * Selects and sorts a subset of the supplied configs based on the attributes.
1161 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1162 * and \c glXChooseFBConfigSGIX.
1164 * \param configs Array of pointers to possible configs. The elements of
1165 * this array that do not meet the criteria will be set to
1166 * NULL. The remaining elements will be sorted according to
1167 * the various visual / FBConfig selection rules.
1168 * \param num_configs Number of elements in the \c configs array.
1169 * \param attribList Attributes used select from \c configs. This array is
1170 * terminated by a \c None tag. The array can either take
1171 * the form expected by \c glXChooseVisual (where boolean
1172 * tags do not have a value) or by \c glXChooseFBConfig
1173 * (where every tag has a value).
1174 * \param fbconfig_style_tags Selects whether \c attribList is in
1175 * \c glXChooseVisual style or
1176 * \c glXChooseFBConfig style.
1177 * \returns The number of valid elements left in \c configs.
1179 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1182 choose_visual( __GLcontextModes
** configs
, int num_configs
,
1183 const int *attribList
, GLboolean fbconfig_style_tags
)
1185 __GLcontextModes test_config
;
1189 /* This is a fairly direct implementation of the selection method
1190 * described by GLX_SGIX_fbconfig. Start by culling out all the
1191 * configs that are not compatible with the selected parameter
1195 init_fbconfig_for_chooser( & test_config
, fbconfig_style_tags
);
1196 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1197 (const INT32
*) attribList
,
1198 GL_TRUE
, fbconfig_style_tags
);
1201 for ( i
= 0 ; i
< num_configs
; i
++ ) {
1202 if ( fbconfigs_compatible( & test_config
, configs
[i
] ) ) {
1203 configs
[ base
] = configs
[ i
];
1212 if ( base
< num_configs
) {
1213 (void) memset( & configs
[ base
], 0,
1214 sizeof( void * ) * (num_configs
- base
) );
1217 /* After the incompatible configs are removed, the resulting
1218 * list is sorted according to the rules set out in the various
1222 qsort( configs
, base
, sizeof( __GLcontextModes
* ),
1223 (int (*)(const void*, const void*)) fbconfig_compare
);
1231 ** Return the visual that best matches the template. Return None if no
1232 ** visual matches the template.
1234 PUBLIC XVisualInfo
*glXChooseVisual(Display
*dpy
, int screen
, int *attribList
)
1236 XVisualInfo
*visualList
= NULL
;
1237 __GLXdisplayPrivate
*priv
;
1238 __GLXscreenConfigs
*psc
;
1239 __GLcontextModes test_config
;
1240 __GLcontextModes
*modes
;
1241 const __GLcontextModes
*best_config
= NULL
;
1244 ** Get a list of all visuals, return if list is empty
1246 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1252 ** Build a template from the defaults and the attribute list
1253 ** Free visual list and return if an unexpected token is encountered
1255 init_fbconfig_for_chooser( & test_config
, GL_FALSE
);
1256 __glXInitializeVisualConfigFromTags( & test_config
, 512,
1257 (const INT32
*) attribList
,
1258 GL_TRUE
, GL_FALSE
);
1261 ** Eliminate visuals that don't meet minimum requirements
1262 ** Compute a score for those that do
1263 ** Remember which visual, if any, got the highest score
1265 for ( modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1266 if ( fbconfigs_compatible( & test_config
, modes
)
1267 && ((best_config
== NULL
)
1268 || (fbconfig_compare( (const __GLcontextModes
* const * const)&modes
, &best_config
) < 0)) ) {
1269 best_config
= modes
;
1274 ** If no visual is acceptable, return None
1275 ** Otherwise, create an XVisualInfo list with just the selected X visual
1278 if (best_config
!= NULL
) {
1279 XVisualInfo visualTemplate
;
1282 visualTemplate
.screen
= screen
;
1283 visualTemplate
.visualid
= best_config
->visualID
;
1284 visualList
= XGetVisualInfo( dpy
, VisualScreenMask
|VisualIDMask
,
1285 &visualTemplate
, &i
);
1292 PUBLIC
const char *glXQueryExtensionsString( Display
*dpy
, int screen
)
1294 __GLXscreenConfigs
*psc
;
1295 __GLXdisplayPrivate
*priv
;
1297 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1301 if (!psc
->effectiveGLXexts
) {
1302 if (!psc
->serverGLXexts
) {
1303 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1304 X_GLXQueryServerString
,
1305 screen
, GLX_EXTENSIONS
);
1308 __glXCalculateUsableExtensions(psc
,
1309 #ifdef GLX_DIRECT_RENDERING
1310 (psc
->driScreen
!= NULL
),
1314 priv
->minorVersion
);
1317 return psc
->effectiveGLXexts
;
1320 PUBLIC
const char *glXGetClientString( Display
*dpy
, int name
)
1324 return (__glXGLXClientVendorName
);
1326 return (__glXGLXClientVersion
);
1327 case GLX_EXTENSIONS
:
1328 return (__glXGetClientExtensions());
1334 PUBLIC
const char *glXQueryServerString( Display
*dpy
, int screen
, int name
)
1336 __GLXscreenConfigs
*psc
;
1337 __GLXdisplayPrivate
*priv
;
1341 if ( GetGLXPrivScreenConfig( dpy
, screen
, & priv
, & psc
) != Success
) {
1347 str
= & priv
->serverGLXvendor
;
1350 str
= & priv
->serverGLXversion
;
1352 case GLX_EXTENSIONS
:
1353 str
= & psc
->serverGLXexts
;
1359 if ( *str
== NULL
) {
1360 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1361 X_GLXQueryServerString
, screen
, name
);
1367 void __glXClientInfo ( Display
*dpy
, int opcode
)
1369 xGLXClientInfoReq
*req
;
1371 char * ext_str
= __glXGetClientGLExtensionString();
1373 /* Send the glXClientInfo request */
1375 GetReq(GLXClientInfo
,req
);
1376 req
->reqType
= opcode
;
1377 req
->glxCode
= X_GLXClientInfo
;
1378 req
->major
= GLX_MAJOR_VERSION
;
1379 req
->minor
= GLX_MINOR_VERSION
;
1381 size
= strlen( ext_str
) + 1;
1382 req
->length
+= (size
+ 3) >> 2;
1383 req
->numbytes
= size
;
1384 Data(dpy
, ext_str
, size
);
1394 ** EXT_import_context
1397 PUBLIC Display
*glXGetCurrentDisplay(void)
1399 GLXContext gc
= __glXGetCurrentContext();
1400 if (NULL
== gc
) return NULL
;
1401 return gc
->currentDpy
;
1404 PUBLIC
GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1405 glXGetCurrentDisplay
)
1408 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1411 * \param dpy Display where \c ctx was created.
1412 * \param ctx Context to query.
1413 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1414 * or zero if the request failed due to internal problems (i.e.,
1415 * unable to allocate temporary memory, etc.)
1418 * This function dynamically determines whether to use the EXT_import_context
1419 * version of the protocol or the GLX 1.3 version of the protocol.
1421 static int __glXQueryContextInfo(Display
*dpy
, GLXContext ctx
)
1423 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1424 xGLXQueryContextReply reply
;
1430 return GLX_BAD_CONTEXT
;
1432 opcode
= __glXSetupForCommand(dpy
);
1437 /* Send the glXQueryContextInfoEXT request */
1440 if ( (priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3) ) {
1441 xGLXQueryContextReq
*req
;
1443 GetReq(GLXQueryContext
, req
);
1445 req
->reqType
= opcode
;
1446 req
->glxCode
= X_GLXQueryContext
;
1447 req
->context
= (unsigned int)(ctx
->xid
);
1450 xGLXVendorPrivateReq
*vpreq
;
1451 xGLXQueryContextInfoEXTReq
*req
;
1453 GetReqExtra( GLXVendorPrivate
,
1454 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1456 req
= (xGLXQueryContextInfoEXTReq
*)vpreq
;
1457 req
->reqType
= opcode
;
1458 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1459 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1460 req
->context
= (unsigned int)(ctx
->xid
);
1463 _XReply(dpy
, (xReply
*) &reply
, 0, False
);
1465 numValues
= reply
.n
;
1468 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1472 int *propList
, *pProp
;
1476 nPropListBytes
= numValues
<< 3;
1477 propList
= (int *) Xmalloc(nPropListBytes
);
1478 if (NULL
== propList
) {
1481 _XRead(dpy
, (char *)propList
, nPropListBytes
);
1483 for (i
=0; i
< numValues
; i
++) {
1485 case GLX_SHARE_CONTEXT_EXT
:
1486 ctx
->share_xid
= *pProp
++;
1488 case GLX_VISUAL_ID_EXT
:
1490 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1493 ctx
->screen
= *pProp
++;
1495 case GLX_FBCONFIG_ID
:
1497 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
, *pProp
++);
1499 case GLX_RENDER_TYPE
:
1500 ctx
->renderType
= *pProp
++;
1507 Xfree((char *)propList
);
1517 glXQueryContext(Display
*dpy
, GLXContext ctx
, int attribute
, int *value
)
1521 /* get the information from the server if we don't have it already */
1522 if (!ctx
->isDirect
&& (ctx
->mode
== NULL
)) {
1523 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1524 if (Success
!= retVal
) return retVal
;
1526 switch (attribute
) {
1527 case GLX_SHARE_CONTEXT_EXT
:
1528 *value
= (int)(ctx
->share_xid
);
1530 case GLX_VISUAL_ID_EXT
:
1531 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1534 *value
= (int)(ctx
->screen
);
1536 case GLX_FBCONFIG_ID
:
1537 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1539 case GLX_RENDER_TYPE
:
1540 *value
= (int)(ctx
->renderType
);
1543 return GLX_BAD_ATTRIBUTE
;
1548 PUBLIC
GLX_ALIAS( int, glXQueryContextInfoEXT
,
1549 (Display
*dpy
, GLXContext ctx
, int attribute
, int *value
),
1550 (dpy
, ctx
, attribute
, value
),
1553 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1558 PUBLIC GLXContext
glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1562 if (contextID
== None
) {
1565 if (__glXIsDirect(dpy
, contextID
)) {
1569 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1571 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1578 PUBLIC
void glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1580 DestroyContext(dpy
, ctx
);
1586 * GLX 1.3 functions - these are just stubs for now!
1589 PUBLIC GLXFBConfig
*glXChooseFBConfig(Display
*dpy
, int screen
,
1590 const int *attribList
, int *nitems
)
1592 __GLcontextModes
** config_list
;
1596 config_list
= (__GLcontextModes
**)
1597 glXGetFBConfigs( dpy
, screen
, & list_size
);
1599 if ( (config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
) ) {
1600 list_size
= choose_visual( config_list
, list_size
, attribList
,
1602 if ( list_size
== 0 ) {
1603 XFree( config_list
);
1608 *nitems
= list_size
;
1609 return (GLXFBConfig
*) config_list
;
1613 PUBLIC GLXContext
glXCreateNewContext(Display
*dpy
, GLXFBConfig config
,
1614 int renderType
, GLXContext shareList
,
1617 return CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1618 allowDirect
, None
, True
, renderType
);
1622 PUBLIC GLXDrawable
glXGetCurrentReadDrawable(void)
1624 GLXContext gc
= __glXGetCurrentContext();
1625 return gc
->currentReadable
;
1629 PUBLIC GLXFBConfig
*glXGetFBConfigs(Display
*dpy
, int screen
, int *nelements
)
1631 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1632 __GLcontextModes
** config
= NULL
;
1636 if ( (priv
->screenConfigs
!= NULL
)
1637 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1638 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1639 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
1640 unsigned num_configs
= 0;
1641 __GLcontextModes
* modes
;
1644 for ( modes
= priv
->screenConfigs
[screen
].configs
1646 ; modes
= modes
->next
) {
1647 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1652 config
= (__GLcontextModes
**) Xmalloc( sizeof(__GLcontextModes
*)
1654 if ( config
!= NULL
) {
1655 *nelements
= num_configs
;
1657 for ( modes
= priv
->screenConfigs
[screen
].configs
1659 ; modes
= modes
->next
) {
1660 if ( modes
->fbconfigID
!= GLX_DONT_CARE
) {
1667 return (GLXFBConfig
*) config
;
1671 PUBLIC
int glXGetFBConfigAttrib(Display
*dpy
, GLXFBConfig config
,
1672 int attribute
, int *value
)
1674 __GLcontextModes
* const modes
= ValidateGLXFBConfig( dpy
, config
);
1676 return (modes
!= NULL
)
1677 ? _gl_get_context_mode_data( modes
, attribute
, value
)
1682 PUBLIC XVisualInfo
*glXGetVisualFromFBConfig(Display
*dpy
, GLXFBConfig config
)
1684 XVisualInfo visualTemplate
;
1685 __GLcontextModes
* fbconfig
= (__GLcontextModes
*) config
;
1689 ** Get a list of all visuals, return if list is empty
1691 visualTemplate
.visualid
= fbconfig
->visualID
;
1692 return XGetVisualInfo(dpy
,VisualIDMask
,&visualTemplate
,&count
);
1697 ** GLX_SGI_swap_control
1699 static int __glXSwapIntervalSGI(int interval
)
1701 xGLXVendorPrivateReq
*req
;
1702 GLXContext gc
= __glXGetCurrentContext();
1704 CARD32
* interval_ptr
;
1708 return GLX_BAD_CONTEXT
;
1711 if ( interval
<= 0 ) {
1712 return GLX_BAD_VALUE
;
1715 #ifdef __DRI_SWAP_CONTROL
1716 if ( gc
->isDirect
) {
1717 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1719 __DRIdrawable
* const pdraw
= GetDRIDrawable( gc
->currentDpy
,
1720 gc
->currentDrawable
,
1722 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1723 psc
->swapControl
->setSwapInterval(pdraw
, interval
);
1727 return GLX_BAD_CONTEXT
;
1731 dpy
= gc
->currentDpy
;
1732 opcode
= __glXSetupForCommand(dpy
);
1737 /* Send the glXSwapIntervalSGI request */
1739 GetReqExtra(GLXVendorPrivate
,sizeof(CARD32
),req
);
1740 req
->reqType
= opcode
;
1741 req
->glxCode
= X_GLXVendorPrivate
;
1742 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1743 req
->contextTag
= gc
->currentContextTag
;
1745 interval_ptr
= (CARD32
*) (req
+ 1);
1746 *interval_ptr
= interval
;
1757 ** GLX_MESA_swap_control
1759 static int __glXSwapIntervalMESA(unsigned int interval
)
1761 #ifdef __DRI_SWAP_CONTROL
1762 GLXContext gc
= __glXGetCurrentContext();
1764 if ( interval
< 0 ) {
1765 return GLX_BAD_VALUE
;
1768 if ( (gc
!= NULL
) && gc
->isDirect
) {
1769 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1772 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1773 __DRIdrawable
* const pdraw
=
1774 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1775 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1776 psc
->swapControl
->setSwapInterval(pdraw
, interval
);
1785 return GLX_BAD_CONTEXT
;
1789 static int __glXGetSwapIntervalMESA(void)
1791 #ifdef __DRI_SWAP_CONTROL
1792 GLXContext gc
= __glXGetCurrentContext();
1794 if ( (gc
!= NULL
) && gc
->isDirect
) {
1795 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1798 if ( (psc
!= NULL
) && (psc
->driScreen
!= NULL
) ) {
1799 __DRIdrawable
* const pdraw
=
1800 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1801 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1802 return psc
->swapControl
->getSwapInterval(pdraw
);
1813 ** GLX_MESA_swap_frame_usage
1816 static GLint
__glXBeginFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1818 int status
= GLX_BAD_CONTEXT
;
1819 #ifdef __DRI_FRAME_TRACKING
1821 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1822 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1824 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1825 status
= psc
->frameTracking
->frameTracking(pdraw
, GL_TRUE
);
1834 static GLint
__glXEndFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
)
1836 int status
= GLX_BAD_CONTEXT
;
1837 #ifdef __DRI_FRAME_TRACKING
1839 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1840 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1842 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1843 status
= psc
->frameTracking
->frameTracking(pdraw
, GL_FALSE
);
1852 static GLint
__glXGetFrameUsageMESA(Display
*dpy
, GLXDrawable drawable
,
1855 int status
= GLX_BAD_CONTEXT
;
1856 #ifdef __DRI_FRAME_TRACKING
1858 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1859 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1861 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1862 int64_t sbc
, missedFrames
;
1863 float lastMissedUsage
;
1865 status
= psc
->frameTracking
->queryFrameTracking(pdraw
, &sbc
,
1879 static GLint
__glXQueryFrameTrackingMESA(Display
*dpy
, GLXDrawable drawable
,
1880 int64_t *sbc
, int64_t *missedFrames
,
1881 GLfloat
*lastMissedUsage
)
1883 int status
= GLX_BAD_CONTEXT
;
1884 #ifdef __DRI_FRAME_TRACKING
1886 __DRIdrawable
* const pdraw
= GetDRIDrawable(dpy
, drawable
, & screen
);
1887 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs(dpy
, screen
);
1889 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1892 status
= psc
->frameTracking
->queryFrameTracking(pdraw
, sbc
, missedFrames
,
1893 lastMissedUsage
, &usage
);
1899 (void) missedFrames
;
1900 (void) lastMissedUsage
;
1907 ** GLX_SGI_video_sync
1909 static int __glXGetVideoSyncSGI(unsigned int *count
)
1911 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1912 * FIXME: there should be a GLX encoding for this call. I can find no
1913 * FIXME: documentation for the GLX encoding.
1915 #ifdef __DRI_MEDIA_STREAM_COUNTER
1916 GLXContext gc
= __glXGetCurrentContext();
1919 if ( (gc
!= NULL
) && gc
->isDirect
) {
1920 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1922 if ( psc
->msc
&& psc
->driScreen
) {
1923 __DRIdrawable
* const pdraw
=
1924 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1928 ret
= (*psc
->msc
->getDrawableMSC
)(&psc
->__driScreen
, pdraw
, &temp
);
1929 *count
= (unsigned) temp
;
1931 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1937 return GLX_BAD_CONTEXT
;
1940 static int __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1942 #ifdef __DRI_MEDIA_STREAM_COUNTER
1943 GLXContext gc
= __glXGetCurrentContext();
1945 if ( divisor
<= 0 || remainder
< 0 )
1946 return GLX_BAD_VALUE
;
1948 if ( (gc
!= NULL
) && gc
->isDirect
) {
1949 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( gc
->currentDpy
,
1951 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
1952 __DRIdrawable
* const pdraw
=
1953 GetDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1958 ret
= (*psc
->msc
->waitForMSC
)(pdraw
, 0, divisor
, remainder
, &msc
,
1960 *count
= (unsigned) msc
;
1961 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
1967 return GLX_BAD_CONTEXT
;
1972 ** GLX_SGIX_fbconfig
1973 ** Many of these functions are aliased to GLX 1.3 entry points in the
1974 ** GLX_functions table.
1977 PUBLIC
GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1978 (Display
*dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1979 (dpy
, config
, attribute
, value
),
1980 glXGetFBConfigAttrib
)
1982 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1983 (Display
*dpy
, int screen
, int *attrib_list
, int *nelements
),
1984 (dpy
, screen
, attrib_list
, nelements
),
1987 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1988 (Display
* dpy
, GLXFBConfigSGIX config
),
1990 glXGetVisualFromFBConfig
)
1992 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
*dpy
,
1993 GLXFBConfigSGIX config
, Pixmap pixmap
)
1995 xGLXVendorPrivateWithReplyReq
*vpreq
;
1996 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1997 GLXPixmap xid
= None
;
1999 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2000 __GLXscreenConfigs
* psc
;
2003 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2007 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2009 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2010 opcode
= __glXSetupForCommand(dpy
);
2015 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2017 GetReqExtra(GLXVendorPrivateWithReply
,
2018 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-sz_xGLXVendorPrivateWithReplyReq
,vpreq
);
2019 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*)vpreq
;
2020 req
->reqType
= opcode
;
2021 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2022 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2023 req
->screen
= fbconfig
->screen
;
2024 req
->fbconfig
= fbconfig
->fbconfigID
;
2025 req
->pixmap
= pixmap
;
2026 req
->glxpixmap
= xid
= XAllocID(dpy
);
2034 PUBLIC GLXContext
glXCreateContextWithConfigSGIX(Display
*dpy
,
2035 GLXFBConfigSGIX config
, int renderType
,
2036 GLXContext shareList
, Bool allowDirect
)
2038 GLXContext gc
= NULL
;
2039 const __GLcontextModes
* const fbconfig
= (__GLcontextModes
*) config
;
2040 __GLXscreenConfigs
* psc
;
2043 if ( (dpy
== NULL
) || (config
== NULL
) ) {
2047 psc
= GetGLXScreenConfigs( dpy
, fbconfig
->screen
);
2049 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
) ) {
2050 gc
= CreateContext( dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2051 allowDirect
, None
, False
, renderType
);
2058 PUBLIC GLXFBConfigSGIX
glXGetFBConfigFromVisualSGIX(Display
*dpy
,
2061 __GLXdisplayPrivate
*priv
;
2062 __GLXscreenConfigs
*psc
;
2064 if ( (GetGLXPrivScreenConfig( dpy
, vis
->screen
, & priv
, & psc
) != Success
)
2065 && __glXExtensionBitIsEnabled( psc
, SGIX_fbconfig_bit
)
2066 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
) ) {
2067 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual( psc
->configs
,
2076 ** GLX_SGIX_swap_group
2078 static void __glXJoinSwapGroupSGIX(Display
*dpy
, GLXDrawable drawable
,
2088 ** GLX_SGIX_swap_barrier
2090 static void __glXBindSwapBarrierSGIX(Display
*dpy
, GLXDrawable drawable
,
2098 static Bool
__glXQueryMaxSwapBarriersSGIX(Display
*dpy
, int screen
, int *max
)
2108 ** GLX_OML_sync_control
2110 static Bool
__glXGetSyncValuesOML(Display
*dpy
, GLXDrawable drawable
,
2111 int64_t *ust
, int64_t *msc
, int64_t *sbc
)
2113 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2114 __GLXdisplayPrivate
* const priv
= __glXInitialize(dpy
);
2116 if ( priv
!= NULL
) {
2118 __DRIdrawable
* const pdraw
= GetDRIDrawable( dpy
, drawable
, & i
);
2119 __GLXscreenConfigs
* const psc
= &priv
->screenConfigs
[i
];
2121 assert( (pdraw
== NULL
) || (i
!= -1) );
2122 return ( (pdraw
&& psc
->sbc
&& psc
->msc
)
2123 && ((*psc
->msc
->getMSC
)(&psc
->driScreen
, msc
) == 0)
2124 && ((*psc
->sbc
->getSBC
)(pdraw
, sbc
) == 0)
2125 && (__glXGetUST(ust
) == 0) );
2137 #ifdef GLX_DIRECT_RENDERING
2139 __driGetMscRateOML(__DRIdrawable
*draw
, int32_t *numerator
, int32_t *denominator
)
2142 __GLXscreenConfigs
*psc
;
2143 XF86VidModeModeLine mode_line
;
2146 __GLXdrawable
*glxDraw
;
2148 glxDraw
= containerOf(draw
, __GLXdrawable
, driDrawable
);
2150 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2151 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
) ) {
2152 unsigned n
= dot_clock
* 1000;
2153 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2155 # define V_INTERLACE 0x010
2156 # define V_DBLSCAN 0x020
2158 if (mode_line
.flags
& V_INTERLACE
)
2160 else if (mode_line
.flags
& V_DBLSCAN
)
2163 /* The OML_sync_control spec requires that if the refresh rate is a
2164 * whole number, that the returned numerator be equal to the refresh
2165 * rate and the denominator be 1.
2173 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2175 /* This is a poor man's way to reduce a fraction. It's far from
2176 * perfect, but it will work well enough for this situation.
2179 for (i
= 0; f
[i
] != 0; i
++) {
2180 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2201 * Determine the refresh rate of the specified drawable and display.
2203 * \param dpy Display whose refresh rate is to be determined.
2204 * \param drawable Drawable whose refresh rate is to be determined.
2205 * \param numerator Numerator of the refresh rate.
2206 * \param demoninator Denominator of the refresh rate.
2207 * \return If the refresh rate for the specified display and drawable could
2208 * be calculated, True is returned. Otherwise False is returned.
2210 * \note This function is implemented entirely client-side. A lot of other
2211 * functionality is required to export GLX_OML_sync_control, so on
2212 * XFree86 this function can be called for direct-rendering contexts
2213 * when GLX_OML_sync_control appears in the client extension string.
2216 GLboolean
__glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2217 int32_t * numerator
, int32_t * denominator
)
2219 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2220 __DRIdrawable
*driDraw
= GetDRIDrawable(dpy
, drawable
, NULL
);
2222 if (driDraw
== NULL
)
2225 return __driGetMscRateOML(driDraw
, numerator
, denominator
);
2236 static int64_t __glXSwapBuffersMscOML(Display
*dpy
, GLXDrawable drawable
,
2237 int64_t target_msc
, int64_t divisor
,
2240 #ifdef __DRI_SWAP_BUFFER_COUNTER
2242 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2243 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2245 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2246 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2247 * of -1 if the function failed because of errors detected in the input
2250 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2252 if ( divisor
> 0 && remainder
>= divisor
)
2255 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2256 return (*psc
->sbc
->swapBuffersMSC
)(pdraw
, target_msc
,
2257 divisor
, remainder
);
2270 static Bool
__glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2271 int64_t target_msc
, int64_t divisor
,
2272 int64_t remainder
, int64_t *ust
,
2273 int64_t *msc
, int64_t *sbc
)
2275 #ifdef __DRI_MEDIA_STREAM_COUNTER
2277 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2278 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2281 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2282 * error", but the return type in the spec is Bool.
2284 if ( divisor
< 0 || remainder
< 0 || target_msc
< 0 )
2286 if ( divisor
> 0 && remainder
>= divisor
)
2289 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2290 ret
= (*psc
->msc
->waitForMSC
)(pdraw
, target_msc
,
2291 divisor
, remainder
, msc
, sbc
);
2293 /* __glXGetUST returns zero on success and non-zero on failure.
2294 * This function returns True on success and False on failure.
2296 return ( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2312 static Bool
__glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2313 int64_t target_sbc
, int64_t *ust
,
2314 int64_t *msc
, int64_t *sbc
)
2316 #ifdef __DRI_SWAP_BUFFER_COUNTER
2318 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2319 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2322 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2323 * error", but the return type in the spec is Bool.
2325 if ( target_sbc
< 0 )
2328 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2329 ret
= (*psc
->sbc
->waitForSBC
)(pdraw
, target_sbc
, msc
, sbc
);
2331 /* __glXGetUST returns zero on success and non-zero on failure.
2332 * This function returns True on success and False on failure.
2334 return( (ret
== 0) && (__glXGetUST( ust
) == 0) );
2349 * GLX_MESA_allocate_memory
2353 PUBLIC
void *glXAllocateMemoryMESA(Display
*dpy
, int scrn
,
2354 size_t size
, float readFreq
,
2355 float writeFreq
, float priority
)
2357 #ifdef __DRI_ALLOCATE
2358 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2360 if (psc
&& psc
->allocate
)
2361 return (*psc
->allocate
->allocateMemory
)( &psc
->__driScreen
, size
,
2362 readFreq
, writeFreq
,
2372 #endif /* GLX_DIRECT_RENDERING */
2378 PUBLIC
void glXFreeMemoryMESA(Display
*dpy
, int scrn
, void *pointer
)
2380 #ifdef __DRI_ALLOCATE
2381 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2383 if (psc
&& psc
->allocate
)
2384 (*psc
->allocate
->freeMemory
)( &psc
->__driScreen
, pointer
);
2390 #endif /* GLX_DIRECT_RENDERING */
2394 PUBLIC GLuint
glXGetMemoryOffsetMESA( Display
*dpy
, int scrn
,
2395 const void *pointer
)
2397 #ifdef __DRI_ALLOCATE
2398 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, scrn
);
2400 if (psc
&& psc
->allocate
)
2401 return (*psc
->allocate
->memoryOffset
)( &psc
->__driScreen
, pointer
);
2407 #endif /* GLX_DIRECT_RENDERING */
2415 * Mesa extension stubs. These will help reduce portability problems.
2420 * Release all buffers associated with the specified GLX drawable.
2423 * This function was intended for stand-alone Mesa. The issue there is that
2424 * the library doesn't get any notification when a window is closed. In
2425 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2426 * supported, there are 3 different functions to destroy a drawable. It
2427 * should be possible to create GLX protocol (or have it determine which
2428 * protocol to use based on the type of the drawable) to have one function
2429 * do the work of 3. For the direct-rendering case, this function could
2430 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2431 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2432 * would need to be used. This really should be done as part of the new DRI
2435 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2436 * __driGarbageCollectDrawables
2437 * glXDestroyGLXPixmap
2438 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2439 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2441 static Bool
__glXReleaseBuffersMESA( Display
*dpy
, GLXDrawable d
)
2449 PUBLIC GLXPixmap
glXCreateGLXPixmapMESA( Display
*dpy
, XVisualInfo
*visual
,
2450 Pixmap pixmap
, Colormap cmap
)
2462 * GLX_MESA_copy_sub_buffer
2464 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2465 static void __glXCopySubBufferMESA(Display
*dpy
, GLXDrawable drawable
,
2466 int x
, int y
, int width
, int height
)
2468 xGLXVendorPrivateReq
*req
;
2471 CARD32
*drawable_ptr
;
2472 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2475 #ifdef __DRI_COPY_SUB_BUFFER
2477 __DRIdrawable
*pdraw
= GetDRIDrawable( dpy
, drawable
, & screen
);
2478 if ( pdraw
!= NULL
) {
2479 __GLXscreenConfigs
* const psc
= GetGLXScreenConfigs( dpy
, screen
);
2480 if (psc
->copySubBuffer
!= NULL
) {
2481 (*psc
->copySubBuffer
->copySubBuffer
)(pdraw
, x
, y
, width
, height
);
2488 opcode
= __glXSetupForCommand(dpy
);
2493 ** The calling thread may or may not have a current context. If it
2494 ** does, send the context tag so the server can do a flush.
2496 gc
= __glXGetCurrentContext();
2497 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2498 ((drawable
== gc
->currentDrawable
) ||
2499 (drawable
== gc
->currentReadable
)) ) {
2500 tag
= gc
->currentContextTag
;
2506 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4,req
);
2507 req
->reqType
= opcode
;
2508 req
->glxCode
= X_GLXVendorPrivate
;
2509 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2510 req
->contextTag
= tag
;
2512 drawable_ptr
= (CARD32
*) (req
+ 1);
2513 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2514 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2515 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2516 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2518 *drawable_ptr
= drawable
;
2530 * GLX_EXT_texture_from_pixmap
2533 static void __glXBindTexImageEXT(Display
*dpy
,
2534 GLXDrawable drawable
,
2536 const int *attrib_list
)
2538 xGLXVendorPrivateReq
*req
;
2539 GLXContext gc
= __glXGetCurrentContext();
2540 CARD32
*drawable_ptr
;
2542 CARD32
*num_attrib_ptr
;
2552 while (attrib_list
[i
* 2] != None
)
2556 #ifdef GLX_DIRECT_RENDERING
2561 opcode
= __glXSetupForCommand(dpy
);
2566 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
,req
);
2567 req
->reqType
= opcode
;
2568 req
->glxCode
= X_GLXVendorPrivate
;
2569 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2570 req
->contextTag
= gc
->currentContextTag
;
2572 drawable_ptr
= (CARD32
*) (req
+ 1);
2573 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2574 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2575 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2577 *drawable_ptr
= drawable
;
2578 *buffer_ptr
= buffer
;
2579 *num_attrib_ptr
= (CARD32
) i
;
2583 while (attrib_list
[i
* 2] != None
)
2585 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2586 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2595 static void __glXReleaseTexImageEXT(Display
*dpy
,
2596 GLXDrawable drawable
,
2599 xGLXVendorPrivateReq
*req
;
2600 GLXContext gc
= __glXGetCurrentContext();
2601 CARD32
*drawable_ptr
;
2608 #ifdef GLX_DIRECT_RENDERING
2613 opcode
= __glXSetupForCommand(dpy
);
2618 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
)+sizeof(INT32
),req
);
2619 req
->reqType
= opcode
;
2620 req
->glxCode
= X_GLXVendorPrivate
;
2621 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2622 req
->contextTag
= gc
->currentContextTag
;
2624 drawable_ptr
= (CARD32
*) (req
+ 1);
2625 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2627 *drawable_ptr
= drawable
;
2628 *buffer_ptr
= buffer
;
2636 * \c strdup is actually not a standard ANSI C or POSIX routine.
2637 * Irix will not define it if ANSI mode is in effect.
2642 __glXstrdup(const char *str
)
2645 copy
= (char *) Xmalloc(strlen(str
) + 1);
2653 ** glXGetProcAddress support
2656 struct name_address_pair
{
2661 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2662 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2664 static const struct name_address_pair GLX_functions
[] = {
2665 /*** GLX_VERSION_1_0 ***/
2666 GLX_FUNCTION( glXChooseVisual
),
2667 GLX_FUNCTION( glXCopyContext
),
2668 GLX_FUNCTION( glXCreateContext
),
2669 GLX_FUNCTION( glXCreateGLXPixmap
),
2670 GLX_FUNCTION( glXDestroyContext
),
2671 GLX_FUNCTION( glXDestroyGLXPixmap
),
2672 GLX_FUNCTION( glXGetConfig
),
2673 GLX_FUNCTION( glXGetCurrentContext
),
2674 GLX_FUNCTION( glXGetCurrentDrawable
),
2675 GLX_FUNCTION( glXIsDirect
),
2676 GLX_FUNCTION( glXMakeCurrent
),
2677 GLX_FUNCTION( glXQueryExtension
),
2678 GLX_FUNCTION( glXQueryVersion
),
2679 GLX_FUNCTION( glXSwapBuffers
),
2680 GLX_FUNCTION( glXUseXFont
),
2681 GLX_FUNCTION( glXWaitGL
),
2682 GLX_FUNCTION( glXWaitX
),
2684 /*** GLX_VERSION_1_1 ***/
2685 GLX_FUNCTION( glXGetClientString
),
2686 GLX_FUNCTION( glXQueryExtensionsString
),
2687 GLX_FUNCTION( glXQueryServerString
),
2689 /*** GLX_VERSION_1_2 ***/
2690 GLX_FUNCTION( glXGetCurrentDisplay
),
2692 /*** GLX_VERSION_1_3 ***/
2693 GLX_FUNCTION( glXChooseFBConfig
),
2694 GLX_FUNCTION( glXCreateNewContext
),
2695 GLX_FUNCTION( glXCreatePbuffer
),
2696 GLX_FUNCTION( glXCreatePixmap
),
2697 GLX_FUNCTION( glXCreateWindow
),
2698 GLX_FUNCTION( glXDestroyPbuffer
),
2699 GLX_FUNCTION( glXDestroyPixmap
),
2700 GLX_FUNCTION( glXDestroyWindow
),
2701 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2702 GLX_FUNCTION( glXGetFBConfigAttrib
),
2703 GLX_FUNCTION( glXGetFBConfigs
),
2704 GLX_FUNCTION( glXGetSelectedEvent
),
2705 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2706 GLX_FUNCTION( glXMakeContextCurrent
),
2707 GLX_FUNCTION( glXQueryContext
),
2708 GLX_FUNCTION( glXQueryDrawable
),
2709 GLX_FUNCTION( glXSelectEvent
),
2711 /*** GLX_SGI_swap_control ***/
2712 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2714 /*** GLX_SGI_video_sync ***/
2715 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2716 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2718 /*** GLX_SGI_make_current_read ***/
2719 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2720 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2722 /*** GLX_EXT_import_context ***/
2723 GLX_FUNCTION( glXFreeContextEXT
),
2724 GLX_FUNCTION( glXGetContextIDEXT
),
2725 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2726 GLX_FUNCTION( glXImportContextEXT
),
2727 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2729 /*** GLX_SGIX_fbconfig ***/
2730 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2731 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2732 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2733 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2734 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2735 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2737 /*** GLX_SGIX_pbuffer ***/
2738 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2739 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2740 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2741 GLX_FUNCTION( glXSelectEventSGIX
),
2742 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2744 /*** GLX_SGIX_swap_group ***/
2745 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2747 /*** GLX_SGIX_swap_barrier ***/
2748 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2749 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2751 /*** GLX_MESA_allocate_memory ***/
2752 GLX_FUNCTION( glXAllocateMemoryMESA
),
2753 GLX_FUNCTION( glXFreeMemoryMESA
),
2754 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2756 /*** GLX_MESA_copy_sub_buffer ***/
2757 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2759 /*** GLX_MESA_pixmap_colormap ***/
2760 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2762 /*** GLX_MESA_release_buffers ***/
2763 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2765 /*** GLX_MESA_swap_control ***/
2766 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2767 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2769 /*** GLX_MESA_swap_frame_usage ***/
2770 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2771 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2772 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2773 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2775 /*** GLX_ARB_get_proc_address ***/
2776 GLX_FUNCTION( glXGetProcAddressARB
),
2779 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2781 /*** GLX_OML_sync_control ***/
2782 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2783 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2784 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2785 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2786 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2788 /*** GLX_EXT_texture_from_pixmap ***/
2789 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2790 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2792 #ifdef GLX_DIRECT_RENDERING
2793 /*** DRI configuration ***/
2794 GLX_FUNCTION( glXGetScreenDriver
),
2795 GLX_FUNCTION( glXGetDriverConfig
),
2798 { NULL
, NULL
} /* end of list */
2802 static const GLvoid
*
2803 get_glx_proc_address(const char *funcName
)
2807 /* try static functions */
2808 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2809 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2810 return GLX_functions
[i
].Address
;
2818 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2819 * \c glXGetProcAddress.
2821 * \param procName Name of a GL or GLX function.
2822 * \returns A pointer to the named function
2824 * \sa glXGetProcAddress
2826 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
*procName
))( void )
2828 typedef void (*gl_function
)( void );
2832 /* Search the table of GLX and internal functions first. If that
2833 * fails and the supplied name could be a valid core GL name, try
2834 * searching the core GL function table. This check is done to prevent
2835 * DRI based drivers from searching the core GL function table for
2836 * internal API functions.
2839 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2840 if ( (f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2841 && (procName
[2] != 'X') ) {
2842 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2849 * Get the address of a named GL function. This is the GLX 1.4 name for
2850 * \c glXGetProcAddressARB.
2852 * \param procName Name of a GL or GLX function.
2853 * \returns A pointer to the named function
2855 * \sa glXGetProcAddressARB
2857 PUBLIC
void (*glXGetProcAddress(const GLubyte
*procName
))( void )
2858 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2859 __attribute__ ((alias ("glXGetProcAddressARB")));
2862 return glXGetProcAddressARB(procName
);
2864 #endif /* __GNUC__ */
2867 #ifdef GLX_DIRECT_RENDERING
2869 * Get the unadjusted system time (UST). Currently, the UST is measured in
2870 * microseconds since Epoc. The actual resolution of the UST may vary from
2871 * system to system, and the units may vary from release to release.
2872 * Drivers should not call this function directly. They should instead use
2873 * \c glXGetProcAddress to obtain a pointer to the function.
2875 * \param ust Location to store the 64-bit UST
2876 * \returns Zero on success or a negative errno value on failure.
2878 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2880 * \since Internal API version 20030317.
2882 int __glXGetUST( int64_t * ust
)
2886 if ( ust
== NULL
) {
2890 if ( gettimeofday( & tv
, NULL
) == 0 ) {
2891 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2897 #endif /* GLX_DIRECT_RENDERING */