OpenGL ES 2.0 和顶点缓冲区对象 (VBO)
我不知道如何在 opengl es 2.0 for iphone 中为我的地形使用顶点缓冲区对象。它是静态数据,所以我希望通过使用 VBO 来提高速度。在常规 OpenGL 中,我使用显示列表和着色器没有问题。但是,在 opengl es 2.0 中,我必须将顶点数据作为属性发送到着色器,并且不知道这如何与 VBO 一起使用。顶点缓冲区如何知道调用时它必须将顶点数据绑定到什么属性?这在 opengl es 2.0 中可能吗?如果没有,是否有其他方法可以优化静态地形的渲染?
I can't figure out how to use a vertex buffer object for my terrain in opengl es 2.0 for iphone. It's static data so I'm hoping for a speed boost by using VBO. In regular OpenGL, I use display lists along with shaders no problem. However, in opengl es 2.0 I have to send the vertex data to the shader as an attribute and don't know how this works with the VBO. How can the vertex buffer know what attribute it has to bind the vertex data to when called? Is this even possible in opengl es 2.0? If not, are there other ways I can optimize the rendering of my terrain that is static?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然,这实际上非常简单,您的属性有一个位置,并且顶点数据通过普通顶点数组的
glVertexAttribPointer()
提供,如下所示:对于 VBO,它是相同的,但您必须绑定
GL_ARRAY_BUFFER
目标的缓冲区,并且glVertexAttribPointer()
的最后一个参数现在是缓冲区内存中的偏移量 贮存。指针值本身被解释为偏移量:在本例中,假设顶点数据在缓冲区的开头上传,则偏移量为 0。偏移量以字节为单位。
然后使用
glDrawArrays()
/glDrawElements()
执行绘图。希望这有帮助!Sure, this is pretty simple actually, your attribute has a location, and vertex data is fed with
glVertexAttribPointer()
for plain Vertex Arrays, like this:For VBOs, it's the same, but you have to bind the buffer to the
GL_ARRAY_BUFFER
target, and the last parameter ofglVertexAttribPointer()
is now an offset into the buffer memory storage. The pointer value itself is interpreted as a offset:In this case the offset is 0, assuming the vertex data is uploaded at the start of the buffer. The offset is measures in bytes.
The drawing is then performed with
glDrawArrays()
/glDrawElements()
. Hope this helps!