Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my CAOpenGLLayer updating slower than my previous NSOpenGLView?
    primarykey
    data
    text
    <p>I have an application which renders OpenGL content on Mac OS X. Originally it was rendering to an NSOpenGLView, then I changed it to render to a CAOpenGLLayer subclass. </p> <p>When I did so I saw a huge performance loss: halved framerate, lower mouse responsivity, stuttering (stops from time to time, up to a second, during which profiler activity reports waiting on mutex for data to load on GPU ram), and doubled CPU usage.</p> <p>I'm investigating this issue and had a few questions:</p> <ul> <li>Has a similar performance hit been seen by someone else?</li> <li>Am I doing something wrong with my CAOpenGLLayer setup?</li> <li>How is CAOpenGLLayer and the Core Animation framework implemented, i.e. what path does my OpenGL content do from my glDrawElements calls up to my screen, and how should I do things on my side to optimize performance with such setup?</li> </ul> <p>Here's my code for CAOpenGLLayer setup:</p> <pre><code>// my application's entry point (can't be easily changed): void AppUpdateLogic(); //update application logic. Will load textures void AppRender(); //executes drawing void AppEventSink(NSEvent* ev); //handle mouse and keyboard events. //Will do pick renderings @interface MyCAOpenGLLayer: CAOpenGLLayer { CGLPixelFormatObj pixelFormat; CGLContextObj glContext; } @end @implementation MyCAOpenGLLayer - (id)init { self = [super init]; CGLPixelFormatAttribute attributes[] = { kCGLPFAAccelerated, kCGLPFAColorSize, (CGLPixelFormatAttribute)24, kCGLPFAAlphaSize, (CGLPixelFormatAttribute)8, kCGLPFADepthSize, (CGLPixelFormatAttribute)16, (CGLPixelFormatAttribute)0 }; GLint numPixelFormats = 0; CGLChoosePixelFormat(attributes, &amp;pixelFormat, &amp;numPixelFormats); glContext = [super copyCGLContextForPixelFormat:mPixelFormat]; return self; } - (void)drawInCGLContext:(CGLContextObj)inGlContext pixelFormat:(CGLPixelFormatObj)inPixelFormat forLayerTime:(CFTimeInterval)timeInterval displayTime:(const CVTimeStamp *)timeStamp { AppRender(); [super drawInCGLContext:inGlContext pixelFormat:inPixelFormat forLayerTime:timeInterval displayTime:timeStamp ] } - (void)releaseCGLPixelFormat:(CGLPixelFormatObj)pixelFormat { [self release]; } - (CGLPixelFormatObj)copyCGLPixelFormatForDisplayMask:(uint32_t)mask { [self retain]; return pixelFormat; } - (CGLContextObj)copyCGLContextForPixelFormat:(CGLPixelFormatObj)pixelFormat { [self retain]; return glContext; } - (void)releaseCGLContext:(CGLContextObj)glContext { [self release]; } @end @interface MyMainViewController: NSViewController { CGLContextObj glContext; CALayer* myOpenGLLayer; } -(void)timerTriggered:(NSTimer*)timer; @end @implementation MyMainViewController -(void)viewDidLoad:(NSView*)view { myOpenGLLayer = [[MyCAOpenGLLayer alloc] init]; [view setLayer:myOpenGLLayer]; [view setWantsLayer:YES]; glContext = [myOpenGLLayer copyCGLContextForPixelFormat:nil]; [NSTimer scheduledTimerWithTimeInterval:1/30.0 target:self selector:@selector(timerTriggered:) userInfo:nil repeats:YES ]; } - (void)timerTriggered:(NSTimer*)timer { CGLContextObj oldContext = CGLContextGetCurrent(); CGLContextSetCurrent(glContext); CGLContextLock(glContext); AppUpdateLogic(); [myOpenGLLayer setNeedsDisplay:YES]; CGLContextUnlock(glContext); CGLContextSetCurrent(oldContext); } - (void)mouseDown:(NSEvent*)event { CGLContextObj oldContext = CGLContextGetCurrent(); CGLContextSetCurrent(glContext); CGLContextLock(glContext); AppEventSink(event); CGLContextUnlock(glContext); CGLContextSetCurrent(oldContext); } @end </code></pre> <p>It may be useful to know my video card isn't very powerful (Intel GMA with 64 MB of shared memory).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload