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