1
1
mirror of https://github.com/wez/wezterm.git synced 2024-09-20 03:09:06 +03:00

gui: more fun with gamma correction

On Windows, both EGL and MESA render modes were too dark.
After a bit of hunting around what I found made EGL and MESA
consistent with my default nVidia GPL rendering was:

* Tell glium that our shader outputs srgb
* Add explicit gamma conversion from linear to srgb in the shader

AFAICT, that shouldn't be required, but it seems as though something
deep in glium really wants to apply some kind of gamma conversion,
and it seems to select the wrong kind unless we set things explicitly
to SRGB.

There are some people complaining about this in
https://github.com/glium/glium/issues/1615.

I actually tried to move entirely aware from the glium srgbtexture2d
type in the hope of having explicit control over the gamma, but the
issue is in what happens to the outputs rather than the inputs.

It appears to me as though the text now looks slightly less
intense, so I think this may be what we need for the gamma issue
in https://github.com/wez/wezterm/issues/544 and potentially
also https://github.com/wez/wezterm/issues/1025

refs: https://github.com/wez/wezterm/issues/1373
This commit is contained in:
Wez Furlong 2021-12-22 18:14:52 -07:00
parent 872935f656
commit 9e146beb02
3 changed files with 31 additions and 5 deletions

View File

@ -48,6 +48,22 @@ vec4 apply_hsv(vec4 c, vec3 transform)
return vec4(hsv2rgb(hsv).rgb, c.a);
}
vec3 to_linear(vec3 v) {
return pow(v, vec3(2.2));
}
vec4 to_linear(vec4 v) {
return vec4(to_linear(v.rgb), v.a);
}
vec3 to_srgb(vec3 v) {
return pow(v, vec3(1.0 / 2.2));
}
vec4 to_srgb(vec4 v) {
return vec4(to_srgb(v.rgb), v.a);
}
void main() {
if (o_has_color == 3.0) {
// Solid color block
@ -79,4 +95,8 @@ void main() {
}
color = apply_hsv(color, o_hsv);
// We MUST output SRGB and tell glium that we do that (outputs_srgb),
// otherwise something in glium over-gamma-corrects depending on the gl setup.
color = to_srgb(color);
}

View File

@ -164,7 +164,7 @@ impl RenderState {
let source = glium::program::ProgramCreationInput::SourceCode {
vertex_shader: &vertex_shader,
fragment_shader: &fragment_shader,
outputs_srgb: false,
outputs_srgb: true,
tessellation_control_shader: None,
tessellation_evaluation_shader: None,
transform_feedback_varyings: None,

View File

@ -213,10 +213,8 @@ impl GlState {
1,
PIXEL_TYPE_ARB as i32,
TYPE_RGBA_ARB as i32,
ACCELERATION_ARB as i32,
FULL_ACCELERATION_ARB as i32,
COLOR_BITS_ARB as i32,
32,
24,
ALPHA_BITS_ARB as i32,
8,
DEPTH_BITS_ARB as i32,
@ -230,9 +228,11 @@ impl GlState {
];
if has_extension(&extensions, "WGL_ARB_framebuffer_sRGB") {
log::trace!("will request FRAMEBUFFER_SRGB_CAPABLE_ARB");
attribs.push(FRAMEBUFFER_SRGB_CAPABLE_ARB as i32);
attribs.push(1);
} else if has_extension(&extensions, "WGL_EXT_framebuffer_sRGB") {
log::trace!("will request FRAMEBUFFER_SRGB_CAPABLE_EXT");
attribs.push(FRAMEBUFFER_SRGB_CAPABLE_EXT as i32);
attribs.push(1);
}
@ -295,6 +295,7 @@ impl GlState {
];
if has_extension(&extensions, "WGL_ARB_create_context_robustness") {
log::trace!("requesting robustness features");
attribs.push(CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB as i32);
attribs.push(LOSE_CONTEXT_ON_RESET_ARB as i32);
attribs.push(CONTEXT_FLAGS_ARB as i32);
@ -310,7 +311,12 @@ impl GlState {
};
if rc.is_null() {
anyhow::bail!("CreateContextAttribsARB failed");
let err = unsafe { winapi::um::errhandlingapi::GetLastError() };
anyhow::bail!(
"CreateContextAttribsARB failed, GetLastError={} {:x}",
err,
err
);
}
unsafe {