[*] osgViewer::GraphicsWindowIOS fixes

This commit is contained in:
konstantin.matveyev 2017-07-30 19:58:56 +03:00
parent 0c1fad2c91
commit 7e5a9582b3

View File

@ -10,7 +10,7 @@
#import <OpenGLES/ES1/glext.h> #import <OpenGLES/ES1/glext.h>
#else #else
#import <OpenGLES/ES2/glext.h> #import <OpenGLES/ES2/glext.h>
#if defined(OSG_GLES3_FEATURES) #if OSG_GLES3_FEATURES
#import <OpenGLES/ES3/glext.h> #import <OpenGLES/ES3/glext.h>
#endif #endif
@ -432,9 +432,17 @@ typedef std::map<void*, unsigned int> TouchPointsIdMapping;
glBindFramebufferOES(GL_FRAMEBUFFER_OES, _msaaFramebuffer); glBindFramebufferOES(GL_FRAMEBUFFER_OES, _msaaFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _msaaRenderBuffer); 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); glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, _msaaRenderBuffer);
glGenRenderbuffersOES(1, &_msaaDepthBuffer); glGenRenderbuffersOES(1, &_msaaDepthBuffer);
@ -507,64 +515,68 @@ typedef std::map<void*, unsigned int> TouchPointsIdMapping;
#if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0) #if defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)
if(_msaaFramebuffer) if (_msaaFramebuffer) {
{ // Resolve the contents from the multisampling buffer into the resolve (view) buffer
glBindFramebufferOES(GL_FRAMEBUFFER_OES, _msaaFramebuffer);
glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, _msaaFramebuffer); glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, _msaaFramebuffer);
glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, _viewFramebuffer); glBindFramebufferOES(GL_DRAW_FRAMEBUFFER_APPLE, _viewFramebuffer);
glResolveMultisampleFramebufferAPPLE(); # if OSG_GLES3_FEATURES
if ([_context API] == kEAGLRenderingAPIOpenGLES3) {
GLenum attachments[] = {GL_DEPTH_ATTACHMENT_OES, GL_COLOR_ATTACHMENT0_OES};
#ifdef OSG_GLES3_FEATURES
switch ([_context API])
{
case kEAGLRenderingAPIOpenGLES3:
glBlitFramebuffer(0, 0, _backingWidth, _backingHeight, glBlitFramebuffer(0, 0, _backingWidth, _backingHeight,
0, 0, _backingWidth, _backingHeight, 0, 0, _backingWidth, _backingHeight,
GL_COLOR_BUFFER_BIT, GL_LINEAR); 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 else
glDiscardFramebufferEXT(GL_READ_FRAMEBUFFER_APPLE, 2, attachments); glResolveMultisampleFramebufferAPPLE();
#endif # else
glResolveMultisampleFramebufferAPPLE();
# endif
} }
#endif #endif
// Present Results step
//swap buffers (sort of i think?)
glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer); glBindRenderbufferOES(GL_RENDERBUFFER_OES, _viewRenderbuffer);
//display render in context
[_context presentRenderbuffer:GL_RENDERBUFFER_OES]; [_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 defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)
if (_msaaFramebuffer) if (_msaaFramebuffer) {
glBindFramebufferOES(GL_FRAMEBUFFER_OES, _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 #endif
[self bindFrameBuffer];
} }
// //
//bind view buffer as current for new render pass //bind view buffer as current for new render pass
// //
- (void)bindFrameBuffer { - (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 defined(__IPHONE_4_0) && (__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0)
if (_msaaFramebuffer) if (_msaaFramebuffer) {
glBindFramebufferOES(GL_READ_FRAMEBUFFER_APPLE, _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 #endif
} }
@ -1016,7 +1028,7 @@ bool GraphicsWindowIOS:: makeCurrentImplementation()
_updateContext = false; _updateContext = false;
} }
//i think we also want to bind the frame buffer here //i think we also want to bind the frame buffer here
//[_view bindFrameBuffer]; // [_view bindFrameBuffer];
return true; return true;
} }