]> git.sesse.net Git - movit/commitdiff
Rename set_uniforms() to set_gl_state(), and make a corresponding clear_gl_state().
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 5 Oct 2012 19:29:34 +0000 (21:29 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 5 Oct 2012 19:29:34 +0000 (21:29 +0200)
blur_effect.cpp
blur_effect.h
effect.cpp
effect.h
effect_chain.cpp
lift_gamma_gain_effect.cpp
lift_gamma_gain_effect.h
sandbox_effect.cpp
sandbox_effect.h
vignette_effect.cpp
vignette_effect.h

index 285169851705309c0867b50bac0408c6284ca1a2..e6a9a313ec8fd82918d7719570d96a194814beb9 100644 (file)
@@ -47,9 +47,9 @@ std::string SingleBlurPassEffect::output_fragment_shader()
        return read_file("blur_effect.frag");
 }
 
        return read_file("blur_effect.frag");
 }
 
-void SingleBlurPassEffect::set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
+void SingleBlurPassEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
 {
 {
-       Effect::set_uniforms(glsl_program_num, prefix, sampler_num);
+       Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
 
        int base_texture_size, texture_size;
        if (direction == HORIZONTAL) {
 
        int base_texture_size, texture_size;
        if (direction == HORIZONTAL) {
@@ -202,3 +202,13 @@ void SingleBlurPassEffect::set_uniforms(GLuint glsl_program_num, const std::stri
        set_uniform_vec4_array(glsl_program_num, prefix, "samples", samples, NUM_TAPS + 1);
 #endif
 }
        set_uniform_vec4_array(glsl_program_num, prefix, "samples", samples, NUM_TAPS + 1);
 #endif
 }
+
+void SingleBlurPassEffect::clear_gl_state()
+{
+       glActiveTexture(GL_TEXTURE0);
+       check_error();
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
+       check_error();
+       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1000);
+       check_error();
+}
index 3e516b76eba22cfb11c8441c59fe5a43ec0f6a61..a440949f00901beb8b7eb206b1b45be23678ac0f 100644 (file)
@@ -22,7 +22,7 @@ public:
        virtual std::string output_fragment_shader() {
                assert(false);
        }
        virtual std::string output_fragment_shader() {
                assert(false);
        }
-       virtual void set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) {
+       virtual void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num) {
                assert(false);
        }
 
                assert(false);
        }
 
@@ -44,7 +44,8 @@ public:
        virtual bool needs_texture_bounce() const { return true; }
        virtual bool needs_mipmaps() const { return true; }
 
        virtual bool needs_texture_bounce() const { return true; }
        virtual bool needs_mipmaps() const { return true; }
 
-       void set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
+       void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
+       void clear_gl_state();
        
        enum Direction { HORIZONTAL = 0, VERTICAL = 1 };
 
        
        enum Direction { HORIZONTAL = 0, VERTICAL = 1 };
 
index 1aa37781525f1f7454f656e0c05161ddce9f82e1..8cdf236a1cad3f07e2a0b2645f22e23066f297b7 100644 (file)
@@ -211,7 +211,7 @@ std::string Effect::output_convenience_uniforms() const
        return output;
 }
 
        return output;
 }
 
-void Effect::set_uniforms(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num)
+void Effect::set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num)
 {
        for (std::map<std::string, float*>::const_iterator it = params_float.begin();
             it != params_float.end();
 {
        for (std::map<std::string, float*>::const_iterator it = params_float.begin();
             it != params_float.end();
@@ -246,3 +246,5 @@ void Effect::set_uniforms(GLuint glsl_program_num, const std::string& prefix, un
                ++*sampler_num;
        }
 }
                ++*sampler_num;
        }
 }
+
+void Effect::clear_gl_state() {}
index 082c234c5292ebf7361326022b6eb918d16c8365..d14176b2b1f4dc5f74f56388766cdfb2d5d14362 100644 (file)
--- a/effect.h
+++ b/effect.h
@@ -115,17 +115,19 @@ public:
        // Returns the GLSL fragment shader string for this effect.
        virtual std::string output_fragment_shader() = 0;
 
        // Returns the GLSL fragment shader string for this effect.
        virtual std::string output_fragment_shader() = 0;
 
-       // Set all uniforms the shader needs in the current GL context.
-       // The default implementation sets one uniform per registered parameter.
+       // Set all OpenGL state that this effect needs before rendering.
+       // The default implementation sets one uniform per registered parameter,
+       // but no other state.
        //
        // <sampler_num> is the first free texture sampler. If you want to use
        // textures, you can bind a texture to GL_TEXTURE0 + <sampler_num>,
        // and then increment the number (so that the next effect in the chain
        // will use a different sampler).
        //
        // <sampler_num> is the first free texture sampler. If you want to use
        // textures, you can bind a texture to GL_TEXTURE0 + <sampler_num>,
        // and then increment the number (so that the next effect in the chain
        // will use a different sampler).
-       //
-       // NOTE: Currently this is also abused a bit to set other GL state
-       // the effect might need.
-       virtual void set_uniforms(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
+       virtual void set_gl_state(GLuint glsl_program_num, const std::string& prefix, unsigned *sampler_num);
+
+       // If you set any special OpenGL state in set_gl_state(), you can clear it
+       // after rendering here. The default implementation does nothing.
+       virtual void clear_gl_state();
 
        // Set a parameter; intended to be called from user code.
        // Neither of these take ownership of the pointer.
 
        // Set a parameter; intended to be called from user code.
        // Neither of these take ownership of the pointer.
index bfb30bfc152e2189a80d1b4fabdbc6d18056f507..2144bfd705526440b8aba2b44c7c00b6b24f8f36 100644 (file)
@@ -573,7 +573,7 @@ void EffectChain::render_to_screen(unsigned char *src)
                unsigned sampler_num = phases[phase].inputs.size();
                for (unsigned i = 0; i < phases[phase].effects.size(); ++i) {
                        Effect *effect = phases[phase].effects[i];
                unsigned sampler_num = phases[phase].inputs.size();
                for (unsigned i = 0; i < phases[phase].effects.size(); ++i) {
                        Effect *effect = phases[phase].effects[i];
-                       effect->set_uniforms(phases[phase].glsl_program_num, effect_ids[effect], &sampler_num);
+                       effect->set_gl_state(phases[phase].glsl_program_num, effect_ids[effect], &sampler_num);
                }
 
                // Now draw!
                }
 
                // Now draw!
@@ -594,11 +594,9 @@ void EffectChain::render_to_screen(unsigned char *src)
                glEnd();
                check_error();
 
                glEnd();
                check_error();
 
-               // HACK
-               glActiveTexture(GL_TEXTURE0);
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
-               check_error();
-               glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1000);
-               check_error();
+               for (unsigned i = 0; i < phases[phase].effects.size(); ++i) {
+                       Effect *effect = phases[phase].effects[i];
+                       effect->clear_gl_state();
+               }
        }
 }
        }
 }
index 19cef18ea25bac5ec897575284b04f79a39996d1..2dc827885cb46a8a005427c18a9e247087abd781 100644 (file)
@@ -22,9 +22,9 @@ std::string LiftGammaGainEffect::output_fragment_shader()
        return read_file("lift_gamma_gain_effect.frag");
 }
 
        return read_file("lift_gamma_gain_effect.frag");
 }
 
-void LiftGammaGainEffect::set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
+void LiftGammaGainEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
 {
 {
-       Effect::set_uniforms(glsl_program_num, prefix, sampler_num);
+       Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
 
        RGBTriplet gain_pow_inv_gamma(
                pow(gain.r, 1.0f / gamma.r),
 
        RGBTriplet gain_pow_inv_gamma(
                pow(gain.r, 1.0f / gamma.r),
index b57a89964204fa5622635ac852d8678721a090ce..533a7b2f22aee450c33eef9a41f4a42d657ce7a0 100644 (file)
@@ -24,7 +24,7 @@ public:
        LiftGammaGainEffect();
        std::string output_fragment_shader();
 
        LiftGammaGainEffect();
        std::string output_fragment_shader();
 
-       void set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
+       void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
 
 private:
        RGBTriplet lift, gamma, gain;
 
 private:
        RGBTriplet lift, gamma, gain;
index 85fa9001589a7356855acfcfdbc3d3fcadecd870..6fdfa5156d8f51aac3c27f41b115c58550ce2c76 100644 (file)
@@ -19,9 +19,9 @@ std::string SandboxEffect::output_fragment_shader()
        return read_file("sandbox_effect.frag");
 }
 
        return read_file("sandbox_effect.frag");
 }
 
-void SandboxEffect::set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
+void SandboxEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
 {
 {
-       Effect::set_uniforms(glsl_program_num, prefix, sampler_num);
+       Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
 
        // Any OpenGL state you might want to set, goes here.
 }
 
        // Any OpenGL state you might want to set, goes here.
 }
index 391be6d78520121193fb81537e615aea7be6e7a7..44e8d3fdbee40464909a1f5192f21060db3868c0 100644 (file)
@@ -15,7 +15,7 @@ public:
        SandboxEffect();
        std::string output_fragment_shader();
 
        SandboxEffect();
        std::string output_fragment_shader();
 
-       void set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
+       void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
 
 private:
        float parm;
 
 private:
        float parm;
index e6e7e7b380e138f221a2defc948f43e20664d3d0..b3a6c04ed6678b2e167c39aeaacd6319143256ba 100644 (file)
@@ -22,9 +22,9 @@ std::string VignetteEffect::output_fragment_shader()
        return read_file("vignette_effect.frag");
 }
 
        return read_file("vignette_effect.frag");
 }
 
-void VignetteEffect::set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
+void VignetteEffect::set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num)
 {
 {
-       Effect::set_uniforms(glsl_program_num, prefix, sampler_num);
+       Effect::set_gl_state(glsl_program_num, prefix, sampler_num);
 
        set_uniform_float(glsl_program_num, prefix, "inv_radius", 1.0f / radius);
 
 
        set_uniform_float(glsl_program_num, prefix, "inv_radius", 1.0f / radius);
 
index 2567e83c38844be7415a2428da01d1a4895dc93a..d7c66f63b0d4f2146972418169755e30f0810db7 100644 (file)
@@ -13,7 +13,7 @@ public:
 
        virtual bool needs_srgb_primaries() const { return false; }
 
 
        virtual bool needs_srgb_primaries() const { return false; }
 
-       void set_uniforms(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
+       void set_gl_state(GLuint glsl_program_num, const std::string &prefix, unsigned *sampler_num);
 
 private:
        Point2D center;
 
 private:
        Point2D center;