[Mesa-dev] [PATCH 01/18] mesa: Store the target index in gl_texture_object

Fredrik Höglund fredrik at kde.org
Thu Jan 23 14:12:19 PST 2014


On Wednesday 22 January 2014, Brian Paul wrote:
> On 01/21/2014 03:35 PM, Fredrik Höglund wrote:
> > This will be used by glBindTextures() so we don't have to look it up
> > for each texture.
> > ---
> >   src/mesa/main/mtypes.h |    1 +
> >   src/mesa/main/texobj.c |    2 ++
> >   2 files changed, 3 insertions(+)
> >
> > diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> > index c396609..2fe47c4 100644
> > --- a/src/mesa/main/mtypes.h
> > +++ b/src/mesa/main/mtypes.h
> > @@ -1194,6 +1194,7 @@ struct gl_texture_object
> >      GLuint Name;                /**< the user-visible texture object ID */
> >      GLchar *Label;               /**< GL_KHR_debug */
> >      GLenum Target;              /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
> > +   GLuint TargetIndex;         /**< The gl_texture_unit::CurrentTex index */
> 
> Could this be "gl_texture_index TargetIndex;"?

It can indeed.  I'll change it.

> >
> >      struct gl_sampler_object Sampler;
> >
> > diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
> > index 3c64c437..4d97275 100644
> > --- a/src/mesa/main/texobj.c
> > +++ b/src/mesa/main/texobj.c
> > @@ -259,6 +259,7 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
> >                              const struct gl_texture_object *src )
> >   {
> >      dest->Target = src->Target;
> > +   dest->TargetIndex = src->TargetIndex;
> >      dest->Name = src->Name;
> >      dest->Priority = src->Priority;
> >      dest->Sampler.BorderColor.f[0] = src->Sampler.BorderColor.f[0];
> > @@ -1318,6 +1319,7 @@ _mesa_BindTexture( GLenum target, GLuint texName )
> >            _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
> >         }
> >         newTexObj->Target = target;
> > +      newTexObj->TargetIndex = targetIndex;
> >      }
> >
> >      assert(valid_texture_object(newTexObj));
> >
> 
> 
> So the memset() in _mesa_initialize_texture_object() would implicitly 
> set TargetIndex = TEXTURE_2D_MULTISAMPLE_INDEX (zero).  Is that going to 
> cause any trouble?

That's a good question.  TargetIndex is only used in _mesa_BindTextures()
and unbind_texobj_from_texunits().  _mesa_BindTextures() checks if Target
is valid before it uses TargetIndex.  If unbind_texobj_from_texunits()
is called with a texture that has never been used, it doesn't matter that the
index is zero, because the texture won't be bound to any unit anyway.
It should probably exit early if the texture doesn't have a target though.

So to the best of my knowledge it shouldn't be a problem.  But maybe it
should be documented somewhere that TargetIndex is only valid when
Target is valid.

Fredrik



More information about the mesa-dev mailing list