implement frame buffer fetch extension for iOS, change composition on stroke drawing and commit, add rename layer dialog
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user