Draw OpenGL Framebuffer/Texture via Graphics::drawImage


Shared OpenGL context issues aside, Is it possible to render the contents of an FBO in the components paint method, providing the texture is in a trivial format?

I have a node-based system that compiles down to bytecode and is rendered using an OpenGL stack-VM into multiple FBO’s, It would be useful to have preview windows on the nodes to see what effect that node is having at each stage.

I know I can get the pixel data copied to the CPU but as I’m using OpenGL to render the components anyway, can I pass an FBO to Graphics::drawImage and it be rendered as an image?

Is there any support for this or will I need to hack it in?

Kind regards,

There is the OpenGLImageType class, but it sounds like the reverse of what you want… it creates Image that map to FBOs instead of the other way around.

If you make a JUCE image of the same format and size, you could possibly use BitmapData and make it point to your FBO’s data store instead… but I haven’t tried that and it sounds like it has a high chance of causing issues, so copying the image over like you’re doing might be the only available method.

Yeah, I saw that.

I briefly looked into how images are drawn with an OpenGLContext and it attempts to pull a OpenGLFramebuffer out of the image class (I assume for caching), Looks like I can possibly intercept this and return my own framebuffer object.

I just need to sit down and actually attempt it. For now, the CPU copy works but the graphs can get quite large. Perhaps I should just implement a caching mechanism instead of copying the pixels each iteration.

Thanks for your help :slight_smile:

1 Like