mesa: Emit errors for inconsistent compressed pixel store state
authorChris Forbes <chrisf@ijw.co.nz>
Tue, 20 May 2014 11:41:59 +0000 (23:41 +1200)
committerChris Forbes <chrisf@ijw.co.nz>
Mon, 9 Jun 2014 19:42:44 +0000 (07:42 +1200)
V2: Use bool rather than GLboolean for internal function

Signed-off-by: Chris Forbes <chrisf@ijw.co.nz>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/main/texgetimage.c
src/mesa/main/teximage.c
src/mesa/main/teximage.h

index 1ac707d134c8180cc5521e41d67e48df7c41b05f..c22fb9b44f834e8405f17ae0e1dbc72039533755 100644 (file)
@@ -963,7 +963,7 @@ getcompressedteximage_error_check(struct gl_context *ctx, GLenum target,
    struct gl_texture_object *texObj;
    struct gl_texture_image *texImage;
    const GLint maxLevels = _mesa_max_texture_levels(ctx, target);
-   GLuint compressedSize;
+   GLuint compressedSize, dimensions;
 
    if (!legal_getteximage_target(ctx, target)) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glGetCompressedTexImage(target=0x%x)",
@@ -1004,6 +1004,14 @@ getcompressedteximage_error_check(struct gl_context *ctx, GLenum target,
                                             texImage->Height,
                                             texImage->Depth);
 
+   /* Check for invalid pixel storage modes */
+   dimensions = _mesa_get_texture_dimensions(texImage->TexObject->Target);
+   if (!_mesa_compressed_texture_pixel_storage_error_check(ctx, dimensions,
+                                                           &ctx->Pack,
+                                                           "glGetCompressedTexImageARB")) {
+      return GL_TRUE;
+   }
+
    if (!_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
       /* do bounds checking on writing to client memory */
       if (clientMemSize < (GLsizei) compressedSize) {
index 5058b394e44248537730642c69fb125e9509d565..cab29c35d63449c40f4365fd9577150013182128 100644 (file)
@@ -2242,6 +2242,36 @@ texture_error_check( struct gl_context *ctx,
 }
 
 
+bool
+_mesa_compressed_texture_pixel_storage_error_check(struct gl_context *ctx,
+                                             GLint dimensions,
+                                             struct gl_pixelstore_attrib *packing,
+                                             const char *caller)
+{
+   if (!_mesa_is_desktop_gl(ctx) || !packing->CompressedBlockSize)
+      return true;
+
+   if (packing->CompressedBlockWidth && packing->SkipPixels % packing->CompressedBlockWidth) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "%s(skip-pixels %% block-width)", caller);
+      return false;
+   }
+
+   if (dimensions > 1 && packing->CompressedBlockHeight && packing->SkipRows % packing->CompressedBlockHeight) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "%s(skip-rows %% block-height)", caller);
+      return false;
+   }
+
+   if (dimensions > 2 && packing->CompressedBlockDepth && packing->SkipImages % packing->CompressedBlockDepth) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "%s(skip-images %% block-depth)", caller);
+      return false;
+   }
+
+   return true;
+}
+
 /**
  * Error checking for glCompressedTexImage[123]D().
  * Note that the width, height and depth values are not fully error checked
@@ -2343,6 +2373,13 @@ compressed_texture_error_check(struct gl_context *ctx, GLint dimensions,
       goto error;
    }
 
+   /* Check for invalid pixel storage modes */
+   if (!_mesa_compressed_texture_pixel_storage_error_check(ctx, dimensions,
+                                                           &ctx->Unpack,
+                                                           "glCompressedTexImage")) {
+      return GL_FALSE;
+   }
+
    /* check image size in bytes */
    if (expectedSize != imageSize) {
       /* Per GL_ARB_texture_compression:  GL_INVALID_VALUE is generated [...]
@@ -3862,6 +3899,14 @@ compressed_subtexture_error_check(struct gl_context *ctx, GLint dims,
       return GL_TRUE;
    }
 
+   /* Check for invalid pixel storage modes */
+   if (!_mesa_compressed_texture_pixel_storage_error_check(ctx, dims,
+                                                           &ctx->Unpack,
+                                                           "glCompressedTexSubImage")) {
+      return GL_FALSE;
+   }
+
+
    expectedSize = compressed_tex_size(width, height, depth, format);
    if (expectedSize != imageSize) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glCompressedTexSubImage%uD(size=%d)",
index 51d94d17e8202c89841bacc9ff1dfbc5dc6798d9..dd1504b405c74a3c4a15f8ce42041a58d65f6269 100644 (file)
@@ -326,6 +326,12 @@ _mesa_TexStorage3DMultisample(GLenum target, GLsizei samples,
                               GLsizei height, GLsizei depth,
                               GLboolean fixedsamplelocations);
 
+bool
+_mesa_compressed_texture_pixel_storage_error_check(struct gl_context *ctx,
+                                             GLint dimensions,
+                                             struct gl_pixelstore_attrib *packing,
+                                             const char *caller);
+
 /*@}*/
 
 #ifdef __cplusplus