No, when you linked your shader you provided it with details on
what “vertex slot” it should expect to find a paticular vertex attribute.
glBindAttribLocation(program_id, vertex_slot, “in_position”);
when you use
glVertexAttribPointer(vertex_slot, 3, GL_FLOAT, GL_FALSE, vertex_stride, offset_into_vertex);
you are describing where attribute information for vertex_slot should come from within currently bound buffer.
glVertexAttribPointer(vertex_slot, 3, GL_FLOAT, GL_FALSE, dif_stride, dif_offset) will still work for the bound shader as long as vertex slot remains the same.
Packing data of different type in the same VBO will require managing a separate VAO per type.
What do you mean by type? Vertex_types or different elements?
say you have two vertex types:
Vertex_A
{
vec3 pos;
vec4 colour;
} vA;
Vertex_B
{
vec3 pos;
vec3 normal;
vec2 texture;
} vB;
You could feasibly fill a VBO with both types of data though you have to ensure that they where not inter mixed. Say we have 10 of each in the buffer first 10 Vertex_A second 10 Vertex_B and as we are using VBO we have at least go a single VAO set globally. (and so can ignore it for this example)
Two shaders one to render flat shaded, and another to diffuse light textured geometry.
to render the first 10, set flat program it expects position in slot 0 and colour in slot 1. So set the attribute pointers
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, vA_stride, offset_pos_in_A);
glEnableVertexAttribArray(0);
then the colour
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, vA_Stride, offset_colour_in_A);
glEnableVertexAttribArray(0);
Then we can draw
glDrawArrays(GL_TRIANGLES, start, 10);
To draw the remaining 10 using the other shader we have to call glVertexAttribPointer again for each attribute but using vB_Stride and offset in vB and start at 10 instead of 0 for glDrawArray().
Its much easier to do this setting in a vao once for each case and just switch between them.
glBindVertexArray();
Infact I have one VAO that sets for just Vertex_A and one that sets for just Vertex_B and have two separate VBO for each vertex type. Both will still work for flat shader as long as they both put pos into attribute slot 0, however the textured shader will look a mess as it wont have access to normal or textured coordinates if it uses data from buffer containing Vertex_A.
Streaming into the buffer will require data offset to be multiple of the vertex stride.
By ‘problematic’ I mean it requires a lot of extra tracking code, making simple thing look complex in the code, not that it is not doable at all.
I don’t know if I have been any real help but I certainly empathise, the inter relationship between shaders, VBO and VAO
still has me unsure on building a flexible way to render various geometries using various effects.
I have taken to having a few core vertex formats, that all place common attributes in the same slot so if a vertex format has an attribute as shader that needs it can find it in that slot. If the VBO doesn’t have all the data at very least the shading effect can work with what is available and use the default value GL provides on missing attribute slot.