Reputation: 15
I have got a texture which is updated from a fragment shader that calculates points positions.
What is the good way to read it back so it could be drawn as primitives ?
Upvotes: 1
Views: 352
Reputation: 17396
If you want to draw using the data from the texture, reading back to host memory is a waste and slow (But for reference you could use glGetTexImage
or glReadPixels
).
Instead, you can draw primitives without providing vertex positions and read them from your texture in the vertex shader (bound as a sampler and using texelFetch
for example).
The coordinates for texel fetch can come from a per-vertex attribute (just like regular texture coordinates), or you can use gl_VertexID
to calculate them implicitly.
As @ColonelThirtyTwo said, you can also use transform feedback. Not using your texture and doing the computation in the fragment shader, but replacing it with computation in a vertex shader. Here the varying variables normally interpolated to the fragment shader get packed and saved in a buffer, still on the GPU.
Upvotes: 1