X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Ftexgetimage.c;h=daabf2e81380216e3dabc76dca6cc8d7a9f374d9;hb=55cf320ed87f902d817dfea363e6612be0c3b675;hp=554c68b718690cde86d36f7689f79732c5a82545;hpb=5c05d28a43b9cd448f60677ae151efda76b54b3a;p=mesa.git diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c index 554c68b7186..daabf2e8138 100644 --- a/src/mesa/main/texgetimage.c +++ b/src/mesa/main/texgetimage.c @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 7.7 * * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. * Copyright (c) 2009 VMware, Inc. @@ -18,9 +17,10 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. */ @@ -37,7 +37,6 @@ #include "format_unpack.h" #include "glformats.h" #include "image.h" -#include "mfeatures.h" #include "mtypes.h" #include "pack.h" #include "pbo.h" @@ -131,6 +130,10 @@ get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions, const GLint depth = texImage->Depth; GLint img, row; + assert(format == GL_DEPTH_STENCIL); + assert(type == GL_UNSIGNED_INT_24_8); + /* XXX type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV is not handled yet */ + for (img = 0; img < depth; img++) { GLubyte *srcMap; GLint rowstride; @@ -146,8 +149,11 @@ get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions, 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)); + /* Unpack from texture's format to GL's z24_s8 layout */ + _mesa_unpack_uint_24_8_depth_stencil_row(texImage->TexFormat, + width, + (const GLuint *) src, + dest); if (ctx->Pack.SwapBytes) { _mesa_swap4((GLuint *) dest, width); } @@ -226,14 +232,16 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions, GLbitfield transferOps) { /* don't want to apply sRGB -> RGB conversion here so override the format */ - const gl_format texFormat = + const mesa_format texFormat = _mesa_get_srgb_format_linear(texImage->TexFormat); const GLenum baseFormat = _mesa_get_format_base_format(texFormat); + const GLenum destBaseFormat = _mesa_base_tex_format(ctx, format); + GLenum rebaseFormat = GL_NONE; const GLuint width = texImage->Width; const GLuint height = texImage->Height; const GLuint depth = texImage->Depth; - GLfloat *tempImage, *srcRow; - GLuint row; + GLfloat *tempImage, *tempSlice, *srcRow; + GLuint row, slice; /* Decompress into temp float buffer, then pack into user buffer */ tempImage = malloc(width * height * depth @@ -243,20 +251,22 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions, return; } - /* Decompress the texture image - results in 'tempImage' */ - { + /* Decompress the texture image slices - results in 'tempImage' */ + for (slice = 0; slice < depth; slice++) { GLubyte *srcMap; GLint srcRowStride; - ctx->Driver.MapTextureImage(ctx, texImage, 0, + tempSlice = tempImage + slice * 4 * width * height; + + ctx->Driver.MapTextureImage(ctx, texImage, slice, 0, 0, width, height, GL_MAP_READ_BIT, &srcMap, &srcRowStride); if (srcMap) { _mesa_decompress_image(texFormat, width, height, - srcMap, srcRowStride, tempImage); + srcMap, srcRowStride, tempSlice); - ctx->Driver.UnmapTextureImage(ctx, texImage, 0); + ctx->Driver.UnmapTextureImage(ctx, texImage, slice); } else { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage"); @@ -266,26 +276,87 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions, } if (baseFormat == GL_LUMINANCE || + baseFormat == GL_INTENSITY || baseFormat == GL_LUMINANCE_ALPHA) { - _mesa_rebase_rgba_float(width * height, (GLfloat (*)[4]) tempImage, - baseFormat); + /* If a luminance (or intensity) texture is read back as RGB(A), the + * returned value should be (L,0,0,1), not (L,L,L,1). Set rebaseFormat + * here to get G=B=0. + */ + rebaseFormat = texImage->_BaseFormat; + } + else if ((baseFormat == GL_RGBA || + baseFormat == GL_RGB || + baseFormat == GL_RG) && + (destBaseFormat == GL_LUMINANCE || + destBaseFormat == GL_LUMINANCE_ALPHA || + destBaseFormat == GL_LUMINANCE_INTEGER_EXT || + destBaseFormat == GL_LUMINANCE_ALPHA_INTEGER_EXT)) { + /* If we're reading back an RGB(A) texture as luminance then we need + * to return L=tex(R). Note, that's different from glReadPixels which + * returns L=R+G+B. + */ + rebaseFormat = GL_LUMINANCE_ALPHA; /* this covers GL_LUMINANCE too */ } - srcRow = tempImage; - for (row = 0; row < height; row++) { - void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, - width, height, format, type, - 0, row, 0); + if (rebaseFormat) { + _mesa_rebase_rgba_float(width * height, (GLfloat (*)[4]) tempImage, + rebaseFormat); + } - _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) srcRow, - format, type, dest, &ctx->Pack, transferOps); - srcRow += width * 4; + tempSlice = tempImage; + for (slice = 0; slice < depth; slice++) { + srcRow = tempSlice; + for (row = 0; row < height; row++) { + void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels, + width, height, format, type, + slice, row, 0); + + _mesa_pack_rgba_span_float(ctx, width, (GLfloat (*)[4]) srcRow, + format, type, dest, &ctx->Pack, transferOps); + srcRow += 4 * width; + } + tempSlice += 4 * width * height; } free(tempImage); } +/** + * Return a base GL format given the user-requested format + * for glGetTexImage(). + */ +GLenum +_mesa_base_pack_format(GLenum format) +{ + switch (format) { + case GL_ABGR_EXT: + case GL_BGRA: + case GL_BGRA_INTEGER: + case GL_RGBA_INTEGER: + return GL_RGBA; + case GL_BGR: + case GL_BGR_INTEGER: + case GL_RGB_INTEGER: + return GL_RGB; + case GL_RED_INTEGER: + return GL_RED; + case GL_GREEN_INTEGER: + return GL_GREEN; + case GL_BLUE_INTEGER: + return GL_BLUE; + case GL_ALPHA_INTEGER: + return GL_ALPHA; + case GL_LUMINANCE_INTEGER_EXT: + return GL_LUMINANCE; + case GL_LUMINANCE_ALPHA_INTEGER_EXT: + return GL_LUMINANCE_ALPHA; + default: + return format; + } +} + + /** * Get an uncompressed color texture image. */ @@ -296,10 +367,10 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions, GLbitfield transferOps) { /* don't want to apply sRGB -> RGB conversion here so override the format */ - const gl_format texFormat = + const mesa_format texFormat = _mesa_get_srgb_format_linear(texImage->TexFormat); const GLuint width = texImage->Width; - const GLenum destBaseFormat = _mesa_base_tex_format(ctx, format); + GLenum destBaseFormat = _mesa_base_pack_format(format); GLenum rebaseFormat = GL_NONE; GLuint height = texImage->Height; GLuint depth = texImage->Depth; @@ -308,6 +379,7 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions, GLuint (*rgba_uint)[4]; GLboolean tex_is_integer = _mesa_is_format_integer_color(texImage->TexFormat); GLboolean tex_is_uint = _mesa_is_format_unsigned(texImage->TexFormat); + GLenum texBaseFormat = _mesa_get_format_base_format(texImage->TexFormat); /* Allocate buffer for one row of texels */ rgba = malloc(4 * width * sizeof(GLfloat)); @@ -332,7 +404,8 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions, rebaseFormat = texImage->_BaseFormat; } else if ((texImage->_BaseFormat == GL_RGBA || - texImage->_BaseFormat == GL_RGB) && + texImage->_BaseFormat == GL_RGB || + texImage->_BaseFormat == GL_RG) && (destBaseFormat == GL_LUMINANCE || destBaseFormat == GL_LUMINANCE_ALPHA || destBaseFormat == GL_LUMINANCE_INTEGER_EXT || @@ -343,6 +416,50 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions, */ rebaseFormat = GL_LUMINANCE_ALPHA; /* this covers GL_LUMINANCE too */ } + else if (texImage->_BaseFormat != texBaseFormat) { + /* The internal format and the real format differ, so we can't rely + * on the unpack functions setting the correct constant values. + * (e.g. reading back GL_RGB8 which is actually RGBA won't set alpha=1) + */ + switch (texImage->_BaseFormat) { + case GL_RED: + if ((texBaseFormat == GL_RGBA || + texBaseFormat == GL_RGB || + texBaseFormat == GL_RG) && + (destBaseFormat == GL_RGBA || + destBaseFormat == GL_RGB || + destBaseFormat == GL_RG || + destBaseFormat == GL_GREEN)) { + rebaseFormat = texImage->_BaseFormat; + break; + } + /* fall through */ + case GL_RG: + if ((texBaseFormat == GL_RGBA || + texBaseFormat == GL_RGB) && + (destBaseFormat == GL_RGBA || + destBaseFormat == GL_RGB || + destBaseFormat == GL_BLUE)) { + rebaseFormat = texImage->_BaseFormat; + break; + } + /* fall through */ + case GL_RGB: + if (texBaseFormat == GL_RGBA && + (destBaseFormat == GL_RGBA || + destBaseFormat == GL_ALPHA || + destBaseFormat == GL_LUMINANCE_ALPHA)) { + rebaseFormat = texImage->_BaseFormat; + } + break; + + case GL_ALPHA: + if (destBaseFormat != GL_ALPHA) { + rebaseFormat = texImage->_BaseFormat; + } + break; + } + } for (img = 0; img < depth; img++) { GLubyte *srcMap; @@ -413,21 +530,13 @@ get_tex_rgba(struct gl_context *ctx, GLuint dimensions, if (type_needs_clamping(type)) { /* the returned image type can't have negative values */ if (dataType == GL_FLOAT || + dataType == GL_HALF_FLOAT || dataType == GL_SIGNED_NORMALIZED || format == GL_LUMINANCE || format == GL_LUMINANCE_ALPHA) { transferOps |= IMAGE_CLAMP_BIT; } } - /* This applies to RGB, RGBA textures. if the format is either LUMINANCE - * or LUMINANCE ALPHA, luminance (L) is computed as L=R+G+B .we need to - * clamp the sum to [0,1]. - */ - else if ((format == GL_LUMINANCE || - format == GL_LUMINANCE_ALPHA) && - dataType == GL_UNSIGNED_NORMALIZED) { - transferOps |= IMAGE_CLAMP_BIT; - } if (_mesa_is_format_compressed(texImage->TexFormat)) { get_tex_rgba_compressed(ctx, dimensions, format, type, @@ -451,16 +560,18 @@ get_tex_memcpy(struct gl_context *ctx, GLenum format, GLenum type, { const GLenum target = texImage->TexObject->Target; GLboolean memCopy = GL_FALSE; + GLenum texBaseFormat = _mesa_get_format_base_format(texImage->TexFormat); /* * Check if we can use memcpy to copy from the hardware texture * format to the user's format/type. * Note that GL's pixel transfer ops don't apply to glGetTexImage() */ - if (target == GL_TEXTURE_1D || - target == GL_TEXTURE_2D || - target == GL_TEXTURE_RECTANGLE || - _mesa_is_cube_face(target)) { + if ((target == GL_TEXTURE_1D || + target == GL_TEXTURE_2D || + target == GL_TEXTURE_RECTANGLE || + _mesa_is_cube_face(target)) && + texBaseFormat == texImage->_BaseFormat) { memCopy = _mesa_format_matches_format_and_type(texImage->TexFormat, format, type, ctx->Pack.SwapBytes); @@ -518,18 +629,8 @@ _mesa_get_teximage(struct gl_context *ctx, GLenum format, GLenum type, GLvoid *pixels, struct gl_texture_image *texImage) { - GLuint dimensions; - - switch (texImage->TexObject->Target) { - case GL_TEXTURE_1D: - dimensions = 1; - break; - case GL_TEXTURE_3D: - dimensions = 3; - break; - default: - dimensions = 2; - } + const GLuint dimensions = + _mesa_get_texture_dimensions(texImage->TexObject->Target); /* map dest buffer, if PBO */ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { @@ -541,7 +642,8 @@ _mesa_get_teximage(struct gl_context *ctx, */ GLubyte *buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, ctx->Pack.BufferObj->Size, - GL_MAP_WRITE_BIT, ctx->Pack.BufferObj); + GL_MAP_WRITE_BIT, ctx->Pack.BufferObj, + MAP_INTERNAL); if (!buf) { /* out of memory or other unexpected error */ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage(map PBO failed)"); @@ -570,7 +672,7 @@ _mesa_get_teximage(struct gl_context *ctx, } if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { - ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj); + ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj, MAP_INTERNAL); } } @@ -595,7 +697,8 @@ _mesa_get_compressed_teximage(struct gl_context *ctx, /* pack texture image into a PBO */ GLubyte *buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, ctx->Pack.BufferObj->Size, - GL_MAP_WRITE_BIT, ctx->Pack.BufferObj); + GL_MAP_WRITE_BIT, ctx->Pack.BufferObj, + MAP_INTERNAL); if (!buf) { /* out of memory or other unexpected error */ _mesa_error(ctx, GL_OUT_OF_MEMORY, @@ -637,7 +740,7 @@ _mesa_get_compressed_teximage(struct gl_context *ctx, } if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { - ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj); + ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj, MAP_INTERNAL); } } @@ -665,8 +768,9 @@ legal_getteximage_target(struct gl_context *ctx, GLenum target) return ctx->Extensions.NV_texture_rectangle; case GL_TEXTURE_1D_ARRAY_EXT: case GL_TEXTURE_2D_ARRAY_EXT: - return (ctx->Extensions.MESA_texture_array || - ctx->Extensions.EXT_texture_array); + return ctx->Extensions.EXT_texture_array; + case GL_TEXTURE_CUBE_MAP_ARRAY: + return ctx->Extensions.ARB_texture_cube_map_array; default: return GL_FALSE; } @@ -766,7 +870,7 @@ getteximage_error_check(struct gl_context *ctx, GLenum target, GLint level, if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { /* PBO should not be mapped */ - if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) { + if (_mesa_check_disallowed_mapping(ctx->Pack.BufferObj)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexImage(PBO is mapped)"); return GL_TRUE; @@ -795,7 +899,8 @@ _mesa_GetnTexImageARB( GLenum target, GLint level, GLenum format, struct gl_texture_object *texObj; struct gl_texture_image *texImage; GET_CURRENT_CONTEXT(ctx); - ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + + FLUSH_VERTICES(ctx, 0); if (getteximage_error_check(ctx, target, level, format, type, bufSize, pixels)) { @@ -908,7 +1013,7 @@ getcompressedteximage_error_check(struct gl_context *ctx, GLenum target, } /* make sure PBO is not mapped */ - if (_mesa_bufferobj_mapped(ctx->Pack.BufferObj)) { + if (_mesa_check_disallowed_mapping(ctx->Pack.BufferObj)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImage(PBO is mapped)"); return GL_TRUE; @@ -926,7 +1031,8 @@ _mesa_GetnCompressedTexImageARB(GLenum target, GLint level, GLsizei bufSize, struct gl_texture_object *texObj; struct gl_texture_image *texImage; GET_CURRENT_CONTEXT(ctx); - ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); + + FLUSH_VERTICES(ctx, 0); if (getcompressedteximage_error_check(ctx, target, level, bufSize, img)) { return; @@ -959,7 +1065,7 @@ _mesa_GetnCompressedTexImageARB(GLenum target, GLint level, GLsizei bufSize, } void GLAPIENTRY -_mesa_GetCompressedTexImageARB(GLenum target, GLint level, GLvoid *img) +_mesa_GetCompressedTexImage(GLenum target, GLint level, GLvoid *img) { _mesa_GetnCompressedTexImageARB(target, level, INT_MAX, img); }