2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
34 /* $XFree86: xc/lib/GL/glx/glxclient.h,v 1.21 2004/02/09 23:46:31 alanh Exp $ */
38 * Direct rendering support added by Precision Insight, Inc.
40 * \author Kevin E. Martin <kevin@precisioninsight.com>
43 #ifndef _GLX_client_h_
44 #define _GLX_client_h_
47 #include <X11/Xproto.h>
48 #include <X11/Xlibint.h>
49 #define GLX_GLXEXT_PROTOTYPES
51 #include <GL/glxext.h>
58 #include "GL/glxint.h"
59 #include "GL/glxproto.h"
60 #include "GL/internal/glcore.h"
61 #include "glapitable.h"
65 #ifdef GLX_BUILT_IN_XMESA
66 #include "realglx.h" /* just silences prototype warnings */
69 #define GLX_MAJOR_VERSION 1 /* current version numbers */
70 #define GLX_MINOR_VERSION 4
72 #define __GLX_MAX_TEXTURE_UNITS 32
74 typedef struct __GLXcontextRec __GLXcontext
;
75 typedef struct __GLXdisplayPrivateRec __GLXdisplayPrivate
;
76 typedef struct _glapi_table __GLapi
;
78 /************************************************************************/
80 #ifdef GLX_DIRECT_RENDERING
82 #include <GL/internal/dri_interface.h>
84 typedef void *(*CreateScreenFunc
)(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
85 int numConfigs
, __GLXvisualConfig
*config
);
87 typedef void *(*CreateNewScreenFunc
)(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
88 const __GLcontextModes
* modes
, const __DRIversion
* ddx_version
,
89 const __DRIversion
* dri_version
, const __DRIversion
* drm_version
,
90 const __DRIframebuffer
* frame_buffer
, void * pSAREA
,
91 int fd
, int internal_api_version
, __GLcontextModes
** driver_modes
);
95 * Display dependent methods. This structure is initialized during the
96 * \c driCreateDisplay call.
98 struct __DRIdisplayRec
{
100 * Method to destroy the private DRI display data.
102 void (*destroyDisplay
)(Display
*dpy
, void *displayPrivate
);
105 * Methods to create the private DRI screen data and initialize the
106 * screen dependent methods.
107 * This is an array [indexed by screen number] of function pointers.
109 * \deprecated This array of function pointers has been replaced by
110 * \c __DRIdisplayRec::createNewScreen.
111 * \sa __DRIdisplayRec::createNewScreen
113 CreateScreenFunc
* createScreen
;
116 * Opaque pointer to private per display direct rendering data.
117 * \c NULL if direct rendering is not supported on this display.
119 struct __DRIdisplayPrivateRec
*private;
122 * Array of pointers to methods to create and initialize the private DRI
125 * \sa __DRIdisplayRec::createScreen
127 CreateNewScreenFunc
* createNewScreen
;
132 ** We keep a linked list of these structures, one per DRI device driver.
134 struct __DRIdriverRec
{
137 CreateScreenFunc createScreenFunc
;
138 CreateNewScreenFunc createNewScreenFunc
;
139 struct __DRIdriverRec
*next
;
143 ** Function to create and DRI display data and initialize the display
144 ** dependent methods.
146 extern void *driCreateDisplay(Display
*dpy
, __DRIdisplay
*pdisp
);
148 extern __DRIdriver
*driGetDriver(Display
*dpy
, int scrNum
);
150 extern void DRI_glXUseXFont( Font font
, int first
, int count
, int listbase
);
153 ** Functions to obtain driver configuration information from a direct
154 ** rendering client application
156 extern const char *glXGetScreenDriver (Display
*dpy
, int scrNum
);
158 extern const char *glXGetDriverConfig (const char *driverName
);
162 /************************************************************************/
164 #define __GL_CLIENT_ATTRIB_STACK_DEPTH 16
166 typedef struct __GLXpixelStoreModeRec
{
167 GLboolean swapEndian
;
176 } __GLXpixelStoreMode
;
178 /* The next 3 structures are deprecated. Client state is no longer tracked
179 * using them. They only remain to maintain the layout / structure offset of
180 * __GLXcontextRec. In XFree86 5.0 they will be removed altogether.
183 typedef struct __GLXvertexArrayPointerStateRecDEPRECATED
{
185 void (*proc
)(const void *);
191 } __GLXvertexArrayPointerStateDEPRECATED
;
193 typedef struct __GLXvertArrayStateRecDEPRECATED
{
194 __GLXvertexArrayPointerStateDEPRECATED vertex
;
195 __GLXvertexArrayPointerStateDEPRECATED normal
;
196 __GLXvertexArrayPointerStateDEPRECATED color
;
197 __GLXvertexArrayPointerStateDEPRECATED index
;
198 __GLXvertexArrayPointerStateDEPRECATED texCoord
[__GLX_MAX_TEXTURE_UNITS
];
199 __GLXvertexArrayPointerStateDEPRECATED edgeFlag
;
200 GLint maxElementsVertices
;
201 GLint maxElementsIndices
;
203 } __GLXvertArrayStateDEPRECATED
;
205 typedef struct __GLXattributeRecDEPRECATED
{
209 ** Pixel storage state. Most of the pixel store mode state is kept
210 ** here and used by the client code to manage the packing and
211 ** unpacking of data sent to/received from the server.
213 __GLXpixelStoreMode storePack
, storeUnpack
;
216 ** Vertex Array storage state. The vertex array component
217 ** state is stored here and is used to manage the packing of
218 ** DrawArrays data sent to the server.
220 __GLXvertArrayStateDEPRECATED vertArray
;
221 } __GLXattributeDEPRECATED
;
223 typedef struct __GLXvertexArrayPointerStateRec
{
224 void (*proc
)(const void *);
225 void (*mtex_proc
)(GLenum
, const void *);
231 } __GLXvertexArrayPointerState
;
234 * Define which entries of \c __GLXvertArrayState::arrays match which
235 * vertex arrays in the client-state vector. These are only the one-of
236 * arrays. See the \c __GLXvertArrayState::arrays documentation for more
239 * \sa __GLXvertArrayState
242 edgeFlag_ARRAY
, /**< \c GL_EDGE_FLAG_ARRAY */
243 index_ARRAY
, /**< \c GL_INDEX_ARRAY */
244 fogCoord_ARRAY
, /**< \c GL_FOG_COORD_ARRAY */
245 secondaryColor_ARRAY
, /**< \c GL_SECONDARY_COLOR_ARRAY */
246 color_ARRAY
, /**< \c GL_COLOR_ARRAY */
247 normal_ARRAY
, /**< \c GL_NORMAL_ARRAY */
250 * \c GL_VERTEX_ARRAY \b must be last! All of the code for emitting arrays
251 * and array elements is written based on the assumption that the vertex
256 __GLX_MAX_ARRAYS
/**< Place holder entry. */
259 #define ENABLE_ARRAY(state,a) \
260 do { (state)->vertArray.enables |= (1U << (a ## _ARRAY)); } while( 0 )
261 #define DISABLE_ARRAY(state,a) \
262 do { (state)->vertArray.enables &= ~(1U << (a ## _ARRAY)); } while( 0 )
263 #define IS_ARRAY_ENABLED_BY_INDEX(state, i) \
264 (((state)->vertArray.enables & (1U << (i))) != 0)
265 #define IS_ARRAY_ENABLED(state, a) \
266 IS_ARRAY_ENABLED_BY_INDEX(state, a ## _ARRAY)
268 #define ENABLE_TEXARRAY(state,a) \
269 do { (state)->vertArray.texture_enables |= (1U << a); } while( 0 )
270 #define DISABLE_TEXARRAY(state,a) \
271 do { (state)->vertArray.texture_enables &= ~(1U << a); } while( 0 )
272 #define IS_TEXARRAY_ENABLED(state, a) \
273 (((state)->vertArray.texture_enables & (1U << a)) != 0)
276 * Client-side vertex array state.
278 typedef struct __GLXvertArrayStateRec
{
280 * Which client-side arrays are enabled? These are the flag bits for
281 * all of the non-texture coordinate arrays.
286 * Which of the texture coordinate arrays are enabled?
288 GLuint texture_enables
;
291 * State for "one-of" arrays. These are the arrays, such as
292 * GL_COLOR_ARRAY or GL_FOG_COORD_ARRAY for which there is only one
293 * array. There are also "many-of" arrays, such as
294 * GL_TEXTURE_COORD_ARRAY.
296 __GLXvertexArrayPointerState arrays
[__GLX_MAX_ARRAYS
];
298 __GLXvertexArrayPointerState texCoord
[__GLX_MAX_TEXTURE_UNITS
];
300 GLint maxElementsVertices
;
301 GLint maxElementsIndices
;
303 } __GLXvertArrayState
;
305 typedef struct __GLXattributeRec
{
309 ** Pixel storage state. Most of the pixel store mode state is kept
310 ** here and used by the client code to manage the packing and
311 ** unpacking of data sent to/received from the server.
313 __GLXpixelStoreMode storePack
, storeUnpack
;
316 ** Vertex Array storage state. The vertex array component
317 ** state is stored here and is used to manage the packing of
318 ** DrawArrays data sent to the server.
320 __GLXvertArrayState vertArray
;
323 * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically
326 GLboolean NoDrawArraysProtocol
;
329 typedef struct __GLXattributeMachineRec
{
330 __GLXattribute
*stack
[__GL_CLIENT_ATTRIB_STACK_DEPTH
];
331 __GLXattribute
**stackPointer
;
332 } __GLXattributeMachine
;
335 * GLX state that needs to be kept on the client. One of these records
336 * exist for each context that has been made current by this client.
338 struct __GLXcontextRec
{
340 * \name Drawing command buffer.
342 * Drawing commands are packed into this buffer before being sent as a
343 * single GLX protocol request. The buffer is sent when it overflows or
344 * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location
345 * in the buffer to be filled. \c limit is described above in the buffer
348 * Commands that require large amounts of data to be transfered will
349 * also use this buffer to hold a header that describes the large
352 * These must be the first 6 fields since they are static initialized
353 * in the dummy context in glxext.c
364 * The XID of this rendering context. When the context is created a
365 * new XID is allocated. This is set to None when the context is
366 * destroyed but is still current to some thread. In this case the
367 * context will be freed on next MakeCurrent.
372 * The XID of the \c shareList context.
380 * This filed has been largely been replaced by the \c mode field, but
381 * the work is not quite done.
391 * \c GL_TRUE if the context was created with ImportContext, which
392 * means the server-side context was created by another X client.
397 * The context tag returned by MakeCurrent when this context is made
398 * current. This tag is used to identify the context that a thread has
399 * current so that proper server context management can be done. It is
400 * used for all context specific commands (i.e., \c Render, \c RenderLarge,
401 * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old
404 GLXContextTag currentContextTag
;
407 * \name Rendering mode
409 * The rendering mode is kept on the client as well as the server.
410 * When \c glRenderMode is called, the buffer associated with the
411 * previous rendering mode (feedback or select) is filled.
415 GLfloat
*feedbackBuf
;
420 * This is \c GL_TRUE if the pixel unpack modes are such that an image
421 * can be unpacked from the clients memory by just copying. It may
422 * still be true that the server will have to do some work. This
423 * just promises that a straight copy will fetch the correct bytes.
425 GLboolean fastImageUnpack
;
428 * Fill newImage with the unpacked form of \c oldImage getting it
429 * ready for transport to the server.
431 void (*fillImage
)(__GLXcontext
*, GLint
, GLint
, GLint
, GLint
, GLenum
,
432 GLenum
, const GLvoid
*, GLubyte
*, GLubyte
*);
435 * \name Client side attribs.
438 __GLXattributeDEPRECATED stateDEPRECATED
;
439 __GLXattributeMachine attributes
;
443 * Client side error code. This is set when client side gl API
444 * routines need to set an error because of a bad enumerant or
445 * running out of memory, etc.
450 * Whether this context does direct rendering.
455 * \c dpy of current display for this context. Will be \c NULL if not
456 * current to any display, or if this is the "dummy context".
461 * The current drawable for this context. Will be None if this
462 * context is not current to any drawable. currentReadable is below.
464 GLXDrawable currentDrawable
;
467 * \name GL Constant Strings
469 * Constant strings that describe the server implementation
470 * These pertain to GL attributes, not to be confused with
471 * GLX versioning attributes.
481 * Record the dpy this context was created on for later freeing
486 * Maximum small render command size. This is the smaller of 64k and
487 * the size of the above buffer.
489 GLint maxSmallRenderCommandSize
;
492 * Major opcode for the extension. Copied here so a lookup isn't
497 #ifdef GLX_DIRECT_RENDERING
499 * Per context direct rendering interface functions and data.
501 __DRIcontext driContext
;
505 * \c GLXFBConfigID used to create this context. May be \c None. This
506 * field has been replaced by the \c mode field.
508 * \since Internal API version 20030317.
511 * This filed has been largely been replaced by the \c mode field, but
512 * the work is not quite done.
514 GLXFBConfigID fbconfigID
;
517 * The current read-drawable for this context. Will be None if this
518 * context is not current to any drawable.
520 * \since Internal API version 20030606.
522 GLXDrawable currentReadable
;
525 * Pointer to client-state data that is private to libGL. This is only
526 * used for indirect rendering contexts.
528 * No internal API version change was made for this change. Client-side
529 * drivers should NEVER use this data or even care that it exists.
531 void * client_state_private
;
534 * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE.
539 * \name Raw server GL version
541 * True core GL version supported by the server. This is the raw value
542 * returned by the server, and it may not reflect what is actually
543 * supported (or reported) by the client-side library.
546 int server_major
; /**< Major version number. */
547 int server_minor
; /**< Minor version number. */
551 #define __glXSetError(gc,code) \
552 if (!(gc)->error) { \
553 (gc)->error = code; \
556 extern void __glFreeAttributeState(__GLXcontext
*);
558 /************************************************************************/
561 * The size of the largest drawing command known to the implementation
562 * that will use the GLXRender GLX command. In this case it is
563 * \c glPolygonStipple.
565 #define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156
568 * To keep the implementation fast, the code uses a "limit" pointer
569 * to determine when the drawing command buffer is too full to hold
570 * another fixed size command. This constant defines the amount of
571 * space that must always be available in the drawing command buffer
572 * at all times for the implementation to work. It is important that
573 * the number be just large enough, but not so large as to reduce the
574 * efficacy of the buffer. The "+32" is just to keep the code working
575 * in case somebody counts wrong.
577 #define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32)
580 * This implementation uses a smaller threshold for switching
581 * to the RenderLarge protocol than the protcol requires so that
582 * large copies don't occur.
584 #define __GLX_RENDER_CMD_SIZE_LIMIT 4096
587 * One of these records exists per screen of the display. It contains
588 * a pointer to the config data for that screen (if the screen supports GL).
590 typedef struct __GLXscreenConfigsRec
{
592 * GLX visuals formated as \c __GLXvisualConfig structures.
595 __GLXvisualConfig
* old_configs
;
600 * GLX extension string reported by the X-server.
602 const char *serverGLXexts
;
605 * GLX extension string to be reported to applications. This is the
606 * set of extensions that the application can actually use.
608 char *effectiveGLXexts
;
610 #ifdef GLX_DIRECT_RENDERING
612 * Per screen direct rendering interface functions and data.
614 __DRIscreen driScreen
;
618 * Linked list of configurations for this screen. This is intended to
619 * be a superset of \c old_configs.
621 __GLcontextModes
*configs
;
623 * Per-screen dynamic GLX extension tracking. The \c direct_support
624 * field only contains enough bits for 64 extensions. Should libGL
625 * ever need to track more than 64 GLX extensions, we can safely grow
626 * this field. The \c __GLXscreenConfigs structure is not used outside
630 unsigned char direct_support
[8];
631 GLboolean ext_list_first_time
;
634 } __GLXscreenConfigs
;
637 * Per display private data. One of these records exists for each display
638 * that is using the OpenGL (GLX) extension.
640 struct __GLXdisplayPrivateRec
{
642 * Back pointer to the display
647 * The \c majorOpcode is common to all connections to the same server.
648 * It is also copied into the context structure.
653 * \name Server Version
655 * Major and minor version returned by the server during initialization.
658 int majorVersion
, minorVersion
;
662 * \name Storage for the servers GLX vendor and versions strings.
664 * These are the same for all screens on this display. These fields will
665 * be filled in on demand.
668 const char *serverGLXvendor
;
669 const char *serverGLXversion
;
673 * Configurations of visuals for all screens on this display.
674 * Also, per screen data which now includes the server \c GLX_EXTENSION
677 __GLXscreenConfigs
*screenConfigs
;
679 #ifdef GLX_DIRECT_RENDERING
681 * Per display direct rendering interface functions and data.
683 __DRIdisplay driDisplay
;
687 void __glXFreeContext(__GLXcontext
*);
689 extern GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*, GLubyte
*);
691 extern void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
693 const GLvoid
* data
, GLint dataLen
);
695 extern void __glXSendLargeCommand(__GLXcontext
*, const GLvoid
*, GLint
,
696 const GLvoid
*, GLint
);
698 /* Initialize the GLX extension for dpy */
699 extern __GLXdisplayPrivate
*__glXInitialize(Display
*);
701 /************************************************************************/
703 extern int __glXDebug
;
705 /* This is per-thread storage in an MT environment */
706 #if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS)
707 extern __GLXcontext
*__glXGetCurrentContext(void);
708 extern void __glXSetCurrentContext(__GLXcontext
*c
);
710 extern __GLXcontext
*__glXcurrentContext
;
711 #define __glXGetCurrentContext() __glXcurrentContext
712 #define __glXSetCurrentContext(gc) __glXcurrentContext = gc
717 ** Global lock for all threads in this address space using the GLX
720 #if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS)
721 extern xmutex_rec __glXmutex
;
722 #define __glXLock() xmutex_lock(&__glXmutex)
723 #define __glXUnlock() xmutex_unlock(&__glXmutex)
726 #define __glXUnlock()
730 ** Setup for a command. Initialize the extension for dpy if necessary.
732 extern CARD8
__glXSetupForCommand(Display
*dpy
);
734 /************************************************************************/
737 ** Data conversion and packing support.
740 extern const GLuint __glXDefaultPixelStore
[9];
742 /* Send an image to the server using RenderLarge. */
743 extern void __glXSendLargeImage(__GLXcontext
*gc
, GLint compsize
, GLint dim
,
744 GLint width
, GLint height
, GLint depth
, GLenum format
, GLenum type
,
745 const GLvoid
*src
, GLubyte
*pc
, GLubyte
*modes
);
747 /* Return the size, in bytes, of some pixel data */
748 extern GLint
__glImageSize(GLint
, GLint
, GLint
, GLenum
, GLenum
, GLenum
);
750 /* Return the number of elements per group of a specified format*/
751 extern GLint
__glElementsPerGroup(GLenum format
, GLenum type
);
753 /* Return the number of bytes per element, based on the element type (other
756 extern GLint
__glBytesPerElement(GLenum type
);
759 ** Fill the transport buffer with the data from the users buffer,
760 ** applying some of the pixel store modes (unpack modes) to the data
761 ** first. As a side effect of this call, the "modes" field is
762 ** updated to contain the modes needed by the server to decode the
765 extern void __glFillImage(__GLXcontext
*, GLint
, GLint
, GLint
, GLint
, GLenum
,
766 GLenum
, const GLvoid
*, GLubyte
*, GLubyte
*);
768 /* Copy map data with a stride into a packed buffer */
769 extern void __glFillMap1f(GLint
, GLint
, GLint
, const GLfloat
*, GLubyte
*);
770 extern void __glFillMap1d(GLint
, GLint
, GLint
, const GLdouble
*, GLubyte
*);
771 extern void __glFillMap2f(GLint
, GLint
, GLint
, GLint
, GLint
,
772 const GLfloat
*, GLfloat
*);
773 extern void __glFillMap2d(GLint
, GLint
, GLint
, GLint
, GLint
,
774 const GLdouble
*, GLdouble
*);
777 ** Empty an image out of the reply buffer into the clients memory applying
778 ** the pack modes to pack back into the clients requested format.
780 extern void __glEmptyImage(__GLXcontext
*, GLint
, GLint
, GLint
, GLint
, GLenum
,
781 GLenum
, const GLubyte
*, GLvoid
*);
785 ** Allocate and Initialize Vertex Array client state
787 extern void __glXInitVertexArrayState(__GLXcontext
*);
790 ** Inform the Server of the major and minor numbers and of the client
791 ** libraries extension string.
793 extern void __glXClientInfo ( Display
*dpy
, int opcode
);
795 /************************************************************************/
798 ** Declarations that should be in Xlib
800 #ifdef __GL_USE_OUR_PROTOTYPES
801 extern void _XFlush(Display
*);
802 extern Status
_XReply(Display
*, xReply
*, int, Bool
);
803 extern void _XRead(Display
*, void*, long);
804 extern void _XSend(Display
*, const void*, long);
809 ** GLX_BUILT_IN_XMESA controls whether libGL has a built-in verions of
810 ** Mesa that can render to non-GLX displays.
812 #ifdef GLX_BUILT_IN_XMESA
813 #define GLX_PREFIX(function) _real_##function
815 #define GLX_PREFIX(function) function
819 extern void __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
,
820 int count
, const INT32
*bp
, Bool tagged_only
, Bool fbconfig_style_tags
);
822 extern char * __glXGetStringFromServer( Display
* dpy
, int opcode
,
823 CARD32 glxCode
, CARD32 for_whom
, CARD32 name
);
825 extern char *__glXstrdup(const char *str
);
828 extern const char __glXGLClientVersion
[];
829 extern const char __glXGLClientExtensions
[];
831 /* Determine the internal API version */
832 extern int __glXGetInternalVersion(void);
834 /* Get the unadjusted system time */
835 extern int __glXGetUST( int64_t * ust
);
837 #endif /* !__GLX_client_h__ */