Search code examples
androidopengl-estextureslibgdxframe-rate

After TextureAtlas is loaded, it's low fps rate for a while


stackoverflowers and other good people, I have one issue with which I don't know how to solve after a two days of trying: I have libgdx project (I'm using stages and actors, but that's not important now) where I add to comments everything not useful and problem is simple:

  1. setting the empty screen first a few (4-5) renderings have delta around 0.04 sec, then around 0,01
  2. setting the screen, where in the resize method I made a new instance of TextureAtlas - it loads two 1024 x 1024 textures takes around 0.5-0.8 sec and after that it starts rendering and first few renderings (5) have delta times around 0.1 sec (on SGS II) or around 0.2 - 0.3 sec (on SG ACE) - and that's a really quite a problem, because when you have some FadeIn effect or whatever animation at the start of the screen you will see maybe the second half of the animation - yea when it has that low fps rating...nothing is drawing (I can't see anything even it says that renderings have been called even after 0.3 sec)

My question is: TextureAtlas is supposed to load every page image when it's called so why it affects running after it has been load? Or at least whether can I know when it will be running, drawing normally?

Really thanks for your answer!

Obivously here's code, but it's simple as this:

public class App extends Game {

    @Override
        public void create() {      
            Gdx.app.log( this.LOG, "Creating game" );
            fpsLogger = new FPSLogger();
                setScreen( new IntroScreen(this) );

    }
}

IntroScreen:

public class IntroScreen implements Screen {
   @Override
    public void resize(
        int width,
        int height )
    {
        super.resize( width, height );
        Gdx.app.log("IntroScreen", "Resize start: " );
        atlas = new TextureAtlas( Gdx.files.internal( "image-atlases/pages-info.atlas" ) );
        Gdx.app.log("IntroScreen", "Resize finished: " );
    }

    @Override
    public void render(
        float delta )
    {
        Gdx.gl.glClearColor( 0f, 0f, 0f, 1f );
        Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT );

        Gdx.app.log( "IntroScreen", "Delta: " + delta );

        // stage is empty
        stage.act( delta );
        stage.draw();
    }
}

And here is output from LogCat:

08-09 01:09:53.689: I/IntroScreen(9757): Resize start: 
08-09 01:09:54.004: I/IntroScreen(9757): Resize finished: 
08-09 01:09:54.009: I/IntroScreen(9757): Delta: 0.10668343
08-09 01:09:54.009: I/IntroScreen(9757): Delta: 0.1037551
08-09 01:09:54.024: I/IntroScreen(9757): Delta: 0.1006427
08-09 01:09:54.039: I/IntroScreen(9757): Delta: 0.09953054
08-09 01:09:54.054: I/IntroScreen(9757): Delta: 0.099971004
08-09 01:09:54.074: I/IntroScreen(9757): Delta: 0.009933725
08-09 01:09:54.089: I/IntroScreen(9757): Delta: 0.012701442
08-09 01:09:54.104: I/IntroScreen(9757): Delta: 0.015878525
08-09 01:09:54.124: I/IntroScreen(9757): Delta: 0.016689042
08-09 01:09:54.144: I/IntroScreen(9757): Delta: 0.017476525
08-09 01:09:54.159: I/IntroScreen(9757): Delta: 0.017719833
08-09 01:09:54.174: I/IntroScreen(9757): Delta: 0.017750284
08-09 01:09:54.189: I/IntroScreen(9757): Delta: 0.017803017
...

Thanks for any help.


Solution

  • On Android, the delta times are smoothed (averaged) over the last 5 frames. If the process of loading a TextureAtlas (or any other assets) makes that frame take longer (as it most likely will), then you'll see higher delta times for the next 5 or so frames. You might try getRawDeltaTime if you want the unsmoothed deltas. Of course, you'll have to ignore the delta time which is passed into the render method, and obtain the raw delta from Gdx.graphics.getRawDeltaTime() at the beginning of your render method.