Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

gltrace: Fix the computation of image sizes.

The size, instead of being computed as

  image_height * row_stride

should actually be

   size_of_first_row + (image_height - 1) * row_stride

as tsondergaard explained in issue #208.
  • Loading branch information...
commit e2f73049f8d52fb06cb9b5d923c1280557aa9238 1 parent 8cf2c4f
@jrfonseca jrfonseca authored
Showing with 18 additions and 4 deletions.
  1. +18 −4 helpers/glsize.hpp
View
22 helpers/glsize.hpp
@@ -896,12 +896,26 @@ _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsize
image_height = height;
}
- /* XXX: GL_UNPACK_IMAGE_HEIGHT and GL_UNPACK_SKIP_IMAGES should probably
- * not be considered for pixel rectangles. */
-
size_t image_stride = image_height*row_stride;
- size_t size = depth*image_stride;
+ /*
+ * We can't just do
+ *
+ * size = depth*image_stride
+ *
+ * here as that could result in reading beyond the end of the buffer when
+ * selecting sub-rectangles via GL_UNPACK_SKIP_*.
+ */
+ size_t size = (width*bits_per_pixel + 7)/8;
+ if (height > 1) {
+ size += (height - 1)*row_stride;
+ }
+ if (depth > 1) {
+ size += (depth - 1)*image_stride;
+ }
+
+ /* XXX: GL_UNPACK_IMAGE_HEIGHT and GL_UNPACK_SKIP_IMAGES should probably
+ * not be considered for pixel rectangles. */
size += (skip_pixels*bits_per_pixel + 7)/8;
size += skip_rows*row_stride;
Please sign in to comment.
Something went wrong with that request. Please try again.