GLSL access!

Started by
3 comments, last by golgoth 18 years, 6 months ago
hi all! can we access variables in opengl form a shader? abstract: uniform float a; uniform float b; varying float c; void main() { c = a + b; } how can we acess "c" once the shader is done? THX
Advertisement
The only way to get data from a shader is to output it to a buffer then read it back.
ok, and how will i do that?
Output whatever data you want from the pixel shader. Use glReadPixels to read it back. It probably won't be very fast so that may not be suitable for whatever it is you're trying to do. If you don't need to access the data on the CPU (ie: use the data in another shader) you can use glCopyTexImage2D or glCopyTexSubImage2D (or the 1D or 3D equivalents) to copy it to a texture. Or you can use the GL_EXT_framebuffer_object extension to render directly into a texture. If you do need the data on the CPU you can use the GL_ARB_pixel_buffer_object extension to use glReadPixels asynchronously, which may offer some speed gains depending on your situation.

EDIT: Just a note... there is no glCopyTexImage3D, only glCopyTexSubImage3D. There is a 1D version of both though.
Thx Kalidor!

since my process is done in one pass only, i think this wont fit! but thx for confirming there is no other ways around!

This topic is closed to new replies.

Advertisement