3
$\begingroup$

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?

$\endgroup$

1 Answer 1

3
$\begingroup$

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.

$\endgroup$
4
  • 1
    $\begingroup$ You could pass the color data in a constant buffer rather than vertex data. If they are all the same. $\endgroup$
    – RichieSams
    May 13, 2016 at 11:55
  • 1
    $\begingroup$ 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. $\endgroup$ May 13, 2016 at 18:02
  • $\begingroup$ @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. $\endgroup$
    – J.Doe
    May 14, 2016 at 0:12
  • $\begingroup$ stackoverflow.com/questions/37221027/… $\endgroup$
    – J.Doe
    May 14, 2016 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.