In gl_texture_image, replace ImageStride with an ImageOffsets array.
[mesa.git] / src / mesa / main / mtypes.h
index c69b4a48b5036eedf8c95a9415711be8c49c436a..e52e0bae5e53f7da05cdfa4287e18020449fba91 100644 (file)
@@ -9,7 +9,7 @@
  * Mesa 3-D graphics library
  * Version:  6.5
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -41,6 +41,7 @@
 #include "glapitable.h"
 #include "glthread.h"
 #include "math/m_matrix.h"     /* GLmatrix */
+#include "bitset.h"
 
 
 /**
@@ -141,7 +142,7 @@ enum
    VERT_ATTRIB_COLOR0 = 3,
    VERT_ATTRIB_COLOR1 = 4,
    VERT_ATTRIB_FOG = 5,
-   VERT_ATTRIB_SIX = 6,
+   VERT_ATTRIB_COLOR_INDEX = 6,
    VERT_ATTRIB_SEVEN = 7,
    VERT_ATTRIB_TEX0 = 8,
    VERT_ATTRIB_TEX1 = 9,
@@ -155,7 +156,19 @@ enum
    VERT_ATTRIB_GENERIC1 = 17,
    VERT_ATTRIB_GENERIC2 = 18,
    VERT_ATTRIB_GENERIC3 = 19,
-   VERT_ATTRIB_MAX = 16  /* XXX not counting generic attribs yet */
+   VERT_ATTRIB_GENERIC4 = 20,
+   VERT_ATTRIB_GENERIC5 = 21,
+   VERT_ATTRIB_GENERIC6 = 22,
+   VERT_ATTRIB_GENERIC7 = 23,
+   VERT_ATTRIB_GENERIC8 = 24,
+   VERT_ATTRIB_GENERIC9 = 25,
+   VERT_ATTRIB_GENERIC10 = 26,
+   VERT_ATTRIB_GENERIC11 = 27,
+   VERT_ATTRIB_GENERIC12 = 28,
+   VERT_ATTRIB_GENERIC13 = 29,
+   VERT_ATTRIB_GENERIC14 = 30,
+   VERT_ATTRIB_GENERIC15 = 31,
+   VERT_ATTRIB_MAX = 32
 };
 
 /**
@@ -163,31 +176,60 @@ enum
  * These are used in bitfields in many places.
  */
 /*@{*/
-#define VERT_BIT_POS      (1 << VERT_ATTRIB_POS)
-#define VERT_BIT_WEIGHT   (1 << VERT_ATTRIB_WEIGHT)
-#define VERT_BIT_NORMAL   (1 << VERT_ATTRIB_NORMAL)
-#define VERT_BIT_COLOR0   (1 << VERT_ATTRIB_COLOR0)
-#define VERT_BIT_COLOR1   (1 << VERT_ATTRIB_COLOR1)
-#define VERT_BIT_FOG      (1 << VERT_ATTRIB_FOG)
-#define VERT_BIT_SIX      (1 << VERT_ATTRIB_SIX)
-#define VERT_BIT_SEVEN    (1 << VERT_ATTRIB_SEVEN)
-#define VERT_BIT_TEX0     (1 << VERT_ATTRIB_TEX0)
-#define VERT_BIT_TEX1     (1 << VERT_ATTRIB_TEX1)
-#define VERT_BIT_TEX2     (1 << VERT_ATTRIB_TEX2)
-#define VERT_BIT_TEX3     (1 << VERT_ATTRIB_TEX3)
-#define VERT_BIT_TEX4     (1 << VERT_ATTRIB_TEX4)
-#define VERT_BIT_TEX5     (1 << VERT_ATTRIB_TEX5)
-#define VERT_BIT_TEX6     (1 << VERT_ATTRIB_TEX6)
-#define VERT_BIT_TEX7     (1 << VERT_ATTRIB_TEX7)
-#define VERT_BIT_GENERIC0 (1 << VERT_ATTRIB_GENERIC0)
-#define VERT_BIT_GENERIC1 (1 << VERT_ATTRIB_GENERIC1)
-#define VERT_BIT_GENERIC2 (1 << VERT_ATTRIB_GENERIC2)
-#define VERT_BIT_GENERIC3 (1 << VERT_ATTRIB_GENERIC3)
+#define VERT_BIT_POS         (1 << VERT_ATTRIB_POS)
+#define VERT_BIT_WEIGHT      (1 << VERT_ATTRIB_WEIGHT)
+#define VERT_BIT_NORMAL      (1 << VERT_ATTRIB_NORMAL)
+#define VERT_BIT_COLOR0      (1 << VERT_ATTRIB_COLOR0)
+#define VERT_BIT_COLOR1      (1 << VERT_ATTRIB_COLOR1)
+#define VERT_BIT_FOG         (1 << VERT_ATTRIB_FOG)
+#define VERT_BIT_COLOR_INDEX (1 << VERT_ATTRIB_COLOR_INDEX)
+#define VERT_BIT_SEVEN       (1 << VERT_ATTRIB_SEVEN)
+#define VERT_BIT_TEX0        (1 << VERT_ATTRIB_TEX0)
+#define VERT_BIT_TEX1        (1 << VERT_ATTRIB_TEX1)
+#define VERT_BIT_TEX2        (1 << VERT_ATTRIB_TEX2)
+#define VERT_BIT_TEX3        (1 << VERT_ATTRIB_TEX3)
+#define VERT_BIT_TEX4        (1 << VERT_ATTRIB_TEX4)
+#define VERT_BIT_TEX5        (1 << VERT_ATTRIB_TEX5)
+#define VERT_BIT_TEX6        (1 << VERT_ATTRIB_TEX6)
+#define VERT_BIT_TEX7        (1 << VERT_ATTRIB_TEX7)
+#define VERT_BIT_GENERIC0    (1 << VERT_ATTRIB_GENERIC0)
+#define VERT_BIT_GENERIC1    (1 << VERT_ATTRIB_GENERIC1)
+#define VERT_BIT_GENERIC2    (1 << VERT_ATTRIB_GENERIC2)
+#define VERT_BIT_GENERIC3    (1 << VERT_ATTRIB_GENERIC3)
+#define VERT_BIT_GENERIC4    (1 << VERT_ATTRIB_GENERIC4)
+#define VERT_BIT_GENERIC5    (1 << VERT_ATTRIB_GENERIC5)
+#define VERT_BIT_GENERIC6    (1 << VERT_ATTRIB_GENERIC6)
+#define VERT_BIT_GENERIC7    (1 << VERT_ATTRIB_GENERIC7)
+#define VERT_BIT_GENERIC8    (1 << VERT_ATTRIB_GENERIC8)
+#define VERT_BIT_GENERIC9    (1 << VERT_ATTRIB_GENERIC9)
+#define VERT_BIT_GENERIC10   (1 << VERT_ATTRIB_GENERIC10)
+#define VERT_BIT_GENERIC11   (1 << VERT_ATTRIB_GENERIC11)
+#define VERT_BIT_GENERIC12   (1 << VERT_ATTRIB_GENERIC12)
+#define VERT_BIT_GENERIC13   (1 << VERT_ATTRIB_GENERIC13)
+#define VERT_BIT_GENERIC14   (1 << VERT_ATTRIB_GENERIC14)
+#define VERT_BIT_GENERIC15   (1 << VERT_ATTRIB_GENERIC15)
 
 #define VERT_BIT_TEX(u)  (1 << (VERT_ATTRIB_TEX0 + (u)))
 #define VERT_BIT_GENERIC(g)  (1 << (VERT_ATTRIB_GENERIC0 + (g)))
 /*@}*/
 
+/**
+ * GLSL allows shader writers to allocate vertex result attributes (varyings) in
+ * single float component granularity. This is in contrast to vertex / fragment
+ * programs, where result attributes (actually texcoords) were allocated
+ * in 4-component vectors of floats granularity.
+ * For performance reasons, it would be optimal to stick with this scheme on a scalar
+ * processor. Varyings will likely be allocated as 3-component vectors, so statistically
+ * we win 2 floats.
+ * The constant VARYINGS_PER_VECTOR tells us how much of float components we pack into
+ * one result vector. For scalar processor it would be 1, for vector processor - 4.
+ * 
+ * NOTE: Currently we pack varyings into vertex attributes.
+ */
+#define VARYINGS_PER_VECTOR 2
+#define VARYING_EMIT_STYLE  EMIT_2F
+#define MAX_VARYING_VECTORS ((MAX_VARYING_FLOATS + VARYINGS_PER_VECTOR - 1) / VARYINGS_PER_VECTOR)
+
 /**
  * Indexes for vertex program result attributes
  */
@@ -207,7 +249,8 @@ enum
 #define VERT_RESULT_PSIZ 12
 #define VERT_RESULT_BFC0 13
 #define VERT_RESULT_BFC1 14
-#define VERT_RESULT_MAX  15
+#define VERT_RESULT_EDGE 15
+#define VERT_RESULT_MAX  16
 /*@}*/
 
 
@@ -319,6 +362,28 @@ enum {
 #define BUFFER_BIT_COLOR6       (1 << BUFFER_COLOR6)
 #define BUFFER_BIT_COLOR7       (1 << BUFFER_COLOR7)
 
+/**
+ * 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_AUX1 | \
+                            BUFFER_BIT_AUX2 | \
+                            BUFFER_BIT_AUX3 | \
+                            BUFFER_BIT_COLOR0 | \
+                            BUFFER_BIT_COLOR1 | \
+                            BUFFER_BIT_COLOR2 | \
+                            BUFFER_BIT_COLOR3 | \
+                            BUFFER_BIT_COLOR4 | \
+                            BUFFER_BIT_COLOR5 | \
+                            BUFFER_BIT_COLOR6 | \
+                            BUFFER_BIT_COLOR7)
+
+
+
 
 /**
  * Data structure for color tables
@@ -429,7 +494,7 @@ struct gl_light
    GLfloat EyePosition[4];     /**< position in eye coordinates */
    GLfloat EyeDirection[4];    /**< spotlight dir in eye coordinates */
    GLfloat SpotExponent;
-   GLfloat SpotCutoff;         /**< in degrees */\r
+   GLfloat SpotCutoff;         /**< in degrees */
    GLfloat _CosCutoffNeg;      /**< = cos(SpotCutoff) */
    GLfloat _CosCutoff;         /**< = MAX(0, cos(SpotCutoff)) */
    GLfloat ConstantAttenuation;
@@ -549,29 +614,27 @@ struct gl_colorbuffer_attrib
 struct gl_current_attrib
 {
    /**
-    * \name Values valid only when FLUSH_VERTICES has been called.
+    * \name Current vertex attributes.
+    * \note Values are valid only after FLUSH_VERTICES has been called.
     */
    /*@{*/
-   GLfloat Attrib[VERT_ATTRIB_MAX][4];         /**< Current vertex attributes
-                                                 *  indexed by VERT_ATTRIB_* */
-   GLfloat Index;                              /**< Current color index */
-   GLboolean EdgeFlag;                         /**< Current edge flag */
+   GLfloat Attrib[VERT_ATTRIB_MAX][4]; /**< Position, color, texcoords, etc */
+   GLfloat Index;                      /**< Current color index */
+   GLboolean EdgeFlag;                 /**< Current edge flag */
    /*@}*/
 
    /**
-    * \name Values are always valid.  
-    * 
-    * \note BTW, note how similar this set of attributes is to the SWvertex
-    * data type in the software rasterizer...
+    * \name Current raster position attributes (always valid).
+    * \note This set of attributes is very similar to the SWvertex struct.
     */
    /*@{*/
-   GLfloat RasterPos[4];                       /**< Current raster position */
-   GLfloat RasterDistance;                     /**< Current raster distance */
-   GLfloat RasterColor[4];                     /**< Current raster color */
-   GLfloat RasterSecondaryColor[4];             /**< Current raster secondary color */
-   GLfloat RasterIndex;                                /**< Current raster index */
-   GLfloat RasterTexCoords[MAX_TEXTURE_UNITS][4];/**< Current raster texcoords */
-   GLboolean RasterPosValid;                   /**< Raster pos valid flag */
+   GLfloat RasterPos[4];
+   GLfloat RasterDistance;
+   GLfloat RasterColor[4];
+   GLfloat RasterSecondaryColor[4];
+   GLfloat RasterIndex;
+   GLfloat RasterTexCoords[MAX_TEXTURE_COORD_UNITS][4];
+   GLboolean RasterPosValid;
    /*@}*/
 };
 
@@ -728,7 +791,7 @@ struct gl_fog_attrib
    GLfloat Index;              /**< Fog index */
    GLenum Mode;                        /**< Fog mode */
    GLboolean ColorSumEnabled;
-   GLenum FogCoordinateSource;  /**< GL_EXT_fog_coord */\r
+   GLenum FogCoordinateSource;  /**< GL_EXT_fog_coord */
    GLfloat _Scale;             /**< (End == Start) ? 1.0 : 1.0 / (End - Start) */
 };
 
@@ -984,8 +1047,8 @@ struct gl_point_attrib
    GLfloat MinSize, MaxSize;   /**< GL_EXT_point_parameters */
    GLfloat Threshold;          /**< GL_EXT_point_parameters */
    GLboolean _Attenuated;      /**< True if Params != [1, 0, 0] */
-   GLboolean PointSprite;      /**< GL_NV_point_sprite / GL_NV_point_sprite */
-   GLboolean CoordReplace[MAX_TEXTURE_UNITS]; /**< GL_NV/ARB_point_sprite */
+   GLboolean PointSprite;      /**< GL_NV/ARB_point_sprite */
+   GLboolean CoordReplace[MAX_TEXTURE_COORD_UNITS]; /**< GL_ARB_point_sprite */
    GLenum SpriteRMode;         /**< GL_NV_point_sprite (only!) */
    GLenum SpriteOrigin;                /**< GL_ARB_point_sprite */
 };
@@ -1153,24 +1216,42 @@ typedef void (*StoreTexelFunc)(struct gl_texture_image *texImage,
                                GLint col, GLint row, GLint img,
                                const void *texel);
 
+
 /**
- * TexImage store function.  This is called by the glTex[Sub]Image
- * functions and is responsible for converting the user-specified texture
- * image into a specific (hardware) image format.
+ * This macro defines the (many) parameters to the texstore functions.
+ * \param dims  either 1 or 2 or 3
+ * \param baseInternalFormat  user-specified base internal format
+ * \param dstFormat  destination Mesa texture format
+ * \param dstAddr  destination image address
+ * \param dstX/Y/Zoffset  destination x/y/z offset (ala TexSubImage), in texels
+ * \param dstRowStride  destination image row stride, in bytes
+ * \param dstImageOffsets  offset of each 2D slice within 3D texture, in texels
+ * \param srcWidth/Height/Depth  source image size, in pixels
+ * \param srcFormat  incoming image format
+ * \param srcType  incoming image data type
+ * \param srcAddr  source image address
+ * \param srcPacking  source image packing parameters
  */
-typedef GLboolean (*StoreTexImageFunc)(GLcontext *ctx, GLuint dims,
-                          GLenum baseInternalFormat,
-                          const struct gl_texture_format *dstFormat,
-                          GLvoid *dstAddr,
-                          GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
-                          GLint dstRowStride, GLint dstImageStride,
-                          GLint srcWidth, GLint srcHeight, GLint srcDepth,
-                          GLenum srcFormat, GLenum srcType,
-                          const GLvoid *srcAddr,
-                          const struct gl_pixelstore_attrib *srcPacking);
+#define TEXSTORE_PARAMS \
+       GLcontext *ctx, GLuint dims, \
+       GLenum baseInternalFormat, \
+       const struct gl_texture_format *dstFormat, \
+       GLvoid *dstAddr, \
+       GLint dstXoffset, GLint dstYoffset, GLint dstZoffset, \
+       GLint dstRowStride, const GLuint *dstImageOffsets, \
+       GLint srcWidth, GLint srcHeight, GLint srcDepth, \
+       GLenum srcFormat, GLenum srcType, \
+       const GLvoid *srcAddr, \
+       const struct gl_pixelstore_attrib *srcPacking
 
 
 
+/**
+ * Texture image storage function.
+ */
+typedef GLboolean (*StoreTexImageFunc)(TEXSTORE_PARAMS);
+
+
 /**
  * Texture format record 
  */
@@ -1214,6 +1295,8 @@ struct gl_texture_format
 };
 
 
+#define MAX_3D_TEXTURE_SIZE (1 << (MAX_3D_TEXTURE_LEVELS - 1))
+
 /**
  * Texture image state.  Describes the dimensions of a texture image,
  * the texel format and pointers to Texel Fetch functions.
@@ -1231,7 +1314,6 @@ struct gl_texture_image
    GLuint Width;               /**< = 2^WidthLog2 + 2*Border */
    GLuint Height;              /**< = 2^HeightLog2 + 2*Border */
    GLuint Depth;               /**< = 2^DepthLog2 + 2*Border */
-   GLuint RowStride;           /**< == Width unless IsClientData and padded */
    GLuint Width2;              /**< = Width - 2*Border */
    GLuint Height2;             /**< = Height - 2*Border */
    GLuint Depth2;              /**< = Depth - 2*Border */
@@ -1242,7 +1324,6 @@ struct gl_texture_image
    GLfloat WidthScale;         /**< used for mipmap LOD computation */
    GLfloat HeightScale;                /**< used for mipmap LOD computation */
    GLfloat DepthScale;         /**< used for mipmap LOD computation */
-   GLvoid *Data;               /**< Image data, accessed via FetchTexel() */
    GLboolean IsClientData;     /**< Data owned by client? */
    GLboolean _IsPowerOfTwo;    /**< Are all dimensions powers of two? */
 
@@ -1256,6 +1337,11 @@ struct gl_texture_image
    GLboolean IsCompressed;     /**< GL_ARB_texture_compression */
    GLuint CompressedSize;      /**< GL_ARB_texture_compression */
 
+   GLuint RowStride;           /**< == Width unless IsClientData and padded */
+   GLuint *ImageOffsets;        /**< if 3D texture: array [Depth] of offsets to
+                                     each 2D slice in 'Data', in texels */
+   GLvoid *Data;               /**< Image data, accessed via FetchTexel() */
+
    /**
     * \name For device driver:
     */
@@ -1576,7 +1662,9 @@ struct gl_client_array
  */
 struct gl_array_attrib
 {
-   struct gl_client_array Vertex;           /**< client data descriptors */
+   /** Conventional vertex arrays */
+   /*@{*/
+   struct gl_client_array Vertex;
    struct gl_client_array Normal;
    struct gl_client_array Color;
    struct gl_client_array SecondaryColor;
@@ -1584,15 +1672,17 @@ struct gl_array_attrib
    struct gl_client_array Index;
    struct gl_client_array TexCoord[MAX_TEXTURE_COORD_UNITS];
    struct gl_client_array EdgeFlag;
+   /*@}*/
 
-   struct gl_client_array VertexAttrib[VERT_ATTRIB_MAX];  /**< GL_NV_vertex_program */
+   /** Generic arrays for vertex programs/shaders; */
+   struct gl_client_array VertexAttrib[VERT_ATTRIB_MAX];
 
    GLint ActiveTexture;                /**< Client Active Texture */
    GLuint LockFirst;            /**< GL_EXT_compiled_vertex_array */
    GLuint LockCount;            /**< GL_EXT_compiled_vertex_array */
 
-   GLbitfield _Enabled;                /**< _NEW_ARRAY_* - bit set if array enabled */
-   GLbitfield NewState;                /**< _NEW_ARRAY_* */
+   GLbitfield _Enabled;                /**< mask of _NEW_ARRAY_* values */
+   GLbitfield NewState;                /**< mask of _NEW_ARRAY_* values */
 
 #if FEATURE_ARB_vertex_buffer_object
    struct gl_buffer_object *NullBufferObj;
@@ -1951,8 +2041,8 @@ struct gl_query_state
  */
 struct gl_shader_objects_state
 {
-   struct gl2_program_intf **CurrentProgram;\r
-   GLboolean _VertexShaderPresent;\r
+   struct gl2_program_intf **CurrentProgram;
+   GLboolean _VertexShaderPresent;
    GLboolean _FragmentShaderPresent;
 };
 
@@ -2024,14 +2114,17 @@ struct gl_shared_state
  */
 struct gl_renderbuffer
 {
+   _glthread_Mutex Mutex;                 /**< for thread safety */
+   GLuint ClassID;        /**< Useful for drivers */
    GLuint Name;
    GLint RefCount;
    GLuint Width, Height;
-   GLenum InternalFormat; /* The user-specified value */
-   GLenum _BaseFormat;    /* Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or */
-                          /* GL_STENCIL_INDEX. */
-   GLenum DataType;       /* Type of values passed to the Get/Put functions */
-   GLubyte RedBits;       /**< Bits per image component */
+   GLenum InternalFormat; /**< The user-specified format */
+   GLenum _ActualFormat;  /**< The driver-chosen format */
+   GLenum _BaseFormat;    /**< Either GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT or
+                               GL_STENCIL_INDEX. */
+   GLenum DataType;      /**< Type of values passed to the Get/Put functions */
+   GLubyte RedBits;      /**< Bits of red per pixel */
    GLubyte GreenBits;
    GLubyte BlueBits;
    GLubyte AlphaBits;
@@ -2139,10 +2232,13 @@ struct gl_renderbuffer_attachment
  */
 struct gl_framebuffer
 {
+   _glthread_Mutex Mutex;                 /**< for thread safety */
    GLuint Name;      /* if zero, this is a window system framebuffer */
    GLint RefCount;
 
-   GLvisual Visual;            /**< The corresponding visual */
+   GLvisual Visual;    /**< The framebuffer's visual.
+                             Immutable if this is a window system buffer.
+                             Computed from attachments if user-made FBO. */
 
    GLboolean Initialized;
 
@@ -2231,7 +2327,7 @@ struct gl_constants
    GLint MaxTextureRectSize;            /* GL_NV_texture_rectangle */
    GLuint MaxTextureCoordUnits;
    GLuint MaxTextureImageUnits;
-   GLuint MaxTextureUnits;              /* = MAX(CoordUnits, ImageUnits) */
+   GLuint MaxTextureUnits;              /* = MIN(CoordUnits, ImageUnits) */
    GLfloat MaxTextureMaxAnisotropy;    /* GL_EXT_texture_filter_anisotropic */
    GLfloat MaxTextureLodBias;           /* GL_EXT_texture_lod_bias */
    GLuint MaxArrayLockSize;
@@ -2493,7 +2589,7 @@ struct matrix_stack
 #define _NEW_ARRAY_COLOR0           VERT_BIT_COLOR0
 #define _NEW_ARRAY_COLOR1           VERT_BIT_COLOR1
 #define _NEW_ARRAY_FOGCOORD         VERT_BIT_FOG
-#define _NEW_ARRAY_INDEX            VERT_BIT_SIX
+#define _NEW_ARRAY_INDEX            VERT_BIT_COLOR_INDEX
 #define _NEW_ARRAY_EDGEFLAG         VERT_BIT_SEVEN
 #define _NEW_ARRAY_TEXCOORD_0       VERT_BIT_TEX0
 #define _NEW_ARRAY_TEXCOORD_1       VERT_BIT_TEX1
@@ -2826,7 +2922,6 @@ struct __GLcontextRec
    GLfloat _ModelViewInvScale;
    GLboolean _NeedEyeCoords;
    GLboolean _ForceEyeCoords; 
-   GLboolean _RotateMode;
    GLenum _CurrentProgram;    /* currently executing program */
 
    struct gl_shine_tab *_ShineTable[2]; /**< Active shine tables */