pouët.net

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?
added on the 2011-02-11 18:19:55 by Danguafer Danguafer
Yea, if you pass it in as a texture and readback the data using glReadBuffer. I think the term you're looking for is GPGPU.

You sure you're not looking for something like OpenCL or CUDA?
added on the 2011-02-11 18:34:34 by hornet hornet
Search for Transform Feedback (you won't find anything useful, but that's the name)
added on the 2011-02-11 18:44:52 by xernobyl xernobyl
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.
added on the 2011-02-11 19:25:07 by decipher decipher
hehehe shhhhh!! :D
added on the 2011-02-11 19:36:08 by ferris ferris
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
added on the 2011-02-11 20:08:18 by Danguafer Danguafer
Try to look at glUniform*, you can directly modify an array (or just a variable) of specified type, and glGetUniform* to get his value.
added on the 2011-02-11 21:17:18 by stfsux stfsux
You are talking about the opposite. I want to change them in the shaders.
added on the 2011-02-11 23:11:42 by Danguafer Danguafer
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.
added on the 2011-02-12 03:01:04 by xernobyl xernobyl
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 :-)
WebGL uses OpenGL ES 2.0, and there's no transform feedback in OpenGL ES 2.0. glReadPixels is your best bet.
added on the 2011-02-12 09:59:04 by kusma kusma
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
added on the 2011-02-12 11:15:01 by stfsux stfsux
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?
added on the 2011-02-12 11:47:24 by kusma kusma
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.
added on the 2011-02-12 12:12:22 by decipher decipher
Quote:

GLSL uniform variables are implicitly constant.

Damn... I didn't know that... what a pity. :(
added on the 2011-02-12 16:40:23 by stfsux stfsux
Ye, glReadPixels is my best bet. But I think that it will be deprecated, 'cause it's possible to access the data through Canvas.
added on the 2011-02-12 19:59:34 by Danguafer Danguafer

login