templates?

I have this vague recollection that there’s some kind of genericity/abstract type feature in GLSL that gets you something similar to template functions in C++, but I can’t find it. Does it exist?

That is, something which avoids you having to do this:


#define FOO_TEMPLATE(TTYPE) \
TTYPE foo( TTYPE tc, TTYPE N, TTYPE M ) \
{ \
return tc * (M-1)/N + 0.5/N ; \
}

FOO_TEMPLATE(float)
FOO_TEMPLATE(vec2)
FOO_TEMPLATE(vec3)
FOO_TEMPLATE(vec4)

Please ignore the fact that in this simple case I could just make this a macro to get around the problem:


#define FOO(tc,N,M) ((tc) * ((M)-1)/(N) + 0.5/(N))

Maybe it’s just the documentation using “genType”, that makes you think that?

You’re probably right. The fact that most of the built-in GLSL functions support it out-of-the-box.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.