I use a rendering loop as follow;
- Orphan the data and map the buffer.
- Record the command and write the generated vertex in the buffer.
- Unmap the buffer.
- Iterate over the commands that can change states, bind textures or draw.
At the moment I use a single interleaved vertex format (SoA) that has all the attribute any of my shaders can use.
struct OneSizeFitAllVertex
{
float pos[3];
float uv0[2];
float uv1[2];
float col[4];
};
When using simpler shader that only use the position and color for example, I would only write the attribute that I care about in the mapped memory and the shader code would simply ignore all the unused attributes.
Because this feel wasteful, I am considering using different vertex format for each of my shaders.
Simple objects rendered using the simple shader would use SimpleVertex:
struct SimpleVertex
{
float pos[3];
float col[4];
};
While others, multi-textured objects, would be rendered using multitexture shader and use MultitextureVertex:
struct MultitextureVertex
{
float pos[3];
float uv0[2];
float uv1[2];
};
How should I handle these different format?
Should I write all the vertex of different format in the same mapped buffer and change my AttribPointers before drawing? This would save some space.
Should I map a different buffers for each vertex formats? Perhaps more efficient.
Or should I keep the 'one size fit all' vertex format? This is easier.
I am curious to learn what is the best practice in this situation. Thanks.