diff --git a/src/osgViewer/GraphicsWindowIOS.mm b/src/osgViewer/GraphicsWindowIOS.mm index 5bca620b5..0636a6d5f 100644 --- a/src/osgViewer/GraphicsWindowIOS.mm +++ b/src/osgViewer/GraphicsWindowIOS.mm @@ -10,7 +10,7 @@ #import #else #import - #if defined(OSG_GLES3_FEATURES) + #if OSG_GLES3_FEATURES #import #endif @@ -432,9 +432,17 @@ typedef std::map TouchPointsIdMapping; glBindFramebufferOES(GL_FRAMEBUFFER_OES, _msaaFramebuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, _msaaRenderBuffer); - // Samples is the amount of pixels the MSAA buffer uses to make one pixel on the render // buffer. Use a small number like 2 for the 3G and below and 4 or more for newer models + // Samples is the amount of pixels the MSAA buffer uses to make one pixel on the render + // buffer. Use a small number like 2 for the 3G and below and 4 or more for newer models + // NOTE: Formats of draw and read buffers must be identical - glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, _win->getTraits()->samples, GL_RGB5_A1_OES, _backingWidth, _backingHeight); + GLenum internalFormat = GL_RGB5_A1_OES; +# if OSG_GLES3_FEATURES + if ([_context API] == kEAGLRenderingAPIOpenGLES3) + internalFormat = GL_RGBA8_OES; +# endif + + glRenderbufferStorageMultisampleAPPLE(GL_RENDERBUFFER_OES, _win->getTraits()->samples, internalFormat, _backingWidth, _backingHeight); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, _msaaRenderBuffer); glGenRenderbuffersOES(1, &_msaaDepthBuffer); @@ -507,64 +515,68 @@ typedef std::map TouchPointsIdMapping; #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) - if(_msaaFramebuffer) - { - glBindFramebufferOES(GL_FRAMEBUFFER_OES, _msaaFramebuffer); - + if (_msaaFramebuffer) { + // Resolve the contents from the multisampling buffer into the resolve (view) buffer glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, _msaaFramebuffer); glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, _viewFramebuffer); - glResolveMultisampleFramebufferAPPLE(); - - GLenum attachments[] = {GL_DEPTH_ATTACHMENT_OES, GL_COLOR_ATTACHMENT0_OES}; - #ifdef OSG_GLES3_FEATURES - switch ([_context API]) - { - case kEAGLRenderingAPIOpenGLES3: - glBlitFramebuffer(0, 0, _backingWidth, _backingHeight, - 0, 0, _backingWidth, _backingHeight, - GL_COLOR_BUFFER_BIT, GL_LINEAR); - glInvalidateFramebuffer(GL_READ_FRAMEBUFFER_APPLE, 2, attachments); - break; - - default: - glResolveMultisampleFramebufferAPPLE(); - glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments); - break; - } - #else - glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments); - #endif +# if OSG_GLES3_FEATURES + if ([_context API] == kEAGLRenderingAPIOpenGLES3) { + glBlitFramebuffer(0, 0, _backingWidth, _backingHeight, + 0, 0, _backingWidth, _backingHeight, + GL_COLOR_BUFFER_BIT, GL_LINEAR); + } + else + glResolveMultisampleFramebufferAPPLE(); +# else + glResolveMultisampleFramebufferAPPLE(); +# endif } #endif - - //swap buffers (sort of i think?) + // Present Results step glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer); - - //display render in context [_context presentRenderbuffer:GL_RENDERBUFFER_OES]; - //re bind the frame buffer for next frames renders - glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer); - #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) - if (_msaaFramebuffer) - glBindFramebufferOES(GL_FRAMEBUFFER_OES, _msaaFramebuffer);; + if (_msaaFramebuffer) { + // Invalidate (discard) step (must be after present step) + GLenum attachments[] = {GL_DEPTH_ATTACHMENT_OES, GL_COLOR_ATTACHMENT0_OES}; +# if OSG_GLES3_FEATURES + if ([_context API] == kEAGLRenderingAPIOpenGLES3) + glInvalidateFramebuffer(GL_READ_FRAMEBUFFER_APPLE, 2, attachments); + else + glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments); +# else + glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments); +# endif + } #endif + + [self bindFrameBuffer]; } // //bind view buffer as current for new render pass // - (void)bindFrameBuffer { - - //bind the frame buffer - glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer); - #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) - if (_msaaFramebuffer) - glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, _msaaFramebuffer); + if (_msaaFramebuffer) { +# if OSG_GLES3_FEATURES + if ([_context API] == kEAGLRenderingAPIOpenGLES3) { + glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, _msaaFramebuffer); + glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, _viewFramebuffer); + } + else + glBindFramebufferOES(GL_FRAMEBUFFER_OES, _msaaFramebuffer); +# else + glBindFramebufferOES(GL_FRAMEBUFFER_OES, _msaaFramebuffer); +# endif + } + else + glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer); +#else + glBindFramebufferOES(GL_FRAMEBUFFER_OES, _viewFramebuffer); #endif } @@ -1016,7 +1028,7 @@ bool GraphicsWindowIOS:: makeCurrentImplementation() _updateContext = false; } //i think we also want to bind the frame buffer here - //[_view bindFrameBuffer]; +// [_view bindFrameBuffer]; return true; }