0
votes

I currently am experiencing very slow performance by iterating through quad triangle strips and drawing each one separately, so I would like to batch all of my rectangles into one single draw call.

Looking around, it seems the best way to do this is to simply occur the overhead of duplicating vertices and using GL_TRIANGLES instead of GL_TRIANGLE_STRIP, simply drawing two separate triangles for each rectangle.

The problem is that each rectangle can have a different color, and I need to programmatically change the color of any of the rectangles. So simply using one GL_TRIANGLES call does not do the trick. Instead, it looks like I'll need to somehow index color data with my vertex data, associating a color with each rectangle. How would I go about this?

Thank you!

1

1 Answers

2
votes

You can use vertex coloring.

Vertices can each have multiple channels of data, including position, color, (multiple) texture, normal, and more.

I recommend interleaving your vertices to include position and color one after the other, directly. Although you can set up a separate array of just colors and do it that way as well (just make sure you line up the colors with the positions correctly).

(Those tutorials are iPhone-oriented but the OpenGL ES code should work fine on Android)