开发者

Is it possible to render in RGB888 with OpenGL?

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.

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

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

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

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

In my case it is ok to fallback to RGB565 if RGB888 isn't avail开发者_如何学运维able, but I would prefer this to be quite rare.

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

Are there any compatibility problems or weird bugs with this?

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


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); 

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).

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.


This is how I do it;

{
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// cocos2d will inherit these values
[window setUserInteractionEnabled:YES]; 
[window setMultipleTouchEnabled:NO];

// must be called before any othe call to the director
[Director useFastDirector];
[[Director sharedDirector] setDisplayFPS:YES];

// create an openGL view inside a window
[[Director sharedDirector] attachInView:window];

// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[Texture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_];  

glClearColor(0.7f,0.7f,0.6f,1.0f);
//glClearColor(1.0f,1.0f,1.0f,1.0f);

[window makeKeyAndVisible];

[[Director sharedDirector] runWithScene:[GameLayer node]];

}

I hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜