From: Maciej Cencora Date: Sat, 14 Nov 2009 14:03:31 +0000 (+0100) Subject: radeon: minor refactoring of texture code X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9d0af686b27b82dce8ad1ee4c951098660807be6;p=mesa.git radeon: minor refactoring of texture code Also properly set dstImageOffsets for TexSubImage case. --- diff --git a/src/mesa/drivers/dri/radeon/radeon_texture.c b/src/mesa/drivers/dri/radeon/radeon_texture.c index 607ce7864e8..8fc686581b5 100644 --- a/src/mesa/drivers/dri/radeon/radeon_texture.c +++ b/src/mesa/drivers/dri/radeon/radeon_texture.c @@ -508,6 +508,27 @@ gl_format radeonChooseTextureFormat(GLcontext * ctx, return MESA_FORMAT_NONE; /* never get here */ } +static GLuint * allocate_image_offsets(GLcontext *ctx, + unsigned alignedWidth, + unsigned height, + unsigned depth) +{ + int i; + GLuint *offsets; + + offsets = _mesa_malloc(depth * sizeof(GLuint)) ; + if (!offsets) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTex[Sub]Image"); + return NULL; + } + + for (i = 0; i < depth; ++i) { + offsets[i] = alignedWidth * height * i; + } + + return offsets; +} + /** * All glTexImage calls go through this function. */ @@ -605,8 +626,8 @@ static void radeon_teximage( } if (pixels) { - radeon_teximage_map(image, GL_TRUE); if (compressed) { + radeon_teximage_map(image, GL_TRUE); if (image->mt) { uint32_t srcRowStride, bytesPerRow, rows; srcRowStride = _mesa_format_row_stride(texImage->TexFormat, width); @@ -629,19 +650,17 @@ static void radeon_teximage( } if (dims == 3) { - int i; - - dstImageOffsets = _mesa_malloc(depth * sizeof(GLuint)) ; - if (!dstImageOffsets) - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage"); - - for (i = 0; i < depth; ++i) { - dstImageOffsets[i] = dstRowStride/_mesa_get_format_bytes(texImage->TexFormat) * height * i; + unsigned alignedWidth = dstRowStride/_mesa_get_format_bytes(texImage->TexFormat); + dstImageOffsets = allocate_image_offsets(ctx, alignedWidth, height, depth); + if (!dstImageOffsets) { + return; } } else { dstImageOffsets = texImage->ImageOffsets; } + radeon_teximage_map(image, GL_TRUE); + if (!_mesa_texstore(ctx, dims, texImage->_BaseFormat, texImage->TexFormat, @@ -752,7 +771,7 @@ static void radeon_texsubimage(GLcontext* ctx, int dims, GLenum target, int leve if (pixels) { GLint dstRowStride; - radeon_teximage_map(image, GL_TRUE); + GLuint *dstImageOffsets; if (image->mt) { radeon_mipmap_level *lvl = &image->mt->levels[image->mtlevel]; @@ -761,6 +780,18 @@ static void radeon_texsubimage(GLcontext* ctx, int dims, GLenum target, int leve dstRowStride = texImage->RowStride * _mesa_get_format_bytes(texImage->TexFormat); } + if (dims == 3) { + unsigned alignedWidth = dstRowStride/_mesa_get_format_bytes(texImage->TexFormat); + dstImageOffsets = allocate_image_offsets(ctx, alignedWidth, height, depth); + if (!dstImageOffsets) { + return; + } + } else { + dstImageOffsets = texImage->ImageOffsets; + } + + radeon_teximage_map(image, GL_TRUE); + if (compressed) { uint32_t srcRowStride, bytesPerRow, rows; GLubyte *img_start; @@ -786,12 +817,16 @@ static void radeon_texsubimage(GLcontext* ctx, int dims, GLenum target, int leve texImage->TexFormat, texImage->Data, xoffset, yoffset, zoffset, dstRowStride, - texImage->ImageOffsets, + dstImageOffsets, width, height, depth, format, type, pixels, packing)) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage"); } } + + if (dims == 3) { + _mesa_free(dstImageOffsets); + } } radeon_teximage_unmap(image);