1 /* $XFree86: xc/lib/GL/include/GL/internal/glcore.h,v 1.7 2001/03/25 05:32:00 tsi Exp $ */
6 ** License Applicability. Except to the extent portions of this file are
7 ** made subject to an alternative license as permitted in the SGI Free
8 ** Software License B, Version 1.1 (the "License"), the contents of this
9 ** file are subject only to the provisions of the License. You may not use
10 ** this file except in compliance with the License. You may obtain a copy
11 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
12 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
14 ** http://oss.sgi.com/projects/FreeB
16 ** Note that, as provided in the License, the Software is distributed on an
17 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
18 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
19 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
20 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
22 ** Original Code. The Original Code is: OpenGL Sample Implementation,
23 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
24 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
25 ** Copyright in any portions created by third parties is as indicated
26 ** elsewhere herein. All Rights Reserved.
28 ** Additional Notice Provisions: The application programming interfaces
29 ** established by SGI in conjunction with the Original Code are The
30 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
31 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
32 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
33 ** Window System(R) (Version 1.3), released October 19, 1998. This software
34 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
35 ** published by SGI, but has not been independently verified as being
36 ** compliant with the OpenGL(R) version 1.2.1 Specification.
41 #include <sys/types.h>
45 #define GL_CORE_MESA 2
47 typedef struct __GLcontextRec __GLcontext
;
48 typedef struct __GLinterfaceRec __GLinterface
;
51 ** This file defines the interface between the GL core and the surrounding
52 ** "operating system" that supports it (currently the GLX or WGL extensions).
54 ** Members (data and function pointers) are documented as imported or
55 ** exported according to how they are used by the core rendering functions.
56 ** Imported members are initialized by the "operating system" and used by
57 ** the core functions. Exported members are initialized by the core functions
58 ** and used by the "operating system".
62 ** Mode and limit information for a context. This information is
63 ** kept around in the context so that values can be used during
64 ** command execution, and for returning information about the
65 ** context to the application.
67 typedef struct __GLcontextModesRec
{
69 GLboolean colorIndexMode
;
70 GLboolean doubleBufferMode
;
73 GLboolean haveAccumBuffer
;
74 GLboolean haveDepthBuffer
;
75 GLboolean haveStencilBuffer
;
77 GLint redBits
, greenBits
, blueBits
, alphaBits
; /* bits per comp */
78 GLuint redMask
, greenMask
, blueMask
, alphaMask
;
79 GLint rgbBits
; /* total bits for rgb */
80 GLint indexBits
; /* total bits for colorindex */
82 GLint accumRedBits
, accumGreenBits
, accumBlueBits
, accumAlphaBits
;
93 /************************************************************************/
96 ** Structure used for allocating and freeing drawable private memory.
97 ** (like software buffers, for example).
99 ** The memory allocation routines are provided by the surrounding
100 ** "operating system" code, and they are to be used for allocating
101 ** software buffers and things which are associated with the drawable,
102 ** and used by any context which draws to that drawable. There are
103 ** separate memory allocation functions for drawables and contexts
104 ** since drawables and contexts can be created and destroyed independently
105 ** of one another, and the "operating system" may want to use separate
106 ** allocation arenas for each.
108 ** The freePrivate function is filled in by the core routines when they
109 ** allocates software buffers, and stick them in "private". The freePrivate
110 ** function will destroy anything allocated to this drawable (to be called
111 ** when the drawable is destroyed).
113 typedef struct __GLdrawableRegionRec __GLdrawableRegion
;
114 typedef struct __GLdrawableBufferRec __GLdrawableBuffer
;
115 typedef struct __GLdrawablePrivateRec __GLdrawablePrivate
;
117 typedef struct __GLregionRectRec
{
118 /* lower left (inside the rectangle) */
120 /* upper right (outside the rectangle) */
124 struct __GLdrawableRegionRec
{
126 __GLregionRect
*rects
;
127 __GLregionRect boundingRect
;
130 /************************************************************************/
132 /* masks for the buffers */
133 #define __GL_FRONT_BUFFER_MASK 0x00000001
134 #define __GL_FRONT_LEFT_BUFFER_MASK 0x00000001
135 #define __GL_FRONT_RIGHT_BUFFER_MASK 0x00000002
136 #define __GL_BACK_BUFFER_MASK 0x00000004
137 #define __GL_BACK_LEFT_BUFFER_MASK 0x00000004
138 #define __GL_BACK_RIGHT_BUFFER_MASK 0x00000008
139 #define __GL_ACCUM_BUFFER_MASK 0x00000010
140 #define __GL_DEPTH_BUFFER_MASK 0x00000020
141 #define __GL_STENCIL_BUFFER_MASK 0x00000040
142 #define __GL_AUX_BUFFER_MASK(i) (0x0000080 << (i))
144 #define __GL_ALL_BUFFER_MASK 0xffffffff
146 /* what Resize routines return if resize resorted to fallback case */
147 #define __GL_BUFFER_FALLBACK 0x10
149 typedef void (*__GLbufFallbackInitFn
)(__GLdrawableBuffer
*buf
,
150 __GLdrawablePrivate
*glPriv
, GLint bits
);
151 typedef void (*__GLbufMainInitFn
)(__GLdrawableBuffer
*buf
,
152 __GLdrawablePrivate
*glPriv
, GLint bits
,
153 __GLbufFallbackInitFn back
);
158 ** This data structure describes the context side of a drawable.
160 ** According to the spec there could be multiple contexts bound to the same
161 ** drawable at the same time (from different threads). In order to avoid
162 ** multiple-access conflicts, locks are used to serialize access. When a
163 ** thread needs to access (read or write) a member of the drawable, it takes
164 ** a lock first. Some of the entries in the drawable are treated "mostly
165 ** constant", so we take the freedom of allowing access to them without
166 ** taking a lock (for optimization reasons).
168 ** For more details regarding locking, see buffers.h in the GL core
170 struct __GLdrawableBufferRec
{
174 GLint width
, height
, depth
;
177 ** Framebuffer base address
182 ** Framebuffer size (in bytes)
187 ** Size (in bytes) of each element in the framebuffer
190 GLuint elementSizeLog2
;
193 ** Element skip from one scanline to the next.
194 ** If the buffer is part of another buffer (for example, fullscreen
195 ** front buffer), outerWidth is the width of that buffer.
200 ** outerWidth * elementSize
205 ** Allocation/deallocation is done based on this handle. A handle
206 ** is conceptually different from the framebuffer 'base'.
211 GLboolean (*resize
)(__GLdrawableBuffer
*buf
,
212 GLint x
, GLint y
, GLuint width
, GLuint height
,
213 __GLdrawablePrivate
*glPriv
, GLuint bufferMask
);
214 void (*lock
)(__GLdrawableBuffer
*buf
, __GLdrawablePrivate
*glPriv
);
215 void (*unlock
)(__GLdrawableBuffer
*buf
, __GLdrawablePrivate
*glPriv
);
216 void (*fill
)(__GLdrawableBuffer
*buf
, __GLdrawablePrivate
*glPriv
,
217 GLuint val
, GLint x
, GLint y
, GLint w
, GLint h
);
218 void (*free
)(__GLdrawableBuffer
*buf
, __GLdrawablePrivate
*glPriv
);
221 void (*freePrivate
)(__GLdrawableBuffer
*buf
, __GLdrawablePrivate
*glPriv
);
229 void *other
; /* implementation private data */
230 __GLbufMainInitFn mainInit
;
231 __GLbufFallbackInitFn fallbackInit
;
235 ** The context side of the drawable private
237 struct __GLdrawablePrivateRec
{
241 __GLcontextModes
*modes
;
246 GLuint width
, height
;
249 ** Origin in screen coordinates of the drawable
251 GLint xOrigin
, yOrigin
;
252 #ifdef __GL_ALIGNED_BUFFERS
254 ** Drawable offset from screen origin
256 GLint xOffset
, yOffset
;
259 ** Alignment restriction
261 GLint xAlignment
, yAlignment
;
264 ** Should we invert the y axis?
269 ** Mask specifying which buffers are renderable by the hw
271 GLuint accelBufferMask
;
274 ** the buffers themselves
276 __GLdrawableBuffer frontBuffer
;
277 __GLdrawableBuffer backBuffer
;
278 __GLdrawableBuffer accumBuffer
;
279 __GLdrawableBuffer depthBuffer
;
280 __GLdrawableBuffer stencilBuffer
;
281 #if defined(__GL_NUMBER_OF_AUX_BUFFERS) && (__GL_NUMBER_OF_AUX_BUFFERS > 0)
282 __GLdrawableBuffer
*auxBuffer
;
285 __GLdrawableRegion ownershipRegion
;
288 ** Lock for the drawable private structure
292 /* lock debugging info */
299 void *(*malloc
)(size_t size
);
300 void *(*calloc
)(size_t numElem
, size_t elemSize
);
301 void *(*realloc
)(void *oldAddr
, size_t newSize
);
302 void (*free
)(void *addr
);
304 GLboolean (*addSwapRect
)(__GLdrawablePrivate
*glPriv
,
305 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
306 void (*setClipRect
)(__GLdrawablePrivate
*glPriv
,
307 GLint x
, GLint y
, GLsizei width
, GLsizei height
);
308 void (*updateClipRegion
)(__GLdrawablePrivate
*glPriv
);
309 GLboolean (*resize
)(__GLdrawablePrivate
*glPriv
);
310 void (*getDrawableSize
)(__GLdrawablePrivate
*glPriv
,
311 GLint
*x
, GLint
*y
, GLuint
*width
, GLuint
*height
);
313 void (*lockDP
)(__GLdrawablePrivate
*glPriv
, __GLcontext
*gc
);
314 void (*unlockDP
)(__GLdrawablePrivate
*glPriv
);
317 #if 0 /* disable, just like in __GLimportsRec */
318 void *wsPriv
; /* pointer to the window system DrawablePrivate */
325 void (*freePrivate
)(__GLdrawablePrivate
*);
332 ** Macros to lock/unlock the drawable private
335 #define __GL_LOCK_DP(glPriv,gc) \
336 (*(glPriv)->lockDP)(glPriv,gc); \
337 (glPriv)->lockLine[(glPriv)->lockRefCount] = __LINE__; \
338 (glPriv)->lockFile[(glPriv)->lockRefCount] = __FILE__; \
339 (glPriv)->lockRefCount++
340 #define __GL_UNLOCK_DP(glPriv) \
341 (glPriv)->lockRefCount--; \
342 (glPriv)->lockLine[(glPriv)->lockRefCount] = 0; \
343 (glPriv)->lockFile[(glPriv)->lockRefCount] = NULL; \
344 (*(glPriv)->unlockDP)(glPriv)
346 #define __GL_LOCK_DP(glPriv,gc) (*(glPriv)->lockDP)(glPriv,gc)
347 #define __GL_UNLOCK_DP(glPriv) (*(glPriv)->unlockDP)(glPriv)
352 ** Procedures which are imported by the GL from the surrounding
353 ** "operating system". Math functions are not considered part of the
354 ** "operating system".
356 typedef struct __GLimportsRec
{
357 /* Memory management */
358 void * (*malloc
)(__GLcontext
*gc
, size_t size
);
359 void *(*calloc
)(__GLcontext
*gc
, size_t numElem
, size_t elemSize
);
360 void *(*realloc
)(__GLcontext
*gc
, void *oldAddr
, size_t newSize
);
361 void (*free
)(__GLcontext
*gc
, void *addr
);
364 void (*warning
)(__GLcontext
*gc
, char *fmt
);
365 void (*fatal
)(__GLcontext
*gc
, char *fmt
);
367 /* other system calls */
368 char *(CAPI
*getenv
)(__GLcontext
*gc
, const char *var
);
369 int (CAPI
*atoi
)(__GLcontext
*gc
, const char *str
);
370 int (CAPI
*sprintf
)(__GLcontext
*gc
, char *str
, const char *fmt
, ...);
371 void *(CAPI
*fopen
)(__GLcontext
*gc
, const char *path
, const char *mode
);
372 int (CAPI
*fclose
)(__GLcontext
*gc
, void *stream
);
373 int (CAPI
*fprintf
)(__GLcontext
*gc
, void *stream
, const char *fmt
, ...);
375 /* Drawing surface management */
376 __GLdrawablePrivate
*(*getDrawablePrivate
)(__GLcontext
*gc
);
379 /* At some point, this field got removed from the XFree86 glcore.h file.
380 * we're removing it here to prevent interop problems. (Brian)
382 /* Pointer to the window system context */
386 /* Operating system dependent data goes here */
390 /************************************************************************/
393 ** Procedures which are exported by the GL to the surrounding "operating
394 ** system" so that it can manage multiple GL context's.
396 typedef struct __GLexportsRec
{
397 /* Context management (return GL_FALSE on failure) */
398 GLboolean (*destroyContext
)(__GLcontext
*gc
);
399 GLboolean (*loseCurrent
)(__GLcontext
*gc
);
400 GLboolean (*makeCurrent
)(__GLcontext
*gc
);
401 GLboolean (*shareContext
)(__GLcontext
*gc
, __GLcontext
*gcShare
);
402 GLboolean (*copyContext
)(__GLcontext
*dst
, const __GLcontext
*src
, GLuint mask
);
403 GLboolean (*forceCurrent
)(__GLcontext
*gc
);
405 /* Drawing surface notification callbacks */
406 GLboolean (*notifyResize
)(__GLcontext
*gc
);
407 void (*notifyDestroy
)(__GLcontext
*gc
);
408 void (*notifySwapBuffers
)(__GLcontext
*gc
);
410 /* Dispatch table override control for external agents like libGLS */
411 struct __GLdispatchStateRec
* (*dispatchExec
)(__GLcontext
*gc
);
412 void (*beginDispatchOverride
)(__GLcontext
*gc
);
413 void (*endDispatchOverride
)(__GLcontext
*gc
);
416 /************************************************************************/
419 ** This must be the first member of a __GLcontext structure. This is the
420 ** only part of a context that is exposed to the outside world; everything
423 struct __GLinterfaceRec
{
428 extern __GLcontext
*__glCoreCreateContext(__GLimports
*, __GLcontextModes
*);
429 extern void __glCoreNopDispatch(void);
431 #endif /* __gl_core_h_ */