Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Accessing array values from a shader

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2014
    Posts
    7

    Accessing array values from a shader

    Suppose I have an array variable in a shader, declared in a shader storage block:

    Code :
    layout(std430, binding = 2) buffer MyBuffer
    {
      float lotsOfFloats[];
    };

    and a struct:

    Code :
    struct myStruct
    {
     float f1;
     vec3 vf1;
    }struct1;

    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:

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

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

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

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

  2. #2
    Junior Member Newbie
    Join Date
    Apr 2014
    Posts
    7
    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •