From: Steinar H. Gunderson Date: Sat, 2 Feb 2013 13:32:01 +0000 (+0100) Subject: Split out some private utilities into effect_util.cpp, so we do not need to include... X-Git-Tag: 1.0~138 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=ad66f9714e4a36008c341355700272a52484a785;ds=sidebyside Split out some private utilities into effect_util.cpp, so we do not need to include e.g. Eigen from effect.h. --- diff --git a/Makefile b/Makefile index cea2234..0d36c7e 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ TESTS += flat_input_test TESTS += ycbcr_input_test # Core. -LIB_OBJS=util.o widgets.o effect.o effect_chain.o init.o +LIB_OBJS=effect_util.o util.o widgets.o effect.o effect_chain.o init.o # Inputs. LIB_OBJS += flat_input.o diff --git a/blur_effect.cpp b/blur_effect.cpp index a74cd41..0ec1b1d 100644 --- a/blur_effect.cpp +++ b/blur_effect.cpp @@ -5,6 +5,7 @@ #include "blur_effect.h" #include "effect_chain.h" +#include "effect_util.h" #include "util.h" // Must match blur_effect.frag. diff --git a/colorspace_conversion_effect.h b/colorspace_conversion_effect.h index b1d6e06..93b1859 100644 --- a/colorspace_conversion_effect.h +++ b/colorspace_conversion_effect.h @@ -11,7 +11,6 @@ #include #include "effect.h" -#include "effect_chain.h" #include "image_format.h" class ColorspaceConversionEffect : public Effect { diff --git a/deconvolution_sharpen_effect.cpp b/deconvolution_sharpen_effect.cpp index 2602664..f3998d9 100644 --- a/deconvolution_sharpen_effect.cpp +++ b/deconvolution_sharpen_effect.cpp @@ -13,6 +13,7 @@ #include #include "deconvolution_sharpen_effect.h" +#include "effect_util.h" #include "util.h" using namespace Eigen; diff --git a/dither_effect.cpp b/dither_effect.cpp index 44933b6..1554356 100644 --- a/dither_effect.cpp +++ b/dither_effect.cpp @@ -3,6 +3,7 @@ #include #include "dither_effect.h" +#include "effect_util.h" #include "util.h" namespace { diff --git a/effect.cpp b/effect.cpp index 0fe09db..483828b 100644 --- a/effect.cpp +++ b/effect.cpp @@ -1,4 +1,3 @@ -#include #include #include #include @@ -6,100 +5,9 @@ #include #include "effect.h" +#include "effect_util.h" #include "util.h" -GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key) -{ - std::string name = prefix + "_" + key; - 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(location, value); - check_error(); -} - -void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value) -{ - GLint location = get_uniform_location(glsl_program_num, prefix, key); - if (location == -1) { - return; - } - check_error(); - glUniform1f(location, value); - check_error(); -} - -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(); - 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) -{ - GLint location = get_uniform_location(glsl_program_num, prefix, key); - if (location == -1) { - return; - } - check_error(); - glUniform3fv(location, 1, values); - check_error(); -} - -void set_uniform_vec4(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(); - glUniform4fv(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(); -} - -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(); - - // 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(); -} - bool Effect::set_int(const std::string &key, int value) { if (params_int.count(key) == 0) { diff --git a/effect.h b/effect.h index 826dd6f..65fdf52 100644 --- a/effect.h +++ b/effect.h @@ -13,10 +13,8 @@ #include #include #include -#include #include #include -#include #include "util.h" @@ -47,16 +45,6 @@ struct RGBATriplet { float r, g, b, a; }; -// Convenience functions that deal with prepending the prefix. -GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key); -void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value); -void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value); -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); -void set_uniform_vec4(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); -void set_uniform_mat3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const Eigen::Matrix3d &matrix); - class Effect { public: virtual ~Effect() {} diff --git a/effect_chain.h b/effect_chain.h index 2199a5d..ddabad9 100644 --- a/effect_chain.h +++ b/effect_chain.h @@ -8,12 +8,9 @@ #include #include -#include "effect.h" #include "image_format.h" -#include "input.h" class Effect; -class EffectChain; class Input; struct Phase; diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index 49d431b..442c2fb 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -4,7 +4,6 @@ #include #include -#include #include "effect.h" #include "effect_chain.h" diff --git a/effect_util.cpp b/effect_util.cpp new file mode 100644 index 0000000..e57a562 --- /dev/null +++ b/effect_util.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +#include "util.h" + +GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key) +{ + std::string name = prefix + "_" + key; + 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(location, value); + check_error(); +} + +void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value) +{ + GLint location = get_uniform_location(glsl_program_num, prefix, key); + if (location == -1) { + return; + } + check_error(); + glUniform1f(location, value); + check_error(); +} + +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(); + 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) +{ + GLint location = get_uniform_location(glsl_program_num, prefix, key); + if (location == -1) { + return; + } + check_error(); + glUniform3fv(location, 1, values); + check_error(); +} + +void set_uniform_vec4(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(); + glUniform4fv(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(); +} + +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(); + + // 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(); +} diff --git a/effect_util.h b/effect_util.h new file mode 100644 index 0000000..13a7754 --- /dev/null +++ b/effect_util.h @@ -0,0 +1,30 @@ +#ifndef _EFFECT_UTIL_H +#define _EFFECT_UTIL_H 1 + +// Utilities that are often useful for implementing Effect instances, +// but don't need to be included from effect.h. + +#include +#include +#include +#include +#include +#include +#include + +#include "util.h" + +class EffectChain; +class Node; + +// Convenience functions that deal with prepending the prefix. +GLint get_uniform_location(GLuint glsl_program_num, const std::string &prefix, const std::string &key); +void set_uniform_int(GLuint glsl_program_num, const std::string &prefix, const std::string &key, int value); +void set_uniform_float(GLuint glsl_program_num, const std::string &prefix, const std::string &key, float value); +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); +void set_uniform_vec4(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); +void set_uniform_mat3(GLuint glsl_program_num, const std::string &prefix, const std::string &key, const Eigen::Matrix3d &matrix); + +#endif // !defined(_EFFECT_UTIL_H) diff --git a/flat_input.cpp b/flat_input.cpp index 9cb9b9c..40fb733 100644 --- a/flat_input.cpp +++ b/flat_input.cpp @@ -2,6 +2,7 @@ #include #include +#include "effect_util.h" #include "flat_input.h" #include "util.h" diff --git a/gamma_compression_effect.h b/gamma_compression_effect.h index f34bca0..6727e6e 100644 --- a/gamma_compression_effect.h +++ b/gamma_compression_effect.h @@ -10,7 +10,6 @@ #include #include "effect.h" -#include "effect_chain.h" #include "image_format.h" #define COMPRESSION_CURVE_SIZE 4096 diff --git a/gamma_expansion_effect.h b/gamma_expansion_effect.h index 059b246..cc65e4f 100644 --- a/gamma_expansion_effect.h +++ b/gamma_expansion_effect.h @@ -10,7 +10,6 @@ #include #include "effect.h" -#include "effect_chain.h" #include "image_format.h" #define EXPANSION_CURVE_SIZE 256 diff --git a/lift_gamma_gain_effect.cpp b/lift_gamma_gain_effect.cpp index 3597e6c..f00da87 100644 --- a/lift_gamma_gain_effect.cpp +++ b/lift_gamma_gain_effect.cpp @@ -1,6 +1,7 @@ #include #include +#include "effect_util.h" #include "lift_gamma_gain_effect.h" #include "util.h" diff --git a/padding_effect.cpp b/padding_effect.cpp index f7f9707..40876b8 100644 --- a/padding_effect.cpp +++ b/padding_effect.cpp @@ -1,6 +1,7 @@ #include #include +#include "effect_util.h" #include "padding_effect.h" #include "util.h" diff --git a/resample_effect.cpp b/resample_effect.cpp index 264e5c1..f0c57c7 100644 --- a/resample_effect.cpp +++ b/resample_effect.cpp @@ -9,6 +9,7 @@ #include #include "effect_chain.h" +#include "effect_util.h" #include "resample_effect.h" #include "util.h" diff --git a/test_util.cpp b/test_util.cpp index 05b61af..190af95 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include "flat_input.h" #include "gtest/gtest.h" diff --git a/util.cpp b/util.cpp index a1bc2fd..a1fac6d 100644 --- a/util.cpp +++ b/util.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include diff --git a/vignette_effect.cpp b/vignette_effect.cpp index bbd61da..ac51977 100644 --- a/vignette_effect.cpp +++ b/vignette_effect.cpp @@ -1,6 +1,7 @@ #include #include +#include "effect_util.h" #include "vignette_effect.h" #include "util.h" diff --git a/white_balance_effect.cpp b/white_balance_effect.cpp index 1583922..56cd8c9 100644 --- a/white_balance_effect.cpp +++ b/white_balance_effect.cpp @@ -4,6 +4,7 @@ #include #include "d65.h" +#include "effect_util.h" #include "util.h" #include "white_balance_effect.h" diff --git a/ycbcr_input.cpp b/ycbcr_input.cpp index 3e691d8..4bc519c 100644 --- a/ycbcr_input.cpp +++ b/ycbcr_input.cpp @@ -5,6 +5,7 @@ #include #include +#include "effect_util.h" #include "util.h" #include "ycbcr_input.h"