OpenGL multisampling not working (and fix)


#1

Hey Jules,

As far as I can tell, OpenGL multisampling isn't working on iOS (current Git checkout as of today) - adding the following lines into the teapot OpenGLDemo constructor makes the OpenGL component render as an empty black box:


openGLContext.setMultisamplingEnabled(true);
OpenGLPixelFormat format;
format.multisamplingLevel = 4;
openGLContext.setPixelFormat(format);

... openGLContext.setRenderer (this); ... etc.

I think additional code is needed in the iOS OpenGLContext::NativeContext::swapBuffers():

   void swapBuffers()
   {
       if (useMSAA)
       {
           glBindFramebuffer(GL_DRAW_FRAMEBUFFER_APPLE, frameBufferHandle);
           glBindFramebuffer(GL_READ_FRAMEBUFFER_APPLE, msaaBufferHandle);
           glResolveMultisampleFramebufferAPPLE();
       }
       ...existing code

Certainly seems to work here?

Steve.


#2

Ah, excellent stuff, ta very much!


#3

Another possible fix for MSAA on iOS. When using FBOs within a multisampled context, the iOS OpenGLFrameBuffer::Pimpl::unbind call is failing.  I think it's because the call to iOS OpenGLContext::NativeContext::getFrameBufferID() is returning the downsampled buffer ID, rather than the multisampled buffer ID and hence subsequent calls are writing to the wrong buffer.

The obvious fix is:

GLuint getFrameBufferID() const noexcept    { return useMSAA ? msaaBufferHandle : frameBufferHandle; }

It seems to work, but there are a couple of other calls to that function, and I'm unsure as to whether either of those calls are expecting the downsampled buffer, so a different fix may be appropriate?


#4

Seems legit! Can't see any problems, and if someone has chosen to use it in multisampled mode then it seems like this is probably what they'd intend to happen. I've checked in these changes now so give me a shout if I've broken anything!


#5

I see some fixes were made to fix some deprecated APPLE-suffixed OpenGL calls for the iOS8 SDK, but seems in the latest version multisampling might be broken? I hit the problem in my own code but reproed using the OpenGLAppExample project on the Github head by adding a couple of lines:

OpenGLAppComponent::OpenGLAppComponent()   : frameCounter (0)
{
    setOpaque (true);
    

// -- lines added here
    juce::OpenGLPixelFormat pixelFormat;
    openGLContext.setMultisamplingEnabled(true);
    pixelFormat.multisamplingLevel = 2;
    openGLContext.setPixelFormat(pixelFormat);

// -- to here

    openGLContext.setRenderer (this);
    openGLContext.attachTo (*this);
    openGLContext.setContinuousRepainting (true);
}


and they result in the following JUCE assert:

JUCE v3.1.0
***** GL_INVALID_OPERATION  at /Users/steve/personaldev/external/juce_master/modules/juce_opengl/opengl/juce_OpenGLContext.cpp : 168
JUCE Assertion failure in juce_opengl.cpp:141

(there's a minor error in the shader in that example with a vec4 missing a precision specifier in the fragment shader, but apart from that this is straight from the example code.)

Problem seems to be consistent between iOS7.1 & 8.1. I'll dig around but if there's anything obvious I'm missing it would be good to know.

Cheers,

Steve.