Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy an array in GLSL?

Tags:

glsl

shader

I searched for 'copy' in the SL reference and couldn't find anything related.

If I have:

float a[3] = float[3] (1.0,2.0,3.0);
float b[3] = a;

Is b now pointing to a? If I change b[0] would that alter a[0]? If the answer is yes, is there a copy function that I could use to a get a clone of a and not point to it? thanks

like image 570
Jeff Saremi Avatar asked Oct 17 '22 15:10

Jeff Saremi


1 Answers

See GLSL - The OpenGL Shading Language 4.6; 5.8. Assignments; page 114

Assignments of values to variable names are done with the assignment operator (=):

lvalue-expression = rvalue-expression

The lvalue-expression evaluates to an l-value. The assignment operator stores the value of r-value-expression into the l-value and returns an r-value with the type and precision of lvalue-expression.

In glsl there is nothing like a pointer or reference or even a "move" assignment. Values are always copied.

like image 101
Rabbid76 Avatar answered Oct 27 '22 10:10

Rabbid76