OpenGL, GLSL and data communication
category: code [glöplog]
Hello,
Is it possible to give an array to the shader, process and return it to the main program?
Is it possible to give an array to the shader, process and return it to the main program?
Search for Transform Feedback (you won't find anything useful, but that's the name)
Danguafer: We do something very similar for modelling meshes on the GPU and streaming out for storage. The idea is to use a combination of textures, glReadBuffer and glReadPixels. Though, it's not that simple, you need to have rock solid intel on the internal format of your textures and what comes out of glReadPixels.
Shameless self-plug: I'll soon document the technique here. Might even share some code.
Shameless self-plug: I'll soon document the technique here. Might even share some code.
hehehe shhhhh!! :D
Actually, I'm trying to use WebGL/GLSL for parallel processing.
I thought that there was another way to accomplish that. I could only find glReadPixels.
And, Decipher, tell when it's done. :D
I thought that there was another way to accomplish that. I could only find glReadPixels.
And, Decipher, tell when it's done. :D
Try to look at glUniform*, you can directly modify an array (or just a variable) of specified type, and glGetUniform* to get his value.
You are talking about the opposite. I want to change them in the shaders.
You can store the output of a vertex shader / geometry shader directly to a buffer using transform feedback and then copy that buffer to wherever you want it.
As said, store your data as 4-floats in a texture and glreadpixel that to get input from shader and gluniform for sending to the shader.
it's not nice, but i bet that the current glsl was build for generating data to the cpu :-)
it's not nice, but i bet that the current glsl was build for generating data to the cpu :-)
WebGL uses OpenGL ES 2.0, and there's no transform feedback in OpenGL ES 2.0. glReadPixels is your best bet.
Quote:
You are talking about the opposite. I want to change them in the shaders.
I´m talking about the 2 ways.
Quote:
Is it possible to give an array to the shader
glUniform1fv (for example)
Quote:
process
Your array, in the shader, just need to be declared as uniform.
Quote:
and return it to the main program
glGetUniform1fv
kernel_error: You can't write to a uniform from a shader, glGetUniform1fv will return the same value as was previously set with glUniform1fv. So what's the point in doing any processing if you get the same value back?
kernel_error: You're wrong. GLSL uniform variables are implicitly constant. Trying to change them is absolutely erroneous and will result in a compiler error.
Quote:
GLSL uniform variables are implicitly constant.
Damn... I didn't know that... what a pity. :(
Ye, glReadPixels is my best bet. But I think that it will be deprecated, 'cause it's possible to access the data through Canvas.