Caller
Caller

Reputation: 53

Effective way of rendering a lot of quads (LibGDX/OpenGL ES)

I want to ask you what is the most effective or atleast sufficient way to render a lot of quads. I want to render a lot of quads (atleast 150x150) aligned in grid. The quads will not have any textures, just solid background (green,black) but colors can be changed during a runtime. Thanks for your answers.

Upvotes: 4

Views: 1224

Answers (1)

Daniel
Daniel

Reputation: 588

You can always abstract it to some sort of editable mesh object which can keep a list of indexes for the points to be drawn, a list of vertices which are drawn in order of the indexes, and then the colour for each vertex. You can then add to this dynamically at run time, and then prepare the mesh everytime you change it, which will bind everything to a VBO, and then you can simply draw it. Everything else is just implementation detail, but if you have a decent knowledge of OpenGL VAO's and VBO's should be fairly trivial. But otherwise I can help with this if you need.

Update(As there isn't enough space in the comment):

If I recall correctly, drawElements is the way to go. Don't draw each object separately, if you do that, you might as well use immediate mode. glDrawElements basically batches all of the information to your graphics card at once where it is all done as much in parallel as possible. If you draw one thing at a time, you won't be taking full advantage of the power of the GPU.

After your comment, this is where you need to make some design decisions based on what you need to do. So you want to translate individual meshes, and then eventually we want to build up a giant buffer which allows us to draw everything at once. So the first step would be to determine how much of the mesh will be moving.

Lets say we have 2 blocks that move, but the rest are stationary, we can create a separate editable mesh from these 2 blocks, and create our giant mesh from the remaining blocks. Another thing to check would be, how often is our mesh going to move? If it moves maybe once every minute or so, I would say its not such a big issue to recreate the entire mesh and bind the data again(assuming the mesh isn't ridiculously large, in which case you can create submeshes and only update those which need updating).

On the point in my previous paragraph, what are you going to be using the translated vertices for? If you are only using it for visual purposes, you can get away with creating a model matrix for your transforms for each sub-mesh that needs to be translated. However if you are going to be using it for things like collision detection you will need to store this information so that it can be used elsewhere. However you can still get away with just using the transform matrix instead of updating the VBO.

Hope this helps in some way! :)

Upvotes: 1

Related Questions