Game Development Reference
In-Depth Information
An index buffer is simply an array of integers, so we don't need to do anything special
before creating it.
Now that we have the data we need to import, we need to create the buffers. For this
we need to create a D3D11_BUFFER_DESC structure to describe the buffer for the
API. Following is the layout of the D3D11_BUFFER_DESC structure, as outlined by
MSDN:
typedef struct D3D11_BUFFER_DESC {
UINT ByteWidth;
D3D11_USAGE Usage;
UINT BindFlags;
UINT CPUAccessFlags;
UINT MiscFlags;
UINT StructureByteStride;
} D3D11_BUFFER_DESC;
( http://msdn.microsoft.com/en-us/library/windows/desktop/ff476092 . )
To start with, ByteWidth describes the total size of the buffer in bytes, which would
be sizeof(PositionNormalVertex) * NumberOfVertices .
Usage specifies how we intend to use the buffer. We choose this value based on
how frequently we intend to use the buffer. The possible options are as follows:
D3D11_USAGE_IMMUTABLE : Most of the time you should use the
D3D11_USAGE_IMMUTABLE for your vertex buffers. This tells the GPU that
you won't be changing the buffer, and it can optimize for higher performance
using that information. This option makes the buffer read-only for the GPU
only; the CPU cannot access this buffer after creation.
D3D11_USAGE_DYNAMIC : This lets the GPU know that you intend to change
the buffer, potentially each frame, and so safeguards need to be put in place
to ensure that you can safely access and update the data, while trying to
maintain performance. This option is read-only for the GPU, and write-only
for the CPU.
Search WWH ::




Custom Search