On 25 October 2011 16:55, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 10/25/2011 04:47 PM, Paul Berry wrote:<br>
> This function is similar to get_base_type(), but when called on<br>
> arrays, it returns the scalar type composing the array. For example,<br>
> glsl_type(vec4[]) => float_type.<br>
> ---<br>
> src/glsl/glsl_types.cpp | 23 +++++++++++++++++++++++<br>
> src/glsl/glsl_types.h | 11 +++++++++++<br>
> 2 files changed, 34 insertions(+), 0 deletions(-)<br>
><br>
> diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp<br>
> index c94aec0..03e9987 100644<br>
> --- a/src/glsl/glsl_types.cpp<br>
> +++ b/src/glsl/glsl_types.cpp<br>
> @@ -258,6 +258,29 @@ const glsl_type *glsl_type::get_base_type() const<br>
> }<br>
><br>
><br>
> +const glsl_type *glsl_type::get_scalar_type() const<br>
> +{<br>
> + const glsl_type *type = this;<br>
> +<br>
> + /* Handle arrays */<br>
> + while (type->base_type == GLSL_TYPE_ARRAY)<br>
> + type = type->fields.array;<br>
<br>
</div>This is going to be a very short loop; in fact, it's actually equivalent to:<br>
<br>
if (type->base_type == GLSL_TYPE_ARRAY)<br>
type = type->fields.array;<br>
<br>
since GLSL explicitly disallows arrays of arrays. That said, it doesn't<br>
really hurt anything, so I'm more observing this than objecting to the code.<br>
<div><br></div></blockquote><div><br>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.<br>
</div></div>