Offscreen Framebuffer objects

Im new to jogl (but ive done some opengl in c in the past) and im struggling to do some offscreen rendering. Basically im trying to do some basic image filtering using shaders.

I’ve successfully accomplished this using the builtin GLPbuffer class but the performance of Screenshot.readToBufferedImage is really poor. I know that you can get better performance from glReadPixels (and thus Screenshot.readToBufferedImage) if you use framebuffer objects with rendberbuffers. However I don’t know how to make a valid opengl context and GL object to use.

I tried using GLDrawableFactory.createExternalContext but you need a context to be current in order to do this.

I guess i could make a small glpbuffer in the background to create a context immediately on that thread, but it seems like a big hack.

What is the preferred method for doing this in jogl?
Thanks.

I haven’t actually implemented something like this before, although I’ve read a bit about it and been meaning to. I think that the poor performance of Screenshot.readToBufferedImage is probably largely because of use of glReadPixels internally. If your goal is to process the data using a shader, then you want to avoid anything that reads it into normal memory since it will be slow and unnecessary. I suggest you read http://www.gamedev.net/reference/articles/article2331.asp. You want to make your FBO and render into a texture as described there, then bind / pass in the texture handle as a parameter to your shader so that it can access the data directly. I’ll say it again - for this application, glReadPixels is not your friend. You’ll be using the same GL context for the off-screen rendering; a good thing, since you want to re-use the same texture data.

Good luck.

I know that glReadPixels is fundamentally a slow operation. but renderbuffers were invented not only to make rending to textures easier but also to make glReadPixels faster. Plus I need to read the image data back into a BufferedImage to integrate this with the resto of mmy product, so getting around a call to glReadPixels is not really an option.

But fundamentally my problem right now is creating a valid jogl GLContext for my offscreen fbo, since im not using any of the built in GLDrawables.

If you are on a desktop using AGP, then glReadPixels is going to be slow.
It is possible to get decent speed if you are using PCIe. For example, reading
back 640x480 at 60fps is possible on PCIe.

You also need to be careful about the pixel formats. There are only a few
‘fast paths’ and on Windows, BGRA is the fast path such that the driver
does not have to perform additional swizzling of the RGB components.

If your card/driver supports FBOs, use that. FBOs are much easier and faster
than PBuffers. Note that the ARB has already approved this extension even
though it still has a EXT suffix to the method names.

.rex