Files
XCEngine/docs/api/rhi/opengl/device/create-fence.md
2026-03-20 02:35:45 +08:00

57 lines
1.0 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.
# OpenGLDevice::CreateFence
```cpp
RHIFence* CreateFence(const FenceDesc& desc) override
```
创建同步栅栏对象。
## 详细描述
创建用于 GPU/CPU 同步的栅栏对象。
### FenceDesc 字段
| 字段 | 描述 |
|------|------|
| `initialValue` | 初始值0=未 signaled, >0=signaled |
### 行为
- `initialValue > 0`: 创建时栅栏处于 signaled 状态
- `initialValue == 0`: 创建时栅栏处于未 signaled 状态
## 参数
- `desc` - 栅栏描述符
## 返回值
`RHIFence*` - 创建的栅栏指针
## 注意事项
- 返回的栅栏对象归调用者所有,需自行管理生命周期
- 栅栏用于同步 GPU 命令执行和 CPU 代码执行
## 示例
```cpp
FenceDesc fenceDesc;
fenceDesc.initialValue = 0;
RHIFence* fence = device.CreateFence(fenceDesc);
// 等待栅栏
while (!fence->IsSignaled()) {
// 等待或做其他工作
}
// GPU 命令完成,栅栏 signaled
```
## 相关文档
- [OpenGLDevice](device.md) - 类总览
- [OpenGLFence](../opengl-fence.md) - OpenGL 栅栏实现