0

我已经看到了很多关于减少对 openGL 的调用的信息,但是我对管道的理解不够好。您可以完全设置 VBO 时间吗?具体使用此示例,它设置 VBO,然后每个帧在绘制调用之前调用启用/指针设置。VBO 可以在创建时使用启用/指针设置完全设置吗?

像这样的东西

 Data_Init_Func(...)
 {
 ....

 glGenBuffers(1, &IndexVBOID);
 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID);
 glBufferData(GL_ELEMENT_ARRAY_BUFFER, SizeInBytes, NULL, GL_STATIC_DRAW);
 short pindices[YYY];
 pindices[0]=0;
 pindices[1]=5;
 //etc...
 offsetInByte=0;
 glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, offsetInByte, SizeInBytes, pindices);

 glGenBuffers(1, VertexVBOID);
 glBindBuffer(GL_ARRAY_BUFFER, VertexVBOID);
 glBufferData(GL_ARRAY_BUFFER, SizeInBytes, NULL, GL_STATIC_DRAW);4

 //data creation and binding
 ...

 // Normally it seems like this code is PER FRAME... DOES IT NEED TO BE?
 glEnableClientState(GL_VERTEX_ARRAY);
 glEnableClientState(GL_NORMAL_ARRAY); 
 glVertexPointer(3, GL_FLOAT, 64, BUFFER_OFFSET(0));
 glNormalPointer(GL_FLOAT, 64, BUFFER_OFFSET(12));
 glClientActiveTexture(GL_TEXTURE0);
 glEnableClientState(GL_TEXTURE_COORD_ARRAY);    //Notice that after we call            
 glClientActiveTexture, we enable the array
 glTexCoordPointer(2, GL_FLOAT, 64, BUFFER_OFFSET(24));
 glClientActiveTexture(GL_TEXTURE1);
 glEnableClientState(GL_TEXTURE_COORD_ARRAY);    //Notice that after we call
 glClientActiveTexture, we enable the array
 glTexCoordPointer(2, GL_FLOAT, 64, BUFFER_OFFSET(32));
 glClientActiveTexture(GL_TEXTURE2);
 glEnableClientState(GL_TEXTURE_COORD_ARRAY);    //Notice that after we call
 glClientActiveTexture, we enable the array
 glTexCoordPointer(2, GL_FLOAT, 64, BUFFER_OFFSET(40));
 ...
 }

 Draw(...)
 {
 glBindBuffer(GL_ARRAY_BUFFER_ARB, VertexVBOID);         // for vertex coordinates
 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexVBOID); // for indices

 // DO I NEED TO CALL THE VERTEX ENABLING/POINTER SETUP HERE?

 // draw 6 quads using offset of index array
 glDrawRangeElements(GL_TRIANGLES, x, y, z, GL_UNSIGNED_SHORT, BUFFER_OFFSET(0));

 ...
 }
4

1 回答 1

1
// DO I NEED TO CALL THE VERTEX ENABLING/POINTER SETUP HERE?

是的。

没有任何属性启用和gl*Pointer调用修改缓冲区对象本身。您不会告诉缓冲区对象它被用于位置和法线。将缓冲区对象想象成一个哑字节数组。

这些gl*Pointer调用告诉 OpenGL 如何解释该字节数组。它们没有附加到缓冲区。他们不修改缓冲区。它们只是告诉 OpenGL 在哪里可以找到特定缓冲区中的特定数据。

如果您想存储这些设置并在以后重置它们,您需要一个顶点数组对象

于 2012-04-09T16:19:07.657 回答