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;
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;
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);
}
{
GLint img, row;
- assert(zoffset + depth <= texImage->Depth);
for (img = 0; img < depth; img++) {
GLubyte *srcMap;
GLint rowstride;
}
}
+/**
+ * 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.
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;
}
}
- /* 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);
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;
}
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);
*/
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;
+ }
}
}
/* If we had to rebase, we have already handled that */
needsRebase = false;
- /* If we were lucky and our RGBA conversion matches the dst format, then
- * we are done.
+ /* If we were lucky and our RGBA conversion matches the dst format,
+ * then we are done.
*/
if (!need_convert)
goto do_swap;
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);
}
texBaseFormat == texImage->_BaseFormat) {
memCopy = _mesa_format_matches_format_and_type(texImage->TexFormat,
format, type,
- ctx->Pack.SwapBytes);
+ ctx->Pack.SwapBytes, NULL);
}
if (depth > 1) {
/* only a single slice is supported at this time */
- memCopy = FALSE;
+ memCopy = GL_FALSE;
}
if (memCopy) {
if (src) {
if (bytesPerRow == dstRowStride && bytesPerRow == srcRowStride) {
- memcpy(dst, src, bytesPerRow * texImage->Height);
+ memcpy(dst, src, bytesPerRow * height);
}
else {
GLuint row;
_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.
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 */
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);
}
}
/**
- * This is the software fallback for Driver.GetCompressedTexImage().
- * All error checking will have been done before this routine is called.
+ * This function assumes that all error checking has been done.
*/
-void
-_mesa_GetCompressedTexImage_sw(struct gl_context *ctx,
- struct gl_texture_image *texImage,
- 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);
GLubyte *dest;
_mesa_compute_compressed_pixelstore(dimensions, texImage->TexFormat,
- texImage->Width, texImage->Height,
- texImage->Depth,
- &ctx->Pack,
- &store);
+ 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,
GLubyte *src;
/* map src texture buffer */
- ctx->Driver.MapTextureImage(ctx, texImage, slice,
- 0, 0, texImage->Width, texImage->Height,
+ ctx->Driver.MapTextureImage(ctx, texImage, zoffset + slice,
+ xoffset, yoffset, width, height,
GL_MAP_READ_BIT, &src, &srcRowStride);
if (src) {
src += srcRowStride;
}
- ctx->Driver.UnmapTextureImage(ctx, texImage, slice);
+ ctx->Driver.UnmapTextureImage(ctx, texImage, zoffset + slice);
/* Advance to next slice */
- dest += store.TotalBytesPerRow * (store.TotalRowsPerSlice - store.CopyRowsPerSlice);
+ dest += store.TotalBytesPerRow * (store.TotalRowsPerSlice -
+ store.CopyRowsPerSlice);
} else {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetCompresssedTexImage");
}
}
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+ if (ctx->Pack.BufferObj) {
ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj, MAP_INTERNAL);
}
}
* 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;
/**
- * Do error checking for a glGetTex(ture)Image() call.
- * \return GL_TRUE if any error, GL_FALSE if no errors.
+ * Wrapper for _mesa_select_tex_image() which can handle target being
+ * GL_TEXTURE_CUBE_MAP in which case we use zoffset to select a cube face.
+ * This can happen for glGetTextureImage and glGetTextureSubImage (DSA
+ * functions).
*/
-static GLboolean
-getteximage_error_check(struct gl_context *ctx,
- struct gl_texture_image *texImage,
- GLenum target, GLint level,
- GLenum format, GLenum type, GLsizei clientMemSize,
- GLvoid *pixels, bool dsa)
+static struct gl_texture_image *
+select_tex_image(const struct gl_texture_object *texObj, GLenum target,
+ GLint level, GLint zoffset)
{
- const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
- const GLuint dimensions = (target == GL_TEXTURE_3D) ? 3 : 2;
- GLenum baseFormat;
- const char *suffix = dsa ? "ture" : "";
+ assert(level >= 0);
+ assert(level < MAX_TEXTURE_LEVELS);
+ if (target == GL_TEXTURE_CUBE_MAP) {
+ assert(zoffset >= 0);
+ assert(zoffset < 6);
+ target = GL_TEXTURE_CUBE_MAP_POSITIVE_X + zoffset;
+ }
+ return _mesa_select_tex_image(texObj, target, level);
+}
- assert(texImage);
- assert(maxLevels != 0);
- if (level < 0 || level >= maxLevels) {
+
+/**
+ * Error-check the offset and size arguments to
+ * glGet[Compressed]TextureSubImage().
+ * \return true if error, false if no error.
+ */
+static bool
+dimensions_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,
+ const char *caller)
+{
+ const struct gl_texture_image *texImage;
+ GLuint imageWidth = 0, imageHeight = 0, imageDepth = 0;
+
+ if (xoffset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(xoffset = %d)", caller, xoffset);
+ return true;
+ }
+
+ if (yoffset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(yoffset = %d)", caller, yoffset);
+ return true;
+ }
+
+ if (zoffset < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(zoffset = %d)", caller, zoffset);
+ return true;
+ }
+
+ if (width < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(width = %d)", caller, width);
+ return true;
+ }
+
+ if (height < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(height = %d)", caller, height);
+ return true;
+ }
+
+ if (depth < 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE, "%s(depth = %d)", caller, depth);
+ return true;
+ }
+
+ /* do special per-target checks */
+ switch (target) {
+ case GL_TEXTURE_1D:
+ if (yoffset != 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(1D, yoffset = %d)", caller, yoffset);
+ return true;
+ }
+ if (height != 1) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(1D, height = %d)", caller, height);
+ return true;
+ }
+ /* fall-through */
+ case GL_TEXTURE_1D_ARRAY:
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_RECTANGLE:
+ if (zoffset != 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(zoffset = %d)", caller, zoffset);
+ return true;
+ }
+ if (depth != 1) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(depth = %d)", caller, depth);
+ return true;
+ }
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ /* Non-array cube maps are special because we have a gl_texture_image
+ * per face.
+ */
+ if (zoffset + depth > 6) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(zoffset + depth = %d)", caller, zoffset + depth);
+ return true;
+ }
+ break;
+ default:
+ ; /* nothing */
+ }
+
+ texImage = select_tex_image(texObj, target, level, zoffset);
+ if (texImage) {
+ imageWidth = texImage->Width;
+ imageHeight = texImage->Height;
+ imageDepth = texImage->Depth;
+ }
+
+ if (xoffset + width > imageWidth) {
_mesa_error(ctx, GL_INVALID_VALUE,
- "glGetTex%sImage(level out of range)", suffix);
- return GL_TRUE;
+ "%s(xoffset %d + width %d > %u)",
+ caller, xoffset, width, imageWidth);
+ return true;
+ }
+
+ if (yoffset + height > imageHeight) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(yoffset %d + height %d > %u)",
+ caller, yoffset, height, imageHeight);
+ return true;
+ }
+
+ if (target != GL_TEXTURE_CUBE_MAP) {
+ /* Cube map error checking was done above */
+ if (zoffset + depth > imageDepth) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(zoffset %d + depth %d > %u)",
+ caller, zoffset, depth, imageDepth);
+ return true;
+ }
+ }
+
+ /* Extra checks for compressed textures */
+ 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,
+ "%s(xoffset = %d)", caller, xoffset);
+ return true;
+ }
+ if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) {
+ if (yoffset % bh != 0) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(yoffset = %d)", caller, yoffset);
+ return true;
+ }
+ }
+
+ 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) &&
+ (xoffset + width != (GLint) texImage->Width)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%s(width = %d)", caller, width);
+ return true;
+ }
+
+ if ((height % bh != 0) &&
+ (yoffset + height != (GLint) texImage->Height)) {
+ _mesa_error(ctx, GL_INVALID_VALUE,
+ "%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;
+ }
+ }
+ }
+
+ if (width == 0 || height == 0 || depth == 0) {
+ /* Not an error, but nothing to do. Return 'true' so that the
+ * caller simply returns.
+ */
+ return true;
+ }
+
+ return false;
+}
+
+
+/**
+ * Do PBO-related error checking for getting uncompressed images.
+ * \return true if there was an error (or the GetTexImage is to be a no-op)
+ */
+static bool
+pbo_error_check(struct gl_context *ctx, GLenum target,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, GLsizei clientMemSize,
+ GLvoid *pixels,
+ const char *caller)
+{
+ const GLuint dimensions = (target == GL_TEXTURE_3D) ? 3 : 2;
+
+ if (!_mesa_validate_pbo_access(dimensions, &ctx->Pack, width, height, depth,
+ format, type, clientMemSize, pixels)) {
+ if (ctx->Pack.BufferObj) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(out of bounds PBO access)", caller);
+ } else {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(out of bounds access: bufSize (%d) is too small)",
+ caller, clientMemSize);
+ }
+ return true;
+ }
+
+ if (ctx->Pack.BufferObj) {
+ /* PBO should not be mapped */
+ if (_mesa_check_disallowed_mapping(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(PBO is mapped)", caller);
+ return true;
+ }
+ }
+
+ if (!ctx->Pack.BufferObj && !pixels) {
+ /* not an error, do nothing */
+ return true;
}
+ return false;
+}
+
+
+/**
+ * Do teximage-related error checking for getting uncompressed images.
+ * \return true if there was an error
+ */
+static bool
+teximage_error_check(struct gl_context *ctx,
+ struct gl_texture_image *texImage,
+ GLenum format, const char *caller)
+{
+ GLenum baseFormat;
+ assert(texImage);
+
/*
* Format and type checking has been moved up to GetnTexImage and
* GetTextureImage so that it happens before getting the texImage object.
if (_mesa_is_color_format(format)
&& !_mesa_is_color_format(baseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTex%sImage(format mismatch)", suffix);
- return GL_TRUE;
+ "%s(format mismatch)", caller);
+ return true;
}
else if (_mesa_is_depth_format(format)
&& !_mesa_is_depth_format(baseFormat)
&& !_mesa_is_depthstencil_format(baseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTex%sImage(format mismatch)", suffix);
- return GL_TRUE;
+ "%s(format mismatch)", caller);
+ return true;
}
else if (_mesa_is_stencil_format(format)
&& !ctx->Extensions.ARB_texture_stencil8) {
_mesa_error(ctx, GL_INVALID_ENUM,
- "glGetTex%sImage(format=GL_STENCIL_INDEX)", suffix);
- return GL_TRUE;
+ "%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,
- "glGetTex%sImage(format mismatch)", suffix);
- return GL_TRUE;
+ "%s(format mismatch)", caller);
+ return true;
}
else if (_mesa_is_depthstencil_format(format)
&& !_mesa_is_depthstencil_format(baseFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTex%sImage(format mismatch)", suffix);
- return GL_TRUE;
+ "%s(format mismatch)", caller);
+ return true;
}
- else if (!_mesa_is_stencil_format(format) && _mesa_is_enum_format_integer(format) !=
+ else if (!_mesa_is_stencil_format(format) &&
+ _mesa_is_enum_format_integer(format) !=
_mesa_is_format_integer(texImage->TexFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTex%sImage(format mismatch)", suffix);
- return GL_TRUE;
+ "%s(format mismatch)", caller);
+ return true;
}
- if (!_mesa_validate_pbo_access(dimensions, &ctx->Pack, texImage->Width,
- texImage->Height, texImage->Depth,
- format, type, clientMemSize, pixels)) {
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTex%sImage(out of bounds PBO access)", suffix);
- } else {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(out of bounds access:"
- " bufSize (%d) is too small)",
- dsa ? "glGetTextureImage" : "glGetnTexImageARB",
- clientMemSize);
- }
- return GL_TRUE;
+ return false;
+}
+
+
+/**
+ * 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;
}
- if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- /* PBO should not be mapped */
- if (_mesa_check_disallowed_mapping(ctx->Pack.BufferObj)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTex%sImage(PBO is mapped)", suffix);
- return GL_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 GL_FALSE;
+ return false;
}
/**
- * This is the implementation for glGetnTexImageARB, glGetTextureImage,
- * and glGetTexImage.
- *
- * Requires caller to pass in texImage object because _mesa_GetTextureImage
- * must handle the GL_TEXTURE_CUBE_MAP target.
- *
- * \param target texture target.
- * \param level image level.
- * \param format pixel data format for returned image.
- * \param type pixel data type for returned image.
- * \param bufSize size of the pixels data buffer.
- * \param pixels returned pixel data.
- * \param dsa True when the caller is an ARB_direct_state_access function,
- * false otherwise
+ * Do error checking for all (non-compressed) get-texture-image functions.
+ * \return true if any error, false if no errors.
*/
-static void
-get_texture_image(struct gl_context *ctx,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage, GLenum target,
- GLint level, GLenum format, GLenum type,
- GLsizei bufSize, GLvoid *pixels, bool dsa)
+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);
- assert(texImage);
- FLUSH_VERTICES(ctx, 0);
+ if (common_error_check(ctx, texObj, target, level, width, height, depth,
+ format, type, bufSize, pixels, caller)) {
+ return true;
+ }
- /*
- * Legal target checking has been moved up to GetnTexImage and
- * GetTextureImage so that it can be caught before receiving a NULL
- * texImage object and exiting.
- */
+ 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 (getteximage_error_check(ctx, texImage, target, level, format,
- type, bufSize, pixels, dsa)) {
- return;
+ if (pbo_error_check(ctx, target, width, height, depth,
+ format, type, bufSize, pixels, caller)) {
+ return true;
}
- if (!_mesa_is_bufferobj(ctx->Pack.BufferObj) && !pixels) {
- /* not an error, do nothing */
- return;
+ texImage = select_tex_image(texObj, target, level, 0);
+ if (teximage_error_check(ctx, texImage, format, caller)) {
+ return true;
}
- if (_mesa_is_zero_size_texture(texImage))
- return;
+ return false;
+}
- if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
- _mesa_debug(ctx, "glGetTex%sImage(tex %u) format = %s, w=%d, h=%d,"
- " dstFmt=0x%x, dstType=0x%x\n",
- dsa ? "ture": "",
- texObj->Name,
- _mesa_get_format_name(texImage->TexFormat),
- texImage->Width, texImage->Height,
- format, type);
+
+/**
+ * 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;
}
- _mesa_lock_texture(ctx, texObj);
- {
- ctx->Driver.GetTexSubImage(ctx, 0, 0, 0,
- texImage->Width, texImage->Height,
- texImage->Depth,
- format, type, pixels, texImage);
+ if (dimensions_error_check(ctx, texObj, target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth, caller)) {
+ return true;
}
- _mesa_unlock_texture(ctx, texObj);
+
+ 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;
}
+
/**
- * Get texture image. Called by glGetTexImage.
- *
- * \param target texture target.
+ * Return the width, height and depth of a texture image.
+ * This function must be resilient to bad parameter values since
+ * this is called before full error checking.
+ */
+static void
+get_texture_image_dims(const struct gl_texture_object *texObj,
+ GLenum target, GLint level,
+ GLsizei *width, GLsizei *height, GLsizei *depth)
+{
+ const struct gl_texture_image *texImage = NULL;
+
+ if (level >= 0 && level < MAX_TEXTURE_LEVELS) {
+ texImage = _mesa_select_tex_image(texObj, target, level);
+ }
+
+ if (texImage) {
+ *width = texImage->Width;
+ *height = texImage->Height;
+ if (target == GL_TEXTURE_CUBE_MAP) {
+ *depth = 6;
+ }
+ else {
+ *depth = texImage->Depth;
+ }
+ }
+ else {
+ *width = *height = *depth = 0;
+ }
+}
+
+
+/**
+ * Common code for all (uncompressed) get-texture-image functions.
+ * \param texObj the texture object (should not be null)
+ * \param target user-provided target, or 0 for DSA
* \param level image level.
* \param format pixel data format for returned image.
* \param type pixel data type for returned image.
* \param bufSize size of the pixels data buffer.
* \param pixels returned pixel data.
+ * \param caller name of calling function
*/
-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,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLint depth,
+ GLenum format, GLenum type,
+ GLvoid *pixels, const char *caller)
{
- struct gl_texture_object *texObj;
struct gl_texture_image *texImage;
- GLenum err;
+ unsigned firstFace, numFaces, i;
+ GLint imageStride;
+
+ FLUSH_VERTICES(ctx, 0);
+
+ texImage = select_tex_image(texObj, target, level, zoffset);
+ assert(texImage); /* should have been error checked already */
+
+ if (_mesa_is_zero_size_texture(texImage)) {
+ /* no image data to return */
+ return;
+ }
+
+ if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
+ _mesa_debug(ctx, "%s(tex %u) format = %s, w=%d, h=%d,"
+ " dstFmt=0x%x, dstType=0x%x\n",
+ caller, texObj->Name,
+ _mesa_get_format_name(texImage->TexFormat),
+ texImage->Width, texImage->Height,
+ format, type);
+ }
+
+ if (target == GL_TEXTURE_CUBE_MAP) {
+ /* Compute stride between cube faces */
+ imageStride = _mesa_image_image_stride(&ctx->Pack, width, height,
+ format, type);
+ firstFace = zoffset;
+ numFaces = depth;
+ zoffset = 0;
+ depth = 1;
+ }
+ else {
+ imageStride = 0;
+ firstFace = _mesa_tex_target_to_face(target);
+ numFaces = 1;
+ }
+
+ _mesa_lock_texture(ctx, texObj);
+
+ for (i = 0; i < numFaces; i++) {
+ texImage = texObj->Image[firstFace + i][level];
+ assert(texImage);
+
+ ctx->Driver.GetTexSubImage(ctx, xoffset, yoffset, zoffset,
+ width, height, depth,
+ format, type, pixels, texImage);
+
+ /* next cube face */
+ pixels = (GLubyte *) pixels + imageStride;
+ }
+
+ _mesa_unlock_texture(ctx, texObj);
+}
+
+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)
+{
+ GLsizei width, height, depth;
+ /* EXT/ARB direct_state_access variants don't call _get_texture_image
+ * with a NULL texObj */
+ bool is_dsa = texObj != NULL;
+
+ if (!is_dsa) {
+ 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,
+ width, height, depth,
+ format, type, bufSize, pixels, caller)) {
+ return;
+ }
+
+ get_texture_image(ctx, texObj, target, level,
+ 0, 0, 0, width, height, depth,
+ format, type, pixels, caller);
+}
+
+
+void GLAPIENTRY
+_mesa_GetnTexImageARB(GLenum target, GLint level, GLenum format, GLenum type,
+ GLsizei bufSize, GLvoid *pixels)
+{
GET_CURRENT_CONTEXT(ctx);
+ static const char *caller = "glGetnTexImageARB";
- /*
- * This has been moved here because a format/type mismatch can cause a NULL
- * texImage object, which in turn causes the mismatch error to be
- * ignored.
- */
- err = _mesa_error_check_format_and_type(ctx, format, type);
- if (err != GL_NO_ERROR) {
- _mesa_error(ctx, err, "glGetnTexImage(format/type)");
+ if (!legal_getteximage_target(ctx, target, false)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller);
return;
}
- /*
- * Legal target checking has been moved here to prevent exiting with a NULL
- * texImage object.
- */
+ _get_texture_image(ctx, NULL, target, level, format, type,
+ bufSize, 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, "glGetnTexImage(target=0x%x)",
- target);
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller);
return;
}
- texObj = _mesa_get_current_tex_object(ctx, target);
- if (!texObj)
+ _get_texture_image(ctx, NULL, target, level, format, type,
+ INT_MAX, pixels, caller);
+}
+
+
+void GLAPIENTRY
+_mesa_GetTextureImage(GLuint texture, GLint level, GLenum format, GLenum type,
+ GLsizei bufSize, GLvoid *pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ static const char *caller = "glGetTextureImage";
+ struct gl_texture_object *texObj =
+ _mesa_lookup_texture_err(ctx, texture, caller);
+
+ if (!texObj) {
return;
+ }
- texImage = _mesa_select_tex_image(texObj, target, level);
- if (!texImage)
+ if (!legal_getteximage_target(ctx, texObj->Target, true)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
return;
+ }
- get_texture_image(ctx, texObj, texImage, target, level, format, type,
- bufSize, pixels, false);
+ _get_texture_image(ctx, texObj, texObj->Target, level, format, type,
+ bufSize, pixels, caller);
}
void GLAPIENTRY
-_mesa_GetTexImage( GLenum target, GLint level, GLenum format,
- GLenum type, GLvoid *pixels )
+_mesa_GetTextureImageEXT(GLuint texture, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid *pixels)
{
- _mesa_GetnTexImageARB(target, level, format, type, INT_MAX, 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);
}
-/**
- * Get texture image.
- *
- * \param texture texture name.
- * \param level image level.
- * \param format pixel data format for returned image.
- * \param type pixel data type for returned image.
- * \param bufSize size of the pixels data buffer.
- * \param pixels returned pixel data.
- */
+
void GLAPIENTRY
-_mesa_GetTextureImage(GLuint texture, GLint level, GLenum format,
- GLenum type, GLsizei bufSize, GLvoid *pixels)
+_mesa_GetMultiTexImageEXT(GLenum texunit, GLenum target, GLint level,
+ GLenum format, GLenum type, GLvoid *pixels)
{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- int i;
- GLint image_stride;
- GLenum err;
GET_CURRENT_CONTEXT(ctx);
+ GLsizei width, height, depth;
+ static const char *caller = "glGetMultiTexImageEXT";
- /*
- * This has been moved here because a format/type mismatch can cause a NULL
- * texImage object, which in turn causes the mismatch error to be
- * ignored.
- */
- err = _mesa_error_check_format_and_type(ctx, format, type);
- if (err != GL_NO_ERROR) {
- _mesa_error(ctx, err, "glGetTextureImage(format/type)");
+ struct gl_texture_object *texObj =
+ _mesa_get_texobj_by_target_and_texunit(ctx, target,
+ texunit - GL_TEXTURE0,
+ false,
+ caller);
+
+ if (!texObj) {
return;
}
- texObj = _mesa_lookup_texture_err(ctx, texture, "glGetTextureImage");
- if (!texObj)
+ if (!legal_getteximage_target(ctx, texObj->Target, true)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s", caller);
return;
+ }
- /*
- * Legal target checking has been moved here to prevent exiting with a NULL
- * texImage object.
- */
- if (!legal_getteximage_target(ctx, texObj->Target, true)) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetTextureImage(target=%s)",
- _mesa_enum_to_string(texObj->Target));
+ get_texture_image_dims(texObj, texObj->Target, level,
+ &width, &height, &depth);
+
+ if (getteximage_error_check(ctx, texObj, texObj->Target, level,
+ width, height, depth,
+ format, type, INT_MAX, pixels, caller)) {
return;
}
- /* Must handle special case GL_TEXTURE_CUBE_MAP. */
- if (texObj->Target == GL_TEXTURE_CUBE_MAP) {
+ get_texture_image(ctx, texObj, texObj->Target, level,
+ 0, 0, 0, width, height, depth,
+ format, type, pixels, caller);
+}
- /* Make sure the texture object is a proper cube.
- * (See texturesubimage in teximage.c for details on why this check is
- * performed.)
- */
- if (!_mesa_cube_level_complete(texObj, level)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetTextureImage(cube map incomplete)");
- return;
- }
- /* Copy each face. */
- for (i = 0; i < 6; ++i) {
- texImage = texObj->Image[i][level];
- assert(texImage);
+void GLAPIENTRY
+_mesa_GetTextureSubImage(GLuint texture, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLenum format, GLenum type, GLsizei bufSize,
+ void *pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ static const char *caller = "glGetTextureSubImage";
+ struct gl_texture_object *texObj =
+ _mesa_lookup_texture_err(ctx, texture, caller);
- get_texture_image(ctx, texObj, texImage, texObj->Target, level,
- format, type, bufSize, pixels, true);
+ if (!texObj) {
+ return;
+ }
- image_stride = _mesa_image_image_stride(&ctx->Pack, texImage->Width,
- texImage->Height, format,
- type);
- pixels = (GLubyte *) pixels + image_stride;
- bufSize -= image_stride;
- }
+ if (!legal_getteximage_target(ctx, texObj->Target, true)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(buffer/multisample texture)", caller);
+ return;
}
- else {
- texImage = _mesa_select_tex_image(texObj, texObj->Target, level);
- if (!texImage)
- return;
- get_texture_image(ctx, texObj, texImage, texObj->Target, level,
- format, type, bufSize, pixels, true);
+ if (gettexsubimage_error_check(ctx, texObj, texObj->Target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth,
+ format, type, bufSize, pixels, caller)) {
+ return;
}
+
+ get_texture_image(ctx, texObj, texObj->Target, level,
+ xoffset, yoffset, zoffset, width, height, depth,
+ format, type, pixels, caller);
}
+
+
/**
- * Do error checking for a glGetCompressedTexImage() call.
- * \return GL_TRUE if any error, GL_FALSE if no errors.
+ * Compute the number of bytes which will be written when retrieving
+ * a sub-region of a compressed texture.
*/
-static GLboolean
+static GLsizei
+packed_compressed_size(GLuint dimensions, mesa_format format,
+ GLsizei width, GLsizei height, GLsizei depth,
+ const struct gl_pixelstore_attrib *packing)
+{
+ struct compressed_pixelstore st;
+ GLsizei totalBytes;
+
+ _mesa_compute_compressed_pixelstore(dimensions, format,
+ width, height, depth,
+ packing, &st);
+ totalBytes =
+ (st.CopySlices - 1) * st.TotalRowsPerSlice * st.TotalBytesPerRow +
+ st.SkipBytes +
+ (st.CopyRowsPerSlice - 1) * st.TotalBytesPerRow +
+ st.CopyBytesPerRow;
+
+ return totalBytes;
+}
+
+
+/**
+ * Do error checking for getting compressed texture images.
+ * \return true if any error, false if no errors.
+ */
+static bool
getcompressedteximage_error_check(struct gl_context *ctx,
- struct gl_texture_image *texImage,
- GLenum target,
- GLint level, GLsizei clientMemSize,
- GLvoid *img, bool dsa)
+ struct gl_texture_object *texObj,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth,
+ GLsizei bufSize, GLvoid *pixels,
+ const char *caller)
{
- const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
- GLuint compressedSize, dimensions;
- const char *suffix = dsa ? "ture" : "";
+ struct gl_texture_image *texImage;
+ GLint maxLevels;
+ GLsizei totalBytes;
+ GLuint dimensions;
- assert(texImage);
+ assert(texObj);
- if (!legal_getteximage_target(ctx, target, dsa)) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetCompressedTex%sImage(target=%s)", suffix,
- _mesa_enum_to_string(target));
- return GL_TRUE;
+ if (texObj->Target == 0) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid texture)", caller);
+ return true;
}
- assert(maxLevels != 0);
+ maxLevels = _mesa_max_texture_levels(ctx, target);
if (level < 0 || level >= maxLevels) {
_mesa_error(ctx, GL_INVALID_VALUE,
- "glGetCompressedTex%sImage(bad level = %d)", suffix, level);
- return GL_TRUE;
+ "%s(bad level = %d)", caller, level);
+ return true;
+ }
+
+ if (dimensions_error_check(ctx, texObj, target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth, caller)) {
+ return true;
}
+ texImage = select_tex_image(texObj, target, level, zoffset);
+ assert(texImage);
+
if (!_mesa_is_format_compressed(texImage->TexFormat)) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetCompressedTex%sImage(texture is not compressed)",
- suffix);
- return GL_TRUE;
+ "%s(texture is not compressed)", caller);
+ return true;
}
- compressedSize = _mesa_format_image_size(texImage->TexFormat,
- texImage->Width,
- texImage->Height,
- texImage->Depth);
-
/* Check for invalid pixel storage modes */
- dimensions = _mesa_get_texture_dimensions(texImage->TexObject->Target);
+ dimensions = _mesa_get_texture_dimensions(texObj->Target);
if (!_mesa_compressed_pixel_storage_error_check(ctx, dimensions,
- &ctx->Pack, dsa ?
- "glGetCompressedTextureImage":
- "glGetCompressedTexImage")) {
- return GL_TRUE;
+ &ctx->Pack,
+ caller)) {
+ return true;
}
- if (!_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
- /* do bounds checking on writing to client memory */
- if (clientMemSize < (GLsizei) compressedSize) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "%s(out of bounds access: bufSize (%d) is too small)",
- dsa ? "glGetCompressedTextureImage" :
- "glGetnCompressedTexImageARB", clientMemSize);
- return GL_TRUE;
- }
- } else {
+ /* Compute number of bytes that may be touched in the dest buffer */
+ totalBytes = packed_compressed_size(dimensions, texImage->TexFormat,
+ width, height, depth,
+ &ctx->Pack);
+
+ /* Do dest buffer bounds checking */
+ if (ctx->Pack.BufferObj) {
/* do bounds checking on PBO write */
- if ((const GLubyte *) img + compressedSize >
- (const GLubyte *) ctx->Pack.BufferObj->Size) {
+ if ((GLubyte *) pixels + totalBytes >
+ (GLubyte *) ctx->Pack.BufferObj->Size) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetCompressedTex%sImage(out of bounds PBO access)",
- suffix);
- return GL_TRUE;
+ "%s(out of bounds PBO access)", caller);
+ return true;
}
/* make sure PBO is not mapped */
if (_mesa_check_disallowed_mapping(ctx->Pack.BufferObj)) {
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(PBO is mapped)", caller);
+ return true;
+ }
+ }
+ else {
+ /* do bounds checking on writing to client memory */
+ if (totalBytes > bufSize) {
_mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetCompressedTex%sImage(PBO is mapped)", suffix);
- return GL_TRUE;
+ "%s(out of bounds access: bufSize (%d) is too small)",
+ caller, bufSize);
+ return true;
}
}
- return GL_FALSE;
+ if (!ctx->Pack.BufferObj && !pixels) {
+ /* not an error, but do nothing */
+ return true;
+ }
+
+ return false;
}
-/** Implements glGetnCompressedTexImageARB, glGetCompressedTexImage, and
- * glGetCompressedTextureImage.
- *
- * texImage must be passed in because glGetCompressedTexImage must handle the
- * target GL_TEXTURE_CUBE_MAP.
+
+/**
+ * Common helper for all glGetCompressed-teximage functions.
*/
-void
-_mesa_get_compressed_texture_image(struct gl_context *ctx,
- struct gl_texture_object *texObj,
- struct gl_texture_image *texImage,
- GLenum target, GLint level,
- GLsizei bufSize, GLvoid *pixels,
- bool dsa)
+static void
+get_compressed_texture_image(struct gl_context *ctx,
+ struct gl_texture_object *texObj,
+ GLenum target, GLint level,
+ GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLint depth,
+ GLvoid *pixels,
+ const char *caller)
{
- assert(texObj);
- assert(texImage);
+ struct gl_texture_image *texImage;
+ unsigned firstFace, numFaces, i, imageStride;
FLUSH_VERTICES(ctx, 0);
- if (getcompressedteximage_error_check(ctx, texImage, target, level,
- bufSize, pixels, dsa)) {
- return;
- }
-
- if (!_mesa_is_bufferobj(ctx->Pack.BufferObj) && !pixels) {
- /* not an error, do nothing */
- return;
- }
+ texImage = select_tex_image(texObj, target, level, zoffset);
+ assert(texImage); /* should have been error checked already */
if (_mesa_is_zero_size_texture(texImage))
return;
if (MESA_VERBOSE & (VERBOSE_API | VERBOSE_TEXTURE)) {
_mesa_debug(ctx,
- "glGetCompressedTex%sImage(tex %u) format = %s, w=%d, h=%d\n",
- dsa ? "ture" : "", texObj->Name,
+ "%s(tex %u) format = %s, w=%d, h=%d\n",
+ caller, texObj->Name,
_mesa_get_format_name(texImage->TexFormat),
texImage->Width, texImage->Height);
}
+ if (target == GL_TEXTURE_CUBE_MAP) {
+ struct compressed_pixelstore store;
+
+ /* Compute image stride between cube faces */
+ _mesa_compute_compressed_pixelstore(2, texImage->TexFormat,
+ width, height, depth,
+ &ctx->Pack, &store);
+ imageStride = store.TotalBytesPerRow * store.TotalRowsPerSlice;
+
+ firstFace = zoffset;
+ numFaces = depth;
+ zoffset = 0;
+ depth = 1;
+ }
+ else {
+ imageStride = 0;
+ firstFace = _mesa_tex_target_to_face(target);
+ numFaces = 1;
+ }
+
_mesa_lock_texture(ctx, texObj);
- {
- ctx->Driver.GetCompressedTexImage(ctx, texImage, pixels);
+
+ for (i = 0; i < numFaces; i++) {
+ texImage = texObj->Image[firstFace + i][level];
+ assert(texImage);
+
+ get_compressed_texsubimage_sw(ctx, texImage,
+ xoffset, yoffset, zoffset,
+ width, height, depth, pixels);
+
+ /* next cube face */
+ pixels = (GLubyte *) pixels + imageStride;
}
+
_mesa_unlock_texture(ctx, texObj);
}
+
void GLAPIENTRY
_mesa_GetnCompressedTexImageARB(GLenum target, GLint level, GLsizei bufSize,
- GLvoid *img)
+ GLvoid *pixels)
{
+ GET_CURRENT_CONTEXT(ctx);
+ static const char *caller = "glGetnCompressedTexImageARB";
+ GLsizei width, height, depth;
struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
+
+ 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_dims(texObj, target, level, &width, &height, &depth);
+
+ if (getcompressedteximage_error_check(ctx, texObj, target, level,
+ 0, 0, 0, width, height, depth,
+ INT_MAX, pixels, caller)) {
+ return;
+ }
+
+ get_compressed_texture_image(ctx, texObj, target, level,
+ 0, 0, 0, width, height, depth,
+ pixels, caller);
+}
+
+
+void GLAPIENTRY
+_mesa_GetCompressedTexImage(GLenum target, GLint level, GLvoid *pixels)
+{
GET_CURRENT_CONTEXT(ctx);
+ static const char *caller = "glGetCompressedTexImage";
+ GLsizei width, height, depth;
+ struct gl_texture_object *texObj;
+
+ if (!legal_getteximage_target(ctx, target, false)) {
+ _mesa_error(ctx, GL_INVALID_ENUM, "%s", caller);
+ return;
+ }
texObj = _mesa_get_current_tex_object(ctx, target);
- if (!texObj)
+ assert(texObj);
+
+ get_texture_image_dims(texObj, target, level,
+ &width, &height, &depth);
+
+ if (getcompressedteximage_error_check(ctx, texObj, target, level,
+ 0, 0, 0, width, height, depth,
+ INT_MAX, pixels, caller)) {
return;
+ }
+
+ get_compressed_texture_image(ctx, texObj, target, level,
+ 0, 0, 0, width, height, depth,
+ pixels, caller);
+}
+
- texImage = _mesa_select_tex_image(texObj, target, level);
- if (!texImage)
+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;
+ }
- _mesa_get_compressed_texture_image(ctx, texObj, texImage, target, level,
- bufSize, img, false);
+ get_compressed_texture_image(ctx, texObj, texObj->Target, level,
+ 0, 0, 0, width, height, depth,
+ pixels, caller);
}
+
void GLAPIENTRY
-_mesa_GetCompressedTexImage(GLenum target, GLint level, GLvoid *img)
+_mesa_GetCompressedMultiTexImageEXT(GLenum texunit, GLenum target, GLint level,
+ GLvoid *pixels)
{
- _mesa_GetnCompressedTexImageARB(target, level, INT_MAX, img);
+ 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);
}
-/**
- * Get compressed texture image.
- *
- * \param texture texture name.
- * \param level image level.
- * \param bufSize size of the pixels data buffer.
- * \param pixels returned pixel data.
- */
+
void GLAPIENTRY
_mesa_GetCompressedTextureImage(GLuint texture, GLint level,
GLsizei bufSize, GLvoid *pixels)
{
- struct gl_texture_object *texObj;
- struct gl_texture_image *texImage;
- int i;
- GLint image_stride;
GET_CURRENT_CONTEXT(ctx);
+ static const char *caller = "glGetCompressedTextureImage";
+ GLsizei width, height, depth;
+ struct gl_texture_object *texObj =
+ _mesa_lookup_texture_err(ctx, texture, caller);
- texObj = _mesa_lookup_texture_err(ctx, texture,
- "glGetCompressedTextureImage");
- if (!texObj)
+ if (!texObj) {
return;
+ }
- /* Must handle special case GL_TEXTURE_CUBE_MAP. */
- if (texObj->Target == GL_TEXTURE_CUBE_MAP) {
+ get_texture_image_dims(texObj, texObj->Target, level,
+ &width, &height, &depth);
- /* Make sure the texture object is a proper cube.
- * (See texturesubimage in teximage.c for details on why this check is
- * performed.)
- */
- if (!_mesa_cube_level_complete(texObj, level)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "glGetCompressedTextureImage(cube map incomplete)");
- return;
- }
+ if (getcompressedteximage_error_check(ctx, texObj, texObj->Target, level,
+ 0, 0, 0, width, height, depth,
+ bufSize, pixels, caller)) {
+ return;
+ }
- /* Copy each face. */
- for (i = 0; i < 6; ++i) {
- texImage = texObj->Image[i][level];
- assert(texImage);
+ get_compressed_texture_image(ctx, texObj, texObj->Target, level,
+ 0, 0, 0, width, height, depth,
+ pixels, caller);
+}
- _mesa_get_compressed_texture_image(ctx, texObj, texImage,
- texObj->Target, level,
- bufSize, pixels, true);
- /* Compressed images don't have a client format */
- image_stride = _mesa_format_image_size(texImage->TexFormat,
- texImage->Width,
- texImage->Height, 1);
+void GLAPIENTRY
+_mesa_GetCompressedTextureSubImage(GLuint texture, GLint level,
+ GLint xoffset, GLint yoffset,
+ GLint zoffset, GLsizei width,
+ GLsizei height, GLsizei depth,
+ GLsizei bufSize, void *pixels)
+{
+ GET_CURRENT_CONTEXT(ctx);
+ static const char *caller = "glGetCompressedTextureImage";
+ struct gl_texture_object *texObj = NULL;
- pixels = (GLubyte *) pixels + image_stride;
- bufSize -= image_stride;
- }
+ texObj = _mesa_lookup_texture_err(ctx, texture, caller);
+ if (!texObj) {
+ return;
}
- else {
- texImage = _mesa_select_tex_image(texObj, texObj->Target, level);
- if (!texImage)
- return;
- _mesa_get_compressed_texture_image(ctx, texObj, texImage,
- texObj->Target, level, bufSize,
- pixels, true);
+ if (getcompressedteximage_error_check(ctx, texObj, texObj->Target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth,
+ bufSize, pixels, caller)) {
+ return;
}
+
+ get_compressed_texture_image(ctx, texObj, texObj->Target, level,
+ xoffset, yoffset, zoffset,
+ width, height, depth,
+ pixels, caller);
}