How does a shader itterate though lists of faces?

So I have my mesh structured as such:

list of vertex {x,y,z}
list of normals {x,y,z}
list of texture points {x,y}
list of materials{…}
list of faces {indexes of vertex[3], of normals[3], of texture[3], of material} //-1 is used to indicate nothing is there for textures or normals

So this question is a bit of a 2 parter: 1) Do I need to stick to a standard data structure for the vertex shader to understand? 2)for custom lists that’s I’m not iterating through, how do I pass them over to the shader?

Shaders don’t iterate through faces; that part is performed implicitly by the implementation.

For each primitive, each vertex is processed by the vertex shader, unless that vertex has been processed previously and the results still in the vertex cache. Then the values of any non-[var]flat[/var] outputs are interpolated across the primitive, and the fragment shader invoked for each fragment which passes all of the fragment tests (pixel ownership, scissor, stencil, depth).

The above is somewhat simplified, and ignores tessellation and geometry shaders, clipping, and probably a few other things.

The data describing the mesh is split between vertex attributes (glVertexAttribPointer() etc) and the topology specified by the element array passed to glDrawElements().

So what’s the least redundant way to relay that mesh while still being able to apply transforms to the model? I’m guessing most games aren’t doing all that math on the CPU when they animate a mesh.

If my goal is to have a model that makes use of the earlier mentioned attributes as well as have a bump map and texture map where I can animate the mesh without have to manipulate it at the application level (CPU), what should I make use of?

Skeletal animation (skinning) is usually performed in the vertex shader.

The attributes for each vertex typically contain the vertex position in the “bind pose”, as well as a set of <bone,weight> pairs (often stored as a uvec4+vec4 pair: 4 bone indices and 4 weights). An array of bone transformations is passed as either a uniform variable or a texture (earlier versions of OpenGL were quite limited in the total amount of space for uniform variables, so larger arrays were often stored in textures).

The bone transformations may be stored as matrices, a quaternion (rotation) plus vector (translation), or dual quaternions. The last option is more complex mathematically, but works better with vertices which are in the middle of a joint (blending between rotations).

So uniforms don’t change per call to render. Is there a way I’m sub-diving the mesh so only one bone is looked at or is there a way to tie the bone to a vertex?

Just was searching around and saw some weird things that may work for me. Is there a way I can say “these 10 integers = 1 vertex” and also send uniforms representing the those lists of vert/norm/tex/mat/etc…? So I still use the index values, but by vertex rather than face.

You’d pass the associated bone (or a list of bone/weight pairs for blended skinning) as vertex attributes.

Don’t do that. While it’s possible to render an OBJ-style structure (where a face has separate position, normal and texture coordinate indices for each vertex), it’s likely to be slower than converting the data to the format that OpenGL wants (a single index for each combination of attributes). Rendering the OBJ-style format directly (by passing indices as vertex attributes and storing the positions, normals and texture coordinates in uniform arrays or textures) requires the vertex shader to obtain the data via dependent fetches, whereas passing the actual data as attributes will have the hardware fetch the data prior to invoking the vertex shader.

However, you’ll probably have to take this approach for materials, as passing all of the material parameters via vertex attributes is likely to increase the memory usage too much.

[QUOTE=GClements;1288117]You’d pass the associated bone (or a list of bone/weight pairs for blended skinning) as vertex attributes…
the format that OpenGL wants (a single index for each combination of attributes).[/QUOTE]

That’s kind of what I meant by “these 10 integers = 1 vertex” where those integers are indexes to lists of vertex,texture pts, normals & material (I arbitrarily said 10). So do I pass those indexes as a VBO or is there some other mechanism? It’s been a while so I need to refresh on all these.

Also I’m a little rusty with my OpenGL jargon, I see in/out is interchangeable with attribute/varying. Which one is common practice now? Also in terms of uniform vs attribute. Since I’m not altering the mesh, do I stick to uniform over attribute?

VBO. You need to use glVertexAttribIPointer() (note the “I”) for integer attributes.

In terms of GLSL syntax, attribute/varying are required for GLSL versions up to 1.20, but are deprecated in favour of in/out in 1.30 and later.

No. Uniform variables are constant for the duration of a draw call. Anything which changes per vertex needs to be an attribute.

At the moment I’m a little confused because I don’t know what’s being fed element by element and what’s just sending over the whole list and individual elements are accessed like an array.
So just to make sure we’re on the same page:

I’m sending indexes as attributes such that for the first triangle i’d have {1,1,1}{2,2,2}{3,3,3} where the first bit the vertex shader would be dealing with is {1,1,1} where I’d be getting the vertex, normal and and texture at index 1 of their corresponding list of values.

Am I going off the rails? It’s been a while so I forget how all the pieces come together.