Home Game Development opengl – LibGDX Table rendering order draw calls

opengl – LibGDX Table rendering order draw calls

0
opengl – LibGDX Table rendering order draw calls

[ad_1]

I’m using LibGDX Table for drawing some simple structure but I am having problem with draw calls and texture binding handling.

For clarification, I have a TextureAtlas loaded and I can get the following textures from it. And then I have a Table with following structure:

table.add(new Image(textureAtlas.findRegion("region1")))
table.row()
table.add(new Image(textureAtlas.findRegion("region2")))
table.row()
table.add(new Image(textureAtlas.findRegion("region3")))

In this case, it renders the table with only one draw call and one texture binding, as all the texture regions belongs to the same loaded Texture.

But now, if I create a table interleaving with another Actor, like this:

table.add(<some actor>)
table.add(new Image(textureAtlas.findRegion("region1")))
table.row()
table.add(<some another actor>)
table.add(new Image(textureAtlas.findRegion("region2")))
table.row()
table.add(<some another actor>)
table.add(new Image(textureAtlas.findRegion("region3")))

The texture regions are not drawn in sequence as before, it’s necessary a new draw call / texture binding for each one of the three texture regions from textureAtlas.

I short, if I draw the three texture regions in sequence, one after the other, it uses only one draw call and texture binding. Otherwise, if there is something else in the middle, it uses a new draw call and texture binding for each texture region, even if they are part of the same texture.

My question is, is there any way I can re-arrange the Table’s drawing order, so I draw the texture regions one after the another, and only after I draw the another Actors? Even if my table has the visual structure I presented above? Or do I need to create a custom Table class for handling this properly?

One thing I’ve already tried was to use table.getChildren(). This returns a list of the table’s children Actors. And I tried to draw the elements from this list in the order I want, but they are not positioned correctly (always at position (0,0)). I also tried to recreate this children list with the order I want, but I cannot do table.setChildren().

[ad_2]