When I create an sRGB default framebuffer on Android (using EGL_KHR_gl_colorspace + EXT_sRGB_write_control), the contents are not properly converted from linear to sRGB as expected (GL ES 3.1, on Mali-T720):
const EGLint window_attribs[] = { EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR, EGL_NONE };
egl_surface = eglCreateWindowSurface(egl_display, config, egl_window, window_attribs);
if (egl_surface == EGL_NO_SURFACE) {
printf("[!] eglCreateWindowSurface failed: %i", eglGetError() );
return false;
}
I verify the encoding of the default framebuffer like this:
glEnable(GL_FRAMEBUFFER_SRGB_EXT);
GLint encoding = -1;
glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &encoding);
if (encoding == GL_LINEAR) printf("Framebuffer: GL_LINEAR\n");
if (encoding == GL_SRGB ) printf("Framebuffer: GL_SRGB\n");
glDisable(GL_FRAMEBUFFER_SRGB_EXT);
On Android, it prints GL_LINEAR, while that should be GL_SRGB, and the framebuffer contents is not converted from linear to sRGB.
On desktop (GLX, NV GTX1060), the same codebase works properly, yet glGetFramebufferAttachmentParameteriv also reports GL_LINEAR instead of GL_SRGB, while the framebuffer contents are properly converted from linear to sRGB. This seems to be a known but unfixed issue: https://forums.developer.nvidia.com/t/gl-framebuffer-srgb-functions-incorrectly/34889/10
sRGB encoded textures (including sRGB ASTC textures) are properly handled on both said hardware (even on desktop; NV driver apparently silently accepts sRGB ASTC texture data, even if otherwise unsupported in hardware). All my code is GL error free.
My question: should I avoid sRGB default framebuffer functionality? It seems to be unreliable on multiple platforms (ARM/Mali and NV/GLX), and there’s no information (like sample code) beyond the EGL_KHR_gl_colorspace spec to be found. I suspect virtually all GL (ES) apps render to an sRGB FBO, then rendered to the default framebuffer, and thus these issues have gone unreported?
Has anyone successfully got this feature working (any platform)? Anything I should double check or verify?
I will probably render to an sRGB FBO as workaround, but I was hoping to save some memory by only using the default framebuffer.