GLSL questions

Hi!
Can’t find in the GLSL specs anything about unary operators (–, ++) in relation to vector types. Are those applicable to vectors or only to the scalar integer types? Example:

ivec2 v = 0;
v++; //Does v go from {0,0} to {1,1} ?

Should one simply understand it like all operators valid for the scalar of type T will work component-wise for vector of type T? Is it so?

Why dont you just try it out? You have a compiler, just ask it what is allowed.

[QUOTE=Yandersen;1262884]Hi!
Can’t find in the GLSL specs anything about unary operators (–, ++) in relation to vector types.[/quote]

The spec is quote clear on this matter:

Emphasis added.

Never ever do this. Compilers, particularly GLSL compilers, can have bugs. You should never assume that some GLSL code is correct just because it happens to work in a compiler.

Thank you, Alfonse! Sorry for being specs-blind from time to time… :slight_smile:

I found a confusing moment there in specs about the matrix constructors:

What about the non-square matrices? If the same method will be used there, this will result in construction of degenerate matrix, which is somewhat senseless. So… Should I be sure that the term “diagonal” refers to the elements defined as (i==j) or for non-square matrices there is some sort of exception not mentioned in specs (or hidden in other places / specs’ versions)?

There is nothing about the use of the term “diagonal” in the context of matrices which requires that the matrix be square. And yes, the diagonal of a matrix are the elements whose row and column indices are identical.

Thank you again, Alfonse!