Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL: Vertex attribute arrays per primitive?

Tags:

c

opengl

I'm wondering if it's possible in OpenGL (via extensions or otherwise) to have an attribute array specified by the glVertexAttribPointertype functions that advances by one for every primitive (or N vertices) instead of one for every vertex?

For example, if I have an array of triangles which have a solid color currently I'm having to repeat the same color data for every vertex, what I would like instead is something along these lines:

struct pos {
    uint8_t x, y;
} positions[NUM_VERTICES];

struct col {
    uint8_t r, g, b;
} colors[NUM_VERTICES / 3];

Where one element of the colors array is reused for every 3 consecutive positions elements when both arrays are submitted to OpenGL with glVertexAttribPointer and renderered with a single glDrawArrays(GL_TRIANGLES, ...);

I found the ARB_instanced_arrays extension, which provides the glVertexAttribDivisorARB function which seemed promising at first, but I don't think it works the way I've described.

like image 670
Xeno Avatar asked Oct 07 '22 07:10

Xeno


1 Answers

This is essentially an alternate form of this question about multi-indexed rendering (it's different, which is why I'm not calling it a duplicate). The simple answer is no. The less simple answer is to do the accessing and indexing yourself.

like image 161
Nicol Bolas Avatar answered Oct 18 '22 12:10

Nicol Bolas