PDA

View Full Version : using built-in functions to initialize constants



grisha
12-07-2004, 12:45 PM
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:

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

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.

gmeed
12-07-2004, 04:37 PM
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.