don't use index buffers for 2d?

Started by
4 comments, last by JonConley 14 years, 8 months ago
am I correct about this? In my 2D engine, there's no benefit to using index buffers since none of the vertices will be shared. I'll be drawing a bunch of individual quads, each with its own texture (or shared texture with different coordinates). My reasoning for this is that, with floats for vertex positions and unsigned ints for indices (each are 4 bytes); one quad is either 6 floats, or 4 floats and 6 indices. So since i can't really share verts in my 2d engine, it's more beneficial to just use verts rather than verts and an index buffer, right?
Advertisement
Not necessarily, one quad is 6 vertices, not 6 floats. So it depends on how much data you're storing in each vertex(ie. Position, UV ). You should also take into consideration that you might need more than just single quads, like what if you want to draw a path, there's sure to be a number of shared vertices.

*edit* also chances are you aren't going to be going over 65355 vertices so you can use a uint16_t(16-bit integer rather than 32-bit).
you're right i mis-stated that. so for a 2D quad, each vert is 2 floats, or 8 bytes.

so 6 * 2 * 4 is 48 bytes for just vertices
or 4 * 2 * 4 + 6 * 2 is 44 bytes, if i use a short like you're describing.
or + 6 * 1 if i use an unsigned byte for a total of 38 bytes
but if i want to use a regular unsigned int it would be 4 * 2 * 4 + 6 * 4, or 56 bytes.

looks like i'm going with indexed arrays and GL_UNSIGNED_SHORT or GL_UNSIGNED_BYTE. thanks!
Also you'll probably need texture coordinates eventually for all those quads so that's an additional 2 float's for each vertex or if you decide to store a vertex colour for additional effects there's another 3 or 4 float's, so indexing can quickly add up to be the better bet.
right but i'll need those texture coords and colors regardless of whether or not i use indexing, so i just used x & y for simplicity
What they are saying is:

if you only have 4 Vertices, that have 2 or 3 floats (may want a Z for depth sorting for drawing order). Then you have 2 floats for U and V. That would be with XYZ and UV 5*4 bytes = 20 bytes per vertex * 4 Vertices = 80 bytes + 4bytes * 6 indices = 104 bytes.

Now if you just did 6 vertices at 20 bytes per vertex you'd be using 120 bytes.

This topic is closed to new replies.

Advertisement