DirectX Graphics – Textures Overview

What is a Texture?

A texture in DirectX is a GPU resource that stores image data used for rendering. Textures can hold color maps, normal maps, depth buffers, and more. They are accessed by shaders through Shader Resource Views (SRV) and can be sampled with various filtering modes.

Common Texture Types

TypeDescriptionTypical Use
2D TextureStandard image stored in a 2D array.Diffuse maps, normal maps.
Cube TextureSix 2D faces forming a cube.Environment mapping, skyboxes.
3D TextureVolume texture with depth dimension.Volume rendering, fog.
Array TextureArray of 2D textures.Texture atlases, material variations.

Creating a Texture (C++)

// Example: Creating a 2D texture
ID3D11Texture2D* tex = nullptr;
D3D11_TEXTURE2D_DESC desc = {};
desc.Width = 256;
desc.Height = 256;
desc.MipLevels = 1;
desc.ArraySize = 1;
desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
desc.SampleDesc.Count = 1;
desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
HRESULT hr = device->CreateTexture2D(&desc, nullptr, &tex);

Binding a Texture to a Shader

// Bind SRV to slot 0
ID3D11ShaderResourceView* srv = nullptr;
device->CreateShaderResourceView(tex, nullptr, &srv);
context->PSSetShaderResources(0, 1, &srv);

Texture Formats

DirectX supports many formats. Choose the appropriate one based on precision and performance.

Further Reading

Explore the following sections for deeper knowledge: