<p>You can set a stride of zero with OpenGL 4.3's <a href="https://www.khronos.org/opengl/wiki/Vertex_Specification#Separate_attribute_format" rel="noreferrer">separate attribute format</a> API, or the ARB_vertex_attrib_binding extension:</p>

<pre><code>glBindVertexBuffer(index, buffer, offset, 0);
</code></pre>

<p>The stride of zero will be a real stride of zero.</p>

<p>This also has the benefit of looking a lot more familiar to D3D users than the <code>glVertexAttribPointer</code> API.</p>

CC BY-SA 3.0
2017-04-05T13:58:50.483Z
hey that's very interesting. that's probably way easier since our engine is more based on d3d ways. I'll look into that tomorrow
v.oddou
CC BY-SA 3.0
2017-04-05T13:54:10.807Z
2017-04-05T13:54:10.807Z
Nicol Bolas
<p>Disable the vertex attrib array and use <code>glVertexAttrib</code> to set the data that should be used.</p>

CC BY-SA 3.0
2017-04-05T07:59:44.857Z
2017-04-05T07:59:44.857Z
ratchet freak
<p>Problem X: I need to provide "compensation" streams for attributes that are not plugged by the mesh data, but the shader requires them.
(In d3d not matching the input layout is a hard error)</p>

<p>Solution Y: In D3D I've created a 16 bytes buffer initialized with some default color (when the missing semantic is color, let's take this as my typical use case) and specified a stride of zero so that one element is repeated whatever the index in the index buffer, and this way I don't need to clog VRAM with the biggest buffer that's necessary to cover all objects. This works in D3D.</p>

<p>But looking at <a href="https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glVertexAttribPointer.xml" rel="nofollow noreferrer">glVertexAttribPointer</a> I see that the API is eating away my stride and makes it automatic when I specify zero.</p>

<p>Any workaround ?</p>

<opengl>
OpenGL set a vertex element stride of zero
v.oddou
# OpenGL set a vertex element stride of zero

(Asked by: username_0 on 2017-04-05)

Problem X: I need to provide "compensation" streams for attributes that are not plugged by the mesh data, but the shader requires them.
(In d3d not matching the input layout is a hard error)

Solution Y: In D3D I've created a 16 bytes buffer initialized with some default color (when the missing semantic is color, let's take this as my typical use case) and specified a stride of zero so that one element is repeated whatever the index in the index buffer, and this way I don't need to clog VRAM with the biggest buffer that's necessary to cover all objects. This works in D3D.

But looking at [glVertexAttribPointer](https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glVertexAttribPointer.xml) I see that the API is eating away my stride and makes it automatic when I specify zero.

Any workaround ?

**Tags:** opengl


---

## 2 answers

### Answer by username_2 on 2017-04-05. Score: 5 | Accepted answer

Disable the vertex attrib array and use `glVertexAttrib` to set the data that should be used.


---

### Answer by username_1 on 2017-04-05. Score: 5

You can set a stride of zero with OpenGL 4.3's [separate attribute format](https://www.khronos.org/opengl/wiki/Vertex_Specification#Separate_attribute_format) API, or the ARB\_vertex\_attrib\_binding extension:

```
glBindVertexBuffer(index, buffer, offset, 0);

```

The stride of zero will be a real stride of zero.

This also has the benefit of looking a lot more familiar to D3D users than the `glVertexAttribPointer` API.

> **Comments:**
> **username_0**: hey that's very interesting. that's probably way easier since our engine is more based on d3d ways. I'll look into that tomorrow  

---

