Refreshing an NSOpenGLView

mac_developer

Registered
I am developing an app for Mac, with MacOS X 10.4 sdk and XCode 3.1.
This app makes OpenGL animations. I am getting some trouble when animating within an NSWindow.

I put my subclass of NSOpenGLView within a NSWindow.
[[myWindow contentView] addSubview:glView];

glView is double buffered, accelerated and in sync with
NSOpenGLCPSwapInterval

Then I activate a NSTimer in the main thread this way
NSRunLoop *loop = [NSRunLoop currentRunLoop];
NSTimeInterval timeInterval = 0.005;

mRenderTimer = [[NSTimer
scheduledTimerWithTimeInterval:timeInterval target:self
selector:@selector(UpdateWindowedScreen:) userInfo:nil
repeats:YES] retain];

[loop addTimer:mRenderTimer forMode:NSDefaultRunLoopMode];
[loop addTimer:mRenderTimer
forMode:NSEventTrackingRunLoopMode];
[loop addTimer:mRenderTimer
forMode:NSModalPanelRunLoopMode];

The method UpdateWindowedScreen called by the timer just calls

[glView setNeedsDisplay:YES];

And the drawRect method of glView just calls
[[self openGLContext] makeCurrentContext];
// draw openGL stuffs
[[self openGLContext] flushBuffer];

-------------------
It works pretty well, at the right speed of 60 FPS, excepted for some critical animations (with too many objects to draw), which cause the animation speed drops down to 30 FPS. Well, now I have noticed that even these critical animations can run at the right speed of 60 FPS if only I open and activate a second window "B" (doing nothing) near to my animation window "A". If the window "B" is activated and is about 2 or 5 pixels at the right of the window "A", or if it overlays even partially the window "A", the critical animations in the window "A" run at 60 FPS. Fine! But if I deactivate the window "B" and activate the window "A", or if I move the window "B" far from the window "A" or if I close the window "B", the animation running in the window "A" runs at 30 FPS. Too bad.
No matter if the window "A" has or has not shadows.

So it seems that activating a second window "B" makes my app gain speed at rendering in the window "A".
I have experimented that adding the method invalidateShadow in the UpdateWindowedScreen, this way

[glView setNeedsDisplay:YES];
[[glView window] invalidateShadow];

helps at gaining the 60 FPS speed again. Anyway, not so well as when activating the window "B". So my question is: How can I gain the 60 FPS speed without activating the window "B", in a professional way?

Thank You and Regards
--
mac_developer
 
Back
Top