glDeleteBuffers slower than glBufferData(glDeleteBuffers 比 glBufferData 慢)
问题描述
我在我的 iOS/Android 游戏中遇到了一些性能问题,其中几个 VBO 必须不时更新.在对我的游戏进行分析后,结果表明 glDeleteBuffers() 每次 VBO 更新最多需要 7 毫秒.当帧通常只需要 4 毫秒来渲染时,这当然会导致打嗝.
I'm having a bit of performance issue in my iOS/Android game where several VBO's have to be updated every once in a while. After profiling my game it turns out that glDeleteBuffers() takes up to 7ms per VBO update. This of course results in a hiccup when frames normally take only 4 ms to render.
这是我更新 VBO 的部分:
Here's the part where I update my VBO:
Chunk* chunk;
pthread_join(constructionThread, (void**)&chunk);
building = false;
if (vboID)
{
//takes 7 milliseconds
glDeleteBuffers(1, &vboID);
vboID = 0;
}
if (offset)
{
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
//takes about 1-2 milliseconds, which is acceptable
glBufferData(GL_ARRAY_BUFFER, offset * 4, constructionBuffer, GL_STATIC_DRAW);
}
其中的偏移量是一个实例变量,基本上是新 VBO 的大小,变化很大.vboID 不言自明,我猜 ;)
where offset is an instance variable is basically the size of the new VBO, which is quite variable. vboID speaks for itself, I guess ;)
推荐答案
glGenBuffers
和 glDeleteBuffers
分别设计为仅在初始化和清理时运行.在运行时调用它们是不好的.
glGenBuffers
and glDeleteBuffers
are designed to only be run on initialization and cleanup, respectively. Calling them during runtime is bad.
glBufferData
用一组新数据替换当前缓冲区数据,这会自动更改缓冲区的大小.您可以安全地删除整个 glGenBuffers
/glDeleteBuffers
并将其移至初始化和清理.
glBufferData
replaces the current buffer data with a new set of data, which automatically changes the size of the buffer. You can safely remove the whole glGenBuffers
/glDeleteBuffers
thing and move it into initialization and cleanup.
此外,您将缓冲区创建为静态缓冲区.这告诉 OpenGL 您几乎永远不会更改它,因此它以一种在 GPU 上访问速度更快但从系统其余部分访问速度较慢的方式存储它.尝试将 GL_STATIC_DRAW
更改为 GL_DYNAMIC_DRAW
或 GL_STREAM_DRAW
.更多信息在这里:http://www.opengl.org/wiki/Buffer_Objects#Buffer_Object_Usage
Additionally, you are creating the buffer as a static buffer. This is telling OpenGL that you will almost never change it so it stores it in a way that's quicker to access on the GPU but slower to access from the rest of the system. Try changing GL_STATIC_DRAW
to GL_DYNAMIC_DRAW
or GL_STREAM_DRAW
. More on this here: http://www.opengl.org/wiki/Buffer_Objects#Buffer_Object_Usage
这篇关于glDeleteBuffers 比 glBufferData 慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:glDeleteBuffers 比 glBufferData 慢
基础教程推荐
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- 运算符重载的基本规则和习语是什么? 2022-10-31
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- C++,'if' 表达式中的变量声明 2021-01-01
- 设计字符串本地化的最佳方法 2022-01-01