PDA

View Full Version : templates?



Dark Photon
08-26-2011, 10:15 AM
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))

Ilian Dinev
08-26-2011, 10:57 AM
Maybe it's just the documentation using "genType", that makes you think that?

Dark Photon
08-26-2011, 05:58 PM
You're probably right. The fact that most of the built-in GLSL functions support it out-of-the-box.