DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit b5d885b0c0a0d4a295afe7bf3460f0111824c14a
parent 890edf0dff9b72ec4df0ccc9293258967261b9ce
Author: falkTX <falktx@gmail.com>
Date:   Sun, 15 Feb 2015 13:50:53 +0000

More OSX work, works nicely as embed now

Diffstat:
Mdgl/src/pugl/pugl_osx.m | 62++++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 16 deletions(-)

diff --git a/dgl/src/pugl/pugl_osx.m b/dgl/src/pugl/pugl_osx.m @@ -35,6 +35,7 @@ backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag; - (void) setPuglview:(PuglView*)view; +- (BOOL) canBecomeKeyWindow; - (BOOL) windowShouldClose:(id)sender; @end @@ -66,6 +67,11 @@ [self setContentSize:NSMakeSize(view->width, view->height)]; } +- (BOOL)canBecomeKeyWindow +{ + return YES; +} + - (BOOL)windowShouldClose:(id)sender { if (puglview->closeFunc) @@ -81,6 +87,7 @@ static void puglDisplay(PuglView* view) { + view->redisplay = false; if (view->displayFunc) { view->displayFunc(view); } @@ -91,15 +98,17 @@ puglDisplay(PuglView* view) @public PuglView* puglview; NSTrackingArea* trackingArea; + bool doubleBuffered; } - (BOOL) acceptsFirstMouse:(NSEvent*)e; +- (BOOL) acceptsFirstResponder; - (BOOL) isFlipped; - (BOOL) isOpaque; - (BOOL) preservesContentInLiveResize; - (id) initWithFrame:(NSRect)frame; - (void) reshape; -- (void) drawRect:(NSRect)rect; +- (void) drawRect:(NSRect)r; - (void) cursorUpdate:(NSEvent*)e; - (void) updateTrackingAreas; - (void) viewWillMoveToWindow:(NSWindow*)newWindow; @@ -130,6 +139,11 @@ puglDisplay(PuglView* view) (void)e; } +- (BOOL) acceptsFirstResponder +{ + return YES; +} + - (BOOL) isFlipped { return YES; @@ -147,16 +161,16 @@ puglDisplay(PuglView* view) - (id) initWithFrame:(NSRect)frame { - puglview = nil; - trackingArea = nil; + puglview = nil; + trackingArea = nil; + doubleBuffered = true; - NSOpenGLPixelFormatAttribute pixelAttribs[16] = { + NSOpenGLPixelFormatAttribute pixelAttribs[] = { + NSOpenGLPFAColorSize, 24, + NSOpenGLPFAAlphaSize, 8, + NSOpenGLPFADepthSize, 16, NSOpenGLPFADoubleBuffer, NSOpenGLPFAAccelerated, - NSOpenGLPFAColorSize, - 8, - NSOpenGLPFADepthSize, - 8, 0 }; @@ -166,12 +180,20 @@ puglDisplay(PuglView* view) if (pixelFormat) { self = [super initWithFrame:frame pixelFormat:pixelFormat]; [pixelFormat release]; + printf("Is doubleBuffered? TRUE\n"); } else { self = [super initWithFrame:frame]; + doubleBuffered = false; + printf("Is doubleBuffered? FALSE\n"); } - if (self) { - [[self openGLContext] makeCurrentContext]; + if (self) { + NSOpenGLContext* context = [self openGLContext]; + [context makeCurrentContext]; + + GLint swapInterval = 1; + [context setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval]; + [self reshape]; } @@ -204,13 +226,19 @@ puglDisplay(PuglView* view) puglview->height = height; } -- (void) drawRect:(NSRect)rect +- (void) drawRect:(NSRect)r { puglDisplay(puglview); - glFlush(); - glSwapAPPLE(); - [super drawRect:rect]; + if (doubleBuffered) { + [[self openGLContext] flushBuffer]; + } else { + glFlush(); + //glSwapAPPLE(); + } + + // unused + return; (void)r; } - (void) cursorUpdate:(NSEvent*)e @@ -421,6 +449,7 @@ puglCreateWindow(PuglView* view, const char* title) } if (view->parent) { + [impl->glview retain]; NSView* pview = (NSView*)view->parent; [pview addSubview:impl->glview]; return 0; @@ -497,9 +526,10 @@ puglDestroy(PuglView* view) PuglStatus puglProcessEvents(PuglView* view) { - [view->impl->glview setNeedsDisplay:YES]; - view->redisplay = false; return PUGL_SUCCESS; + + // unused + (void)view; } void