1

glVertexAttribPointer()'s first argument is an index representing where the vertex attribute resides, Opengl offers a minimum of 16 slots.

I want all 16 to represent different vertex attributes (position=0, uvs=1, colors=3, weights=8, etc) and for these to be constant across every vertex type, even if the vertex doesn't use that attribute.

My question is, does it matter at all if the indices are not contigious for a given vertex? For example, would this be inefficient at all:

enum Attrib : GLuint {
    aPos        = 0,
    aUv1        = 1,
    aUv2        = 2,
    aColor1     = 3,
    aColor2     = 4, 
    aNormal     = 5,
    aTangent    = 6,
    aBitangent  = 7,
    aBoneIndex  = 8,
    aBoneWeight = 9,
    aAttrib1    = 10,
    aAttrib2    = 11,
    aAttrib3    = 12,
    aAttrib4    = 13, 
    aAttrib5    = 14,
    aAttrib6    = 15, 
    a__count    = 16
};

glVertexAttribPointer(aPos, ...);
glVertexAttribPointer(aUv1, ...);
glVertexAttribPointer(aAttrib1, ...);
Anne Quinn
  • 12,609
  • 8
  • 54
  • 101
  • 1
    Does multiple vertex types imply multiple shader programs? – Albjenow Nov 15 '19 at 11:50
  • @Albjenow - Yeah, some require different vertex attributes. There's a lot of shaders but only a few vertex types – Anne Quinn Nov 15 '19 at 11:57
  • 3
    Probably it makes it easier to handle the different shaders, if you use the same attribute index for a attribute type in each shader program. But the resource index itself is just an arbitrary positive, integral number, you can define it. – Rabbid76 Nov 15 '19 at 12:02

1 Answers1

2

There is no known performance penalty from using arbitrary attribute indices for vertex arrays. To add some justification to this, more recent APIs like Vulkan and D3D12 had the opportunity to enforce contiguity of attribute indices. Being more low-level APIs, if there was some performance to be gained by such a restriction, they would have imposed it.

They did not.

By contrast, Vulkan effectively made the vertex format part of the program pipeline state, thus enforcing a direct correlation between programs and the vertex format. So it's not like Vulkan wasn't willing to restrict things compared to OpenGL.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982