summaryrefslogtreecommitdiff
path: root/helpers
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2014-01-21 14:32:46 +0000
committerJosé Fonseca <jfonseca@vmware.com>2014-01-21 14:32:46 +0000
commite2f73049f8d52fb06cb9b5d923c1280557aa9238 (patch)
tree9e90f566c9d2cb9ca0767dbafecec537a8fee99a /helpers
parent8cf2c4f7e9949f1fd0d60f76a63b13277e2c5895 (diff)
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.
Diffstat (limited to 'helpers')
-rw-r--r--helpers/glsize.hpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/helpers/glsize.hpp b/helpers/glsize.hpp
index 7c1d0176..0293a139 100644
--- a/helpers/glsize.hpp
+++ b/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;