From c367f4d46ee70c1d5879031235824e59e13f6677 Mon Sep 17 00:00:00 2001 From: Roland Scheidegger Date: Sat, 21 Nov 2009 04:22:50 -0800 Subject: [PATCH] mesa: handle different RowStride in _mesa_get_compressed_teximage drivers storing compressed textures with non-native stride but relying on _mesa_get_compressed_teximage for GetCompressedTexImage otherwise won't work correctly (for instance i965 compressed mipmaps). --- src/mesa/main/texgetimage.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c index 2f88718933a..008407210d9 100644 --- a/src/mesa/main/texgetimage.c +++ b/src/mesa/main/texgetimage.c @@ -521,10 +521,11 @@ _mesa_get_compressed_teximage(GLcontext *ctx, GLenum target, GLint level, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { - const GLuint size = _mesa_format_image_size(texImage->TexFormat, - texImage->Width, - texImage->Height, - texImage->Depth); + const GLuint row_stride = _mesa_format_row_stride(texImage->TexFormat, + texImage->Width); + const GLuint row_stride_stored = _mesa_format_row_stride(texImage->TexFormat, + texImage->RowStride); + GLuint i; if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { /* pack texture image into a PBO */ @@ -540,8 +541,22 @@ _mesa_get_compressed_teximage(GLcontext *ctx, GLenum target, GLint level, img = ADD_POINTERS(buf, img); } - /* just memcpy, no pixelstore or pixel transfer */ - _mesa_memcpy(img, texImage->Data, size); + /* no pixelstore or pixel transfer, but respect stride */ + + if (row_stride == row_stride_stored) { + const GLuint size = _mesa_format_image_size(texImage->TexFormat, + texImage->Width, + texImage->Height, + texImage->Depth); + _mesa_memcpy(img, texImage->Data, size); + } + else { + GLuint bw, bh; + _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh); + for (i = 0; i < (texImage->Height + bh - 1) / bh; i++) { + memcpy(img + i * row_stride, texImage->Data + i * row_stride_stored, row_stride); + } + } if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, -- 2.30.2