Opengl-es手动调用onDrawFrame

发布于 2024-12-04 14:49:45 字数 473 浏览 6 评论 0原文

我正在创建一个游戏循环,并且我需要能够调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雅心素梦 2024-12-11 14:49:45

我不知道在游戏循环中调用 setRenderer() 或手动调用 onDrawFrame() 将如何解决任何问题。您应该重构渲染调用以考虑绘制所需的时间,换句话说就是基于时间的动画。在任何情况下,在任何绘图调用之前手动调用 onDrawFrame() 而不调用 eglMakeCurrent() 都将不起作用,因为您同时拥有渲染器和游戏循环线程绘图。

编辑:由于您使用的是 GLSurfaceView,如果您觉得 RENDERMODE_CONTINUOUSLY 对您来说太慢,您可以从游戏循环中调用 requestRender() 来触发渲染。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文