jimvonmoon
06-03-2012, 03:22 AM
Hello,
I was just coding a simple manager for my buffer objects and I have found something that I find interesting. Let's create an IBO:
glGenBuffers(1, &bufferObject);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObject);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(arrVertexBuffer), arrVertexBuffer, GL_STATIC_DRAW);
That's right - I am creating an IBO, but fill it with vertex data.
Now let's draw something:
glBindBuffer(GL_ARRAY_BUFFER, bufferObject);
// Some code...
glDrawArrays(GL_TRIANGLES, 0, vertexCount);
I was a bit surprised that it worked. I checked it on Windows 7 with nVidia card (OpenGL 2.0) and Android 2.3.6 (GLES 2.0).
So my questions are:
1. Can I legally create a buffer as IBO and then use it as VBO (and vice versa)?
2. If yes, then I guess that IBOs and VBOs, at the moment of their creation, are in fact the same thing. So why do we need to pass the target to glBufferData? Wouldn't passing a buffer object name be more intuitive?
Sorry for those noob questions, but I find it interesting and I couldn't find an answer anywhere. Everyone is saying just "create buffer as VBO and use it as VBO" (even the OpenGL standard document), so I was hoping to get some information here. :)
I was just coding a simple manager for my buffer objects and I have found something that I find interesting. Let's create an IBO:
glGenBuffers(1, &bufferObject);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObject);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(arrVertexBuffer), arrVertexBuffer, GL_STATIC_DRAW);
That's right - I am creating an IBO, but fill it with vertex data.
Now let's draw something:
glBindBuffer(GL_ARRAY_BUFFER, bufferObject);
// Some code...
glDrawArrays(GL_TRIANGLES, 0, vertexCount);
I was a bit surprised that it worked. I checked it on Windows 7 with nVidia card (OpenGL 2.0) and Android 2.3.6 (GLES 2.0).
So my questions are:
1. Can I legally create a buffer as IBO and then use it as VBO (and vice versa)?
2. If yes, then I guess that IBOs and VBOs, at the moment of their creation, are in fact the same thing. So why do we need to pass the target to glBufferData? Wouldn't passing a buffer object name be more intuitive?
Sorry for those noob questions, but I find it interesting and I couldn't find an answer anywhere. Everyone is saying just "create buffer as VBO and use it as VBO" (even the OpenGL standard document), so I was hoping to get some information here. :)