是否有可能通过Java API来使用Android上的像素映射为GLES?有可能、像素、Java、API

2023-09-06 00:44:52 作者:你瞎啊撞我心上

我想实现关屏呈现与OpenGL ES的Andr​​oid上。我的最终目标是提高纹理贴图的表现,我做普通的Java和位图/ 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.

有使用帧缓冲器更先进的方法。在code样品是相当复杂的,我不指望从帧缓冲更快的转移到Android的位图比它与pbuffer而使。我说的对我的估计?

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的内存比普通副本之间的更复杂的内存共享。问题是,相关的API并不present在Android SDK。

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中没有暴露 eglCreateImageKHR EGLImageKHR 结构。所有的C ++的例子我能找到依靠他们。

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

eglCreatePixmapSurface ,但我无法弄清楚如何从文档中使用它。也许它接收某种在 native_pixmap 参数位图处理,但我找不到任何方法来建立这样一个句柄。搜索eglCreatePixmapSurface机器人只会导致问题报告。

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.

我的主要问题是:我可以使用像素映射在Android与Java无需编写原生code?如果我需要去本地的工作有code,我可以用它来评估潜水前的表现深入的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与本地code。我有在这一个code例如文章。我测的主要性能改进这种方法。

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已经为像素图,并没有pbuffer而使支持不会对Nvidia的Tegra的设备正常工作。您应该使用FBO附加纹理代替。这是Android类表面纹理的实现方式。

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.

如果您需要阿尔法纹理,这是另一个原因,使用本地code。 有位图和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.

使用硬件纹理玉米pression格式(ETC / PVR代替PNG)和MIP贴图提高了装载的性能和质地的质量呈现很多太,如本 一文。

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的平台code使用glReadPixels()来实现TextureView.getBitmap(),这是非常缓慢的。最好的解决办法是将纹理复制到一个位图,而是直接显示渲染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.