Graphics Reference
In-Depth Information
We could use copy and paste and simply duplicate the code we wrote in the previous
section, but the code quickly becomes unwieldy and cumbersome to navigate. Instead we
use an object-oriented approach and create the OpenGL-derived layer (called
OpenGLVidGridLayer
), a
VideoChannel
object that represents one video stream, and a
VideoChannelController
object that provides an interface for playback and rendering.
Here is what each object does:
.
OpenGLVidGridLayer
This object initializes the layer so that it runs asynchronously, sets the frame, sets
the background color to black, sets the video paths array from what was passed in,
initializes the
VideoChannel
and the
VideoChannelController
objects, calls
-canDrawInCGLContext
and
-drawInCGLContext
, and acts as a proxy to start play-
back of all the movies that were assigned to
VideoChannel
objects.
.
VideoChannel
This object represents each video on the grid. It stores the rectangle that will be
used to composite the video in the parent rectangle, checks to see if its assigned
video is ready to draw the next frame, initializes the visual context using the width
and height specified by the rectangle it was initialized with, draws the video
assigned to it using OpenGL calls, and provides a proxy method for video playback.
.
VideoChannelController
This object takes an array of
VideoChannel
objects, each initialized with a movie
and rectangle, to be used to render in the grid. It provides a proxy function that
instructs all
VideoChannel
s to start or stop playback on their movies, provides a
proxy function to see if all
VideoChannel
s are ready to draw their next frame,
provides a proxy function to tell all
VideoChannel
s to set up their visual contexts,
calls initial OpenGL drawing code that is common for all
VideoChannel
s, and
provides a proxy function to tell all
VideoChannel
s to render their movies in their
respective compositing rectangles.
This object-oriented approach is a double-edged sword. Although it enables us to organize
things in a cleaner fashion, it makes it necessary to think about everything in terms of
objects, so study theses descriptions so that you know where to look in the project code
to figure out what is going on. The
VideoChannelController
object provides control for
each of the
VideoChannel
s and is probably the best place to start to see how things work.
The
OpenGLVidGridLayer
only does initialization and provides the functionality to decide
whether we should draw at the current time.
Figure 8-1 depicts the demo application, OpenGL VidGrid. The full display area in the
window is the
CAOpenGLLayer
-derived class, called
OpenGLVidGridLayer
. Each of the indi-
vidual movie clips displaying on the screen are represented in code by the
VideoChannel
class.