在后台运行 Android OpenGL 作为应用程序的渲染资源? [英] Run Android OpenGL in Background as Rendering Resource for App?

查看:18
本文介绍了在后台运行 Android OpenGL 作为应用程序的渲染资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序的后台运行一个 Android OpenGL-ES 界面来为应用程序提供动态图形资源(位图等).OpenGL GLSurfaceView 不是我的应用程序的可见屏幕;它仅用作渲染工厂来制造供主要活动使用的图形.

I want to run an Android OpenGL-ES surface in the background of my app to provide dynamic graphical resources (bitmaps, etc.) for the application. The OpenGl GLSurfaceView is not the visible screen of my app; it is only used as a rendering factory to manufacture graphics for use by the main activity.

有谁知道如何让 Android GLSurfaceView 在它不是活动视图时运行?Google Android 文档清楚地表明,当 GLSurfaceView 失去其作为主视图的状态时,表面及其所有资源都会被销毁.

Does anyone know how to make an Android GLSurfaceView run when it is not an active view? The Google Android documentation is clear that when a GLSurfaceView loses its status as a primary view, the surface is destroyed along with all of its resources.

当 GLSurfaceView 及其关联的 GLSurfaceView.Renderer 不是(并且永远不会是)应用程序的主视图时,有什么方法可以保持其正常运行?

Is there any way to keep a GLSurfaceView and its associated GLSurfaceView.Renderer running normally when it is not (and never is) the application's primary view?

推荐答案

对于你想要做的事情,你应该完全跳过 GLSurfaceView.由于您只想进行一些 OpenGL 屏幕外渲染,因此可以使用 EGL 像素缓冲区并将其转换为位图.请参阅 anddev 上的这个线程 寻求解决方案.我已经在我的一些应用中非常成功地使用了它.

For what you're trying to do, you should skip the GLSurfaceView entirely. Since you just want to do some OpenGL offscreen rendering, you can make use of an EGL pixel buffer and convert it to a bitmap. See this thread on anddev for a solution. I've used it very successfully in a few of my apps.

该线程底部的实现有点错误,因为它做了一些非常简单的 EGL 选择.我建议实现一个更强大的选择器,您可以在 Robert Green 的 GLWallpaperService,如果你愿意的话.

The implementation towards the bottom of that thread is a bit buggy, since it does some very simple EGL choosing. I'd recommend implementing a more robust chooser, which you can find in Robert Green's GLWallpaperService, if you'd like.

我最终做出的另一个改变是移除了垂直像素镜像.我只是在 onSurfaceCreate 中翻转了我的视口,而不是在写入位图时手动翻转渲染的像素.

Another change I ended up making was to remove the vertical pixel mirroring. I just ended up flipping my viewport in onSurfaceCreate, rather than manually flip rendered pixels when writing to the bitmap.

祝你好运!

这篇关于在后台运行 Android OpenGL 作为应用程序的渲染资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆