Results 1 to 2 of 2

Thread: Accessing array values from a shader

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2014

    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;

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

Similar Threads

  1. Offset incorrect when accessing array
    By svcop3 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-10-2016, 11:15 AM
  2. Replies: 0
    Last Post: 04-24-2014, 09:28 AM
  3. Replies: 1
    Last Post: 09-11-2012, 07:19 PM
  4. Accessing array elements
    By yossi in forum OpenGL: GLSL
    Replies: 1
    Last Post: 05-19-2004, 09:12 PM
  5. accessing an array faster
    By divide in forum OpenGL: General
    Replies: 6
    Last Post: 02-10-2004, 03:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean