Game Development Reference
In-Depth Information
Specifying a model's index stream
You will notice that the corners of the cube in the previous diagram have been
labeled with a number as well as their model space coordinates. If we cast our
minds back to our work with 2D graphics, we will remember that Marmalade
renders polygons by accepting a stream of vertices as input and also a stream of
indices that defines the order in which those vertices should be processed.
The same approach applies when rendering 3D graphics. We specify the index
stream as an array of unsigned 16-bit integers ( uint16 ) and this dictates the order
in which the vertices will be read out of the stream for rendering.
One advantage of using an index stream is that we can potentially refer to the same
point several times without having to duplicate it in the vertex stream, thus saving
us some memory. Since the index stream is just telling the GPU which order it has to
process the data contained in the vertex, color, UV, and normal streams, it can be as
long or as short as we want it to be. The index stream doesn't even need to reference
every single element of the other streams, meaning we could potentially create one
set of streams that can be referenced by multiple different index streams.
Another advantage of index streams is that we can use them to speed up rendering.
You will recall that we used the function call IwGxDrawPrims to render a 2D
polygon. To render 3D polygons, we use the exact same call. Each call to this
function results in the rendering engine having to perform some initialization, so
if we can find a way to minimize the number of draw calls we have to make, we
can render the game world more quickly.
We can use the index stream to achieve this by inserting degenerate polygons into
the polygon render list. A degenerate polygon is one that does not modify any pixels
when it is drawn and this is achieved by ensuring that all the vertices that make up
the polygon will lie on the same line. Most graphics hardware are clever enough to
recognize a degenerate polygon and will not waste time trying to render it.
As an example, let's assume we are rendering some triangle strips. We could render
them by calling IwGxDrawPrims twice, or we could join the two strips with some
degenerate polygons and render them both with a single call to IwGxDrawPrims .
We can continue to do this to join together as many triangle strips as we want.
 
Search WWH ::




Custom Search