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