Game Development Reference
In-Depth Information
Finally StructureByteStride tells the API how large each element in your array
is. This is simply a sizeof(VertexPositionNormal) ; in our case, however, set
this as required in your situation.
Building these buffers is made easier with the CD3D11_BUFFER_DESC class
provided with Windows 8. To build an immutable vertex buffer you just need the fol-
lowing code:
CD3D11_BUFFER_DESC desc = CD3D11_BUFFER_DESC(
sizeof(VertexPositionNormal) * NumVerts,
D3D11_BIND_VERTEX_BUFFER,
D3D11_USAGE_IMMUTABLE);
Setting the buffers
Now that we have a description that can be used to create the buffer as well as the
vertex data, we can go about actually creating the buffer resource for use by the
GPU. To do this we need our ID3D11Device1 pointer, and the CreateBuffer()
method, used as follows:
PositionNormalVertex vertices[];
D3D11_BUFFER_DESC vertDesc;
// code to create the above items
ID3D11Buffer *pBuffer;
D3D11_SUBRESOURCE_DATA bufferData = {0};
bufferData.pSysMem = vertices;
bufferData.SysMemPitch = 0;
bufferData.SysMemSlicePitch = 0;
M_d3dDevice->CreateBuffer(&vertDesc,
&bufferData, &pBuffer);
The preceding code creates an ID3D11Buffer object which contains our vertex
buffer as described in our buffer description structure, and prefilled with data from
our vertex array. Remember it's a similar method for the index buffer, but instead of
our vertex array, you just need an array of integers.
Search WWH ::




Custom Search