Fetching vertex attributes at different rate

Is there a way to fetch different vertex attributes at different rate. Like to use new vertex coordinates per every execution of the vertex shader but use the same color for 3 vertices. This would result in the vertex-pos VBO having 3x as many elements as the vertex-color VBO. Can that be done? Thanks!

ARB_instanced_arrays allows you to fetch different vertex attributes at different rates. This has been in core since OpenGL 3.3.

However, this is used for instancing (when you want one or more vertex attribute values to be applied to “all” verts in other vtx attribs, not just to one primitive’s worth of verts in the other vtx attribs).

Couple ideas for you. One is you could repeat the color for multiple verts. Another is you could use flat shading so that only the color for only one of the verts is applied to the entire triangle. Or you could lookup the color in the vert shader based on gl_VertexID or similar.

Thanks! Actually, I wanted to do text rendering and particles, where I want to provide the center of a quad while its 4 points are calculated in the vertex shader(as the width of the quads is fixed). …so I would need to store 1 position, 1 color, 4 texture-coords per quad(2 triangles).

Geometry shader: can I use that while I cant calculate the texture coords in the shader?
Instanced rendering: how much slower would it be compared to providing all the (unnecessary) data for all vertex attribs and use a normal draw call? and compared to the geometry shader?

As I understand, instanced rendering works well when the instanced objects are complex, not like in this case with 4 vertices.

[QUOTE=Aliii;1257870]Thanks! Actually, I wanted to do text rendering and particles, where I want to provide the center of a quad while its 4 points are calculated in the vertex shader(as the width of the quads is fixed). …so I would need to store 1 position, 1 color, 4 texture-coords per quad(2 triangles).

Geometry shader: can I use that while I cant calculate the texture coords in the shader?[/QUOTE]

Yes. A geometry shader is actually good for the simple point-to-quad spread operation you’re describing. You can easily calculate your texture coordinates in the shader, as well as compute your quad positions based on some dimension you pass in or compute in the shader.

Instanced rendering: how much slower would it be compared to providing all the (unnecessary) data for all vertex attribs and use a normal draw call? and compared to the geometry shader?

As I said, it doesn’t sound like instancing is the problem you have. Do the geom shader pt-to-quad spread, and it sounds like you want to just rip a standard draw call. Now if instead your input data for each resulting primitive wasn’t a single vertex but a number of vertices, and you had a number of them, that’s when you’d want to use instancing. And yes, instanced rendering can be very efficient because it reduces CPU overhead dispatching batches.

Thanks! I will try the geom shader approach then.