Split out some private utilities into effect_util.cpp, so we do not need to include...
[movit] / lift_gamma_gain_effect.cpp
index 149cb44..f00da87 100644 (file)
@@ -1,19 +1,38 @@
+#include <GL/glew.h>
+#include <math.h>
+
+#include "effect_util.h"
 #include "lift_gamma_gain_effect.h"
 #include "util.h"
 
 LiftGammaGainEffect::LiftGammaGainEffect()
        : lift(0.0f, 0.0f, 0.0f),
          gamma(1.0f, 1.0f, 1.0f),
-         gain(1.0f, 1.0f, 1.0f),
-         saturation(1.0f)
+         gain(1.0f, 1.0f, 1.0f)
 {
        register_vec3("lift", (float *)&lift);
        register_vec3("gamma", (float *)&gamma);
        register_vec3("gain", (float *)&gain);
-       register_float("saturation", &saturation);
 }
 
-std::string LiftGammaGainEffect::output_glsl()
+std::string LiftGammaGainEffect::output_fragment_shader()
+{
+       return read_file("lift_gamma_gain_effect.frag");
+}
+
+void LiftGammaGainEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
 {
-       return read_file("lift_gamma_gain_effect.glsl");
+       Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
+
+       RGBTriplet gain_pow_inv_gamma(
+               pow(gain.r, 1.0f / gamma.r),
+               pow(gain.g, 1.0f / gamma.g),
+               pow(gain.b, 1.0f / gamma.b));
+       set_uniform_vec3(glsl_program_num, prefix, "gain_pow_inv_gamma", (float *)&gain_pow_inv_gamma);
+
+       RGBTriplet inv_gamma_22(
+               2.2f / gamma.r,
+               2.2f / gamma.g,
+               2.2f / gamma.b);
+       set_uniform_vec3(glsl_program_num, prefix, "inv_gamma_22", (float *)&inv_gamma_22);
 }