2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * Client-side GLX interface.
36 #include "glxclient.h"
38 #include "glxextensions.h"
40 #ifdef GLX_DIRECT_RENDERING
41 #ifdef GLX_USE_APPLEGL
42 #include "apple_glx_context.h"
43 #include "apple_glx.h"
44 #include "glx_error.h"
47 #include <X11/extensions/xf86vmode.h>
54 #include <X11/Xlib-xcb.h>
59 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
60 static const char __glXGLXClientVersion
[] = "1.4";
62 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
64 static Bool windowExistsFlag
;
66 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
84 GarbageCollectDRIDrawables(struct glx_screen
* sc
)
87 __GLXDRIdrawable
*pdraw
;
88 struct glx_display
*priv
= sc
->display
;
89 XWindowAttributes xwa
;
90 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
92 /* Set no-op error handler so Xlib doesn't bail out if the windows
93 * has alreay been destroyed on the server. */
94 XSync(priv
->dpy
, GL_FALSE
);
95 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
97 if (__glxHashFirst(priv
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
99 windowExistsFlag
= GL_TRUE
;
100 XGetWindowAttributes(priv
->dpy
, draw
, &xwa
); /* dummy request */
101 if (!windowExistsFlag
) {
102 /* Destroy the local drawable data, if the drawable no
103 longer exists in the Xserver */
104 (*pdraw
->destroyDrawable
) (pdraw
);
105 __glxHashDelete(priv
->drawHash
, draw
);
107 } while (__glxHashNext(priv
->drawHash
, &draw
, (void *) &pdraw
) == 1);
110 XSync(priv
->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 _X_HIDDEN __GLXDRIdrawable
*
124 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
126 struct glx_display
*priv
= __glXInitialize(dpy
);
127 __GLXDRIdrawable
*pdraw
;
132 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
142 * Get the GLX per-screen data structure associated with a GLX context.
144 * \param dpy Display for which the GLX per-screen information is to be
146 * \param scrn Screen on \c dpy for which the GLX per-screen information is
148 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
149 * specify a valid GLX screen, or NULL otherwise.
151 * \todo Should this function validate that \c scrn is within the screen
152 * number range for \c dpy?
155 static struct glx_screen
*
156 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
158 struct glx_display
*const priv
= __glXInitialize(dpy
);
162 NULL
) ? priv
->screens
[scrn
] : NULL
;
167 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
168 struct glx_screen
** ppsc
)
170 /* Initialize the extension, if needed . This has the added value
171 * of initializing/allocating the display private
175 return GLX_NO_EXTENSION
;
178 *ppriv
= __glXInitialize(dpy
);
179 if (*ppriv
== NULL
) {
180 return GLX_NO_EXTENSION
;
183 /* Check screen number to see if its valid */
184 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
185 return GLX_BAD_SCREEN
;
188 /* Check to see if the GL is supported on this screen */
189 *ppsc
= (*ppriv
)->screens
[scrn
];
190 if ((*ppsc
)->configs
== NULL
) {
191 /* No support for GL on this screen regardless of visual */
192 return GLX_BAD_VISUAL
;
200 * Determine if a \c GLXFBConfig supplied by the application is valid.
202 * \param dpy Application supplied \c Display pointer.
203 * \param config Application supplied \c GLXFBConfig.
205 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
206 * \c struct glx_config structure is returned. Otherwise, \c NULL
209 static struct glx_config
*
210 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
212 struct glx_display
*const priv
= __glXInitialize(dpy
);
213 int num_screens
= ScreenCount(dpy
);
215 struct glx_config
*config
;
218 for (i
= 0; i
< num_screens
; i
++) {
219 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
220 config
= config
->next
) {
221 if (config
== (struct glx_config
*) fbconfig
) {
232 glx_context_init(struct glx_context
*gc
,
233 struct glx_screen
*psc
, struct glx_config
*config
)
235 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
236 if (!gc
->majorOpcode
)
239 gc
->screen
= psc
->scr
;
242 gc
->isDirect
= GL_TRUE
;
243 gc
->currentContextTag
= -1;
250 * Create a new context. Exactly one of \c vis and \c fbconfig should be
253 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
254 * SGIX_fbconfig protocol be used?
255 * \param renderType For FBConfigs, what is the rendering type?
259 CreateContext(Display
* dpy
, int generic_id
,
260 struct glx_config
*config
,
261 GLXContext shareList_user
,
263 unsigned code
, int renderType
, int screen
)
265 struct glx_context
*gc
= NULL
;
266 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
267 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
271 if (generic_id
== None
)
275 if (allowDirect
&& psc
->vtable
->create_context
)
276 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
278 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
284 case X_GLXCreateContext
: {
285 xGLXCreateContextReq
*req
;
287 /* Send the glXCreateContext request */
288 GetReq(GLXCreateContext
, req
);
289 req
->reqType
= gc
->majorOpcode
;
290 req
->glxCode
= X_GLXCreateContext
;
291 req
->context
= gc
->xid
= XAllocID(dpy
);
292 req
->visual
= generic_id
;
293 req
->screen
= screen
;
294 req
->shareList
= shareList
? shareList
->xid
: None
;
295 req
->isDirect
= gc
->isDirect
;
299 case X_GLXCreateNewContext
: {
300 xGLXCreateNewContextReq
*req
;
302 /* Send the glXCreateNewContext request */
303 GetReq(GLXCreateNewContext
, req
);
304 req
->reqType
= gc
->majorOpcode
;
305 req
->glxCode
= X_GLXCreateNewContext
;
306 req
->context
= gc
->xid
= XAllocID(dpy
);
307 req
->fbconfig
= generic_id
;
308 req
->screen
= screen
;
309 req
->renderType
= renderType
;
310 req
->shareList
= shareList
? shareList
->xid
: None
;
311 req
->isDirect
= gc
->isDirect
;
315 case X_GLXvop_CreateContextWithConfigSGIX
: {
316 xGLXVendorPrivateWithReplyReq
*vpreq
;
317 xGLXCreateContextWithConfigSGIXReq
*req
;
319 /* Send the glXCreateNewContext request */
320 GetReqExtra(GLXVendorPrivateWithReply
,
321 sz_xGLXCreateContextWithConfigSGIXReq
-
322 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
323 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
324 req
->reqType
= gc
->majorOpcode
;
325 req
->glxCode
= X_GLXVendorPrivateWithReply
;
326 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
327 req
->context
= gc
->xid
= XAllocID(dpy
);
328 req
->fbconfig
= generic_id
;
329 req
->screen
= screen
;
330 req
->renderType
= renderType
;
331 req
->shareList
= shareList
? shareList
->xid
: None
;
332 req
->isDirect
= gc
->isDirect
;
337 /* What to do here? This case is the sign of an internal error. It
338 * should never be reachable.
346 gc
->imported
= GL_FALSE
;
347 gc
->renderType
= renderType
;
349 return (GLXContext
) gc
;
353 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
354 GLXContext shareList
, Bool allowDirect
)
356 struct glx_config
*config
= NULL
;
359 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
360 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
362 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
363 if (config
== NULL
) {
366 error
.errorCode
= BadValue
;
367 error
.resourceID
= vis
->visualid
;
368 error
.sequenceNumber
= dpy
->request
;
369 error
.type
= X_Error
;
370 error
.majorCode
= __glXSetupForCommand(dpy
);
371 error
.minorCode
= X_GLXCreateContext
;
372 _XError(dpy
, &error
);
376 renderType
= config
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
379 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
380 X_GLXCreateContext
, renderType
, vis
->screen
);
384 glx_send_destroy_context(Display
*dpy
, XID xid
)
386 CARD8 opcode
= __glXSetupForCommand(dpy
);
387 xGLXDestroyContextReq
*req
;
390 GetReq(GLXDestroyContext
, req
);
391 req
->reqType
= opcode
;
392 req
->glxCode
= X_GLXDestroyContext
;
399 ** Destroy the named context
402 DestroyContext(Display
* dpy
, GLXContext ctx
)
404 struct glx_context
*gc
= (struct glx_context
*) ctx
;
410 if (gc
->currentDpy
) {
411 /* This context is bound to some thread. According to the man page,
412 * we should not actually delete the context until it's unbound.
413 * Note that we set gc->xid = None above. In MakeContextCurrent()
414 * we check for that and delete the context there.
417 glx_send_destroy_context(dpy
, gc
->xid
);
424 if (gc
->vtable
->destroy
)
425 gc
->vtable
->destroy(gc
);
429 glXDestroyContext(Display
* dpy
, GLXContext gc
)
431 DestroyContext(dpy
, gc
);
435 ** Return the major and minor version #s for the GLX extension
438 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
440 struct glx_display
*priv
;
442 /* Init the extension. This fetches the major and minor version. */
443 priv
= __glXInitialize(dpy
);
448 *major
= priv
->majorVersion
;
450 *minor
= priv
->minorVersion
;
455 ** Query the existance of the GLX extension
458 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
460 int major_op
, erb
, evb
;
463 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
474 ** Put a barrier in the token stream that forces the GL to finish its
475 ** work before X can proceed.
480 struct glx_context
*gc
= __glXGetCurrentContext();
482 if (gc
&& gc
->vtable
->wait_gl
)
483 gc
->vtable
->wait_gl(gc
);
487 ** Put a barrier in the token stream that forces X to finish its
488 ** work before GL can proceed.
493 struct glx_context
*gc
= __glXGetCurrentContext();
495 if (gc
&& gc
->vtable
->wait_x
)
496 gc
->vtable
->wait_x(gc
);
500 glXUseXFont(Font font
, int first
, int count
, int listBase
)
502 struct glx_context
*gc
= __glXGetCurrentContext();
504 if (gc
&& gc
->vtable
->use_x_font
)
505 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
508 /************************************************************************/
511 ** Copy the source context to the destination context using the
515 glXCopyContext(Display
* dpy
, GLXContext source_user
,
516 GLXContext dest_user
, unsigned long mask
)
518 struct glx_context
*source
= (struct glx_context
*) source_user
;
519 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
520 #ifdef GLX_USE_APPLEGL
521 struct glx_context
*gc
= __glXGetCurrentContext();
525 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
526 mask
, &errorcode
, &x11error
)) {
527 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
531 xGLXCopyContextReq
*req
;
532 struct glx_context
*gc
= __glXGetCurrentContext();
536 opcode
= __glXSetupForCommand(dpy
);
541 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
543 /* NOT_DONE: This does not work yet */
548 ** If the source is the current context, send its tag so that the context
549 ** can be flushed before the copy.
551 if (source
== gc
&& dpy
== gc
->currentDpy
) {
552 tag
= gc
->currentContextTag
;
558 /* Send the glXCopyContext request */
560 GetReq(GLXCopyContext
, req
);
561 req
->reqType
= opcode
;
562 req
->glxCode
= X_GLXCopyContext
;
563 req
->source
= source
? source
->xid
: None
;
564 req
->dest
= dest
? dest
->xid
: None
;
566 req
->contextTag
= tag
;
569 #endif /* GLX_USE_APPLEGL */
574 * Determine if a context uses direct rendering.
576 * \param dpy Display where the context was created.
577 * \param contextID ID of the context to be tested.
579 * \returns \c GL_TRUE if the context is direct rendering or not.
582 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
584 #if !defined(USE_XCB)
585 xGLXIsDirectReq
*req
;
586 xGLXIsDirectReply reply
;
590 opcode
= __glXSetupForCommand(dpy
);
596 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
597 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
602 const Bool is_direct
= reply
->is_direct
? True
: False
;
607 /* Send the glXIsDirect request */
609 GetReq(GLXIsDirect
, req
);
610 req
->reqType
= opcode
;
611 req
->glxCode
= X_GLXIsDirect
;
612 req
->context
= contextID
;
613 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
617 return reply
.isDirect
;
623 * Shouldn't this function \b always return \c GL_FALSE when
624 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
625 * the GLX protocol here at all?
628 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
630 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
635 else if (gc
->isDirect
) {
638 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
641 return __glXIsDirect(dpy
, gc
->xid
);
646 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
648 #ifdef GLX_USE_APPLEGL
649 int screen
= vis
->screen
;
650 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
651 const struct glx_config
*config
;
653 config
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
655 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
660 xGLXCreateGLXPixmapReq
*req
;
664 opcode
= __glXSetupForCommand(dpy
);
669 /* Send the glXCreateGLXPixmap request */
671 GetReq(GLXCreateGLXPixmap
, req
);
672 req
->reqType
= opcode
;
673 req
->glxCode
= X_GLXCreateGLXPixmap
;
674 req
->screen
= vis
->screen
;
675 req
->visual
= vis
->visualid
;
676 req
->pixmap
= pixmap
;
677 req
->glxpixmap
= xid
= XAllocID(dpy
);
681 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
683 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
684 * is actually bound to a context... */
686 struct glx_display
*const priv
= __glXInitialize(dpy
);
687 __GLXDRIdrawable
*pdraw
;
688 struct glx_screen
*psc
;
689 struct glx_config
*config
;
691 psc
= priv
->screens
[vis
->screen
];
692 if (psc
->driScreen
== NULL
)
694 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
695 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, config
);
697 fprintf(stderr
, "failed to create pixmap\n");
701 if (__glxHashInsert(priv
->drawHash
, req
->glxpixmap
, pdraw
)) {
702 (*pdraw
->destroyDrawable
) (pdraw
);
703 return None
; /* FIXME: Check what we're supposed to do here... */
713 ** Destroy the named pixmap
716 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
718 #ifdef GLX_USE_APPLEGL
719 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
720 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
722 xGLXDestroyGLXPixmapReq
*req
;
725 opcode
= __glXSetupForCommand(dpy
);
730 /* Send the glXDestroyGLXPixmap request */
732 GetReq(GLXDestroyGLXPixmap
, req
);
733 req
->reqType
= opcode
;
734 req
->glxCode
= X_GLXDestroyGLXPixmap
;
735 req
->glxpixmap
= glxpixmap
;
739 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
741 struct glx_display
*const priv
= __glXInitialize(dpy
);
742 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
745 (*pdraw
->destroyDrawable
) (pdraw
);
746 __glxHashDelete(priv
->drawHash
, glxpixmap
);
750 #endif /* GLX_USE_APPLEGL */
754 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
756 #ifdef GLX_USE_APPLEGL
757 GLXContext gc
= glXGetCurrentContext();
758 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
759 apple_glx_swap_buffers(gc
->driContext
);
761 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
764 struct glx_context
*gc
;
770 xGLXSwapBuffersReq
*req
;
773 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
774 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
778 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
783 opcode
= __glXSetupForCommand(dpy
);
789 ** The calling thread may or may not have a current context. If it
790 ** does, send the context tag so the server can do a flush.
792 gc
= __glXGetCurrentContext();
793 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
794 ((drawable
== gc
->currentDrawable
)
795 || (drawable
== gc
->currentReadable
))) {
796 tag
= gc
->currentContextTag
;
803 c
= XGetXCBConnection(dpy
);
804 xcb_glx_swap_buffers(c
, tag
, drawable
);
807 /* Send the glXSwapBuffers request */
809 GetReq(GLXSwapBuffers
, req
);
810 req
->reqType
= opcode
;
811 req
->glxCode
= X_GLXSwapBuffers
;
812 req
->drawable
= drawable
;
813 req
->contextTag
= tag
;
818 #endif /* GLX_USE_APPLEGL */
823 ** Return configuration information for the given display, screen and
824 ** visual combination.
827 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
830 struct glx_display
*priv
;
831 struct glx_screen
*psc
;
832 struct glx_config
*config
;
835 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
836 if (status
== Success
) {
837 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
839 /* Lookup attribute after first finding a match on the visual */
840 if (config
!= NULL
) {
841 return glx_config_get(config
, attribute
, value_return
);
844 status
= GLX_BAD_VISUAL
;
848 ** If we can't find the config for this visual, this visual is not
849 ** supported by the OpenGL implementation on the server.
851 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
852 *value_return
= GL_FALSE
;
859 /************************************************************************/
862 init_fbconfig_for_chooser(struct glx_config
* config
,
863 GLboolean fbconfig_style_tags
)
865 memset(config
, 0, sizeof(struct glx_config
));
866 config
->visualID
= (XID
) GLX_DONT_CARE
;
867 config
->visualType
= GLX_DONT_CARE
;
869 /* glXChooseFBConfig specifies different defaults for these two than
872 if (fbconfig_style_tags
) {
873 config
->rgbMode
= GL_TRUE
;
874 config
->doubleBufferMode
= GLX_DONT_CARE
;
877 config
->visualRating
= GLX_DONT_CARE
;
878 config
->transparentPixel
= GLX_NONE
;
879 config
->transparentRed
= GLX_DONT_CARE
;
880 config
->transparentGreen
= GLX_DONT_CARE
;
881 config
->transparentBlue
= GLX_DONT_CARE
;
882 config
->transparentAlpha
= GLX_DONT_CARE
;
883 config
->transparentIndex
= GLX_DONT_CARE
;
885 config
->drawableType
= GLX_WINDOW_BIT
;
887 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
888 config
->xRenderable
= GLX_DONT_CARE
;
889 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
891 config
->swapMethod
= GLX_DONT_CARE
;
894 #define MATCH_DONT_CARE( param ) \
896 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
897 && (a-> param != b-> param) ) { \
902 #define MATCH_MINIMUM( param ) \
904 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
905 && (a-> param > b-> param) ) { \
910 #define MATCH_EXACT( param ) \
912 if ( a-> param != b-> param) { \
917 /* Test that all bits from a are contained in b */
918 #define MATCH_MASK(param) \
920 if ((a->param & ~b->param) != 0) \
925 * Determine if two GLXFBConfigs are compatible.
927 * \param a Application specified config to test.
928 * \param b Server specified config to test against \c a.
931 fbconfigs_compatible(const struct glx_config
* const a
,
932 const struct glx_config
* const b
)
934 MATCH_DONT_CARE(doubleBufferMode
);
935 MATCH_DONT_CARE(visualType
);
936 MATCH_DONT_CARE(visualRating
);
937 MATCH_DONT_CARE(xRenderable
);
938 MATCH_DONT_CARE(fbconfigID
);
939 MATCH_DONT_CARE(swapMethod
);
941 MATCH_MINIMUM(rgbBits
);
942 MATCH_MINIMUM(numAuxBuffers
);
943 MATCH_MINIMUM(redBits
);
944 MATCH_MINIMUM(greenBits
);
945 MATCH_MINIMUM(blueBits
);
946 MATCH_MINIMUM(alphaBits
);
947 MATCH_MINIMUM(depthBits
);
948 MATCH_MINIMUM(stencilBits
);
949 MATCH_MINIMUM(accumRedBits
);
950 MATCH_MINIMUM(accumGreenBits
);
951 MATCH_MINIMUM(accumBlueBits
);
952 MATCH_MINIMUM(accumAlphaBits
);
953 MATCH_MINIMUM(sampleBuffers
);
954 MATCH_MINIMUM(maxPbufferWidth
);
955 MATCH_MINIMUM(maxPbufferHeight
);
956 MATCH_MINIMUM(maxPbufferPixels
);
957 MATCH_MINIMUM(samples
);
959 MATCH_DONT_CARE(stereoMode
);
962 MATCH_MASK(drawableType
);
963 MATCH_MASK(renderType
);
965 /* There is a bug in a few of the XFree86 DDX drivers. They contain
966 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
967 * Technically speaking, it is a bug in the DDX driver, but there is
968 * enough of an installed base to work around the problem here. In any
969 * case, 0 is not a valid value of the transparent type, so we'll treat 0
970 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
971 * 0 from the server to be a match to maintain backward compatibility with
972 * the (broken) drivers.
975 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
976 if (a
->transparentPixel
== GLX_NONE
) {
977 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
981 MATCH_EXACT(transparentPixel
);
984 switch (a
->transparentPixel
) {
985 case GLX_TRANSPARENT_RGB
:
986 MATCH_DONT_CARE(transparentRed
);
987 MATCH_DONT_CARE(transparentGreen
);
988 MATCH_DONT_CARE(transparentBlue
);
989 MATCH_DONT_CARE(transparentAlpha
);
992 case GLX_TRANSPARENT_INDEX
:
993 MATCH_DONT_CARE(transparentIndex
);
1005 /* There's some trickly language in the GLX spec about how this is supposed
1006 * to work. Basically, if a given component size is either not specified
1007 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1008 * Well, that's really hard to do with the code as-is. This behavior is
1009 * closer to correct, but still not technically right.
1011 #define PREFER_LARGER_OR_ZERO(comp) \
1013 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1014 if ( ((*a)-> comp) == 0 ) { \
1017 else if ( ((*b)-> comp) == 0 ) { \
1021 return ((*b)-> comp) - ((*a)-> comp) ; \
1026 #define PREFER_LARGER(comp) \
1028 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1029 return ((*b)-> comp) - ((*a)-> comp) ; \
1033 #define PREFER_SMALLER(comp) \
1035 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1036 return ((*a)-> comp) - ((*b)-> comp) ; \
1041 * Compare two GLXFBConfigs. This function is intended to be used as the
1042 * compare function passed in to qsort.
1044 * \returns If \c a is a "better" config, according to the specification of
1045 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1046 * better, then a number greater than zero is return. If both are
1047 * equal, zero is returned.
1048 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1051 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1053 /* The order of these comparisons must NOT change. It is defined by
1054 * the GLX 1.3 spec and ARB_multisample.
1057 PREFER_SMALLER(visualSelectGroup
);
1059 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1060 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1061 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1063 PREFER_SMALLER(visualRating
);
1065 /* This isn't quite right. It is supposed to compare the sum of the
1066 * components the user specifically set minimums for.
1068 PREFER_LARGER_OR_ZERO(redBits
);
1069 PREFER_LARGER_OR_ZERO(greenBits
);
1070 PREFER_LARGER_OR_ZERO(blueBits
);
1071 PREFER_LARGER_OR_ZERO(alphaBits
);
1073 PREFER_SMALLER(rgbBits
);
1075 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1076 /* Prefer single-buffer.
1078 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1081 PREFER_SMALLER(numAuxBuffers
);
1083 PREFER_LARGER_OR_ZERO(depthBits
);
1084 PREFER_SMALLER(stencilBits
);
1086 /* This isn't quite right. It is supposed to compare the sum of the
1087 * components the user specifically set minimums for.
1089 PREFER_LARGER_OR_ZERO(accumRedBits
);
1090 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1091 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1092 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1094 PREFER_SMALLER(visualType
);
1096 /* None of the multisample specs say where this comparison should happen,
1097 * so I put it near the end.
1099 PREFER_SMALLER(sampleBuffers
);
1100 PREFER_SMALLER(samples
);
1102 /* None of the pbuffer or fbconfig specs say that this comparison needs
1103 * to happen at all, but it seems like it should.
1105 PREFER_LARGER(maxPbufferWidth
);
1106 PREFER_LARGER(maxPbufferHeight
);
1107 PREFER_LARGER(maxPbufferPixels
);
1114 * Selects and sorts a subset of the supplied configs based on the attributes.
1115 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1116 * and \c glXChooseFBConfigSGIX.
1118 * \param configs Array of pointers to possible configs. The elements of
1119 * this array that do not meet the criteria will be set to
1120 * NULL. The remaining elements will be sorted according to
1121 * the various visual / FBConfig selection rules.
1122 * \param num_configs Number of elements in the \c configs array.
1123 * \param attribList Attributes used select from \c configs. This array is
1124 * terminated by a \c None tag. The array can either take
1125 * the form expected by \c glXChooseVisual (where boolean
1126 * tags do not have a value) or by \c glXChooseFBConfig
1127 * (where every tag has a value).
1128 * \param fbconfig_style_tags Selects whether \c attribList is in
1129 * \c glXChooseVisual style or
1130 * \c glXChooseFBConfig style.
1131 * \returns The number of valid elements left in \c configs.
1133 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1136 choose_visual(struct glx_config
** configs
, int num_configs
,
1137 const int *attribList
, GLboolean fbconfig_style_tags
)
1139 struct glx_config test_config
;
1143 /* This is a fairly direct implementation of the selection method
1144 * described by GLX_SGIX_fbconfig. Start by culling out all the
1145 * configs that are not compatible with the selected parameter
1149 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1150 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1151 (const INT32
*) attribList
,
1152 GL_TRUE
, fbconfig_style_tags
);
1155 for (i
= 0; i
< num_configs
; i
++) {
1156 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1157 configs
[base
] = configs
[i
];
1166 if (base
< num_configs
) {
1167 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1170 /* After the incompatible configs are removed, the resulting
1171 * list is sorted according to the rules set out in the various
1175 qsort(configs
, base
, sizeof(struct glx_config
*),
1176 (int (*)(const void *, const void *)) fbconfig_compare
);
1184 ** Return the visual that best matches the template. Return None if no
1185 ** visual matches the template.
1187 _X_EXPORT XVisualInfo
*
1188 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1190 XVisualInfo
*visualList
= NULL
;
1191 struct glx_display
*priv
;
1192 struct glx_screen
*psc
;
1193 struct glx_config test_config
;
1194 struct glx_config
*config
;
1195 struct glx_config
*best_config
= NULL
;
1198 ** Get a list of all visuals, return if list is empty
1200 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1206 ** Build a template from the defaults and the attribute list
1207 ** Free visual list and return if an unexpected token is encountered
1209 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1210 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1211 (const INT32
*) attribList
,
1215 ** Eliminate visuals that don't meet minimum requirements
1216 ** Compute a score for those that do
1217 ** Remember which visual, if any, got the highest score
1218 ** If no visual is acceptable, return None
1219 ** Otherwise, create an XVisualInfo list with just the selected X visual
1222 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1223 if (fbconfigs_compatible(&test_config
, config
)
1224 && ((best_config
== NULL
) ||
1225 (fbconfig_compare (&config
, &best_config
) < 0))) {
1226 XVisualInfo visualTemplate
;
1227 XVisualInfo
*newList
;
1230 visualTemplate
.screen
= screen
;
1231 visualTemplate
.visualid
= config
->visualID
;
1232 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1233 &visualTemplate
, &i
);
1237 visualList
= newList
;
1238 best_config
= config
;
1243 #ifdef GLX_USE_APPLEGL
1244 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1245 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1253 _X_EXPORT
const char *
1254 glXQueryExtensionsString(Display
* dpy
, int screen
)
1256 struct glx_screen
*psc
;
1257 struct glx_display
*priv
;
1259 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1263 if (!psc
->effectiveGLXexts
) {
1264 if (!psc
->serverGLXexts
) {
1265 psc
->serverGLXexts
=
1266 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1270 __glXCalculateUsableExtensions(psc
,
1271 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1272 (psc
->driScreen
!= NULL
),
1276 priv
->minorVersion
);
1279 return psc
->effectiveGLXexts
;
1282 _X_EXPORT
const char *
1283 glXGetClientString(Display
* dpy
, int name
)
1289 return (__glXGLXClientVendorName
);
1291 return (__glXGLXClientVersion
);
1292 case GLX_EXTENSIONS
:
1293 return (__glXGetClientExtensions());
1299 _X_EXPORT
const char *
1300 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1302 struct glx_screen
*psc
;
1303 struct glx_display
*priv
;
1307 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1313 str
= &priv
->serverGLXvendor
;
1316 str
= &priv
->serverGLXversion
;
1318 case GLX_EXTENSIONS
:
1319 str
= &psc
->serverGLXexts
;
1326 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1333 __glXClientInfo(Display
* dpy
, int opcode
)
1335 char *ext_str
= __glXGetClientGLExtensionString();
1336 int size
= strlen(ext_str
) + 1;
1339 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1340 xcb_glx_client_info(c
,
1341 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1343 xGLXClientInfoReq
*req
;
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 req
->length
+= (size
+ 3) >> 2;
1354 req
->numbytes
= size
;
1355 Data(dpy
, ext_str
, size
);
1359 #endif /* USE_XCB */
1366 ** EXT_import_context
1370 glXGetCurrentDisplay(void)
1372 struct glx_context
*gc
= __glXGetCurrentContext();
1375 return gc
->currentDpy
;
1379 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1380 glXGetCurrentDisplay
)
1382 #ifndef GLX_USE_APPLEGL
1383 _X_EXPORT GLXContext
1384 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1386 struct glx_display
*priv
= __glXInitialize(dpy
);
1387 struct glx_screen
*psc
;
1388 xGLXQueryContextReply reply
;
1390 struct glx_context
*ctx
;
1391 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1394 struct glx_config
*mode
;
1396 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1399 opcode
= __glXSetupForCommand(dpy
);
1403 /* Send the glXQueryContextInfoEXT request */
1406 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1407 xGLXQueryContextReq
*req
;
1409 GetReq(GLXQueryContext
, req
);
1411 req
->reqType
= opcode
;
1412 req
->glxCode
= X_GLXQueryContext
;
1413 req
->context
= contextID
;
1416 xGLXVendorPrivateReq
*vpreq
;
1417 xGLXQueryContextInfoEXTReq
*req
;
1419 GetReqExtra(GLXVendorPrivate
,
1420 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1422 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1423 req
->reqType
= opcode
;
1424 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1425 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1426 req
->context
= contextID
;
1429 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1431 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1432 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1435 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1439 /* Look up screen first so we can look up visuals/fbconfigs later */
1441 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1442 if (pProp
[0] == GLX_SCREEN
)
1443 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1452 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1454 case GLX_SHARE_CONTEXT_EXT
:
1457 case GLX_VISUAL_ID_EXT
:
1458 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1460 case GLX_FBCONFIG_ID
:
1461 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1463 case GLX_RENDER_TYPE
:
1464 renderType
= pProp
[1];
1471 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1475 ctx
->xid
= contextID
;
1476 ctx
->imported
= GL_TRUE
;
1477 ctx
->share_xid
= share
;
1479 return (GLXContext
) ctx
;
1485 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1487 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1489 switch (attribute
) {
1490 case GLX_SHARE_CONTEXT_EXT
:
1491 *value
= ctx
->share_xid
;
1493 case GLX_VISUAL_ID_EXT
:
1494 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1497 *value
= ctx
->screen
;
1499 case GLX_FBCONFIG_ID
:
1500 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1502 case GLX_RENDER_TYPE
:
1503 *value
= ctx
->renderType
;
1506 return GLX_BAD_ATTRIBUTE
;
1512 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1513 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1514 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1516 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1518 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1524 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1526 DestroyContext(dpy
, ctx
);
1530 _X_EXPORT GLXFBConfig
*
1531 glXChooseFBConfig(Display
* dpy
, int screen
,
1532 const int *attribList
, int *nitems
)
1534 struct glx_config
**config_list
;
1538 config_list
= (struct glx_config
**)
1539 glXGetFBConfigs(dpy
, screen
, &list_size
);
1541 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1542 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1543 if (list_size
== 0) {
1549 *nitems
= list_size
;
1550 return (GLXFBConfig
*) config_list
;
1554 _X_EXPORT GLXContext
1555 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1556 int renderType
, GLXContext shareList
, Bool allowDirect
)
1558 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1560 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1561 allowDirect
, X_GLXCreateNewContext
, renderType
,
1566 _X_EXPORT GLXDrawable
1567 glXGetCurrentReadDrawable(void)
1569 struct glx_context
*gc
= __glXGetCurrentContext();
1571 return gc
->currentReadable
;
1575 _X_EXPORT GLXFBConfig
*
1576 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1578 struct glx_display
*priv
= __glXInitialize(dpy
);
1579 struct glx_config
**config_list
= NULL
;
1580 struct glx_config
*config
;
1581 unsigned num_configs
= 0;
1585 if (priv
&& (priv
->screens
!= NULL
)
1586 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1587 && (priv
->screens
[screen
]->configs
!= NULL
)
1588 && (priv
->screens
[screen
]->configs
->fbconfigID
1589 != (int) GLX_DONT_CARE
)) {
1591 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1592 config
= config
->next
) {
1593 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1598 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1599 if (config_list
!= NULL
) {
1600 *nelements
= num_configs
;
1602 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1603 config
= config
->next
) {
1604 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1605 config_list
[i
] = config
;
1612 return (GLXFBConfig
*) config_list
;
1617 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1618 int attribute
, int *value
)
1620 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1623 return GLXBadFBConfig
;
1625 return glx_config_get(config
, attribute
, value
);
1629 _X_EXPORT XVisualInfo
*
1630 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1632 XVisualInfo visualTemplate
;
1633 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1637 ** Get a list of all visuals, return if list is empty
1639 visualTemplate
.visualid
= config
->visualID
;
1640 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1643 #ifndef GLX_USE_APPLEGL
1645 ** GLX_SGI_swap_control
1648 __glXSwapIntervalSGI(int interval
)
1650 xGLXVendorPrivateReq
*req
;
1651 struct glx_context
*gc
= __glXGetCurrentContext();
1652 struct glx_screen
*psc
;
1654 CARD32
*interval_ptr
;
1658 return GLX_BAD_CONTEXT
;
1661 if (interval
<= 0) {
1662 return GLX_BAD_VALUE
;
1665 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1667 #ifdef GLX_DIRECT_RENDERING
1668 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1669 __GLXDRIdrawable
*pdraw
=
1670 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1671 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1676 dpy
= gc
->currentDpy
;
1677 opcode
= __glXSetupForCommand(dpy
);
1682 /* Send the glXSwapIntervalSGI request */
1684 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1685 req
->reqType
= opcode
;
1686 req
->glxCode
= X_GLXVendorPrivate
;
1687 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1688 req
->contextTag
= gc
->currentContextTag
;
1690 interval_ptr
= (CARD32
*) (req
+ 1);
1691 *interval_ptr
= interval
;
1702 ** GLX_MESA_swap_control
1705 __glXSwapIntervalMESA(unsigned int interval
)
1707 #ifdef GLX_DIRECT_RENDERING
1708 struct glx_context
*gc
= __glXGetCurrentContext();
1710 if (gc
!= NULL
&& gc
->isDirect
) {
1711 struct glx_screen
*psc
;
1713 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1714 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1715 __GLXDRIdrawable
*pdraw
=
1716 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1717 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1722 return GLX_BAD_CONTEXT
;
1727 __glXGetSwapIntervalMESA(void)
1729 #ifdef GLX_DIRECT_RENDERING
1730 struct glx_context
*gc
= __glXGetCurrentContext();
1732 if (gc
!= NULL
&& gc
->isDirect
) {
1733 struct glx_screen
*psc
;
1735 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1736 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1737 __GLXDRIdrawable
*pdraw
=
1738 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1739 return psc
->driScreen
->getSwapInterval(pdraw
);
1749 ** GLX_SGI_video_sync
1752 __glXGetVideoSyncSGI(unsigned int *count
)
1754 int64_t ust
, msc
, sbc
;
1756 struct glx_context
*gc
= __glXGetCurrentContext();
1757 struct glx_screen
*psc
;
1758 #ifdef GLX_DIRECT_RENDERING
1759 __GLXDRIdrawable
*pdraw
;
1763 return GLX_BAD_CONTEXT
;
1765 #ifdef GLX_DIRECT_RENDERING
1767 return GLX_BAD_CONTEXT
;
1770 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1771 #ifdef GLX_DIRECT_RENDERING
1772 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1775 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1776 * FIXME: there should be a GLX encoding for this call. I can find no
1777 * FIXME: documentation for the GLX encoding.
1779 #ifdef GLX_DIRECT_RENDERING
1780 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1781 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1782 *count
= (unsigned) msc
;
1783 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1787 return GLX_BAD_CONTEXT
;
1791 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1793 struct glx_context
*gc
= __glXGetCurrentContext();
1794 struct glx_screen
*psc
;
1795 #ifdef GLX_DIRECT_RENDERING
1796 __GLXDRIdrawable
*pdraw
;
1798 int64_t ust
, msc
, sbc
;
1801 if (divisor
<= 0 || remainder
< 0)
1802 return GLX_BAD_VALUE
;
1805 return GLX_BAD_CONTEXT
;
1807 #ifdef GLX_DIRECT_RENDERING
1809 return GLX_BAD_CONTEXT
;
1812 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1813 #ifdef GLX_DIRECT_RENDERING
1814 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1817 #ifdef GLX_DIRECT_RENDERING
1818 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1819 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1821 *count
= (unsigned) msc
;
1822 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1826 return GLX_BAD_CONTEXT
;
1829 #endif /* GLX_USE_APPLEGL */
1832 ** GLX_SGIX_fbconfig
1833 ** Many of these functions are aliased to GLX 1.3 entry points in the
1834 ** GLX_functions table.
1838 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1839 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1840 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1842 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1843 (Display
* dpy
, int screen
, int *attrib_list
,
1844 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1847 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1848 (Display
* dpy
, GLXFBConfigSGIX config
),
1849 (dpy
, config
), glXGetVisualFromFBConfig
)
1852 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1853 GLXFBConfigSGIX fbconfig
,
1856 #ifndef GLX_USE_APPLEGL
1857 xGLXVendorPrivateWithReplyReq
*vpreq
;
1858 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1859 GLXPixmap xid
= None
;
1861 struct glx_screen
*psc
;
1863 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1866 if ((dpy
== NULL
) || (config
== NULL
)) {
1869 #ifdef GLX_USE_APPLEGL
1870 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1875 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1877 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1878 opcode
= __glXSetupForCommand(dpy
);
1883 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1885 GetReqExtra(GLXVendorPrivateWithReply
,
1886 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1887 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1888 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1889 req
->reqType
= opcode
;
1890 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1891 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1892 req
->screen
= config
->screen
;
1893 req
->fbconfig
= config
->fbconfigID
;
1894 req
->pixmap
= pixmap
;
1895 req
->glxpixmap
= xid
= XAllocID(dpy
);
1904 _X_EXPORT GLXContext
1905 glXCreateContextWithConfigSGIX(Display
* dpy
,
1906 GLXFBConfigSGIX fbconfig
, int renderType
,
1907 GLXContext shareList
, Bool allowDirect
)
1909 GLXContext gc
= NULL
;
1910 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1911 struct glx_screen
*psc
;
1914 if ((dpy
== NULL
) || (config
== NULL
)) {
1918 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1920 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1921 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1923 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
1931 _X_EXPORT GLXFBConfigSGIX
1932 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
1934 struct glx_display
*priv
;
1935 struct glx_screen
*psc
= NULL
;
1937 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
1938 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
1939 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
1940 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
1947 #ifndef GLX_USE_APPLEGL
1949 ** GLX_SGIX_swap_group
1952 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
1962 ** GLX_SGIX_swap_barrier
1965 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
1973 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
1983 ** GLX_OML_sync_control
1986 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
1987 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
1989 struct glx_display
* const priv
= __glXInitialize(dpy
);
1991 #ifdef GLX_DIRECT_RENDERING
1992 __GLXDRIdrawable
*pdraw
;
1994 struct glx_screen
*psc
;
1999 #ifdef GLX_DIRECT_RENDERING
2000 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2001 psc
= pdraw
? pdraw
->psc
: NULL
;
2002 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2003 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2011 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2013 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
2014 int32_t * numerator
, int32_t * denominator
)
2017 struct glx_screen
*psc
;
2018 XF86VidModeModeLine mode_line
;
2023 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2024 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2025 unsigned n
= dot_clock
* 1000;
2026 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2028 # define V_INTERLACE 0x010
2029 # define V_DBLSCAN 0x020
2031 if (mode_line
.flags
& V_INTERLACE
)
2033 else if (mode_line
.flags
& V_DBLSCAN
)
2036 /* The OML_sync_control spec requires that if the refresh rate is a
2037 * whole number, that the returned numerator be equal to the refresh
2038 * rate and the denominator be 1.
2046 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2048 /* This is a poor man's way to reduce a fraction. It's far from
2049 * perfect, but it will work well enough for this situation.
2052 for (i
= 0; f
[i
] != 0; i
++) {
2053 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2079 * Determine the refresh rate of the specified drawable and display.
2081 * \param dpy Display whose refresh rate is to be determined.
2082 * \param drawable Drawable whose refresh rate is to be determined.
2083 * \param numerator Numerator of the refresh rate.
2084 * \param demoninator Denominator of the refresh rate.
2085 * \return If the refresh rate for the specified display and drawable could
2086 * be calculated, True is returned. Otherwise False is returned.
2088 * \note This function is implemented entirely client-side. A lot of other
2089 * functionality is required to export GLX_OML_sync_control, so on
2090 * XFree86 this function can be called for direct-rendering contexts
2091 * when GLX_OML_sync_control appears in the client extension string.
2095 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2096 int32_t * numerator
, int32_t * denominator
)
2098 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2099 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2104 return __glxGetMscRate(draw
, numerator
, denominator
);
2116 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2117 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2119 struct glx_context
*gc
= __glXGetCurrentContext();
2120 #ifdef GLX_DIRECT_RENDERING
2121 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2122 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2125 if (!gc
) /* no GLX for this */
2128 #ifdef GLX_DIRECT_RENDERING
2129 if (!pdraw
|| !gc
->isDirect
)
2133 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2134 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2135 * of -1 if the function failed because of errors detected in the input
2138 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2140 if (divisor
> 0 && remainder
>= divisor
)
2143 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2146 #ifdef GLX_DIRECT_RENDERING
2147 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2148 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2157 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2158 int64_t target_msc
, int64_t divisor
,
2159 int64_t remainder
, int64_t * ust
,
2160 int64_t * msc
, int64_t * sbc
)
2162 #ifdef GLX_DIRECT_RENDERING
2163 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2165 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2169 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2170 * error", but the return type in the spec is Bool.
2172 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2174 if (divisor
> 0 && remainder
>= divisor
)
2177 #ifdef GLX_DIRECT_RENDERING
2178 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2179 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2190 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2191 int64_t target_sbc
, int64_t * ust
,
2192 int64_t * msc
, int64_t * sbc
)
2194 #ifdef GLX_DIRECT_RENDERING
2195 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2197 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2200 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2201 * error", but the return type in the spec is Bool.
2206 #ifdef GLX_DIRECT_RENDERING
2207 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2208 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2220 * Mesa extension stubs. These will help reduce portability problems.
2225 * Release all buffers associated with the specified GLX drawable.
2228 * This function was intended for stand-alone Mesa. The issue there is that
2229 * the library doesn't get any notification when a window is closed. In
2230 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2231 * supported, there are 3 different functions to destroy a drawable. It
2232 * should be possible to create GLX protocol (or have it determine which
2233 * protocol to use based on the type of the drawable) to have one function
2234 * do the work of 3. For the direct-rendering case, this function could
2235 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2236 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2237 * would need to be used. This really should be done as part of the new DRI
2240 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2241 * __driGarbageCollectDrawables
2242 * glXDestroyGLXPixmap
2243 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2244 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2247 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2256 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2257 Pixmap pixmap
, Colormap cmap
)
2270 * GLX_MESA_copy_sub_buffer
2272 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2274 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2275 int x
, int y
, int width
, int height
)
2277 xGLXVendorPrivateReq
*req
;
2278 struct glx_context
*gc
;
2280 CARD32
*drawable_ptr
;
2281 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2284 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2285 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2286 if (pdraw
!= NULL
) {
2287 struct glx_screen
*psc
= pdraw
->psc
;
2288 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2290 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2297 opcode
= __glXSetupForCommand(dpy
);
2302 ** The calling thread may or may not have a current context. If it
2303 ** does, send the context tag so the server can do a flush.
2305 gc
= __glXGetCurrentContext();
2306 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2307 ((drawable
== gc
->currentDrawable
) ||
2308 (drawable
== gc
->currentReadable
))) {
2309 tag
= gc
->currentContextTag
;
2316 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2317 req
->reqType
= opcode
;
2318 req
->glxCode
= X_GLXVendorPrivate
;
2319 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2320 req
->contextTag
= tag
;
2322 drawable_ptr
= (CARD32
*) (req
+ 1);
2323 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2324 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2325 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2326 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2328 *drawable_ptr
= drawable
;
2340 __glXBindTexImageEXT(Display
* dpy
,
2341 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2343 struct glx_context
*gc
= __glXGetCurrentContext();
2345 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2348 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2352 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2354 struct glx_context
*gc
= __glXGetCurrentContext();
2356 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2359 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2364 #endif /* GLX_USE_APPLEGL */
2367 * \c strdup is actually not a standard ANSI C or POSIX routine.
2368 * Irix will not define it if ANSI mode is in effect.
2373 __glXstrdup(const char *str
)
2376 copy
= (char *) Xmalloc(strlen(str
) + 1);
2384 ** glXGetProcAddress support
2387 struct name_address_pair
2393 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2394 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2396 static const struct name_address_pair GLX_functions
[] = {
2397 /*** GLX_VERSION_1_0 ***/
2398 GLX_FUNCTION(glXChooseVisual
),
2399 GLX_FUNCTION(glXCopyContext
),
2400 GLX_FUNCTION(glXCreateContext
),
2401 GLX_FUNCTION(glXCreateGLXPixmap
),
2402 GLX_FUNCTION(glXDestroyContext
),
2403 GLX_FUNCTION(glXDestroyGLXPixmap
),
2404 GLX_FUNCTION(glXGetConfig
),
2405 GLX_FUNCTION(glXGetCurrentContext
),
2406 GLX_FUNCTION(glXGetCurrentDrawable
),
2407 GLX_FUNCTION(glXIsDirect
),
2408 GLX_FUNCTION(glXMakeCurrent
),
2409 GLX_FUNCTION(glXQueryExtension
),
2410 GLX_FUNCTION(glXQueryVersion
),
2411 GLX_FUNCTION(glXSwapBuffers
),
2412 GLX_FUNCTION(glXUseXFont
),
2413 GLX_FUNCTION(glXWaitGL
),
2414 GLX_FUNCTION(glXWaitX
),
2416 /*** GLX_VERSION_1_1 ***/
2417 GLX_FUNCTION(glXGetClientString
),
2418 GLX_FUNCTION(glXQueryExtensionsString
),
2419 GLX_FUNCTION(glXQueryServerString
),
2421 /*** GLX_VERSION_1_2 ***/
2422 GLX_FUNCTION(glXGetCurrentDisplay
),
2424 /*** GLX_VERSION_1_3 ***/
2425 GLX_FUNCTION(glXChooseFBConfig
),
2426 GLX_FUNCTION(glXCreateNewContext
),
2427 GLX_FUNCTION(glXCreatePbuffer
),
2428 GLX_FUNCTION(glXCreatePixmap
),
2429 GLX_FUNCTION(glXCreateWindow
),
2430 GLX_FUNCTION(glXDestroyPbuffer
),
2431 GLX_FUNCTION(glXDestroyPixmap
),
2432 GLX_FUNCTION(glXDestroyWindow
),
2433 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2434 GLX_FUNCTION(glXGetFBConfigAttrib
),
2435 GLX_FUNCTION(glXGetFBConfigs
),
2436 GLX_FUNCTION(glXGetSelectedEvent
),
2437 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2438 GLX_FUNCTION(glXMakeContextCurrent
),
2439 GLX_FUNCTION(glXQueryContext
),
2440 GLX_FUNCTION(glXQueryDrawable
),
2441 GLX_FUNCTION(glXSelectEvent
),
2443 #ifndef GLX_USE_APPLEGL
2444 /*** GLX_SGI_swap_control ***/
2445 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2447 /*** GLX_SGI_video_sync ***/
2448 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2449 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2451 /*** GLX_SGI_make_current_read ***/
2452 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2453 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2455 /*** GLX_EXT_import_context ***/
2456 GLX_FUNCTION(glXFreeContextEXT
),
2457 GLX_FUNCTION(glXGetContextIDEXT
),
2458 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2459 GLX_FUNCTION(glXImportContextEXT
),
2460 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2463 /*** GLX_SGIX_fbconfig ***/
2464 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2465 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2466 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2467 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2468 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2469 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2471 #ifndef GLX_USE_APPLEGL
2472 /*** GLX_SGIX_pbuffer ***/
2473 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2474 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2475 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2476 GLX_FUNCTION(glXSelectEventSGIX
),
2477 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2479 /*** GLX_SGIX_swap_group ***/
2480 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2482 /*** GLX_SGIX_swap_barrier ***/
2483 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2484 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2486 /*** GLX_MESA_copy_sub_buffer ***/
2487 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2489 /*** GLX_MESA_pixmap_colormap ***/
2490 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2492 /*** GLX_MESA_release_buffers ***/
2493 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2495 /*** GLX_MESA_swap_control ***/
2496 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2497 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2500 /*** GLX_ARB_get_proc_address ***/
2501 GLX_FUNCTION(glXGetProcAddressARB
),
2504 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2506 #ifndef GLX_USE_APPLEGL
2507 /*** GLX_OML_sync_control ***/
2508 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2509 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2510 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2511 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2512 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2514 /*** GLX_EXT_texture_from_pixmap ***/
2515 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2516 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2519 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2520 /*** DRI configuration ***/
2521 GLX_FUNCTION(glXGetScreenDriver
),
2522 GLX_FUNCTION(glXGetDriverConfig
),
2525 {NULL
, NULL
} /* end of list */
2528 #ifndef GLX_USE_APPLEGL
2529 static const GLvoid
*
2530 get_glx_proc_address(const char *funcName
)
2534 /* try static functions */
2535 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2536 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2537 return GLX_functions
[i
].Address
;
2545 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2546 * \c glXGetProcAddress.
2548 * \param procName Name of a GL or GLX function.
2549 * \returns A pointer to the named function
2551 * \sa glXGetProcAddress
2553 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2555 typedef void (*gl_function
) (void);
2559 /* Search the table of GLX and internal functions first. If that
2560 * fails and the supplied name could be a valid core GL name, try
2561 * searching the core GL function table. This check is done to prevent
2562 * DRI based drivers from searching the core GL function table for
2563 * internal API functions.
2565 #ifdef GLX_USE_APPLEGL
2566 f
= (gl_function
) apple_glx_get_proc_address(procName
);
2568 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2569 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2570 && (procName
[2] != 'X')) {
2571 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2578 * Get the address of a named GL function. This is the GLX 1.4 name for
2579 * \c glXGetProcAddressARB.
2581 * \param procName Name of a GL or GLX function.
2582 * \returns A pointer to the named function
2584 * \sa glXGetProcAddressARB
2586 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2587 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2588 __attribute__ ((alias("glXGetProcAddressARB")));
2591 return glXGetProcAddressARB(procName
);
2593 #endif /* __GNUC__ */
2596 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2598 * Get the unadjusted system time (UST). Currently, the UST is measured in
2599 * microseconds since Epoc. The actual resolution of the UST may vary from
2600 * system to system, and the units may vary from release to release.
2601 * Drivers should not call this function directly. They should instead use
2602 * \c glXGetProcAddress to obtain a pointer to the function.
2604 * \param ust Location to store the 64-bit UST
2605 * \returns Zero on success or a negative errno value on failure.
2607 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2609 * \since Internal API version 20030317.
2612 __glXGetUST(int64_t * ust
)
2620 if (gettimeofday(&tv
, NULL
) == 0) {
2621 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2628 #endif /* GLX_DIRECT_RENDERING */