简体   繁体   English

分配顶点缓冲区对象

[英]Allocating vertex buffer object

I'm trying to create terrain from a heightmap in opengl(c++), and following this tutorial . 我正在尝试根据opengl(c ++)中的高度图创建地形,并按照本教程进行操作

I'm also trying to use a vertex buffer object to speed it up. 我也在尝试使用顶点缓冲区对象来加快速度。 In their example, they create a vertex object with 3 floats for x, y, z. 在他们的示例中,他们创建了一个顶点对象,该对象具有x,y,z的3个浮点数。 They then pass a pointer to an array of these vertex objects to be copied to the buffer object. 然后,它们将指针传递到这些顶点对象的数组,以将其复制到缓冲区对象。 What I don't understand is why for the size of the buffer parameter they pass it the size of the 3 floats (multiplied by the number of vertices). 我不明白的是,为什么要为buffer参数的大小传递3个float的大小(乘以顶点数)。

Surely the vertex objects being passed to it are larger than just the size of the 3 floats? 确定传递给它的顶点对象是否大于3个浮点的大小? Does the glBufferDataARB function somehow extract these variables? glBufferDataARB函数会以某种方式提取这些变量吗? Is the size of an object equal to the size of the variables in it? 对象的大小等于其中的变量的大小吗? or am I missing something? 还是我错过了什么?

VBOs store bytes. VBO存储字节。 Later gl*Pointer() and/or glVertexAttrib() calls tell OpenGL how to interpret those bytes. 随后的gl*Pointer()和/或glVertexAttrib()调用告诉OpenGL如何解释这些字节。

To store three floats you need sizeof(float) * 3 bytes. 要存储三个浮点数,您需要sizeof(float) * 3个字节。

To store N three-float vertices you need sizeof(float) * 3 * N bytes. 要存储N三浮点顶点,您需要sizeof(float) * 3 * N个字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM