[Mesa-dev] [PATCH] mesa: Use GL_RED for DEPTH_TEXTURE_MODE for everything but legacy GL.

Matt Turner mattst88 at gmail.com
Mon Nov 19 10:32:35 PST 2012


On Sat, Nov 17, 2012 at 11:26 PM, Kenneth Graunke <kenneth at whitecape.org> wrote:
> According to page 163 of the ES 3.0 spec:
>
> "Texture lookups involving textures with depth component data generate
>  a texture base color C_b either using depth data directly or by
>  performing a comparison with the D_ref value used to perform the
>  lookup, as described in section 3.8.15.  The resulting value R_t is
>  then expanded to a color C_b = (R_t,0,0,1), ..."
>
> In other words, depth textures are supposed to be treated as GL_RED.
>
> A discussion about this text can be found in Khronos bugzilla:
> https://cvs.khronos.org/bugzilla/show_bug.cgi?id=7962
>
> It's unclear what the behavior of desktop GL should be.  The GL 3.x
> specifications indicate that it should be (r, r, r, 1), which is
> GL_LUMINANCE (the old default).  However, page 112 of the 4.2 core
> specification contains the text quoted above, explicitly declaring it
> to be (R_t, 0, 0, 1), which is GL_RED.
>
> So it hinges on whether the 4.2 text is a change or a clarification.
> Personally I think that using GL_RED in core contexts and GL_INTENSITY
> in legacy contexts seems reasonable.
>
> Fixes 4 es3conform tests:
> - depth_texture_fbo
> - depth_texture_fbo_clear
> - depth_texture_teximage
> - depth_texture_texsubimage
>
> Cc: Ian Romanick <idr at freedesktop.org>
> ---
>  src/mesa/drivers/dri/intel/intel_tex.c         | 2 +-
>  src/mesa/drivers/dri/nouveau/nouveau_texture.c | 2 +-
>  src/mesa/drivers/dri/r200/r200_tex.c           | 2 +-
>  src/mesa/drivers/dri/radeon/radeon_tex.c       | 2 +-
>  src/mesa/main/texobj.c                         | 9 +++++----
>  src/mesa/main/texobj.h                         | 5 +++--
>  src/mesa/state_tracker/st_cb_texture.c         | 2 +-
>  7 files changed, 13 insertions(+), 11 deletions(-)
>
> No piglit regressions.  nouveau/radeon changes not even compile tested. :(
>
> Ian, do you have any insight as to whether this is correct?  Clearly it's
> correct to use GL_RED for ES 3.0, but I don't know about desktop.
>
> diff --git a/src/mesa/drivers/dri/intel/intel_tex.c b/src/mesa/drivers/dri/intel/intel_tex.c
> index 6820f98..b927440 100644
> --- a/src/mesa/drivers/dri/intel/intel_tex.c
> +++ b/src/mesa/drivers/dri/intel/intel_tex.c
> @@ -34,7 +34,7 @@ intelNewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
>     (void) ctx;
>
>     DBG("%s\n", __FUNCTION__);
> -   _mesa_initialize_texture_object(&obj->base, name, target);
> +   _mesa_initialize_texture_object(ctx, &obj->base, name, target);
>
>     return &obj->base;
>  }
> diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
> index 288b510..0daef57 100644
> --- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c
> +++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
> @@ -46,7 +46,7 @@ nouveau_texture_new(struct gl_context *ctx, GLuint name, GLenum target)
>  {
>         struct nouveau_texture *nt = CALLOC_STRUCT(nouveau_texture);
>
> -       _mesa_initialize_texture_object(&nt->base, name, target);
> +       _mesa_initialize_texture_object(ctx, &nt->base, name, target);
>
>         return &nt->base;
>  }
> diff --git a/src/mesa/drivers/dri/r200/r200_tex.c b/src/mesa/drivers/dri/r200/r200_tex.c
> index a4347c6..a74a2e9 100644
> --- a/src/mesa/drivers/dri/r200/r200_tex.c
> +++ b/src/mesa/drivers/dri/r200/r200_tex.c
> @@ -477,7 +477,7 @@ static struct gl_texture_object *r200NewTextureObject(struct gl_context * ctx,
>            __FUNCTION__, ctx,
>            _mesa_lookup_enum_by_nr(target), t);
>
> -   _mesa_initialize_texture_object(&t->base, name, target);
> +   _mesa_initialize_texture_object(ctx, &t->base, name, target);
>     t->base.Sampler.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy;
>
>     /* Initialize hardware state */
> diff --git a/src/mesa/drivers/dri/radeon/radeon_tex.c b/src/mesa/drivers/dri/radeon/radeon_tex.c
> index 5ca07e0..56efb8c 100644
> --- a/src/mesa/drivers/dri/radeon/radeon_tex.c
> +++ b/src/mesa/drivers/dri/radeon/radeon_tex.c
> @@ -411,7 +411,7 @@ radeonNewTextureObject( struct gl_context *ctx, GLuint name, GLenum target )
>     r100ContextPtr rmesa = R100_CONTEXT(ctx);
>     radeonTexObj* t = CALLOC_STRUCT(radeon_tex_obj);
>
> -   _mesa_initialize_texture_object(&t->base, name, target);
> +   _mesa_initialize_texture_object(ctx, &t->base, name, target);
>     t->base.Sampler.MaxAnisotropy = rmesa->radeon.initialMaxAnisotropy;
>
>     t->border_fallback = GL_FALSE;
> diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
> index d650c75..7fdc10b 100644
> --- a/src/mesa/main/texobj.c
> +++ b/src/mesa/main/texobj.c
> @@ -84,7 +84,7 @@ _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target )
>     struct gl_texture_object *obj;
>     (void) ctx;
>     obj = MALLOC_STRUCT(gl_texture_object);
> -   _mesa_initialize_texture_object(obj, name, target);
> +   _mesa_initialize_texture_object(ctx, obj, name, target);
>     return obj;
>  }
>
> @@ -96,8 +96,9 @@ _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target )
>   * \param target  the texture target
>   */
>  void
> -_mesa_initialize_texture_object( struct gl_texture_object *obj,
> -                                 GLuint name, GLenum target )
> +_mesa_initialize_texture_object(struct gl_context *ctx,
> +                                struct gl_texture_object *obj,
> +                                GLuint name, GLenum target)
>  {
>     ASSERT(target == 0 ||
>            target == GL_TEXTURE_1D ||
> @@ -145,7 +146,7 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
>     obj->Sampler.MaxAnisotropy = 1.0;
>     obj->Sampler.CompareMode = GL_NONE;         /* ARB_shadow */
>     obj->Sampler.CompareFunc = GL_LEQUAL;       /* ARB_shadow */
> -   obj->DepthMode = GL_LUMINANCE;
> +   obj->DepthMode = ctx->API == API_OPENGL ? GL_LUMINANCE : GL_RED;
>     obj->Sampler.CubeMapSeamless = GL_FALSE;
>     obj->Swizzle[0] = GL_RED;
>     obj->Swizzle[1] = GL_GREEN;
> diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
> index f86b4eb..e1e9862 100644
> --- a/src/mesa/main/texobj.h
> +++ b/src/mesa/main/texobj.h
> @@ -50,8 +50,9 @@ extern struct gl_texture_object *
>  _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target );
>
>  extern void
> -_mesa_initialize_texture_object( struct gl_texture_object *obj,
> -                                 GLuint name, GLenum target );
> +_mesa_initialize_texture_object(struct gl_context *ctx,
> +                                struct gl_texture_object *obj,
> +                                GLuint name, GLenum target);
>
>  extern void
>  _mesa_delete_texture_object( struct gl_context *ctx,
> diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
> index f06814f..dae5444 100644
> --- a/src/mesa/state_tracker/st_cb_texture.c
> +++ b/src/mesa/state_tracker/st_cb_texture.c
> @@ -138,7 +138,7 @@ st_NewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
>     struct st_texture_object *obj = ST_CALLOC_STRUCT(st_texture_object);
>
>     DBG("%s\n", __FUNCTION__);
> -   _mesa_initialize_texture_object(&obj->base, name, target);
> +   _mesa_initialize_texture_object(ctx, &obj->base, name, target);
>
>     return &obj->base;
>  }
> --
> 1.8.0

Don't know if you'll have to change this patch per Ian's review, but
it does indeed fix these tests for me.

Tested-by: Matt Turner <mattst88 at gmail.com>


More information about the mesa-dev mailing list