From b57138b57a3aa0c54a7499287a58ce0e2153dc39 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 2 Jun 2014 16:29:06 +1200 Subject: [PATCH] mesa: Add pixel storage support for GetCompressedTexImage Signed-off-by: Chris Forbes Reviewed-by: Ian Romanick --- src/mesa/main/texgetimage.c | 73 +++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c index c22fb9b..8c0d3a1 100644 --- a/src/mesa/main/texgetimage.c +++ b/src/mesa/main/texgetimage.c @@ -43,6 +43,7 @@ #include "texcompress.h" #include "texgetimage.h" #include "teximage.h" +#include "texstore.h" @@ -686,56 +687,62 @@ _mesa_get_compressed_teximage(struct gl_context *ctx, struct gl_texture_image *texImage, GLvoid *img) { - const GLuint row_stride = - _mesa_format_row_stride(texImage->TexFormat, texImage->Width); - GLuint i; - GLubyte *src; - GLint srcRowStride; + const GLuint dimensions = + _mesa_get_texture_dimensions(texImage->TexObject->Target); + struct compressed_pixelstore store; + GLuint i, slice; + GLubyte *dest; + + _mesa_compute_compressed_pixelstore(dimensions, texImage, + texImage->Width, texImage->Height, + texImage->Depth, + &ctx->Pack, + &store); if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { /* pack texture image into a PBO */ - GLubyte *buf = (GLubyte *) + dest = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, ctx->Pack.BufferObj->Size, GL_MAP_WRITE_BIT, ctx->Pack.BufferObj, MAP_INTERNAL); - if (!buf) { + if (!dest) { /* out of memory or other unexpected error */ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetCompresssedTexImage(map PBO failed)"); return; } - img = ADD_POINTERS(buf, img); + dest = ADD_POINTERS(dest, img); + } else { + dest = img; } - /* map src texture buffer */ - ctx->Driver.MapTextureImage(ctx, texImage, 0, - 0, 0, texImage->Width, texImage->Height, - GL_MAP_READ_BIT, &src, &srcRowStride); + dest += store.SkipBytes; - if (src) { - /* no pixelstore or pixel transfer, but respect stride */ + for (slice = 0; slice < store.CopySlices; slice++) { + GLint srcRowStride; + GLubyte *src; - if (row_stride == srcRowStride) { - const GLuint size = _mesa_format_image_size(texImage->TexFormat, - texImage->Width, - texImage->Height, - texImage->Depth); - memcpy(img, src, 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((GLubyte *)img + i * row_stride, - (GLubyte *)src + i * srcRowStride, - row_stride); + /* map src texture buffer */ + ctx->Driver.MapTextureImage(ctx, texImage, 0, + 0, 0, texImage->Width, texImage->Height, + GL_MAP_READ_BIT, &src, &srcRowStride); + + if (src) { + + for (i = 0; i < store.CopyRowsPerSlice; i++) { + memcpy(dest, src, store.CopyBytesPerRow); + dest += store.TotalBytesPerRow; + src += srcRowStride; } - } - ctx->Driver.UnmapTextureImage(ctx, texImage, 0); - } - else { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetCompresssedTexImage"); + ctx->Driver.UnmapTextureImage(ctx, texImage, 0); + + /* Advance to next slice */ + dest += store.TotalBytesPerRow * (store.TotalRowsPerSlice - store.CopyRowsPerSlice); + + } else { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetCompresssedTexImage"); + } } if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { -- 2.7.4