X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Ftexgetimage.c;h=06e032396e4e5e49fd0e560bc41358a0c3137b28;hb=ab9136ef750a1209db26d6c9dffe299f4134682e;hp=199fb5cb9001c7368ce60a8715415cafc88002ed;hpb=0c513a9c1b5125ba647c17f330635ded46d4d174;p=mesa.git diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c index 199fb5cb900..06e032396e4 100644 --- a/src/mesa/main/texgetimage.c +++ b/src/mesa/main/texgetimage.c @@ -49,7 +49,7 @@ /** * Can the given type represent negative values? */ -static INLINE GLboolean +static inline GLboolean type_with_negative_values(GLenum type) { switch (type) { @@ -71,14 +71,13 @@ type_with_negative_values(GLenum type) static void get_tex_depth(struct gl_context *ctx, GLuint dimensions, GLenum format, GLenum type, GLvoid *pixels, - const struct gl_texture_image *texImage) + struct gl_texture_image *texImage) { const GLint width = texImage->Width; const GLint height = texImage->Height; const GLint depth = texImage->Depth; GLint img, row; GLfloat *depthRow = (GLfloat *) malloc(width * sizeof(GLfloat)); - const GLint texelSize = _mesa_get_format_bytes(texImage->TexFormat); if (!depthRow) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); @@ -86,18 +85,24 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions, } for (img = 0; img < depth; img++) { + GLubyte *srcMap; + GLint srcRowStride; + + /* map src texture buffer */ + ctx->Driver.MapTextureImage(ctx, texImage, img, + 0, 0, width, height, GL_MAP_READ_BIT, + &srcMap, &srcRowStride); + for (row = 0; row < height; row++) { void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, width, height, format, type, img, row, 0); - const GLubyte *src = (GLubyte *) texImage->Data + - (texImage->ImageOffsets[img] + - texImage->RowStride * row) * texelSize; - + const GLubyte *src = srcMap + row * srcRowStride; _mesa_unpack_float_z_row(texImage->TexFormat, width, src, depthRow); - _mesa_pack_depth_span(ctx, width, dest, type, depthRow, &ctx->Pack); } + + ctx->Driver.UnmapTextureImage(ctx, texImage, img); } free(depthRow); @@ -110,27 +115,35 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions, static void get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions, GLenum format, GLenum type, GLvoid *pixels, - const struct gl_texture_image *texImage) + struct gl_texture_image *texImage) { const GLint width = texImage->Width; const GLint height = texImage->Height; const GLint depth = texImage->Depth; - const GLint rowstride = texImage->RowStride; - const GLuint *src = (const GLuint *) texImage->Data; GLint img, row; for (img = 0; img < depth; img++) { + GLubyte *srcMap; + GLint rowstride; + + /* map src texture buffer */ + ctx->Driver.MapTextureImage(ctx, texImage, img, + 0, 0, width, height, GL_MAP_READ_BIT, + &srcMap, &rowstride); + for (row = 0; row < height; row++) { + const GLubyte *src = srcMap + row * rowstride; void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, width, height, format, type, img, row, 0); + /* XXX Z24_S8 vs. S8_Z24??? */ memcpy(dest, src, width * sizeof(GLuint)); if (ctx->Pack.SwapBytes) { _mesa_swap4((GLuint *) dest, width); } - - src += rowstride; } + + ctx->Driver.UnmapTextureImage(ctx, texImage, img); } } @@ -228,8 +241,32 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions, return; } - _mesa_decompress_image(texFormat, texImage->Width, texImage->Height, - texImage->Data, texImage->RowStride, tempImage); + /* Decompress the texture image - results in 'tempImage' */ + { + GLubyte *srcMap; + GLint srcRowStride; + GLuint bytes, bw, bh; + + bytes = _mesa_get_format_bytes(texImage->TexFormat); + _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh); + + ctx->Driver.MapTextureImage(ctx, texImage, 0, + 0, 0, width, height, + GL_MAP_READ_BIT, + &srcMap, &srcRowStride); + + /* XXX This line is a bit of a hack to work around the + * mismatch of compressed row strides as returned by + * MapTextureImage() vs. what the texture decompression code + * uses. This will be fixed in the future. + */ + srcRowStride = srcRowStride * bh / bytes; + + _mesa_decompress_image(texFormat, width, height, + srcMap, srcRowStride, tempImage); + + ctx->Driver.UnmapTextureImage(ctx, texImage, 0); + } if (baseFormat == GL_LUMINANCE || baseFormat == GL_LUMINANCE_ALPHA) { @@ -257,7 +294,6 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions, } else { /* No decompression needed */ - const GLint texelSize = _mesa_get_format_bytes(texFormat); GLuint img, row; GLfloat (*rgba)[4]; @@ -268,13 +304,19 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions, } for (img = 0; img < depth; img++) { + GLubyte *srcMap; + GLint rowstride; + + /* map src texture buffer */ + ctx->Driver.MapTextureImage(ctx, texImage, img, + 0, 0, width, height, GL_MAP_READ_BIT, + &srcMap, &rowstride); + for (row = 0; row < height; row++) { + const GLubyte *src = srcMap + row * rowstride; void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, width, height, format, type, img, row, 0); - const GLubyte *src = (const GLubyte *) texImage->Data + - (texImage->ImageOffsets[img] + - texImage->RowStride * row) * texelSize; _mesa_unpack_rgba_row(texFormat, width, src, rgba); @@ -314,6 +356,9 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions, format, type, dest, &ctx->Pack, transferOps); } + + /* Unmap the src texture buffer */ + ctx->Driver.UnmapTextureImage(ctx, texImage, img); } free(rgba); @@ -328,9 +373,9 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions, static GLboolean get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, GLvoid *pixels, - struct gl_texture_object *texObj, struct gl_texture_image *texImage) { + const GLenum target = texImage->TexObject->Target; GLboolean memCopy = GL_FALSE; /* @@ -339,11 +384,11 @@ get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, * so we don't have to worry about those. * XXX more format combinations could be supported here. */ - if ((texObj->Target == GL_TEXTURE_1D || - texObj->Target == GL_TEXTURE_2D || - texObj->Target == GL_TEXTURE_RECTANGLE || - (texObj->Target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && - texObj->Target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) { + if ((target == GL_TEXTURE_1D || + target == GL_TEXTURE_2D || + target == GL_TEXTURE_RECTANGLE || + (target >= GL_TEXTURE_CUBE_MAP_POSITIVE_X && + target <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z))) { if ((texImage->TexFormat == MESA_FORMAT_ARGB8888 || texImage->TexFormat == MESA_FORMAT_SARGB8) && format == GL_BGRA && @@ -426,14 +471,13 @@ get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, * unmap with ctx->Driver.UnmapTextureImage(). */ void -_mesa_get_teximage(struct gl_context *ctx, GLenum target, GLint level, +_mesa_get_teximage(struct gl_context *ctx, GLenum format, GLenum type, GLvoid *pixels, - struct gl_texture_object *texObj, struct gl_texture_image *texImage) { GLuint dimensions; - switch (target) { + switch (texImage->TexObject->Target) { case GL_TEXTURE_1D: dimensions = 1; break; @@ -466,7 +510,7 @@ _mesa_get_teximage(struct gl_context *ctx, GLenum target, GLint level, pixels = ADD_POINTERS(buf, pixels); } - if (get_tex_memcpy(ctx, format, type, pixels, texObj, texImage)) { + if (get_tex_memcpy(ctx, format, type, pixels, texImage)) { /* all done */ } else if (format == GL_DEPTH_COMPONENT) { @@ -727,8 +771,7 @@ _mesa_GetnTexImageARB( GLenum target, GLint level, GLenum format, _mesa_lock_texture(ctx, texObj); { - ctx->Driver.GetTexImage(ctx, target, level, format, type, pixels, - texObj, texImage); + ctx->Driver.GetTexImage(ctx, format, type, pixels, texImage); } _mesa_unlock_texture(ctx, texObj); } @@ -841,7 +884,7 @@ _mesa_GetnCompressedTexImageARB(GLenum target, GLint level, GLsizei bufSize, return; } - if (_mesa_is_bufferobj(ctx->Pack.BufferObj) && !img) { + if (!_mesa_is_bufferobj(ctx->Pack.BufferObj) && !img) { /* not an error, do nothing */ return; }