Graphics Reference
In-Depth Information
The Quartz Composition Layer and OpenGL
All the power of OpenGL is at your fingertips in a QCCompositionLayer as it inherits
directly from CAOpenGLLayer , which we discuss in detail in Chapter 8, “OpenGL Layer.”
What we learned in that chapter is that we first determine whether we should draw using
-canDrawInCGLContext and then draw in the context using -drawInCGLContext . We can
override both of these methods if we create our own QCCompositionLayer -derived class
and add additional functionality.
This gives you the power to do any additional rendering you might want to do before
displaying the current frame in the composition. Remember that Quartz Compositions
are playing, which is to say that they are rendering to the screen on a regular basis. The
frequency is not something that you control because it is related to your hardware and
the video refresh rate. What you do know, however, is that if -drawInCGLContext has
been called, the next frame is ready to be rendered, and -drawInCGLContext has provided
you a CGLContextObj object into which you can render your own drawing. Listing 9-4
demonstrates what the default implementation of a QCQuartzCompositionLayer derived
class looks like.
LISTING 9-4
Default QCCompositionLayer Derived Class Implementation
@interface QuartzLayer : QCCompositionLayer {
}
@end
@implementation QuartzLayer
- ( BOOL )canDrawInCGLContext:(CGLContextObj)glContext
pixelFormat:(CGLPixelFormatObj)pixelFormat
forLayerTime:( CFTimeInterval )timeInterval
displayTime:( const CVTimeStamp *)timeStamp;
{
return [ super canDrawInCGLContext:glContext
pixelFormat:pixelFormat
forLayerTime:timeInterval
displayTime:timeStamp];
}
- ( void )drawInCGLContext:(CGLContextObj)glContext
pixelFormat:(CGLPixelFormatObj)pixelFormat
forLayerTime:( CFTimeInterval )timeInterval
displayTime:( const CVTimeStamp *)timeStamp;
{
 
Search WWH ::




Custom Search