如何停止 Open GL 渲染器
由于某种原因,我需要重新启动 GLSurfaceView.Renderer,因此我需要在应用程序中花一些时间再次调用 setRenderer(newRenderer),Android 不喜欢这种做法,并会抛出 IllegalStateException 说“setRenderer 已被调用”。 现在,
我知道这是因为渲染器附加到 GLSurfaceView,我需要将此渲染器与表面视图解除绑定,以便我可以再次调用 setRenderer。
有人有解决方案吗?
附: 代码如下所示:
render = new Renderer(this);
setContentView(R.layout.main);
graphicView = (GLSurfaceView) this.findViewById(R.id.graphicView);
//DO STUFF
graphicView.setRenderer(render);
//DO STUFF
Renderer newRender = new Renderer();
graphicView.setRenderer(newRender); <= ...and Android hates this line sooo much
谢谢!
For some reason, I need to restart a GLSurfaceView.Renderer so I want some time in my app to call setRenderer(newRenderer) a second time, which Android doesn't like and throws a IllegalStateException saying "setRenderer has already been called"...
Now, I know this is because the renderer is attached to the GLSurfaceView and I need to unbind this renderer to the surface view, so I can call again setRenderer.
Anyone has a solution for this ?
P.S.:
Code looks like this :
render = new Renderer(this);
setContentView(R.layout.main);
graphicView = (GLSurfaceView) this.findViewById(R.id.graphicView);
//DO STUFF
graphicView.setRenderer(render);
//DO STUFF
Renderer newRender = new Renderer();
graphicView.setRenderer(newRender); <= ...and Android hates this line sooo much
Thanks !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在这里找到了答案,这个“LemonDev”确实救了我life :
可以停止/销毁 OpenGL 表面视图,并通过调用 OnPause() 和 postDelayed 销毁来将新的 GLSurfaceView 设置为新的渲染器处理程序和一个 Runnable,如下所示:
这将创建一个新的渲染器并暂停 GLSurfaceView。然后,应用程序将“销毁”一些您无法使用 SDK 触及的内部内容...之后,您可以销毁 GLSurfaceView,创建另一个并为其设置新的渲染器。
我现在的问题是纹理尚未刷新,但是,这仍然很棒!
Found the answer here, this "LemonDev" do saved my life :
One can stop/destroy an OpenGL surface view and set the new GLSurfaceView a new renderer by calling the OnPause() and postDelayed the destruction with a Handler and a Runnable, like this :
This will create a new renderer and pause the GLSurfaceView. The application then will "destroy" some internal stuffs that you can't touch with the SDK... After this, you can destroy the GLSurfaceView, create another one and set the new renderer to it.
My problem now is that the textures are not refreshed yet but, still, this is great !
你真的需要调用 setRenderer 两次吗?
Android 文档提到:
相反,我猜你想暂停渲染?
使用
setRenderMode(RENDERMODE_WHEN_DIRTY);
暂停渲染器Do you really need to call setRenderer twice?
The android documentation mentions :
Instead, I guess you want to pause the rendering?
Use
setRenderMode(RENDERMODE_WHEN_DIRTY);
to pause the renderer我找到了一种更简单的方法来刷新纹理。在您的 Activity 类中调用 invalidate() ,然后在您的表面视图类中,您的 onDrawFrame 每次都会被调用。因此您可以在此处加载纹理,从而完成您的工作!
I found an easier way to refresh textures. In your Activity class call invalidate() and then in your surface view class your onDrawFrame will keep getting called everytime..So you can load your texture here and thereby your work will be done!