Reputation: 359
In Direct3D, when we specify the input to vertex shader using D3D11_INPUT_ELEMENT_DESC
and when we call IASetVertexBuffers
, we have to specify 'the input slot(s)'. What exactly are these input slots, and what is the OpenGL equivalent? These input slots don't seem to be the same thing as 'locations' specified via layout(location = K)
in GLSL and the first argument to glVertexAttribPointer
.
Upvotes: 2
Views: 1530
Reputation: 474086
A vertex input comes from an array of values stored in a buffer. The SemanticIndex
identifies where that input goes in the shader. The InputSlot
defines which buffer provides the data for that attribute. Buffers aren't bound to semantic indices; they're bound to input slots.
See, D3D has two arrays of things: an array of semantics (which match semantics defined in the shader) and an array of input slots. Each semantic you use has an INPUT_DESC structure for it, which specifies (among other things) the mapping from a semantic to the input slots that feeds it. Vertex buffers are bound to input slots. Any inputs which use those slots will pull their data from the same buffer. A particular input can have an offset for how its vertex data is accessed; this allows for interleaving vertex data.
OpenGL 4.3/ARB_separate_attrib_format provides similar concepts with glVertexAttribFormat
and glVertexAttribBinding
. The former specifies what attribute location the vertex data goes to. The latter specifies which buffer binding index will feed that attribute. Buffers are bound to buffer binding indices with glBindVertexBuffer(s)
.
When using the older glBindBuffer(GL_ARRAY_BUFFER)/glVertexAttribPointer
APIs, the buffer binding index and the attribute location index are effectively the same. But this is a poor API and if you don't have to support older GL versions, I'd advise you to use the newer stuff.
Upvotes: 5