[Mesa-dev] [PATCH] mesa: Add condition in glGetTexImage for zero size textures

Brian Paul brianp at vmware.com
Tue Jan 17 06:51:20 PST 2012


On 01/16/2012 05:40 PM, Anuj Phogat wrote:
> TestMipMaps() function in src/OGLconform/textureNPOT.c calls glTexImage2D()
> with width = 0. Texture with zero size skips miptree allocation due to a
> condition in function _mesa_store_teximage3d(). While calling glGetTexImage()
> it results in assertion failure in intel_map_texture_image() due to null mt
> pointer.
>
> This patch fixes the issue by detecting the zero size texture early in
> glGetTexImage. In such a case function simply returns doing nothing.
> Verified that below mentioned bug is fixed by this patch.
>
> https://bugs.freedesktop.org/show_bug.cgi?id=42334
>
> Signed-off-by: Anuj Phogat<anuj.phogat at gmail.com>
> ---
>   Brian, I agree glTexImage is a better place for this fix. I have made the
>   changes as per your suggestions. Let me know if i missed something.

I think a similar check should be added for glGetCompressedTexImage.


>
>   src/mesa/main/texgetimage.c |    3 +++
>   src/mesa/main/teximage.h    |    9 ++++++++-
>   2 files changed, 11 insertions(+), 1 deletions(-)
>
> diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
> index f848aa8..2269f8f 100644
> --- a/src/mesa/main/texgetimage.c
> +++ b/src/mesa/main/texgetimage.c
> @@ -837,6 +837,9 @@ _mesa_GetnTexImageARB( GLenum target, GLint level, GLenum format,
>      texObj = _mesa_get_current_tex_object(ctx, target);
>      texImage = _mesa_select_tex_image(ctx, texObj, target, level);
>
> +   if (_mesa_is_zero_size_texture(texImage))
> +      return;
> +
>      if (MESA_VERBOSE&  (VERBOSE_API | VERBOSE_TEXTURE)) {
>         _mesa_debug(ctx, "glGetTexImage(tex %u) format = %s, w=%d, h=%d,"
>                     " dstFmt=0x%x, dstType=0x%x\n",
> diff --git a/src/mesa/main/teximage.h b/src/mesa/main/teximage.h
> index 12af0e6..6d8cdb3 100644
> --- a/src/mesa/main/teximage.h
> +++ b/src/mesa/main/teximage.h
> @@ -44,7 +44,14 @@ _mesa_is_cube_face(GLenum target)
>              target<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB);
>   }
>
> -
> +/** Is any of the dimensions of given texture equal to zero? */
> +static inline GLboolean
> +_mesa_is_zero_size_texture(struct gl_texture_image *texImage)

The param could be const-qualified.


> +{
> +   return (texImage->Width == 0 ||
> +           texImage->Height == 0 ||
> +           texImage->Depth == 0);
> +}
>
>   /** \name Internal functions */
>   /*@{*/


-Brian


More information about the mesa-dev mailing list