Search code examples
javaopengl3djoglmultisampling

JOGL FBObject multisampling


I am using JOGL to develop a simple OpenGL 3D graphics engine. Right now, I've implemented a simple rendering pipeline which renders the scene onto a FBO, which then gets passed to a shader that renders the FBO's color texture to the screen, optionally applying some post-process effect, such as a blur.

Without using FBOs, it's very easy to enable nice-looking multisampling with JOGL. For instance, since I'm hosting my GL panel inside Swing, I'm using a GLJPanel and creating it like so, to enable multisampling:

GLCapabilities caps = new GLCapabilities(null);
caps.setSampleBuffers(true);
caps.setNumSamples(8);
GLJPanel gljp = new GLJPanel(caps);

This is pretty straightforward and leads to nice-looking results. However, this isn't very useful when the geometry must first get drawn to a FBO. The best way to do this is to just attach a GL_TEXTURE_2D_MULTISAMPLE to the FBO, render the scene, and then performing the multisampling in the fragment shader of the second pass.

Although JOGL provides a rather extensive FBObject class to help manage FBOs, I failed to find a way to get it to render to a multisampled texture (it only allows working with TextureAttachment objects, which are hardcoded to work only with TEXTURE_2D resources). I thus resorted to simply using the provided FBObject as a skeleton, but doing most of the work with plain gl.gl* calls. I know this isn't hacky or anything, and perhaps a "cleaner" solution would just be to extend TextureAttachment and create a class dedicated to multisampled textures.

I'm just wondering - am I missing something, or does JOGL really not support FBOs with multisampled textures?


Solution

  • In case anyone is looking for the same answer, I actually just stopped using FBObjects altogether, and I'm currently using plain old gl.gl* commands for managing my framebuffers (including my new deferred renderer's GBuffer).