[Mesa-dev] [PATCH] mesa: fix an issue with texture border and array textures

Brian Paul brianp at vmware.com
Mon Feb 20 07:54:21 PST 2012


On 02/16/2012 08:48 PM, Anuj Phogat wrote:
> As suggested by Brian, for a 1D texture array, the border only applies to the
> width.  For a 2D texture array the border applies to the width and height but
> not the depth.  This was not handled correctly _mesa_init_teximage_fields().
>
> Note: This is a candidate for stable branches
>
> Signed-off-by: Anuj Phogat<anuj.phogat at gmail.com>
> ---
> Added the case when incoming height, depth is zero. I will develop a piglit
> test case as suggested.
>
>   src/mesa/main/teximage.c |   70 ++++++++++++++++++++++++++++++++++++++-------
>   1 files changed, 59 insertions(+), 11 deletions(-)
>
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index 6acff24..9b6c6c8 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -1083,11 +1083,13 @@ _mesa_init_teximage_fields(struct gl_context *ctx,
>                              GLint border, GLenum internalFormat,
>                              gl_format format)
>   {
> +   GLenum target;
>      ASSERT(img);
>      ASSERT(width>= 0);
>      ASSERT(height>= 0);
>      ASSERT(depth>= 0);
>
> +   target = img->TexObject->Target;
>      img->_BaseFormat = _mesa_base_tex_format( ctx, internalFormat );
>      ASSERT(img->_BaseFormat>  0);
>      img->InternalFormat = internalFormat;
> @@ -1099,26 +1101,72 @@ _mesa_init_teximage_fields(struct gl_context *ctx,
>      img->Width2 = width - 2 * border;   /* == 1<<  img->WidthLog2; */
>      img->WidthLog2 = _mesa_logbase2(img->Width2);
>
> -   if (height == 1) { /* 1-D texture */
> -      img->Height2 = 1;
> +   switch(target) {
> +   case GL_TEXTURE_1D:
> +   case GL_TEXTURE_BUFFER:
> +   case GL_PROXY_TEXTURE_1D:
> +      if (height == 0)
> +         img->Height2 = 0;
> +      else
> +         img->Height2 = 1;
>         img->HeightLog2 = 0;
> -   }
> -   else {
> +      if (depth == 0)
> +         img->Depth2 = 0;
> +      else
> +         img->Depth2 = 1;
> +      img->DepthLog2 = 0;
> +      break;
> +   case GL_TEXTURE_1D_ARRAY:
> +   case GL_PROXY_TEXTURE_1D_ARRAY:
> +      img->Height2 = height; /* no border */
> +      img->HeightLog2 = 0; /* not used */
> +      if (depth == 0)
> +         img->Depth2 = 0;
> +      else
> +         img->Depth2 = 1;
> +      img->DepthLog2 = 0;
> +      break;
> +   case GL_TEXTURE_2D:
> +   case GL_TEXTURE_RECTANGLE:
> +   case GL_TEXTURE_CUBE_MAP:
> +   case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
> +   case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
> +   case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
> +   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
> +   case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
> +   case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
> +   case GL_TEXTURE_EXTERNAL_OES:
> +   case GL_PROXY_TEXTURE_2D:
> +   case GL_PROXY_TEXTURE_RECTANGLE:
> +   case GL_PROXY_TEXTURE_CUBE_MAP:
>         img->Height2 = height - 2 * border; /* == 1<<  img->HeightLog2; */
>         img->HeightLog2 = _mesa_logbase2(img->Height2);
> -   }
> -
> -   if (depth == 1) {  /* 2-D texture */
> -      img->Depth2 = 1;
> +      if (depth == 0)
> +         img->Depth2 = 0;
> +      else
> +         img->Depth2 = 1;
>         img->DepthLog2 = 0;
> -   }
> -   else {
> +      break;
> +   case GL_TEXTURE_2D_ARRAY:
> +   case GL_PROXY_TEXTURE_2D_ARRAY:
> +      img->Height2 = height - 2 * border; /* == 1<<  img->HeightLog2; */
> +      img->HeightLog2 = _mesa_logbase2(img->Height2);
> +      img->Depth2 = depth; /* no border */
> +      img->DepthLog2 = 0; /* not used */
> +      break;
> +   case GL_TEXTURE_3D:
> +   case GL_PROXY_TEXTURE_3D:
> +      img->Height2 = height - 2 * border; /* == 1<<  img->HeightLog2; */
> +      img->HeightLog2 = _mesa_logbase2(img->Height2);
>         img->Depth2 = depth - 2 * border;   /* == 1<<  img->DepthLog2; */
>         img->DepthLog2 = _mesa_logbase2(img->Depth2);
> +      break;
> +   default:
> +      _mesa_problem(NULL, "invalid target 0x%x in _mesa_init_teximage_fields()",
> +                    target);
>      }
>
>      img->MaxLog2 = MAX2(img->WidthLog2, img->HeightLog2);
> -
>      img->TexFormat = format;
>   }
>

Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the mesa-dev mailing list