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 * Direct rendering support added by Precision Insight, Inc.
35 * \author Kevin E. Martin <kevin@precisioninsight.com>
38 #ifndef _GLX_client_h_
39 #define _GLX_client_h_
40 #include <X11/Xproto.h>
41 #include <X11/Xlibint.h>
42 #include <X11/extensions/extutil.h>
43 #define GLX_GLXEXT_PROTOTYPES
45 #include <GL/glxext.h>
52 #include "GL/glxint.h"
53 #include "GL/glxproto.h"
54 #include "GL/internal/glcore.h"
55 #include "glapi/glapitable.h"
57 #if defined( PTHREADS )
61 #include "glxextensions.h"
64 /* If we build the library with gcc's -fvisibility=hidden flag, we'll
65 * use the PUBLIC macro to mark functions that are to be exported.
67 * We also need to define a USED attribute, so the optimizer doesn't
68 * inline a static function that we later use in an alias. - ajax
71 # define PUBLIC __attribute__((visibility("default")))
72 # define USED __attribute__((used))
80 #define GLX_MAJOR_VERSION 1 /* current version numbers */
81 #define GLX_MINOR_VERSION 4
83 #define __GLX_MAX_TEXTURE_UNITS 32
85 typedef struct __GLXscreenConfigsRec __GLXscreenConfigs;
86 typedef struct __GLXcontextRec __GLXcontext;
87 typedef struct __GLXdrawableRec __GLXdrawable;
88 typedef struct __GLXdisplayPrivateRec __GLXdisplayPrivate;
89 typedef struct _glapi_table __GLapi;
91 /************************************************************************/
93 #ifdef GLX_DIRECT_RENDERING
95 #define containerOf(ptr, type, member) \
96 (type *)( (char *)ptr - offsetof(type,member) )
98 extern void DRI_glXUseXFont(Font font, int first, int count, int listbase);
102 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
104 #include <GL/internal/dri_interface.h>
107 * Display dependent methods. This structure is initialized during the
108 * \c driCreateDisplay call.
110 typedef struct __GLXDRIdisplayRec __GLXDRIdisplay;
111 typedef struct __GLXDRIscreenRec __GLXDRIscreen;
112 typedef struct __GLXDRIdrawableRec __GLXDRIdrawable;
113 typedef struct __GLXDRIcontextRec __GLXDRIcontext;
115 #include "glxextensions.h"
117 struct __GLXDRIdisplayRec
120 * Method to destroy the private DRI display data.
122 void (*destroyDisplay) (__GLXDRIdisplay * display);
124 __GLXscreenConfigs *(*createScreen)(int screen, __GLXdisplayPrivate * priv);
127 struct __GLXDRIscreenRec {
129 void (*destroyScreen)(__GLXscreenConfigs *psc);
131 __GLXDRIcontext *(*createContext)(__GLXscreenConfigs *psc,
132 const __GLcontextModes *mode,
134 GLXContext shareList, int renderType);
136 __GLXDRIdrawable *(*createDrawable)(__GLXscreenConfigs *psc,
138 GLXDrawable glxDrawable,
139 const __GLcontextModes *modes);
141 int64_t (*swapBuffers)(__GLXDRIdrawable *pdraw, int64_t target_msc,
142 int64_t divisor, int64_t remainder);
143 void (*copySubBuffer)(__GLXDRIdrawable *pdraw,
144 int x, int y, int width, int height);
145 void (*waitX)(__GLXDRIdrawable *pdraw);
146 void (*waitGL)(__GLXDRIdrawable *pdraw);
147 int (*getDrawableMSC)(__GLXscreenConfigs *psc, __GLXDRIdrawable *pdraw,
148 int64_t *ust, int64_t *msc, int64_t *sbc);
149 int (*waitForMSC)(__GLXDRIdrawable *pdraw, int64_t target_msc,
150 int64_t divisor, int64_t remainder, int64_t *ust,
151 int64_t *msc, int64_t *sbc);
152 int (*waitForSBC)(__GLXDRIdrawable *pdraw, int64_t target_sbc, int64_t *ust,
153 int64_t *msc, int64_t *sbc);
154 void (*setSwapInterval)(__GLXDRIdrawable *pdraw, int interval);
155 int (*getSwapInterval)(__GLXDRIdrawable *pdraw);
158 struct __GLXDRIcontextRec
160 void (*destroyContext) (__GLXDRIcontext * context,
161 __GLXscreenConfigs * psc, Display * dpy);
162 Bool(*bindContext) (__GLXDRIcontext * context, __GLXDRIdrawable * pdraw,
163 __GLXDRIdrawable * pread);
165 void (*unbindContext) (__GLXDRIcontext * context);
168 struct __GLXDRIdrawableRec
170 void (*destroyDrawable) (__GLXDRIdrawable * drawable);
174 __GLXscreenConfigs *psc;
175 GLenum textureTarget;
176 __DRIdrawable *driDrawable;
177 GLenum textureFormat; /* EXT_texture_from_pixmap support */
178 unsigned long eventMask;
182 ** Function to create and DRI display data and initialize the display
183 ** dependent methods.
185 extern __GLXDRIdisplay *driswCreateDisplay(Display * dpy);
186 extern __GLXDRIdisplay *driCreateDisplay(Display * dpy);
187 extern __GLXDRIdisplay *dri2CreateDisplay(Display * dpy);
188 extern void dri2InvalidateBuffers(Display *dpy, XID drawable);
192 ** Functions to obtain driver configuration information from a direct
193 ** rendering client application
195 extern const char *glXGetScreenDriver(Display * dpy, int scrNum);
197 extern const char *glXGetDriverConfig(const char *driverName);
201 /************************************************************************/
203 #define __GL_CLIENT_ATTRIB_STACK_DEPTH 16
205 typedef struct __GLXpixelStoreModeRec
207 GLboolean swapEndian;
216 } __GLXpixelStoreMode;
219 typedef struct __GLXattributeRec
224 * Pixel storage state. Most of the pixel store mode state is kept
225 * here and used by the client code to manage the packing and
226 * unpacking of data sent to/received from the server.
228 __GLXpixelStoreMode storePack, storeUnpack;
231 * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically
234 GLboolean NoDrawArraysProtocol;
237 * Vertex Array storage state. The vertex array component
238 * state is stored here and is used to manage the packing of
239 * DrawArrays data sent to the server.
241 struct array_state_vector *array_state;
244 typedef struct __GLXattributeMachineRec
246 __GLXattribute *stack[__GL_CLIENT_ATTRIB_STACK_DEPTH];
247 __GLXattribute **stackPointer;
248 } __GLXattributeMachine;
250 struct glx_context_vtable {
251 void (*bind_tex_image)(Display * dpy,
252 GLXDrawable drawable,
253 int buffer, const int *attrib_list);
254 void (*release_tex_image)(Display * dpy, GLXDrawable drawable, int buffer);
259 * GLX state that needs to be kept on the client. One of these records
260 * exist for each context that has been made current by this client.
262 struct __GLXcontextRec
265 * \name Drawing command buffer.
267 * Drawing commands are packed into this buffer before being sent as a
268 * single GLX protocol request. The buffer is sent when it overflows or
269 * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location
270 * in the buffer to be filled. \c limit is described above in the buffer
273 * Commands that require large amounts of data to be transfered will
274 * also use this buffer to hold a header that describes the large
277 * These must be the first 6 fields since they are static initialized
278 * in the dummy context in glxext.c
289 * The XID of this rendering context. When the context is created a
290 * new XID is allocated. This is set to None when the context is
291 * destroyed but is still current to some thread. In this case the
292 * context will be freed on next MakeCurrent.
297 * The XID of the \c shareList context.
305 __GLXscreenConfigs *psc;
308 * \c GL_TRUE if the context was created with ImportContext, which
309 * means the server-side context was created by another X client.
314 * The context tag returned by MakeCurrent when this context is made
315 * current. This tag is used to identify the context that a thread has
316 * current so that proper server context management can be done. It is
317 * used for all context specific commands (i.e., \c Render, \c RenderLarge,
318 * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old
321 GLXContextTag currentContextTag;
324 * \name Rendering mode
326 * The rendering mode is kept on the client as well as the server.
327 * When \c glRenderMode is called, the buffer associated with the
328 * previous rendering mode (feedback or select) is filled.
332 GLfloat *feedbackBuf;
337 * This is \c GL_TRUE if the pixel unpack modes are such that an image
338 * can be unpacked from the clients memory by just copying. It may
339 * still be true that the server will have to do some work. This
340 * just promises that a straight copy will fetch the correct bytes.
342 GLboolean fastImageUnpack;
345 * Fill newImage with the unpacked form of \c oldImage getting it
346 * ready for transport to the server.
348 void (*fillImage) (__GLXcontext *, GLint, GLint, GLint, GLint, GLenum,
349 GLenum, const GLvoid *, GLubyte *, GLubyte *);
352 * Client side attribs.
354 __GLXattributeMachine attributes;
357 * Client side error code. This is set when client side gl API
358 * routines need to set an error because of a bad enumerant or
359 * running out of memory, etc.
364 * Whether this context does direct rendering.
369 * \c dpy of current display for this context. Will be \c NULL if not
370 * current to any display, or if this is the "dummy context".
375 * The current drawable for this context. Will be None if this
376 * context is not current to any drawable. currentReadable is below.
378 GLXDrawable currentDrawable;
381 * \name GL Constant Strings
383 * Constant strings that describe the server implementation
384 * These pertain to GL attributes, not to be confused with
385 * GLX versioning attributes.
395 * Record the dpy this context was created on for later freeing
400 * Maximum small render command size. This is the smaller of 64k and
401 * the size of the above buffer.
403 GLint maxSmallRenderCommandSize;
406 * Major opcode for the extension. Copied here so a lookup isn't
412 * Pointer to the mode used to create this context.
414 const __GLcontextModes *mode;
416 #ifdef GLX_DIRECT_RENDERING
417 #ifdef GLX_USE_APPLEGL
421 __GLXDRIcontext *driContext;
422 __DRIcontext *__driContext;
427 * The current read-drawable for this context. Will be None if this
428 * context is not current to any drawable.
430 * \since Internal API version 20030606.
432 GLXDrawable currentReadable;
435 * Pointer to client-state data that is private to libGL. This is only
436 * used for indirect rendering contexts.
438 * No internal API version change was made for this change. Client-side
439 * drivers should NEVER use this data or even care that it exists.
441 void *client_state_private;
444 * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE.
449 * \name Raw server GL version
451 * True core GL version supported by the server. This is the raw value
452 * returned by the server, and it may not reflect what is actually
453 * supported (or reported) by the client-side library.
456 int server_major; /**< Major version number. */
457 int server_minor; /**< Minor version number. */
461 * Thread ID we're currently current in. Zero if none.
463 unsigned long thread_id;
465 char gl_extension_bits[__GL_EXT_BYTES];
467 const struct glx_context_vtable *vtable;
470 #define __glXSetError(gc,code) \
471 if (!(gc)->error) { \
472 (gc)->error = code; \
475 extern void __glFreeAttributeState(__GLXcontext *);
477 /************************************************************************/
480 * The size of the largest drawing command known to the implementation
481 * that will use the GLXRender GLX command. In this case it is
482 * \c glPolygonStipple.
484 #define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156
487 * To keep the implementation fast, the code uses a "limit" pointer
488 * to determine when the drawing command buffer is too full to hold
489 * another fixed size command. This constant defines the amount of
490 * space that must always be available in the drawing command buffer
491 * at all times for the implementation to work. It is important that
492 * the number be just large enough, but not so large as to reduce the
493 * efficacy of the buffer. The "+32" is just to keep the code working
494 * in case somebody counts wrong.
496 #define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32)
499 * This implementation uses a smaller threshold for switching
500 * to the RenderLarge protocol than the protcol requires so that
501 * large copies don't occur.
503 #define __GLX_RENDER_CMD_SIZE_LIMIT 4096
506 * One of these records exists per screen of the display. It contains
507 * a pointer to the config data for that screen (if the screen supports GL).
509 struct __GLXscreenConfigsRec
512 * GLX extension string reported by the X-server.
514 const char *serverGLXexts;
517 * GLX extension string to be reported to applications. This is the
518 * set of extensions that the application can actually use.
520 char *effectiveGLXexts;
523 * Context vtable to use for direct contexts on this screen
525 const struct glx_context_vtable *direct_context_vtable;
527 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
529 * Per screen direct rendering interface functions and data.
531 __DRIscreen *__driScreen;
532 __glxHashTable *drawHash;
536 __GLXDRIscreen *driScreen;
538 const __DRIconfig **driver_configs;
540 #ifdef __DRI_COPY_SUB_BUFFER
541 const __DRIcopySubBufferExtension *driCopySubBuffer;
544 #ifdef __DRI_SWAP_CONTROL
545 const __DRIswapControlExtension *swapControl;
548 #ifdef __DRI_FRAME_TRACKING
549 const __DRIframeTrackingExtension *frameTracking;
552 #ifdef __DRI_MEDIA_STREAM_COUNTER
553 const __DRImediaStreamCounterExtension *msc;
556 #ifdef __DRI_TEX_BUFFER
557 const __DRItexBufferExtension *texBuffer;
561 const __DRI2flushExtension *f;
564 #ifdef __DRI2_CONFIG_QUERY
565 const __DRI2configQueryExtension *config;
571 * Linked list of glx visuals and fbconfigs for this screen.
573 __GLcontextModes *visuals, *configs;
576 * Per-screen dynamic GLX extension tracking. The \c direct_support
577 * field only contains enough bits for 64 extensions. Should libGL
578 * ever need to track more than 64 GLX extensions, we can safely grow
579 * this field. The \c __GLXscreenConfigs structure is not used outside
583 unsigned char direct_support[8];
584 GLboolean ext_list_first_time;
590 * Per display private data. One of these records exists for each display
591 * that is using the OpenGL (GLX) extension.
593 struct __GLXdisplayPrivateRec
596 * Back pointer to the display
601 * The \c majorOpcode is common to all connections to the same server.
602 * It is also copied into the context structure.
607 * \name Server Version
609 * Major and minor version returned by the server during initialization.
612 int majorVersion, minorVersion;
616 * \name Storage for the servers GLX vendor and versions strings.
618 * These are the same for all screens on this display. These fields will
619 * be filled in on demand.
622 const char *serverGLXvendor;
623 const char *serverGLXversion;
627 * Configurations of visuals for all screens on this display.
628 * Also, per screen data which now includes the server \c GLX_EXTENSION
631 __GLXscreenConfigs **screenConfigs;
633 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
635 * Per display direct rendering interface functions and data.
637 __GLXDRIdisplay *driswDisplay;
638 __GLXDRIdisplay *driDisplay;
639 __GLXDRIdisplay *dri2Display;
644 glx_screen_init(__GLXscreenConfigs *psc,
645 int screen, __GLXdisplayPrivate * priv);
647 extern __GLXDRIdrawable *
648 dri2GetGlxDrawableFromXDrawableId(Display *dpy, XID id);
650 extern GLubyte *__glXFlushRenderBuffer(__GLXcontext *, GLubyte *);
652 extern void __glXSendLargeChunk(__GLXcontext * gc, GLint requestNumber,
654 const GLvoid * data, GLint dataLen);
656 extern void __glXSendLargeCommand(__GLXcontext *, const GLvoid *, GLint,
657 const GLvoid *, GLint);
659 /* Initialize the GLX extension for dpy */
660 extern __GLXdisplayPrivate *__glXInitialize(Display *);
662 extern void __glXPreferEGL(int state);
664 /************************************************************************/
666 extern int __glXDebug;
668 /* This is per-thread storage in an MT environment */
669 #if defined( PTHREADS )
671 extern void __glXSetCurrentContext(__GLXcontext * c);
673 # if defined( GLX_USE_TLS )
675 extern __thread void *__glX_tls_Context
676 __attribute__ ((tls_model("initial-exec")));
678 # define __glXGetCurrentContext() __glX_tls_Context
682 extern __GLXcontext *__glXGetCurrentContext(void);
684 # endif /* defined( GLX_USE_TLS ) */
688 extern __GLXcontext *__glXcurrentContext;
689 #define __glXGetCurrentContext() __glXcurrentContext
690 #define __glXSetCurrentContext(gc) __glXcurrentContext = gc
692 #endif /* defined( PTHREADS ) */
694 extern void __glXSetCurrentContextNull(void);
696 extern void __glXFreeContext(__GLXcontext *);
700 ** Global lock for all threads in this address space using the GLX
703 #if defined( PTHREADS )
704 extern pthread_mutex_t __glXmutex;
705 #define __glXLock() pthread_mutex_lock(&__glXmutex)
706 #define __glXUnlock() pthread_mutex_unlock(&__glXmutex)
709 #define __glXUnlock()
713 ** Setup for a command. Initialize the extension for dpy if necessary.
715 extern CARD8 __glXSetupForCommand(Display * dpy);
717 /************************************************************************/
720 ** Data conversion and packing support.
723 extern const GLuint __glXDefaultPixelStore[9];
725 /* Send an image to the server using RenderLarge. */
726 extern void __glXSendLargeImage(__GLXcontext * gc, GLint compsize, GLint dim,
727 GLint width, GLint height, GLint depth,
728 GLenum format, GLenum type,
729 const GLvoid * src, GLubyte * pc,
732 /* Return the size, in bytes, of some pixel data */
733 extern GLint __glImageSize(GLint, GLint, GLint, GLenum, GLenum, GLenum);
735 /* Return the number of elements per group of a specified format*/
736 extern GLint __glElementsPerGroup(GLenum format, GLenum type);
738 /* Return the number of bytes per element, based on the element type (other
741 extern GLint __glBytesPerElement(GLenum type);
744 ** Fill the transport buffer with the data from the users buffer,
745 ** applying some of the pixel store modes (unpack modes) to the data
746 ** first. As a side effect of this call, the "modes" field is
747 ** updated to contain the modes needed by the server to decode the
750 extern void __glFillImage(__GLXcontext *, GLint, GLint, GLint, GLint, GLenum,
751 GLenum, const GLvoid *, GLubyte *, GLubyte *);
753 /* Copy map data with a stride into a packed buffer */
754 extern void __glFillMap1f(GLint, GLint, GLint, const GLfloat *, GLubyte *);
755 extern void __glFillMap1d(GLint, GLint, GLint, const GLdouble *, GLubyte *);
756 extern void __glFillMap2f(GLint, GLint, GLint, GLint, GLint,
757 const GLfloat *, GLfloat *);
758 extern void __glFillMap2d(GLint, GLint, GLint, GLint, GLint,
759 const GLdouble *, GLdouble *);
762 ** Empty an image out of the reply buffer into the clients memory applying
763 ** the pack modes to pack back into the clients requested format.
765 extern void __glEmptyImage(__GLXcontext *, GLint, GLint, GLint, GLint, GLenum,
766 GLenum, const GLubyte *, GLvoid *);
770 ** Allocate and Initialize Vertex Array client state, and free.
772 extern void __glXInitVertexArrayState(__GLXcontext *);
773 extern void __glXFreeVertexArrayState(__GLXcontext *);
776 ** Inform the Server of the major and minor numbers and of the client
777 ** libraries extension string.
779 extern void __glXClientInfo(Display * dpy, int opcode);
781 /************************************************************************/
784 ** Declarations that should be in Xlib
786 #ifdef __GL_USE_OUR_PROTOTYPES
787 extern void _XFlush(Display *);
788 extern Status _XReply(Display *, xReply *, int, Bool);
789 extern void _XRead(Display *, void *, long);
790 extern void _XSend(Display *, const void *, long);
794 extern void __glXInitializeVisualConfigFromTags(__GLcontextModes * config,
795 int count, const INT32 * bp,
797 Bool fbconfig_style_tags);
799 extern char *__glXQueryServerString(Display * dpy, int opcode,
800 CARD32 screen, CARD32 name);
801 extern char *__glXGetString(Display * dpy, int opcode,
802 CARD32 screen, CARD32 name);
804 extern char *__glXstrdup(const char *str);
807 extern const char __glXGLClientVersion[];
808 extern const char __glXGLClientExtensions[];
810 /* Get the unadjusted system time */
811 extern int __glXGetUST(int64_t * ust);
813 extern GLboolean __glXGetMscRateOML(Display * dpy, GLXDrawable drawable,
815 int32_t * denominator);
817 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
819 __driGetMscRateOML(__DRIdrawable * draw,
820 int32_t * numerator, int32_t * denominator, void *private);
822 /* So that dri2.c:DRI2WireToEvent() can access
823 * glx_info->codes->first_event */
824 XExtDisplayInfo *__glXFindDisplay (Display *dpy);
826 extern __GLXDRIdrawable *
827 GetGLXDRIDrawable(Display *dpy, GLXDrawable drawable, int *const scrn_num);
831 #endif /* !__GLX_client_h__ */