是否可以通过 GLES 的 Java API 在 Android 上使用像素图? [英] Is it possible to use pixmaps on Android via Java API for GLES?

查看:11
本文介绍了是否可以通过 GLES 的 Java API 在 Android 上使用像素图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Android 上使用 OpenGL ES 实现离屏渲染.我的最终目标是提高我在普通 java 和 Bitmap/int[] API 中执行的纹理映射的性能.我尝试了 pbuffer 方法,类似于 相关论坛帖子.它显示出相当低的性能,glReadPixels 调用在一台设备上最多需要 50 毫秒,而在另一台设备上最多需要 15 毫秒.

I'm trying to implement off-screen rendering with OpenGL ES on Android. My ultimate goal is to improve performance of texture mapping which I do in plain java and Bitmap/int[] APIs. I tried pbuffer approach, similar to the sample code from a relevant forum thread. It shows rather low performance, glReadPixels call takes up to 50 ms on one device and up to 15 ms on another.

有更现代的方法使用帧缓冲区.代码示例相当复杂,我预计从帧缓冲区到 Android 位图的传输速度不会比使用 pbuffers 快得多.我的估计是对的吗?

There is more modern approach using Frame Buffers. The code samples are rather complicated and I don't expect much faster transfer from Frame Buffer to Android's Bitmaps than it was with pbuffers. Am I right with my estimation?

第三种方法是使用像素图.如果我理解正确的文档,他们应该在 OpenGL 和 Dalvik 的内存之间利用比普通副本更复杂的内存共享.问题是 Android SDK 中没有相关的 API.

The third approach is using pixmaps. If I understood the docs right they should utilize more sophisticated memory sharing between OpenGL and Dalvik's memory than plain copy. The problem is that relevant APIs aren't present in the Android SDK.

Java 中没有暴露 eglCreateImageKHREGLImageKHR 结构.我能找到的所有 C++ 示例都依赖于它们.

There is no eglCreateImageKHR and EGLImageKHR structure exposed in Java. All C++ examples I could find rely on them.

eglCreatePixmapSurface 但我无法从文档中弄清楚如何使用它.可能它在 native_pixmap 参数中接收某种位图句柄,但我找不到任何方法来创建这样的句柄.搜索eglCreatePixmapSurface android"只会导致问题报告.

There is eglCreatePixmapSurface but I can't figure out how to use it from the docs. Probably it receives some kind of bitmap handle in the native_pixmap parameter, but I can't find any way to create such a handle. Searching for "eglCreatePixmapSurface android" leads only to problem reports.

我的主要问题是:我可以在不编写本机代码的情况下通过 Java 在 Android 上使用像素图吗?如果我需要使用原生代码,在深入研究 OpenGL 之前,是否有可以用来评估性能的工作代码?

My main question is: can I use pixmaps on Android from Java without writing native code? If I need to go native is there working code I can use to evaluate performance before diving deep into OpenGL?

推荐答案

在 Android 上提高纹理加载性能的最佳方法是使用您安装的 EGL 图像扩展和带有原生代码的 EGL_NATIVE_BUFFER_ANDROID.我在这个 文章.我用这种方法测量了主要的性能改进.

The best way to improve texture loading performance on Android is to use the EGL image extensions you sited and EGL_NATIVE_BUFFER_ANDROID with native code. I have a code example of that in this article. I measured major performance improvements with this approach.

Android 不支持 Pixmap,并且 pbuffers 无法在 Nvidia Tegra 设备上运行.您应该改用 FBO 附加的纹理.这就是Android SurfaceTexture 类的实现方式.

Android has no support for Pixmaps and pbuffers do not work on Nvidia Tegra devices. You should use FBO-attached textures instead. That is the way the Android SurfaceTexture class is implemented.

如果您需要 alpha 纹理,这是使用本机代码的另一个原因.Bitmap 和带有 alpha 纹理的 OpenGL ES 之间存在兼容性问题.

If you need alpha textures, that is another reason to use native code. There is a compatibility problem between Bitmap and OpenGL ES with alpha textures.

使用硬件纹理压缩格式(ETC/PVR 代替 PNG)和 mipmap 也大大提高了纹理渲染的加载性能和质量,如本文章.

Using hardware texture compression formats (ETC/PVR instead of PNG) and mipmaps improves the loading performance and quality of texture rendering a lot too, as discussed in this article.

最大的问题是 glReadPixels().EGL_NATIVE_BUFFER_ANDROID 仅适用于写入纹理,不适用于将它们读回位图.Android的平台代码使用glReadPixels()来实现TextureView.getBitmap(),速度很慢.最好的解决方案是不将纹理复制到 Bitmap,而是直接显示渲染的 TextureView,从而避免 glReadPixels().

The big problem is glReadPixels(). EGL_NATIVE_BUFFER_ANDROID only works for writing textures, not for reading them back to a Bitmap. Android's platform code uses glReadPixels() to implement TextureView.getBitmap() and it is very slow. The best solution is to not copy the texture to a Bitmap, but to display the rendered TextureView directly which avoids glReadPixels().

我一直在使用 OpenGL ES 2.0,而 3.0 可能会改善这种情况.

I have been working with OpenGL ES 2.0 and the situation may have been improved with 3.0.

这篇关于是否可以通过 GLES 的 Java API 在 Android 上使用像素图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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