Writing Structured Data

In the beginning of the section, we mentioned reading and writing structured data. If all you had was an array of vec4, you probably could get by with using image buffers. However, if you really have a collection of structured objects, where each is a heterogeneous collection of types, image buffers would become quite cumbersome. With shader storage buffers, however, you get full use of GLSL structure definitions and arrays to define the layout of your buffer. See the example in Example 11.7 to get the idea.

Example 11.7. Declaration of Structured Data

#version 430 core// structure of a single data itemstruct ItemType {    int count;    vec4 data[3];    // ... other fields};// declare a buffer ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.