mtypes.h 151 KB
Newer Older
Jouk Jansen's avatar
 
Jouk Jansen committed
1 2
/*
 * Mesa 3-D graphics library
3
 *
4 5
 * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
 * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
6
 *
Jouk Jansen's avatar
 
Jouk Jansen committed
7 8 9 10 11 12
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
13
 *
Jouk Jansen's avatar
 
Jouk Jansen committed
14 15
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
16
 *
Jouk Jansen's avatar
 
Jouk Jansen committed
17 18 19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 21 22 23
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
Jouk Jansen's avatar
 
Jouk Jansen committed
24 25
 */

26 27 28 29 30 31
/**
 * \file mtypes.h
 * Main Mesa data structures.
 *
 * Please try to mark derived values with a leading underscore ('_').
 */
Jouk Jansen's avatar
 
Jouk Jansen committed
32

Brian Paul's avatar
Brian Paul committed
33 34
#ifndef MTYPES_H
#define MTYPES_H
35

Jouk Jansen's avatar
 
Jouk Jansen committed
36

37
#include <stdint.h>             /* uint32_t */
38
#include <stdbool.h>
39
#include "c11/threads.h"
40

41 42
#include "main/glheader.h"
#include "main/config.h"
Brian Paul's avatar
Brian Paul committed
43
#include "glapi/glapi.h"
Jouk Jansen's avatar
 
Jouk Jansen committed
44
#include "math/m_matrix.h"	/* GLmatrix */
45
#include "compiler/shader_enums.h"
46
#include "compiler/shader_info.h"
47
#include "main/formats.h"       /* MESA_FORMAT_COUNT */
48
#include "compiler/glsl/list.h"
49
#include "util/bitscan.h"
50
#include "util/u_dynarray.h"
Jouk Jansen's avatar
 
Jouk Jansen committed
51

52

53 54 55 56 57
#ifdef __cplusplus
extern "C" {
#endif


Ian Romanick's avatar
Ian Romanick committed
58 59 60 61 62 63 64
/**
 * \name 64-bit extension of GLbitfield.
 */
/*@{*/
typedef GLuint64 GLbitfield64;

/** Set a single bit */
65
#define BITFIELD64_BIT(b)      ((GLbitfield64)1 << (b))
66 67 68 69 70 71
/** Set all bits up to excluding bit b */
#define BITFIELD64_MASK(b)      \
   ((b) == 64 ? (~(GLbitfield64)0) : BITFIELD64_BIT(b) - 1)
/** Set count bits starting from bit b  */
#define BITFIELD64_RANGE(b, count) \
   (BITFIELD64_MASK((b) + (count)) & ~BITFIELD64_MASK(b))
Ian Romanick's avatar
Ian Romanick committed
72 73


74
/**
75
 * \name Some forward type declarations
Jouk Jansen's avatar
 
Jouk Jansen committed
76
 */
77
/*@{*/
Jouk Jansen's avatar
 
Jouk Jansen committed
78
struct _mesa_HashTable;
79
struct gl_attrib_node;
80
struct gl_list_extensions;
81
struct gl_meta_state;
82
struct gl_program_cache;
Jouk Jansen's avatar
 
Jouk Jansen committed
83
struct gl_texture_object;
84
struct gl_debug_state;
85
struct gl_context;
86
struct st_context;
87
struct gl_uniform_storage;
Brian Paul's avatar
Brian Paul committed
88 89
struct prog_instruction;
struct gl_program_parameter_list;
90 91
struct set;
struct set_entry;
92
struct vbo_context;
93
/*@}*/
Jouk Jansen's avatar
 
Jouk Jansen committed
94 95


96
/** Extra draw modes beyond GL_POINTS, GL_TRIANGLE_FAN, etc */
97
#define PRIM_MAX                 GL_PATCHES
98
#define PRIM_OUTSIDE_BEGIN_END   (PRIM_MAX + 1)
99
#define PRIM_UNKNOWN             (PRIM_MAX + 2)
100

101
/**
102
 * Determine if the given gl_varying_slot appears in the fragment shader.
103
 */
104 105
static inline GLboolean
_mesa_varying_slot_in_fs(gl_varying_slot slot)
106
{
107 108 109 110 111 112 113
   switch (slot) {
   case VARYING_SLOT_PSIZ:
   case VARYING_SLOT_BFC0:
   case VARYING_SLOT_BFC1:
   case VARYING_SLOT_EDGE:
   case VARYING_SLOT_CLIP_VERTEX:
   case VARYING_SLOT_LAYER:
114 115
   case VARYING_SLOT_TESS_LEVEL_OUTER:
   case VARYING_SLOT_TESS_LEVEL_INNER:
116 117
   case VARYING_SLOT_BOUNDING_BOX0:
   case VARYING_SLOT_BOUNDING_BOX1:
118 119 120 121
      return GL_FALSE;
   default:
      return GL_TRUE;
   }
122 123
}

124
/**
125 126
 * Indexes for all renderbuffers
 */
127 128 129 130 131 132 133 134 135 136
typedef enum
{
   /* the four standard color buffers */
   BUFFER_FRONT_LEFT,
   BUFFER_BACK_LEFT,
   BUFFER_FRONT_RIGHT,
   BUFFER_BACK_RIGHT,
   BUFFER_DEPTH,
   BUFFER_STENCIL,
   BUFFER_ACCUM,
Brian Paul's avatar
Brian Paul committed
137 138
   /* optional aux buffer */
   BUFFER_AUX0,
139 140 141 142 143 144 145 146 147
   /* generic renderbuffers */
   BUFFER_COLOR0,
   BUFFER_COLOR1,
   BUFFER_COLOR2,
   BUFFER_COLOR3,
   BUFFER_COLOR4,
   BUFFER_COLOR5,
   BUFFER_COLOR6,
   BUFFER_COLOR7,
148 149
   BUFFER_COUNT,
   BUFFER_NONE = -1,
150
} gl_buffer_index;
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173

/**
 * Bit flags for all renderbuffers
 */
#define BUFFER_BIT_FRONT_LEFT   (1 << BUFFER_FRONT_LEFT)
#define BUFFER_BIT_BACK_LEFT    (1 << BUFFER_BACK_LEFT)
#define BUFFER_BIT_FRONT_RIGHT  (1 << BUFFER_FRONT_RIGHT)
#define BUFFER_BIT_BACK_RIGHT   (1 << BUFFER_BACK_RIGHT)
#define BUFFER_BIT_AUX0         (1 << BUFFER_AUX0)
#define BUFFER_BIT_AUX1         (1 << BUFFER_AUX1)
#define BUFFER_BIT_AUX2         (1 << BUFFER_AUX2)
#define BUFFER_BIT_AUX3         (1 << BUFFER_AUX3)
#define BUFFER_BIT_DEPTH        (1 << BUFFER_DEPTH)
#define BUFFER_BIT_STENCIL      (1 << BUFFER_STENCIL)
#define BUFFER_BIT_ACCUM        (1 << BUFFER_ACCUM)
#define BUFFER_BIT_COLOR0       (1 << BUFFER_COLOR0)
#define BUFFER_BIT_COLOR1       (1 << BUFFER_COLOR1)
#define BUFFER_BIT_COLOR2       (1 << BUFFER_COLOR2)
#define BUFFER_BIT_COLOR3       (1 << BUFFER_COLOR3)
#define BUFFER_BIT_COLOR4       (1 << BUFFER_COLOR4)
#define BUFFER_BIT_COLOR5       (1 << BUFFER_COLOR5)
#define BUFFER_BIT_COLOR6       (1 << BUFFER_COLOR6)
#define BUFFER_BIT_COLOR7       (1 << BUFFER_COLOR7)
174

Brian Paul's avatar
Brian Paul committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
/**
 * Mask of all the color buffer bits (but not accum).
 */
#define BUFFER_BITS_COLOR  (BUFFER_BIT_FRONT_LEFT | \
                            BUFFER_BIT_BACK_LEFT | \
                            BUFFER_BIT_FRONT_RIGHT | \
                            BUFFER_BIT_BACK_RIGHT | \
                            BUFFER_BIT_AUX0 | \
                            BUFFER_BIT_COLOR0 | \
                            BUFFER_BIT_COLOR1 | \
                            BUFFER_BIT_COLOR2 | \
                            BUFFER_BIT_COLOR3 | \
                            BUFFER_BIT_COLOR4 | \
                            BUFFER_BIT_COLOR5 | \
                            BUFFER_BIT_COLOR6 | \
                            BUFFER_BIT_COLOR7)

192 193 194
/* Mask of bits for depth+stencil buffers */
#define BUFFER_BITS_DEPTH_STENCIL (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL)

195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
/**
 * Framebuffer configuration (aka visual / pixelformat)
 * Note: some of these fields should be boolean, but it appears that
 * code in drivers/dri/common/util.c requires int-sized fields.
 */
struct gl_config
{
   GLboolean rgbMode;
   GLboolean floatMode;
   GLuint doubleBufferMode;
   GLuint stereoMode;

   GLboolean haveAccumBuffer;
   GLboolean haveDepthBuffer;
   GLboolean haveStencilBuffer;

   GLint redBits, greenBits, blueBits, alphaBits;	/* bits per comp */
   GLuint redMask, greenMask, blueMask, alphaMask;
   GLint rgbBits;		/* total bits for rgb */
   GLint indexBits;		/* total bits for colorindex */

   GLint accumRedBits, accumGreenBits, accumBlueBits, accumAlphaBits;
   GLint depthBits;
   GLint stencilBits;

   GLint numAuxBuffers;

   GLint level;

   /* EXT_visual_rating / GLX 1.2 */
   GLint visualRating;

   /* EXT_visual_info / GLX 1.2 */
   GLint transparentPixel;
   /*    colors are floats scaled to ints */
   GLint transparentRed, transparentGreen, transparentBlue, transparentAlpha;
   GLint transparentIndex;

   /* ARB_multisample / SGIS_multisample */
   GLint sampleBuffers;
   GLint samples;

   /* SGIX_pbuffer / GLX 1.3 */
   GLint maxPbufferWidth;
   GLint maxPbufferHeight;
   GLint maxPbufferPixels;
   GLint optimalPbufferWidth;   /* Only for SGIX_pbuffer. */
   GLint optimalPbufferHeight;  /* Only for SGIX_pbuffer. */

   /* OML_swap_method */
   GLint swapMethod;

   /* EXT_texture_from_pixmap */
   GLint bindToTextureRgb;
   GLint bindToTextureRgba;
   GLint bindToMipmapTexture;
   GLint bindToTextureTargets;
   GLint yInverted;
253 254 255

   /* EXT_framebuffer_sRGB */
   GLint sRGBCapable;
256 257 258
};


259 260
/**
 * \name Bit flags used for updating material values.
Jouk Jansen's avatar
 
Jouk Jansen committed
261
 */
262
/*@{*/
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
#define MAT_ATTRIB_FRONT_AMBIENT           0 
#define MAT_ATTRIB_BACK_AMBIENT            1
#define MAT_ATTRIB_FRONT_DIFFUSE           2 
#define MAT_ATTRIB_BACK_DIFFUSE            3
#define MAT_ATTRIB_FRONT_SPECULAR          4 
#define MAT_ATTRIB_BACK_SPECULAR           5
#define MAT_ATTRIB_FRONT_EMISSION          6
#define MAT_ATTRIB_BACK_EMISSION           7
#define MAT_ATTRIB_FRONT_SHININESS         8
#define MAT_ATTRIB_BACK_SHININESS          9
#define MAT_ATTRIB_FRONT_INDEXES           10
#define MAT_ATTRIB_BACK_INDEXES            11
#define MAT_ATTRIB_MAX                     12

#define MAT_ATTRIB_AMBIENT(f)  (MAT_ATTRIB_FRONT_AMBIENT+(f))  
#define MAT_ATTRIB_DIFFUSE(f)  (MAT_ATTRIB_FRONT_DIFFUSE+(f))  
#define MAT_ATTRIB_SPECULAR(f) (MAT_ATTRIB_FRONT_SPECULAR+(f)) 
#define MAT_ATTRIB_EMISSION(f) (MAT_ATTRIB_FRONT_EMISSION+(f)) 
#define MAT_ATTRIB_SHININESS(f)(MAT_ATTRIB_FRONT_SHININESS+(f))
#define MAT_ATTRIB_INDEXES(f)  (MAT_ATTRIB_FRONT_INDEXES+(f))  

#define MAT_INDEX_AMBIENT  0
#define MAT_INDEX_DIFFUSE  1
#define MAT_INDEX_SPECULAR 2

#define MAT_BIT_FRONT_AMBIENT         (1<<MAT_ATTRIB_FRONT_AMBIENT)
#define MAT_BIT_BACK_AMBIENT          (1<<MAT_ATTRIB_BACK_AMBIENT)
#define MAT_BIT_FRONT_DIFFUSE         (1<<MAT_ATTRIB_FRONT_DIFFUSE)
#define MAT_BIT_BACK_DIFFUSE          (1<<MAT_ATTRIB_BACK_DIFFUSE)
#define MAT_BIT_FRONT_SPECULAR        (1<<MAT_ATTRIB_FRONT_SPECULAR)
#define MAT_BIT_BACK_SPECULAR         (1<<MAT_ATTRIB_BACK_SPECULAR)
#define MAT_BIT_FRONT_EMISSION        (1<<MAT_ATTRIB_FRONT_EMISSION)
#define MAT_BIT_BACK_EMISSION         (1<<MAT_ATTRIB_BACK_EMISSION)
#define MAT_BIT_FRONT_SHININESS       (1<<MAT_ATTRIB_FRONT_SHININESS)
#define MAT_BIT_BACK_SHININESS        (1<<MAT_ATTRIB_BACK_SHININESS)
#define MAT_BIT_FRONT_INDEXES         (1<<MAT_ATTRIB_FRONT_INDEXES)
#define MAT_BIT_BACK_INDEXES          (1<<MAT_ATTRIB_BACK_INDEXES)


#define FRONT_MATERIAL_BITS	(MAT_BIT_FRONT_EMISSION | 	\
				 MAT_BIT_FRONT_AMBIENT |	\
				 MAT_BIT_FRONT_DIFFUSE | 	\
				 MAT_BIT_FRONT_SPECULAR |	\
				 MAT_BIT_FRONT_SHININESS | 	\
				 MAT_BIT_FRONT_INDEXES)

#define BACK_MATERIAL_BITS	(MAT_BIT_BACK_EMISSION |	\
				 MAT_BIT_BACK_AMBIENT |		\
				 MAT_BIT_BACK_DIFFUSE |		\
				 MAT_BIT_BACK_SPECULAR |	\
				 MAT_BIT_BACK_SHININESS |	\
				 MAT_BIT_BACK_INDEXES)
Jouk Jansen's avatar
 
Jouk Jansen committed
315 316

#define ALL_MATERIAL_BITS	(FRONT_MATERIAL_BITS | BACK_MATERIAL_BITS)
317
/*@}*/
Jouk Jansen's avatar
 
Jouk Jansen committed
318 319


320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
/**
 * Material state.
 */
struct gl_material
{
   GLfloat Attrib[MAT_ATTRIB_MAX][4];
};


/**
 * Light state flags.
 */
/*@{*/
#define LIGHT_SPOT         0x1
#define LIGHT_LOCAL_VIEWER 0x2
#define LIGHT_POSITIONAL   0x4
#define LIGHT_NEED_VERTICES (LIGHT_POSITIONAL|LIGHT_LOCAL_VIEWER)
/*@}*/


340
/**
341
 * Light source state.
342
 */
343 344
struct gl_light
{
345 346 347 348
   GLfloat Ambient[4];		/**< ambient color */
   GLfloat Diffuse[4];		/**< diffuse color */
   GLfloat Specular[4];		/**< specular color */
   GLfloat EyePosition[4];	/**< position in eye coordinates */
349
   GLfloat SpotDirection[4];	/**< spotlight direction in eye coordinates */
Jouk Jansen's avatar
 
Jouk Jansen committed
350
   GLfloat SpotExponent;
Jouk Jansen's avatar
 
Jouk Jansen committed
351
   GLfloat SpotCutoff;		/**< in degrees */
352
   GLfloat _CosCutoff;		/**< = MAX(0, cos(SpotCutoff)) */
Jouk Jansen's avatar
 
Jouk Jansen committed
353 354 355
   GLfloat ConstantAttenuation;
   GLfloat LinearAttenuation;
   GLfloat QuadraticAttenuation;
356
   GLboolean Enabled;		/**< On/off flag */
Jouk Jansen's avatar
 
Jouk Jansen committed
357

358 359 360 361
   /** 
    * \name Derived fields
    */
   /*@{*/
362
   GLbitfield _Flags;		/**< Mask of LIGHT_x bits defined above */
Jouk Jansen's avatar
 
Jouk Jansen committed
363

364 365 366
   GLfloat _Position[4];	/**< position in eye/obj coordinates */
   GLfloat _VP_inf_norm[3];	/**< Norm direction to infinite light */
   GLfloat _h_inf_norm[3];	/**< Norm( _VP_inf_norm + <0,0,1> ) */
367
   GLfloat _NormSpotDirection[4]; /**< normalized spotlight direction */
368
   GLfloat _VP_inf_spot_attenuation;
Jouk Jansen's avatar
 
Jouk Jansen committed
369

370 371 372 373
   GLfloat _MatAmbient[2][3];	/**< material ambient * light ambient */
   GLfloat _MatDiffuse[2][3];	/**< material diffuse * light diffuse */
   GLfloat _MatSpecular[2][3];	/**< material spec * light specular */
   /*@}*/
Jouk Jansen's avatar
 
Jouk Jansen committed
374 375 376
};


377
/**
378
 * Light model state.
379
 */
380 381
struct gl_lightmodel
{
382 383 384 385 386
   GLfloat Ambient[4];		/**< ambient color */
   GLboolean LocalViewer;	/**< Local (or infinite) view point? */
   GLboolean TwoSide;		/**< Two (or one) sided lighting? */
   GLenum ColorControl;		/**< either GL_SINGLE_COLOR
				 *    or GL_SEPARATE_SPECULAR_COLOR */
Jouk Jansen's avatar
 
Jouk Jansen committed
387 388 389
};


390
/**
391
 * Accumulation buffer attribute group (GL_ACCUM_BUFFER_BIT)
Jouk Jansen's avatar
 
Jouk Jansen committed
392
 */
393 394
struct gl_accum_attrib
{
395
   GLfloat ClearColor[4];	/**< Accumulation buffer clear color */
Jouk Jansen's avatar
 
Jouk Jansen committed
396 397
};

398 399 400 401 402 403 404

/**
 * Used for storing clear color, texture border color, etc.
 * The float values are typically unclamped.
 */
union gl_color_union
{
405 406 407 408
   GLfloat f[4];
   GLint i[4];
   GLuint ui[4];
};
Jouk Jansen's avatar
 
Jouk Jansen committed
409

410

411
/**
412
 * Color buffer attribute group (GL_COLOR_BUFFER_BIT).
413
 */
414 415
struct gl_colorbuffer_attrib
{
416 417 418 419
   GLuint ClearIndex;                      /**< Index for glClear */
   union gl_color_union ClearColor;        /**< Color for glClear, unclamped */
   GLuint IndexMask;                       /**< Color index write mask */
   GLubyte ColorMask[MAX_DRAW_BUFFERS][4]; /**< Each flag is 0xff or 0x0 */
420

421
   GLenum DrawBuffer[MAX_DRAW_BUFFERS];	/**< Which buffer to draw into */
422 423 424 425 426 427 428

   /** 
    * \name alpha testing
    */
   /*@{*/
   GLboolean AlphaEnabled;		/**< Alpha test enabled flag */
   GLenum AlphaFunc;			/**< Alpha test function */
429
   GLfloat AlphaRefUnclamped;
430 431 432 433 434 435 436
   GLclampf AlphaRef;			/**< Alpha reference value */
   /*@}*/

   /** 
    * \name Blending
    */
   /*@{*/
437
   GLbitfield BlendEnabled;		/**< Per-buffer blend enable flags */
438

439 440
   /* NOTE: this does _not_ depend on fragment clamping or any other clamping
    * control, only on the fixed-pointness of the render target.
441 442 443
    * The query does however depend on fragment color clamping.
    */
   GLfloat BlendColorUnclamped[4];               /**< Blending color */
444
   GLfloat BlendColor[4];		/**< Blending color */
445

446 447 448 449 450 451 452 453
   struct
   {
      GLenum SrcRGB;             /**< RGB blend source term */
      GLenum DstRGB;             /**< RGB blend dest term */
      GLenum SrcA;               /**< Alpha blend source term */
      GLenum DstA;               /**< Alpha blend dest term */
      GLenum EquationRGB;        /**< GL_ADD, GL_SUBTRACT, etc. */
      GLenum EquationA;          /**< GL_ADD, GL_SUBTRACT, etc. */
454 455 456 457 458
      /**
       * Set if any blend factor uses SRC1.  Computed at the time blend factors
       * get set.
       */
      GLboolean _UsesDualSrc;
459 460 461 462 463
   } Blend[MAX_DRAW_BUFFERS];
   /** Are the blend func terms currently different for each buffer/target? */
   GLboolean _BlendFuncPerBuffer;
   /** Are the blend equations currently different for each buffer/target? */
   GLboolean _BlendEquationPerBuffer;
464 465 466 467 468 469 470 471 472

   /**
    * Which advanced blending mode is in use (or BLEND_NONE).
    *
    * KHR_blend_equation_advanced only allows advanced blending with a single
    * draw buffer, and NVX_blend_equation_advanced_multi_draw_buffer still
    * requires all draw buffers to match, so we only need a single value.
    */
   enum gl_advanced_blend_mode _AdvancedBlendMode;
473 474 475

   /** Coherency requested via glEnable(GL_BLEND_ADVANCED_COHERENT_KHR)? */
   bool BlendCoherent;
476 477 478 479 480 481 482 483
   /*@}*/

   /** 
    * \name Logic op
    */
   /*@{*/
   GLboolean IndexLogicOpEnabled;	/**< Color index logic op enabled flag */
   GLboolean ColorLogicOpEnabled;	/**< RGBA logic op enabled flag */
484 485
   GLenum LogicOp;			/**< Logic operator */

486 487 488
   /*@}*/

   GLboolean DitherFlag;		/**< Dither enable flag */
489

490
   GLboolean _ClampFragmentColor; /** < with GL_FIXED_ONLY_ARB resolved */
491
   GLenum ClampFragmentColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
492
   GLenum ClampReadColor;     /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
493

494
   GLboolean sRGBEnabled;    /**< Framebuffer sRGB blending/updating requested */
Jouk Jansen's avatar
 
Jouk Jansen committed
495 496 497
};


498
/**
499
 * Current attribute group (GL_CURRENT_BIT).
500
 */
501 502
struct gl_current_attrib
{
503
   /**
504
    * \name Current vertex attributes (color, texcoords, etc).
505
    * \note Values are valid only after FLUSH_VERTICES has been called.
506 507
    * \note Index and Edgeflag current values are stored as floats in the 
    * SIX and SEVEN attribute slots.
508
    * \note We need double storage for 64-bit vertex attributes
Jouk Jansen's avatar
 
Jouk Jansen committed
509
    */
510
   GLfloat Attrib[VERT_ATTRIB_MAX][4*2];
511

512
   /**
513 514
    * \name Current raster position attributes (always up to date after a
    * glRasterPos call).
Jouk Jansen's avatar
 
Jouk Jansen committed
515
    */
516 517 518 519
   GLfloat RasterPos[4];
   GLfloat RasterDistance;
   GLfloat RasterColor[4];
   GLfloat RasterSecondaryColor[4];
520
   GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
521
   GLboolean RasterPosValid;
Jouk Jansen's avatar
 
Jouk Jansen committed
522 523 524
};


525
/**
526
 * Depth buffer attribute group (GL_DEPTH_BUFFER_BIT).
527
 */
528 529
struct gl_depthbuffer_attrib
{
530
   GLenum Func;			/**< Function for depth buffer compare */
Keith Whitwell's avatar
Keith Whitwell committed
531
   GLclampd Clear;		/**< Value to clear depth buffer to */
532 533 534 535
   GLboolean Test;		/**< Depth buffering enabled flag */
   GLboolean Mask;		/**< Depth buffer writable? */
   GLboolean BoundsTest;        /**< GL_EXT_depth_bounds_test */
   GLfloat BoundsMin, BoundsMax;/**< GL_EXT_depth_bounds_test */
Jouk Jansen's avatar
 
Jouk Jansen committed
536 537 538
};


539
/**
540
 * Evaluator attribute group (GL_EVAL_BIT).
541
 */
542 543
struct gl_eval_attrib
{
544 545 546 547
   /**
    * \name Enable bits 
    */
   /*@{*/
Jouk Jansen's avatar
 
Jouk Jansen committed
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
   GLboolean Map1Color4;
   GLboolean Map1Index;
   GLboolean Map1Normal;
   GLboolean Map1TextureCoord1;
   GLboolean Map1TextureCoord2;
   GLboolean Map1TextureCoord3;
   GLboolean Map1TextureCoord4;
   GLboolean Map1Vertex3;
   GLboolean Map1Vertex4;
   GLboolean Map2Color4;
   GLboolean Map2Index;
   GLboolean Map2Normal;
   GLboolean Map2TextureCoord1;
   GLboolean Map2TextureCoord2;
   GLboolean Map2TextureCoord3;
   GLboolean Map2TextureCoord4;
   GLboolean Map2Vertex3;
   GLboolean Map2Vertex4;
   GLboolean AutoNormal;
567 568 569 570 571 572
   /*@}*/
   
   /**
    * \name Map Grid endpoints and divisions and calculated du values
    */
   /*@{*/
Jouk Jansen's avatar
 
Jouk Jansen committed
573 574 575 576 577
   GLint MapGrid1un;
   GLfloat MapGrid1u1, MapGrid1u2, MapGrid1du;
   GLint MapGrid2un, MapGrid2vn;
   GLfloat MapGrid2u1, MapGrid2u2, MapGrid2du;
   GLfloat MapGrid2v1, MapGrid2v2, MapGrid2dv;
578
   /*@}*/
Jouk Jansen's avatar
 
Jouk Jansen committed
579 580 581
};


582 583 584 585 586 587 588 589 590 591 592 593
/**
 * Compressed fog mode.
 */
enum gl_fog_mode
{
   FOG_NONE,
   FOG_LINEAR,
   FOG_EXP,
   FOG_EXP2,
};


594
/**
595
 * Fog attribute group (GL_FOG_BIT).
596
 */
597 598
struct gl_fog_attrib
{
599
   GLboolean Enabled;		/**< Fog enabled flag */
600
   GLboolean ColorSumEnabled;
601 602
   uint8_t _PackedMode;		/**< Fog mode as 2 bits */
   uint8_t _PackedEnabledMode;	/**< Masked CompressedMode */
603
   GLfloat ColorUnclamped[4];            /**< Fog color */
604 605 606 607 608 609
   GLfloat Color[4];		/**< Fog color */
   GLfloat Density;		/**< Density >= 0.0 */
   GLfloat Start;		/**< Start distance in eye coords */
   GLfloat End;			/**< End distance in eye coords */
   GLfloat Index;		/**< Fog index */
   GLenum Mode;			/**< Fog mode */
Jouk Jansen's avatar
 
Jouk Jansen committed
610
   GLenum FogCoordinateSource;  /**< GL_EXT_fog_coord */
Michal Krol's avatar
Michal Krol committed
611
   GLfloat _Scale;		/**< (End == Start) ? 1.0 : 1.0 / (End - Start) */
612
   GLenum FogDistanceMode;     /**< GL_NV_fog_distance */
Jouk Jansen's avatar
 
Jouk Jansen committed
613 614 615
};


616
/** 
617
 * Hint attribute group (GL_HINT_BIT).
618 619 620
 * 
 * Values are always one of GL_FASTEST, GL_NICEST, or GL_DONT_CARE.
 */
621 622
struct gl_hint_attrib
{
Jouk Jansen's avatar
 
Jouk Jansen committed
623 624 625 626 627
   GLenum PerspectiveCorrection;
   GLenum PointSmooth;
   GLenum LineSmooth;
   GLenum PolygonSmooth;
   GLenum Fog;
628
   GLenum TextureCompression;   /**< GL_ARB_texture_compression */
Brian Paul's avatar
Brian Paul committed
629
   GLenum GenerateMipmap;       /**< GL_SGIS_generate_mipmap */
Michal Krol's avatar
Michal Krol committed
630
   GLenum FragmentShaderDerivative; /**< GL_ARB_fragment_shader */
Jouk Jansen's avatar
 
Jouk Jansen committed
631 632
};

Brian Paul's avatar
Brian Paul committed
633

634
/**
635
 * Lighting attribute group (GL_LIGHT_BIT).
636
 */
637 638 639
struct gl_light_attrib
{
   struct gl_light Light[MAX_LIGHTS];	/**< Array of light sources */
640
   struct gl_lightmodel Model;		/**< Lighting model */
Keith Whitwell's avatar
Keith Whitwell committed
641

642
   /**
643 644
    * Front and back material values.
    * Note: must call FLUSH_VERTICES() before using.
Keith Whitwell's avatar
Keith Whitwell committed
645
    */
646
   struct gl_material Material;
647 648

   GLboolean Enabled;			/**< Lighting enabled flag */
Dave Airlie's avatar
Dave Airlie committed
649 650
   GLboolean ColorMaterialEnabled;

651
   GLenum ShadeModel;			/**< GL_FLAT or GL_SMOOTH */
652
   GLenum ProvokingVertex;              /**< GL_EXT_provoking_vertex */
653 654
   GLenum ColorMaterialFace;		/**< GL_FRONT, BACK or FRONT_AND_BACK */
   GLenum ColorMaterialMode;		/**< GL_AMBIENT, GL_DIFFUSE, etc */
655
   GLbitfield _ColorMaterialBitmask;	/**< bitmask formed from Face and Mode */
Jouk Jansen's avatar
 
Jouk Jansen committed
656

Dave Airlie's avatar
Dave Airlie committed
657 658 659

   GLboolean _ClampVertexColor;
   GLenum ClampVertexColor;             /**< GL_TRUE, GL_FALSE, GL_FIXED_ONLY */
Jouk Jansen's avatar
 
Jouk Jansen committed
660

661
   /** 
662
    * Derived state for optimizations: 
663 664
    */
   /*@{*/
665 666
   GLbitfield _EnabledLights;	/**< bitmask containing enabled lights */

667 668
   GLboolean _NeedEyeCoords;		
   GLboolean _NeedVertices;		/**< Use fast shader? */
Dave Airlie's avatar
Dave Airlie committed
669

Jouk Jansen's avatar
 
Jouk Jansen committed
670
   GLfloat _BaseColor[2][3];
671
   /*@}*/
Jouk Jansen's avatar
 
Jouk Jansen committed
672 673 674
};


675
/**
676
 * Line attribute group (GL_LINE_BIT).
677
 */
678 679
struct gl_line_attrib
{
680 681 682 683 684
   GLboolean SmoothFlag;	/**< GL_LINE_SMOOTH enabled? */
   GLboolean StippleFlag;	/**< GL_LINE_STIPPLE enabled? */
   GLushort StipplePattern;	/**< Stipple pattern */
   GLint StippleFactor;		/**< Stipple repeat factor */
   GLfloat Width;		/**< Line width */
Jouk Jansen's avatar
 
Jouk Jansen committed
685 686 687
};


688
/**
689
 * Display list attribute group (GL_LIST_BIT).
690
 */
691 692
struct gl_list_attrib
{
Jouk Jansen's avatar
 
Jouk Jansen committed
693 694 695
   GLuint ListBase;
};

Brian Paul's avatar
Brian Paul committed
696

697
/**
698
 * Multisample attribute group (GL_MULTISAMPLE_BIT).
699
 */
700 701
struct gl_multisample_attrib
{
702 703 704 705 706
   GLboolean Enabled;
   GLboolean SampleAlphaToCoverage;
   GLboolean SampleAlphaToOne;
   GLboolean SampleCoverage;
   GLboolean SampleCoverageInvert;
707
   GLboolean SampleShading;
Chris Forbes's avatar
Chris Forbes committed
708 709 710

   /* ARB_texture_multisample / GL3.2 additions */
   GLboolean SampleMask;
711

712 713
   GLfloat SampleCoverageValue;  /**< In range [0, 1] */
   GLfloat MinSampleShadingValue;  /**< In range [0, 1] */
714

715 716
   /** The GL spec defines this as an array but >32x MSAA is madness */
   GLbitfield SampleMaskValue;
717 718 719
};


Brian's avatar
Brian committed
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
/**
 * A pixelmap (see glPixelMap)
 */
struct gl_pixelmap
{
   GLint Size;
   GLfloat Map[MAX_PIXEL_MAP_TABLE];
};


/**
 * Collection of all pixelmaps
 */
struct gl_pixelmaps
{
   struct gl_pixelmap RtoR;  /**< i.e. GL_PIXEL_MAP_R_TO_R */
   struct gl_pixelmap GtoG;
   struct gl_pixelmap BtoB;
   struct gl_pixelmap AtoA;
   struct gl_pixelmap ItoR;
   struct gl_pixelmap ItoG;
   struct gl_pixelmap ItoB;
   struct gl_pixelmap ItoA;
   struct gl_pixelmap ItoI;
   struct gl_pixelmap StoS;
};


748
/**
749
 * Pixel attribute group (GL_PIXEL_MODE_BIT).
750
 */
751 752
struct gl_pixel_attrib
{
753
   GLenum ReadBuffer;		/**< source buffer for glRead/CopyPixels() */
Brian's avatar
Brian committed
754 755 756 757

   /*--- Begin Pixel Transfer State ---*/
   /* Fields are in the order in which they're applied... */

758 759
   /** Scale & Bias (index shift, offset) */
   /*@{*/
Jouk Jansen's avatar
 
Jouk Jansen committed
760 761 762 763 764 765
   GLfloat RedBias, RedScale;
   GLfloat GreenBias, GreenScale;
   GLfloat BlueBias, BlueScale;
   GLfloat AlphaBias, AlphaScale;
   GLfloat DepthBias, DepthScale;
   GLint IndexShift, IndexOffset;
766
   /*@}*/
Brian's avatar
Brian committed
767 768 769

   /* Pixel Maps */
   /* Note: actual pixel maps are not part of this attrib group */
Jouk Jansen's avatar
 
Jouk Jansen committed
770 771
   GLboolean MapColorFlag;
   GLboolean MapStencilFlag;
Brian's avatar
Brian committed
772 773 774

   /*--- End Pixel Transfer State ---*/

Brian Paul's avatar
Brian Paul committed
775
   /** glPixelZoom */
Brian's avatar
Brian committed
776
   GLfloat ZoomX, ZoomY;
Jouk Jansen's avatar
 
Jouk Jansen committed
777 778 779
};


780
/**
781
 * Point attribute group (GL_POINT_BIT).
782
 */
783 784
struct gl_point_attrib
{
785 786 787 788
   GLfloat Size;		/**< User-specified point size */
   GLfloat Params[3];		/**< GL_EXT_point_parameters */
   GLfloat MinSize, MaxSize;	/**< GL_EXT_point_parameters */
   GLfloat Threshold;		/**< GL_EXT_point_parameters */
Dave Airlie's avatar
Dave Airlie committed
789
   GLboolean SmoothFlag;	/**< True if GL_POINT_SMOOTH is enabled */
790
   GLboolean _Attenuated;	/**< True if Params != [1, 0, 0] */
791
   GLboolean PointSprite;	/**< GL_NV/ARB_point_sprite */
792
   GLbitfield CoordReplace;     /**< GL_ARB_point_sprite*/
793
   GLenum SpriteRMode;		/**< GL_NV_point_sprite (only!) */
794
   GLenum SpriteOrigin;		/**< GL_ARB_point_sprite */
Jouk Jansen's avatar
 
Jouk Jansen committed
795 796 797
};


798
/**
799
 * Polygon attribute group (GL_POLYGON_BIT).
800
 */
801 802
struct gl_polygon_attrib
{
803 804 805 806 807 808 809 810 811
   GLenum FrontFace;		/**< Either GL_CW or GL_CCW */
   GLenum FrontMode;		/**< Either GL_POINT, GL_LINE or GL_FILL */
   GLenum BackMode;		/**< Either GL_POINT, GL_LINE or GL_FILL */
   GLboolean CullFlag;		/**< Culling on/off flag */
   GLboolean SmoothFlag;	/**< True if GL_POLYGON_SMOOTH is enabled */
   GLboolean StippleFlag;	/**< True if GL_POLYGON_STIPPLE is enabled */
   GLenum CullFaceMode;		/**< Culling mode GL_FRONT or GL_BACK */
   GLfloat OffsetFactor;	/**< Polygon offset factor, from user */
   GLfloat OffsetUnits;		/**< Polygon offset units, from user */
812
   GLfloat OffsetClamp;		/**< Polygon offset clamp, from user */
813 814 815
   GLboolean OffsetPoint;	/**< Offset in GL_POINT mode */
   GLboolean OffsetLine;	/**< Offset in GL_LINE mode */
   GLboolean OffsetFill;	/**< Offset in GL_FILL mode */
Jouk Jansen's avatar
 
Jouk Jansen committed
816 817 818
};


819
/**
820
 * Scissor attributes (GL_SCISSOR_BIT).
821
 */
822
struct gl_scissor_rect
823
{
824 825
   GLint X, Y;			/**< Lower left corner of box */
   GLsizei Width, Height;	/**< Size of box */
Jouk Jansen's avatar
 
Jouk Jansen committed
826
};
827 828 829 830
struct gl_scissor_attrib
{
   GLbitfield EnableFlags;	/**< Scissor test enabled? */
   struct gl_scissor_rect ScissorArray[MAX_VIEWPORTS];
831 832 833
   GLint NumWindowRects;        /**< Count of enabled window rectangles */
   GLenum WindowRectMode;       /**< Whether to include or exclude the rects */
   struct gl_scissor_rect WindowRects[MAX_WINDOW_RECTANGLES];
834
};
Jouk Jansen's avatar
 
Jouk Jansen committed
835 836


837
/**
838
 * Stencil attribute group (GL_STENCIL_BUFFER_BIT).
839 840 841 842 843 844 845 846 847 848 849 850 851
 *
 * Three sets of stencil data are tracked so that OpenGL 2.0,
 * GL_EXT_stencil_two_side, and GL_ATI_separate_stencil can all be supported
 * simultaneously.  In each of the stencil state arrays, element 0 corresponds
 * to GL_FRONT.  Element 1 corresponds to the OpenGL 2.0 /
 * GL_ATI_separate_stencil GL_BACK state.  Element 2 corresponds to the
 * GL_EXT_stencil_two_side GL_BACK state.
 *
 * The derived value \c _BackFace is either 1 or 2 depending on whether or
 * not GL_STENCIL_TEST_TWO_SIDE_EXT is enabled.
 *
 * The derived value \c _TestTwoSide is set when the front-face and back-face
 * stencil state are different.
852
 */
853 854
struct gl_stencil_attrib
{
855 856
   GLboolean Enabled;		/**< Enabled flag */
   GLboolean TestTwoSide;	/**< GL_EXT_stencil_two_side */
857
   GLubyte ActiveFace;		/**< GL_EXT_stencil_two_side (0 or 2) */
858
   GLubyte _BackFace;           /**< Current back stencil state (1 or 2) */
859 860 861 862 863 864 865
   GLenum Function[3];		/**< Stencil function */
   GLenum FailFunc[3];		/**< Fail function */
   GLenum ZPassFunc[3];		/**< Depth buffer pass function */
   GLenum ZFailFunc[3];		/**< Depth buffer fail function */
   GLint Ref[3];		/**< Reference value */
   GLuint ValueMask[3];		/**< Value mask */
   GLuint WriteMask[3];		/**< Write mask */
866
   GLuint Clear;		/**< Clear value */
Jouk Jansen's avatar
 
Jouk Jansen committed
867 868 869
};


870
/**
871
 * An index for each type of texture object.  These correspond to the GL
Brian Paul's avatar
Brian Paul committed
872
 * texture target enums, such as GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.
873
 * Note: the order is from highest priority to lowest priority.
874
 */
875 876
typedef enum
{
877 878
   TEXTURE_2D_MULTISAMPLE_INDEX,
   TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX,
879
   TEXTURE_CUBE_ARRAY_INDEX,
880
   TEXTURE_BUFFER_INDEX,
881 882
   TEXTURE_2D_ARRAY_INDEX,
   TEXTURE_1D_ARRAY_INDEX,
883
   TEXTURE_EXTERNAL_INDEX,
884 885 886 887 888 889
   TEXTURE_CUBE_INDEX,
   TEXTURE_3D_INDEX,
   TEXTURE_RECT_INDEX,
   TEXTURE_2D_INDEX,
   TEXTURE_1D_INDEX,
   NUM_TEXTURE_TARGETS
890
} gl_texture_index;
891

Brian Paul's avatar
Brian Paul committed
892

893 894 895 896
/**
 * Bit flags for each type of texture object
 */
/*@{*/
897 898
#define TEXTURE_2D_MULTISAMPLE_BIT (1 << TEXTURE_2D_MULTISAMPLE_INDEX)
#define TEXTURE_2D_MULTISAMPLE_ARRAY_BIT (1 << TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX)
899
#define TEXTURE_CUBE_ARRAY_BIT (1 << TEXTURE_CUBE_ARRAY_INDEX)
900
#define TEXTURE_BUFFER_BIT   (1 << TEXTURE_BUFFER_INDEX)
901 902
#define TEXTURE_2D_ARRAY_BIT (1 << TEXTURE_2D_ARRAY_INDEX)
#define TEXTURE_1D_ARRAY_BIT (1 << TEXTURE_1D_ARRAY_INDEX)
903
#define TEXTURE_EXTERNAL_BIT (1 << TEXTURE_EXTERNAL_INDEX)
904
#define TEXTURE_CUBE_BIT     (1 << TEXTURE_CUBE_INDEX)
905
#define TEXTURE_3D_BIT       (1 << TEXTURE_3D_INDEX)
906
#define TEXTURE_RECT_BIT     (1 << TEXTURE_RECT_INDEX)
907 908
#define TEXTURE_2D_BIT       (1 << TEXTURE_2D_INDEX)
#define TEXTURE_1D_BIT       (1 << TEXTURE_1D_INDEX)
909
/*@}*/
Brian Paul's avatar
Brian Paul committed
910 911


912
/**
913 914
 * Texture image state.  Drivers will typically create a subclass of this
 * with extra fields for memory buffers, etc.
915
 */
916 917
struct gl_texture_image
{
918
   GLint InternalFormat;	/**< Internal format as given by the user */
919
   GLenum _BaseFormat;		/**< Either GL_RGB, GL_RGBA, GL_ALPHA,
Brian Paul's avatar
Brian Paul committed
920
				 *   GL_LUMINANCE, GL_LUMINANCE_ALPHA,
921 922 923
				 *   GL_INTENSITY, GL_DEPTH_COMPONENT or
				 *   GL_DEPTH_STENCIL_EXT only. Used for
				 *   choosing TexEnv arithmetic.
Jouk Jansen's avatar
 
Jouk Jansen committed
924
				 */
925
   mesa_format TexFormat;         /**< The actual texture memory format */
926

927 928 929 930 931 932 933 934 935 936
   GLuint Border;		/**< 0 or 1 */
   GLuint Width;		/**< = 2^WidthLog2 + 2*Border */
   GLuint Height;		/**< = 2^HeightLog2 + 2*Border */
   GLuint Depth;		/**< = 2^DepthLog2 + 2*Border */
   GLuint Width2;		/**< = Width - 2*Border */
   GLuint Height2;		/**< = Height - 2*Border */
   GLuint Depth2;		/**< = Depth - 2*Border */
   GLuint WidthLog2;		/**< = log2(Width2) */
   GLuint HeightLog2;		/**< = log2(Height2) */
   GLuint DepthLog2;		/**< = log2(Depth2) */
937 938
   GLuint MaxNumLevels;		/**< = maximum possible number of mipmap
                                       levels, computed from the dimensions */
939

Brian Paul's avatar
Brian Paul committed
940
   struct gl_texture_object *TexObject;  /**< Pointer back to parent object */
941 942 943
   GLuint Level;                /**< Which mipmap level am I? */
   /** Cube map face: index into gl_texture_object::Image[] array */
   GLuint Face;
944 945

   /** GL_ARB_texture_multisample */
946 947
   GLuint NumSamples;            /**< Sample count, or 0 for non-multisample */
   GLboolean FixedSampleLocations; /**< Same sample locations for all pixels? */
Jouk Jansen's avatar
 
Jouk Jansen committed
948 949
};

950 951 952 953

/**
 * Indexes for cube map faces.
 */
954 955 956 957 958 959 960 961 962 963
typedef enum
{
   FACE_POS_X = 0,
   FACE_NEG_X = 1,
   FACE_POS_Y = 2,
   FACE_NEG_Y = 3,
   FACE_POS_Z = 4,
   FACE_NEG_Z = 5,
   MAX_FACES = 6
} gl_face_index;
964

Jouk Jansen's avatar
 
Jouk Jansen committed
965

966
/**
967 968
 * Sampler object state.  These objects are new with GL_ARB_sampler_objects
 * and OpenGL 3.3.  Legacy texture objects also contain a sampler object.
969
 */
970
struct gl_sampler_object
971
{
972
   mtx_t Mutex;
973 974
   GLuint Name;
   GLint RefCount;
975
   GLchar *Label;               /**< GL_KHR_debug */
976

977 978 979
   GLenum WrapS;		/**< S-axis texture image wrap mode */
   GLenum WrapT;		/**< T-axis texture image wrap mode */
   GLenum WrapR;		/**< R-axis texture image wrap mode */
980 981
   GLenum MinFilter;		/**< minification filter */
   GLenum MagFilter;		/**< magnification filter */