summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/teximage.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2006-05-20 16:19:48 +0000
committerBrian Paul <[email protected]>2006-05-20 16:19:48 +0000
commitb0b6d1abe5c7e629baebd4bf3d3ee3b17ba6ff08 (patch)
treeebac2d5b8cf7d29a38beb6bc7854b5f67a8b9524 /src/mesa/main/teximage.c
parent226d0187b530482684f3a0dddd0934bd015eb986 (diff)
In gl_texture_image, replace ImageStride with an ImageOffsets array.
Some hardware lays out 3D mipmaps in a manner that can't be expressed with a simple image stride. The ImageOffsets array is allocated and initialized to typical defaults in the _mesa_init_teximage_fields() function. If needed, a driver will then have to replace these offsets. TexStore and TexelFetch routines updated to use offsets array.
Diffstat (limited to 'src/mesa/main/teximage.c')
-rw-r--r--src/mesa/main/teximage.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index 91a96e871b0..02d2aa362cb 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -662,7 +662,9 @@ _mesa_delete_texture_image( GLcontext *ctx, struct gl_texture_image *texImage )
ctx->Driver.FreeTexImageData( ctx, texImage );
}
ASSERT(texImage->Data == NULL);
- FREE( texImage );
+ if (texImage->ImageOffsets)
+ _mesa_free(texImage->ImageOffsets);
+ _mesa_free(texImage);
}
@@ -1050,7 +1052,10 @@ clear_teximage_fields(struct gl_texture_image *img)
img->Height = 0;
img->Depth = 0;
img->RowStride = 0;
- img->ImageStride = 0;
+ if (img->ImageOffsets) {
+ _mesa_free(img->ImageOffsets);
+ img->ImageOffsets = NULL;
+ }
img->Width2 = 0;
img->Height2 = 0;
img->Depth2 = 0;
@@ -1070,7 +1075,7 @@ clear_teximage_fields(struct gl_texture_image *img)
* Initialize basic fields of the gl_texture_image struct.
*
* \param ctx GL context.
- * \param target texture target.
+ * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
* \param img texture image structure to be initialized.
* \param width image width.
* \param height image height.
@@ -1087,7 +1092,13 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
GLsizei width, GLsizei height, GLsizei depth,
GLint border, GLenum internalFormat)
{
+ GLint i;
+
ASSERT(img);
+ ASSERT(width > 0);
+ ASSERT(height > 0);
+ ASSERT(depth > 0);
+
img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat );
ASSERT(img->_BaseFormat > 0);
img->InternalFormat = internalFormat;
@@ -1095,8 +1106,6 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
img->Width = width;
img->Height = height;
img->Depth = depth;
- img->RowStride = width;
- img->ImageStride = width * height;
img->Width2 = width - 2 * border; /* == 1 << img->WidthLog2; */
img->Height2 = height - 2 * border; /* == 1 << img->HeightLog2; */
img->Depth2 = depth - 2 * border; /* == 1 << img->DepthLog2; */
@@ -1120,6 +1129,17 @@ _mesa_init_teximage_fields(GLcontext *ctx, GLenum target,
else
img->_IsPowerOfTwo = GL_FALSE;
+ /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
+ img->RowStride = width;
+ /* Allocate the ImageOffsets array and initialize to typical values.
+ * We allocate the array for 1D/2D textures too in order to avoid special-
+ * case code in the texstore routines.
+ */
+ img->ImageOffsets = (GLuint *) _mesa_malloc(depth * sizeof(GLuint));
+ for (i = 0; i < depth; i++) {
+ img->ImageOffsets[i] = i * width * height;
+ }
+
/* Compute Width/Height/DepthScale for mipmap lod computation */
if (target == GL_TEXTURE_RECTANGLE_NV) {
/* scale = 1.0 since texture coords directly map to texels */