TheMax3131's picture

How to store/read data on GPU and CPU

Hi everybody,

I wonder how structure to use to store (in the vertex shader program) and read (in the host program) data. Is there a kind of a float[] array in GLSL? Can i use it in the vertex shader program and read it in the host program?

Thank's for reading this message!


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mOfl's picture

Depends on what you want to accomplish. There are, of course, several ways of storing data in the video memory. You can store per-vertex attributes in Vertex Buffer Objects and all sort of (uniform) data in Uniform Buffer Objects. On newer cards, you can also store information in optimized textures, namely Texture Buffer Objects. Storing data on any other type of texture is possible, too. GLSL also supports arrays that are used in C fashion, i.e.

float myArray[3];
myArray[0] = 1.0f;

which can be set the usual way - you just need to use the vector versions of the glUniform commands, i.e. instead of

you use
Using the buffer objects, however, will usually be more performant.

If you want to read back data from the shader, you usually write (draw) it into a texture in your fragment shader. The texture could be read from your application afterwards. Edited: This was false information. Another method would be to use Transform Feedback which allows you to write varying vertex attributes to buffer objects right after the vertex or - if you use one - geometry shader stage, which can also be read afterwards from your application.