OpenGL ES 2.0:使用具有新顶点数据大小的 glBufferData
我有一个顶点属性数组 GLfloat *vxData
。我已将 GL_ARRAY_BUFFER
和 GL_ELEMENT_ARRAY_BUFFER
与 vxData
和正确的索引数据绑定在一起,并且初始顶点渲染成功。
在每个渲染步骤中,我都会执行以下操作:
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, vxDataSize, vxData, GL_STATIC_DRAW);
glDrawElements(...)
在某个阶段,vxData
更改大小以容纳更少/更多的顶点,重新创建索引数据以反映这一点,并更新 vxDataSize
。对于数据更改后立即进行的渲染,简单地调用上面相同的行是否正确?
我知道其他可能性,例如使用 glMapBufferOES
,我只是想知道上述内容在技术上对于这种情况是否正确。
I have an array of vertex attributes GLfloat *vxData
. I've bound both GL_ARRAY_BUFFER
and GL_ELEMENT_ARRAY_BUFFER
with vxData
and the correct index data, and the initial vertices render successfully.
At each render step I do:
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
glBufferData(GL_ARRAY_BUFFER, vxDataSize, vxData, GL_STATIC_DRAW);
glDrawElements(...)
At some stage, vxData
changes size to accommodate fewer/more vertices, the index data is recreated to reflect this, and vxDataSize
is updated. For the render immediately following this change in data, is it correct to simply call the same lines above?
I'm aware of alternative possibilities e.g. using glMapBufferOES
, I'd simply like to know whether the above is technically correct for this scenario.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确吗?是的,您可以这样做,并且您应该获得能够呈现您期望的功能的代码。这好吗?
不。
首先,您对 OpenGL 实现撒了谎。你告诉它你正在制作静态数据。 STATIC 表示您上传一次。一次。如果您每帧都这样做,那么您应该使用 STREAM,而不是 STATIC。
其次,您不应该使缓冲区变大或变小。刷新旧数据是一回事,但如果您告诉 OpenGL 缓冲区需要更大,那么它必须实际分配内存。那不好。选择尺寸并坚持使用。选择您可以使用的最大尺寸并留在那里。
Is it correct? Yes, you can do that and you should get functional code that renders what you expect it to. Is it good?
No.
First, you're lying to the OpenGL implementation. You told it that you were making STATIC data. STATIC means you upload to it once. If you're doing that every frame, then you should be using STREAM, not STATIC.
Second, you should not be making buffers bigger and smaller. It's one thing to flush the old data out, but if you're telling OpenGL that the buffer needs to be bigger, then it has to actually allocate memory. That's not good. Pick a size and stick with it. Pick the largest size you can expect to use and stay there.