From: José Fonseca Date: Sun, 16 Sep 2012 01:33:07 +0000 (+0100) Subject: trace: Fix alignment bug in computing image sizes. X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=a3b4d63c07781b5536d008a6b78716a4aeea1813 trace: Fix alignment bug in computing image sizes. Match precisely what the OpenGL spec says. Fixes the stride computation of RGB8. Based on discussion and code from Carl Worth and Paul Berry. --- diff --git a/helpers/glsize.hpp b/helpers/glsize.hpp index a589199..6ffba68 100644 --- a/helpers/glsize.hpp +++ b/helpers/glsize.hpp @@ -608,28 +608,32 @@ static inline size_t _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsizei depth, GLboolean has_unpack_subimage) { unsigned num_channels = _gl_format_channels(format); + unsigned bits_per_element; unsigned bits_per_pixel; switch (type) { case GL_BITMAP: - bits_per_pixel = 1; + bits_per_pixel = bits_per_element = 1; break; case GL_BYTE: case GL_UNSIGNED_BYTE: - bits_per_pixel = 8 * num_channels; + bits_per_element = 8; + bits_per_pixel = bits_per_element * num_channels; break; case GL_SHORT: case GL_UNSIGNED_SHORT: case GL_HALF_FLOAT: - bits_per_pixel = 16 * num_channels; + bits_per_element = 16; + bits_per_pixel = bits_per_element * num_channels; break; case GL_INT: case GL_UNSIGNED_INT: case GL_FLOAT: - bits_per_pixel = 32 * num_channels; + bits_per_element = 32; + bits_per_pixel = bits_per_element * num_channels; break; case GL_UNSIGNED_BYTE_3_3_2: case GL_UNSIGNED_BYTE_2_3_3_REV: - bits_per_pixel = 8; + bits_per_pixel = bits_per_element = 8; break; case GL_UNSIGNED_SHORT_4_4_4_4: case GL_UNSIGNED_SHORT_4_4_4_4_REV: @@ -639,7 +643,7 @@ _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsize case GL_UNSIGNED_SHORT_5_6_5_REV: case GL_UNSIGNED_SHORT_8_8_MESA: case GL_UNSIGNED_SHORT_8_8_REV_MESA: - bits_per_pixel = 16; + bits_per_pixel = bits_per_element = 16; break; case GL_UNSIGNED_INT_8_8_8_8: case GL_UNSIGNED_INT_8_8_8_8_REV: @@ -650,14 +654,14 @@ _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsize case GL_UNSIGNED_INT_5_9_9_9_REV: case GL_UNSIGNED_INT_S8_S8_8_8_NV: case GL_UNSIGNED_INT_8_8_S8_S8_REV_NV: - bits_per_pixel = 32; + bits_per_pixel = bits_per_element = 32; break; case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: - bits_per_pixel = 64; + bits_per_pixel = bits_per_element = 64; break; default: os::log("apitrace: warning: %s: unexpected type GLenum 0x%04X\n", __FUNCTION__, type); - bits_per_pixel = 0; + bits_per_pixel = bits_per_element = 0; break; } @@ -683,9 +687,11 @@ _gl_image_size(GLenum format, GLenum type, GLsizei width, GLsizei height, GLsize size_t row_stride = (row_length*bits_per_pixel + 7)/8; - if ((GLint)bits_per_pixel < alignment*8 && - (bits_per_pixel & 7) == 0 && - _is_pot(bits_per_pixel)) { + if ((bits_per_element == 1*8 || + bits_per_element == 2*8 || + bits_per_element == 4*8 || + bits_per_element == 8*8) && + (GLint)bits_per_element < alignment*8) { row_stride = _align(row_stride, alignment); }