1 /* -*- mode: c; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 3; coding: utf-8-unix -*- */
3 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
4 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice including the dates of first publication and
14 * either this permission notice or a reference to
15 * http://oss.sgi.com/projects/FreeB/
16 * shall be included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * Except as contained in this notice, the name of Silicon Graphics, Inc.
27 * shall not be used in advertising or otherwise to promote the sale, use or
28 * other dealings in this Software without prior written authorization from
29 * Silicon Graphics, Inc.
34 * Client-side GLX interface.
37 #include "glxclient.h"
39 #include "glxextensions.h"
40 #include "glcontextmodes.h"
42 #ifdef GLX_DIRECT_RENDERING
44 #include <X11/extensions/xf86vmode.h>
48 static const char __glXGLXClientVendorName
[] = "SGI";
49 static const char __glXGLXClientVersion
[] = "1.4";
52 /****************************************************************************/
54 #ifdef GLX_DIRECT_RENDERING
56 static Bool windowExistsFlag
;
58 windowExistsErrorHandler(Display
* dpy
, XErrorEvent
* xerr
)
60 if (xerr
->error_code
== BadWindow
) {
61 windowExistsFlag
= GL_FALSE
;
67 * Find drawables in the local hash that have been destroyed on the
70 * \param dpy Display to destroy drawables for
71 * \param screen Screen number to destroy drawables for
74 GarbageCollectDRIDrawables(Display
* dpy
, __GLXscreenConfigs
* sc
)
77 __GLXDRIdrawable
*pdraw
;
78 XWindowAttributes xwa
;
79 int (*oldXErrorHandler
) (Display
*, XErrorEvent
*);
81 /* Set no-op error handler so Xlib doesn't bail out if the windows
82 * has alreay been destroyed on the server. */
84 oldXErrorHandler
= XSetErrorHandler(windowExistsErrorHandler
);
86 if (__glxHashFirst(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1) {
88 windowExistsFlag
= GL_TRUE
;
89 XGetWindowAttributes(dpy
, draw
, &xwa
); /* dummy request */
90 if (!windowExistsFlag
) {
91 /* Destroy the local drawable data, if the drawable no
92 longer exists in the Xserver */
93 (*pdraw
->destroyDrawable
) (pdraw
);
94 __glxHashDelete(sc
->drawHash
, draw
);
96 } while (__glxHashNext(sc
->drawHash
, &draw
, (void *) &pdraw
) == 1);
100 XSetErrorHandler(oldXErrorHandler
);
103 extern __GLXDRIdrawable
*GetGLXDRIDrawable(Display
* dpy
,
104 GLXDrawable drawable
,
105 int *const scrn_num
);
108 * Get the __DRIdrawable for the drawable associated with a GLXContext
110 * \param dpy The display associated with \c drawable.
111 * \param drawable GLXDrawable whose __DRIdrawable part is to be retrieved.
112 * \param scrn_num If non-NULL, the drawables screen is stored there
113 * \returns A pointer to the context's __DRIdrawable on success, or NULL if
114 * the drawable is not associated with a direct-rendering context.
116 _X_HIDDEN __GLXDRIdrawable
*
117 GetGLXDRIDrawable(Display
* dpy
, GLXDrawable drawable
, int *const scrn_num
)
119 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
120 __GLXDRIdrawable
*pdraw
;
121 const unsigned screen_count
= ScreenCount(dpy
);
123 __GLXscreenConfigs
*psc
;
128 for (i
= 0; i
< screen_count
; i
++) {
129 psc
= &priv
->screenConfigs
[i
];
130 if (psc
->drawHash
== NULL
)
133 if (__glxHashLookup(psc
->drawHash
, drawable
, (void *) &pdraw
) == 0) {
134 if (scrn_num
!= NULL
)
147 * Get the GLX per-screen data structure associated with a GLX context.
149 * \param dpy Display for which the GLX per-screen information is to be
151 * \param scrn Screen on \c dpy for which the GLX per-screen information is
153 * \returns A pointer to the GLX per-screen data if \c dpy and \c scrn
154 * specify a valid GLX screen, or NULL otherwise.
156 * \todo Should this function validate that \c scrn is within the screen
157 * number range for \c dpy?
160 static __GLXscreenConfigs
*
161 GetGLXScreenConfigs(Display
* dpy
, int scrn
)
163 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
165 return (priv
->screenConfigs
!= NULL
) ? &priv
->screenConfigs
[scrn
] : NULL
;
170 GetGLXPrivScreenConfig(Display
* dpy
, int scrn
, __GLXdisplayPrivate
** ppriv
,
171 __GLXscreenConfigs
** ppsc
)
173 /* Initialize the extension, if needed . This has the added value
174 * of initializing/allocating the display private
178 return GLX_NO_EXTENSION
;
181 *ppriv
= __glXInitialize(dpy
);
182 if (*ppriv
== NULL
) {
183 return GLX_NO_EXTENSION
;
186 /* Check screen number to see if its valid */
187 if ((scrn
< 0) || (scrn
>= ScreenCount(dpy
))) {
188 return GLX_BAD_SCREEN
;
191 /* Check to see if the GL is supported on this screen */
192 *ppsc
= &((*ppriv
)->screenConfigs
[scrn
]);
193 if ((*ppsc
)->configs
== NULL
) {
194 /* No support for GL on this screen regardless of visual */
195 return GLX_BAD_VISUAL
;
203 * Determine if a \c GLXFBConfig supplied by the application is valid.
205 * \param dpy Application supplied \c Display pointer.
206 * \param config Application supplied \c GLXFBConfig.
208 * \returns If the \c GLXFBConfig is valid, the a pointer to the matching
209 * \c __GLcontextModes structure is returned. Otherwise, \c NULL
212 static __GLcontextModes
*
213 ValidateGLXFBConfig(Display
* dpy
, GLXFBConfig config
)
215 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
216 const unsigned num_screens
= ScreenCount(dpy
);
218 const __GLcontextModes
*modes
;
222 for (i
= 0; i
< num_screens
; i
++) {
223 for (modes
= priv
->screenConfigs
[i
].configs
; modes
!= NULL
;
224 modes
= modes
->next
) {
225 if (modes
== (__GLcontextModes
*) config
) {
226 return (__GLcontextModes
*) config
;
237 * \todo It should be possible to move the allocate of \c client_state_private
238 * later in the function for direct-rendering contexts. Direct-rendering
239 * contexts don't need to track client state, so they don't need that memory
242 * \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
243 * function called \c __glXAllocateClientState that allocates the memory and
244 * does all the initialization (including the pixel pack / unpack).
247 AllocateGLXContext(Display
* dpy
)
252 __GLXattribute
*state
;
257 opcode
= __glXSetupForCommand(dpy
);
262 /* Allocate our context record */
263 gc
= (GLXContext
) Xmalloc(sizeof(struct __GLXcontextRec
));
268 memset(gc
, 0, sizeof(struct __GLXcontextRec
));
270 state
= Xmalloc(sizeof(struct __GLXattributeRec
));
276 gc
->client_state_private
= state
;
277 memset(gc
->client_state_private
, 0, sizeof(struct __GLXattributeRec
));
278 state
->NoDrawArraysProtocol
= (getenv("LIBGL_NO_DRAWARRAYS") != NULL
);
281 ** Create a temporary buffer to hold GLX rendering commands. The size
282 ** of the buffer is selected so that the maximum number of GLX rendering
283 ** commands can fit in a single X packet and still have room in the X
284 ** packet for the GLXRenderReq header.
287 bufSize
= (XMaxRequestSize(dpy
) * 4) - sz_xGLXRenderReq
;
288 gc
->buf
= (GLubyte
*) Xmalloc(bufSize
);
290 Xfree(gc
->client_state_private
);
294 gc
->bufSize
= bufSize
;
296 /* Fill in the new context */
297 gc
->renderMode
= GL_RENDER
;
299 state
->storePack
.alignment
= 4;
300 state
->storeUnpack
.alignment
= 4;
302 gc
->attributes
.stackPointer
= &gc
->attributes
.stack
[0];
305 ** PERFORMANCE NOTE: A mode dependent fill image can speed things up.
306 ** Other code uses the fastImageUnpack bit, but it is never set
309 gc
->fastImageUnpack
= GL_FALSE
;
310 gc
->fillImage
= __glFillImage
;
312 gc
->bufEnd
= gc
->buf
+ bufSize
;
313 gc
->isDirect
= GL_FALSE
;
316 ** Set limit register so that there will be one command per packet
321 gc
->limit
= gc
->buf
+ bufSize
- __GLX_BUFFER_LIMIT_SIZE
;
324 gc
->majorOpcode
= opcode
;
327 ** Constrain the maximum drawing command size allowed to be
328 ** transfered using the X_GLXRender protocol request. First
329 ** constrain by a software limit, then constrain by the protocl
332 if (bufSize
> __GLX_RENDER_CMD_SIZE_LIMIT
) {
333 bufSize
= __GLX_RENDER_CMD_SIZE_LIMIT
;
335 if (bufSize
> __GLX_MAX_RENDER_CMD_SIZE
) {
336 bufSize
= __GLX_MAX_RENDER_CMD_SIZE
;
338 gc
->maxSmallRenderCommandSize
= bufSize
;
344 * Create a new context. Exactly one of \c vis and \c fbconfig should be
347 * \param use_glx_1_3 For FBConfigs, should GLX 1.3 protocol or
348 * SGIX_fbconfig protocol be used?
349 * \param renderType For FBConfigs, what is the rendering type?
353 CreateContext(Display
* dpy
, XVisualInfo
* vis
,
354 const __GLcontextModes
* const fbconfig
,
355 GLXContext shareList
,
356 Bool allowDirect
, GLXContextID contextID
,
357 Bool use_glx_1_3
, int renderType
)
360 #ifdef GLX_DIRECT_RENDERING
361 int screen
= (fbconfig
== NULL
) ? vis
->screen
: fbconfig
->screen
;
362 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
368 gc
= AllocateGLXContext(dpy
);
372 if (None
== contextID
) {
373 if ((vis
== NULL
) && (fbconfig
== NULL
))
376 #ifdef GLX_DIRECT_RENDERING
377 if (allowDirect
&& psc
->driScreen
) {
378 const __GLcontextModes
*mode
;
380 if (fbconfig
== NULL
) {
381 mode
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
385 error
.errorCode
= BadValue
;
386 error
.resourceID
= vis
->visualid
;
387 error
.sequenceNumber
= dpy
->request
;
388 error
.type
= X_Error
;
389 error
.majorCode
= gc
->majorOpcode
;
390 error
.minorCode
= X_GLXCreateContext
;
391 _XError(dpy
, &error
);
399 gc
->driContext
= psc
->driScreen
->createContext(psc
, mode
, gc
,
402 if (gc
->driContext
!= NULL
) {
403 gc
->screen
= mode
->screen
;
406 gc
->isDirect
= GL_TRUE
;
412 if (fbconfig
== NULL
) {
413 xGLXCreateContextReq
*req
;
415 /* Send the glXCreateContext request */
416 GetReq(GLXCreateContext
, req
);
417 req
->reqType
= gc
->majorOpcode
;
418 req
->glxCode
= X_GLXCreateContext
;
419 req
->context
= gc
->xid
= XAllocID(dpy
);
420 req
->visual
= vis
->visualid
;
421 req
->screen
= vis
->screen
;
422 req
->shareList
= shareList
? shareList
->xid
: None
;
423 #ifdef GLX_DIRECT_RENDERING
424 req
->isDirect
= gc
->driContext
!= NULL
;
429 else if (use_glx_1_3
) {
430 xGLXCreateNewContextReq
*req
;
432 /* Send the glXCreateNewContext request */
433 GetReq(GLXCreateNewContext
, req
);
434 req
->reqType
= gc
->majorOpcode
;
435 req
->glxCode
= X_GLXCreateNewContext
;
436 req
->context
= gc
->xid
= XAllocID(dpy
);
437 req
->fbconfig
= fbconfig
->fbconfigID
;
438 req
->screen
= fbconfig
->screen
;
439 req
->renderType
= renderType
;
440 req
->shareList
= shareList
? shareList
->xid
: None
;
441 #ifdef GLX_DIRECT_RENDERING
442 req
->isDirect
= gc
->driContext
!= NULL
;
448 xGLXVendorPrivateWithReplyReq
*vpreq
;
449 xGLXCreateContextWithConfigSGIXReq
*req
;
451 /* Send the glXCreateNewContext request */
452 GetReqExtra(GLXVendorPrivateWithReply
,
453 sz_xGLXCreateContextWithConfigSGIXReq
-
454 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
455 req
= (xGLXCreateContextWithConfigSGIXReq
*) vpreq
;
456 req
->reqType
= gc
->majorOpcode
;
457 req
->glxCode
= X_GLXVendorPrivateWithReply
;
458 req
->vendorCode
= X_GLXvop_CreateContextWithConfigSGIX
;
459 req
->context
= gc
->xid
= XAllocID(dpy
);
460 req
->fbconfig
= fbconfig
->fbconfigID
;
461 req
->screen
= fbconfig
->screen
;
462 req
->renderType
= renderType
;
463 req
->shareList
= shareList
? shareList
->xid
: None
;
464 #ifdef GLX_DIRECT_RENDERING
465 req
->isDirect
= gc
->driContext
!= NULL
;
473 gc
->imported
= GL_FALSE
;
477 gc
->imported
= GL_TRUE
;
484 glXCreateContext(Display
* dpy
, XVisualInfo
* vis
,
485 GLXContext shareList
, Bool allowDirect
)
487 return CreateContext(dpy
, vis
, NULL
, shareList
, allowDirect
, None
,
492 __glXFreeContext(__GLXcontext
* gc
)
495 XFree((char *) gc
->vendor
);
497 XFree((char *) gc
->renderer
);
499 XFree((char *) gc
->version
);
501 XFree((char *) gc
->extensions
);
502 __glFreeAttributeState(gc
);
503 XFree((char *) gc
->buf
);
504 Xfree((char *) gc
->client_state_private
);
510 ** Destroy the named context
513 DestroyContext(Display
* dpy
, GLXContext gc
)
515 xGLXDestroyContextReq
*req
;
520 opcode
= __glXSetupForCommand(dpy
);
521 if (!opcode
|| !gc
) {
527 imported
= gc
->imported
;
530 #ifdef GLX_DIRECT_RENDERING
531 /* Destroy the direct rendering context */
532 if (gc
->driContext
) {
533 (*gc
->driContext
->destroyContext
) (gc
->driContext
, gc
->psc
, dpy
);
534 gc
->driContext
= NULL
;
535 GarbageCollectDRIDrawables(dpy
, gc
->psc
);
539 __glXFreeVertexArrayState(gc
);
541 if (gc
->currentDpy
) {
542 /* Have to free later cuz it's in use now */
546 /* Destroy the handle if not current to anybody */
548 __glXFreeContext(gc
);
553 ** This dpy also created the server side part of the context.
554 ** Send the glXDestroyContext request.
557 GetReq(GLXDestroyContext
, req
);
558 req
->reqType
= opcode
;
559 req
->glxCode
= X_GLXDestroyContext
;
567 glXDestroyContext(Display
* dpy
, GLXContext gc
)
569 DestroyContext(dpy
, gc
);
573 ** Return the major and minor version #s for the GLX extension
576 glXQueryVersion(Display
* dpy
, int *major
, int *minor
)
578 __GLXdisplayPrivate
*priv
;
580 /* Init the extension. This fetches the major and minor version. */
581 priv
= __glXInitialize(dpy
);
586 *major
= priv
->majorVersion
;
588 *minor
= priv
->minorVersion
;
593 ** Query the existance of the GLX extension
596 glXQueryExtension(Display
* dpy
, int *errorBase
, int *eventBase
)
598 int major_op
, erb
, evb
;
601 rv
= XQueryExtension(dpy
, GLX_EXTENSION_NAME
, &major_op
, &evb
, &erb
);
612 ** Put a barrier in the token stream that forces the GL to finish its
613 ** work before X can proceed.
619 GLXContext gc
= __glXGetCurrentContext();
620 Display
*dpy
= gc
->currentDpy
;
625 /* Flush any pending commands out */
626 __glXFlushRenderBuffer(gc
, gc
->pc
);
628 #ifdef GLX_DIRECT_RENDERING
629 if (gc
->driContext
) {
630 /* This bit of ugliness unwraps the glFinish function */
639 /* Send the glXWaitGL request */
641 GetReq(GLXWaitGL
, req
);
642 req
->reqType
= gc
->majorOpcode
;
643 req
->glxCode
= X_GLXWaitGL
;
644 req
->contextTag
= gc
->currentContextTag
;
650 ** Put a barrier in the token stream that forces X to finish its
651 ** work before GL can proceed.
657 GLXContext gc
= __glXGetCurrentContext();
658 Display
*dpy
= gc
->currentDpy
;
663 /* Flush any pending commands out */
664 __glXFlushRenderBuffer(gc
, gc
->pc
);
666 #ifdef GLX_DIRECT_RENDERING
667 if (gc
->driContext
) {
674 ** Send the glXWaitX request.
677 GetReq(GLXWaitX
, req
);
678 req
->reqType
= gc
->majorOpcode
;
679 req
->glxCode
= X_GLXWaitX
;
680 req
->contextTag
= gc
->currentContextTag
;
686 glXUseXFont(Font font
, int first
, int count
, int listBase
)
688 xGLXUseXFontReq
*req
;
689 GLXContext gc
= __glXGetCurrentContext();
690 Display
*dpy
= gc
->currentDpy
;
695 /* Flush any pending commands out */
696 (void) __glXFlushRenderBuffer(gc
, gc
->pc
);
698 #ifdef GLX_DIRECT_RENDERING
699 if (gc
->driContext
) {
700 DRI_glXUseXFont(font
, first
, count
, listBase
);
705 /* Send the glXUseFont request */
707 GetReq(GLXUseXFont
, req
);
708 req
->reqType
= gc
->majorOpcode
;
709 req
->glxCode
= X_GLXUseXFont
;
710 req
->contextTag
= gc
->currentContextTag
;
714 req
->listBase
= listBase
;
719 /************************************************************************/
722 ** Copy the source context to the destination context using the
726 glXCopyContext(Display
* dpy
, GLXContext source
,
727 GLXContext dest
, unsigned long mask
)
729 xGLXCopyContextReq
*req
;
730 GLXContext gc
= __glXGetCurrentContext();
734 opcode
= __glXSetupForCommand(dpy
);
739 #ifdef GLX_DIRECT_RENDERING
740 if (gc
->driContext
) {
741 /* NOT_DONE: This does not work yet */
746 ** If the source is the current context, send its tag so that the context
747 ** can be flushed before the copy.
749 if (source
== gc
&& dpy
== gc
->currentDpy
) {
750 tag
= gc
->currentContextTag
;
756 /* Send the glXCopyContext request */
758 GetReq(GLXCopyContext
, req
);
759 req
->reqType
= opcode
;
760 req
->glxCode
= X_GLXCopyContext
;
761 req
->source
= source
? source
->xid
: None
;
762 req
->dest
= dest
? dest
->xid
: None
;
764 req
->contextTag
= tag
;
771 * Determine if a context uses direct rendering.
773 * \param dpy Display where the context was created.
774 * \param contextID ID of the context to be tested.
776 * \returns \c GL_TRUE if the context is direct rendering or not.
779 __glXIsDirect(Display
* dpy
, GLXContextID contextID
)
781 xGLXIsDirectReq
*req
;
782 xGLXIsDirectReply reply
;
785 opcode
= __glXSetupForCommand(dpy
);
790 /* Send the glXIsDirect request */
792 GetReq(GLXIsDirect
, req
);
793 req
->reqType
= opcode
;
794 req
->glxCode
= X_GLXIsDirect
;
795 req
->context
= contextID
;
796 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
800 return reply
.isDirect
;
805 * Shouldn't this function \b always return \c GL_FALSE when
806 * \c GLX_DIRECT_RENDERING is not defined? Do we really need to bother with
807 * the GLX protocol here at all?
810 glXIsDirect(Display
* dpy
, GLXContext gc
)
814 #ifdef GLX_DIRECT_RENDERING
816 else if (gc
->driContext
) {
820 return __glXIsDirect(dpy
, gc
->xid
);
824 glXCreateGLXPixmap(Display
* dpy
, XVisualInfo
* vis
, Pixmap pixmap
)
826 xGLXCreateGLXPixmapReq
*req
;
830 opcode
= __glXSetupForCommand(dpy
);
835 /* Send the glXCreateGLXPixmap request */
837 GetReq(GLXCreateGLXPixmap
, req
);
838 req
->reqType
= opcode
;
839 req
->glxCode
= X_GLXCreateGLXPixmap
;
840 req
->screen
= vis
->screen
;
841 req
->visual
= vis
->visualid
;
842 req
->pixmap
= pixmap
;
843 req
->glxpixmap
= xid
= XAllocID(dpy
);
850 ** Destroy the named pixmap
853 glXDestroyGLXPixmap(Display
* dpy
, GLXPixmap glxpixmap
)
855 xGLXDestroyGLXPixmapReq
*req
;
858 opcode
= __glXSetupForCommand(dpy
);
863 /* Send the glXDestroyGLXPixmap request */
865 GetReq(GLXDestroyGLXPixmap
, req
);
866 req
->reqType
= opcode
;
867 req
->glxCode
= X_GLXDestroyGLXPixmap
;
868 req
->glxpixmap
= glxpixmap
;
874 glXSwapBuffers(Display
* dpy
, GLXDrawable drawable
)
876 xGLXSwapBuffersReq
*req
;
880 #ifdef GLX_DIRECT_RENDERING
881 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
885 (*pdraw
->psc
->driScreen
->swapBuffers
) (pdraw
);
890 opcode
= __glXSetupForCommand(dpy
);
896 ** The calling thread may or may not have a current context. If it
897 ** does, send the context tag so the server can do a flush.
899 gc
= __glXGetCurrentContext();
900 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
901 ((drawable
== gc
->currentDrawable
)
902 || (drawable
== gc
->currentReadable
))) {
903 tag
= gc
->currentContextTag
;
909 /* Send the glXSwapBuffers request */
911 GetReq(GLXSwapBuffers
, req
);
912 req
->reqType
= opcode
;
913 req
->glxCode
= X_GLXSwapBuffers
;
914 req
->drawable
= drawable
;
915 req
->contextTag
= tag
;
923 ** Return configuration information for the given display, screen and
924 ** visual combination.
927 glXGetConfig(Display
* dpy
, XVisualInfo
* vis
, int attribute
,
930 __GLXdisplayPrivate
*priv
;
931 __GLXscreenConfigs
*psc
;
932 __GLcontextModes
*modes
;
935 status
= GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
);
936 if (status
== Success
) {
937 modes
= _gl_context_modes_find_visual(psc
->visuals
, vis
->visualid
);
939 /* Lookup attribute after first finding a match on the visual */
941 return _gl_get_context_mode_data(modes
, attribute
, value_return
);
944 status
= GLX_BAD_VISUAL
;
948 ** If we can't find the config for this visual, this visual is not
949 ** supported by the OpenGL implementation on the server.
951 if ((status
== GLX_BAD_VISUAL
) && (attribute
== GLX_USE_GL
)) {
952 *value_return
= GL_FALSE
;
959 /************************************************************************/
962 init_fbconfig_for_chooser(__GLcontextModes
* config
,
963 GLboolean fbconfig_style_tags
)
965 memset(config
, 0, sizeof(__GLcontextModes
));
966 config
->visualID
= (XID
) GLX_DONT_CARE
;
967 config
->visualType
= GLX_DONT_CARE
;
969 /* glXChooseFBConfig specifies different defaults for these two than
972 if (fbconfig_style_tags
) {
973 config
->rgbMode
= GL_TRUE
;
974 config
->doubleBufferMode
= GLX_DONT_CARE
;
977 config
->visualRating
= GLX_DONT_CARE
;
978 config
->transparentPixel
= GLX_NONE
;
979 config
->transparentRed
= GLX_DONT_CARE
;
980 config
->transparentGreen
= GLX_DONT_CARE
;
981 config
->transparentBlue
= GLX_DONT_CARE
;
982 config
->transparentAlpha
= GLX_DONT_CARE
;
983 config
->transparentIndex
= GLX_DONT_CARE
;
985 config
->drawableType
= GLX_WINDOW_BIT
;
987 (config
->rgbMode
) ? GLX_RGBA_BIT
: GLX_COLOR_INDEX_BIT
;
988 config
->xRenderable
= GLX_DONT_CARE
;
989 config
->fbconfigID
= (GLXFBConfigID
) (GLX_DONT_CARE
);
991 config
->swapMethod
= GLX_DONT_CARE
;
994 #define MATCH_DONT_CARE( param ) \
996 if ( (a-> param != GLX_DONT_CARE) \
997 && (a-> param != b-> param) ) { \
1002 #define MATCH_MINIMUM( param ) \
1004 if ( (a-> param != GLX_DONT_CARE) \
1005 && (a-> param > b-> param) ) { \
1010 #define MATCH_EXACT( param ) \
1012 if ( a-> param != b-> param) { \
1018 * Determine if two GLXFBConfigs are compatible.
1020 * \param a Application specified config to test.
1021 * \param b Server specified config to test against \c a.
1024 fbconfigs_compatible(const __GLcontextModes
* const a
,
1025 const __GLcontextModes
* const b
)
1027 MATCH_DONT_CARE(doubleBufferMode
);
1028 MATCH_DONT_CARE(visualType
);
1029 MATCH_DONT_CARE(visualRating
);
1030 MATCH_DONT_CARE(xRenderable
);
1031 MATCH_DONT_CARE(fbconfigID
);
1032 MATCH_DONT_CARE(swapMethod
);
1034 MATCH_MINIMUM(rgbBits
);
1035 MATCH_MINIMUM(numAuxBuffers
);
1036 MATCH_MINIMUM(redBits
);
1037 MATCH_MINIMUM(greenBits
);
1038 MATCH_MINIMUM(blueBits
);
1039 MATCH_MINIMUM(alphaBits
);
1040 MATCH_MINIMUM(depthBits
);
1041 MATCH_MINIMUM(stencilBits
);
1042 MATCH_MINIMUM(accumRedBits
);
1043 MATCH_MINIMUM(accumGreenBits
);
1044 MATCH_MINIMUM(accumBlueBits
);
1045 MATCH_MINIMUM(accumAlphaBits
);
1046 MATCH_MINIMUM(sampleBuffers
);
1047 MATCH_MINIMUM(maxPbufferWidth
);
1048 MATCH_MINIMUM(maxPbufferHeight
);
1049 MATCH_MINIMUM(maxPbufferPixels
);
1050 MATCH_MINIMUM(samples
);
1052 MATCH_DONT_CARE(stereoMode
);
1055 if (((a
->drawableType
& b
->drawableType
) == 0)
1056 || ((a
->renderType
& b
->renderType
) == 0)) {
1061 /* There is a bug in a few of the XFree86 DDX drivers. They contain
1062 * visuals with a "transparent type" of 0 when they really mean GLX_NONE.
1063 * Technically speaking, it is a bug in the DDX driver, but there is
1064 * enough of an installed base to work around the problem here. In any
1065 * case, 0 is not a valid value of the transparent type, so we'll treat 0
1066 * from the app as GLX_DONT_CARE. We'll consider GLX_NONE from the app and
1067 * 0 from the server to be a match to maintain backward compatibility with
1068 * the (broken) drivers.
1071 if (a
->transparentPixel
!= GLX_DONT_CARE
&& a
->transparentPixel
!= 0) {
1072 if (a
->transparentPixel
== GLX_NONE
) {
1073 if (b
->transparentPixel
!= GLX_NONE
&& b
->transparentPixel
!= 0)
1077 MATCH_EXACT(transparentPixel
);
1080 switch (a
->transparentPixel
) {
1081 case GLX_TRANSPARENT_RGB
:
1082 MATCH_DONT_CARE(transparentRed
);
1083 MATCH_DONT_CARE(transparentGreen
);
1084 MATCH_DONT_CARE(transparentBlue
);
1085 MATCH_DONT_CARE(transparentAlpha
);
1088 case GLX_TRANSPARENT_INDEX
:
1089 MATCH_DONT_CARE(transparentIndex
);
1101 /* There's some trickly language in the GLX spec about how this is supposed
1102 * to work. Basically, if a given component size is either not specified
1103 * or the requested size is zero, it is supposed to act like PERFER_SMALLER.
1104 * Well, that's really hard to do with the code as-is. This behavior is
1105 * closer to correct, but still not technically right.
1107 #define PREFER_LARGER_OR_ZERO(comp) \
1109 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1110 if ( ((*a)-> comp) == 0 ) { \
1113 else if ( ((*b)-> comp) == 0 ) { \
1117 return ((*b)-> comp) - ((*a)-> comp) ; \
1122 #define PREFER_LARGER(comp) \
1124 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1125 return ((*b)-> comp) - ((*a)-> comp) ; \
1129 #define PREFER_SMALLER(comp) \
1131 if ( ((*a)-> comp) != ((*b)-> comp) ) { \
1132 return ((*a)-> comp) - ((*b)-> comp) ; \
1137 * Compare two GLXFBConfigs. This function is intended to be used as the
1138 * compare function passed in to qsort.
1140 * \returns If \c a is a "better" config, according to the specification of
1141 * SGIX_fbconfig, a number less than zero is returned. If \c b is
1142 * better, then a number greater than zero is return. If both are
1143 * equal, zero is returned.
1144 * \sa qsort, glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1147 fbconfig_compare(const __GLcontextModes
* const *const a
,
1148 const __GLcontextModes
* const *const b
)
1150 /* The order of these comparisons must NOT change. It is defined by
1151 * the GLX 1.3 spec and ARB_multisample.
1154 PREFER_SMALLER(visualSelectGroup
);
1156 /* The sort order for the visualRating is GLX_NONE, GLX_SLOW, and
1157 * GLX_NON_CONFORMANT_CONFIG. It just so happens that this is the
1158 * numerical sort order of the enums (0x8000, 0x8001, and 0x800D).
1160 PREFER_SMALLER(visualRating
);
1162 /* This isn't quite right. It is supposed to compare the sum of the
1163 * components the user specifically set minimums for.
1165 PREFER_LARGER_OR_ZERO(redBits
);
1166 PREFER_LARGER_OR_ZERO(greenBits
);
1167 PREFER_LARGER_OR_ZERO(blueBits
);
1168 PREFER_LARGER_OR_ZERO(alphaBits
);
1170 PREFER_SMALLER(rgbBits
);
1172 if (((*a
)->doubleBufferMode
!= (*b
)->doubleBufferMode
)) {
1173 /* Prefer single-buffer.
1175 return (!(*a
)->doubleBufferMode
) ? -1 : 1;
1178 PREFER_SMALLER(numAuxBuffers
);
1180 PREFER_LARGER_OR_ZERO(depthBits
);
1181 PREFER_SMALLER(stencilBits
);
1183 /* This isn't quite right. It is supposed to compare the sum of the
1184 * components the user specifically set minimums for.
1186 PREFER_LARGER_OR_ZERO(accumRedBits
);
1187 PREFER_LARGER_OR_ZERO(accumGreenBits
);
1188 PREFER_LARGER_OR_ZERO(accumBlueBits
);
1189 PREFER_LARGER_OR_ZERO(accumAlphaBits
);
1191 PREFER_SMALLER(visualType
);
1193 /* None of the multisample specs say where this comparison should happen,
1194 * so I put it near the end.
1196 PREFER_SMALLER(sampleBuffers
);
1197 PREFER_SMALLER(samples
);
1199 /* None of the pbuffer or fbconfig specs say that this comparison needs
1200 * to happen at all, but it seems like it should.
1202 PREFER_LARGER(maxPbufferWidth
);
1203 PREFER_LARGER(maxPbufferHeight
);
1204 PREFER_LARGER(maxPbufferPixels
);
1211 * Selects and sorts a subset of the supplied configs based on the attributes.
1212 * This function forms to basis of \c glXChooseVisual, \c glXChooseFBConfig,
1213 * and \c glXChooseFBConfigSGIX.
1215 * \param configs Array of pointers to possible configs. The elements of
1216 * this array that do not meet the criteria will be set to
1217 * NULL. The remaining elements will be sorted according to
1218 * the various visual / FBConfig selection rules.
1219 * \param num_configs Number of elements in the \c configs array.
1220 * \param attribList Attributes used select from \c configs. This array is
1221 * terminated by a \c None tag. The array can either take
1222 * the form expected by \c glXChooseVisual (where boolean
1223 * tags do not have a value) or by \c glXChooseFBConfig
1224 * (where every tag has a value).
1225 * \param fbconfig_style_tags Selects whether \c attribList is in
1226 * \c glXChooseVisual style or
1227 * \c glXChooseFBConfig style.
1228 * \returns The number of valid elements left in \c configs.
1230 * \sa glXChooseVisual, glXChooseFBConfig, glXChooseFBConfigSGIX
1233 choose_visual(__GLcontextModes
** configs
, int num_configs
,
1234 const int *attribList
, GLboolean fbconfig_style_tags
)
1236 __GLcontextModes test_config
;
1240 /* This is a fairly direct implementation of the selection method
1241 * described by GLX_SGIX_fbconfig. Start by culling out all the
1242 * configs that are not compatible with the selected parameter
1246 init_fbconfig_for_chooser(&test_config
, fbconfig_style_tags
);
1247 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1248 (const INT32
*) attribList
,
1249 GL_TRUE
, fbconfig_style_tags
);
1252 for (i
= 0; i
< num_configs
; i
++) {
1253 if (fbconfigs_compatible(&test_config
, configs
[i
])) {
1254 configs
[base
] = configs
[i
];
1263 if (base
< num_configs
) {
1264 (void) memset(&configs
[base
], 0, sizeof(void *) * (num_configs
- base
));
1267 /* After the incompatible configs are removed, the resulting
1268 * list is sorted according to the rules set out in the various
1272 qsort(configs
, base
, sizeof(__GLcontextModes
*),
1273 (int (*)(const void *, const void *)) fbconfig_compare
);
1281 ** Return the visual that best matches the template. Return None if no
1282 ** visual matches the template.
1284 PUBLIC XVisualInfo
*
1285 glXChooseVisual(Display
* dpy
, int screen
, int *attribList
)
1287 XVisualInfo
*visualList
= NULL
;
1288 __GLXdisplayPrivate
*priv
;
1289 __GLXscreenConfigs
*psc
;
1290 __GLcontextModes test_config
;
1291 __GLcontextModes
*modes
;
1292 const __GLcontextModes
*best_config
= NULL
;
1295 ** Get a list of all visuals, return if list is empty
1297 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1303 ** Build a template from the defaults and the attribute list
1304 ** Free visual list and return if an unexpected token is encountered
1306 init_fbconfig_for_chooser(&test_config
, GL_FALSE
);
1307 __glXInitializeVisualConfigFromTags(&test_config
, 512,
1308 (const INT32
*) attribList
,
1312 ** Eliminate visuals that don't meet minimum requirements
1313 ** Compute a score for those that do
1314 ** Remember which visual, if any, got the highest score
1316 for (modes
= psc
->visuals
; modes
!= NULL
; modes
= modes
->next
) {
1317 if (fbconfigs_compatible(&test_config
, modes
)
1318 && ((best_config
== NULL
)
1321 ((const __GLcontextModes
* const *const) &modes
,
1322 &best_config
) < 0))) {
1323 best_config
= modes
;
1328 ** If no visual is acceptable, return None
1329 ** Otherwise, create an XVisualInfo list with just the selected X visual
1332 if (best_config
!= NULL
) {
1333 XVisualInfo visualTemplate
;
1336 visualTemplate
.screen
= screen
;
1337 visualTemplate
.visualid
= best_config
->visualID
;
1338 visualList
= XGetVisualInfo(dpy
, VisualScreenMask
| VisualIDMask
,
1339 &visualTemplate
, &i
);
1347 glXQueryExtensionsString(Display
* dpy
, int screen
)
1349 __GLXscreenConfigs
*psc
;
1350 __GLXdisplayPrivate
*priv
;
1352 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1356 if (!psc
->effectiveGLXexts
) {
1357 if (!psc
->serverGLXexts
) {
1358 psc
->serverGLXexts
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1359 X_GLXQueryServerString
,
1364 __glXCalculateUsableExtensions(psc
,
1365 #ifdef GLX_DIRECT_RENDERING
1366 (psc
->driScreen
!= NULL
),
1370 priv
->minorVersion
);
1373 return psc
->effectiveGLXexts
;
1377 glXGetClientString(Display
* dpy
, int name
)
1381 return (__glXGLXClientVendorName
);
1383 return (__glXGLXClientVersion
);
1384 case GLX_EXTENSIONS
:
1385 return (__glXGetClientExtensions());
1392 glXQueryServerString(Display
* dpy
, int screen
, int name
)
1394 __GLXscreenConfigs
*psc
;
1395 __GLXdisplayPrivate
*priv
;
1399 if (GetGLXPrivScreenConfig(dpy
, screen
, &priv
, &psc
) != Success
) {
1405 str
= &priv
->serverGLXvendor
;
1408 str
= &priv
->serverGLXversion
;
1410 case GLX_EXTENSIONS
:
1411 str
= &psc
->serverGLXexts
;
1418 *str
= __glXGetStringFromServer(dpy
, priv
->majorOpcode
,
1419 X_GLXQueryServerString
, screen
, name
);
1426 __glXClientInfo(Display
* dpy
, int opcode
)
1428 xGLXClientInfoReq
*req
;
1430 char *ext_str
= __glXGetClientGLExtensionString();
1432 /* Send the glXClientInfo request */
1434 GetReq(GLXClientInfo
, req
);
1435 req
->reqType
= opcode
;
1436 req
->glxCode
= X_GLXClientInfo
;
1437 req
->major
= GLX_MAJOR_VERSION
;
1438 req
->minor
= GLX_MINOR_VERSION
;
1440 size
= strlen(ext_str
) + 1;
1441 req
->length
+= (size
+ 3) >> 2;
1442 req
->numbytes
= size
;
1443 Data(dpy
, ext_str
, size
);
1453 ** EXT_import_context
1457 glXGetCurrentDisplay(void)
1459 GLXContext gc
= __glXGetCurrentContext();
1462 return gc
->currentDpy
;
1466 GLX_ALIAS(Display
*, glXGetCurrentDisplayEXT
, (void), (),
1467 glXGetCurrentDisplay
)
1470 * Used internally by libGL to send \c xGLXQueryContextinfoExtReq requests
1473 * \param dpy Display where \c ctx was created.
1474 * \param ctx Context to query.
1475 * \returns \c Success on success. \c GLX_BAD_CONTEXT if \c ctx is invalid,
1476 * or zero if the request failed due to internal problems (i.e.,
1477 * unable to allocate temporary memory, etc.)
1480 * This function dynamically determines whether to use the EXT_import_context
1481 * version of the protocol or the GLX 1.3 version of the protocol.
1483 static int __glXQueryContextInfo(Display
* dpy
, GLXContext ctx
)
1485 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1486 xGLXQueryContextReply reply
;
1492 return GLX_BAD_CONTEXT
;
1494 opcode
= __glXSetupForCommand(dpy
);
1499 /* Send the glXQueryContextInfoEXT request */
1502 if ((priv
->majorVersion
> 1) || (priv
->minorVersion
>= 3)) {
1503 xGLXQueryContextReq
*req
;
1505 GetReq(GLXQueryContext
, req
);
1507 req
->reqType
= opcode
;
1508 req
->glxCode
= X_GLXQueryContext
;
1509 req
->context
= (unsigned int) (ctx
->xid
);
1512 xGLXVendorPrivateReq
*vpreq
;
1513 xGLXQueryContextInfoEXTReq
*req
;
1515 GetReqExtra(GLXVendorPrivate
,
1516 sz_xGLXQueryContextInfoEXTReq
- sz_xGLXVendorPrivateReq
,
1518 req
= (xGLXQueryContextInfoEXTReq
*) vpreq
;
1519 req
->reqType
= opcode
;
1520 req
->glxCode
= X_GLXVendorPrivateWithReply
;
1521 req
->vendorCode
= X_GLXvop_QueryContextInfoEXT
;
1522 req
->context
= (unsigned int) (ctx
->xid
);
1525 _XReply(dpy
, (xReply
*) & reply
, 0, False
);
1527 numValues
= reply
.n
;
1530 else if (numValues
> __GLX_MAX_CONTEXT_PROPS
)
1533 int *propList
, *pProp
;
1537 nPropListBytes
= numValues
<< 3;
1538 propList
= (int *) Xmalloc(nPropListBytes
);
1539 if (NULL
== propList
) {
1543 _XRead(dpy
, (char *) propList
, nPropListBytes
);
1545 for (i
= 0; i
< numValues
; i
++) {
1547 case GLX_SHARE_CONTEXT_EXT
:
1548 ctx
->share_xid
= *pProp
++;
1550 case GLX_VISUAL_ID_EXT
:
1552 _gl_context_modes_find_visual(ctx
->psc
->visuals
, *pProp
++);
1555 ctx
->screen
= *pProp
++;
1557 case GLX_FBCONFIG_ID
:
1559 _gl_context_modes_find_fbconfig(ctx
->psc
->configs
,
1562 case GLX_RENDER_TYPE
:
1563 ctx
->renderType
= *pProp
++;
1570 Xfree((char *) propList
);
1580 glXQueryContext(Display
* dpy
, GLXContext ctx
, int attribute
, int *value
)
1584 /* get the information from the server if we don't have it already */
1585 #ifdef GLX_DIRECT_RENDERING
1586 if (!ctx
->driContext
&& (ctx
->mode
== NULL
)) {
1588 if (ctx
->mode
== NULL
) {
1590 retVal
= __glXQueryContextInfo(dpy
, ctx
);
1591 if (Success
!= retVal
)
1594 switch (attribute
) {
1595 case GLX_SHARE_CONTEXT_EXT
:
1596 *value
= (int) (ctx
->share_xid
);
1598 case GLX_VISUAL_ID_EXT
:
1599 *value
= ctx
->mode
? ctx
->mode
->visualID
: None
;
1602 *value
= (int) (ctx
->screen
);
1604 case GLX_FBCONFIG_ID
:
1605 *value
= ctx
->mode
? ctx
->mode
->fbconfigID
: None
;
1607 case GLX_RENDER_TYPE
:
1608 *value
= (int) (ctx
->renderType
);
1611 return GLX_BAD_ATTRIBUTE
;
1617 GLX_ALIAS(int, glXQueryContextInfoEXT
,
1618 (Display
* dpy
, GLXContext ctx
, int attribute
, int *value
),
1619 (dpy
, ctx
, attribute
, value
), glXQueryContext
)
1621 PUBLIC GLXContextID
glXGetContextIDEXT(const GLXContext ctx
)
1627 glXImportContextEXT(Display
* dpy
, GLXContextID contextID
)
1631 if (contextID
== None
) {
1634 if (__glXIsDirect(dpy
, contextID
)) {
1638 ctx
= CreateContext(dpy
, NULL
, NULL
, NULL
, False
, contextID
, False
, 0);
1640 if (Success
!= __glXQueryContextInfo(dpy
, ctx
)) {
1648 glXFreeContextEXT(Display
* dpy
, GLXContext ctx
)
1650 DestroyContext(dpy
, ctx
);
1656 * GLX 1.3 functions - these are just stubs for now!
1659 PUBLIC GLXFBConfig
*
1660 glXChooseFBConfig(Display
* dpy
, int screen
,
1661 const int *attribList
, int *nitems
)
1663 __GLcontextModes
**config_list
;
1667 config_list
= (__GLcontextModes
**)
1668 glXGetFBConfigs(dpy
, screen
, &list_size
);
1670 if ((config_list
!= NULL
) && (list_size
> 0) && (attribList
!= NULL
)) {
1671 list_size
= choose_visual(config_list
, list_size
, attribList
, GL_TRUE
);
1672 if (list_size
== 0) {
1678 *nitems
= list_size
;
1679 return (GLXFBConfig
*) config_list
;
1684 glXCreateNewContext(Display
* dpy
, GLXFBConfig config
,
1685 int renderType
, GLXContext shareList
, Bool allowDirect
)
1687 return CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
1688 allowDirect
, None
, True
, renderType
);
1693 glXGetCurrentReadDrawable(void)
1695 GLXContext gc
= __glXGetCurrentContext();
1696 return gc
->currentReadable
;
1700 PUBLIC GLXFBConfig
*
1701 glXGetFBConfigs(Display
* dpy
, int screen
, int *nelements
)
1703 __GLXdisplayPrivate
*priv
= __glXInitialize(dpy
);
1704 __GLcontextModes
**config
= NULL
;
1708 if ((priv
->screenConfigs
!= NULL
)
1709 && (screen
>= 0) && (screen
<= ScreenCount(dpy
))
1710 && (priv
->screenConfigs
[screen
].configs
!= NULL
)
1711 && (priv
->screenConfigs
[screen
].configs
->fbconfigID
!= GLX_DONT_CARE
)) {
1712 unsigned num_configs
= 0;
1713 __GLcontextModes
*modes
;
1716 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1717 modes
= modes
->next
) {
1718 if (modes
->fbconfigID
!= GLX_DONT_CARE
) {
1723 config
= (__GLcontextModes
**) Xmalloc(sizeof(__GLcontextModes
*)
1725 if (config
!= NULL
) {
1726 *nelements
= num_configs
;
1728 for (modes
= priv
->screenConfigs
[screen
].configs
; modes
!= NULL
;
1729 modes
= modes
->next
) {
1730 if (modes
->fbconfigID
!= GLX_DONT_CARE
) {
1737 return (GLXFBConfig
*) config
;
1742 glXGetFBConfigAttrib(Display
* dpy
, GLXFBConfig config
,
1743 int attribute
, int *value
)
1745 __GLcontextModes
*const modes
= ValidateGLXFBConfig(dpy
, config
);
1747 return (modes
!= NULL
)
1748 ? _gl_get_context_mode_data(modes
, attribute
, value
)
1753 PUBLIC XVisualInfo
*
1754 glXGetVisualFromFBConfig(Display
* dpy
, GLXFBConfig config
)
1756 XVisualInfo visualTemplate
;
1757 __GLcontextModes
*fbconfig
= (__GLcontextModes
*) config
;
1761 ** Get a list of all visuals, return if list is empty
1763 visualTemplate
.visualid
= fbconfig
->visualID
;
1764 return XGetVisualInfo(dpy
, VisualIDMask
, &visualTemplate
, &count
);
1769 ** GLX_SGI_swap_control
1772 __glXSwapIntervalSGI(int interval
)
1774 xGLXVendorPrivateReq
*req
;
1775 GLXContext gc
= __glXGetCurrentContext();
1777 CARD32
*interval_ptr
;
1781 return GLX_BAD_CONTEXT
;
1784 if (interval
<= 0) {
1785 return GLX_BAD_VALUE
;
1788 #ifdef __DRI_SWAP_CONTROL
1789 if (gc
->driContext
) {
1790 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1792 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(gc
->currentDpy
,
1793 gc
->currentDrawable
,
1795 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1796 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1800 return GLX_BAD_CONTEXT
;
1804 dpy
= gc
->currentDpy
;
1805 opcode
= __glXSetupForCommand(dpy
);
1810 /* Send the glXSwapIntervalSGI request */
1812 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
), req
);
1813 req
->reqType
= opcode
;
1814 req
->glxCode
= X_GLXVendorPrivate
;
1815 req
->vendorCode
= X_GLXvop_SwapIntervalSGI
;
1816 req
->contextTag
= gc
->currentContextTag
;
1818 interval_ptr
= (CARD32
*) (req
+ 1);
1819 *interval_ptr
= interval
;
1830 ** GLX_MESA_swap_control
1833 __glXSwapIntervalMESA(unsigned int interval
)
1835 #ifdef __DRI_SWAP_CONTROL
1836 GLXContext gc
= __glXGetCurrentContext();
1839 return GLX_BAD_VALUE
;
1842 if (gc
!= NULL
&& gc
->driContext
) {
1843 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1846 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1847 __GLXDRIdrawable
*pdraw
=
1848 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1849 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1850 psc
->swapControl
->setSwapInterval(pdraw
->driDrawable
, interval
);
1859 return GLX_BAD_CONTEXT
;
1864 __glXGetSwapIntervalMESA(void)
1866 #ifdef __DRI_SWAP_CONTROL
1867 GLXContext gc
= __glXGetCurrentContext();
1869 if (gc
!= NULL
&& gc
->driContext
) {
1870 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
1873 if ((psc
!= NULL
) && (psc
->driScreen
!= NULL
)) {
1874 __GLXDRIdrawable
*pdraw
=
1875 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
1876 if (psc
->swapControl
!= NULL
&& pdraw
!= NULL
) {
1877 return psc
->swapControl
->getSwapInterval(pdraw
->driDrawable
);
1888 ** GLX_MESA_swap_frame_usage
1892 __glXBeginFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
1894 int status
= GLX_BAD_CONTEXT
;
1895 #ifdef __DRI_FRAME_TRACKING
1897 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1898 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
1900 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1901 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
, GL_TRUE
);
1911 __glXEndFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
)
1913 int status
= GLX_BAD_CONTEXT
;
1914 #ifdef __DRI_FRAME_TRACKING
1916 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1917 __GLXscreenConfigs
*psc
= GetGLXScreenConfigs(dpy
, screen
);
1919 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
)
1920 status
= psc
->frameTracking
->frameTracking(pdraw
->driDrawable
,
1931 __glXGetFrameUsageMESA(Display
* dpy
, GLXDrawable drawable
, GLfloat
* usage
)
1933 int status
= GLX_BAD_CONTEXT
;
1934 #ifdef __DRI_FRAME_TRACKING
1936 __GLXDRIdrawable
*const pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1937 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
1939 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1940 int64_t sbc
, missedFrames
;
1941 float lastMissedUsage
;
1943 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1959 __glXQueryFrameTrackingMESA(Display
* dpy
, GLXDrawable drawable
,
1960 int64_t * sbc
, int64_t * missedFrames
,
1961 GLfloat
* lastMissedUsage
)
1963 int status
= GLX_BAD_CONTEXT
;
1964 #ifdef __DRI_FRAME_TRACKING
1966 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
1967 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
1969 if (pdraw
!= NULL
&& psc
->frameTracking
!= NULL
) {
1972 status
= psc
->frameTracking
->queryFrameTracking(pdraw
->driDrawable
,
1981 (void) missedFrames
;
1982 (void) lastMissedUsage
;
1989 ** GLX_SGI_video_sync
1992 __glXGetVideoSyncSGI(unsigned int *count
)
1994 /* FIXME: Looking at the GLX_SGI_video_sync spec in the extension registry,
1995 * FIXME: there should be a GLX encoding for this call. I can find no
1996 * FIXME: documentation for the GLX encoding.
1998 #ifdef __DRI_MEDIA_STREAM_COUNTER
1999 GLXContext gc
= __glXGetCurrentContext();
2002 if (gc
!= NULL
&& gc
->driContext
) {
2003 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2005 if (psc
->msc
&& psc
->driScreen
) {
2006 __GLXDRIdrawable
*pdraw
=
2007 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2011 ret
= (*psc
->msc
->getDrawableMSC
) (psc
->__driScreen
,
2012 pdraw
->driDrawable
, &temp
);
2013 *count
= (unsigned) temp
;
2015 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2021 return GLX_BAD_CONTEXT
;
2025 __glXWaitVideoSyncSGI(int divisor
, int remainder
, unsigned int *count
)
2027 #ifdef __DRI_MEDIA_STREAM_COUNTER
2028 GLXContext gc
= __glXGetCurrentContext();
2030 if (divisor
<= 0 || remainder
< 0)
2031 return GLX_BAD_VALUE
;
2033 if (gc
!= NULL
&& gc
->driContext
) {
2034 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(gc
->currentDpy
,
2036 if (psc
->msc
!= NULL
&& psc
->driScreen
) {
2037 __GLXDRIdrawable
*pdraw
=
2038 GetGLXDRIDrawable(gc
->currentDpy
, gc
->currentDrawable
, NULL
);
2043 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, 0,
2044 divisor
, remainder
, &msc
, &sbc
);
2045 *count
= (unsigned) msc
;
2046 return (ret
== 0) ? 0 : GLX_BAD_CONTEXT
;
2052 return GLX_BAD_CONTEXT
;
2057 ** GLX_SGIX_fbconfig
2058 ** Many of these functions are aliased to GLX 1.3 entry points in the
2059 ** GLX_functions table.
2063 GLX_ALIAS(int, glXGetFBConfigAttribSGIX
,
2064 (Display
* dpy
, GLXFBConfigSGIX config
, int attribute
, int *value
),
2065 (dpy
, config
, attribute
, value
), glXGetFBConfigAttrib
)
2067 PUBLIC
GLX_ALIAS(GLXFBConfigSGIX
*, glXChooseFBConfigSGIX
,
2068 (Display
* dpy
, int screen
, int *attrib_list
,
2069 int *nelements
), (dpy
, screen
, attrib_list
, nelements
),
2072 PUBLIC
GLX_ALIAS(XVisualInfo
*, glXGetVisualFromFBConfigSGIX
,
2073 (Display
* dpy
, GLXFBConfigSGIX config
),
2074 (dpy
, config
), glXGetVisualFromFBConfig
)
2076 PUBLIC GLXPixmap
glXCreateGLXPixmapWithConfigSGIX(Display
* dpy
,
2077 GLXFBConfigSGIX config
,
2080 xGLXVendorPrivateWithReplyReq
*vpreq
;
2081 xGLXCreateGLXPixmapWithConfigSGIXReq
*req
;
2082 GLXPixmap xid
= None
;
2084 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2085 __GLXscreenConfigs
*psc
;
2088 if ((dpy
== NULL
) || (config
== NULL
)) {
2092 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2094 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2095 opcode
= __glXSetupForCommand(dpy
);
2100 /* Send the glXCreateGLXPixmapWithConfigSGIX request */
2102 GetReqExtra(GLXVendorPrivateWithReply
,
2103 sz_xGLXCreateGLXPixmapWithConfigSGIXReq
-
2104 sz_xGLXVendorPrivateWithReplyReq
, vpreq
);
2105 req
= (xGLXCreateGLXPixmapWithConfigSGIXReq
*) vpreq
;
2106 req
->reqType
= opcode
;
2107 req
->glxCode
= X_GLXVendorPrivateWithReply
;
2108 req
->vendorCode
= X_GLXvop_CreateGLXPixmapWithConfigSGIX
;
2109 req
->screen
= fbconfig
->screen
;
2110 req
->fbconfig
= fbconfig
->fbconfigID
;
2111 req
->pixmap
= pixmap
;
2112 req
->glxpixmap
= xid
= XAllocID(dpy
);
2121 glXCreateContextWithConfigSGIX(Display
* dpy
,
2122 GLXFBConfigSGIX config
, int renderType
,
2123 GLXContext shareList
, Bool allowDirect
)
2125 GLXContext gc
= NULL
;
2126 const __GLcontextModes
*const fbconfig
= (__GLcontextModes
*) config
;
2127 __GLXscreenConfigs
*psc
;
2130 if ((dpy
== NULL
) || (config
== NULL
)) {
2134 psc
= GetGLXScreenConfigs(dpy
, fbconfig
->screen
);
2136 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)) {
2137 gc
= CreateContext(dpy
, NULL
, (__GLcontextModes
*) config
, shareList
,
2138 allowDirect
, None
, False
, renderType
);
2145 PUBLIC GLXFBConfigSGIX
2146 glXGetFBConfigFromVisualSGIX(Display
* dpy
, XVisualInfo
* vis
)
2148 __GLXdisplayPrivate
*priv
;
2149 __GLXscreenConfigs
*psc
;
2151 if ((GetGLXPrivScreenConfig(dpy
, vis
->screen
, &priv
, &psc
) != Success
)
2152 && __glXExtensionBitIsEnabled(psc
, SGIX_fbconfig_bit
)
2153 && (psc
->configs
->fbconfigID
!= GLX_DONT_CARE
)) {
2154 return (GLXFBConfigSGIX
) _gl_context_modes_find_visual(psc
->configs
,
2163 ** GLX_SGIX_swap_group
2166 __glXJoinSwapGroupSGIX(Display
* dpy
, GLXDrawable drawable
,
2176 ** GLX_SGIX_swap_barrier
2179 __glXBindSwapBarrierSGIX(Display
* dpy
, GLXDrawable drawable
, int barrier
)
2187 __glXQueryMaxSwapBarriersSGIX(Display
* dpy
, int screen
, int *max
)
2197 ** GLX_OML_sync_control
2200 __glXGetSyncValuesOML(Display
* dpy
, GLXDrawable drawable
,
2201 int64_t * ust
, int64_t * msc
, int64_t * sbc
)
2203 #if defined(__DRI_SWAP_BUFFER_COUNTER) && defined(__DRI_MEDIA_STREAM_COUNTER)
2204 __GLXdisplayPrivate
*const priv
= __glXInitialize(dpy
);
2208 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &i
);
2209 __GLXscreenConfigs
*const psc
= &priv
->screenConfigs
[i
];
2211 assert((pdraw
== NULL
) || (i
!= -1));
2212 return ((pdraw
&& psc
->sbc
&& psc
->msc
)
2213 && ((*psc
->msc
->getMSC
) (psc
->driScreen
, msc
) == 0)
2214 && ((*psc
->sbc
->getSBC
) (pdraw
->driDrawable
, sbc
) == 0)
2215 && (__glXGetUST(ust
) == 0));
2227 #ifdef GLX_DIRECT_RENDERING
2229 __driGetMscRateOML(__DRIdrawable
* draw
,
2230 int32_t * numerator
, int32_t * denominator
, void *private)
2233 __GLXscreenConfigs
*psc
;
2234 XF86VidModeModeLine mode_line
;
2237 __GLXDRIdrawable
*glxDraw
= private;
2240 if (XF86VidModeQueryVersion(psc
->dpy
, &i
, &i
) &&
2241 XF86VidModeGetModeLine(psc
->dpy
, psc
->scr
, &dot_clock
, &mode_line
)) {
2242 unsigned n
= dot_clock
* 1000;
2243 unsigned d
= mode_line
.vtotal
* mode_line
.htotal
;
2245 # define V_INTERLACE 0x010
2246 # define V_DBLSCAN 0x020
2248 if (mode_line
.flags
& V_INTERLACE
)
2250 else if (mode_line
.flags
& V_DBLSCAN
)
2253 /* The OML_sync_control spec requires that if the refresh rate is a
2254 * whole number, that the returned numerator be equal to the refresh
2255 * rate and the denominator be 1.
2263 static const unsigned f
[] = { 13, 11, 7, 5, 3, 2, 0 };
2265 /* This is a poor man's way to reduce a fraction. It's far from
2266 * perfect, but it will work well enough for this situation.
2269 for (i
= 0; f
[i
] != 0; i
++) {
2270 while (n
% f
[i
] == 0 && d
% f
[i
] == 0) {
2291 * Determine the refresh rate of the specified drawable and display.
2293 * \param dpy Display whose refresh rate is to be determined.
2294 * \param drawable Drawable whose refresh rate is to be determined.
2295 * \param numerator Numerator of the refresh rate.
2296 * \param demoninator Denominator of the refresh rate.
2297 * \return If the refresh rate for the specified display and drawable could
2298 * be calculated, True is returned. Otherwise False is returned.
2300 * \note This function is implemented entirely client-side. A lot of other
2301 * functionality is required to export GLX_OML_sync_control, so on
2302 * XFree86 this function can be called for direct-rendering contexts
2303 * when GLX_OML_sync_control appears in the client extension string.
2307 __glXGetMscRateOML(Display
* dpy
, GLXDrawable drawable
,
2308 int32_t * numerator
, int32_t * denominator
)
2310 #if defined( GLX_DIRECT_RENDERING ) && defined( XF86VIDMODE )
2311 __GLXDRIdrawable
*draw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2316 return __driGetMscRateOML(draw
->driDrawable
, numerator
, denominator
, draw
);
2328 __glXSwapBuffersMscOML(Display
* dpy
, GLXDrawable drawable
,
2329 int64_t target_msc
, int64_t divisor
, int64_t remainder
)
2331 #ifdef __DRI_SWAP_BUFFER_COUNTER
2333 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2334 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2336 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2337 * error", but it also says "It [glXSwapBuffersMscOML] will return a value
2338 * of -1 if the function failed because of errors detected in the input
2341 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2343 if (divisor
> 0 && remainder
>= divisor
)
2346 if (pdraw
!= NULL
&& psc
->counters
!= NULL
)
2347 return (*psc
->sbc
->swapBuffersMSC
) (pdraw
->driDrawable
, target_msc
,
2348 divisor
, remainder
);
2362 __glXWaitForMscOML(Display
* dpy
, GLXDrawable drawable
,
2363 int64_t target_msc
, int64_t divisor
,
2364 int64_t remainder
, int64_t * ust
,
2365 int64_t * msc
, int64_t * sbc
)
2367 #ifdef __DRI_MEDIA_STREAM_COUNTER
2369 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2370 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2373 /* The OML_sync_control spec says these should "generate a GLX_BAD_VALUE
2374 * error", but the return type in the spec is Bool.
2376 if (divisor
< 0 || remainder
< 0 || target_msc
< 0)
2378 if (divisor
> 0 && remainder
>= divisor
)
2381 if (pdraw
!= NULL
&& psc
->msc
!= NULL
) {
2382 ret
= (*psc
->msc
->waitForMSC
) (pdraw
->driDrawable
, target_msc
,
2383 divisor
, remainder
, msc
, sbc
);
2385 /* __glXGetUST returns zero on success and non-zero on failure.
2386 * This function returns True on success and False on failure.
2388 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2405 __glXWaitForSbcOML(Display
* dpy
, GLXDrawable drawable
,
2406 int64_t target_sbc
, int64_t * ust
,
2407 int64_t * msc
, int64_t * sbc
)
2409 #ifdef __DRI_SWAP_BUFFER_COUNTER
2411 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2412 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2415 /* The OML_sync_control spec says this should "generate a GLX_BAD_VALUE
2416 * error", but the return type in the spec is Bool.
2421 if (pdraw
!= NULL
&& psc
->sbc
!= NULL
) {
2423 (*psc
->sbc
->waitForSBC
) (pdraw
->driDrawable
, target_sbc
, msc
, sbc
);
2425 /* __glXGetUST returns zero on success and non-zero on failure.
2426 * This function returns True on success and False on failure.
2428 return ((ret
== 0) && (__glXGetUST(ust
) == 0));
2443 * GLX_MESA_allocate_memory
2448 glXAllocateMemoryMESA(Display
* dpy
, int scrn
,
2449 size_t size
, float readFreq
,
2450 float writeFreq
, float priority
)
2452 #ifdef __DRI_ALLOCATE
2453 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2455 if (psc
&& psc
->allocate
)
2456 return (*psc
->allocate
->allocateMemory
) (psc
->__driScreen
, size
,
2457 readFreq
, writeFreq
, priority
);
2466 #endif /* GLX_DIRECT_RENDERING */
2473 glXFreeMemoryMESA(Display
* dpy
, int scrn
, void *pointer
)
2475 #ifdef __DRI_ALLOCATE
2476 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2478 if (psc
&& psc
->allocate
)
2479 (*psc
->allocate
->freeMemory
) (psc
->__driScreen
, pointer
);
2485 #endif /* GLX_DIRECT_RENDERING */
2490 glXGetMemoryOffsetMESA(Display
* dpy
, int scrn
, const void *pointer
)
2492 #ifdef __DRI_ALLOCATE
2493 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, scrn
);
2495 if (psc
&& psc
->allocate
)
2496 return (*psc
->allocate
->memoryOffset
) (psc
->__driScreen
, pointer
);
2502 #endif /* GLX_DIRECT_RENDERING */
2511 * Mesa extension stubs. These will help reduce portability problems.
2516 * Release all buffers associated with the specified GLX drawable.
2519 * This function was intended for stand-alone Mesa. The issue there is that
2520 * the library doesn't get any notification when a window is closed. In
2521 * DRI there is a similar but slightly different issue. When GLX 1.3 is
2522 * supported, there are 3 different functions to destroy a drawable. It
2523 * should be possible to create GLX protocol (or have it determine which
2524 * protocol to use based on the type of the drawable) to have one function
2525 * do the work of 3. For the direct-rendering case, this function could
2526 * just call the driver's \c __DRIdrawableRec::destroyDrawable function.
2527 * This would reduce the frequency with which \c __driGarbageCollectDrawables
2528 * would need to be used. This really should be done as part of the new DRI
2531 * \sa http://oss.sgi.com/projects/ogl-sample/registry/MESA/release_buffers.txt
2532 * __driGarbageCollectDrawables
2533 * glXDestroyGLXPixmap
2534 * glXDestroyPbuffer glXDestroyPixmap glXDestroyWindow
2535 * glXDestroyGLXPbufferSGIX glXDestroyGLXVideoSourceSGIX
2538 __glXReleaseBuffersMESA(Display
* dpy
, GLXDrawable d
)
2547 glXCreateGLXPixmapMESA(Display
* dpy
, XVisualInfo
* visual
,
2548 Pixmap pixmap
, Colormap cmap
)
2561 * GLX_MESA_copy_sub_buffer
2563 #define X_GLXvop_CopySubBufferMESA 5154 /* temporary */
2565 __glXCopySubBufferMESA(Display
* dpy
, GLXDrawable drawable
,
2566 int x
, int y
, int width
, int height
)
2568 xGLXVendorPrivateReq
*req
;
2571 CARD32
*drawable_ptr
;
2572 INT32
*x_ptr
, *y_ptr
, *w_ptr
, *h_ptr
;
2575 #ifdef __DRI_COPY_SUB_BUFFER
2577 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, &screen
);
2578 if (pdraw
!= NULL
) {
2579 __GLXscreenConfigs
*const psc
= GetGLXScreenConfigs(dpy
, screen
);
2580 if (psc
->copySubBuffer
!= NULL
) {
2581 (*psc
->copySubBuffer
->copySubBuffer
) (pdraw
->driDrawable
,
2582 x
, y
, width
, height
);
2589 opcode
= __glXSetupForCommand(dpy
);
2594 ** The calling thread may or may not have a current context. If it
2595 ** does, send the context tag so the server can do a flush.
2597 gc
= __glXGetCurrentContext();
2598 if ((gc
!= NULL
) && (dpy
== gc
->currentDpy
) &&
2599 ((drawable
== gc
->currentDrawable
) ||
2600 (drawable
== gc
->currentReadable
))) {
2601 tag
= gc
->currentContextTag
;
2608 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
) * 4, req
);
2609 req
->reqType
= opcode
;
2610 req
->glxCode
= X_GLXVendorPrivate
;
2611 req
->vendorCode
= X_GLXvop_CopySubBufferMESA
;
2612 req
->contextTag
= tag
;
2614 drawable_ptr
= (CARD32
*) (req
+ 1);
2615 x_ptr
= (INT32
*) (drawable_ptr
+ 1);
2616 y_ptr
= (INT32
*) (drawable_ptr
+ 2);
2617 w_ptr
= (INT32
*) (drawable_ptr
+ 3);
2618 h_ptr
= (INT32
*) (drawable_ptr
+ 4);
2620 *drawable_ptr
= drawable
;
2632 * GLX_EXT_texture_from_pixmap
2636 __glXBindTexImageEXT(Display
* dpy
,
2637 GLXDrawable drawable
, int buffer
, const int *attrib_list
)
2639 xGLXVendorPrivateReq
*req
;
2640 GLXContext gc
= __glXGetCurrentContext();
2641 CARD32
*drawable_ptr
;
2643 CARD32
*num_attrib_ptr
;
2653 while (attrib_list
[i
* 2] != None
)
2657 #ifdef GLX_DIRECT_RENDERING
2658 if (gc
->driContext
) {
2659 __GLXDRIdrawable
*pdraw
= GetGLXDRIDrawable(dpy
, drawable
, NULL
);
2662 (*pdraw
->psc
->texBuffer
->setTexBuffer
) (gc
->__driContext
,
2663 pdraw
->textureTarget
,
2664 pdraw
->driDrawable
);
2670 opcode
= __glXSetupForCommand(dpy
);
2675 GetReqExtra(GLXVendorPrivate
, 12 + 8 * i
, req
);
2676 req
->reqType
= opcode
;
2677 req
->glxCode
= X_GLXVendorPrivate
;
2678 req
->vendorCode
= X_GLXvop_BindTexImageEXT
;
2679 req
->contextTag
= gc
->currentContextTag
;
2681 drawable_ptr
= (CARD32
*) (req
+ 1);
2682 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2683 num_attrib_ptr
= (CARD32
*) (buffer_ptr
+ 1);
2684 attrib_ptr
= (CARD32
*) (num_attrib_ptr
+ 1);
2686 *drawable_ptr
= drawable
;
2687 *buffer_ptr
= buffer
;
2688 *num_attrib_ptr
= (CARD32
) i
;
2692 while (attrib_list
[i
* 2] != None
) {
2693 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 0];
2694 *attrib_ptr
++ = (CARD32
) attrib_list
[i
* 2 + 1];
2704 __glXReleaseTexImageEXT(Display
* dpy
, GLXDrawable drawable
, int buffer
)
2706 xGLXVendorPrivateReq
*req
;
2707 GLXContext gc
= __glXGetCurrentContext();
2708 CARD32
*drawable_ptr
;
2715 #ifdef GLX_DIRECT_RENDERING
2720 opcode
= __glXSetupForCommand(dpy
);
2725 GetReqExtra(GLXVendorPrivate
, sizeof(CARD32
) + sizeof(INT32
), req
);
2726 req
->reqType
= opcode
;
2727 req
->glxCode
= X_GLXVendorPrivate
;
2728 req
->vendorCode
= X_GLXvop_ReleaseTexImageEXT
;
2729 req
->contextTag
= gc
->currentContextTag
;
2731 drawable_ptr
= (CARD32
*) (req
+ 1);
2732 buffer_ptr
= (INT32
*) (drawable_ptr
+ 1);
2734 *drawable_ptr
= drawable
;
2735 *buffer_ptr
= buffer
;
2744 * \c strdup is actually not a standard ANSI C or POSIX routine.
2745 * Irix will not define it if ANSI mode is in effect.
2750 __glXstrdup(const char *str
)
2753 copy
= (char *) Xmalloc(strlen(str
) + 1);
2761 ** glXGetProcAddress support
2764 struct name_address_pair
2770 #define GLX_FUNCTION(f) { # f, (GLvoid *) f }
2771 #define GLX_FUNCTION2(n,f) { # n, (GLvoid *) f }
2773 static const struct name_address_pair GLX_functions
[] = {
2774 /*** GLX_VERSION_1_0 ***/
2775 GLX_FUNCTION( glXChooseVisual
),
2776 GLX_FUNCTION( glXCopyContext
),
2777 GLX_FUNCTION( glXCreateContext
),
2778 GLX_FUNCTION( glXCreateGLXPixmap
),
2779 GLX_FUNCTION( glXDestroyContext
),
2780 GLX_FUNCTION( glXDestroyGLXPixmap
),
2781 GLX_FUNCTION( glXGetConfig
),
2782 GLX_FUNCTION( glXGetCurrentContext
),
2783 GLX_FUNCTION( glXGetCurrentDrawable
),
2784 GLX_FUNCTION( glXIsDirect
),
2785 GLX_FUNCTION( glXMakeCurrent
),
2786 GLX_FUNCTION( glXQueryExtension
),
2787 GLX_FUNCTION( glXQueryVersion
),
2788 GLX_FUNCTION( glXSwapBuffers
),
2789 GLX_FUNCTION( glXUseXFont
),
2790 GLX_FUNCTION( glXWaitGL
),
2791 GLX_FUNCTION( glXWaitX
),
2793 /*** GLX_VERSION_1_1 ***/
2794 GLX_FUNCTION( glXGetClientString
),
2795 GLX_FUNCTION( glXQueryExtensionsString
),
2796 GLX_FUNCTION( glXQueryServerString
),
2798 /*** GLX_VERSION_1_2 ***/
2799 GLX_FUNCTION( glXGetCurrentDisplay
),
2801 /*** GLX_VERSION_1_3 ***/
2802 GLX_FUNCTION( glXChooseFBConfig
),
2803 GLX_FUNCTION( glXCreateNewContext
),
2804 GLX_FUNCTION( glXCreatePbuffer
),
2805 GLX_FUNCTION( glXCreatePixmap
),
2806 GLX_FUNCTION( glXCreateWindow
),
2807 GLX_FUNCTION( glXDestroyPbuffer
),
2808 GLX_FUNCTION( glXDestroyPixmap
),
2809 GLX_FUNCTION( glXDestroyWindow
),
2810 GLX_FUNCTION( glXGetCurrentReadDrawable
),
2811 GLX_FUNCTION( glXGetFBConfigAttrib
),
2812 GLX_FUNCTION( glXGetFBConfigs
),
2813 GLX_FUNCTION( glXGetSelectedEvent
),
2814 GLX_FUNCTION( glXGetVisualFromFBConfig
),
2815 GLX_FUNCTION( glXMakeContextCurrent
),
2816 GLX_FUNCTION( glXQueryContext
),
2817 GLX_FUNCTION( glXQueryDrawable
),
2818 GLX_FUNCTION( glXSelectEvent
),
2820 /*** GLX_SGI_swap_control ***/
2821 GLX_FUNCTION2( glXSwapIntervalSGI
, __glXSwapIntervalSGI
),
2823 /*** GLX_SGI_video_sync ***/
2824 GLX_FUNCTION2( glXGetVideoSyncSGI
, __glXGetVideoSyncSGI
),
2825 GLX_FUNCTION2( glXWaitVideoSyncSGI
, __glXWaitVideoSyncSGI
),
2827 /*** GLX_SGI_make_current_read ***/
2828 GLX_FUNCTION2( glXMakeCurrentReadSGI
, glXMakeContextCurrent
),
2829 GLX_FUNCTION2( glXGetCurrentReadDrawableSGI
, glXGetCurrentReadDrawable
),
2831 /*** GLX_EXT_import_context ***/
2832 GLX_FUNCTION( glXFreeContextEXT
),
2833 GLX_FUNCTION( glXGetContextIDEXT
),
2834 GLX_FUNCTION2( glXGetCurrentDisplayEXT
, glXGetCurrentDisplay
),
2835 GLX_FUNCTION( glXImportContextEXT
),
2836 GLX_FUNCTION2( glXQueryContextInfoEXT
, glXQueryContext
),
2838 /*** GLX_SGIX_fbconfig ***/
2839 GLX_FUNCTION2( glXGetFBConfigAttribSGIX
, glXGetFBConfigAttrib
),
2840 GLX_FUNCTION2( glXChooseFBConfigSGIX
, glXChooseFBConfig
),
2841 GLX_FUNCTION( glXCreateGLXPixmapWithConfigSGIX
),
2842 GLX_FUNCTION( glXCreateContextWithConfigSGIX
),
2843 GLX_FUNCTION2( glXGetVisualFromFBConfigSGIX
, glXGetVisualFromFBConfig
),
2844 GLX_FUNCTION( glXGetFBConfigFromVisualSGIX
),
2846 /*** GLX_SGIX_pbuffer ***/
2847 GLX_FUNCTION( glXCreateGLXPbufferSGIX
),
2848 GLX_FUNCTION( glXDestroyGLXPbufferSGIX
),
2849 GLX_FUNCTION( glXQueryGLXPbufferSGIX
),
2850 GLX_FUNCTION( glXSelectEventSGIX
),
2851 GLX_FUNCTION( glXGetSelectedEventSGIX
),
2853 /*** GLX_SGIX_swap_group ***/
2854 GLX_FUNCTION2( glXJoinSwapGroupSGIX
, __glXJoinSwapGroupSGIX
),
2856 /*** GLX_SGIX_swap_barrier ***/
2857 GLX_FUNCTION2( glXBindSwapBarrierSGIX
, __glXBindSwapBarrierSGIX
),
2858 GLX_FUNCTION2( glXQueryMaxSwapBarriersSGIX
, __glXQueryMaxSwapBarriersSGIX
),
2860 /*** GLX_MESA_allocate_memory ***/
2861 GLX_FUNCTION( glXAllocateMemoryMESA
),
2862 GLX_FUNCTION( glXFreeMemoryMESA
),
2863 GLX_FUNCTION( glXGetMemoryOffsetMESA
),
2865 /*** GLX_MESA_copy_sub_buffer ***/
2866 GLX_FUNCTION2( glXCopySubBufferMESA
, __glXCopySubBufferMESA
),
2868 /*** GLX_MESA_pixmap_colormap ***/
2869 GLX_FUNCTION( glXCreateGLXPixmapMESA
),
2871 /*** GLX_MESA_release_buffers ***/
2872 GLX_FUNCTION2( glXReleaseBuffersMESA
, __glXReleaseBuffersMESA
),
2874 /*** GLX_MESA_swap_control ***/
2875 GLX_FUNCTION2( glXSwapIntervalMESA
, __glXSwapIntervalMESA
),
2876 GLX_FUNCTION2( glXGetSwapIntervalMESA
, __glXGetSwapIntervalMESA
),
2878 /*** GLX_MESA_swap_frame_usage ***/
2879 GLX_FUNCTION2( glXBeginFrameTrackingMESA
, __glXBeginFrameTrackingMESA
),
2880 GLX_FUNCTION2( glXEndFrameTrackingMESA
, __glXEndFrameTrackingMESA
),
2881 GLX_FUNCTION2( glXGetFrameUsageMESA
, __glXGetFrameUsageMESA
),
2882 GLX_FUNCTION2( glXQueryFrameTrackingMESA
, __glXQueryFrameTrackingMESA
),
2884 /*** GLX_ARB_get_proc_address ***/
2885 GLX_FUNCTION( glXGetProcAddressARB
),
2888 GLX_FUNCTION2( glXGetProcAddress
, glXGetProcAddressARB
),
2890 /*** GLX_OML_sync_control ***/
2891 GLX_FUNCTION2( glXWaitForSbcOML
, __glXWaitForSbcOML
),
2892 GLX_FUNCTION2( glXWaitForMscOML
, __glXWaitForMscOML
),
2893 GLX_FUNCTION2( glXSwapBuffersMscOML
, __glXSwapBuffersMscOML
),
2894 GLX_FUNCTION2( glXGetMscRateOML
, __glXGetMscRateOML
),
2895 GLX_FUNCTION2( glXGetSyncValuesOML
, __glXGetSyncValuesOML
),
2897 /*** GLX_EXT_texture_from_pixmap ***/
2898 GLX_FUNCTION2( glXBindTexImageEXT
, __glXBindTexImageEXT
),
2899 GLX_FUNCTION2( glXReleaseTexImageEXT
, __glXReleaseTexImageEXT
),
2901 #ifdef GLX_DIRECT_RENDERING
2902 /*** DRI configuration ***/
2903 GLX_FUNCTION( glXGetScreenDriver
),
2904 GLX_FUNCTION( glXGetDriverConfig
),
2907 { NULL
, NULL
} /* end of list */
2910 static const GLvoid
*
2911 get_glx_proc_address(const char *funcName
)
2915 /* try static functions */
2916 for (i
= 0; GLX_functions
[i
].Name
; i
++) {
2917 if (strcmp(GLX_functions
[i
].Name
, funcName
) == 0)
2918 return GLX_functions
[i
].Address
;
2926 * Get the address of a named GL function. This is the pre-GLX 1.4 name for
2927 * \c glXGetProcAddress.
2929 * \param procName Name of a GL or GLX function.
2930 * \returns A pointer to the named function
2932 * \sa glXGetProcAddress
2934 PUBLIC
void (*glXGetProcAddressARB(const GLubyte
* procName
)) (void)
2936 typedef void (*gl_function
) (void);
2940 /* Search the table of GLX and internal functions first. If that
2941 * fails and the supplied name could be a valid core GL name, try
2942 * searching the core GL function table. This check is done to prevent
2943 * DRI based drivers from searching the core GL function table for
2944 * internal API functions.
2947 f
= (gl_function
) get_glx_proc_address((const char *) procName
);
2948 if ((f
== NULL
) && (procName
[0] == 'g') && (procName
[1] == 'l')
2949 && (procName
[2] != 'X')) {
2950 f
= (gl_function
) _glapi_get_proc_address((const char *) procName
);
2957 * Get the address of a named GL function. This is the GLX 1.4 name for
2958 * \c glXGetProcAddressARB.
2960 * \param procName Name of a GL or GLX function.
2961 * \returns A pointer to the named function
2963 * \sa glXGetProcAddressARB
2965 PUBLIC
void (*glXGetProcAddress(const GLubyte
* procName
)) (void)
2966 #if defined(__GNUC__) && !defined(GLX_ALIAS_UNSUPPORTED)
2967 __attribute__ ((alias("glXGetProcAddressARB")));
2970 return glXGetProcAddressARB(procName
);
2972 #endif /* __GNUC__ */
2975 #ifdef GLX_DIRECT_RENDERING
2977 * Get the unadjusted system time (UST). Currently, the UST is measured in
2978 * microseconds since Epoc. The actual resolution of the UST may vary from
2979 * system to system, and the units may vary from release to release.
2980 * Drivers should not call this function directly. They should instead use
2981 * \c glXGetProcAddress to obtain a pointer to the function.
2983 * \param ust Location to store the 64-bit UST
2984 * \returns Zero on success or a negative errno value on failure.
2986 * \sa glXGetProcAddress, PFNGLXGETUSTPROC
2988 * \since Internal API version 20030317.
2991 __glXGetUST(int64_t * ust
)
2999 if (gettimeofday(&tv
, NULL
) == 0) {
3000 ust
[0] = (tv
.tv_sec
* 1000000) + tv
.tv_usec
;
3007 #endif /* GLX_DIRECT_RENDERING */