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
;
412 if (gc
->currentDpy
) {
413 /* This context is bound to some thread. According to the man page,
414 * we should not actually delete the context until it's unbound.
415 * Note that we set gc->xid = None above. In MakeContextCurrent()
416 * we check for that and delete the context there.
419 glx_send_destroy_context(dpy
, gc
->xid
);
426 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_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
597 const Bool is_direct
= reply
->is_direct
? True
: False
;
602 /* Send the glXIsDirect request */
604 GetReq(GLXIsDirect
, req
);
605 req
->reqType
= opcode
;
606 req
->glxCode
= X_GLXIsDirect
;
607 req
->context
= contextID
;
608 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
612 return reply
.isDirect
;
618 * Shouldn't this function \b always return \c GL_FALSE when
619 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
620 * the GLX protocol here at all?
623 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
625 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
630 else if (gc
->isDirect
) {
633 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
636 return __glXIsDirect(dpy
, gc
->xid
);
641 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
643 #ifdef GLX_USE_APPLEGL
644 int screen
= vis
->screen
;
645 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
646 const struct glx_config
*config
;
648 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
650 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
655 xGLXCreateGLXPixmapReq
*req
;
656 struct glx_drawable
*glxDraw
;
660 opcode
= __glXSetupForCommand(dpy
);
665 glxDraw
= Xmalloc(sizeof(*glxDraw
));
669 /* Send the glXCreateGLXPixmap request */
671 GetReq(GLXCreateGLXPixmap
, req
);
672 req
->reqType
= opcode
;
673 req
->glxCode
= X_GLXCreateGLXPixmap
;
674 req
->screen
= vis
->screen
;
675 req
->visual
= vis
->visualid
;
676 req
->pixmap
= pixmap
;
677 req
->glxpixmap
= xid
= XAllocID(dpy
);
681 if (InitGLXDrawable(dpy
, glxDraw
, pixmap
, req
->glxpixmap
)) {
686 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
688 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
689 * is actually bound to a context... */
691 struct glx_display
*const priv
= __glXInitialize(dpy
);
692 __GLXDRIdrawable
*pdraw
;
693 struct glx_screen
*psc
;
694 struct glx_config
*config
;
696 psc
= priv
->screens
[vis
->screen
];
697 if (psc
->driScreen
== NULL
)
700 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
701 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, xid
, config
);
703 fprintf(stderr
, "failed to create pixmap\n");
708 if (__glxHashInsert(priv
->drawHash
, xid
, pdraw
)) {
709 (*pdraw
->destroyDrawable
) (pdraw
);
716 xGLXDestroyGLXPixmapReq
*dreq
;
718 GetReq(GLXDestroyGLXPixmap
, dreq
);
719 dreq
->reqType
= opcode
;
720 dreq
->glxCode
= X_GLXDestroyGLXPixmap
;
721 dreq
->glxpixmap
= xid
;
732 ** Destroy the named pixmap
735 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
737 #ifdef GLX_USE_APPLEGL
738 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
739 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
741 xGLXDestroyGLXPixmapReq
*req
;
744 opcode
= __glXSetupForCommand(dpy
);
749 /* Send the glXDestroyGLXPixmap request */
751 GetReq(GLXDestroyGLXPixmap
, req
);
752 req
->reqType
= opcode
;
753 req
->glxCode
= X_GLXDestroyGLXPixmap
;
754 req
->glxpixmap
= glxpixmap
;
758 DestroyGLXDrawable(dpy
, glxpixmap
);
760 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
762 struct glx_display
*const priv
= __glXInitialize(dpy
);
763 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
766 (*pdraw
->destroyDrawable
) (pdraw
);
767 __glxHashDelete(priv
->drawHash
, glxpixmap
);
771 #endif /* GLX_USE_APPLEGL */
775 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
777 #ifdef GLX_USE_APPLEGL
778 struct glx_context
* gc
= __glXGetCurrentContext();
779 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
780 apple_glx_swap_buffers(gc
->driContext
);
782 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
785 struct glx_context
*gc
;
791 xGLXSwapBuffersReq
*req
;
794 gc
= __glXGetCurrentContext();
796 #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);
809 opcode
= __glXSetupForCommand(dpy
);
815 ** The calling thread may or may not have a current context. If it
816 ** does, send the context tag so the server can do a flush.
818 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
819 ((drawable
== gc
->currentDrawable
)
820 || (drawable
== gc
->currentReadable
))) {
821 tag
= gc
->currentContextTag
;
828 c
= XGetXCBConnection(dpy
);
829 xcb_glx_swap_buffers(c
, tag
, drawable
);
832 /* Send the glXSwapBuffers request */
834 GetReq(GLXSwapBuffers
, req
);
835 req
->reqType
= opcode
;
836 req
->glxCode
= X_GLXSwapBuffers
;
837 req
->drawable
= drawable
;
838 req
->contextTag
= tag
;
843 #endif /* GLX_USE_APPLEGL */
848 ** Return configuration information for the given display, screen and
849 ** visual combination.
852 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
855 struct glx_display
*priv
;
856 struct glx_screen
*psc
;
857 struct glx_config
*config
;
860 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
861 if (status
== Success
) {
862 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
864 /* Lookup attribute after first finding a match on the visual */
865 if (config
!= NULL
) {
866 return glx_config_get(config
, attribute
, value_return
);
869 status
= GLX_BAD_VISUAL
;
873 ** If we can't find the config for this visual, this visual is not
874 ** supported by the OpenGL implementation on the server.
876 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
877 *value_return
= GL_FALSE
;
884 /************************************************************************/
887 init_fbconfig_for_chooser(struct glx_config
* config
,
888 GLboolean fbconfig_style_tags
)
890 memset(config
, 0, sizeof(struct glx_config
));
891 config
->visualID
= (XID
) GLX_DONT_CARE
;
892 config
->visualType
= GLX_DONT_CARE
;
894 /* glXChooseFBConfig specifies different defaults for these two than
897 if (fbconfig_style_tags
) {
898 config
->rgbMode
= GL_TRUE
;
899 config
->doubleBufferMode
= GLX_DONT_CARE
;
902 config
->visualRating
= GLX_DONT_CARE
;
903 config
->transparentPixel
= GLX_NONE
;
904 config
->transparentRed
= GLX_DONT_CARE
;
905 config
->transparentGreen
= GLX_DONT_CARE
;
906 config
->transparentBlue
= GLX_DONT_CARE
;
907 config
->transparentAlpha
= GLX_DONT_CARE
;
908 config
->transparentIndex
= GLX_DONT_CARE
;
910 config
->drawableType
= GLX_WINDOW_BIT
;
912 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
913 config
->xRenderable
= GLX_DONT_CARE
;
914 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
916 config
->swapMethod
= GLX_DONT_CARE
;
919 #define MATCH_DONT_CARE( param ) \
921 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
922 && (a-> param != b-> param) ) { \
927 #define MATCH_MINIMUM( param ) \
929 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
930 && (a-> param > b-> param) ) { \
935 #define MATCH_EXACT( param ) \
937 if ( a-> param != b-> param) { \
942 /* Test that all bits from a are contained in b */
943 #define MATCH_MASK(param) \
945 if ((a->param & ~b->param) != 0) \
950 * Determine if two GLXFBConfigs are compatible.
952 * \param a Application specified config to test.
953 * \param b Server specified config to test against \c a.
956 fbconfigs_compatible(const struct glx_config
* const a
,
957 const struct glx_config
* const b
)
959 MATCH_DONT_CARE(doubleBufferMode
);
960 MATCH_DONT_CARE(visualType
);
961 MATCH_DONT_CARE(visualRating
);
962 MATCH_DONT_CARE(xRenderable
);
963 MATCH_DONT_CARE(fbconfigID
);
964 MATCH_DONT_CARE(swapMethod
);
966 MATCH_MINIMUM(rgbBits
);
967 MATCH_MINIMUM(numAuxBuffers
);
968 MATCH_MINIMUM(redBits
);
969 MATCH_MINIMUM(greenBits
);
970 MATCH_MINIMUM(blueBits
);
971 MATCH_MINIMUM(alphaBits
);
972 MATCH_MINIMUM(depthBits
);
973 MATCH_MINIMUM(stencilBits
);
974 MATCH_MINIMUM(accumRedBits
);
975 MATCH_MINIMUM(accumGreenBits
);
976 MATCH_MINIMUM(accumBlueBits
);
977 MATCH_MINIMUM(accumAlphaBits
);
978 MATCH_MINIMUM(sampleBuffers
);
979 MATCH_MINIMUM(maxPbufferWidth
);
980 MATCH_MINIMUM(maxPbufferHeight
);
981 MATCH_MINIMUM(maxPbufferPixels
);
982 MATCH_MINIMUM(samples
);
984 MATCH_DONT_CARE(stereoMode
);
987 MATCH_MASK(drawableType
);
988 MATCH_MASK(renderType
);
990 /* There is a bug in a few of the XFree86 DDX drivers. They contain
991 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
992 * Technically speaking, it is a bug in the DDX driver, but there is
993 * enough of an installed base to work around the problem here. In any
994 * case, 0 is not a valid value of the transparent type, so we'll treat 0
995 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
996 * 0 from the server to be a match to maintain backward compatibility with
997 * the (broken) drivers.
1000 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1001 if (a
->transparentPixel
== GLX_NONE
) {
1002 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1006 MATCH_EXACT(transparentPixel
);
1009 switch (a
->transparentPixel
) {
1010 case GLX_TRANSPARENT_RGB
:
1011 MATCH_DONT_CARE(transparentRed
);
1012 MATCH_DONT_CARE(transparentGreen
);
1013 MATCH_DONT_CARE(transparentBlue
);
1014 MATCH_DONT_CARE(transparentAlpha
);
1017 case GLX_TRANSPARENT_INDEX
:
1018 MATCH_DONT_CARE(transparentIndex
);
1030 /* There's some trickly language in the GLX spec about how this is supposed
1031 * to work. Basically, if a given component size is either not specified
1032 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1033 * Well, that's really hard to do with the code as-is. This behavior is
1034 * closer to correct, but still not technically right.
1036 #define PREFER_LARGER_OR_ZERO(comp) \
1038 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1039 if ( ((*a)-> comp) == 0 ) { \
1042 else if ( ((*b)-> comp) == 0 ) { \
1046 return ((*b)-> comp) - ((*a)-> comp) ; \
1051 #define PREFER_LARGER(comp) \
1053 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1054 return ((*b)-> comp) - ((*a)-> comp) ; \
1058 #define PREFER_SMALLER(comp) \
1060 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1061 return ((*a)-> comp) - ((*b)-> comp) ; \
1066 * Compare two GLXFBConfigs. This function is intended to be used as the
1067 * compare function passed in to qsort.
1069 * \returns If \c a is a "better" config, according to the specification of
1070 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1071 * better, then a number greater than zero is return. If both are
1072 * equal, zero is returned.
1073 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1076 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1078 /* The order of these comparisons must NOT change. It is defined by
1079 * the GLX 1.3 spec and ARB_multisample.
1082 PREFER_SMALLER(visualSelectGroup
);
1084 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1085 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1086 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1088 PREFER_SMALLER(visualRating
);
1090 /* This isn't quite right. It is supposed to compare the sum of the
1091 * components the user specifically set minimums for.
1093 PREFER_LARGER_OR_ZERO(redBits
);
1094 PREFER_LARGER_OR_ZERO(greenBits
);
1095 PREFER_LARGER_OR_ZERO(blueBits
);
1096 PREFER_LARGER_OR_ZERO(alphaBits
);
1098 PREFER_SMALLER(rgbBits
);
1100 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1101 /* Prefer single-buffer.
1103 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1106 PREFER_SMALLER(numAuxBuffers
);
1108 PREFER_LARGER_OR_ZERO(depthBits
);
1109 PREFER_SMALLER(stencilBits
);
1111 /* This isn't quite right. It is supposed to compare the sum of the
1112 * components the user specifically set minimums for.
1114 PREFER_LARGER_OR_ZERO(accumRedBits
);
1115 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1116 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1117 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1119 PREFER_SMALLER(visualType
);
1121 /* None of the multisample specs say where this comparison should happen,
1122 * so I put it near the end.
1124 PREFER_SMALLER(sampleBuffers
);
1125 PREFER_SMALLER(samples
);
1127 /* None of the pbuffer or fbconfig specs say that this comparison needs
1128 * to happen at all, but it seems like it should.
1130 PREFER_LARGER(maxPbufferWidth
);
1131 PREFER_LARGER(maxPbufferHeight
);
1132 PREFER_LARGER(maxPbufferPixels
);
1139 * Selects and sorts a subset of the supplied configs based on the attributes.
1140 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1141 * and \c glXChooseFBConfigSGIX.
1143 * \param configs Array of pointers to possible configs. The elements of
1144 * this array that do not meet the criteria will be set to
1145 * NULL. The remaining elements will be sorted according to
1146 * the various visual / FBConfig selection rules.
1147 * \param num_configs Number of elements in the \c configs array.
1148 * \param attribList Attributes used select from \c configs. This array is
1149 * terminated by a \c None tag. The array can either take
1150 * the form expected by \c glXChooseVisual (where boolean
1151 * tags do not have a value) or by \c glXChooseFBConfig
1152 * (where every tag has a value).
1153 * \param fbconfig_style_tags Selects whether \c attribList is in
1154 * \c glXChooseVisual style or
1155 * \c glXChooseFBConfig style.
1156 * \returns The number of valid elements left in \c configs.
1158 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1161 choose_visual(struct glx_config
** configs
, int num_configs
,
1162 const int *attribList
, GLboolean fbconfig_style_tags
)
1164 struct glx_config test_config
;
1168 /* This is a fairly direct implementation of the selection method
1169 * described by GLX_SGIX_fbconfig. Start by culling out all the
1170 * configs that are not compatible with the selected parameter
1174 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1175 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1176 (const INT32
*) attribList
,
1177 GL_TRUE
, fbconfig_style_tags
);
1180 for (i
= 0; i
< num_configs
; i
++) {
1181 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1182 configs
[base
] = configs
[i
];
1191 if (base
< num_configs
) {
1192 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1195 /* After the incompatible configs are removed, the resulting
1196 * list is sorted according to the rules set out in the various
1200 qsort(configs
, base
, sizeof(struct glx_config
*),
1201 (int (*)(const void *, const void *)) fbconfig_compare
);
1209 ** Return the visual that best matches the template. Return None if no
1210 ** visual matches the template.
1212 _X_EXPORT XVisualInfo
*
1213 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1215 XVisualInfo
*visualList
= NULL
;
1216 struct glx_display
*priv
;
1217 struct glx_screen
*psc
;
1218 struct glx_config test_config
;
1219 struct glx_config
*config
;
1220 struct glx_config
*best_config
= NULL
;
1223 ** Get a list of all visuals, return if list is empty
1225 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1231 ** Build a template from the defaults and the attribute list
1232 ** Free visual list and return if an unexpected token is encountered
1234 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1235 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1236 (const INT32
*) attribList
,
1240 ** Eliminate visuals that don't meet minimum requirements
1241 ** Compute a score for those that do
1242 ** Remember which visual, if any, got the highest score
1243 ** If no visual is acceptable, return None
1244 ** Otherwise, create an XVisualInfo list with just the selected X visual
1247 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1248 if (fbconfigs_compatible(&test_config
, config
)
1249 && ((best_config
== NULL
) ||
1250 (fbconfig_compare (&config
, &best_config
) < 0))) {
1251 XVisualInfo visualTemplate
;
1252 XVisualInfo
*newList
;
1255 visualTemplate
.screen
= screen
;
1256 visualTemplate
.visualid
= config
->visualID
;
1257 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1258 &visualTemplate
, &i
);
1262 visualList
= newList
;
1263 best_config
= config
;
1268 #ifdef GLX_USE_APPLEGL
1269 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1270 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1278 _X_EXPORT
const char *
1279 glXQueryExtensionsString(Display
* dpy
, int screen
)
1281 struct glx_screen
*psc
;
1282 struct glx_display
*priv
;
1284 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1288 if (!psc
->effectiveGLXexts
) {
1289 if (!psc
->serverGLXexts
) {
1290 psc
->serverGLXexts
=
1291 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1295 __glXCalculateUsableExtensions(psc
,
1296 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1297 (psc
->driScreen
!= NULL
),
1301 priv
->minorVersion
);
1304 return psc
->effectiveGLXexts
;
1307 _X_EXPORT
const char *
1308 glXGetClientString(Display
* dpy
, int name
)
1314 return (__glXGLXClientVendorName
);
1316 return (__glXGLXClientVersion
);
1317 case GLX_EXTENSIONS
:
1318 return (__glXGetClientExtensions());
1324 _X_EXPORT
const char *
1325 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1327 struct glx_screen
*psc
;
1328 struct glx_display
*priv
;
1332 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1338 str
= &priv
->serverGLXvendor
;
1341 str
= &priv
->serverGLXversion
;
1343 case GLX_EXTENSIONS
:
1344 str
= &psc
->serverGLXexts
;
1351 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1358 __glXClientInfo(Display
* dpy
, int opcode
)
1360 char *ext_str
= __glXGetClientGLExtensionString();
1361 int size
= strlen(ext_str
) + 1;
1364 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1365 xcb_glx_client_info(c
,
1366 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1368 xGLXClientInfoReq
*req
;
1370 /* Send the glXClientInfo request */
1372 GetReq(GLXClientInfo
, req
);
1373 req
->reqType
= opcode
;
1374 req
->glxCode
= X_GLXClientInfo
;
1375 req
->major
= GLX_MAJOR_VERSION
;
1376 req
->minor
= GLX_MINOR_VERSION
;
1378 req
->length
+= (size
+ 3) >> 2;
1379 req
->numbytes
= size
;
1380 Data(dpy
, ext_str
, size
);
1384 #endif /* USE_XCB */
1391 ** EXT_import_context
1395 glXGetCurrentDisplay(void)
1397 struct glx_context
*gc
= __glXGetCurrentContext();
1400 return gc
->currentDpy
;
1404 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1405 glXGetCurrentDisplay
)
1407 #ifndef GLX_USE_APPLEGL
1408 _X_EXPORT GLXContext
1409 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1411 struct glx_display
*priv
= __glXInitialize(dpy
);
1412 struct glx_screen
*psc
;
1413 xGLXQueryContextReply reply
;
1415 struct glx_context
*ctx
;
1416 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1419 struct glx_config
*mode
;
1421 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1424 opcode
= __glXSetupForCommand(dpy
);
1428 /* Send the glXQueryContextInfoEXT request */
1431 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1432 xGLXQueryContextReq
*req
;
1434 GetReq(GLXQueryContext
, req
);
1436 req
->reqType
= opcode
;
1437 req
->glxCode
= X_GLXQueryContext
;
1438 req
->context
= contextID
;
1441 xGLXVendorPrivateReq
*vpreq
;
1442 xGLXQueryContextInfoEXTReq
*req
;
1444 GetReqExtra(GLXVendorPrivate
,
1445 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1447 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1448 req
->reqType
= opcode
;
1449 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1450 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1451 req
->context
= contextID
;
1454 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1456 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1457 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1460 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1464 /* Look up screen first so we can look up visuals/fbconfigs later */
1466 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1467 if (pProp
[0] == GLX_SCREEN
)
1468 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1477 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1479 case GLX_SHARE_CONTEXT_EXT
:
1482 case GLX_VISUAL_ID_EXT
:
1483 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1485 case GLX_FBCONFIG_ID
:
1486 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1488 case GLX_RENDER_TYPE
:
1489 renderType
= pProp
[1];
1496 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1500 ctx
->xid
= contextID
;
1501 ctx
->imported
= GL_TRUE
;
1502 ctx
->share_xid
= share
;
1504 return (GLXContext
) ctx
;
1510 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1512 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1514 switch (attribute
) {
1515 case GLX_SHARE_CONTEXT_EXT
:
1516 *value
= ctx
->share_xid
;
1518 case GLX_VISUAL_ID_EXT
:
1519 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1522 *value
= ctx
->screen
;
1524 case GLX_FBCONFIG_ID
:
1525 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1527 case GLX_RENDER_TYPE
:
1528 *value
= ctx
->renderType
;
1531 return GLX_BAD_ATTRIBUTE
;
1537 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1538 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1539 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1541 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1543 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1549 GLX_ALIAS_VOID(glXFreeContextEXT
, (Display
*dpy
, GLXContext ctx
), (dpy
, ctx
),
1552 _X_EXPORT GLXFBConfig
*
1553 glXChooseFBConfig(Display
* dpy
, int screen
,
1554 const int *attribList
, int *nitems
)
1556 struct glx_config
**config_list
;
1560 config_list
= (struct glx_config
**)
1561 glXGetFBConfigs(dpy
, screen
, &list_size
);
1563 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1564 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1565 if (list_size
== 0) {
1571 *nitems
= list_size
;
1572 return (GLXFBConfig
*) config_list
;
1576 _X_EXPORT GLXContext
1577 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1578 int renderType
, GLXContext shareList
, Bool allowDirect
)
1580 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1582 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1583 allowDirect
, X_GLXCreateNewContext
, renderType
,
1588 _X_EXPORT GLXDrawable
1589 glXGetCurrentReadDrawable(void)
1591 struct glx_context
*gc
= __glXGetCurrentContext();
1593 return gc
->currentReadable
;
1597 _X_EXPORT GLXFBConfig
*
1598 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1600 struct glx_display
*priv
= __glXInitialize(dpy
);
1601 struct glx_config
**config_list
= NULL
;
1602 struct glx_config
*config
;
1603 unsigned num_configs
= 0;
1607 if (priv
&& (priv
->screens
!= NULL
)
1608 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1609 && (priv
->screens
[screen
]->configs
!= NULL
)
1610 && (priv
->screens
[screen
]->configs
->fbconfigID
1611 != (int) GLX_DONT_CARE
)) {
1613 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1614 config
= config
->next
) {
1615 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1620 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1621 if (config_list
!= NULL
) {
1622 *nelements
= num_configs
;
1624 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1625 config
= config
->next
) {
1626 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1627 config_list
[i
] = config
;
1634 return (GLXFBConfig
*) config_list
;
1639 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1640 int attribute
, int *value
)
1642 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1645 return GLXBadFBConfig
;
1647 return glx_config_get(config
, attribute
, value
);
1651 _X_EXPORT XVisualInfo
*
1652 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1654 XVisualInfo visualTemplate
;
1655 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1659 ** Get a list of all visuals, return if list is empty
1661 visualTemplate
.visualid
= config
->visualID
;
1662 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1665 #ifndef GLX_USE_APPLEGL
1667 ** GLX_SGI_swap_control
1670 __glXSwapIntervalSGI(int interval
)
1672 xGLXVendorPrivateReq
*req
;
1673 struct glx_context
*gc
= __glXGetCurrentContext();
1674 struct glx_screen
*psc
;
1676 CARD32
*interval_ptr
;
1680 return GLX_BAD_CONTEXT
;
1683 if (interval
<= 0) {
1684 return GLX_BAD_VALUE
;
1687 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1689 #ifdef GLX_DIRECT_RENDERING
1690 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1691 __GLXDRIdrawable
*pdraw
=
1692 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1693 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1698 dpy
= gc
->currentDpy
;
1699 opcode
= __glXSetupForCommand(dpy
);
1704 /* Send the glXSwapIntervalSGI request */
1706 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1707 req
->reqType
= opcode
;
1708 req
->glxCode
= X_GLXVendorPrivate
;
1709 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1710 req
->contextTag
= gc
->currentContextTag
;
1712 interval_ptr
= (CARD32
*) (req
+ 1);
1713 *interval_ptr
= interval
;
1724 ** GLX_MESA_swap_control
1727 __glXSwapIntervalMESA(unsigned int interval
)
1729 #ifdef GLX_DIRECT_RENDERING
1730 struct glx_context
*gc
= __glXGetCurrentContext();
1732 if (gc
!= NULL
&& gc
->isDirect
) {
1733 struct glx_screen
*psc
;
1735 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1736 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1737 __GLXDRIdrawable
*pdraw
=
1738 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1739 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1744 return GLX_BAD_CONTEXT
;
1749 __glXGetSwapIntervalMESA(void)
1751 #ifdef GLX_DIRECT_RENDERING
1752 struct glx_context
*gc
= __glXGetCurrentContext();
1754 if (gc
!= NULL
&& gc
->isDirect
) {
1755 struct glx_screen
*psc
;
1757 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1758 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
1759 __GLXDRIdrawable
*pdraw
=
1760 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1761 return psc
->driScreen
->getSwapInterval(pdraw
);
1771 ** GLX_SGI_video_sync
1774 __glXGetVideoSyncSGI(unsigned int *count
)
1776 int64_t ust
, msc
, sbc
;
1778 struct glx_context
*gc
= __glXGetCurrentContext();
1779 struct glx_screen
*psc
;
1780 #ifdef GLX_DIRECT_RENDERING
1781 __GLXDRIdrawable
*pdraw
;
1785 return GLX_BAD_CONTEXT
;
1787 #ifdef GLX_DIRECT_RENDERING
1789 return GLX_BAD_CONTEXT
;
1792 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
1793 #ifdef GLX_DIRECT_RENDERING
1794 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1797 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1798 * FIXME: there should be a GLX encoding for this call. I can find no
1799 * FIXME: documentation for the GLX encoding.
1801 #ifdef GLX_DIRECT_RENDERING
1802 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
1803 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
1804 *count
= (unsigned) msc
;
1805 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1809 return GLX_BAD_CONTEXT
;
1813 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
1815 struct glx_context
*gc
= __glXGetCurrentContext();
1816 struct glx_screen
*psc
;
1817 #ifdef GLX_DIRECT_RENDERING
1818 __GLXDRIdrawable
*pdraw
;
1820 int64_t ust
, msc
, sbc
;
1823 if (divisor
<= 0 || remainder
< 0)
1824 return GLX_BAD_VALUE
;
1827 return GLX_BAD_CONTEXT
;
1829 #ifdef GLX_DIRECT_RENDERING
1831 return GLX_BAD_CONTEXT
;
1834 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1835 #ifdef GLX_DIRECT_RENDERING
1836 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1839 #ifdef GLX_DIRECT_RENDERING
1840 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
1841 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
1843 *count
= (unsigned) msc
;
1844 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
1848 return GLX_BAD_CONTEXT
;
1851 #endif /* GLX_USE_APPLEGL */
1854 ** GLX_SGIX_fbconfig
1855 ** Many of these functions are aliased to GLX 1.3 entry points in the
1856 ** GLX_functions table.
1860 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
1861 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
1862 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
1864 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
1865 (Display
* dpy
, int screen
, int *attrib_list
,
1866 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
1869 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
1870 (Display
* dpy
, GLXFBConfigSGIX config
),
1871 (dpy
, config
), glXGetVisualFromFBConfig
)
1874 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
1875 GLXFBConfigSGIX fbconfig
,
1878 #ifndef GLX_USE_APPLEGL
1879 xGLXVendorPrivateWithReplyReq
*vpreq
;
1880 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
1881 GLXPixmap xid
= None
;
1883 struct glx_screen
*psc
;
1885 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1888 if ((dpy
== NULL
) || (config
== NULL
)) {
1891 #ifdef GLX_USE_APPLEGL
1892 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
1897 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1899 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1900 opcode
= __glXSetupForCommand(dpy
);
1905 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
1907 GetReqExtra(GLXVendorPrivateWithReply
,
1908 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
1909 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
1910 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
1911 req
->reqType
= opcode
;
1912 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1913 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
1914 req
->screen
= config
->screen
;
1915 req
->fbconfig
= config
->fbconfigID
;
1916 req
->pixmap
= pixmap
;
1917 req
->glxpixmap
= xid
= XAllocID(dpy
);
1926 _X_EXPORT GLXContext
1927 glXCreateContextWithConfigSGIX(Display
* dpy
,
1928 GLXFBConfigSGIX fbconfig
, int renderType
,
1929 GLXContext shareList
, Bool allowDirect
)
1931 GLXContext gc
= NULL
;
1932 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1933 struct glx_screen
*psc
;
1936 if ((dpy
== NULL
) || (config
== NULL
)) {
1940 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
1942 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
1943 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1945 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
1953 _X_EXPORT GLXFBConfigSGIX
1954 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
1956 struct glx_display
*priv
;
1957 struct glx_screen
*psc
= NULL
;
1959 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) == Success
)
1960 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
1961 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
1962 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
1969 #ifndef GLX_USE_APPLEGL
1971 ** GLX_SGIX_swap_group
1974 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
1984 ** GLX_SGIX_swap_barrier
1987 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
1995 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2005 ** GLX_OML_sync_control
2008 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2009 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2011 struct glx_display
* const priv
= __glXInitialize(dpy
);
2013 #ifdef GLX_DIRECT_RENDERING
2014 __GLXDRIdrawable
*pdraw
;
2016 struct glx_screen
*psc
;
2021 #ifdef GLX_DIRECT_RENDERING
2022 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2023 psc
= pdraw
? pdraw
->psc
: NULL
;
2024 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2025 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2033 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2035 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
2036 int32_t * numerator
, int32_t * denominator
)
2039 struct glx_screen
*psc
;
2040 XF86VidModeModeLine mode_line
;
2045 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2046 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2047 unsigned n
= dot_clock
* 1000;
2048 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2050 # define V_INTERLACE 0x010
2051 # define V_DBLSCAN 0x020
2053 if (mode_line
.flags
& V_INTERLACE
)
2055 else if (mode_line
.flags
& V_DBLSCAN
)
2058 /* The OML_sync_control spec requires that if the refresh rate is a
2059 * whole number, that the returned numerator be equal to the refresh
2060 * rate and the denominator be 1.
2068 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2070 /* This is a poor man's way to reduce a fraction. It's far from
2071 * perfect, but it will work well enough for this situation.
2074 for (i
= 0; f
[i
] != 0; i
++) {
2075 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2095 * Determine the refresh rate of the specified drawable and display.
2097 * \param dpy Display whose refresh rate is to be determined.
2098 * \param drawable Drawable whose refresh rate is to be determined.
2099 * \param numerator Numerator of the refresh rate.
2100 * \param demoninator Denominator of the refresh rate.
2101 * \return If the refresh rate for the specified display and drawable could
2102 * be calculated, True is returned. Otherwise False is returned.
2104 * \note This function is implemented entirely client-side. A lot of other
2105 * functionality is required to export GLX_OML_sync_control, so on
2106 * XFree86 this function can be called for direct-rendering contexts
2107 * when GLX_OML_sync_control appears in the client extension string.
2111 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2112 int32_t * numerator
, int32_t * denominator
)
2114 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2115 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2120 return __glxGetMscRate(draw
, numerator
, denominator
);
2132 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2133 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2135 struct glx_context
*gc
= __glXGetCurrentContext();
2136 #ifdef GLX_DIRECT_RENDERING
2137 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2138 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2141 if (!gc
) /* no GLX for this */
2144 #ifdef GLX_DIRECT_RENDERING
2145 if (!pdraw
|| !gc
->isDirect
)
2149 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2150 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2151 * of -1 if the function failed because of errors detected in the input
2154 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2156 if (divisor
> 0 && remainder
>= divisor
)
2159 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2162 #ifdef GLX_DIRECT_RENDERING
2163 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2164 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2173 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2174 int64_t target_msc
, int64_t divisor
,
2175 int64_t remainder
, int64_t * ust
,
2176 int64_t * msc
, int64_t * sbc
)
2178 #ifdef GLX_DIRECT_RENDERING
2179 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2180 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2185 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2186 * error", but the return type in the spec is Bool.
2188 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2190 if (divisor
> 0 && remainder
>= divisor
)
2193 #ifdef GLX_DIRECT_RENDERING
2194 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2195 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2206 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2207 int64_t target_sbc
, int64_t * ust
,
2208 int64_t * msc
, int64_t * sbc
)
2210 #ifdef GLX_DIRECT_RENDERING
2211 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2212 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2216 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2217 * error", but the return type in the spec is Bool.
2222 #ifdef GLX_DIRECT_RENDERING
2223 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2224 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2236 * Mesa extension stubs. These will help reduce portability problems.
2241 * Release all buffers associated with the specified GLX drawable.
2244 * This function was intended for stand-alone Mesa. The issue there is that
2245 * the library doesn't get any notification when a window is closed. In
2246 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2247 * supported, there are 3 different functions to destroy a drawable. It
2248 * should be possible to create GLX protocol (or have it determine which
2249 * protocol to use based on the type of the drawable) to have one function
2250 * do the work of 3. For the direct-rendering case, this function could
2251 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2252 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2253 * would need to be used. This really should be done as part of the new DRI
2256 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2257 * __driGarbageCollectDrawables
2258 * glXDestroyGLXPixmap
2259 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2260 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2263 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2272 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2273 Pixmap pixmap
, Colormap cmap
)
2286 * GLX_MESA_copy_sub_buffer
2288 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2290 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2291 int x
, int y
, int width
, int height
)
2293 xGLXVendorPrivateReq
*req
;
2294 struct glx_context
*gc
;
2296 CARD32
*drawable_ptr
;
2297 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2300 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2301 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2302 if (pdraw
!= NULL
) {
2303 struct glx_screen
*psc
= pdraw
->psc
;
2304 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2306 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2313 opcode
= __glXSetupForCommand(dpy
);
2318 ** The calling thread may or may not have a current context. If it
2319 ** does, send the context tag so the server can do a flush.
2321 gc
= __glXGetCurrentContext();
2322 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2323 ((drawable
== gc
->currentDrawable
) ||
2324 (drawable
== gc
->currentReadable
))) {
2325 tag
= gc
->currentContextTag
;
2332 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2333 req
->reqType
= opcode
;
2334 req
->glxCode
= X_GLXVendorPrivate
;
2335 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2336 req
->contextTag
= tag
;
2338 drawable_ptr
= (CARD32
*) (req
+ 1);
2339 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2340 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2341 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2342 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2344 *drawable_ptr
= drawable
;
2356 __glXBindTexImageEXT(Display
* dpy
,
2357 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2359 struct glx_context
*gc
= __glXGetCurrentContext();
2361 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2364 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2368 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2370 struct glx_context
*gc
= __glXGetCurrentContext();
2372 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2375 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2380 #endif /* GLX_USE_APPLEGL */
2383 * \c strdup is actually not a standard ANSI C or POSIX routine.
2384 * Irix will not define it if ANSI mode is in effect.
2389 __glXstrdup(const char *str
)
2392 copy
= (char *) Xmalloc(strlen(str
) + 1);
2400 ** glXGetProcAddress support
2403 struct name_address_pair
2409 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2410 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2412 static const struct name_address_pair GLX_functions
[] = {
2413 /*** GLX_VERSION_1_0 ***/
2414 GLX_FUNCTION(glXChooseVisual
),
2415 GLX_FUNCTION(glXCopyContext
),
2416 GLX_FUNCTION(glXCreateContext
),
2417 GLX_FUNCTION(glXCreateGLXPixmap
),
2418 GLX_FUNCTION(glXDestroyContext
),
2419 GLX_FUNCTION(glXDestroyGLXPixmap
),
2420 GLX_FUNCTION(glXGetConfig
),
2421 GLX_FUNCTION(glXGetCurrentContext
),
2422 GLX_FUNCTION(glXGetCurrentDrawable
),
2423 GLX_FUNCTION(glXIsDirect
),
2424 GLX_FUNCTION(glXMakeCurrent
),
2425 GLX_FUNCTION(glXQueryExtension
),
2426 GLX_FUNCTION(glXQueryVersion
),
2427 GLX_FUNCTION(glXSwapBuffers
),
2428 GLX_FUNCTION(glXUseXFont
),
2429 GLX_FUNCTION(glXWaitGL
),
2430 GLX_FUNCTION(glXWaitX
),
2432 /*** GLX_VERSION_1_1 ***/
2433 GLX_FUNCTION(glXGetClientString
),
2434 GLX_FUNCTION(glXQueryExtensionsString
),
2435 GLX_FUNCTION(glXQueryServerString
),
2437 /*** GLX_VERSION_1_2 ***/
2438 GLX_FUNCTION(glXGetCurrentDisplay
),
2440 /*** GLX_VERSION_1_3 ***/
2441 GLX_FUNCTION(glXChooseFBConfig
),
2442 GLX_FUNCTION(glXCreateNewContext
),
2443 GLX_FUNCTION(glXCreatePbuffer
),
2444 GLX_FUNCTION(glXCreatePixmap
),
2445 GLX_FUNCTION(glXCreateWindow
),
2446 GLX_FUNCTION(glXDestroyPbuffer
),
2447 GLX_FUNCTION(glXDestroyPixmap
),
2448 GLX_FUNCTION(glXDestroyWindow
),
2449 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2450 GLX_FUNCTION(glXGetFBConfigAttrib
),
2451 GLX_FUNCTION(glXGetFBConfigs
),
2452 GLX_FUNCTION(glXGetSelectedEvent
),
2453 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2454 GLX_FUNCTION(glXMakeContextCurrent
),
2455 GLX_FUNCTION(glXQueryContext
),
2456 GLX_FUNCTION(glXQueryDrawable
),
2457 GLX_FUNCTION(glXSelectEvent
),
2459 #ifndef GLX_USE_APPLEGL
2460 /*** GLX_SGI_swap_control ***/
2461 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2463 /*** GLX_SGI_video_sync ***/
2464 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2465 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2467 /*** GLX_SGI_make_current_read ***/
2468 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2469 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2471 /*** GLX_EXT_import_context ***/
2472 GLX_FUNCTION(glXFreeContextEXT
),
2473 GLX_FUNCTION(glXGetContextIDEXT
),
2474 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2475 GLX_FUNCTION(glXImportContextEXT
),
2476 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2479 /*** GLX_SGIX_fbconfig ***/
2480 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2481 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2482 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2483 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2484 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2485 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2487 #ifndef GLX_USE_APPLEGL
2488 /*** GLX_SGIX_pbuffer ***/
2489 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2490 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2491 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2492 GLX_FUNCTION(glXSelectEventSGIX
),
2493 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2495 /*** GLX_SGIX_swap_group ***/
2496 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2498 /*** GLX_SGIX_swap_barrier ***/
2499 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2500 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2502 /*** GLX_MESA_copy_sub_buffer ***/
2503 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2505 /*** GLX_MESA_pixmap_colormap ***/
2506 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2508 /*** GLX_MESA_release_buffers ***/
2509 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2511 /*** GLX_MESA_swap_control ***/
2512 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2513 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2516 /*** GLX_ARB_get_proc_address ***/
2517 GLX_FUNCTION(glXGetProcAddressARB
),
2520 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2522 #ifndef GLX_USE_APPLEGL
2523 /*** GLX_OML_sync_control ***/
2524 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2525 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2526 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2527 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2528 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2530 /*** GLX_EXT_texture_from_pixmap ***/
2531 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2532 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2535 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2536 /*** DRI configuration ***/
2537 GLX_FUNCTION(glXGetScreenDriver
),
2538 GLX_FUNCTION(glXGetDriverConfig
),
2541 {NULL
, NULL
} /* end of list */
2544 static const GLvoid
*
2545 get_glx_proc_address(const char *funcName
)
2549 /* try static functions */
2550 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2551 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2552 return GLX_functions
[i
].Address
;
2559 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2560 * \c glXGetProcAddress.
2562 * \param procName Name of a GL or GLX function.
2563 * \returns A pointer to the named function
2565 * \sa glXGetProcAddress
2567 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2569 typedef void (*gl_function
) (void);
2573 /* Search the table of GLX and internal functions first. If that
2574 * fails and the supplied name could be a valid core GL name, try
2575 * searching the core GL function table. This check is done to prevent
2576 * DRI based drivers from searching the core GL function table for
2577 * internal API functions.
2579 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2580 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2581 && (procName
[2] != 'X')) {
2582 #ifdef GLX_SHARED_GLAPI
2583 f
= (gl_function
) __indirect_get_proc_address((const char *) procName
);
2586 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2588 struct glx_context
*gc
= __glXGetCurrentContext();
2590 if (gc
!= NULL
&& gc
->vtable
->get_proc_address
!= NULL
)
2591 f
= gc
->vtable
->get_proc_address((const char *) procName
);
2598 * Get the address of a named GL function. This is the GLX 1.4 name for
2599 * \c glXGetProcAddressARB.
2601 * \param procName Name of a GL or GLX function.
2602 * \returns A pointer to the named function
2604 * \sa glXGetProcAddressARB
2606 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2607 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2608 __attribute__ ((alias("glXGetProcAddressARB")));
2611 return glXGetProcAddressARB(procName
);
2613 #endif /* __GNUC__ */
2616 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2618 * Get the unadjusted system time (UST). Currently, the UST is measured in
2619 * microseconds since Epoc. The actual resolution of the UST may vary from
2620 * system to system, and the units may vary from release to release.
2621 * Drivers should not call this function directly. They should instead use
2622 * \c glXGetProcAddress to obtain a pointer to the function.
2624 * \param ust Location to store the 64-bit UST
2625 * \returns Zero on success or a negative errno value on failure.
2627 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2629 * \since Internal API version 20030317.
2632 __glXGetUST(int64_t * ust
)
2640 if (gettimeofday(&tv
, NULL
) == 0) {
2641 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
2648 #endif /* GLX_DIRECT_RENDERING */