X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect.cpp;h=384e8c2944e741ce53bade017d4e7b9064148228;hp=6f3121d8afa6e873012da7629aa68717a9827d4f;hb=a616ded3842994840ce0cfa365d259f602493779;hpb=ab636361e865c389fe60584562372ec39ac4c511 diff --git a/effect.cpp b/effect.cpp index 6f3121d..384e8c2 100644 --- a/effect.cpp +++ b/effect.cpp @@ -1,12 +1,12 @@ #include #include #include +#include + #include "effect.h" #include "effect_chain.h" #include "util.h" -#include "opengl.h" - GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key) { std::string name = prefix + "_" + key; @@ -35,47 +35,56 @@ void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const 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) +void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values) { GLint location = get_uniform_location(glsl_program_num, prefix, key); if (location == -1) { return; } check_error(); - glUniform1fv(location, num_values, values); + glUniform2fv(location, 1, values); check_error(); } -void set_uniform_vec2(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values) +void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values) { GLint location = get_uniform_location(glsl_program_num, prefix, key); if (location == -1) { return; } check_error(); - glUniform2fv(location, 1, values); + glUniform3fv(location, 1, values); check_error(); } -void set_uniform_vec3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const float *values) +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(); - glUniform3fv(location, 1, values); + glUniform4fv(location, num_values, 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) +void set_uniform_mat3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const Eigen::Matrix3d& matrix) { GLint location = get_uniform_location(glsl_program_num, prefix, key); if (location == -1) { return; } check_error(); - glUniform4fv(location, num_values, values); + + // Convert to float (GLSL has no double matrices). + float matrixf[9]; + for (unsigned y = 0; y < 3; ++y) { + for (unsigned x = 0; x < 3; ++x) { + matrixf[y + x * 3] = matrix(y, x); + } + } + + glUniformMatrix3fv(location, 1, GL_FALSE, matrixf); check_error(); } @@ -167,11 +176,6 @@ 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 &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