diff --git a/PanoPainter-OSX/main.cpp b/PanoPainter-OSX/main.cpp index f2bd452..04387bd 100644 --- a/PanoPainter-OSX/main.cpp +++ b/PanoPainter-OSX/main.cpp @@ -14,11 +14,15 @@ @interface View : NSOpenGLView { CVDisplayLinkRef dl; + NSOpenGLContext* glctx; + _CGLContextObject* cgl; + bool gl_ready; } - (void)terminateGL; @end @implementation View - (instancetype)initWithFrame:(NSRect)frameRect { + gl_ready = false; NSOpenGLPixelFormatAttribute attrs[] = { NSOpenGLPFADoubleBuffer, @@ -57,14 +61,18 @@ CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj]; CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(dl, cglContext, cglPixelFormat); + CGLEnable([self.openGLContext CGLContextObj], kCGLCECrashOnRemovedFunctions); + // Activate the display link CVDisplayLinkStart(dl); - - CGLEnable([self.openGLContext CGLContextObj], kCGLCECrashOnRemovedFunctions); + + cgl = [[self openGLContext] CGLContextObj]; + glctx = [self openGLContext]; CGLLockContext([[self openGLContext] CGLContextObj]); App::I.init(); CGLUnlockContext([[self openGLContext] CGLContextObj]); + gl_ready = true; } - (void)terminateGL @@ -90,24 +98,23 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime double now = hostTime / _timeFreq; // this will not update unless 1/30th of a second has passed since the last update - if ( now < _prevTime + (1.0 / 30.0) ) + if ( now < _prevTime + (1.0 / 30.0) && App::I.redraw ) { - // Add your drawing codes here - [[self openGLContext] makeCurrentContext]; - // We draw on a secondary thread through the display link // When resizing the view, -reshape is called automatically on the main // thread. Add a mutex around to avoid the threads accessing the context // simultaneously when resizing - CGLLockContext([[self openGLContext] CGLContextObj]); + [glctx makeCurrentContext]; + CGLLockContext([glctx CGLContextObj]); + App::I.clear(); App::I.update(now - _prevTime); //[[self openGLContext] flushBuffer]; // returning NO will cause the layer to NOT be redrawn - CGLFlushDrawable([[self openGLContext] CGLContextObj]); - CGLUnlockContext([[self openGLContext] CGLContextObj]); + CGLFlushDrawable([glctx CGLContextObj]); + CGLUnlockContext([glctx CGLContextObj]); return NO; } else @@ -130,21 +137,21 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime - (void)drawRect:(NSRect)dirtyRect { NSLog(@"drawRect"); - // Add your drawing codes here - [[self openGLContext] makeCurrentContext]; // We draw on a secondary thread through the display link // When resizing the view, -reshape is called automatically on the main // thread. Add a mutex around to avoid the threads accessing the context // simultaneously when resizing - CGLLockContext([[self openGLContext] CGLContextObj]); + [glctx makeCurrentContext]; + CGLLockContext(cgl); + App::I.update(0); //[[self openGLContext] flushBuffer]; // returning NO will cause the layer to NOT be redrawn - CGLFlushDrawable([[self openGLContext] CGLContextObj]); - CGLUnlockContext([[self openGLContext] CGLContextObj]); + CGLFlushDrawable(cgl); + CGLUnlockContext(cgl); } - (void)reshape diff --git a/PanoPainter/AppDelegate.m b/PanoPainter/AppDelegate.m index 63752ef..58061ca 100644 --- a/PanoPainter/AppDelegate.m +++ b/PanoPainter/AppDelegate.m @@ -7,6 +7,7 @@ // #import "AppDelegate.h" +#include "app.h" @interface AppDelegate () @@ -32,10 +33,12 @@ - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. + App::I.redraw = true; } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + App::I.redraw = true; } - (void)applicationWillTerminate:(UIApplication *)application { diff --git a/data/layout.xml b/data/layout.xml index e36854d..649be86 100644 --- a/data/layout.xml +++ b/data/layout.xml @@ -165,6 +165,34 @@ + + + + + + + + + + + + + +