Add a facility to route all rasterization through a fragment program
[mesa.git] / src / mesa / main / mtypes.h
1 /**
2 * \file mtypes.h
3 * Main Mesa data structures.
4 *
5 * Please try to mark derived values with a leading underscore ('_').
6 */
7
8 /*
9 * Mesa 3-D graphics library
10 * Version: 6.3
11 *
12 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be included
22 * in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
28 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 */
31
32
33
34 #ifndef TYPES_H
35 #define TYPES_H
36
37
38 #include "glheader.h"
39 #include "config.h" /* Hardwired parameters */
40 #include "glapitable.h"
41 #include "glthread.h"
42 #include "math/m_matrix.h" /* GLmatrix */
43
44
45 /**
46 * Color channel data type.
47 */
48 #if CHAN_BITS == 8
49 typedef GLubyte GLchan;
50 #define CHAN_MAX 255
51 #define CHAN_MAXF 255.0F
52 #define CHAN_TYPE GL_UNSIGNED_BYTE
53 #elif CHAN_BITS == 16
54 typedef GLushort GLchan;
55 #define CHAN_MAX 65535
56 #define CHAN_MAXF 65535.0F
57 #define CHAN_TYPE GL_UNSIGNED_SHORT
58 #elif CHAN_BITS == 32
59 typedef GLfloat GLchan;
60 #define CHAN_MAX 1.0
61 #define CHAN_MAXF 1.0F
62 #define CHAN_TYPE GL_FLOAT
63 #else
64 #error "illegal number of color channel bits"
65 #endif
66
67
68 /**
69 * Accumulation buffer data type.
70 */
71 #if ACCUM_BITS==8
72 typedef GLbyte GLaccum;
73 #elif ACCUM_BITS==16
74 typedef GLshort GLaccum;
75 #elif ACCUM_BITS==32
76 typedef GLfloat GLaccum;
77 #else
78 # error "illegal number of accumulation bits"
79 #endif
80
81
82 /**
83 * Stencil buffer data type.
84 */
85 #if STENCIL_BITS==8
86 typedef GLubyte GLstencil;
87 # define STENCIL_MAX 0xff
88 #elif STENCIL_BITS==16
89 typedef GLushort GLstencil;
90 # define STENCIL_MAX 0xffff
91 #else
92 # error "illegal number of stencil bits"
93 #endif
94
95
96 /**
97 * Used for storing intermediate depth buffer values.
98 * The actual depth/Z buffer might use 16 or 32-bit values.
99 *
100 * \note Must be 32-bits!
101 */
102 typedef GLuint GLdepth;
103
104
105 /**
106 * Fixed point data type.
107 */
108 typedef int GLfixed;
109 /*
110 * Fixed point arithmetic macros
111 */
112 #ifndef FIXED_FRAC_BITS
113 #define FIXED_FRAC_BITS 11
114 #endif
115
116 #define FIXED_SHIFT FIXED_FRAC_BITS
117 #define FIXED_ONE (1 << FIXED_SHIFT)
118 #define FIXED_HALF (1 << (FIXED_SHIFT-1))
119 #define FIXED_FRAC_MASK (FIXED_ONE - 1)
120 #define FIXED_INT_MASK (~FIXED_FRAC_MASK)
121 #define FIXED_EPSILON 1
122 #define FIXED_SCALE ((float) FIXED_ONE)
123 #define FIXED_DBL_SCALE ((double) FIXED_ONE)
124 #define FloatToFixed(X) (IROUND((X) * FIXED_SCALE))
125 #define FixedToDouble(X) ((X) * (1.0 / FIXED_DBL_SCALE))
126 #define IntToFixed(I) ((I) << FIXED_SHIFT)
127 #define FixedToInt(X) ((X) >> FIXED_SHIFT)
128 #define FixedToUns(X) (((unsigned int)(X)) >> FIXED_SHIFT)
129 #define FixedCeil(X) (((X) + FIXED_ONE - FIXED_EPSILON) & FIXED_INT_MASK)
130 #define FixedFloor(X) ((X) & FIXED_INT_MASK)
131 #define FixedToFloat(X) ((X) * (1.0F / FIXED_SCALE))
132 #define PosFloatToFixed(X) FloatToFixed(X)
133 #define SignedFloatToFixed(X) FloatToFixed(X)
134
135
136
137 /**
138 * \name Some forward type declarations
139 */
140 /*@{*/
141 struct _mesa_HashTable;
142 struct gl_texture_image;
143 struct gl_texture_object;
144 typedef struct __GLcontextRec GLcontext;
145 typedef struct __GLcontextModesRec GLvisual;
146 typedef struct gl_frame_buffer GLframebuffer;
147 struct gl_pixelstore_attrib;
148 struct gl_texture_format;
149 /*@}*/
150
151
152
153 /**
154 * Indexes for vertex program attributes.
155 * GL_NV_vertex_program aliases generic attributes over the conventional
156 * attributes. In GL_ARB_vertex_program shader the aliasing is optional.
157 * In GL_ARB_vertex_shader / OpenGL 2.0 the aliasing is disallowed (the
158 * generic attributes are distinct/separate).
159 */
160 enum
161 {
162 VERT_ATTRIB_POS = 0,
163 VERT_ATTRIB_WEIGHT = 1,
164 VERT_ATTRIB_NORMAL = 2,
165 VERT_ATTRIB_COLOR0 = 3,
166 VERT_ATTRIB_COLOR1 = 4,
167 VERT_ATTRIB_FOG = 5,
168 VERT_ATTRIB_SIX = 6,
169 VERT_ATTRIB_SEVEN = 7,
170 VERT_ATTRIB_TEX0 = 8,
171 VERT_ATTRIB_TEX1 = 9,
172 VERT_ATTRIB_TEX2 = 10,
173 VERT_ATTRIB_TEX3 = 11,
174 VERT_ATTRIB_TEX4 = 12,
175 VERT_ATTRIB_TEX5 = 13,
176 VERT_ATTRIB_TEX6 = 14,
177 VERT_ATTRIB_TEX7 = 15,
178 VERT_ATTRIB_GENERIC0 = 16,
179 VERT_ATTRIB_GENERIC1 = 17,
180 VERT_ATTRIB_GENERIC2 = 18,
181 VERT_ATTRIB_GENERIC3 = 19,
182 VERT_ATTRIB_MAX = 16
183 };
184
185 /**
186 * Bitflags for vertex attributes.
187 * These are used in bitfields in many places.
188 */
189 /*@{*/
190 #define VERT_BIT_POS (1 << VERT_ATTRIB_POS)
191 #define VERT_BIT_WEIGHT (1 << VERT_ATTRIB_WEIGHT)
192 #define VERT_BIT_NORMAL (1 << VERT_ATTRIB_NORMAL)
193 #define VERT_BIT_COLOR0 (1 << VERT_ATTRIB_COLOR0)
194 #define VERT_BIT_COLOR1 (1 << VERT_ATTRIB_COLOR1)
195 #define VERT_BIT_FOG (1 << VERT_ATTRIB_FOG)
196 #define VERT_BIT_SIX (1 << VERT_ATTRIB_SIX)
197 #define VERT_BIT_SEVEN (1 << VERT_ATTRIB_SEVEN)
198 #define VERT_BIT_TEX0 (1 << VERT_ATTRIB_TEX0)
199 #define VERT_BIT_TEX1 (1 << VERT_ATTRIB_TEX1)
200 #define VERT_BIT_TEX2 (1 << VERT_ATTRIB_TEX2)
201 #define VERT_BIT_TEX3 (1 << VERT_ATTRIB_TEX3)
202 #define VERT_BIT_TEX4 (1 << VERT_ATTRIB_TEX4)
203 #define VERT_BIT_TEX5 (1 << VERT_ATTRIB_TEX5)
204 #define VERT_BIT_TEX6 (1 << VERT_ATTRIB_TEX6)
205 #define VERT_BIT_TEX7 (1 << VERT_ATTRIB_TEX7)
206 #define VERT_BIT_GENERIC0 (1 << VERT_ATTRIB_GENERIC0)
207 #define VERT_BIT_GENERIC1 (1 << VERT_ATTRIB_GENERIC1)
208 #define VERT_BIT_GENERIC2 (1 << VERT_ATTRIB_GENERIC2)
209 #define VERT_BIT_GENERIC3 (1 << VERT_ATTRIB_GENERIC3)
210
211 #define VERT_BIT_TEX(u) (1 << (VERT_ATTRIB_TEX0 + (u)))
212 #define VERT_BIT_GENERIC(g) (1 << (VERT_ATTRIB_GENERIC0 + (g)))
213 /*@}*/
214
215
216 /**
217 * Indexes for vertex program result attributes
218 */
219 #define VERT_RESULT_HPOS 0
220 #define VERT_RESULT_COL0 1
221 #define VERT_RESULT_COL1 2
222 #define VERT_RESULT_BFC0 3
223 #define VERT_RESULT_BFC1 4
224 #define VERT_RESULT_FOGC 5
225 #define VERT_RESULT_PSIZ 6
226 #define VERT_RESULT_TEX0 7
227 #define VERT_RESULT_TEX1 8
228 #define VERT_RESULT_TEX2 9
229 #define VERT_RESULT_TEX3 10
230 #define VERT_RESULT_TEX4 11
231 #define VERT_RESULT_TEX5 12
232 #define VERT_RESULT_TEX6 13
233 #define VERT_RESULT_TEX7 14
234 #define VERT_RESULT_MAX 15
235
236
237 /**
238 * Indexes for fragment program input attributes.
239 */
240 enum
241 {
242 FRAG_ATTRIB_WPOS = 0,
243 FRAG_ATTRIB_COL0 = 1,
244 FRAG_ATTRIB_COL1 = 2,
245 FRAG_ATTRIB_FOGC = 3,
246 FRAG_ATTRIB_TEX0 = 4,
247 FRAG_ATTRIB_TEX1 = 5,
248 FRAG_ATTRIB_TEX2 = 6,
249 FRAG_ATTRIB_TEX3 = 7,
250 FRAG_ATTRIB_TEX4 = 8,
251 FRAG_ATTRIB_TEX5 = 9,
252 FRAG_ATTRIB_TEX6 = 10,
253 FRAG_ATTRIB_TEX7 = 11
254 };
255
256 /*
257 * Bitflags for fragment attributes.
258 */
259 /*@{*/
260 #define FRAG_BIT_WPOS (1 << FRAG_ATTRIB_WPOS)
261 #define FRAG_BIT_COL0 (1 << FRAG_ATTRIB_COL0)
262 #define FRAG_BIT_COL1 (1 << FRAG_ATTRIB_COL1)
263 #define FRAG_BIT_FOGC (1 << FRAG_ATTRIB_FOGC)
264 #define FRAG_BIT_TEX0 (1 << FRAG_ATTRIB_TEX0)
265 #define FRAG_BIT_TEX1 (1 << FRAG_ATTRIB_TEX1)
266 #define FRAG_BIT_TEX2 (1 << FRAG_ATTRIB_TEX2)
267 #define FRAG_BIT_TEX3 (1 << FRAG_ATTRIB_TEX3)
268 #define FRAG_BIT_TEX4 (1 << FRAG_ATTRIB_TEX4)
269 #define FRAG_BIT_TEX5 (1 << FRAG_ATTRIB_TEX5)
270 #define FRAG_BIT_TEX6 (1 << FRAG_ATTRIB_TEX6)
271 #define FRAG_BIT_TEX7 (1 << FRAG_ATTRIB_TEX7)
272
273 #define FRAG_BITS_TEX_ANY (FRAG_BIT_TEX0| \
274 FRAG_BIT_TEX1| \
275 FRAG_BIT_TEX2| \
276 FRAG_BIT_TEX3| \
277 FRAG_BIT_TEX4| \
278 FRAG_BIT_TEX5| \
279 FRAG_BIT_TEX6| \
280 FRAG_BIT_TEX7)
281 /*@}*/
282
283
284 /**
285 * Bits for each basic buffer in a complete framebuffer.
286 * When glDrawBuffer(GL_FRONT_AND_BACK) is called (non-stereo),
287 * _DrawDestMask will be set to (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT),
288 * for example. Also passed to ctx->Driver.Clear() to indicate which
289 * buffers to clear.
290 */
291 /*@{*/
292 #define DD_FRONT_LEFT_BIT 0x1
293 #define DD_FRONT_RIGHT_BIT 0x2
294 #define DD_BACK_LEFT_BIT 0x4
295 #define DD_BACK_RIGHT_BIT 0x8
296 #define DD_AUX0_BIT 0x10
297 #define DD_AUX1_BIT 0x20
298 #define DD_AUX2_BIT 0x40
299 #define DD_AUX3_BIT 0x80
300 #define DD_DEPTH_BIT GL_DEPTH_BUFFER_BIT /* 0x00000100 */
301 #define DD_ACCUM_BIT GL_ACCUM_BUFFER_BIT /* 0x00000200 */
302 #define DD_STENCIL_BIT GL_STENCIL_BUFFER_BIT /* 0x00000400 */
303 /*@}*/
304
305
306 /**
307 * Data structure for color tables
308 */
309 struct gl_color_table
310 {
311 GLenum Format; /**< GL_ALPHA, GL_RGB, GL_RGB, etc */
312 GLenum IntFormat;
313 GLuint Size; /**< number of entries (rows) in table */
314 GLvoid *Table; /**< points to data of <Type> */
315 GLenum Type; /**< GL_UNSIGNED_BYTE or GL_FLOAT */
316 GLubyte RedSize;
317 GLubyte GreenSize;
318 GLubyte BlueSize;
319 GLubyte AlphaSize;
320 GLubyte LuminanceSize;
321 GLubyte IntensitySize;
322 };
323
324
325 /**
326 * \name Bit flags used for updating material values.
327 */
328 /*@{*/
329 #define MAT_ATTRIB_FRONT_AMBIENT 0
330 #define MAT_ATTRIB_BACK_AMBIENT 1
331 #define MAT_ATTRIB_FRONT_DIFFUSE 2
332 #define MAT_ATTRIB_BACK_DIFFUSE 3
333 #define MAT_ATTRIB_FRONT_SPECULAR 4
334 #define MAT_ATTRIB_BACK_SPECULAR 5
335 #define MAT_ATTRIB_FRONT_EMISSION 6
336 #define MAT_ATTRIB_BACK_EMISSION 7
337 #define MAT_ATTRIB_FRONT_SHININESS 8
338 #define MAT_ATTRIB_BACK_SHININESS 9
339 #define MAT_ATTRIB_FRONT_INDEXES 10
340 #define MAT_ATTRIB_BACK_INDEXES 11
341 #define MAT_ATTRIB_MAX 12
342
343 #define MAT_ATTRIB_AMBIENT(f) (MAT_ATTRIB_FRONT_AMBIENT+(f))
344 #define MAT_ATTRIB_DIFFUSE(f) (MAT_ATTRIB_FRONT_DIFFUSE+(f))
345 #define MAT_ATTRIB_SPECULAR(f) (MAT_ATTRIB_FRONT_SPECULAR+(f))
346 #define MAT_ATTRIB_EMISSION(f) (MAT_ATTRIB_FRONT_EMISSION+(f))
347 #define MAT_ATTRIB_SHININESS(f)(MAT_ATTRIB_FRONT_SHININESS+(f))
348 #define MAT_ATTRIB_INDEXES(f) (MAT_ATTRIB_FRONT_INDEXES+(f))
349
350 #define MAT_INDEX_AMBIENT 0
351 #define MAT_INDEX_DIFFUSE 1
352 #define MAT_INDEX_SPECULAR 2
353
354 #define MAT_BIT_FRONT_AMBIENT (1<<MAT_ATTRIB_FRONT_AMBIENT)
355 #define MAT_BIT_BACK_AMBIENT (1<<MAT_ATTRIB_BACK_AMBIENT)
356 #define MAT_BIT_FRONT_DIFFUSE (1<<MAT_ATTRIB_FRONT_DIFFUSE)
357 #define MAT_BIT_BACK_DIFFUSE (1<<MAT_ATTRIB_BACK_DIFFUSE)
358 #define MAT_BIT_FRONT_SPECULAR (1<<MAT_ATTRIB_FRONT_SPECULAR)
359 #define MAT_BIT_BACK_SPECULAR (1<<MAT_ATTRIB_BACK_SPECULAR)
360 #define MAT_BIT_FRONT_EMISSION (1<<MAT_ATTRIB_FRONT_EMISSION)
361 #define MAT_BIT_BACK_EMISSION (1<<MAT_ATTRIB_BACK_EMISSION)
362 #define MAT_BIT_FRONT_SHININESS (1<<MAT_ATTRIB_FRONT_SHININESS)
363 #define MAT_BIT_BACK_SHININESS (1<<MAT_ATTRIB_BACK_SHININESS)
364 #define MAT_BIT_FRONT_INDEXES (1<<MAT_ATTRIB_FRONT_INDEXES)
365 #define MAT_BIT_BACK_INDEXES (1<<MAT_ATTRIB_BACK_INDEXES)
366
367
368 #define FRONT_MATERIAL_BITS (MAT_BIT_FRONT_EMISSION | \
369 MAT_BIT_FRONT_AMBIENT | \
370 MAT_BIT_FRONT_DIFFUSE | \
371 MAT_BIT_FRONT_SPECULAR | \
372 MAT_BIT_FRONT_SHININESS | \
373 MAT_BIT_FRONT_INDEXES)
374
375 #define BACK_MATERIAL_BITS (MAT_BIT_BACK_EMISSION | \
376 MAT_BIT_BACK_AMBIENT | \
377 MAT_BIT_BACK_DIFFUSE | \
378 MAT_BIT_BACK_SPECULAR | \
379 MAT_BIT_BACK_SHININESS | \
380 MAT_BIT_BACK_INDEXES)
381
382 #define ALL_MATERIAL_BITS (FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
383 /*@}*/
384
385
386 #define EXP_TABLE_SIZE 512 /**< Specular exponent lookup table sizes */
387 #define SHINE_TABLE_SIZE 256 /**< Material shininess lookup table sizes */
388
389 /**
390 * Material shininess lookup table.
391 */
392 struct gl_shine_tab
393 {
394 struct gl_shine_tab *next, *prev;
395 GLfloat tab[SHINE_TABLE_SIZE+1];
396 GLfloat shininess;
397 GLuint refcount;
398 };
399
400
401 /**
402 * Light source state.
403 */
404 struct gl_light
405 {
406 struct gl_light *next; /**< double linked list with sentinel */
407 struct gl_light *prev;
408
409 GLfloat Ambient[4]; /**< ambient color */
410 GLfloat Diffuse[4]; /**< diffuse color */
411 GLfloat Specular[4]; /**< specular color */
412 GLfloat EyePosition[4]; /**< position in eye coordinates */
413 GLfloat EyeDirection[4]; /**< spotlight dir in eye coordinates */
414 GLfloat SpotExponent;
415 GLfloat SpotCutoff; /**< in degrees */
416 GLfloat _CosCutoff; /**< = MAX(0, cos(SpotCutoff)) */
417 GLfloat ConstantAttenuation;
418 GLfloat LinearAttenuation;
419 GLfloat QuadraticAttenuation;
420 GLboolean Enabled; /**< On/off flag */
421
422 /**
423 * \name Derived fields
424 */
425 /*@{*/
426 GLuint _Flags; /**< State */
427
428 GLfloat _Position[4]; /**< position in eye/obj coordinates */
429 GLfloat _VP_inf_norm[3]; /**< Norm direction to infinite light */
430 GLfloat _h_inf_norm[3]; /**< Norm( _VP_inf_norm + <0,0,1> ) */
431 GLfloat _NormDirection[4]; /**< normalized spotlight direction */
432 GLfloat _VP_inf_spot_attenuation;
433
434 GLfloat _SpotExpTable[EXP_TABLE_SIZE][2]; /**< to replace a pow() call */
435 GLfloat _MatAmbient[2][3]; /**< material ambient * light ambient */
436 GLfloat _MatDiffuse[2][3]; /**< material diffuse * light diffuse */
437 GLfloat _MatSpecular[2][3]; /**< material spec * light specular */
438 GLfloat _dli; /**< CI diffuse light intensity */
439 GLfloat _sli; /**< CI specular light intensity */
440 /*@}*/
441 };
442
443
444 /**
445 * Light model state.
446 */
447 struct gl_lightmodel
448 {
449 GLfloat Ambient[4]; /**< ambient color */
450 GLboolean LocalViewer; /**< Local (or infinite) view point? */
451 GLboolean TwoSide; /**< Two (or one) sided lighting? */
452 GLenum ColorControl; /**< either GL_SINGLE_COLOR
453 * or GL_SEPARATE_SPECULAR_COLOR */
454 };
455
456
457 /**
458 * Material state.
459 */
460 struct gl_material
461 {
462 GLfloat Attrib[MAT_ATTRIB_MAX][4];
463 };
464
465
466 /**
467 * Accumulation buffer attribute group (GL_ACCUM_BUFFER_BIT)
468 */
469 struct gl_accum_attrib
470 {
471 GLfloat ClearColor[4]; /**< Accumulation buffer clear color */
472 };
473
474
475 /**
476 * Color buffer attribute group (GL_COLOR_BUFFER_BIT).
477 */
478 struct gl_colorbuffer_attrib
479 {
480 GLuint ClearIndex; /**< Index to use for glClear */
481 GLclampf ClearColor[4]; /**< Color to use for glClear */
482
483 GLuint IndexMask; /**< Color index write mask */
484 GLubyte ColorMask[4]; /**< Each flag is 0xff or 0x0 */
485
486 GLenum DrawBuffer[MAX_DRAW_BUFFERS]; /**< Which buffer to draw into */
487 GLbitfield _DrawDestMask[MAX_DRAW_BUFFERS];/**< bitmask of DD_*_BIT bits */
488
489 /**
490 * \name alpha testing
491 */
492 /*@{*/
493 GLboolean AlphaEnabled; /**< Alpha test enabled flag */
494 GLenum AlphaFunc; /**< Alpha test function */
495 GLclampf AlphaRef; /**< Alpha reference value */
496 /*@}*/
497
498 /**
499 * \name Blending
500 */
501 /*@{*/
502 GLboolean BlendEnabled; /**< Blending enabled flag */
503 GLenum BlendSrcRGB; /**< Blending source operator */
504 GLenum BlendDstRGB; /**< Blending destination operator */
505 GLenum BlendSrcA; /**< GL_INGR_blend_func_separate */
506 GLenum BlendDstA; /**< GL_INGR_blend_func_separate */
507 GLenum BlendEquationRGB; /**< Blending equation */
508 GLenum BlendEquationA; /**< GL_EXT_blend_equation_separate */
509 GLfloat BlendColor[4]; /**< Blending color */
510 /*@}*/
511
512 /**
513 * \name Logic op
514 */
515 /*@{*/
516 GLenum LogicOp; /**< Logic operator */
517 GLboolean IndexLogicOpEnabled; /**< Color index logic op enabled flag */
518 GLboolean ColorLogicOpEnabled; /**< RGBA logic op enabled flag */
519 GLboolean _LogicOpEnabled; /**< RGBA logic op + EXT_blend_logic_op enabled flag */
520 /*@}*/
521
522 GLboolean DitherFlag; /**< Dither enable flag */
523 };
524
525
526 /**
527 * Current attribute group (GL_CURRENT_BIT).
528 */
529 struct gl_current_attrib
530 {
531 /**
532 * \name Values valid only when FLUSH_VERTICES has been called.
533 */
534 /*@{*/
535 GLfloat Attrib[VERT_ATTRIB_MAX][4]; /**< Current vertex attributes
536 * indexed by VERT_ATTRIB_* */
537 GLfloat Index; /**< Current color index */
538 GLboolean EdgeFlag; /**< Current edge flag */
539 /*@}*/
540
541 /**
542 * \name Values are always valid.
543 *
544 * \note BTW, note how similar this set of attributes is to the SWvertex
545 * data type in the software rasterizer...
546 */
547 /*@{*/
548 GLfloat RasterPos[4]; /**< Current raster position */
549 GLfloat RasterDistance; /**< Current raster distance */
550 GLfloat RasterColor[4]; /**< Current raster color */
551 GLfloat RasterSecondaryColor[4]; /**< Current raster secondary color */
552 GLfloat RasterIndex; /**< Current raster index */
553 GLfloat RasterTexCoords[MAX_TEXTURE_UNITS][4];/**< Current raster texcoords */
554 GLboolean RasterPosValid; /**< Raster pos valid flag */
555 /*@}*/
556 };
557
558
559 /**
560 * Depth buffer attribute group (GL_DEPTH_BUFFER_BIT).
561 */
562 struct gl_depthbuffer_attrib
563 {
564 GLenum Func; /**< Function for depth buffer compare */
565 GLclampd Clear; /**< Value to clear depth buffer to */
566 GLboolean Test; /**< Depth buffering enabled flag */
567 GLboolean Mask; /**< Depth buffer writable? */
568 GLboolean OcclusionTest; /**< GL_HP_occlusion_test */
569 GLboolean BoundsTest; /**< GL_EXT_depth_bounds_test */
570 GLfloat BoundsMin, BoundsMax;/**< GL_EXT_depth_bounds_test */
571 };
572
573
574 /**
575 * glEnable()/glDisable() attribute group (GL_ENABLE_BIT).
576 */
577 struct gl_enable_attrib
578 {
579 GLboolean AlphaTest;
580 GLboolean AutoNormal;
581 GLboolean Blend;
582 GLuint ClipPlanes;
583 GLboolean ColorMaterial;
584 GLboolean ColorTable; /* SGI_color_table */
585 GLboolean PostColorMatrixColorTable; /* SGI_color_table */
586 GLboolean PostConvolutionColorTable; /* SGI_color_table */
587 GLboolean Convolution1D;
588 GLboolean Convolution2D;
589 GLboolean Separable2D;
590 GLboolean CullFace;
591 GLboolean DepthTest;
592 GLboolean Dither;
593 GLboolean Fog;
594 GLboolean Histogram;
595 GLboolean Light[MAX_LIGHTS];
596 GLboolean Lighting;
597 GLboolean LineSmooth;
598 GLboolean LineStipple;
599 GLboolean IndexLogicOp;
600 GLboolean ColorLogicOp;
601 GLboolean Map1Color4;
602 GLboolean Map1Index;
603 GLboolean Map1Normal;
604 GLboolean Map1TextureCoord1;
605 GLboolean Map1TextureCoord2;
606 GLboolean Map1TextureCoord3;
607 GLboolean Map1TextureCoord4;
608 GLboolean Map1Vertex3;
609 GLboolean Map1Vertex4;
610 GLboolean Map1Attrib[16]; /* GL_NV_vertex_program */
611 GLboolean Map2Color4;
612 GLboolean Map2Index;
613 GLboolean Map2Normal;
614 GLboolean Map2TextureCoord1;
615 GLboolean Map2TextureCoord2;
616 GLboolean Map2TextureCoord3;
617 GLboolean Map2TextureCoord4;
618 GLboolean Map2Vertex3;
619 GLboolean Map2Vertex4;
620 GLboolean Map2Attrib[16]; /* GL_NV_vertex_program */
621 GLboolean MinMax;
622 GLboolean Normalize;
623 GLboolean PixelTexture;
624 GLboolean PointSmooth;
625 GLboolean PolygonOffsetPoint;
626 GLboolean PolygonOffsetLine;
627 GLboolean PolygonOffsetFill;
628 GLboolean PolygonSmooth;
629 GLboolean PolygonStipple;
630 GLboolean RescaleNormals;
631 GLboolean Scissor;
632 GLboolean Stencil;
633 GLboolean StencilTwoSide; /* GL_EXT_stencil_two_side */
634 GLboolean MultisampleEnabled; /* GL_ARB_multisample */
635 GLboolean SampleAlphaToCoverage; /* GL_ARB_multisample */
636 GLboolean SampleAlphaToOne; /* GL_ARB_multisample */
637 GLboolean SampleCoverage; /* GL_ARB_multisample */
638 GLboolean SampleCoverageInvert; /* GL_ARB_multisample */
639 GLboolean RasterPositionUnclipped; /* GL_IBM_rasterpos_clip */
640 GLuint Texture[MAX_TEXTURE_IMAGE_UNITS];
641 GLuint TexGen[MAX_TEXTURE_COORD_UNITS];
642 /* SGI_texture_color_table */
643 GLboolean TextureColorTable[MAX_TEXTURE_IMAGE_UNITS];
644 /* GL_NV_vertex_program */
645 GLboolean VertexProgram;
646 GLboolean VertexProgramPointSize;
647 GLboolean VertexProgramTwoSide;
648 /* GL_ARB_point_sprite / GL_NV_point_sprite */
649 GLboolean PointSprite;
650 GLboolean FragmentShaderATI;
651 };
652
653
654 /**
655 * Evaluator attribute group (GL_EVAL_BIT).
656 */
657 struct gl_eval_attrib
658 {
659 /**
660 * \name Enable bits
661 */
662 /*@{*/
663 GLboolean Map1Color4;
664 GLboolean Map1Index;
665 GLboolean Map1Normal;
666 GLboolean Map1TextureCoord1;
667 GLboolean Map1TextureCoord2;
668 GLboolean Map1TextureCoord3;
669 GLboolean Map1TextureCoord4;
670 GLboolean Map1Vertex3;
671 GLboolean Map1Vertex4;
672 GLboolean Map1Attrib[16]; /* GL_NV_vertex_program */
673 GLboolean Map2Color4;
674 GLboolean Map2Index;
675 GLboolean Map2Normal;
676 GLboolean Map2TextureCoord1;
677 GLboolean Map2TextureCoord2;
678 GLboolean Map2TextureCoord3;
679 GLboolean Map2TextureCoord4;
680 GLboolean Map2Vertex3;
681 GLboolean Map2Vertex4;
682 GLboolean Map2Attrib[16]; /* GL_NV_vertex_program */
683 GLboolean AutoNormal;
684 /*@}*/
685
686 /**
687 * \name Map Grid endpoints and divisions and calculated du values
688 */
689 /*@{*/
690 GLint MapGrid1un;
691 GLfloat MapGrid1u1, MapGrid1u2, MapGrid1du;
692 GLint MapGrid2un, MapGrid2vn;
693 GLfloat MapGrid2u1, MapGrid2u2, MapGrid2du;
694 GLfloat MapGrid2v1, MapGrid2v2, MapGrid2dv;
695 /*@}*/
696 };
697
698
699 /**
700 * Fog attribute group (GL_FOG_BIT).
701 */
702 struct gl_fog_attrib
703 {
704 GLboolean Enabled; /**< Fog enabled flag */
705 GLfloat Color[4]; /**< Fog color */
706 GLfloat Density; /**< Density >= 0.0 */
707 GLfloat Start; /**< Start distance in eye coords */
708 GLfloat End; /**< End distance in eye coords */
709 GLfloat Index; /**< Fog index */
710 GLenum Mode; /**< Fog mode */
711 GLboolean ColorSumEnabled;
712 GLenum FogCoordinateSource; /**< GL_EXT_fog_coord */
713 };
714
715
716 /**
717 * Hint attribute group (GL_HINT_BIT).
718 *
719 * Values are always one of GL_FASTEST, GL_NICEST, or GL_DONT_CARE.
720 */
721 struct gl_hint_attrib
722 {
723 GLenum PerspectiveCorrection;
724 GLenum PointSmooth;
725 GLenum LineSmooth;
726 GLenum PolygonSmooth;
727 GLenum Fog;
728 GLenum ClipVolumeClipping; /**< GL_EXT_clip_volume_hint */
729 GLenum TextureCompression; /**< GL_ARB_texture_compression */
730 GLenum GenerateMipmap; /**< GL_SGIS_generate_mipmap */
731 GLenum FragmentShaderDerivative; /**< GL_ARB_fragment_shader */
732 };
733
734
735 /**
736 * Histogram attributes.
737 */
738 struct gl_histogram_attrib
739 {
740 GLuint Width; /**< number of table entries */
741 GLint Format; /**< GL_ALPHA, GL_RGB, etc */
742 GLuint Count[HISTOGRAM_TABLE_SIZE][4]; /**< the histogram */
743 GLboolean Sink; /**< terminate image transfer? */
744 GLubyte RedSize; /**< Bits per counter */
745 GLubyte GreenSize;
746 GLubyte BlueSize;
747 GLubyte AlphaSize;
748 GLubyte LuminanceSize;
749 };
750
751
752 /**
753 * Color Min/max state.
754 */
755 struct gl_minmax_attrib
756 {
757 GLenum Format;
758 GLboolean Sink;
759 GLfloat Min[4], Max[4]; /**< RGBA */
760 };
761
762
763 /**
764 * Image convolution state.
765 */
766 struct gl_convolution_attrib
767 {
768 GLenum Format;
769 GLenum InternalFormat;
770 GLuint Width;
771 GLuint Height;
772 GLfloat Filter[MAX_CONVOLUTION_WIDTH * MAX_CONVOLUTION_HEIGHT * 4];
773 };
774
775
776 /**
777 * Light state flags.
778 */
779 /*@{*/
780 #define LIGHT_SPOT 0x1
781 #define LIGHT_LOCAL_VIEWER 0x2
782 #define LIGHT_POSITIONAL 0x4
783 #define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
784 /*@}*/
785
786
787 /**
788 * Lighting attribute group (GL_LIGHT_BIT).
789 */
790 struct gl_light_attrib
791 {
792 struct gl_light Light[MAX_LIGHTS]; /**< Array of light sources */
793 struct gl_lightmodel Model; /**< Lighting model */
794
795 /**
796 * Must flush FLUSH_VERTICES before referencing:
797 */
798 /*@{*/
799 struct gl_material Material; /**< Includes front & back values */
800 /*@}*/
801
802 GLboolean Enabled; /**< Lighting enabled flag */
803 GLenum ShadeModel; /**< GL_FLAT or GL_SMOOTH */
804 GLenum ColorMaterialFace; /**< GL_FRONT, BACK or FRONT_AND_BACK */
805 GLenum ColorMaterialMode; /**< GL_AMBIENT, GL_DIFFUSE, etc */
806 GLuint ColorMaterialBitmask; /**< bitmask formed from Face and Mode */
807 GLboolean ColorMaterialEnabled;
808
809 struct gl_light EnabledList; /**< List sentinel */
810
811 /**
812 * Derived state for optimizations:
813 */
814 /*@{*/
815 GLboolean _NeedEyeCoords;
816 GLboolean _NeedVertices; /**< Use fast shader? */
817 GLuint _Flags; /**< LIGHT_* flags, see above */
818 GLfloat _BaseColor[2][3];
819 /*@}*/
820 };
821
822
823 /**
824 * Line attribute group (GL_LINE_BIT).
825 */
826 struct gl_line_attrib
827 {
828 GLboolean SmoothFlag; /**< GL_LINE_SMOOTH enabled? */
829 GLboolean StippleFlag; /**< GL_LINE_STIPPLE enabled? */
830 GLushort StipplePattern; /**< Stipple pattern */
831 GLint StippleFactor; /**< Stipple repeat factor */
832 GLfloat Width; /**< Line width */
833 GLfloat _Width; /**< Clamped Line width */
834 };
835
836
837 /**
838 * Display list attribute group (GL_LIST_BIT).
839 */
840 struct gl_list_attrib
841 {
842 GLuint ListBase;
843 };
844
845
846 /**
847 * Used by device drivers to hook new commands into display lists.
848 */
849 struct gl_list_instruction
850 {
851 GLuint Size;
852 void (*Execute)( GLcontext *ctx, void *data );
853 void (*Destroy)( GLcontext *ctx, void *data );
854 void (*Print)( GLcontext *ctx, void *data );
855 };
856
857 #define MAX_DLIST_EXT_OPCODES 16
858
859 /**
860 * Used by device drivers to hook new commands into display lists.
861 */
862 struct gl_list_extensions
863 {
864 struct gl_list_instruction Opcode[MAX_DLIST_EXT_OPCODES];
865 GLuint NumOpcodes;
866 };
867
868
869 /**
870 * Multisample attribute group (GL_MULTISAMPLE_BIT).
871 */
872 struct gl_multisample_attrib
873 {
874 GLboolean Enabled;
875 GLboolean SampleAlphaToCoverage;
876 GLboolean SampleAlphaToOne;
877 GLboolean SampleCoverage;
878 GLfloat SampleCoverageValue;
879 GLboolean SampleCoverageInvert;
880 };
881
882
883 /**
884 * Pixel attribute group (GL_PIXEL_MODE_BIT).
885 */
886 struct gl_pixel_attrib
887 {
888 GLenum ReadBuffer; /**< source buffer for glReadPixels()/glCopyPixels() */
889 GLubyte _ReadSrcMask; /**< Not really a mask, but like _DrawDestMask
890 *
891 * May be: FRONT_LEFT_BIT, BACK_LEFT_BIT,
892 * FRONT_RIGHT_BIT or BACK_RIGHT_BIT. */
893 GLfloat RedBias, RedScale;
894 GLfloat GreenBias, GreenScale;
895 GLfloat BlueBias, BlueScale;
896 GLfloat AlphaBias, AlphaScale;
897 GLfloat DepthBias, DepthScale;
898 GLint IndexShift, IndexOffset;
899 GLboolean MapColorFlag;
900 GLboolean MapStencilFlag;
901 GLfloat ZoomX, ZoomY;
902 /* XXX move these out of gl_pixel_attrib */
903 GLint MapStoSsize; /**< Size of each pixel map */
904 GLint MapItoIsize;
905 GLint MapItoRsize;
906 GLint MapItoGsize;
907 GLint MapItoBsize;
908 GLint MapItoAsize;
909 GLint MapRtoRsize;
910 GLint MapGtoGsize;
911 GLint MapBtoBsize;
912 GLint MapAtoAsize;
913 GLint MapStoS[MAX_PIXEL_MAP_TABLE]; /**< Pixel map tables */
914 GLint MapItoI[MAX_PIXEL_MAP_TABLE];
915 GLfloat MapItoR[MAX_PIXEL_MAP_TABLE];
916 GLfloat MapItoG[MAX_PIXEL_MAP_TABLE];
917 GLfloat MapItoB[MAX_PIXEL_MAP_TABLE];
918 GLfloat MapItoA[MAX_PIXEL_MAP_TABLE];
919 GLubyte MapItoR8[MAX_PIXEL_MAP_TABLE]; /**< converted to 8-bit color */
920 GLubyte MapItoG8[MAX_PIXEL_MAP_TABLE];
921 GLubyte MapItoB8[MAX_PIXEL_MAP_TABLE];
922 GLubyte MapItoA8[MAX_PIXEL_MAP_TABLE];
923 GLfloat MapRtoR[MAX_PIXEL_MAP_TABLE];
924 GLfloat MapGtoG[MAX_PIXEL_MAP_TABLE];
925 GLfloat MapBtoB[MAX_PIXEL_MAP_TABLE];
926 GLfloat MapAtoA[MAX_PIXEL_MAP_TABLE];
927 /** GL_EXT_histogram */
928 GLboolean HistogramEnabled;
929 GLboolean MinMaxEnabled;
930 /** GL_SGIS_pixel_texture */
931 GLboolean PixelTextureEnabled;
932 GLenum FragmentRgbSource;
933 GLenum FragmentAlphaSource;
934 /** GL_SGI_color_matrix */
935 GLfloat PostColorMatrixScale[4]; /**< RGBA */
936 GLfloat PostColorMatrixBias[4]; /**< RGBA */
937 /** GL_SGI_color_table */
938 GLfloat ColorTableScale[4];
939 GLfloat ColorTableBias[4];
940 GLboolean ColorTableEnabled;
941 GLfloat PCCTscale[4];
942 GLfloat PCCTbias[4];
943 GLboolean PostConvolutionColorTableEnabled;
944 GLfloat PCMCTscale[4];
945 GLfloat PCMCTbias[4];
946 GLboolean PostColorMatrixColorTableEnabled;
947 /** GL_SGI_texture_color_table */
948 GLfloat TextureColorTableScale[4];
949 GLfloat TextureColorTableBias[4];
950 /** Convolution */
951 GLboolean Convolution1DEnabled;
952 GLboolean Convolution2DEnabled;
953 GLboolean Separable2DEnabled;
954 GLfloat ConvolutionBorderColor[3][4];
955 GLenum ConvolutionBorderMode[3];
956 GLfloat ConvolutionFilterScale[3][4];
957 GLfloat ConvolutionFilterBias[3][4];
958 GLfloat PostConvolutionScale[4]; /**< RGBA */
959 GLfloat PostConvolutionBias[4]; /**< RGBA */
960 };
961
962
963 /**
964 * Point attribute group (GL_POINT_BIT).
965 */
966 struct gl_point_attrib
967 {
968 GLboolean SmoothFlag; /**< True if GL_POINT_SMOOTH is enabled */
969 GLfloat Size; /**< User-specified point size */
970 GLfloat _Size; /**< Size clamped to Const.Min/MaxPointSize */
971 GLfloat Params[3]; /**< GL_EXT_point_parameters */
972 GLfloat MinSize, MaxSize; /**< GL_EXT_point_parameters */
973 GLfloat Threshold; /**< GL_EXT_point_parameters */
974 GLboolean _Attenuated; /**< True if Params != [1, 0, 0] */
975 GLboolean PointSprite; /**< GL_NV_point_sprite / GL_NV_point_sprite */
976 GLboolean CoordReplace[MAX_TEXTURE_UNITS]; /**< GL_NV_point_sprite / GL_NV_point_sprite */
977 GLenum SpriteRMode; /**< GL_NV_point_sprite (only!) */
978 GLenum SpriteOrigin; /**< GL_ARB_point_sprite */
979 };
980
981
982 /**
983 * Polygon attribute group (GL_POLYGON_BIT).
984 */
985 struct gl_polygon_attrib
986 {
987 GLenum FrontFace; /**< Either GL_CW or GL_CCW */
988 GLenum FrontMode; /**< Either GL_POINT, GL_LINE or GL_FILL */
989 GLenum BackMode; /**< Either GL_POINT, GL_LINE or GL_FILL */
990 GLboolean _FrontBit; /**< 0=GL_CCW, 1=GL_CW */
991 GLboolean CullFlag; /**< Culling on/off flag */
992 GLboolean SmoothFlag; /**< True if GL_POLYGON_SMOOTH is enabled */
993 GLboolean StippleFlag; /**< True if GL_POLYGON_STIPPLE is enabled */
994 GLenum CullFaceMode; /**< Culling mode GL_FRONT or GL_BACK */
995 GLfloat OffsetFactor; /**< Polygon offset factor, from user */
996 GLfloat OffsetUnits; /**< Polygon offset units, from user */
997 GLboolean OffsetPoint; /**< Offset in GL_POINT mode */
998 GLboolean OffsetLine; /**< Offset in GL_LINE mode */
999 GLboolean OffsetFill; /**< Offset in GL_FILL mode */
1000 };
1001
1002
1003 /**
1004 * Scissor attributes (GL_SCISSOR_BIT).
1005 */
1006 struct gl_scissor_attrib
1007 {
1008 GLboolean Enabled; /**< Scissor test enabled? */
1009 GLint X, Y; /**< Lower left corner of box */
1010 GLsizei Width, Height; /**< Size of box */
1011 };
1012
1013
1014 /**
1015 * Stencil attribute group (GL_STENCIL_BUFFER_BIT).
1016 */
1017 struct gl_stencil_attrib
1018 {
1019 GLboolean Enabled; /**< Enabled flag */
1020 GLboolean TestTwoSide; /**< GL_EXT_stencil_two_side */
1021 GLubyte ActiveFace; /**< GL_EXT_stencil_two_side (0 or 1) */
1022 GLenum Function[2]; /**< Stencil function */
1023 GLenum FailFunc[2]; /**< Fail function */
1024 GLenum ZPassFunc[2]; /**< Depth buffer pass function */
1025 GLenum ZFailFunc[2]; /**< Depth buffer fail function */
1026 GLstencil Ref[2]; /**< Reference value */
1027 GLstencil ValueMask[2]; /**< Value mask */
1028 GLstencil WriteMask[2]; /**< Write mask */
1029 GLstencil Clear; /**< Clear value */
1030 };
1031
1032
1033 #define NUM_TEXTURE_TARGETS 5 /* 1D, 2D, 3D, CUBE and RECT */
1034
1035 /**
1036 * An index for each type of texture object
1037 */
1038 /*@{*/
1039 #define TEXTURE_1D_INDEX 0
1040 #define TEXTURE_2D_INDEX 1
1041 #define TEXTURE_3D_INDEX 2
1042 #define TEXTURE_CUBE_INDEX 3
1043 #define TEXTURE_RECT_INDEX 4
1044 /*@}*/
1045
1046 /**
1047 * Bit flags for each type of texture object
1048 * Used for Texture.Unit[]._ReallyEnabled flags.
1049 */
1050 /*@{*/
1051 #define TEXTURE_1D_BIT (1 << TEXTURE_1D_INDEX)
1052 #define TEXTURE_2D_BIT (1 << TEXTURE_2D_INDEX)
1053 #define TEXTURE_3D_BIT (1 << TEXTURE_3D_INDEX)
1054 #define TEXTURE_CUBE_BIT (1 << TEXTURE_CUBE_INDEX)
1055 #define TEXTURE_RECT_BIT (1 << TEXTURE_RECT_INDEX)
1056 /*@}*/
1057
1058
1059 /**
1060 * TexGenEnabled flags.
1061 */
1062 /*@{*/
1063 #define S_BIT 1
1064 #define T_BIT 2
1065 #define R_BIT 4
1066 #define Q_BIT 8
1067 /*@}*/
1068
1069
1070 /**
1071 * Bit flag versions of the corresponding GL_ constants.
1072 */
1073 /*@{*/
1074 #define TEXGEN_SPHERE_MAP 0x1
1075 #define TEXGEN_OBJ_LINEAR 0x2
1076 #define TEXGEN_EYE_LINEAR 0x4
1077 #define TEXGEN_REFLECTION_MAP_NV 0x8
1078 #define TEXGEN_NORMAL_MAP_NV 0x10
1079
1080 #define TEXGEN_NEED_NORMALS (TEXGEN_SPHERE_MAP | \
1081 TEXGEN_REFLECTION_MAP_NV | \
1082 TEXGEN_NORMAL_MAP_NV)
1083 #define TEXGEN_NEED_EYE_COORD (TEXGEN_SPHERE_MAP | \
1084 TEXGEN_REFLECTION_MAP_NV | \
1085 TEXGEN_NORMAL_MAP_NV | \
1086 TEXGEN_EYE_LINEAR)
1087 /*@}*/
1088
1089
1090 /* A selection of state flags to make driver and module's lives easier. */
1091 #define ENABLE_TEXGEN0 0x1
1092 #define ENABLE_TEXGEN1 0x2
1093 #define ENABLE_TEXGEN2 0x4
1094 #define ENABLE_TEXGEN3 0x8
1095 #define ENABLE_TEXGEN4 0x10
1096 #define ENABLE_TEXGEN5 0x20
1097 #define ENABLE_TEXGEN6 0x40
1098 #define ENABLE_TEXGEN7 0x80
1099
1100 #define ENABLE_TEXMAT0 0x1 /* Ie. not the identity matrix */
1101 #define ENABLE_TEXMAT1 0x2
1102 #define ENABLE_TEXMAT2 0x4
1103 #define ENABLE_TEXMAT3 0x8
1104 #define ENABLE_TEXMAT4 0x10
1105 #define ENABLE_TEXMAT5 0x20
1106 #define ENABLE_TEXMAT6 0x40
1107 #define ENABLE_TEXMAT7 0x80
1108
1109 #define ENABLE_TEXGEN(i) (ENABLE_TEXGEN0 << (i))
1110 #define ENABLE_TEXMAT(i) (ENABLE_TEXMAT0 << (i))
1111
1112
1113 /**
1114 * Texel fetch function prototype. We use texel fetch functions to
1115 * extract RGBA, color indexes and depth components out of 1D, 2D and 3D
1116 * texture images. These functions help to isolate us from the gritty
1117 * details of all the various texture image encodings.
1118 *
1119 * \param texImage texture image.
1120 * \param col texel column.
1121 * \param row texel row.
1122 * \param img texel image level/layer.
1123 * \param texelOut output texel (up to 4 GLchans)
1124 */
1125 typedef void (*FetchTexelFuncC)( const struct gl_texture_image *texImage,
1126 GLint col, GLint row, GLint img,
1127 GLchan *texelOut );
1128
1129 /**
1130 * As above, but returns floats.
1131 * Used for depth component images and for upcoming signed/float
1132 * texture images.
1133 */
1134 typedef void (*FetchTexelFuncF)( const struct gl_texture_image *texImage,
1135 GLint col, GLint row, GLint img,
1136 GLfloat *texelOut );
1137
1138
1139 /**
1140 * TexImage store function. This is called by the glTex[Sub]Image
1141 * functions and is responsible for converting the user-specified texture
1142 * image into a specific (hardware) image format.
1143 */
1144 typedef GLboolean (*StoreTexImageFunc)(GLcontext *ctx, GLuint dims,
1145 GLenum baseInternalFormat,
1146 const struct gl_texture_format *dstFormat,
1147 GLvoid *dstAddr,
1148 GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
1149 GLint dstRowStride, GLint dstImageStride,
1150 GLint srcWidth, GLint srcHeight, GLint srcDepth,
1151 GLenum srcFormat, GLenum srcType,
1152 const GLvoid *srcAddr,
1153 const struct gl_pixelstore_attrib *srcPacking);
1154
1155
1156
1157 /**
1158 * Texture format record
1159 */
1160 struct gl_texture_format
1161 {
1162 GLint MesaFormat; /**< One of the MESA_FORMAT_* values */
1163
1164 GLenum BaseFormat; /**< Either GL_RGB, GL_RGBA, GL_ALPHA,
1165 * GL_LUMINANCE, GL_LUMINANCE_ALPHA,
1166 * GL_INTENSITY, GL_COLOR_INDEX or
1167 * GL_DEPTH_COMPONENT.
1168 */
1169 GLenum DataType; /**< GL_FLOAT or GL_UNSIGNED_NORMALIZED_ARB */
1170 GLubyte RedBits; /**< Bits per texel component */
1171 GLubyte GreenBits; /**< These are just rough approximations for */
1172 GLubyte BlueBits; /**< compressed texture formats. */
1173 GLubyte AlphaBits;
1174 GLubyte LuminanceBits;
1175 GLubyte IntensityBits;
1176 GLubyte IndexBits;
1177 GLubyte DepthBits;
1178
1179 GLuint TexelBytes; /**< Bytes per texel, 0 if compressed format */
1180
1181 StoreTexImageFunc StoreImage;
1182
1183 /**
1184 * \name Texel fetch function pointers
1185 */
1186 /*@{*/
1187 FetchTexelFuncC FetchTexel1D;
1188 FetchTexelFuncC FetchTexel2D;
1189 FetchTexelFuncC FetchTexel3D;
1190 FetchTexelFuncF FetchTexel1Df;
1191 FetchTexelFuncF FetchTexel2Df;
1192 FetchTexelFuncF FetchTexel3Df;
1193 /*@}*/
1194 };
1195
1196
1197 /**
1198 * Texture image state. Describes the dimensions of a texture image,
1199 * the texel format and pointers to Texel Fetch functions.
1200 */
1201 struct gl_texture_image
1202 {
1203 GLenum Format; /**< Either GL_RGB, GL_RGBA, GL_ALPHA,
1204 * GL_LUMINANCE, GL_LUMINANCE_ALPHA,
1205 * GL_INTENSITY, GL_COLOR_INDEX or
1206 * GL_DEPTH_COMPONENT only.
1207 * Used for choosing TexEnv arithmetic.
1208 */
1209 GLint IntFormat; /**< Internal format as given by the user */
1210 GLuint Border; /**< 0 or 1 */
1211 GLuint Width; /**< = 2^WidthLog2 + 2*Border */
1212 GLuint Height; /**< = 2^HeightLog2 + 2*Border */
1213 GLuint Depth; /**< = 2^DepthLog2 + 2*Border */
1214 GLuint RowStride; /**< == Width unless IsClientData and padded */
1215 GLuint Width2; /**< = Width - 2*Border */
1216 GLuint Height2; /**< = Height - 2*Border */
1217 GLuint Depth2; /**< = Depth - 2*Border */
1218 GLuint WidthLog2; /**< = log2(Width2) */
1219 GLuint HeightLog2; /**< = log2(Height2) */
1220 GLuint DepthLog2; /**< = log2(Depth2) */
1221 GLuint MaxLog2; /**< = MAX(WidthLog2, HeightLog2) */
1222 GLfloat WidthScale; /**< used for mipmap LOD computation */
1223 GLfloat HeightScale; /**< used for mipmap LOD computation */
1224 GLfloat DepthScale; /**< used for mipmap LOD computation */
1225 GLvoid *Data; /**< Image data, accessed via FetchTexel() */
1226 GLboolean IsClientData; /**< Data owned by client? */
1227 GLboolean _IsPowerOfTwo; /**< Are all dimensions powers of two? */
1228
1229 const struct gl_texture_format *TexFormat;
1230
1231 struct gl_texture_object *TexObject; /**< Pointer back to parent object */
1232
1233 FetchTexelFuncC FetchTexelc; /**< GLchan texel fetch function pointer */
1234 FetchTexelFuncF FetchTexelf; /**< Float texel fetch function pointer */
1235
1236 GLboolean IsCompressed; /**< GL_ARB_texture_compression */
1237 GLuint CompressedSize; /**< GL_ARB_texture_compression */
1238
1239 /**
1240 * \name For device driver:
1241 */
1242 /*@{*/
1243 void *DriverData; /**< Arbitrary device driver data */
1244 /*@}*/
1245 };
1246
1247
1248 /**
1249 * Indexes for cube map faces.
1250 */
1251 /*@{*/
1252 #define FACE_POS_X 0
1253 #define FACE_NEG_X 1
1254 #define FACE_POS_Y 2
1255 #define FACE_NEG_Y 3
1256 #define FACE_POS_Z 4
1257 #define FACE_NEG_Z 5
1258 #define MAX_FACES 6
1259 /*@}*/
1260
1261
1262 /**
1263 * Texture object state. Contains the array of mipmap images, border color,
1264 * wrap modes, filter modes, shadow/texcompare state, and the per-texture
1265 * color palette.
1266 */
1267 struct gl_texture_object
1268 {
1269 _glthread_Mutex Mutex; /**< for thread safety */
1270 GLint RefCount; /**< reference count */
1271 GLuint Name; /**< the user-visible texture object ID */
1272 GLenum Target; /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
1273 GLfloat Priority; /**< in [0,1] */
1274 GLfloat BorderColor[4]; /**< unclamped */
1275 GLchan _BorderChan[4]; /**< clamped, as GLchan */
1276 GLenum WrapS; /**< S-axis texture image wrap mode */
1277 GLenum WrapT; /**< T-axis texture image wrap mode */
1278 GLenum WrapR; /**< R-axis texture image wrap mode */
1279 GLenum MinFilter; /**< minification filter */
1280 GLenum MagFilter; /**< magnification filter */
1281 GLfloat MinLod; /**< min lambda, OpenGL 1.2 */
1282 GLfloat MaxLod; /**< max lambda, OpenGL 1.2 */
1283 GLfloat LodBias; /**< OpenGL 1.4 */
1284 GLint BaseLevel; /**< min mipmap level, OpenGL 1.2 */
1285 GLint MaxLevel; /**< max mipmap level, OpenGL 1.2 */
1286 GLfloat MaxAnisotropy; /**< GL_EXT_texture_filter_anisotropic */
1287 GLboolean CompareFlag; /**< GL_SGIX_shadow */
1288 GLenum CompareOperator; /**< GL_SGIX_shadow */
1289 GLfloat ShadowAmbient; /**< GL_ARB_shadow_ambient */
1290 GLenum CompareMode; /**< GL_ARB_shadow */
1291 GLenum CompareFunc; /**< GL_ARB_shadow */
1292 GLenum DepthMode; /**< GL_ARB_depth_texture */
1293 GLint _MaxLevel; /**< actual max mipmap level (q in the spec) */
1294 GLfloat _MaxLambda; /**< = _MaxLevel - BaseLevel (q - b in spec) */
1295 GLboolean GenerateMipmap; /**< GL_SGIS_generate_mipmap */
1296 GLboolean _IsPowerOfTwo; /**< Are all image dimensions powers of two? */
1297 GLboolean Complete; /**< Is texture object complete? */
1298
1299 /** Actual texture images, indexed by [cube face] and [mipmap level] */
1300 struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
1301
1302 /** GL_EXT_paletted_texture */
1303 struct gl_color_table Palette;
1304
1305
1306 /**
1307 * \name For device driver.
1308 * Note: instead of attaching driver data to this pointer, it's preferable
1309 * to instead use this struct as a base class for your own texture object
1310 * class. Driver->NewTextureObject() can be used to implement the
1311 * allocation.
1312 */
1313 void *DriverData; /**< Arbitrary device driver data */
1314 };
1315
1316
1317 /**
1318 * Texture combine environment state.
1319 *
1320 * \todo
1321 * If GL_NV_texture_env_combine4 is ever supported, the arrays in this
1322 * structure will need to be expanded for 4 elements.
1323 */
1324 struct gl_tex_env_combine_state
1325 {
1326 GLenum ModeRGB; /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1327 GLenum ModeA; /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1328 GLenum SourceRGB[3]; /**< GL_PRIMARY_COLOR, GL_TEXTURE, etc. */
1329 GLenum SourceA[3]; /**< GL_PRIMARY_COLOR, GL_TEXTURE, etc. */
1330 GLenum OperandRGB[3]; /**< SRC_COLOR, ONE_MINUS_SRC_COLOR, etc */
1331 GLenum OperandA[3]; /**< SRC_ALPHA, ONE_MINUS_SRC_ALPHA, etc */
1332 GLuint ScaleShiftRGB; /**< 0, 1 or 2 */
1333 GLuint ScaleShiftA; /**< 0, 1 or 2 */
1334 GLuint _NumArgsRGB; /**< Number of inputs used for the combine mode. */
1335 GLuint _NumArgsA; /**< Number of inputs used for the combine mode. */
1336 };
1337
1338
1339 /**
1340 * Texture unit state. Contains enable flags, texture environment/function/
1341 * combiners, texgen state, pointers to current texture objects and
1342 * post-filter color tables.
1343 */
1344 struct gl_texture_unit
1345 {
1346 GLuint Enabled; /**< bitmask of TEXTURE_*_BIT flags */
1347 GLuint _ReallyEnabled; /**< 0 or exactly one of TEXTURE_*_BIT flags */
1348
1349 GLenum EnvMode; /**< GL_MODULATE, GL_DECAL, GL_BLEND, etc. */
1350 GLfloat EnvColor[4];
1351 GLuint TexGenEnabled; /**< Bitwise-OR of [STRQ]_BIT values */
1352 /** \name Tex coord generation mode
1353 * Either GL_OBJECT_LINEAR, GL_EYE_LINEAR or GL_SPHERE_MAP. */
1354 /*@{*/
1355 GLenum GenModeS;
1356 GLenum GenModeT;
1357 GLenum GenModeR;
1358 GLenum GenModeQ;
1359 /*@}*/
1360 GLuint _GenBitS;
1361 GLuint _GenBitT;
1362 GLuint _GenBitR;
1363 GLuint _GenBitQ;
1364 GLuint _GenFlags; /**< bitwise or of GenBit[STRQ] */
1365 GLfloat ObjectPlaneS[4];
1366 GLfloat ObjectPlaneT[4];
1367 GLfloat ObjectPlaneR[4];
1368 GLfloat ObjectPlaneQ[4];
1369 GLfloat EyePlaneS[4];
1370 GLfloat EyePlaneT[4];
1371 GLfloat EyePlaneR[4];
1372 GLfloat EyePlaneQ[4];
1373 GLfloat LodBias; /**< for biasing mipmap levels */
1374
1375 /**
1376 * \name GL_EXT_texture_env_combine
1377 */
1378 struct gl_tex_env_combine_state Combine;
1379
1380 /**
1381 * Derived state based on \c EnvMode and the \c BaseFormat of the
1382 * currently enabled texture.
1383 */
1384 struct gl_tex_env_combine_state _EnvMode;
1385
1386 /**
1387 * Currently enabled combiner state. This will point to either
1388 * \c Combine or \c _EnvMode.
1389 */
1390 struct gl_tex_env_combine_state *_CurrentCombine;
1391
1392 struct gl_texture_object *Current1D;
1393 struct gl_texture_object *Current2D;
1394 struct gl_texture_object *Current3D;
1395 struct gl_texture_object *CurrentCubeMap; /**< GL_ARB_texture_cube_map */
1396 struct gl_texture_object *CurrentRect; /**< GL_NV_texture_rectangle */
1397
1398 struct gl_texture_object *_Current; /**< Points to really enabled tex obj */
1399
1400 struct gl_texture_object Saved1D; /**< only used by glPush/PopAttrib */
1401 struct gl_texture_object Saved2D;
1402 struct gl_texture_object Saved3D;
1403 struct gl_texture_object SavedCubeMap;
1404 struct gl_texture_object SavedRect;
1405
1406 /* GL_SGI_texture_color_table */
1407 struct gl_color_table ColorTable;
1408 struct gl_color_table ProxyColorTable;
1409 GLboolean ColorTableEnabled;
1410 };
1411
1412
1413 /**
1414 * Texture attribute group (GL_TEXTURE_BIT).
1415 */
1416 struct gl_texture_attrib
1417 {
1418 /**
1419 * name multitexture
1420 */
1421 /**@{*/
1422 GLuint CurrentUnit; /**< Active texture unit */
1423 GLuint _EnabledUnits; /**< one bit set for each really-enabled unit */
1424 GLuint _EnabledCoordUnits; /**< one bit per enabled coordinate unit */
1425 GLuint _GenFlags; /**< for texgen */
1426 GLuint _TexGenEnabled;
1427 GLuint _TexMatEnabled;
1428 /**@}*/
1429
1430 struct gl_texture_unit Unit[MAX_TEXTURE_UNITS];
1431
1432 struct gl_texture_object *Proxy1D;
1433 struct gl_texture_object *Proxy2D;
1434 struct gl_texture_object *Proxy3D;
1435 struct gl_texture_object *ProxyCubeMap;
1436 struct gl_texture_object *ProxyRect;
1437
1438 /** GL_EXT_shared_texture_palette */
1439 GLboolean SharedPalette;
1440 struct gl_color_table Palette;
1441 };
1442
1443
1444 /**
1445 * Transformation attribute group (GL_TRANSFORM_BIT).
1446 */
1447 struct gl_transform_attrib
1448 {
1449 GLenum MatrixMode; /**< Matrix mode */
1450 GLfloat EyeUserPlane[MAX_CLIP_PLANES][4]; /**< User clip planes */
1451 GLfloat _ClipUserPlane[MAX_CLIP_PLANES][4]; /**< derived */
1452 GLuint ClipPlanesEnabled; /**< on/off bitmask */
1453 GLboolean Normalize; /**< Normalize all normals? */
1454 GLboolean RescaleNormals; /**< GL_EXT_rescale_normal */
1455 GLboolean RasterPositionUnclipped; /**< GL_IBM_rasterpos_clip */
1456
1457 GLboolean CullVertexFlag; /**< True if GL_CULL_VERTEX_EXT is enabled */
1458 GLfloat CullEyePos[4];
1459 GLfloat CullObjPos[4];
1460 };
1461
1462
1463 /**
1464 * Viewport attribute group (GL_VIEWPORT_BIT).
1465 */
1466 struct gl_viewport_attrib
1467 {
1468 GLint X, Y; /**< position */
1469 GLsizei Width, Height; /**< size */
1470 GLfloat Near, Far; /**< Depth buffer range */
1471 GLmatrix _WindowMap; /**< Mapping transformation as a matrix. */
1472 };
1473
1474
1475 /**
1476 * Node for the attribute stack.
1477 */
1478 struct gl_attrib_node
1479 {
1480 GLbitfield kind;
1481 void *data;
1482 struct gl_attrib_node *next;
1483 };
1484
1485
1486 /**
1487 * GL_ARB_vertex/pixel_buffer_object buffer object
1488 */
1489 struct gl_buffer_object
1490 {
1491 GLint RefCount;
1492 GLuint Name;
1493 GLenum Usage;
1494 GLenum Access;
1495 GLvoid *Pointer; /**< Only valid while buffer is mapped */
1496 GLsizeiptrARB Size; /**< Size of storage in bytes */
1497 GLubyte *Data; /**< Location of storage either in RAM or VRAM. */
1498 GLboolean OnCard; /**< Is buffer in VRAM? (hardware drivers) */
1499 };
1500
1501
1502
1503 /**
1504 * Client pixel packing/unpacking attributes
1505 */
1506 struct gl_pixelstore_attrib
1507 {
1508 GLint Alignment;
1509 GLint RowLength;
1510 GLint SkipPixels;
1511 GLint SkipRows;
1512 GLint ImageHeight; /**< for GL_EXT_texture3D */
1513 GLint SkipImages; /**< for GL_EXT_texture3D */
1514 GLboolean SwapBytes;
1515 GLboolean LsbFirst;
1516 GLboolean ClientStorage; /**< GL_APPLE_client_storage */
1517 GLboolean Invert; /**< GL_MESA_pack_invert */
1518 struct gl_buffer_object *BufferObj; /**< GL_ARB_pixel_buffer_object */
1519 };
1520
1521
1522 #define CA_CLIENT_DATA 0x1 /**< Data not allocated by mesa */
1523
1524
1525 /**
1526 * Client vertex array attributes
1527 */
1528 struct gl_client_array
1529 {
1530 GLint Size; /**< components per element (1,2,3,4) */
1531 GLenum Type; /**< datatype: GL_FLOAT, GL_INT, etc */
1532 GLsizei Stride; /**< user-specified stride */
1533 GLsizei StrideB; /**< actual stride in bytes */
1534 const GLubyte *Ptr; /**< Points to array data */
1535 GLuint Enabled; /**< one of the _NEW_ARRAY_ bits */
1536 GLboolean Normalized; /**< GL_ARB_vertex_program */
1537
1538 /**< GL_ARB_vertex_buffer_object */
1539 struct gl_buffer_object *BufferObj;
1540 GLuint _MaxElement;
1541
1542 GLuint Flags;
1543 };
1544
1545
1546 /**
1547 * Vertex array state
1548 */
1549 struct gl_array_attrib
1550 {
1551 struct gl_client_array Vertex; /**< client data descriptors */
1552 struct gl_client_array Normal;
1553 struct gl_client_array Color;
1554 struct gl_client_array SecondaryColor;
1555 struct gl_client_array FogCoord;
1556 struct gl_client_array Index;
1557 struct gl_client_array TexCoord[MAX_TEXTURE_COORD_UNITS];
1558 struct gl_client_array EdgeFlag;
1559
1560 struct gl_client_array VertexAttrib[VERT_ATTRIB_MAX]; /**< GL_NV_vertex_program */
1561
1562 GLint ActiveTexture; /**< Client Active Texture */
1563 GLuint LockFirst; /**< GL_EXT_compiled_vertex_array */
1564 GLuint LockCount; /**< GL_EXT_compiled_vertex_array */
1565
1566 GLuint _Enabled; /**< _NEW_ARRAY_* - bit set if array enabled */
1567 GLuint NewState; /**< _NEW_ARRAY_* */
1568
1569 #if FEATURE_ARB_vertex_buffer_object
1570 struct gl_buffer_object *NullBufferObj;
1571 struct gl_buffer_object *ArrayBufferObj;
1572 struct gl_buffer_object *ElementArrayBufferObj;
1573 #endif
1574 GLuint _MaxElement; /* Min of all enabled array's maxes */
1575 };
1576
1577
1578 /**
1579 * Feedback buffer state
1580 */
1581 struct gl_feedback
1582 {
1583 GLenum Type;
1584 GLuint _Mask; /* FB_* bits */
1585 GLfloat *Buffer;
1586 GLuint BufferSize;
1587 GLuint Count;
1588 };
1589
1590
1591 /**
1592 * Selection buffer state
1593 */
1594 struct gl_selection
1595 {
1596 GLuint *Buffer; /**< selection buffer */
1597 GLuint BufferSize; /**< size of the selection buffer */
1598 GLuint BufferCount; /**< number of values in the selection buffer */
1599 GLuint Hits; /**< number of records in the selection buffer */
1600 GLuint NameStackDepth; /**< name stack depth */
1601 GLuint NameStack[MAX_NAME_STACK_DEPTH]; /**< name stack */
1602 GLboolean HitFlag; /**< hit flag */
1603 GLfloat HitMinZ; /**< minimum hit depth */
1604 GLfloat HitMaxZ; /**< maximum hit depth */
1605 };
1606
1607
1608 /**
1609 * 1-D Evaluator control points
1610 */
1611 struct gl_1d_map
1612 {
1613 GLuint Order; /**< Number of control points */
1614 GLfloat u1, u2, du; /**< u1, u2, 1.0/(u2-u1) */
1615 GLfloat *Points; /**< Points to contiguous control points */
1616 };
1617
1618
1619 /**
1620 * 2-D Evaluator control points
1621 */
1622 struct gl_2d_map
1623 {
1624 GLuint Uorder; /**< Number of control points in U dimension */
1625 GLuint Vorder; /**< Number of control points in V dimension */
1626 GLfloat u1, u2, du;
1627 GLfloat v1, v2, dv;
1628 GLfloat *Points; /**< Points to contiguous control points */
1629 };
1630
1631
1632 /**
1633 * All evaluator control point state
1634 */
1635 struct gl_evaluators
1636 {
1637 /**
1638 * \name 1-D maps
1639 */
1640 /*@{*/
1641 struct gl_1d_map Map1Vertex3;
1642 struct gl_1d_map Map1Vertex4;
1643 struct gl_1d_map Map1Index;
1644 struct gl_1d_map Map1Color4;
1645 struct gl_1d_map Map1Normal;
1646 struct gl_1d_map Map1Texture1;
1647 struct gl_1d_map Map1Texture2;
1648 struct gl_1d_map Map1Texture3;
1649 struct gl_1d_map Map1Texture4;
1650 struct gl_1d_map Map1Attrib[16]; /**< GL_NV_vertex_program */
1651 /*@}*/
1652
1653 /**
1654 * \name 2-D maps
1655 */
1656 /*@{*/
1657 struct gl_2d_map Map2Vertex3;
1658 struct gl_2d_map Map2Vertex4;
1659 struct gl_2d_map Map2Index;
1660 struct gl_2d_map Map2Color4;
1661 struct gl_2d_map Map2Normal;
1662 struct gl_2d_map Map2Texture1;
1663 struct gl_2d_map Map2Texture2;
1664 struct gl_2d_map Map2Texture3;
1665 struct gl_2d_map Map2Texture4;
1666 struct gl_2d_map Map2Attrib[16]; /**< GL_NV_vertex_program */
1667 /*@}*/
1668 };
1669
1670
1671 /**
1672 * NV_fragment_program runtime state
1673 */
1674 struct fp_machine
1675 {
1676 GLfloat Temporaries[MAX_NV_FRAGMENT_PROGRAM_TEMPS][4];
1677 GLfloat Inputs[MAX_NV_FRAGMENT_PROGRAM_INPUTS][4];
1678 GLfloat Outputs[MAX_NV_FRAGMENT_PROGRAM_OUTPUTS][4];
1679 GLuint CondCodes[4];
1680 };
1681
1682 /**
1683 * ATI_fragment_shader runtime state
1684 */
1685 #define ATI_FS_INPUT_PRIMARY 0
1686 #define ATI_FS_INPUT_SECONDARY 1
1687
1688 /* 6 register sets - 2 inputs (primary, secondary) */
1689 struct atifs_machine
1690 {
1691 GLfloat Registers[6][4];
1692 GLfloat PrevPassRegisters[6][4];
1693 GLfloat Inputs[2][4];
1694 GLuint pass;
1695 };
1696
1697
1698 /**
1699 * Names of the various vertex/fragment register files
1700 */
1701 enum register_file
1702 {
1703 PROGRAM_TEMPORARY,
1704 PROGRAM_INPUT,
1705 PROGRAM_OUTPUT,
1706 PROGRAM_LOCAL_PARAM,
1707 PROGRAM_ENV_PARAM,
1708 PROGRAM_NAMED_PARAM,
1709 PROGRAM_STATE_VAR,
1710 PROGRAM_WRITE_ONLY,
1711 PROGRAM_ADDRESS
1712 };
1713
1714
1715 /** Vertex and fragment instructions */
1716 struct vp_instruction;
1717 struct fp_instruction;
1718 struct atifs_instruction;
1719 struct program_parameter_list;
1720
1721
1722 /**
1723 * Base class for any kind of program object
1724 */
1725 struct program
1726 {
1727 GLuint Id;
1728 GLubyte *String; /**< Null-terminated program text */
1729 GLint RefCount;
1730 GLenum Target;
1731 GLenum Format; /**< String encoding format */
1732 GLboolean Resident;
1733 GLfloat LocalParams[MAX_PROGRAM_LOCAL_PARAMS][4];
1734 GLuint NumInstructions; /* GL_ARB_vertex/fragment_program */
1735 GLuint NumTemporaries;
1736 GLuint NumParameters;
1737 GLuint NumAttributes;
1738 GLuint NumAddressRegs;
1739 };
1740
1741
1742 /** Vertex program object */
1743 struct vertex_program
1744 {
1745 struct program Base; /* base class */
1746 struct vp_instruction *Instructions; /* Compiled instructions */
1747 GLboolean IsNVProgram; /* GL_NV_vertex_program ? */
1748 GLboolean IsPositionInvariant; /* GL_NV_vertex_program1_1 */
1749 GLuint InputsRead; /* Bitmask of which input regs are read */
1750 GLuint OutputsWritten; /* Bitmask of which output regs are written to */
1751 struct program_parameter_list *Parameters; /**< array [NumParameters] */
1752 };
1753
1754
1755 /** Fragment program object */
1756 struct fragment_program
1757 {
1758 struct program Base; /**< base class */
1759 struct fp_instruction *Instructions; /**< Compiled instructions */
1760 GLuint InputsRead; /**< Bitmask of which input regs are read */
1761 GLuint OutputsWritten; /**< Bitmask of which output regs are written to */
1762 GLuint TexturesUsed[MAX_TEXTURE_IMAGE_UNITS]; /**< TEXTURE_x_INDEX bitmask */
1763 GLuint NumAluInstructions; /**< GL_ARB_fragment_program */
1764 GLuint NumTexInstructions;
1765 GLuint NumTexIndirections;
1766 GLenum FogOption;
1767 struct program_parameter_list *Parameters; /**< array [NumParameters] */
1768
1769 #ifdef USE_TCC
1770 char c_str[4096]; /* experimental... */
1771 int c_strlen;
1772 #endif
1773 };
1774
1775 struct ati_fragment_shader
1776 {
1777 struct program Base;
1778 struct atifs_instruction *Instructions;
1779 GLfloat Constants[8][4];
1780 GLint NumPasses;
1781 GLint cur_pass;
1782 };
1783
1784 /**
1785 * State common to vertex and fragment programs.
1786 */
1787 struct gl_program_state
1788 {
1789 GLint ErrorPos; /* GL_PROGRAM_ERROR_POSITION_NV */
1790 const char *ErrorString; /* GL_PROGRAM_ERROR_STRING_NV */
1791 };
1792
1793
1794 /**
1795 * State vars for GL_ARB/GL_NV_vertex_program
1796 */
1797 struct gl_vertex_program_state
1798 {
1799 GLboolean Enabled; /**< GL_VERTEX_PROGRAM_NV */
1800 GLboolean _Enabled; /**< Really enabled? */
1801 GLboolean PointSizeEnabled; /**< GL_VERTEX_PROGRAM_POINT_SIZE_NV */
1802 GLboolean TwoSideEnabled; /**< GL_VERTEX_PROGRAM_TWO_SIDE_NV */
1803 struct vertex_program *Current; /**< ptr to currently bound program */
1804
1805 GLenum TrackMatrix[MAX_NV_VERTEX_PROGRAM_PARAMS / 4];
1806 GLenum TrackMatrixTransform[MAX_NV_VERTEX_PROGRAM_PARAMS / 4];
1807
1808 GLfloat Parameters[MAX_NV_VERTEX_PROGRAM_PARAMS][4]; /* Env params */
1809 /* Only used during program execution (may be moved someday): */
1810 GLfloat Temporaries[MAX_NV_VERTEX_PROGRAM_TEMPS][4];
1811 GLfloat Inputs[MAX_NV_VERTEX_PROGRAM_INPUTS][4];
1812 GLuint InputsSize[MAX_NV_VERTEX_PROGRAM_INPUTS];
1813 GLfloat Outputs[MAX_NV_VERTEX_PROGRAM_OUTPUTS][4];
1814 GLint AddressReg[4];
1815
1816 #if FEATURE_MESA_program_debug
1817 GLprogramcallbackMESA Callback;
1818 GLvoid *CallbackData;
1819 GLboolean CallbackEnabled;
1820 GLuint CurrentPosition;
1821 #endif
1822 };
1823
1824
1825 /*
1826 * State for GL_ARB/NV_fragment_program
1827 */
1828 struct gl_fragment_program_state
1829 {
1830 GLboolean Enabled; /* GL_VERTEX_PROGRAM_NV */
1831 GLboolean _Enabled; /* Really enabled? */
1832 GLboolean _Active; /* Really really enabled? */
1833 struct fragment_program *Current; /* ptr to currently bound program */
1834 struct fragment_program *_Current; /* ptr to currently active program */
1835 struct fp_machine Machine; /* machine state */
1836 GLfloat Parameters[MAX_NV_FRAGMENT_PROGRAM_PARAMS][4]; /* Env params */
1837
1838 #if FEATURE_MESA_program_debug
1839 GLprogramcallbackMESA Callback;
1840 GLvoid *CallbackData;
1841 GLboolean CallbackEnabled;
1842 GLuint CurrentPosition;
1843 #endif
1844 };
1845
1846 /*
1847 * State for GL_fragment_shader
1848 */
1849 struct gl_ati_fragment_shader_state
1850 {
1851 GLboolean Enabled;
1852 GLboolean _Enabled;
1853 GLboolean Compiling;
1854 struct atifs_machine Machine; /* machine state */
1855 struct ati_fragment_shader *Current;
1856 };
1857
1858 /*
1859 * State for GL_ARB_occlusion_query
1860 */
1861 struct gl_occlusion_state
1862 {
1863 GLboolean Active;
1864 GLuint CurrentQueryObject;
1865 GLuint PassedCounter;
1866 struct _mesa_HashTable *QueryObjects;
1867 };
1868
1869 /**
1870 * gl2 unique interface identifier.
1871 * Each gl2 interface has its own interface id used for object queries.
1872 */
1873 enum gl2_uiid
1874 {
1875 UIID_UNKNOWN, /* supported by all objects */
1876 UIID_GENERIC, /* generic object */
1877 UIID_CONTAINER, /* contains generic objects */
1878 UIID_SHADER, /* shader object */
1879 UIID_FRAGMENT_SHADER, /* fragment shader */
1880 UIID_VERTEX_SHADER, /* vertex shader */
1881 UIID_PROGRAM, /* program object */
1882 UIID_3DLABS_SHHANDLE /* encapsulates 3dlabs' ShHandle */
1883 };
1884
1885 struct gl2_unknown_intf
1886 {
1887 GLvoid (* AddRef) (struct gl2_unknown_intf **);
1888 GLvoid (* Release) (struct gl2_unknown_intf **);
1889 struct gl2_unknown_intf **(* QueryInterface) (struct gl2_unknown_intf **, enum gl2_uiid uiid);
1890 };
1891
1892 struct gl2_generic_intf
1893 {
1894 struct gl2_unknown_intf _unknown;
1895 GLvoid (* Delete) (struct gl2_generic_intf **);
1896 GLenum (* GetType) (struct gl2_generic_intf **);
1897 GLhandleARB (* GetName) (struct gl2_generic_intf **);
1898 GLboolean (* GetDeleteStatus) (struct gl2_generic_intf **);
1899 const GLcharARB *(* GetInfoLog) (struct gl2_generic_intf **);
1900 };
1901
1902 struct gl2_container_intf
1903 {
1904 struct gl2_generic_intf _generic;
1905 GLboolean (* Attach) (struct gl2_container_intf **, struct gl2_generic_intf **);
1906 GLboolean (* Detach) (struct gl2_container_intf **, struct gl2_generic_intf **);
1907 GLsizei (* GetAttachedCount) (struct gl2_container_intf **);
1908 struct gl2_generic_intf **(* GetAttached) (struct gl2_container_intf **, GLuint);
1909 };
1910
1911 struct gl2_shader_intf
1912 {
1913 struct gl2_generic_intf _generic;
1914 GLenum (* GetSubType) (struct gl2_shader_intf **);
1915 GLboolean (* GetCompileStatus) (struct gl2_shader_intf **);
1916 GLvoid (* SetSource) (struct gl2_shader_intf **, GLcharARB *, GLint *, GLsizei);
1917 const GLcharARB *(* GetSource) (struct gl2_shader_intf **);
1918 GLvoid (* Compile) (struct gl2_shader_intf **);
1919 };
1920
1921 struct gl2_program_intf
1922 {
1923 struct gl2_container_intf _container;
1924 GLboolean (* GetLinkStatus) (struct gl2_program_intf **);
1925 GLboolean (* GetValidateStatus) (struct gl2_program_intf **);
1926 GLvoid (* Link) (struct gl2_program_intf **);
1927 GLvoid (* Validate) (struct gl2_program_intf **);
1928 };
1929
1930 struct gl2_fragment_shader_intf
1931 {
1932 struct gl2_shader_intf _shader;
1933 };
1934
1935 struct gl2_vertex_shader_intf
1936 {
1937 struct gl2_shader_intf _shader;
1938 };
1939
1940 struct gl2_3dlabs_shhandle_intf
1941 {
1942 struct gl2_unknown_intf _unknown;
1943 GLvoid *(* GetShHandle) (struct gl2_3dlabs_shhandle_intf **);
1944 };
1945
1946 struct gl_shader_objects_state
1947 {
1948 struct gl2_program_intf **current_program;
1949 };
1950
1951
1952 /**
1953 * State which can be shared by multiple contexts:
1954 */
1955 struct gl_shared_state
1956 {
1957 _glthread_Mutex Mutex; /**< for thread safety */
1958 GLint RefCount; /**< Reference count */
1959 struct _mesa_HashTable *DisplayList; /**< Display lists hash table */
1960 struct _mesa_HashTable *TexObjects; /**< Texture objects hash table */
1961
1962 /**
1963 * \name Default texture objects (shared by all multi-texture units)
1964 */
1965 /*@{*/
1966 struct gl_texture_object *Default1D;
1967 struct gl_texture_object *Default2D;
1968 struct gl_texture_object *Default3D;
1969 struct gl_texture_object *DefaultCubeMap;
1970 struct gl_texture_object *DefaultRect;
1971 /*@}*/
1972
1973 /**
1974 * \name Vertex/fragment programs
1975 */
1976 /*@{*/
1977 struct _mesa_HashTable *Programs;
1978 #if FEATURE_ARB_vertex_program
1979 struct program *DefaultVertexProgram;
1980 #endif
1981 #if FEATURE_ARB_fragment_program
1982 struct program *DefaultFragmentProgram;
1983 #endif
1984 #if FEATURE_ATI_fragment_shader
1985 struct program *DefaultFragmentShader;
1986 #endif
1987 /*@}*/
1988
1989 #if FEATURE_ARB_vertex_buffer_object || FEATURE_ARB_pixel_buffer_object
1990 struct _mesa_HashTable *BufferObjects;
1991 #endif
1992
1993 struct _mesa_HashTable *GL2Objects;
1994
1995 #if FEATURE_EXT_framebuffer_object
1996 struct _mesa_HashTable *RenderBuffers;
1997 struct _mesa_HashTable *FrameBuffers;
1998 #endif
1999
2000 void *DriverData; /**< Device driver shared state */
2001 };
2002
2003
2004 /**
2005 * Frame buffer.
2006 *
2007 * A "frame buffer" is a color buffer and its optional ancillary buffers:
2008 * depth, accum, stencil, and software-simulated alpha buffers.
2009 * In C++ terms, think of this as a base class from which device drivers
2010 * will make derived classes.
2011 */
2012 struct gl_frame_buffer
2013 {
2014 GLvisual Visual; /**< The corresponding visual */
2015
2016 GLuint Width, Height; /**< size of frame buffer in pixels */
2017
2018 GLboolean Initialized;
2019
2020 GLboolean UseSoftwareDepthBuffer;
2021 GLboolean UseSoftwareAccumBuffer;
2022 GLboolean UseSoftwareStencilBuffer;
2023 GLboolean UseSoftwareAlphaBuffers;
2024 GLboolean UseSoftwareAuxBuffers;
2025
2026 /** \name Software depth (aka Z) buffer */
2027 /*@{*/
2028 GLvoid *DepthBuffer; /**< array [Width*Height] of GLushort or GLuint*/
2029 /*@}*/
2030
2031 /** \name Software stencil buffer */
2032 /*@{*/
2033 GLstencil *Stencil; /**< array [Width*Height] of GLstencil values */
2034 /*@}*/
2035
2036 /** \name Software accumulation buffer */
2037 /*@{*/
2038 GLaccum *Accum; /**< array [4*Width*Height] of GLaccum values */
2039 /*@}*/
2040
2041 /** \name Software alpha planes */
2042 /*@{*/
2043 GLchan *FrontLeftAlpha; /**< array [Width*Height] of GLchan */
2044 GLchan *BackLeftAlpha; /**< array [Width*Height] of GLchan */
2045 GLchan *FrontRightAlpha; /**< array [Width*Height] of GLchan */
2046 GLchan *BackRightAlpha; /**< array [Width*Height] of GLchan */
2047 /*@}*/
2048
2049 GLchan *AuxBuffers[MAX_AUX_BUFFERS];
2050
2051 /**
2052 * \name Drawing bounds
2053 *
2054 * Intersection of window size and scissor box
2055 */
2056 /*@{*/
2057 GLint _Xmin; /**< inclusive */
2058 GLint _Ymin; /**< inclusive */
2059 GLint _Xmax; /**< exclusive */
2060 GLint _Ymax; /**< exclusive */
2061 /*@}*/
2062 };
2063
2064
2065 /**
2066 * Constants which may be overridden by device driver during context creation
2067 * but are never changed after that.
2068 */
2069 struct gl_constants
2070 {
2071 GLint MaxTextureLevels; /**< Maximum number of allowed mipmap levels. */
2072 GLint Max3DTextureLevels; /**< Maximum number of allowed mipmap levels for 3D texture targets. */
2073 GLint MaxCubeTextureLevels; /**< Maximum number of allowed mipmap levels for GL_ARB_texture_cube_map */
2074 GLint MaxTextureRectSize; /* GL_NV_texture_rectangle */
2075 GLuint MaxTextureCoordUnits;
2076 GLuint MaxTextureImageUnits;
2077 GLuint MaxTextureUnits; /* = MAX(CoordUnits, ImageUnits) */
2078 GLfloat MaxTextureMaxAnisotropy; /* GL_EXT_texture_filter_anisotropic */
2079 GLfloat MaxTextureLodBias; /* GL_EXT_texture_lod_bias */
2080 GLuint MaxArrayLockSize;
2081 GLint SubPixelBits;
2082 GLfloat MinPointSize, MaxPointSize; /* aliased */
2083 GLfloat MinPointSizeAA, MaxPointSizeAA; /* antialiased */
2084 GLfloat PointSizeGranularity;
2085 GLfloat MinLineWidth, MaxLineWidth; /* aliased */
2086 GLfloat MinLineWidthAA, MaxLineWidthAA; /* antialiased */
2087 GLfloat LineWidthGranularity;
2088 GLuint MaxColorTableSize;
2089 GLuint MaxConvolutionWidth;
2090 GLuint MaxConvolutionHeight;
2091 GLuint MaxClipPlanes;
2092 GLuint MaxLights;
2093 GLfloat MaxShininess; /* GL_NV_light_max_exponent */
2094 GLfloat MaxSpotExponent; /* GL_NV_light_max_exponent */
2095 GLuint MaxViewportWidth, MaxViewportHeight;
2096 /* GL_ARB_vertex_program */
2097 GLuint MaxVertexProgramInstructions;
2098 GLuint MaxVertexProgramAttribs;
2099 GLuint MaxVertexProgramTemps;
2100 GLuint MaxVertexProgramLocalParams;
2101 GLuint MaxVertexProgramEnvParams;
2102 GLuint MaxVertexProgramAddressRegs;
2103 /* GL_ARB_fragment_program */
2104 GLuint MaxFragmentProgramInstructions;
2105 GLuint MaxFragmentProgramAttribs;
2106 GLuint MaxFragmentProgramTemps;
2107 GLuint MaxFragmentProgramLocalParams;
2108 GLuint MaxFragmentProgramEnvParams;
2109 GLuint MaxFragmentProgramAddressRegs;
2110 GLuint MaxFragmentProgramAluInstructions;
2111 GLuint MaxFragmentProgramTexInstructions;
2112 GLuint MaxFragmentProgramTexIndirections;
2113 /* vertex or fragment program */
2114 GLuint MaxProgramMatrices;
2115 GLuint MaxProgramMatrixStackDepth;
2116 /* vertex array / buffer object bounds checking */
2117 GLboolean CheckArrayBounds;
2118 /* GL_ARB_draw_buffers */
2119 GLuint MaxDrawBuffers;
2120 /* GL_OES_read_format */
2121 GLenum ColorReadFormat;
2122 GLenum ColorReadType;
2123 /* GL_EXT_framebuffer_object */
2124 GLuint MaxColorAttachments;
2125 GLuint MaxRenderbufferSize;
2126 };
2127
2128
2129 /**
2130 * Enable flag for each OpenGL extension. Different device drivers will
2131 * enable different extensions at runtime.
2132 */
2133 struct gl_extensions
2134 {
2135 /**
2136 * \name Flags to quickly test if certain extensions are available.
2137 *
2138 * Not every extension needs to have such a flag, but it's encouraged.
2139 */
2140 /*@{*/
2141 GLboolean dummy; /* don't remove this! */
2142 GLboolean ARB_depth_texture;
2143 GLboolean ARB_draw_buffers;
2144 GLboolean ARB_fragment_program;
2145 GLboolean ARB_fragment_shader;
2146 GLboolean ARB_half_float_pixel;
2147 GLboolean ARB_imaging;
2148 GLboolean ARB_multisample;
2149 GLboolean ARB_multitexture;
2150 GLboolean ARB_occlusion_query;
2151 GLboolean ARB_point_sprite;
2152 GLboolean ARB_shader_objects;
2153 GLboolean ARB_shading_language_100;
2154 GLboolean ARB_shadow;
2155 GLboolean ARB_texture_border_clamp;
2156 GLboolean ARB_texture_compression;
2157 GLboolean ARB_texture_cube_map;
2158 GLboolean ARB_texture_env_combine;
2159 GLboolean ARB_texture_env_crossbar;
2160 GLboolean ARB_texture_env_dot3;
2161 GLboolean ARB_texture_float;
2162 GLboolean ARB_texture_mirrored_repeat;
2163 GLboolean ARB_texture_non_power_of_two;
2164 GLboolean ARB_transpose_matrix;
2165 GLboolean ARB_vertex_buffer_object;
2166 GLboolean ARB_vertex_program;
2167 GLboolean ARB_vertex_shader;
2168 GLboolean ARB_window_pos;
2169 GLboolean EXT_abgr;
2170 GLboolean EXT_bgra;
2171 GLboolean EXT_blend_color;
2172 GLboolean EXT_blend_equation_separate;
2173 GLboolean EXT_blend_func_separate;
2174 GLboolean EXT_blend_logic_op;
2175 GLboolean EXT_blend_minmax;
2176 GLboolean EXT_blend_subtract;
2177 GLboolean EXT_clip_volume_hint;
2178 GLboolean EXT_cull_vertex;
2179 GLboolean EXT_convolution;
2180 GLboolean EXT_compiled_vertex_array;
2181 GLboolean EXT_copy_texture;
2182 GLboolean EXT_depth_bounds_test;
2183 GLboolean EXT_draw_range_elements;
2184 GLboolean EXT_framebuffer_object;
2185 GLboolean EXT_fog_coord;
2186 GLboolean EXT_histogram;
2187 GLboolean EXT_multi_draw_arrays;
2188 GLboolean EXT_paletted_texture;
2189 GLboolean EXT_packed_pixels;
2190 GLboolean EXT_pixel_buffer_object;
2191 GLboolean EXT_point_parameters;
2192 GLboolean EXT_polygon_offset;
2193 GLboolean EXT_rescale_normal;
2194 GLboolean EXT_shadow_funcs;
2195 GLboolean EXT_secondary_color;
2196 GLboolean EXT_separate_specular_color;
2197 GLboolean EXT_shared_texture_palette;
2198 GLboolean EXT_stencil_wrap;
2199 GLboolean EXT_stencil_two_side;
2200 GLboolean EXT_subtexture;
2201 GLboolean EXT_texture;
2202 GLboolean EXT_texture_object;
2203 GLboolean EXT_texture3D;
2204 GLboolean EXT_texture_compression_s3tc;
2205 GLboolean EXT_texture_env_add;
2206 GLboolean EXT_texture_env_combine;
2207 GLboolean EXT_texture_env_dot3;
2208 GLboolean EXT_texture_filter_anisotropic;
2209 GLboolean EXT_texture_lod_bias;
2210 GLboolean EXT_texture_mirror_clamp;
2211 GLboolean EXT_vertex_array;
2212 GLboolean EXT_vertex_array_set;
2213 /* vendor extensions */
2214 GLboolean APPLE_client_storage;
2215 GLboolean APPLE_packed_pixels;
2216 GLboolean ATI_texture_mirror_once;
2217 GLboolean ATI_texture_env_combine3;
2218 GLboolean ATI_fragment_shader;
2219 GLboolean HP_occlusion_test;
2220 GLboolean IBM_rasterpos_clip;
2221 GLboolean IBM_multimode_draw_arrays;
2222 GLboolean MESA_pack_invert;
2223 GLboolean MESA_packed_depth_stencil;
2224 GLboolean MESA_program_debug;
2225 GLboolean MESA_resize_buffers;
2226 GLboolean MESA_ycbcr_texture;
2227 GLboolean NV_blend_square;
2228 GLboolean NV_fragment_program;
2229 GLboolean NV_light_max_exponent;
2230 GLboolean NV_point_sprite;
2231 GLboolean NV_texgen_reflection;
2232 GLboolean NV_texture_rectangle;
2233 GLboolean NV_vertex_program;
2234 GLboolean NV_vertex_program1_1;
2235 GLboolean OES_read_format;
2236 GLboolean SGI_color_matrix;
2237 GLboolean SGI_color_table;
2238 GLboolean SGI_texture_color_table;
2239 GLboolean SGIS_generate_mipmap;
2240 GLboolean SGIS_pixel_texture;
2241 GLboolean SGIS_texture_edge_clamp;
2242 GLboolean SGIS_texture_lod;
2243 GLboolean SGIX_depth_texture;
2244 GLboolean SGIX_pixel_texture;
2245 GLboolean SGIX_shadow;
2246 GLboolean SGIX_shadow_ambient; /* or GL_ARB_shadow_ambient */
2247 GLboolean TDFX_texture_compression_FXT1;
2248 GLboolean S3_s3tc;
2249 /*@}*/
2250 /* The extension string */
2251 const GLubyte *String;
2252 };
2253
2254
2255 /**
2256 * A stack of matrices (projection, modelview, color, texture, etc).
2257 */
2258 struct matrix_stack
2259 {
2260 GLmatrix *Top; /**< points into Stack */
2261 GLmatrix *Stack; /**< array [MaxDepth] of GLmatrix */
2262 GLuint Depth; /**< 0 <= Depth < MaxDepth */
2263 GLuint MaxDepth; /**< size of Stack[] array */
2264 GLuint DirtyFlag; /**< _NEW_MODELVIEW or _NEW_PROJECTION, for example */
2265 };
2266
2267
2268 /**
2269 * \name Bits for image transfer operations
2270 *
2271 * \sa __GLcontextRec::ImageTransferState.
2272 */
2273 /*@{*/
2274 #define IMAGE_SCALE_BIAS_BIT 0x1
2275 #define IMAGE_SHIFT_OFFSET_BIT 0x2
2276 #define IMAGE_MAP_COLOR_BIT 0x4
2277 #define IMAGE_COLOR_TABLE_BIT 0x8
2278 #define IMAGE_CONVOLUTION_BIT 0x10
2279 #define IMAGE_POST_CONVOLUTION_SCALE_BIAS 0x20
2280 #define IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT 0x40
2281 #define IMAGE_COLOR_MATRIX_BIT 0x80
2282 #define IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT 0x100
2283 #define IMAGE_HISTOGRAM_BIT 0x200
2284 #define IMAGE_MIN_MAX_BIT 0x400
2285 #define IMAGE_CLAMP_BIT 0x800 /* extra */
2286
2287
2288 /** Pixel Transfer ops up to convolution */
2289 #define IMAGE_PRE_CONVOLUTION_BITS (IMAGE_SCALE_BIAS_BIT | \
2290 IMAGE_SHIFT_OFFSET_BIT | \
2291 IMAGE_MAP_COLOR_BIT | \
2292 IMAGE_COLOR_TABLE_BIT)
2293
2294 /** Pixel transfer ops after convolution */
2295 #define IMAGE_POST_CONVOLUTION_BITS (IMAGE_POST_CONVOLUTION_SCALE_BIAS | \
2296 IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT | \
2297 IMAGE_COLOR_MATRIX_BIT | \
2298 IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT |\
2299 IMAGE_HISTOGRAM_BIT | \
2300 IMAGE_MIN_MAX_BIT)
2301 /*@}*/
2302
2303
2304 /**
2305 * \name Bits to indicate what state has changed.
2306 *
2307 * 4 unused flags.
2308 */
2309 /*@{*/
2310 #define _NEW_MODELVIEW 0x1 /**< __GLcontextRec::ModelView */
2311 #define _NEW_PROJECTION 0x2 /**< __GLcontextRec::Projection */
2312 #define _NEW_TEXTURE_MATRIX 0x4 /**< __GLcontextRec::TextureMatrix */
2313 #define _NEW_COLOR_MATRIX 0x8 /**< __GLcontextRec::ColorMatrix */
2314 #define _NEW_ACCUM 0x10 /**< __GLcontextRec::Accum */
2315 #define _NEW_COLOR 0x20 /**< __GLcontextRec::Color */
2316 #define _NEW_DEPTH 0x40 /**< __GLcontextRec::Depth */
2317 #define _NEW_EVAL 0x80 /**< __GLcontextRec::Eval, __GLcontextRec::EvalMap */
2318 #define _NEW_FOG 0x100 /**< __GLcontextRec::Fog */
2319 #define _NEW_HINT 0x200 /**< __GLcontextRec::Hint */
2320 #define _NEW_LIGHT 0x400 /**< __GLcontextRec::Light */
2321 #define _NEW_LINE 0x800 /**< __GLcontextRec::Line */
2322 #define _NEW_PIXEL 0x1000 /**< __GLcontextRec::Pixel */
2323 #define _NEW_POINT 0x2000 /**< __GLcontextRec::Point */
2324 #define _NEW_POLYGON 0x4000 /**< __GLcontextRec::Polygon */
2325 #define _NEW_POLYGONSTIPPLE 0x8000 /**< __GLcontextRec::PolygonStipple */
2326 #define _NEW_SCISSOR 0x10000 /**< __GLcontextRec::Scissor */
2327 #define _NEW_STENCIL 0x20000 /**< __GLcontextRec::Stencil */
2328 #define _NEW_TEXTURE 0x40000 /**< __GLcontextRec::Texture */
2329 #define _NEW_TRANSFORM 0x80000 /**< __GLcontextRec::Transform */
2330 #define _NEW_VIEWPORT 0x100000 /**< __GLcontextRec::Viewport */
2331 #define _NEW_PACKUNPACK 0x200000 /**< __GLcontextRec::Pack, __GLcontextRec::Unpack */
2332 #define _NEW_ARRAY 0x400000 /**< __GLcontextRec::Array */
2333 #define _NEW_RENDERMODE 0x800000 /**< __GLcontextRec::RenderMode, __GLcontextRec::Feedback, __GLcontextRec::Select */
2334 #define _NEW_BUFFERS 0x1000000 /**< __GLcontextRec::Visual, __GLcontextRec::DrawBuffer, */
2335 #define _NEW_MULTISAMPLE 0x2000000 /**< __GLcontextRec::Multisample */
2336 #define _NEW_TRACK_MATRIX 0x4000000 /**< __GLcontextRec::VertexProgram */
2337 #define _NEW_PROGRAM 0x8000000 /**< __GLcontextRec::VertexProgram */
2338 #define _NEW_ALL ~0
2339 /*@}*/
2340
2341
2342 /**
2343 * \name Bits to track array state changes
2344 *
2345 * Also used to summarize array enabled.
2346 */
2347 /*@{*/
2348 #define _NEW_ARRAY_VERTEX VERT_BIT_POS
2349 #define _NEW_ARRAY_WEIGHT VERT_BIT_WEIGHT
2350 #define _NEW_ARRAY_NORMAL VERT_BIT_NORMAL
2351 #define _NEW_ARRAY_COLOR0 VERT_BIT_COLOR0
2352 #define _NEW_ARRAY_COLOR1 VERT_BIT_COLOR1
2353 #define _NEW_ARRAY_FOGCOORD VERT_BIT_FOG
2354 #define _NEW_ARRAY_INDEX VERT_BIT_SIX
2355 #define _NEW_ARRAY_EDGEFLAG VERT_BIT_SEVEN
2356 #define _NEW_ARRAY_TEXCOORD_0 VERT_BIT_TEX0
2357 #define _NEW_ARRAY_TEXCOORD_1 VERT_BIT_TEX1
2358 #define _NEW_ARRAY_TEXCOORD_2 VERT_BIT_TEX2
2359 #define _NEW_ARRAY_TEXCOORD_3 VERT_BIT_TEX3
2360 #define _NEW_ARRAY_TEXCOORD_4 VERT_BIT_TEX4
2361 #define _NEW_ARRAY_TEXCOORD_5 VERT_BIT_TEX5
2362 #define _NEW_ARRAY_TEXCOORD_6 VERT_BIT_TEX6
2363 #define _NEW_ARRAY_TEXCOORD_7 VERT_BIT_TEX7
2364 #define _NEW_ARRAY_ATTRIB_0 0x10000 /* start at bit 16 */
2365 #define _NEW_ARRAY_ALL 0xffffffff
2366
2367
2368 #define _NEW_ARRAY_TEXCOORD(i) (_NEW_ARRAY_TEXCOORD_0 << (i))
2369 #define _NEW_ARRAY_ATTRIB(i) (_NEW_ARRAY_ATTRIB_0 << (i))
2370 /*@}*/
2371
2372
2373 /**
2374 * \name A bunch of flags that we think might be useful to drivers.
2375 *
2376 * Set in the __GLcontextRec::_TriangleCaps bitfield.
2377 */
2378 /*@{*/
2379 #define DD_FLATSHADE 0x1
2380 #define DD_SEPARATE_SPECULAR 0x2
2381 #define DD_TRI_CULL_FRONT_BACK 0x4 /* special case on some hw */
2382 #define DD_TRI_LIGHT_TWOSIDE 0x8
2383 #define DD_TRI_UNFILLED 0x10
2384 #define DD_TRI_SMOOTH 0x20
2385 #define DD_TRI_STIPPLE 0x40
2386 #define DD_TRI_OFFSET 0x80
2387 #define DD_LINE_SMOOTH 0x100
2388 #define DD_LINE_STIPPLE 0x200
2389 #define DD_LINE_WIDTH 0x400
2390 #define DD_POINT_SMOOTH 0x800
2391 #define DD_POINT_SIZE 0x1000
2392 #define DD_POINT_ATTEN 0x2000
2393 #define DD_TRI_TWOSTENCIL 0x4000
2394 /*@}*/
2395
2396
2397 /**
2398 * \name Define the state changes under which each of these bits might change
2399 */
2400 /*@{*/
2401 #define _DD_NEW_FLATSHADE _NEW_LIGHT
2402 #define _DD_NEW_SEPARATE_SPECULAR (_NEW_LIGHT | _NEW_FOG | _NEW_PROGRAM)
2403 #define _DD_NEW_TRI_CULL_FRONT_BACK _NEW_POLYGON
2404 #define _DD_NEW_TRI_LIGHT_TWOSIDE _NEW_LIGHT
2405 #define _DD_NEW_TRI_UNFILLED _NEW_POLYGON
2406 #define _DD_NEW_TRI_SMOOTH _NEW_POLYGON
2407 #define _DD_NEW_TRI_STIPPLE _NEW_POLYGON
2408 #define _DD_NEW_TRI_OFFSET _NEW_POLYGON
2409 #define _DD_NEW_LINE_SMOOTH _NEW_LINE
2410 #define _DD_NEW_LINE_STIPPLE _NEW_LINE
2411 #define _DD_NEW_LINE_WIDTH _NEW_LINE
2412 #define _DD_NEW_POINT_SMOOTH _NEW_POINT
2413 #define _DD_NEW_POINT_SIZE _NEW_POINT
2414 #define _DD_NEW_POINT_ATTEN _NEW_POINT
2415 /*@}*/
2416
2417
2418 #define _MESA_NEW_NEED_EYE_COORDS (_NEW_LIGHT | \
2419 _NEW_TEXTURE | \
2420 _NEW_POINT | \
2421 _NEW_MODELVIEW)
2422
2423 #define _MESA_NEW_NEED_NORMALS (_NEW_LIGHT | \
2424 _NEW_TEXTURE)
2425
2426 #define _IMAGE_NEW_TRANSFER_STATE (_NEW_PIXEL | _NEW_COLOR_MATRIX)
2427
2428
2429
2430
2431 /*
2432 * Forward declaration of display list data types:
2433 */
2434 union node;
2435 typedef union node Node;
2436
2437
2438 /* This has to be included here. */
2439 #include "dd.h"
2440
2441
2442 #define NUM_VERTEX_FORMAT_ENTRIES (sizeof(GLvertexformat) / sizeof(void *))
2443
2444 /**
2445 * Core Mesa's support for tnl modules:
2446 */
2447 struct gl_tnl_module
2448 {
2449 /**
2450 * Vertex format to be lazily swapped into current dispatch.
2451 */
2452 const GLvertexformat *Current;
2453
2454 /**
2455 * \name Record of functions swapped out.
2456 * On restore, only need to swap these functions back in.
2457 */
2458 /*@{*/
2459 void *Swapped[NUM_VERTEX_FORMAT_ENTRIES][2];
2460 GLuint SwapCount;
2461 /*@}*/
2462 };
2463
2464 /* Strictly this is a tnl/ private concept, but it doesn't seem
2465 * worthwhile adding a tnl private structure just to hold this one bit
2466 * of information:
2467 */
2468 #define MESA_DLIST_DANGLING_REFS 0x1
2469
2470 /* Provide a location where information about a display list can be
2471 * collected. Could be extended with driverPrivate structures,
2472 * etc. in the future.
2473 */
2474 struct mesa_display_list
2475 {
2476 Node *node;
2477 GLuint id;
2478 GLuint flags;
2479 };
2480
2481
2482 /**
2483 * State used during display list compilation and execution.
2484 */
2485 struct mesa_list_state
2486 {
2487 struct mesa_display_list *CallStack[MAX_LIST_NESTING];
2488 GLuint CallDepth; /**< Current recursion calling depth */
2489
2490 struct mesa_display_list *CurrentList;
2491 Node *CurrentListPtr; /**< Head of list being compiled */
2492 GLuint CurrentListNum; /**< Number of the list being compiled */
2493 Node *CurrentBlock; /**< Pointer to current block of nodes */
2494 GLuint CurrentPos; /**< Index into current block of nodes */
2495
2496 GLvertexformat ListVtxfmt;
2497
2498 GLubyte ActiveAttribSize[VERT_ATTRIB_MAX];
2499 GLfloat CurrentAttrib[VERT_ATTRIB_MAX][4];
2500
2501 GLubyte ActiveMaterialSize[MAT_ATTRIB_MAX];
2502 GLfloat CurrentMaterial[MAT_ATTRIB_MAX][4];
2503
2504 GLubyte ActiveIndex;
2505 GLfloat CurrentIndex;
2506
2507 GLubyte ActiveEdgeFlag;
2508 GLboolean CurrentEdgeFlag;
2509 };
2510
2511
2512 /**
2513 * Mesa rendering context.
2514 *
2515 * This is the central context data structure for Mesa. Almost all
2516 * OpenGL state is contained in this structure.
2517 * Think of this as a base class from which device drivers will derive
2518 * sub classes.
2519 *
2520 * The GLcontext typedef names this structure.
2521 */
2522 struct __GLcontextRec
2523 {
2524 /**
2525 * \name OS related interfaces.
2526 *
2527 * These \b must be the first members of this structure, because they are
2528 * exposed to the outside world (i.e. GLX extension).
2529 */
2530 /*@{*/
2531 __GLimports imports;
2532 __GLexports exports;
2533 /*@}*/
2534
2535 /** State possibly shared with other contexts in the address space */
2536 struct gl_shared_state *Shared;
2537
2538 /** \name API function pointer tables */
2539 /*@{*/
2540 struct _glapi_table *Save; /**< Display list save functions */
2541 struct _glapi_table *Exec; /**< Execute functions */
2542 struct _glapi_table *CurrentDispatch; /**< == Save or Exec !! */
2543 /*@}*/
2544
2545 GLvisual Visual;
2546 GLframebuffer *DrawBuffer; /**< buffer for writing */
2547 GLframebuffer *ReadBuffer; /**< buffer for reading */
2548
2549 /**
2550 * Device driver function pointer table
2551 */
2552 struct dd_function_table Driver;
2553
2554 void *DriverCtx; /**< Points to device driver context/state */
2555 void *DriverMgrCtx; /**< Points to device driver manager (optional)*/
2556
2557 /** Core/Driver constants */
2558 struct gl_constants Const;
2559
2560 /** \name The various 4x4 matrix stacks */
2561 /*@{*/
2562 struct matrix_stack ModelviewMatrixStack;
2563 struct matrix_stack ProjectionMatrixStack;
2564 struct matrix_stack ColorMatrixStack;
2565 struct matrix_stack TextureMatrixStack[MAX_TEXTURE_COORD_UNITS];
2566 struct matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
2567 struct matrix_stack *CurrentStack; /**< Points to one of the above stacks */
2568 /*@}*/
2569
2570 /** Combined modelview and projection matrix */
2571 GLmatrix _ModelProjectMatrix;
2572
2573 /** \name Display lists */
2574 struct mesa_list_state ListState;
2575
2576 GLboolean ExecuteFlag; /**< Execute GL commands? */
2577 GLboolean CompileFlag; /**< Compile GL commands into display list? */
2578
2579 /** Extensions */
2580 struct gl_extensions Extensions;
2581
2582 /** \name Renderer attribute stack */
2583 /*@{*/
2584 GLuint AttribStackDepth;
2585 struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
2586 /*@}*/
2587
2588 /** \name Renderer attribute groups
2589 *
2590 * We define a struct for each attribute group to make pushing and popping
2591 * attributes easy. Also it's a good organization.
2592 */
2593 /*@{*/
2594 struct gl_accum_attrib Accum; /**< Accumulation buffer attributes */
2595 struct gl_colorbuffer_attrib Color; /**< Color buffers attributes */
2596 struct gl_current_attrib Current; /**< Current attributes */
2597 struct gl_depthbuffer_attrib Depth; /**< Depth buffer attributes */
2598 struct gl_eval_attrib Eval; /**< Eval attributes */
2599 struct gl_fog_attrib Fog; /**< Fog attributes */
2600 struct gl_hint_attrib Hint; /**< Hint attributes */
2601 struct gl_light_attrib Light; /**< Light attributes */
2602 struct gl_line_attrib Line; /**< Line attributes */
2603 struct gl_list_attrib List; /**< List attributes */
2604 struct gl_multisample_attrib Multisample;
2605 struct gl_pixel_attrib Pixel; /**< Pixel attributes */
2606 struct gl_point_attrib Point; /**< Point attributes */
2607 struct gl_polygon_attrib Polygon; /**< Polygon attributes */
2608 GLuint PolygonStipple[32]; /**< Polygon stipple */
2609 struct gl_scissor_attrib Scissor; /**< Scissor attributes */
2610 struct gl_stencil_attrib Stencil; /**< Stencil buffer attributes */
2611 struct gl_texture_attrib Texture; /**< Texture attributes */
2612 struct gl_transform_attrib Transform; /**< Transformation attributes */
2613 struct gl_viewport_attrib Viewport; /**< Viewport attributes */
2614 /*@}*/
2615
2616 /** \name Client attribute stack */
2617 /*@{*/
2618 GLuint ClientAttribStackDepth;
2619 struct gl_attrib_node *ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
2620 /*@}*/
2621
2622 /** \name Client attribute groups */
2623 /*@{*/
2624 struct gl_array_attrib Array; /**< Vertex arrays */
2625 struct gl_pixelstore_attrib Pack; /**< Pixel packing */
2626 struct gl_pixelstore_attrib Unpack; /**< Pixel unpacking */
2627 struct gl_pixelstore_attrib DefaultPacking; /**< Default params */
2628 /*@}*/
2629
2630 /** \name Other assorted state (not pushed/popped on attribute stack) */
2631 /*@{*/
2632 struct gl_histogram_attrib Histogram;
2633 struct gl_minmax_attrib MinMax;
2634 struct gl_convolution_attrib Convolution1D;
2635 struct gl_convolution_attrib Convolution2D;
2636 struct gl_convolution_attrib Separable2D;
2637
2638 struct gl_evaluators EvalMap; /**< All evaluators */
2639 struct gl_feedback Feedback; /**< Feedback */
2640 struct gl_selection Select; /**< Selection */
2641
2642 struct gl_color_table ColorTable; /**< Pre-convolution */
2643 struct gl_color_table ProxyColorTable; /**< Pre-convolution */
2644 struct gl_color_table PostConvolutionColorTable;
2645 struct gl_color_table ProxyPostConvolutionColorTable;
2646 struct gl_color_table PostColorMatrixColorTable;
2647 struct gl_color_table ProxyPostColorMatrixColorTable;
2648
2649 struct gl_program_state Program; /**< for vertex or fragment progs */
2650 struct gl_vertex_program_state VertexProgram; /**< GL_NV_vertex_program */
2651 struct gl_fragment_program_state FragmentProgram; /**< GL_NV_fragment_program */
2652 struct gl_ati_fragment_shader_state ATIFragmentShader; /**< GL_ATI_fragment_shader */
2653
2654 struct fragment_program _TexEnvProgram; /**< Texture state as fragment program */
2655 struct vertex_program _TnlProgram; /**< Fixed func TNL state as vertex program */
2656
2657 GLboolean _MaintainTexEnvProgram;
2658 GLboolean _MaintainTnlProgram;
2659
2660 struct gl_occlusion_state Occlusion; /**< GL_ARB_occlusion_query */
2661
2662 struct gl_shader_objects_state ShaderObjects; /* GL_ARB_shader_objects */
2663 /*@}*/
2664
2665 #if FEATURE_EXT_framebuffer_object
2666 struct gl_framebuffer *CurrentFramebuffer;
2667 struct gl_renderbuffer *CurrentRenderbuffer;
2668 #endif
2669
2670 GLenum ErrorValue; /**< Last error code */
2671 GLenum RenderMode; /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
2672 GLuint NewState; /**< bitwise-or of _NEW_* flags */
2673
2674 /** \name Derived state */
2675 /*@{*/
2676 GLuint _TriangleCaps; /**< bitwise-or of DD_* flags */
2677 GLuint _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
2678 GLfloat _EyeZDir[3];
2679 GLfloat _ModelViewInvScale;
2680 GLuint _NeedEyeCoords;
2681 GLuint _ForceEyeCoords;
2682 GLboolean _RotateMode;
2683 GLenum _CurrentProgram; /* currently executing program */
2684
2685 struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */
2686 struct gl_shine_tab *_ShineTabList; /**< MRU list of inactive shine tables */
2687 /**@}*/
2688
2689 struct gl_list_extensions ListExt; /**< driver dlist extensions */
2690
2691
2692 GLboolean OcclusionResult; /**< for GL_HP_occlusion_test */
2693 GLboolean OcclusionResultSaved; /**< for GL_HP_occlusion_test */
2694 GLuint _Facing; /**< This is a hack for 2-sided stencil test.
2695 *
2696 * We don't have a better way to communicate this value from
2697 * swrast_setup to swrast. */
2698
2699
2700 /** \name Z buffer stuff */
2701 /*@{*/
2702 GLuint DepthMax; /**< Max depth buffer value */
2703 GLfloat DepthMaxF; /**< Float max depth buffer value */
2704 GLfloat MRD; /**< minimum resolvable difference in Z values */
2705 /*@}*/
2706
2707 /** \name Color clamping (tentative part of GL_ARB_color_clamp_control) */
2708 /*@{*/
2709 GLboolean ClampFragmentColors;
2710 GLboolean ClampVertexColors;
2711 /*@}*/
2712
2713 /** \name For debugging/development only */
2714 /*@{*/
2715 GLboolean FirstTimeCurrent;
2716 /*@}*/
2717
2718 /** Dither disable via MESA_NO_DITHER env var */
2719 GLboolean NoDither;
2720
2721 /** software compression/decompression supported or not */
2722 GLboolean Mesa_DXTn;
2723
2724 /** Core tnl module support */
2725 struct gl_tnl_module TnlModule;
2726
2727 /**
2728 * \name Hooks for module contexts.
2729 *
2730 * These will eventually live in the driver or elsewhere.
2731 */
2732 /*@{*/
2733 void *swrast_context;
2734 void *swsetup_context;
2735 void *swtnl_context;
2736 void *swtnl_im;
2737 void *acache_context;
2738 void *aelt_context;
2739 /*@}*/
2740 };
2741
2742
2743 /** The string names for GL_POINT, GL_LINE_LOOP, etc */
2744 extern const char *_mesa_prim_name[GL_POLYGON+4];
2745
2746
2747 #ifdef MESA_DEBUG
2748 extern int MESA_VERBOSE;
2749 extern int MESA_DEBUG_FLAGS;
2750 # define MESA_FUNCTION __FUNCTION__
2751 #else
2752 # define MESA_VERBOSE 0
2753 # define MESA_DEBUG_FLAGS 0
2754 # define MESA_FUNCTION "a function"
2755 # ifndef NDEBUG
2756 # define NDEBUG
2757 # endif
2758 #endif
2759
2760
2761 enum _verbose
2762 {
2763 VERBOSE_VARRAY = 0x0001,
2764 VERBOSE_TEXTURE = 0x0002,
2765 VERBOSE_IMMEDIATE = 0x0004,
2766 VERBOSE_PIPELINE = 0x0008,
2767 VERBOSE_DRIVER = 0x0010,
2768 VERBOSE_STATE = 0x0020,
2769 VERBOSE_API = 0x0040,
2770 VERBOSE_DISPLAY_LIST = 0x0100,
2771 VERBOSE_LIGHTING = 0x0200,
2772 VERBOSE_PRIMS = 0x0400,
2773 VERBOSE_VERTS = 0x0800
2774 };
2775
2776
2777 enum _debug
2778 {
2779 DEBUG_ALWAYS_FLUSH = 0x1
2780 };
2781
2782
2783
2784 #define Elements(x) sizeof(x)/sizeof(*(x))
2785
2786
2787 #endif /* TYPES_H */