Files
XCEngine/docs/api/rhi/opengl/command-list/clear.md

47 lines
1.6 KiB
Markdown
Raw Normal View History

# OpenGLCommandList::Clear
```cpp
2026-03-20 02:35:45 +08:00
void Clear(float r, float g, float b, float a, unsigned int buffers)
```
2026-03-20 02:35:45 +08:00
清除指定的缓冲区。
**参数:**
2026-03-20 02:35:45 +08:00
- `r` - 清除颜色红色分量(范围 0.0f - 1.0f
- `g` - 清除颜色绿色分量(范围 0.0f - 1.0f
- `b` - 清除颜色蓝色分量(范围 0.0f - 1.0f
- `a` - 清除颜色 Alpha 分量(范围 0.0f - 1.0f
- `buffers` - 要清除的缓冲区标志,使用 `ClearFlag` 枚举值的位或组合:
- `ClearFlag::Color` (1) - 清除颜色缓冲区
- `ClearFlag::Depth` (2) - 清除深度缓冲区
- `ClearFlag::Stencil` (4) - 清除模板缓冲区
**返回值**:无
**示例:**
```cpp
2026-03-20 02:35:45 +08:00
// 清除颜色缓冲区
commandList->Clear(0.0f, 0.0f, 0.0f, 1.0f, static_cast<unsigned int>(ClearFlag::Color));
// 清除颜色和深度缓冲区
commandList->Clear(0.0f, 0.0f, 0.0f, 1.0f,
static_cast<unsigned int>(ClearFlag::Color) |
static_cast<unsigned int>(ClearFlag::Depth));
// 清除所有缓冲区
commandList->Clear(0.0f, 0.0f, 0.0f, 1.0f,
static_cast<unsigned int>(ClearFlag::Color) |
static_cast<unsigned int>(ClearFlag::Depth) |
static_cast<unsigned int>(ClearFlag::Stencil));
```
## 相关文档
- [OpenGLCommandList 总览](command-list.md) - 返回类总览
2026-03-20 02:35:45 +08:00
- [ClearColor](clear-color.md) - 仅清除颜色缓冲区
- [ClearDepth](clear-depth.md) - 仅清除深度缓冲区
- [ClearStencil](clear-stencil.md) - 仅清除模板缓冲区
- [ClearDepthStencil](clear-depth-stencil.md) - 清除深度和模板缓冲区
- [ClearFlag 枚举](../../enums/clear-flag.md) - 清除缓冲区标志