View Full Version : GLSL questions

Yandersen

12-08-2014, 02:41 PM

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?

Cornix

12-08-2014, 03:20 PM

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

Alfonse Reinheart

12-08-2014, 03:36 PM

Hi!

Can't find in the GLSL specs anything about unary operators (--, ++) in relation to vector types.

The spec is quote clear on this matter: (https://www.opengl.org/registry/doc/GLSLangSpec.4.50.pdf#page=109)

The arithmetic unary operators negate (-), post- and pre-increment and decrement (-- and ++) operate on integer or floating-point values (including vectors and matrices). All unary operators work component-wise on their operands. These result with the same type they operated on. For post- and pre-increment and decrement, the expression must be one that could be assigned to (an l-value). Pre-increment and pre-decrement add or subtract 1 or 1.0 to the contents of the expression they operate on, and the value of the pre-increment or pre-decrement expression is the resulting value of that modification. Post-increment and post-decrement expressions add or subtract 1 or 1.0 to the contents of the expression they operate on, but the resulting expression has the expression’s value before the post-increment or post-decrement was executed.

Emphasis added.

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

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.

Yandersen

12-08-2014, 04:44 PM

Thank you, Alfonse! Sorry for being specs-blind from time to time... :)

Yandersen

12-10-2014, 08:38 AM

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

If there is a single scalar parameter to a matrix constructor, it is used to initialize all the components on the matrix’s diagonal, with the remaining components initialized to 0.0.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)?

Alfonse Reinheart

12-10-2014, 10:04 AM

There is nothing about the use of the term "diagonal" in the context of matrices which requires that the matrix be square. (https://en.wikipedia.org/wiki/Diagonal_matrix) And yes, the diagonal of a matrix are the elements whose row and column indices are identical.

Yandersen

12-10-2014, 10:09 AM

Thank you again, Alfonse!

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.