Game Development Reference
In-Depth Information
3.1.1 Creating a Vertex and Index Buffer
We can create a vertex and index buffer with the following two
methods:
HRESULT IDirect3DDevice9::CreateVertexBuffer(
UINT Length,
DWORD Usage,
DWORD FVF,
D3DPOOL Pool
IDirect3DVertexBuffer9** ppVertexBuffer,
HANDLE* pSharedHandle
);
HRESULT IDirect3DDevice9::CreateIndexBuffer(
UINT Length,
DWORD Usage,
D3DFORMAT Format,
D3DPOOL Pool,
IDirect3DIndexBuffer9** ppIndexBuffer,
HANDLE* pSharedHandle
);
The majority of the parameters are identical for both methods, so let's
cover the parameters of both methods together.
Length —The number of bytes to allocate for the buffer. If we
wanted a vertex buffer to have enough memory to store eight ver-
tices, we would set this parameter to 8 * sizeof(Vertex) ,
where Vertex is our vertex structure.
Usage —Specifies some additional properties about how the buffer
is used. This value can be zero, indicating no additional properties,
or a combination of one or more of the following flags:
D3DUSAGE_DYNAMIC —Setting this flag makes the buffer
dynamic. See the notes on static and dynamic buffers on the
following page.
D3DUSAGE_POINTS —This flag specifies that the buffer will
hold point primitives. Point primitives are covered in “Particle
Systems” in Chapter 14. This flag is used only for vertex
buffers.
D3DUSAGE_SOFTWAREPROCESSING —Vertex processing is
done in software.
D3DUSAGE_WRITEONLY —Specifies that the application will
only write to the buffer. This allows the driver to place the
buffer in the best memory location for write operations. Note
that reading from a buffer created with this flag will result in an
error.
Search WWH ::




Custom Search