NSOpenGLView help needed, frame jitter/tearing

Ok, so i’ve setup my project to use a cocoa window instead of glut, but i’m having problems
with framerates and frame tearing/jittter.

I’ve tried all the approaches to synchronize my updates to vertical refresh rate, but I always
end up with either solid fps and tearing, or no tearing but framerate fluctuation (jitter).

In the end, I followed this article to create a displaylink to drive my renderloop
http://developer.apple.com/qa/qa2004/qa1385.html

This ensures that the render call is synchronized with the refresh rate of my monitor. As I
understand it this means that my render method will be called inbetween monitor refreshes
but I also need to set the swap interval on my opengl context to 1 so that opengl will only
do buffer-swaps when the next refresh cycle occurs, so as not to cause any tearing.

My issue is as follows, if I do use the displaylink to drive my renderloop, but don’t set the
NSOpenGLCPSwapInterval to 1, I get a steady 60fps but I see tearing on my screen, however
if I do set the gl swap interval to 1, forcing gl to only swap inbetween refresh cycles, I get
no more tearing but my framerate fluctuates between 40 and 60fps.

My renderloop looks like this:

  
-(CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime  
{  
	// draw here  
	[[self openGLContext] makeCurrentContext];  
  
	NSRect rectView = [self bounds];  
		ofWindowPtr->render(rectView.size.width, rectView.size.height);  
		  
	[[self openGLContext] flushBuffer];  
	  
	return kCVReturnSuccess;  
}  

Currently I’m only rendering a couple of rectangles and circles, so performance is not the
issue here.

Anybody got any advice?

  • Edvin