On 06/18/2013 06:47 AM, Ian Romanick wrote:
On 06/18/2013 04:22 AM, Kenneth Graunke wrote:
This patch introduces new functions to quickly grab a pointer to a
vector type. For example:
glsl_type::bvec(4) returns glsl_type::bvec4_type
glsl_type::ivec(3) returns glsl_type::ivec3_type
glsl_type::uvec(2) returns glsl_type::uvec2_type
glsl_type::vec(1) returns glsl_type::float_type
This is less wordy than glsl_type::get_instance(GLSL_TYPE_BOOL, 4, 1),
which can help avoid extra word wrapping.
One thing that's annoying about this code is that we have so many ways
to get at types. You can get them from a symbol table, you can get them
from the direct pointers, you can get them from pointer math, or you can
get them from get_instance. I'm not sure replacing one with another
makes it much better.
I remember considering having separate overloads of get_instance for
vectors and matrices. I don't recall why I didn't do it that way.
Signed-off-by: Kenneth Graunke <kenn...@whitecape.org>
---
src/glsl/glsl_types.cpp | 52
+++++++++++++++++++++++++++++++++++++++++++++++++
src/glsl/glsl_types.h | 9 +++++++++
2 files changed, 61 insertions(+)
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index df9c5d3..a5491c5 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -534,6 +534,58 @@ glsl_type::glsl_type(const glsl_type *array,
unsigned length) :
}
+const glsl_type *const
+glsl_type::vec(unsigned components)
+{
+ if (components == 0 || components > 4)
+ return error_type;
+
+ static const glsl_type *const ts[] = {
+ float_type, vec2_type, vec3_type, vec4_type
+ };
+ return ts[components - 1];
We could just embed this code in get_instance. That seems better than
adding new methods that are only used in method that's part of the same
class.
They're also used in patch 3, outside the class. That was the
motivation for adding them...and I thought it was a bit tidier this way.
But if you'd prefer just putting this in get_instance, that's fine by
me...it's what I originally did in v0 of this series anyway.
--Ken
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev