4

In OpenGL ES, I can create sRGB render buffers using either OpenGL ES 3.0 or OpenGL ES 2.0 with the extension GL_EXT_sRGB. I create a renderable texture with internal format GL_SRGB8_ALPHA8 (or GL_SRGB8_ALPHA8_EXT) and it works fine on the Android devices that support it.

However, I can't find any way to make the default render buffer use sRGB on Android. I'm using GLSurfaceView, so it goes through EGL and eglChooseConfig, but I can't find what attribute, if any, governs the sRGB setting.

I can of course work around it by rendering to an sRGB target and then copying to the backbuffer before display, but that is rather wasteful. It was much easier to do in OpenGL and DirectX, but OpenGL ES needs the sRGB setting to be applied when the render buffer/frame buffer is created.

Any ideas?

Muzza
  • 1,236
  • 9
  • 13

1 Answers1

4

You are definitely on the right track, the only way to get an sRGB default framebuffer in OpenGL ES is going to involve going through EGL. Now, EGL 1.4 does not have built-in support for different color spaces on GL's default framebuffer, however there is an extension that your system may support called EGL_KHR_gl_colorspace.

If your EGL implementation supports this extension, then you can pass the following attribute pair to EGL when you create your window surface:

     EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR

Now, here is where things get kind of funny... the constant EGL_GL_COLORSPACE_SRGB_KHR has the same value as EGL_VG_COLORSPACE_sRGB in EGL 1.3. EGL_VG_COLORSPACE_sRGB was called EGL_COLORSPACE_sRGB in EGL 1.2. If sRGB OpenGL color spaces are promoted to core for EGL 1.5, the thing will probably be renamed yet again - back to what it was called in EGL 1.2 ;)

Long story short, if your implementation supports this extension you can use the EGL_VG_COLORSPACE... constants for an OpenGL surface as well. It basically extends the functionality that OpenVG had to OpenGL, right down to using the exact same numeric values for the constants.

Andon M. Coleman
  • 42,359
  • 2
  • 81
  • 106
  • Accepted as the correct answer. This is what I was trying to do already, but it appears it failed because I don't have any devices that support the required EGL extension. Even OpenGL ES 3.0 devices that fully support sRGB within OpenGL ES such as the 2nd Gen Nexus 7 are not currently exposing the EGL extension which is a bit of an annoying limitation. Looks like I need to wait for software updates or new devices to use this feature. – Muzza Jan 04 '14 at 05:52