D3D11_TEXTURE2D_DESC
Synopsis
typedef struct D3D11_TEXTURE2D_DESC {
UINT Width;
UINT Height;
UINT MipLevels;
UINT ArraySize;
DXGI_FORMAT Format;
DXGI_SAMPLE_DESC SampleDesc;
D3D11_USAGE Usage;
UINT BindFlags;
UINT CPUAccessFlags;
UINT MiscFlags;
} D3D11_TEXTURE2D_DESC;
Members
Member | Type | Description |
---|---|---|
Width | UINT | Texture width in texels. Must be greater than zero. |
Height | UINT | Texture height in texels. Must be greater than zero. |
MipLevels | UINT | Number of mipmap levels. Use 0 to generate all levels. |
ArraySize | UINT | Number of textures in the array. Use 1 for non‑array textures. |
Format | DXGI_FORMAT | Format of the texture data (e.g., DXGI_FORMAT_R8G8B8A8_UNORM). |
SampleDesc | DXGI_SAMPLE_DESC | Multisampling parameters (Count and Quality). |
Usage | D3D11_USAGE | Intended usage (DEFAULT, IMMUTABLE, DYNAMIC, STAGING). |
BindFlags | UINT | Combination of D3D11_BIND_ flags indicating bind points. |
CPUAccessFlags | UINT | CPU access options (D3D11_CPU_ACCESS_READ, D3D11_CPU_ACCESS_WRITE). |
MiscFlags | UINT | Miscellaneous flags (D3D11_RESOURCE_MISC_GENERATE_MIPS, etc.). |
Remarks
The D3D11_TEXTURE2D_DESC
structure describes a 2‑dimensional texture. It is used when creating a texture with ID3D11Device::CreateTexture2D
. Fields must be set according to the intended usage and hardware capabilities. For multisampled textures, SampleDesc.Count
must be greater than 1 and MipLevels
must be 1.
Example
// Create a 256x256 texture with 4 mip levels, RGBA8 format
D3D11_TEXTURE2D_DESC texDesc = {};
texDesc.Width = 256;
texDesc.Height = 256;
texDesc.MipLevels = 4;
texDesc.ArraySize = 1;
texDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
texDesc.SampleDesc.Count = 1;
texDesc.Usage = D3D11_USAGE_DEFAULT;
texDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
texDesc.CPUAccessFlags = 0;
texDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
ID3D11Texture2D* pTexture = nullptr;
HRESULT hr = device->CreateTexture2D(&texDesc, nullptr, &pTexture);
if (SUCCEEDED(hr)) {
// Use the texture
}