1
\$\begingroup\$

I'm making a game with Libgdx 1.6.4 and experience some lag issues on iPhone 4 and then discovered:

// in the constructor
GLProfiler.enable(); 

...

// in the render method
Gdx.app.debug("draw calls: " + GLProfiler.drawCalls);
Gdx.app.debug("texture bindings: " + GLProfiler.textureBindings);
GLProfiler.reset();

What the log shows is that the number of draw calls is always equal to the number of texture bindings. Do you know if this is ok?

It seems strange because I have all images as TextureRegion in only one TextureAtlas with size 1024x512. Isn't it supposed to be that I will have for example 50 draw calls and only 1-2 texture binding instead of 50 draw calls and 50 texture bindings. Can this be the source of the lag?

Another clue may be, that I use a SpriteBatch and Scene2d Stage at the same time, but they both use the same TextureAtlas. The Scene2d Skin is loading the TextureAtlas and SpriteBatch draws TextureRegions from the skins' regions.

Thank you for any help.

--- Update ---

The main SpriteBatch (it's only one) is making 9 totalRenderCalls. The value of maxSpritesInBatch is 26. These values seem normal from what I read in the Docs and the FPS during rendering with the SpriteBatch is 60 FPS. Which is ok, no problem there.

The problem with the lag is when I use a Scene2D Stage to display a Dialog above the GameScreen. The Stage has it's own batch which I don't manipulate directly. When the Dialog is displayed the frame rate drops to 49-50 and the Animations in the Dialog are crappy. I guess the problem has something to do with Texture Binding of the main SpriteBatch and the Stage's SpriteBatch.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

As described here (last chapter), please check the value of the field renderCalls in your SpriteBatch (you have only one unique SpriteBatch instance right ?), this should tell you the real number of draw calls that the batch has made.

If you have more renderCalls than what you would expect then maxSpritesInBatch value is too low or your sprites have properties which make them not batchable (they would use different textures, or different shaders, or their shaders would need different uniforms values depending on which sprite is drawn).

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for the answer! I will update the question above to be more clear. \$\endgroup\$
    – luben
    Aug 17, 2015 at 14:02
  • \$\begingroup\$ It turned out to be very stupid mistake of mine. During code rearrangements I have left one more call to stage.draw() and it was called twice per frame. That was the cause of the lag, and that's why it was visible only during Stage having to draw something like a Dialog. I don't know if I should vote to flag or delete this question, as my problem turned out to has nothing related to OpenGL and texture bindings. \$\endgroup\$
    – luben
    Aug 17, 2015 at 16:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .