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

51 lines
1.1 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.
# OpenGLFence::Wait
```cpp
void Wait(uint64_t timeoutNs) override;
```
等待栅栏达到 signaled 状态或超时。
## 详细描述
此方法尝试等待 `m_sync`OpenGL 同步对象)变为 signaled 状态:
- **未信号或无同步对象**:直接调用 `glFinish()` 阻塞 CPU直到 GPU 完成所有命令,然后将 `m_completedValue` 更新为 `m_fenceValue`
- **已信号状态**:调用 `glClientWaitSync()` 尝试获取同步状态,支持超时
- **timeout = 0**:立即返回,不阻塞
内部使用 `GL_SYNC_FLUSH_COMMANDS_BIT` 标志确保客户端命令已刷新。
## 参数
| 参数 | 类型 | 描述 |
|------|------|------|
| `timeoutNs` | `uint64_t` | 超时时间,以纳秒为单位。为 `0` 时立即返回 |
## 返回值
## 示例
```cpp
OpenGLFence fence;
fence.Initialize(false);
fence.Signal();
// 等待最多 1 秒 (1000000000 ns)
fence.Wait(1000000000);
// 等待最多 100 毫秒
fence.Wait(100000000);
// timeout = 0 立即返回
fence.Wait(0);
```
## 相关文档
- [OpenGLFence 总览](fence.md) - 返回类总览
- [Signal](signal.md) - 信号栅栏
- [IsSignaled](is-signaled.md) - 非阻塞检查状态