Search code examples
copenglvertexvertex-buffer

OpenGL storing variables per shape without any duplicates


I've been working on a sprite renderer, and I have rectangles being rendered correctly, but now I want to rotate them and perhaps add textures to the endeavor. However, I don't know how to store the angle, for example, without duplicating the data. Currently, every vertex has its position, and it would be a waste to repeat every angle, textureatlas_index, etc. 4 times for each rectangle mesh. So here's the question, is there an efficient way to store variables such as angles, or textureatlas_indexes per shape, and not per vertex?

Edit: one more thing, my sprite renderer does have a maximum capacity, so it's not dynamically sized, but I can't access that maximum capacity pre-runtime, so static arrays are not really an option.

I'm targetting 3.3 core


Solution

  • I settled for a streamed texture buffer and gl_VertexId/4 to get the current rectangle's index