I've been looking into gamma correction, and what I should do to do proper gamma-aware rendering, but browsing the web has left me somewhat confused.
My basic understanding is as follows.
1. (most) texture images are gamma pre-corrected (not linear, either sRGB or something similar).
2. Shading computation should be done in a linear color space.
To do gamma-aware rendering in theory, I have to:
A. transform my texture images from nonlinear to linear color space
B. do my lighting/shading computations in linear color space
C. transform the results from linear back to nonlinear color space
Now I understand that OpenGL helps me with step A with the sRGB internal texture format, and that step B is my own concerns. My main confusion comes with step C. If I would render to an FBO, I can specify the sRGB format for the FBO as well, and OpenGL takes care of step C. However, I cannot really find anything similar for rendering directly to screen. It would appear that in that case I would have to do step C myself - explicitly - in my shaders. I cannot get OpenGL to do that for me automatically. Is this a correct assumption, or am I missing something?
On 12/19/2014 10:03 AM, elect [via jogamp] wrote:
> I think it should be definitely determined at the creation of the opengl context.
I am unaware of a generic overall SRGB mode,
but if you have information about it (GL, EGL, ..)
Unfortunately documentation over internet regarding sRGB for the default framebuffer lacks. What I linked is the only source mentioning something about it and therefore this is the only thing my assumption is based on. I had the hint of the context reading this guy
In the GL pipeline one should work in linear RGB (lRGB). OpenGL offers all the tools to make it without any additional modification for the devs and, more important, free performance-wise. This means sRGB textures as input will be translated automatically to lRGB and output textures to sRGB, default framebuffer included, if properly configured.
Scanning Jogl, I found some interesting variables about the same thema
public static final int EGL_VG_COLORSPACE_sRGB = 0x3089;
public static final int EGL_VG_COLORSPACE_LINEAR = 0x308A;
public static final int WGL_ARB_framebuffer_sRGB = 1;
public static final int WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB = 0x20A9;
public static final int WGL_EXT_framebuffer_sRGB = 1;
public static final int WGL_FRAMEBUFFER_SRGB_CAPABLE_EXT = 0x20A9;
public static final int GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB = 0x20B2;
public static final int GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT = 0x20B2;
> Sven Gothel wrote
> This is not a canonical reference,
> hence your assumption would need some reason,
> e.g. a EGL, GLX, WGL .. reference.
> As I understand, you assume either:
>  SRGB selection as a context property
> This does not exist in the GL spec.
>  SRGB selection as a pixelformat property
> We have to look, but I doubt.
> One may select SRGB texture formats, GL spec.
> I am unaware of a generic overall SRGB mode,
> but if you have information about it (GL, EGL, ..)
> that would be great.
> signature.asc (828 bytes)
> Unfortunately documentation over internet regarding sRGB for the default
> framebuffer lacks. What I linked is the only source mentioning something about
> it and therefore this is the only thing my assumption is based on. I had the
> hint of the context reading this guy
> http://stackoverflow.com/questions/25842211/opengl-srgb-framebuffer-oddity >
> In the GL pipeline one should work in linear RGB (lRGB). OpenGL offers all the
> tools to make it without any additional modification for the devs and, more
> important, free performance-wise. This means sRGB textures as input will be
> translated automatically to lRGB and output textures to sRGB, default
> framebuffer included, if properly configured.
So, we would need a GLCapabilities extension for colorspace selection.
Maybe this has to be defined in it's parent Capabilities, allowing to
select the default framebuffer / pixelformat (-> onscreen).
This 'Capabilities.colorspace' entry shall be utilized for
 onscreen drawables and  offscreen FBO drawables, if available.
Capabilities.colorspace might be of an integer or enum type
w/ (currently known) values: lRGB (default, linear) and sRGB (standardized RGB).
We may refactor TextureData.Colorspace and extend it's type accordingly.
Onscreen drawables will require assistance of EGL, GLX, EGL ..,
where FBO offscreen can be supported merely by 'some' GL extension(s).