• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/glthread.h"
43 #include "main/consts_exts.h"
44 #include "main/shader_types.h"
45 #include "main/glconfig.h"
46 #include "main/menums.h"
47 #include "main/config.h"
48 #include "glapi/glapi.h"
49 #include "math/m_matrix.h"	/* GLmatrix */
50 #include "compiler/shader_enums.h"
51 #include "compiler/shader_info.h"
52 #include "main/formats.h"       /* MESA_FORMAT_COUNT */
53 #include "compiler/glsl/list.h"
54 #include "compiler/glsl/ir_uniform.h"
55 #include "util/u_idalloc.h"
56 #include "util/simple_mtx.h"
57 #include "util/u_dynarray.h"
58 #include "util/mesa-sha1.h"
59 #include "vbo/vbo.h"
60 
61 #include "pipe/p_state.h"
62 
63 #include "frontend/api.h"
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 #define GET_COLORMASK_BIT(mask, buf, chan) (((mask) >> (4 * (buf) + (chan))) & 0x1)
70 #define GET_COLORMASK(mask, buf) (((mask) >> (4 * (buf))) & 0xf)
71 
72 
73 /**
74  * \name Some forward type declarations
75  */
76 /*@{*/
77 struct _mesa_HashTable;
78 struct gl_attrib_node;
79 struct gl_list_extensions;
80 struct gl_meta_state;
81 struct gl_program_cache;
82 struct gl_texture_object;
83 struct gl_debug_state;
84 struct gl_context;
85 struct st_context;
86 struct gl_uniform_storage;
87 struct prog_instruction;
88 struct gl_program_parameter_list;
89 struct gl_shader_spirv_data;
90 struct set;
91 struct shader_includes;
92 /*@}*/
93 
94 
95 /** Extra draw modes beyond GL_POINTS, GL_TRIANGLE_FAN, etc */
96 #define PRIM_MAX                 GL_PATCHES
97 #define PRIM_OUTSIDE_BEGIN_END   (PRIM_MAX + 1)
98 #define PRIM_UNKNOWN             (PRIM_MAX + 2)
99 
100 /**
101  * Bit flags for all renderbuffers
102  */
103 #define BUFFER_BIT_FRONT_LEFT   (1 << BUFFER_FRONT_LEFT)
104 #define BUFFER_BIT_BACK_LEFT    (1 << BUFFER_BACK_LEFT)
105 #define BUFFER_BIT_FRONT_RIGHT  (1 << BUFFER_FRONT_RIGHT)
106 #define BUFFER_BIT_BACK_RIGHT   (1 << BUFFER_BACK_RIGHT)
107 #define BUFFER_BIT_DEPTH        (1 << BUFFER_DEPTH)
108 #define BUFFER_BIT_STENCIL      (1 << BUFFER_STENCIL)
109 #define BUFFER_BIT_ACCUM        (1 << BUFFER_ACCUM)
110 #define BUFFER_BIT_COLOR0       (1 << BUFFER_COLOR0)
111 #define BUFFER_BIT_COLOR1       (1 << BUFFER_COLOR1)
112 #define BUFFER_BIT_COLOR2       (1 << BUFFER_COLOR2)
113 #define BUFFER_BIT_COLOR3       (1 << BUFFER_COLOR3)
114 #define BUFFER_BIT_COLOR4       (1 << BUFFER_COLOR4)
115 #define BUFFER_BIT_COLOR5       (1 << BUFFER_COLOR5)
116 #define BUFFER_BIT_COLOR6       (1 << BUFFER_COLOR6)
117 #define BUFFER_BIT_COLOR7       (1 << BUFFER_COLOR7)
118 
119 /**
120  * Mask of all the color buffer bits (but not accum).
121  */
122 #define BUFFER_BITS_COLOR  (BUFFER_BIT_FRONT_LEFT | \
123                             BUFFER_BIT_BACK_LEFT | \
124                             BUFFER_BIT_FRONT_RIGHT | \
125                             BUFFER_BIT_BACK_RIGHT | \
126                             BUFFER_BIT_COLOR0 | \
127                             BUFFER_BIT_COLOR1 | \
128                             BUFFER_BIT_COLOR2 | \
129                             BUFFER_BIT_COLOR3 | \
130                             BUFFER_BIT_COLOR4 | \
131                             BUFFER_BIT_COLOR5 | \
132                             BUFFER_BIT_COLOR6 | \
133                             BUFFER_BIT_COLOR7)
134 
135 /* Mask of bits for depth+stencil buffers */
136 #define BUFFER_BITS_DEPTH_STENCIL (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)
137 
138 
139 #define FRONT_MATERIAL_BITS   (MAT_BIT_FRONT_EMISSION | \
140                                MAT_BIT_FRONT_AMBIENT | \
141                                MAT_BIT_FRONT_DIFFUSE | \
142                                MAT_BIT_FRONT_SPECULAR | \
143                                MAT_BIT_FRONT_SHININESS | \
144                                MAT_BIT_FRONT_INDEXES)
145 
146 #define BACK_MATERIAL_BITS    (MAT_BIT_BACK_EMISSION | \
147                                MAT_BIT_BACK_AMBIENT | \
148                                MAT_BIT_BACK_DIFFUSE | \
149                                MAT_BIT_BACK_SPECULAR | \
150                                MAT_BIT_BACK_SHININESS | \
151                                MAT_BIT_BACK_INDEXES)
152 
153 #define ALL_MATERIAL_BITS     (FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
154 /*@}*/
155 
156 
157 /**
158  * Material state.
159  */
160 struct gl_material
161 {
162    GLfloat Attrib[MAT_ATTRIB_MAX][4];
163 };
164 
165 
166 /**
167  * Light state flags.
168  */
169 /*@{*/
170 #define LIGHT_SPOT         0x1
171 #define LIGHT_LOCAL_VIEWER 0x2
172 #define LIGHT_POSITIONAL   0x4
173 #define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
174 /*@}*/
175 
176 
177 /**
178  * Light source state.
179  */
180 struct gl_light
181 {
182    GLboolean Enabled;		/**< On/off flag */
183 
184    /**
185     * \name Derived fields
186     */
187    /*@{*/
188    GLbitfield _Flags;		/**< Mask of LIGHT_x bits defined above */
189 
190    GLfloat _Position[4];	/**< position in eye/obj coordinates */
191    GLfloat _VP_inf_norm[3];	/**< Norm direction to infinite light */
192    GLfloat _h_inf_norm[3];	/**< Norm( _VP_inf_norm + <0,0,1> ) */
193    GLfloat _NormSpotDirection[4]; /**< normalized spotlight direction */
194    GLfloat _VP_inf_spot_attenuation;
195 
196    GLfloat _MatAmbient[2][3];	/**< material ambient * light ambient */
197    GLfloat _MatDiffuse[2][3];	/**< material diffuse * light diffuse */
198    GLfloat _MatSpecular[2][3];	/**< material spec * light specular */
199    /*@}*/
200 };
201 
202 
203 /**
204  * Light model state.
205  */
206 struct gl_lightmodel
207 {
208    GLfloat Ambient[4];		/**< ambient color */
209    GLboolean LocalViewer;	/**< Local (or infinite) view point? */
210    GLboolean TwoSide;		/**< Two (or one) sided lighting? */
211    GLenum16 ColorControl;	/**< either GL_SINGLE_COLOR
212                                      or GL_SEPARATE_SPECULAR_COLOR */
213 };
214 
215 
216 /**
217  * Accumulation buffer attribute group (GL_ACCUM_BUFFER_BIT)
218  */
219 struct gl_accum_attrib
220 {
221    GLfloat ClearColor[4];	/**< Accumulation buffer clear color */
222 };
223 
224 
225 /**
226  * Used for storing clear color, texture border color, etc.
227  * The float values are typically unclamped.
228  */
229 union gl_color_union
230 {
231    GLfloat f[4];
232    GLint i[4];
233    GLuint ui[4];
234 };
235 
236 
237 /**
238  * Color buffer attribute group (GL_COLOR_BUFFER_BIT).
239  */
240 struct gl_colorbuffer_attrib
241 {
242    GLuint ClearIndex;                      /**< Index for glClear */
243    union gl_color_union ClearColor;        /**< Color for glClear, unclamped */
244    GLuint IndexMask;                       /**< Color index write mask */
245 
246    /** 4 colormask bits per draw buffer, max 8 draw buffers. 4*8 = 32 bits */
247    GLbitfield ColorMask;
248 
249    GLenum16 DrawBuffer[MAX_DRAW_BUFFERS];  /**< Which buffer to draw into */
250 
251    /**
252     * \name alpha testing
253     */
254    /*@{*/
255    GLboolean AlphaEnabled;		/**< Alpha test enabled flag */
256    GLenum16 AlphaFunc;			/**< Alpha test function */
257    GLfloat AlphaRefUnclamped;
258    GLclampf AlphaRef;			/**< Alpha reference value */
259    /*@}*/
260 
261    /**
262     * \name Blending
263     */
264    /*@{*/
265    GLbitfield BlendEnabled;		/**< Per-buffer blend enable flags */
266 
267    /* NOTE: this does _not_ depend on fragment clamping or any other clamping
268     * control, only on the fixed-pointness of the render target.
269     * The query does however depend on fragment color clamping.
270     */
271    GLfloat BlendColorUnclamped[4];      /**< Blending color */
272    GLfloat BlendColor[4];		/**< Blending color */
273 
274    struct
275    {
276       GLenum16 SrcRGB;             /**< RGB blend source term */
277       GLenum16 DstRGB;             /**< RGB blend dest term */
278       GLenum16 SrcA;               /**< Alpha blend source term */
279       GLenum16 DstA;               /**< Alpha blend dest term */
280       GLenum16 EquationRGB;        /**< GL_ADD, GL_SUBTRACT, etc. */
281       GLenum16 EquationA;          /**< GL_ADD, GL_SUBTRACT, etc. */
282    } Blend[MAX_DRAW_BUFFERS];
283    /** Bitfield of color buffers with enabled dual source blending. */
284    GLbitfield _BlendUsesDualSrc;
285    /** Are the blend func terms currently different for each buffer/target? */
286    GLboolean _BlendFuncPerBuffer;
287    /** Are the blend equations currently different for each buffer/target? */
288    GLboolean _BlendEquationPerBuffer;
289 
290    /**
291     * Which advanced blending mode is in use (or BLEND_NONE).
292     *
293     * KHR_blend_equation_advanced only allows advanced blending with a single
294     * draw buffer, and NVX_blend_equation_advanced_multi_draw_buffer still
295     * requires all draw buffers to match, so we only need a single value.
296     */
297    enum gl_advanced_blend_mode _AdvancedBlendMode;
298 
299    /** Coherency requested via glEnable(GL_BLEND_ADVANCED_COHERENT_KHR)? */
300    bool BlendCoherent;
301    /*@}*/
302 
303    /**
304     * \name Logic op
305     */
306    /*@{*/
307    GLboolean IndexLogicOpEnabled;	/**< Color index logic op enabled flag */
308    GLboolean ColorLogicOpEnabled;	/**< RGBA logic op enabled flag */
309    GLenum16 LogicOp;			/**< Logic operator */
310    enum gl_logicop_mode _LogicOp;
311    /*@}*/
312 
313    GLboolean DitherFlag;           /**< Dither enable flag */
314 
315    GLboolean _ClampFragmentColor;  /** < with GL_FIXED_ONLY_ARB resolved */
316    GLenum16 ClampFragmentColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
317    GLenum16 ClampReadColor;     /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
318 
319    GLboolean sRGBEnabled;  /**< Framebuffer sRGB blending/updating requested */
320 };
321 
322 
323 /**
324  * Vertex format to describe a vertex element.
325  */
326 struct gl_vertex_format
327 {
328    GLenum16 Type;        /**< datatype: GL_FLOAT, GL_INT, etc */
329    GLenum16 Format;      /**< default: GL_RGBA, but may be GL_BGRA */
330    enum pipe_format _PipeFormat:16; /**< pipe_format for Gallium */
331    GLubyte Size:5;       /**< components per element (1,2,3,4) */
332    GLubyte Normalized:1; /**< GL_ARB_vertex_program */
333    GLubyte Integer:1;    /**< Integer-valued? */
334    GLubyte Doubles:1;    /**< double values are not converted to floats */
335    GLubyte _ElementSize; /**< Size of each element in bytes */
336 };
337 
338 
339 /**
340  * Current attribute group (GL_CURRENT_BIT).
341  */
342 struct gl_current_attrib
343 {
344    /**
345     * \name Current vertex attributes (color, texcoords, etc).
346     * \note Values are valid only after FLUSH_VERTICES has been called.
347     * \note Index and Edgeflag current values are stored as floats in the
348     * SIX and SEVEN attribute slots.
349     * \note We need double storage for 64-bit vertex attributes
350     */
351    GLfloat Attrib[VERT_ATTRIB_MAX][4*2];
352 
353    /**
354     * \name Current raster position attributes (always up to date after a
355     * glRasterPos call).
356     */
357    GLfloat RasterPos[4];
358    GLfloat RasterDistance;
359    GLfloat RasterColor[4];
360    GLfloat RasterSecondaryColor[4];
361    GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
362    GLboolean RasterPosValid;
363 };
364 
365 
366 /**
367  * Depth buffer attribute group (GL_DEPTH_BUFFER_BIT).
368  */
369 struct gl_depthbuffer_attrib
370 {
371    GLenum16 Func;		/**< Function for depth buffer compare */
372    GLclampd Clear;		/**< Value to clear depth buffer to */
373    GLboolean Test;		/**< Depth buffering enabled flag */
374    GLboolean Mask;		/**< Depth buffer writable? */
375    GLboolean BoundsTest;        /**< GL_EXT_depth_bounds_test */
376    GLclampd BoundsMin, BoundsMax;/**< GL_EXT_depth_bounds_test */
377 };
378 
379 
380 /**
381  * Evaluator attribute group (GL_EVAL_BIT).
382  */
383 struct gl_eval_attrib
384 {
385    /**
386     * \name Enable bits
387     */
388    /*@{*/
389    GLboolean Map1Color4;
390    GLboolean Map1Index;
391    GLboolean Map1Normal;
392    GLboolean Map1TextureCoord1;
393    GLboolean Map1TextureCoord2;
394    GLboolean Map1TextureCoord3;
395    GLboolean Map1TextureCoord4;
396    GLboolean Map1Vertex3;
397    GLboolean Map1Vertex4;
398    GLboolean Map2Color4;
399    GLboolean Map2Index;
400    GLboolean Map2Normal;
401    GLboolean Map2TextureCoord1;
402    GLboolean Map2TextureCoord2;
403    GLboolean Map2TextureCoord3;
404    GLboolean Map2TextureCoord4;
405    GLboolean Map2Vertex3;
406    GLboolean Map2Vertex4;
407    GLboolean AutoNormal;
408    /*@}*/
409 
410    /**
411     * \name Map Grid endpoints and divisions and calculated du values
412     */
413    /*@{*/
414    GLint MapGrid1un;
415    GLfloat MapGrid1u1, MapGrid1u2, MapGrid1du;
416    GLint MapGrid2un, MapGrid2vn;
417    GLfloat MapGrid2u1, MapGrid2u2, MapGrid2du;
418    GLfloat MapGrid2v1, MapGrid2v2, MapGrid2dv;
419    /*@}*/
420 };
421 
422 
423 /**
424  * Compressed fog mode.
425  */
426 enum gl_fog_mode
427 {
428    FOG_NONE,
429    FOG_LINEAR,
430    FOG_EXP,
431    FOG_EXP2,
432 };
433 
434 
435 /**
436  * Fog attribute group (GL_FOG_BIT).
437  */
438 struct gl_fog_attrib
439 {
440    GLboolean Enabled;		/**< Fog enabled flag */
441    GLboolean ColorSumEnabled;
442    uint8_t _PackedMode;		/**< Fog mode as 2 bits */
443    uint8_t _PackedEnabledMode;	/**< Masked CompressedMode */
444    GLfloat ColorUnclamped[4];            /**< Fog color */
445    GLfloat Color[4];		/**< Fog color */
446    GLfloat Density;		/**< Density >= 0.0 */
447    GLfloat Start;		/**< Start distance in eye coords */
448    GLfloat End;			/**< End distance in eye coords */
449    GLfloat Index;		/**< Fog index */
450    GLenum16 Mode;		/**< Fog mode */
451    GLenum16 FogCoordinateSource;/**< GL_EXT_fog_coord */
452    GLenum16 FogDistanceMode;     /**< GL_NV_fog_distance */
453 };
454 
455 
456 /**
457  * Hint attribute group (GL_HINT_BIT).
458  *
459  * Values are always one of GL_FASTEST, GL_NICEST, or GL_DONT_CARE.
460  */
461 struct gl_hint_attrib
462 {
463    GLenum16 PerspectiveCorrection;
464    GLenum16 PointSmooth;
465    GLenum16 LineSmooth;
466    GLenum16 PolygonSmooth;
467    GLenum16 Fog;
468    GLenum16 TextureCompression;   /**< GL_ARB_texture_compression */
469    GLenum16 GenerateMipmap;       /**< GL_SGIS_generate_mipmap */
470    GLenum16 FragmentShaderDerivative; /**< GL_ARB_fragment_shader */
471    GLuint MaxShaderCompilerThreads; /**< GL_ARB_parallel_shader_compile */
472 };
473 
474 
475 struct gl_light_uniforms {
476    /* These must be in the same order as the STATE_* enums,
477     * which should also match the order of gl_LightSource members.
478     */
479    GLfloat Ambient[4];           /**< STATE_AMBIENT */
480    GLfloat Diffuse[4];           /**< STATE_DIFFUSE */
481    GLfloat Specular[4];          /**< STATE_SPECULAR */
482    GLfloat EyePosition[4];       /**< STATE_POSITION in eye coordinates */
483    GLfloat _HalfVector[4];       /**< STATE_HALF_VECTOR */
484    GLfloat SpotDirection[3];     /**< STATE_SPOT_DIRECTION in eye coordinates */
485    GLfloat _CosCutoff;           /**< = MAX(0, cos(SpotCutoff)) */
486    GLfloat ConstantAttenuation;  /**< STATE_ATTENUATION */
487    GLfloat LinearAttenuation;
488    GLfloat QuadraticAttenuation;
489    GLfloat SpotExponent;
490    GLfloat SpotCutoff;           /**< STATE_SPOT_CUTOFF in degrees */
491 };
492 
493 
494 /**
495  * Lighting attribute group (GL_LIGHT_BIT).
496  */
497 struct gl_light_attrib
498 {
499    /* gl_LightSource uniforms */
500    union {
501       struct gl_light_uniforms LightSource[MAX_LIGHTS];
502       GLfloat LightSourceData[(sizeof(struct gl_light_uniforms) / 4) * MAX_LIGHTS];
503    };
504 
505    struct gl_light Light[MAX_LIGHTS];	/**< Array of light sources */
506    struct gl_lightmodel Model;		/**< Lighting model */
507 
508    /**
509     * Front and back material values.
510     * Note: must call FLUSH_VERTICES() before using.
511     */
512    struct gl_material Material;
513 
514    GLboolean Enabled;			/**< Lighting enabled flag */
515    GLboolean ColorMaterialEnabled;
516 
517    GLenum16 ShadeModel;			/**< GL_FLAT or GL_SMOOTH */
518    GLenum16 ProvokingVertex;              /**< GL_EXT_provoking_vertex */
519    GLenum16 ColorMaterialFace;		/**< GL_FRONT, BACK or FRONT_AND_BACK */
520    GLenum16 ColorMaterialMode;		/**< GL_AMBIENT, GL_DIFFUSE, etc */
521    GLbitfield _ColorMaterialBitmask;	/**< bitmask formed from Face and Mode */
522 
523 
524    GLboolean _ClampVertexColor;
525    GLenum16 ClampVertexColor;             /**< GL_TRUE, GL_FALSE, GL_FIXED_ONLY */
526 
527    /**
528     * Derived state for optimizations:
529     */
530    /*@{*/
531    GLbitfield _EnabledLights;	/**< bitmask containing enabled lights */
532 
533    GLboolean _NeedEyeCoords;
534    GLboolean _NeedVertices;		/**< Use fast shader? */
535 
536    GLfloat _BaseColor[2][3];
537    /*@}*/
538 };
539 
540 
541 /**
542  * Line attribute group (GL_LINE_BIT).
543  */
544 struct gl_line_attrib
545 {
546    GLboolean SmoothFlag;	/**< GL_LINE_SMOOTH enabled? */
547    GLboolean StippleFlag;	/**< GL_LINE_STIPPLE enabled? */
548    GLushort StipplePattern;	/**< Stipple pattern */
549    GLint StippleFactor;		/**< Stipple repeat factor */
550    GLfloat Width;		/**< Line width */
551 };
552 
553 
554 /**
555  * Display list attribute group (GL_LIST_BIT).
556  */
557 struct gl_list_attrib
558 {
559    GLuint ListBase;
560 };
561 
562 
563 /**
564  * Multisample attribute group (GL_MULTISAMPLE_BIT).
565  */
566 struct gl_multisample_attrib
567 {
568    GLboolean Enabled;
569    GLboolean SampleAlphaToCoverage;
570    GLboolean SampleAlphaToOne;
571    GLboolean SampleCoverage;
572    GLboolean SampleCoverageInvert;
573    GLboolean SampleShading;
574 
575    /* ARB_texture_multisample / GL3.2 additions */
576    GLboolean SampleMask;
577 
578    GLfloat SampleCoverageValue;  /**< In range [0, 1] */
579    GLfloat MinSampleShadingValue;  /**< In range [0, 1] */
580 
581    /** The GL spec defines this as an array but >32x MSAA is madness */
582    GLbitfield SampleMaskValue;
583 
584    /* NV_alpha_to_coverage_dither_control */
585    GLenum SampleAlphaToCoverageDitherControl;
586 };
587 
588 
589 /**
590  * A pixelmap (see glPixelMap)
591  */
592 struct gl_pixelmap
593 {
594    GLint Size;
595    GLfloat Map[MAX_PIXEL_MAP_TABLE];
596 };
597 
598 
599 /**
600  * Collection of all pixelmaps
601  */
602 struct gl_pixelmaps
603 {
604    struct gl_pixelmap RtoR;  /**< i.e. GL_PIXEL_MAP_R_TO_R */
605    struct gl_pixelmap GtoG;
606    struct gl_pixelmap BtoB;
607    struct gl_pixelmap AtoA;
608    struct gl_pixelmap ItoR;
609    struct gl_pixelmap ItoG;
610    struct gl_pixelmap ItoB;
611    struct gl_pixelmap ItoA;
612    struct gl_pixelmap ItoI;
613    struct gl_pixelmap StoS;
614 };
615 
616 
617 /**
618  * Pixel attribute group (GL_PIXEL_MODE_BIT).
619  */
620 struct gl_pixel_attrib
621 {
622    GLenum16 ReadBuffer;		/**< source buffer for glRead/CopyPixels() */
623 
624    /*--- Begin Pixel Transfer State ---*/
625    /* Fields are in the order in which they're applied... */
626 
627    /** Scale & Bias (index shift, offset) */
628    /*@{*/
629    GLfloat RedBias, RedScale;
630    GLfloat GreenBias, GreenScale;
631    GLfloat BlueBias, BlueScale;
632    GLfloat AlphaBias, AlphaScale;
633    GLfloat DepthBias, DepthScale;
634    GLint IndexShift, IndexOffset;
635    /*@}*/
636 
637    /* Pixel Maps */
638    /* Note: actual pixel maps are not part of this attrib group */
639    GLboolean MapColorFlag;
640    GLboolean MapStencilFlag;
641 
642    /*--- End Pixel Transfer State ---*/
643 
644    /** glPixelZoom */
645    GLfloat ZoomX, ZoomY;
646 };
647 
648 
649 /**
650  * Point attribute group (GL_POINT_BIT).
651  */
652 struct gl_point_attrib
653 {
654    GLfloat Size;		/**< User-specified point size */
655    GLfloat Params[3];		/**< GL_EXT_point_parameters */
656    GLfloat MinSize, MaxSize;	/**< GL_EXT_point_parameters */
657    GLfloat Threshold;		/**< GL_EXT_point_parameters */
658    GLboolean SmoothFlag;	/**< True if GL_POINT_SMOOTH is enabled */
659    GLboolean _Attenuated;	/**< True if Params != [1, 0, 0] */
660    GLboolean PointSprite;	/**< GL_NV/ARB_point_sprite */
661    GLbitfield CoordReplace;     /**< GL_ARB_point_sprite*/
662    GLenum16 SpriteOrigin;	/**< GL_ARB_point_sprite */
663 };
664 
665 
666 /**
667  * Polygon attribute group (GL_POLYGON_BIT).
668  */
669 struct gl_polygon_attrib
670 {
671    GLenum16 FrontFace;		/**< Either GL_CW or GL_CCW */
672    GLenum FrontMode;		/**< Either GL_POINT, GL_LINE or GL_FILL */
673    GLenum BackMode;		/**< Either GL_POINT, GL_LINE or GL_FILL */
674    GLboolean CullFlag;		/**< Culling on/off flag */
675    GLboolean SmoothFlag;	/**< True if GL_POLYGON_SMOOTH is enabled */
676    GLboolean StippleFlag;	/**< True if GL_POLYGON_STIPPLE is enabled */
677    GLenum16 CullFaceMode;	/**< Culling mode GL_FRONT or GL_BACK */
678    GLfloat OffsetFactor;	/**< Polygon offset factor, from user */
679    GLfloat OffsetUnits;		/**< Polygon offset units, from user */
680    GLfloat OffsetClamp;		/**< Polygon offset clamp, from user */
681    GLboolean OffsetPoint;	/**< Offset in GL_POINT mode */
682    GLboolean OffsetLine;	/**< Offset in GL_LINE mode */
683    GLboolean OffsetFill;	/**< Offset in GL_FILL mode */
684 };
685 
686 
687 /**
688  * Scissor attributes (GL_SCISSOR_BIT).
689  */
690 struct gl_scissor_rect
691 {
692    GLint X, Y;			/**< Lower left corner of box */
693    GLsizei Width, Height;	/**< Size of box */
694 };
695 
696 
697 struct gl_scissor_attrib
698 {
699    GLbitfield EnableFlags;	/**< Scissor test enabled? */
700    struct gl_scissor_rect ScissorArray[MAX_VIEWPORTS];
701    GLint NumWindowRects;        /**< Count of enabled window rectangles */
702    GLenum16 WindowRectMode;     /**< Whether to include or exclude the rects */
703    struct gl_scissor_rect WindowRects[MAX_WINDOW_RECTANGLES];
704 };
705 
706 
707 /**
708  * Stencil attribute group (GL_STENCIL_BUFFER_BIT).
709  *
710  * Three sets of stencil data are tracked so that OpenGL 2.0,
711  * GL_EXT_stencil_two_side, and GL_ATI_separate_stencil can all be supported
712  * simultaneously.  In each of the stencil state arrays, element 0 corresponds
713  * to GL_FRONT.  Element 1 corresponds to the OpenGL 2.0 /
714  * GL_ATI_separate_stencil GL_BACK state.  Element 2 corresponds to the
715  * GL_EXT_stencil_two_side GL_BACK state.
716  *
717  * The derived value \c _BackFace is either 1 or 2 depending on whether or
718  * not GL_STENCIL_TEST_TWO_SIDE_EXT is enabled.
719  *
720  * The derived value \c _TestTwoSide is set when the front-face and back-face
721  * stencil state are different.
722  */
723 struct gl_stencil_attrib
724 {
725    GLboolean Enabled;		/**< Enabled flag */
726    GLboolean TestTwoSide;	/**< GL_EXT_stencil_two_side */
727    GLubyte ActiveFace;		/**< GL_EXT_stencil_two_side (0 or 2) */
728    GLubyte _BackFace;           /**< Current back stencil state (1 or 2) */
729    GLenum16 Function[3];	/**< Stencil function */
730    GLenum16 FailFunc[3];	/**< Fail function */
731    GLenum16 ZPassFunc[3];	/**< Depth buffer pass function */
732    GLenum16 ZFailFunc[3];	/**< Depth buffer fail function */
733    GLint Ref[3];		/**< Reference value */
734    GLuint ValueMask[3];		/**< Value mask */
735    GLuint WriteMask[3];		/**< Write mask */
736    GLuint Clear;		/**< Clear value */
737 };
738 
739 
740 /**
741  * Bit flags for each type of texture object
742  */
743 /*@{*/
744 #define TEXTURE_2D_MULTISAMPLE_BIT (1 << TEXTURE_2D_MULTISAMPLE_INDEX)
745 #define TEXTURE_2D_MULTISAMPLE_ARRAY_BIT (1 << TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX)
746 #define TEXTURE_CUBE_ARRAY_BIT (1 << TEXTURE_CUBE_ARRAY_INDEX)
747 #define TEXTURE_BUFFER_BIT   (1 << TEXTURE_BUFFER_INDEX)
748 #define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX)
749 #define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX)
750 #define TEXTURE_EXTERNAL_BIT (1 << TEXTURE_EXTERNAL_INDEX)
751 #define TEXTURE_CUBE_BIT     (1 << TEXTURE_CUBE_INDEX)
752 #define TEXTURE_3D_BIT       (1 << TEXTURE_3D_INDEX)
753 #define TEXTURE_RECT_BIT     (1 << TEXTURE_RECT_INDEX)
754 #define TEXTURE_2D_BIT       (1 << TEXTURE_2D_INDEX)
755 #define TEXTURE_1D_BIT       (1 << TEXTURE_1D_INDEX)
756 /*@}*/
757 
758 
759 /**
760  * Texture image state.  Drivers will typically create a subclass of this
761  * with extra fields for memory buffers, etc.
762  */
763 struct gl_texture_image
764 {
765    GLint InternalFormat;	/**< Internal format as given by the user */
766    GLenum16 _BaseFormat;	/**< Either GL_RGB, GL_RGBA, GL_ALPHA,
767                                  *   GL_LUMINANCE, GL_LUMINANCE_ALPHA,
768                                  *   GL_INTENSITY, GL_DEPTH_COMPONENT or
769                                  *   GL_DEPTH_STENCIL_EXT only. Used for
770                                  *   choosing TexEnv arithmetic.
771                                  */
772    mesa_format TexFormat;         /**< The actual texture memory format */
773 
774    GLuint Border;		/**< 0 or 1 */
775    GLuint Width;		/**< = 2^WidthLog2 + 2*Border */
776    GLuint Height;		/**< = 2^HeightLog2 + 2*Border */
777    GLuint Depth;		/**< = 2^DepthLog2 + 2*Border */
778    GLuint Width2;		/**< = Width - 2*Border */
779    GLuint Height2;		/**< = Height - 2*Border */
780    GLuint Depth2;		/**< = Depth - 2*Border */
781    GLuint WidthLog2;		/**< = log2(Width2) */
782    GLuint HeightLog2;		/**< = log2(Height2) */
783    GLuint DepthLog2;		/**< = log2(Depth2) */
784    GLuint MaxNumLevels;		/**< = maximum possible number of mipmap
785                                        levels, computed from the dimensions */
786 
787    struct gl_texture_object *TexObject;  /**< Pointer back to parent object */
788    GLuint Level;                /**< Which mipmap level am I? */
789    /** Cube map face: index into gl_texture_object::Image[] array */
790    GLuint Face;
791 
792    /** GL_ARB_texture_multisample */
793    GLuint NumSamples;            /**< Sample count, or 0 for non-multisample */
794    GLboolean FixedSampleLocations; /**< Same sample locations for all pixels? */
795 
796    /* If stImage->pt != NULL, image data is stored here.
797     * Else there is no image data.
798     */
799    struct pipe_resource *pt;
800 
801    /* List of transfers, allocated on demand.
802     * transfer[layer] is a mapping for that layer.
803     */
804    struct st_texture_image_transfer *transfer;
805    unsigned num_transfers;
806 
807    /* For compressed images unsupported by the driver. Keep track of
808     * the original data. This is necessary for mapping/unmapping,
809     * as well as image copies.
810     */
811    struct st_compressed_data* compressed_data;
812 };
813 
814 
815 /**
816  * Indexes for cube map faces.
817  */
818 typedef enum
819 {
820    FACE_POS_X = 0,
821    FACE_NEG_X = 1,
822    FACE_POS_Y = 2,
823    FACE_NEG_Y = 3,
824    FACE_POS_Z = 4,
825    FACE_NEG_Z = 5,
826    MAX_FACES = 6
827 } gl_face_index;
828 
829 /**
830  * Sampler state saved and restore by glPush/PopAttrib.
831  *
832  * Don't put fields here that glPushAttrib shouldn't save.
833  * E.g. no GLES fields because GLES doesn't have glPushAttrib.
834  */
835 struct gl_sampler_attrib
836 {
837    GLenum16 WrapS;		/**< S-axis texture image wrap mode */
838    GLenum16 WrapT;		/**< T-axis texture image wrap mode */
839    GLenum16 WrapR;		/**< R-axis texture image wrap mode */
840    GLenum16 MinFilter;		/**< minification filter */
841    GLenum16 MagFilter;		/**< magnification filter */
842    GLenum16 sRGBDecode;         /**< GL_DECODE_EXT or GL_SKIP_DECODE_EXT */
843    GLfloat MinLod;		/**< min lambda, OpenGL 1.2 */
844    GLfloat MaxLod;		/**< max lambda, OpenGL 1.2 */
845    GLfloat LodBias;		/**< OpenGL 1.4 */
846    GLfloat MaxAnisotropy;	/**< GL_EXT_texture_filter_anisotropic */
847    GLenum16 CompareMode;	/**< GL_ARB_shadow */
848    GLenum16 CompareFunc;	/**< GL_ARB_shadow */
849    GLboolean CubeMapSeamless;   /**< GL_AMD_seamless_cubemap_per_texture */
850    GLboolean IsBorderColorNonZero; /**< Does the border color have any effect? */
851    GLenum16 ReductionMode;      /**< GL_EXT_texture_filter_minmax */
852 
853    struct pipe_sampler_state state;  /**< Gallium representation */
854 };
855 
856 /**
857  * Texture state saved and restored by glPush/PopAttrib.
858  *
859  * Don't put fields here that glPushAttrib shouldn't save.
860  * E.g. no GLES fields because GLES doesn't have glPushAttrib.
861  */
862 struct gl_texture_object_attrib
863 {
864    GLfloat Priority;           /**< in [0,1] */
865    GLint BaseLevel;            /**< min mipmap level, OpenGL 1.2 */
866    GLint MaxLevel;             /**< max mipmap level (max=1000), OpenGL 1.2 */
867    GLenum Swizzle[4];          /**< GL_EXT_texture_swizzle */
868    GLushort _Swizzle;          /**< same as Swizzle, but SWIZZLE_* format */
869    GLenum16 DepthMode;         /**< GL_ARB_depth_texture */
870    GLenum16 ImageFormatCompatibilityType; /**< GL_ARB_shader_image_load_store */
871    GLushort MinLayer;          /**< GL_ARB_texture_view */
872    GLushort NumLayers;         /**< GL_ARB_texture_view */
873    GLboolean GenerateMipmap;   /**< GL_SGIS_generate_mipmap */
874    GLbyte ImmutableLevels;     /**< ES 3.0 / ARB_texture_view */
875    GLubyte MinLevel;           /**< GL_ARB_texture_view */
876    GLubyte NumLevels;          /**< GL_ARB_texture_view */
877 };
878 
879 
880 typedef enum
881 {
882    WRAP_S = (1<<0),
883    WRAP_T = (1<<1),
884    WRAP_R = (1<<2),
885 } gl_sampler_wrap;
886 
887 /**
888  * Sampler object state.  These objects are new with GL_ARB_sampler_objects
889  * and OpenGL 3.3.  Legacy texture objects also contain a sampler object.
890  */
891 struct gl_sampler_object
892 {
893    GLuint Name;
894    GLchar *Label;               /**< GL_KHR_debug */
895    GLint RefCount;
896 
897    struct gl_sampler_attrib Attrib;  /**< State saved by glPushAttrib */
898 
899    uint8_t glclamp_mask; /**< mask of GL_CLAMP wraps active */
900 
901    /** GL_ARB_bindless_texture */
902    bool HandleAllocated;
903    struct util_dynarray Handles;
904 };
905 
906 /**
907  * YUV color space that should be used to sample textures backed by YUV
908  * images.
909  */
910 enum gl_texture_yuv_color_space
911 {
912    GL_TEXTURE_YUV_COLOR_SPACE_REC601,
913    GL_TEXTURE_YUV_COLOR_SPACE_REC709,
914    GL_TEXTURE_YUV_COLOR_SPACE_REC2020,
915 };
916 
917 /**
918  * Texture object state.  Contains the array of mipmap images, border color,
919  * wrap modes, filter modes, and shadow/texcompare state.
920  */
921 struct gl_texture_object
922 {
923    GLint RefCount;             /**< reference count */
924    GLuint Name;                /**< the user-visible texture object ID */
925    GLenum16 Target;            /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
926    GLchar *Label;              /**< GL_KHR_debug */
927 
928    struct gl_sampler_object Sampler;
929    struct gl_texture_object_attrib Attrib;  /**< State saved by glPushAttrib */
930 
931    gl_texture_index TargetIndex; /**< The gl_texture_unit::CurrentTex index.
932                                       Only valid when Target is valid. */
933    GLbyte _MaxLevel;           /**< actual max mipmap level (q in the spec) */
934    GLfloat _MaxLambda;         /**< = _MaxLevel - BaseLevel (q - p in spec) */
935    GLint CropRect[4];          /**< GL_OES_draw_texture */
936    GLboolean _BaseComplete;    /**< Is the base texture level valid? */
937    GLboolean _MipmapComplete;  /**< Is the whole mipmap valid? */
938    GLboolean _IsIntegerFormat; /**< Does the texture store integer values? */
939    GLboolean _RenderToTexture; /**< Any rendering to this texture? */
940    GLboolean Immutable;        /**< GL_ARB_texture_storage */
941    GLboolean _IsFloat;         /**< GL_OES_float_texture */
942    GLboolean _IsHalfFloat;     /**< GL_OES_half_float_texture */
943    bool HandleAllocated;       /**< GL_ARB_bindless_texture */
944 
945    /* This should not be restored by glPopAttrib: */
946    bool StencilSampling;       /**< Should we sample stencil instead of depth? */
947 
948    /** GL_OES_EGL_image_external */
949    GLboolean External;
950    GLubyte RequiredTextureImageUnits;
951 
952    /** GL_EXT_memory_object */
953    GLenum16 TextureTiling;
954 
955    /** GL_ARB_texture_buffer_object */
956    GLenum16 BufferObjectFormat;
957    /** Equivalent Mesa format for BufferObjectFormat. */
958    mesa_format _BufferObjectFormat;
959    /* TODO: BufferObject->Name should be restored by glPopAttrib(GL_TEXTURE_BIT); */
960    struct gl_buffer_object *BufferObject;
961 
962    /** GL_ARB_texture_buffer_range */
963    GLintptr BufferOffset;
964    GLsizeiptr BufferSize; /**< if this is -1, use BufferObject->Size instead */
965 
966    /** Actual texture images, indexed by [cube face] and [mipmap level] */
967    struct gl_texture_image *Image[MAX_FACES][MAX_TEXTURE_LEVELS];
968 
969    /** GL_ARB_bindless_texture */
970    struct util_dynarray SamplerHandles;
971    struct util_dynarray ImageHandles;
972 
973    /** GL_ARB_sparse_texture */
974    GLboolean IsSparse;
975    GLint VirtualPageSizeIndex;
976    GLint NumSparseLevels;
977 
978    /* The texture must include at levels [0..lastLevel] once validated:
979     */
980    GLuint lastLevel;
981 
982    unsigned int validated_first_level;
983    unsigned int validated_last_level;
984 
985    /* On validation any active images held in main memory or in other
986     * textures will be copied to this texture and the old storage freed.
987     */
988    struct pipe_resource *pt;
989 
990    /* Protect modifications of the sampler_views array */
991    simple_mtx_t validate_mutex;
992 
993    /* Container of sampler views (one per context) attached to this texture
994     * object. Created lazily on first binding in context.
995     *
996     * Purely read-only accesses to the current context's own sampler view
997     * require no locking. Another thread may simultaneously replace the
998     * container object in order to grow the array, but the old container will
999     * be kept alive.
1000     *
1001     * Writing to the container (even for modifying the current context's own
1002     * sampler view) always requires taking the validate_mutex to protect against
1003     * concurrent container switches.
1004     *
1005     * NULL'ing another context's sampler view is allowed only while
1006     * implementing an API call that modifies the texture: an application which
1007     * calls those while simultaneously reading the texture in another context
1008     * invokes undefined behavior. (TODO: a dubious violation of this rule is
1009     * st_finalize_texture, which is a lazy operation that corresponds to a
1010     * texture modification.)
1011     */
1012    struct st_sampler_views *sampler_views;
1013 
1014    /* Old sampler views container objects that have not been freed yet because
1015     * other threads/contexts may still be reading from them.
1016     */
1017    struct st_sampler_views *sampler_views_old;
1018 
1019    /* True if this texture comes from the window system. Such a texture
1020     * cannot be reallocated and the format can only be changed with a sampler
1021     * view or a surface.
1022     */
1023    GLboolean surface_based;
1024 
1025    /* If surface_based is true, this format should be used for all sampler
1026     * views and surfaces instead of pt->format.
1027     */
1028    enum pipe_format surface_format;
1029 
1030    /* If surface_based is true and surface_format is a YUV format, these
1031     * settings should be used to convert from YUV to RGB.
1032     */
1033    enum gl_texture_yuv_color_space yuv_color_space;
1034    bool yuv_full_range;
1035 
1036    /* When non-negative, samplers should use this level instead of the level
1037     * range specified by the GL state.
1038     *
1039     * This is used for EGL images, which may correspond to a single level out
1040     * of an imported pipe_resources with multiple mip levels.
1041     */
1042    int level_override;
1043 
1044    /* When non-negative, samplers should use this layer instead of the one
1045     * specified by the GL state.
1046     *
1047     * This is used for EGL images and VDPAU interop, where imported
1048     * pipe_resources may be cube, 3D, or array textures (containing layers
1049     * with different fields in the case of VDPAU) even though the GL state
1050     * describes one non-array texture per field.
1051     */
1052    int layer_override;
1053 
1054     /**
1055      * Set when the texture images of this texture object might not all be in
1056      * the pipe_resource *pt above.
1057      */
1058     bool needs_validation;
1059 };
1060 
1061 
1062 /** Up to four combiner sources are possible with GL_NV_texture_env_combine4 */
1063 #define MAX_COMBINER_TERMS 4
1064 
1065 
1066 /**
1067  * Texture combine environment state.
1068  */
1069 struct gl_tex_env_combine_state
1070 {
1071    GLenum16 ModeRGB;       /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1072    GLenum16 ModeA;         /**< GL_REPLACE, GL_DECAL, GL_ADD, etc. */
1073    /** Source terms: GL_PRIMARY_COLOR, GL_TEXTURE, etc */
1074    GLenum16 SourceRGB[MAX_COMBINER_TERMS];
1075    GLenum16 SourceA[MAX_COMBINER_TERMS];
1076    /** Source operands: GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR, etc */
1077    GLenum16 OperandRGB[MAX_COMBINER_TERMS];
1078    GLenum16 OperandA[MAX_COMBINER_TERMS];
1079    GLubyte ScaleShiftRGB; /**< 0, 1 or 2 */
1080    GLubyte ScaleShiftA;   /**< 0, 1 or 2 */
1081    GLubyte _NumArgsRGB;   /**< Number of inputs used for the RGB combiner */
1082    GLubyte _NumArgsA;     /**< Number of inputs used for the A combiner */
1083 };
1084 
1085 
1086 /** Compressed TexEnv effective Combine mode */
1087 enum gl_tex_env_mode
1088 {
1089    TEXENV_MODE_REPLACE,                 /* r = a0 */
1090    TEXENV_MODE_MODULATE,                /* r = a0 * a1 */
1091    TEXENV_MODE_ADD,                     /* r = a0 + a1 */
1092    TEXENV_MODE_ADD_SIGNED,              /* r = a0 + a1 - 0.5 */
1093    TEXENV_MODE_INTERPOLATE,             /* r = a0 * a2 + a1 * (1 - a2) */
1094    TEXENV_MODE_SUBTRACT,                /* r = a0 - a1 */
1095    TEXENV_MODE_DOT3_RGB,                /* r = a0 . a1 */
1096    TEXENV_MODE_DOT3_RGB_EXT,            /* r = a0 . a1 */
1097    TEXENV_MODE_DOT3_RGBA,               /* r = a0 . a1 */
1098    TEXENV_MODE_DOT3_RGBA_EXT,           /* r = a0 . a1 */
1099    TEXENV_MODE_MODULATE_ADD_ATI,        /* r = a0 * a2 + a1 */
1100    TEXENV_MODE_MODULATE_SIGNED_ADD_ATI, /* r = a0 * a2 + a1 - 0.5 */
1101    TEXENV_MODE_MODULATE_SUBTRACT_ATI,   /* r = a0 * a2 - a1 */
1102    TEXENV_MODE_ADD_PRODUCTS_NV,         /* r = a0 * a1 + a2 * a3 */
1103    TEXENV_MODE_ADD_PRODUCTS_SIGNED_NV,  /* r = a0 * a1 + a2 * a3 - 0.5 */
1104 };
1105 
1106 
1107 /** Compressed TexEnv Combine source */
1108 enum gl_tex_env_source
1109 {
1110    TEXENV_SRC_TEXTURE0,
1111    TEXENV_SRC_TEXTURE1,
1112    TEXENV_SRC_TEXTURE2,
1113    TEXENV_SRC_TEXTURE3,
1114    TEXENV_SRC_TEXTURE4,
1115    TEXENV_SRC_TEXTURE5,
1116    TEXENV_SRC_TEXTURE6,
1117    TEXENV_SRC_TEXTURE7,
1118    TEXENV_SRC_TEXTURE,
1119    TEXENV_SRC_PREVIOUS,
1120    TEXENV_SRC_PRIMARY_COLOR,
1121    TEXENV_SRC_CONSTANT,
1122    TEXENV_SRC_ZERO,
1123    TEXENV_SRC_ONE,
1124 };
1125 
1126 
1127 /** Compressed TexEnv Combine operand */
1128 enum gl_tex_env_operand
1129 {
1130    TEXENV_OPR_COLOR,
1131    TEXENV_OPR_ONE_MINUS_COLOR,
1132    TEXENV_OPR_ALPHA,
1133    TEXENV_OPR_ONE_MINUS_ALPHA,
1134 };
1135 
1136 
1137 /** Compressed TexEnv Combine argument */
1138 struct gl_tex_env_argument
1139 {
1140 #ifdef __GNUC__
1141    __extension__ uint8_t Source:4;  /**< TEXENV_SRC_x */
1142    __extension__ uint8_t Operand:2; /**< TEXENV_OPR_x */
1143 #else
1144    uint8_t Source;  /**< SRC_x */
1145    uint8_t Operand; /**< OPR_x */
1146 #endif
1147 };
1148 
1149 
1150 /***
1151  * Compressed TexEnv Combine state.
1152  */
1153 struct gl_tex_env_combine_packed
1154 {
1155    uint32_t ModeRGB:4;        /**< Effective mode for RGB as 4 bits */
1156    uint32_t ModeA:4;          /**< Effective mode for RGB as 4 bits */
1157    uint32_t ScaleShiftRGB:2;  /**< 0, 1 or 2 */
1158    uint32_t ScaleShiftA:2;    /**< 0, 1 or 2 */
1159    uint32_t NumArgsRGB:3;     /**< Number of inputs used for the RGB combiner */
1160    uint32_t NumArgsA:3;       /**< Number of inputs used for the A combiner */
1161    /** Source arguments in a packed manner */
1162    struct gl_tex_env_argument ArgsRGB[MAX_COMBINER_TERMS];
1163    struct gl_tex_env_argument ArgsA[MAX_COMBINER_TERMS];
1164 };
1165 
1166 
1167 /**
1168  * TexGenEnabled flags.
1169  */
1170 /*@{*/
1171 #define S_BIT 1
1172 #define T_BIT 2
1173 #define R_BIT 4
1174 #define Q_BIT 8
1175 #define STR_BITS (S_BIT | T_BIT | R_BIT)
1176 /*@}*/
1177 
1178 
1179 /**
1180  * Bit flag versions of the corresponding GL_ constants.
1181  */
1182 /*@{*/
1183 #define TEXGEN_SPHERE_MAP        0x1
1184 #define TEXGEN_OBJ_LINEAR        0x2
1185 #define TEXGEN_EYE_LINEAR        0x4
1186 #define TEXGEN_REFLECTION_MAP_NV 0x8
1187 #define TEXGEN_NORMAL_MAP_NV     0x10
1188 
1189 #define TEXGEN_NEED_NORMALS   (TEXGEN_SPHERE_MAP        | \
1190                                TEXGEN_REFLECTION_MAP_NV | \
1191                                TEXGEN_NORMAL_MAP_NV)
1192 #define TEXGEN_NEED_EYE_COORD (TEXGEN_SPHERE_MAP        | \
1193                                TEXGEN_REFLECTION_MAP_NV | \
1194                                TEXGEN_NORMAL_MAP_NV     | \
1195                                TEXGEN_EYE_LINEAR)
1196 /*@}*/
1197 
1198 
1199 
1200 /** Tex-gen enabled for texture unit? */
1201 #define ENABLE_TEXGEN(unit) (1 << (unit))
1202 
1203 /** Non-identity texture matrix for texture unit? */
1204 #define ENABLE_TEXMAT(unit) (1 << (unit))
1205 
1206 
1207 /**
1208  * Texture coord generation state.
1209  */
1210 struct gl_texgen
1211 {
1212    GLenum16 Mode;       /**< GL_EYE_LINEAR, GL_SPHERE_MAP, etc */
1213    GLbitfield8 _ModeBit; /**< TEXGEN_x bit corresponding to Mode */
1214 };
1215 
1216 
1217 /**
1218  * Sampler-related subset of a texture unit, like current texture objects.
1219  */
1220 struct gl_texture_unit
1221 {
1222    GLfloat LodBias;		/**< for biasing mipmap levels */
1223    float LodBiasQuantized;      /**< to reduce pipe_sampler_state variants */
1224 
1225    /** Texture targets that have a non-default texture bound */
1226    GLbitfield _BoundTextures;
1227 
1228    /** Current sampler object (GL_ARB_sampler_objects) */
1229    struct gl_sampler_object *Sampler;
1230 
1231    /** Current texture object pointers */
1232    struct gl_texture_object *CurrentTex[NUM_TEXTURE_TARGETS];
1233 
1234    /** Points to highest priority, complete and enabled texture object */
1235    struct gl_texture_object *_Current;
1236 };
1237 
1238 enum {
1239    GEN_S,
1240    GEN_T,
1241    GEN_R,
1242    GEN_Q,
1243    NUM_GEN,
1244 };
1245 
1246 /**
1247  * Fixed-function-related subset of a texture unit, like enable flags,
1248  * texture environment/function/combiners, and texgen state.
1249  */
1250 struct gl_fixedfunc_texture_unit
1251 {
1252    GLbitfield16 Enabled;          /**< bitmask of TEXTURE_*_BIT flags */
1253 
1254    GLenum16 EnvMode;            /**< GL_MODULATE, GL_DECAL, GL_BLEND, etc. */
1255    GLclampf EnvColor[4];
1256    GLfloat EnvColorUnclamped[4];
1257 
1258    struct gl_texgen GenS;
1259    struct gl_texgen GenT;
1260    struct gl_texgen GenR;
1261    struct gl_texgen GenQ;
1262 
1263    GLfloat EyePlane[NUM_GEN][4];
1264    GLfloat ObjectPlane[NUM_GEN][4];
1265 
1266    GLbitfield8 TexGenEnabled;	/**< Bitwise-OR of [STRQ]_BIT values */
1267    GLbitfield8 _GenFlags;	/**< Bitwise-OR of Gen[STRQ]._ModeBit */
1268 
1269    /**
1270     * \name GL_EXT_texture_env_combine
1271     */
1272    struct gl_tex_env_combine_state Combine;
1273 
1274    /**
1275     * Derived state based on \c EnvMode and the \c BaseFormat of the
1276     * currently enabled texture.
1277     */
1278    struct gl_tex_env_combine_state _EnvMode;
1279 
1280    /** Current compressed TexEnv & Combine state */
1281    struct gl_tex_env_combine_packed _CurrentCombinePacked;
1282 
1283    /**
1284     * Currently enabled combiner state.  This will point to either
1285     * \c Combine or \c _EnvMode.
1286     */
1287    struct gl_tex_env_combine_state *_CurrentCombine;
1288 };
1289 
1290 
1291 /**
1292  * Texture attribute group (GL_TEXTURE_BIT).
1293  */
1294 struct gl_texture_attrib
1295 {
1296    struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
1297 
1298    /** GL_ARB_texture_buffer_object */
1299    struct gl_buffer_object *BufferObject;
1300 
1301    GLuint CurrentUnit;   /**< GL_ACTIVE_TEXTURE */
1302 
1303    /** Texture coord units/sets used for fragment texturing */
1304    GLbitfield8 _EnabledCoordUnits;
1305 
1306    /** Texture coord units that have texgen enabled */
1307    GLbitfield8 _TexGenEnabled;
1308 
1309    /** Texture coord units that have non-identity matrices */
1310    GLbitfield8 _TexMatEnabled;
1311 
1312    /** Bitwise-OR of all Texture.Unit[i]._GenFlags */
1313    GLbitfield8 _GenFlags;
1314 
1315    /** Largest index of a texture unit with _Current != NULL. */
1316    GLshort _MaxEnabledTexImageUnit;
1317 
1318    /** Largest index + 1 of texture units that have had any CurrentTex set. */
1319    GLubyte NumCurrentTexUsed;
1320 
1321    /** GL_ARB_seamless_cubemap */
1322    GLboolean CubeMapSeamless;
1323 
1324    struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
1325    struct gl_fixedfunc_texture_unit FixedFuncUnit[MAX_TEXTURE_COORD_UNITS];
1326 };
1327 
1328 
1329 /**
1330  * Data structure representing a single clip plane (e.g. one of the elements
1331  * of the ctx->Transform.EyeUserPlane or ctx->Transform._ClipUserPlane array).
1332  */
1333 typedef GLfloat gl_clip_plane[4];
1334 
1335 
1336 /**
1337  * Transformation attribute group (GL_TRANSFORM_BIT).
1338  */
1339 struct gl_transform_attrib
1340 {
1341    GLenum16 MatrixMode;				/**< Matrix mode */
1342    gl_clip_plane EyeUserPlane[MAX_CLIP_PLANES];	/**< User clip planes */
1343    gl_clip_plane _ClipUserPlane[MAX_CLIP_PLANES]; /**< derived */
1344    GLbitfield ClipPlanesEnabled;                /**< on/off bitmask */
1345    GLboolean Normalize;				/**< Normalize all normals? */
1346    GLboolean RescaleNormals;			/**< GL_EXT_rescale_normal */
1347    GLboolean RasterPositionUnclipped;           /**< GL_IBM_rasterpos_clip */
1348    GLboolean DepthClampNear;			/**< GL_AMD_depth_clamp_separate */
1349    GLboolean DepthClampFar;			/**< GL_AMD_depth_clamp_separate */
1350    /** GL_ARB_clip_control */
1351    GLenum16 ClipOrigin;   /**< GL_LOWER_LEFT or GL_UPPER_LEFT */
1352    GLenum16 ClipDepthMode;/**< GL_NEGATIVE_ONE_TO_ONE or GL_ZERO_TO_ONE */
1353 };
1354 
1355 
1356 /**
1357  * Viewport attribute group (GL_VIEWPORT_BIT).
1358  */
1359 struct gl_viewport_attrib
1360 {
1361    GLfloat X, Y;		/**< position */
1362    GLfloat Width, Height;	/**< size */
1363    GLfloat Near, Far;		/**< Depth buffer range */
1364 
1365    /**< GL_NV_viewport_swizzle */
1366    GLenum16 SwizzleX, SwizzleY, SwizzleZ, SwizzleW;
1367 };
1368 
1369 
1370 /**
1371  * Fields describing a mapped buffer range.
1372  */
1373 struct gl_buffer_mapping
1374 {
1375    GLbitfield AccessFlags; /**< Mask of GL_MAP_x_BIT flags */
1376    GLvoid *Pointer;        /**< User-space address of mapping */
1377    GLintptr Offset;        /**< Mapped offset */
1378    GLsizeiptr Length;      /**< Mapped length */
1379 };
1380 
1381 
1382 /**
1383  * Usages we've seen for a buffer object.
1384  */
1385 typedef enum
1386 {
1387    USAGE_UNIFORM_BUFFER = 0x1,
1388    USAGE_TEXTURE_BUFFER = 0x2,
1389    USAGE_ATOMIC_COUNTER_BUFFER = 0x4,
1390    USAGE_SHADER_STORAGE_BUFFER = 0x8,
1391    USAGE_TRANSFORM_FEEDBACK_BUFFER = 0x10,
1392    USAGE_PIXEL_PACK_BUFFER = 0x20,
1393    USAGE_ARRAY_BUFFER = 0x40,
1394    USAGE_DISABLE_MINMAX_CACHE = 0x100,
1395 } gl_buffer_usage;
1396 
1397 
1398 /**
1399  * GL_ARB_vertex/pixel_buffer_object buffer object
1400  */
1401 struct gl_buffer_object
1402 {
1403    GLint RefCount;
1404    GLuint Name;
1405    GLchar *Label;       /**< GL_KHR_debug */
1406 
1407    /**
1408     * The context that holds a global buffer reference for the lifetime of
1409     * the GL buffer ID to skip refcounting for all its private bind points.
1410     * Other contexts must still do refcounting as usual. Shared binding points
1411     * like TBO within gl_texture_object are always refcounted.
1412     *
1413     * Implementation details:
1414     * - Only the context that creates the buffer ("creating context") skips
1415     *   refcounting.
1416     * - Only buffers represented by an OpenGL buffer ID skip refcounting.
1417     *   Other internal buffers don't. (glthread requires refcounting for
1418     *   internal buffers, etc.)
1419     * - glDeleteBuffers removes the global buffer reference and increments
1420     *   RefCount for all private bind points where the deleted buffer is bound
1421     *   (e.g. unbound VAOs that are not changed by glDeleteBuffers),
1422     *   effectively enabling refcounting for that context. This is the main
1423     *   point where the global buffer reference is removed.
1424     * - glDeleteBuffers called from a different context adds the buffer into
1425     *   the ZombieBufferObjects list, which is a way to notify the creating
1426     *   context that it should remove its global buffer reference to allow
1427     *   freeing the buffer. The creating context walks over that list in a few
1428     *   GL functions.
1429     * - xxxDestroyContext walks over all buffers and removes its global
1430     *   reference from those buffers that it created.
1431     */
1432    struct gl_context *Ctx;
1433    GLint CtxRefCount;   /**< Non-atomic references held by Ctx. */
1434 
1435    GLenum16 Usage;      /**< GL_STREAM_DRAW_ARB, GL_STREAM_READ_ARB, etc. */
1436    GLbitfield StorageFlags; /**< GL_MAP_PERSISTENT_BIT, etc. */
1437    GLsizeiptrARB Size;  /**< Size of buffer storage in bytes */
1438    GLubyte *Data;       /**< Location of storage either in RAM or VRAM. */
1439    GLboolean DeletePending;   /**< true if buffer object is removed from the hash */
1440    GLboolean Written;   /**< Ever written to? (for debugging) */
1441    GLboolean Immutable; /**< GL_ARB_buffer_storage */
1442    gl_buffer_usage UsageHistory; /**< How has this buffer been used so far? */
1443 
1444    /** Counters used for buffer usage warnings */
1445    GLuint NumSubDataCalls;
1446    GLuint NumMapBufferWriteCalls;
1447 
1448    struct gl_buffer_mapping Mappings[MAP_COUNT];
1449 
1450    /** Memoization of min/max index computations for static index buffers */
1451    simple_mtx_t MinMaxCacheMutex;
1452    struct hash_table *MinMaxCache;
1453    unsigned MinMaxCacheHitIndices;
1454    unsigned MinMaxCacheMissIndices;
1455    bool MinMaxCacheDirty;
1456 
1457    bool HandleAllocated; /**< GL_ARB_bindless_texture */
1458 
1459    struct pipe_resource *buffer;
1460    struct gl_context *private_refcount_ctx;
1461    /* This mechanism allows passing buffer references to the driver without
1462     * using atomics to increase the reference count.
1463     *
1464     * This private refcount can be decremented without atomics but only one
1465     * context (ctx above) can use this counter to be thread-safe.
1466     *
1467     * This number is atomically added to buffer->reference.count at
1468     * initialization. If it's never used, the same number is atomically
1469     * subtracted from buffer->reference.count before destruction. If this
1470     * number is decremented, we can pass that reference to the driver without
1471     * touching reference.count. At buffer destruction we only subtract
1472     * the number of references we did not return. This can possibly turn
1473     * a million atomic increments into 1 add and 1 subtract atomic op.
1474     */
1475    int private_refcount;
1476 
1477    struct pipe_transfer *transfer[MAP_COUNT];
1478 };
1479 
1480 
1481 /**
1482  * Client pixel packing/unpacking attributes
1483  */
1484 struct gl_pixelstore_attrib
1485 {
1486    GLint Alignment;
1487    GLint RowLength;
1488    GLint SkipPixels;
1489    GLint SkipRows;
1490    GLint ImageHeight;
1491    GLint SkipImages;
1492    GLboolean SwapBytes;
1493    GLboolean LsbFirst;
1494    GLboolean Invert;        /**< GL_MESA_pack_invert */
1495    GLint CompressedBlockWidth;   /**< GL_ARB_compressed_texture_pixel_storage */
1496    GLint CompressedBlockHeight;
1497    GLint CompressedBlockDepth;
1498    GLint CompressedBlockSize;
1499    struct gl_buffer_object *BufferObj; /**< GL_ARB_pixel_buffer_object */
1500 };
1501 
1502 
1503 /**
1504  * Enum for defining the mapping for the position/generic0 attribute.
1505  *
1506  * Do not change the order of the values as these are used as
1507  * array indices.
1508  */
1509 typedef enum
1510 {
1511    ATTRIBUTE_MAP_MODE_IDENTITY, /**< 1:1 mapping */
1512    ATTRIBUTE_MAP_MODE_POSITION, /**< get position and generic0 from position */
1513    ATTRIBUTE_MAP_MODE_GENERIC0, /**< get position and generic0 from generic0 */
1514    ATTRIBUTE_MAP_MODE_MAX       /**< for sizing arrays */
1515 } gl_attribute_map_mode;
1516 
1517 
1518 /**
1519  * Attributes to describe a vertex array.
1520  *
1521  * Contains the size, type, format and normalization flag,
1522  * along with the index of a vertex buffer binding point.
1523  *
1524  * Note that the Stride field corresponds to VERTEX_ATTRIB_ARRAY_STRIDE
1525  * and is only present for backwards compatibility reasons.
1526  * Rendering always uses VERTEX_BINDING_STRIDE.
1527  * The gl*Pointer() functions will set VERTEX_ATTRIB_ARRAY_STRIDE
1528  * and VERTEX_BINDING_STRIDE to the same value, while
1529  * glBindVertexBuffer() will only set VERTEX_BINDING_STRIDE.
1530  */
1531 struct gl_array_attributes
1532 {
1533    /** Points to client array data. Not used when a VBO is bound */
1534    const GLubyte *Ptr;
1535    /** Offset of the first element relative to the binding offset */
1536    GLuint RelativeOffset;
1537    /** Vertex format */
1538    struct gl_vertex_format Format;
1539    /** Stride as specified with gl*Pointer() */
1540    GLshort Stride;
1541    /** Index into gl_vertex_array_object::BufferBinding[] array */
1542    GLubyte BufferBindingIndex;
1543 
1544    /**
1545     * Derived effective buffer binding index
1546     *
1547     * Index into the gl_vertex_buffer_binding array of the vao.
1548     * Similar to BufferBindingIndex, but with the mapping of the
1549     * position/generic0 attributes applied and with identical
1550     * gl_vertex_buffer_binding entries collapsed to a single
1551     * entry within the vao.
1552     *
1553     * The value is valid past calling _mesa_update_vao_derived_arrays.
1554     * Note that _mesa_update_vao_derived_arrays is called when binding
1555     * the VAO to Array._DrawVAO.
1556     */
1557    GLubyte _EffBufferBindingIndex;
1558    /**
1559     * Derived effective relative offset.
1560     *
1561     * Relative offset to the effective buffers offset in
1562     * gl_vertex_buffer_binding::_EffOffset.
1563     *
1564     * The value is valid past calling _mesa_update_vao_derived_arrays.
1565     * Note that _mesa_update_vao_derived_arrays is called when binding
1566     * the VAO to Array._DrawVAO.
1567     */
1568    GLushort _EffRelativeOffset;
1569 };
1570 
1571 
1572 /**
1573  * This describes the buffer object used for a vertex array (or
1574  * multiple vertex arrays).  If BufferObj points to the default/null
1575  * buffer object, then the vertex array lives in user memory and not a VBO.
1576  */
1577 struct gl_vertex_buffer_binding
1578 {
1579    GLintptr Offset;                    /**< User-specified offset */
1580    GLsizei Stride;                     /**< User-specified stride */
1581    GLuint InstanceDivisor;             /**< GL_ARB_instanced_arrays */
1582    struct gl_buffer_object *BufferObj; /**< GL_ARB_vertex_buffer_object */
1583    GLbitfield _BoundArrays;            /**< Arrays bound to this binding point */
1584 
1585    /**
1586     * Derived effective bound arrays.
1587     *
1588     * The effective binding handles enabled arrays past the
1589     * position/generic0 attribute mapping and reduces the refered
1590     * gl_vertex_buffer_binding entries to a unique subset.
1591     *
1592     * The value is valid past calling _mesa_update_vao_derived_arrays.
1593     * Note that _mesa_update_vao_derived_arrays is called when binding
1594     * the VAO to Array._DrawVAO.
1595     */
1596    GLbitfield _EffBoundArrays;
1597    /**
1598     * Derived offset.
1599     *
1600     * The absolute offset to that we can collapse some attributes
1601     * to this unique effective binding.
1602     * For user space array bindings this contains the smallest pointer value
1603     * in the bound and interleaved arrays.
1604     * For VBO bindings this contains an offset that lets the attributes
1605     * _EffRelativeOffset stay positive and in bounds with
1606     * Const.MaxVertexAttribRelativeOffset
1607     *
1608     * The value is valid past calling _mesa_update_vao_derived_arrays.
1609     * Note that _mesa_update_vao_derived_arrays is called when binding
1610     * the VAO to Array._DrawVAO.
1611     */
1612    GLintptr _EffOffset;
1613 };
1614 
1615 
1616 /**
1617  * A representation of "Vertex Array Objects" (VAOs) from OpenGL 3.1+ /
1618  * the GL_ARB_vertex_array_object extension.
1619  */
1620 struct gl_vertex_array_object
1621 {
1622    /** Name of the VAO as received from glGenVertexArray. */
1623    GLuint Name;
1624 
1625    GLint RefCount;
1626 
1627    GLchar *Label;       /**< GL_KHR_debug */
1628 
1629    /**
1630     * Has this array object been bound?
1631     */
1632    GLboolean EverBound;
1633 
1634    /**
1635     * Whether the VAO is changed by the application so often that some of
1636     * the derived fields are not updated at all to decrease overhead.
1637     * Also, interleaved arrays are not detected, because it's too expensive
1638     * to do that before every draw call.
1639     */
1640    bool IsDynamic;
1641 
1642    /**
1643     * Marked to true if the object is shared between contexts and immutable.
1644     * Then reference counting is done using atomics and thread safe.
1645     * Is used for dlist VAOs.
1646     */
1647    bool SharedAndImmutable;
1648 
1649    /**
1650     * Number of updates that were done by the application. This is used to
1651     * decide whether the VAO is static or dynamic.
1652     */
1653    unsigned NumUpdates;
1654 
1655    /** Vertex attribute arrays */
1656    struct gl_array_attributes VertexAttrib[VERT_ATTRIB_MAX];
1657 
1658    /** Vertex buffer bindings */
1659    struct gl_vertex_buffer_binding BufferBinding[VERT_ATTRIB_MAX];
1660 
1661    /** Mask indicating which vertex arrays have vertex buffer associated. */
1662    GLbitfield VertexAttribBufferMask;
1663 
1664    /** Mask indicating which vertex arrays have a non-zero instance divisor. */
1665    GLbitfield NonZeroDivisorMask;
1666 
1667    /** Mask of VERT_BIT_* values indicating which arrays are enabled */
1668    GLbitfield Enabled;
1669 
1670    /**
1671     * Mask indicating which VertexAttrib and BufferBinding structures have
1672     * been changed since the VAO creation. No bit is ever cleared to 0 by
1673     * state updates. Setting to the default state doesn't update this.
1674     * (e.g. unbinding) Setting the derived state (_* fields) doesn't update
1675     * this either.
1676     */
1677    GLbitfield NonDefaultStateMask;
1678 
1679    /**
1680     * Mask of VERT_BIT_* enabled arrays past position/generic0 mapping
1681     *
1682     * The value is valid past calling _mesa_update_vao_derived_arrays.
1683     * Note that _mesa_update_vao_derived_arrays is called when binding
1684     * the VAO to Array._DrawVAO.
1685     */
1686    GLbitfield _EffEnabledVBO;
1687 
1688    /** Same as _EffEnabledVBO, but for instance divisors. */
1689    GLbitfield _EffEnabledNonZeroDivisor;
1690 
1691    /** Denotes the way the position/generic0 attribute is mapped */
1692    gl_attribute_map_mode _AttributeMapMode;
1693 
1694    /** "Enabled" with the position/generic0 attribute aliasing resolved */
1695    GLbitfield _EnabledWithMapMode;
1696 
1697    /** Which states have been changed according to the gallium definitions. */
1698    bool NewVertexBuffers;
1699    bool NewVertexElements;
1700 
1701    /** The index buffer (also known as the element array buffer in OpenGL). */
1702    struct gl_buffer_object *IndexBufferObj;
1703 };
1704 
1705 
1706 /**
1707  * Vertex array state
1708  */
1709 struct gl_array_attrib
1710 {
1711    /** Currently bound array object. */
1712    struct gl_vertex_array_object *VAO;
1713 
1714    /** The default vertex array object */
1715    struct gl_vertex_array_object *DefaultVAO;
1716 
1717    /** The last VAO accessed by a DSA function */
1718    struct gl_vertex_array_object *LastLookedUpVAO;
1719 
1720    /** These contents are copied to newly created VAOs. */
1721    struct gl_vertex_array_object DefaultVAOState;
1722 
1723    /** Array objects (GL_ARB_vertex_array_object) */
1724    struct _mesa_HashTable *Objects;
1725 
1726    GLint ActiveTexture;		/**< Client Active Texture */
1727    GLuint LockFirst;            /**< GL_EXT_compiled_vertex_array */
1728    GLuint LockCount;            /**< GL_EXT_compiled_vertex_array */
1729 
1730    /**
1731     * \name Primitive restart controls
1732     *
1733     * Primitive restart is enabled if either \c PrimitiveRestart or
1734     * \c PrimitiveRestartFixedIndex is set.
1735     */
1736    /*@{*/
1737    GLboolean PrimitiveRestart;
1738    GLboolean PrimitiveRestartFixedIndex;
1739    GLboolean _PrimitiveRestart[3]; /**< Enable indexed by index_size_shift. */
1740    GLuint RestartIndex;
1741    GLuint _RestartIndex[3]; /**< Restart indices indexed by index_size_shift. */
1742    /*@}*/
1743 
1744    /* GL_ARB_vertex_buffer_object */
1745    struct gl_buffer_object *ArrayBufferObj;
1746 
1747    /**
1748     * Vertex array object that is used with the currently active draw command.
1749     * The _DrawVAO is either set to the currently bound VAO for array type
1750     * draws or to internal VAO's set up by the vbo module to execute immediate
1751     * mode or display list draws.
1752     */
1753    struct gl_vertex_array_object *_DrawVAO;
1754    /**
1755     * The VERT_BIT_* bits effectively enabled from the current _DrawVAO.
1756     * This is always a subset of _mesa_get_vao_vp_inputs(_DrawVAO)
1757     * but may omit those arrays that shall not be referenced by the current
1758     * gl_vertex_program_state::_VPMode. For example the generic attributes are
1759     * maked out form the _DrawVAO's enabled arrays when a fixed function
1760     * array draw is executed.
1761     */
1762    GLbitfield _DrawVAOEnabledAttribs;
1763 
1764    /**
1765     * If gallium vertex buffers are dirty, this flag indicates whether gallium
1766     * vertex elements are dirty too. If this is false, GL states corresponding
1767     * to vertex elements have not been changed. Thus, this affects what will
1768     * happen when ST_NEW_VERTEX_ARRAYS is set.
1769     *
1770     * The driver should clear this when it's done.
1771     */
1772    bool NewVertexElements;
1773 
1774    /**
1775     * Initially or if the VAO referenced by _DrawVAO is deleted the _DrawVAO
1776     * pointer is set to the _EmptyVAO which is just an empty VAO all the time.
1777     */
1778    struct gl_vertex_array_object *_EmptyVAO;
1779 
1780    /** Legal array datatypes and the API for which they have been computed */
1781    GLbitfield LegalTypesMask;
1782    gl_api LegalTypesMaskAPI;
1783 };
1784 
1785 
1786 /**
1787  * Feedback buffer state
1788  */
1789 struct gl_feedback
1790 {
1791    GLenum16 Type;
1792    GLbitfield _Mask;    /**< FB_* bits */
1793    GLfloat *Buffer;
1794    GLuint BufferSize;
1795    GLuint Count;
1796 };
1797 
1798 
1799 /**
1800  * Selection buffer state
1801  */
1802 struct gl_selection
1803 {
1804    GLuint *Buffer;	/**< selection buffer */
1805    GLuint BufferSize;	/**< size of the selection buffer */
1806    GLuint BufferCount;	/**< number of values in the selection buffer */
1807    GLuint Hits;		/**< number of records in the selection buffer */
1808    GLuint NameStackDepth; /**< name stack depth */
1809    GLuint NameStack[MAX_NAME_STACK_DEPTH]; /**< name stack */
1810    GLboolean HitFlag;	/**< hit flag */
1811    GLfloat HitMinZ;	/**< minimum hit depth */
1812    GLfloat HitMaxZ;	/**< maximum hit depth */
1813 
1814    /* HW GL_SELECT */
1815    void *SaveBuffer;        /**< array holds multi stack data */
1816    GLuint SaveBufferTail;   /**< offset to SaveBuffer's tail */
1817    GLuint SavedStackNum;    /**< number of saved stacks */
1818 
1819    GLboolean ResultUsed;    /**< whether any draw used result buffer */
1820    GLuint ResultOffset;     /**< offset into result buffer */
1821    struct gl_buffer_object *Result; /**< result buffer */
1822 };
1823 
1824 
1825 /**
1826  * 1-D Evaluator control points
1827  */
1828 struct gl_1d_map
1829 {
1830    GLuint Order;	/**< Number of control points */
1831    GLfloat u1, u2, du;	/**< u1, u2, 1.0/(u2-u1) */
1832    GLfloat *Points;	/**< Points to contiguous control points */
1833 };
1834 
1835 
1836 /**
1837  * 2-D Evaluator control points
1838  */
1839 struct gl_2d_map
1840 {
1841    GLuint Uorder;		/**< Number of control points in U dimension */
1842    GLuint Vorder;		/**< Number of control points in V dimension */
1843    GLfloat u1, u2, du;
1844    GLfloat v1, v2, dv;
1845    GLfloat *Points;		/**< Points to contiguous control points */
1846 };
1847 
1848 
1849 /**
1850  * All evaluator control point state
1851  */
1852 struct gl_evaluators
1853 {
1854    /**
1855     * \name 1-D maps
1856     */
1857    /*@{*/
1858    struct gl_1d_map Map1Vertex3;
1859    struct gl_1d_map Map1Vertex4;
1860    struct gl_1d_map Map1Index;
1861    struct gl_1d_map Map1Color4;
1862    struct gl_1d_map Map1Normal;
1863    struct gl_1d_map Map1Texture1;
1864    struct gl_1d_map Map1Texture2;
1865    struct gl_1d_map Map1Texture3;
1866    struct gl_1d_map Map1Texture4;
1867    /*@}*/
1868 
1869    /**
1870     * \name 2-D maps
1871     */
1872    /*@{*/
1873    struct gl_2d_map Map2Vertex3;
1874    struct gl_2d_map Map2Vertex4;
1875    struct gl_2d_map Map2Index;
1876    struct gl_2d_map Map2Color4;
1877    struct gl_2d_map Map2Normal;
1878    struct gl_2d_map Map2Texture1;
1879    struct gl_2d_map Map2Texture2;
1880    struct gl_2d_map Map2Texture3;
1881    struct gl_2d_map Map2Texture4;
1882    /*@}*/
1883 };
1884 
1885 
1886 /**
1887  * Transform feedback object state
1888  */
1889 struct gl_transform_feedback_object
1890 {
1891    GLuint Name;  /**< AKA the object ID */
1892    GLint RefCount;
1893    GLchar *Label;     /**< GL_KHR_debug */
1894    GLboolean Active;  /**< Is transform feedback enabled? */
1895    GLboolean Paused;  /**< Is transform feedback paused? */
1896    GLboolean EndedAnytime; /**< Has EndTransformFeedback been called
1897                                 at least once? */
1898    GLboolean EverBound; /**< Has this object been bound? */
1899 
1900    /**
1901     * GLES: if Active is true, remaining number of primitives which can be
1902     * rendered without overflow.  This is necessary to track because GLES
1903     * requires us to generate INVALID_OPERATION if a call to glDrawArrays or
1904     * glDrawArraysInstanced would overflow transform feedback buffers.
1905     * Undefined if Active is false.
1906     *
1907     * Not tracked for desktop GL since it's unnecessary.
1908     */
1909    unsigned GlesRemainingPrims;
1910 
1911    /**
1912     * The program active when BeginTransformFeedback() was called.
1913     * When active and unpaused, this equals ctx->Shader.CurrentProgram[stage],
1914     * where stage is the pipeline stage that is the source of data for
1915     * transform feedback.
1916     */
1917    struct gl_program *program;
1918 
1919    /** The feedback buffers */
1920    GLuint BufferNames[MAX_FEEDBACK_BUFFERS];
1921    struct gl_buffer_object *Buffers[MAX_FEEDBACK_BUFFERS];
1922 
1923    /** Start of feedback data in dest buffer */
1924    GLintptr Offset[MAX_FEEDBACK_BUFFERS];
1925 
1926    /**
1927     * Max data to put into dest buffer (in bytes).  Computed based on
1928     * RequestedSize and the actual size of the buffer.
1929     */
1930    GLsizeiptr Size[MAX_FEEDBACK_BUFFERS];
1931 
1932    /**
1933     * Size that was specified when the buffer was bound.  If the buffer was
1934     * bound with glBindBufferBase() or glBindBufferOffsetEXT(), this value is
1935     * zero.
1936     */
1937    GLsizeiptr RequestedSize[MAX_FEEDBACK_BUFFERS];
1938 
1939    unsigned num_targets;
1940    struct pipe_stream_output_target *targets[PIPE_MAX_SO_BUFFERS];
1941 
1942    /* This encapsulates the count that can be used as a source for draw_vbo.
1943     * It contains stream output targets from the last call of
1944     * EndTransformFeedback for each stream. */
1945    struct pipe_stream_output_target *draw_count[MAX_VERTEX_STREAMS];
1946 };
1947 
1948 
1949 /**
1950  * Context state for transform feedback.
1951  */
1952 struct gl_transform_feedback_state
1953 {
1954    GLenum16 Mode;     /**< GL_POINTS, GL_LINES or GL_TRIANGLES */
1955 
1956    /** The general binding point (GL_TRANSFORM_FEEDBACK_BUFFER) */
1957    struct gl_buffer_object *CurrentBuffer;
1958 
1959    /** The table of all transform feedback objects */
1960    struct _mesa_HashTable *Objects;
1961 
1962    /** The current xform-fb object (GL_TRANSFORM_FEEDBACK_BINDING) */
1963    struct gl_transform_feedback_object *CurrentObject;
1964 
1965    /** The default xform-fb object (Name==0) */
1966    struct gl_transform_feedback_object *DefaultObject;
1967 };
1968 
1969 
1970 /**
1971  * A "performance monitor" as described in AMD_performance_monitor.
1972  */
1973 struct gl_perf_monitor_object
1974 {
1975    GLuint Name;
1976 
1977    /** True if the monitor is currently active (Begin called but not End). */
1978    GLboolean Active;
1979 
1980    /**
1981     * True if the monitor has ended.
1982     *
1983     * This is distinct from !Active because it may never have began.
1984     */
1985    GLboolean Ended;
1986 
1987    /**
1988     * A list of groups with currently active counters.
1989     *
1990     * ActiveGroups[g] == n if there are n counters active from group 'g'.
1991     */
1992    unsigned *ActiveGroups;
1993 
1994    /**
1995     * An array of bitsets, subscripted by group ID, then indexed by counter ID.
1996     *
1997     * Checking whether counter 'c' in group 'g' is active can be done via:
1998     *
1999     *    BITSET_TEST(ActiveCounters[g], c)
2000     */
2001    GLuint **ActiveCounters;
2002 
2003    unsigned num_active_counters;
2004 
2005    struct gl_perf_counter_object {
2006       struct pipe_query *query;
2007       int id;
2008       int group_id;
2009       unsigned batch_index;
2010    } *active_counters;
2011 
2012    struct pipe_query *batch_query;
2013    union pipe_query_result *batch_result;
2014 };
2015 
2016 
2017 union gl_perf_monitor_counter_value
2018 {
2019    float f;
2020    uint64_t u64;
2021    uint32_t u32;
2022 };
2023 
2024 
2025 struct gl_perf_monitor_counter
2026 {
2027    /** Human readable name for the counter. */
2028    const char *Name;
2029 
2030    /**
2031     * Data type of the counter.  Valid values are FLOAT, UNSIGNED_INT,
2032     * UNSIGNED_INT64_AMD, and PERCENTAGE_AMD.
2033     */
2034    GLenum16 Type;
2035 
2036    /** Minimum counter value. */
2037    union gl_perf_monitor_counter_value Minimum;
2038 
2039    /** Maximum counter value. */
2040    union gl_perf_monitor_counter_value Maximum;
2041 
2042    unsigned query_type;
2043    unsigned flags;
2044 };
2045 
2046 
2047 struct gl_perf_monitor_group
2048 {
2049    /** Human readable name for the group. */
2050    const char *Name;
2051 
2052    /**
2053     * Maximum number of counters in this group which can be active at the
2054     * same time.
2055     */
2056    GLuint MaxActiveCounters;
2057 
2058    /** Array of counters within this group. */
2059    const struct gl_perf_monitor_counter *Counters;
2060    GLuint NumCounters;
2061 
2062    bool has_batch;
2063 };
2064 
2065 /**
2066  * A query object instance as described in INTEL_performance_query.
2067  *
2068  * NB: We want to keep this and the corresponding backend structure
2069  * relatively lean considering that applications may expect to
2070  * allocate enough objects to be able to query around all draw calls
2071  * in a frame.
2072  */
2073 struct gl_perf_query_object
2074 {
2075    GLuint Id;          /**< hash table ID/name */
2076    unsigned Used:1;    /**< has been used for 1 or more queries */
2077    unsigned Active:1;  /**< inside Begin/EndPerfQuery */
2078    unsigned Ready:1;   /**< result is ready? */
2079 };
2080 
2081 
2082 /**
2083  * Context state for AMD_performance_monitor.
2084  */
2085 struct gl_perf_monitor_state
2086 {
2087    /** Array of performance monitor groups (indexed by group ID) */
2088    const struct gl_perf_monitor_group *Groups;
2089    GLuint NumGroups;
2090 
2091    /** The table of all performance monitors. */
2092    struct _mesa_HashTable *Monitors;
2093 };
2094 
2095 
2096 /**
2097  * Context state for INTEL_performance_query.
2098  */
2099 struct gl_perf_query_state
2100 {
2101    struct _mesa_HashTable *Objects; /**< The table of all performance query objects */
2102 };
2103 
2104 
2105 /**
2106  * State common to vertex and fragment programs.
2107  */
2108 struct gl_program_state
2109 {
2110    GLint ErrorPos;                       /* GL_PROGRAM_ERROR_POSITION_ARB/NV */
2111    const char *ErrorString;              /* GL_PROGRAM_ERROR_STRING_ARB/NV */
2112 };
2113 
2114 
2115 /**
2116  * Context state for vertex programs.
2117  */
2118 struct gl_vertex_program_state
2119 {
2120    GLboolean Enabled;            /**< User-set GL_VERTEX_PROGRAM_ARB/NV flag */
2121    GLboolean PointSizeEnabled;   /**< GL_VERTEX_PROGRAM_POINT_SIZE_ARB/NV */
2122    GLboolean TwoSideEnabled;     /**< GL_VERTEX_PROGRAM_TWO_SIDE_ARB/NV */
2123    /** Whether the fixed-func program is being used right now. */
2124    GLboolean _UsesTnlProgram;
2125 
2126    struct gl_program *Current;  /**< User-bound vertex program */
2127 
2128    /** Currently enabled and valid vertex program (including internal
2129     * programs, user-defined vertex programs and GLSL vertex shaders).
2130     * This is the program we must use when rendering.
2131     */
2132    struct gl_program *_Current;
2133 
2134    GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
2135 
2136    /** Program to emulate fixed-function T&L (see above) */
2137    struct gl_program *_TnlProgram;
2138 
2139    /** Cache of fixed-function programs */
2140    struct gl_program_cache *Cache;
2141 
2142    GLboolean _Overriden;
2143 
2144    bool _VPModeOptimizesConstantAttribs;
2145 
2146    /**
2147     * If we have a vertex program, a TNL program or no program at all.
2148     * Note that this value should be kept up to date all the time,
2149     * nevertheless its correctness is asserted in _mesa_update_state.
2150     * The reason is to avoid calling _mesa_update_state twice we need
2151     * this value on draw *before* actually calling _mesa_update_state.
2152     * Also it should need to get recomputed only on changes to the
2153     * vertex program which are heavyweight already.
2154     */
2155    gl_vertex_processing_mode _VPMode;
2156 
2157    GLbitfield _VaryingInputs;  /**< mask of VERT_BIT_* flags */
2158    GLbitfield _VPModeInputFilter;
2159 };
2160 
2161 /**
2162  * Context state for tessellation control programs.
2163  */
2164 struct gl_tess_ctrl_program_state
2165 {
2166    /** Currently bound and valid shader. */
2167    struct gl_program *_Current;
2168 
2169    GLint patch_vertices;
2170    GLfloat patch_default_outer_level[4];
2171    GLfloat patch_default_inner_level[2];
2172 };
2173 
2174 /**
2175  * Context state for tessellation evaluation programs.
2176  */
2177 struct gl_tess_eval_program_state
2178 {
2179    /** Currently bound and valid shader. */
2180    struct gl_program *_Current;
2181 };
2182 
2183 /**
2184  * Context state for geometry programs.
2185  */
2186 struct gl_geometry_program_state
2187 {
2188    /**
2189     * Currently enabled and valid program (including internal programs
2190     * and compiled shader programs).
2191     */
2192    struct gl_program *_Current;
2193 };
2194 
2195 /**
2196  * Context state for fragment programs.
2197  */
2198 struct gl_fragment_program_state
2199 {
2200    GLboolean Enabled;     /**< User-set fragment program enable flag */
2201    /** Whether the fixed-func program is being used right now. */
2202    GLboolean _UsesTexEnvProgram;
2203 
2204    struct gl_program *Current;  /**< User-bound fragment program */
2205 
2206    /**
2207     * Currently enabled and valid fragment program (including internal
2208     * programs, user-defined fragment programs and GLSL fragment shaders).
2209     * This is the program we must use when rendering.
2210     */
2211    struct gl_program *_Current;
2212 
2213    GLfloat Parameters[MAX_PROGRAM_ENV_PARAMS][4]; /**< Env params */
2214 
2215    /** Program to emulate fixed-function texture env/combine (see above) */
2216    struct gl_program *_TexEnvProgram;
2217 
2218    /** Cache of fixed-function programs */
2219    struct gl_program_cache *Cache;
2220 };
2221 
2222 
2223 /**
2224  * Context state for compute programs.
2225  */
2226 struct gl_compute_program_state
2227 {
2228    /** Currently enabled and valid program (including internal programs
2229     * and compiled shader programs).
2230     */
2231    struct gl_program *_Current;
2232 };
2233 
2234 
2235 /**
2236  * ATI_fragment_shader runtime state
2237  */
2238 
2239 struct atifs_instruction;
2240 struct atifs_setupinst;
2241 
2242 /**
2243  * ATI fragment shader
2244  */
2245 struct ati_fragment_shader
2246 {
2247    GLuint Id;
2248    GLint RefCount;
2249    struct atifs_instruction *Instructions[2];
2250    struct atifs_setupinst *SetupInst[2];
2251    GLfloat Constants[8][4];
2252    GLbitfield LocalConstDef;  /**< Indicates which constants have been set */
2253    GLubyte numArithInstr[2];
2254    GLubyte regsAssigned[2];
2255    GLubyte NumPasses;         /**< 1 or 2 */
2256    /**
2257     * Current compile stage: 0 setup pass1, 1 arith pass1,
2258     * 2 setup pass2, 3 arith pass2.
2259     */
2260    GLubyte cur_pass;
2261    GLubyte last_optype;
2262    GLboolean interpinp1;
2263    GLboolean isValid;
2264    /**
2265     * Array of 2 bit values for each tex unit to remember whether
2266     * STR or STQ swizzle was used
2267     */
2268    GLuint swizzlerq;
2269    struct gl_program *Program;
2270 };
2271 
2272 /**
2273  * Context state for GL_ATI_fragment_shader
2274  */
2275 struct gl_ati_fragment_shader_state
2276 {
2277    GLboolean Enabled;
2278    GLboolean Compiling;
2279    GLfloat GlobalConstants[8][4];
2280    struct ati_fragment_shader *Current;
2281 };
2282 
2283 #define GLSL_DUMP      0x1  /**< Dump shaders to stdout */
2284 #define GLSL_LOG       0x2  /**< Write shaders to files */
2285 #define GLSL_UNIFORMS  0x4  /**< Print glUniform calls */
2286 #define GLSL_NOP_VERT  0x8  /**< Force no-op vertex shaders */
2287 #define GLSL_NOP_FRAG 0x10  /**< Force no-op fragment shaders */
2288 #define GLSL_USE_PROG 0x20  /**< Log glUseProgram calls */
2289 #define GLSL_REPORT_ERRORS 0x40  /**< Print compilation errors */
2290 #define GLSL_DUMP_ON_ERROR 0x80 /**< Dump shaders to stderr on compile error */
2291 #define GLSL_CACHE_INFO 0x100 /**< Print debug information about shader cache */
2292 #define GLSL_CACHE_FALLBACK 0x200 /**< Force shader cache fallback paths */
2293 
2294 
2295 /**
2296  * Context state for GLSL vertex/fragment shaders.
2297  * Extended to support pipeline object
2298  */
2299 struct gl_pipeline_object
2300 {
2301    /** Name of the pipeline object as received from glGenProgramPipelines.
2302     * It would be 0 for shaders without separate shader objects.
2303     */
2304    GLuint Name;
2305 
2306    GLint RefCount;
2307 
2308    GLchar *Label;   /**< GL_KHR_debug */
2309 
2310    /**
2311     * Programs used for rendering
2312     *
2313     * There is a separate program set for each shader stage.
2314     */
2315    struct gl_program *CurrentProgram[MESA_SHADER_STAGES];
2316 
2317    struct gl_shader_program *ReferencedPrograms[MESA_SHADER_STAGES];
2318 
2319    /**
2320     * Program used by glUniform calls.
2321     *
2322     * Explicitly set by \c glUseProgram and \c glActiveProgramEXT.
2323     */
2324    struct gl_shader_program *ActiveProgram;
2325 
2326    GLbitfield Flags;         /**< Mask of GLSL_x flags */
2327    GLboolean EverBound;      /**< Has the pipeline object been created */
2328    GLboolean Validated;      /**< Pipeline Validation status */
2329    GLboolean UserValidated;  /**< Validation status initiated by the user */
2330 
2331    GLchar *InfoLog;
2332 };
2333 
2334 /**
2335  * Context state for GLSL pipeline shaders.
2336  */
2337 struct gl_pipeline_shader_state
2338 {
2339    /** Currently bound pipeline object. See _mesa_BindProgramPipeline() */
2340    struct gl_pipeline_object *Current;
2341 
2342    /** Default Object to ensure that _Shader is never NULL */
2343    struct gl_pipeline_object *Default;
2344 
2345    /** Pipeline objects */
2346    struct _mesa_HashTable *Objects;
2347 };
2348 
2349 /**
2350  * Occlusion/timer query object.
2351  */
2352 struct gl_query_object
2353 {
2354    GLenum16 Target;    /**< The query target, when active */
2355    GLuint Id;          /**< hash table ID/name */
2356    GLchar *Label;      /**< GL_KHR_debug */
2357    GLuint64EXT Result; /**< the counter */
2358    GLboolean Active;   /**< inside Begin/EndQuery */
2359    GLboolean Ready;    /**< result is ready? */
2360    GLboolean EverBound;/**< has query object ever been bound */
2361    GLuint Stream;      /**< The stream */
2362 
2363    struct pipe_query *pq;
2364 
2365    /* Begin TIMESTAMP query for GL_TIME_ELAPSED_EXT queries */
2366    struct pipe_query *pq_begin;
2367 
2368    unsigned type;  /**< PIPE_QUERY_x */
2369 };
2370 
2371 
2372 /**
2373  * Context state for query objects.
2374  */
2375 struct gl_query_state
2376 {
2377    struct _mesa_HashTable *QueryObjects;
2378    struct gl_query_object *CurrentOcclusionObject; /* GL_ARB_occlusion_query */
2379    struct gl_query_object *CurrentTimerObject;     /* GL_EXT_timer_query */
2380 
2381    /** GL_NV_conditional_render */
2382    struct gl_query_object *CondRenderQuery;
2383 
2384    /** GL_EXT_transform_feedback */
2385    struct gl_query_object *PrimitivesGenerated[MAX_VERTEX_STREAMS];
2386    struct gl_query_object *PrimitivesWritten[MAX_VERTEX_STREAMS];
2387 
2388    /** GL_ARB_transform_feedback_overflow_query */
2389    struct gl_query_object *TransformFeedbackOverflow[MAX_VERTEX_STREAMS];
2390    struct gl_query_object *TransformFeedbackOverflowAny;
2391 
2392    /** GL_ARB_timer_query */
2393    struct gl_query_object *TimeElapsed;
2394 
2395    /** GL_ARB_pipeline_statistics_query */
2396    struct gl_query_object *pipeline_stats[MAX_PIPELINE_STATISTICS];
2397 
2398    GLenum16 CondRenderMode;
2399 };
2400 
2401 
2402 /** Sync object state */
2403 struct gl_sync_object
2404 {
2405    GLuint Name;               /**< Fence name */
2406    GLint RefCount;            /**< Reference count */
2407    GLchar *Label;             /**< GL_KHR_debug */
2408    GLboolean DeletePending;   /**< Object was deleted while there were still
2409                                * live references (e.g., sync not yet finished)
2410                                */
2411    GLenum16 SyncCondition;
2412    GLbitfield Flags;          /**< Flags passed to glFenceSync */
2413    GLuint StatusFlag:1;       /**< Has the sync object been signaled? */
2414 
2415    struct pipe_fence_handle *fence;
2416    simple_mtx_t mutex; /**< protects "fence" */
2417 };
2418 
2419 
2420 /**
2421  * State which can be shared by multiple contexts:
2422  */
2423 struct gl_shared_state
2424 {
2425    simple_mtx_t Mutex;		   /**< for thread safety */
2426    GLint RefCount;			   /**< Reference count */
2427    bool DisplayListsAffectGLThread;
2428 
2429    struct _mesa_HashTable *DisplayList;	   /**< Display lists hash table */
2430    struct _mesa_HashTable *BitmapAtlas;    /**< For optimized glBitmap text */
2431    struct _mesa_HashTable *TexObjects;	   /**< Texture objects hash table */
2432 
2433    /** Default texture objects (shared by all texture units) */
2434    struct gl_texture_object *DefaultTex[NUM_TEXTURE_TARGETS];
2435 
2436    /** Fallback texture used when a bound texture is incomplete */
2437    struct gl_texture_object *FallbackTex[NUM_TEXTURE_TARGETS];
2438 
2439    /**
2440     * \name Thread safety and statechange notification for texture
2441     * objects.
2442     *
2443     * \todo Improve the granularity of locking.
2444     */
2445    /*@{*/
2446    simple_mtx_t TexMutex;		/**< texobj thread safety */
2447    GLuint TextureStateStamp;	        /**< state notification for shared tex */
2448    /*@}*/
2449 
2450    /**
2451     * \name Vertex/geometry/fragment programs
2452     */
2453    /*@{*/
2454    struct _mesa_HashTable *Programs; /**< All vertex/fragment programs */
2455    struct gl_program *DefaultVertexProgram;
2456    struct gl_program *DefaultFragmentProgram;
2457    /*@}*/
2458 
2459    /* GL_ATI_fragment_shader */
2460    struct _mesa_HashTable *ATIShaders;
2461    struct ati_fragment_shader *DefaultFragmentShader;
2462 
2463    struct _mesa_HashTable *BufferObjects;
2464 
2465    /* Buffer objects released by a different context than the one that
2466     * created them. Since the creating context holds one global buffer
2467     * reference for each buffer it created and skips reference counting,
2468     * deleting a buffer by another context can't touch the buffer reference
2469     * held by the context that created it. Only the creating context can
2470     * remove its global buffer reference.
2471     *
2472     * This list contains all buffers that were deleted by a different context
2473     * than the one that created them. This list should be probed by all
2474     * contexts regularly and remove references of those buffers that they own.
2475     */
2476    struct set *ZombieBufferObjects;
2477 
2478    /** Table of both gl_shader and gl_shader_program objects */
2479    struct _mesa_HashTable *ShaderObjects;
2480 
2481    /* GL_EXT_framebuffer_object */
2482    struct _mesa_HashTable *RenderBuffers;
2483    struct _mesa_HashTable *FrameBuffers;
2484 
2485    /* GL_ARB_sync */
2486    struct set *SyncObjects;
2487 
2488    /** GL_ARB_sampler_objects */
2489    struct _mesa_HashTable *SamplerObjects;
2490 
2491    /* GL_ARB_bindless_texture */
2492    struct hash_table_u64 *TextureHandles;
2493    struct hash_table_u64 *ImageHandles;
2494    mtx_t HandlesMutex; /**< For texture/image handles safety */
2495 
2496    /* GL_ARB_shading_language_include */
2497    struct shader_includes *ShaderIncludes;
2498    /* glCompileShaderInclude expects ShaderIncludes not to change while it is
2499     * in progress.
2500     */
2501    simple_mtx_t ShaderIncludeMutex;
2502 
2503    /**
2504     * Some context in this share group was affected by a GPU reset
2505     *
2506     * On the next call to \c glGetGraphicsResetStatus, contexts that have not
2507     * been affected by a GPU reset must also return
2508     * \c GL_INNOCENT_CONTEXT_RESET_ARB.
2509     *
2510     * Once this field becomes true, it is never reset to false.
2511     */
2512    bool ShareGroupReset;
2513 
2514    /** EXT_external_objects */
2515    struct _mesa_HashTable *MemoryObjects;
2516 
2517    /** EXT_semaphore */
2518    struct _mesa_HashTable *SemaphoreObjects;
2519 
2520    /**
2521     * Some context in this share group was affected by a disjoint
2522     * operation. This operation can be anything that has effects on
2523     * values of timer queries in such manner that they become invalid for
2524     * performance metrics. As example gpu reset, counter overflow or gpu
2525     * frequency changes.
2526     */
2527    bool DisjointOperation;
2528 
2529    /**
2530     * Whether at least one image has been imported or exported, excluding
2531     * the default framebuffer. If this is false, glFlush can be executed
2532     * asynchronously because there is no invisible dependency on external
2533     * users.
2534     */
2535    bool HasExternallySharedImages;
2536 
2537    /* Small display list storage */
2538    struct {
2539       union gl_dlist_node *ptr;
2540       struct util_idalloc free_idx;
2541       unsigned size;
2542    } small_dlist_store;
2543 };
2544 
2545 
2546 
2547 /**
2548  * Renderbuffers represent drawing surfaces such as color, depth and/or
2549  * stencil.  A framebuffer object has a set of renderbuffers.
2550  * Drivers will typically derive subclasses of this type.
2551  */
2552 struct gl_renderbuffer
2553 {
2554    GLuint ClassID;        /**< Useful for drivers */
2555    GLuint Name;
2556    GLchar *Label;         /**< GL_KHR_debug */
2557    GLint RefCount;
2558    GLuint Width, Height;
2559    GLuint Depth;
2560    GLboolean AttachedAnytime; /**< TRUE if it was attached to a framebuffer */
2561    GLubyte NumSamples;    /**< zero means not multisampled */
2562    GLubyte NumStorageSamples; /**< for AMD_framebuffer_multisample_advanced */
2563    GLenum16 InternalFormat; /**< The user-specified format */
2564    GLenum16 _BaseFormat;    /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
2565                                GL_STENCIL_INDEX. */
2566    mesa_format Format;      /**< The actual renderbuffer memory format */
2567    /**
2568     * Pointer to the texture image if this renderbuffer wraps a texture,
2569     * otherwise NULL.
2570     *
2571     * Note that the reference on the gl_texture_object containing this
2572     * TexImage is held by the gl_renderbuffer_attachment.
2573     */
2574    struct gl_texture_image *TexImage;
2575 
2576    /** Delete this renderbuffer */
2577    void (*Delete)(struct gl_context *ctx, struct gl_renderbuffer *rb);
2578 
2579    /** Allocate new storage for this renderbuffer */
2580    GLboolean (*AllocStorage)(struct gl_context *ctx,
2581                              struct gl_renderbuffer *rb,
2582                              GLenum internalFormat,
2583                              GLuint width, GLuint height);
2584 
2585    struct pipe_resource *texture;
2586    /* This points to either "surface_linear" or "surface_srgb".
2587     * It doesn't hold the pipe_surface reference. The other two do.
2588     */
2589    struct pipe_surface *surface;
2590    struct pipe_surface *surface_linear;
2591    struct pipe_surface *surface_srgb;
2592    GLboolean defined;        /**< defined contents? */
2593 
2594    struct pipe_transfer *transfer; /**< only used when mapping the resource */
2595 
2596    /**
2597     * Used only when hardware accumulation buffers are not supported.
2598     */
2599    boolean software;
2600    void *data;
2601 
2602    bool use_readpix_cache;
2603 
2604    /* Inputs from Driver.RenderTexture, don't use directly. */
2605    boolean is_rtt; /**< whether Driver.RenderTexture was called */
2606    unsigned rtt_face, rtt_slice;
2607    boolean rtt_layered; /**< whether glFramebufferTexture was called */
2608    unsigned rtt_nr_samples; /**< from FramebufferTexture2DMultisampleEXT */
2609 };
2610 
2611 
2612 /**
2613  * A renderbuffer attachment points to either a texture object (and specifies
2614  * a mipmap level, cube face or 3D texture slice) or points to a renderbuffer.
2615  */
2616 struct gl_renderbuffer_attachment
2617 {
2618    GLenum16 Type; /**< \c GL_NONE or \c GL_TEXTURE or \c GL_RENDERBUFFER_EXT */
2619    GLboolean Complete;
2620 
2621    /**
2622     * If \c Type is \c GL_RENDERBUFFER_EXT, this stores a pointer to the
2623     * application supplied renderbuffer object.
2624     */
2625    struct gl_renderbuffer *Renderbuffer;
2626 
2627    /**
2628     * If \c Type is \c GL_TEXTURE, this stores a pointer to the application
2629     * supplied texture object.
2630     */
2631    struct gl_texture_object *Texture;
2632    GLuint TextureLevel; /**< Attached mipmap level. */
2633    GLsizei NumSamples;  /**< from FramebufferTexture2DMultisampleEXT */
2634    GLuint CubeMapFace;  /**< 0 .. 5, for cube map textures. */
2635    GLuint Zoffset;      /**< Slice for 3D textures,  or layer for both 1D
2636                          * and 2D array textures */
2637    GLboolean Layered;
2638 };
2639 
2640 
2641 /**
2642  * A framebuffer is a collection of renderbuffers (color, depth, stencil, etc).
2643  * In C++ terms, think of this as a base class from which device drivers
2644  * will make derived classes.
2645  */
2646 struct gl_framebuffer
2647 {
2648    simple_mtx_t Mutex;  /**< for thread safety */
2649    /**
2650     * If zero, this is a window system framebuffer.  If non-zero, this
2651     * is a FBO framebuffer; note that for some devices (i.e. those with
2652     * a natural pixel coordinate system for FBOs that differs from the
2653     * OpenGL/Mesa coordinate system), this means that the viewport,
2654     * polygon face orientation, and polygon stipple will have to be inverted.
2655     */
2656    GLuint Name;
2657    GLint RefCount;
2658 
2659    GLchar *Label;       /**< GL_KHR_debug */
2660 
2661    GLboolean DeletePending;
2662 
2663    /**
2664     * The framebuffer's visual. Immutable if this is a window system buffer.
2665     * Computed from attachments if user-made FBO.
2666     */
2667    struct gl_config Visual;
2668 
2669    /**
2670     * Size of frame buffer in pixels. If there are no attachments, then both
2671     * of these are 0.
2672     */
2673    GLuint Width, Height;
2674 
2675    /**
2676     * In the case that the framebuffer has no attachment (i.e.
2677     * GL_ARB_framebuffer_no_attachments) then the geometry of
2678     * the framebuffer is specified by the default values.
2679     */
2680    struct {
2681      GLuint Width, Height, Layers, NumSamples;
2682      GLboolean FixedSampleLocations;
2683      /* Derived from NumSamples by the driver so that it can choose a valid
2684       * value for the hardware.
2685       */
2686      GLuint _NumSamples;
2687    } DefaultGeometry;
2688 
2689    /** \name  Drawing bounds (Intersection of buffer size and scissor box)
2690     * The drawing region is given by [_Xmin, _Xmax) x [_Ymin, _Ymax),
2691     * (inclusive for _Xmin and _Ymin while exclusive for _Xmax and _Ymax)
2692     */
2693    /*@{*/
2694    GLint _Xmin, _Xmax;
2695    GLint _Ymin, _Ymax;
2696    /*@}*/
2697 
2698    /** \name  Derived Z buffer stuff */
2699    /*@{*/
2700    GLuint _DepthMax;	/**< Max depth buffer value */
2701    GLfloat _DepthMaxF;	/**< Float max depth buffer value */
2702    GLfloat _MRD;	/**< minimum resolvable difference in Z values */
2703    /*@}*/
2704 
2705    /** One of the GL_FRAMEBUFFER_(IN)COMPLETE_* tokens */
2706    GLenum16 _Status;
2707 
2708    /** Whether one of Attachment has Type != GL_NONE
2709     * NOTE: the values for Width and Height are set to 0 in case of having
2710     * no attachments, a backend driver supporting the extension
2711     * GL_ARB_framebuffer_no_attachments must check for the flag _HasAttachments
2712     * and if GL_FALSE, must then use the values in DefaultGeometry to initialize
2713     * its viewport, scissor and so on (in particular _Xmin, _Xmax, _Ymin and
2714     * _Ymax do NOT take into account _HasAttachments being false). To get the
2715     * geometry of the framebuffer, the  helper functions
2716     *   _mesa_geometric_width(),
2717     *   _mesa_geometric_height(),
2718     *   _mesa_geometric_samples() and
2719     *   _mesa_geometric_layers()
2720     * are available that check _HasAttachments.
2721     */
2722    bool _HasAttachments;
2723 
2724    GLbitfield _IntegerBuffers;  /**< Which color buffers are integer valued */
2725    GLbitfield _BlendForceAlphaToOne;  /**< Which color buffers need blend factor adjustment */
2726    GLbitfield _FP32Buffers; /**< Which color buffers are FP32 */
2727 
2728    /* ARB_color_buffer_float */
2729    GLboolean _AllColorBuffersFixedPoint; /* no integer, no float */
2730    GLboolean _HasSNormOrFloatColorBuffer;
2731 
2732    /**
2733     * The maximum number of layers in the framebuffer, or 0 if the framebuffer
2734     * is not layered.  For cube maps and cube map arrays, each cube face
2735     * counts as a layer. As the case for Width, Height a backend driver
2736     * supporting GL_ARB_framebuffer_no_attachments must use DefaultGeometry
2737     * in the case that _HasAttachments is false
2738     */
2739    GLuint MaxNumLayers;
2740 
2741    /** Array of all renderbuffer attachments, indexed by BUFFER_* tokens. */
2742    struct gl_renderbuffer_attachment Attachment[BUFFER_COUNT];
2743 
2744    /* In unextended OpenGL these vars are part of the GL_COLOR_BUFFER
2745     * attribute group and GL_PIXEL attribute group, respectively.
2746     */
2747    GLenum16 ColorDrawBuffer[MAX_DRAW_BUFFERS];
2748    GLenum16 ColorReadBuffer;
2749 
2750    /* GL_ARB_sample_locations */
2751    GLfloat *SampleLocationTable; /**< If NULL, no table has been specified */
2752    GLboolean ProgrammableSampleLocations;
2753    GLboolean SampleLocationPixelGrid;
2754 
2755    /** Computed from ColorDraw/ReadBuffer above */
2756    GLuint _NumColorDrawBuffers;
2757    gl_buffer_index _ColorDrawBufferIndexes[MAX_DRAW_BUFFERS];
2758    gl_buffer_index _ColorReadBufferIndex;
2759    struct gl_renderbuffer *_ColorDrawBuffers[MAX_DRAW_BUFFERS];
2760    struct gl_renderbuffer *_ColorReadBuffer;
2761 
2762    /* GL_MESA_framebuffer_flip_y */
2763    bool FlipY;
2764 
2765    /** Delete this framebuffer */
2766    void (*Delete)(struct gl_framebuffer *fb);
2767 
2768    struct st_framebuffer_iface *iface;
2769    enum st_attachment_type statts[ST_ATTACHMENT_COUNT];
2770    unsigned num_statts;
2771    int32_t stamp;
2772    int32_t iface_stamp;
2773    uint32_t iface_ID;
2774 
2775    /* list of framebuffer objects */
2776    struct list_head head;
2777 };
2778 
2779 /**
2780  * A stack of matrices (projection, modelview, color, texture, etc).
2781  */
2782 struct gl_matrix_stack
2783 {
2784    GLmatrix *Top;      /**< points into Stack */
2785    GLmatrix *Stack;    /**< array [MaxDepth] of GLmatrix */
2786    unsigned StackSize; /**< Number of elements in Stack */
2787    GLuint Depth;       /**< 0 <= Depth < MaxDepth */
2788    GLuint MaxDepth;    /**< size of Stack[] array */
2789    GLuint DirtyFlag;   /**< _NEW_MODELVIEW or _NEW_PROJECTION, for example */
2790 };
2791 
2792 
2793 /**
2794  * \name Bits for image transfer operations
2795  * \sa __struct gl_contextRec::ImageTransferState.
2796  */
2797 /*@{*/
2798 #define IMAGE_SCALE_BIAS_BIT                      0x1
2799 #define IMAGE_SHIFT_OFFSET_BIT                    0x2
2800 #define IMAGE_MAP_COLOR_BIT                       0x4
2801 #define IMAGE_CLAMP_BIT                           0x800
2802 
2803 
2804 /** Pixel Transfer ops */
2805 #define IMAGE_BITS (IMAGE_SCALE_BIAS_BIT | \
2806                     IMAGE_SHIFT_OFFSET_BIT | \
2807                     IMAGE_MAP_COLOR_BIT)
2808 
2809 
2810 /**
2811  * \name Bits to indicate what state has changed.
2812  */
2813 /*@{*/
2814 #define _NEW_MODELVIEW         (1u << 0)   /**< gl_context::ModelView */
2815 #define _NEW_PROJECTION        (1u << 1)   /**< gl_context::Projection */
2816 #define _NEW_TEXTURE_MATRIX    (1u << 2)   /**< gl_context::TextureMatrix */
2817 #define _NEW_COLOR             (1u << 3)   /**< gl_context::Color */
2818 #define _NEW_DEPTH             (1u << 4)   /**< gl_context::Depth */
2819 #define _NEW_TNL_SPACES        (1u << 5)  /**< _mesa_update_tnl_spaces */
2820 #define _NEW_FOG               (1u << 6)   /**< gl_context::Fog */
2821 #define _NEW_HINT              (1u << 7)   /**< gl_context::Hint */
2822 #define _NEW_LIGHT_CONSTANTS   (1u << 8)   /**< gl_context::Light */
2823 #define _NEW_LINE              (1u << 9)   /**< gl_context::Line */
2824 #define _NEW_PIXEL             (1u << 10)  /**< gl_context::Pixel */
2825 #define _NEW_POINT             (1u << 11)  /**< gl_context::Point */
2826 #define _NEW_POLYGON           (1u << 12)  /**< gl_context::Polygon */
2827 #define _NEW_POLYGONSTIPPLE    (1u << 13)  /**< gl_context::PolygonStipple */
2828 #define _NEW_SCISSOR           (1u << 14)  /**< gl_context::Scissor */
2829 #define _NEW_STENCIL           (1u << 15)  /**< gl_context::Stencil */
2830 #define _NEW_TEXTURE_OBJECT    (1u << 16)  /**< gl_context::Texture (bindings only) */
2831 #define _NEW_TRANSFORM         (1u << 17)  /**< gl_context::Transform */
2832 #define _NEW_VIEWPORT          (1u << 18)  /**< gl_context::Viewport */
2833 #define _NEW_TEXTURE_STATE     (1u << 19)  /**< gl_context::Texture (states only) */
2834 #define _NEW_LIGHT_STATE       (1u << 20)  /**< gl_context::Light */
2835 #define _NEW_RENDERMODE        (1u << 21)  /**< gl_context::RenderMode, etc */
2836 #define _NEW_BUFFERS           (1u << 22)  /**< gl_context::Visual, DrawBuffer, */
2837 #define _NEW_CURRENT_ATTRIB    (1u << 23)  /**< gl_context::Current */
2838 #define _NEW_MULTISAMPLE       (1u << 24)  /**< gl_context::Multisample */
2839 #define _NEW_TRACK_MATRIX      (1u << 25)  /**< gl_context::VertexProgram */
2840 #define _NEW_PROGRAM           (1u << 26)  /**< New program/shader state */
2841 #define _NEW_PROGRAM_CONSTANTS (1u << 27)
2842 #define _NEW_FF_VERT_PROGRAM   (1u << 28)
2843 #define _NEW_FRAG_CLAMP        (1u << 29)
2844 #define _NEW_MATERIAL          (1u << 30)  /**< gl_context::Light.Material */
2845 #define _NEW_FF_FRAG_PROGRAM   (1u << 31)
2846 #define _NEW_ALL ~0
2847 /*@}*/
2848 
2849 
2850 /**
2851  * Composite state flags, deprecated and inefficient, do not use.
2852  */
2853 /*@{*/
2854 #define _NEW_LIGHT     (_NEW_LIGHT_CONSTANTS |  /* state parameters */ \
2855                         _NEW_LIGHT_STATE |      /* rasterizer state */ \
2856                         _NEW_MATERIAL |         /* light materials */ \
2857                         _NEW_FF_VERT_PROGRAM | \
2858                         _NEW_FF_FRAG_PROGRAM)
2859 
2860 #define _NEW_TEXTURE   (_NEW_TEXTURE_OBJECT | _NEW_TEXTURE_STATE | \
2861                         _NEW_FF_VERT_PROGRAM | _NEW_FF_FRAG_PROGRAM)
2862 
2863 #define _MESA_NEW_NEED_EYE_COORDS         (_NEW_FF_VERT_PROGRAM | \
2864                                            _NEW_FF_FRAG_PROGRAM | \
2865                                            _NEW_LIGHT_CONSTANTS | \
2866                                            _NEW_TEXTURE_STATE |	\
2867                                            _NEW_POINT |		\
2868                                            _NEW_PROGRAM |	\
2869                                            _NEW_MODELVIEW)
2870 
2871 #define _MESA_NEW_SEPARATE_SPECULAR        (_NEW_LIGHT | \
2872                                             _NEW_FOG | \
2873                                             _NEW_PROGRAM)
2874 
2875 
2876 /*@}*/
2877 
2878 
2879 
2880 
2881 /* This has to be included here. */
2882 #include "dd.h"
2883 
2884 
2885 /** Opaque declaration of display list payload data type */
2886 union gl_dlist_node;
2887 
2888 
2889 /**
2890  * Per-display list information.
2891  */
2892 struct gl_display_list
2893 {
2894    GLuint Name;
2895    bool execute_glthread;
2896    bool small_list;
2897    GLchar *Label;     /**< GL_KHR_debug */
2898    /** The dlist commands are in a linked list of nodes */
2899    union {
2900       /* Big lists allocate their own storage */
2901       union gl_dlist_node *Head;
2902       /* Small lists use ctx->Shared->small_dlist_store */
2903       struct {
2904          unsigned start;
2905          unsigned count;
2906       };
2907    };
2908 };
2909 
2910 
2911 /**
2912  * State used during display list compilation and execution.
2913  */
2914 struct gl_dlist_state
2915 {
2916    struct gl_display_list *CurrentList; /**< List currently being compiled */
2917    union gl_dlist_node *CurrentBlock; /**< Pointer to current block of nodes */
2918    GLuint CurrentPos;		/**< Index into current block of nodes */
2919    GLuint CallDepth;		/**< Current recursion calling depth */
2920    GLuint LastInstSize;         /**< Size of the last node. */
2921 
2922    GLubyte ActiveAttribSize[VERT_ATTRIB_MAX];
2923    uint32_t CurrentAttrib[VERT_ATTRIB_MAX][8];
2924 
2925    GLubyte ActiveMaterialSize[MAT_ATTRIB_MAX];
2926    GLfloat CurrentMaterial[MAT_ATTRIB_MAX][4];
2927 
2928    struct {
2929       /* State known to have been set by the currently-compiling display
2930        * list.  Used to eliminate some redundant state changes.
2931        */
2932       GLenum16 ShadeModel;
2933       bool UseLoopback;
2934    } Current;
2935 };
2936 
2937 /**
2938  * Driver-specific state flags.
2939  *
2940  * These are or'd with gl_context::NewDriverState to notify a driver about
2941  * a state change. The driver sets the flags at context creation and
2942  * the meaning of the bits set is opaque to core Mesa.
2943  */
2944 struct gl_driver_flags
2945 {
2946    /**
2947     * gl_context::AtomicBufferBindings
2948     */
2949    uint64_t NewAtomicBuffer;
2950 
2951    /** gl_context::Color::Alpha* */
2952    uint64_t NewAlphaTest;
2953 
2954    /** gl_context::Multisample::Enabled */
2955    uint64_t NewMultisampleEnable;
2956 
2957    /** gl_context::Multisample::(Min)SampleShading */
2958    uint64_t NewSampleShading;
2959 
2960    /** gl_context::Transform::ClipPlanesEnabled */
2961    uint64_t NewClipPlaneEnable;
2962 
2963    /** gl_context::Color::ClampFragmentColor */
2964    uint64_t NewFragClamp;
2965 
2966    /** Shader constants (uniforms, program parameters, state constants) */
2967    uint64_t NewShaderConstants[MESA_SHADER_STAGES];
2968 
2969    /** For GL_CLAMP emulation */
2970    uint64_t NewSamplersWithClamp;
2971 };
2972 
2973 struct gl_buffer_binding
2974 {
2975    struct gl_buffer_object *BufferObject;
2976    /** Start of uniform block data in the buffer */
2977    GLintptr Offset;
2978    /** Size of data allowed to be referenced from the buffer (in bytes) */
2979    GLsizeiptr Size;
2980    /**
2981     * glBindBufferBase() indicates that the Size should be ignored and only
2982     * limited by the current size of the BufferObject.
2983     */
2984    GLboolean AutomaticSize;
2985 };
2986 
2987 /**
2988  * ARB_shader_image_load_store image unit.
2989  */
2990 struct gl_image_unit
2991 {
2992    /**
2993     * Texture object bound to this unit.
2994     */
2995    struct gl_texture_object *TexObj;
2996 
2997    /**
2998     * Level of the texture object bound to this unit.
2999     */
3000    GLubyte Level;
3001 
3002    /**
3003     * \c GL_TRUE if the whole level is bound as an array of layers, \c
3004     * GL_FALSE if only some specific layer of the texture is bound.
3005     * \sa Layer
3006     */
3007    GLboolean Layered;
3008 
3009    /**
3010     * Layer of the texture object bound to this unit as specified by the
3011     * application.
3012     */
3013    GLushort Layer;
3014 
3015    /**
3016     * Layer of the texture object bound to this unit, or zero if
3017     * Layered == false.
3018     */
3019    GLushort _Layer;
3020 
3021    /**
3022     * Access allowed to this texture image.  Either \c GL_READ_ONLY,
3023     * \c GL_WRITE_ONLY or \c GL_READ_WRITE.
3024     */
3025    GLenum16 Access;
3026 
3027    /**
3028     * GL internal format that determines the interpretation of the
3029     * image memory when shader image operations are performed through
3030     * this unit.
3031     */
3032    GLenum16 Format;
3033 
3034    /**
3035     * Mesa format corresponding to \c Format.
3036     */
3037    mesa_format _ActualFormat:16;
3038 };
3039 
3040 /**
3041  * Shader subroutines storage
3042  */
3043 struct gl_subroutine_index_binding
3044 {
3045    GLuint NumIndex;
3046    GLuint *IndexPtr;
3047 };
3048 
3049 struct gl_texture_handle_object
3050 {
3051    struct gl_texture_object *texObj;
3052    struct gl_sampler_object *sampObj;
3053    GLuint64 handle;
3054 };
3055 
3056 struct gl_image_handle_object
3057 {
3058    struct gl_image_unit imgObj;
3059    GLuint64 handle;
3060 };
3061 
3062 struct gl_memory_object
3063 {
3064    GLuint Name;            /**< hash table ID/name */
3065    GLboolean Immutable;    /**< denotes mutability state of parameters */
3066    GLboolean Dedicated;    /**< import memory from a dedicated allocation */
3067 
3068    struct pipe_memory_object *memory;
3069 
3070    /* TEXTURE_TILING_EXT param from gl_texture_object */
3071    GLuint TextureTiling;
3072 };
3073 
3074 struct gl_semaphore_object
3075 {
3076    GLuint Name;            /**< hash table ID/name */
3077    struct pipe_fence_handle *fence;
3078    enum pipe_fd_type type;
3079    uint64_t timeline_value;
3080 };
3081 
3082 /**
3083  * One element of the client attrib stack.
3084  */
3085 struct gl_client_attrib_node
3086 {
3087    GLbitfield Mask;
3088    struct gl_array_attrib Array;
3089    struct gl_vertex_array_object VAO;
3090    struct gl_pixelstore_attrib Pack;
3091    struct gl_pixelstore_attrib Unpack;
3092 };
3093 
3094 /**
3095  * The VBO module implemented in src/vbo.
3096  */
3097 struct vbo_context {
3098    struct gl_array_attributes current[VBO_ATTRIB_MAX];
3099 
3100    struct gl_vertex_array_object *VAO;
3101 
3102    struct vbo_exec_context exec;
3103    struct vbo_save_context save;
3104 };
3105 
3106 /**
3107  * glEnable node for the attribute stack. (glPushAttrib/glPopAttrib)
3108  */
3109 struct gl_enable_attrib_node
3110 {
3111    GLboolean AlphaTest;
3112    GLboolean AutoNormal;
3113    GLboolean Blend;
3114    GLbitfield ClipPlanes;
3115    GLboolean ColorMaterial;
3116    GLboolean CullFace;
3117    GLboolean DepthClampNear;
3118    GLboolean DepthClampFar;
3119    GLboolean DepthTest;
3120    GLboolean Dither;
3121    GLboolean Fog;
3122    GLboolean Light[MAX_LIGHTS];
3123    GLboolean Lighting;
3124    GLboolean LineSmooth;
3125    GLboolean LineStipple;
3126    GLboolean IndexLogicOp;
3127    GLboolean ColorLogicOp;
3128 
3129    GLboolean Map1Color4;
3130    GLboolean Map1Index;
3131    GLboolean Map1Normal;
3132    GLboolean Map1TextureCoord1;
3133    GLboolean Map1TextureCoord2;
3134    GLboolean Map1TextureCoord3;
3135    GLboolean Map1TextureCoord4;
3136    GLboolean Map1Vertex3;
3137    GLboolean Map1Vertex4;
3138    GLboolean Map2Color4;
3139    GLboolean Map2Index;
3140    GLboolean Map2Normal;
3141    GLboolean Map2TextureCoord1;
3142    GLboolean Map2TextureCoord2;
3143    GLboolean Map2TextureCoord3;
3144    GLboolean Map2TextureCoord4;
3145    GLboolean Map2Vertex3;
3146    GLboolean Map2Vertex4;
3147 
3148    GLboolean Normalize;
3149    GLboolean PixelTexture;
3150    GLboolean PointSmooth;
3151    GLboolean PolygonOffsetPoint;
3152    GLboolean PolygonOffsetLine;
3153    GLboolean PolygonOffsetFill;
3154    GLboolean PolygonSmooth;
3155    GLboolean PolygonStipple;
3156    GLboolean RescaleNormals;
3157    GLbitfield Scissor;
3158    GLboolean Stencil;
3159    GLboolean StencilTwoSide;          /* GL_EXT_stencil_two_side */
3160    GLboolean MultisampleEnabled;      /* GL_ARB_multisample */
3161    GLboolean SampleAlphaToCoverage;   /* GL_ARB_multisample */
3162    GLboolean SampleAlphaToOne;        /* GL_ARB_multisample */
3163    GLboolean SampleCoverage;          /* GL_ARB_multisample */
3164    GLboolean RasterPositionUnclipped; /* GL_IBM_rasterpos_clip */
3165 
3166    GLbitfield Texture[MAX_TEXTURE_UNITS];
3167    GLbitfield TexGen[MAX_TEXTURE_UNITS];
3168 
3169    /* GL_ARB_vertex_program */
3170    GLboolean VertexProgram;
3171    GLboolean VertexProgramPointSize;
3172    GLboolean VertexProgramTwoSide;
3173 
3174    /* GL_ARB_fragment_program */
3175    GLboolean FragmentProgram;
3176 
3177    /* GL_ARB_point_sprite */
3178    GLboolean PointSprite;
3179    GLboolean FragmentShaderATI;
3180 
3181    /* GL_ARB_framebuffer_sRGB / GL_EXT_framebuffer_sRGB */
3182    GLboolean sRGBEnabled;
3183 
3184    /* GL_NV_conservative_raster */
3185    GLboolean ConservativeRasterization;
3186 };
3187 
3188 /**
3189  * Texture node for the attribute stack. (glPushAttrib/glPopAttrib)
3190  */
3191 struct gl_texture_attrib_node
3192 {
3193    GLuint CurrentUnit;   /**< GL_ACTIVE_TEXTURE */
3194    GLuint NumTexSaved;
3195    struct gl_fixedfunc_texture_unit FixedFuncUnit[MAX_TEXTURE_COORD_UNITS];
3196    GLfloat LodBias[MAX_TEXTURE_UNITS];
3197    float LodBiasQuantized[MAX_TEXTURE_UNITS];
3198 
3199    /** Saved default texture object state. */
3200    struct gl_texture_object SavedDefaultObj[NUM_TEXTURE_TARGETS];
3201 
3202    /* For saving per texture object state (wrap modes, filters, etc),
3203     * SavedObj[][].Target is unused, so the value is invalid.
3204     */
3205    struct gl_texture_object SavedObj[MAX_COMBINED_TEXTURE_IMAGE_UNITS][NUM_TEXTURE_TARGETS];
3206 };
3207 
3208 
3209 /**
3210  * Node for the attribute stack. (glPushAttrib/glPopAttrib)
3211  */
3212 struct gl_attrib_node
3213 {
3214    GLbitfield Mask;
3215    GLbitfield OldPopAttribStateMask;
3216    struct gl_accum_attrib Accum;
3217    struct gl_colorbuffer_attrib Color;
3218    struct gl_current_attrib Current;
3219    struct gl_depthbuffer_attrib Depth;
3220    struct gl_enable_attrib_node Enable;
3221    struct gl_eval_attrib Eval;
3222    struct gl_fog_attrib Fog;
3223    struct gl_hint_attrib Hint;
3224    struct gl_light_attrib Light;
3225    struct gl_line_attrib Line;
3226    struct gl_list_attrib List;
3227    struct gl_pixel_attrib Pixel;
3228    struct gl_point_attrib Point;
3229    struct gl_polygon_attrib Polygon;
3230    GLuint PolygonStipple[32];
3231    struct gl_scissor_attrib Scissor;
3232    struct gl_stencil_attrib Stencil;
3233    struct gl_transform_attrib Transform;
3234    struct gl_multisample_attrib Multisample;
3235    struct gl_texture_attrib_node Texture;
3236 
3237    struct viewport_state
3238    {
3239       struct gl_viewport_attrib ViewportArray[MAX_VIEWPORTS];
3240       GLuint SubpixelPrecisionBias[2];
3241    } Viewport;
3242 };
3243 
3244 /**
3245  * Mesa rendering context.
3246  *
3247  * This is the central context data structure for Mesa.  Almost all
3248  * OpenGL state is contained in this structure.
3249  * Think of this as a base class from which device drivers will derive
3250  * sub classes.
3251  */
3252 struct gl_context
3253 {
3254    /** State possibly shared with other contexts in the address space */
3255    struct gl_shared_state *Shared;
3256 
3257    /** Whether Shared->BufferObjects has already been locked for this context. */
3258    bool BufferObjectsLocked;
3259    /** Whether Shared->TexMutex has already been locked for this context. */
3260    bool TexturesLocked;
3261 
3262    /** \name API function pointer tables */
3263    /*@{*/
3264    gl_api API;
3265 
3266    /**
3267     * The current dispatch table for non-displaylist-saving execution, either
3268     * BeginEnd or OutsideBeginEnd
3269     */
3270    struct _glapi_table *Exec;
3271    /**
3272     * The normal dispatch table for non-displaylist-saving, non-begin/end
3273     */
3274    struct _glapi_table *OutsideBeginEnd;
3275    /** The dispatch table used between glNewList() and glEndList() */
3276    struct _glapi_table *Save;
3277    /**
3278     * The dispatch table used between glBegin() and glEnd() (outside of a
3279     * display list).  Only valid functions between those two are set.
3280     */
3281    struct _glapi_table *BeginEnd;
3282    /**
3283     * Same as BeginEnd except vertex postion set functions. Used when
3284     * HW GL_SELECT mode instead of BeginEnd.
3285     */
3286    struct _glapi_table *HWSelectModeBeginEnd;
3287    /**
3288     * Dispatch table for when a graphics reset has happened.
3289     */
3290    struct _glapi_table *ContextLost;
3291    /**
3292     * Dispatch table used to marshal API calls from the client program to a
3293     * separate server thread.
3294     */
3295    struct _glapi_table *MarshalExec;
3296    /**
3297     * Dispatch table currently in use for fielding API calls from the client
3298     * program.  If API calls are being marshalled to another thread, this ==
3299     * MarshalExec.  Otherwise it == CurrentServerDispatch.
3300     */
3301    struct _glapi_table *CurrentClientDispatch;
3302 
3303    /**
3304     * Dispatch table currently in use for performing API calls.  == Save or
3305     * Exec.
3306     */
3307    struct _glapi_table *CurrentServerDispatch;
3308 
3309    /*@}*/
3310 
3311    struct glthread_state GLThread;
3312 
3313    struct gl_config Visual;
3314    struct gl_framebuffer *DrawBuffer;	/**< buffer for writing */
3315    struct gl_framebuffer *ReadBuffer;	/**< buffer for reading */
3316    struct gl_framebuffer *WinSysDrawBuffer;  /**< set with MakeCurrent */
3317    struct gl_framebuffer *WinSysReadBuffer;  /**< set with MakeCurrent */
3318 
3319    /**
3320     * Device driver function pointer table
3321     */
3322    struct dd_function_table Driver;
3323 
3324    /** Core/Driver constants */
3325    struct gl_constants Const;
3326 
3327    /**
3328     * Bitmask of valid primitive types supported by this context type,
3329     * GL version, and extensions, not taking current states into account.
3330     * Current states can further reduce the final bitmask at draw time.
3331     */
3332    GLbitfield SupportedPrimMask;
3333 
3334    /**
3335     * Bitmask of valid primitive types depending on current states (such as
3336     * shaders). This is 0 if the current states should result in
3337     * GL_INVALID_OPERATION in draw calls.
3338     */
3339    GLbitfield ValidPrimMask;
3340 
3341    GLenum16 DrawGLError; /**< GL error to return from draw calls */
3342 
3343    /**
3344     * Same as ValidPrimMask, but should be applied to glDrawElements*.
3345     */
3346    GLbitfield ValidPrimMaskIndexed;
3347 
3348    /**
3349     * Whether DrawPixels/CopyPixels/Bitmap are valid to render.
3350     */
3351    bool DrawPixValid;
3352 
3353    /** \name The various 4x4 matrix stacks */
3354    /*@{*/
3355    struct gl_matrix_stack ModelviewMatrixStack;
3356    struct gl_matrix_stack ProjectionMatrixStack;
3357    struct gl_matrix_stack TextureMatrixStack[MAX_TEXTURE_UNITS];
3358    struct gl_matrix_stack ProgramMatrixStack[MAX_PROGRAM_MATRICES];
3359    struct gl_matrix_stack *CurrentStack; /**< Points to one of the above stacks */
3360    /*@}*/
3361 
3362    /** Combined modelview and projection matrix */
3363    GLmatrix _ModelProjectMatrix;
3364 
3365    /** \name Display lists */
3366    struct gl_dlist_state ListState;
3367 
3368    GLboolean ExecuteFlag;	/**< Execute GL commands? */
3369    GLboolean CompileFlag;	/**< Compile GL commands into display list? */
3370 
3371    /** Extension information */
3372    struct gl_extensions Extensions;
3373 
3374    /** GL version integer, for example 31 for GL 3.1, or 20 for GLES 2.0. */
3375    GLuint Version;
3376    char *VersionString;
3377 
3378    /** \name State attribute stack (for glPush/PopAttrib) */
3379    /*@{*/
3380    GLuint AttribStackDepth;
3381    struct gl_attrib_node *AttribStack[MAX_ATTRIB_STACK_DEPTH];
3382    /*@}*/
3383 
3384    /** \name Renderer attribute groups
3385     *
3386     * We define a struct for each attribute group to make pushing and popping
3387     * attributes easy.  Also it's a good organization.
3388     */
3389    /*@{*/
3390    struct gl_accum_attrib	Accum;		/**< Accum buffer attributes */
3391    struct gl_colorbuffer_attrib	Color;		/**< Color buffer attributes */
3392    struct gl_current_attrib	Current;	/**< Current attributes */
3393    struct gl_depthbuffer_attrib	Depth;		/**< Depth buffer attributes */
3394    struct gl_eval_attrib	Eval;		/**< Eval attributes */
3395    struct gl_fog_attrib		Fog;		/**< Fog attributes */
3396    struct gl_hint_attrib	Hint;		/**< Hint attributes */
3397    struct gl_light_attrib	Light;		/**< Light attributes */
3398    struct gl_line_attrib	Line;		/**< Line attributes */
3399    struct gl_list_attrib	List;		/**< List attributes */
3400    struct gl_multisample_attrib Multisample;
3401    struct gl_pixel_attrib	Pixel;		/**< Pixel attributes */
3402    struct gl_point_attrib	Point;		/**< Point attributes */
3403    struct gl_polygon_attrib	Polygon;	/**< Polygon attributes */
3404    GLuint PolygonStipple[32];			/**< Polygon stipple */
3405    struct gl_scissor_attrib	Scissor;	/**< Scissor attributes */
3406    struct gl_stencil_attrib	Stencil;	/**< Stencil buffer attributes */
3407    struct gl_texture_attrib	Texture;	/**< Texture attributes */
3408    struct gl_transform_attrib	Transform;	/**< Transformation attributes */
3409    struct gl_viewport_attrib	ViewportArray[MAX_VIEWPORTS];	/**< Viewport attributes */
3410    GLuint SubpixelPrecisionBias[2];	/**< Viewport attributes */
3411    /*@}*/
3412 
3413    /** \name Client attribute stack */
3414    /*@{*/
3415    GLuint ClientAttribStackDepth;
3416    struct gl_client_attrib_node ClientAttribStack[MAX_CLIENT_ATTRIB_STACK_DEPTH];
3417    /*@}*/
3418 
3419    /** \name Client attribute groups */
3420    /*@{*/
3421    struct gl_array_attrib	Array;	/**< Vertex arrays */
3422    struct gl_pixelstore_attrib	Pack;	/**< Pixel packing */
3423    struct gl_pixelstore_attrib	Unpack;	/**< Pixel unpacking */
3424    struct gl_pixelstore_attrib	DefaultPacking;	/**< Default params */
3425    /*@}*/
3426 
3427    /** \name Other assorted state (not pushed/popped on attribute stack) */
3428    /*@{*/
3429    struct gl_pixelmaps          PixelMaps;
3430 
3431    struct gl_evaluators EvalMap;   /**< All evaluators */
3432    struct gl_feedback   Feedback;  /**< Feedback */
3433    struct gl_selection  Select;    /**< Selection */
3434 
3435    struct gl_program_state Program;  /**< general program state */
3436    struct gl_vertex_program_state VertexProgram;
3437    struct gl_fragment_program_state FragmentProgram;
3438    struct gl_geometry_program_state GeometryProgram;
3439    struct gl_compute_program_state ComputeProgram;
3440    struct gl_tess_ctrl_program_state TessCtrlProgram;
3441    struct gl_tess_eval_program_state TessEvalProgram;
3442    struct gl_ati_fragment_shader_state ATIFragmentShader;
3443 
3444    struct gl_pipeline_shader_state Pipeline; /**< GLSL pipeline shader object state */
3445    struct gl_pipeline_object Shader; /**< GLSL shader object state */
3446 
3447    /**
3448     * Current active shader pipeline state
3449     *
3450     * Almost all internal users want ::_Shader instead of ::Shader.  The
3451     * exceptions are bits of legacy GLSL API that do not know about separate
3452     * shader objects.
3453     *
3454     * If a program is active via \c glUseProgram, this will point to
3455     * \c ::Shader.
3456     *
3457     * If a program pipeline is active via \c glBindProgramPipeline, this will
3458     * point to \c ::Pipeline.Current.
3459     *
3460     * If neither a program nor a program pipeline is active, this will point to
3461     * \c ::Pipeline.Default.  This ensures that \c ::_Shader will never be
3462     * \c NULL.
3463     */
3464    struct gl_pipeline_object *_Shader;
3465 
3466    /**
3467     * NIR containing the functions that implement software fp64 support.
3468     */
3469    struct nir_shader *SoftFP64;
3470 
3471    struct gl_query_state Query;  /**< occlusion, timer queries */
3472 
3473    struct gl_transform_feedback_state TransformFeedback;
3474 
3475    struct gl_perf_monitor_state PerfMonitor;
3476    struct gl_perf_query_state PerfQuery;
3477 
3478    struct gl_buffer_object *DrawIndirectBuffer; /** < GL_ARB_draw_indirect */
3479    struct gl_buffer_object *ParameterBuffer; /** < GL_ARB_indirect_parameters */
3480    struct gl_buffer_object *DispatchIndirectBuffer; /** < GL_ARB_compute_shader */
3481 
3482    struct gl_buffer_object *CopyReadBuffer; /**< GL_ARB_copy_buffer */
3483    struct gl_buffer_object *CopyWriteBuffer; /**< GL_ARB_copy_buffer */
3484 
3485    struct gl_buffer_object *QueryBuffer; /**< GL_ARB_query_buffer_object */
3486 
3487    /**
3488     * Current GL_ARB_uniform_buffer_object binding referenced by
3489     * GL_UNIFORM_BUFFER target for glBufferData, glMapBuffer, etc.
3490     */
3491    struct gl_buffer_object *UniformBuffer;
3492 
3493    /**
3494     * Current GL_ARB_shader_storage_buffer_object binding referenced by
3495     * GL_SHADER_STORAGE_BUFFER target for glBufferData, glMapBuffer, etc.
3496     */
3497    struct gl_buffer_object *ShaderStorageBuffer;
3498 
3499    /**
3500     * Array of uniform buffers for GL_ARB_uniform_buffer_object and GL 3.1.
3501     * This is set up using glBindBufferRange() or glBindBufferBase().  They are
3502     * associated with uniform blocks by glUniformBlockBinding()'s state in the
3503     * shader program.
3504     */
3505    struct gl_buffer_binding
3506       UniformBufferBindings[MAX_COMBINED_UNIFORM_BUFFERS];
3507 
3508    /**
3509     * Array of shader storage buffers for ARB_shader_storage_buffer_object
3510     * and GL 4.3. This is set up using glBindBufferRange() or
3511     * glBindBufferBase().  They are associated with shader storage blocks by
3512     * glShaderStorageBlockBinding()'s state in the shader program.
3513     */
3514    struct gl_buffer_binding
3515       ShaderStorageBufferBindings[MAX_COMBINED_SHADER_STORAGE_BUFFERS];
3516 
3517    /**
3518     * Object currently associated with the GL_ATOMIC_COUNTER_BUFFER
3519     * target.
3520     */
3521    struct gl_buffer_object *AtomicBuffer;
3522 
3523    /**
3524     * Object currently associated w/ the GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD
3525     * target.
3526     */
3527    struct gl_buffer_object *ExternalVirtualMemoryBuffer;
3528 
3529    /**
3530     * Array of atomic counter buffer binding points.
3531     */
3532    struct gl_buffer_binding
3533       AtomicBufferBindings[MAX_COMBINED_ATOMIC_BUFFERS];
3534 
3535    /**
3536     * Array of image units for ARB_shader_image_load_store.
3537     */
3538    struct gl_image_unit ImageUnits[MAX_IMAGE_UNITS];
3539 
3540    struct gl_subroutine_index_binding SubroutineIndex[MESA_SHADER_STAGES];
3541    /*@}*/
3542 
3543    struct gl_meta_state *Meta;  /**< for "meta" operations */
3544 
3545    /* GL_EXT_framebuffer_object */
3546    struct gl_renderbuffer *CurrentRenderbuffer;
3547 
3548    GLenum16 ErrorValue;      /**< Last error code */
3549 
3550    /**
3551     * Recognize and silence repeated error debug messages in buggy apps.
3552     */
3553    const char *ErrorDebugFmtString;
3554    GLuint ErrorDebugCount;
3555 
3556    /* GL_ARB_debug_output/GL_KHR_debug */
3557    simple_mtx_t DebugMutex;
3558    struct gl_debug_state *Debug;
3559 
3560    GLenum16 RenderMode;      /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
3561    GLbitfield NewState;      /**< bitwise-or of _NEW_* flags */
3562    GLbitfield PopAttribState; /**< Updated state since glPushAttrib */
3563    uint64_t NewDriverState;  /**< bitwise-or of flags from DriverFlags */
3564 
3565    struct gl_driver_flags DriverFlags;
3566 
3567    GLboolean ViewportInitialized;  /**< has viewport size been initialized? */
3568    GLboolean _AllowDrawOutOfOrder;
3569 
3570    /** \name Derived state */
3571    GLbitfield _ImageTransferState;/**< bitwise-or of IMAGE_*_BIT flags */
3572    GLfloat _EyeZDir[3];
3573    GLfloat _ModelViewInvScale; /* may be for model- or eyespace lighting */
3574    GLfloat _ModelViewInvScaleEyespace; /* always factor defined in spec */
3575    GLboolean _NeedEyeCoords;
3576 
3577    GLuint TextureStateTimestamp; /**< detect changes to shared state */
3578 
3579    GLboolean LastVertexStageDirty; /**< the last vertex stage has changed */
3580    GLboolean PointSizeIsSet; /**< the glPointSize value in the shader is set */
3581 
3582    /** \name For debugging/development only */
3583    /*@{*/
3584    GLboolean FirstTimeCurrent;
3585    /*@}*/
3586 
3587    /**
3588     * False if this context was created without a config. This is needed
3589     * because the initial state of glDrawBuffers depends on this
3590     */
3591    GLboolean HasConfig;
3592 
3593    GLboolean TextureFormatSupported[MESA_FORMAT_COUNT];
3594 
3595    GLboolean RasterDiscard;  /**< GL_RASTERIZER_DISCARD */
3596    GLboolean IntelConservativeRasterization; /**< GL_CONSERVATIVE_RASTERIZATION_INTEL */
3597    GLboolean ConservativeRasterization; /**< GL_CONSERVATIVE_RASTERIZATION_NV */
3598    GLfloat ConservativeRasterDilate;
3599    GLenum16 ConservativeRasterMode;
3600 
3601    GLboolean IntelBlackholeRender; /**< GL_INTEL_blackhole_render */
3602 
3603    /** Does glVertexAttrib(0) alias glVertex()? */
3604    bool _AttribZeroAliasesVertex;
3605 
3606    /**
3607     * When set, TileRasterOrderIncreasingX/Y control the order that a tiled
3608     * renderer's tiles should be excecuted, to meet the requirements of
3609     * GL_MESA_tile_raster_order.
3610     */
3611    GLboolean TileRasterOrderFixed;
3612    GLboolean TileRasterOrderIncreasingX;
3613    GLboolean TileRasterOrderIncreasingY;
3614 
3615    /**
3616     * \name Hooks for module contexts.
3617     *
3618     * These will eventually live in the driver or elsewhere.
3619     */
3620    /*@{*/
3621    struct vbo_context vbo_context;
3622    struct st_context *st;
3623    struct pipe_screen *screen;
3624    struct pipe_context *pipe;
3625    struct st_config_options *st_opts;
3626    struct cso_context *cso_context;
3627    bool has_invalidate_buffer;
3628    bool has_string_marker;
3629    /* On old libGL's for linux we need to invalidate the drawables
3630     * on glViewpport calls, this is set via a option.
3631     */
3632    bool invalidate_on_gl_viewport;
3633 
3634    /*@}*/
3635 
3636    /**
3637     * \name NV_vdpau_interop
3638     */
3639    /*@{*/
3640    const void *vdpDevice;
3641    const void *vdpGetProcAddress;
3642    struct set *vdpSurfaces;
3643    /*@}*/
3644 
3645    /**
3646     * Has this context observed a GPU reset in any context in the share group?
3647     *
3648     * Once this field becomes true, it is never reset to false.
3649     */
3650    GLboolean ShareGroupReset;
3651 
3652    /**
3653     * \name OES_primitive_bounding_box
3654     *
3655     * Stores the arguments to glPrimitiveBoundingBox
3656     */
3657    GLfloat PrimitiveBoundingBox[8];
3658 
3659    struct disk_cache *Cache;
3660 
3661    /**
3662     * \name GL_ARB_bindless_texture
3663     */
3664    /*@{*/
3665    struct hash_table_u64 *ResidentTextureHandles;
3666    struct hash_table_u64 *ResidentImageHandles;
3667    /*@}*/
3668 
3669    bool shader_builtin_ref;
3670 };
3671 
3672 #ifndef NDEBUG
3673 extern int MESA_VERBOSE;
3674 extern int MESA_DEBUG_FLAGS;
3675 #else
3676 # define MESA_VERBOSE 0
3677 # define MESA_DEBUG_FLAGS 0
3678 #endif
3679 
3680 
3681 /** The MESA_VERBOSE var is a bitmask of these flags */
3682 enum _verbose
3683 {
3684    VERBOSE_VARRAY		= 0x0001,
3685    VERBOSE_TEXTURE		= 0x0002,
3686    VERBOSE_MATERIAL		= 0x0004,
3687    VERBOSE_PIPELINE		= 0x0008,
3688    VERBOSE_DRIVER		= 0x0010,
3689    VERBOSE_STATE		= 0x0020,
3690    VERBOSE_API			= 0x0040,
3691    VERBOSE_DISPLAY_LIST		= 0x0100,
3692    VERBOSE_LIGHTING		= 0x0200,
3693    VERBOSE_PRIMS		= 0x0400,
3694    VERBOSE_VERTS		= 0x0800,
3695    VERBOSE_DISASSEM		= 0x1000,
3696    VERBOSE_SWAPBUFFERS          = 0x4000
3697 };
3698 
3699 
3700 /** The MESA_DEBUG_FLAGS var is a bitmask of these flags */
3701 enum _debug
3702 {
3703    DEBUG_SILENT                 = (1 << 0),
3704    DEBUG_ALWAYS_FLUSH		= (1 << 1),
3705    DEBUG_INCOMPLETE_TEXTURE     = (1 << 2),
3706    DEBUG_INCOMPLETE_FBO         = (1 << 3),
3707    DEBUG_CONTEXT                = (1 << 4)
3708 };
3709 
3710 #ifdef __cplusplus
3711 }
3712 #endif
3713 
3714 #endif /* MTYPES_H */
3715