Game Development Reference
In-Depth Information
Mapping the buffer
The first method for updating a buffer involves mapping the buffer to system memory
and copying your data into that memory block. Direct3D will handle taking the
data as it is copied and copying it to the graphics hardware. To do this,
ID3D11DeviceContext provides a Map() command, as shown in the following
code snippet:
m_d3dContext->Map(
resourceToMap,
subresource,
mapType,
mapFlags,
pMappedResource
);
Here you need to specify the resource to map; this would be your D3D11Buffer
pointer, and the index of the subresource, which in many cases will stay at zero.
After that you need to specify what type of mapping will occur. There are a few op-
tions to choose from depending on what you intend to do. They are as follows:
D3D11_MAP_READ
D3D11_MAP_WRITE
D3D11_MAP_READ_WRITE
D3D11_MAP_WRITE_DISCARD
D3D11_MAP_WRITE_NO_OVERWRITE
D3D11_MAP_WRITE_DISCARD tells the GPU to discard the previous contents of the
buffer upon mapping, meaning that you cannot read from the buffer, and if you don't
write anything the GPU will read undefined memory. In this case the resource must
be created with CPU write access and a DYNAMIC usage.
You will generally provide zero for the mapFlags parameter, which when set with
the D3D11_MAP_FLAG_DO_NOT_WAIT will return an error and continue rather than
waiting for the GPU to finish with the resource.
Search WWH ::




Custom Search