Opengl-es手动调用onDrawFrame
我正在创建一个游戏循环,并且我需要能够调用 onDrawFrame (从渲染器内部手动),以便在发现进程落后时“跳过帧”。
目前我有一个 GLSurfaceView 类,它调用
setRenderer(glSurfaceRenderer);
通过此设置,我知道 onDrawFrame 会在每个刻度线被调用。
我尝试将上述调用放入一个方法中,以便我可以从游戏循环内部调用它,但在游戏循环的第二次运行时,我崩溃并显示消息:
setRenderer has already been called for this instance
是否有一种方法可以在每帧手动调用渲染器
将只调用
onDrawFrame
方法工作正常。或者在使用 openGL 时以这种方式控制渲染器不是一个好习惯
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道在游戏循环中调用
setRenderer()
或手动调用onDrawFrame()
将如何解决任何问题。您应该重构渲染调用以考虑绘制所需的时间,换句话说就是基于时间的动画。在任何情况下,在任何绘图调用之前手动调用onDrawFrame()
而不调用eglMakeCurrent()
都将不起作用,因为您同时拥有渲染器和游戏循环线程绘图。编辑:由于您使用的是 GLSurfaceView,如果您觉得
RENDERMODE_CONTINUOUSLY
对您来说太慢,您可以从游戏循环中调用requestRender()
来触发渲染。I don't see how calling
setRenderer()
nor manually callingonDrawFrame()
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 callingonDrawFrame()
without a call toeglMakeCurrent()
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 feelRENDERMODE_CONTINUOUSLY
is too slow for you.