Graphics Reference
In-Depth Information
"Resource Creation" section that resources are created with very specific usage and access
patterns. Depending on what a resource will be used for, it can be advantageous to only al-
low it to be accessible by the GPU. In other cases, it may be necessary to be able to directly
manipulate the resources in the host C/C++ application.
Direct3D 11 provides a number of different techniques to modify or manipulate the
contents of a resource. We will explore each of these methods in detail in this section,
and will also consider how each of these methods provides useful operations in different
situations.
2.3.1 Manipulating Resources
The first group of methods that we will look at is used to modify the contents of a resource.
As we will see shortly, it is also possible to read the contents of a resource with some of
the methods.
Mapping Resources
The primary way to manipulate the contents of a buffer for both reading and writing from
the CPU is the Map / Unmap method of the device context. If a resource has CPU read
or write access flags set, an application can map the contents of the resource to system
memory. The map and unmap method prototypes are shown in Listing 2.49.
HRESULT Map(
ID3DllResource *pResource,
UINT Subresource,
D3D11_MAP MapType,
UINT MapFlags,
D3D11_MAPPED_SUBRES0URCE *pMappedResource
);
void Unmap(
ID3DllResource *pResource,
UINT Subresource
);
Listing 2.49. The method prototypes of the map and unmap methods.
The resource and subresource to be mapped are specified in the pResource and
Subresource parameters, respectively. Next, the mapping type is specified in the MapType
parameter, which indicates if the resource will be read or written, and how any writing will
be performed. The members of the D3D11_MAP enumeration are shown in Listing 2.50.
Search WWH ::




Custom Search