implement multithreaded rendering with context switch, gl state save/restore, add progress bar ui node, implement stencil texture for brush, implement multithreaded canvas load/save/export pano. Missing multithread in windows.

This commit is contained in:
2017-10-20 09:16:12 +01:00
parent 32ede1be90
commit 283e4e2b5c
42 changed files with 610 additions and 65 deletions

View File

@@ -43,13 +43,13 @@
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "icon512.png",
"filename" : "iTunesArtwork.png",
"scale" : "1x"
},
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "icon1024.png",
"filename" : "iTunesArtwork@2x.png",
"scale" : "2x"
}
],

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

View File

@@ -6,20 +6,26 @@
#include "image.h"
#include "app.h"
#include "keymap.h"
#include "main.h"
#include <CoreFoundation/CoreFoundation.h>
#include <Cocoa/Cocoa.h>
#include <CoreVideo/CoreVideo.h>
#include <OpenGL/OpenGL.h>
@interface View : NSOpenGLView
@implementation View
- (void)async_lock
{
CVDisplayLinkRef dl;
NSOpenGLContext* glctx;
_CGLContextObject* cgl;
bool gl_ready;
CGLLockContext([glctx CGLContextObj]);
[glctx makeCurrentContext];
}
- (void)async_unlock
{
CGLUnlockContext([glctx CGLContextObj]);
}
- (void)async_swap
{
CGLFlushDrawable([glctx CGLContextObj]);
}
- (void)terminateGL;
@end @implementation View
- (instancetype)initWithFrame:(NSRect)frameRect
{
gl_ready = false;
@@ -98,22 +104,25 @@ 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) && App::I.redraw )
if (1 /*now < _prevTime + (1.0 / 30.0) &&*/ )
{
// 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
[glctx makeCurrentContext];
CGLLockContext([glctx CGLContextObj]);
App::I.clear();
App::I.update(now - _prevTime);
[glctx makeCurrentContext];
if (App::I.redraw)
{
App::I.clear();
App::I.update(now - _prevTime);
CGLFlushDrawable([glctx CGLContextObj]);
}
//[[self openGLContext] flushBuffer];
// returning NO will cause the layer to NOT be redrawn
CGLFlushDrawable([glctx CGLContextObj]);
CGLUnlockContext([glctx CGLContextObj]);
return NO;
}
@@ -142,9 +151,11 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
// 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
[glctx makeCurrentContext];
CGLLockContext(cgl);
[glctx makeCurrentContext];
App::I.redraw = true;
App::I.clear();
App::I.update(0);
//[[self openGLContext] flushBuffer];
@@ -325,6 +336,7 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
view = [[View alloc] initWithFrame:r];
controller = [[Controller alloc] initWithWindow:window];
App::I.osx_view = view;
auto style = NSTitledWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask|NSClosableWindowMask;
window = [[Window alloc] initWithContentRect:r styleMask:style backing:NSBackingStoreBuffered defer:NO];

17
PanoPainter-OSX/main.h Normal file
View File

@@ -0,0 +1,17 @@
#include <CoreFoundation/CoreFoundation.h>
#include <Cocoa/Cocoa.h>
#include <CoreVideo/CoreVideo.h>
#include <OpenGL/OpenGL.h>
@interface View : NSOpenGLView
{
CVDisplayLinkRef dl;
NSOpenGLContext* glctx;
_CGLContextObject* cgl;
bool gl_ready;
}
- (void)terminateGL;
- (void)async_lock;
- (void)async_unlock;
- (void)async_swap;
@end