[Mesa-dev] [PATCH 1/2] mesa: Add glsl_type::get_scalar_type() function.

Paul Berry stereotype441 at gmail.com
Tue Oct 25 17:02:05 PDT 2011


On 25 October 2011 16:55, Kenneth Graunke <kenneth at whitecape.org> wrote:

> On 10/25/2011 04:47 PM, Paul Berry wrote:
> > This function is similar to get_base_type(), but when called on
> > arrays, it returns the scalar type composing the array.  For example,
> > glsl_type(vec4[]) => float_type.
> > ---
> >  src/glsl/glsl_types.cpp |   23 +++++++++++++++++++++++
> >  src/glsl/glsl_types.h   |   11 +++++++++++
> >  2 files changed, 34 insertions(+), 0 deletions(-)
> >
> > diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
> > index c94aec0..03e9987 100644
> > --- a/src/glsl/glsl_types.cpp
> > +++ b/src/glsl/glsl_types.cpp
> > @@ -258,6 +258,29 @@ const glsl_type *glsl_type::get_base_type() const
> >  }
> >
> >
> > +const glsl_type *glsl_type::get_scalar_type() const
> > +{
> > +   const glsl_type *type = this;
> > +
> > +   /* Handle arrays */
> > +   while (type->base_type == GLSL_TYPE_ARRAY)
> > +      type = type->fields.array;
>
> This is going to be a very short loop; in fact, it's actually equivalent
> to:
>
>   if (type->base_type == GLSL_TYPE_ARRAY)
>      type = type->fields.array;
>
> since GLSL explicitly disallows arrays of arrays.  That said, it doesn't
> really hurt anything, so I'm more observing this than objecting to the
> code.
>
>
That's a fair point.  I think I prefer to leave it as originally written, on
the theory that if arrays of arrays are ever allowed, then the loop will be
required.  But it's not a strong preference.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20111025/e3bf338b/attachment.htm>


More information about the mesa-dev mailing list