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 2 of 2

Thread: using built-in functions to initialize constants

  1. #1

    using built-in functions to initialize constants

    Simple question about glsl standard (or about generic compiler included in ShaderDesigner):

    Why is it illegal to use expressions with built-in functions to initialize a constant? For example this shader:
    Code :
    const float f = sqrt( 0.5 );	// ERROR: 0: 1:  '=' :   assigning non-constant to 'const float'
    void main()
    {
    	gl_FragColor = vec4( f );
    }
    In GLSLangSpec.Full.1.10.59.pdf sqrt function defined as
    Code :
    genType sqrt (genType x)
    so if x have type 'const float' so return type should also be 'const float', isn't it?

    Yes, I can remove 'const' and it will compile, but I'm just curious - is this error correct according to standard?

    PS. Nvidia compiler works fine with this code.

  2. #2
    Intern Contributor
    Join Date
    Jul 2004
    Posts
    50

    Re: using built-in functions to initialize constants

    Just a guess: this may be disallowed to avoid having to implement sqrt and other functions in the driver. In other words, the function may only exist on the gpu, but you're asking the driver to use it when you compile the program.

Posting Permissions

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