开发者

Opengl-es calling onDrawFrame manually

开发者 https://www.devze.com 2023-04-05 10:20 出处:网络
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.

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 th开发者_运维知识库e renderer in such a way when using openGL


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号