X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect.cpp;h=74bd939f3f1e811303519e4aaf5d5ed2dac615bb;hp=7f8dda2de1d76a1a57ec54bf06b10191bec62805;hb=0de0202b22a6349d0f9c838947a96eef8155ac90;hpb=879854382e1f6db14812cd6bd5390ca01f4b1d5a diff --git a/effect.cpp b/effect.cpp index 7f8dda2..74bd939 100644 --- a/effect.cpp +++ b/effect.cpp @@ -1,5 +1,3 @@ -#define GL_GLEXT_PROTOTYPES 1 - #include #include #include @@ -7,8 +5,7 @@ #include "effect_chain.h" #include "util.h" -#include -#include +#include "opengl.h" GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key) { @@ -82,6 +79,24 @@ void set_uniform_vec4_array(GLuint glsl_program_num, const std::string &prefix, check_error(); } +void set_uniform_mat3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const Matrix3x3 matrix) +{ + GLint location = get_uniform_location(glsl_program_num, prefix, key); + if (location == -1) { + return; + } + check_error(); + + // Convert to float (GLSL has no double matrices). + float matrixf[9]; + for (unsigned i = 0; i < 9; ++i) { + matrixf[i] = matrix[i]; + } + + glUniformMatrix3fv(location, 1, GL_FALSE, matrixf); + check_error(); +} + bool Effect::set_int(const std::string &key, int value) { if (params_int.count(key) == 0) { @@ -170,11 +185,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, Effect *input) -{ - chain->add_effect_raw(this, input); -} - // Output convenience uniforms for each parameter. // These will be filled in per-frame. std::string Effect::output_convenience_uniforms() const @@ -211,7 +221,7 @@ std::string Effect::output_convenience_uniforms() const 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::const_iterator it = params_float.begin(); it != params_float.end(); @@ -229,7 +239,7 @@ void Effect::set_uniforms(GLuint glsl_program_num, const std::string& prefix, un set_uniform_vec3(glsl_program_num, prefix, it->first, it->second); } - for (std::map::const_iterator it = params_tex_1d.begin(); + for (std::map::iterator it = params_tex_1d.begin(); it != params_tex_1d.end(); ++it) { glActiveTexture(GL_TEXTURE0 + *sampler_num); @@ -240,9 +250,12 @@ void Effect::set_uniforms(GLuint glsl_program_num, const std::string& prefix, un if (it->second.needs_update) { glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE16F_ARB, it->second.size, 0, GL_LUMINANCE, GL_FLOAT, it->second.values); check_error(); + it->second.needs_update = false; } set_uniform_int(glsl_program_num, prefix, it->first, *sampler_num); ++*sampler_num; } } + +void Effect::clear_gl_state() {}