X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Ftexgetimage.c;h=9171a8de8116b0a8e3d63b4d0f9b7fa2cd641a9e;hb=c601e730b298c5bdd34bc4335f203d46c5cdf9b3;hp=3c1e166ffa1322a9298e2145389f44bba4b3fa19;hpb=9b387b5d3f4103c51079ea5298d33086af6da433;p=mesa.git diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c index 3c1e166ffa1..9171a8de811 100644 --- a/src/mesa/main/texgetimage.c +++ b/src/mesa/main/texgetimage.c @@ -88,12 +88,6 @@ get_tex_depth(struct gl_context *ctx, GLuint dimensions, return; } - if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY) { - depth = height; - height = 1; - } - - assert(zoffset + depth <= texImage->Depth); for (img = 0; img < depth; img++) { GLubyte *srcMap; GLint srcRowStride; @@ -138,10 +132,7 @@ get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions, GLint img, row; assert(format == GL_DEPTH_STENCIL); - assert(type == GL_UNSIGNED_INT_24_8 || - type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV); - assert(zoffset + depth <= texImage->Depth); for (img = 0; img < depth; img++) { GLubyte *srcMap; GLint rowstride; @@ -157,10 +148,19 @@ 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); - _mesa_unpack_depth_stencil_row(texImage->TexFormat, - width, - (const GLuint *) src, - type, dest); + switch (type) { + case GL_UNSIGNED_INT_24_8: + _mesa_unpack_uint_24_8_depth_stencil_row(texImage->TexFormat, + width, src, dest); + break; + case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: + _mesa_unpack_float_32_uint_24_8_depth_stencil_row(texImage->TexFormat, + width, + src, dest); + break; + default: + unreachable("bad type in get_tex_depth_stencil()"); + } if (ctx->Pack.SwapBytes) { _mesa_swap4((GLuint *) dest, width); } @@ -233,7 +233,6 @@ get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions, { GLint img, row; - assert(zoffset + depth <= texImage->Depth); for (img = 0; img < depth; img++) { GLubyte *srcMap; GLint rowstride; @@ -273,6 +272,40 @@ get_tex_ycbcr(struct gl_context *ctx, GLuint dimensions, } } +/** + * Depending on the base format involved we may need to apply a rebase + * transform (for example: if we download to a Luminance format we want + * G=0 and B=0). + */ +static bool +teximage_needs_rebase(mesa_format texFormat, GLenum baseFormat, + bool is_compressed, uint8_t *rebaseSwizzle) +{ + bool needsRebase = false; + + if (baseFormat == GL_LUMINANCE || + baseFormat == GL_INTENSITY) { + needsRebase = true; + rebaseSwizzle[0] = MESA_FORMAT_SWIZZLE_X; + rebaseSwizzle[1] = MESA_FORMAT_SWIZZLE_ZERO; + rebaseSwizzle[2] = MESA_FORMAT_SWIZZLE_ZERO; + rebaseSwizzle[3] = MESA_FORMAT_SWIZZLE_ONE; + } else if (baseFormat == GL_LUMINANCE_ALPHA) { + needsRebase = true; + rebaseSwizzle[0] = MESA_FORMAT_SWIZZLE_X; + rebaseSwizzle[1] = MESA_FORMAT_SWIZZLE_ZERO; + rebaseSwizzle[2] = MESA_FORMAT_SWIZZLE_ZERO; + rebaseSwizzle[3] = MESA_FORMAT_SWIZZLE_W; + } else if (!is_compressed && + (baseFormat != _mesa_get_format_base_format(texFormat))) { + needsRebase = + _mesa_compute_rgba2base2rgba_component_mapping(baseFormat, + rebaseSwizzle); + } + + return needsRebase; +} + /** * Get a color texture image with decompression. @@ -297,8 +330,7 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions, uint8_t rebaseSwizzle[4]; /* Decompress into temp float buffer, then pack into user buffer */ - tempImage = malloc(width * height * depth - * 4 * sizeof(GLfloat)); + tempImage = malloc(width * height * depth * 4 * sizeof(GLfloat)); if (!tempImage) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()"); return; @@ -328,26 +360,8 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions, } } - /* Depending on the base format involved we may need to apply a rebase - * transform (for example: if we download to a Luminance format we want - * G=0 and B=0). - */ - if (baseFormat == GL_LUMINANCE || - baseFormat == GL_INTENSITY) { - needsRebase = true; - rebaseSwizzle[0] = MESA_FORMAT_SWIZZLE_X; - rebaseSwizzle[1] = MESA_FORMAT_SWIZZLE_ZERO; - rebaseSwizzle[2] = MESA_FORMAT_SWIZZLE_ZERO; - rebaseSwizzle[3] = MESA_FORMAT_SWIZZLE_ONE; - } else if (baseFormat == GL_LUMINANCE_ALPHA) { - needsRebase = true; - rebaseSwizzle[0] = MESA_FORMAT_SWIZZLE_X; - rebaseSwizzle[1] = MESA_FORMAT_SWIZZLE_ZERO; - rebaseSwizzle[2] = MESA_FORMAT_SWIZZLE_ZERO; - rebaseSwizzle[3] = MESA_FORMAT_SWIZZLE_W; - } else { - needsRebase = false; - } + needsRebase = teximage_needs_rebase(texFormat, baseFormat, true, + rebaseSwizzle); srcStride = 4 * width * sizeof(GLfloat); dstStride = _mesa_image_row_stride(&ctx->Pack, width, format, type); @@ -361,6 +375,13 @@ get_tex_rgba_compressed(struct gl_context *ctx, GLuint dimensions, tempSlice, RGBA32_FLOAT, srcStride, width, height, needsRebase ? rebaseSwizzle : NULL); + + /* Handle byte swapping if required */ + if (ctx->Pack.SwapBytes) { + _mesa_swap_bytes_2d_image(format, type, &ctx->Pack, + width, height, dest, dest); + } + tempSlice += 4 * width * height; } @@ -425,38 +446,8 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions, bool needsRebase; void *rgba = NULL; - if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY) { - depth = height; - height = 1; - zoffset = yoffset; - yoffset = 0; - } - - /* Depending on the base format involved we may need to apply a rebase - * transform (for example: if we download to a Luminance format we want - * G=0 and B=0). - */ - if (texImage->_BaseFormat == GL_LUMINANCE || - texImage->_BaseFormat == GL_INTENSITY) { - needsRebase = true; - rebaseSwizzle[0] = MESA_FORMAT_SWIZZLE_X; - rebaseSwizzle[1] = MESA_FORMAT_SWIZZLE_ZERO; - rebaseSwizzle[2] = MESA_FORMAT_SWIZZLE_ZERO; - rebaseSwizzle[3] = MESA_FORMAT_SWIZZLE_ONE; - } else if (texImage->_BaseFormat == GL_LUMINANCE_ALPHA) { - needsRebase = true; - rebaseSwizzle[0] = MESA_FORMAT_SWIZZLE_X; - rebaseSwizzle[1] = MESA_FORMAT_SWIZZLE_ZERO; - rebaseSwizzle[2] = MESA_FORMAT_SWIZZLE_ZERO; - rebaseSwizzle[3] = MESA_FORMAT_SWIZZLE_W; - } else if (texImage->_BaseFormat != - _mesa_get_format_base_format(texFormat)) { - needsRebase = - _mesa_compute_rgba2base2rgba_component_mapping(texImage->_BaseFormat, - rebaseSwizzle); - } else { - needsRebase = false; - } + needsRebase = teximage_needs_rebase(texFormat, texImage->_BaseFormat, false, + rebaseSwizzle); /* Describe the dst format */ dst_is_integer = _mesa_is_enum_format_integer(format); @@ -511,13 +502,15 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions, */ if (format == rgba_format) { rgba = dest; - } else if (rgba == NULL) { /* Allocate the RGBA buffer only once */ + } else { need_convert = true; - rgba = malloc(height * rgba_stride); - if (!rgba) { - _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()"); - ctx->Driver.UnmapTextureImage(ctx, texImage, img); - return; + if (rgba == NULL) { /* Allocate the RGBA buffer only once */ + rgba = malloc(height * rgba_stride); + if (!rgba) { + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage()"); + ctx->Driver.UnmapTextureImage(ctx, texImage, img); + return; + } } } @@ -557,25 +550,16 @@ get_tex_rgba_uncompressed(struct gl_context *ctx, GLuint dimensions, do_swap: /* Handle byte swapping if required */ - if (ctx->Pack.SwapBytes) { - GLint swapSize = _mesa_sizeof_packed_type(type); - if (swapSize == 2 || swapSize == 4) { - int swapsPerPixel = _mesa_bytes_per_pixel(format, type) / swapSize; - assert(_mesa_bytes_per_pixel(format, type) % swapSize == 0); - if (swapSize == 2) - _mesa_swap2((GLushort *) dest, width * height * swapsPerPixel); - else if (swapSize == 4) - _mesa_swap4((GLuint *) dest, width * height * swapsPerPixel); - } - } + if (ctx->Pack.SwapBytes) + _mesa_swap_bytes_2d_image(format, type, &ctx->Pack, + width, height, dest, dest); /* Unmap the src texture buffer */ ctx->Driver.UnmapTextureImage(ctx, texImage, zoffset + img); } done: - if (rgba) - free(rgba); + free(rgba); } @@ -656,7 +640,7 @@ get_tex_memcpy(struct gl_context *ctx, if (depth > 1) { /* only a single slice is supported at this time */ - memCopy = FALSE; + memCopy = GL_FALSE; } if (memCopy) { @@ -677,7 +661,7 @@ get_tex_memcpy(struct gl_context *ctx, if (src) { if (bytesPerRow == dstRowStride && bytesPerRow == srcRowStride) { - memcpy(dst, src, bytesPerRow * texImage->Height); + memcpy(dst, src, bytesPerRow * height); } else { GLuint row; @@ -717,7 +701,7 @@ _mesa_GetTexSubImage_sw(struct gl_context *ctx, _mesa_get_texture_dimensions(texImage->TexObject->Target); /* map dest buffer, if PBO */ - if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { + if (ctx->Pack.BufferObj) { /* Packing texture image into a PBO. * Map the (potentially) VRAM-based buffer into our process space so * we can write into it with the code below. @@ -739,6 +723,17 @@ _mesa_GetTexSubImage_sw(struct gl_context *ctx, pixels = ADD_POINTERS(buf, pixels); } + /* for all array textures, the Z axis selects the layer */ + if (texImage->TexObject->Target == GL_TEXTURE_1D_ARRAY) { + depth = height; + height = 1; + zoffset = yoffset; + yoffset = 0; + assert(zoffset + depth <= texImage->Height); + } else { + assert(zoffset + depth <= texImage->Depth); + } + if (get_tex_memcpy(ctx, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels, texImage)) { /* all done */ @@ -765,7 +760,7 @@ _mesa_GetTexSubImage_sw(struct gl_context *ctx, width, height, depth, format, type, pixels, texImage); } - if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { + if (ctx->Pack.BufferObj) { ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj, MAP_INTERNAL); } } @@ -773,16 +768,15 @@ _mesa_GetTexSubImage_sw(struct gl_context *ctx, /** - * This is the software fallback for Driver.GetCompressedTexSubImage(). - * All error checking will have been done before this routine is called. + * This function assumes that all error checking has been done. */ -void -_mesa_GetCompressedTexSubImage_sw(struct gl_context *ctx, - struct gl_texture_image *texImage, - GLint xoffset, GLint yoffset, - GLint zoffset, GLsizei width, - GLint height, GLint depth, - GLvoid *img) +static void +get_compressed_texsubimage_sw(struct gl_context *ctx, + struct gl_texture_image *texImage, + GLint xoffset, GLint yoffset, + GLint zoffset, GLsizei width, + GLint height, GLint depth, + GLvoid *img) { const GLuint dimensions = _mesa_get_texture_dimensions(texImage->TexObject->Target); @@ -794,7 +788,7 @@ _mesa_GetCompressedTexSubImage_sw(struct gl_context *ctx, width, height, depth, &ctx->Pack, &store); - if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { + if (ctx->Pack.BufferObj) { /* pack texture image into a PBO */ dest = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, ctx->Pack.BufferObj->Size, @@ -841,7 +835,7 @@ _mesa_GetCompressedTexSubImage_sw(struct gl_context *ctx, } } - if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { + if (ctx->Pack.BufferObj) { ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj, MAP_INTERNAL); } } @@ -875,12 +869,12 @@ legal_getteximage_target(struct gl_context *ctx, GLenum target, bool dsa) * the targets from table 8.19 (for GetTexImage and GetnTexImage *only*), * or TEXTURE_CUBE_MAP (for GetTextureImage *only*)." (Emphasis added.) */ - case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB: - case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB: - case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB: + case GL_TEXTURE_CUBE_MAP_POSITIVE_X: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: + case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: + case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: return dsa ? GL_FALSE : ctx->Extensions.ARB_texture_cube_map; case GL_TEXTURE_CUBE_MAP: return dsa ? GL_TRUE : GL_FALSE; @@ -892,7 +886,7 @@ legal_getteximage_target(struct gl_context *ctx, GLenum target, bool dsa) /** * Wrapper for _mesa_select_tex_image() which can handle target being - * GL_TEXTURE_CUBE_MAP_ARB in which case we use zoffset to select a cube face. + * GL_TEXTURE_CUBE_MAP in which case we use zoffset to select a cube face. * This can happen for glGetTextureImage and glGetTextureSubImage (DSA * functions). */ @@ -913,8 +907,7 @@ select_tex_image(const struct gl_texture_object *texObj, GLenum target, /** * Error-check the offset and size arguments to - * glGet[Compressed]TextureSubImage(). Also checks if the specified - * texture image is missing. + * glGet[Compressed]TextureSubImage(). * \return true if error, false if no error. */ static bool @@ -926,7 +919,7 @@ dimensions_error_check(struct gl_context *ctx, const char *caller) { const struct gl_texture_image *texImage; - int i; + GLuint imageWidth = 0, imageHeight = 0, imageDepth = 0; if (xoffset < 0) { _mesa_error(ctx, GL_INVALID_VALUE, "%s(xoffset = %d)", caller, xoffset); @@ -966,7 +959,7 @@ dimensions_error_check(struct gl_context *ctx, "%s(1D, yoffset = %d)", caller, yoffset); return true; } - if (height > 1) { + if (height != 1) { _mesa_error(ctx, GL_INVALID_VALUE, "%s(1D, height = %d)", caller, height); return true; @@ -980,7 +973,7 @@ dimensions_error_check(struct gl_context *ctx, "%s(zoffset = %d)", caller, zoffset); return true; } - if (depth > 1) { + if (depth != 1) { _mesa_error(ctx, GL_INVALID_VALUE, "%s(depth = %d)", caller, depth); return true; @@ -995,57 +988,47 @@ dimensions_error_check(struct gl_context *ctx, "%s(zoffset + depth = %d)", caller, zoffset + depth); return true; } - /* check that the range of faces exist */ - for (i = 0; i < depth; i++) { - GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + zoffset + i; - if (!_mesa_select_tex_image(texObj, face, level)) { - /* non-existant face */ - _mesa_error(ctx, GL_INVALID_OPERATION, - "%s(missing cube face)", caller); - return true; - } - } break; default: ; /* nothing */ } texImage = select_tex_image(texObj, target, level, zoffset); - if (!texImage) { - /* missing texture image */ - _mesa_error(ctx, GL_INVALID_OPERATION, "%s(missing image)", caller); - return true; + if (texImage) { + imageWidth = texImage->Width; + imageHeight = texImage->Height; + imageDepth = texImage->Depth; } - if (xoffset + width > texImage->Width) { + if (xoffset + width > imageWidth) { _mesa_error(ctx, GL_INVALID_VALUE, "%s(xoffset %d + width %d > %u)", - caller, xoffset, width, texImage->Width); + caller, xoffset, width, imageWidth); return true; } - if (yoffset + height > texImage->Height) { + if (yoffset + height > imageHeight) { _mesa_error(ctx, GL_INVALID_VALUE, "%s(yoffset %d + height %d > %u)", - caller, yoffset, height, texImage->Height); + caller, yoffset, height, imageHeight); return true; } if (target != GL_TEXTURE_CUBE_MAP) { /* Cube map error checking was done above */ - if (zoffset + depth > texImage->Depth) { + if (zoffset + depth > imageDepth) { _mesa_error(ctx, GL_INVALID_VALUE, "%s(zoffset %d + depth %d > %u)", - caller, zoffset, depth, texImage->Depth); + caller, zoffset, depth, imageDepth); return true; } } /* Extra checks for compressed textures */ - { - GLuint bw, bh; - _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh); - if (bw > 1 || bh > 1) { + if (texImage) { + GLuint bw, bh, bd; + _mesa_get_format_block_size_3d(texImage->TexFormat, &bw, &bh, &bd); + if (bw > 1 || bh > 1 || bd > 1) { /* offset must be multiple of block size */ if (xoffset % bw != 0) { _mesa_error(ctx, GL_INVALID_VALUE, @@ -1060,7 +1043,13 @@ dimensions_error_check(struct gl_context *ctx, } } - /* The size must be a multiple of bw x bh, or we must be using a + if (zoffset % bd != 0) { + _mesa_error(ctx, GL_INVALID_VALUE, + "%s(zoffset = %d)", caller, zoffset); + return true; + } + + /* The size must be a multiple of bw x bh x bd, or we must be using a * offset+size that exactly hits the edge of the image. */ if ((width % bw != 0) && @@ -1076,6 +1065,13 @@ dimensions_error_check(struct gl_context *ctx, "%s(height = %d)", caller, height); return true; } + + if ((depth % bd != 0) && + (zoffset + depth != (GLint) texImage->Depth)) { + _mesa_error(ctx, GL_INVALID_VALUE, + "%s(depth = %d)", caller, depth); + return true; + } } } @@ -1105,7 +1101,7 @@ pbo_error_check(struct gl_context *ctx, GLenum target, if (!_mesa_validate_pbo_access(dimensions, &ctx->Pack, width, height, depth, format, type, clientMemSize, pixels)) { - if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { + if (ctx->Pack.BufferObj) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(out of bounds PBO access)", caller); } else { @@ -1116,7 +1112,7 @@ pbo_error_check(struct gl_context *ctx, GLenum target, return true; } - if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { + if (ctx->Pack.BufferObj) { /* PBO should not be mapped */ if (_mesa_check_disallowed_mapping(ctx->Pack.BufferObj)) { _mesa_error(ctx, GL_INVALID_OPERATION, @@ -1125,7 +1121,7 @@ pbo_error_check(struct gl_context *ctx, GLenum target, } } - if (!_mesa_is_bufferobj(ctx->Pack.BufferObj) && !pixels) { + if (!ctx->Pack.BufferObj && !pixels) { /* not an error, do nothing */ return true; } @@ -1135,53 +1131,15 @@ pbo_error_check(struct gl_context *ctx, GLenum target, /** - * Do error checking for all (non-compressed) get-texture-image functions. - * \return true if any error, false if no errors. + * Do teximage-related error checking for getting uncompressed images. + * \return true if there was an error */ static bool -getteximage_error_check(struct gl_context *ctx, - struct gl_texture_object *texObj, - GLenum target, GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLsizei width, GLsizei height, GLsizei depth, - GLenum format, GLenum type, GLsizei bufSize, - GLvoid *pixels, const char *caller) +teximage_error_check(struct gl_context *ctx, + struct gl_texture_image *texImage, + GLenum format, const char *caller) { - struct gl_texture_image *texImage; - GLenum baseFormat, err; - GLint maxLevels; - - assert(texObj); - - if (texObj->Target == 0) { - _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid texture)", caller); - return true; - } - - maxLevels = _mesa_max_texture_levels(ctx, target); - if (level < 0 || level >= maxLevels) { - _mesa_error(ctx, GL_INVALID_VALUE, "%s(level = %d)", caller, level); - return true; - } - - err = _mesa_error_check_format_and_type(ctx, format, type); - if (err != GL_NO_ERROR) { - _mesa_error(ctx, err, "%s(format/type)", caller); - return true; - } - - if (dimensions_error_check(ctx, texObj, target, level, - xoffset, yoffset, zoffset, - width, height, depth, caller)) { - return true; - } - - if (pbo_error_check(ctx, target, width, height, depth, - format, type, bufSize, pixels, caller)) { - return true; - } - - texImage = select_tex_image(texObj, target, level, zoffset); + GLenum baseFormat; assert(texImage); /* @@ -1213,6 +1171,13 @@ getteximage_error_check(struct gl_context *ctx, "%s(format=GL_STENCIL_INDEX)", caller); return true; } + else if (_mesa_is_stencil_format(format) + && !_mesa_is_depthstencil_format(baseFormat) + && !_mesa_is_stencil_format(baseFormat)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(format mismatch)", caller); + return true; + } else if (_mesa_is_ycbcr_format(format) && !_mesa_is_ycbcr_format(baseFormat)) { _mesa_error(ctx, GL_INVALID_OPERATION, @@ -1237,6 +1202,142 @@ getteximage_error_check(struct gl_context *ctx, } +/** + * Do common teximage-related error checking for getting uncompressed images. + * \return true if there was an error + */ +static bool +common_error_check(struct gl_context *ctx, + struct gl_texture_object *texObj, + GLenum target, GLint level, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, GLsizei bufSize, + GLvoid *pixels, const char *caller) +{ + GLenum err; + GLint maxLevels; + + if (texObj->Target == 0) { + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid texture)", caller); + return true; + } + + maxLevels = _mesa_max_texture_levels(ctx, target); + if (level < 0 || level >= maxLevels) { + _mesa_error(ctx, GL_INVALID_VALUE, "%s(level = %d)", caller, level); + return true; + } + + err = _mesa_error_check_format_and_type(ctx, format, type); + if (err != GL_NO_ERROR) { + _mesa_error(ctx, err, "%s(format/type)", caller); + return true; + } + + /* According to OpenGL 4.6 spec, section 8.11.4 ("Texture Image Queries"): + * + * "An INVALID_OPERATION error is generated by GetTextureImage if the + * effective target is TEXTURE_CUBE_MAP or TEXTURE_CUBE_MAP_ARRAY , + * and the texture object is not cube complete or cube array complete, + * respectively." + * + * This applies also to GetTextureSubImage, GetCompressedTexImage, + * GetCompressedTextureImage, and GetnCompressedTexImage. + */ + if (target == GL_TEXTURE_CUBE_MAP && !_mesa_cube_complete(texObj)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(cube incomplete)", caller); + return true; + } + + return false; +} + + +/** + * Do error checking for all (non-compressed) get-texture-image functions. + * \return true if any error, false if no errors. + */ +static bool +getteximage_error_check(struct gl_context *ctx, + struct gl_texture_object *texObj, + GLenum target, GLint level, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, GLsizei bufSize, + GLvoid *pixels, const char *caller) +{ + struct gl_texture_image *texImage; + + assert(texObj); + + if (common_error_check(ctx, texObj, target, level, width, height, depth, + format, type, bufSize, pixels, caller)) { + return true; + } + + if (width == 0 || height == 0 || depth == 0) { + /* Not an error, but nothing to do. Return 'true' so that the + * caller simply returns. + */ + return true; + } + + if (pbo_error_check(ctx, target, width, height, depth, + format, type, bufSize, pixels, caller)) { + return true; + } + + texImage = select_tex_image(texObj, target, level, 0); + if (teximage_error_check(ctx, texImage, format, caller)) { + return true; + } + + return false; +} + + +/** + * Do error checking for all (non-compressed) get-texture-image functions. + * \return true if any error, false if no errors. + */ +static bool +gettexsubimage_error_check(struct gl_context *ctx, + struct gl_texture_object *texObj, + GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLsizei width, GLsizei height, GLsizei depth, + GLenum format, GLenum type, GLsizei bufSize, + GLvoid *pixels, const char *caller) +{ + struct gl_texture_image *texImage; + + assert(texObj); + + if (common_error_check(ctx, texObj, target, level, width, height, depth, + format, type, bufSize, pixels, caller)) { + return true; + } + + if (dimensions_error_check(ctx, texObj, target, level, + xoffset, yoffset, zoffset, + width, height, depth, caller)) { + return true; + } + + if (pbo_error_check(ctx, target, width, height, depth, + format, type, bufSize, pixels, caller)) { + return true; + } + + texImage = select_tex_image(texObj, target, level, zoffset); + if (teximage_error_check(ctx, texImage, format, caller)) { + return true; + } + + return false; +} + + /** * Return the width, height and depth of a texture image. * This function must be resilient to bad parameter values since @@ -1344,28 +1445,29 @@ get_texture_image(struct gl_context *ctx, _mesa_unlock_texture(ctx, texObj); } - -void GLAPIENTRY -_mesa_GetnTexImageARB(GLenum target, GLint level, GLenum format, GLenum type, - GLsizei bufSize, GLvoid *pixels) +static void +_get_texture_image(struct gl_context *ctx, + struct gl_texture_object *texObj, + GLenum target, GLint level, + GLenum format, GLenum type, + GLsizei bufSize, GLvoid *pixels, + const char *caller) { - GET_CURRENT_CONTEXT(ctx); - static const char *caller = "glGetnTexImageARB"; GLsizei width, height, depth; - struct gl_texture_object *texObj; + /* EXT/ARB direct_state_access variants don't call _get_texture_image + * with a NULL texObj */ + bool is_dsa = texObj != NULL; - if (!legal_getteximage_target(ctx, target, false)) { - _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller); - return; + if (!is_dsa) { + texObj = _mesa_get_current_tex_object(ctx, target); + assert(texObj); } - texObj = _mesa_get_current_tex_object(ctx, target); - assert(texObj); get_texture_image_dims(texObj, target, level, &width, &height, &depth); if (getteximage_error_check(ctx, texObj, target, level, - 0, 0, 0, width, height, depth, + width, height, depth, format, type, bufSize, pixels, caller)) { return; } @@ -1377,33 +1479,36 @@ _mesa_GetnTexImageARB(GLenum target, GLint level, GLenum format, GLenum type, void GLAPIENTRY -_mesa_GetTexImage(GLenum target, GLint level, GLenum format, GLenum type, - GLvoid *pixels ) +_mesa_GetnTexImageARB(GLenum target, GLint level, GLenum format, GLenum type, + GLsizei bufSize, GLvoid *pixels) { GET_CURRENT_CONTEXT(ctx); - static const char *caller = "glGetTexImage"; - GLsizei width, height, depth; - struct gl_texture_object *texObj; + static const char *caller = "glGetnTexImageARB"; if (!legal_getteximage_target(ctx, target, false)) { _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller); return; } - texObj = _mesa_get_current_tex_object(ctx, target); - assert(texObj); + _get_texture_image(ctx, NULL, target, level, format, type, + bufSize, pixels, caller); +} - get_texture_image_dims(texObj, target, level, &width, &height, &depth); - if (getteximage_error_check(ctx, texObj, target, level, - 0, 0, 0, width, height, depth, - format, type, INT_MAX, pixels, caller)) { +void GLAPIENTRY +_mesa_GetTexImage(GLenum target, GLint level, GLenum format, GLenum type, + GLvoid *pixels ) +{ + GET_CURRENT_CONTEXT(ctx); + static const char *caller = "glGetTexImage"; + + if (!legal_getteximage_target(ctx, target, false)) { + _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller); return; } - get_texture_image(ctx, texObj, target, level, - 0, 0, 0, width, height, depth, - format, type, pixels, caller); + _get_texture_image(ctx, NULL, target, level, format, type, + INT_MAX, pixels, caller); } @@ -1412,7 +1517,6 @@ _mesa_GetTextureImage(GLuint texture, GLint level, GLenum format, GLenum type, GLsizei bufSize, GLvoid *pixels) { GET_CURRENT_CONTEXT(ctx); - GLsizei width, height, depth; static const char *caller = "glGetTextureImage"; struct gl_texture_object *texObj = _mesa_lookup_texture_err(ctx, texture, caller); @@ -1421,12 +1525,69 @@ _mesa_GetTextureImage(GLuint texture, GLint level, GLenum format, GLenum type, return; } + if (!legal_getteximage_target(ctx, texObj->Target, true)) { + _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller); + return; + } + + _get_texture_image(ctx, texObj, texObj->Target, level, format, type, + bufSize, pixels, caller); +} + + +void GLAPIENTRY +_mesa_GetTextureImageEXT(GLuint texture, GLenum target, GLint level, + GLenum format, GLenum type, GLvoid *pixels) +{ + GET_CURRENT_CONTEXT(ctx); + static const char *caller = "glGetTextureImageEXT"; + struct gl_texture_object *texObj = + _mesa_lookup_or_create_texture(ctx, target, texture, + false, true, caller); + + if (!texObj) { + return; + } + + if (!legal_getteximage_target(ctx, target, true)) { + _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller); + return; + } + + _get_texture_image(ctx, texObj, target, level, format, type, + INT_MAX, pixels, caller); +} + + +void GLAPIENTRY +_mesa_GetMultiTexImageEXT(GLenum texunit, GLenum target, GLint level, + GLenum format, GLenum type, GLvoid *pixels) +{ + GET_CURRENT_CONTEXT(ctx); + GLsizei width, height, depth; + static const char *caller = "glGetMultiTexImageEXT"; + + struct gl_texture_object *texObj = + _mesa_get_texobj_by_target_and_texunit(ctx, target, + texunit - GL_TEXTURE0, + false, + caller); + + if (!texObj) { + return; + } + + if (!legal_getteximage_target(ctx, texObj->Target, true)) { + _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller); + return; + } + get_texture_image_dims(texObj, texObj->Target, level, &width, &height, &depth); if (getteximage_error_check(ctx, texObj, texObj->Target, level, - 0, 0, 0, width, height, depth, - format, type, bufSize, pixels, caller)) { + width, height, depth, + format, type, INT_MAX, pixels, caller)) { return; } @@ -1452,9 +1613,16 @@ _mesa_GetTextureSubImage(GLuint texture, GLint level, return; } - if (getteximage_error_check(ctx, texObj, texObj->Target, level, - xoffset, yoffset, zoffset, width, height, depth, - format, type, bufSize, pixels, caller)) { + if (!legal_getteximage_target(ctx, texObj->Target, true)) { + _mesa_error(ctx, GL_INVALID_OPERATION, + "%s(buffer/multisample texture)", caller); + return; + } + + if (gettexsubimage_error_check(ctx, texObj, texObj->Target, level, + xoffset, yoffset, zoffset, + width, height, depth, + format, type, bufSize, pixels, caller)) { return; } @@ -1551,7 +1719,7 @@ getcompressedteximage_error_check(struct gl_context *ctx, &ctx->Pack); /* Do dest buffer bounds checking */ - if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { + if (ctx->Pack.BufferObj) { /* do bounds checking on PBO write */ if ((GLubyte *) pixels + totalBytes > (GLubyte *) ctx->Pack.BufferObj->Size) { @@ -1576,7 +1744,7 @@ getcompressedteximage_error_check(struct gl_context *ctx, } } - if (!_mesa_is_bufferobj(ctx->Pack.BufferObj) && !pixels) { + if (!ctx->Pack.BufferObj && !pixels) { /* not an error, but do nothing */ return true; } @@ -1642,9 +1810,9 @@ get_compressed_texture_image(struct gl_context *ctx, texImage = texObj->Image[firstFace + i][level]; assert(texImage); - ctx->Driver.GetCompressedTexSubImage(ctx, texImage, - xoffset, yoffset, zoffset, - width, height, depth, pixels); + get_compressed_texsubimage_sw(ctx, texImage, + xoffset, yoffset, zoffset, + width, height, depth, pixels); /* next cube face */ pixels = (GLubyte *) pixels + imageStride; @@ -1716,6 +1884,62 @@ _mesa_GetCompressedTexImage(GLenum target, GLint level, GLvoid *pixels) } +void GLAPIENTRY +_mesa_GetCompressedTextureImageEXT(GLuint texture, GLenum target, GLint level, + GLvoid *pixels) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_texture_object* texObj; + GLsizei width, height, depth; + static const char *caller = "glGetCompressedTextureImageEXT"; + + texObj = _mesa_lookup_or_create_texture(ctx, target, texture, + false, true, caller); + + get_texture_image_dims(texObj, texObj->Target, level, + &width, &height, &depth); + + if (getcompressedteximage_error_check(ctx, texObj, texObj->Target, level, + 0, 0, 0, width, height, depth, + INT_MAX, pixels, caller)) { + return; + } + + get_compressed_texture_image(ctx, texObj, texObj->Target, level, + 0, 0, 0, width, height, depth, + pixels, caller); +} + + +void GLAPIENTRY +_mesa_GetCompressedMultiTexImageEXT(GLenum texunit, GLenum target, GLint level, + GLvoid *pixels) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_texture_object* texObj; + GLsizei width, height, depth; + static const char *caller = "glGetCompressedMultiTexImageEXT"; + + texObj = _mesa_get_texobj_by_target_and_texunit(ctx, target, + texunit - GL_TEXTURE0, + false, + caller); + + get_texture_image_dims(texObj, texObj->Target, level, + &width, &height, &depth); + + if (getcompressedteximage_error_check(ctx, texObj, texObj->Target, level, + 0, 0, 0, width, height, depth, + INT_MAX, pixels, caller)) { + return; + } + + get_compressed_texture_image(ctx, texObj, texObj->Target, level, + 0, 0, 0, width, height, depth, + pixels, caller); +} + + void GLAPIENTRY _mesa_GetCompressedTextureImage(GLuint texture, GLint level, GLsizei bufSize, GLvoid *pixels) @@ -1745,7 +1969,7 @@ _mesa_GetCompressedTextureImage(GLuint texture, GLint level, } -void APIENTRY +void GLAPIENTRY _mesa_GetCompressedTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, @@ -1754,7 +1978,7 @@ _mesa_GetCompressedTextureSubImage(GLuint texture, GLint level, { GET_CURRENT_CONTEXT(ctx); static const char *caller = "glGetCompressedTextureImage"; - struct gl_texture_object *texObj; + struct gl_texture_object *texObj = NULL; texObj = _mesa_lookup_texture_err(ctx, texture, caller); if (!texObj) {