Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rossipoo

macrumors regular
Original poster
Jun 7, 2009
109
0
I am having an issue with an opengl view that is not updating WHILE THE WINDOW IS BEING RESIZED, but not actually changing the size of the window. If the window size is changed continuously, then a redraw will happen. I have a method animate which is on a timer that is in the NSRunLoopCommonModes. The timer is firing like normal, but a call to setNeedsDisplay in my animate method does not cause a redraw.

My understanding is that during a resize, the main run loop does not run, and I assume that setNeedsDisplay is only checked during the main run loop, which makes sense to me why it doesn't work, but I'm not sure what to do about it.

I have "fixed" it by checking inLiveResize in my animate method and calling display if so:
Code:
if ([self inLiveResize]) {
	[self display];
} else {
	[self setNeedsDisplay];
}
but I'm not sure that this is the optimal solution. It seems like some places online say to avoid using display, I can't find any other way to make a display happen.

Is this the right way to deal with this? Does anyone know of a better solution?
 

rossipoo

macrumors regular
Original poster
Jun 7, 2009
109
0
After thinking about this for a bit I decided to change the code in animate to this:
Code:
[self setNeedsDisplay];
if ([self inLiveResize]) {
	[[NSOperationQueue mainQueue] addOperationWithBlock:^{
		[self displayIfNeeded];
	}];
}
This seems better to me, in theory, since now setNeedsDisplay can be called multiple times from different timers in one loop, and still only cause one render to happen.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
Try adding your timer to the run loop like this after it's created:

Code:
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode];

If you can, avoid NSTimer for powering your OpenGL view. See Driving OpenGL Rendering Loops
 

rossipoo

macrumors regular
Original poster
Jun 7, 2009
109
0
Thanks, I hadn't seen this display link code before, it seems to work well. I can't tell any performance difference right now, but I'm sure that's because I don't have a whole lot in my draw call. I assume that because it uses a different thread, the display link code would be able to handle a lot more.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.