I have just started to learn (modern) OpenGL recently, so it is possible that I have missed something. And I definitely can't say I know how OpenGL works like a real pro, so what I'm saying is merely my understanding. Please do correct me if you don't feel troubled.
I have found the good old task by which I'm asked to draw a textured cube on the screen. I have implemented a coloured cube using EBO:
// format: {xyzrgb}
float square[] = {
-0.5f, -0.5f, -0.5f, 1.f, 0.f, 0.f, 1.f,
0.5f, -0.5f, -0.5f, 1.f, 0.f, 0.f, 1.f,
0.5f, 0.5f, -0.5f, 1.f, 0.f, 0.f, 1.f,
-0.5f, 0.5f, -0.5f, 1.f, 0.f, 0.f, 1.f,
-0.5f, -0.5f, 0.5f, 1.f, 0.f, 0.f, 1.f,
0.5f, -0.5f, 0.5f, 1.f, 0.f, 0.f, 1.f,
0.5f, 0.5f, 0.5f, 1.f, 0.f, 0.f, 1.f,
-0.5f, 0.5f, 0.5f, 1.f, 0.f, 0.f, 1.f,
};
unsigned int cubeindices[] = {
0, 1, 2,
2, 3, 0,
4, 5, 1,
1, 0, 4,
1, 5, 6,
6, 2, 1,
5, 4, 7,
7, 6, 5,
3, 2, 6,
6, 7, 3,
4, 0, 3,
3, 7, 4,
};
And I have used glDrawElements to draw the cube:
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 3*sizeof(GL_FLOAT), (const void*)0);
glVertexAttribPointer(1, 3, GL_FLOAT, false, 3*sizeof(GL_FLOAT), (const void*)(3*sizeof(GL_FLOAT)));
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, iboID);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, nullptr);
I have to say that my codes are not structured in this way, I just picked up all the OpenGL functions to make them easier to read. There may be some issues, but my own codes did compile, and I hope my idea can be understood by the scraped ones.
----------- the question -----------
I guess that glVertexAttribPointer() generated some arrays for shaders (possibly a VBO?), and by calling glDrawElements the vertex shader receives the array "expanded" according to the EBO. layout (location = 0) in vec4 position and layout (location = 1) in vec3 colour correspond to the two vertex attribute arrays respectively.
My question is: is it possible for me to hint OpenGL not to apply my EBO to a vertex attribute array, more specifically number 1? If this is allowed then I can change my data format to {{xyz, xyz, ...}{uv, uv, ...}}, which is more meaningful (at least to me) and easier to maintain. If not, is there an alternative solution?
Many thanks!