<p>The offset in <code>glVertexArrayVertexBuffer</code> is the common offset for all attributes bound to that buffer. It's where the vbo data starts.</p>

<p>The offset in <code>glVertexArrayAttribFormat</code> is added to that common offset for that attribute. </p>

<p>This allows you to interleave attributes using a single vbo binding point. and change the vbo binding for those attributes in a single call.</p>

<p>To make an example: </p>

<pre><code>struct Vertex {
    vec3 pos;
    vec3 normal;
}

glVertexAttribFormat(posAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, pos));
glVertexAttribBinding(posAttrLoc, vertexBindingPoint);
glEnableVertexAttribArray(posAttrLoc);

glVertexAttribFormat(normalAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, normal));
glVertexAttribBinding(normalAttrLoc, vertexBindingPoint);
glEnableVertexAttribArray(normalAttrLoc);
</code></pre>

<p>then to bind the buffer you pass the offset to where you put in where the data was uploaded to, this is 0 in the basic case.</p>

<pre><code>glBindVertexBuffer(vertexBindingPoint, mesh.vbo, mesh.vboOffset, sizeof(Vertex));
</code></pre>

CC BY-SA 4.0
2018-08-22T11:15:05.737Z
so when data is tightly packed and there is no interleaving , like a situation where pos data is first and then the whole normals are , the offset bcomes one .
mahdi mahzouni
CC BY-SA 4.0
2018-08-22T11:20:42.040Z
@mahdimahzuni then you'd use separate binding points for each attribute, the offset in `glVertexAttribFormat` become 0 and the offset in `glBindVertexBuffer` is where each attribute begins.
ratchet freak
CC BY-SA 4.0
2018-08-22T11:25:21.210Z
tnx superb explanation, performance wise is it bad to use two binding points or are they similar ?
mahdi mahzouni
CC BY-SA 4.0
2018-08-22T11:02:14.317Z
2018-08-22T11:02:14.317Z
ratchet freak
<p>Using The DSA Ext with opengl , API calls to guide opengl to the buffer format are :</p>

<pre><code>glVertexArrayAttribFormat(  GLuint vaobj,
GLuint attribindex,
GLint size,
GLenum type,
GLboolean normalized,
GLuint relativeoffset);
</code></pre>

<p>and another one is :</p>

<pre><code>glVertexArrayVertexBuffer(  GLuint vaobj,
GLuint bindingindex,
GLuint buffer,
GLintptr offset,
GLsizei stride);
</code></pre>

<p>my question is what's the difference between relativeOffset and the offset in both function calls ? when i set one the results are ok but when you set both your layout will be incorrected and thus the results are wrong.</p>

<opengl>
Difference between relativeOffset and offset in VAO with Direct Access Ext
mahdi mahzouni
# Difference between relativeOffset and offset in VAO with Direct Access Ext

(Asked by: username_0 on 2018-08-22)

Using The DSA Ext with opengl , API calls to guide opengl to the buffer format are :
glVertexArrayAttribFormat(  GLuint vaobj,
GLuint attribindex,
GLint size,
GLenum type,
GLboolean normalized,
GLuint relativeoffset);

and another one is :
glVertexArrayVertexBuffer(  GLuint vaobj,
GLuint bindingindex,
GLuint buffer,
GLintptr offset,
GLsizei stride);

my question is what's the difference between relativeOffset and the offset in both function calls ? when i set one the results are ok but when you set both your layout will be incorrected and thus the results are wrong.

**Tags:** opengl

---

## 1 answers

### Answer by username_1 on 2018-08-22. Score: 2 | Accepted answer

The offset in glVertexArrayVertexBuffer is the common offset for all attributes bound to that buffer. It's where the vbo data starts.
The offset in glVertexArrayAttribFormat is added to that common offset for that attribute. 
This allows you to interleave attributes using a single vbo binding point. and change the vbo binding for those attributes in a single call.
To make an example: 
struct Vertex {
    vec3 pos;
    vec3 normal;
}

glVertexAttribFormat(posAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, pos));
glVertexAttribBinding(posAttrLoc, vertexBindingPoint);
glEnableVertexAttribArray(posAttrLoc);

glVertexAttribFormat(normalAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, normal));
glVertexAttribBinding(normalAttrLoc, vertexBindingPoint);
glEnableVertexAttribArray(normalAttrLoc);

then to bind the buffer you pass the offset to where you put in where the data was uploaded to, this is 0 in the basic case.
glBindVertexBuffer(vertexBindingPoint, mesh.vbo, mesh.vboOffset, sizeof(Vertex));

> **Comments:**
> **username_0**: so when data is tightly packed and there is no interleaving , like a situation where pos data is first and then the whole normals are , the offset bcomes one .  
> **username_1**: @mahdimahzuni then you'd use separate binding points for each attribute, the offset in `glVertexAttribFormat` become 0 and the offset in `glBindVertexBuffer` is where each attribute begins.  
> **username_0**: tnx superb explanation, performance wise is it bad to use two binding points or are they similar ?  

---

