]> git.sesse.net Git - movit/blobdiff - effect.cpp
Add a diffusion effect, and hook it up in the GUI.
[movit] / effect.cpp
index 4cc1775d75587305e4504fdf0a534c78d73ec817..1aa37781525f1f7454f656e0c05161ddce9f82e1 100644 (file)
@@ -4,68 +4,81 @@
 #include <string.h>
 #include <assert.h>
 #include "effect.h"
+#include "effect_chain.h"
 #include "util.h"
 
 #include <GL/gl.h>
 #include <GL/glext.h>
 
-void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value)
+GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key)
 {
        std::string name = prefix + "_" + key;
-       GLint l = glGetUniformLocation(glsl_program_num, name.c_str());
-       if (l == -1) {
+       return glGetUniformLocation(glsl_program_num, name.c_str());
+}
+
+void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value)
+{
+       GLint location = get_uniform_location(glsl_program_num, prefix, key);
+       if (location == -1) {
                return;
        }
        check_error();
-       glUniform1i(l, value);
+       glUniform1i(location, value);
        check_error();
 }
 
 void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value)
 {
-       std::string name = prefix + "_" + key;
-       GLint l = glGetUniformLocation(glsl_program_num, name.c_str());
-       if (l == -1) {
+       GLint location = get_uniform_location(glsl_program_num, prefix, key);
+       if (location == -1) {
                return;
        }
        check_error();
-       glUniform1f(l, value);
+       glUniform1f(location, value);
        check_error();
 }
 
 void set_uniform_float_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values)
 {
-       std::string name = prefix + "_" + key;
-       GLint l = glGetUniformLocation(glsl_program_num, name.c_str());
-       if (l == -1) {
+       GLint location = get_uniform_location(glsl_program_num, prefix, key);
+       if (location == -1) {
                return;
        }
        check_error();
-       glUniform1fv(l, num_values, values);
+       glUniform1fv(location, num_values, values);
        check_error();
 }
 
 void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
 {
-       std::string name = prefix + "_" + key;
-       GLint l = glGetUniformLocation(glsl_program_num, name.c_str());
-       if (l == -1) {
+       GLint location = get_uniform_location(glsl_program_num, prefix, key);
+       if (location == -1) {
                return;
        }
        check_error();
-       glUniform2fv(l, 1, values);
+       glUniform2fv(location, 1, values);
        check_error();
 }
 
 void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values)
 {
-       std::string name = prefix + "_" + key;
-       GLint l = glGetUniformLocation(glsl_program_num, name.c_str());
-       if (l == -1) {
+       GLint location = get_uniform_location(glsl_program_num, prefix, key);
+       if (location == -1) {
                return;
        }
        check_error();
-       glUniform3fv(l, 1, values);
+       glUniform3fv(location, 1, values);
+       check_error();
+}
+
+void set_uniform_vec4_array(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values, size_t num_values)
+{
+       GLint location = get_uniform_location(glsl_program_num, prefix, key);
+       if (location == -1) {
+               return;
+       }
+       check_error();
+       glUniform4fv(location, num_values, values);
        check_error();
 }
 
@@ -157,6 +170,11 @@ void Effect::invalidate_1d_texture(const std::string &key)
        params_tex_1d[key].needs_update = true;
 }
 
+void Effect::add_self_to_effect_chain(EffectChain *chain, const std::vector<Effect *> &inputs)
+{
+       chain->add_effect_raw(this, inputs);
+}
+
 // Output convenience uniforms for each parameter.
 // These will be filled in per-frame.
 std::string Effect::output_convenience_uniforms() const