Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
55 pj 1
/* $XFree86: xc/lib/GL/include/GL/internal/glcore.h,v 1.7 2001/03/25 05:32:00 tsi Exp $ */
2
#ifndef __gl_core_h_
3
#define __gl_core_h_
4
 
5
/*
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:
13
**
14
** http://oss.sgi.com/projects/FreeB
15
**
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.
21
**
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.
27
**
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.
37
**
38
*/
39
 
40
#ifndef XFree86LOADER
41
#include <sys/types.h>
42
#endif
43
 
44
#define GL_CORE_SGI  1
45
#define GL_CORE_MESA 2
46
 
47
typedef struct __GLcontextRec __GLcontext;
48
typedef struct __GLinterfaceRec __GLinterface;
49
 
50
/*
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).
53
**
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".
59
*/
60
 
61
/*
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.
66
*/
67
typedef struct __GLcontextModesRec {
68
    GLboolean rgbMode;
69
    GLboolean colorIndexMode;
70
    GLboolean doubleBufferMode;
71
    GLboolean stereoMode;
72
 
73
    GLboolean haveAccumBuffer;
74
    GLboolean haveDepthBuffer;
75
    GLboolean haveStencilBuffer;
76
 
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 */
81
 
82
    GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits;
83
    GLint depthBits;
84
    GLint stencilBits;
85
 
86
    GLint numAuxBuffers;
87
 
88
    GLint level;
89
 
90
    GLint pixmapMode;
91
} __GLcontextModes;
92
 
93
/************************************************************************/
94
 
95
/*
96
** Structure used for allocating and freeing drawable private memory.
97
** (like software buffers, for example).
98
**
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.
107
**
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).
112
*/
113
typedef struct __GLdrawableRegionRec __GLdrawableRegion;
114
typedef struct __GLdrawableBufferRec __GLdrawableBuffer;
115
typedef struct __GLdrawablePrivateRec __GLdrawablePrivate;
116
 
117
typedef struct __GLregionRectRec {
118
    /* lower left (inside the rectangle) */
119
    GLint x0, y0;
120
    /* upper right (outside the rectangle) */
121
    GLint x1, y1;
122
} __GLregionRect;
123
 
124
struct __GLdrawableRegionRec {
125
    GLint numRects;
126
    __GLregionRect *rects;
127
    __GLregionRect boundingRect;
128
};
129
 
130
/************************************************************************/
131
 
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))
143
 
144
#define __GL_ALL_BUFFER_MASK            0xffffffff
145
 
146
/* what Resize routines return if resize resorted to fallback case */
147
#define __GL_BUFFER_FALLBACK    0x10
148
 
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);
154
 
155
/*
156
** A drawable buffer
157
**
158
** This data structure describes the context side of a drawable.  
159
**
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).
167
**
168
** For more details regarding locking, see buffers.h in the GL core
169
*/
170
struct __GLdrawableBufferRec {
171
    /*
172
    ** Buffer dimensions
173
    */
174
    GLint width, height, depth;
175
 
176
    /*
177
    ** Framebuffer base address
178
    */
179
    void *base;
180
 
181
    /*
182
    ** Framebuffer size (in bytes)
183
    */
184
    GLuint size;
185
 
186
    /*
187
    ** Size (in bytes) of each element in the framebuffer
188
    */
189
    GLuint elementSize;
190
    GLuint elementSizeLog2;
191
 
192
    /*
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.
196
    */
197
    GLint outerWidth;
198
 
199
    /*
200
    ** outerWidth * elementSize
201
    */
202
    GLint byteWidth;
203
 
204
    /*
205
    ** Allocation/deallocation is done based on this handle.  A handle
206
    ** is conceptually different from the framebuffer 'base'.
207
    */
208
    void *handle;
209
 
210
    /* imported */
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);
219
 
220
    /* exported */
221
    void (*freePrivate)(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv);
222
#ifdef __cplusplus
223
    void *privatePtr;
224
#else
225
    void *private;
226
#endif
227
 
228
    /* private */
229
    void *other;        /* implementation private data */
230
    __GLbufMainInitFn mainInit;
231
    __GLbufFallbackInitFn fallbackInit;
232
};
233
 
234
/*
235
** The context side of the drawable private
236
*/
237
struct __GLdrawablePrivateRec {
238
    /*
239
    ** Drawable Modes
240
    */
241
    __GLcontextModes *modes;
242
 
243
    /*
244
    ** Drawable size
245
    */
246
    GLuint width, height;
247
 
248
    /*
249
    ** Origin in screen coordinates of the drawable
250
    */
251
    GLint xOrigin, yOrigin;
252
#ifdef __GL_ALIGNED_BUFFERS
253
    /*
254
    ** Drawable offset from screen origin
255
    */
256
    GLint xOffset, yOffset;
257
 
258
    /*
259
    ** Alignment restriction
260
    */
261
    GLint xAlignment, yAlignment;
262
#endif
263
    /*
264
    ** Should we invert the y axis?
265
    */
266
    GLint yInverted;
267
 
268
    /*
269
    ** Mask specifying which buffers are renderable by the hw
270
    */
271
    GLuint accelBufferMask;
272
 
273
    /*
274
    ** the buffers themselves
275
    */
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;
283
#endif
284
 
285
    __GLdrawableRegion ownershipRegion;
286
 
287
    /*
288
    ** Lock for the drawable private structure
289
    */
290
    void *lock;
291
#ifdef DEBUG
292
    /* lock debugging info */
293
    int lockRefCount;
294
    int lockLine[10];
295
    char *lockFile[10];
296
#endif
297
 
298
    /* imported */
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);
303
 
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);
312
 
313
    void (*lockDP)(__GLdrawablePrivate *glPriv, __GLcontext *gc);
314
    void (*unlockDP)(__GLdrawablePrivate *glPriv);
315
 
316
    /* exported */
317
#if 0 /* disable, just like in __GLimportsRec */
318
    void *wsPriv;       /* pointer to the window system DrawablePrivate */
319
#endif
320
#ifdef __cplusplus
321
    void *privatePtr;
322
#else
323
    void *private;
324
#endif
325
    void (*freePrivate)(__GLdrawablePrivate *);
326
 
327
    /* client data */
328
    void *other;
329
};
330
 
331
/*
332
** Macros to lock/unlock the drawable private
333
*/
334
#if defined(DEBUG)
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)
345
#else /* DEBUG */
346
#define __GL_LOCK_DP(glPriv,gc)         (*(glPriv)->lockDP)(glPriv,gc)
347
#define __GL_UNLOCK_DP(glPriv)          (*(glPriv)->unlockDP)(glPriv)
348
#endif /* DEBUG */
349
 
350
 
351
/*
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".
355
*/
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);
362
 
363
    /* Error handling */
364
    void (*warning)(__GLcontext *gc, char *fmt);
365
    void (*fatal)(__GLcontext *gc, char *fmt);
366
 
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, ...);
374
 
375
    /* Drawing surface management */
376
    __GLdrawablePrivate *(*getDrawablePrivate)(__GLcontext *gc);
377
 
378
#if 0
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)
381
    */
382
    /* Pointer to the window system context */
383
    void *wscx;
384
#endif
385
 
386
    /* Operating system dependent data goes here */
387
    void *other;
388
} __GLimports;
389
 
390
/************************************************************************/
391
 
392
/*
393
** Procedures which are exported by the GL to the surrounding "operating
394
** system" so that it can manage multiple GL context's.
395
*/
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);
404
 
405
    /* Drawing surface notification callbacks */
406
    GLboolean (*notifyResize)(__GLcontext *gc);
407
    void (*notifyDestroy)(__GLcontext *gc);
408
    void (*notifySwapBuffers)(__GLcontext *gc);
409
 
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);
414
} __GLexports;
415
 
416
/************************************************************************/
417
 
418
/*
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
421
** else is opaque.
422
*/
423
struct __GLinterfaceRec {
424
    __GLimports imports;
425
    __GLexports exports;
426
};
427
 
428
extern __GLcontext *__glCoreCreateContext(__GLimports *, __GLcontextModes *);
429
extern void __glCoreNopDispatch(void);
430
 
431
#endif /* __gl_core_h_ */