Files
XCEngine/docs/api/rhi/d3d12/d3d12-render-target-view.md

69 lines
1.8 KiB
Markdown
Raw Normal View History

# D3D12RenderTargetView
DirectX 12 渲染目标视图的 D3D12 实现。
## 头文件
```cpp
#include <XCEngine/RHI/D3D12/D3D12RenderTargetView.h>
```
## 公共成员函数
### 构造函数与析构函数
#### `D3D12RenderTargetView()`
默认构造函数。
#### `~D3D12RenderTargetView()`
析构函数,确保调用 `Shutdown()`
### 初始化
#### `void Initialize(ID3D12Device* device, ID3D12Resource* resource, const D3D12_RENDER_TARGET_VIEW_DESC* desc = nullptr)`
在描述符堆中分配描述符并创建 RTV。
- `device`: D3D12 设备
- `resource`: 资源对象
- `desc`: RTV 描述(可选,自动推断)
#### `void InitializeAt(ID3D12Device* device, ID3D12Resource* resource, D3D12_CPU_DESCRIPTOR_HANDLE handle, const D3D12_RENDER_TARGET_VIEW_DESC* desc = nullptr)`
在指定描述符句柄位置创建 RTV。
- `handle`: 预分配的描述符句柄
#### `void Shutdown()`
释放 RTV不释放资源
### 属性
#### `D3D12_CPU_DESCRIPTOR_HANDLE GetCPUDescriptorHandle() const`
获取 CPU 描述符句柄。
### 静态辅助函数
#### `static D3D12_RENDER_TARGET_VIEW_DESC CreateDesc(Format format, D3D12_RTV_DIMENSION dimension = D3D12_RTV_DIMENSION_TEXTURE2D)`
创建 RTV 描述。
## 内部成员
| 成员 | 类型 | 描述 |
|------|------|------|
| `m_handle` | `D3D12_CPU_DESCRIPTOR_HANDLE` | CPU 描述符句柄 |
| `m_resource` | `ID3D12Resource*` | 关联的资源 |
## 使用示例
```cpp
D3D12RenderTargetView rtv;
rtv.Initialize(device->GetDevice(), texture->GetResource());
// Or at specific handle
D3D12_CPU_DESCRIPTOR_HANDLE handle = rtvHeap.GetCPUDescriptorHandle(0);
D3D12RenderTargetView rtv2;
rtv2.InitializeAt(device->GetDevice(), texture2->GetResource(), handle);
```
## 备注
- RTV 不拥有底层资源Shutdown 不会释放资源
- RTV 必须在 RTV 类型描述符堆中分配