Files
XCEngine/docs/api/rhi/d3d12/swap-chain/get-back-buffer.md
ssdfasd 26fe3cd835 D3D12: Add bounds check to GetBackBuffer and update unit tests
- Add assert() bounds check to GetBackBuffer() to catch invalid indices
- Include <cassert> in D3D12SwapChain.cpp
- Update test_swap_chain.cpp to use reference return type
- Mark InvalidIndex test as DISABLED (assert aborts on invalid index)
- Update get-back-buffer.md documentation
2026-03-20 18:35:00 +08:00

48 lines
1018 B
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.
# D3D12SwapChain::GetBackBuffer
## 函数签名
```cpp
D3D12Texture& GetBackBuffer(uint32_t index)
const D3D12Texture& GetBackBuffer(uint32_t index) const
```
## 中文描述
获取指定索引的后台缓冲区。返回引用而非指针,避免空指针检查。
## 参数
| 参数 | 类型 | 描述 |
|------|------|------|
| `index` | `uint32_t` | 缓冲区索引(必须在有效范围内) |
## 返回值
`D3D12Texture&` - 后台缓冲区纹理引用
## 注意事项
- 返回引用而非指针,调用者无需检查空值
- 如果索引越界,会触发 assert 断言失败
- 返回的引用在 SwapChain 存活期间有效SwapChain 销毁后引用失效
## 复杂度
O(1)
## 示例
```cpp
// 获取后台缓冲区(返回引用)
D3D12Texture& buffer = swapChain.GetBackBuffer(0);
// 使用封装接口
gCommandList.TransitionBarrier(buffer.GetResource(),
ResourceStates::Present, ResourceStates::RenderTarget);
```
## 相关文档
- [D3D12SwapChain](swap-chain.md) - 类总览