You can initialize when creating textures, padding or create data. This article will demonstrate how to initialize different types of textures.
Default type texture:
Default, this texture created with D3D11_USAGE_DEFAULT type most commonly used type of texture. You can use one of the following two methods to initialize Texture:
- Call ID3D11Device :: CreateTexture2D method and specify the data to pInitialData variables.
- After creating texture ID3D11Device :: CreateTexture2D method calls, method calls ID3D11DeviceContext :: UpdateSubresource filling texture data.
Dynamic type texture:
This type of texture created with D3D11_USAGE_DYNAMIC, filling the texture data as follows:
- Get the texture data memory pointer by calling ID3D11DeviceContext :: Map method and specify D3D11_MAP_WRITE_DISCARD flag.
- Memory write address pointer to the data.
- When you write data call ID3D11DeviceContext :: Unmap method.
Staging types of textures:
This type of texture created with D3D11_USAGE_STAGING, filling the texture data as follows:
1. Obtain the texture data memory pointer by calling ID3D11DeviceContext :: Map method and specify D3D11_MAP_WRITE flag.
2. The data is written to the memory address pointer.
3. When you are finished writing data call ID3D11DeviceContext :: Unmap method.
Staging a texture type may be filled and defaut type dynamic texture as ID3D11DeviceContext :: CopyResource ID3D11DeviceContext :: CopySubresourceRegion source or target objects.