OSDN Git Service

Merge ../mesa into vulkan
[android-x86/external-mesa.git] / src / mesa / main / mtypes.h
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5  * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  */
25
26 /**
27  * \file mtypes.h
28  * Main Mesa data structures.
29  *
30  * Please try to mark derived values with a leading underscore ('_').
31  */
32
33 #ifndef MTYPES_H
34 #define MTYPES_H
35
36
37 #include <stdint.h>             /* uint32_t */
38 #include <stdbool.h>
39 #include "c11/threads.h"
40
41 #include "main/glheader.h"
42 #include "main/config.h"
43 #include "glapi/glapi.h"
44 #include "math/m_matrix.h"      /* GLmatrix */
45 #include "glsl/nir/shader_enums.h"
46 #include "main/formats.h"       /* MESA_FORMAT_COUNT */
47
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53
54 /**
55  * \name 64-bit extension of GLbitfield.
56  */
57 /*@{*/
58 typedef GLuint64 GLbitfield64;
59
60 /** Set a single bit */
61 #define BITFIELD64_BIT(b)      ((GLbitfield64)1 << (b))
62 /** Set all bits up to excluding bit b */
63 #define BITFIELD64_MASK(b)      \
64    ((b) == 64 ? (~(GLbitfield64)0) : BITFIELD64_BIT(b) - 1)
65 /** Set count bits starting from bit b  */
66 #define BITFIELD64_RANGE(b, count) \
67    (BITFIELD64_MASK((b) + (count)) & ~BITFIELD64_MASK(b))
68
69
70 /**
71  * \name Some forward type declarations
72  */
73 /*@{*/
74 struct _mesa_HashTable;
75 struct gl_attrib_node;
76 struct gl_list_extensions;
77 struct gl_meta_state;
78 struct gl_program_cache;
79 struct gl_texture_object;
80 struct gl_debug_state;
81 struct gl_context;
82 struct st_context;
83 struct gl_uniform_storage;
84 struct prog_instruction;
85 struct gl_program_parameter_list;
86 struct set;
87 struct set_entry;
88 struct vbo_context;
89 /*@}*/
90
91
92 /** Extra draw modes beyond GL_POINTS, GL_TRIANGLE_FAN, etc */
93 #define PRIM_MAX                 GL_PATCHES
94 #define PRIM_OUTSIDE_BEGIN_END   (PRIM_MAX + 1)
95 #define PRIM_UNKNOWN             (PRIM_MAX + 2)
96
97 /**
98  * Determine if the given gl_varying_slot appears in the fragment shader.
99  */
100 static inline GLboolean
101 _mesa_varying_slot_in_fs(gl_varying_slot slot)
102 {
103    switch (slot) {
104    case VARYING_SLOT_PSIZ:
105    case VARYING_SLOT_BFC0:
106    case VARYING_SLOT_BFC1:
107    case VARYING_SLOT_EDGE:
108    case VARYING_SLOT_CLIP_VERTEX:
109    case VARYING_SLOT_LAYER:
110    case VARYING_SLOT_TESS_LEVEL_OUTER:
111    case VARYING_SLOT_TESS_LEVEL_INNER:
112       return GL_FALSE;
113    default:
114       return GL_TRUE;
115    }
116 }
117
118 /**
119  * Indexes for all renderbuffers
120  */
121 typedef enum
122 {
123    /* the four standard color buffers */
124    BUFFER_FRONT_LEFT,
125    BUFFER_BACK_LEFT,
126    BUFFER_FRONT_RIGHT,
127    BUFFER_BACK_RIGHT,
128    BUFFER_DEPTH,
129    BUFFER_STENCIL,
130    BUFFER_ACCUM,
131    /* optional aux buffer */
132    BUFFER_AUX0,
133    /* generic renderbuffers */
134    BUFFER_COLOR0,
135    BUFFER_COLOR1,
136    BUFFER_COLOR2,
137    BUFFER_COLOR3,
138    BUFFER_COLOR4,
139    BUFFER_COLOR5,
140    BUFFER_COLOR6,
141    BUFFER_COLOR7,
142    BUFFER_COUNT
143 } gl_buffer_index;
144
145 /**
146  * Bit flags for all renderbuffers
147  */
148 #define BUFFER_BIT_FRONT_LEFT   (1 << BUFFER_FRONT_LEFT)
149 #define BUFFER_BIT_BACK_LEFT    (1 << BUFFER_BACK_LEFT)
150 #define BUFFER_BIT_FRONT_RIGHT  (1 << BUFFER_FRONT_RIGHT)
151 #define BUFFER_BIT_BACK_RIGHT   (1 << BUFFER_BACK_RIGHT)
152 #define BUFFER_BIT_AUX0         (1 << BUFFER_AUX0)
153 #define BUFFER_BIT_AUX1         (1 << BUFFER_AUX1)
154 #define BUFFER_BIT_AUX2         (1 << BUFFER_AUX2)
155 #define BUFFER_BIT_AUX3         (1 << BUFFER_AUX3)
156 #define BUFFER_BIT_DEPTH        (1 << BUFFER_DEPTH)
157 #define BUFFER_BIT_STENCIL      (1 << BUFFER_STENCIL)
158 #define BUFFER_BIT_ACCUM        (1 << BUFFER_ACCUM)
159 #define BUFFER_BIT_COLOR0       (1 << BUFFER_COLOR0)
160 #define BUFFER_BIT_COLOR1       (1 << BUFFER_COLOR1)
161 #define BUFFER_BIT_COLOR2       (1 << BUFFER_COLOR2)
162 #define BUFFER_BIT_COLOR3       (1 << BUFFER_COLOR3)
163 #define BUFFER_BIT_COLOR4       (1 << BUFFER_COLOR4)
164 #define BUFFER_BIT_COLOR5       (1 << BUFFER_COLOR5)
165 #define BUFFER_BIT_COLOR6       (1 << BUFFER_COLOR6)
166 #define BUFFER_BIT_COLOR7       (1 << BUFFER_COLOR7)
167
168 /**
169  * Mask of all the color buffer bits (but not accum).
170  */
171 #define BUFFER_BITS_COLOR  (BUFFER_BIT_FRONT_LEFT | \
172                             BUFFER_BIT_BACK_LEFT | \
173                             BUFFER_BIT_FRONT_RIGHT | \
174                             BUFFER_BIT_BACK_RIGHT | \
175                             BUFFER_BIT_AUX0 | \
176                             BUFFER_BIT_COLOR0 | \
177                             BUFFER_BIT_COLOR1 | \
178                             BUFFER_BIT_COLOR2 | \
179                             BUFFER_BIT_COLOR3 | \
180                             BUFFER_BIT_COLOR4 | \
181                             BUFFER_BIT_COLOR5 | \
182                             BUFFER_BIT_COLOR6 | \
183                             BUFFER_BIT_COLOR7)
184
185 /**
186  * Framebuffer configuration (aka visual / pixelformat)
187  * Note: some of these fields should be boolean, but it appears that
188  * code in drivers/dri/common/util.c requires int-sized fields.
189  */
190 struct gl_config
191 {
192    GLboolean rgbMode;
193    GLboolean floatMode;
194    GLuint doubleBufferMode;
195    GLuint stereoMode;
196
197    GLboolean haveAccumBuffer;
198    GLboolean haveDepthBuffer;
199    GLboolean haveStencilBuffer;
200
201    GLint redBits, greenBits, blueBits, alphaBits;       /* bits per comp */
202    GLuint redMask, greenMask, blueMask, alphaMask;
203    GLint rgbBits;               /* total bits for rgb */
204    GLint indexBits;             /* total bits for colorindex */
205
206    GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits;
207    GLint depthBits;
208    GLint stencilBits;
209
210    GLint numAuxBuffers;
211
212    GLint level;
213
214    /* EXT_visual_rating / GLX 1.2 */
215    GLint visualRating;
216
217    /* EXT_visual_info / GLX 1.2 */
218    GLint transparentPixel;
219    /*    colors are floats scaled to ints */
220    GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha;
221    GLint transparentIndex;
222
223    /* ARB_multisample / SGIS_multisample */
224    GLint sampleBuffers;
225    GLint samples;
226
227    /* SGIX_pbuffer / GLX 1.3 */
228    GLint maxPbufferWidth;
229    GLint maxPbufferHeight;
230    GLint maxPbufferPixels;
231    GLint optimalPbufferWidth;   /* Only for SGIX_pbuffer. */
232    GLint optimalPbufferHeight;  /* Only for SGIX_pbuffer. */
233
234    /* OML_swap_method */
235    GLint swapMethod;
236
237    /* EXT_texture_from_pixmap */
238    GLint bindToTextureRgb;
239    GLint bindToTextureRgba;
240    GLint bindToMipmapTexture;
241    GLint bindToTextureTargets;
242    GLint yInverted;
243
244    /* EXT_framebuffer_sRGB */
245    GLint sRGBCapable;
246 };
247
248
249 /**
250  * \name Bit flags used for updating material values.
251  */
252 /*@{*/
253 #define MAT_ATTRIB_FRONT_AMBIENT           0 
254 #define MAT_ATTRIB_BACK_AMBIENT            1
255 #define MAT_ATTRIB_FRONT_DIFFUSE           2 
256 #define MAT_ATTRIB_BACK_DIFFUSE            3
257 #define MAT_ATTRIB_FRONT_SPECULAR          4 
258 #define MAT_ATTRIB_BACK_SPECULAR           5
259 #define MAT_ATTRIB_FRONT_EMISSION          6
260 #define MAT_ATTRIB_BACK_EMISSION           7
261 #define MAT_ATTRIB_FRONT_SHININESS         8
262 #define MAT_ATTRIB_BACK_SHININESS          9
263 #define MAT_ATTRIB_FRONT_INDEXES           10
264 #define MAT_ATTRIB_BACK_INDEXES            11
265 #define MAT_ATTRIB_MAX                     12
266
267 #define MAT_ATTRIB_AMBIENT(f)  (MAT_ATTRIB_FRONT_AMBIENT+(f))  
268 #define MAT_ATTRIB_DIFFUSE(f)  (MAT_ATTRIB_FRONT_DIFFUSE+(f))  
269 #define MAT_ATTRIB_SPECULAR(f) (MAT_ATTRIB_FRONT_SPECULAR+(f)) 
270 #define MAT_ATTRIB_EMISSION(f) (MAT_ATTRIB_FRONT_EMISSION+(f)) 
271 #define MAT_ATTRIB_SHININESS(f)(MAT_ATTRIB_FRONT_SHININESS+(f))
272 #define MAT_ATTRIB_INDEXES(f)  (MAT_ATTRIB_FRONT_INDEXES+(f))  
273
274 #define MAT_INDEX_AMBIENT  0
275 #define MAT_INDEX_DIFFUSE  1
276 #define MAT_INDEX_SPECULAR 2
277
278 #define MAT_BIT_FRONT_AMBIENT         (1<<MAT_ATTRIB_FRONT_AMBIENT)
279 #define MAT_BIT_BACK_AMBIENT          (1<<MAT_ATTRIB_BACK_AMBIENT)
280 #define MAT_BIT_FRONT_DIFFUSE         (1<<MAT_ATTRIB_FRONT_DIFFUSE)
281 #define MAT_BIT_BACK_DIFFUSE          (1<<MAT_ATTRIB_BACK_DIFFUSE)
282 #define MAT_BIT_FRONT_SPECULAR        (1<<MAT_ATTRIB_FRONT_SPECULAR)
283 #define MAT_BIT_BACK_SPECULAR         (1<<MAT_ATTRIB_BACK_SPECULAR)
284 #define MAT_BIT_FRONT_EMISSION        (1<<MAT_ATTRIB_FRONT_EMISSION)
285 #define MAT_BIT_BACK_EMISSION         (1<<MAT_ATTRIB_BACK_EMISSION)
286 #define MAT_BIT_FRONT_SHININESS       (1<<MAT_ATTRIB_FRONT_SHININESS)
287 #define MAT_BIT_BACK_SHININESS        (1<<MAT_ATTRIB_BACK_SHININESS)
288 #define MAT_BIT_FRONT_INDEXES         (1<<MAT_ATTRIB_FRONT_INDEXES)
289 #define MAT_BIT_BACK_INDEXES          (1<<MAT_ATTRIB_BACK_INDEXES)
290
291
292 #define FRONT_MATERIAL_BITS     (MAT_BIT_FRONT_EMISSION |       \
293                                  MAT_BIT_FRONT_AMBIENT |        \
294                                  MAT_BIT_FRONT_DIFFUSE |        \
295                                  MAT_BIT_FRONT_SPECULAR |       \
296                                  MAT_BIT_FRONT_SHININESS |      \
297                                  MAT_BIT_FRONT_INDEXES)
298
299 #define BACK_MATERIAL_BITS      (MAT_BIT_BACK_EMISSION |        \
300                                  MAT_BIT_BACK_AMBIENT |         \
301                                  MAT_BIT_BACK_DIFFUSE |         \
302                                  MAT_BIT_BACK_SPECULAR |        \
303                                  MAT_BIT_BACK_SHININESS |       \
304                                  MAT_BIT_BACK_INDEXES)
305
306 #define ALL_MATERIAL_BITS       (FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
307 /*@}*/
308
309
310 /**
311  * Material state.
312  */
313 struct gl_material
314 {
315    GLfloat Attrib[MAT_ATTRIB_MAX][4];
316 };
317
318
319 /**
320  * Light state flags.
321  */
322 /*@{*/
323 #define LIGHT_SPOT         0x1
324 #define LIGHT_LOCAL_VIEWER 0x2
325 #define LIGHT_POSITIONAL   0x4
326 #define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
327 /*@}*/
328
329
330 /**
331  * Light source state.
332  */
333 struct gl_light
334 {
335    struct gl_light *next;       /**< double linked list with sentinel */
336    struct gl_light *prev;
337
338    GLfloat Ambient[4];          /**< ambient color */
339    GLfloat Diffuse[4];          /**< diffuse color */
340    GLfloat Specular[4];         /**< specular color */
341    GLfloat EyePosition[4];      /**< position in eye coordinates */
342    GLfloat SpotDirection[4];    /**< spotlight direction in eye coordinates */
343    GLfloat SpotExponent;
344    GLfloat SpotCutoff;          /**< in degrees */
345    GLfloat _CosCutoff;          /**< = MAX(0, cos(SpotCutoff)) */
346    GLfloat ConstantAttenuation;
347    GLfloat LinearAttenuation;
348    GLfloat QuadraticAttenuation;
349    GLboolean Enabled;           /**< On/off flag */
350
351    /** 
352     * \name Derived fields
353     */
354    /*@{*/
355    GLbitfield _Flags;           /**< Mask of LIGHT_x bits defined above */
356
357    GLfloat _Position[4];        /**< position in eye/obj coordinates */
358    GLfloat _VP_inf_norm[3];     /**< Norm direction to infinite light */
359    GLfloat _h_inf_norm[3];      /**< Norm( _VP_inf_norm + <0,0,1> ) */
360    GLfloat _NormSpotDirection[4]; /**< normalized spotlight direction */
361    GLfloat _VP_inf_spot_attenuation;
362
363    GLfloat _MatAmbient[2][3];   /**< material ambient * light ambient */
364    GLfloat _MatDiffuse[2][3];   /**< material diffuse * light diffuse */
365    GLfloat _MatSpecular[2][3];  /**< material spec * light specular */
366    /*@}*/
367 };
368
369
370 /**
371  * Light model state.
372  */
373 struct gl_lightmodel
374 {
375    GLfloat Ambient[4];          /**< ambient color */
376    GLboolean LocalViewer;       /**< Local (or infinite) view point? */
377    GLboolean TwoSide;           /**< Two (or one) sided lighting? */
378    GLenum ColorControl;         /**< either GL_SINGLE_COLOR
379                                  *    or GL_SEPARATE_SPECULAR_COLOR */
380 };
381
382
383 /**
384  * Accumulation buffer attribute group (GL_ACCUM_BUFFER_BIT)
385  */
386 struct gl_accum_attrib
387 {
388    GLfloat ClearColor[4];       /**< Accumulation buffer clear color */
389 };
390
391
392 /**
393  * Used for storing clear color, texture border color, etc.
394  * The float values are typically unclamped.
395  */
396 union gl_color_union
397 {
398    GLfloat f[4];
399    GLint i[4];
400    GLuint ui[4];
401 };
402
403
404 /**
405  * Color buffer attribute group (GL_COLOR_BUFFER_BIT).
406  */
407 struct gl_colorbuffer_attrib
408 {
409    GLuint ClearIndex;                      /**< Index for glClear */
410    union gl_color_union ClearColor;        /**< Color for glClear, unclamped */
411    GLuint IndexMask;                       /**< Color index write mask */
412    GLubyte ColorMask[MAX_DRAW_BUFFERS][4]; /**< Each flag is 0xff or 0x0 */
413
414    GLenum DrawBuffer[MAX_DRAW_BUFFERS]; /**< Which buffer to draw into */
415
416    /** 
417     * \name alpha testing
418     */
419    /*@{*/
420    GLboolean AlphaEnabled;              /**< Alpha test enabled flag */
421    GLenum AlphaFunc;                    /**< Alpha test function */
422    GLfloat AlphaRefUnclamped;
423    GLclampf AlphaRef;                   /**< Alpha reference value */
424    /*@}*/
425
426    /** 
427     * \name Blending
428     */
429    /*@{*/
430    GLbitfield BlendEnabled;             /**< Per-buffer blend enable flags */
431
432    /* NOTE: this does _not_ depend on fragment clamping or any other clamping
433     * control, only on the fixed-pointness of the render target.
434     * The query does however depend on fragment color clamping.
435     */
436    GLfloat BlendColorUnclamped[4];               /**< Blending color */
437    GLfloat BlendColor[4];               /**< Blending color */
438
439    struct
440    {
441       GLenum SrcRGB;             /**< RGB blend source term */
442       GLenum DstRGB;             /**< RGB blend dest term */
443       GLenum SrcA;               /**< Alpha blend source term */
444       GLenum DstA;               /**< Alpha blend dest term */
445       GLenum EquationRGB;        /**< GL_ADD, GL_SUBTRACT, etc. */
446       GLenum EquationA;          /**< GL_ADD, GL_SUBTRACT, etc. */
447       /**
448        * Set if any blend factor uses SRC1.  Computed at the time blend factors
449        * get set.
450        */
451       GLboolean _UsesDualSrc;
452    } Blend[MAX_DRAW_BUFFERS];
453    /** Are the blend func terms currently different for each buffer/target? */
454    GLboolean _BlendFuncPerBuffer;
455    /** Are the blend equations currently different for each buffer/target? */
456    GLboolean _BlendEquationPerBuffer;
457    /*@}*/
458
459    /** 
460     * \name Logic op
461     */
462    /*@{*/
463    GLboolean IndexLogicOpEnabled;       /**< Color index logic op enabled flag */
464    GLboolean ColorLogicOpEnabled;       /**< RGBA logic op enabled flag */
465    GLenum LogicOp;                      /**< Logic operator */
466
467    /*@}*/
468
469    GLboolean DitherFlag;                /**< Dither enable flag */
470
471    GLboolean _ClampFragmentColor; /** < with GL_FIXED_ONLY_ARB resolved */
472    GLenum ClampFragmentColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
473    GLenum ClampReadColor;     /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
474
475    GLboolean sRGBEnabled;    /**< Framebuffer sRGB blending/updating requested */
476 };
477
478
479 /**
480  * Current attribute group (GL_CURRENT_BIT).
481  */
482 struct gl_current_attrib
483 {
484    /**
485     * \name Current vertex attributes (color, texcoords, etc).
486     * \note Values are valid only after FLUSH_VERTICES has been called.
487     * \note Index and Edgeflag current values are stored as floats in the 
488     * SIX and SEVEN attribute slots.
489     * \note We need double storage for 64-bit vertex attributes
490     */
491    GLfloat Attrib[VERT_ATTRIB_MAX][4*2];
492
493    /**
494     * \name Current raster position attributes (always up to date after a
495     * glRasterPos call).
496     */
497    GLfloat RasterPos[4];
498    GLfloat RasterDistance;
499    GLfloat RasterColor[4];
500    GLfloat RasterSecondaryColor[4];
501    GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
502    GLboolean RasterPosValid;
503 };
504
505
506 /**
507  * Depth buffer attribute group (GL_DEPTH_BUFFER_BIT).
508  */
509 struct gl_depthbuffer_attrib
510 {
511    GLenum Func;                 /**< Function for depth buffer compare */
512    GLclampd Clear;              /**< Value to clear depth buffer to */
513    GLboolean Test;              /**< Depth buffering enabled flag */
514    GLboolean Mask;              /**< Depth buffer writable? */
515    GLboolean BoundsTest;        /**< GL_EXT_depth_bounds_test */
516    GLfloat BoundsMin, BoundsMax;/**< GL_EXT_depth_bounds_test */
517 };
518
519
520 /**
521  * Evaluator attribute group (GL_EVAL_BIT).
522  */
523 struct gl_eval_attrib
524 {
525    /**
526     * \name Enable bits 
527     */
528    /*@{*/
529    GLboolean Map1Color4;
530    GLboolean Map1Index;
531    GLboolean Map1Normal;
532    GLboolean Map1TextureCoord1;
533    GLboolean Map1TextureCoord2;
534    GLboolean Map1TextureCoord3;
535    GLboolean Map1TextureCoord4;
536    GLboolean Map1Vertex3;
537    GLboolean Map1Vertex4;
538    GLboolean Map2Color4;
539    GLboolean Map2Index;
540    GLboolean Map2Normal;
541    GLboolean Map2TextureCoord1;
542    GLboolean Map2TextureCoord2;
543    GLboolean Map2TextureCoord3;
544    GLboolean Map2TextureCoord4;
545    GLboolean Map2Vertex3;
546    GLboolean Map2Vertex4;
547    GLboolean AutoNormal;
548    /*@}*/
549    
550    /**
551     * \name Map Grid endpoints and divisions and calculated du values
552     */
553    /*@{*/
554    GLint MapGrid1un;
555    GLfloat MapGrid1u1, MapGrid1u2, MapGrid1du;
556    GLint MapGrid2un, MapGrid2vn;
557    GLfloat MapGrid2u1, MapGrid2u2, MapGrid2du;
558    GLfloat MapGrid2v1, MapGrid2v2, MapGrid2dv;
559    /*@}*/
560 };
561
562
563 /**
564  * Fog attribute group (GL_FOG_BIT).
565  */
566 struct gl_fog_attrib
567 {
568    GLboolean Enabled;           /**< Fog enabled flag */
569    GLboolean ColorSumEnabled;
570    GLfloat ColorUnclamped[4];            /**< Fog color */
571    GLfloat Color[4];            /**< Fog color */
572    GLfloat Density;             /**< Density >= 0.0 */
573    GLfloat Start;               /**< Start distance in eye coords */
574    GLfloat End;                 /**< End distance in eye coords */
575    GLfloat Index;               /**< Fog index */
576    GLenum Mode;                 /**< Fog mode */
577    GLenum FogCoordinateSource;  /**< GL_EXT_fog_coord */
578    GLfloat _Scale;              /**< (End == Start) ? 1.0 : 1.0 / (End - Start) */
579    GLenum FogDistanceMode;     /**< GL_NV_fog_distance */
580 };
581
582
583 /** 
584  * Hint attribute group (GL_HINT_BIT).
585  * 
586  * Values are always one of GL_FASTEST, GL_NICEST, or GL_DONT_CARE.
587  */
588 struct gl_hint_attrib
589 {
590    GLenum PerspectiveCorrection;
591    GLenum PointSmooth;
592    GLenum LineSmooth;
593    GLenum PolygonSmooth;
594    GLenum Fog;
595    GLenum TextureCompression;   /**< GL_ARB_texture_compression */
596    GLenum GenerateMipmap;       /**< GL_SGIS_generate_mipmap */
597    GLenum FragmentShaderDerivative; /**< GL_ARB_fragment_shader */
598 };
599
600
601 /**
602  * Lighting attribute group (GL_LIGHT_BIT).
603  */
604 struct gl_light_attrib
605 {
606    struct gl_light Light[MAX_LIGHTS];   /**< Array of light sources */
607    struct gl_lightmodel Model;          /**< Lighting model */
608
609    /**
610     * Front and back material values.
611     * Note: must call FLUSH_VERTICES() before using.
612     */
613    struct gl_material Material;
614
615    GLboolean Enabled;                   /**< Lighting enabled flag */
616    GLboolean ColorMaterialEnabled;
617
618    GLenum ShadeModel;                   /**< GL_FLAT or GL_SMOOTH */
619    GLenum ProvokingVertex;              /**< GL_EXT_provoking_vertex */
620    GLenum ColorMaterialFace;            /**< GL_FRONT, BACK or FRONT_AND_BACK */
621    GLenum ColorMaterialMode;            /**< GL_AMBIENT, GL_DIFFUSE, etc */
622    GLbitfield _ColorMaterialBitmask;    /**< bitmask formed from Face and Mode */
623
624
625    GLboolean _ClampVertexColor;
626    GLenum ClampVertexColor;             /**< GL_TRUE, GL_FALSE, GL_FIXED_ONLY */
627
628    /** 
629     * Derived state for optimizations: 
630     */
631    /*@{*/
632    GLboolean _NeedEyeCoords;            
633    GLboolean _NeedVertices;             /**< Use fast shader? */
634    struct gl_light EnabledList;         /**< List sentinel */
635
636    GLfloat _BaseColor[2][3];
637    /*@}*/
638 };
639
640
641 /**
642  * Line attribute group (GL_LINE_BIT).
643  */
644 struct gl_line_attrib
645 {
646    GLboolean SmoothFlag;        /**< GL_LINE_SMOOTH enabled? */
647    GLboolean StippleFlag;       /**< GL_LINE_STIPPLE enabled? */
648    GLushort StipplePattern;     /**< Stipple pattern */
649    GLint StippleFactor;         /**< Stipple repeat factor */
650    GLfloat Width;               /**< Line width */
651 };
652
653
654 /**
655  * Display list attribute group (GL_LIST_BIT).
656  */
657 struct gl_list_attrib
658 {
659    GLuint ListBase;
660 };
661
662
663 /**
664  * Multisample attribute group (GL_MULTISAMPLE_BIT).
665  */
666 struct gl_multisample_attrib
667 {
668    GLboolean Enabled;
669    GLboolean _Enabled;   /**< true if Enabled and multisample buffer */
670    GLboolean SampleAlphaToCoverage;
671    GLboolean SampleAlphaToOne;
672    GLboolean SampleCoverage;
673    GLboolean SampleCoverageInvert;
674    GLboolean SampleShading;
675
676    /* ARB_texture_multisample / GL3.2 additions */
677    GLboolean SampleMask;
678
679    GLfloat SampleCoverageValue;
680    GLfloat MinSampleShadingValue;
681
682    /** The GL spec defines this as an array but >32x MSAA is madness */
683    GLbitfield SampleMaskValue;
684 };
685
686
687 /**
688  * A pixelmap (see glPixelMap)
689  */
690 struct gl_pixelmap
691 {
692    GLint Size;
693    GLfloat Map[MAX_PIXEL_MAP_TABLE];
694 };
695
696
697 /**
698  * Collection of all pixelmaps
699  */
700 struct gl_pixelmaps
701 {
702    struct gl_pixelmap RtoR;  /**< i.e. GL_PIXEL_MAP_R_TO_R */
703    struct gl_pixelmap GtoG;
704    struct gl_pixelmap BtoB;
705    struct gl_pixelmap AtoA;
706    struct gl_pixelmap ItoR;
707    struct gl_pixelmap ItoG;
708    struct gl_pixelmap ItoB;
709    struct gl_pixelmap ItoA;
710    struct gl_pixelmap ItoI;
711    struct gl_pixelmap StoS;
712 };
713
714
715 /**
716  * Pixel attribute group (GL_PIXEL_MODE_BIT).
717  */
718 struct gl_pixel_attrib
719 {
720    GLenum ReadBuffer;           /**< source buffer for glRead/CopyPixels() */
721
722    /*--- Begin Pixel Transfer State ---*/
723    /* Fields are in the order in which they're applied... */
724
725    /** Scale & Bias (index shift, offset) */
726    /*@{*/
727    GLfloat RedBias, RedScale;
728    GLfloat GreenBias, GreenScale;
729    GLfloat BlueBias, BlueScale;
730    GLfloat AlphaBias, AlphaScale;
731    GLfloat DepthBias, DepthScale;
732    GLint IndexShift, IndexOffset;
733    /*@}*/
734
735    /* Pixel Maps */
736    /* Note: actual pixel maps are not part of this attrib group */
737    GLboolean MapColorFlag;
738    GLboolean MapStencilFlag;
739
740    /*--- End Pixel Transfer State ---*/
741
742    /** glPixelZoom */
743    GLfloat ZoomX, ZoomY;
744 };
745
746
747 /**
748  * Point attribute group (GL_POINT_BIT).
749  */
750 struct gl_point_attrib
751 {
752    GLfloat Size;                /**< User-specified point size */
753    GLfloat Params[3];           /**< GL_EXT_point_parameters */
754    GLfloat MinSize, MaxSize;    /**< GL_EXT_point_parameters */
755    GLfloat Threshold;           /**< GL_EXT_point_parameters */
756    GLboolean SmoothFlag;        /**< True if GL_POINT_SMOOTH is enabled */
757    GLboolean _Attenuated;       /**< True if Params != [1, 0, 0] */
758    GLboolean PointSprite;       /**< GL_NV/ARB_point_sprite */
759    GLboolean CoordReplace[MAX_TEXTURE_COORD_UNITS]; /**< GL_ARB_point_sprite*/
760    GLenum SpriteRMode;          /**< GL_NV_point_sprite (only!) */
761    GLenum SpriteOrigin;         /**< GL_ARB_point_sprite */
762 };
763
764
765 /**
766  * Polygon attribute group (GL_POLYGON_BIT).
767  */
768 struct gl_polygon_attrib
769 {
770    GLenum FrontFace;            /**< Either GL_CW or GL_CCW */
771    GLenum FrontMode;            /**< Either GL_POINT, GL_LINE or GL_FILL */
772    GLenum BackMode;             /**< Either GL_POINT, GL_LINE or GL_FILL */
773    GLboolean _FrontBit;         /**< 0=GL_CCW, 1=GL_CW */
774    GLboolean CullFlag;          /**< Culling on/off flag */
775    GLboolean SmoothFlag;        /**< True if GL_POLYGON_SMOOTH is enabled */
776    GLboolean StippleFlag;       /**< True if GL_POLYGON_STIPPLE is enabled */
777    GLenum CullFaceMode;         /**< Culling mode GL_FRONT or GL_BACK */
778    GLfloat OffsetFactor;        /**< Polygon offset factor, from user */
779    GLfloat OffsetUnits;         /**< Polygon offset units, from user */
780    GLfloat OffsetClamp;         /**< Polygon offset clamp, from user */
781    GLboolean OffsetPoint;       /**< Offset in GL_POINT mode */
782    GLboolean OffsetLine;        /**< Offset in GL_LINE mode */
783    GLboolean OffsetFill;        /**< Offset in GL_FILL mode */
784 };
785
786
787 /**
788  * Scissor attributes (GL_SCISSOR_BIT).
789  */
790 struct gl_scissor_rect
791 {
792    GLint X, Y;                  /**< Lower left corner of box */
793    GLsizei Width, Height;       /**< Size of box */
794 };
795 struct gl_scissor_attrib
796 {
797    GLbitfield EnableFlags;      /**< Scissor test enabled? */
798    struct gl_scissor_rect ScissorArray[MAX_VIEWPORTS];
799 };
800
801
802 /**
803  * Stencil attribute group (GL_STENCIL_BUFFER_BIT).
804  *
805  * Three sets of stencil data are tracked so that OpenGL 2.0,
806  * GL_EXT_stencil_two_side, and GL_ATI_separate_stencil can all be supported
807  * simultaneously.  In each of the stencil state arrays, element 0 corresponds
808  * to GL_FRONT.  Element 1 corresponds to the OpenGL 2.0 /
809  * GL_ATI_separate_stencil GL_BACK state.  Element 2 corresponds to the
810  * GL_EXT_stencil_two_side GL_BACK state.
811  *
812  * The derived value \c _BackFace is either 1 or 2 depending on whether or
813  * not GL_STENCIL_TEST_TWO_SIDE_EXT is enabled.
814  *
815  * The derived value \c _TestTwoSide is set when the front-face and back-face
816  * stencil state are different.
817  */
818 struct gl_stencil_attrib
819 {
820    GLboolean Enabled;           /**< Enabled flag */
821    GLboolean TestTwoSide;       /**< GL_EXT_stencil_two_side */
822    GLubyte ActiveFace;          /**< GL_EXT_stencil_two_side (0 or 2) */
823    GLboolean _Enabled;          /**< Enabled and stencil buffer present */
824    GLboolean _WriteEnabled;     /**< _Enabled and non-zero writemasks */
825    GLboolean _TestTwoSide;
826    GLubyte _BackFace;           /**< Current back stencil state (1 or 2) */
827    GLenum Function[3];          /**< Stencil function */
828    GLenum FailFunc[3];          /**< Fail function */
829    GLenum ZPassFunc[3];         /**< Depth buffer pass function */
830    GLenum ZFailFunc[3];         /**< Depth buffer fail function */
831    GLint Ref[3];                /**< Reference value */
832    GLuint ValueMask[3];         /**< Value mask */
833    GLuint WriteMask[3];         /**< Write mask */
834    GLuint Clear;                /**< Clear value */
835 };
836
837
838 /**
839  * An index for each type of texture object.  These correspond to the GL
840  * texture target enums, such as GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.
841  * Note: the order is from highest priority to lowest priority.
842  */
843 typedef enum
844 {
845    TEXTURE_2D_MULTISAMPLE_INDEX,
846    TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX,
847    TEXTURE_CUBE_ARRAY_INDEX,
848    TEXTURE_BUFFER_INDEX,
849    TEXTURE_2D_ARRAY_INDEX,
850    TEXTURE_1D_ARRAY_INDEX,
851    TEXTURE_EXTERNAL_INDEX,
852    TEXTURE_CUBE_INDEX,
853    TEXTURE_3D_INDEX,
854    TEXTURE_RECT_INDEX,
855    TEXTURE_2D_INDEX,
856    TEXTURE_1D_INDEX,
857    NUM_TEXTURE_TARGETS
858 } gl_texture_index;
859
860
861 /**
862  * Bit flags for each type of texture object
863  */
864 /*@{*/
865 #define TEXTURE_2D_MULTISAMPLE_BIT (1 << TEXTURE_2D_MULTISAMPLE_INDEX)
866 #define TEXTURE_2D_MULTISAMPLE_ARRAY_BIT (1 << TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX)
867 #define TEXTURE_CUBE_ARRAY_BIT (1 << TEXTURE_CUBE_ARRAY_INDEX)
868 #define TEXTURE_BUFFER_BIT   (1 << TEXTURE_BUFFER_INDEX)
869 #define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX)
870 #define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX)
871 #define TEXTURE_EXTERNAL_BIT (1 << TEXTURE_EXTERNAL_INDEX)
872 #define TEXTURE_CUBE_BIT     (1 << TEXTURE_CUBE_INDEX)
873 #define TEXTURE_3D_BIT       (1 << TEXTURE_3D_INDEX)
874 #define TEXTURE_RECT_BIT     (1 << TEXTURE_RECT_INDEX)
875 #define TEXTURE_2D_BIT       (1 << TEXTURE_2D_INDEX)
876 #define TEXTURE_1D_BIT       (1 << TEXTURE_1D_INDEX)
877 /*@}*/
878
879
880 /**
881  * Texture image state.  Drivers will typically create a subclass of this
882  * with extra fields for memory buffers, etc.
883  */
884 struct gl_texture_image
885 {
886    GLint InternalFormat;        /**< Internal format as given by the user */
887    GLenum _BaseFormat;          /**< Either GL_RGB, GL_RGBA, GL_ALPHA,
888                                  *   GL_LUMINANCE, GL_LUMINANCE_ALPHA,
889                                  *   GL_INTENSITY, GL_DEPTH_COMPONENT or
890                                  *   GL_DEPTH_STENCIL_EXT only. Used for
891                                  *   choosing TexEnv arithmetic.
892                                  */
893    mesa_format TexFormat;         /**< The actual texture memory format */
894
895    GLuint Border;               /**< 0 or 1 */
896    GLuint Width;                /**< = 2^WidthLog2 + 2*Border */
897    GLuint Height;               /**< = 2^HeightLog2 + 2*Border */
898    GLuint Depth;                /**< = 2^DepthLog2 + 2*Border */
899    GLuint Width2;               /**< = Width - 2*Border */
900    GLuint Height2;              /**< = Height - 2*Border */
901    GLuint Depth2;               /**< = Depth - 2*Border */
902    GLuint WidthLog2;            /**< = log2(Width2) */
903    GLuint HeightLog2;           /**< = log2(Height2) */
904    GLuint DepthLog2;            /**< = log2(Depth2) */
905    GLuint MaxNumLevels;         /**< = maximum possible number of mipmap
906                                        levels, computed from the dimensions */
907
908    struct gl_texture_object *TexObject;  /**< Pointer back to parent object */
909    GLuint Level;                /**< Which mipmap level am I? */
910    /** Cube map face: index into gl_texture_object::Image[] array */
911    GLuint Face;
912
913    /** GL_ARB_texture_multisample */
914    GLuint NumSamples;            /**< Sample count, or 0 for non-multisample */
915    GLboolean FixedSampleLocations; /**< Same sample locations for all pixels? */
916 };
917
918
919 /**
920  * Indexes for cube map faces.
921  */
922 typedef enum
923 {
924    FACE_POS_X = 0,
925    FACE_NEG_X = 1,
926    FACE_POS_Y = 2,
927    FACE_NEG_Y = 3,
928    FACE_POS_Z = 4,
929    FACE_NEG_Z = 5,
930    MAX_FACES = 6
931 } gl_face_index;
932
933
934 /**
935  * Sampler object state.  These objects are new with GL_ARB_sampler_objects
936  * and OpenGL 3.3.  Legacy texture objects also contain a sampler object.
937  */
938 struct gl_sampler_object
939 {
940    mtx_t Mutex;
941    GLuint Name;
942    GLint RefCount;
943    GLchar *Label;               /**< GL_KHR_debug */
944
945    GLenum WrapS;                /**< S-axis texture image wrap mode */
946    GLenum WrapT;                /**< T-axis texture image wrap mode */
947    GLenum WrapR;                /**< R-axis texture image wrap mode */
948    GLenum MinFilter;            /**< minification filter */
949    GLenum MagFilter;            /**< magnification filter */
950    union gl_color_union BorderColor;  /**< Interpreted according to texture format */
951    GLfloat MinLod;              /**< min lambda, OpenGL 1.2 */
952    GLfloat MaxLod;              /**< max lambda, OpenGL 1.2 */
953    GLfloat LodBias;             /**< OpenGL 1.4 */
954    GLfloat MaxAnisotropy;       /**< GL_EXT_texture_filter_anisotropic */
955    GLenum CompareMode;          /**< GL_ARB_shadow */
956    GLenum CompareFunc;          /**< GL_ARB_shadow */
957    GLenum sRGBDecode;           /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */
958    GLboolean CubeMapSeamless;   /**< GL_AMD_seamless_cubemap_per_texture */
959 };
960
961
962 /**
963  * Texture object state.  Contains the array of mipmap images, border color,
964  * wrap modes, filter modes, and shadow/texcompare state.
965  */
966 struct gl_texture_object
967 {
968    mtx_t Mutex;      /**< for thread safety */
969    GLint RefCount;             /**< reference count */
970    GLuint Name;                /**< the user-visible texture object ID */
971    GLchar *Label;               /**< GL_KHR_debug */
972    GLenum Target;              /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
973    gl_texture_index TargetIndex; /**< The gl_texture_unit::CurrentTex index.
974                                       Only valid when Target is valid. */
975
976    struct gl_sampler_object Sampler;
977
978    GLenum DepthMode;           /**< GL_ARB_depth_texture */
979    bool StencilSampling;       /**< Should we sample stencil instead of depth? */
980
981    GLfloat Priority;           /**< in [0,1] */
982    GLint BaseLevel;            /**< min mipmap level, OpenGL 1.2 */
983    GLint MaxLevel;             /**< max mipmap level, OpenGL 1.2 */
984    GLint ImmutableLevels;      /**< ES 3.0 / ARB_texture_view */
985    GLint _MaxLevel;            /**< actual max mipmap level (q in the spec) */
986    GLfloat _MaxLambda;         /**< = _MaxLevel - BaseLevel (q - p in spec) */
987    GLint CropRect[4];          /**< GL_OES_draw_texture */
988    GLenum Swizzle[4];          /**< GL_EXT_texture_swizzle */
989    GLuint _Swizzle;            /**< same as Swizzle, but SWIZZLE_* format */
990    GLboolean GenerateMipmap;   /**< GL_SGIS_generate_mipmap */
991    GLboolean _BaseComplete;    /**< Is the base texture level valid? */
992    GLboolean _MipmapComplete;  /**< Is the whole mipmap valid? */
993    GLboolean _IsIntegerFormat; /**< Does the texture store integer values? */
994    GLboolean _RenderToTexture; /**< Any rendering to this texture? */
995    GLboolean Purgeable;        /**< Is the buffer purgeable under memory
996                                     pressure? */
997    GLboolean Immutable;        /**< GL_ARB_texture_storage */
998    GLboolean _IsFloat;         /**< GL_OES_float_texture */
999    GLboolean _IsHalfFloat;     /**< GL_OES_half_float_texture */
1000
1001    GLuint MinLevel;            /**< GL_ARB_texture_view */
1002    GLuint MinLayer;            /**< GL_ARB_texture_view */
1003    GLuint NumLevels;           /**< GL_ARB_texture_view */
1004    GLuint NumLayers;           /**< GL_ARB_texture_view */
1005
1006    /** Actual texture images, indexed by [cube face] and [mipmap level] */
1007    struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
1008
1009    /** GL_ARB_texture_buffer_object */
1010    struct gl_buffer_object *BufferObject;
1011    GLenum BufferObjectFormat;
1012    /** Equivalent Mesa format for BufferObjectFormat. */
1013    mesa_format _BufferObjectFormat;
1014    /** GL_ARB_texture_buffer_range */
1015    GLintptr BufferOffset;
1016    GLsizeiptr BufferSize; /**< if this is -1, use BufferObject->Size instead */
1017
1018    /** GL_OES_EGL_image_external */
1019    GLint RequiredTextureImageUnits;
1020
1021    /** GL_ARB_shader_image_load_store */
1022    GLenum ImageFormatCompatibilityType;
1023 };
1024
1025
1026 /** Up to four combiner sources are possible with GL_NV_texture_env_combine4 */
1027 #define MAX_COMBINER_TERMS 4
1028
1029
1030 /**
1031  * Texture combine environment state.
1032  */
1033 struct gl_tex_env_combine_state
1034 {
1035    GLenum ModeRGB;       /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1036    GLenum ModeA;         /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1037    /** Source terms: GL_PRIMARY_COLOR, GL_TEXTURE, etc */
1038    GLenum SourceRGB[MAX_COMBINER_TERMS];
1039    GLenum SourceA[MAX_COMBINER_TERMS];
1040    /** Source operands: GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, etc */
1041    GLenum OperandRGB[MAX_COMBINER_TERMS];
1042    GLenum OperandA[MAX_COMBINER_TERMS];
1043    GLuint ScaleShiftRGB; /**< 0, 1 or 2 */
1044    GLuint ScaleShiftA;   /**< 0, 1 or 2 */
1045    GLuint _NumArgsRGB;   /**< Number of inputs used for the RGB combiner */
1046    GLuint _NumArgsA;     /**< Number of inputs used for the A combiner */
1047 };
1048
1049
1050 /**
1051  * TexGenEnabled flags.
1052  */
1053 /*@{*/
1054 #define S_BIT 1
1055 #define T_BIT 2
1056 #define R_BIT 4
1057 #define Q_BIT 8
1058 #define STR_BITS (S_BIT | T_BIT | R_BIT)
1059 /*@}*/
1060
1061
1062 /**
1063  * Bit flag versions of the corresponding GL_ constants.
1064  */
1065 /*@{*/
1066 #define TEXGEN_SPHERE_MAP        0x1
1067 #define TEXGEN_OBJ_LINEAR        0x2
1068 #define TEXGEN_EYE_LINEAR        0x4
1069 #define TEXGEN_REFLECTION_MAP_NV 0x8
1070 #define TEXGEN_NORMAL_MAP_NV     0x10
1071
1072 #define TEXGEN_NEED_NORMALS      (TEXGEN_SPHERE_MAP        | \
1073                                   TEXGEN_REFLECTION_MAP_NV | \
1074                                   TEXGEN_NORMAL_MAP_NV)
1075 #define TEXGEN_NEED_EYE_COORD    (TEXGEN_SPHERE_MAP        | \
1076                                   TEXGEN_REFLECTION_MAP_NV | \
1077                                   TEXGEN_NORMAL_MAP_NV     | \
1078                                   TEXGEN_EYE_LINEAR)
1079 /*@}*/
1080
1081
1082
1083 /** Tex-gen enabled for texture unit? */
1084 #define ENABLE_TEXGEN(unit) (1 << (unit))
1085
1086 /** Non-identity texture matrix for texture unit? */
1087 #define ENABLE_TEXMAT(unit) (1 << (unit))
1088
1089
1090 /**
1091  * Texture coord generation state.
1092  */
1093 struct gl_texgen
1094 {
1095    GLenum Mode;         /**< GL_EYE_LINEAR, GL_SPHERE_MAP, etc */
1096    GLbitfield _ModeBit; /**< TEXGEN_x bit corresponding to Mode */
1097    GLfloat ObjectPlane[4];
1098    GLfloat EyePlane[4];
1099 };
1100
1101
1102 /**
1103  * Texture unit state.  Contains enable flags, texture environment/function/
1104  * combiners, texgen state, and pointers to current texture objects.
1105  */
1106 struct gl_texture_unit
1107 {
1108    GLbitfield Enabled;          /**< bitmask of TEXTURE_*_BIT flags */
1109
1110    GLenum EnvMode;              /**< GL_MODULATE, GL_DECAL, GL_BLEND, etc. */
1111    GLclampf EnvColor[4];
1112    GLfloat EnvColorUnclamped[4];
1113
1114    struct gl_texgen GenS;
1115    struct gl_texgen GenT;
1116    struct gl_texgen GenR;
1117    struct gl_texgen GenQ;
1118    GLbitfield TexGenEnabled;    /**< Bitwise-OR of [STRQ]_BIT values */
1119    GLbitfield _GenFlags;        /**< Bitwise-OR of Gen[STRQ]._ModeBit */
1120
1121    GLfloat LodBias;             /**< for biasing mipmap levels */
1122
1123    /** Texture targets that have a non-default texture bound */
1124    GLbitfield _BoundTextures;
1125
1126    /** Current sampler object (GL_ARB_sampler_objects) */
1127    struct gl_sampler_object *Sampler;
1128
1129    /** 
1130     * \name GL_EXT_texture_env_combine 
1131     */
1132    struct gl_tex_env_combine_state Combine;
1133
1134    /**
1135     * Derived state based on \c EnvMode and the \c BaseFormat of the
1136     * currently enabled texture.
1137     */
1138    struct gl_tex_env_combine_state _EnvMode;
1139
1140    /**
1141     * Currently enabled combiner state.  This will point to either
1142     * \c Combine or \c _EnvMode.
1143     */
1144    struct gl_tex_env_combine_state *_CurrentCombine;
1145
1146    /** Current texture object pointers */
1147    struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
1148
1149    /** Points to highest priority, complete and enabled texture object */
1150    struct gl_texture_object *_Current;
1151
1152 };
1153
1154
1155 /**
1156  * Texture attribute group (GL_TEXTURE_BIT).
1157  */
1158 struct gl_texture_attrib
1159 {
1160    GLuint CurrentUnit;   /**< GL_ACTIVE_TEXTURE */
1161
1162    /** GL_ARB_seamless_cubemap */
1163    GLboolean CubeMapSeamless;
1164
1165    struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
1166
1167    /** GL_ARB_texture_buffer_object */
1168    struct gl_buffer_object *BufferObject;
1169
1170    /** Texture coord units/sets used for fragment texturing */
1171    GLbitfield _EnabledCoordUnits;
1172
1173    /** Texture coord units that have texgen enabled */
1174    GLbitfield _TexGenEnabled;
1175
1176    /** Texture coord units that have non-identity matrices */
1177    GLbitfield _TexMatEnabled;
1178
1179    /** Bitwise-OR of all Texture.Unit[i]._GenFlags */
1180    GLbitfield _GenFlags;
1181
1182    /** Largest index of a texture unit with _Current != NULL. */
1183    GLint _MaxEnabledTexImageUnit;
1184
1185    /** Largest index + 1 of texture units that have had any CurrentTex set. */
1186    GLint NumCurrentTexUsed;
1187
1188    struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
1189 };
1190
1191
1192 /**
1193  * Data structure representing a single clip plane (e.g. one of the elements
1194  * of the ctx->Transform.EyeUserPlane or ctx->Transform._ClipUserPlane array).
1195  */
1196 typedef GLfloat gl_clip_plane[4];
1197
1198
1199 /**
1200  * Transformation attribute group (GL_TRANSFORM_BIT).
1201  */
1202 struct gl_transform_attrib
1203 {
1204    GLenum MatrixMode;                           /**< Matrix mode */
1205    gl_clip_plane EyeUserPlane[MAX_CLIP_PLANES]; /**< User clip planes */
1206    gl_clip_plane _ClipUserPlane[MAX_CLIP_PLANES]; /**< derived */
1207    GLbitfield ClipPlanesEnabled;                /**< on/off bitmask */
1208    GLboolean Normalize;                         /**< Normalize all normals? */
1209    GLboolean RescaleNormals;                    /**< GL_EXT_rescale_normal */
1210    GLboolean RasterPositionUnclipped;           /**< GL_IBM_rasterpos_clip */
1211    GLboolean DepthClamp;                        /**< GL_ARB_depth_clamp */
1212    /** GL_ARB_clip_control */
1213    GLenum ClipOrigin;     /**< GL_LOWER_LEFT or GL_UPPER_LEFT */
1214    GLenum ClipDepthMode;  /**< GL_NEGATIVE_ONE_TO_ONE or GL_ZERO_TO_ONE */
1215 };
1216
1217
1218 /**
1219  * Viewport attribute group (GL_VIEWPORT_BIT).
1220  */
1221 struct gl_viewport_attrib
1222 {
1223    GLfloat X, Y;                /**< position */
1224    GLfloat Width, Height;       /**< size */
1225    GLdouble Near, Far;          /**< Depth buffer range */
1226 };
1227
1228
1229 typedef enum {
1230    MAP_USER,
1231    MAP_INTERNAL,
1232
1233    MAP_COUNT
1234 } gl_map_buffer_index;
1235
1236
1237 /**
1238  * Fields describing a mapped buffer range.
1239  */
1240 struct gl_buffer_mapping {
1241    GLbitfield AccessFlags; /**< Mask of GL_MAP_x_BIT flags */
1242    GLvoid *Pointer;     /**< User-space address of mapping */
1243    GLintptr Offset;     /**< Mapped offset */
1244    GLsizeiptr Length;   /**< Mapped length */
1245 };
1246
1247
1248 /**
1249  * Usages we've seen for a buffer object.
1250  */
1251 typedef enum {
1252    USAGE_UNIFORM_BUFFER = 0x1,
1253    USAGE_TEXTURE_BUFFER = 0x2,
1254    USAGE_ATOMIC_COUNTER_BUFFER = 0x4,
1255    USAGE_SHADER_STORAGE_BUFFER = 0x8,
1256 } gl_buffer_usage;
1257
1258
1259 /**
1260  * GL_ARB_vertex/pixel_buffer_object buffer object
1261  */
1262 struct gl_buffer_object
1263 {
1264    mtx_t Mutex;
1265    GLint RefCount;
1266    GLuint Name;
1267    GLchar *Label;       /**< GL_KHR_debug */
1268    GLenum Usage;        /**< GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, etc. */
1269    GLbitfield StorageFlags; /**< GL_MAP_PERSISTENT_BIT, etc. */
1270    GLsizeiptrARB Size;  /**< Size of buffer storage in bytes */
1271    GLubyte *Data;       /**< Location of storage either in RAM or VRAM. */
1272    GLboolean DeletePending;   /**< true if buffer object is removed from the hash */
1273    GLboolean Written;   /**< Ever written to? (for debugging) */
1274    GLboolean Purgeable; /**< Is the buffer purgeable under memory pressure? */
1275    GLboolean Immutable; /**< GL_ARB_buffer_storage */
1276    gl_buffer_usage UsageHistory; /**< How has this buffer been used so far? */
1277
1278    /** Counters used for buffer usage warnings */
1279    GLuint NumSubDataCalls;
1280    GLuint NumMapBufferWriteCalls;
1281
1282    struct gl_buffer_mapping Mappings[MAP_COUNT];
1283 };
1284
1285
1286 /**
1287  * Client pixel packing/unpacking attributes
1288  */
1289 struct gl_pixelstore_attrib
1290 {
1291    GLint Alignment;
1292    GLint RowLength;
1293    GLint SkipPixels;
1294    GLint SkipRows;
1295    GLint ImageHeight;
1296    GLint SkipImages;
1297    GLboolean SwapBytes;
1298    GLboolean LsbFirst;
1299    GLboolean Invert;        /**< GL_MESA_pack_invert */
1300    GLint CompressedBlockWidth;   /**< GL_ARB_compressed_texture_pixel_storage */
1301    GLint CompressedBlockHeight;
1302    GLint CompressedBlockDepth;
1303    GLint CompressedBlockSize;
1304    struct gl_buffer_object *BufferObj; /**< GL_ARB_pixel_buffer_object */
1305 };
1306
1307
1308 /**
1309  * Client vertex array attributes
1310  */
1311 struct gl_client_array
1312 {
1313    GLint Size;                  /**< components per element (1,2,3,4) */
1314    GLenum Type;                 /**< datatype: GL_FLOAT, GL_INT, etc */
1315    GLenum Format;               /**< default: GL_RGBA, but may be GL_BGRA */
1316    GLsizei Stride;              /**< user-specified stride */
1317    GLsizei StrideB;             /**< actual stride in bytes */
1318    GLuint _ElementSize;         /**< size of each element in bytes */
1319    const GLubyte *Ptr;          /**< Points to array data */
1320    GLboolean Enabled;           /**< Enabled flag is a boolean */
1321    GLboolean Normalized;        /**< GL_ARB_vertex_program */
1322    GLboolean Integer;           /**< Integer-valued? */
1323    GLboolean Doubles;       /**< double precision values are not converted to floats */
1324    GLuint InstanceDivisor;      /**< GL_ARB_instanced_arrays */
1325
1326    struct gl_buffer_object *BufferObj;/**< GL_ARB_vertex_buffer_object */
1327 };
1328
1329
1330 /**
1331  * Vertex attribute array as seen by the client.
1332  *
1333  * Contains the size, type, format and normalization flag,
1334  * along with the index of a vertex buffer binding point.
1335  *
1336  * Note that the Stride field corresponds to VERTEX_ATTRIB_ARRAY_STRIDE
1337  * and is only present for backwards compatibility reasons.
1338  * Rendering always uses VERTEX_BINDING_STRIDE.
1339  * The gl*Pointer() functions will set VERTEX_ATTRIB_ARRAY_STRIDE
1340  * and VERTEX_BINDING_STRIDE to the same value, while
1341  * glBindVertexBuffer() will only set VERTEX_BINDING_STRIDE.
1342  */
1343 struct gl_vertex_attrib_array
1344 {
1345    GLint Size;              /**< Components per element (1,2,3,4) */
1346    GLenum Type;             /**< Datatype: GL_FLOAT, GL_INT, etc */
1347    GLenum Format;           /**< Default: GL_RGBA, but may be GL_BGRA */
1348    GLsizei Stride;          /**< Stride as specified with gl*Pointer() */
1349    const GLubyte *Ptr;      /**< Points to client array data. Not used when a VBO is bound */
1350    GLintptr RelativeOffset; /**< Offset of the first element relative to the binding offset */
1351    GLboolean Enabled;       /**< Whether the array is enabled */
1352    GLboolean Normalized;    /**< Fixed-point values are normalized when converted to floats */
1353    GLboolean Integer;       /**< Fixed-point values are not converted to floats */
1354    GLboolean Doubles;       /**< double precision values are not converted to floats */
1355    GLuint _ElementSize;     /**< Size of each element in bytes */
1356    GLuint VertexBinding;    /**< Vertex buffer binding */
1357 };
1358
1359
1360 /**
1361  * This describes the buffer object used for a vertex array (or
1362  * multiple vertex arrays).  If BufferObj points to the default/null
1363  * buffer object, then the vertex array lives in user memory and not a VBO.
1364  */
1365 struct gl_vertex_buffer_binding
1366 {
1367    GLintptr Offset;                    /**< User-specified offset */
1368    GLsizei Stride;                     /**< User-specified stride */
1369    GLuint InstanceDivisor;             /**< GL_ARB_instanced_arrays */
1370    struct gl_buffer_object *BufferObj; /**< GL_ARB_vertex_buffer_object */
1371    GLbitfield64 _BoundArrays;          /**< Arrays bound to this binding point */
1372 };
1373
1374
1375 /**
1376  * A representation of "Vertex Array Objects" (VAOs) from OpenGL 3.1+,
1377  * GL_ARB_vertex_array_object, or the original GL_APPLE_vertex_array_object
1378  * extension.
1379  */
1380 struct gl_vertex_array_object
1381 {
1382    /** Name of the VAO as received from glGenVertexArray. */
1383    GLuint Name;
1384
1385    GLint RefCount;
1386
1387    GLchar *Label;       /**< GL_KHR_debug */
1388
1389    mtx_t Mutex;
1390
1391    /**
1392     * Does the VAO use ARB semantics or Apple semantics?
1393     *
1394     * There are several ways in which ARB_vertex_array_object and
1395     * APPLE_vertex_array_object VAOs have differing semantics.  At the very
1396     * least,
1397     *
1398     *     - ARB VAOs require that all array data be sourced from vertex buffer
1399     *       objects, but Apple VAOs do not.
1400     *
1401     *     - ARB VAOs require that names come from GenVertexArrays.
1402     *
1403     * This flag notes which behavior governs this VAO.
1404     */
1405    GLboolean ARBsemantics;
1406
1407    /**
1408     * Has this array object been bound?
1409     */
1410    GLboolean EverBound;
1411
1412    /**
1413     * Derived vertex attribute arrays
1414     *
1415     * This is a legacy data structure created from gl_vertex_attrib_array and
1416     * gl_vertex_buffer_binding, for compatibility with existing driver code.
1417     */
1418    struct gl_client_array _VertexAttrib[VERT_ATTRIB_MAX];
1419
1420    /** Vertex attribute arrays */
1421    struct gl_vertex_attrib_array VertexAttrib[VERT_ATTRIB_MAX];
1422
1423    /** Vertex buffer bindings */
1424    struct gl_vertex_buffer_binding VertexBinding[VERT_ATTRIB_MAX];
1425
1426    /** Mask indicating which vertex arrays have vertex buffer associated. */
1427    GLbitfield64 VertexAttribBufferMask;
1428
1429    /** Mask of VERT_BIT_* values indicating which arrays are enabled */
1430    GLbitfield64 _Enabled;
1431
1432    /** Mask of VERT_BIT_* values indicating changed/dirty arrays */
1433    GLbitfield64 NewArrays;
1434
1435    /** The index buffer (also known as the element array buffer in OpenGL). */
1436    struct gl_buffer_object *IndexBufferObj;
1437 };
1438
1439
1440 /** Used to signal when transitioning from one kind of drawing method
1441  * to another.
1442  */
1443 typedef enum {
1444    DRAW_NONE,          /**< Initial value only */
1445    DRAW_BEGIN_END,
1446    DRAW_DISPLAY_LIST,
1447    DRAW_ARRAYS
1448 } gl_draw_method;
1449
1450 /**
1451  * Enum for the OpenGL APIs we know about and may support.
1452  *
1453  * NOTE: This must match the api_enum table in
1454  * src/mesa/main/get_hash_generator.py
1455  */
1456 typedef enum
1457 {
1458    API_OPENGL_COMPAT,      /* legacy / compatibility contexts */
1459    API_OPENGLES,
1460    API_OPENGLES2,
1461    API_OPENGL_CORE,
1462    API_OPENGL_LAST = API_OPENGL_CORE
1463 } gl_api;
1464
1465 /**
1466  * Vertex array state
1467  */
1468 struct gl_array_attrib
1469 {
1470    /** Currently bound array object. See _mesa_BindVertexArrayAPPLE() */
1471    struct gl_vertex_array_object *VAO;
1472
1473    /** The default vertex array object */
1474    struct gl_vertex_array_object *DefaultVAO;
1475
1476    /** The last VAO accessed by a DSA function */
1477    struct gl_vertex_array_object *LastLookedUpVAO;
1478
1479    /** Array objects (GL_ARB/APPLE_vertex_array_object) */
1480    struct _mesa_HashTable *Objects;
1481
1482    GLint ActiveTexture;         /**< Client Active Texture */
1483    GLuint LockFirst;            /**< GL_EXT_compiled_vertex_array */
1484    GLuint LockCount;            /**< GL_EXT_compiled_vertex_array */
1485
1486    /**
1487     * \name Primitive restart controls
1488     *
1489     * Primitive restart is enabled if either \c PrimitiveRestart or
1490     * \c PrimitiveRestartFixedIndex is set.
1491     */
1492    /*@{*/
1493    GLboolean PrimitiveRestart;
1494    GLboolean PrimitiveRestartFixedIndex;
1495    GLboolean _PrimitiveRestart;
1496    GLuint RestartIndex;
1497    /*@}*/
1498
1499    /** One of the DRAW_xxx flags, not consumed by drivers */
1500    gl_draw_method DrawMethod;
1501
1502    /* GL_ARB_vertex_buffer_object */
1503    struct gl_buffer_object *ArrayBufferObj;
1504
1505    /**
1506     * Vertex arrays as consumed by a driver.
1507     * The array pointer is set up only by the VBO module.
1508     */
1509    const struct gl_client_array **_DrawArrays; /**< 0..VERT_ATTRIB_MAX-1 */
1510
1511    /** Legal array datatypes and the API for which they have been computed */
1512    GLbitfield LegalTypesMask;
1513    gl_api LegalTypesMaskAPI;
1514 };
1515
1516
1517 /**
1518  * Feedback buffer state
1519  */
1520 struct gl_feedback
1521 {
1522    GLenum Type;
1523    GLbitfield _Mask;    /**< FB_* bits */
1524    GLfloat *Buffer;
1525    GLuint BufferSize;
1526    GLuint Count;
1527 };
1528
1529
1530 /**
1531  * Selection buffer state
1532  */
1533 struct gl_selection
1534 {
1535    GLuint *Buffer;      /**< selection buffer */
1536    GLuint BufferSize;   /**< size of the selection buffer */
1537    GLuint BufferCount;  /**< number of values in the selection buffer */
1538    GLuint Hits;         /**< number of records in the selection buffer */
1539    GLuint NameStackDepth; /**< name stack depth */
1540    GLuint NameStack[MAX_NAME_STACK_DEPTH]; /**< name stack */
1541    GLboolean HitFlag;   /**< hit flag */
1542    GLfloat HitMinZ;     /**< minimum hit depth */
1543    GLfloat HitMaxZ;     /**< maximum hit depth */
1544 };
1545
1546
1547 /**
1548  * 1-D Evaluator control points
1549  */
1550 struct gl_1d_map
1551 {
1552    GLuint Order;        /**< Number of control points */
1553    GLfloat u1, u2, du;  /**< u1, u2, 1.0/(u2-u1) */
1554    GLfloat *Points;     /**< Points to contiguous control points */
1555 };
1556
1557
1558 /**
1559  * 2-D Evaluator control points
1560  */
1561 struct gl_2d_map
1562 {
1563    GLuint Uorder;               /**< Number of control points in U dimension */
1564    GLuint Vorder;               /**< Number of control points in V dimension */
1565    GLfloat u1, u2, du;
1566    GLfloat v1, v2, dv;
1567    GLfloat *Points;             /**< Points to contiguous control points */
1568 };
1569
1570
1571 /**
1572  * All evaluator control point state
1573  */
1574 struct gl_evaluators
1575 {
1576    /** 
1577     * \name 1-D maps
1578     */
1579    /*@{*/
1580    struct gl_1d_map Map1Vertex3;
1581    struct gl_1d_map Map1Vertex4;
1582    struct gl_1d_map Map1Index;
1583    struct gl_1d_map Map1Color4;
1584    struct gl_1d_map Map1Normal;
1585    struct gl_1d_map Map1Texture1;
1586    struct gl_1d_map Map1Texture2;
1587    struct gl_1d_map Map1Texture3;
1588    struct gl_1d_map Map1Texture4;
1589    /*@}*/
1590
1591    /** 
1592     * \name 2-D maps 
1593     */
1594    /*@{*/
1595    struct gl_2d_map Map2Vertex3;
1596    struct gl_2d_map Map2Vertex4;
1597    struct gl_2d_map Map2Index;
1598    struct gl_2d_map Map2Color4;
1599    struct gl_2d_map Map2Normal;
1600    struct gl_2d_map Map2Texture1;
1601    struct gl_2d_map Map2Texture2;
1602    struct gl_2d_map Map2Texture3;
1603    struct gl_2d_map Map2Texture4;
1604    /*@}*/
1605 };
1606
1607
1608 struct gl_transform_feedback_varying_info
1609 {
1610    char *Name;
1611    GLenum Type;
1612    GLint Size;
1613 };
1614
1615
1616 /**
1617  * Per-output info vertex shaders for transform feedback.
1618  */
1619 struct gl_transform_feedback_output
1620 {
1621    unsigned OutputRegister;
1622    unsigned OutputBuffer;
1623    unsigned NumComponents;
1624    unsigned StreamId;
1625
1626    /** offset (in DWORDs) of this output within the interleaved structure */
1627    unsigned DstOffset;
1628
1629    /**
1630     * Offset into the output register of the data to output.  For example,
1631     * if NumComponents is 2 and ComponentOffset is 1, then the data to
1632     * offset is in the y and z components of the output register.
1633     */
1634    unsigned ComponentOffset;
1635 };
1636
1637
1638 /** Post-link transform feedback info. */
1639 struct gl_transform_feedback_info
1640 {
1641    unsigned NumOutputs;
1642
1643    /**
1644     * Number of transform feedback buffers in use by this program.
1645     */
1646    unsigned NumBuffers;
1647
1648    struct gl_transform_feedback_output *Outputs;
1649
1650    /** Transform feedback varyings used for the linking of this shader program.
1651     *
1652     * Use for glGetTransformFeedbackVarying().
1653     */
1654    struct gl_transform_feedback_varying_info *Varyings;
1655    GLint NumVarying;
1656
1657    /**
1658     * Total number of components stored in each buffer.  This may be used by
1659     * hardware back-ends to determine the correct stride when interleaving
1660     * multiple transform feedback outputs in the same buffer.
1661     */
1662    unsigned BufferStride[MAX_FEEDBACK_BUFFERS];
1663
1664    /**
1665     * Which transform feedback stream this buffer binding is associated with.
1666     */
1667    unsigned BufferStream[MAX_FEEDBACK_BUFFERS];
1668 };
1669
1670
1671 /**
1672  * Transform feedback object state
1673  */
1674 struct gl_transform_feedback_object
1675 {
1676    GLuint Name;  /**< AKA the object ID */
1677    GLint RefCount;
1678    GLchar *Label;     /**< GL_KHR_debug */
1679    GLboolean Active;  /**< Is transform feedback enabled? */
1680    GLboolean Paused;  /**< Is transform feedback paused? */
1681    GLboolean EndedAnytime; /**< Has EndTransformFeedback been called
1682                                 at least once? */
1683    GLboolean EverBound; /**< Has this object been bound? */
1684
1685    /**
1686     * GLES: if Active is true, remaining number of primitives which can be
1687     * rendered without overflow.  This is necessary to track because GLES
1688     * requires us to generate INVALID_OPERATION if a call to glDrawArrays or
1689     * glDrawArraysInstanced would overflow transform feedback buffers.
1690     * Undefined if Active is false.
1691     *
1692     * Not tracked for desktop GL since it's unnecessary.
1693     */
1694    unsigned GlesRemainingPrims;
1695
1696    /**
1697     * The shader program active when BeginTransformFeedback() was called.
1698     * When active and unpaused, this equals ctx->Shader.CurrentProgram[stage],
1699     * where stage is the pipeline stage that is the source of data for
1700     * transform feedback.
1701     */
1702    struct gl_shader_program *shader_program;
1703
1704    /** The feedback buffers */
1705    GLuint BufferNames[MAX_FEEDBACK_BUFFERS];
1706    struct gl_buffer_object *Buffers[MAX_FEEDBACK_BUFFERS];
1707
1708    /** Start of feedback data in dest buffer */
1709    GLintptr Offset[MAX_FEEDBACK_BUFFERS];
1710
1711    /**
1712     * Max data to put into dest buffer (in bytes).  Computed based on
1713     * RequestedSize and the actual size of the buffer.
1714     */
1715    GLsizeiptr Size[MAX_FEEDBACK_BUFFERS];
1716
1717    /**
1718     * Size that was specified when the buffer was bound.  If the buffer was
1719     * bound with glBindBufferBase() or glBindBufferOffsetEXT(), this value is
1720     * zero.
1721     */
1722    GLsizeiptr RequestedSize[MAX_FEEDBACK_BUFFERS];
1723 };
1724
1725
1726 /**
1727  * Context state for transform feedback.
1728  */
1729 struct gl_transform_feedback_state
1730 {
1731    GLenum Mode;       /**< GL_POINTS, GL_LINES or GL_TRIANGLES */
1732
1733    /** The general binding point (GL_TRANSFORM_FEEDBACK_BUFFER) */
1734    struct gl_buffer_object *CurrentBuffer;
1735
1736    /** The table of all transform feedback objects */
1737    struct _mesa_HashTable *Objects;
1738
1739    /** The current xform-fb object (GL_TRANSFORM_FEEDBACK_BINDING) */
1740    struct gl_transform_feedback_object *CurrentObject;
1741
1742    /** The default xform-fb object (Name==0) */
1743    struct gl_transform_feedback_object *DefaultObject;
1744 };
1745
1746
1747 /**
1748  * A "performance monitor" as described in AMD_performance_monitor.
1749  */
1750 struct gl_perf_monitor_object
1751 {
1752    GLuint Name;
1753
1754    /** True if the monitor is currently active (Begin called but not End). */
1755    GLboolean Active;
1756
1757    /**
1758     * True if the monitor has ended.
1759     *
1760     * This is distinct from !Active because it may never have began.
1761     */
1762    GLboolean Ended;
1763
1764    /**
1765     * A list of groups with currently active counters.
1766     *
1767     * ActiveGroups[g] == n if there are n counters active from group 'g'.
1768     */
1769    unsigned *ActiveGroups;
1770
1771    /**
1772     * An array of bitsets, subscripted by group ID, then indexed by counter ID.
1773     *
1774     * Checking whether counter 'c' in group 'g' is active can be done via:
1775     *
1776     *    BITSET_TEST(ActiveCounters[g], c)
1777     */
1778    GLuint **ActiveCounters;
1779 };
1780
1781
1782 union gl_perf_monitor_counter_value
1783 {
1784    float f;
1785    uint64_t u64;
1786    uint32_t u32;
1787 };
1788
1789
1790 struct gl_perf_monitor_counter
1791 {
1792    /** Human readable name for the counter. */
1793    const char *Name;
1794
1795    /**
1796     * Data type of the counter.  Valid values are FLOAT, UNSIGNED_INT,
1797     * UNSIGNED_INT64_AMD, and PERCENTAGE_AMD.
1798     */
1799    GLenum Type;
1800
1801    /** Minimum counter value. */
1802    union gl_perf_monitor_counter_value Minimum;
1803
1804    /** Maximum counter value. */
1805    union gl_perf_monitor_counter_value Maximum;
1806 };
1807
1808
1809 struct gl_perf_monitor_group
1810 {
1811    /** Human readable name for the group. */
1812    const char *Name;
1813
1814    /**
1815     * Maximum number of counters in this group which can be active at the
1816     * same time.
1817     */
1818    GLuint MaxActiveCounters;
1819
1820    /** Array of counters within this group. */
1821    const struct gl_perf_monitor_counter *Counters;
1822    GLuint NumCounters;
1823 };
1824
1825
1826 /**
1827  * Context state for AMD_performance_monitor.
1828  */
1829 struct gl_perf_monitor_state
1830 {
1831    /** Array of performance monitor groups (indexed by group ID) */
1832    const struct gl_perf_monitor_group *Groups;
1833    GLuint NumGroups;
1834
1835    /** The table of all performance monitors. */
1836    struct _mesa_HashTable *Monitors;
1837 };
1838
1839
1840 /**
1841  * Names of the various vertex/fragment program register files, etc.
1842  *
1843  * NOTE: first four tokens must fit into 2 bits (see t_vb_arbprogram.c)
1844  * All values should fit in a 4-bit field.
1845  *
1846  * NOTE: PROGRAM_STATE_VAR, PROGRAM_CONSTANT, and PROGRAM_UNIFORM can all be
1847  * considered to be "uniform" variables since they can only be set outside
1848  * glBegin/End.  They're also all stored in the same Parameters array.
1849  */
1850 typedef enum
1851 {
1852    PROGRAM_TEMPORARY,   /**< machine->Temporary[] */
1853    PROGRAM_ARRAY,       /**< Arrays & Matrixes */
1854    PROGRAM_INPUT,       /**< machine->Inputs[] */
1855    PROGRAM_OUTPUT,      /**< machine->Outputs[] */
1856    PROGRAM_STATE_VAR,   /**< gl_program->Parameters[] */
1857    PROGRAM_CONSTANT,    /**< gl_program->Parameters[] */
1858    PROGRAM_UNIFORM,     /**< gl_program->Parameters[] */
1859    PROGRAM_WRITE_ONLY,  /**< A dummy, write-only register */
1860    PROGRAM_ADDRESS,     /**< machine->AddressReg */
1861    PROGRAM_SAMPLER,     /**< for shader samplers, compile-time only */
1862    PROGRAM_SYSTEM_VALUE,/**< InstanceId, PrimitiveID, etc. */
1863    PROGRAM_UNDEFINED,   /**< Invalid/TBD value */
1864    PROGRAM_FILE_MAX
1865 } gl_register_file;
1866
1867
1868 /**
1869  * Base class for any kind of program object
1870  */
1871 struct gl_program
1872 {
1873    mtx_t Mutex;
1874    GLuint Id;
1875    GLint RefCount;
1876    GLubyte *String;  /**< Null-terminated program text */
1877
1878    GLenum Target;    /**< GL_VERTEX/FRAGMENT_PROGRAM_ARB, GL_GEOMETRY_PROGRAM_NV */
1879    GLenum Format;    /**< String encoding format */
1880
1881    struct prog_instruction *Instructions;
1882
1883    struct nir_shader *nir;
1884
1885    GLbitfield64 InputsRead;     /**< Bitmask of which input regs are read */
1886    GLbitfield64 DoubleInputsRead;     /**< Bitmask of which input regs are read  and are doubles */
1887    GLbitfield64 OutputsWritten; /**< Bitmask of which output regs are written */
1888    GLbitfield PatchInputsRead;  /**< VAR[0..31] usage for patch inputs (user-defined only) */
1889    GLbitfield PatchOutputsWritten; /**< VAR[0..31] usage for patch outputs (user-defined only) */
1890    GLbitfield SystemValuesRead;   /**< Bitmask of SYSTEM_VALUE_x inputs used */
1891    GLbitfield TexturesUsed[MAX_COMBINED_TEXTURE_IMAGE_UNITS];  /**< TEXTURE_x_BIT bitmask */
1892    GLbitfield SamplersUsed;   /**< Bitfield of which samplers are used */
1893    GLbitfield ShadowSamplers; /**< Texture units used for shadow sampling. */
1894
1895    GLboolean UsesGather; /**< Does this program use gather4 at all? */
1896
1897    /**
1898     * For vertex and geometry shaders, true if the program uses the
1899     * gl_ClipDistance output.  Ignored for fragment shaders.
1900     */
1901    unsigned ClipDistanceArraySize;
1902
1903
1904    /** Named parameters, constants, etc. from program text */
1905    struct gl_program_parameter_list *Parameters;
1906
1907    /**
1908     * Local parameters used by the program.
1909     *
1910     * It's dynamically allocated because it is rarely used (just
1911     * assembly-style programs), and MAX_PROGRAM_LOCAL_PARAMS entries once it's
1912     * allocated.
1913     */
1914    GLfloat (*LocalParams)[4];
1915
1916    /** Map from sampler unit to texture unit (set by glUniform1i()) */
1917    GLubyte SamplerUnits[MAX_SAMPLERS];
1918
1919    /** Bitmask of which register files are read/written with indirect
1920     * addressing.  Mask of (1 << PROGRAM_x) bits.
1921     */
1922    GLbitfield IndirectRegisterFiles;
1923
1924    /** Logical counts */
1925    /*@{*/
1926    GLuint NumInstructions;
1927    GLuint NumTemporaries;
1928    GLuint NumParameters;
1929    GLuint NumAttributes;
1930    GLuint NumAddressRegs;
1931    GLuint NumAluInstructions;
1932    GLuint NumTexInstructions;
1933    GLuint NumTexIndirections;
1934    /*@}*/
1935    /** Native, actual h/w counts */
1936    /*@{*/
1937    GLuint NumNativeInstructions;
1938    GLuint NumNativeTemporaries;
1939    GLuint NumNativeParameters;
1940    GLuint NumNativeAttributes;
1941    GLuint NumNativeAddressRegs;
1942    GLuint NumNativeAluInstructions;
1943    GLuint NumNativeTexInstructions;
1944    GLuint NumNativeTexIndirections;
1945    /*@}*/
1946 };
1947
1948
1949 /** Vertex program object */
1950 struct gl_vertex_program
1951 {
1952    struct gl_program Base;   /**< base class */
1953    GLboolean IsPositionInvariant;
1954 };
1955
1956
1957 /** Tessellation control program object */
1958 struct gl_tess_ctrl_program
1959 {
1960    struct gl_program Base;   /**< base class */
1961
1962    /* output layout */
1963    GLint VerticesOut;
1964 };
1965
1966
1967 /** Tessellation evaluation program object */
1968 struct gl_tess_eval_program
1969 {
1970    struct gl_program Base;   /**< base class */
1971
1972    /* input layout */
1973    GLenum PrimitiveMode; /* GL_TRIANGLES, GL_QUADS or GL_ISOLINES */
1974    GLenum Spacing;       /* GL_EQUAL, GL_FRACTIONAL_EVEN, GL_FRACTIONAL_ODD */
1975    GLenum VertexOrder;   /* GL_CW or GL_CCW */
1976    bool PointMode;
1977 };
1978
1979
1980 /** Geometry program object */
1981 struct gl_geometry_program
1982 {
1983    struct gl_program Base;   /**< base class */
1984
1985    GLint VerticesIn;
1986    GLint VerticesOut;
1987    GLint Invocations;
1988    GLenum InputType;  /**< GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_ARB,
1989                            GL_TRIANGLES, or GL_TRIANGLES_ADJACENCY_ARB */
1990    GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
1991    bool UsesEndPrimitive;
1992    bool UsesStreams;
1993 };
1994
1995
1996 /** Fragment program object */
1997 struct gl_fragment_program
1998 {
1999    struct gl_program Base;   /**< base class */
2000    GLboolean UsesKill;          /**< shader uses KIL instruction */
2001    GLboolean UsesDFdy;          /**< shader uses DDY instruction */
2002    GLboolean OriginUpperLeft;
2003    GLboolean PixelCenterInteger;
2004    enum gl_frag_depth_layout FragDepthLayout;
2005
2006    /**
2007     * GLSL interpolation qualifier associated with each fragment shader input.
2008     * For inputs that do not have an interpolation qualifier specified in
2009     * GLSL, the value is INTERP_QUALIFIER_NONE.
2010     */
2011    enum glsl_interp_qualifier InterpQualifier[VARYING_SLOT_MAX];
2012
2013    /**
2014     * Bitfield indicating, for each fragment shader input, 1 if that input
2015     * uses centroid interpolation, 0 otherwise.  Unused inputs are 0.
2016     */
2017    GLbitfield64 IsCentroid;
2018
2019    /**
2020     * Bitfield indicating, for each fragment shader input, 1 if that input
2021     * uses sample interpolation, 0 otherwise.  Unused inputs are 0.
2022     */
2023    GLbitfield64 IsSample;
2024 };
2025
2026
2027 /** Compute program object */
2028 struct gl_compute_program
2029 {
2030    struct gl_program Base;   /**< base class */
2031
2032    /**
2033     * Size specified using local_size_{x,y,z}.
2034     */
2035    unsigned LocalSize[3];
2036 };
2037
2038
2039 /**
2040  * State common to vertex and fragment programs.
2041  */
2042 struct gl_program_state
2043 {
2044    GLint ErrorPos;                       /* GL_PROGRAM_ERROR_POSITION_ARB/NV */
2045    const char *ErrorString;              /* GL_PROGRAM_ERROR_STRING_ARB/NV */
2046 };
2047
2048
2049 /**
2050  * Context state for vertex programs.
2051  */
2052 struct gl_vertex_program_state
2053 {
2054    GLboolean Enabled;            /**< User-set GL_VERTEX_PROGRAM_ARB/NV flag */
2055    GLboolean _Enabled;           /**< Enabled and _valid_ user program? */
2056    GLboolean PointSizeEnabled;   /**< GL_VERTEX_PROGRAM_POINT_SIZE_ARB/NV */
2057    GLboolean TwoSideEnabled;     /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
2058    /** Computed two sided lighting for fixed function/programs. */
2059    GLboolean _TwoSideEnabled;
2060    struct gl_vertex_program *Current;  /**< User-bound vertex program */
2061
2062    /** Currently enabled and valid vertex program (including internal
2063     * programs, user-defined vertex programs and GLSL vertex shaders).
2064     * This is the program we must use when rendering.
2065     */
2066    struct gl_vertex_program *_Current;
2067
2068    GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
2069
2070    /** Should fixed-function T&L be implemented with a vertex prog? */
2071    GLboolean _MaintainTnlProgram;
2072
2073    /** Program to emulate fixed-function T&L (see above) */
2074    struct gl_vertex_program *_TnlProgram;
2075
2076    /** Cache of fixed-function programs */
2077    struct gl_program_cache *Cache;
2078
2079    GLboolean _Overriden;
2080 };
2081
2082 /**
2083  * Context state for tessellation control programs.
2084  */
2085 struct gl_tess_ctrl_program_state
2086 {
2087    /** Currently bound and valid shader. */
2088    struct gl_tess_ctrl_program *_Current;
2089
2090    GLint patch_vertices;
2091    GLfloat patch_default_outer_level[4];
2092    GLfloat patch_default_inner_level[2];
2093 };
2094
2095 /**
2096  * Context state for tessellation evaluation programs.
2097  */
2098 struct gl_tess_eval_program_state
2099 {
2100    /** Currently bound and valid shader. */
2101    struct gl_tess_eval_program *_Current;
2102 };
2103
2104 /**
2105  * Context state for geometry programs.
2106  */
2107 struct gl_geometry_program_state
2108 {
2109    /** Currently enabled and valid program (including internal programs
2110     * and compiled shader programs).
2111     */
2112    struct gl_geometry_program *_Current;
2113 };
2114
2115 /**
2116  * Context state for fragment programs.
2117  */
2118 struct gl_fragment_program_state
2119 {
2120    GLboolean Enabled;     /**< User-set fragment program enable flag */
2121    GLboolean _Enabled;    /**< Enabled and _valid_ user program? */
2122    struct gl_fragment_program *Current;  /**< User-bound fragment program */
2123
2124    /** Currently enabled and valid fragment program (including internal
2125     * programs, user-defined fragment programs and GLSL fragment shaders).
2126     * This is the program we must use when rendering.
2127     */
2128    struct gl_fragment_program *_Current;
2129
2130    GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
2131
2132    /** Should fixed-function texturing be implemented with a fragment prog? */
2133    GLboolean _MaintainTexEnvProgram;
2134
2135    /** Program to emulate fixed-function texture env/combine (see above) */
2136    struct gl_fragment_program *_TexEnvProgram;
2137
2138    /** Cache of fixed-function programs */
2139    struct gl_program_cache *Cache;
2140 };
2141
2142
2143 /**
2144  * Context state for compute programs.
2145  */
2146 struct gl_compute_program_state
2147 {
2148    /** Currently enabled and valid program (including internal programs
2149     * and compiled shader programs).
2150     */
2151    struct gl_compute_program *_Current;
2152 };
2153
2154
2155 /**
2156  * ATI_fragment_shader runtime state
2157  */
2158
2159 struct atifs_instruction;
2160 struct atifs_setupinst;
2161
2162 /**
2163  * ATI fragment shader
2164  */
2165 struct ati_fragment_shader
2166 {
2167    GLuint Id;
2168    GLint RefCount;
2169    struct atifs_instruction *Instructions[2];
2170    struct atifs_setupinst *SetupInst[2];
2171    GLfloat Constants[8][4];
2172    GLbitfield LocalConstDef;  /**< Indicates which constants have been set */
2173    GLubyte numArithInstr[2];
2174    GLubyte regsAssigned[2];
2175    GLubyte NumPasses;         /**< 1 or 2 */
2176    GLubyte cur_pass;
2177    GLubyte last_optype;
2178    GLboolean interpinp1;
2179    GLboolean isValid;
2180    GLuint swizzlerq;
2181 };
2182
2183 /**
2184  * Context state for GL_ATI_fragment_shader
2185  */
2186 struct gl_ati_fragment_shader_state
2187 {
2188    GLboolean Enabled;
2189    GLboolean _Enabled;                  /**< enabled and valid shader? */
2190    GLboolean Compiling;
2191    GLfloat GlobalConstants[8][4];
2192    struct ati_fragment_shader *Current;
2193 };
2194
2195 /**
2196  *  Shader subroutine function definition
2197  */
2198 struct gl_subroutine_function
2199 {
2200    char *name;
2201    int index;
2202    int num_compat_types;
2203    const struct glsl_type **types;
2204 };
2205
2206 /**
2207  * A GLSL vertex or fragment shader object.
2208  */
2209 struct gl_shader
2210 {
2211    /** GL_FRAGMENT_SHADER || GL_VERTEX_SHADER || GL_GEOMETRY_SHADER_ARB ||
2212     *  GL_TESS_CONTROL_SHADER || GL_TESS_EVALUATION_SHADER.
2213     * Must be the first field.
2214     */
2215    GLenum Type;
2216    gl_shader_stage Stage;
2217    GLuint Name;  /**< AKA the handle */
2218    GLint RefCount;  /**< Reference count */
2219    GLchar *Label;   /**< GL_KHR_debug */
2220    GLboolean DeletePending;
2221    GLboolean CompileStatus;
2222    bool IsES;              /**< True if this shader uses GLSL ES */
2223
2224    GLuint SourceChecksum;       /**< for debug/logging purposes */
2225    const GLchar *Source;  /**< Source code string */
2226
2227    struct gl_program *Program;  /**< Post-compile assembly code */
2228    GLchar *InfoLog;
2229
2230    unsigned Version;       /**< GLSL version used for linking */
2231
2232    /**
2233     * \name Sampler tracking
2234     *
2235     * \note Each of these fields is only set post-linking.
2236     */
2237    /*@{*/
2238    unsigned num_samplers;       /**< Number of samplers used by this shader. */
2239    GLbitfield active_samplers;  /**< Bitfield of which samplers are used */
2240    GLbitfield shadow_samplers;  /**< Samplers used for shadow sampling. */
2241    /*@}*/
2242
2243    /**
2244     * Map from sampler unit to texture unit (set by glUniform1i())
2245     *
2246     * A sampler unit is associated with each sampler uniform by the linker.
2247     * The sampler unit associated with each uniform is stored in the
2248     * \c gl_uniform_storage::sampler field.
2249     */
2250    GLubyte SamplerUnits[MAX_SAMPLERS];
2251    /** Which texture target is being sampled (TEXTURE_1D/2D/3D/etc_INDEX) */
2252    gl_texture_index SamplerTargets[MAX_SAMPLERS];
2253
2254    /**
2255     * Number of default uniform block components used by this shader.
2256     *
2257     * This field is only set post-linking.
2258     */
2259    unsigned num_uniform_components;
2260
2261    /**
2262     * Number of combined uniform components used by this shader.
2263     *
2264     * This field is only set post-linking.  It is the sum of the uniform block
2265     * sizes divided by sizeof(float), and num_uniform_compoennts.
2266     */
2267    unsigned num_combined_uniform_components;
2268
2269    /**
2270     * This shader's uniform/ssbo block information.
2271     *
2272     * These fields are only set post-linking.
2273     *
2274     * BufferInterfaceBlocks is a list containing both UBOs and SSBOs. This is
2275     * useful during the linking process so that we don't have to handle SSBOs
2276     * specifically.
2277     *
2278     * UniformBlocks is a list of UBOs. This is useful for backends that need
2279     * or prefer to see separate index spaces for UBOS and SSBOs like the GL
2280     * API specifies.
2281     *
2282     * ShaderStorageBlocks is a list of SSBOs. This is useful for backends that
2283     * need or prefer to see separate index spaces for UBOS and SSBOs like the
2284     * GL API specifies.
2285     *
2286     * UniformBlocks and ShaderStorageBlocks only have pointers into
2287     * BufferInterfaceBlocks so the actual resource information is not
2288     * duplicated.
2289     */
2290    unsigned NumBufferInterfaceBlocks;
2291    struct gl_uniform_block *BufferInterfaceBlocks;
2292
2293    unsigned NumUniformBlocks;
2294    struct gl_uniform_block **UniformBlocks;
2295
2296    unsigned NumShaderStorageBlocks;
2297    struct gl_uniform_block **ShaderStorageBlocks;
2298
2299    struct exec_list *ir;
2300    struct exec_list *packed_varyings;
2301    struct exec_list *fragdata_arrays;
2302    struct glsl_symbol_table *symbols;
2303
2304    bool uses_builtin_functions;
2305    bool uses_gl_fragcoord;
2306    bool redeclares_gl_fragcoord;
2307    bool ARB_fragment_coord_conventions_enable;
2308
2309    /**
2310     * Fragment shader state from GLSL 1.50 layout qualifiers.
2311     */
2312    bool origin_upper_left;
2313    bool pixel_center_integer;
2314
2315    /**
2316     * Tessellation Control shader state from layout qualifiers.
2317     */
2318    struct {
2319       /**
2320        * 0 - vertices not declared in shader, or
2321        * 1 .. GL_MAX_PATCH_VERTICES
2322        */
2323       GLint VerticesOut;
2324    } TessCtrl;
2325
2326    /**
2327     * Tessellation Evaluation shader state from layout qualifiers.
2328     */
2329    struct {
2330       /**
2331        * GL_TRIANGLES, GL_QUADS, GL_ISOLINES or PRIM_UNKNOWN if it's not set
2332        * in this shader.
2333        */
2334       GLenum PrimitiveMode;
2335       /**
2336        * GL_EQUAL, GL_FRACTIONAL_ODD, GL_FRACTIONAL_EVEN, or 0 if it's not set
2337        * in this shader.
2338        */
2339       GLenum Spacing;
2340       /**
2341        * GL_CW, GL_CCW, or 0 if it's not set in this shader.
2342        */
2343       GLenum VertexOrder;
2344       /**
2345        * 1, 0, or -1 if it's not set in this shader.
2346        */
2347       int PointMode;
2348    } TessEval;
2349
2350    /**
2351     * Geometry shader state from GLSL 1.50 layout qualifiers.
2352     */
2353    struct {
2354       GLint VerticesOut;
2355       /**
2356        * 0 - Invocations count not declared in shader, or
2357        * 1 .. MAX_GEOMETRY_SHADER_INVOCATIONS
2358        */
2359       GLint Invocations;
2360       /**
2361        * GL_POINTS, GL_LINES, GL_LINES_ADJACENCY, GL_TRIANGLES, or
2362        * GL_TRIANGLES_ADJACENCY, or PRIM_UNKNOWN if it's not set in this
2363        * shader.
2364        */
2365       GLenum InputType;
2366        /**
2367         * GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP, or PRIM_UNKNOWN if
2368         * it's not set in this shader.
2369         */
2370       GLenum OutputType;
2371    } Geom;
2372
2373    /**
2374     * Map from image uniform index to image unit (set by glUniform1i())
2375     *
2376     * An image uniform index is associated with each image uniform by
2377     * the linker.  The image index associated with each uniform is
2378     * stored in the \c gl_uniform_storage::image field.
2379     */
2380    GLubyte ImageUnits[MAX_IMAGE_UNIFORMS];
2381
2382    /**
2383     * Access qualifier specified in the shader for each image uniform
2384     * index.  Either \c GL_READ_ONLY, \c GL_WRITE_ONLY or \c
2385     * GL_READ_WRITE.
2386     *
2387     * It may be different, though only more strict than the value of
2388     * \c gl_image_unit::Access for the corresponding image unit.
2389     */
2390    GLenum ImageAccess[MAX_IMAGE_UNIFORMS];
2391
2392    /**
2393     * Number of image uniforms defined in the shader.  It specifies
2394     * the number of valid elements in the \c ImageUnits and \c
2395     * ImageAccess arrays above.
2396     */
2397    GLuint NumImages;
2398
2399    struct gl_active_atomic_buffer **AtomicBuffers;
2400    unsigned NumAtomicBuffers;
2401
2402    /**
2403     * Whether early fragment tests are enabled as defined by
2404     * ARB_shader_image_load_store.
2405     */
2406    bool EarlyFragmentTests;
2407
2408    /**
2409     * Compute shader state from ARB_compute_shader layout qualifiers.
2410     */
2411    struct {
2412       /**
2413        * Size specified using local_size_{x,y,z}, or all 0's to indicate that
2414        * it's not set in this shader.
2415        */
2416       unsigned LocalSize[3];
2417    } Comp;
2418
2419    /**
2420      * Number of types for subroutine uniforms.
2421      */
2422    GLuint NumSubroutineUniformTypes;
2423
2424    /**
2425      * Subroutine uniform remap table
2426      * based on the program level uniform remap table.
2427      */
2428    GLuint NumSubroutineUniformRemapTable;
2429    struct gl_uniform_storage **SubroutineUniformRemapTable;
2430
2431    /**
2432     * Num of subroutine functions for this stage
2433     * and storage for them.
2434     */
2435    GLuint NumSubroutineFunctions;
2436    struct gl_subroutine_function *SubroutineFunctions;
2437 };
2438
2439
2440 struct gl_uniform_buffer_variable
2441 {
2442    char *Name;
2443
2444    /**
2445     * Name of the uniform as seen by glGetUniformIndices.
2446     *
2447     * glGetUniformIndices requires that the block instance index \b not be
2448     * present in the name of queried uniforms.
2449     *
2450     * \note
2451     * \c gl_uniform_buffer_variable::IndexName and
2452     * \c gl_uniform_buffer_variable::Name may point to identical storage.
2453     */
2454    char *IndexName;
2455
2456    const struct glsl_type *Type;
2457    unsigned int Offset;
2458    GLboolean RowMajor;
2459 };
2460
2461
2462 enum gl_uniform_block_packing
2463 {
2464    ubo_packing_std140,
2465    ubo_packing_shared,
2466    ubo_packing_packed,
2467    ubo_packing_std430
2468 };
2469
2470
2471 struct gl_uniform_block
2472 {
2473    /** Declared name of the uniform block */
2474    char *Name;
2475
2476    /** Array of supplemental information about UBO ir_variables. */
2477    struct gl_uniform_buffer_variable *Uniforms;
2478    GLuint NumUniforms;
2479
2480    /**
2481     * Index (GL_UNIFORM_BLOCK_BINDING) into ctx->UniformBufferBindings[] to use
2482     * with glBindBufferBase to bind a buffer object to this uniform block.  When
2483     * updated in the program, _NEW_BUFFER_OBJECT will be set.
2484     */
2485    GLuint Binding;
2486
2487    /**
2488     * Vulkan descriptor set qualifier for this block.
2489     */
2490    GLuint Set;
2491
2492    /**
2493     * Minimum size (in bytes) of a buffer object to back this uniform buffer
2494     * (GL_UNIFORM_BLOCK_DATA_SIZE).
2495     */
2496    GLuint UniformBufferSize;
2497
2498    /**
2499     * Is this actually an interface block for a shader storage buffer?
2500     */
2501    bool IsShaderStorage;
2502
2503    /**
2504     * Layout specified in the shader
2505     *
2506     * This isn't accessible through the API, but it is used while
2507     * cross-validating uniform blocks.
2508     */
2509    enum gl_uniform_block_packing _Packing;
2510 };
2511
2512 /**
2513  * Structure that represents a reference to an atomic buffer from some
2514  * shader program.
2515  */
2516 struct gl_active_atomic_buffer
2517 {
2518    /** Uniform indices of the atomic counters declared within it. */
2519    GLuint *Uniforms;
2520    GLuint NumUniforms;
2521
2522    /** Binding point index associated with it. */
2523    GLuint Binding;
2524
2525    /** Minimum reasonable size it is expected to have. */
2526    GLuint MinimumSize;
2527
2528    /** Shader stages making use of it. */
2529    GLboolean StageReferences[MESA_SHADER_STAGES];
2530 };
2531
2532 /**
2533  * Data container for shader queries. This holds only the minimal
2534  * amount of required information for resource queries to work.
2535  */
2536 struct gl_shader_variable
2537 {
2538    /**
2539     * Declared type of the variable
2540     */
2541    const struct glsl_type *type;
2542
2543    /**
2544     * Declared name of the variable
2545     */
2546    char *name;
2547
2548    /**
2549     * Storage location of the base of this variable
2550     *
2551     * The precise meaning of this field depends on the nature of the variable.
2552     *
2553     *   - Vertex shader input: one of the values from \c gl_vert_attrib.
2554     *   - Vertex shader output: one of the values from \c gl_varying_slot.
2555     *   - Geometry shader input: one of the values from \c gl_varying_slot.
2556     *   - Geometry shader output: one of the values from \c gl_varying_slot.
2557     *   - Fragment shader input: one of the values from \c gl_varying_slot.
2558     *   - Fragment shader output: one of the values from \c gl_frag_result.
2559     *   - Uniforms: Per-stage uniform slot number for default uniform block.
2560     *   - Uniforms: Index within the uniform block definition for UBO members.
2561     *   - Non-UBO Uniforms: explicit location until linking then reused to
2562     *     store uniform slot number.
2563     *   - Other: This field is not currently used.
2564     *
2565     * If the variable is a uniform, shader input, or shader output, and the
2566     * slot has not been assigned, the value will be -1.
2567     */
2568    int location;
2569
2570    /**
2571     * Output index for dual source blending.
2572     *
2573     * \note
2574     * The GLSL spec only allows the values 0 or 1 for the index in \b dual
2575     * source blending.
2576     */
2577    unsigned index:1;
2578
2579    /**
2580     * Specifies whether a shader input/output is per-patch in tessellation
2581     * shader stages.
2582     */
2583    unsigned patch:1;
2584
2585    /**
2586     * Storage class of the variable.
2587     *
2588     * \sa (n)ir_variable_mode
2589     */
2590    unsigned mode:4;
2591 };
2592
2593 /**
2594  * Active resource in a gl_shader_program
2595  */
2596 struct gl_program_resource
2597 {
2598    GLenum Type; /** Program interface type. */
2599    const void *Data; /** Pointer to resource associated data structure. */
2600    uint8_t StageReferences; /** Bitmask of shader stage references. */
2601 };
2602
2603 /**
2604  * A GLSL program object.
2605  * Basically a linked collection of vertex and fragment shaders.
2606  */
2607 struct gl_shader_program
2608 {
2609    GLenum Type;  /**< Always GL_SHADER_PROGRAM (internal token) */
2610    GLuint Name;  /**< aka handle or ID */
2611    GLchar *Label;   /**< GL_KHR_debug */
2612    GLint RefCount;  /**< Reference count */
2613    GLboolean DeletePending;
2614
2615    /**
2616     * Is the application intending to glGetProgramBinary this program?
2617     */
2618    GLboolean BinaryRetreivableHint;
2619
2620    /**
2621     * Indicates whether program can be bound for individual pipeline stages
2622     * using UseProgramStages after it is next linked.
2623     */
2624    GLboolean SeparateShader;
2625
2626    GLuint NumShaders;          /**< number of attached shaders */
2627    struct gl_shader **Shaders; /**< List of attached the shaders */
2628
2629    /**
2630     * User-defined attribute bindings
2631     *
2632     * These are set via \c glBindAttribLocation and are used to direct the
2633     * GLSL linker.  These are \b not the values used in the compiled shader,
2634     * and they are \b not the values returned by \c glGetAttribLocation.
2635     */
2636    struct string_to_uint_map *AttributeBindings;
2637
2638    /**
2639     * User-defined fragment data bindings
2640     *
2641     * These are set via \c glBindFragDataLocation and are used to direct the
2642     * GLSL linker.  These are \b not the values used in the compiled shader,
2643     * and they are \b not the values returned by \c glGetFragDataLocation.
2644     */
2645    struct string_to_uint_map *FragDataBindings;
2646    struct string_to_uint_map *FragDataIndexBindings;
2647
2648    /**
2649     * Transform feedback varyings last specified by
2650     * glTransformFeedbackVaryings().
2651     *
2652     * For the current set of transform feedback varyings used for transform
2653     * feedback output, see LinkedTransformFeedback.
2654     */
2655    struct {
2656       GLenum BufferMode;
2657       GLuint NumVarying;
2658       GLchar **VaryingNames;  /**< Array [NumVarying] of char * */
2659    } TransformFeedback;
2660
2661    /** Post-link transform feedback info. */
2662    struct gl_transform_feedback_info LinkedTransformFeedback;
2663
2664    /** Post-link gl_FragDepth layout for ARB_conservative_depth. */
2665    enum gl_frag_depth_layout FragDepthLayout;
2666
2667    /**
2668     * Tessellation Control shader state from layout qualifiers.
2669     */
2670    struct {
2671       /**
2672        * 0 - vertices not declared in shader, or
2673        * 1 .. GL_MAX_PATCH_VERTICES
2674        */
2675       GLint VerticesOut;
2676    } TessCtrl;
2677
2678    /**
2679     * Tessellation Evaluation shader state from layout qualifiers.
2680     */
2681    struct {
2682       /** GL_TRIANGLES, GL_QUADS or GL_ISOLINES */
2683       GLenum PrimitiveMode;
2684       /** GL_EQUAL, GL_FRACTIONAL_ODD or GL_FRACTIONAL_EVEN */
2685       GLenum Spacing;
2686       /** GL_CW or GL_CCW */
2687       GLenum VertexOrder;
2688       bool PointMode;
2689       /**
2690        * True if gl_ClipDistance is written to.  Copied into
2691        * gl_tess_eval_program by _mesa_copy_linked_program_data().
2692        */
2693       GLuint ClipDistanceArraySize; /**< Size of the gl_ClipDistance array, or
2694                                          0 if not present. */
2695    } TessEval;
2696
2697    /**
2698     * Geometry shader state - copied into gl_geometry_program by
2699     * _mesa_copy_linked_program_data().
2700     */
2701    struct {
2702       GLint VerticesIn;
2703       GLint VerticesOut;
2704       /**
2705        * 1 .. MAX_GEOMETRY_SHADER_INVOCATIONS
2706        */
2707       GLint Invocations;
2708       GLenum InputType;  /**< GL_POINTS, GL_LINES, GL_LINES_ADJACENCY_ARB,
2709                               GL_TRIANGLES, or GL_TRIANGLES_ADJACENCY_ARB */
2710       GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
2711       /**
2712        * True if gl_ClipDistance is written to.  Copied into
2713        * gl_geometry_program by _mesa_copy_linked_program_data().
2714        */
2715       GLuint ClipDistanceArraySize; /**< Size of the gl_ClipDistance array, or
2716                                          0 if not present. */
2717       bool UsesEndPrimitive;
2718       bool UsesStreams;
2719    } Geom;
2720
2721    /** Vertex shader state */
2722    struct {
2723       /**
2724        * True if gl_ClipDistance is written to.  Copied into gl_vertex_program
2725        * by _mesa_copy_linked_program_data().
2726        */
2727       GLuint ClipDistanceArraySize; /**< Size of the gl_ClipDistance array, or
2728                                          0 if not present. */
2729    } Vert;
2730
2731    /**
2732     * Compute shader state - copied into gl_compute_program by
2733     * _mesa_copy_linked_program_data().
2734     */
2735    struct {
2736       /**
2737        * If this shader contains a compute stage, size specified using
2738        * local_size_{x,y,z}.  Otherwise undefined.
2739        */
2740       unsigned LocalSize[3];
2741       /**
2742        * Size of shared variables accessed by the compute shader.
2743        */
2744       unsigned SharedSize;
2745    } Comp;
2746
2747    /* post-link info: */
2748    unsigned NumUniformStorage;
2749    unsigned NumHiddenUniforms;
2750    struct gl_uniform_storage *UniformStorage;
2751
2752    /**
2753     * Mapping from GL uniform locations returned by \c glUniformLocation to
2754     * UniformStorage entries. Arrays will have multiple contiguous slots
2755     * in the UniformRemapTable, all pointing to the same UniformStorage entry.
2756     */
2757    unsigned NumUniformRemapTable;
2758    struct gl_uniform_storage **UniformRemapTable;
2759
2760    /**
2761     * Size of the gl_ClipDistance array that is output from the last pipeline
2762     * stage before the fragment shader.
2763     */
2764    unsigned LastClipDistanceArraySize;
2765
2766    /**
2767     * This shader's uniform/ssbo block information.
2768     *
2769     * BufferInterfaceBlocks is a list containing both UBOs and SSBOs. This is
2770     * useful during the linking process so that we don't have to handle SSBOs
2771     * specifically.
2772     *
2773     * UniformBlocks is a list of UBOs. This is useful for backends that need
2774     * or prefer to see separate index spaces for UBOS and SSBOs like the GL
2775     * API specifies.
2776     *
2777     * ShaderStorageBlocks is a list of SSBOs. This is useful for backends that
2778     * need or prefer to see separate index spaces for UBOS and SSBOs like the
2779     * GL API specifies.
2780     *
2781     * UniformBlocks and ShaderStorageBlocks only have pointers into
2782     * BufferInterfaceBlocks so the actual resource information is not
2783     * duplicated and are only set after linking.
2784     */
2785    unsigned NumBufferInterfaceBlocks;
2786    struct gl_uniform_block *BufferInterfaceBlocks;
2787
2788    unsigned NumUniformBlocks;
2789    struct gl_uniform_block **UniformBlocks;
2790
2791    unsigned NumShaderStorageBlocks;
2792    struct gl_uniform_block **ShaderStorageBlocks;
2793
2794    /**
2795     * Indices into the BufferInterfaceBlocks[] array for each stage they're
2796     * used in, or -1.
2797     *
2798     * This is used to maintain the Binding values of the stage's
2799     * BufferInterfaceBlocks[] and to answer the
2800     * GL_UNIFORM_BLOCK_REFERENCED_BY_*_SHADER queries.
2801     */
2802    int *InterfaceBlockStageIndex[MESA_SHADER_STAGES];
2803
2804    /**
2805     * Indices into the BufferInterfaceBlocks[] array for Uniform Buffer
2806     * Objects and Shader Storage Buffer Objects.
2807     */
2808    unsigned *UboInterfaceBlockIndex;
2809    unsigned *SsboInterfaceBlockIndex;
2810
2811    /**
2812     * Map of active uniform names to locations
2813     *
2814     * Maps any active uniform that is not an array element to a location.
2815     * Each active uniform, including individual structure members will appear
2816     * in this map.  This roughly corresponds to the set of names that would be
2817     * enumerated by \c glGetActiveUniform.
2818     */
2819    struct string_to_uint_map *UniformHash;
2820
2821    struct gl_active_atomic_buffer *AtomicBuffers;
2822    unsigned NumAtomicBuffers;
2823
2824    GLboolean LinkStatus;   /**< GL_LINK_STATUS */
2825    GLboolean Validated;
2826    GLboolean _Used;        /**< Ever used for drawing? */
2827    GLboolean SamplersValidated; /**< Samplers validated against texture units? */
2828    GLchar *InfoLog;
2829
2830    unsigned Version;       /**< GLSL version used for linking */
2831    bool IsES;              /**< True if this program uses GLSL ES */
2832
2833    /**
2834     * Per-stage shaders resulting from the first stage of linking.
2835     *
2836     * Set of linked shaders for this program.  The array is accessed using the
2837     * \c MESA_SHADER_* defines.  Entries for non-existent stages will be
2838     * \c NULL.
2839     */
2840    struct gl_shader *_LinkedShaders[MESA_SHADER_STAGES];
2841
2842    /** List of all active resources after linking. */
2843    struct gl_program_resource *ProgramResourceList;
2844    unsigned NumProgramResourceList;
2845
2846    /* True if any of the fragment shaders attached to this program use:
2847     * #extension ARB_fragment_coord_conventions: enable
2848     */
2849    GLboolean ARB_fragment_coord_conventions_enable;
2850 };   
2851
2852
2853 #define GLSL_DUMP      0x1  /**< Dump shaders to stdout */
2854 #define GLSL_LOG       0x2  /**< Write shaders to files */
2855 #define GLSL_OPT       0x4  /**< Force optimizations (override pragmas) */
2856 #define GLSL_NO_OPT    0x8  /**< Force no optimizations (override pragmas) */
2857 #define GLSL_UNIFORMS 0x10  /**< Print glUniform calls */
2858 #define GLSL_NOP_VERT 0x20  /**< Force no-op vertex shaders */
2859 #define GLSL_NOP_FRAG 0x40  /**< Force no-op fragment shaders */
2860 #define GLSL_USE_PROG 0x80  /**< Log glUseProgram calls */
2861 #define GLSL_REPORT_ERRORS 0x100  /**< Print compilation errors */
2862 #define GLSL_DUMP_ON_ERROR 0x200 /**< Dump shaders to stderr on compile error */
2863
2864
2865 /**
2866  * Context state for GLSL vertex/fragment shaders.
2867  * Extended to support pipeline object
2868  */
2869 struct gl_pipeline_object
2870 {
2871    /** Name of the pipeline object as received from glGenProgramPipelines.
2872     * It would be 0 for shaders without separate shader objects.
2873     */
2874    GLuint Name;
2875
2876    GLint RefCount;
2877
2878    mtx_t Mutex;
2879
2880    GLchar *Label;   /**< GL_KHR_debug */
2881
2882    /**
2883     * Programs used for rendering
2884     *
2885     * There is a separate program set for each shader stage.
2886     */
2887    struct gl_shader_program *CurrentProgram[MESA_SHADER_STAGES];
2888
2889    struct gl_shader_program *_CurrentFragmentProgram;
2890
2891    /**
2892     * Program used by glUniform calls.
2893     *
2894     * Explicitly set by \c glUseProgram and \c glActiveProgramEXT.
2895     */
2896    struct gl_shader_program *ActiveProgram;
2897
2898    GLbitfield Flags;                    /**< Mask of GLSL_x flags */
2899
2900    GLboolean EverBound;                 /**< Has the pipeline object been created */
2901
2902    GLboolean Validated;                 /**< Pipeline Validation status */
2903
2904    GLchar *InfoLog;
2905 };
2906
2907 /**
2908  * Context state for GLSL pipeline shaders.
2909  */
2910 struct gl_pipeline_shader_state
2911 {
2912    /** Currently bound pipeline object. See _mesa_BindProgramPipeline() */
2913    struct gl_pipeline_object *Current;
2914
2915    /* Default Object to ensure that _Shader is never NULL */
2916    struct gl_pipeline_object *Default;
2917
2918    /** Pipeline objects */
2919    struct _mesa_HashTable *Objects;
2920 };
2921
2922 /**
2923  * Compiler options for a single GLSL shaders type
2924  */
2925 struct gl_shader_compiler_options
2926 {
2927    /** Driver-selectable options: */
2928    GLboolean EmitCondCodes;             /**< Use condition codes? */
2929    GLboolean EmitNoLoops;
2930    GLboolean EmitNoFunctions;
2931    GLboolean EmitNoCont;                  /**< Emit CONT opcode? */
2932    GLboolean EmitNoMainReturn;            /**< Emit CONT/RET opcodes? */
2933    GLboolean EmitNoNoise;                 /**< Emit NOISE opcodes? */
2934    GLboolean EmitNoPow;                   /**< Emit POW opcodes? */
2935    GLboolean EmitNoSat;                   /**< Emit SAT opcodes? */
2936    GLboolean LowerClipDistance; /**< Lower gl_ClipDistance from float[8] to vec4[2]? */
2937
2938    /**
2939     * \name Forms of indirect addressing the driver cannot do.
2940     */
2941    /*@{*/
2942    GLboolean EmitNoIndirectInput;   /**< No indirect addressing of inputs */
2943    GLboolean EmitNoIndirectOutput;  /**< No indirect addressing of outputs */
2944    GLboolean EmitNoIndirectTemp;    /**< No indirect addressing of temps */
2945    GLboolean EmitNoIndirectUniform; /**< No indirect addressing of constants */
2946    GLboolean EmitNoIndirectSampler; /**< No indirect addressing of samplers */
2947    /*@}*/
2948
2949    GLuint MaxIfDepth;               /**< Maximum nested IF blocks */
2950    GLuint MaxUnrollIterations;
2951
2952    /**
2953     * Optimize code for array of structures backends.
2954     *
2955     * This is a proxy for:
2956     *   - preferring DP4 instructions (rather than MUL/MAD) for
2957     *     matrix * vector operations, such as position transformation.
2958     */
2959    GLboolean OptimizeForAOS;
2960
2961    GLboolean LowerBufferInterfaceBlocks; /**< Lower UBO and SSBO access to intrinsics. */
2962
2963    GLboolean LowerShaderSharedVariables; /**< Lower compute shader shared
2964                                           *   variable access to intrinsics. */
2965
2966    const struct nir_shader_compiler_options *NirOptions;
2967 };
2968
2969
2970 /**
2971  * Occlusion/timer query object.
2972  */
2973 struct gl_query_object
2974 {
2975    GLenum Target;      /**< The query target, when active */
2976    GLuint Id;          /**< hash table ID/name */
2977    GLchar *Label;       /**< GL_KHR_debug */
2978    GLuint64EXT Result; /**< the counter */
2979    GLboolean Active;   /**< inside Begin/EndQuery */
2980    GLboolean Ready;    /**< result is ready? */
2981    GLboolean EverBound;/**< has query object ever been bound */
2982    GLuint Stream;      /**< The stream */
2983 };
2984
2985
2986 /**
2987  * Context state for query objects.
2988  */
2989 struct gl_query_state
2990 {
2991    struct _mesa_HashTable *QueryObjects;
2992    struct gl_query_object *CurrentOcclusionObject; /* GL_ARB_occlusion_query */
2993    struct gl_query_object *CurrentTimerObject;     /* GL_EXT_timer_query */
2994
2995    /** GL_NV_conditional_render */
2996    struct gl_query_object *CondRenderQuery;
2997
2998    /** GL_EXT_transform_feedback */
2999    struct gl_query_object *PrimitivesGenerated[MAX_VERTEX_STREAMS];
3000    struct gl_query_object *PrimitivesWritten[MAX_VERTEX_STREAMS];
3001
3002    /** GL_ARB_timer_query */
3003    struct gl_query_object *TimeElapsed;
3004
3005    /** GL_ARB_pipeline_statistics_query */
3006    struct gl_query_object *pipeline_stats[MAX_PIPELINE_STATISTICS];
3007
3008    GLenum CondRenderMode;
3009 };
3010
3011
3012 /** Sync object state */
3013 struct gl_sync_object
3014 {
3015    GLenum Type;               /**< GL_SYNC_FENCE */
3016    GLuint Name;               /**< Fence name */
3017    GLchar *Label;             /**< GL_KHR_debug */
3018    GLint RefCount;            /**< Reference count */
3019    GLboolean DeletePending;   /**< Object was deleted while there were still
3020                                * live references (e.g., sync not yet finished)
3021                                */
3022    GLenum SyncCondition;
3023    GLbitfield Flags;          /**< Flags passed to glFenceSync */
3024    GLuint StatusFlag:1;       /**< Has the sync object been signaled? */
3025 };
3026
3027
3028 /**
3029  * State which can be shared by multiple contexts:
3030  */
3031 struct gl_shared_state
3032 {
3033    mtx_t Mutex;            /**< for thread safety */
3034    GLint RefCount;                         /**< Reference count */
3035    struct _mesa_HashTable *DisplayList;    /**< Display lists hash table */
3036    struct _mesa_HashTable *TexObjects;     /**< Texture objects hash table */
3037
3038    /** Default texture objects (shared by all texture units) */
3039    struct gl_texture_object *DefaultTex[NUM_TEXTURE_TARGETS];
3040
3041    /** Fallback texture used when a bound texture is incomplete */
3042    struct gl_texture_object *FallbackTex[NUM_TEXTURE_TARGETS];
3043
3044    /**
3045     * \name Thread safety and statechange notification for texture
3046     * objects. 
3047     *
3048     * \todo Improve the granularity of locking.
3049     */
3050    /*@{*/
3051    mtx_t TexMutex;              /**< texobj thread safety */
3052    GLuint TextureStateStamp;            /**< state notification for shared tex */
3053    /*@}*/
3054
3055    /** Default buffer object for vertex arrays that aren't in VBOs */
3056    struct gl_buffer_object *NullBufferObj;
3057
3058    /**
3059     * \name Vertex/geometry/fragment programs
3060     */
3061    /*@{*/
3062    struct _mesa_HashTable *Programs; /**< All vertex/fragment programs */
3063    struct gl_vertex_program *DefaultVertexProgram;
3064    struct gl_fragment_program *DefaultFragmentProgram;
3065    /*@}*/
3066
3067    /* GL_ATI_fragment_shader */
3068    struct _mesa_HashTable *ATIShaders;
3069    struct ati_fragment_shader *DefaultFragmentShader;
3070
3071    struct _mesa_HashTable *BufferObjects;
3072
3073    /** Table of both gl_shader and gl_shader_program objects */
3074    struct _mesa_HashTable *ShaderObjects;
3075
3076    /* GL_EXT_framebuffer_object */
3077    struct _mesa_HashTable *RenderBuffers;
3078    struct _mesa_HashTable *FrameBuffers;
3079
3080    /* GL_ARB_sync */
3081    struct set *SyncObjects;
3082
3083    /** GL_ARB_sampler_objects */
3084    struct _mesa_HashTable *SamplerObjects;
3085
3086    /**
3087     * Some context in this share group was affected by a GPU reset
3088     *
3089     * On the next call to \c glGetGraphicsResetStatus, contexts that have not
3090     * been affected by a GPU reset must also return
3091     * \c GL_INNOCENT_CONTEXT_RESET_ARB.
3092     *
3093     * Once this field becomes true, it is never reset to false.
3094     */
3095    bool ShareGroupReset;
3096 };
3097
3098
3099
3100 /**
3101  * Renderbuffers represent drawing surfaces such as color, depth and/or
3102  * stencil.  A framebuffer object has a set of renderbuffers.
3103  * Drivers will typically derive subclasses of this type.
3104  */
3105 struct gl_renderbuffer
3106 {
3107    mtx_t Mutex; /**< for thread safety */
3108    GLuint ClassID;        /**< Useful for drivers */
3109    GLuint Name;
3110    GLchar *Label;         /**< GL_KHR_debug */
3111    GLint RefCount;
3112    GLuint Width, Height;
3113    GLuint Depth;
3114    GLboolean Purgeable;  /**< Is the buffer purgeable under memory pressure? */
3115    GLboolean AttachedAnytime; /**< TRUE if it was attached to a framebuffer */
3116    /**
3117     * True for renderbuffers that wrap textures, giving the driver a chance to
3118     * flush render caches through the FinishRenderTexture hook.
3119     *
3120     * Drivers may also set this on renderbuffers other than those generated by
3121     * glFramebufferTexture(), though it means FinishRenderTexture() would be
3122     * called without a rb->TexImage.
3123     */
3124    GLboolean NeedsFinishRenderTexture;
3125    GLubyte NumSamples;
3126    GLenum InternalFormat; /**< The user-specified format */
3127    GLenum _BaseFormat;    /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
3128                                GL_STENCIL_INDEX. */
3129    mesa_format Format;      /**< The actual renderbuffer memory format */
3130    /**
3131     * Pointer to the texture image if this renderbuffer wraps a texture,
3132     * otherwise NULL.
3133     *
3134     * Note that the reference on the gl_texture_object containing this
3135     * TexImage is held by the gl_renderbuffer_attachment.
3136     */
3137    struct gl_texture_image *TexImage;
3138
3139    /** Delete this renderbuffer */
3140    void (*Delete)(struct gl_context *ctx, struct gl_renderbuffer *rb);
3141
3142    /** Allocate new storage for this renderbuffer */
3143    GLboolean (*AllocStorage)(struct gl_context *ctx,
3144                              struct gl_renderbuffer *rb,
3145                              GLenum internalFormat,
3146                              GLuint width, GLuint height);
3147 };
3148
3149
3150 /**
3151  * A renderbuffer attachment points to either a texture object (and specifies
3152  * a mipmap level, cube face or 3D texture slice) or points to a renderbuffer.
3153  */
3154 struct gl_renderbuffer_attachment
3155 {
3156    GLenum Type;  /**< \c GL_NONE or \c GL_TEXTURE or \c GL_RENDERBUFFER_EXT */
3157    GLboolean Complete;
3158
3159    /**
3160     * If \c Type is \c GL_RENDERBUFFER_EXT, this stores a pointer to the
3161     * application supplied renderbuffer object.
3162     */
3163    struct gl_renderbuffer *Renderbuffer;
3164
3165    /**
3166     * If \c Type is \c GL_TEXTURE, this stores a pointer to the application
3167     * supplied texture object.
3168     */
3169    struct gl_texture_object *Texture;
3170    GLuint TextureLevel; /**< Attached mipmap level. */
3171    GLuint CubeMapFace;  /**< 0 .. 5, for cube map textures. */
3172    GLuint Zoffset;      /**< Slice for 3D textures,  or layer for both 1D
3173                          * and 2D array textures */
3174    GLboolean Layered;
3175 };
3176
3177
3178 /**
3179  * A framebuffer is a collection of renderbuffers (color, depth, stencil, etc).
3180  * In C++ terms, think of this as a base class from which device drivers
3181  * will make derived classes.
3182  */
3183 struct gl_framebuffer
3184 {
3185    mtx_t Mutex;  /**< for thread safety */
3186    /**
3187     * If zero, this is a window system framebuffer.  If non-zero, this
3188     * is a FBO framebuffer; note that for some devices (i.e. those with
3189     * a natural pixel coordinate system for FBOs that differs from the
3190     * OpenGL/Mesa coordinate system), this means that the viewport,
3191     * polygon face orientation, and polygon stipple will have to be inverted.
3192     */
3193    GLuint Name;
3194    GLint RefCount;
3195
3196    GLchar *Label;       /**< GL_KHR_debug */
3197
3198    GLboolean DeletePending;
3199
3200    /**
3201     * The framebuffer's visual. Immutable if this is a window system buffer.
3202     * Computed from attachments if user-made FBO.
3203     */
3204    struct gl_config Visual;
3205
3206    /**
3207     * Size of frame buffer in pixels. If there are no attachments, then both
3208     * of these are 0.
3209     */
3210    GLuint Width, Height;
3211
3212    /**
3213     * In the case that the framebuffer has no attachment (i.e.
3214     * GL_ARB_framebuffer_no_attachments) then the geometry of
3215     * the framebuffer is specified by the default values.
3216     */
3217    struct {
3218      GLuint Width, Height, Layers, NumSamples;
3219      GLboolean FixedSampleLocations;
3220    } DefaultGeometry;
3221
3222    /** \name  Drawing bounds (Intersection of buffer size and scissor box)
3223     * The drawing region is given by [_Xmin, _Xmax) x [_Ymin, _Ymax),
3224     * (inclusive for _Xmin and _Ymin while exclusive for _Xmax and _Ymax)
3225     */
3226    /*@{*/
3227    GLint _Xmin, _Xmax;
3228    GLint _Ymin, _Ymax;
3229    /*@}*/
3230
3231    /** \name  Derived Z buffer stuff */
3232    /*@{*/
3233    GLuint _DepthMax;    /**< Max depth buffer value */
3234    GLfloat _DepthMaxF;  /**< Float max depth buffer value */
3235    GLfloat _MRD;        /**< minimum resolvable difference in Z values */
3236    /*@}*/
3237
3238    /** One of the GL_FRAMEBUFFER_(IN)COMPLETE_* tokens */
3239    GLenum _Status;
3240
3241    /** Whether one of Attachment has Type != GL_NONE
3242     * NOTE: the values for Width and Height are set to 0 in case of having
3243     * no attachments, a backend driver supporting the extension
3244     * GL_ARB_framebuffer_no_attachments must check for the flag _HasAttachments
3245     * and if GL_FALSE, must then use the values in DefaultGeometry to initialize
3246     * its viewport, scissor and so on (in particular _Xmin, _Xmax, _Ymin and
3247     * _Ymax do NOT take into account _HasAttachments being false). To get the
3248     * geometry of the framebuffer, the  helper functions
3249     *   _mesa_geometric_width(),
3250     *   _mesa_geometric_height(),
3251     *   _mesa_geometric_samples() and
3252     *   _mesa_geometric_layers()
3253     * are available that check _HasAttachments.
3254     */
3255    bool _HasAttachments;
3256
3257    /** Integer color values */
3258    GLboolean _IntegerColor;
3259
3260    /* ARB_color_buffer_float */
3261    GLboolean _AllColorBuffersFixedPoint; /* no integer, no float */
3262    GLboolean _HasSNormOrFloatColorBuffer;
3263
3264    /**
3265     * The maximum number of layers in the framebuffer, or 0 if the framebuffer
3266     * is not layered.  For cube maps and cube map arrays, each cube face
3267     * counts as a layer. As the case for Width, Height a backend driver
3268     * supporting GL_ARB_framebuffer_no_attachments must use DefaultGeometry
3269     * in the case that _HasAttachments is false
3270     */
3271    GLuint MaxNumLayers;
3272
3273    /** Array of all renderbuffer attachments, indexed by BUFFER_* tokens. */
3274    struct gl_renderbuffer_attachment Attachment[BUFFER_COUNT];
3275
3276    /* In unextended OpenGL these vars are part of the GL_COLOR_BUFFER
3277     * attribute group and GL_PIXEL attribute group, respectively.
3278     */
3279    GLenum ColorDrawBuffer[MAX_DRAW_BUFFERS];
3280    GLenum ColorReadBuffer;
3281
3282    /** Computed from ColorDraw/ReadBuffer above */
3283    GLuint _NumColorDrawBuffers;
3284    GLint _ColorDrawBufferIndexes[MAX_DRAW_BUFFERS]; /**< BUFFER_x or -1 */
3285    GLint _ColorReadBufferIndex; /* -1 = None */
3286    struct gl_renderbuffer *_ColorDrawBuffers[MAX_DRAW_BUFFERS];
3287    struct gl_renderbuffer *_ColorReadBuffer;
3288
3289    /** Delete this framebuffer */
3290    void (*Delete)(struct gl_framebuffer *fb);
3291 };
3292
3293
3294 /**
3295  * Precision info for shader datatypes.  See glGetShaderPrecisionFormat().
3296  */
3297 struct gl_precision
3298 {
3299    GLushort RangeMin;   /**< min value exponent */
3300    GLushort RangeMax;   /**< max value exponent */
3301    GLushort Precision;  /**< number of mantissa bits */
3302 };
3303
3304
3305 /**
3306  * Limits for vertex, geometry and fragment programs/shaders.
3307  */
3308 struct gl_program_constants
3309 {
3310    /* logical limits */
3311    GLuint MaxInstructions;
3312    GLuint MaxAluInstructions;
3313    GLuint MaxTexInstructions;
3314    GLuint MaxTexIndirections;
3315    GLuint MaxAttribs;
3316    GLuint MaxTemps;
3317    GLuint MaxAddressRegs;
3318    GLuint MaxAddressOffset;  /**< [-MaxAddressOffset, MaxAddressOffset-1] */
3319    GLuint MaxParameters;
3320    GLuint MaxLocalParams;
3321    GLuint MaxEnvParams;
3322    /* native/hardware limits */
3323    GLuint MaxNativeInstructions;
3324    GLuint MaxNativeAluInstructions;
3325    GLuint MaxNativeTexInstructions;
3326    GLuint MaxNativeTexIndirections;
3327    GLuint MaxNativeAttribs;
3328    GLuint MaxNativeTemps;
3329    GLuint MaxNativeAddressRegs;
3330    GLuint MaxNativeParameters;
3331    /* For shaders */
3332    GLuint MaxUniformComponents;  /**< Usually == MaxParameters * 4 */
3333
3334    /**
3335     * \name Per-stage input / output limits
3336     *
3337     * Previous to OpenGL 3.2, the intrastage data limits were advertised with
3338     * a single value: GL_MAX_VARYING_COMPONENTS (GL_MAX_VARYING_VECTORS in
3339     * ES).  This is stored as \c gl_constants::MaxVarying.
3340     *
3341     * Starting with OpenGL 3.2, the limits are advertised with per-stage
3342     * variables.  Each stage as a certain number of outputs that it can feed
3343     * to the next stage and a certain number inputs that it can consume from
3344     * the previous stage.
3345     *
3346     * Vertex shader inputs do not participate this in this accounting.
3347     * These are tracked exclusively by \c gl_program_constants::MaxAttribs.
3348     *
3349     * Fragment shader outputs do not participate this in this accounting.
3350     * These are tracked exclusively by \c gl_constants::MaxDrawBuffers.
3351     */
3352    /*@{*/
3353    GLuint MaxInputComponents;
3354    GLuint MaxOutputComponents;
3355    /*@}*/
3356
3357    /* ES 2.0 and GL_ARB_ES2_compatibility */
3358    struct gl_precision LowFloat, MediumFloat, HighFloat;
3359    struct gl_precision LowInt, MediumInt, HighInt;
3360    /* GL_ARB_uniform_buffer_object */
3361    GLuint MaxUniformBlocks;
3362    GLuint MaxCombinedUniformComponents;
3363    GLuint MaxTextureImageUnits;
3364
3365    /* GL_ARB_shader_atomic_counters */
3366    GLuint MaxAtomicBuffers;
3367    GLuint MaxAtomicCounters;
3368
3369    /* GL_ARB_shader_image_load_store */
3370    GLuint MaxImageUniforms;
3371
3372    /* GL_ARB_shader_storage_buffer_object */
3373    GLuint MaxShaderStorageBlocks;
3374 };
3375
3376
3377 /**
3378  * Constants which may be overridden by device driver during context creation
3379  * but are never changed after that.
3380  */
3381 struct gl_constants
3382 {
3383    GLuint MaxTextureMbytes;      /**< Max memory per image, in MB */
3384    GLuint MaxTextureLevels;      /**< Max mipmap levels. */ 
3385    GLuint Max3DTextureLevels;    /**< Max mipmap levels for 3D textures */
3386    GLuint MaxCubeTextureLevels;  /**< Max mipmap levels for cube textures */
3387    GLuint MaxArrayTextureLayers; /**< Max layers in array textures */
3388    GLuint MaxTextureRectSize;    /**< Max rectangle texture size, in pixes */
3389    GLuint MaxTextureCoordUnits;
3390    GLuint MaxCombinedTextureImageUnits;
3391    GLuint MaxTextureUnits; /**< = MIN(CoordUnits, FragmentProgram.ImageUnits) */
3392    GLfloat MaxTextureMaxAnisotropy;  /**< GL_EXT_texture_filter_anisotropic */
3393    GLfloat MaxTextureLodBias;        /**< GL_EXT_texture_lod_bias */
3394    GLuint MaxTextureBufferSize;      /**< GL_ARB_texture_buffer_object */
3395
3396    GLuint TextureBufferOffsetAlignment; /**< GL_ARB_texture_buffer_range */
3397
3398    GLuint MaxArrayLockSize;
3399
3400    GLint SubPixelBits;
3401
3402    GLfloat MinPointSize, MaxPointSize;       /**< aliased */
3403    GLfloat MinPointSizeAA, MaxPointSizeAA;   /**< antialiased */
3404    GLfloat PointSizeGranularity;
3405    GLfloat MinLineWidth, MaxLineWidth;       /**< aliased */
3406    GLfloat MinLineWidthAA, MaxLineWidthAA;   /**< antialiased */
3407    GLfloat LineWidthGranularity;
3408
3409    GLuint MaxClipPlanes;
3410    GLuint MaxLights;
3411    GLfloat MaxShininess;                     /**< GL_NV_light_max_exponent */
3412    GLfloat MaxSpotExponent;                  /**< GL_NV_light_max_exponent */
3413
3414    GLuint MaxViewportWidth, MaxViewportHeight;
3415    GLuint MaxViewports;                      /**< GL_ARB_viewport_array */
3416    GLuint ViewportSubpixelBits;              /**< GL_ARB_viewport_array */
3417    struct {
3418       GLfloat Min;
3419       GLfloat Max;
3420    } ViewportBounds;                         /**< GL_ARB_viewport_array */
3421
3422    struct gl_program_constants Program[MESA_SHADER_STAGES];
3423    GLuint MaxProgramMatrices;
3424    GLuint MaxProgramMatrixStackDepth;
3425
3426    struct {
3427       GLuint SamplesPassed;
3428       GLuint TimeElapsed;
3429       GLuint Timestamp;
3430       GLuint PrimitivesGenerated;
3431       GLuint PrimitivesWritten;
3432       GLuint VerticesSubmitted;
3433       GLuint PrimitivesSubmitted;
3434       GLuint VsInvocations;
3435       GLuint TessPatches;
3436       GLuint TessInvocations;
3437       GLuint GsInvocations;
3438       GLuint GsPrimitives;
3439       GLuint FsInvocations;
3440       GLuint ComputeInvocations;
3441       GLuint ClInPrimitives;
3442       GLuint ClOutPrimitives;
3443    } QueryCounterBits;
3444
3445    GLuint MaxDrawBuffers;    /**< GL_ARB_draw_buffers */
3446
3447    GLuint MaxColorAttachments;   /**< GL_EXT_framebuffer_object */
3448    GLuint MaxRenderbufferSize;   /**< GL_EXT_framebuffer_object */
3449    GLuint MaxSamples;            /**< GL_ARB_framebuffer_object */
3450
3451    /**
3452     * GL_ARB_framebuffer_no_attachments
3453     */
3454    GLuint MaxFramebufferWidth;
3455    GLuint MaxFramebufferHeight;
3456    GLuint MaxFramebufferLayers;
3457    GLuint MaxFramebufferSamples;
3458
3459    /** Number of varying vectors between any two shader stages. */
3460    GLuint MaxVarying;
3461
3462    /** @{
3463     * GL_ARB_uniform_buffer_object
3464     */
3465    GLuint MaxCombinedUniformBlocks;
3466    GLuint MaxUniformBufferBindings;
3467    GLuint MaxUniformBlockSize;
3468    GLuint UniformBufferOffsetAlignment;
3469    /** @} */
3470
3471    /** @{
3472     * GL_ARB_shader_storage_buffer_object
3473     */
3474    GLuint MaxCombinedShaderStorageBlocks;
3475    GLuint MaxShaderStorageBufferBindings;
3476    GLuint MaxShaderStorageBlockSize;
3477    GLuint ShaderStorageBufferOffsetAlignment;
3478    /** @} */
3479
3480    /**
3481     * GL_ARB_explicit_uniform_location
3482     */
3483    GLuint MaxUserAssignableUniformLocations;
3484
3485    /** geometry shader */
3486    GLuint MaxGeometryOutputVertices;
3487    GLuint MaxGeometryTotalOutputComponents;
3488
3489    GLuint GLSLVersion;  /**< Desktop GLSL version supported (ex: 120 = 1.20) */
3490
3491    /**
3492     * Changes default GLSL extension behavior from "error" to "warn".  It's out
3493     * of spec, but it can make some apps work that otherwise wouldn't.
3494     */
3495    GLboolean ForceGLSLExtensionsWarn;
3496
3497    /**
3498     * If non-zero, forces GLSL shaders to behave as if they began
3499     * with "#version ForceGLSLVersion".
3500     */
3501    GLuint ForceGLSLVersion;
3502
3503    /**
3504     * Allow GLSL #extension directives in the middle of shaders.
3505     */
3506    GLboolean AllowGLSLExtensionDirectiveMidShader;
3507
3508    /**
3509     * Does the driver support real 32-bit integers?  (Otherwise, integers are
3510     * simulated via floats.)
3511     */
3512    GLboolean NativeIntegers;
3513
3514    /**
3515     * Does VertexID count from zero or from base vertex?
3516     *
3517     * \note
3518     * If desktop GLSL 1.30 or GLSL ES 3.00 are not supported, this field is
3519     * ignored and need not be set.
3520     */
3521    bool VertexID_is_zero_based;
3522
3523    /**
3524     * If the driver supports real 32-bit integers, what integer value should be
3525     * used for boolean true in uniform uploads?  (Usually 1 or ~0.)
3526     */
3527    GLuint UniformBooleanTrue;
3528
3529    /**
3530     * Maximum amount of time, measured in nanseconds, that the server can wait.
3531     */
3532    GLuint64 MaxServerWaitTimeout;
3533
3534    /** GL_EXT_provoking_vertex */
3535    GLboolean QuadsFollowProvokingVertexConvention;
3536
3537    /** GL_ARB_viewport_array */
3538    GLenum LayerAndVPIndexProvokingVertex;
3539
3540    /** OpenGL version 3.0 */
3541    GLbitfield ContextFlags;  /**< Ex: GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT */
3542
3543    /** OpenGL version 3.2 */
3544    GLbitfield ProfileMask;   /**< Mask of CONTEXT_x_PROFILE_BIT */
3545
3546    /** OpenGL version 4.4 */
3547    GLuint MaxVertexAttribStride;
3548
3549    /** GL_EXT_transform_feedback */
3550    GLuint MaxTransformFeedbackBuffers;
3551    GLuint MaxTransformFeedbackSeparateComponents;
3552    GLuint MaxTransformFeedbackInterleavedComponents;
3553    GLuint MaxVertexStreams;
3554
3555    /** GL_EXT_gpu_shader4 */
3556    GLint MinProgramTexelOffset, MaxProgramTexelOffset;
3557
3558    /** GL_ARB_texture_gather */
3559    GLuint MinProgramTextureGatherOffset;
3560    GLuint MaxProgramTextureGatherOffset;
3561    GLuint MaxProgramTextureGatherComponents;
3562
3563    /* GL_ARB_robustness */
3564    GLenum ResetStrategy;
3565
3566    /* GL_ARB_blend_func_extended */
3567    GLuint MaxDualSourceDrawBuffers;
3568
3569    /**
3570     * Whether the implementation strips out and ignores texture borders.
3571     *
3572     * Many GPU hardware implementations don't support rendering with texture
3573     * borders and mipmapped textures.  (Note: not static border color, but the
3574     * old 1-pixel border around each edge).  Implementations then have to do
3575     * slow fallbacks to be correct, or just ignore the border and be fast but
3576     * wrong.  Setting the flag strips the border off of TexImage calls,
3577     * providing "fast but wrong" at significantly reduced driver complexity.
3578     *
3579     * Texture borders are deprecated in GL 3.0.
3580     **/
3581    GLboolean StripTextureBorder;
3582
3583    /**
3584     * For drivers which can do a better job at eliminating unused uniforms
3585     * than the GLSL compiler.
3586     *
3587     * XXX Remove these as soon as a better solution is available.
3588     */
3589    GLboolean GLSLSkipStrictMaxUniformLimitCheck;
3590
3591    /** Whether gl_FragCoord and gl_FrontFacing are system values. */
3592    bool GLSLFragCoordIsSysVal;
3593    bool GLSLFrontFacingIsSysVal;
3594
3595    /**
3596     * Always use the GetTransformFeedbackVertexCount() driver hook, rather
3597     * than passing the transform feedback object to the drawing function.
3598     */
3599    GLboolean AlwaysUseGetTransformFeedbackVertexCount;
3600
3601    /** GL_ARB_map_buffer_alignment */
3602    GLuint MinMapBufferAlignment;
3603
3604    /**
3605     * Disable varying packing.  This is out of spec, but potentially useful
3606     * for older platforms that supports a limited number of texture
3607     * indirections--on these platforms, unpacking the varyings in the fragment
3608     * shader increases the number of texture indirections by 1, which might
3609     * make some shaders not executable at all.
3610     *
3611     * Drivers that support transform feedback must set this value to GL_FALSE.
3612     */
3613    GLboolean DisableVaryingPacking;
3614
3615    /**
3616     * Should meaningful names be generated for compiler temporary variables?
3617     *
3618     * Generally, it is not useful to have the compiler generate "meaningful"
3619     * names for temporary variables that it creates.  This can, however, be a
3620     * useful debugging aid.  In Mesa debug builds or release builds when
3621     * MESA_GLSL is set at run-time, meaningful names will be generated.
3622     * Drivers can also force names to be generated by setting this field.
3623     * For example, the i965 driver may set it when INTEL_DEBUG=vs (to dump
3624     * vertex shader assembly) is set at run-time.
3625     */
3626    bool GenerateTemporaryNames;
3627
3628    /*
3629     * Maximum value supported for an index in DrawElements and friends.
3630     *
3631     * This must be at least (1ull<<24)-1.  The default value is
3632     * (1ull<<32)-1.
3633     *
3634     * \since ES 3.0 or GL_ARB_ES3_compatibility
3635     * \sa _mesa_init_constants
3636     */
3637    GLuint64 MaxElementIndex;
3638
3639    /**
3640     * Disable interpretation of line continuations (lines ending with a
3641     * backslash character ('\') in GLSL source.
3642     */
3643    GLboolean DisableGLSLLineContinuations;
3644
3645    /** GL_ARB_texture_multisample */
3646    GLint MaxColorTextureSamples;
3647    GLint MaxDepthTextureSamples;
3648    GLint MaxIntegerSamples;
3649
3650    /**
3651     * GL_EXT_texture_multisample_blit_scaled implementation assumes that
3652     * samples are laid out in a rectangular grid roughly corresponding to
3653     * sample locations within a pixel. Below SampleMap{2,4,8}x variables
3654     * are used to map indices of rectangular grid to sample numbers within
3655     * a pixel. This mapping of indices to sample numbers must be initialized
3656     * by the driver for the target hardware. For example, if we have the 8X
3657     * MSAA sample number layout (sample positions) for XYZ hardware:
3658     *
3659     *        sample indices layout          sample number layout
3660     *            ---------                      ---------
3661     *            | 0 | 1 |                      | a | b |
3662     *            ---------                      ---------
3663     *            | 2 | 3 |                      | c | d |
3664     *            ---------                      ---------
3665     *            | 4 | 5 |                      | e | f |
3666     *            ---------                      ---------
3667     *            | 6 | 7 |                      | g | h |
3668     *            ---------                      ---------
3669     *
3670     * Where a,b,c,d,e,f,g,h are integers between [0-7].
3671     *
3672     * Then, initialize the SampleMap8x variable for XYZ hardware as shown
3673     * below:
3674     *    SampleMap8x = {a, b, c, d, e, f, g, h};
3675     *
3676     * Follow the logic for sample counts 2-8.
3677     *
3678     * For 16x the sample indices layout as a 4x4 grid as follows:
3679     *
3680     *            -----------------
3681     *            | 0 | 1 | 2 | 3 |
3682     *            -----------------
3683     *            | 4 | 5 | 6 | 7 |
3684     *            -----------------
3685     *            | 8 | 9 |10 |11 |
3686     *            -----------------
3687     *            |12 |13 |14 |15 |
3688     *            -----------------
3689     */
3690    uint8_t SampleMap2x[2];
3691    uint8_t SampleMap4x[4];
3692    uint8_t SampleMap8x[8];
3693    uint8_t SampleMap16x[16];
3694
3695    /** GL_ARB_shader_atomic_counters */
3696    GLuint MaxAtomicBufferBindings;
3697    GLuint MaxAtomicBufferSize;
3698    GLuint MaxCombinedAtomicBuffers;
3699    GLuint MaxCombinedAtomicCounters;
3700
3701    /** GL_ARB_vertex_attrib_binding */
3702    GLint MaxVertexAttribRelativeOffset;
3703    GLint MaxVertexAttribBindings;
3704
3705    /* GL_ARB_shader_image_load_store */
3706    GLuint MaxImageUnits;
3707    GLuint MaxCombinedShaderOutputResources;
3708    GLuint MaxImageSamples;
3709    GLuint MaxCombinedImageUniforms;
3710
3711    /** GL_ARB_compute_shader */
3712    GLuint MaxComputeWorkGroupCount[3]; /* Array of x, y, z dimensions */
3713    GLuint MaxComputeWorkGroupSize[3]; /* Array of x, y, z dimensions */
3714    GLuint MaxComputeWorkGroupInvocations;
3715
3716    /** GL_ARB_gpu_shader5 */
3717    GLfloat MinFragmentInterpolationOffset;
3718    GLfloat MaxFragmentInterpolationOffset;
3719
3720    GLboolean FakeSWMSAA;
3721
3722    /** GL_KHR_context_flush_control */
3723    GLenum ContextReleaseBehavior;
3724
3725    struct gl_shader_compiler_options ShaderCompilerOptions[MESA_SHADER_STAGES];
3726
3727    /** GL_ARB_tessellation_shader */
3728    GLuint MaxPatchVertices;
3729    GLuint MaxTessGenLevel;
3730    GLuint MaxTessPatchComponents;
3731    GLuint MaxTessControlTotalOutputComponents;
3732    bool LowerTessLevel; /**< Lower gl_TessLevel* from float[n] to vecn? */
3733 };
3734
3735
3736 /**
3737  * Enable flag for each OpenGL extension.  Different device drivers will
3738  * enable different extensions at runtime.
3739  */
3740 struct gl_extensions
3741 {
3742    GLboolean dummy;  /* don't remove this! */
3743    GLboolean dummy_true;  /* Set true by _mesa_init_extensions(). */
3744    GLboolean dummy_false; /* Set false by _mesa_init_extensions(). */
3745    GLboolean ANGLE_texture_compression_dxt;
3746    GLboolean ARB_ES2_compatibility;
3747    GLboolean ARB_ES3_compatibility;
3748    GLboolean ARB_arrays_of_arrays;
3749    GLboolean ARB_base_instance;
3750    GLboolean ARB_blend_func_extended;
3751    GLboolean ARB_buffer_storage;
3752    GLboolean ARB_clear_texture;
3753    GLboolean ARB_clip_control;
3754    GLboolean ARB_color_buffer_float;
3755    GLboolean ARB_compute_shader;
3756    GLboolean ARB_conditional_render_inverted;
3757    GLboolean ARB_conservative_depth;
3758    GLboolean ARB_copy_image;
3759    GLboolean ARB_depth_buffer_float;
3760    GLboolean ARB_depth_clamp;
3761    GLboolean ARB_depth_texture;
3762    GLboolean ARB_derivative_control;
3763    GLboolean ARB_draw_buffers_blend;
3764    GLboolean ARB_draw_elements_base_vertex;
3765    GLboolean ARB_draw_indirect;
3766    GLboolean ARB_draw_instanced;
3767    GLboolean ARB_fragment_coord_conventions;
3768    GLboolean ARB_fragment_layer_viewport;
3769    GLboolean ARB_fragment_program;
3770    GLboolean ARB_fragment_program_shadow;
3771    GLboolean ARB_fragment_shader;
3772    GLboolean ARB_framebuffer_no_attachments;
3773    GLboolean ARB_framebuffer_object;
3774    GLboolean ARB_enhanced_layouts;
3775    GLboolean ARB_explicit_attrib_location;
3776    GLboolean ARB_explicit_uniform_location;
3777    GLboolean ARB_gpu_shader5;
3778    GLboolean ARB_gpu_shader_fp64;
3779    GLboolean ARB_half_float_vertex;
3780    GLboolean ARB_indirect_parameters;
3781    GLboolean ARB_instanced_arrays;
3782    GLboolean ARB_internalformat_query;
3783    GLboolean ARB_map_buffer_range;
3784    GLboolean ARB_occlusion_query;
3785    GLboolean ARB_occlusion_query2;
3786    GLboolean ARB_pipeline_statistics_query;
3787    GLboolean ARB_point_sprite;
3788    GLboolean ARB_sample_shading;
3789    GLboolean ARB_seamless_cube_map;
3790    GLboolean ARB_shader_atomic_counters;
3791    GLboolean ARB_shader_bit_encoding;
3792    GLboolean ARB_shader_clock;
3793    GLboolean ARB_shader_draw_parameters;
3794    GLboolean ARB_shader_image_load_store;
3795    GLboolean ARB_shader_image_size;
3796    GLboolean ARB_shader_precision;
3797    GLboolean ARB_shader_stencil_export;
3798    GLboolean ARB_shader_storage_buffer_object;
3799    GLboolean ARB_shader_subroutine;
3800    GLboolean ARB_shader_texture_image_samples;
3801    GLboolean ARB_shader_texture_lod;
3802    GLboolean ARB_shading_language_packing;
3803    GLboolean ARB_shading_language_420pack;
3804    GLboolean ARB_shadow;
3805    GLboolean ARB_stencil_texturing;
3806    GLboolean ARB_sync;
3807    GLboolean ARB_tessellation_shader;
3808    GLboolean ARB_texture_border_clamp;
3809    GLboolean ARB_texture_buffer_object;
3810    GLboolean ARB_texture_buffer_object_rgb32;
3811    GLboolean ARB_texture_buffer_range;
3812    GLboolean ARB_texture_compression_bptc;
3813    GLboolean ARB_texture_compression_rgtc;
3814    GLboolean ARB_texture_cube_map;
3815    GLboolean ARB_texture_cube_map_array;
3816    GLboolean ARB_texture_env_combine;
3817    GLboolean ARB_texture_env_crossbar;
3818    GLboolean ARB_texture_env_dot3;
3819    GLboolean ARB_texture_float;
3820    GLboolean ARB_texture_gather;
3821    GLboolean ARB_texture_mirror_clamp_to_edge;
3822    GLboolean ARB_texture_multisample;
3823    GLboolean ARB_texture_non_power_of_two;
3824    GLboolean ARB_texture_stencil8;
3825    GLboolean ARB_texture_query_levels;
3826    GLboolean ARB_texture_query_lod;
3827    GLboolean ARB_texture_rg;
3828    GLboolean ARB_texture_rgb10_a2ui;
3829    GLboolean ARB_texture_view;
3830    GLboolean ARB_timer_query;
3831    GLboolean ARB_transform_feedback2;
3832    GLboolean ARB_transform_feedback3;
3833    GLboolean ARB_transform_feedback_instanced;
3834    GLboolean ARB_uniform_buffer_object;
3835    GLboolean ARB_vertex_attrib_64bit;
3836    GLboolean ARB_vertex_program;
3837    GLboolean ARB_vertex_shader;
3838    GLboolean ARB_vertex_type_10f_11f_11f_rev;
3839    GLboolean ARB_vertex_type_2_10_10_10_rev;
3840    GLboolean ARB_viewport_array;
3841    GLboolean EXT_blend_color;
3842    GLboolean EXT_blend_equation_separate;
3843    GLboolean EXT_blend_func_separate;
3844    GLboolean EXT_blend_minmax;
3845    GLboolean EXT_depth_bounds_test;
3846    GLboolean EXT_draw_buffers2;
3847    GLboolean EXT_framebuffer_multisample;
3848    GLboolean EXT_framebuffer_multisample_blit_scaled;
3849    GLboolean EXT_framebuffer_sRGB;
3850    GLboolean EXT_gpu_program_parameters;
3851    GLboolean EXT_gpu_shader4;
3852    GLboolean EXT_packed_float;
3853    GLboolean EXT_pixel_buffer_object;
3854    GLboolean EXT_point_parameters;
3855    GLboolean EXT_polygon_offset_clamp;
3856    GLboolean EXT_provoking_vertex;
3857    GLboolean EXT_shader_integer_mix;
3858    GLboolean EXT_shader_samples_identical;
3859    GLboolean EXT_stencil_two_side;
3860    GLboolean EXT_texture_array;
3861    GLboolean EXT_texture_compression_latc;
3862    GLboolean EXT_texture_compression_s3tc;
3863    GLboolean EXT_texture_env_dot3;
3864    GLboolean EXT_texture_filter_anisotropic;
3865    GLboolean EXT_texture_integer;
3866    GLboolean EXT_texture_mirror_clamp;
3867    GLboolean EXT_texture_shared_exponent;
3868    GLboolean EXT_texture_snorm;
3869    GLboolean EXT_texture_sRGB;
3870    GLboolean EXT_texture_sRGB_decode;
3871    GLboolean EXT_texture_swizzle;
3872    GLboolean EXT_transform_feedback;
3873    GLboolean EXT_timer_query;
3874    GLboolean EXT_vertex_array_bgra;
3875    GLboolean OES_standard_derivatives;
3876    /* vendor extensions */
3877    GLboolean AMD_performance_monitor;
3878    GLboolean AMD_pinned_memory;
3879    GLboolean AMD_seamless_cubemap_per_texture;
3880    GLboolean AMD_vertex_shader_layer;
3881    GLboolean AMD_vertex_shader_viewport_index;
3882    GLboolean APPLE_object_purgeable;
3883    GLboolean ATI_texture_compression_3dc;
3884    GLboolean ATI_texture_mirror_once;
3885    GLboolean ATI_texture_env_combine3;
3886    GLboolean ATI_fragment_shader;
3887    GLboolean ATI_separate_stencil;
3888    GLboolean INTEL_performance_query;
3889    GLboolean KHR_texture_compression_astc_hdr;
3890    GLboolean KHR_texture_compression_astc_ldr;
3891    GLboolean MESA_pack_invert;
3892    GLboolean MESA_ycbcr_texture;
3893    GLboolean NV_conditional_render;
3894    GLboolean NV_fog_distance;
3895    GLboolean NV_fragment_program_option;
3896    GLboolean NV_point_sprite;
3897    GLboolean NV_primitive_restart;
3898    GLboolean NV_texture_barrier;
3899    GLboolean NV_texture_env_combine4;
3900    GLboolean NV_texture_rectangle;
3901    GLboolean NV_vdpau_interop;
3902    GLboolean TDFX_texture_compression_FXT1;
3903    GLboolean OES_EGL_image;
3904    GLboolean OES_draw_texture;
3905    GLboolean OES_depth_texture_cube_map;
3906    GLboolean OES_EGL_image_external;
3907    GLboolean OES_texture_float;
3908    GLboolean OES_texture_float_linear;
3909    GLboolean OES_texture_half_float;
3910    GLboolean OES_texture_half_float_linear;
3911    GLboolean OES_compressed_ETC1_RGB8_texture;
3912    GLboolean extension_sentinel;
3913    /** The extension string */
3914    const GLubyte *String;
3915    /** Number of supported extensions */
3916    GLuint Count;
3917    /**
3918     * The context version which extension helper functions compare against.
3919     * By default, the value is equal to ctx->Version. This changes to ~0
3920     * while meta is in progress.
3921     */
3922    GLubyte Version;
3923 };
3924
3925
3926 /**
3927  * A stack of matrices (projection, modelview, color, texture, etc).
3928  */
3929 struct gl_matrix_stack
3930 {
3931    GLmatrix *Top;      /**< points into Stack */
3932    GLmatrix *Stack;    /**< array [MaxDepth] of GLmatrix */
3933    GLuint Depth;       /**< 0 <= Depth < MaxDepth */
3934    GLuint MaxDepth;    /**< size of Stack[] array */
3935    GLuint DirtyFlag;   /**< _NEW_MODELVIEW or _NEW_PROJECTION, for example */
3936 };
3937
3938
3939 /**
3940  * \name Bits for image transfer operations 
3941  * \sa __struct gl_contextRec::ImageTransferState.
3942  */
3943 /*@{*/
3944 #define IMAGE_SCALE_BIAS_BIT                      0x1
3945 #define IMAGE_SHIFT_OFFSET_BIT                    0x2
3946 #define IMAGE_MAP_COLOR_BIT                       0x4
3947 #define IMAGE_CLAMP_BIT                           0x800
3948
3949
3950 /** Pixel Transfer ops */
3951 #define IMAGE_BITS (IMAGE_SCALE_BIAS_BIT |                      \
3952                     IMAGE_SHIFT_OFFSET_BIT |                    \
3953                     IMAGE_MAP_COLOR_BIT)
3954
3955 /**
3956  * \name Bits to indicate what state has changed.  
3957  */
3958 /*@{*/
3959 #define _NEW_MODELVIEW         (1 << 0)   /**< gl_context::ModelView */
3960 #define _NEW_PROJECTION        (1 << 1)   /**< gl_context::Projection */
3961 #define _NEW_TEXTURE_MATRIX    (1 << 2)   /**< gl_context::TextureMatrix */
3962 #define _NEW_COLOR             (1 << 3)   /**< gl_context::Color */
3963 #define _NEW_DEPTH             (1 << 4)   /**< gl_context::Depth */
3964 #define _NEW_EVAL              (1 << 5)   /**< gl_context::Eval, EvalMap */
3965 #define _NEW_FOG               (1 << 6)   /**< gl_context::Fog */
3966 #define _NEW_HINT              (1 << 7)   /**< gl_context::Hint */
3967 #define _NEW_LIGHT             (1 << 8)   /**< gl_context::Light */
3968 #define _NEW_LINE              (1 << 9)   /**< gl_context::Line */
3969 #define _NEW_PIXEL             (1 << 10)  /**< gl_context::Pixel */
3970 #define _NEW_POINT             (1 << 11)  /**< gl_context::Point */
3971 #define _NEW_POLYGON           (1 << 12)  /**< gl_context::Polygon */
3972 #define _NEW_POLYGONSTIPPLE    (1 << 13)  /**< gl_context::PolygonStipple */
3973 #define _NEW_SCISSOR           (1 << 14)  /**< gl_context::Scissor */
3974 #define _NEW_STENCIL           (1 << 15)  /**< gl_context::Stencil */
3975 #define _NEW_TEXTURE           (1 << 16)  /**< gl_context::Texture */
3976 #define _NEW_TRANSFORM         (1 << 17)  /**< gl_context::Transform */
3977 #define _NEW_VIEWPORT          (1 << 18)  /**< gl_context::Viewport */
3978 /* gap, re-use for core Mesa state only; use ctx->DriverFlags otherwise */
3979 #define _NEW_ARRAY             (1 << 20)  /**< gl_context::Array */
3980 #define _NEW_RENDERMODE        (1 << 21)  /**< gl_context::RenderMode, etc */
3981 #define _NEW_BUFFERS           (1 << 22)  /**< gl_context::Visual, DrawBuffer, */
3982 #define _NEW_CURRENT_ATTRIB    (1 << 23)  /**< gl_context::Current */
3983 #define _NEW_MULTISAMPLE       (1 << 24)  /**< gl_context::Multisample */
3984 #define _NEW_TRACK_MATRIX      (1 << 25)  /**< gl_context::VertexProgram */
3985 #define _NEW_PROGRAM           (1 << 26)  /**< New program/shader state */
3986 #define _NEW_PROGRAM_CONSTANTS (1 << 27)
3987 #define _NEW_BUFFER_OBJECT     (1 << 28)
3988 #define _NEW_FRAG_CLAMP        (1 << 29)
3989 /* gap, re-use for core Mesa state only; use ctx->DriverFlags otherwise */
3990 #define _NEW_VARYING_VP_INPUTS (1 << 31) /**< gl_context::varying_vp_inputs */
3991 #define _NEW_ALL ~0
3992 /*@}*/
3993
3994
3995 /**
3996  * Composite state flags
3997  */
3998 /*@{*/
3999 #define _MESA_NEW_NEED_EYE_COORDS         (_NEW_LIGHT |         \
4000                                            _NEW_TEXTURE |       \
4001                                            _NEW_POINT |         \
4002                                            _NEW_PROGRAM |       \
4003                                            _NEW_MODELVIEW)
4004
4005 #define _MESA_NEW_SEPARATE_SPECULAR        (_NEW_LIGHT | \
4006                                             _NEW_FOG | \
4007                                             _NEW_PROGRAM)
4008
4009
4010 /*@}*/
4011
4012
4013
4014
4015 /* This has to be included here. */
4016 #include "dd.h"
4017
4018
4019 /**
4020  * Display list flags.
4021  * Strictly this is a tnl-private concept, but it doesn't seem
4022  * worthwhile adding a tnl private structure just to hold this one bit
4023  * of information:
4024  */
4025 #define DLIST_DANGLING_REFS     0x1 
4026
4027
4028 /** Opaque declaration of display list payload data type */
4029 union gl_dlist_node;
4030
4031
4032 /**
4033  * Provide a location where information about a display list can be
4034  * collected.  Could be extended with driverPrivate structures,
4035  * etc. in the future.
4036  */
4037 struct gl_display_list
4038 {
4039    GLuint Name;
4040    GLchar *Label;     /**< GL_KHR_debug */
4041    GLbitfield Flags;  /**< DLIST_x flags */
4042    /** The dlist commands are in a linked list of nodes */
4043    union gl_dlist_node *Head;
4044 };
4045
4046
4047 /**
4048  * State used during display list compilation and execution.
4049  */
4050 struct gl_dlist_state
4051 {
4052    GLuint CallDepth;            /**< Current recursion calling depth */
4053
4054    struct gl_display_list *CurrentList; /**< List currently being compiled */
4055    union gl_dlist_node *CurrentBlock; /**< Pointer to current block of nodes */
4056    GLuint CurrentPos;           /**< Index into current block of nodes */
4057
4058    GLvertexformat ListVtxfmt;
4059
4060    GLubyte ActiveAttribSize[VERT_ATTRIB_MAX];
4061    GLfloat CurrentAttrib[VERT_ATTRIB_MAX][4];
4062    
4063    GLubyte ActiveMaterialSize[MAT_ATTRIB_MAX];
4064    GLfloat CurrentMaterial[MAT_ATTRIB_MAX][4];
4065
4066    struct {
4067       /* State known to have been set by the currently-compiling display
4068        * list.  Used to eliminate some redundant state changes.
4069        */
4070       GLenum ShadeModel;
4071    } Current;
4072 };
4073
4074 /** @{
4075  *
4076  * These are a mapping of the GL_ARB_debug_output/GL_KHR_debug enums
4077  * to small enums suitable for use as an array index.
4078  */
4079
4080 enum mesa_debug_source {
4081    MESA_DEBUG_SOURCE_API,
4082    MESA_DEBUG_SOURCE_WINDOW_SYSTEM,
4083    MESA_DEBUG_SOURCE_SHADER_COMPILER,
4084    MESA_DEBUG_SOURCE_THIRD_PARTY,
4085    MESA_DEBUG_SOURCE_APPLICATION,
4086    MESA_DEBUG_SOURCE_OTHER,
4087    MESA_DEBUG_SOURCE_COUNT
4088 };
4089
4090 enum mesa_debug_type {
4091    MESA_DEBUG_TYPE_ERROR,
4092    MESA_DEBUG_TYPE_DEPRECATED,
4093    MESA_DEBUG_TYPE_UNDEFINED,
4094    MESA_DEBUG_TYPE_PORTABILITY,
4095    MESA_DEBUG_TYPE_PERFORMANCE,
4096    MESA_DEBUG_TYPE_OTHER,
4097    MESA_DEBUG_TYPE_MARKER,
4098    MESA_DEBUG_TYPE_PUSH_GROUP,
4099    MESA_DEBUG_TYPE_POP_GROUP,
4100    MESA_DEBUG_TYPE_COUNT
4101 };
4102
4103 enum mesa_debug_severity {
4104    MESA_DEBUG_SEVERITY_LOW,
4105    MESA_DEBUG_SEVERITY_MEDIUM,
4106    MESA_DEBUG_SEVERITY_HIGH,
4107    MESA_DEBUG_SEVERITY_NOTIFICATION,
4108    MESA_DEBUG_SEVERITY_COUNT
4109 };
4110
4111 /** @} */
4112
4113 /**
4114  * Driver-specific state flags.
4115  *
4116  * These are or'd with gl_context::NewDriverState to notify a driver about
4117  * a state change. The driver sets the flags at context creation and
4118  * the meaning of the bits set is opaque to core Mesa.
4119  */
4120 struct gl_driver_flags
4121 {
4122    /** gl_context::Array::_DrawArrays (vertex array state) */
4123    uint64_t NewArray;
4124
4125    /** gl_context::TransformFeedback::CurrentObject */
4126    uint64_t NewTransformFeedback;
4127
4128    /** gl_context::TransformFeedback::CurrentObject::shader_program */
4129    uint64_t NewTransformFeedbackProg;
4130
4131    /** gl_context::RasterDiscard */
4132    uint64_t NewRasterizerDiscard;
4133
4134    /**
4135     * gl_context::UniformBufferBindings
4136     * gl_shader_program::UniformBlocks
4137     */
4138    uint64_t NewUniformBuffer;
4139
4140    /**
4141     * gl_context::ShaderStorageBufferBindings
4142     * gl_shader_program::ShaderStorageBlocks
4143     */
4144    uint64_t NewShaderStorageBuffer;
4145
4146    uint64_t NewTextureBuffer;
4147
4148    /**
4149     * gl_context::AtomicBufferBindings
4150     */
4151    uint64_t NewAtomicBuffer;
4152
4153    /**
4154     * gl_context::ImageUnits
4155     */
4156    uint64_t NewImageUnits;
4157
4158    /**
4159     * gl_context::TessCtrlProgram::patch_default_*
4160     */
4161    uint64_t NewDefaultTessLevels;
4162 };
4163
4164 struct gl_uniform_buffer_binding
4165 {
4166    struct gl_buffer_object *BufferObject;
4167    /** Start of uniform block data in the buffer */
4168    GLintptr Offset;
4169    /** Size of data allowed to be referenced from the buffer (in bytes) */
4170    GLsizeiptr Size;
4171    /**
4172     * glBindBufferBase() indicates that the Size should be ignored and only
4173     * limited by the current size of the BufferObject.
4174     */
4175    GLboolean AutomaticSize;
4176 };
4177
4178 struct gl_shader_storage_buffer_binding
4179 {
4180    struct gl_buffer_object *BufferObject;
4181    /** Start of shader storage block data in the buffer */
4182    GLintptr Offset;
4183    /** Size of data allowed to be referenced from the buffer (in bytes) */
4184    GLsizeiptr Size;
4185    /**
4186     * glBindBufferBase() indicates that the Size should be ignored and only
4187     * limited by the current size of the BufferObject.
4188     */
4189    GLboolean AutomaticSize;
4190 };
4191
4192 /**
4193  * ARB_shader_image_load_store image unit.
4194  */
4195 struct gl_image_unit
4196 {
4197    /**
4198     * Texture object bound to this unit.
4199     */
4200    struct gl_texture_object *TexObj;
4201
4202    /**
4203     * Level of the texture object bound to this unit.
4204     */
4205    GLuint Level;
4206
4207    /**
4208     * \c GL_TRUE if the whole level is bound as an array of layers, \c
4209     * GL_FALSE if only some specific layer of the texture is bound.
4210     * \sa Layer
4211     */
4212    GLboolean Layered;
4213
4214    /**
4215     * Layer of the texture object bound to this unit as specified by the
4216     * application.
4217     */
4218    GLuint Layer;
4219
4220    /**
4221     * Layer of the texture object bound to this unit, or zero if the
4222     * whole level is bound.
4223     */
4224    GLuint _Layer;
4225
4226    /**
4227     * Access allowed to this texture image.  Either \c GL_READ_ONLY,
4228     * \c GL_WRITE_ONLY or \c GL_READ_WRITE.
4229     */
4230    GLenum Access;
4231
4232    /**
4233     * GL internal format that determines the interpretation of the
4234     * image memory when shader image operations are performed through
4235     * this unit.
4236     */
4237    GLenum Format;
4238
4239    /**
4240     * Mesa format corresponding to \c Format.
4241     */
4242    mesa_format _ActualFormat;
4243
4244 };
4245
4246 /**
4247  * Binding point for an atomic counter buffer object.
4248  */
4249 struct gl_atomic_buffer_binding
4250 {
4251    struct gl_buffer_object *BufferObject;
4252    GLintptr Offset;
4253    GLsizeiptr Size;
4254 };
4255
4256 /**
4257  * Mesa rendering context.
4258  *
4259  * This is the central context data structure for Mesa.  Almost all
4260  * OpenGL state is contained in this structure.
4261  * Think of this as a base class from which device drivers will derive
4262  * sub classes.
4263  */
4264 struct gl_context
4265 {
4266    /** State possibly shared with other contexts in the address space */
4267    struct gl_shared_state *Shared;
4268
4269    /** \name API function pointer tables */
4270    /*@{*/
4271    gl_api API;
4272    /**
4273     * The current dispatch table for non-displaylist-saving execution, either
4274     * BeginEnd or OutsideBeginEnd
4275     */
4276    struct _glapi_table *Exec;
4277    /**
4278     * The normal dispatch table for non-displaylist-saving, non-begin/end
4279     */
4280    struct _glapi_table *OutsideBeginEnd;
4281    /** The dispatch table used between glNewList() and glEndList() */
4282    struct _glapi_table *Save;
4283    /**
4284     * The dispatch table used between glBegin() and glEnd() (outside of a
4285     * display list).  Only valid functions between those two are set, which is
4286     * mostly just the set in a GLvertexformat struct.
4287     */
4288    struct _glapi_table *BeginEnd;
4289    /**
4290     * Tracks the current dispatch table out of the 3 above, so that it can be
4291     * re-set on glXMakeCurrent().
4292     */
4293    struct _glapi_table *CurrentDispatch;
4294    /*@}*/
4295
4296    struct gl_config Visual;
4297    struct gl_framebuffer *DrawBuffer;   /**< buffer for writing */
4298    struct gl_framebuffer *ReadBuffer;   /**< buffer for reading */
4299    struct gl_framebuffer *WinSysDrawBuffer;  /**< set with MakeCurrent */
4300    struct gl_framebuffer *WinSysReadBuffer;  /**< set with MakeCurrent */
4301
4302    /**
4303     * Device driver function pointer table
4304     */
4305    struct dd_function_table Driver;
4306
4307    /** Core/Driver constants */
4308    struct gl_constants Const;
4309
4310    /** \name The various 4x4 matrix stacks */
4311    /*@{*/
4312    struct gl_matrix_stack ModelviewMatrixStack;
4313    struct gl_matrix_stack ProjectionMatrixStack;
4314    struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS];
4315    struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
4316    struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
4317    /*@}*/
4318
4319    /** Combined modelview and projection matrix */
4320    GLmatrix _ModelProjectMatrix;
4321
4322    /** \name Display lists */
4323    struct gl_dlist_state ListState;
4324
4325    GLboolean ExecuteFlag;       /**< Execute GL commands? */
4326    GLboolean CompileFlag;       /**< Compile GL commands into display list? */
4327
4328    /** Extension information */
4329    struct gl_extensions Extensions;
4330
4331    /** GL version integer, for example 31 for GL 3.1, or 20 for GLES 2.0. */
4332    GLuint Version;
4333    char *VersionString;
4334
4335    /** \name State attribute stack (for glPush/PopAttrib) */
4336    /*@{*/
4337    GLuint AttribStackDepth;
4338    struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
4339    /*@}*/
4340
4341    /** \name Renderer attribute groups
4342     * 
4343     * We define a struct for each attribute group to make pushing and popping
4344     * attributes easy.  Also it's a good organization.
4345     */
4346    /*@{*/
4347    struct gl_accum_attrib       Accum;          /**< Accum buffer attributes */
4348    struct gl_colorbuffer_attrib Color;          /**< Color buffer attributes */
4349    struct gl_current_attrib     Current;        /**< Current attributes */
4350    struct gl_depthbuffer_attrib Depth;          /**< Depth buffer attributes */
4351    struct gl_eval_attrib        Eval;           /**< Eval attributes */
4352    struct gl_fog_attrib         Fog;            /**< Fog attributes */
4353    struct gl_hint_attrib        Hint;           /**< Hint attributes */
4354    struct gl_light_attrib       Light;          /**< Light attributes */
4355    struct gl_line_attrib        Line;           /**< Line attributes */
4356    struct gl_list_attrib        List;           /**< List attributes */
4357    struct gl_multisample_attrib Multisample;
4358    struct gl_pixel_attrib       Pixel;          /**< Pixel attributes */
4359    struct gl_point_attrib       Point;          /**< Point attributes */
4360    struct gl_polygon_attrib     Polygon;        /**< Polygon attributes */
4361    GLuint PolygonStipple[32];                   /**< Polygon stipple */
4362    struct gl_scissor_attrib     Scissor;        /**< Scissor attributes */
4363    struct gl_stencil_attrib     Stencil;        /**< Stencil buffer attributes */
4364    struct gl_texture_attrib     Texture;        /**< Texture attributes */
4365    struct gl_transform_attrib   Transform;      /**< Transformation attributes */
4366    struct gl_viewport_attrib    ViewportArray[MAX_VIEWPORTS];   /**< Viewport attributes */
4367    /*@}*/
4368
4369    /** \name Client attribute stack */
4370    /*@{*/
4371    GLuint ClientAttribStackDepth;
4372    struct gl_attrib_node *ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
4373    /*@}*/
4374
4375    /** \name Client attribute groups */
4376    /*@{*/
4377    struct gl_array_attrib       Array;  /**< Vertex arrays */
4378    struct gl_pixelstore_attrib  Pack;   /**< Pixel packing */
4379    struct gl_pixelstore_attrib  Unpack; /**< Pixel unpacking */
4380    struct gl_pixelstore_attrib  DefaultPacking; /**< Default params */
4381    /*@}*/
4382
4383    /** \name Other assorted state (not pushed/popped on attribute stack) */
4384    /*@{*/
4385    struct gl_pixelmaps          PixelMaps;
4386
4387    struct gl_evaluators EvalMap;   /**< All evaluators */
4388    struct gl_feedback   Feedback;  /**< Feedback */
4389    struct gl_selection  Select;    /**< Selection */
4390
4391    struct gl_program_state Program;  /**< general program state */
4392    struct gl_vertex_program_state VertexProgram;
4393    struct gl_fragment_program_state FragmentProgram;
4394    struct gl_geometry_program_state GeometryProgram;
4395    struct gl_compute_program_state ComputeProgram;
4396    struct gl_tess_ctrl_program_state TessCtrlProgram;
4397    struct gl_tess_eval_program_state TessEvalProgram;
4398    struct gl_ati_fragment_shader_state ATIFragmentShader;
4399
4400    struct gl_pipeline_shader_state Pipeline; /**< GLSL pipeline shader object state */
4401    struct gl_pipeline_object Shader; /**< GLSL shader object state */
4402
4403    /**
4404     * Current active shader pipeline state
4405     *
4406     * Almost all internal users want ::_Shader instead of ::Shader.  The
4407     * exceptions are bits of legacy GLSL API that do not know about separate
4408     * shader objects.
4409     *
4410     * If a program is active via \c glUseProgram, this will point to
4411     * \c ::Shader.
4412     *
4413     * If a program pipeline is active via \c glBindProgramPipeline, this will
4414     * point to \c ::Pipeline.Current.
4415     *
4416     * If neither a program nor a program pipeline is active, this will point to
4417     * \c ::Pipeline.Default.  This ensures that \c ::_Shader will never be
4418     * \c NULL.
4419     */
4420    struct gl_pipeline_object *_Shader;
4421
4422    struct gl_query_state Query;  /**< occlusion, timer queries */
4423
4424    struct gl_transform_feedback_state TransformFeedback;
4425
4426    struct gl_perf_monitor_state PerfMonitor;
4427
4428    struct gl_buffer_object *DrawIndirectBuffer; /** < GL_ARB_draw_indirect */
4429    struct gl_buffer_object *ParameterBuffer; /** < GL_ARB_indirect_parameters */
4430    struct gl_buffer_object *DispatchIndirectBuffer; /** < GL_ARB_compute_shader */
4431
4432    struct gl_buffer_object *CopyReadBuffer; /**< GL_ARB_copy_buffer */
4433    struct gl_buffer_object *CopyWriteBuffer; /**< GL_ARB_copy_buffer */
4434
4435    /**
4436     * Current GL_ARB_uniform_buffer_object binding referenced by
4437     * GL_UNIFORM_BUFFER target for glBufferData, glMapBuffer, etc.
4438     */
4439    struct gl_buffer_object *UniformBuffer;
4440
4441    /**
4442     * Current GL_ARB_shader_storage_buffer_object binding referenced by
4443     * GL_SHADER_STORAGE_BUFFER target for glBufferData, glMapBuffer, etc.
4444     */
4445    struct gl_buffer_object *ShaderStorageBuffer;
4446
4447    /**
4448     * Array of uniform buffers for GL_ARB_uniform_buffer_object and GL 3.1.
4449     * This is set up using glBindBufferRange() or glBindBufferBase().  They are
4450     * associated with uniform blocks by glUniformBlockBinding()'s state in the
4451     * shader program.
4452     */
4453    struct gl_uniform_buffer_binding
4454       UniformBufferBindings[MAX_COMBINED_UNIFORM_BUFFERS];
4455
4456    /**
4457     * Array of shader storage buffers for ARB_shader_storage_buffer_object
4458     * and GL 4.3. This is set up using glBindBufferRange() or
4459     * glBindBufferBase().  They are associated with shader storage blocks by
4460     * glShaderStorageBlockBinding()'s state in the shader program.
4461     */
4462    struct gl_shader_storage_buffer_binding
4463       ShaderStorageBufferBindings[MAX_COMBINED_SHADER_STORAGE_BUFFERS];
4464
4465    /**
4466     * Object currently associated with the GL_ATOMIC_COUNTER_BUFFER
4467     * target.
4468     */
4469    struct gl_buffer_object *AtomicBuffer;
4470
4471    /**
4472     * Object currently associated w/ the GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
4473     * target.
4474     */
4475    struct gl_buffer_object *ExternalVirtualMemoryBuffer;
4476
4477    /**
4478     * Array of atomic counter buffer binding points.
4479     */
4480    struct gl_atomic_buffer_binding
4481       AtomicBufferBindings[MAX_COMBINED_ATOMIC_BUFFERS];
4482
4483    /**
4484     * Array of image units for ARB_shader_image_load_store.
4485     */
4486    struct gl_image_unit ImageUnits[MAX_IMAGE_UNITS];
4487
4488    /*@}*/
4489
4490    struct gl_meta_state *Meta;  /**< for "meta" operations */
4491
4492    /* GL_EXT_framebuffer_object */
4493    struct gl_renderbuffer *CurrentRenderbuffer;
4494
4495    GLenum ErrorValue;        /**< Last error code */
4496
4497    /**
4498     * Recognize and silence repeated error debug messages in buggy apps.
4499     */
4500    const char *ErrorDebugFmtString;
4501    GLuint ErrorDebugCount;
4502
4503    /* GL_ARB_debug_output/GL_KHR_debug */
4504    mtx_t DebugMutex;
4505    struct gl_debug_state *Debug;
4506
4507    GLenum RenderMode;        /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
4508    GLbitfield NewState;      /**< bitwise-or of _NEW_* flags */
4509    uint64_t NewDriverState;  /**< bitwise-or of flags from DriverFlags */
4510
4511    struct gl_driver_flags DriverFlags;
4512
4513    GLboolean ViewportInitialized;  /**< has viewport size been initialized? */
4514
4515    GLbitfield64 varying_vp_inputs;  /**< mask of VERT_BIT_* flags */
4516
4517    /** \name Derived state */
4518    GLbitfield _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
4519    GLfloat _EyeZDir[3];
4520    GLfloat _ModelViewInvScale;
4521    GLboolean _NeedEyeCoords;
4522    GLboolean _ForceEyeCoords; 
4523
4524    GLuint TextureStateTimestamp; /**< detect changes to shared state */
4525
4526    struct gl_list_extensions *ListExt; /**< driver dlist extensions */
4527
4528    /** \name For debugging/development only */
4529    /*@{*/
4530    GLboolean FirstTimeCurrent;
4531    /*@}*/
4532
4533    /**
4534     * False if this context was created without a config. This is needed
4535     * because the initial state of glDrawBuffers depends on this
4536     */
4537    GLboolean HasConfig;
4538
4539    /** software compression/decompression supported or not */
4540    GLboolean Mesa_DXTn;
4541
4542    GLboolean TextureFormatSupported[MESA_FORMAT_COUNT];
4543
4544    GLboolean RasterDiscard;  /**< GL_RASTERIZER_DISCARD */
4545
4546    /**
4547     * \name Hooks for module contexts.  
4548     *
4549     * These will eventually live in the driver or elsewhere.
4550     */
4551    /*@{*/
4552    void *swrast_context;
4553    void *swsetup_context;
4554    void *swtnl_context;
4555    struct vbo_context *vbo_context;
4556    struct st_context *st;
4557    void *aelt_context;
4558    /*@}*/
4559
4560    /**
4561     * \name NV_vdpau_interop
4562     */
4563    /*@{*/
4564    const void *vdpDevice;
4565    const void *vdpGetProcAddress;
4566    struct set *vdpSurfaces;
4567    /*@}*/
4568
4569    /**
4570     * Has this context observed a GPU reset in any context in the share group?
4571     *
4572     * Once this field becomes true, it is never reset to false.
4573     */
4574    GLboolean ShareGroupReset;
4575 };
4576
4577
4578 #ifdef DEBUG
4579 extern int MESA_VERBOSE;
4580 extern int MESA_DEBUG_FLAGS;
4581 # define MESA_FUNCTION __func__
4582 #else
4583 # define MESA_VERBOSE 0
4584 # define MESA_DEBUG_FLAGS 0
4585 # define MESA_FUNCTION "a function"
4586 #endif
4587
4588
4589 /** The MESA_VERBOSE var is a bitmask of these flags */
4590 enum _verbose
4591 {
4592    VERBOSE_VARRAY               = 0x0001,
4593    VERBOSE_TEXTURE              = 0x0002,
4594    VERBOSE_MATERIAL             = 0x0004,
4595    VERBOSE_PIPELINE             = 0x0008,
4596    VERBOSE_DRIVER               = 0x0010,
4597    VERBOSE_STATE                = 0x0020,
4598    VERBOSE_API                  = 0x0040,
4599    VERBOSE_DISPLAY_LIST         = 0x0100,
4600    VERBOSE_LIGHTING             = 0x0200,
4601    VERBOSE_PRIMS                = 0x0400,
4602    VERBOSE_VERTS                = 0x0800,
4603    VERBOSE_DISASSEM             = 0x1000,
4604    VERBOSE_DRAW                 = 0x2000,
4605    VERBOSE_SWAPBUFFERS          = 0x4000
4606 };
4607
4608
4609 /** The MESA_DEBUG_FLAGS var is a bitmask of these flags */
4610 enum _debug
4611 {
4612    DEBUG_SILENT                 = (1 << 0),
4613    DEBUG_ALWAYS_FLUSH           = (1 << 1),
4614    DEBUG_INCOMPLETE_TEXTURE     = (1 << 2),
4615    DEBUG_INCOMPLETE_FBO         = (1 << 3)
4616 };
4617
4618 /**
4619  * Checks if the active fragment shader program can have side effects due
4620  * to use of things like atomic buffers or images
4621  */
4622 static inline bool
4623 _mesa_active_fragment_shader_has_side_effects(const struct gl_context *ctx)
4624 {
4625    const struct gl_shader *sh;
4626
4627    if (!ctx->_Shader->_CurrentFragmentProgram)
4628       return false;
4629
4630    sh = ctx->_Shader->_CurrentFragmentProgram->_LinkedShaders[MESA_SHADER_FRAGMENT];
4631    return sh->NumAtomicBuffers > 0 ||
4632           sh->NumImages > 0 ||
4633           sh->NumShaderStorageBlocks > 0;
4634 }
4635
4636 #ifdef __cplusplus
4637 }
4638 #endif
4639
4640 #endif /* MTYPES_H */