3

I am making a 2d game in opengl es 2.0

Inside are tons of rectangles defined by 4 points and one 4 component color.

I am using vertex buffer objects, and I have heard that it is efficent to interlace the data.

So like traditionally you would do

Corner.x
Corner.y
Corner.z
Corner.rgba
(repeat for each corner) 

However in my situations two assumptions can be made that can probably make things faster

1. All the rectangles z values are 0
2. All corners of the rectangle have the same color. 

Is it possible, and what would it look like to have a buffer object structured like this.

Corner.xy
Corner.xy
Corner.xy
Corner.xy
Color.rgba? 

Is it even possible to have opengl assume that the Z is always 0? Is it possible to reuse the color like to hat?

J.Doe
  • 1,445
  • 12
  • 23

1 Answers1

3

Is it even possible to have opengl assume that the Z is always 0?

Yes it is. Just set the component count to 2 in glVertexAttribPointer and the other 2 components (z and w) will be auto filled with 0 and 1 resp.

Is it possible to reuse the color like to hat?

No it is not. Opengl (and most other graphics apis) require that each vertex is referenced by only a single index.

ratchet freak
  • 5,950
  • 16
  • 28
  • 1
    You could pass the color data in a constant buffer rather than vertex data. If they are all the same. – RichieSams May 13 '16 at 11:55
  • 1
    If GL ES 3.0 is a possibility, you could also use geometry instancing, but it doesn't seem to be available in GL ES 2.0 as far as I can tell from some googling. – Nathan Reed May 13 '16 at 18:02
  • @Ratchet freak OK I re-strategised my plan! Thank you for letting me know. If you are willing I made a new one because I am stuck on that one, I need to get good at vertex buffers somehow. – J.Doe May 14 '16 at 00:12
  • http://stackoverflow.com/questions/37221027/how-to-write-complicated-vertex-buffers – J.Doe May 14 '16 at 00:12