mirror of
https://github.com/SpaceManiac/SpacemanDMM.git
synced 2025-12-23 05:36:47 +00:00
Fix decals having subtly wrong colors, by disabling SRGB
This commit is contained in:
parent
5557fa1b36
commit
d2770a035c
5 changed files with 16 additions and 37 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1133,6 +1133,7 @@ dependencies = [
|
|||
"dreammaker 0.1.0",
|
||||
"gfx 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gfx_device_gl 0.15.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gfx_gl 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gfx_window_glutin 0.26.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"glutin 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"imgui 0.0.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ path = "main.rs"
|
|||
dreammaker = { path = "../dreammaker" }
|
||||
dmm-tools = { path = "../tools" }
|
||||
glutin = "0.18.0"
|
||||
gfx_gl = "0.5.0"
|
||||
gfx = "0.17.1"
|
||||
gfx_window_glutin = "0.26.0"
|
||||
gfx_device_gl = "0.15.3"
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ pub fn load_texture(factory: &mut Factory, bitmap: lodepng::Bitmap<RGBA>) -> Tex
|
|||
}
|
||||
|
||||
let kind = gfx::texture::Kind::D2(width as u16, height as u16, gfx::texture::AaMode::Single);
|
||||
let (_, view) = factory.create_texture_immutable_u8::<gfx::format::Srgba8>(
|
||||
let (_, view) = factory.create_texture_immutable_u8::<::ColorFormat>(
|
||||
kind,
|
||||
gfx::texture::Mipmap::Provided,
|
||||
&[&new_buffer[..]]
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ extern crate divrem;
|
|||
extern crate serde;
|
||||
extern crate toml;
|
||||
extern crate petgraph;
|
||||
extern crate gfx_gl as gl;
|
||||
|
||||
extern crate dreammaker as dm;
|
||||
extern crate dmm_tools;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use imgui::{FrameSize, ImFontConfig, ImGui, ImGuiMouseCursor, ImVec4, ImGuiStyle};
|
||||
use imgui::{FrameSize, ImFontConfig, ImGui, ImGuiMouseCursor, ImVec4};
|
||||
use imgui_gfx_renderer::{Renderer, Shaders};
|
||||
use std::time::Instant;
|
||||
|
||||
|
|
@ -26,6 +26,16 @@ pub fn run(title: String, clear_color: [f32; 4]) -> ::EditorScene {
|
|||
let (window, mut device, mut factory, mut main_color, mut main_depth) =
|
||||
gfx_window_glutin::init::<ColorFormat, DepthFormat>(window, context, &events_loop);
|
||||
|
||||
// gfx's gl backend sets FRAMEBUFFER_SRGB permanently by default - actually
|
||||
// we want it off permanently. I've been told this is most sanely set on a
|
||||
// per-render-pass basis, but neither the world nor imgui blend colors
|
||||
// accurately if it is set.
|
||||
unsafe {
|
||||
device.with_gl(|gl| {
|
||||
gl.Disable(::gl::FRAMEBUFFER_SRGB);
|
||||
});
|
||||
}
|
||||
|
||||
let (ww, wh): (f64, f64) = window.get_outer_size().unwrap().into();
|
||||
let (dw, dh): (f64, f64) = window.get_primary_monitor().get_dimensions().into();
|
||||
window.set_position(((dw - ww) / 2.0, (dh - wh) / 2.0).into());
|
||||
|
|
@ -49,7 +59,7 @@ pub fn run(title: String, clear_color: [f32; 4]) -> ::EditorScene {
|
|||
};
|
||||
|
||||
let mut imgui = ImGui::init();
|
||||
fix_imgui_srgb(&mut imgui.style_mut().colors, &dark_theme());
|
||||
imgui.style_mut().colors.clone_from(&dark_theme());
|
||||
imgui.set_ini_filename(None);
|
||||
|
||||
// In the examples we only use integer DPI factors, because the UI can get very blurry
|
||||
|
|
@ -301,40 +311,6 @@ fn update_mouse(imgui: &mut ImGui, mouse_state: &mut MouseState) {
|
|||
mouse_state.wheel = 0.0;
|
||||
}
|
||||
|
||||
fn fix_imgui_srgb(dest: &mut [ImVec4; 43], source: &[ImVec4; 43]) {
|
||||
// Fix incorrect colors with sRGB framebuffer
|
||||
fn imgui_gamma_to_linear(col: ImVec4) -> ImVec4 {
|
||||
let x = col.x.powf(2.2);
|
||||
let y = col.y.powf(2.2);
|
||||
let z = col.z.powf(2.2);
|
||||
let w = 1.0 - (1.0 - col.w).powf(2.2);
|
||||
ImVec4::new(x, y, z, w)
|
||||
}
|
||||
|
||||
for (dest, source) in dest.iter_mut().zip(source.iter()) {
|
||||
*dest = imgui_gamma_to_linear(*source);
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround for ImGuiStyle not being Clone.
|
||||
fn _clone_imgui_style(style: &ImGuiStyle) -> ImGuiStyle {
|
||||
macro_rules! f {
|
||||
($($f:ident,)*) => {
|
||||
ImGuiStyle {
|
||||
$($f: style.$f,)*
|
||||
}
|
||||
}
|
||||
}
|
||||
f! { alpha, window_padding, window_rounding, window_border_size,
|
||||
window_min_size, window_title_align, child_rounding, child_border_size,
|
||||
popup_rounding, popup_border_size, frame_padding, frame_rounding,
|
||||
frame_border_size, item_spacing, item_inner_spacing, touch_extra_padding,
|
||||
indent_spacing, columns_min_spacing, scrollbar_size, scrollbar_rounding,
|
||||
grab_min_size, grab_rounding, button_text_align, display_window_padding,
|
||||
display_safe_area_padding, anti_aliased_lines, anti_aliased_fill,
|
||||
curve_tessellation_tol, colors, }
|
||||
}
|
||||
|
||||
fn dark_theme() -> [ImVec4; 43] {
|
||||
[
|
||||
ImVec4::new(1.00, 1.00, 1.00, 1.00),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue