Skip to content

Latest commit

 

History

History
62 lines (37 loc) · 2.85 KB

overviews-direct3d-11-resources-textures-how-to-fill-manually.md

File metadata and controls

62 lines (37 loc) · 2.85 KB
title description ms.assetid ms.topic ms.date
How to Initialize a Texture Programmatically
This topic has several examples showing how to initialize textures that are created with different types of usages.
65e8ae82-50aa-4303-853e-3457da18f44f
article
05/31/2018

How to: Initialize a Texture Programmatically

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

How to Use Direct3D 11

Textures