Files
XCEngine/docs/api/rhi/d3d12/sampler/index.md
2026-03-20 02:35:45 +08:00

72 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# D3D12Sampler 类
## 命名空间
`XCEngine::RHI`
## 类型
类 (Class),继承自 `RHISampler`
## 描述
D3D12 采样器实现类,用于配置纹理采样状态。封装 D3D12 采样器描述符,支持过滤模式、寻址模式等采样参数配置。
## 概述
`D3D12Sampler` 是 RHI 抽象层在 DirectX 12 后端的采样器实现。该类管理 D3D12 采样器状态,与 `RHISampler` 基类配合提供跨平台统一的采样器接口。
**当前实现状态**: 本类为存根实现,`Initialize()` 仅存储描述符,未创建实际 D3D12 采样器对象。
## 公共方法表格
| 方法 | 签名 | 描述 |
|------|------|------|
| `D3D12Sampler` | `D3D12Sampler()` | 构造函数,初始化描述符为零 |
| `~D3D12Sampler` | `~D3D12Sampler()` | 析构函数,调用 `Shutdown()` |
| `Initialize` | `bool Initialize(ID3D12Device* device, const D3D12_SAMPLER_DESC& desc)` | 初始化采样器 |
| `Shutdown` | `void Shutdown()` | 关闭采样器,重置描述符 |
| `GetDesc` | `D3D12_SAMPLER_DESC GetDesc() const` | 获取采样器描述符副本 |
| `GetNativeHandle` | `void* GetNativeHandle()` | 获取原生句柄(暂未实现) |
| `GetID` | `unsigned int GetID()` | 获取采样器 ID暂未实现 |
| `Bind` | `void Bind(unsigned int unit)` | 绑定到纹理单元(暂未实现) |
| `Unbind` | `void Unbind(unsigned int unit)` | 从纹理单元解绑(暂未实现) |
## 头文件
```cpp
#include "XCEngine/RHI/D3D12/D3D12Sampler.h"
```
## 使用示例
```cpp
#include "XCEngine/RHI/D3D12/D3D12Sampler.h"
using namespace XCEngine::RHI;
// 创建设备指针 (假设已创建)
ID3D12Device* device = ...;
// 配置采样器描述符
D3D12_SAMPLER_DESC samplerDesc = {};
samplerDesc.Filter = D3D12_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
samplerDesc.AddressV = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
samplerDesc.AddressW = D3D12_TEXTURE_ADDRESS_MODE_WRAP;
samplerDesc.MaxAnisotropy = 16;
samplerDesc.ComparisonFunc = D3D12_COMPARISON_FUNC_LESS;
samplerDesc.BorderColor[0] = 0.0f;
samplerDesc.BorderColor[1] = 0.0f;
samplerDesc.BorderColor[2] = 0.0f;
samplerDesc.BorderColor[3] = 1.0f;
// 创建并初始化采样器
D3D12Sampler* sampler = new D3D12Sampler();
if (sampler->Initialize(device, samplerDesc)) {
D3D12_SAMPLER_DESC desc = sampler->GetDesc();
// 使用采样器...
sampler->Shutdown();
}
delete sampler;
```
## 相关文档
- [RHISampler 基类](../RHISampler.md)
- [D3D12 枚举映射](./D3D12Enum.md)