i recently had problems of FPS drop (~40 FPS), and when i searched where it was. I saw that it wasnt me, all my calculation were done in 7 ms which is far from the 16 ms limit.
This is the code i used :
long time = 0;
public void render(float delta)
System.out.println("since last frame : " +( System.currentTimeMillis()-time));
time = System.currentTimeMillis();
System.out.println("render : " + (System.currentTimeMillis()-time));
And my time "since last frame" was around 22 ms and my "render" was around 7 ms. I just don't understand what libgdx is doing during thoses 15 ms, or if it is my fault.
Best How To :
LibGDX is swapping the back and front buffer. This requires to wait for the GPU to finish rendering. So whatever you've told the GPU to do in
render() which hasn't finished yet will still have to finish before the next call to the
render() method can be made.
CPU and GPU operate in parallel. e.g. when you call
SpriteBatch#end() it will almost return immediatly (if it doesn't have to wait for something else to complete first). But that doesn't mean that it is actually rendered. It only means that it has instructed the GPU to render whatever you've added to the batch using e.g. the
This rendering happens onto the backbuffer, which is an off-screen image. When your
render() method completes this backbuffer is swapped with the frontbuffer, so that the screen displays whatever you've rendered in your
render() method. It can only swap these buffers if the GPU completed executed your instructions and thus it needs to wait if it hasn't completed yet.