Problem in dynamic loop


I’m learning about GLSL.
Appearing below is a GLSL fragment source code I wrote for experiment.

uniform int			N_LOOP;
void main(void)
	int i;
	float tmp=0.0f;
	for(i=0; i<N_LOOP; i++){
		tmp	+= 0.1f;
	gl_FragColor	= vec4(tmp, 0.0, 0.0, 0.0);

And, I set N_LOOP by written the below code.

glUniform1iARB(glGetUniformLocationARB(_programObject, "N_LOOP"), nLoop);

I think that the result of this program is depend on nLoop but the result I got was similar to vec4(0.1, 0.0, 0.0, 0.0).
It seems that for-loop doesn’t works dynamically.

Does GLSL support dynamic loop like I used above ?
(Is this written in specification or FAQ ?
I didn’t find such description.)

Would you please give me some advice ?

My execution environment is GeForce6800GT(AGP).
When I wrote same program in HLSL and executed, the result is similar to (0.1*N_LOOP, 0.0, 0.0, 0.0).

Should work. What driver are you running?

You have errors.

0.1f should be 0.1
Get rid of the "f"s and turn on strict GLSL support with NVEmulate.

Thanks V-man.

I changed code from 1.0f to 1.0, and executed program.
As a result, I got a correct result.
Then, I changed code from 1.0 to 1.0f for confirmation.
As a result, I got a correnct result, too.

I don’t understand why my code works correctly, but it is truth that result is correctly.
I hated to bother you about this.

What is the value of N_LOOP?

The GLSL spec says

The consequences of very long or non-terminating loops are platform dependent.
On your hardware, the max count loop is 255. If you exceed this limit, no error is generated but the results are undefined.



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