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

30 lines
896 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.
# OpenGLBuffer::SetData
```cpp
void SetData(const void* data, size_t size, size_t offset = 0) override;
```
设置缓冲区数据。支持部分更新:当 `offset == 0``size` 等于缓冲区大小时,使用 `glBufferData` 替换整个缓冲区;否则使用 `glBufferSubData` 进行部分更新。
**参数:**
- `data` - 要写入的数据指针
- `size` - 数据大小(字节)
- `offset` - 缓冲区内的偏移量(默认 0
**示例:**
```cpp
// 更新整个缓冲区
buffer.SetData(vertices, sizeof(vertices));
// 部分更新
buffer.SetData(newVertices, sizeof(newVertices), sizeof(vertices));
```
**注意:** 动态缓冲区使用 `GL_DYNAMIC_DRAW`,静态缓冲区使用 `GL_STATIC_DRAW`
## 相关文档
- [OpenGLBuffer 总览](buffer.md) - 返回类总览
- [Map](map.md) - 映射缓冲区方式写入
- [Initialize](initialize.md) - 初始化缓冲区