From: Brian Paul Date: Sat, 24 Dec 2011 15:54:27 +0000 (-0700) Subject: mesa: fix _mesa_store_texsubimage2d() for GL_TEXTURE_1D_ARRAY X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=afebe13986e1ab69c8f80e957653b35aaee2269b;p=mesa.git mesa: fix _mesa_store_texsubimage2d() for GL_TEXTURE_1D_ARRAY For 1D arrays, map each slice separately. Note that this was handled correctly in _mesa_store_teximage2d() but not here. Reviewed-by: José Fonseca --- diff --git a/src/mesa/main/texstore.c b/src/mesa/main/texstore.c index a57a38e1266..fb1ad04e014 100644 --- a/src/mesa/main/texstore.c +++ b/src/mesa/main/texstore.c @@ -4888,35 +4888,56 @@ _mesa_store_texsubimage2d(struct gl_context *ctx, GLenum target, GLint level, struct gl_texture_image *texImage) { const GLbitfield rwMode = get_read_write_mode(format, texImage->TexFormat); - GLubyte *dstMap; - GLint dstRowStride; - GLboolean success; + GLboolean success = GL_FALSE; + GLuint slice, numSlices, sliceOffset, srcImageStride; + const GLubyte *src; /* get pointer to src pixels (may be in a pbo which we'll map here) */ - pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type, - pixels, packing, "glTexSubImage2D"); - if (!pixels) + src = (const GLubyte *) + _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type, + pixels, packing, "glTexSubImage2D"); + if (!src) return; - /* Map dest texture buffer */ - ctx->Driver.MapTextureImage(ctx, texImage, 0, - xoffset, yoffset, width, height, - rwMode, - &dstMap, &dstRowStride); - - if (dstMap) { - success = _mesa_texstore(ctx, 2, texImage->_BaseFormat, - texImage->TexFormat, - 0, 0, 0, /* dstX/Y/Zoffset */ - dstRowStride, - &dstMap, - width, height, 1, - format, type, pixels, packing); - - ctx->Driver.UnmapTextureImage(ctx, texImage, 0); + if (target == GL_TEXTURE_1D_ARRAY) { + /* map each slice of the 1D array separately */ + numSlices = height; + sliceOffset = yoffset; + height = 1; + yoffset = 0; + srcImageStride = _mesa_image_row_stride(packing, width, format, type); } else { - success = GL_FALSE; + /* regular 2D image */ + numSlices = 1; + sliceOffset = 0; + srcImageStride = 0; + } + + for (slice = 0; slice < numSlices; slice++) { + GLubyte *dstMap; + GLint dstRowStride; + + ctx->Driver.MapTextureImage(ctx, texImage, + slice + sliceOffset, + xoffset, yoffset, width, height, + rwMode, &dstMap, &dstRowStride); + if (dstMap) { + success = _mesa_texstore(ctx, 2, texImage->_BaseFormat, + texImage->TexFormat, + 0, 0, 0, /* dstX/Y/Zoffset */ + dstRowStride, + &dstMap, + width, height, 1, /* w, h, d */ + format, type, src, packing); + + ctx->Driver.UnmapTextureImage(ctx, texImage, slice + sliceOffset); + } + + src += srcImageStride; + + if (!success) + break; } if (!success)