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 #include "glx_error.h"
42 #ifdef GLX_DIRECT_RENDERING
43 #ifdef GLX_USE_APPLEGL
44 #include "apple_glx_context.h"
45 #include "apple_glx.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 _X_HIDDEN
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
->share_xid
= shareList
? shareList
->xid
: None
;
348 gc
->imported
= GL_FALSE
;
349 gc
->renderType
= renderType
;
351 return (GLXContext
) gc
;
355 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
356 GLXContext shareList
, Bool allowDirect
)
358 struct glx_config
*config
= NULL
;
361 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
362 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
364 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
365 if (config
== NULL
) {
368 error
.errorCode
= BadValue
;
369 error
.resourceID
= vis
->visualid
;
370 error
.sequenceNumber
= dpy
->request
;
371 error
.type
= X_Error
;
372 error
.majorCode
= __glXSetupForCommand(dpy
);
373 error
.minorCode
= X_GLXCreateContext
;
374 _XError(dpy
, &error
);
378 renderType
= config
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
381 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
382 X_GLXCreateContext
, renderType
, vis
->screen
);
386 glx_send_destroy_context(Display
*dpy
, XID xid
)
388 CARD8 opcode
= __glXSetupForCommand(dpy
);
389 xGLXDestroyContextReq
*req
;
392 GetReq(GLXDestroyContext
, req
);
393 req
->reqType
= opcode
;
394 req
->glxCode
= X_GLXDestroyContext
;
401 ** Destroy the named context
405 glXDestroyContext(Display
* dpy
, GLXContext ctx
)
407 struct glx_context
*gc
= (struct glx_context
*) ctx
;
409 if (gc
== NULL
|| gc
->xid
== None
)
414 glx_send_destroy_context(dpy
, gc
->xid
);
416 if (gc
->currentDpy
) {
417 /* This context is bound to some thread. According to the man page,
418 * we should not actually delete the context until it's unbound.
419 * Note that we set gc->xid = None above. In MakeContextCurrent()
420 * we check for that and delete the context there.
424 gc
->vtable
->destroy(gc
);
430 ** Return the major and minor version #s for the GLX extension
433 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
435 struct glx_display
*priv
;
437 /* Init the extension. This fetches the major and minor version. */
438 priv
= __glXInitialize(dpy
);
443 *major
= priv
->majorVersion
;
445 *minor
= priv
->minorVersion
;
450 ** Query the existance of the GLX extension
453 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
455 int major_op
, erb
, evb
;
458 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
469 ** Put a barrier in the token stream that forces the GL to finish its
470 ** work before X can proceed.
475 struct glx_context
*gc
= __glXGetCurrentContext();
477 if (gc
&& gc
->vtable
->wait_gl
)
478 gc
->vtable
->wait_gl(gc
);
482 ** Put a barrier in the token stream that forces X to finish its
483 ** work before GL can proceed.
488 struct glx_context
*gc
= __glXGetCurrentContext();
490 if (gc
&& gc
->vtable
->wait_x
)
491 gc
->vtable
->wait_x(gc
);
495 glXUseXFont(Font font
, int first
, int count
, int listBase
)
497 struct glx_context
*gc
= __glXGetCurrentContext();
499 if (gc
&& gc
->vtable
->use_x_font
)
500 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
503 /************************************************************************/
506 ** Copy the source context to the destination context using the
510 glXCopyContext(Display
* dpy
, GLXContext source_user
,
511 GLXContext dest_user
, unsigned long mask
)
513 struct glx_context
*source
= (struct glx_context
*) source_user
;
514 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
515 #ifdef GLX_USE_APPLEGL
516 struct glx_context
*gc
= __glXGetCurrentContext();
520 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
521 mask
, &errorcode
, &x11error
)) {
522 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
526 xGLXCopyContextReq
*req
;
527 struct glx_context
*gc
= __glXGetCurrentContext();
531 opcode
= __glXSetupForCommand(dpy
);
536 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
538 /* NOT_DONE: This does not work yet */
543 ** If the source is the current context, send its tag so that the context
544 ** can be flushed before the copy.
546 if (source
== gc
&& dpy
== gc
->currentDpy
) {
547 tag
= gc
->currentContextTag
;
553 /* Send the glXCopyContext request */
555 GetReq(GLXCopyContext
, req
);
556 req
->reqType
= opcode
;
557 req
->glxCode
= X_GLXCopyContext
;
558 req
->source
= source
? source
->xid
: None
;
559 req
->dest
= dest
? dest
->xid
: None
;
561 req
->contextTag
= tag
;
564 #endif /* GLX_USE_APPLEGL */
569 * Determine if a context uses direct rendering.
571 * \param dpy Display where the context was created.
572 * \param contextID ID of the context to be tested.
574 * \returns \c GL_TRUE if the context is direct rendering or not.
577 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
579 #if !defined(USE_XCB)
580 xGLXIsDirectReq
*req
;
581 xGLXIsDirectReply reply
;
585 opcode
= __glXSetupForCommand(dpy
);
591 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
592 xcb_generic_error_t
*err
;
593 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
598 const Bool is_direct
= (reply
!= NULL
&& reply
->is_direct
) ? True
: False
;
601 __glXSendErrorForXcb(dpy
, err
);
609 /* Send the glXIsDirect request */
611 GetReq(GLXIsDirect
, req
);
612 req
->reqType
= opcode
;
613 req
->glxCode
= X_GLXIsDirect
;
614 req
->context
= contextID
;
615 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
619 return reply
.isDirect
;
625 * Shouldn't this function \b always return \c GL_FALSE when
626 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
627 * the GLX protocol here at all?
630 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
632 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
637 else if (gc
->isDirect
) {
640 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
643 return __glXIsDirect(dpy
, gc
->xid
);
648 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
650 #ifdef GLX_USE_APPLEGL
651 int screen
= vis
->screen
;
652 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
653 const struct glx_config
*config
;
655 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
657 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
662 xGLXCreateGLXPixmapReq
*req
;
663 struct glx_drawable
*glxDraw
;
667 opcode
= __glXSetupForCommand(dpy
);
672 glxDraw
= Xmalloc(sizeof(*glxDraw
));
676 /* Send the glXCreateGLXPixmap request */
678 GetReq(GLXCreateGLXPixmap
, req
);
679 req
->reqType
= opcode
;
680 req
->glxCode
= X_GLXCreateGLXPixmap
;
681 req
->screen
= vis
->screen
;
682 req
->visual
= vis
->visualid
;
683 req
->pixmap
= pixmap
;
684 req
->glxpixmap
= xid
= XAllocID(dpy
);
688 if (InitGLXDrawable(dpy
, glxDraw
, pixmap
, req
->glxpixmap
)) {
693 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
695 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
696 * is actually bound to a context... */
698 struct glx_display
*const priv
= __glXInitialize(dpy
);
699 __GLXDRIdrawable
*pdraw
;
700 struct glx_screen
*psc
;
701 struct glx_config
*config
;
703 psc
= priv
->screens
[vis
->screen
];
704 if (psc
->driScreen
== NULL
)
707 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
708 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
710 fprintf(stderr
, "failed to create pixmap\n");
715 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
716 (*pdraw
->destroyDrawable
) (pdraw
);
723 xGLXDestroyGLXPixmapReq
*dreq
;
725 GetReq(GLXDestroyGLXPixmap
, dreq
);
726 dreq
->reqType
= opcode
;
727 dreq
->glxCode
= X_GLXDestroyGLXPixmap
;
728 dreq
->glxpixmap
= xid
;
739 ** Destroy the named pixmap
742 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
744 #ifdef GLX_USE_APPLEGL
745 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
746 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
748 xGLXDestroyGLXPixmapReq
*req
;
751 opcode
= __glXSetupForCommand(dpy
);
756 /* Send the glXDestroyGLXPixmap request */
758 GetReq(GLXDestroyGLXPixmap
, req
);
759 req
->reqType
= opcode
;
760 req
->glxCode
= X_GLXDestroyGLXPixmap
;
761 req
->glxpixmap
= glxpixmap
;
765 DestroyGLXDrawable(dpy
, glxpixmap
);
767 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
769 struct glx_display
*const priv
= __glXInitialize(dpy
);
770 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
773 (*pdraw
->destroyDrawable
) (pdraw
);
774 __glxHashDelete(priv
->drawHash
, glxpixmap
);
778 #endif /* GLX_USE_APPLEGL */
782 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
784 #ifdef GLX_USE_APPLEGL
785 struct glx_context
* gc
= __glXGetCurrentContext();
786 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
787 apple_glx_swap_buffers(gc
->driContext
);
789 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
792 struct glx_context
*gc
;
798 xGLXSwapBuffersReq
*req
;
801 gc
= __glXGetCurrentContext();
803 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
805 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
808 if (gc
&& drawable
== gc
->currentDrawable
) {
812 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
818 opcode
= __glXSetupForCommand(dpy
);
824 ** The calling thread may or may not have a current context. If it
825 ** does, send the context tag so the server can do a flush.
827 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
828 ((drawable
== gc
->currentDrawable
)
829 || (drawable
== gc
->currentReadable
))) {
830 tag
= gc
->currentContextTag
;
837 c
= XGetXCBConnection(dpy
);
838 xcb_glx_swap_buffers(c
, tag
, drawable
);
841 /* Send the glXSwapBuffers request */
843 GetReq(GLXSwapBuffers
, req
);
844 req
->reqType
= opcode
;
845 req
->glxCode
= X_GLXSwapBuffers
;
846 req
->drawable
= drawable
;
847 req
->contextTag
= tag
;
852 #endif /* GLX_USE_APPLEGL */
857 ** Return configuration information for the given display, screen and
858 ** visual combination.
861 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
864 struct glx_display
*priv
;
865 struct glx_screen
*psc
;
866 struct glx_config
*config
;
869 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
870 if (status
== Success
) {
871 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
873 /* Lookup attribute after first finding a match on the visual */
874 if (config
!= NULL
) {
875 return glx_config_get(config
, attribute
, value_return
);
878 status
= GLX_BAD_VISUAL
;
882 ** If we can't find the config for this visual, this visual is not
883 ** supported by the OpenGL implementation on the server.
885 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
886 *value_return
= GL_FALSE
;
893 /************************************************************************/
896 init_fbconfig_for_chooser(struct glx_config
* config
,
897 GLboolean fbconfig_style_tags
)
899 memset(config
, 0, sizeof(struct glx_config
));
900 config
->visualID
= (XID
) GLX_DONT_CARE
;
901 config
->visualType
= GLX_DONT_CARE
;
903 /* glXChooseFBConfig specifies different defaults for these two than
906 if (fbconfig_style_tags
) {
907 config
->rgbMode
= GL_TRUE
;
908 config
->doubleBufferMode
= GLX_DONT_CARE
;
911 config
->visualRating
= GLX_DONT_CARE
;
912 config
->transparentPixel
= GLX_NONE
;
913 config
->transparentRed
= GLX_DONT_CARE
;
914 config
->transparentGreen
= GLX_DONT_CARE
;
915 config
->transparentBlue
= GLX_DONT_CARE
;
916 config
->transparentAlpha
= GLX_DONT_CARE
;
917 config
->transparentIndex
= GLX_DONT_CARE
;
919 config
->drawableType
= GLX_WINDOW_BIT
;
921 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
922 config
->xRenderable
= GLX_DONT_CARE
;
923 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
925 config
->swapMethod
= GLX_DONT_CARE
;
928 #define MATCH_DONT_CARE( param ) \
930 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
931 && (a-> param != b-> param) ) { \
936 #define MATCH_MINIMUM( param ) \
938 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
939 && (a-> param > b-> param) ) { \
944 #define MATCH_EXACT( param ) \
946 if ( a-> param != b-> param) { \
951 /* Test that all bits from a are contained in b */
952 #define MATCH_MASK(param) \
954 if ((a->param & ~b->param) != 0) \
959 * Determine if two GLXFBConfigs are compatible.
961 * \param a Application specified config to test.
962 * \param b Server specified config to test against \c a.
965 fbconfigs_compatible(const struct glx_config
* const a
,
966 const struct glx_config
* const b
)
968 MATCH_DONT_CARE(doubleBufferMode
);
969 MATCH_DONT_CARE(visualType
);
970 MATCH_DONT_CARE(visualRating
);
971 MATCH_DONT_CARE(xRenderable
);
972 MATCH_DONT_CARE(fbconfigID
);
973 MATCH_DONT_CARE(swapMethod
);
975 MATCH_MINIMUM(rgbBits
);
976 MATCH_MINIMUM(numAuxBuffers
);
977 MATCH_MINIMUM(redBits
);
978 MATCH_MINIMUM(greenBits
);
979 MATCH_MINIMUM(blueBits
);
980 MATCH_MINIMUM(alphaBits
);
981 MATCH_MINIMUM(depthBits
);
982 MATCH_MINIMUM(stencilBits
);
983 MATCH_MINIMUM(accumRedBits
);
984 MATCH_MINIMUM(accumGreenBits
);
985 MATCH_MINIMUM(accumBlueBits
);
986 MATCH_MINIMUM(accumAlphaBits
);
987 MATCH_MINIMUM(sampleBuffers
);
988 MATCH_MINIMUM(maxPbufferWidth
);
989 MATCH_MINIMUM(maxPbufferHeight
);
990 MATCH_MINIMUM(maxPbufferPixels
);
991 MATCH_MINIMUM(samples
);
993 MATCH_DONT_CARE(stereoMode
);
996 MATCH_MASK(drawableType
);
997 MATCH_MASK(renderType
);
999 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1000 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1001 * Technically speaking, it is a bug in the DDX driver, but there is
1002 * enough of an installed base to work around the problem here. In any
1003 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1004 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1005 * 0 from the server to be a match to maintain backward compatibility with
1006 * the (broken) drivers.
1009 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1010 if (a
->transparentPixel
== GLX_NONE
) {
1011 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1015 MATCH_EXACT(transparentPixel
);
1018 switch (a
->transparentPixel
) {
1019 case GLX_TRANSPARENT_RGB
:
1020 MATCH_DONT_CARE(transparentRed
);
1021 MATCH_DONT_CARE(transparentGreen
);
1022 MATCH_DONT_CARE(transparentBlue
);
1023 MATCH_DONT_CARE(transparentAlpha
);
1026 case GLX_TRANSPARENT_INDEX
:
1027 MATCH_DONT_CARE(transparentIndex
);
1039 /* There's some trickly language in the GLX spec about how this is supposed
1040 * to work. Basically, if a given component size is either not specified
1041 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1042 * Well, that's really hard to do with the code as-is. This behavior is
1043 * closer to correct, but still not technically right.
1045 #define PREFER_LARGER_OR_ZERO(comp) \
1047 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1048 if ( ((*a)-> comp) == 0 ) { \
1051 else if ( ((*b)-> comp) == 0 ) { \
1055 return ((*b)-> comp) - ((*a)-> comp) ; \
1060 #define PREFER_LARGER(comp) \
1062 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1063 return ((*b)-> comp) - ((*a)-> comp) ; \
1067 #define PREFER_SMALLER(comp) \
1069 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1070 return ((*a)-> comp) - ((*b)-> comp) ; \
1075 * Compare two GLXFBConfigs. This function is intended to be used as the
1076 * compare function passed in to qsort.
1078 * \returns If \c a is a "better" config, according to the specification of
1079 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1080 * better, then a number greater than zero is return. If both are
1081 * equal, zero is returned.
1082 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1085 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1087 /* The order of these comparisons must NOT change. It is defined by
1088 * the GLX 1.3 spec and ARB_multisample.
1091 PREFER_SMALLER(visualSelectGroup
);
1093 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1094 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1095 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1097 PREFER_SMALLER(visualRating
);
1099 /* This isn't quite right. It is supposed to compare the sum of the
1100 * components the user specifically set minimums for.
1102 PREFER_LARGER_OR_ZERO(redBits
);
1103 PREFER_LARGER_OR_ZERO(greenBits
);
1104 PREFER_LARGER_OR_ZERO(blueBits
);
1105 PREFER_LARGER_OR_ZERO(alphaBits
);
1107 PREFER_SMALLER(rgbBits
);
1109 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1110 /* Prefer single-buffer.
1112 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1115 PREFER_SMALLER(numAuxBuffers
);
1117 PREFER_LARGER_OR_ZERO(depthBits
);
1118 PREFER_SMALLER(stencilBits
);
1120 /* This isn't quite right. It is supposed to compare the sum of the
1121 * components the user specifically set minimums for.
1123 PREFER_LARGER_OR_ZERO(accumRedBits
);
1124 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1125 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1126 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1128 PREFER_SMALLER(visualType
);
1130 /* None of the multisample specs say where this comparison should happen,
1131 * so I put it near the end.
1133 PREFER_SMALLER(sampleBuffers
);
1134 PREFER_SMALLER(samples
);
1136 /* None of the pbuffer or fbconfig specs say that this comparison needs
1137 * to happen at all, but it seems like it should.
1139 PREFER_LARGER(maxPbufferWidth
);
1140 PREFER_LARGER(maxPbufferHeight
);
1141 PREFER_LARGER(maxPbufferPixels
);
1148 * Selects and sorts a subset of the supplied configs based on the attributes.
1149 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1150 * and \c glXChooseFBConfigSGIX.
1152 * \param configs Array of pointers to possible configs. The elements of
1153 * this array that do not meet the criteria will be set to
1154 * NULL. The remaining elements will be sorted according to
1155 * the various visual / FBConfig selection rules.
1156 * \param num_configs Number of elements in the \c configs array.
1157 * \param attribList Attributes used select from \c configs. This array is
1158 * terminated by a \c None tag. The array can either take
1159 * the form expected by \c glXChooseVisual (where boolean
1160 * tags do not have a value) or by \c glXChooseFBConfig
1161 * (where every tag has a value).
1162 * \param fbconfig_style_tags Selects whether \c attribList is in
1163 * \c glXChooseVisual style or
1164 * \c glXChooseFBConfig style.
1165 * \returns The number of valid elements left in \c configs.
1167 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1170 choose_visual(struct glx_config
** configs
, int num_configs
,
1171 const int *attribList
, GLboolean fbconfig_style_tags
)
1173 struct glx_config test_config
;
1177 /* This is a fairly direct implementation of the selection method
1178 * described by GLX_SGIX_fbconfig. Start by culling out all the
1179 * configs that are not compatible with the selected parameter
1183 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1184 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1185 (const INT32
*) attribList
,
1186 GL_TRUE
, fbconfig_style_tags
);
1189 for (i
= 0; i
< num_configs
; i
++) {
1190 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1191 configs
[base
] = configs
[i
];
1200 if (base
< num_configs
) {
1201 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1204 /* After the incompatible configs are removed, the resulting
1205 * list is sorted according to the rules set out in the various
1209 qsort(configs
, base
, sizeof(struct glx_config
*),
1210 (int (*)(const void *, const void *)) fbconfig_compare
);
1218 ** Return the visual that best matches the template. Return None if no
1219 ** visual matches the template.
1221 _X_EXPORT XVisualInfo
*
1222 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1224 XVisualInfo
*visualList
= NULL
;
1225 struct glx_display
*priv
;
1226 struct glx_screen
*psc
;
1227 struct glx_config test_config
;
1228 struct glx_config
*config
;
1229 struct glx_config
*best_config
= NULL
;
1232 ** Get a list of all visuals, return if list is empty
1234 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1240 ** Build a template from the defaults and the attribute list
1241 ** Free visual list and return if an unexpected token is encountered
1243 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1244 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1245 (const INT32
*) attribList
,
1249 ** Eliminate visuals that don't meet minimum requirements
1250 ** Compute a score for those that do
1251 ** Remember which visual, if any, got the highest score
1252 ** If no visual is acceptable, return None
1253 ** Otherwise, create an XVisualInfo list with just the selected X visual
1256 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1257 if (fbconfigs_compatible(&test_config
, config
)
1258 && ((best_config
== NULL
) ||
1259 (fbconfig_compare (&config
, &best_config
) < 0))) {
1260 XVisualInfo visualTemplate
;
1261 XVisualInfo
*newList
;
1264 visualTemplate
.screen
= screen
;
1265 visualTemplate
.visualid
= config
->visualID
;
1266 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1267 &visualTemplate
, &i
);
1271 visualList
= newList
;
1272 best_config
= config
;
1277 #ifdef GLX_USE_APPLEGL
1278 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1279 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1287 _X_EXPORT
const char *
1288 glXQueryExtensionsString(Display
* dpy
, int screen
)
1290 struct glx_screen
*psc
;
1291 struct glx_display
*priv
;
1293 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1297 if (!psc
->effectiveGLXexts
) {
1298 if (!psc
->serverGLXexts
) {
1299 psc
->serverGLXexts
=
1300 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1304 __glXCalculateUsableExtensions(psc
,
1305 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1306 (psc
->driScreen
!= NULL
),
1310 priv
->minorVersion
);
1313 return psc
->effectiveGLXexts
;
1316 _X_EXPORT
const char *
1317 glXGetClientString(Display
* dpy
, int name
)
1323 return (__glXGLXClientVendorName
);
1325 return (__glXGLXClientVersion
);
1326 case GLX_EXTENSIONS
:
1327 return (__glXGetClientExtensions());
1333 _X_EXPORT
const char *
1334 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1336 struct glx_screen
*psc
;
1337 struct glx_display
*priv
;
1341 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1347 str
= &priv
->serverGLXvendor
;
1350 str
= &priv
->serverGLXversion
;
1352 case GLX_EXTENSIONS
:
1353 str
= &psc
->serverGLXexts
;
1360 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1367 __glXClientInfo(Display
* dpy
, int opcode
)
1369 char *ext_str
= __glXGetClientGLExtensionString();
1370 int size
= strlen(ext_str
) + 1;
1373 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1374 xcb_glx_client_info(c
,
1375 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1377 xGLXClientInfoReq
*req
;
1379 /* Send the glXClientInfo request */
1381 GetReq(GLXClientInfo
, req
);
1382 req
->reqType
= opcode
;
1383 req
->glxCode
= X_GLXClientInfo
;
1384 req
->major
= GLX_MAJOR_VERSION
;
1385 req
->minor
= GLX_MINOR_VERSION
;
1387 req
->length
+= (size
+ 3) >> 2;
1388 req
->numbytes
= size
;
1389 Data(dpy
, ext_str
, size
);
1393 #endif /* USE_XCB */
1400 ** EXT_import_context
1404 glXGetCurrentDisplay(void)
1406 struct glx_context
*gc
= __glXGetCurrentContext();
1409 return gc
->currentDpy
;
1413 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1414 glXGetCurrentDisplay
)
1416 #ifndef GLX_USE_APPLEGL
1417 _X_EXPORT GLXContext
1418 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1420 struct glx_display
*priv
= __glXInitialize(dpy
);
1421 struct glx_screen
*psc
= NULL
;
1422 xGLXQueryContextReply reply
;
1424 struct glx_context
*ctx
;
1426 /* This GLX implementation knows about 5 different properties, so
1427 * allow the server to send us one of each.
1429 int propList
[5 * 2], *pProp
, nPropListBytes
;
1433 struct glx_config
*mode
;
1434 uint32_t fbconfigID
= 0;
1435 uint32_t visualID
= 0;
1437 Bool got_screen
= False
;
1439 /* The GLX_EXT_import_context spec says:
1441 * "If <contextID> does not refer to a valid context, then a BadContext
1442 * error is generated; if <contextID> refers to direct rendering
1443 * context then no error is generated but glXImportContextEXT returns
1446 * If contextID is None, generate BadContext on the client-side. Other
1447 * sorts of invalid contexts will be detected by the server in the
1448 * __glXIsDirect call.
1450 if (contextID
== None
) {
1451 __glXSendError(dpy
, GLXBadContext
, contextID
, X_GLXIsDirect
, false);
1455 if (__glXIsDirect(dpy
, contextID
))
1458 opcode
= __glXSetupForCommand(dpy
);
1462 /* Send the glXQueryContextInfoEXT request */
1465 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1466 xGLXQueryContextReq
*req
;
1468 GetReq(GLXQueryContext
, req
);
1470 req
->reqType
= opcode
;
1471 req
->glxCode
= X_GLXQueryContext
;
1472 req
->context
= contextID
;
1475 xGLXVendorPrivateReq
*vpreq
;
1476 xGLXQueryContextInfoEXTReq
*req
;
1478 GetReqExtra(GLXVendorPrivate
,
1479 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1481 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1482 req
->reqType
= opcode
;
1483 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1484 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1485 req
->context
= contextID
;
1488 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1490 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1491 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1494 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1498 numProps
= nPropListBytes
/ (2 * sizeof(propList
[0]));
1504 for (i
= 0, pProp
= propList
; i
< numProps
; i
++, pProp
+= 2)
1510 case GLX_SHARE_CONTEXT_EXT
:
1513 case GLX_VISUAL_ID_EXT
:
1514 visualID
= pProp
[1];
1516 case GLX_FBCONFIG_ID
:
1517 fbconfigID
= pProp
[1];
1519 case GLX_RENDER_TYPE
:
1520 renderType
= pProp
[1];
1527 psc
= GetGLXScreenConfigs(dpy
, screen
);
1531 if (fbconfigID
!= 0) {
1532 mode
= glx_config_find_fbconfig(psc
->configs
, fbconfigID
);
1533 } else if (visualID
!= 0) {
1534 mode
= glx_config_find_visual(psc
->visuals
, visualID
);
1540 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1544 ctx
->xid
= contextID
;
1545 ctx
->imported
= GL_TRUE
;
1546 ctx
->share_xid
= share
;
1548 return (GLXContext
) ctx
;
1554 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1556 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1558 switch (attribute
) {
1559 case GLX_SHARE_CONTEXT_EXT
:
1560 *value
= ctx
->share_xid
;
1562 case GLX_VISUAL_ID_EXT
:
1563 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1566 *value
= ctx
->screen
;
1568 case GLX_FBCONFIG_ID
:
1569 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1571 case GLX_RENDER_TYPE
:
1572 *value
= ctx
->renderType
;
1575 return GLX_BAD_ATTRIBUTE
;
1581 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1582 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1583 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1585 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1587 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1589 return (ctx
== NULL
) ? None
: ctx
->xid
;
1593 glXFreeContextEXT(Display
*dpy
, GLXContext ctx
)
1595 struct glx_context
*gc
= (struct glx_context
*) ctx
;
1597 if (gc
== NULL
|| gc
->xid
== None
)
1600 /* The GLX_EXT_import_context spec says:
1602 * "glXFreeContext does not free the server-side context information or
1603 * the XID associated with the server-side context."
1605 * Don't send any protocol. Just destroy the client-side tracking of the
1606 * context. Also, only release the context structure if it's not current.
1609 if (gc
->currentDpy
) {
1612 gc
->vtable
->destroy(gc
);
1617 _X_EXPORT GLXFBConfig
*
1618 glXChooseFBConfig(Display
* dpy
, int screen
,
1619 const int *attribList
, int *nitems
)
1621 struct glx_config
**config_list
;
1625 config_list
= (struct glx_config
**)
1626 glXGetFBConfigs(dpy
, screen
, &list_size
);
1628 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1629 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1630 if (list_size
== 0) {
1636 *nitems
= list_size
;
1637 return (GLXFBConfig
*) config_list
;
1641 _X_EXPORT GLXContext
1642 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1643 int renderType
, GLXContext shareList
, Bool allowDirect
)
1645 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1647 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1648 allowDirect
, X_GLXCreateNewContext
, renderType
,
1653 _X_EXPORT GLXDrawable
1654 glXGetCurrentReadDrawable(void)
1656 struct glx_context
*gc
= __glXGetCurrentContext();
1658 return gc
->currentReadable
;
1662 _X_EXPORT GLXFBConfig
*
1663 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1665 struct glx_display
*priv
= __glXInitialize(dpy
);
1666 struct glx_config
**config_list
= NULL
;
1667 struct glx_config
*config
;
1668 unsigned num_configs
= 0;
1672 if (priv
&& (priv
->screens
!= NULL
)
1673 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1674 && (priv
->screens
[screen
]->configs
!= NULL
)
1675 && (priv
->screens
[screen
]->configs
->fbconfigID
1676 != (int) GLX_DONT_CARE
)) {
1678 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1679 config
= config
->next
) {
1680 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1685 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1686 if (config_list
!= NULL
) {
1687 *nelements
= num_configs
;
1689 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1690 config
= config
->next
) {
1691 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1692 config_list
[i
] = config
;
1699 return (GLXFBConfig
*) config_list
;
1704 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1705 int attribute
, int *value
)
1707 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1710 return GLXBadFBConfig
;
1712 return glx_config_get(config
, attribute
, value
);
1716 _X_EXPORT XVisualInfo
*
1717 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1719 XVisualInfo visualTemplate
;
1720 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1724 ** Get a list of all visuals, return if list is empty
1726 visualTemplate
.visualid
= config
->visualID
;
1727 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1730 #ifndef GLX_USE_APPLEGL
1732 ** GLX_SGI_swap_control
1735 __glXSwapIntervalSGI(int interval
)
1737 xGLXVendorPrivateReq
*req
;
1738 struct glx_context
*gc
= __glXGetCurrentContext();
1739 struct glx_screen
*psc
;
1741 CARD32
*interval_ptr
;
1745 return GLX_BAD_CONTEXT
;
1748 if (interval
<= 0) {
1749 return GLX_BAD_VALUE
;
1752 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1754 #ifdef GLX_DIRECT_RENDERING
1755 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1756 __GLXDRIdrawable
*pdraw
=
1757 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1758 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1763 dpy
= gc
->currentDpy
;
1764 opcode
= __glXSetupForCommand(dpy
);
1769 /* Send the glXSwapIntervalSGI request */
1771 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1772 req
->reqType
= opcode
;
1773 req
->glxCode
= X_GLXVendorPrivate
;
1774 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1775 req
->contextTag
= gc
->currentContextTag
;
1777 interval_ptr
= (CARD32
*) (req
+ 1);
1778 *interval_ptr
= interval
;
1789 ** GLX_MESA_swap_control
1792 __glXSwapIntervalMESA(unsigned int interval
)
1794 #ifdef GLX_DIRECT_RENDERING
1795 struct glx_context
*gc
= __glXGetCurrentContext();
1797 if (gc
!= NULL
&& gc
->isDirect
) {
1798 struct glx_screen
*psc
;
1800 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1801 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1802 __GLXDRIdrawable
*pdraw
=
1803 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1804 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1809 return GLX_BAD_CONTEXT
;
1814 __glXGetSwapIntervalMESA(void)
1816 #ifdef GLX_DIRECT_RENDERING
1817 struct glx_context
*gc
= __glXGetCurrentContext();
1819 if (gc
!= NULL
&& gc
->isDirect
) {
1820 struct glx_screen
*psc
;
1822 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1823 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1824 __GLXDRIdrawable
*pdraw
=
1825 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1826 return psc
->driScreen
->getSwapInterval(pdraw
);
1836 ** GLX_SGI_video_sync
1839 __glXGetVideoSyncSGI(unsigned int *count
)
1841 int64_t ust
, msc
, sbc
;
1843 struct glx_context
*gc
= __glXGetCurrentContext();
1844 struct glx_screen
*psc
;
1845 #ifdef GLX_DIRECT_RENDERING
1846 __GLXDRIdrawable
*pdraw
;
1850 return GLX_BAD_CONTEXT
;
1852 #ifdef GLX_DIRECT_RENDERING
1854 return GLX_BAD_CONTEXT
;
1857 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1858 #ifdef GLX_DIRECT_RENDERING
1859 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1862 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1863 * FIXME: there should be a GLX encoding for this call. I can find no
1864 * FIXME: documentation for the GLX encoding.
1866 #ifdef GLX_DIRECT_RENDERING
1867 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1868 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1869 *count
= (unsigned) msc
;
1870 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1874 return GLX_BAD_CONTEXT
;
1878 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1880 struct glx_context
*gc
= __glXGetCurrentContext();
1881 struct glx_screen
*psc
;
1882 #ifdef GLX_DIRECT_RENDERING
1883 __GLXDRIdrawable
*pdraw
;
1885 int64_t ust
, msc
, sbc
;
1888 if (divisor
<= 0 || remainder
< 0)
1889 return GLX_BAD_VALUE
;
1892 return GLX_BAD_CONTEXT
;
1894 #ifdef GLX_DIRECT_RENDERING
1896 return GLX_BAD_CONTEXT
;
1899 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1900 #ifdef GLX_DIRECT_RENDERING
1901 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1904 #ifdef GLX_DIRECT_RENDERING
1905 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1906 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1908 *count
= (unsigned) msc
;
1909 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1913 return GLX_BAD_CONTEXT
;
1916 #endif /* GLX_USE_APPLEGL */
1919 ** GLX_SGIX_fbconfig
1920 ** Many of these functions are aliased to GLX 1.3 entry points in the
1921 ** GLX_functions table.
1925 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1926 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1927 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1929 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1930 (Display
* dpy
, int screen
, int *attrib_list
,
1931 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1934 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1935 (Display
* dpy
, GLXFBConfigSGIX config
),
1936 (dpy
, config
), glXGetVisualFromFBConfig
)
1939 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1940 GLXFBConfigSGIX fbconfig
,
1943 #ifndef GLX_USE_APPLEGL
1944 xGLXVendorPrivateWithReplyReq
*vpreq
;
1945 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1946 GLXPixmap xid
= None
;
1948 struct glx_screen
*psc
;
1950 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1953 if ((dpy
== NULL
) || (config
== NULL
)) {
1956 #ifdef GLX_USE_APPLEGL
1957 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1962 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1964 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1965 opcode
= __glXSetupForCommand(dpy
);
1970 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1972 GetReqExtra(GLXVendorPrivateWithReply
,
1973 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1974 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1975 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1976 req
->reqType
= opcode
;
1977 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1978 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1979 req
->screen
= config
->screen
;
1980 req
->fbconfig
= config
->fbconfigID
;
1981 req
->pixmap
= pixmap
;
1982 req
->glxpixmap
= xid
= XAllocID(dpy
);
1991 _X_EXPORT GLXContext
1992 glXCreateContextWithConfigSGIX(Display
* dpy
,
1993 GLXFBConfigSGIX fbconfig
, int renderType
,
1994 GLXContext shareList
, Bool allowDirect
)
1996 GLXContext gc
= NULL
;
1997 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1998 struct glx_screen
*psc
;
2001 if ((dpy
== NULL
) || (config
== NULL
)) {
2005 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2007 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2008 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
2010 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2018 _X_EXPORT GLXFBConfigSGIX
2019 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2021 struct glx_display
*priv
;
2022 struct glx_screen
*psc
= NULL
;
2024 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
2025 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2026 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2027 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2034 #ifndef GLX_USE_APPLEGL
2036 ** GLX_SGIX_swap_group
2039 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2049 ** GLX_SGIX_swap_barrier
2052 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2060 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2070 ** GLX_OML_sync_control
2073 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2074 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2076 struct glx_display
* const priv
= __glXInitialize(dpy
);
2078 #ifdef GLX_DIRECT_RENDERING
2079 __GLXDRIdrawable
*pdraw
;
2081 struct glx_screen
*psc
;
2086 #ifdef GLX_DIRECT_RENDERING
2087 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2088 psc
= pdraw
? pdraw
->psc
: NULL
;
2089 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2090 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2098 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2100 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
2101 int32_t * numerator
, int32_t * denominator
)
2104 struct glx_screen
*psc
;
2105 XF86VidModeModeLine mode_line
;
2110 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2111 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2112 unsigned n
= dot_clock
* 1000;
2113 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2115 # define V_INTERLACE 0x010
2116 # define V_DBLSCAN 0x020
2118 if (mode_line
.flags
& V_INTERLACE
)
2120 else if (mode_line
.flags
& V_DBLSCAN
)
2123 /* The OML_sync_control spec requires that if the refresh rate is a
2124 * whole number, that the returned numerator be equal to the refresh
2125 * rate and the denominator be 1.
2133 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2135 /* This is a poor man's way to reduce a fraction. It's far from
2136 * perfect, but it will work well enough for this situation.
2139 for (i
= 0; f
[i
] != 0; i
++) {
2140 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2160 * Determine the refresh rate of the specified drawable and display.
2162 * \param dpy Display whose refresh rate is to be determined.
2163 * \param drawable Drawable whose refresh rate is to be determined.
2164 * \param numerator Numerator of the refresh rate.
2165 * \param demoninator Denominator of the refresh rate.
2166 * \return If the refresh rate for the specified display and drawable could
2167 * be calculated, True is returned. Otherwise False is returned.
2169 * \note This function is implemented entirely client-side. A lot of other
2170 * functionality is required to export GLX_OML_sync_control, so on
2171 * XFree86 this function can be called for direct-rendering contexts
2172 * when GLX_OML_sync_control appears in the client extension string.
2176 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2177 int32_t * numerator
, int32_t * denominator
)
2179 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2180 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2185 return __glxGetMscRate(draw
, numerator
, denominator
);
2197 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2198 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2200 struct glx_context
*gc
= __glXGetCurrentContext();
2201 #ifdef GLX_DIRECT_RENDERING
2202 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2203 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2206 if (!gc
) /* no GLX for this */
2209 #ifdef GLX_DIRECT_RENDERING
2210 if (!pdraw
|| !gc
->isDirect
)
2214 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2215 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2216 * of -1 if the function failed because of errors detected in the input
2219 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2221 if (divisor
> 0 && remainder
>= divisor
)
2224 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2227 #ifdef GLX_DIRECT_RENDERING
2228 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2229 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2238 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2239 int64_t target_msc
, int64_t divisor
,
2240 int64_t remainder
, int64_t * ust
,
2241 int64_t * msc
, int64_t * sbc
)
2243 #ifdef GLX_DIRECT_RENDERING
2244 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2245 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2250 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2251 * error", but the return type in the spec is Bool.
2253 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2255 if (divisor
> 0 && remainder
>= divisor
)
2258 #ifdef GLX_DIRECT_RENDERING
2259 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2260 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2271 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2272 int64_t target_sbc
, int64_t * ust
,
2273 int64_t * msc
, int64_t * sbc
)
2275 #ifdef GLX_DIRECT_RENDERING
2276 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2277 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2281 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2282 * error", but the return type in the spec is Bool.
2287 #ifdef GLX_DIRECT_RENDERING
2288 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2289 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2301 * Mesa extension stubs. These will help reduce portability problems.
2306 * Release all buffers associated with the specified GLX drawable.
2309 * This function was intended for stand-alone Mesa. The issue there is that
2310 * the library doesn't get any notification when a window is closed. In
2311 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2312 * supported, there are 3 different functions to destroy a drawable. It
2313 * should be possible to create GLX protocol (or have it determine which
2314 * protocol to use based on the type of the drawable) to have one function
2315 * do the work of 3. For the direct-rendering case, this function could
2316 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2317 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2318 * would need to be used. This really should be done as part of the new DRI
2321 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2322 * __driGarbageCollectDrawables
2323 * glXDestroyGLXPixmap
2324 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2325 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2328 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2337 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2338 Pixmap pixmap
, Colormap cmap
)
2351 * GLX_MESA_copy_sub_buffer
2353 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2355 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2356 int x
, int y
, int width
, int height
)
2358 xGLXVendorPrivateReq
*req
;
2359 struct glx_context
*gc
;
2361 CARD32
*drawable_ptr
;
2362 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2365 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2366 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2367 if (pdraw
!= NULL
) {
2368 struct glx_screen
*psc
= pdraw
->psc
;
2369 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2371 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2378 opcode
= __glXSetupForCommand(dpy
);
2383 ** The calling thread may or may not have a current context. If it
2384 ** does, send the context tag so the server can do a flush.
2386 gc
= __glXGetCurrentContext();
2387 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2388 ((drawable
== gc
->currentDrawable
) ||
2389 (drawable
== gc
->currentReadable
))) {
2390 tag
= gc
->currentContextTag
;
2397 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2398 req
->reqType
= opcode
;
2399 req
->glxCode
= X_GLXVendorPrivate
;
2400 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2401 req
->contextTag
= tag
;
2403 drawable_ptr
= (CARD32
*) (req
+ 1);
2404 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2405 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2406 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2407 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2409 *drawable_ptr
= drawable
;
2421 __glXBindTexImageEXT(Display
* dpy
,
2422 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2424 struct glx_context
*gc
= __glXGetCurrentContext();
2426 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2429 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2433 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2435 struct glx_context
*gc
= __glXGetCurrentContext();
2437 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2440 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2445 #endif /* GLX_USE_APPLEGL */
2448 * \c strdup is actually not a standard ANSI C or POSIX routine.
2449 * Irix will not define it if ANSI mode is in effect.
2454 __glXstrdup(const char *str
)
2457 copy
= (char *) Xmalloc(strlen(str
) + 1);
2465 ** glXGetProcAddress support
2468 struct name_address_pair
2474 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2475 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2477 static const struct name_address_pair GLX_functions
[] = {
2478 /*** GLX_VERSION_1_0 ***/
2479 GLX_FUNCTION(glXChooseVisual
),
2480 GLX_FUNCTION(glXCopyContext
),
2481 GLX_FUNCTION(glXCreateContext
),
2482 GLX_FUNCTION(glXCreateGLXPixmap
),
2483 GLX_FUNCTION(glXDestroyContext
),
2484 GLX_FUNCTION(glXDestroyGLXPixmap
),
2485 GLX_FUNCTION(glXGetConfig
),
2486 GLX_FUNCTION(glXGetCurrentContext
),
2487 GLX_FUNCTION(glXGetCurrentDrawable
),
2488 GLX_FUNCTION(glXIsDirect
),
2489 GLX_FUNCTION(glXMakeCurrent
),
2490 GLX_FUNCTION(glXQueryExtension
),
2491 GLX_FUNCTION(glXQueryVersion
),
2492 GLX_FUNCTION(glXSwapBuffers
),
2493 GLX_FUNCTION(glXUseXFont
),
2494 GLX_FUNCTION(glXWaitGL
),
2495 GLX_FUNCTION(glXWaitX
),
2497 /*** GLX_VERSION_1_1 ***/
2498 GLX_FUNCTION(glXGetClientString
),
2499 GLX_FUNCTION(glXQueryExtensionsString
),
2500 GLX_FUNCTION(glXQueryServerString
),
2502 /*** GLX_VERSION_1_2 ***/
2503 GLX_FUNCTION(glXGetCurrentDisplay
),
2505 /*** GLX_VERSION_1_3 ***/
2506 GLX_FUNCTION(glXChooseFBConfig
),
2507 GLX_FUNCTION(glXCreateNewContext
),
2508 GLX_FUNCTION(glXCreatePbuffer
),
2509 GLX_FUNCTION(glXCreatePixmap
),
2510 GLX_FUNCTION(glXCreateWindow
),
2511 GLX_FUNCTION(glXDestroyPbuffer
),
2512 GLX_FUNCTION(glXDestroyPixmap
),
2513 GLX_FUNCTION(glXDestroyWindow
),
2514 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2515 GLX_FUNCTION(glXGetFBConfigAttrib
),
2516 GLX_FUNCTION(glXGetFBConfigs
),
2517 GLX_FUNCTION(glXGetSelectedEvent
),
2518 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2519 GLX_FUNCTION(glXMakeContextCurrent
),
2520 GLX_FUNCTION(glXQueryContext
),
2521 GLX_FUNCTION(glXQueryDrawable
),
2522 GLX_FUNCTION(glXSelectEvent
),
2524 #ifndef GLX_USE_APPLEGL
2525 /*** GLX_SGI_swap_control ***/
2526 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2528 /*** GLX_SGI_video_sync ***/
2529 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2530 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2532 /*** GLX_SGI_make_current_read ***/
2533 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2534 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2536 /*** GLX_EXT_import_context ***/
2537 GLX_FUNCTION(glXFreeContextEXT
),
2538 GLX_FUNCTION(glXGetContextIDEXT
),
2539 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2540 GLX_FUNCTION(glXImportContextEXT
),
2541 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2544 /*** GLX_SGIX_fbconfig ***/
2545 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2546 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2547 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2548 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2549 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2550 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2552 #ifndef GLX_USE_APPLEGL
2553 /*** GLX_SGIX_pbuffer ***/
2554 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2555 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2556 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2557 GLX_FUNCTION(glXSelectEventSGIX
),
2558 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2560 /*** GLX_SGIX_swap_group ***/
2561 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2563 /*** GLX_SGIX_swap_barrier ***/
2564 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2565 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2567 /*** GLX_MESA_copy_sub_buffer ***/
2568 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2570 /*** GLX_MESA_pixmap_colormap ***/
2571 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2573 /*** GLX_MESA_release_buffers ***/
2574 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2576 /*** GLX_MESA_swap_control ***/
2577 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2578 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2581 /*** GLX_ARB_get_proc_address ***/
2582 GLX_FUNCTION(glXGetProcAddressARB
),
2585 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2587 #ifndef GLX_USE_APPLEGL
2588 /*** GLX_OML_sync_control ***/
2589 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2590 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2591 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2592 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2593 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2595 /*** GLX_EXT_texture_from_pixmap ***/
2596 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2597 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2600 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2601 /*** DRI configuration ***/
2602 GLX_FUNCTION(glXGetScreenDriver
),
2603 GLX_FUNCTION(glXGetDriverConfig
),
2606 /*** GLX_ARB_create_context and GLX_ARB_create_context_profile ***/
2607 GLX_FUNCTION(glXCreateContextAttribsARB
),
2609 {NULL
, NULL
} /* end of list */
2612 static const GLvoid
*
2613 get_glx_proc_address(const char *funcName
)
2617 /* try static functions */
2618 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2619 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2620 return GLX_functions
[i
].Address
;
2627 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2628 * \c glXGetProcAddress.
2630 * \param procName Name of a GL or GLX function.
2631 * \returns A pointer to the named function
2633 * \sa glXGetProcAddress
2635 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2637 typedef void (*gl_function
) (void);
2641 /* Search the table of GLX and internal functions first. If that
2642 * fails and the supplied name could be a valid core GL name, try
2643 * searching the core GL function table. This check is done to prevent
2644 * DRI based drivers from searching the core GL function table for
2645 * internal API functions.
2647 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2648 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2649 && (procName
[2] != 'X')) {
2650 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2652 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2654 struct glx_context
*gc
= __glXGetCurrentContext();
2656 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2657 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2664 * Get the address of a named GL function. This is the GLX 1.4 name for
2665 * \c glXGetProcAddressARB.
2667 * \param procName Name of a GL or GLX function.
2668 * \returns A pointer to the named function
2670 * \sa glXGetProcAddressARB
2672 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2673 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2674 __attribute__ ((alias("glXGetProcAddressARB")));
2677 return glXGetProcAddressARB(procName
);
2679 #endif /* __GNUC__ */
2682 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2684 * Get the unadjusted system time (UST). Currently, the UST is measured in
2685 * microseconds since Epoc. The actual resolution of the UST may vary from
2686 * system to system, and the units may vary from release to release.
2687 * Drivers should not call this function directly. They should instead use
2688 * \c glXGetProcAddress to obtain a pointer to the function.
2690 * \param ust Location to store the 64-bit UST
2691 * \returns Zero on success or a negative errno value on failure.
2693 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2695 * \since Internal API version 20030317.
2698 __glXGetUST(int64_t * ust
)
2706 if (gettimeofday(&tv
, NULL
) == 0) {
2707 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2714 #endif /* GLX_DIRECT_RENDERING */