Login  Register

Compositing brush strokes offscreen

Posted by kitfox on Mar 22, 2012; 4:04pm
URL: https://forum.jogamp.org/Compositing-brush-strokes-offscreen-tp3848844.html

I'm creating a painting application backed by JOGL.  I have a tool that allows the user to click and drag to draw brush strokes on the screen.  

At the moment, the brushstroke drawing code is all being done with BufferedImages.  At the moment the user starts dragging, a BufferedImage is allocated to capture the entire stroke.  Another BufferedImage is also created which is filled with the image of the head of the brush.  As the user drags the mouse, the trajectory is calculated and used to draw many copies of the brush tip image into the stroke collector buffer.  When the user is done, the stroke collector image is then drawn into the scene as a whole.

The above process is quite slow, and since I am already using JOGL to render to the screen, it would be nice if I could do this offscreen task using JOGL too.  The trouble is, I need to compute my stroke buffer as I receive mouse input, so I can't wait until the GLEventListener sends me the GLAutoDrawable.  One option is to create a second rendering context - however, I would like to be able to render the partially completed stroke buffer over top of my image to give the user some visual feedback.  If I'm using two separate GL contexts, I'd have to read the stroke buffer image out of one into the CPU and then write it back into the other.  Being able to do everything in the same GL context would save me that very expensive step.

I'd plan to use framebuffer render-to-texture techniques to do the actual compositing.  How would I set up JOGL so that a Swing thread could jump in and read and write framebuffer textures on the fly?