我已经看到了很多关于减少对 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));
...
}