--- old/modules/graphics/src/main/native-glass/mac/GlassFrameBufferObject.h 2015-03-17 18:08:23.000000000 -0700 +++ new/modules/graphics/src/main/native-glass/mac/GlassFrameBufferObject.h 2015-03-17 18:08:23.000000000 -0700 @@ -38,10 +38,12 @@ GLuint _texture; GLuint _fbo; GLuint _fboToRestore; + BOOL _isSwPipe; } - (void)blitFromFBO:(GlassFrameBufferObject*)other_fbo; - (GLuint)texture; - (GLuint)fbo; +- (void)setIsSwPipe:(BOOL)isSwPipe; @end --- old/modules/graphics/src/main/native-glass/mac/GlassFrameBufferObject.m 2015-03-17 18:08:24.000000000 -0700 +++ new/modules/graphics/src/main/native-glass/mac/GlassFrameBufferObject.m 2015-03-17 18:08:24.000000000 -0700 @@ -190,6 +190,7 @@ self->_height = 0; self->_texture = 0; self->_fbo = 0; + self->_isSwPipe = NO; [self _assertContext]; if ([self _supportsFbo] == NO) @@ -228,14 +229,54 @@ [self _assertContext]; { if ((width > 0) && (height > 0)) - { + { + if(self->_isSwPipe) + { + self->_fboToRestore = 0; // default to screen + glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, (GLint*)&self->_fboToRestore); + LOG(" will need to restore to FBO: %d", self->_fboToRestore); + } + [self _createFboIfNeededForWidth:width andHeight:height]; + + if (self->_isSwPipe && (self->_fbo != 0)) + { + GLuint framebufferToBind = self->_fbo; // our own FBO + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferToBind); + LOG(" bounded to FBO: %d", self->_fbo); + } } } LOG(" BOUND"); LOG(" glGetError(): %d", glGetError()); } +- (void)unbind +{ + if (self->_isSwPipe) + { + LOG(" GlassFrameBufferObject unbind"); + [self _assertContext]; + { + GLint framebufferCurrent = 0; + glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &framebufferCurrent); + + if ((GLuint)framebufferCurrent != self->_fbo) + { + fprintf(stderr, "ERROR: unexpected fbo is bound! Expected %d, but found %d\n", self->_fbo, framebufferCurrent); + } + + if (![GlassApplication syncRenderingDisabled]) { + glFinish(); + } + GLuint framebufferToRevertTo = self->_fboToRestore; + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebufferToRevertTo); + LOG(" restored to FBO: %d", framebufferToRevertTo); + LOG(" glGetError(): %d", glGetError()); + } + } +} + - (void)blitForWidth:(GLuint)width andHeight:(GLuint)height { LOG(" GlassFrameBufferObject blitForWidth:%d andHeight:%d [%p]", width, height, self); @@ -294,4 +335,9 @@ return self->_fbo; } +- (void)setIsSwPipe:(BOOL)isSwPipe +{ + self->_isSwPipe = isSwPipe; +} + @end --- old/modules/graphics/src/main/native-glass/mac/GlassLayer3D.h 2015-03-17 18:08:25.000000000 -0700 +++ new/modules/graphics/src/main/native-glass/mac/GlassLayer3D.h 2015-03-17 18:08:25.000000000 -0700 @@ -42,7 +42,8 @@ - (id)initWithSharedContext:(CGLContextObj)ctx andClientContext:(CGLContextObj)clCtx - withHiDPIAware:(BOOL)HiDPIAware; + withHiDPIAware:(BOOL)HiDPIAware + withIsSwPipe:(BOOL)isSwPipe; - (uint32_t)getRemoteLayerIdForServer:(NSString*)serverName; - (void)hostRemoteLayerId:(uint32_t)layerId; --- old/modules/graphics/src/main/native-glass/mac/GlassLayer3D.m 2015-03-17 18:08:25.000000000 -0700 +++ new/modules/graphics/src/main/native-glass/mac/GlassLayer3D.m 2015-03-17 18:08:25.000000000 -0700 @@ -68,6 +68,7 @@ - (id)initWithSharedContext:(CGLContextObj)ctx andClientContext:(CGLContextObj)clCtx withHiDPIAware:(BOOL)HiDPIAware + withIsSwPipe:(BOOL)isSwPipe { LOG("GlassLayer3D initWithSharedContext]"); self = [super init]; @@ -77,8 +78,8 @@ self->_remoteLayer = nil; self->_remoteLayerID = 0; - self->_painterOffscreen = [[GlassOffscreen alloc] initWithContext:clCtx]; - self->_glassOffscreen = [[GlassOffscreen alloc] initWithContext:ctx]; + self->_painterOffscreen = [[GlassOffscreen alloc] initWithContext:clCtx andIsSwPipe:isSwPipe]; + self->_glassOffscreen = [[GlassOffscreen alloc] initWithContext:ctx andIsSwPipe:isSwPipe]; [self->_glassOffscreen setLayer:self]; LOG(" GlassLayer3D context: %p", ctx); --- old/modules/graphics/src/main/native-glass/mac/GlassOffscreen.h 2015-03-17 18:08:26.000000000 -0700 +++ new/modules/graphics/src/main/native-glass/mac/GlassOffscreen.h 2015-03-17 18:08:26.000000000 -0700 @@ -32,6 +32,7 @@ // as destination (to draw into) - (void)bindForWidth:(GLuint)width andHeight:(GLuint)height; +- (void)unbind; // as source (to show) - (GLuint)texture; @@ -47,9 +48,9 @@ { CGLContextObj _ctx; CGLContextObj _ctxToRestore; - + id _offscreen; - + GLboolean _dirty; GLfloat _backgroundR; @@ -60,7 +61,8 @@ CAOpenGLLayer* _layer; } -- (id)initWithContext:(CGLContextObj)ctx; +- (id)initWithContext:(CGLContextObj)ctx + andIsSwPipe:(BOOL)isSwPipe; - (CGLContextObj)getContext; - (void)setBackgroundColor:(NSColor*)color; --- old/modules/graphics/src/main/native-glass/mac/GlassOffscreen.m 2015-03-17 18:08:27.000000000 -0700 +++ new/modules/graphics/src/main/native-glass/mac/GlassOffscreen.m 2015-03-17 18:08:27.000000000 -0700 @@ -43,6 +43,7 @@ @implementation GlassOffscreen - (id)initWithContext:(CGLContextObj)ctx + andIsSwPipe:(BOOL)isSwPipe; { self = [super init]; if (self != nil) @@ -62,6 +63,7 @@ // TODO: implement PBuffer if needed //self->_offscreen = [[GlassPBuffer alloc] init]; } + [(GlassFrameBufferObject*)self->_offscreen setIsSwPipe:(BOOL)isSwPipe]; } [self unsetContext]; } @@ -139,6 +141,12 @@ { [self setContext]; [self->_offscreen bindForWidth:width andHeight:height]; +} + +- (void)unbind +{ + assert(CGLGetCurrentContext() == self->_ctx); + [self->_offscreen unbind]; [self unsetContext]; } --- old/modules/graphics/src/main/native-glass/mac/GlassView3D.m 2015-03-17 18:08:28.000000000 -0700 +++ new/modules/graphics/src/main/native-glass/mac/GlassView3D.m 2015-03-17 18:08:27.000000000 -0700 @@ -116,7 +116,7 @@ - (void)_initialize3dWithJproperties:(jobject)jproperties { GET_MAIN_JENV; - + int depthBits = 0; if (jproperties != NULL) { @@ -150,6 +150,8 @@ } CGLContextObj clientCGL = NULL; + BOOL isSwPipe = NO; + if (jproperties != NULL) { jobject contextPtrKey = (*env)->NewStringUTF(env, "contextPtr"); @@ -175,6 +177,7 @@ { // this can happen in Rain or clients other than Prism (ie. device details do not have the shared context set) sharedCGL = clientCGL; + isSwPipe = YES; } self->isHiDPIAware = NO; @@ -191,7 +194,7 @@ } } - GlassLayer3D *layer = [[GlassLayer3D alloc] initWithSharedContext:sharedCGL andClientContext:clientCGL withHiDPIAware:self->isHiDPIAware]; + GlassLayer3D *layer = [[GlassLayer3D alloc] initWithSharedContext:sharedCGL andClientContext:clientCGL withHiDPIAware:self->isHiDPIAware withIsSwPipe:isSwPipe]; // https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/nsview_Class/Reference/NSView.html#//apple_ref/occ/instm/NSView/setWantsLayer: // the order of the following 2 calls is important: here we indicate we want a layer-hosting view @@ -233,6 +236,7 @@ { glDeleteTextures(1, &self->_texture); } + [[layer getPainterOffscreen] unbind]; } [[self layer] release]; @@ -605,6 +609,7 @@ if (self->_drawCounter == 0) { GlassLayer3D *layer = (GlassLayer3D*)[self layer]; + [[layer getPainterOffscreen] unbind]; [layer flush]; } LOG("end");