/** used for mipmap LOD computation */
GLfloat WidthScale, HeightScale, DepthScale;
- /** These fields only valid when texture memory is mapped */
- GLint RowStride; /**< Padded width in units of texels */
+ /**
+ * Byte stride between rows in ImageSlices.
+ *
+ * For compressed textures, this is the byte stride between one row of
+ * blocks and the next row of blocks.
+ *
+ * Only valid while one of the ImageSlices is mapped, and must be the same
+ * between all slices.
+ */
+ GLint RowStride;
void **ImageSlices; /**< if 3D texture: array [Depth] of offsets to
each 2D slice in 'Data', in texels */
GLubyte *Map; /**< Pointer to mapped image memory */
fetch_compressed(const struct swrast_texture_image *swImage,
GLint i, GLint j, GLint k, GLfloat *texel)
{
+ /* The FetchCompressedTexel function takes an integer pixel rowstride,
+ * while the image's rowstride is bytes per row of blocks.
+ */
+ GLuint bw, bh;
+ GLuint texelBytes = _mesa_get_format_bytes(swImage->Base.TexFormat);
+ _mesa_get_format_block_size(swImage->Base.TexFormat, &bw, &bh);
+ assert(swImage->RowStride * bw % texelBytes == 0);
+
swImage->FetchCompressedTexel(swImage->ImageSlices[k],
- swImage->RowStride,
+ swImage->RowStride * bw / texelBytes,
i, j, texel);
}
#define TEXEL_ADDR( type, image, i, j, k, size ) \
((void) (k), \
- ((type *)(image)->ImageSlices[0] + ((image)->RowStride * (j) + (i)) * (size)))
+ ((type *)((image)->ImageSlices[0] + (image)->RowStride * (j)) + \
+ (i) * (size)))
#define FETCH(x) fetch_texel_2d_##x
#elif DIM == 3
#define TEXEL_ADDR( type, image, i, j, k, size ) \
- ((type *)(image)->ImageSlices[k] + \
- ((image)->RowStride * (j) + (i)) * (size))
+ ((type *)((image)->ImageSlices[k] + \
+ (image)->RowStride * (j)) + (i) * (size))
#define FETCH(x) fetch_texel_3d_##x
const GLboolean repeatNoBorderPOT = (samp->WrapS == GL_REPEAT)
&& (samp->WrapT == GL_REPEAT)
- && (tImg->Border == 0 && (tImg->Width == swImg->RowStride))
+ && (tImg->Border == 0)
+ && (_mesa_format_row_stride(tImg->TexFormat, tImg->Width) ==
+ swImg->RowStride)
&& swImg->_IsPowerOfTwo;
ASSERT(lambda != NULL);
return GL_FALSE;
/* RowStride and ImageSlices[] describe how to address texels in 'Data' */
- swImg->RowStride = texImage->Width;
+ swImg->RowStride = _mesa_format_row_stride(texImage->TexFormat,
+ texImage->Width);
for (i = 0; i < slices; i++) {
swImg->ImageSlices[i] = swImg->Buffer + bytesPerSlice * i;
&& texObj2D->_Swizzle == SWIZZLE_NOOP
&& swImg->_IsPowerOfTwo
&& texImg->Border == 0
- && texImg->Width == swImg->RowStride
+ && (_mesa_format_row_stride(format, texImg->Width) ==
+ swImg->RowStride)
&& (format == MESA_FORMAT_RGB888 || format == MESA_FORMAT_RGBA8888)
&& minFilter == magFilter
&& ctx->Light.Model.ColorControl == GL_SINGLE_COLOR