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