6

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 I see that the API is eating away my stride and makes it automatic when I specify zero.

Any workaround ?

v.oddou
  • 623
  • 4
  • 9

2 Answers2

5

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

ratchet freak
  • 5,950
  • 16
  • 28
5

You can set a stride of zero with OpenGL 4.3's 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.

Nicol Bolas
  • 9,762
  • 18
  • 25
  • 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 Apr 05 '17 at 13:58