[Mesa-dev] [PATCH] mesa: finish implementing ARB_texture_stencil8 (v5)

Anuj Phogat anuj.phogat at gmail.com
Mon Apr 27 11:15:31 PDT 2015


On Tue, Apr 21, 2015 at 6:59 PM, Dave Airlie <airlied at gmail.com> wrote:
> Parts of this were implemented previously, so finish it off.
>
> v2: fix getteximage falling into the integer check
>     add fixes for the FBO paths, (fbo-stencil8 test).
>
> v3: fix getteximage path harder.
> v4: remove swapbytes from getteximage path (Ilia)
> v5: brown paper bag the swapbytes removal. (Ilia)
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  src/mesa/main/extensions.c  |  1 +
>  src/mesa/main/fbobject.c    |  9 +++++---
>  src/mesa/main/texgetimage.c | 50 ++++++++++++++++++++++++++++++++++++++++++++-
>  src/mesa/main/teximage.c    |  3 ++-
>  4 files changed, 58 insertions(+), 5 deletions(-)
>
> diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
> index 861b150..3d4965c 100644
> --- a/src/mesa/main/extensions.c
> +++ b/src/mesa/main/extensions.c
> @@ -186,6 +186,7 @@ static const struct extension extension_table[] = {
>     { "GL_ARB_texture_rectangle",                   o(NV_texture_rectangle),                    GL,             2004 },
>     { "GL_ARB_texture_rgb10_a2ui",                  o(ARB_texture_rgb10_a2ui),                  GL,             2009 },
>     { "GL_ARB_texture_rg",                          o(ARB_texture_rg),                          GL,             2008 },
> +   { "GL_ARB_texture_stencil8",                    o(ARB_texture_stencil8),                    GL,             2013 },
>     { "GL_ARB_texture_storage",                     o(dummy_true),                              GL,             2011 },
>     { "GL_ARB_texture_storage_multisample",         o(ARB_texture_multisample),                 GL,             2012 },
>     { "GL_ARB_texture_view",                        o(ARB_texture_view),                        GL,             2012 },
> diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
> index 8032585..27cf97f 100644
> --- a/src/mesa/main/fbobject.c
> +++ b/src/mesa/main/fbobject.c
> @@ -813,8 +813,10 @@ test_attachment_completeness(const struct gl_context *ctx, GLenum format,
>           if (ctx->Extensions.ARB_depth_texture &&
>               baseFormat == GL_DEPTH_STENCIL) {
>              /* OK */
> -         }
> -         else {
> +         } else if (ctx->Extensions.ARB_texture_stencil8 &&
> +                    baseFormat == GL_STENCIL_INDEX) {
> +            /* OK */
> +         } else {
>              /* no such thing as stencil-only textures */
>              att_incomplete("illegal stencil texture");
>              att->Complete = GL_FALSE;
> @@ -978,7 +980,8 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
>
>           if (!is_format_color_renderable(ctx, attFormat,
>                                           texImg->InternalFormat) &&
> -             !is_legal_depth_format(ctx, f)) {
> +             !is_legal_depth_format(ctx, f) &&
> +             f != GL_STENCIL_INDEX) {
>              fb->_Status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
>              fbo_incomplete(ctx, "texture attachment incomplete", -1);
>              return;
> diff --git a/src/mesa/main/texgetimage.c b/src/mesa/main/texgetimage.c
> index 255d365..e6d6471 100644
> --- a/src/mesa/main/texgetimage.c
> +++ b/src/mesa/main/texgetimage.c
> @@ -175,6 +175,51 @@ get_tex_depth_stencil(struct gl_context *ctx, GLuint dimensions,
>     }
>  }
>
> +/**
> + * glGetTexImage for stencil pixels.
> + */
> +static void
> +get_tex_stencil(struct gl_context *ctx, GLuint dimensions,
> +                GLenum format, GLenum type, GLvoid *pixels,
> +                struct gl_texture_image *texImage)
> +{
> +   const GLint width = texImage->Width;
> +   const GLint height = texImage->Height;
> +   const GLint depth = texImage->Depth;
> +   GLint img, row;
> +
> +   assert(format == GL_STENCIL_INDEX);
> +
> +   for (img = 0; img < depth; img++) {
> +      GLubyte *srcMap;
> +      GLint rowstride;
> +
> +      /* map src texture buffer */
> +      ctx->Driver.MapTextureImage(ctx, texImage, img,
> +                                  0, 0, width, height, GL_MAP_READ_BIT,
> +                                  &srcMap, &rowstride);
> +
> +      if (srcMap) {
> +         for (row = 0; row < height; row++) {
> +            const GLubyte *src = srcMap + row * rowstride;
> +            void *dest = _mesa_image_address(dimensions, &ctx->Pack, pixels,
> +                                             width, height, format, type,
> +                                             img, row, 0);
> +            _mesa_unpack_ubyte_stencil_row(texImage->TexFormat,
> +                                           width,
> +                                           (const GLuint *) src,
> +                                           dest);
> +         }
> +
> +         ctx->Driver.UnmapTextureImage(ctx, texImage, img);
> +      }
> +      else {
> +         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage");
> +         break;
> +      }
> +   }
> +}
> +
>
>  /**
>   * glGetTexImage for YCbCr pixels.
> @@ -684,6 +729,9 @@ _mesa_GetTexImage_sw(struct gl_context *ctx,
>     else if (format == GL_DEPTH_STENCIL_EXT) {
>        get_tex_depth_stencil(ctx, dimensions, format, type, pixels, texImage);
>     }
> +   else if (format == GL_STENCIL_INDEX) {
> +      get_tex_stencil(ctx, dimensions, format, type, pixels, texImage);
> +   }
>     else if (format == GL_YCBCR_MESA) {
>        get_tex_ycbcr(ctx, dimensions, format, type, pixels, texImage);
>     }
> @@ -879,7 +927,7 @@ getteximage_error_check(struct gl_context *ctx,
>                    "glGetTex%sImage(format mismatch)", suffix);
>        return GL_TRUE;
>     }
> -   else if (_mesa_is_enum_format_integer(format) !=
> +   else if (!_mesa_is_stencil_format(format) && _mesa_is_enum_format_integer(format) !=
>              _mesa_is_format_integer(texImage->TexFormat)) {
>        _mesa_error(ctx, GL_INVALID_OPERATION,
>                    "glGetTex%sImage(format mismatch)", suffix);
> diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
> index 8d9d7cf..d07263c 100644
> --- a/src/mesa/main/teximage.c
> +++ b/src/mesa/main/teximage.c
> @@ -1997,7 +1997,8 @@ _mesa_legal_texture_base_format_for_target(struct gl_context *ctx,
>                                             const char *caller)
>  {
>     if (_mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_COMPONENT
> -       || _mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_STENCIL) {
> +       || _mesa_base_tex_format(ctx, internalFormat) == GL_DEPTH_STENCIL
> +       || _mesa_base_tex_format(ctx, internalFormat) == GL_STENCIL_INDEX) {
>        /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
>         * Profile spec says:
>         *
> --
> 2.1.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev

LGTM.
Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>


More information about the mesa-dev mailing list