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"
62 #include "glxextensions.h"
66 #ifdef GLX_BUILT_IN_XMESA
67 #include "realglx.h" /* just silences prototype warnings */
70 #define GLX_MAJOR_VERSION 1 /* current version numbers */
71 #define GLX_MINOR_VERSION 4
73 #define __GLX_MAX_TEXTURE_UNITS 32
75 typedef struct __GLXcontextRec __GLXcontext
;
76 typedef struct __GLXdisplayPrivateRec __GLXdisplayPrivate
;
77 typedef struct _glapi_table __GLapi
;
79 /************************************************************************/
81 #ifdef GLX_DIRECT_RENDERING
83 #include <GL/internal/dri_interface.h>
85 typedef void *(*CreateScreenFunc
)(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
86 int numConfigs
, __GLXvisualConfig
*config
);
88 typedef void *(*CreateNewScreenFunc
)(Display
*dpy
, int scrn
, __DRIscreen
*psc
,
89 const __GLcontextModes
* modes
, const __DRIversion
* ddx_version
,
90 const __DRIversion
* dri_version
, const __DRIversion
* drm_version
,
91 const __DRIframebuffer
* frame_buffer
, void * pSAREA
,
92 int fd
, int internal_api_version
, __GLcontextModes
** driver_modes
);
96 * Display dependent methods. This structure is initialized during the
97 * \c driCreateDisplay call.
99 struct __DRIdisplayRec
{
101 * Method to destroy the private DRI display data.
103 void (*destroyDisplay
)(Display
*dpy
, void *displayPrivate
);
106 * Methods to create the private DRI screen data and initialize the
107 * screen dependent methods.
108 * This is an array [indexed by screen number] of function pointers.
110 * \deprecated This array of function pointers has been replaced by
111 * \c __DRIdisplayRec::createNewScreen.
112 * \sa __DRIdisplayRec::createNewScreen
114 CreateScreenFunc
* createScreen
;
117 * Opaque pointer to private per display direct rendering data.
118 * \c NULL if direct rendering is not supported on this display.
120 struct __DRIdisplayPrivateRec
*private;
123 * Array of pointers to methods to create and initialize the private DRI
126 * \sa __DRIdisplayRec::createScreen
128 CreateNewScreenFunc
* createNewScreen
;
133 ** We keep a linked list of these structures, one per DRI device driver.
135 struct __DRIdriverRec
{
138 CreateScreenFunc createScreenFunc
;
139 CreateNewScreenFunc createNewScreenFunc
;
140 struct __DRIdriverRec
*next
;
144 ** Function to create and DRI display data and initialize the display
145 ** dependent methods.
147 extern void *driCreateDisplay(Display
*dpy
, __DRIdisplay
*pdisp
);
149 extern __DRIdriver
*driGetDriver(Display
*dpy
, int scrNum
);
151 extern void DRI_glXUseXFont( Font font
, int first
, int count
, int listbase
);
154 ** Functions to obtain driver configuration information from a direct
155 ** rendering client application
157 extern const char *glXGetScreenDriver (Display
*dpy
, int scrNum
);
159 extern const char *glXGetDriverConfig (const char *driverName
);
163 /************************************************************************/
165 #define __GL_CLIENT_ATTRIB_STACK_DEPTH 16
167 typedef struct __GLXpixelStoreModeRec
{
168 GLboolean swapEndian
;
177 } __GLXpixelStoreMode
;
179 /* The next 3 structures are deprecated. Client state is no longer tracked
180 * using them. They only remain to maintain the layout / structure offset of
181 * __GLXcontextRec. In XFree86 5.0 they will be removed altogether.
184 typedef struct __GLXvertexArrayPointerStateRecDEPRECATED
{
186 void (*proc
)(const void *);
192 } __GLXvertexArrayPointerStateDEPRECATED
;
194 typedef struct __GLXvertArrayStateRecDEPRECATED
{
195 __GLXvertexArrayPointerStateDEPRECATED vertex
;
196 __GLXvertexArrayPointerStateDEPRECATED normal
;
197 __GLXvertexArrayPointerStateDEPRECATED color
;
198 __GLXvertexArrayPointerStateDEPRECATED index
;
199 __GLXvertexArrayPointerStateDEPRECATED texCoord
[__GLX_MAX_TEXTURE_UNITS
];
200 __GLXvertexArrayPointerStateDEPRECATED edgeFlag
;
201 GLint maxElementsVertices
;
202 GLint maxElementsIndices
;
204 } __GLXvertArrayStateDEPRECATED
;
206 typedef struct __GLXattributeRecDEPRECATED
{
210 ** Pixel storage state. Most of the pixel store mode state is kept
211 ** here and used by the client code to manage the packing and
212 ** unpacking of data sent to/received from the server.
214 __GLXpixelStoreMode storePack
, storeUnpack
;
217 ** Vertex Array storage state. The vertex array component
218 ** state is stored here and is used to manage the packing of
219 ** DrawArrays data sent to the server.
221 __GLXvertArrayStateDEPRECATED vertArray
;
222 } __GLXattributeDEPRECATED
;
225 typedef struct __GLXattributeRec
{
229 * Pixel storage state. Most of the pixel store mode state is kept
230 * here and used by the client code to manage the packing and
231 * unpacking of data sent to/received from the server.
233 __GLXpixelStoreMode storePack
, storeUnpack
;
236 * Is EXT_vertex_array / GL 1.1 DrawArrays protocol specifically
239 GLboolean NoDrawArraysProtocol
;
242 * Vertex Array storage state. The vertex array component
243 * state is stored here and is used to manage the packing of
244 * DrawArrays data sent to the server.
246 struct array_state_vector
* array_state
;
249 typedef struct __GLXattributeMachineRec
{
250 __GLXattribute
*stack
[__GL_CLIENT_ATTRIB_STACK_DEPTH
];
251 __GLXattribute
**stackPointer
;
252 } __GLXattributeMachine
;
255 * GLX state that needs to be kept on the client. One of these records
256 * exist for each context that has been made current by this client.
258 struct __GLXcontextRec
{
260 * \name Drawing command buffer.
262 * Drawing commands are packed into this buffer before being sent as a
263 * single GLX protocol request. The buffer is sent when it overflows or
264 * is flushed by \c __glXFlushRenderBuffer. \c pc is the next location
265 * in the buffer to be filled. \c limit is described above in the buffer
268 * Commands that require large amounts of data to be transfered will
269 * also use this buffer to hold a header that describes the large
272 * These must be the first 6 fields since they are static initialized
273 * in the dummy context in glxext.c
284 * The XID of this rendering context. When the context is created a
285 * new XID is allocated. This is set to None when the context is
286 * destroyed but is still current to some thread. In this case the
287 * context will be freed on next MakeCurrent.
292 * The XID of the \c shareList context.
300 * This filed has been largely been replaced by the \c mode field, but
301 * the work is not quite done.
311 * \c GL_TRUE if the context was created with ImportContext, which
312 * means the server-side context was created by another X client.
317 * The context tag returned by MakeCurrent when this context is made
318 * current. This tag is used to identify the context that a thread has
319 * current so that proper server context management can be done. It is
320 * used for all context specific commands (i.e., \c Render, \c RenderLarge,
321 * \c WaitX, \c WaitGL, \c UseXFont, and \c MakeCurrent (for the old
324 GLXContextTag currentContextTag
;
327 * \name Rendering mode
329 * The rendering mode is kept on the client as well as the server.
330 * When \c glRenderMode is called, the buffer associated with the
331 * previous rendering mode (feedback or select) is filled.
335 GLfloat
*feedbackBuf
;
340 * This is \c GL_TRUE if the pixel unpack modes are such that an image
341 * can be unpacked from the clients memory by just copying. It may
342 * still be true that the server will have to do some work. This
343 * just promises that a straight copy will fetch the correct bytes.
345 GLboolean fastImageUnpack
;
348 * Fill newImage with the unpacked form of \c oldImage getting it
349 * ready for transport to the server.
351 void (*fillImage
)(__GLXcontext
*, GLint
, GLint
, GLint
, GLint
, GLenum
,
352 GLenum
, const GLvoid
*, GLubyte
*, GLubyte
*);
355 * \name Client side attribs.
358 __GLXattributeDEPRECATED stateDEPRECATED
;
359 __GLXattributeMachine attributes
;
363 * Client side error code. This is set when client side gl API
364 * routines need to set an error because of a bad enumerant or
365 * running out of memory, etc.
370 * Whether this context does direct rendering.
375 * \c dpy of current display for this context. Will be \c NULL if not
376 * current to any display, or if this is the "dummy context".
381 * The current drawable for this context. Will be None if this
382 * context is not current to any drawable. currentReadable is below.
384 GLXDrawable currentDrawable
;
387 * \name GL Constant Strings
389 * Constant strings that describe the server implementation
390 * These pertain to GL attributes, not to be confused with
391 * GLX versioning attributes.
401 * Record the dpy this context was created on for later freeing
406 * Maximum small render command size. This is the smaller of 64k and
407 * the size of the above buffer.
409 GLint maxSmallRenderCommandSize
;
412 * Major opcode for the extension. Copied here so a lookup isn't
417 #ifdef GLX_DIRECT_RENDERING
419 * Per context direct rendering interface functions and data.
421 __DRIcontext driContext
;
425 * \c GLXFBConfigID used to create this context. May be \c None. This
426 * field has been replaced by the \c mode field.
428 * \since Internal API version 20030317.
431 * This filed has been largely been replaced by the \c mode field, but
432 * the work is not quite done.
434 GLXFBConfigID fbconfigID
;
437 * The current read-drawable for this context. Will be None if this
438 * context is not current to any drawable.
440 * \since Internal API version 20030606.
442 GLXDrawable currentReadable
;
445 * Pointer to client-state data that is private to libGL. This is only
446 * used for indirect rendering contexts.
448 * No internal API version change was made for this change. Client-side
449 * drivers should NEVER use this data or even care that it exists.
451 void * client_state_private
;
454 * Stored value for \c glXQueryContext attribute \c GLX_RENDER_TYPE.
459 * \name Raw server GL version
461 * True core GL version supported by the server. This is the raw value
462 * returned by the server, and it may not reflect what is actually
463 * supported (or reported) by the client-side library.
466 int server_major
; /**< Major version number. */
467 int server_minor
; /**< Minor version number. */
470 char gl_extension_bits
[ __GL_EXT_BYTES
];
473 #define __glXSetError(gc,code) \
474 if (!(gc)->error) { \
475 (gc)->error = code; \
478 extern void __glFreeAttributeState(__GLXcontext
*);
480 /************************************************************************/
483 * The size of the largest drawing command known to the implementation
484 * that will use the GLXRender GLX command. In this case it is
485 * \c glPolygonStipple.
487 #define __GLX_MAX_SMALL_RENDER_CMD_SIZE 156
490 * To keep the implementation fast, the code uses a "limit" pointer
491 * to determine when the drawing command buffer is too full to hold
492 * another fixed size command. This constant defines the amount of
493 * space that must always be available in the drawing command buffer
494 * at all times for the implementation to work. It is important that
495 * the number be just large enough, but not so large as to reduce the
496 * efficacy of the buffer. The "+32" is just to keep the code working
497 * in case somebody counts wrong.
499 #define __GLX_BUFFER_LIMIT_SIZE (__GLX_MAX_SMALL_RENDER_CMD_SIZE + 32)
502 * This implementation uses a smaller threshold for switching
503 * to the RenderLarge protocol than the protcol requires so that
504 * large copies don't occur.
506 #define __GLX_RENDER_CMD_SIZE_LIMIT 4096
509 * One of these records exists per screen of the display. It contains
510 * a pointer to the config data for that screen (if the screen supports GL).
512 typedef struct __GLXscreenConfigsRec
{
514 * GLX visuals formated as \c __GLXvisualConfig structures.
517 __GLXvisualConfig
* old_configs
;
522 * GLX extension string reported by the X-server.
524 const char *serverGLXexts
;
527 * GLX extension string to be reported to applications. This is the
528 * set of extensions that the application can actually use.
530 char *effectiveGLXexts
;
532 #ifdef GLX_DIRECT_RENDERING
534 * Per screen direct rendering interface functions and data.
536 __DRIscreen driScreen
;
540 * Linked list of configurations for this screen. This is intended to
541 * be a superset of \c old_configs.
543 __GLcontextModes
*configs
;
545 * Per-screen dynamic GLX extension tracking. The \c direct_support
546 * field only contains enough bits for 64 extensions. Should libGL
547 * ever need to track more than 64 GLX extensions, we can safely grow
548 * this field. The \c __GLXscreenConfigs structure is not used outside
552 unsigned char direct_support
[8];
553 GLboolean ext_list_first_time
;
556 } __GLXscreenConfigs
;
559 * Per display private data. One of these records exists for each display
560 * that is using the OpenGL (GLX) extension.
562 struct __GLXdisplayPrivateRec
{
564 * Back pointer to the display
569 * The \c majorOpcode is common to all connections to the same server.
570 * It is also copied into the context structure.
575 * \name Server Version
577 * Major and minor version returned by the server during initialization.
580 int majorVersion
, minorVersion
;
584 * \name Storage for the servers GLX vendor and versions strings.
586 * These are the same for all screens on this display. These fields will
587 * be filled in on demand.
590 const char *serverGLXvendor
;
591 const char *serverGLXversion
;
595 * Configurations of visuals for all screens on this display.
596 * Also, per screen data which now includes the server \c GLX_EXTENSION
599 __GLXscreenConfigs
*screenConfigs
;
601 #ifdef GLX_DIRECT_RENDERING
603 * Per display direct rendering interface functions and data.
605 __DRIdisplay driDisplay
;
609 void __glXFreeContext(__GLXcontext
*);
611 extern GLubyte
*__glXFlushRenderBuffer(__GLXcontext
*, GLubyte
*);
613 extern void __glXSendLargeChunk(__GLXcontext
*gc
, GLint requestNumber
,
615 const GLvoid
* data
, GLint dataLen
);
617 extern void __glXSendLargeCommand(__GLXcontext
*, const GLvoid
*, GLint
,
618 const GLvoid
*, GLint
);
620 /* Initialize the GLX extension for dpy */
621 extern __GLXdisplayPrivate
*__glXInitialize(Display
*);
623 /************************************************************************/
625 extern int __glXDebug
;
627 /* This is per-thread storage in an MT environment */
628 #if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS)
629 extern __GLXcontext
*__glXGetCurrentContext(void);
630 extern void __glXSetCurrentContext(__GLXcontext
*c
);
632 extern __GLXcontext
*__glXcurrentContext
;
633 #define __glXGetCurrentContext() __glXcurrentContext
634 #define __glXSetCurrentContext(gc) __glXcurrentContext = gc
639 ** Global lock for all threads in this address space using the GLX
642 #if defined(GLX_DIRECT_RENDERING) && defined(XTHREADS)
643 extern xmutex_rec __glXmutex
;
644 #define __glXLock() xmutex_lock(&__glXmutex)
645 #define __glXUnlock() xmutex_unlock(&__glXmutex)
648 #define __glXUnlock()
652 ** Setup for a command. Initialize the extension for dpy if necessary.
654 extern CARD8
__glXSetupForCommand(Display
*dpy
);
656 /************************************************************************/
659 ** Data conversion and packing support.
662 extern const GLuint __glXDefaultPixelStore
[9];
664 /* Send an image to the server using RenderLarge. */
665 extern void __glXSendLargeImage(__GLXcontext
*gc
, GLint compsize
, GLint dim
,
666 GLint width
, GLint height
, GLint depth
, GLenum format
, GLenum type
,
667 const GLvoid
*src
, GLubyte
*pc
, GLubyte
*modes
);
669 /* Return the size, in bytes, of some pixel data */
670 extern GLint
__glImageSize(GLint
, GLint
, GLint
, GLenum
, GLenum
, GLenum
);
672 /* Return the number of elements per group of a specified format*/
673 extern GLint
__glElementsPerGroup(GLenum format
, GLenum type
);
675 /* Return the number of bytes per element, based on the element type (other
678 extern GLint
__glBytesPerElement(GLenum type
);
681 ** Fill the transport buffer with the data from the users buffer,
682 ** applying some of the pixel store modes (unpack modes) to the data
683 ** first. As a side effect of this call, the "modes" field is
684 ** updated to contain the modes needed by the server to decode the
687 extern void __glFillImage(__GLXcontext
*, GLint
, GLint
, GLint
, GLint
, GLenum
,
688 GLenum
, const GLvoid
*, GLubyte
*, GLubyte
*);
690 /* Copy map data with a stride into a packed buffer */
691 extern void __glFillMap1f(GLint
, GLint
, GLint
, const GLfloat
*, GLubyte
*);
692 extern void __glFillMap1d(GLint
, GLint
, GLint
, const GLdouble
*, GLubyte
*);
693 extern void __glFillMap2f(GLint
, GLint
, GLint
, GLint
, GLint
,
694 const GLfloat
*, GLfloat
*);
695 extern void __glFillMap2d(GLint
, GLint
, GLint
, GLint
, GLint
,
696 const GLdouble
*, GLdouble
*);
699 ** Empty an image out of the reply buffer into the clients memory applying
700 ** the pack modes to pack back into the clients requested format.
702 extern void __glEmptyImage(__GLXcontext
*, GLint
, GLint
, GLint
, GLint
, GLenum
,
703 GLenum
, const GLubyte
*, GLvoid
*);
707 ** Allocate and Initialize Vertex Array client state
709 extern void __glXInitVertexArrayState(__GLXcontext
*);
712 ** Inform the Server of the major and minor numbers and of the client
713 ** libraries extension string.
715 extern void __glXClientInfo ( Display
*dpy
, int opcode
);
717 /************************************************************************/
720 ** Declarations that should be in Xlib
722 #ifdef __GL_USE_OUR_PROTOTYPES
723 extern void _XFlush(Display
*);
724 extern Status
_XReply(Display
*, xReply
*, int, Bool
);
725 extern void _XRead(Display
*, void*, long);
726 extern void _XSend(Display
*, const void*, long);
731 ** GLX_BUILT_IN_XMESA controls whether libGL has a built-in verions of
732 ** Mesa that can render to non-GLX displays.
734 #ifdef GLX_BUILT_IN_XMESA
735 #define GLX_PREFIX(function) _real_##function
737 #define GLX_PREFIX(function) function
741 extern void __glXInitializeVisualConfigFromTags( __GLcontextModes
*config
,
742 int count
, const INT32
*bp
, Bool tagged_only
, Bool fbconfig_style_tags
);
744 extern char * __glXGetStringFromServer( Display
* dpy
, int opcode
,
745 CARD32 glxCode
, CARD32 for_whom
, CARD32 name
);
747 extern char *__glXstrdup(const char *str
);
750 extern const char __glXGLClientVersion
[];
751 extern const char __glXGLClientExtensions
[];
753 /* Determine the internal API version */
754 extern int __glXGetInternalVersion(void);
756 /* Get the unadjusted system time */
757 extern int __glXGetUST( int64_t * ust
);
759 #endif /* !__GLX_client_h__ */