How to: Initialize a Texture Programmatically

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.
0 out of 1 rated this helpful - Rate this topic

You can initialize a texture during object creation, or you can fill the object programmatically after it is created. This topic has several examples showing how to initialize textures that are created with different types of usages. This example assumes you already know how to Create a Texture.

Default Usage

The most common type of usage is default usage. To fill a default texture (one created with D3D11_USAGE_DEFAULT) you can either:

Dynamic Usage

To fill a dynamic texture (one created with D3D11_USAGE_DYNAMIC):

  1. Get a pointer to the texture memory by passing in D3D11_MAP_WRITE_DISCARD when calling ID3D11DeviceContext::Map.
  2. Write data to the memory.
  3. Call ID3D11DeviceContext::Unmap when you are finished writing data.

Staging Usage

To fill a staging texture (one created with D3D11_USAGE_STAGING):

  1. Get a pointer to the texture memory by passing in D3D11_MAP_WRITE when calling ID3D11DeviceContext::Map.
  2. Write data to the memory.
  3. Call ID3D11DeviceContext::Unmap when you are finished writing data.

A staging texture can then be used as the source parameter to ID3D11DeviceContext::CopyResource or ID3D11DeviceContext::CopySubresourceRegion to fill a default or dynamic resource.

Related topics

Textures

 

 

Send comments about this topic to Microsoft

Build date: 11/28/2012

Did you find this helpful?
(1500 characters remaining)

Community Additions

© 2013 Microsoft. All rights reserved.