X-Git-Url: https://git.sesse.net/?p=movit;a=blobdiff_plain;f=effect_chain_test.cpp;h=673e9cc3665fd1acac09d9815eaa84947d416e22;hp=fed8b91b693f42ef6796307d3039d3d29d668663;hb=60e4852ff1b04c525a9e3f1c98a1017db28b27bd;hpb=85f9719bf3519b1f1942738d11601584f5d38725 diff --git a/effect_chain_test.cpp b/effect_chain_test.cpp index fed8b91..673e9cc 100644 --- a/effect_chain_test.cpp +++ b/effect_chain_test.cpp @@ -9,6 +9,7 @@ #include "effect_chain.h" #include "flat_input.h" #include "gtest/gtest.h" +#include "init.h" #include "input.h" #include "mirror_effect.h" #include "multiply_effect.h" @@ -18,6 +19,8 @@ using namespace std; +namespace movit { + TEST(EffectChainTest, EmptyChain) { float data[] = { 0.0f, 0.25f, 0.3f, @@ -220,7 +223,7 @@ private: GammaCurve overridden_gamma_curve; }; -TEST(EffectChainTester, HandlesInputChangingColorspace) { +TEST(EffectChainTest, HandlesInputChangingColorspace) { const int size = 4; float data[size] = { @@ -519,17 +522,27 @@ class MipmapNeedingEffect : public Effect { public: MipmapNeedingEffect() {} virtual bool needs_mipmaps() const { return true; } + + // To be allowed to mess with the sampler state. + virtual bool needs_texture_bounce() const { return true; } + virtual string effect_type_id() const { return "MipmapNeedingEffect"; } string output_fragment_shader() { return read_file("mipmap_needing_effect.frag"); } + virtual void inform_added(EffectChain *chain) { this->chain = chain; } + void set_gl_state(GLuint glsl_program_num, const string& prefix, unsigned *sampler_num) { - glActiveTexture(GL_TEXTURE0); + Node *self = chain->find_node_for_effect(this); + glActiveTexture(chain->get_input_sampler(self, 0)); check_error(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); check_error(); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); check_error(); } + +private: + EffectChain *chain; }; TEST(EffectChainTest, MipmapGenerationWorks) { @@ -957,8 +970,6 @@ TEST(EffectChainTest, VirtualSizeIsSentOnToInputs) { expect_equal(data, out_data, size, size); } -extern bool movit_initialized; - // Does not use EffectChainTest, so that it can construct an EffectChain without // a shared ResourcePool (which is also properly destroyed afterwards). // Also turns on debugging to test that code path. @@ -972,11 +983,10 @@ TEST(EffectChainTest, IdentityWithOwnPool) { 0.75f, 1.0f, 1.0f, 0.0f, 0.25f, 0.3f, }; - float out_data[6]; + float out_data[6], temp[6 * 4]; EffectChain chain(width, height); - movit_initialized = false; - init_movit(".", MOVIT_DEBUG_ON); + movit_debug_level = MOVIT_DEBUG_ON; ImageFormat format; format.color_space = COLORSPACE_sRGB; @@ -992,7 +1002,7 @@ TEST(EffectChainTest, IdentityWithOwnPool) { check_error(); glBindTexture(GL_TEXTURE_2D, texnum); check_error(); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, NULL); check_error(); glGenFramebuffers(1, &fbo); @@ -1014,11 +1024,17 @@ TEST(EffectChainTest, IdentityWithOwnPool) { chain.render_to_fbo(fbo, width, height); glBindFramebuffer(GL_FRAMEBUFFER, fbo); - glReadPixels(0, 0, width, height, GL_RED, GL_FLOAT, out_data); + check_error(); + glReadPixels(0, 0, width, height, GL_RGBA, GL_FLOAT, temp); + check_error(); + for (unsigned i = 0; i < 6; ++i) { + out_data[i] = temp[i * 4]; + } expect_equal(expected_data, out_data, width, height); // Reset the debug status again. - movit_initialized = false; - init_movit(".", MOVIT_DEBUG_OFF); + movit_debug_level = MOVIT_DEBUG_OFF; } + +} // namespace movit