Graphics Reference
In-Depth Information
.
Preconfigured OpenGL Context
NOTE
.
Viewport automatically set to the
CAOpenGLLayer 's frame
If you are new to OpenGL, you might not
understand what having all this set up for
you really means. The bottom line is that you
gain a great deal of functionality without
having to painstakingly write out the code
yourself. Core Animation does all the heavy
lifting for you, so you can focus on your
OpenGL rendering code.
.
Preconfigured pixel format object
The setup code is so simplified that you
need to be concerned with only two
functions. The first function checks to
see if the frame for the next time should
be rendered, and the second function
renders the content depending upon whether the first returned YES or NO . If you have a
good understanding of these two functions, you have a very good understanding of how
the CAOpenGLLayer works and, more important, how to use it. These functions are shown
in Listing 8-1.
LISTING 8-1
CAOpenGLLayer Delegate Rendering Functions
- ( BOOL )canDrawInCGLContext:(CGLContextObj)glContext
pixelFormat:(CGLPixelFormatObj)pixelFormat
forLayerTime:( CFTimeInterval )timeInterval
displayTime:( const CVTimeStamp *)timestamp;
- ( void )drawInCGLContext:(CGLContextObj)glContext
pixelFormat:(CGLPixelFormatObj)pixelFormat
forLayerTime:( CFTimeInterval )interval
displayTime:( const CVTimeStamp *)timestamp;
The function -canDrawInCGLContext gets called only if you have set the layer's asynchro-
nous property to YES . You can do so with the following call in your CAOpenGLLayer
derived layer's init method:
[self setAsynchronous:YES];
You don't need to set this if you plan to update the content manually or according to
some other scheme, such as a timer. In that case you simply need to call
-setNeedsDisplay:YES on the layer whenever you want the content to be refreshed.
In our case, however, we want -canDrawInCGLContext to be called periodically because we
are going to be constantly checking for a new frame to be ready while the movie is
playing. To pull this off, set the asynchronous property to YES .
The function -drawInCGLContext gets called only if -canDrawInCGLContext returned YES .
After it is called, it takes the responsibility for rendering your OpenGL content into a
rendering context.
 
Search WWH ::




Custom Search