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"
41 #ifdef GLX_DIRECT_RENDERING
42 #ifdef GLX_USE_APPLEGL
43 #include "apple_glx_context.h"
44 #include "apple_glx.h"
45 #include "glx_error.h"
49 #include <X11/extensions/xf86vmode.h>
57 #include <X11/Xlib-xcb.h>
62 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
63 static const char __glXGLXClientVersion
[] = "1.4";
65 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
68 * Get the __DRIdrawable for the drawable associated with a GLXContext
70 * \param dpy The display associated with \c drawable.
71 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
72 * \param scrn_num If non-NULL, the drawables screen is stored there
73 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
74 * the drawable is not associated with a direct-rendering context.
76 _X_HIDDEN __GLXDRIdrawable
*
77 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
79 struct glx_display
*priv
= __glXInitialize(dpy
);
80 __GLXDRIdrawable
*pdraw
;
85 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
93 _X_HIDDEN
struct glx_drawable
*
94 GetGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
96 struct glx_display
*priv
= __glXInitialize(dpy
);
97 struct glx_drawable
*glxDraw
;
102 if (__glxHashLookup(priv
->glXDrawHash
, drawable
, (void *) &glxDraw
) == 0)
109 InitGLXDrawable(Display
*dpy
, struct glx_drawable
*glxDraw
, XID xDrawable
,
110 GLXDrawable drawable
)
112 struct glx_display
*priv
= __glXInitialize(dpy
);
117 glxDraw
->xDrawable
= xDrawable
;
118 glxDraw
->drawable
= drawable
;
119 glxDraw
->lastEventSbc
= 0;
120 glxDraw
->eventSbcWrap
= 0;
122 return __glxHashInsert(priv
->glXDrawHash
, drawable
, glxDraw
);
126 DestroyGLXDrawable(Display
*dpy
, GLXDrawable drawable
)
128 struct glx_display
*priv
= __glXInitialize(dpy
);
129 struct glx_drawable
*glxDraw
;
134 glxDraw
= GetGLXDrawable(dpy
, drawable
);
135 __glxHashDelete(priv
->glXDrawHash
, drawable
);
140 * Get the GLX per-screen data structure associated with a GLX context.
142 * \param dpy Display for which the GLX per-screen information is to be
144 * \param scrn Screen on \c dpy for which the GLX per-screen information is
146 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
147 * specify a valid GLX screen, or NULL otherwise.
149 * \todo Should this function validate that \c scrn is within the screen
150 * number range for \c dpy?
153 static struct glx_screen
*
154 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
156 struct glx_display
*const priv
= __glXInitialize(dpy
);
160 NULL
) ? priv
->screens
[scrn
] : NULL
;
165 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
166 struct glx_screen
** ppsc
)
168 /* Initialize the extension, if needed . This has the added value
169 * of initializing/allocating the display private
173 return GLX_NO_EXTENSION
;
176 *ppriv
= __glXInitialize(dpy
);
177 if (*ppriv
== NULL
) {
178 return GLX_NO_EXTENSION
;
181 /* Check screen number to see if its valid */
182 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
183 return GLX_BAD_SCREEN
;
186 /* Check to see if the GL is supported on this screen */
187 *ppsc
= (*ppriv
)->screens
[scrn
];
188 if ((*ppsc
)->configs
== NULL
) {
189 /* No support for GL on this screen regardless of visual */
190 return GLX_BAD_VISUAL
;
198 * Determine if a \c GLXFBConfig supplied by the application is valid.
200 * \param dpy Application supplied \c Display pointer.
201 * \param config Application supplied \c GLXFBConfig.
203 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
204 * \c struct glx_config structure is returned. Otherwise, \c NULL
207 static struct glx_config
*
208 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
210 struct glx_display
*const priv
= __glXInitialize(dpy
);
211 int num_screens
= ScreenCount(dpy
);
213 struct glx_config
*config
;
216 for (i
= 0; i
< num_screens
; i
++) {
217 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
218 config
= config
->next
) {
219 if (config
== (struct glx_config
*) fbconfig
) {
230 glx_context_init(struct glx_context
*gc
,
231 struct glx_screen
*psc
, struct glx_config
*config
)
233 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
234 if (!gc
->majorOpcode
)
237 gc
->screen
= psc
->scr
;
240 gc
->isDirect
= GL_TRUE
;
241 gc
->currentContextTag
= -1;
248 * Create a new context.
250 * \param renderType For FBConfigs, what is the rendering type?
254 CreateContext(Display
*dpy
, int generic_id
, struct glx_config
*config
,
255 GLXContext shareList_user
, Bool allowDirect
,
256 unsigned code
, int renderType
, int screen
)
258 struct glx_context
*gc
;
259 struct glx_screen
*psc
;
260 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
264 psc
= GetGLXScreenConfigs(dpy
, screen
);
268 if (generic_id
== None
)
272 #ifdef GLX_USE_APPLEGL
273 gc
= applegl_create_context(psc
, config
, shareList
, renderType
);
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
);
285 case X_GLXCreateContext
: {
286 xGLXCreateContextReq
*req
;
288 /* Send the glXCreateContext request */
289 GetReq(GLXCreateContext
, req
);
290 req
->reqType
= gc
->majorOpcode
;
291 req
->glxCode
= X_GLXCreateContext
;
292 req
->context
= gc
->xid
= XAllocID(dpy
);
293 req
->visual
= generic_id
;
294 req
->screen
= screen
;
295 req
->shareList
= shareList
? shareList
->xid
: None
;
296 req
->isDirect
= gc
->isDirect
;
300 case X_GLXCreateNewContext
: {
301 xGLXCreateNewContextReq
*req
;
303 /* Send the glXCreateNewContext request */
304 GetReq(GLXCreateNewContext
, req
);
305 req
->reqType
= gc
->majorOpcode
;
306 req
->glxCode
= X_GLXCreateNewContext
;
307 req
->context
= gc
->xid
= XAllocID(dpy
);
308 req
->fbconfig
= generic_id
;
309 req
->screen
= screen
;
310 req
->renderType
= renderType
;
311 req
->shareList
= shareList
? shareList
->xid
: None
;
312 req
->isDirect
= gc
->isDirect
;
316 case X_GLXvop_CreateContextWithConfigSGIX
: {
317 xGLXVendorPrivateWithReplyReq
*vpreq
;
318 xGLXCreateContextWithConfigSGIXReq
*req
;
320 /* Send the glXCreateNewContext request */
321 GetReqExtra(GLXVendorPrivateWithReply
,
322 sz_xGLXCreateContextWithConfigSGIXReq
-
323 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
324 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
325 req
->reqType
= gc
->majorOpcode
;
326 req
->glxCode
= X_GLXVendorPrivateWithReply
;
327 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
328 req
->context
= gc
->xid
= XAllocID(dpy
);
329 req
->fbconfig
= generic_id
;
330 req
->screen
= screen
;
331 req
->renderType
= renderType
;
332 req
->shareList
= shareList
? shareList
->xid
: None
;
333 req
->isDirect
= gc
->isDirect
;
338 /* What to do here? This case is the sign of an internal error. It
339 * should never be reachable.
347 gc
->imported
= GL_FALSE
;
348 gc
->renderType
= renderType
;
350 return (GLXContext
) gc
;
354 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
355 GLXContext shareList
, Bool allowDirect
)
357 struct glx_config
*config
= NULL
;
360 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
361 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
363 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
364 if (config
== NULL
) {
367 error
.errorCode
= BadValue
;
368 error
.resourceID
= vis
->visualid
;
369 error
.sequenceNumber
= dpy
->request
;
370 error
.type
= X_Error
;
371 error
.majorCode
= __glXSetupForCommand(dpy
);
372 error
.minorCode
= X_GLXCreateContext
;
373 _XError(dpy
, &error
);
377 renderType
= config
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
380 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
381 X_GLXCreateContext
, renderType
, vis
->screen
);
385 glx_send_destroy_context(Display
*dpy
, XID xid
)
387 CARD8 opcode
= __glXSetupForCommand(dpy
);
388 xGLXDestroyContextReq
*req
;
391 GetReq(GLXDestroyContext
, req
);
392 req
->reqType
= opcode
;
393 req
->glxCode
= X_GLXDestroyContext
;
400 ** Destroy the named context
404 glXDestroyContext(Display
* dpy
, GLXContext ctx
)
406 struct glx_context
*gc
= (struct glx_context
*) ctx
;
408 if (gc
== NULL
|| gc
->xid
== None
)
413 glx_send_destroy_context(dpy
, gc
->xid
);
415 if (gc
->currentDpy
) {
416 /* This context is bound to some thread. According to the man page,
417 * we should not actually delete the context until it's unbound.
418 * Note that we set gc->xid = None above. In MakeContextCurrent()
419 * we check for that and delete the context there.
423 gc
->vtable
->destroy(gc
);
429 ** Return the major and minor version #s for the GLX extension
432 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
434 struct glx_display
*priv
;
436 /* Init the extension. This fetches the major and minor version. */
437 priv
= __glXInitialize(dpy
);
442 *major
= priv
->majorVersion
;
444 *minor
= priv
->minorVersion
;
449 ** Query the existance of the GLX extension
452 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
454 int major_op
, erb
, evb
;
457 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
468 ** Put a barrier in the token stream that forces the GL to finish its
469 ** work before X can proceed.
474 struct glx_context
*gc
= __glXGetCurrentContext();
476 if (gc
&& gc
->vtable
->wait_gl
)
477 gc
->vtable
->wait_gl(gc
);
481 ** Put a barrier in the token stream that forces X to finish its
482 ** work before GL can proceed.
487 struct glx_context
*gc
= __glXGetCurrentContext();
489 if (gc
&& gc
->vtable
->wait_x
)
490 gc
->vtable
->wait_x(gc
);
494 glXUseXFont(Font font
, int first
, int count
, int listBase
)
496 struct glx_context
*gc
= __glXGetCurrentContext();
498 if (gc
&& gc
->vtable
->use_x_font
)
499 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
502 /************************************************************************/
505 ** Copy the source context to the destination context using the
509 glXCopyContext(Display
* dpy
, GLXContext source_user
,
510 GLXContext dest_user
, unsigned long mask
)
512 struct glx_context
*source
= (struct glx_context
*) source_user
;
513 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
514 #ifdef GLX_USE_APPLEGL
515 struct glx_context
*gc
= __glXGetCurrentContext();
519 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
520 mask
, &errorcode
, &x11error
)) {
521 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
525 xGLXCopyContextReq
*req
;
526 struct glx_context
*gc
= __glXGetCurrentContext();
530 opcode
= __glXSetupForCommand(dpy
);
535 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
537 /* NOT_DONE: This does not work yet */
542 ** If the source is the current context, send its tag so that the context
543 ** can be flushed before the copy.
545 if (source
== gc
&& dpy
== gc
->currentDpy
) {
546 tag
= gc
->currentContextTag
;
552 /* Send the glXCopyContext request */
554 GetReq(GLXCopyContext
, req
);
555 req
->reqType
= opcode
;
556 req
->glxCode
= X_GLXCopyContext
;
557 req
->source
= source
? source
->xid
: None
;
558 req
->dest
= dest
? dest
->xid
: None
;
560 req
->contextTag
= tag
;
563 #endif /* GLX_USE_APPLEGL */
568 * Determine if a context uses direct rendering.
570 * \param dpy Display where the context was created.
571 * \param contextID ID of the context to be tested.
573 * \returns \c GL_TRUE if the context is direct rendering or not.
576 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
578 #if !defined(USE_XCB)
579 xGLXIsDirectReq
*req
;
580 xGLXIsDirectReply reply
;
584 opcode
= __glXSetupForCommand(dpy
);
590 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
591 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
596 const Bool is_direct
= (reply
!= NULL
&& reply
->is_direct
) ? True
: False
;
601 /* Send the glXIsDirect request */
603 GetReq(GLXIsDirect
, req
);
604 req
->reqType
= opcode
;
605 req
->glxCode
= X_GLXIsDirect
;
606 req
->context
= contextID
;
607 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
611 return reply
.isDirect
;
617 * Shouldn't this function \b always return \c GL_FALSE when
618 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
619 * the GLX protocol here at all?
622 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
624 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
629 else if (gc
->isDirect
) {
632 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
635 return __glXIsDirect(dpy
, gc
->xid
);
640 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
642 #ifdef GLX_USE_APPLEGL
643 int screen
= vis
->screen
;
644 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
645 const struct glx_config
*config
;
647 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
649 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
654 xGLXCreateGLXPixmapReq
*req
;
655 struct glx_drawable
*glxDraw
;
659 opcode
= __glXSetupForCommand(dpy
);
664 glxDraw
= Xmalloc(sizeof(*glxDraw
));
668 /* Send the glXCreateGLXPixmap request */
670 GetReq(GLXCreateGLXPixmap
, req
);
671 req
->reqType
= opcode
;
672 req
->glxCode
= X_GLXCreateGLXPixmap
;
673 req
->screen
= vis
->screen
;
674 req
->visual
= vis
->visualid
;
675 req
->pixmap
= pixmap
;
676 req
->glxpixmap
= xid
= XAllocID(dpy
);
680 if (InitGLXDrawable(dpy
, glxDraw
, pixmap
, req
->glxpixmap
)) {
685 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
687 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
688 * is actually bound to a context... */
690 struct glx_display
*const priv
= __glXInitialize(dpy
);
691 __GLXDRIdrawable
*pdraw
;
692 struct glx_screen
*psc
;
693 struct glx_config
*config
;
695 psc
= priv
->screens
[vis
->screen
];
696 if (psc
->driScreen
== NULL
)
699 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
700 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
702 fprintf(stderr
, "failed to create pixmap\n");
707 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
708 (*pdraw
->destroyDrawable
) (pdraw
);
715 xGLXDestroyGLXPixmapReq
*dreq
;
717 GetReq(GLXDestroyGLXPixmap
, dreq
);
718 dreq
->reqType
= opcode
;
719 dreq
->glxCode
= X_GLXDestroyGLXPixmap
;
720 dreq
->glxpixmap
= xid
;
731 ** Destroy the named pixmap
734 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
736 #ifdef GLX_USE_APPLEGL
737 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
738 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
740 xGLXDestroyGLXPixmapReq
*req
;
743 opcode
= __glXSetupForCommand(dpy
);
748 /* Send the glXDestroyGLXPixmap request */
750 GetReq(GLXDestroyGLXPixmap
, req
);
751 req
->reqType
= opcode
;
752 req
->glxCode
= X_GLXDestroyGLXPixmap
;
753 req
->glxpixmap
= glxpixmap
;
757 DestroyGLXDrawable(dpy
, glxpixmap
);
759 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
761 struct glx_display
*const priv
= __glXInitialize(dpy
);
762 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
765 (*pdraw
->destroyDrawable
) (pdraw
);
766 __glxHashDelete(priv
->drawHash
, glxpixmap
);
770 #endif /* GLX_USE_APPLEGL */
774 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
776 #ifdef GLX_USE_APPLEGL
777 struct glx_context
* gc
= __glXGetCurrentContext();
778 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
779 apple_glx_swap_buffers(gc
->driContext
);
781 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
784 struct glx_context
*gc
;
790 xGLXSwapBuffersReq
*req
;
793 gc
= __glXGetCurrentContext();
795 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
797 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
800 if (gc
&& drawable
== gc
->currentDrawable
) {
804 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
810 opcode
= __glXSetupForCommand(dpy
);
816 ** The calling thread may or may not have a current context. If it
817 ** does, send the context tag so the server can do a flush.
819 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
820 ((drawable
== gc
->currentDrawable
)
821 || (drawable
== gc
->currentReadable
))) {
822 tag
= gc
->currentContextTag
;
829 c
= XGetXCBConnection(dpy
);
830 xcb_glx_swap_buffers(c
, tag
, drawable
);
833 /* Send the glXSwapBuffers request */
835 GetReq(GLXSwapBuffers
, req
);
836 req
->reqType
= opcode
;
837 req
->glxCode
= X_GLXSwapBuffers
;
838 req
->drawable
= drawable
;
839 req
->contextTag
= tag
;
844 #endif /* GLX_USE_APPLEGL */
849 ** Return configuration information for the given display, screen and
850 ** visual combination.
853 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
856 struct glx_display
*priv
;
857 struct glx_screen
*psc
;
858 struct glx_config
*config
;
861 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
862 if (status
== Success
) {
863 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
865 /* Lookup attribute after first finding a match on the visual */
866 if (config
!= NULL
) {
867 return glx_config_get(config
, attribute
, value_return
);
870 status
= GLX_BAD_VISUAL
;
874 ** If we can't find the config for this visual, this visual is not
875 ** supported by the OpenGL implementation on the server.
877 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
878 *value_return
= GL_FALSE
;
885 /************************************************************************/
888 init_fbconfig_for_chooser(struct glx_config
* config
,
889 GLboolean fbconfig_style_tags
)
891 memset(config
, 0, sizeof(struct glx_config
));
892 config
->visualID
= (XID
) GLX_DONT_CARE
;
893 config
->visualType
= GLX_DONT_CARE
;
895 /* glXChooseFBConfig specifies different defaults for these two than
898 if (fbconfig_style_tags
) {
899 config
->rgbMode
= GL_TRUE
;
900 config
->doubleBufferMode
= GLX_DONT_CARE
;
903 config
->visualRating
= GLX_DONT_CARE
;
904 config
->transparentPixel
= GLX_NONE
;
905 config
->transparentRed
= GLX_DONT_CARE
;
906 config
->transparentGreen
= GLX_DONT_CARE
;
907 config
->transparentBlue
= GLX_DONT_CARE
;
908 config
->transparentAlpha
= GLX_DONT_CARE
;
909 config
->transparentIndex
= GLX_DONT_CARE
;
911 config
->drawableType
= GLX_WINDOW_BIT
;
913 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
914 config
->xRenderable
= GLX_DONT_CARE
;
915 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
917 config
->swapMethod
= GLX_DONT_CARE
;
920 #define MATCH_DONT_CARE( param ) \
922 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
923 && (a-> param != b-> param) ) { \
928 #define MATCH_MINIMUM( param ) \
930 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
931 && (a-> param > b-> param) ) { \
936 #define MATCH_EXACT( param ) \
938 if ( a-> param != b-> param) { \
943 /* Test that all bits from a are contained in b */
944 #define MATCH_MASK(param) \
946 if ((a->param & ~b->param) != 0) \
951 * Determine if two GLXFBConfigs are compatible.
953 * \param a Application specified config to test.
954 * \param b Server specified config to test against \c a.
957 fbconfigs_compatible(const struct glx_config
* const a
,
958 const struct glx_config
* const b
)
960 MATCH_DONT_CARE(doubleBufferMode
);
961 MATCH_DONT_CARE(visualType
);
962 MATCH_DONT_CARE(visualRating
);
963 MATCH_DONT_CARE(xRenderable
);
964 MATCH_DONT_CARE(fbconfigID
);
965 MATCH_DONT_CARE(swapMethod
);
967 MATCH_MINIMUM(rgbBits
);
968 MATCH_MINIMUM(numAuxBuffers
);
969 MATCH_MINIMUM(redBits
);
970 MATCH_MINIMUM(greenBits
);
971 MATCH_MINIMUM(blueBits
);
972 MATCH_MINIMUM(alphaBits
);
973 MATCH_MINIMUM(depthBits
);
974 MATCH_MINIMUM(stencilBits
);
975 MATCH_MINIMUM(accumRedBits
);
976 MATCH_MINIMUM(accumGreenBits
);
977 MATCH_MINIMUM(accumBlueBits
);
978 MATCH_MINIMUM(accumAlphaBits
);
979 MATCH_MINIMUM(sampleBuffers
);
980 MATCH_MINIMUM(maxPbufferWidth
);
981 MATCH_MINIMUM(maxPbufferHeight
);
982 MATCH_MINIMUM(maxPbufferPixels
);
983 MATCH_MINIMUM(samples
);
985 MATCH_DONT_CARE(stereoMode
);
988 MATCH_MASK(drawableType
);
989 MATCH_MASK(renderType
);
991 /* There is a bug in a few of the XFree86 DDX drivers. They contain
992 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
993 * Technically speaking, it is a bug in the DDX driver, but there is
994 * enough of an installed base to work around the problem here. In any
995 * case, 0 is not a valid value of the transparent type, so we'll treat 0
996 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
997 * 0 from the server to be a match to maintain backward compatibility with
998 * the (broken) drivers.
1001 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1002 if (a
->transparentPixel
== GLX_NONE
) {
1003 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1007 MATCH_EXACT(transparentPixel
);
1010 switch (a
->transparentPixel
) {
1011 case GLX_TRANSPARENT_RGB
:
1012 MATCH_DONT_CARE(transparentRed
);
1013 MATCH_DONT_CARE(transparentGreen
);
1014 MATCH_DONT_CARE(transparentBlue
);
1015 MATCH_DONT_CARE(transparentAlpha
);
1018 case GLX_TRANSPARENT_INDEX
:
1019 MATCH_DONT_CARE(transparentIndex
);
1031 /* There's some trickly language in the GLX spec about how this is supposed
1032 * to work. Basically, if a given component size is either not specified
1033 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1034 * Well, that's really hard to do with the code as-is. This behavior is
1035 * closer to correct, but still not technically right.
1037 #define PREFER_LARGER_OR_ZERO(comp) \
1039 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1040 if ( ((*a)-> comp) == 0 ) { \
1043 else if ( ((*b)-> comp) == 0 ) { \
1047 return ((*b)-> comp) - ((*a)-> comp) ; \
1052 #define PREFER_LARGER(comp) \
1054 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1055 return ((*b)-> comp) - ((*a)-> comp) ; \
1059 #define PREFER_SMALLER(comp) \
1061 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1062 return ((*a)-> comp) - ((*b)-> comp) ; \
1067 * Compare two GLXFBConfigs. This function is intended to be used as the
1068 * compare function passed in to qsort.
1070 * \returns If \c a is a "better" config, according to the specification of
1071 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1072 * better, then a number greater than zero is return. If both are
1073 * equal, zero is returned.
1074 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1077 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1079 /* The order of these comparisons must NOT change. It is defined by
1080 * the GLX 1.3 spec and ARB_multisample.
1083 PREFER_SMALLER(visualSelectGroup
);
1085 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1086 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1087 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1089 PREFER_SMALLER(visualRating
);
1091 /* This isn't quite right. It is supposed to compare the sum of the
1092 * components the user specifically set minimums for.
1094 PREFER_LARGER_OR_ZERO(redBits
);
1095 PREFER_LARGER_OR_ZERO(greenBits
);
1096 PREFER_LARGER_OR_ZERO(blueBits
);
1097 PREFER_LARGER_OR_ZERO(alphaBits
);
1099 PREFER_SMALLER(rgbBits
);
1101 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1102 /* Prefer single-buffer.
1104 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1107 PREFER_SMALLER(numAuxBuffers
);
1109 PREFER_LARGER_OR_ZERO(depthBits
);
1110 PREFER_SMALLER(stencilBits
);
1112 /* This isn't quite right. It is supposed to compare the sum of the
1113 * components the user specifically set minimums for.
1115 PREFER_LARGER_OR_ZERO(accumRedBits
);
1116 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1117 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1118 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1120 PREFER_SMALLER(visualType
);
1122 /* None of the multisample specs say where this comparison should happen,
1123 * so I put it near the end.
1125 PREFER_SMALLER(sampleBuffers
);
1126 PREFER_SMALLER(samples
);
1128 /* None of the pbuffer or fbconfig specs say that this comparison needs
1129 * to happen at all, but it seems like it should.
1131 PREFER_LARGER(maxPbufferWidth
);
1132 PREFER_LARGER(maxPbufferHeight
);
1133 PREFER_LARGER(maxPbufferPixels
);
1140 * Selects and sorts a subset of the supplied configs based on the attributes.
1141 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1142 * and \c glXChooseFBConfigSGIX.
1144 * \param configs Array of pointers to possible configs. The elements of
1145 * this array that do not meet the criteria will be set to
1146 * NULL. The remaining elements will be sorted according to
1147 * the various visual / FBConfig selection rules.
1148 * \param num_configs Number of elements in the \c configs array.
1149 * \param attribList Attributes used select from \c configs. This array is
1150 * terminated by a \c None tag. The array can either take
1151 * the form expected by \c glXChooseVisual (where boolean
1152 * tags do not have a value) or by \c glXChooseFBConfig
1153 * (where every tag has a value).
1154 * \param fbconfig_style_tags Selects whether \c attribList is in
1155 * \c glXChooseVisual style or
1156 * \c glXChooseFBConfig style.
1157 * \returns The number of valid elements left in \c configs.
1159 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1162 choose_visual(struct glx_config
** configs
, int num_configs
,
1163 const int *attribList
, GLboolean fbconfig_style_tags
)
1165 struct glx_config test_config
;
1169 /* This is a fairly direct implementation of the selection method
1170 * described by GLX_SGIX_fbconfig. Start by culling out all the
1171 * configs that are not compatible with the selected parameter
1175 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1176 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1177 (const INT32
*) attribList
,
1178 GL_TRUE
, fbconfig_style_tags
);
1181 for (i
= 0; i
< num_configs
; i
++) {
1182 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1183 configs
[base
] = configs
[i
];
1192 if (base
< num_configs
) {
1193 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1196 /* After the incompatible configs are removed, the resulting
1197 * list is sorted according to the rules set out in the various
1201 qsort(configs
, base
, sizeof(struct glx_config
*),
1202 (int (*)(const void *, const void *)) fbconfig_compare
);
1210 ** Return the visual that best matches the template. Return None if no
1211 ** visual matches the template.
1213 _X_EXPORT XVisualInfo
*
1214 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1216 XVisualInfo
*visualList
= NULL
;
1217 struct glx_display
*priv
;
1218 struct glx_screen
*psc
;
1219 struct glx_config test_config
;
1220 struct glx_config
*config
;
1221 struct glx_config
*best_config
= NULL
;
1224 ** Get a list of all visuals, return if list is empty
1226 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1232 ** Build a template from the defaults and the attribute list
1233 ** Free visual list and return if an unexpected token is encountered
1235 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1236 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1237 (const INT32
*) attribList
,
1241 ** Eliminate visuals that don't meet minimum requirements
1242 ** Compute a score for those that do
1243 ** Remember which visual, if any, got the highest score
1244 ** If no visual is acceptable, return None
1245 ** Otherwise, create an XVisualInfo list with just the selected X visual
1248 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1249 if (fbconfigs_compatible(&test_config
, config
)
1250 && ((best_config
== NULL
) ||
1251 (fbconfig_compare (&config
, &best_config
) < 0))) {
1252 XVisualInfo visualTemplate
;
1253 XVisualInfo
*newList
;
1256 visualTemplate
.screen
= screen
;
1257 visualTemplate
.visualid
= config
->visualID
;
1258 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1259 &visualTemplate
, &i
);
1263 visualList
= newList
;
1264 best_config
= config
;
1269 #ifdef GLX_USE_APPLEGL
1270 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1271 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1279 _X_EXPORT
const char *
1280 glXQueryExtensionsString(Display
* dpy
, int screen
)
1282 struct glx_screen
*psc
;
1283 struct glx_display
*priv
;
1285 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1289 if (!psc
->effectiveGLXexts
) {
1290 if (!psc
->serverGLXexts
) {
1291 psc
->serverGLXexts
=
1292 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1296 __glXCalculateUsableExtensions(psc
,
1297 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1298 (psc
->driScreen
!= NULL
),
1302 priv
->minorVersion
);
1305 return psc
->effectiveGLXexts
;
1308 _X_EXPORT
const char *
1309 glXGetClientString(Display
* dpy
, int name
)
1315 return (__glXGLXClientVendorName
);
1317 return (__glXGLXClientVersion
);
1318 case GLX_EXTENSIONS
:
1319 return (__glXGetClientExtensions());
1325 _X_EXPORT
const char *
1326 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1328 struct glx_screen
*psc
;
1329 struct glx_display
*priv
;
1333 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1339 str
= &priv
->serverGLXvendor
;
1342 str
= &priv
->serverGLXversion
;
1344 case GLX_EXTENSIONS
:
1345 str
= &psc
->serverGLXexts
;
1352 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1359 __glXClientInfo(Display
* dpy
, int opcode
)
1361 char *ext_str
= __glXGetClientGLExtensionString();
1362 int size
= strlen(ext_str
) + 1;
1365 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1366 xcb_glx_client_info(c
,
1367 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1369 xGLXClientInfoReq
*req
;
1371 /* Send the glXClientInfo request */
1373 GetReq(GLXClientInfo
, req
);
1374 req
->reqType
= opcode
;
1375 req
->glxCode
= X_GLXClientInfo
;
1376 req
->major
= GLX_MAJOR_VERSION
;
1377 req
->minor
= GLX_MINOR_VERSION
;
1379 req
->length
+= (size
+ 3) >> 2;
1380 req
->numbytes
= size
;
1381 Data(dpy
, ext_str
, size
);
1385 #endif /* USE_XCB */
1392 ** EXT_import_context
1396 glXGetCurrentDisplay(void)
1398 struct glx_context
*gc
= __glXGetCurrentContext();
1401 return gc
->currentDpy
;
1405 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1406 glXGetCurrentDisplay
)
1408 #ifndef GLX_USE_APPLEGL
1409 _X_EXPORT GLXContext
1410 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1412 struct glx_display
*priv
= __glXInitialize(dpy
);
1413 struct glx_screen
*psc
= NULL
;
1414 xGLXQueryContextReply reply
;
1416 struct glx_context
*ctx
;
1418 /* This GLX implementation knows about 5 different properties, so
1419 * allow the server to send us one of each.
1421 int propList
[5 * 2], *pProp
, nPropListBytes
;
1425 struct glx_config
*mode
;
1426 uint32_t fbconfigID
= 0;
1427 uint32_t visualID
= 0;
1429 Bool got_screen
= False
;
1431 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1434 opcode
= __glXSetupForCommand(dpy
);
1438 /* Send the glXQueryContextInfoEXT request */
1441 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1442 xGLXQueryContextReq
*req
;
1444 GetReq(GLXQueryContext
, req
);
1446 req
->reqType
= opcode
;
1447 req
->glxCode
= X_GLXQueryContext
;
1448 req
->context
= contextID
;
1451 xGLXVendorPrivateReq
*vpreq
;
1452 xGLXQueryContextInfoEXTReq
*req
;
1454 GetReqExtra(GLXVendorPrivate
,
1455 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1457 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1458 req
->reqType
= opcode
;
1459 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1460 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1461 req
->context
= contextID
;
1464 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1466 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1467 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1470 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1474 numProps
= nPropListBytes
/ (2 * sizeof(propList
[0]));
1480 for (i
= 0, pProp
= propList
; i
< numProps
; i
++, pProp
+= 2)
1486 case GLX_SHARE_CONTEXT_EXT
:
1489 case GLX_VISUAL_ID_EXT
:
1490 visualID
= pProp
[1];
1492 case GLX_FBCONFIG_ID
:
1493 fbconfigID
= pProp
[1];
1495 case GLX_RENDER_TYPE
:
1496 renderType
= pProp
[1];
1503 psc
= GetGLXScreenConfigs(dpy
, screen
);
1507 if (fbconfigID
!= 0) {
1508 mode
= glx_config_find_fbconfig(psc
->configs
, fbconfigID
);
1509 } else if (visualID
!= 0) {
1510 mode
= glx_config_find_visual(psc
->visuals
, visualID
);
1516 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1520 ctx
->xid
= contextID
;
1521 ctx
->imported
= GL_TRUE
;
1522 ctx
->share_xid
= share
;
1524 return (GLXContext
) ctx
;
1530 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1532 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1534 switch (attribute
) {
1535 case GLX_SHARE_CONTEXT_EXT
:
1536 *value
= ctx
->share_xid
;
1538 case GLX_VISUAL_ID_EXT
:
1539 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1542 *value
= ctx
->screen
;
1544 case GLX_FBCONFIG_ID
:
1545 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1547 case GLX_RENDER_TYPE
:
1548 *value
= ctx
->renderType
;
1551 return GLX_BAD_ATTRIBUTE
;
1557 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1558 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1559 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1561 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1563 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1565 return (ctx
== NULL
) ? None
: ctx
->xid
;
1569 glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1571 struct glx_context
*gc
= (struct glx_context
*) ctx
;
1573 if (gc
== NULL
|| gc
->xid
== None
)
1576 /* The GLX_EXT_import_context spec says:
1578 * "glXFreeContext does not free the server-side context information or
1579 * the XID associated with the server-side context."
1581 * Don't send any protocol. Just destroy the client-side tracking of the
1582 * context. Also, only release the context structure if it's not current.
1585 if (gc
->currentDpy
) {
1588 gc
->vtable
->destroy(gc
);
1593 _X_EXPORT GLXFBConfig
*
1594 glXChooseFBConfig(Display
* dpy
, int screen
,
1595 const int *attribList
, int *nitems
)
1597 struct glx_config
**config_list
;
1601 config_list
= (struct glx_config
**)
1602 glXGetFBConfigs(dpy
, screen
, &list_size
);
1604 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1605 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1606 if (list_size
== 0) {
1612 *nitems
= list_size
;
1613 return (GLXFBConfig
*) config_list
;
1617 _X_EXPORT GLXContext
1618 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1619 int renderType
, GLXContext shareList
, Bool allowDirect
)
1621 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1623 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1624 allowDirect
, X_GLXCreateNewContext
, renderType
,
1629 _X_EXPORT GLXDrawable
1630 glXGetCurrentReadDrawable(void)
1632 struct glx_context
*gc
= __glXGetCurrentContext();
1634 return gc
->currentReadable
;
1638 _X_EXPORT GLXFBConfig
*
1639 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1641 struct glx_display
*priv
= __glXInitialize(dpy
);
1642 struct glx_config
**config_list
= NULL
;
1643 struct glx_config
*config
;
1644 unsigned num_configs
= 0;
1648 if (priv
&& (priv
->screens
!= NULL
)
1649 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1650 && (priv
->screens
[screen
]->configs
!= NULL
)
1651 && (priv
->screens
[screen
]->configs
->fbconfigID
1652 != (int) GLX_DONT_CARE
)) {
1654 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1655 config
= config
->next
) {
1656 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1661 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1662 if (config_list
!= NULL
) {
1663 *nelements
= num_configs
;
1665 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1666 config
= config
->next
) {
1667 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1668 config_list
[i
] = config
;
1675 return (GLXFBConfig
*) config_list
;
1680 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1681 int attribute
, int *value
)
1683 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1686 return GLXBadFBConfig
;
1688 return glx_config_get(config
, attribute
, value
);
1692 _X_EXPORT XVisualInfo
*
1693 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1695 XVisualInfo visualTemplate
;
1696 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1700 ** Get a list of all visuals, return if list is empty
1702 visualTemplate
.visualid
= config
->visualID
;
1703 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1706 #ifndef GLX_USE_APPLEGL
1708 ** GLX_SGI_swap_control
1711 __glXSwapIntervalSGI(int interval
)
1713 xGLXVendorPrivateReq
*req
;
1714 struct glx_context
*gc
= __glXGetCurrentContext();
1715 struct glx_screen
*psc
;
1717 CARD32
*interval_ptr
;
1721 return GLX_BAD_CONTEXT
;
1724 if (interval
<= 0) {
1725 return GLX_BAD_VALUE
;
1728 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1730 #ifdef GLX_DIRECT_RENDERING
1731 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1732 __GLXDRIdrawable
*pdraw
=
1733 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1734 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1739 dpy
= gc
->currentDpy
;
1740 opcode
= __glXSetupForCommand(dpy
);
1745 /* Send the glXSwapIntervalSGI request */
1747 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1748 req
->reqType
= opcode
;
1749 req
->glxCode
= X_GLXVendorPrivate
;
1750 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1751 req
->contextTag
= gc
->currentContextTag
;
1753 interval_ptr
= (CARD32
*) (req
+ 1);
1754 *interval_ptr
= interval
;
1765 ** GLX_MESA_swap_control
1768 __glXSwapIntervalMESA(unsigned int interval
)
1770 #ifdef GLX_DIRECT_RENDERING
1771 struct glx_context
*gc
= __glXGetCurrentContext();
1773 if (gc
!= NULL
&& gc
->isDirect
) {
1774 struct glx_screen
*psc
;
1776 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1777 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1778 __GLXDRIdrawable
*pdraw
=
1779 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1780 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1785 return GLX_BAD_CONTEXT
;
1790 __glXGetSwapIntervalMESA(void)
1792 #ifdef GLX_DIRECT_RENDERING
1793 struct glx_context
*gc
= __glXGetCurrentContext();
1795 if (gc
!= NULL
&& gc
->isDirect
) {
1796 struct glx_screen
*psc
;
1798 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1799 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1800 __GLXDRIdrawable
*pdraw
=
1801 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1802 return psc
->driScreen
->getSwapInterval(pdraw
);
1812 ** GLX_SGI_video_sync
1815 __glXGetVideoSyncSGI(unsigned int *count
)
1817 int64_t ust
, msc
, sbc
;
1819 struct glx_context
*gc
= __glXGetCurrentContext();
1820 struct glx_screen
*psc
;
1821 #ifdef GLX_DIRECT_RENDERING
1822 __GLXDRIdrawable
*pdraw
;
1826 return GLX_BAD_CONTEXT
;
1828 #ifdef GLX_DIRECT_RENDERING
1830 return GLX_BAD_CONTEXT
;
1833 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1834 #ifdef GLX_DIRECT_RENDERING
1835 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1838 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1839 * FIXME: there should be a GLX encoding for this call. I can find no
1840 * FIXME: documentation for the GLX encoding.
1842 #ifdef GLX_DIRECT_RENDERING
1843 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1844 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1845 *count
= (unsigned) msc
;
1846 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1850 return GLX_BAD_CONTEXT
;
1854 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1856 struct glx_context
*gc
= __glXGetCurrentContext();
1857 struct glx_screen
*psc
;
1858 #ifdef GLX_DIRECT_RENDERING
1859 __GLXDRIdrawable
*pdraw
;
1861 int64_t ust
, msc
, sbc
;
1864 if (divisor
<= 0 || remainder
< 0)
1865 return GLX_BAD_VALUE
;
1868 return GLX_BAD_CONTEXT
;
1870 #ifdef GLX_DIRECT_RENDERING
1872 return GLX_BAD_CONTEXT
;
1875 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1876 #ifdef GLX_DIRECT_RENDERING
1877 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1880 #ifdef GLX_DIRECT_RENDERING
1881 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1882 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1884 *count
= (unsigned) msc
;
1885 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1889 return GLX_BAD_CONTEXT
;
1892 #endif /* GLX_USE_APPLEGL */
1895 ** GLX_SGIX_fbconfig
1896 ** Many of these functions are aliased to GLX 1.3 entry points in the
1897 ** GLX_functions table.
1901 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1902 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1903 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1905 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1906 (Display
* dpy
, int screen
, int *attrib_list
,
1907 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1910 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1911 (Display
* dpy
, GLXFBConfigSGIX config
),
1912 (dpy
, config
), glXGetVisualFromFBConfig
)
1915 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1916 GLXFBConfigSGIX fbconfig
,
1919 #ifndef GLX_USE_APPLEGL
1920 xGLXVendorPrivateWithReplyReq
*vpreq
;
1921 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1922 GLXPixmap xid
= None
;
1924 struct glx_screen
*psc
;
1926 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1929 if ((dpy
== NULL
) || (config
== NULL
)) {
1932 #ifdef GLX_USE_APPLEGL
1933 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1938 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1940 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1941 opcode
= __glXSetupForCommand(dpy
);
1946 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1948 GetReqExtra(GLXVendorPrivateWithReply
,
1949 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1950 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1951 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1952 req
->reqType
= opcode
;
1953 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1954 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1955 req
->screen
= config
->screen
;
1956 req
->fbconfig
= config
->fbconfigID
;
1957 req
->pixmap
= pixmap
;
1958 req
->glxpixmap
= xid
= XAllocID(dpy
);
1967 _X_EXPORT GLXContext
1968 glXCreateContextWithConfigSGIX(Display
* dpy
,
1969 GLXFBConfigSGIX fbconfig
, int renderType
,
1970 GLXContext shareList
, Bool allowDirect
)
1972 GLXContext gc
= NULL
;
1973 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1974 struct glx_screen
*psc
;
1977 if ((dpy
== NULL
) || (config
== NULL
)) {
1981 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1983 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1984 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1986 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
1994 _X_EXPORT GLXFBConfigSGIX
1995 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
1997 struct glx_display
*priv
;
1998 struct glx_screen
*psc
= NULL
;
2000 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
2001 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2002 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2003 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2010 #ifndef GLX_USE_APPLEGL
2012 ** GLX_SGIX_swap_group
2015 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2025 ** GLX_SGIX_swap_barrier
2028 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2036 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2046 ** GLX_OML_sync_control
2049 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2050 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2052 struct glx_display
* const priv
= __glXInitialize(dpy
);
2054 #ifdef GLX_DIRECT_RENDERING
2055 __GLXDRIdrawable
*pdraw
;
2057 struct glx_screen
*psc
;
2062 #ifdef GLX_DIRECT_RENDERING
2063 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2064 psc
= pdraw
? pdraw
->psc
: NULL
;
2065 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2066 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2074 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2076 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
2077 int32_t * numerator
, int32_t * denominator
)
2080 struct glx_screen
*psc
;
2081 XF86VidModeModeLine mode_line
;
2086 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2087 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2088 unsigned n
= dot_clock
* 1000;
2089 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2091 # define V_INTERLACE 0x010
2092 # define V_DBLSCAN 0x020
2094 if (mode_line
.flags
& V_INTERLACE
)
2096 else if (mode_line
.flags
& V_DBLSCAN
)
2099 /* The OML_sync_control spec requires that if the refresh rate is a
2100 * whole number, that the returned numerator be equal to the refresh
2101 * rate and the denominator be 1.
2109 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2111 /* This is a poor man's way to reduce a fraction. It's far from
2112 * perfect, but it will work well enough for this situation.
2115 for (i
= 0; f
[i
] != 0; i
++) {
2116 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2136 * Determine the refresh rate of the specified drawable and display.
2138 * \param dpy Display whose refresh rate is to be determined.
2139 * \param drawable Drawable whose refresh rate is to be determined.
2140 * \param numerator Numerator of the refresh rate.
2141 * \param demoninator Denominator of the refresh rate.
2142 * \return If the refresh rate for the specified display and drawable could
2143 * be calculated, True is returned. Otherwise False is returned.
2145 * \note This function is implemented entirely client-side. A lot of other
2146 * functionality is required to export GLX_OML_sync_control, so on
2147 * XFree86 this function can be called for direct-rendering contexts
2148 * when GLX_OML_sync_control appears in the client extension string.
2152 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2153 int32_t * numerator
, int32_t * denominator
)
2155 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2156 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2161 return __glxGetMscRate(draw
, numerator
, denominator
);
2173 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2174 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2176 struct glx_context
*gc
= __glXGetCurrentContext();
2177 #ifdef GLX_DIRECT_RENDERING
2178 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2179 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2182 if (!gc
) /* no GLX for this */
2185 #ifdef GLX_DIRECT_RENDERING
2186 if (!pdraw
|| !gc
->isDirect
)
2190 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2191 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2192 * of -1 if the function failed because of errors detected in the input
2195 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2197 if (divisor
> 0 && remainder
>= divisor
)
2200 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2203 #ifdef GLX_DIRECT_RENDERING
2204 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2205 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2214 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2215 int64_t target_msc
, int64_t divisor
,
2216 int64_t remainder
, int64_t * ust
,
2217 int64_t * msc
, int64_t * sbc
)
2219 #ifdef GLX_DIRECT_RENDERING
2220 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2221 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2226 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2227 * error", but the return type in the spec is Bool.
2229 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2231 if (divisor
> 0 && remainder
>= divisor
)
2234 #ifdef GLX_DIRECT_RENDERING
2235 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2236 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2247 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2248 int64_t target_sbc
, int64_t * ust
,
2249 int64_t * msc
, int64_t * sbc
)
2251 #ifdef GLX_DIRECT_RENDERING
2252 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2253 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2257 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2258 * error", but the return type in the spec is Bool.
2263 #ifdef GLX_DIRECT_RENDERING
2264 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2265 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2277 * Mesa extension stubs. These will help reduce portability problems.
2282 * Release all buffers associated with the specified GLX drawable.
2285 * This function was intended for stand-alone Mesa. The issue there is that
2286 * the library doesn't get any notification when a window is closed. In
2287 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2288 * supported, there are 3 different functions to destroy a drawable. It
2289 * should be possible to create GLX protocol (or have it determine which
2290 * protocol to use based on the type of the drawable) to have one function
2291 * do the work of 3. For the direct-rendering case, this function could
2292 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2293 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2294 * would need to be used. This really should be done as part of the new DRI
2297 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2298 * __driGarbageCollectDrawables
2299 * glXDestroyGLXPixmap
2300 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2301 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2304 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2313 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2314 Pixmap pixmap
, Colormap cmap
)
2327 * GLX_MESA_copy_sub_buffer
2329 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2331 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2332 int x
, int y
, int width
, int height
)
2334 xGLXVendorPrivateReq
*req
;
2335 struct glx_context
*gc
;
2337 CARD32
*drawable_ptr
;
2338 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2341 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2342 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2343 if (pdraw
!= NULL
) {
2344 struct glx_screen
*psc
= pdraw
->psc
;
2345 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2347 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2354 opcode
= __glXSetupForCommand(dpy
);
2359 ** The calling thread may or may not have a current context. If it
2360 ** does, send the context tag so the server can do a flush.
2362 gc
= __glXGetCurrentContext();
2363 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2364 ((drawable
== gc
->currentDrawable
) ||
2365 (drawable
== gc
->currentReadable
))) {
2366 tag
= gc
->currentContextTag
;
2373 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2374 req
->reqType
= opcode
;
2375 req
->glxCode
= X_GLXVendorPrivate
;
2376 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2377 req
->contextTag
= tag
;
2379 drawable_ptr
= (CARD32
*) (req
+ 1);
2380 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2381 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2382 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2383 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2385 *drawable_ptr
= drawable
;
2397 __glXBindTexImageEXT(Display
* dpy
,
2398 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2400 struct glx_context
*gc
= __glXGetCurrentContext();
2402 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2405 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2409 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2411 struct glx_context
*gc
= __glXGetCurrentContext();
2413 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2416 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2421 #endif /* GLX_USE_APPLEGL */
2424 * \c strdup is actually not a standard ANSI C or POSIX routine.
2425 * Irix will not define it if ANSI mode is in effect.
2430 __glXstrdup(const char *str
)
2433 copy
= (char *) Xmalloc(strlen(str
) + 1);
2441 ** glXGetProcAddress support
2444 struct name_address_pair
2450 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2451 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2453 static const struct name_address_pair GLX_functions
[] = {
2454 /*** GLX_VERSION_1_0 ***/
2455 GLX_FUNCTION(glXChooseVisual
),
2456 GLX_FUNCTION(glXCopyContext
),
2457 GLX_FUNCTION(glXCreateContext
),
2458 GLX_FUNCTION(glXCreateGLXPixmap
),
2459 GLX_FUNCTION(glXDestroyContext
),
2460 GLX_FUNCTION(glXDestroyGLXPixmap
),
2461 GLX_FUNCTION(glXGetConfig
),
2462 GLX_FUNCTION(glXGetCurrentContext
),
2463 GLX_FUNCTION(glXGetCurrentDrawable
),
2464 GLX_FUNCTION(glXIsDirect
),
2465 GLX_FUNCTION(glXMakeCurrent
),
2466 GLX_FUNCTION(glXQueryExtension
),
2467 GLX_FUNCTION(glXQueryVersion
),
2468 GLX_FUNCTION(glXSwapBuffers
),
2469 GLX_FUNCTION(glXUseXFont
),
2470 GLX_FUNCTION(glXWaitGL
),
2471 GLX_FUNCTION(glXWaitX
),
2473 /*** GLX_VERSION_1_1 ***/
2474 GLX_FUNCTION(glXGetClientString
),
2475 GLX_FUNCTION(glXQueryExtensionsString
),
2476 GLX_FUNCTION(glXQueryServerString
),
2478 /*** GLX_VERSION_1_2 ***/
2479 GLX_FUNCTION(glXGetCurrentDisplay
),
2481 /*** GLX_VERSION_1_3 ***/
2482 GLX_FUNCTION(glXChooseFBConfig
),
2483 GLX_FUNCTION(glXCreateNewContext
),
2484 GLX_FUNCTION(glXCreatePbuffer
),
2485 GLX_FUNCTION(glXCreatePixmap
),
2486 GLX_FUNCTION(glXCreateWindow
),
2487 GLX_FUNCTION(glXDestroyPbuffer
),
2488 GLX_FUNCTION(glXDestroyPixmap
),
2489 GLX_FUNCTION(glXDestroyWindow
),
2490 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2491 GLX_FUNCTION(glXGetFBConfigAttrib
),
2492 GLX_FUNCTION(glXGetFBConfigs
),
2493 GLX_FUNCTION(glXGetSelectedEvent
),
2494 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2495 GLX_FUNCTION(glXMakeContextCurrent
),
2496 GLX_FUNCTION(glXQueryContext
),
2497 GLX_FUNCTION(glXQueryDrawable
),
2498 GLX_FUNCTION(glXSelectEvent
),
2500 #ifndef GLX_USE_APPLEGL
2501 /*** GLX_SGI_swap_control ***/
2502 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2504 /*** GLX_SGI_video_sync ***/
2505 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2506 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2508 /*** GLX_SGI_make_current_read ***/
2509 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2510 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2512 /*** GLX_EXT_import_context ***/
2513 GLX_FUNCTION(glXFreeContextEXT
),
2514 GLX_FUNCTION(glXGetContextIDEXT
),
2515 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2516 GLX_FUNCTION(glXImportContextEXT
),
2517 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2520 /*** GLX_SGIX_fbconfig ***/
2521 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2522 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2523 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2524 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2525 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2526 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2528 #ifndef GLX_USE_APPLEGL
2529 /*** GLX_SGIX_pbuffer ***/
2530 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2531 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2532 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2533 GLX_FUNCTION(glXSelectEventSGIX
),
2534 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2536 /*** GLX_SGIX_swap_group ***/
2537 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2539 /*** GLX_SGIX_swap_barrier ***/
2540 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2541 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2543 /*** GLX_MESA_copy_sub_buffer ***/
2544 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2546 /*** GLX_MESA_pixmap_colormap ***/
2547 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2549 /*** GLX_MESA_release_buffers ***/
2550 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2552 /*** GLX_MESA_swap_control ***/
2553 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2554 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2557 /*** GLX_ARB_get_proc_address ***/
2558 GLX_FUNCTION(glXGetProcAddressARB
),
2561 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2563 #ifndef GLX_USE_APPLEGL
2564 /*** GLX_OML_sync_control ***/
2565 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2566 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2567 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2568 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2569 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2571 /*** GLX_EXT_texture_from_pixmap ***/
2572 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2573 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2576 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2577 /*** DRI configuration ***/
2578 GLX_FUNCTION(glXGetScreenDriver
),
2579 GLX_FUNCTION(glXGetDriverConfig
),
2582 {NULL
, NULL
} /* end of list */
2585 static const GLvoid
*
2586 get_glx_proc_address(const char *funcName
)
2590 /* try static functions */
2591 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2592 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2593 return GLX_functions
[i
].Address
;
2600 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2601 * \c glXGetProcAddress.
2603 * \param procName Name of a GL or GLX function.
2604 * \returns A pointer to the named function
2606 * \sa glXGetProcAddress
2608 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2610 typedef void (*gl_function
) (void);
2614 /* Search the table of GLX and internal functions first. If that
2615 * fails and the supplied name could be a valid core GL name, try
2616 * searching the core GL function table. This check is done to prevent
2617 * DRI based drivers from searching the core GL function table for
2618 * internal API functions.
2620 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2621 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2622 && (procName
[2] != 'X')) {
2623 #ifdef GLX_SHARED_GLAPI
2624 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2627 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2629 struct glx_context
*gc
= __glXGetCurrentContext();
2631 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2632 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2639 * Get the address of a named GL function. This is the GLX 1.4 name for
2640 * \c glXGetProcAddressARB.
2642 * \param procName Name of a GL or GLX function.
2643 * \returns A pointer to the named function
2645 * \sa glXGetProcAddressARB
2647 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2648 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2649 __attribute__ ((alias("glXGetProcAddressARB")));
2652 return glXGetProcAddressARB(procName
);
2654 #endif /* __GNUC__ */
2657 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2659 * Get the unadjusted system time (UST). Currently, the UST is measured in
2660 * microseconds since Epoc. The actual resolution of the UST may vary from
2661 * system to system, and the units may vary from release to release.
2662 * Drivers should not call this function directly. They should instead use
2663 * \c glXGetProcAddress to obtain a pointer to the function.
2665 * \param ust Location to store the 64-bit UST
2666 * \returns Zero on success or a negative errno value on failure.
2668 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2670 * \since Internal API version 20030317.
2673 __glXGetUST(int64_t * ust
)
2681 if (gettimeofday(&tv
, NULL
) == 0) {
2682 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2689 #endif /* GLX_DIRECT_RENDERING */