Help building a GPU based basic painting application.

Started by
1 comment, last by HexDump 8 years, 11 months ago

Hi,

I have been playing around with a CPU implementation of a painting application. The tools I want to implement are pretty basic paint, floodfill, eraser and do/redo. My platform is android so I'm using opengl-es.

My implementation is pretty slow when using large images because CPU/GPU work is not balanced and we have the always dreaded bus bottleneck when downloading/uploading textures. I could try to implement some kind of "Tiled" implementation to split the canvas I want to draw on in smaller textures and consume gpu bandwith in a more optimized way but I think it is time to start learning a bit about how to do this on the gpu.

Could anyone be so kind to point me in the right direction here? I don't want/need the exact implementation but some guidelines on how to implement this tools. Paint seems to be pretty straightforward. I think I could use my drawing line code to generate geometry for my lines, but for example, how could I implement the eraser tool? I guess some kind of black shading program magic could do the work, but again I'm lost on this subject.

Come'n guys let's discuss best techniques to build this little app.

Cheers.

Advertisement

something like flood fill might not be simple to implement on a GPU. GPUs also have quite different capabilities and precision, that might lead to a lot of custom solutions.

if you had something like a huge guassian blur or a bilateral filter, then I'd agree with you to try it on GPU, but for simple drawing I think your idea about updating just the parts on the GPU that actually really changed sound like the best solution. Drawing those "straightforward" things on CPU shouldn't be slow, it worst case you could vectorize your code with MMX/SSE2/NEON.

Have you ever profiled your app to figure out which part actually accounts for the performance problems? That would be the first step before you spent a lot of time on a GPU solution that might not really solve the source of the problem.

Hi,

Yes I have profiled it. The main problem is the bus bottleneck. Uploading & downloading the texture every 0.1 seconds (this is the delay time I have set for adding new points to a line when drawing) is pretty slow on mobile. This is why I thought about the tiling solution.

On the other hand, I was thinking about doing the flood fill by the cpu because I guessed it could be hard to implement / debug on gpu and I don't mind if it takes a little time to do it and upload the texture to the gpu. The main constraint is found when painting / deleting with the finger. This has to be smooth.

So, do you recomend going with the image tiling solution istead of the GPU one?

P.D: Let me explain the conclusions I have come across while reading about shaders and trying to apply them to my project:

1) Drawing seems simple. I could just make the shader draw the selected brush on a texture I would reserve for the painting without cleaning it every frame and I think everything would work. This texture will then be applied to a cuad covering all screen space.

2) Flood fill. I would do this as I told you using the CPU instead of the gpu.

3) Erasing: This is something I don't know how to do. Perhaps just lowering the alpha of the pixels I want to delete could do the trick?

4) Undo/Redo:

- When undoing and redoing I could keep a list of the lines used for painting or deleting and redo or undo the action. For example, if it is a deletion and I want to redo I would apply the alpha changing values to the positions uploaded to the gpu that represent the path points the user draw while deleting. For the flood fill actions... they will agin be undo/redo on the cpu.

Obviously for 1,3 and 4 I would need a line drawing algorithm on gpu. Don't really know if all mobile devices can do this.

What do you think?

Cheers.

This topic is closed to new replies.

Advertisement