I'm currently working on a 2d sandbox tile game in LibGDX and I noticed I had 700+ draw calls. So checked my code and I could not find anything that would cause a new draw call. All the tiles are drawn between a single batch.begin() and a batch.end(). I commented out the code for rendering the tiles and I had around 2-3 draw calls. I can't figure out whats wrong so I am posting this here.
Here is the call chain of the render method:
In my world class:
public void render(SpriteBatch batch, ShapeRenderer shapeBatch) {
batch.begin();
chunkManager.render(batch);
if (selectedBlock != null) batch.draw(gameScreen.app.assetManager.get("misc/block_selection_texture.png",Texture.class), selectedPosition.x * 32, selectedPosition.y * 32);
batch.end();
}
World is calling chunkManager.render(..):
public void render(SpriteBatch batch) {
//Render all the chunks
for (Chunk c : activeChunks) {
if (c != currentChunk) {
c.render(batch);
}
}
//Render Current Chunk the player is in in front of every other chunk
currentChunk.render(batch);
}
ChunkManager is calling c.render(..):
public void render(SpriteBatch batch){
//Render all Blocks inside the Chunk
for(Block b:blocks.values()){
b.render(batch); // <- this is the line I commented out
}
//Render all Entities inside the Chunk
for(Entity e:entities){
e.render(batch);
}
}
Chunk is calling b.render(..):
public void render(SpriteBatch batch){
float hp = hardness/maxHardness;
//tint the blocks based on their health
batch.setColor(1*hp,1*hp,1*hp,1);
batch.draw(texture, x*32, y*32);
batch.setColor(Color.WHITE);
}
and e.render(..):
public void render(SpriteBatch batch){
if(isAnimated) {
renderAnimation(batch); // -> just batch.draw(..) for animations
} else {
batch.draw(texture, x, y);
}
}
No comments:
Post a Comment