Search code examples
androidopengl-esrendererglsurfaceviewgame-loop

Opengl-es calling onDrawFrame manually


I am creating a game loop and I need to be able to call onDrawFrame (from inside the renderer manually) in order to "skip frames" if I find that I am falling behind on processes.

Currently I have a GLSurfaceView class that calls

setRenderer(glSurfaceRenderer);

With this set up I understand that onDrawFrame is called every tick.

I tried putting the above call inside a method so that I could call it from inside my game loop but on the second run of the game loop I crash with the message saying

setRenderer has already been called for this instance

Is there a way to call the renderer manually every frame

Will just calling the

onDrawFrame

method work properly. Or is it not good practice to control the renderer in such a way when using openGL


Solution

  • I don't see how calling setRenderer() nor manually calling onDrawFrame() in the game loop will solve anything. You should refactor your rendering calls to take into account the time it takes draw so in other words time based animation. In any case manually calling onDrawFrame() without a call to eglMakeCurrent() before any drawing calls won't work as you have both the renderer and game loop thread drawing.

    Edit: Since you are using GLSurfaceView, you can call requestRender() from your game loop to trigger a render if you feel RENDERMODE_CONTINUOUSLY is too slow for you.