Search code examples
glslshader

How to copy an array in GLSL?


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


Solution

  • 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.