FBConfig support for EXT_tfp
[mesa.git] / include / GL / internal / glcore.h
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 #ifdef CAPI
45 #undef CAPI
46 #endif
47 #define CAPI
48
49 #define GL_CORE_SGI 1
50 #define GL_CORE_MESA 2
51 #define GL_CORE_APPLE 4
52
53 typedef struct __GLcontextRec __GLcontext;
54 typedef struct __GLinterfaceRec __GLinterface;
55
56 /*
57 ** This file defines the interface between the GL core and the surrounding
58 ** "operating system" that supports it (currently the GLX or WGL extensions).
59 **
60 ** Members (data and function pointers) are documented as imported or
61 ** exported according to how they are used by the core rendering functions.
62 ** Imported members are initialized by the "operating system" and used by
63 ** the core functions. Exported members are initialized by the core functions
64 ** and used by the "operating system".
65 */
66
67 /*
68 ** Mode and limit information for a context. This information is
69 ** kept around in the context so that values can be used during
70 ** command execution, and for returning information about the
71 ** context to the application.
72 */
73 typedef struct __GLcontextModesRec {
74 struct __GLcontextModesRec * next;
75
76 GLboolean rgbMode;
77 GLboolean floatMode;
78 GLboolean colorIndexMode;
79 GLuint doubleBufferMode;
80 GLuint stereoMode;
81
82 GLboolean haveAccumBuffer;
83 GLboolean haveDepthBuffer;
84 GLboolean haveStencilBuffer;
85
86 GLint redBits, greenBits, blueBits, alphaBits; /* bits per comp */
87 GLuint redMask, greenMask, blueMask, alphaMask;
88 GLint rgbBits; /* total bits for rgb */
89 GLint indexBits; /* total bits for colorindex */
90
91 GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits;
92 GLint depthBits;
93 GLint stencilBits;
94
95 GLint numAuxBuffers;
96
97 GLint level;
98
99 GLint pixmapMode;
100
101 /* GLX */
102 GLint visualID;
103 GLint visualType; /**< One of the GLX X visual types. (i.e.,
104 * \c GLX_TRUE_COLOR, etc.)
105 */
106
107 /* EXT_visual_rating / GLX 1.2 */
108 GLint visualRating;
109
110 /* EXT_visual_info / GLX 1.2 */
111 GLint transparentPixel;
112 /* colors are floats scaled to ints */
113 GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha;
114 GLint transparentIndex;
115
116 /* ARB_multisample / SGIS_multisample */
117 GLint sampleBuffers;
118 GLint samples;
119
120 /* SGIX_fbconfig / GLX 1.3 */
121 GLint drawableType;
122 GLint renderType;
123 GLint xRenderable;
124 GLint fbconfigID;
125
126 /* SGIX_pbuffer / GLX 1.3 */
127 GLint maxPbufferWidth;
128 GLint maxPbufferHeight;
129 GLint maxPbufferPixels;
130 GLint optimalPbufferWidth; /* Only for SGIX_pbuffer. */
131 GLint optimalPbufferHeight; /* Only for SGIX_pbuffer. */
132
133 /* SGIX_visual_select_group */
134 GLint visualSelectGroup;
135
136 /* OML_swap_method */
137 GLint swapMethod;
138
139 GLint screen;
140
141 /* EXT_texture_from_pixmap */
142 GLint bindToTextureRgb;
143 GLint bindToTextureRgba;
144 GLint bindToMipmapTexture;
145 GLint bindToTextureTargets;
146 GLint yInverted;
147 } __GLcontextModes;
148
149 /* Several fields of __GLcontextModes can take these as values. Since
150 * GLX header files may not be available everywhere they need to be used,
151 * redefine them here.
152 */
153 #define GLX_NONE 0x8000
154 #define GLX_SLOW_CONFIG 0x8001
155 #define GLX_TRUE_COLOR 0x8002
156 #define GLX_DIRECT_COLOR 0x8003
157 #define GLX_PSEUDO_COLOR 0x8004
158 #define GLX_STATIC_COLOR 0x8005
159 #define GLX_GRAY_SCALE 0x8006
160 #define GLX_STATIC_GRAY 0x8007
161 #define GLX_TRANSPARENT_RGB 0x8008
162 #define GLX_TRANSPARENT_INDEX 0x8009
163 #define GLX_NON_CONFORMANT_CONFIG 0x800D
164 #define GLX_SWAP_EXCHANGE_OML 0x8061
165 #define GLX_SWAP_COPY_OML 0x8062
166 #define GLX_SWAP_UNDEFINED_OML 0x8063
167
168 #define GLX_DONT_CARE 0xFFFFFFFF
169
170 #define GLX_RGBA_BIT 0x00000001
171 #define GLX_COLOR_INDEX_BIT 0x00000002
172 #define GLX_WINDOW_BIT 0x00000001
173 #define GLX_PIXMAP_BIT 0x00000002
174 #define GLX_PBUFFER_BIT 0x00000004
175
176 #define GLX_Y_INVERTED_EXT 0x6009
177 #define GLX_BIND_TO_TEXTURE_RGB_EXT 0x600A
178 #define GLX_BIND_TO_TEXTURE_RGBA_EXT 0x600B
179 #define GLX_BIND_TO_MIPMAP_TEXTURE_EXT 0x600C
180 #define GLX_BIND_TO_TEXTURE_TARGETS_EXT 0x600D
181
182 #define GLX_TEXTURE_1D_BIT_EXT 0x00000001
183 #define GLX_TEXTURE_2D_BIT_EXT 0x00000002
184 #define GLX_TEXTURE_RECTANGLE_BIT_EXT 0x00000004
185
186
187 /************************************************************************/
188
189 /*
190 ** Structure used for allocating and freeing drawable private memory.
191 ** (like software buffers, for example).
192 **
193 ** The memory allocation routines are provided by the surrounding
194 ** "operating system" code, and they are to be used for allocating
195 ** software buffers and things which are associated with the drawable,
196 ** and used by any context which draws to that drawable. There are
197 ** separate memory allocation functions for drawables and contexts
198 ** since drawables and contexts can be created and destroyed independently
199 ** of one another, and the "operating system" may want to use separate
200 ** allocation arenas for each.
201 **
202 ** The freePrivate function is filled in by the core routines when they
203 ** allocates software buffers, and stick them in "private". The freePrivate
204 ** function will destroy anything allocated to this drawable (to be called
205 ** when the drawable is destroyed).
206 */
207 typedef struct __GLdrawableRegionRec __GLdrawableRegion;
208 typedef struct __GLdrawableBufferRec __GLdrawableBuffer;
209 typedef struct __GLdrawablePrivateRec __GLdrawablePrivate;
210
211 typedef struct __GLregionRectRec {
212 /* lower left (inside the rectangle) */
213 GLint x0, y0;
214 /* upper right (outside the rectangle) */
215 GLint x1, y1;
216 } __GLregionRect;
217
218 struct __GLdrawableRegionRec {
219 GLint numRects;
220 __GLregionRect *rects;
221 __GLregionRect boundingRect;
222 };
223
224 /************************************************************************/
225
226 /* masks for the buffers */
227 #define __GL_FRONT_BUFFER_MASK 0x00000001
228 #define __GL_FRONT_LEFT_BUFFER_MASK 0x00000001
229 #define __GL_FRONT_RIGHT_BUFFER_MASK 0x00000002
230 #define __GL_BACK_BUFFER_MASK 0x00000004
231 #define __GL_BACK_LEFT_BUFFER_MASK 0x00000004
232 #define __GL_BACK_RIGHT_BUFFER_MASK 0x00000008
233 #define __GL_ACCUM_BUFFER_MASK 0x00000010
234 #define __GL_DEPTH_BUFFER_MASK 0x00000020
235 #define __GL_STENCIL_BUFFER_MASK 0x00000040
236 #define __GL_AUX_BUFFER_MASK(i) (0x0000080 << (i))
237
238 #define __GL_ALL_BUFFER_MASK 0xffffffff
239
240 /* what Resize routines return if resize resorted to fallback case */
241 #define __GL_BUFFER_FALLBACK 0x10
242
243 typedef void (*__GLbufFallbackInitFn)(__GLdrawableBuffer *buf,
244 __GLdrawablePrivate *glPriv, GLint bits);
245 typedef void (*__GLbufMainInitFn)(__GLdrawableBuffer *buf,
246 __GLdrawablePrivate *glPriv, GLint bits,
247 __GLbufFallbackInitFn back);
248
249 /*
250 ** A drawable buffer
251 **
252 ** This data structure describes the context side of a drawable.
253 **
254 ** According to the spec there could be multiple contexts bound to the same
255 ** drawable at the same time (from different threads). In order to avoid
256 ** multiple-access conflicts, locks are used to serialize access. When a
257 ** thread needs to access (read or write) a member of the drawable, it takes
258 ** a lock first. Some of the entries in the drawable are treated "mostly
259 ** constant", so we take the freedom of allowing access to them without
260 ** taking a lock (for optimization reasons).
261 **
262 ** For more details regarding locking, see buffers.h in the GL core
263 */
264 struct __GLdrawableBufferRec {
265 /*
266 ** Buffer dimensions
267 */
268 GLint width, height, depth;
269
270 /*
271 ** Framebuffer base address
272 */
273 void *base;
274
275 /*
276 ** Framebuffer size (in bytes)
277 */
278 GLuint size;
279
280 /*
281 ** Size (in bytes) of each element in the framebuffer
282 */
283 GLuint elementSize;
284 GLuint elementSizeLog2;
285
286 /*
287 ** Element skip from one scanline to the next.
288 ** If the buffer is part of another buffer (for example, fullscreen
289 ** front buffer), outerWidth is the width of that buffer.
290 */
291 GLint outerWidth;
292
293 /*
294 ** outerWidth * elementSize
295 */
296 GLint byteWidth;
297
298 /*
299 ** Allocation/deallocation is done based on this handle. A handle
300 ** is conceptually different from the framebuffer 'base'.
301 */
302 void *handle;
303
304 /* imported */
305 GLboolean (*resize)(__GLdrawableBuffer *buf,
306 GLint x, GLint y, GLuint width, GLuint height,
307 __GLdrawablePrivate *glPriv, GLuint bufferMask);
308 void (*lock)(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv);
309 void (*unlock)(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv);
310 void (*fill)(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv,
311 GLuint val, GLint x, GLint y, GLint w, GLint h);
312 void (*free)(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv);
313
314 /* exported */
315 void (*freePrivate)(__GLdrawableBuffer *buf, __GLdrawablePrivate *glPriv);
316 #ifdef __cplusplus
317 void *privatePtr;
318 #else
319 void *private;
320 #endif
321
322 /* private */
323 void *other; /* implementation private data */
324 __GLbufMainInitFn mainInit;
325 __GLbufFallbackInitFn fallbackInit;
326 };
327
328 /*
329 ** The context side of the drawable private
330 */
331 struct __GLdrawablePrivateRec {
332 /*
333 ** Drawable Modes
334 */
335 __GLcontextModes *modes;
336
337 /*
338 ** Drawable size
339 */
340 GLuint width, height;
341
342 /*
343 ** Origin in screen coordinates of the drawable
344 */
345 GLint xOrigin, yOrigin;
346 #ifdef __GL_ALIGNED_BUFFERS
347 /*
348 ** Drawable offset from screen origin
349 */
350 GLint xOffset, yOffset;
351
352 /*
353 ** Alignment restriction
354 */
355 GLint xAlignment, yAlignment;
356 #endif
357 /*
358 ** Should we invert the y axis?
359 */
360 GLint yInverted;
361
362 /*
363 ** Mask specifying which buffers are renderable by the hw
364 */
365 GLuint accelBufferMask;
366
367 /*
368 ** the buffers themselves
369 */
370 __GLdrawableBuffer frontBuffer;
371 __GLdrawableBuffer backBuffer;
372 __GLdrawableBuffer accumBuffer;
373 __GLdrawableBuffer depthBuffer;
374 __GLdrawableBuffer stencilBuffer;
375 #if defined(__GL_NUMBER_OF_AUX_BUFFERS) && (__GL_NUMBER_OF_AUX_BUFFERS > 0)
376 __GLdrawableBuffer *auxBuffer;
377 #endif
378
379 __GLdrawableRegion ownershipRegion;
380
381 /*
382 ** Lock for the drawable private structure
383 */
384 void *lock;
385 #ifdef DEBUG
386 /* lock debugging info */
387 int lockRefCount;
388 int lockLine[10];
389 char *lockFile[10];
390 #endif
391
392 /* imported */
393 void *(*malloc)(size_t size);
394 void *(*calloc)(size_t numElem, size_t elemSize);
395 void *(*realloc)(void *oldAddr, size_t newSize);
396 void (*free)(void *addr);
397
398 GLboolean (*addSwapRect)(__GLdrawablePrivate *glPriv,
399 GLint x, GLint y, GLsizei width, GLsizei height);
400 void (*setClipRect)(__GLdrawablePrivate *glPriv,
401 GLint x, GLint y, GLsizei width, GLsizei height);
402 void (*updateClipRegion)(__GLdrawablePrivate *glPriv);
403 GLboolean (*resize)(__GLdrawablePrivate *glPriv);
404 void (*getDrawableSize)(__GLdrawablePrivate *glPriv,
405 GLint *x, GLint *y, GLuint *width, GLuint *height);
406
407 void (*lockDP)(__GLdrawablePrivate *glPriv, __GLcontext *gc);
408 void (*unlockDP)(__GLdrawablePrivate *glPriv);
409
410 /* exported */
411 #ifdef __cplusplus
412 void *privatePtr;
413 #else
414 void *private;
415 #endif
416 void (*freePrivate)(__GLdrawablePrivate *);
417
418 /* client data */
419 void *other;
420 };
421
422 /*
423 ** Macros to lock/unlock the drawable private
424 */
425 #if defined(DEBUG)
426 #define __GL_LOCK_DP(glPriv,gc) \
427 (*(glPriv)->lockDP)(glPriv,gc); \
428 (glPriv)->lockLine[(glPriv)->lockRefCount] = __LINE__; \
429 (glPriv)->lockFile[(glPriv)->lockRefCount] = __FILE__; \
430 (glPriv)->lockRefCount++
431 #define __GL_UNLOCK_DP(glPriv) \
432 (glPriv)->lockRefCount--; \
433 (glPriv)->lockLine[(glPriv)->lockRefCount] = 0; \
434 (glPriv)->lockFile[(glPriv)->lockRefCount] = NULL; \
435 (*(glPriv)->unlockDP)(glPriv)
436 #else /* DEBUG */
437 #define __GL_LOCK_DP(glPriv,gc) (*(glPriv)->lockDP)(glPriv,gc)
438 #define __GL_UNLOCK_DP(glPriv) (*(glPriv)->unlockDP)(glPriv)
439 #endif /* DEBUG */
440
441
442 /*
443 ** Procedures which are imported by the GL from the surrounding
444 ** "operating system". Math functions are not considered part of the
445 ** "operating system".
446 */
447 typedef struct __GLimportsRec {
448 /* Memory management */
449 void * (*malloc)(__GLcontext *gc, size_t size);
450 void *(*calloc)(__GLcontext *gc, size_t numElem, size_t elemSize);
451 void *(*realloc)(__GLcontext *gc, void *oldAddr, size_t newSize);
452 void (*free)(__GLcontext *gc, void *addr);
453
454 /* Error handling */
455 void (*warning)(__GLcontext *gc, char *fmt);
456 void (*fatal)(__GLcontext *gc, char *fmt);
457
458 /* other system calls */
459 char *(CAPI *getenv)(__GLcontext *gc, const char *var);
460 int (CAPI *atoi)(__GLcontext *gc, const char *str);
461 int (CAPI *sprintf)(__GLcontext *gc, char *str, const char *fmt, ...);
462 void *(CAPI *fopen)(__GLcontext *gc, const char *path, const char *mode);
463 int (CAPI *fclose)(__GLcontext *gc, void *stream);
464 int (CAPI *fprintf)(__GLcontext *gc, void *stream, const char *fmt, ...);
465
466 /* Drawing surface management */
467 __GLdrawablePrivate *(*getDrawablePrivate)(__GLcontext *gc);
468 __GLdrawablePrivate *(*getReadablePrivate)(__GLcontext *gc);
469
470 /* Operating system dependent data goes here */
471 void *other;
472 } __GLimports;
473
474 /************************************************************************/
475
476 /*
477 ** Procedures which are exported by the GL to the surrounding "operating
478 ** system" so that it can manage multiple GL context's.
479 */
480 typedef struct __GLexportsRec {
481 /* Context management (return GL_FALSE on failure) */
482 GLboolean (*destroyContext)(__GLcontext *gc);
483 GLboolean (*loseCurrent)(__GLcontext *gc);
484 /* oldglPriv isn't used anymore, kept for backwards compatibility */
485 GLboolean (*makeCurrent)(__GLcontext *gc);
486 GLboolean (*shareContext)(__GLcontext *gc, __GLcontext *gcShare);
487 GLboolean (*copyContext)(__GLcontext *dst, const __GLcontext *src, GLuint mask);
488 GLboolean (*forceCurrent)(__GLcontext *gc);
489
490 /* Drawing surface notification callbacks */
491 GLboolean (*notifyResize)(__GLcontext *gc);
492 void (*notifyDestroy)(__GLcontext *gc);
493 void (*notifySwapBuffers)(__GLcontext *gc);
494
495 /* Dispatch table override control for external agents like libGLS */
496 struct __GLdispatchStateRec* (*dispatchExec)(__GLcontext *gc);
497 void (*beginDispatchOverride)(__GLcontext *gc);
498 void (*endDispatchOverride)(__GLcontext *gc);
499 } __GLexports;
500
501 /************************************************************************/
502
503 /*
504 ** This must be the first member of a __GLcontext structure. This is the
505 ** only part of a context that is exposed to the outside world; everything
506 ** else is opaque.
507 */
508 struct __GLinterfaceRec {
509 __GLimports imports;
510 __GLexports exports;
511 };
512
513 extern __GLcontext *__glCoreCreateContext(__GLimports *, __GLcontextModes *);
514 extern void __glCoreNopDispatch(void);
515
516 #endif /* __gl_core_h_ */