Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: templates?

  1. #1
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    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:

    Code :
    #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:

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

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: templates?

    Maybe it's just the documentation using "genType", that makes you think that?

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: templates?

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •