本文介绍了是否可以使用 OpenGL 以 RGB888 进行渲染?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在各种设备上使用 Android 上的 OpenGL 玩了一段时间.除非我错了,否则默认渲染始终使用 RGB565 像素格式.

I have played for a while with OpenGL on Android on various devices. And unless I'm wrong, the default rendering is always performed with the RGB565 pixel format.

不过,我想使用 RGB888 渲染更准确的颜色.

I would however like to render more accurate colors using RGB888.

GLSurfaceView 文档提到了两种与像素格式相关的方法:

The GLSurfaceView documentation mentions two methods which relate to pixel formats:

  • the setFormat() method exposed by SurfaceHolder, as returned by SurfaceView.getHolder()
  • the GLSurfaceView.setEGLConfigChooser() family of methods

除非我错了,我想我只需要使用后者.还是在这里使用 SurfaceHolder.setFormat() 相关?

Unless I'm wrong, I think I only need to use the later. Or is using SurfaceHolder.setFormat() relevant here?

EGLConfigChooser 类的文档提到 EGL10.eglChooseConfig(),发现哪些配置可用.

The documentation of the EGLConfigChooser class mentions EGL10.eglChooseConfig(), to discover which configurations are available.

在我的情况下,如果 RGB888 不可用,则可以回退到 RGB565,但我希望这种情况很少见.

In my case it is ok to fallback to RGB565 if RGB888 isn't available, but I would prefer this to be quite rare.

那么,是否可以在大多数设备上使用 RGB888?

So, is it possible to use RGB888 on most devices?

这是否有任何兼容性问题或奇怪的错误?

Are there any compatibility problems or weird bugs with this?

您有设置 GLSurfaceView 以呈现 RGB888 的正确可靠方法的示例吗?

Do you have an example of a correct and reliable way to setup the GLSurfaceView for rendering RGB888?

推荐答案

在较新的设备上,大多数应该支持 RGBA8888 作为原生格式.强制 RGBA 颜色格式的一种方法是设置表面的半透明度,除了深度和模板缓冲区之外,您仍然希望选择 EGLConfig 来最好地猜测通道的配置.

On newer devices, most of them should support RGBA8888 as a native format. One way to force RGBA color format is to set the translucency of the surface, you'd still want to pick the EGLConfig to best guess the config for the channels in addition to the depth and stencil buffers.

setEGLConfigChooser(8, 8, 8, 8, 0, 0);
getHolder().setFormat(PixelFormat.RGBA_8888);

但是,如果我正确阅读了您的问题,您要求支持 RGB888(不关心 alpha),换句话说,可能并非所有设备都支持 RGBX8888(驱动程序供应商限制).

However, if I read your question correctly you're asking for RGB888 support (alpha don't care) in other words, RGBX8888 which might not be supported by all devices (driver vendor limitation).

关于性能需要记住的一点是,由于 RGBA8888 是大多数 GPU 硬件本机支持的颜色格式,因此最好避免使用任何其他颜色格式(非本机支持),因为这通常会转化为添加非必要工作的颜色转换加载到 GPU.

Something to keep in mind about performance though, since RGBA8888 is the color format natively supported by most GPUs hardware it's best to avoid any other color format (non natively supported) since that usually translate into a color conversion underneath adding non necessary work load to the GPU.

这篇关于是否可以使用 OpenGL 以 RGB888 进行渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 12:27