Game Development Reference
In-Depth Information
&vb,
0);
This next code example shows how to create a dynamic index buffer
that has enough memory to hold 36 16-bit indices.
IDirect3DIndexBuffer9* ib;
_device->CreateIndexBuffer(
36 * sizeof( WORD ),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&ib,
0);
3.1.2 Accessing a Buffer's Memory
To access the memory of a vertex/index buffer, we need to get a pointer
to its internal memory contents. We obtain a pointer to its contents by
using the Lock method. It is important to unlock the buffer when we
are done accessing it. Once we have a pointer to the memory, we can
read and write information to it.
Note: If the vertex/index buffer was created with the usage flag
D3DUSAGE_WRITEONLY , you must not read from the buffer. Doing so
will result in a failed read.
HRESULT IDirect3DVertexBuffer9::Lock(
UINT OffsetToLock,
UINT SizeToLock,
BYTE** ppbData,
DWORD Flags
);
HRESULT IDirect3DIndexBuffer9::Lock(
UINT OffsetToLock,
UINT SizeToLock,
BYTE** ppbData,
DWORD Flags
);
Figure 3.1: The Offset
ToLock and SizeToLock
parameters specify the
block of memory to lock.
Specifying zero for both of
these parameters is a
shortcut to lock the entire
buffer.
The parameters for both methods are exactly the same.
OffsetToLock —Offset, in bytes, from the start of the buffer to
the location to begin the lock. See Figure 3.1.
Search WWH ::




Custom Search