Sign in to follow this  

don't use index buffers for 2d?

This topic is 3047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3047 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this