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