Files
XCEngine/docs/api/rhi/d3d12/sampler/initialize.md

53 lines
1.3 KiB
Markdown
Raw Normal View History

2026-03-20 02:35:45 +08:00
# D3D12Sampler::Initialize
## 函数签名
```cpp
bool Initialize(ID3D12Device* device, const D3D12_SAMPLER_DESC& desc)
```
## 描述
初始化 D3D12 采样器对象。根据提供的采样器描述符创建并配置 D3D12 采样器状态。
## 参数
| 参数 | 类型 | 描述 |
|------|------|------|
| `device` | `ID3D12Device*` | D3D12 设备指针,用于创建采样器资源 |
| `desc` | `const D3D12_SAMPLER_DESC&` | 采样器描述符,包含过滤模式、寻址模式等配置 |
## 返回值
`bool` - 初始化成功返回 `true`,否则返回 `false`
## 示例
```cpp
D3D12Sampler sampler;
D3D12_SAMPLER_DESC desc = {};
desc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
desc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
desc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
desc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
desc.MipLODBias = 0.0f;
desc.MaxAnisotropy = 16;
desc.ComparisonFunc = D3D12_COMPARISON_FUNC_NEVER;
desc.BorderColor[0] = 0.0f;
desc.BorderColor[1] = 0.0f;
desc.BorderColor[2] = 0.0f;
desc.BorderColor[3] = 0.0f;
desc.MinLOD = 0.0f;
desc.MaxLOD = D3D12_FLOAT32_MAX;
if (sampler.Initialize(device, desc)) {
// 采样器初始化成功
}
```
## 相关文档
- [D3D12Sampler::Shutdown](shutdown.md) - 关闭采样器
- [D3D12Sampler::GetDesc](get-desc.md) - 获取采样器描述符
- [D3D12Sampler](sampler.md) - 类总览