Direct State AccessGL 4.5

glVertexArrayAttribFormat

Describes the format of one attribute inside a vertex — without saying which buffer.

Signature

void glVertexArrayAttribFormat(GLuint vaobj, GLuint attribindex, GLint size,
                               GLenum type, GLboolean normalized, GLuint relativeoffset);

How it works

The DSA way splits glVertexAttribPointer into three calls. This one says what the attribute looks like: size components of type, starting relativeoffset bytes into each vertex. glVertexArrayAttribBinding then says which binding point it reads from, and glVertexArrayVertexBuffer which buffer sits on that binding point, with the stride.

Because the format is separate from the buffer, the same VAO layout can be pointed at another buffer with one call.

vertex 0vertex 1xyzuvxyzuv0481216202428323640stride = 20offset = 12offset = 0location 0: size 3, GL_FLOATlocation 1: size 2, GL_FLOAT
Two vertices of an interleaved buffer: position (3 floats) then texture coordinates (2 floats). Every attribute uses the same stride, 20 bytes from one vertex to the next; the offset says where inside a vertex the attribute starts.

Parameters

vaobjGLuint

The VAO.

attribindexGLuint

Attribute location, as layout(location = N).

sizeGLint

Components: 1–4.

typeGLenum

Component type, e.g. GL_FLOAT.

normalizedGLboolean

Normalize integer types to 0–1 / -1–1.

relativeoffsetGLuint

Offset of this attribute inside ONE vertex — offsetof(Vertex, member).

Tips & pitfalls

  • Direct State Access (GL 4.5): the object is passed as a parameter, so nothing needs to be bound and no global state is disturbed.

Example

example.cpp
1glVertexArrayAttribFormat(vao, 0, 3, GL_FLOAT, GL_FALSE, offsetof(Vertex, pos));
2glVertexArrayAttribFormat(vao, 1, 2, GL_FLOAT, GL_FALSE, offsetof(Vertex, uv));
Official Khronos documentation