Szabolcs Dombi
Szabolcs Dombi

Reputation: 5783

explicit or implicit vec4 in glsl

I found something interesting and I would like to understand it.

Using GLSL #version 330

type of gl_Position is vec4

These lines compile fine:

gl_Position = vec4(0, 0, 0, 0);
gl_Position = vec4(vec3(0, 0, 0), 0);
gl_Position = vec4(vec2(0, 0), vec2(0, 0));
...

Somehow:

gl_Position = (vec2(0, 0), vec2(0, 0));

raises:

error C1035: assignment of incompatible types

The Compiler was able to parse (vec2(0, 0), vec2(0, 0)) without raising syntax error. I want to know what this statement means, I believe it is correct and has a different type then vec4.

Question: What does (vec2(0, 0), vec2(0, 0)) mean in GLSL?

EDIT:

Compiles:

 float x = (0.0, 1.0, 1.0, 2.0, 3.0, 5.0, 8.0);

Syntax error:

 float x = 0.0, 1.0, 1.0, 2.0, 3.0, 5.0, 8.0;

Upvotes: 1

Views: 594

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409176

You use the comma operator, creating one vec2 and then another vec2 and it's the last vec2 that is the result of the expression.

Upvotes: 4

Related Questions