Game Development Reference
In-Depth Information
SizeToLock —Number of bytes to lock
ppbData —A pointer to the start of the locked memory
Flags —Flags describing how the lock is done. This can be zero or
a combination of one or more of the following flags:
D3DLOCK_DISCARD —This flag is used only for dynamic buff-
ers. It instructs the hardware to discard the buffer and return a
pointer to a newly allocated buffer. This is useful because it
allows the hardware to continue rendering from the discarded
buffer while we access the newly allocated buffer. This pre-
vents the hardware from stalling.
D3DLOCK_NOOVERWRITE —This flag is used only for dynamic
buffers. It states that you are only going to append data to a
buffer. That is, you will not overwrite any memory that is cur-
rently being rendered. This is beneficial because it allows the
hardware to continue rendering at the same time you add new
data to the buffer.
D3DLOCK_READONLY —This flag states that you are locking
the buffer only to read data and that you won't be writing to it.
This allows for some internal optimizations.
Flags D3DLOCK_DISCARD and D3DLOCK_NOOVERWRITE address the
fact that a portion of the buffer's memory could be in use (being ren-
dered) at the time of a lock call. If circumstances allow these flags to be
used, they prevent a rendering stall when locking, which otherwise
would occur.
The following example shows how the Lock method is commonly
used. Note how we call the Unlock method when we are done.
Vertex* vertices;
_vb->Lock(0, 0, (void**)&vertices, 0);
// lock the entire buffer
vertices[0] = Vertex(-1.0f, 0.0f, 2.0f); // write vertices to
vertices[1] = Vertex( 0.0f, 1.0f, 2.0f); // the buffer
vertices[2] = Vertex( 1.0f, 0.0f, 2.0f);
_vb->Unlock(); // unlock when you're done accessing the buffer
3.1.3 Retrieving Information about a Vertex and Index
Buffer
Sometimes we need to get information about the vertex/index buffer.
The following example demonstrates the methods used to obtain such
information:
Search WWH ::




Custom Search