From 05cc7dce02b656e633c880dcc55acdf370cb25c1 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Wed, 27 Jul 2016 05:24:18 +0300 Subject: [PATCH] -no-srgb option --- src/app.cc | 4 +--- src/backdrop.cc | 12 +++++++----- src/color.cc | 19 +++++++++++++++++++ src/color.h | 12 ++++++++++++ src/texture.cc | 9 ++++++--- 5 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 src/color.cc create mode 100644 src/color.h diff --git a/src/app.cc b/src/app.cc index e9e4cbb..81325f6 100644 --- a/src/app.cc +++ b/src/app.cc @@ -42,10 +42,8 @@ bool app_init(int argc, char **argv) glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); - //glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - if(GLEW_ARB_framebuffer_sRGB) { + if(opt.srgb && GLEW_ARB_framebuffer_sRGB) { printf("enabling sRGB framebuffer\n"); glEnable(GL_FRAMEBUFFER_SRGB); } diff --git a/src/backdrop.cc b/src/backdrop.cc index b81a04a..91c709a 100644 --- a/src/backdrop.cc +++ b/src/backdrop.cc @@ -6,6 +6,7 @@ #include "meshgen.h" #include "backdrop.h" #include "app.h" +#include "color.h" static unsigned int sdr_grid; static Texture *tex_grid; @@ -13,14 +14,15 @@ static Texture *tex_grid; static Mesh *mesh_skydome; static unsigned int sdr_skydome; -static const Vec3 grid_color = Vec3(1.0, 0.07, 1.0); -static const Vec3 mid_color = Vec3(0.133, 0.006, 0.612); -static const Vec3 horiz_color = Vec3(0.612, 0.006, 1.0); -static const Vec3 zenith_color = Vec3(0.029, 0.029, 0.029); -static const Vec3 fog_color = Vec3(0.01, 0.01, 0.01); bool init_backdrop() { + Vec3 grid_color = color(1.0, 0.07, 1.0); + Vec3 mid_color = color(0.133, 0.006, 0.612); + Vec3 horiz_color = color(0.612, 0.006, 1.0); + Vec3 zenith_color = color(0.029, 0.029, 0.029); + Vec3 fog_color = color(0.01, 0.01, 0.01); + if(!(sdr_grid = create_program_load("sdr/grid.v.glsl", "sdr/grid.p.glsl"))) { return false; } diff --git a/src/color.cc b/src/color.cc new file mode 100644 index 0000000..ae27f89 --- /dev/null +++ b/src/color.cc @@ -0,0 +1,19 @@ +#include "color.h" +#include "opt.h" + +Color color(float r, float g, float b) +{ + return opt.srgb ? Color(r, g, b) : linear_to_srgb(Color(r, g, b)); +} + +Color linear_to_srgb(const Color &c) +{ + const float inv_gamma = 1.0f / 2.2f; + return Color(pow(c.x, inv_gamma), pow(c.y, inv_gamma), pow(c.z, inv_gamma)); +} + +Color srgb_to_linear(const Color &c) +{ + const float gamma = 2.2f; + return Color(pow(c.x, gamma), pow(c.y, gamma), pow(c.z, gamma)); +} diff --git a/src/color.h b/src/color.h new file mode 100644 index 0000000..2fe4db4 --- /dev/null +++ b/src/color.h @@ -0,0 +1,12 @@ +#ifndef COLOR_H_ +#define COLOR_H_ + +#include "gmath/gmath.h" + +typedef Vec3 Color; + +Color color(float r, float g, float b); +Color linear_to_srgb(const Color &c); +Color srgb_to_linear(const Color &c); + +#endif // COLOR_H_ diff --git a/src/texture.cc b/src/texture.cc index f332efa..49f3aab 100644 --- a/src/texture.cc +++ b/src/texture.cc @@ -3,6 +3,7 @@ #include "image.h" #include "opengl.h" #include "imago2.h" +#include "opt.h" #if defined(GL_ES_VERSION_2_0) || defined(GL_VERSION_3_0) #define USE_GL_GENERATE_MIPMAP @@ -394,21 +395,23 @@ static int gltype_from_ifmt(unsigned int ifmt) static int glifmt_from_imgfmt(Image::Format fmt) { + bool use_srgb = GLEW_EXT_texture_sRGB && opt.srgb; + switch(fmt) { case Image::FMT_GREY: - return GLEW_EXT_texture_sRGB ? GL_SLUMINANCE : GL_LUMINANCE; + return use_srgb ? GL_SLUMINANCE : GL_LUMINANCE; case Image::FMT_GREY_FLOAT: return GL_LUMINANCE16F; case Image::FMT_RGB: - return GLEW_EXT_texture_sRGB ? GL_SRGB : GL_RGB; + return use_srgb ? GL_SRGB : GL_RGB; case Image::FMT_RGB_FLOAT: return GL_RGB16F; case Image::FMT_RGBA: - return GLEW_EXT_texture_sRGB ? GL_SRGB_ALPHA : GL_RGBA; + return use_srgb ? GL_SRGB_ALPHA : GL_RGBA; case Image::FMT_RGBA_FLOAT: return GL_RGBA16F; -- 1.7.10.4