Should my CVDisplayLinkOutputCallback method be used to update as well as render an OpenGL scene

967 views Asked by At

I have managed to set up an NSOpenGLView using CVDisplayLinkSetOutputCallback as a method to render a scene in my application. Everything appears to be working correctly and the callback method is firing at a pretty decent rate.

So far, I have based my implementation on the code found in this forum thread (specifically, this post) from quite a while ago (2009).

Digging further through the thread, there is mention of setting up an NSTimer for a fixed step interval which would call out to an update:(NSTimeInterval)duration method for integrating physics simulations and the like. However, it appears that the delta time between frames is also being calculated in the display link callback method too which i'm finding quite confusing.

I hadn't previously considered a fixed step time interval for updating my scene and to be honest, it doesn't seem quite right to me but i'm still learning OpenGL and the finer nuances of game development.

Is it a good approach to tie the update and render methods together in the display link callback, or would it be better suited to sit elsewhere?

I have used GLKit for iOS and to get everything up and working was fairly simple in that you conform to the appropriate delegate methods and your update and render methods are called accordingly.

So far, my code looks like this: (based on the code found in the forum thread)

static CVReturn displayLinkOutputCallback(CVDisplayLinkRef displayLink, const CVTimeStamp *now, const CVTimeStamp *outputTime, CVOptionFlags flagsIn, CVOptionFlags *flagsOut, void *displayLinkContext)
{
    NSOpenGLView *view = (__bridge NSOpenGLView *)displayLinkContext;

    NSTimeInterval deltaTime = 1.0 / (outputTime->rateScalar * (double)outputTime->videoTimeScale / (double)outputTime->videoRefreshPeriod);

    [view update:deltaTime];

    [view drawRect:[view frame]];

    return kCVReturnSuccess;
}

Is this a viable approach? Should I be using an NSTimer instead? Or is there an alternative method that would perhaps be better suited?

I am not overly familiar with CVDisplayLink so I am unsure if this is the best place to be implementing methods to update as well as render my scene. Should CVDisplayLink be used in this way, i.e.: for scene rendering and updating all in one?

Any further information would be greatly appreciated.

0

There are 0 answers