Graphics Reference
In-Depth Information
To understand all of this code, you likely need to understand OpenGL, which is beyond
the scope of this topic. However, take a look at these two lines from Listing 8-5:
glEnable( CVOpenGLTextureGetTarget (currentFrame));
glBindTexture( CVOpenGLTextureGetTarget (currentFrame),
CVOpenGLTextureGetName (currentFrame));
These two lines tell OpenGL to enable and bind the drawing texture to the currentFrame
( CVImageBufferRef ) that we saved off in our call to -canDrawInCGLContext . In other
words, this is how we tell OpenGL what to draw.
Why Use CAOpenGLLayer for Movie Playback?
You might be a little confused as to why we duplicated a functionality we easily implemented
in Chapter 7 using QuickTime Layers. Why not just use a QTMovieLayer for movie playback?
If all you need is movie playback, you should indeed just use a QTMovieLayer instead.
However, we are building up to the ultimate reason, which is to use OpenGL for simultane-
ously playing back multiple video streams.
If you were to try to playback multiple videos in multiple QTMovieLayers , you would find the
performance degrades quickly. OpenGL enables us to get all the image data from each of the
movie objects at once and composite them into a single context. This reduces the overhead
and improves performance. This first section on the CAOpenGLLayer is provided as a building
block that assists you in understanding how to composite multiple video streams, as covered
in the next section.
Rendering Multiple Video Channels
The final goal for this chapter is to demonstrate how to render multiple QuickTime video
streams in a single CAOpenGLLayer . As noted in the sidebar, the primary reason for using
OpenGL here instead of QTMovieLayer boils down to performance. Performance degrades
quickly when you load and playback multiple QTMovies using multiple QTMovieLayers . To
improve performance, we instead get the current frame of each movie playing back and
composite them all together in the same OpenGL context.
To achieve this is not much different from what we did in the previous section to render a
single QuickTime movie using OpenGL. We create an image buffer for each QuickTime
movie and check each of them periodically to see if the next frame is ready in the call to
-canDrawInCGLContext . We also need to set up a way to display the movies in a grid by
setting a drawing rectangle for each movie as they are initialized.
 
Search WWH ::




Custom Search