Jump to content
  • Advertisement
Sign in to follow this  

Batching Shapes Together

This topic is 2134 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

I'd like to write a batching class to hold the vertices for all my shapes. I want to support lines, squares, circles, polygons up to 8 vertices, etc. I'd prefer to draw them a single draw call as well. The way it'd work is I'd have methods in my ShapeBatch class such as AddLine(), AddBox(), AddCircle(), etc. They'd take parameters to setup the shapes, and return a pointer handle so the programmer has access to it. Internally, the shapes' definitions are all stored in an STL vector, and I'd like all of the shapes' vertices to be stored in a single STL vector which will act as a vertex array. Now, of course, how would I go about manipulating the vertices when I need to? I guess each shape can store the index to the first vertex in the array, but then removing shapes from the list would require me to iterate through the entire list from the point where the shape was remove all the way to the end to decrement the starting index offset.


Also, what if some of my shapes were solid and others were just outlines? This would be very helpful in writing debug geometry. I could just have two STL vectors of vertices: one for drawing with GL_LINES, and another for GL_TRIANGLES. Then, of course, the solid-drawn one would require an index buffer as well so that shapes can be drawn all at once, but not connected...


I also face a similar situation with my sprite library. I usually store sprites as 4-point quads, but then my 9-sliced quads will be made up of 16 vertices a piece. Should I have separate vectors for quads and 9-sliced objects? It'd be much easier to code, but then I have more vectors to manage per sprite library...


What are you takes on doing this?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!