2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
33 * Client-side GLX interface.
36 #include "glxclient.h"
38 #include "glxextensions.h"
40 #ifdef GLX_DIRECT_RENDERING
41 #ifdef GLX_USE_APPLEGL
42 #include "apple_glx_context.h"
43 #include "apple_glx.h"
44 #include "glx_error.h"
47 #include <X11/extensions/xf86vmode.h>
54 #include <X11/Xlib-xcb.h>
59 static const char __glXGLXClientVendorName
[] = "Mesa Project and SGI";
60 static const char __glXGLXClientVersion
[] = "1.4";
61 static const struct glx_context_vtable indirect_context_vtable
;
63 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
65 static Bool windowExistsFlag
;
67 windowExistsErrorHandler(Display
* dpy
, XErrorEvent
* xerr
)
71 if (xerr
->error_code
== BadWindow
) {
72 windowExistsFlag
= GL_FALSE
;
78 * Find drawables in the local hash that have been destroyed on the
81 * \param dpy Display to destroy drawables for
82 * \param screen Screen number to destroy drawables for
85 GarbageCollectDRIDrawables(struct glx_screen
* sc
)
88 __GLXDRIdrawable
*pdraw
;
89 struct glx_display
*priv
= sc
->display
;
90 XWindowAttributes xwa
;
91 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
93 /* Set no-op error handler so Xlib doesn't bail out if the windows
94 * has alreay been destroyed on the server. */
95 XSync(priv
->dpy
, GL_FALSE
);
96 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
98 if (__glxHashFirst(priv
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
100 windowExistsFlag
= GL_TRUE
;
101 XGetWindowAttributes(priv
->dpy
, draw
, &xwa
); /* dummy request */
102 if (!windowExistsFlag
) {
103 /* Destroy the local drawable data, if the drawable no
104 longer exists in the Xserver */
105 (*pdraw
->destroyDrawable
) (pdraw
);
106 __glxHashDelete(priv
->drawHash
, draw
);
108 } while (__glxHashNext(priv
->drawHash
, &draw
, (void *) &pdraw
) == 1);
111 XSync(priv
->dpy
, GL_FALSE
);
112 XSetErrorHandler(oldXErrorHandler
);
116 * Get the __DRIdrawable for the drawable associated with a GLXContext
118 * \param dpy The display associated with \c drawable.
119 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
120 * \param scrn_num If non-NULL, the drawables screen is stored there
121 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
122 * the drawable is not associated with a direct-rendering context.
124 _X_HIDDEN __GLXDRIdrawable
*
125 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
)
127 struct glx_display
*priv
= __glXInitialize(dpy
);
128 __GLXDRIdrawable
*pdraw
;
133 if (__glxHashLookup(priv
->drawHash
, drawable
, (void *) &pdraw
) == 0)
143 * Get the GLX per-screen data structure associated with a GLX context.
145 * \param dpy Display for which the GLX per-screen information is to be
147 * \param scrn Screen on \c dpy for which the GLX per-screen information is
149 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
150 * specify a valid GLX screen, or NULL otherwise.
152 * \todo Should this function validate that \c scrn is within the screen
153 * number range for \c dpy?
156 static struct glx_screen
*
157 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
159 struct glx_display
*const priv
= __glXInitialize(dpy
);
163 NULL
) ? priv
->screens
[scrn
] : NULL
;
168 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, struct glx_display
** ppriv
,
169 struct glx_screen
** ppsc
)
171 /* Initialize the extension, if needed . This has the added value
172 * of initializing/allocating the display private
176 return GLX_NO_EXTENSION
;
179 *ppriv
= __glXInitialize(dpy
);
180 if (*ppriv
== NULL
) {
181 return GLX_NO_EXTENSION
;
184 /* Check screen number to see if its valid */
185 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
186 return GLX_BAD_SCREEN
;
189 /* Check to see if the GL is supported on this screen */
190 *ppsc
= (*ppriv
)->screens
[scrn
];
191 if ((*ppsc
)->configs
== NULL
) {
192 /* No support for GL on this screen regardless of visual */
193 return GLX_BAD_VISUAL
;
201 * Determine if a \c GLXFBConfig supplied by the application is valid.
203 * \param dpy Application supplied \c Display pointer.
204 * \param config Application supplied \c GLXFBConfig.
206 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
207 * \c struct glx_config structure is returned. Otherwise, \c NULL
210 static struct glx_config
*
211 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
213 struct glx_display
*const priv
= __glXInitialize(dpy
);
214 int num_screens
= ScreenCount(dpy
);
216 struct glx_config
*config
;
219 for (i
= 0; i
< num_screens
; i
++) {
220 for (config
= priv
->screens
[i
]->configs
; config
!= NULL
;
221 config
= config
->next
) {
222 if (config
== (struct glx_config
*) fbconfig
) {
232 #ifdef GLX_USE_APPLEGL
234 static const struct glx_context_vtable applegl_context_vtable
;
236 static struct glx_context
*
237 applegl_create_context(struct glx_screen
*psc
,
238 struct glx_config
*mode
,
239 struct glx_context
*shareList
, int renderType
)
241 struct glx_context
*gc
;
245 /* TODO: Integrate this with apple_glx_create_context and make
246 * struct apple_glx_context inherit from struct glx_context. */
248 gc
= Xmalloc(sizeof *gc
);
252 memset(gc
, 0, sizeof *gc
);
253 if (!glx_context_init(&gc
->base
, &psc
->base
, mode
)) {
258 gc
->vtable
= &applegl_context_vtable
;
259 gc
->driContext
= NULL
;
260 gc
->do_destroy
= False
;
262 /* TODO: darwin: Integrate with above to do indirect */
263 if(apple_glx_create_context(&gc
->driContext
, dpy
, screen
, fbconfig
,
264 shareList
? shareList
->driContext
: NULL
,
265 &errorcode
, &x11error
)) {
266 __glXSendError(dpy
, errorcode
, 0, X_GLXCreateContext
, x11error
);
267 gc
->vtable
->destroy(gc
);
271 gc
->currentContextTag
= -1;
273 gc
->isDirect
= allowDirect
;
274 gc
->xid
= 1; /* Just something not None, so we know when to destroy
275 * it in MakeContextCurrent. */
283 * \todo It should be possible to move the allocate of \c client_state_private
284 * later in the function for direct-rendering contexts. Direct-rendering
285 * contexts don't need to track client state, so they don't need that memory
288 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
289 * function called \c __glXAllocateClientState that allocates the memory and
290 * does all the initialization (including the pixel pack / unpack).
292 static struct glx_context
*
293 indirect_create_context(struct glx_screen
*psc
,
294 struct glx_config
*mode
,
295 struct glx_context
*shareList
, int renderType
)
297 struct glx_context
*gc
;
300 __GLXattribute
*state
;
302 opcode
= __glXSetupForCommand(psc
->dpy
);
307 /* Allocate our context record */
308 gc
= Xmalloc(sizeof *gc
);
313 memset(gc
, 0, sizeof *gc
);
315 glx_context_init(gc
, psc
, mode
);
316 gc
->isDirect
= GL_FALSE
;
317 gc
->vtable
= &indirect_context_vtable
;
318 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
324 gc
->client_state_private
= state
;
325 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
326 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
329 ** Create a temporary buffer to hold GLX rendering commands. The size
330 ** of the buffer is selected so that the maximum number of GLX rendering
331 ** commands can fit in a single X packet and still have room in the X
332 ** packet for the GLXRenderReq header.
335 bufSize
= (XMaxRequestSize(psc
->dpy
) * 4) - sz_xGLXRenderReq
;
336 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
338 Xfree(gc
->client_state_private
);
342 gc
->bufSize
= bufSize
;
344 /* Fill in the new context */
345 gc
->renderMode
= GL_RENDER
;
347 state
->storePack
.alignment
= 4;
348 state
->storeUnpack
.alignment
= 4;
350 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
353 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
354 ** Other code uses the fastImageUnpack bit, but it is never set
357 gc
->fastImageUnpack
= GL_FALSE
;
358 gc
->fillImage
= __glFillImage
;
360 gc
->bufEnd
= gc
->buf
+ bufSize
;
361 gc
->isDirect
= GL_FALSE
;
364 ** Set limit register so that there will be one command per packet
369 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
371 gc
->majorOpcode
= opcode
;
374 ** Constrain the maximum drawing command size allowed to be
375 ** transfered using the X_GLXRender protocol request. First
376 ** constrain by a software limit, then constrain by the protocl
379 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
380 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
382 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
383 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
385 gc
->maxSmallRenderCommandSize
= bufSize
;
391 struct glx_screen_vtable indirect_screen_vtable
= {
392 indirect_create_context
395 _X_HIDDEN
struct glx_screen
*
396 indirect_create_screen(int screen
, struct glx_display
* priv
)
398 struct glx_screen
*psc
;
400 psc
= Xmalloc(sizeof *psc
);
404 memset(psc
, 0, sizeof *psc
);
405 glx_screen_init(psc
, screen
, priv
);
406 psc
->vtable
= &indirect_screen_vtable
;
413 glx_context_init(struct glx_context
*gc
,
414 struct glx_screen
*psc
, struct glx_config
*config
)
416 gc
->majorOpcode
= __glXSetupForCommand(psc
->display
->dpy
);
417 if (!gc
->majorOpcode
)
420 gc
->screen
= psc
->scr
;
423 gc
->isDirect
= GL_TRUE
;
424 gc
->currentContextTag
= -1;
431 * Create a new context. Exactly one of \c vis and \c fbconfig should be
434 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
435 * SGIX_fbconfig protocol be used?
436 * \param renderType For FBConfigs, what is the rendering type?
440 CreateContext(Display
* dpy
, int generic_id
,
441 struct glx_config
*config
,
442 GLXContext shareList_user
,
444 unsigned code
, int renderType
, int screen
)
446 struct glx_context
*gc
= NULL
;
447 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
448 struct glx_context
*shareList
= (struct glx_context
*) shareList_user
;
452 if (generic_id
== None
)
456 if (allowDirect
&& psc
->vtable
->create_context
)
457 gc
= psc
->vtable
->create_context(psc
, config
, shareList
, renderType
);
459 gc
= indirect_create_context(psc
, config
, shareList
, renderType
);
465 case X_GLXCreateContext
: {
466 xGLXCreateContextReq
*req
;
468 /* Send the glXCreateContext request */
469 GetReq(GLXCreateContext
, req
);
470 req
->reqType
= gc
->majorOpcode
;
471 req
->glxCode
= X_GLXCreateContext
;
472 req
->context
= gc
->xid
= XAllocID(dpy
);
473 req
->visual
= generic_id
;
474 req
->screen
= screen
;
475 req
->shareList
= shareList
? shareList
->xid
: None
;
476 req
->isDirect
= gc
->isDirect
;
480 case X_GLXCreateNewContext
: {
481 xGLXCreateNewContextReq
*req
;
483 /* Send the glXCreateNewContext request */
484 GetReq(GLXCreateNewContext
, req
);
485 req
->reqType
= gc
->majorOpcode
;
486 req
->glxCode
= X_GLXCreateNewContext
;
487 req
->context
= gc
->xid
= XAllocID(dpy
);
488 req
->fbconfig
= generic_id
;
489 req
->screen
= screen
;
490 req
->renderType
= renderType
;
491 req
->shareList
= shareList
? shareList
->xid
: None
;
492 req
->isDirect
= gc
->isDirect
;
496 case X_GLXvop_CreateContextWithConfigSGIX
: {
497 xGLXVendorPrivateWithReplyReq
*vpreq
;
498 xGLXCreateContextWithConfigSGIXReq
*req
;
500 /* Send the glXCreateNewContext request */
501 GetReqExtra(GLXVendorPrivateWithReply
,
502 sz_xGLXCreateContextWithConfigSGIXReq
-
503 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
504 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
505 req
->reqType
= gc
->majorOpcode
;
506 req
->glxCode
= X_GLXVendorPrivateWithReply
;
507 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
508 req
->context
= gc
->xid
= XAllocID(dpy
);
509 req
->fbconfig
= generic_id
;
510 req
->screen
= screen
;
511 req
->renderType
= renderType
;
512 req
->shareList
= shareList
? shareList
->xid
: None
;
513 req
->isDirect
= gc
->isDirect
;
518 /* What to do here? This case is the sign of an internal error. It
519 * should never be reachable.
527 gc
->imported
= GL_FALSE
;
528 gc
->renderType
= renderType
;
530 return (GLXContext
) gc
;
534 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
535 GLXContext shareList
, Bool allowDirect
)
537 struct glx_config
*config
= NULL
;
540 #if defined(GLX_DIRECT_RENDERING) || defined(GLX_USE_APPLEGL)
541 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, vis
->screen
);
543 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
544 if (config
== NULL
) {
547 error
.errorCode
= BadValue
;
548 error
.resourceID
= vis
->visualid
;
549 error
.sequenceNumber
= dpy
->request
;
550 error
.type
= X_Error
;
551 error
.majorCode
= __glXSetupForCommand(dpy
);
552 error
.minorCode
= X_GLXCreateContext
;
553 _XError(dpy
, &error
);
557 renderType
= config
->rgbMode
? GLX_RGBA_TYPE
: GLX_COLOR_INDEX_TYPE
;
560 return CreateContext(dpy
, vis
->visualid
, config
, shareList
, allowDirect
,
561 X_GLXCreateContext
, renderType
, vis
->screen
);
565 glx_send_destroy_context(Display
*dpy
, XID xid
)
567 CARD8 opcode
= __glXSetupForCommand(dpy
);
568 xGLXDestroyContextReq
*req
;
571 GetReq(GLXDestroyContext
, req
);
572 req
->reqType
= opcode
;
573 req
->glxCode
= X_GLXDestroyContext
;
580 indirect_destroy_context(struct glx_context
*gc
)
582 if (!gc
->imported
&& gc
->xid
)
583 glx_send_destroy_context(gc
->psc
->dpy
, gc
->xid
);
585 __glXFreeVertexArrayState(gc
);
588 XFree((char *) gc
->vendor
);
590 XFree((char *) gc
->renderer
);
592 XFree((char *) gc
->version
);
594 XFree((char *) gc
->extensions
);
595 __glFreeAttributeState(gc
);
596 XFree((char *) gc
->buf
);
597 Xfree((char *) gc
->client_state_private
);
602 ** Destroy the named context
605 DestroyContext(Display
* dpy
, GLXContext ctx
)
607 struct glx_context
*gc
= (struct glx_context
*) ctx
;
613 if (gc
->currentDpy
) {
614 /* This context is bound to some thread. According to the man page,
615 * we should not actually delete the context until it's unbound.
616 * Note that we set gc->xid = None above. In MakeContextCurrent()
617 * we check for that and delete the context there.
620 glx_send_destroy_context(dpy
, gc
->xid
);
627 if (gc
->vtable
->destroy
)
628 gc
->vtable
->destroy(gc
);
632 glXDestroyContext(Display
* dpy
, GLXContext gc
)
634 DestroyContext(dpy
, gc
);
638 ** Return the major and minor version #s for the GLX extension
641 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
643 struct glx_display
*priv
;
645 /* Init the extension. This fetches the major and minor version. */
646 priv
= __glXInitialize(dpy
);
651 *major
= priv
->majorVersion
;
653 *minor
= priv
->minorVersion
;
658 ** Query the existance of the GLX extension
661 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
663 int major_op
, erb
, evb
;
666 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
677 indirect_wait_gl(struct glx_context
*gc
)
680 Display
*dpy
= gc
->currentDpy
;
682 /* Flush any pending commands out */
683 __glXFlushRenderBuffer(gc
, gc
->pc
);
685 /* Send the glXWaitGL request */
687 GetReq(GLXWaitGL
, req
);
688 req
->reqType
= gc
->majorOpcode
;
689 req
->glxCode
= X_GLXWaitGL
;
690 req
->contextTag
= gc
->currentContextTag
;
696 ** Put a barrier in the token stream that forces the GL to finish its
697 ** work before X can proceed.
702 struct glx_context
*gc
= __glXGetCurrentContext();
704 if (gc
&& gc
->vtable
->use_x_font
)
705 gc
->vtable
->wait_gl(gc
);
709 indirect_wait_x(struct glx_context
*gc
)
712 Display
*dpy
= gc
->currentDpy
;
714 /* Flush any pending commands out */
715 __glXFlushRenderBuffer(gc
, gc
->pc
);
718 GetReq(GLXWaitX
, req
);
719 req
->reqType
= gc
->majorOpcode
;
720 req
->glxCode
= X_GLXWaitX
;
721 req
->contextTag
= gc
->currentContextTag
;
727 ** Put a barrier in the token stream that forces X to finish its
728 ** work before GL can proceed.
733 struct glx_context
*gc
= __glXGetCurrentContext();
735 if (gc
&& gc
->vtable
->use_x_font
)
736 gc
->vtable
->wait_x(gc
);
740 indirect_use_x_font(struct glx_context
*gc
,
741 Font font
, int first
, int count
, int listBase
)
743 xGLXUseXFontReq
*req
;
744 Display
*dpy
= gc
->currentDpy
;
746 /* Flush any pending commands out */
747 __glXFlushRenderBuffer(gc
, gc
->pc
);
749 /* Send the glXUseFont request */
751 GetReq(GLXUseXFont
, req
);
752 req
->reqType
= gc
->majorOpcode
;
753 req
->glxCode
= X_GLXUseXFont
;
754 req
->contextTag
= gc
->currentContextTag
;
758 req
->listBase
= listBase
;
763 #ifdef GLX_USE_APPLEGL
766 applegl_destroy_context(struct glx_context
*gc
)
768 apple_glx_destroy_context(&gc
->driContext
, gc
->currentDpy
);
772 applegl_wait_gl(struct glx_context
*gc
)
778 applegl_wait_x(struct glx_context
*gc
)
780 apple_glx_waitx(gc
->dpy
, gc
->driContext
);
783 static const struct glx_context_vtable applegl_context_vtable
= {
784 applegl_destroy_context
,
788 NULL
, /* bind_tex_image, */
789 NULL
, /* release_tex_image, */
795 glXUseXFont(Font font
, int first
, int count
, int listBase
)
797 struct glx_context
*gc
= __glXGetCurrentContext();
799 if (gc
&& gc
->vtable
->use_x_font
)
800 gc
->vtable
->use_x_font(gc
, font
, first
, count
, listBase
);
803 /************************************************************************/
806 ** Copy the source context to the destination context using the
810 glXCopyContext(Display
* dpy
, GLXContext source_user
,
811 GLXContext dest_user
, unsigned long mask
)
813 struct glx_context
*source
= (struct glx_context
*) source_user
;
814 struct glx_context
*dest
= (struct glx_context
*) dest_user
;
815 #ifdef GLX_USE_APPLEGL
816 struct glx_context
*gc
= __glXGetCurrentContext();
820 if(apple_glx_copy_context(gc
->driContext
, source
->driContext
, dest
->driContext
,
821 mask
, &errorcode
, &x11error
)) {
822 __glXSendError(dpy
, errorcode
, 0, X_GLXCopyContext
, x11error
);
826 xGLXCopyContextReq
*req
;
827 struct glx_context
*gc
= __glXGetCurrentContext();
831 opcode
= __glXSetupForCommand(dpy
);
836 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
838 /* NOT_DONE: This does not work yet */
843 ** If the source is the current context, send its tag so that the context
844 ** can be flushed before the copy.
846 if (source
== gc
&& dpy
== gc
->currentDpy
) {
847 tag
= gc
->currentContextTag
;
853 /* Send the glXCopyContext request */
855 GetReq(GLXCopyContext
, req
);
856 req
->reqType
= opcode
;
857 req
->glxCode
= X_GLXCopyContext
;
858 req
->source
= source
? source
->xid
: None
;
859 req
->dest
= dest
? dest
->xid
: None
;
861 req
->contextTag
= tag
;
864 #endif /* GLX_USE_APPLEGL */
869 * Determine if a context uses direct rendering.
871 * \param dpy Display where the context was created.
872 * \param contextID ID of the context to be tested.
874 * \returns \c GL_TRUE if the context is direct rendering or not.
877 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
879 #if !defined(USE_XCB)
880 xGLXIsDirectReq
*req
;
881 xGLXIsDirectReply reply
;
885 opcode
= __glXSetupForCommand(dpy
);
891 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
892 xcb_glx_is_direct_reply_t
*reply
= xcb_glx_is_direct_reply(c
,
897 const Bool is_direct
= reply
->is_direct
? True
: False
;
902 /* Send the glXIsDirect request */
904 GetReq(GLXIsDirect
, req
);
905 req
->reqType
= opcode
;
906 req
->glxCode
= X_GLXIsDirect
;
907 req
->context
= contextID
;
908 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
912 return reply
.isDirect
;
918 * Shouldn't this function \b always return \c GL_FALSE when
919 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
920 * the GLX protocol here at all?
923 glXIsDirect(Display
* dpy
, GLXContext gc_user
)
925 struct glx_context
*gc
= (struct glx_context
*) gc_user
;
930 else if (gc
->isDirect
) {
933 #ifdef GLX_USE_APPLEGL /* TODO: indirect on darwin */
936 return __glXIsDirect(dpy
, gc
->xid
);
941 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
943 #ifdef GLX_USE_APPLEGL
944 int screen
= vis
->screen
;
945 struct glx_screen
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
946 const struct glx_config
*config
;
948 config
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
950 if(apple_glx_pixmap_create(dpy
, vis
->screen
, pixmap
, config
))
955 xGLXCreateGLXPixmapReq
*req
;
959 opcode
= __glXSetupForCommand(dpy
);
964 /* Send the glXCreateGLXPixmap request */
966 GetReq(GLXCreateGLXPixmap
, req
);
967 req
->reqType
= opcode
;
968 req
->glxCode
= X_GLXCreateGLXPixmap
;
969 req
->screen
= vis
->screen
;
970 req
->visual
= vis
->visualid
;
971 req
->pixmap
= pixmap
;
972 req
->glxpixmap
= xid
= XAllocID(dpy
);
976 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
978 /* FIXME: Maybe delay __DRIdrawable creation until the drawable
979 * is actually bound to a context... */
981 struct glx_display
*const priv
= __glXInitialize(dpy
);
982 __GLXDRIdrawable
*pdraw
;
983 struct glx_screen
*psc
;
984 struct glx_config
*config
;
986 psc
= priv
->screens
[vis
->screen
];
987 if (psc
->driScreen
== NULL
)
989 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
990 pdraw
= psc
->driScreen
->createDrawable(psc
, pixmap
, req
->glxpixmap
, config
);
992 fprintf(stderr
, "failed to create pixmap\n");
996 if (__glxHashInsert(priv
->drawHash
, req
->glxpixmap
, pdraw
)) {
997 (*pdraw
->destroyDrawable
) (pdraw
);
998 return None
; /* FIXME: Check what we're supposed to do here... */
1008 ** Destroy the named pixmap
1011 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
1013 #ifdef GLX_USE_APPLEGL
1014 if(apple_glx_pixmap_destroy(dpy
, glxpixmap
))
1015 __glXSendError(dpy
, GLXBadPixmap
, glxpixmap
, X_GLXDestroyPixmap
, false);
1017 xGLXDestroyGLXPixmapReq
*req
;
1020 opcode
= __glXSetupForCommand(dpy
);
1025 /* Send the glXDestroyGLXPixmap request */
1027 GetReq(GLXDestroyGLXPixmap
, req
);
1028 req
->reqType
= opcode
;
1029 req
->glxCode
= X_GLXDestroyGLXPixmap
;
1030 req
->glxpixmap
= glxpixmap
;
1034 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1036 struct glx_display
*const priv
= __glXInitialize(dpy
);
1037 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, glxpixmap
);
1039 if (pdraw
!= NULL
) {
1040 (*pdraw
->destroyDrawable
) (pdraw
);
1041 __glxHashDelete(priv
->drawHash
, glxpixmap
);
1045 #endif /* GLX_USE_APPLEGL */
1049 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
1051 #ifdef GLX_USE_APPLEGL
1052 GLXContext gc
= glXGetCurrentContext();
1053 if(gc
&& apple_glx_is_current_drawable(dpy
, gc
->driContext
, drawable
)) {
1054 apple_glx_swap_buffers(gc
->driContext
);
1056 __glXSendError(dpy
, GLXBadCurrentWindow
, 0, X_GLXSwapBuffers
, false);
1059 struct glx_context
*gc
;
1063 xcb_connection_t
*c
;
1065 xGLXSwapBuffersReq
*req
;
1068 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1069 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
1071 if (pdraw
!= NULL
) {
1073 (*pdraw
->psc
->driScreen
->swapBuffers
)(pdraw
, 0, 0, 0);
1078 opcode
= __glXSetupForCommand(dpy
);
1084 ** The calling thread may or may not have a current context. If it
1085 ** does, send the context tag so the server can do a flush.
1087 gc
= __glXGetCurrentContext();
1088 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
1089 ((drawable
== gc
->currentDrawable
)
1090 || (drawable
== gc
->currentReadable
))) {
1091 tag
= gc
->currentContextTag
;
1098 c
= XGetXCBConnection(dpy
);
1099 xcb_glx_swap_buffers(c
, tag
, drawable
);
1102 /* Send the glXSwapBuffers request */
1104 GetReq(GLXSwapBuffers
, req
);
1105 req
->reqType
= opcode
;
1106 req
->glxCode
= X_GLXSwapBuffers
;
1107 req
->drawable
= drawable
;
1108 req
->contextTag
= tag
;
1112 #endif /* USE_XCB */
1113 #endif /* GLX_USE_APPLEGL */
1118 ** Return configuration information for the given display, screen and
1119 ** visual combination.
1122 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
1125 struct glx_display
*priv
;
1126 struct glx_screen
*psc
;
1127 struct glx_config
*config
;
1130 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
1131 if (status
== Success
) {
1132 config
= glx_config_find_visual(psc
->visuals
, vis
->visualid
);
1134 /* Lookup attribute after first finding a match on the visual */
1135 if (config
!= NULL
) {
1136 return glx_config_get(config
, attribute
, value_return
);
1139 status
= GLX_BAD_VISUAL
;
1143 ** If we can't find the config for this visual, this visual is not
1144 ** supported by the OpenGL implementation on the server.
1146 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
1147 *value_return
= GL_FALSE
;
1154 /************************************************************************/
1157 init_fbconfig_for_chooser(struct glx_config
* config
,
1158 GLboolean fbconfig_style_tags
)
1160 memset(config
, 0, sizeof(struct glx_config
));
1161 config
->visualID
= (XID
) GLX_DONT_CARE
;
1162 config
->visualType
= GLX_DONT_CARE
;
1164 /* glXChooseFBConfig specifies different defaults for these two than
1167 if (fbconfig_style_tags
) {
1168 config
->rgbMode
= GL_TRUE
;
1169 config
->doubleBufferMode
= GLX_DONT_CARE
;
1172 config
->visualRating
= GLX_DONT_CARE
;
1173 config
->transparentPixel
= GLX_NONE
;
1174 config
->transparentRed
= GLX_DONT_CARE
;
1175 config
->transparentGreen
= GLX_DONT_CARE
;
1176 config
->transparentBlue
= GLX_DONT_CARE
;
1177 config
->transparentAlpha
= GLX_DONT_CARE
;
1178 config
->transparentIndex
= GLX_DONT_CARE
;
1180 config
->drawableType
= GLX_WINDOW_BIT
;
1181 config
->renderType
=
1182 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
1183 config
->xRenderable
= GLX_DONT_CARE
;
1184 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
1186 config
->swapMethod
= GLX_DONT_CARE
;
1189 #define MATCH_DONT_CARE( param ) \
1191 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1192 && (a-> param != b-> param) ) { \
1197 #define MATCH_MINIMUM( param ) \
1199 if ( ((int) a-> param != (int) GLX_DONT_CARE) \
1200 && (a-> param > b-> param) ) { \
1205 #define MATCH_EXACT( param ) \
1207 if ( a-> param != b-> param) { \
1212 /* Test that all bits from a are contained in b */
1213 #define MATCH_MASK(param) \
1215 if ((a->param & ~b->param) != 0) \
1220 * Determine if two GLXFBConfigs are compatible.
1222 * \param a Application specified config to test.
1223 * \param b Server specified config to test against \c a.
1226 fbconfigs_compatible(const struct glx_config
* const a
,
1227 const struct glx_config
* const b
)
1229 MATCH_DONT_CARE(doubleBufferMode
);
1230 MATCH_DONT_CARE(visualType
);
1231 MATCH_DONT_CARE(visualRating
);
1232 MATCH_DONT_CARE(xRenderable
);
1233 MATCH_DONT_CARE(fbconfigID
);
1234 MATCH_DONT_CARE(swapMethod
);
1236 MATCH_MINIMUM(rgbBits
);
1237 MATCH_MINIMUM(numAuxBuffers
);
1238 MATCH_MINIMUM(redBits
);
1239 MATCH_MINIMUM(greenBits
);
1240 MATCH_MINIMUM(blueBits
);
1241 MATCH_MINIMUM(alphaBits
);
1242 MATCH_MINIMUM(depthBits
);
1243 MATCH_MINIMUM(stencilBits
);
1244 MATCH_MINIMUM(accumRedBits
);
1245 MATCH_MINIMUM(accumGreenBits
);
1246 MATCH_MINIMUM(accumBlueBits
);
1247 MATCH_MINIMUM(accumAlphaBits
);
1248 MATCH_MINIMUM(sampleBuffers
);
1249 MATCH_MINIMUM(maxPbufferWidth
);
1250 MATCH_MINIMUM(maxPbufferHeight
);
1251 MATCH_MINIMUM(maxPbufferPixels
);
1252 MATCH_MINIMUM(samples
);
1254 MATCH_DONT_CARE(stereoMode
);
1257 MATCH_MASK(drawableType
);
1258 MATCH_MASK(renderType
);
1260 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1261 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1262 * Technically speaking, it is a bug in the DDX driver, but there is
1263 * enough of an installed base to work around the problem here. In any
1264 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1265 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1266 * 0 from the server to be a match to maintain backward compatibility with
1267 * the (broken) drivers.
1270 if (a
->transparentPixel
!= (int) GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1271 if (a
->transparentPixel
== GLX_NONE
) {
1272 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1276 MATCH_EXACT(transparentPixel
);
1279 switch (a
->transparentPixel
) {
1280 case GLX_TRANSPARENT_RGB
:
1281 MATCH_DONT_CARE(transparentRed
);
1282 MATCH_DONT_CARE(transparentGreen
);
1283 MATCH_DONT_CARE(transparentBlue
);
1284 MATCH_DONT_CARE(transparentAlpha
);
1287 case GLX_TRANSPARENT_INDEX
:
1288 MATCH_DONT_CARE(transparentIndex
);
1300 /* There's some trickly language in the GLX spec about how this is supposed
1301 * to work. Basically, if a given component size is either not specified
1302 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1303 * Well, that's really hard to do with the code as-is. This behavior is
1304 * closer to correct, but still not technically right.
1306 #define PREFER_LARGER_OR_ZERO(comp) \
1308 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1309 if ( ((*a)-> comp) == 0 ) { \
1312 else if ( ((*b)-> comp) == 0 ) { \
1316 return ((*b)-> comp) - ((*a)-> comp) ; \
1321 #define PREFER_LARGER(comp) \
1323 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1324 return ((*b)-> comp) - ((*a)-> comp) ; \
1328 #define PREFER_SMALLER(comp) \
1330 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1331 return ((*a)-> comp) - ((*b)-> comp) ; \
1336 * Compare two GLXFBConfigs. This function is intended to be used as the
1337 * compare function passed in to qsort.
1339 * \returns If \c a is a "better" config, according to the specification of
1340 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1341 * better, then a number greater than zero is return. If both are
1342 * equal, zero is returned.
1343 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1346 fbconfig_compare(struct glx_config
**a
, struct glx_config
**b
)
1348 /* The order of these comparisons must NOT change. It is defined by
1349 * the GLX 1.3 spec and ARB_multisample.
1352 PREFER_SMALLER(visualSelectGroup
);
1354 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1355 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1356 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1358 PREFER_SMALLER(visualRating
);
1360 /* This isn't quite right. It is supposed to compare the sum of the
1361 * components the user specifically set minimums for.
1363 PREFER_LARGER_OR_ZERO(redBits
);
1364 PREFER_LARGER_OR_ZERO(greenBits
);
1365 PREFER_LARGER_OR_ZERO(blueBits
);
1366 PREFER_LARGER_OR_ZERO(alphaBits
);
1368 PREFER_SMALLER(rgbBits
);
1370 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1371 /* Prefer single-buffer.
1373 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1376 PREFER_SMALLER(numAuxBuffers
);
1378 PREFER_LARGER_OR_ZERO(depthBits
);
1379 PREFER_SMALLER(stencilBits
);
1381 /* This isn't quite right. It is supposed to compare the sum of the
1382 * components the user specifically set minimums for.
1384 PREFER_LARGER_OR_ZERO(accumRedBits
);
1385 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1386 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1387 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1389 PREFER_SMALLER(visualType
);
1391 /* None of the multisample specs say where this comparison should happen,
1392 * so I put it near the end.
1394 PREFER_SMALLER(sampleBuffers
);
1395 PREFER_SMALLER(samples
);
1397 /* None of the pbuffer or fbconfig specs say that this comparison needs
1398 * to happen at all, but it seems like it should.
1400 PREFER_LARGER(maxPbufferWidth
);
1401 PREFER_LARGER(maxPbufferHeight
);
1402 PREFER_LARGER(maxPbufferPixels
);
1409 * Selects and sorts a subset of the supplied configs based on the attributes.
1410 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1411 * and \c glXChooseFBConfigSGIX.
1413 * \param configs Array of pointers to possible configs. The elements of
1414 * this array that do not meet the criteria will be set to
1415 * NULL. The remaining elements will be sorted according to
1416 * the various visual / FBConfig selection rules.
1417 * \param num_configs Number of elements in the \c configs array.
1418 * \param attribList Attributes used select from \c configs. This array is
1419 * terminated by a \c None tag. The array can either take
1420 * the form expected by \c glXChooseVisual (where boolean
1421 * tags do not have a value) or by \c glXChooseFBConfig
1422 * (where every tag has a value).
1423 * \param fbconfig_style_tags Selects whether \c attribList is in
1424 * \c glXChooseVisual style or
1425 * \c glXChooseFBConfig style.
1426 * \returns The number of valid elements left in \c configs.
1428 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1431 choose_visual(struct glx_config
** configs
, int num_configs
,
1432 const int *attribList
, GLboolean fbconfig_style_tags
)
1434 struct glx_config test_config
;
1438 /* This is a fairly direct implementation of the selection method
1439 * described by GLX_SGIX_fbconfig. Start by culling out all the
1440 * configs that are not compatible with the selected parameter
1444 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1445 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1446 (const INT32
*) attribList
,
1447 GL_TRUE
, fbconfig_style_tags
);
1450 for (i
= 0; i
< num_configs
; i
++) {
1451 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1452 configs
[base
] = configs
[i
];
1461 if (base
< num_configs
) {
1462 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1465 /* After the incompatible configs are removed, the resulting
1466 * list is sorted according to the rules set out in the various
1470 qsort(configs
, base
, sizeof(struct glx_config
*),
1471 (int (*)(const void *, const void *)) fbconfig_compare
);
1479 ** Return the visual that best matches the template. Return None if no
1480 ** visual matches the template.
1482 _X_EXPORT XVisualInfo
*
1483 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1485 XVisualInfo
*visualList
= NULL
;
1486 struct glx_display
*priv
;
1487 struct glx_screen
*psc
;
1488 struct glx_config test_config
;
1489 struct glx_config
*config
;
1490 struct glx_config
*best_config
= NULL
;
1493 ** Get a list of all visuals, return if list is empty
1495 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1501 ** Build a template from the defaults and the attribute list
1502 ** Free visual list and return if an unexpected token is encountered
1504 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1505 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1506 (const INT32
*) attribList
,
1510 ** Eliminate visuals that don't meet minimum requirements
1511 ** Compute a score for those that do
1512 ** Remember which visual, if any, got the highest score
1513 ** If no visual is acceptable, return None
1514 ** Otherwise, create an XVisualInfo list with just the selected X visual
1517 for (config
= psc
->visuals
; config
!= NULL
; config
= config
->next
) {
1518 if (fbconfigs_compatible(&test_config
, config
)
1519 && ((best_config
== NULL
) ||
1520 (fbconfig_compare (&config
, &best_config
) < 0))) {
1521 XVisualInfo visualTemplate
;
1522 XVisualInfo
*newList
;
1525 visualTemplate
.screen
= screen
;
1526 visualTemplate
.visualid
= config
->visualID
;
1527 newList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1528 &visualTemplate
, &i
);
1532 visualList
= newList
;
1533 best_config
= config
;
1538 #ifdef GLX_USE_APPLEGL
1539 if(visualList
&& getenv("LIBGL_DUMP_VISUALID")) {
1540 printf("visualid 0x%lx\n", visualList
[0].visualid
);
1548 _X_EXPORT
const char *
1549 glXQueryExtensionsString(Display
* dpy
, int screen
)
1551 struct glx_screen
*psc
;
1552 struct glx_display
*priv
;
1554 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1558 if (!psc
->effectiveGLXexts
) {
1559 if (!psc
->serverGLXexts
) {
1560 psc
->serverGLXexts
=
1561 __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
,
1565 __glXCalculateUsableExtensions(psc
,
1566 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
1567 (psc
->driScreen
!= NULL
),
1571 priv
->minorVersion
);
1574 return psc
->effectiveGLXexts
;
1577 _X_EXPORT
const char *
1578 glXGetClientString(Display
* dpy
, int name
)
1584 return (__glXGLXClientVendorName
);
1586 return (__glXGLXClientVersion
);
1587 case GLX_EXTENSIONS
:
1588 return (__glXGetClientExtensions());
1594 _X_EXPORT
const char *
1595 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1597 struct glx_screen
*psc
;
1598 struct glx_display
*priv
;
1602 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1608 str
= &priv
->serverGLXvendor
;
1611 str
= &priv
->serverGLXversion
;
1613 case GLX_EXTENSIONS
:
1614 str
= &psc
->serverGLXexts
;
1621 *str
= __glXQueryServerString(dpy
, priv
->majorOpcode
, screen
, name
);
1628 __glXClientInfo(Display
* dpy
, int opcode
)
1630 char *ext_str
= __glXGetClientGLExtensionString();
1631 int size
= strlen(ext_str
) + 1;
1634 xcb_connection_t
*c
= XGetXCBConnection(dpy
);
1635 xcb_glx_client_info(c
,
1636 GLX_MAJOR_VERSION
, GLX_MINOR_VERSION
, size
, ext_str
);
1638 xGLXClientInfoReq
*req
;
1640 /* Send the glXClientInfo request */
1642 GetReq(GLXClientInfo
, req
);
1643 req
->reqType
= opcode
;
1644 req
->glxCode
= X_GLXClientInfo
;
1645 req
->major
= GLX_MAJOR_VERSION
;
1646 req
->minor
= GLX_MINOR_VERSION
;
1648 req
->length
+= (size
+ 3) >> 2;
1649 req
->numbytes
= size
;
1650 Data(dpy
, ext_str
, size
);
1654 #endif /* USE_XCB */
1661 ** EXT_import_context
1665 glXGetCurrentDisplay(void)
1667 struct glx_context
*gc
= __glXGetCurrentContext();
1670 return gc
->currentDpy
;
1674 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1675 glXGetCurrentDisplay
)
1677 #ifndef GLX_USE_APPLEGL
1678 _X_EXPORT GLXContext
1679 glXImportContextEXT(Display
*dpy
, GLXContextID contextID
)
1681 struct glx_display
*priv
= __glXInitialize(dpy
);
1682 struct glx_screen
*psc
;
1683 xGLXQueryContextReply reply
;
1685 struct glx_context
*ctx
;
1686 int propList
[__GLX_MAX_CONTEXT_PROPS
* 2], *pProp
, nPropListBytes
;
1689 struct glx_config
*mode
;
1691 if (contextID
== None
|| __glXIsDirect(dpy
, contextID
))
1694 opcode
= __glXSetupForCommand(dpy
);
1698 /* Send the glXQueryContextInfoEXT request */
1701 if (priv
->majorVersion
> 1 || priv
->minorVersion
>= 3) {
1702 xGLXQueryContextReq
*req
;
1704 GetReq(GLXQueryContext
, req
);
1706 req
->reqType
= opcode
;
1707 req
->glxCode
= X_GLXQueryContext
;
1708 req
->context
= contextID
;
1711 xGLXVendorPrivateReq
*vpreq
;
1712 xGLXQueryContextInfoEXTReq
*req
;
1714 GetReqExtra(GLXVendorPrivate
,
1715 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1717 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1718 req
->reqType
= opcode
;
1719 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1720 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1721 req
->context
= contextID
;
1724 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1726 if (reply
.n
<= __GLX_MAX_CONTEXT_PROPS
)
1727 nPropListBytes
= reply
.n
* 2 * sizeof propList
[0];
1730 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1734 /* Look up screen first so we can look up visuals/fbconfigs later */
1736 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1737 if (pProp
[0] == GLX_SCREEN
)
1738 psc
= GetGLXScreenConfigs(dpy
, pProp
[1]);
1747 for (i
= 0, pProp
= propList
; i
< reply
.n
; i
++, pProp
+= 2)
1749 case GLX_SHARE_CONTEXT_EXT
:
1752 case GLX_VISUAL_ID_EXT
:
1753 mode
= glx_config_find_visual(psc
->visuals
, pProp
[1]);
1755 case GLX_FBCONFIG_ID
:
1756 mode
= glx_config_find_fbconfig(psc
->configs
, pProp
[1]);
1758 case GLX_RENDER_TYPE
:
1759 renderType
= pProp
[1];
1766 ctx
= indirect_create_context(psc
, mode
, NULL
, renderType
);
1770 ctx
->xid
= contextID
;
1771 ctx
->imported
= GL_TRUE
;
1772 ctx
->share_xid
= share
;
1774 return (GLXContext
) ctx
;
1780 glXQueryContext(Display
* dpy
, GLXContext ctx_user
, int attribute
, int *value
)
1782 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1784 switch (attribute
) {
1785 case GLX_SHARE_CONTEXT_EXT
:
1786 *value
= ctx
->share_xid
;
1788 case GLX_VISUAL_ID_EXT
:
1789 *value
= ctx
->config
? ctx
->config
->visualID
: None
;
1792 *value
= ctx
->screen
;
1794 case GLX_FBCONFIG_ID
:
1795 *value
= ctx
->config
? ctx
->config
->fbconfigID
: None
;
1797 case GLX_RENDER_TYPE
:
1798 *value
= ctx
->renderType
;
1801 return GLX_BAD_ATTRIBUTE
;
1807 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1808 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1809 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1811 _X_EXPORT GLXContextID
glXGetContextIDEXT(const GLXContext ctx_user
)
1813 struct glx_context
*ctx
= (struct glx_context
*) ctx_user
;
1819 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1821 DestroyContext(dpy
, ctx
);
1825 _X_EXPORT GLXFBConfig
*
1826 glXChooseFBConfig(Display
* dpy
, int screen
,
1827 const int *attribList
, int *nitems
)
1829 struct glx_config
**config_list
;
1833 config_list
= (struct glx_config
**)
1834 glXGetFBConfigs(dpy
, screen
, &list_size
);
1836 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1837 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1838 if (list_size
== 0) {
1844 *nitems
= list_size
;
1845 return (GLXFBConfig
*) config_list
;
1849 _X_EXPORT GLXContext
1850 glXCreateNewContext(Display
* dpy
, GLXFBConfig fbconfig
,
1851 int renderType
, GLXContext shareList
, Bool allowDirect
)
1853 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1855 return CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
1856 allowDirect
, X_GLXCreateNewContext
, renderType
,
1861 _X_EXPORT GLXDrawable
1862 glXGetCurrentReadDrawable(void)
1864 struct glx_context
*gc
= __glXGetCurrentContext();
1866 return gc
->currentReadable
;
1870 _X_EXPORT GLXFBConfig
*
1871 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1873 struct glx_display
*priv
= __glXInitialize(dpy
);
1874 struct glx_config
**config_list
= NULL
;
1875 struct glx_config
*config
;
1876 unsigned num_configs
= 0;
1880 if (priv
&& (priv
->screens
!= NULL
)
1881 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1882 && (priv
->screens
[screen
]->configs
!= NULL
)
1883 && (priv
->screens
[screen
]->configs
->fbconfigID
1884 != (int) GLX_DONT_CARE
)) {
1886 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1887 config
= config
->next
) {
1888 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1893 config_list
= Xmalloc(num_configs
* sizeof *config_list
);
1894 if (config_list
!= NULL
) {
1895 *nelements
= num_configs
;
1897 for (config
= priv
->screens
[screen
]->configs
; config
!= NULL
;
1898 config
= config
->next
) {
1899 if (config
->fbconfigID
!= (int) GLX_DONT_CARE
) {
1900 config_list
[i
] = config
;
1907 return (GLXFBConfig
*) config_list
;
1912 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig fbconfig
,
1913 int attribute
, int *value
)
1915 struct glx_config
*config
= ValidateGLXFBConfig(dpy
, fbconfig
);
1918 return GLXBadFBConfig
;
1920 return glx_config_get(config
, attribute
, value
);
1924 _X_EXPORT XVisualInfo
*
1925 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig fbconfig
)
1927 XVisualInfo visualTemplate
;
1928 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
1932 ** Get a list of all visuals, return if list is empty
1934 visualTemplate
.visualid
= config
->visualID
;
1935 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1938 #ifndef GLX_USE_APPLEGL
1940 ** GLX_SGI_swap_control
1943 __glXSwapIntervalSGI(int interval
)
1945 xGLXVendorPrivateReq
*req
;
1946 struct glx_context
*gc
= __glXGetCurrentContext();
1947 struct glx_screen
*psc
;
1949 CARD32
*interval_ptr
;
1953 return GLX_BAD_CONTEXT
;
1956 if (interval
<= 0) {
1957 return GLX_BAD_VALUE
;
1960 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
1962 #ifdef GLX_DIRECT_RENDERING
1963 if (gc
->isDirect
&& psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
1964 __GLXDRIdrawable
*pdraw
=
1965 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
1966 psc
->driScreen
->setSwapInterval(pdraw
, interval
);
1971 dpy
= gc
->currentDpy
;
1972 opcode
= __glXSetupForCommand(dpy
);
1977 /* Send the glXSwapIntervalSGI request */
1979 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1980 req
->reqType
= opcode
;
1981 req
->glxCode
= X_GLXVendorPrivate
;
1982 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1983 req
->contextTag
= gc
->currentContextTag
;
1985 interval_ptr
= (CARD32
*) (req
+ 1);
1986 *interval_ptr
= interval
;
1997 ** GLX_MESA_swap_control
2000 __glXSwapIntervalMESA(unsigned int interval
)
2002 #ifdef GLX_DIRECT_RENDERING
2003 struct glx_context
*gc
= __glXGetCurrentContext();
2005 if (gc
!= NULL
&& gc
->isDirect
) {
2006 struct glx_screen
*psc
;
2008 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2009 if (psc
->driScreen
&& psc
->driScreen
->setSwapInterval
) {
2010 __GLXDRIdrawable
*pdraw
=
2011 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2012 return psc
->driScreen
->setSwapInterval(pdraw
, interval
);
2017 return GLX_BAD_CONTEXT
;
2022 __glXGetSwapIntervalMESA(void)
2024 #ifdef GLX_DIRECT_RENDERING
2025 struct glx_context
*gc
= __glXGetCurrentContext();
2027 if (gc
!= NULL
&& gc
->isDirect
) {
2028 struct glx_screen
*psc
;
2030 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2031 if (psc
->driScreen
&& psc
->driScreen
->getSwapInterval
) {
2032 __GLXDRIdrawable
*pdraw
=
2033 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2034 return psc
->driScreen
->getSwapInterval(pdraw
);
2044 ** GLX_SGI_video_sync
2047 __glXGetVideoSyncSGI(unsigned int *count
)
2049 int64_t ust
, msc
, sbc
;
2051 struct glx_context
*gc
= __glXGetCurrentContext();
2052 struct glx_screen
*psc
;
2053 #ifdef GLX_DIRECT_RENDERING
2054 __GLXDRIdrawable
*pdraw
;
2058 return GLX_BAD_CONTEXT
;
2060 #ifdef GLX_DIRECT_RENDERING
2062 return GLX_BAD_CONTEXT
;
2065 psc
= GetGLXScreenConfigs(gc
->currentDpy
, gc
->screen
);
2066 #ifdef GLX_DIRECT_RENDERING
2067 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2070 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
2071 * FIXME: there should be a GLX encoding for this call. I can find no
2072 * FIXME: documentation for the GLX encoding.
2074 #ifdef GLX_DIRECT_RENDERING
2075 if (psc
->driScreen
&& psc
->driScreen
->getDrawableMSC
) {
2076 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, &ust
, &msc
, &sbc
);
2077 *count
= (unsigned) msc
;
2078 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2082 return GLX_BAD_CONTEXT
;
2086 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2088 struct glx_context
*gc
= __glXGetCurrentContext();
2089 struct glx_screen
*psc
;
2090 #ifdef GLX_DIRECT_RENDERING
2091 __GLXDRIdrawable
*pdraw
;
2093 int64_t ust
, msc
, sbc
;
2096 if (divisor
<= 0 || remainder
< 0)
2097 return GLX_BAD_VALUE
;
2100 return GLX_BAD_CONTEXT
;
2102 #ifdef GLX_DIRECT_RENDERING
2104 return GLX_BAD_CONTEXT
;
2107 psc
= GetGLXScreenConfigs( gc
->currentDpy
, gc
->screen
);
2108 #ifdef GLX_DIRECT_RENDERING
2109 pdraw
= GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
);
2112 #ifdef GLX_DIRECT_RENDERING
2113 if (psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2114 ret
= psc
->driScreen
->waitForMSC(pdraw
, 0, divisor
, remainder
, &ust
, &msc
,
2116 *count
= (unsigned) msc
;
2117 return (ret
== True
) ? 0 : GLX_BAD_CONTEXT
;
2121 return GLX_BAD_CONTEXT
;
2124 #endif /* GLX_USE_APPLEGL */
2127 ** GLX_SGIX_fbconfig
2128 ** Many of these functions are aliased to GLX 1.3 entry points in the
2129 ** GLX_functions table.
2133 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2134 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2135 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2137 _X_EXPORT
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2138 (Display
* dpy
, int screen
, int *attrib_list
,
2139 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2142 _X_EXPORT
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2143 (Display
* dpy
, GLXFBConfigSGIX config
),
2144 (dpy
, config
), glXGetVisualFromFBConfig
)
2147 glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2148 GLXFBConfigSGIX fbconfig
,
2151 #ifndef GLX_USE_APPLEGL
2152 xGLXVendorPrivateWithReplyReq
*vpreq
;
2153 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2154 GLXPixmap xid
= None
;
2156 struct glx_screen
*psc
;
2158 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2161 if ((dpy
== NULL
) || (config
== NULL
)) {
2164 #ifdef GLX_USE_APPLEGL
2165 if(apple_glx_pixmap_create(dpy
, config
->screen
, pixmap
, config
))
2170 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2172 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2173 opcode
= __glXSetupForCommand(dpy
);
2178 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2180 GetReqExtra(GLXVendorPrivateWithReply
,
2181 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2182 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2183 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2184 req
->reqType
= opcode
;
2185 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2186 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2187 req
->screen
= config
->screen
;
2188 req
->fbconfig
= config
->fbconfigID
;
2189 req
->pixmap
= pixmap
;
2190 req
->glxpixmap
= xid
= XAllocID(dpy
);
2199 _X_EXPORT GLXContext
2200 glXCreateContextWithConfigSGIX(Display
* dpy
,
2201 GLXFBConfigSGIX fbconfig
, int renderType
,
2202 GLXContext shareList
, Bool allowDirect
)
2204 GLXContext gc
= NULL
;
2205 struct glx_config
*config
= (struct glx_config
*) fbconfig
;
2206 struct glx_screen
*psc
;
2209 if ((dpy
== NULL
) || (config
== NULL
)) {
2213 psc
= GetGLXScreenConfigs(dpy
, config
->screen
);
2215 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2216 gc
= CreateContext(dpy
, config
->fbconfigID
, config
, shareList
,
2218 X_GLXvop_CreateContextWithConfigSGIX
, renderType
,
2226 _X_EXPORT GLXFBConfigSGIX
2227 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2229 struct glx_display
*priv
;
2230 struct glx_screen
*psc
= NULL
;
2232 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2233 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2234 && (psc
->configs
->fbconfigID
!= (int) GLX_DONT_CARE
)) {
2235 return (GLXFBConfigSGIX
) glx_config_find_visual(psc
->configs
,
2242 #ifndef GLX_USE_APPLEGL
2244 ** GLX_SGIX_swap_group
2247 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2257 ** GLX_SGIX_swap_barrier
2260 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2268 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2278 ** GLX_OML_sync_control
2281 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2282 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2284 struct glx_display
* const priv
= __glXInitialize(dpy
);
2286 #ifdef GLX_DIRECT_RENDERING
2287 __GLXDRIdrawable
*pdraw
;
2289 struct glx_screen
*psc
;
2294 #ifdef GLX_DIRECT_RENDERING
2295 pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2296 psc
= pdraw
? pdraw
->psc
: NULL
;
2297 if (pdraw
&& psc
->driScreen
->getDrawableMSC
) {
2298 ret
= psc
->driScreen
->getDrawableMSC(psc
, pdraw
, ust
, msc
, sbc
);
2306 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2308 __glxGetMscRate(__GLXDRIdrawable
*glxDraw
,
2309 int32_t * numerator
, int32_t * denominator
)
2312 struct glx_screen
*psc
;
2313 XF86VidModeModeLine mode_line
;
2318 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2319 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2320 unsigned n
= dot_clock
* 1000;
2321 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2323 # define V_INTERLACE 0x010
2324 # define V_DBLSCAN 0x020
2326 if (mode_line
.flags
& V_INTERLACE
)
2328 else if (mode_line
.flags
& V_DBLSCAN
)
2331 /* The OML_sync_control spec requires that if the refresh rate is a
2332 * whole number, that the returned numerator be equal to the refresh
2333 * rate and the denominator be 1.
2341 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2343 /* This is a poor man's way to reduce a fraction. It's far from
2344 * perfect, but it will work well enough for this situation.
2347 for (i
= 0; f
[i
] != 0; i
++) {
2348 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2374 * Determine the refresh rate of the specified drawable and display.
2376 * \param dpy Display whose refresh rate is to be determined.
2377 * \param drawable Drawable whose refresh rate is to be determined.
2378 * \param numerator Numerator of the refresh rate.
2379 * \param demoninator Denominator of the refresh rate.
2380 * \return If the refresh rate for the specified display and drawable could
2381 * be calculated, True is returned. Otherwise False is returned.
2383 * \note This function is implemented entirely client-side. A lot of other
2384 * functionality is required to export GLX_OML_sync_control, so on
2385 * XFree86 this function can be called for direct-rendering contexts
2386 * when GLX_OML_sync_control appears in the client extension string.
2390 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2391 int32_t * numerator
, int32_t * denominator
)
2393 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2394 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
);
2399 return __glxGetMscRate(draw
, numerator
, denominator
);
2411 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2412 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2414 struct glx_context
*gc
= __glXGetCurrentContext();
2415 #ifdef GLX_DIRECT_RENDERING
2416 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2417 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2420 if (!gc
) /* no GLX for this */
2423 #ifdef GLX_DIRECT_RENDERING
2424 if (!pdraw
|| !gc
->isDirect
)
2428 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2429 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2430 * of -1 if the function failed because of errors detected in the input
2433 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2435 if (divisor
> 0 && remainder
>= divisor
)
2438 if (target_msc
== 0 && divisor
== 0 && remainder
== 0)
2441 #ifdef GLX_DIRECT_RENDERING
2442 if (psc
->driScreen
&& psc
->driScreen
->swapBuffers
)
2443 return (*psc
->driScreen
->swapBuffers
)(pdraw
, target_msc
, divisor
,
2452 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2453 int64_t target_msc
, int64_t divisor
,
2454 int64_t remainder
, int64_t * ust
,
2455 int64_t * msc
, int64_t * sbc
)
2457 #ifdef GLX_DIRECT_RENDERING
2458 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2460 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2464 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2465 * error", but the return type in the spec is Bool.
2467 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2469 if (divisor
> 0 && remainder
>= divisor
)
2472 #ifdef GLX_DIRECT_RENDERING
2473 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForMSC
) {
2474 ret
= psc
->driScreen
->waitForMSC(pdraw
, target_msc
, divisor
, remainder
,
2485 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2486 int64_t target_sbc
, int64_t * ust
,
2487 int64_t * msc
, int64_t * sbc
)
2489 #ifdef GLX_DIRECT_RENDERING
2490 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2492 struct glx_screen
*psc
= pdraw
? pdraw
->psc
: NULL
;
2495 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2496 * error", but the return type in the spec is Bool.
2501 #ifdef GLX_DIRECT_RENDERING
2502 if (pdraw
&& psc
->driScreen
&& psc
->driScreen
->waitForSBC
) {
2503 ret
= psc
->driScreen
->waitForSBC(pdraw
, target_sbc
, ust
, msc
, sbc
);
2515 * Mesa extension stubs. These will help reduce portability problems.
2520 * Release all buffers associated with the specified GLX drawable.
2523 * This function was intended for stand-alone Mesa. The issue there is that
2524 * the library doesn't get any notification when a window is closed. In
2525 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2526 * supported, there are 3 different functions to destroy a drawable. It
2527 * should be possible to create GLX protocol (or have it determine which
2528 * protocol to use based on the type of the drawable) to have one function
2529 * do the work of 3. For the direct-rendering case, this function could
2530 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2531 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2532 * would need to be used. This really should be done as part of the new DRI
2535 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2536 * __driGarbageCollectDrawables
2537 * glXDestroyGLXPixmap
2538 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2539 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2542 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2551 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2552 Pixmap pixmap
, Colormap cmap
)
2565 * GLX_MESA_copy_sub_buffer
2567 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2569 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2570 int x
, int y
, int width
, int height
)
2572 xGLXVendorPrivateReq
*req
;
2573 struct glx_context
*gc
;
2575 CARD32
*drawable_ptr
;
2576 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2579 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2580 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
);
2581 if (pdraw
!= NULL
) {
2582 struct glx_screen
*psc
= pdraw
->psc
;
2583 if (psc
->driScreen
->copySubBuffer
!= NULL
) {
2585 (*psc
->driScreen
->copySubBuffer
) (pdraw
, x
, y
, width
, height
);
2592 opcode
= __glXSetupForCommand(dpy
);
2597 ** The calling thread may or may not have a current context. If it
2598 ** does, send the context tag so the server can do a flush.
2600 gc
= __glXGetCurrentContext();
2601 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2602 ((drawable
== gc
->currentDrawable
) ||
2603 (drawable
== gc
->currentReadable
))) {
2604 tag
= gc
->currentContextTag
;
2611 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2612 req
->reqType
= opcode
;
2613 req
->glxCode
= X_GLXVendorPrivate
;
2614 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2615 req
->contextTag
= tag
;
2617 drawable_ptr
= (CARD32
*) (req
+ 1);
2618 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2619 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2620 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2621 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2623 *drawable_ptr
= drawable
;
2635 * GLX_EXT_texture_from_pixmap
2638 indirect_bind_tex_image(Display
* dpy
,
2639 GLXDrawable drawable
,
2640 int buffer
, const int *attrib_list
)
2642 xGLXVendorPrivateReq
*req
;
2643 struct glx_context
*gc
= __glXGetCurrentContext();
2644 CARD32
*drawable_ptr
;
2646 CARD32
*num_attrib_ptr
;
2653 while (attrib_list
[i
* 2] != None
)
2657 opcode
= __glXSetupForCommand(dpy
);
2662 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2663 req
->reqType
= opcode
;
2664 req
->glxCode
= X_GLXVendorPrivate
;
2665 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2666 req
->contextTag
= gc
->currentContextTag
;
2668 drawable_ptr
= (CARD32
*) (req
+ 1);
2669 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2670 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2671 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2673 *drawable_ptr
= drawable
;
2674 *buffer_ptr
= buffer
;
2675 *num_attrib_ptr
= (CARD32
) i
;
2679 while (attrib_list
[i
* 2] != None
) {
2680 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2681 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2691 indirect_release_tex_image(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2693 xGLXVendorPrivateReq
*req
;
2694 struct glx_context
*gc
= __glXGetCurrentContext();
2695 CARD32
*drawable_ptr
;
2699 opcode
= __glXSetupForCommand(dpy
);
2704 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2705 req
->reqType
= opcode
;
2706 req
->glxCode
= X_GLXVendorPrivate
;
2707 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2708 req
->contextTag
= gc
->currentContextTag
;
2710 drawable_ptr
= (CARD32
*) (req
+ 1);
2711 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2713 *drawable_ptr
= drawable
;
2714 *buffer_ptr
= buffer
;
2720 static const struct glx_context_vtable indirect_context_vtable
= {
2721 indirect_destroy_context
,
2722 indirect_bind_context
,
2723 indirect_unbind_context
,
2726 indirect_use_x_font
,
2727 indirect_bind_tex_image
,
2728 indirect_release_tex_image
,
2733 __glXBindTexImageEXT(Display
* dpy
,
2734 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2736 struct glx_context
*gc
= __glXGetCurrentContext();
2738 if (gc
== NULL
|| gc
->vtable
->bind_tex_image
== NULL
)
2741 gc
->vtable
->bind_tex_image(dpy
, drawable
, buffer
, attrib_list
);
2745 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2747 struct glx_context
*gc
= __glXGetCurrentContext();
2749 if (gc
== NULL
|| gc
->vtable
->release_tex_image
== NULL
)
2752 gc
->vtable
->release_tex_image(dpy
, drawable
, buffer
);
2757 #endif /* GLX_USE_APPLEGL */
2760 * \c strdup is actually not a standard ANSI C or POSIX routine.
2761 * Irix will not define it if ANSI mode is in effect.
2766 __glXstrdup(const char *str
)
2769 copy
= (char *) Xmalloc(strlen(str
) + 1);
2777 ** glXGetProcAddress support
2780 struct name_address_pair
2786 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2787 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2789 static const struct name_address_pair GLX_functions
[] = {
2790 /*** GLX_VERSION_1_0 ***/
2791 GLX_FUNCTION(glXChooseVisual
),
2792 GLX_FUNCTION(glXCopyContext
),
2793 GLX_FUNCTION(glXCreateContext
),
2794 GLX_FUNCTION(glXCreateGLXPixmap
),
2795 GLX_FUNCTION(glXDestroyContext
),
2796 GLX_FUNCTION(glXDestroyGLXPixmap
),
2797 GLX_FUNCTION(glXGetConfig
),
2798 GLX_FUNCTION(glXGetCurrentContext
),
2799 GLX_FUNCTION(glXGetCurrentDrawable
),
2800 GLX_FUNCTION(glXIsDirect
),
2801 GLX_FUNCTION(glXMakeCurrent
),
2802 GLX_FUNCTION(glXQueryExtension
),
2803 GLX_FUNCTION(glXQueryVersion
),
2804 GLX_FUNCTION(glXSwapBuffers
),
2805 GLX_FUNCTION(glXUseXFont
),
2806 GLX_FUNCTION(glXWaitGL
),
2807 GLX_FUNCTION(glXWaitX
),
2809 /*** GLX_VERSION_1_1 ***/
2810 GLX_FUNCTION(glXGetClientString
),
2811 GLX_FUNCTION(glXQueryExtensionsString
),
2812 GLX_FUNCTION(glXQueryServerString
),
2814 /*** GLX_VERSION_1_2 ***/
2815 GLX_FUNCTION(glXGetCurrentDisplay
),
2817 /*** GLX_VERSION_1_3 ***/
2818 GLX_FUNCTION(glXChooseFBConfig
),
2819 GLX_FUNCTION(glXCreateNewContext
),
2820 GLX_FUNCTION(glXCreatePbuffer
),
2821 GLX_FUNCTION(glXCreatePixmap
),
2822 GLX_FUNCTION(glXCreateWindow
),
2823 GLX_FUNCTION(glXDestroyPbuffer
),
2824 GLX_FUNCTION(glXDestroyPixmap
),
2825 GLX_FUNCTION(glXDestroyWindow
),
2826 GLX_FUNCTION(glXGetCurrentReadDrawable
),
2827 GLX_FUNCTION(glXGetFBConfigAttrib
),
2828 GLX_FUNCTION(glXGetFBConfigs
),
2829 GLX_FUNCTION(glXGetSelectedEvent
),
2830 GLX_FUNCTION(glXGetVisualFromFBConfig
),
2831 GLX_FUNCTION(glXMakeContextCurrent
),
2832 GLX_FUNCTION(glXQueryContext
),
2833 GLX_FUNCTION(glXQueryDrawable
),
2834 GLX_FUNCTION(glXSelectEvent
),
2836 #ifndef GLX_USE_APPLEGL
2837 /*** GLX_SGI_swap_control ***/
2838 GLX_FUNCTION2(glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2840 /*** GLX_SGI_video_sync ***/
2841 GLX_FUNCTION2(glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2842 GLX_FUNCTION2(glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2844 /*** GLX_SGI_make_current_read ***/
2845 GLX_FUNCTION2(glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2846 GLX_FUNCTION2(glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2848 /*** GLX_EXT_import_context ***/
2849 GLX_FUNCTION(glXFreeContextEXT
),
2850 GLX_FUNCTION(glXGetContextIDEXT
),
2851 GLX_FUNCTION2(glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2852 GLX_FUNCTION(glXImportContextEXT
),
2853 GLX_FUNCTION2(glXQueryContextInfoEXT
, glXQueryContext
),
2856 /*** GLX_SGIX_fbconfig ***/
2857 GLX_FUNCTION2(glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2858 GLX_FUNCTION2(glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2859 GLX_FUNCTION(glXCreateGLXPixmapWithConfigSGIX
),
2860 GLX_FUNCTION(glXCreateContextWithConfigSGIX
),
2861 GLX_FUNCTION2(glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2862 GLX_FUNCTION(glXGetFBConfigFromVisualSGIX
),
2864 #ifndef GLX_USE_APPLEGL
2865 /*** GLX_SGIX_pbuffer ***/
2866 GLX_FUNCTION(glXCreateGLXPbufferSGIX
),
2867 GLX_FUNCTION(glXDestroyGLXPbufferSGIX
),
2868 GLX_FUNCTION(glXQueryGLXPbufferSGIX
),
2869 GLX_FUNCTION(glXSelectEventSGIX
),
2870 GLX_FUNCTION(glXGetSelectedEventSGIX
),
2872 /*** GLX_SGIX_swap_group ***/
2873 GLX_FUNCTION2(glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2875 /*** GLX_SGIX_swap_barrier ***/
2876 GLX_FUNCTION2(glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2877 GLX_FUNCTION2(glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2879 /*** GLX_MESA_copy_sub_buffer ***/
2880 GLX_FUNCTION2(glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2882 /*** GLX_MESA_pixmap_colormap ***/
2883 GLX_FUNCTION(glXCreateGLXPixmapMESA
),
2885 /*** GLX_MESA_release_buffers ***/
2886 GLX_FUNCTION2(glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2888 /*** GLX_MESA_swap_control ***/
2889 GLX_FUNCTION2(glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2890 GLX_FUNCTION2(glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2893 /*** GLX_ARB_get_proc_address ***/
2894 GLX_FUNCTION(glXGetProcAddressARB
),
2897 GLX_FUNCTION2(glXGetProcAddress
, glXGetProcAddressARB
),
2899 #ifndef GLX_USE_APPLEGL
2900 /*** GLX_OML_sync_control ***/
2901 GLX_FUNCTION2(glXWaitForSbcOML
, __glXWaitForSbcOML
),
2902 GLX_FUNCTION2(glXWaitForMscOML
, __glXWaitForMscOML
),
2903 GLX_FUNCTION2(glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2904 GLX_FUNCTION2(glXGetMscRateOML
, __glXGetMscRateOML
),
2905 GLX_FUNCTION2(glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2907 /*** GLX_EXT_texture_from_pixmap ***/
2908 GLX_FUNCTION2(glXBindTexImageEXT
, __glXBindTexImageEXT
),
2909 GLX_FUNCTION2(glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2912 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2913 /*** DRI configuration ***/
2914 GLX_FUNCTION(glXGetScreenDriver
),
2915 GLX_FUNCTION(glXGetDriverConfig
),
2918 {NULL
, NULL
} /* end of list */
2921 #ifndef GLX_USE_APPLEGL
2922 static const GLvoid
*
2923 get_glx_proc_address(const char *funcName
)
2927 /* try static functions */
2928 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2929 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2930 return GLX_functions
[i
].Address
;
2938 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2939 * \c glXGetProcAddress.
2941 * \param procName Name of a GL or GLX function.
2942 * \returns A pointer to the named function
2944 * \sa glXGetProcAddress
2946 _X_EXPORT
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2948 typedef void (*gl_function
) (void);
2952 /* Search the table of GLX and internal functions first. If that
2953 * fails and the supplied name could be a valid core GL name, try
2954 * searching the core GL function table. This check is done to prevent
2955 * DRI based drivers from searching the core GL function table for
2956 * internal API functions.
2958 #ifdef GLX_USE_APPLEGL
2959 f
= (gl_function
) apple_glx_get_proc_address(procName
);
2961 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2962 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2963 && (procName
[2] != 'X')) {
2964 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2971 * Get the address of a named GL function. This is the GLX 1.4 name for
2972 * \c glXGetProcAddressARB.
2974 * \param procName Name of a GL or GLX function.
2975 * \returns A pointer to the named function
2977 * \sa glXGetProcAddressARB
2979 _X_EXPORT
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2980 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2981 __attribute__ ((alias("glXGetProcAddressARB")));
2984 return glXGetProcAddressARB(procName
);
2986 #endif /* __GNUC__ */
2989 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
2991 * Get the unadjusted system time (UST). Currently, the UST is measured in
2992 * microseconds since Epoc. The actual resolution of the UST may vary from
2993 * system to system, and the units may vary from release to release.
2994 * Drivers should not call this function directly. They should instead use
2995 * \c glXGetProcAddress to obtain a pointer to the function.
2997 * \param ust Location to store the 64-bit UST
2998 * \returns Zero on success or a negative errno value on failure.
3000 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
3002 * \since Internal API version 20030317.
3005 __glXGetUST(int64_t * ust
)
3013 if (gettimeofday(&tv
, NULL
) == 0) {
3014 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3021 #endif /* GLX_DIRECT_RENDERING */