View Full Version : Accessing array values from a shader

05-02-2014, 08:00 AM
Suppose I have an array variable in a shader, declared in a shader storage block:

layout(std430, binding = 2) buffer MyBuffer
float lotsOfFloats[];

and a struct:

struct myStruct
float f1;
vec3 vf1;

Is there a way to "quickly" initialize an object of this structure in a shader using the values in the array in a buffer storage block ( in the lotsOfFloats array in this example)? Say, in C++ one can copy memory from the array to the object:

memcpy(&struct1, &lotsOfFloats[0], sizeof(myStruct) );

Or one can byte copy array values to the object through assignment:

struct1 = *(myStruct*)&lotsOfFloats[0];

Is there a similar way in GLSL? E.g. will work the second way (byte copy assignment) in GLSL?

05-02-2014, 10:27 AM
Well, as has been advised elsewhere, the solution to this question is that one can pass to a shader already formatted data (array of structs) instead of raw floats.