>- Guide for integrating and using the DirectXTex texture processing library in new projects. Use this skill when asked about adding DirectXTex to a project, loading/saving textures, format conversion, mipmap generation, block compression, or Direct3D resource creation.
npx skills add https://github.com/microsoft/DirectXTex --skill directxtex-usage
This skill provides guidance for integrating the DirectXTex texture processing library into a C++ project.
Invoke this skill when:
DirectXTex is a texture processing library for Direct3D 11 and Direct3D 12 applications. It provides support for reading and writing DDS files, and performing various texture content processing operations including resizing, format conversion, mipmap generation, block compression, and normal map creation.
directxtex_desktop_win10, directxtex_uwpdirectxtexIn your vcpkg.json file, add the following:
{
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"dependencies": [
"directxtex"
]
}
vcpkg install directxtex
Features: dx12 (DirectX 12 API support), openexr (OpenEXR support), tools (command-line tools). Triplets: x64-windows, x64-linux, arm64-windows, etc.
For DLL usage (x64-windows default triplet), define DIRECTX_TEX_IMPORT in your consuming project. For static library usage, use -static-md triplet variants.
CMakeLists.txt:
find_package(directxtex CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Microsoft::DirectXTex)
Use directxtex_desktop_win10 for Win32 desktop applications or directxtex_uwp for UWP apps.
Add the appropriate .vcxproj from the DirectXTex/ folder to your solution and add a project reference. Add the DirectXTex directory to your Additional Include Directories.
#include <d3d12.h> // or <d3d11_1.h> — include BEFORE DirectXTex.h
#include <DirectXTex.h>
using namespace DirectX;
For auxiliary features, include additional headers:
#include <DirectXTexEXR.h> // OpenEXR support
#include <DirectXTexJPEG.h> // libjpeg support (non-WIC)
#include <DirectXTexPNG.h> // libpng support (non-WIC)
#include <DirectXTexXbox.h> // Xbox tiling extensions
> DirectXTexJPEG, DirectXTexPNG are typically only used on Linux.
ScratchImage is the primary image container. It owns pixel memory and provides access to individual mip levels, array slices, and volume depth slices.
ScratchImage image;
HRESULT hr = LoadFromDDSFile(L"texture.dds", DDS_FLAGS_NONE, nullptr, image);
if (FAILED(hr))
// handle error
const TexMetadata& metadata = image.GetMetadata();
const Image* img = image.GetImage(0, 0, 0); // mip 0, item 0, slice 0
Describes the texture dimensions, format, mip levels, array size, and type (1D, 2D, 3D, cubemap).
A memory buffer used for serialized output (e.g., saving to memory rather than files).
All processing functions return HRESULT. Check with FAILED() / SUCCEEDED() macros.
// From DDS file
ScratchImage image;
HRESULT hr = LoadFromDDSFile(L"texture.dds", DDS_FLAGS_NONE, nullptr, image);
// From WIC file (PNG, BMP, JPEG, TIFF, etc.) — Windows only
ScratchImage image;
HRESULT hr = LoadFromWICFile(L"texture.png", WIC_FLAGS_NONE, nullptr, image);
// From TGA file
ScratchImage image;
HRESULT hr = LoadFromTGAFile(L"texture.tga", TGA_FLAGS_NONE, nullptr, image);
// From HDR file
ScratchImage image;
HRESULT hr = LoadFromHDRFile(L"texture.hdr", nullptr, image);
// From memory
ScratchImage image;
HRESULT hr = LoadFromDDSMemory(pData, dataSize, DDS_FLAGS_NONE, nullptr, image);
// Save to DDS file
const Image* img = image.GetImages();
size_t nimages = image.GetImageCount();
const TexMetadata& metadata = image.GetMetadata();
HRESULT hr = SaveToDDSFile(img, nimages, metadata, DDS_FLAGS_NONE, L"output.dds");
// Save single image to WIC file (PNG) — Windows only
hr = SaveToWICFile(*image.GetImage(0, 0, 0), WIC_FLAGS_NONE,
GetWICCodec(WIC_CODEC_PNG), L"output.png");
// Save to memory blob
Blob blob;
hr = SaveToDDSMemory(img, nimages, metadata, DDS_FLAGS_NONE, blob);
ScratchImage converted;
HRESULT hr = Convert(image.GetImages(), image.GetImageCount(), image.GetMetadata(),
DXGI_FORMAT_R8G8B8A8_UNORM, TEX_FILTER_DEFAULT, TEX_THRESHOLD_DEFAULT, converted);
ScratchImage resized;
HRESULT hr = Resize(image.GetImages(), image.GetImageCount(), image.GetMetadata(),
1024, 1024, TEX_FILTER_DEFAULT, resized);
ScratchImage mipChain;
HRESULT hr = GenerateMipMaps(image.GetImages(), image.GetImageCount(), image.GetMetadata(),
TEX_FILTER_DEFAULT, 0, mipChain);
// 0 levels = generate full mip chain
ScratchImage compressed;
HRESULT hr = Compress(image.GetImages(), image.GetImageCount(), image.GetMetadata(),
DXGI_FORMAT_BC7_UNORM, TEX_COMPRESS_DEFAULT, TEX_THRESHOLD_DEFAULT, compressed);
// GPU-accelerated BC6H/BC7 compression (Direct3D 11)
ScratchImage compressed;
HRESULT hr = Compress(pDevice, image.GetImages(), image.GetImageCount(), image.GetMetadata(),
DXGI_FORMAT_BC7_UNORM, TEX_COMPRESS_DEFAULT, TEX_ALPHA_WEIGHT_DEFAULT, compressed);
ScratchImage decompressed;
HRESULT hr = Decompress(image.GetImages(), image.GetImageCount(), image.GetMetadata(),
DXGI_FORMAT_R8G8B8A8_UNORM, decompressed);
ScratchImage normalMap;
HRESULT hr = ComputeNormalMap(*image.GetImage(0, 0, 0),
CNMAP_CHANNEL_LUMINANCE, 2.0f,
DXGI_FORMAT_R8G8B8A8_UNORM, normalMap);
ScratchImage pmAlpha;
HRESULT hr = PremultiplyAlpha(image.GetImages(), image.GetImageCount(), image.GetMetadata(),
TEX_PMALPHA_DEFAULT, pmAlpha);
#include <d3d11.h>
#include <DirectXTex.h>
// Create texture resource
ID3D11Resource* pTexture = nullptr;
HRESULT hr = CreateTexture(pDevice, image.GetImages(), image.GetImageCount(),
image.GetMetadata(), &pTexture);
// Create shader resource view directly
ID3D11ShaderResourceView* pSRV = nullptr;
hr = CreateShaderResourceView(pDevice, image.GetImages(), image.GetImageCount(),
image.GetMetadata(), &pSRV);
#include <d3d12.h>
#include <DirectXTex.h>
// Create committed resource
ID3D12Resource* pTexture = nullptr;
HRESULT hr = CreateTexture(pDevice, image.GetMetadata(), &pTexture);
// Prepare upload data for CopyTextureRegion
std::vector<D3D12_SUBRESOURCE_DATA> subresources;
hr = PrepareUpload(pDevice, image.GetImages(), image.GetImageCount(),
image.GetMetadata(), subresources);
A common offline texture processing pipeline:
// 1. Load source image
ScratchImage source;
HRESULT hr = LoadFromWICFile(L"diffuse.png", WIC_FLAGS_NONE, nullptr, source);
if (FAILED(hr)) return hr;
// 2. Resize if needed
ScratchImage resized;
if (source.GetMetadata().width != 1024 || source.GetMetadata().height != 1024)
{
hr = Resize(*source.GetImage(0, 0, 0), 1024, 1024, TEX_FILTER_DEFAULT, resized);
if (FAILED(hr)) return hr;
}
else
{
resized = std::move(source);
}
// 3. Generate mipmaps
ScratchImage mipChain;
hr = GenerateMipMaps(*resized.GetImage(0, 0, 0), TEX_FILTER_DEFAULT, 0, mipChain);
if (FAILED(hr)) return hr;
// 4. Compress to BC7
ScratchImage compressed;
hr = Compress(mipChain.GetImages(), mipChain.GetImageCount(), mipChain.GetMetadata(),
DXGI_FORMAT_BC7_UNORM, TEX_COMPRESS_DEFAULT, TEX_THRESHOLD_DEFAULT, compressed);
if (FAILED(hr)) return hr;
// 5. Save as DDS
hr = SaveToDDSFile(compressed.GetImages(), compressed.GetImageCount(),
compressed.GetMetadata(), DDS_FLAGS_NONE, L"diffuse.dds");
DirectXTex provides utility functions for querying DXGI format properties:
bool compressed = IsCompressed(DXGI_FORMAT_BC7_UNORM); // true
size_t bpp = BitsPerPixel(DXGI_FORMAT_R8G8B8A8_UNORM); // 32
bool srgb = IsSRGB(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); // true
DXGI_FORMAT srgbFmt = MakeSRGB(DXGI_FORMAT_R8G8B8A8_UNORM); // _SRGB variant
DXGI_FORMAT linearFmt = MakeLinear(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); // non-SRGB
size_t rowPitch, slicePitch;
ComputePitch(DXGI_FORMAT_R8G8B8A8_UNORM, 256, 256, rowPitch, slicePitch);
| Platform | DDS | HDR | TGA | WIC | Direct3D 11 | Direct3D 12 |
| --- | --- | --- | --- | --- | --- | --- |
| Windows desktop | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| UWP | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| Xbox (GDK) | ✓ | ✓ | ✓ | — | ✓ | ✓ |
| Linux | ✓ | ✓ | ✓ | — | — | — |
DirectXTex includes three CLI tools for texture processing:
Example texconv usage:
texconv -f BC7_UNORM -m 0 -y diffuse.png
Develop React Native, Flutter, or native mobile apps with modern architecture patterns. Masters cross-platform development, native integrations, offline sync, and app store optimization. Use PROACTIVELY for mobile features, cross-platform code, or app optimization.
Serves as a reviewer of the codebase with instructions on looking for Apple App Store optimizations or rejection reasons.
Track physical units and propagate measurement uncertainty in scientific calculations using pint and uncertainties. Use for unit conversion and dimensional checking, GUM uncertainty budgets, Type A and Type B evaluation, coverage factors and expanded uncertainty, Monte Carlo propagation, significant-figure and plus-minus reporting, error propagation through curve fits, CODATA constants, auditing Python code for stripped units or broken uncertainty propagation, and order-of-magnitude plausibility checks using dimensionless groups (Reynolds, Peclet, Damkohler, Knudsen, Biot, Womersley), characteristic scales such as diffusion time or Debye length, and observed magnitude ranges. Trigger on "is this number physically reasonable", "sanity check these units", "what regime is this flow in", or a result that looks off by orders of magnitude.
Master AngularJS to Angular migration, including hybrid apps, component conversion, dependency injection changes, and routing migration.
Build, read, validate, modify SBML biological network models via the libSBML Python API. SBML Levels 1–3, reactions/kinetic laws, species, rules, FBC extension for flux balance, conversion. Interoperates with COBRApy, Tellurium/RoadRunner, COPASI. Use when programmatically constructing ODE or constraint-based metabolic/signaling models in SBML.
Use when you need to run a binary, trace execution, or observe runtime behavior. Runtime analysis via QEMU emulation, GDB debugging, and Frida hooking - syscall tracing (strace), breakpoints, memory inspection, function interception. Keywords - "run binary", "execute", "debug", "trace syscalls", "set breakpoint", "qemu", "gdb", "frida", "strace", "watch memory
Use when reverse engineering tools are missing, not working, or need configuration. Installation guides for radare2 (r2), Ghidra, GDB, QEMU, Frida, binutils, and cross-compilation toolchains. Keywords - "install radare2", "setup ghidra", "r2 not found", "qemu missing", "tool not installed", "configure gdb", "cross-compiler
Use when first encountering an unknown binary, ELF file, executable, or firmware blob. Fast fingerprinting via rabin2 - architecture detection (ARM, x86, MIPS), ABI identification, dependency mapping, string extraction. Keywords - "what is this binary", "identify architecture", "check file type", "rabin2", "file analysis", "quick scan
Take microsoft/directxtex-usage from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.