ofxFBOFloatTexture - Very Simple GPU Computing

Well, I feel a bit small next to the previous “ofxOpenCL” topic but I’m trying to understand a bit better how GPU Computing works in general.

I’ve just finished to read the excellent tutorial from Dominik Göddeke on this topic so I wrote a little addon…

I’m still learning a lot in C++ and OpenGL so I’m pretty sure we can do things better and I would love to hear what you guys are thinking about this class (less upload/download time?).


As I’m not just uploading data, you will need ofxShader to run the example.

Anyway the class is really easy to use…

create a float array:

float* data = (float*)malloc(4*textSize*textSize*sizeof(float));  

upload it to the gpu:


activate your shader and then call the compute method like that:


then if you want you can download back the data


you can also switch the input and output texture so you can apply more shaders.


The main problem is still the uploading and downloading performances (most of time I guess you don’t need to do it every frame), so maybe someone has an idea on how to do that differently?!



Note: This addon was written thanks to Zach Gage who wrote a very clean and understandable fbo code… it really helps me getting into fbos and stuffs like that! Cheers for that!


hey thats wicked! it’s like you’ve written your own version of opencl :stuck_out_tongue:

P.S. ideally you shouldn’t ever need to keep reading back and forth between ram and graphics card. You should just send all your init data once, and then keep updating everything on gpu. Any external events like input, parameters etc. you can send through uniforms - or if its large data, send them in as small textures.

Thanks Memo!

I know you should do each transfers only once at the beginning of your application but actually sometimes you really need to update big things … So it would rocks if someone knows how to make it faster!

For example I’m using this addon for a GPU verlet engine that react to some blob tracking, so if I want my particle system to be aware of the peoples in front of the camera I have no choices… Until someone make something like CVSL where all the computer vision will be done on the gpu I definitively need to upload the new data every frame!

Maybe in my case I could find some crazy arithmetic to send all my floats with a texture (hehe! it’s kind of funny to write that after developing something named ofxFloatTexture)… the problem actually is that I create some normal map of the blobs with two sobel filters and that I need to convert my opencv float image to an opengl float texture… and that I need that for … tomorrow!

You mean like this? :wink:

Actually most of this is pretty basic. Why aren’t you doing it all on the gpu? With your float texture class 90% of the work is done! Image differencing, thresholding etc. is very straightforward. If you already have the sobel filter you have the edges as well. You can put your entire process in a single shader (subtract background, apply threshold, find edges). Of course if you apply a little blur to remove noise that would have to be a few extra passes.

*EDIT* actually you can’t do the sobel in the same pass as the background subtraction. But you can do one pass for greyscale+background subtraction+threshold. then do another pass for the sobel.

Oh my god!
You are an evil man!
Well it’s still for tomorrow, so I guess I will stick with the cpu version :stuck_out_tongue:
But I will definitively do something soon! Thanks for showing me this, it gave me more hope!

btw, there are a few GPU CV libraries for windows, if you are on windows. E.g. OpenVidia, GPUCV etc. all for windows, none for mac :frowning:

Are all textures float textures? Can the values go negative?