From: Brian Paul Date: Sun, 25 Oct 2009 23:07:06 +0000 (-0600) Subject: mesa: fix-up error checking related to compressed texture block size X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=07ad6393cb31d8f1f086f9c46705334ef9cf25f6;p=mesa.git mesa: fix-up error checking related to compressed texture block size --- diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c index 4fbfeb85826..bd5ad562580 100644 --- a/src/mesa/main/teximage.c +++ b/src/mesa/main/teximage.c @@ -3046,6 +3046,15 @@ compressed_tex_size(GLsizei width, GLsizei height, GLsizei depth, } +/* + * Return compressed texture block size, in pixels. + */ +static void +get_compressed_block_size(GLenum glformat, GLuint *bw, GLuint *bh) +{ + gl_format mesaFormat = _mesa_glenum_to_compressed_format(glformat); + _mesa_get_format_block_size(mesaFormat, bw, bh); +} /** @@ -3163,6 +3172,7 @@ compressed_subtexture_error_check(GLcontext *ctx, GLint dimensions, GLenum format, GLsizei imageSize) { GLint expectedSize, maxLevels = 0, maxTextureSize; + GLuint bw, bh; (void) zoffset; if (dimensions == 1) { @@ -3212,16 +3222,18 @@ compressed_subtexture_error_check(GLcontext *ctx, GLint dimensions, if (level < 0 || level >= maxLevels) return GL_INVALID_VALUE; - /* XXX these tests are specific to the compressed format. - * this code should be generalized in some way. + /* + * do checks which depend on compression block size */ - if ((xoffset & 3) != 0 || (yoffset & 3) != 0) + get_compressed_block_size(format, &bw, &bh); + + if ((xoffset % bw != 0) || (yoffset % bh != 0)) return GL_INVALID_VALUE; - if ((width & 3) != 0 && width != 2 && width != 1) + if ((width % bw != 0) && width != 2 && width != 1) return GL_INVALID_VALUE; - if ((height & 3) != 0 && height != 2 && height != 1) + if ((height % bh != 0) && height != 2 && height != 1) return GL_INVALID_VALUE; expectedSize = compressed_tex_size(width, height, depth, format);