Game Development Reference
In-Depth Information
a. Start at the beginning of the vertex buffer: i =0.
b. Lock segment i with the D3DLOCK_DISCARD
flag.
c. Copy 500 particles to segment i .
3. Render segment i .
4. Next segment: i ++
Remark: Recall that our vertex buffer is dynamic, and therefore we
can take advantage of the dynamic locking flags D3DLOCK_NOOVER-
WRITE and D3DLOCK_DISCARD . These flags allow us to lock parts of the
vertex buffer that are not being rendered while other parts of the ver-
tex buffer are being rendered. For instance, suppose that we are
rendering segment 0; using the D3DLOCK_NOOVERWRITE flag, we can
lock and fill segment 1 while we are rendering segment 0. This pre-
vents a rendering stall that otherwise would incur.
This approach is more efficient. First, we have reduced the size of the
vertex buffer needed. Secondly, the CPU and graphics card are now
working in unison; that is, we copy a small batch of particles to the ver-
tex buffer (CPU work), and then we draw the small batch (graphics card
work). Then we copy the next batch of particles to the vertex buffer
and draw that batch. This continues until all the particles have been
rendered. As you can see, the graphics card is no longer sitting idle
waiting for the entire vertex buffer to be filled.
We now turn our attention to the implementation of this rendering
scheme. To facilitate the rendering of a particle system using this
scheme, we use the following data members of the PSystem class:
_vbSize —The number of particles that our vertex buffer can hold
at a given time. This value is independent of the number of parti-
cles in the actual particle system.
_vbOffset —This variable marks the offset (measured in parti-
cles, not bytes) into the vertex buffer into which we should begin
copying the next batch of particles. For instance, if batch one
resides in entries 0 to 499 of the vertex buffer, the offset to start
copying batch two would be 500.
_vbBatchSize —The number of particles that we define to be in a
batch.
We now present the code for the rendering method:
void PSystem::render()
{
if( !_particles.empty() )
{
// set render states
preRender();
Search WWH ::




Custom Search