]> git.sesse.net Git - movit/blobdiff - test_util.cpp
Now that we render to an FBO, we can do with a much smaller window for the test.
[movit] / test_util.cpp
index a52eb797782fbad2f0f4aae297d2248322903a75..c8337d279966e5f0552530fd3107765f5835cb71 100644 (file)
@@ -9,6 +9,32 @@
 
 EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned height, ColorSpace color_space, GammaCurve gamma_curve)
        : chain(width, height), width(width), height(height)
+{
+       add_input(data, color_space, gamma_curve);
+
+       glGenTextures(1, &texnum);
+       check_error();
+       glBindTexture(GL_TEXTURE_2D, texnum);
+       check_error();
+       glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+       check_error();
+
+       glGenFramebuffers(1, &fbo);
+       check_error();
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+       check_error();
+       glFramebufferTexture2D(
+               GL_FRAMEBUFFER,
+               GL_COLOR_ATTACHMENT0,
+               GL_TEXTURE_2D,
+               texnum,
+               0);
+       check_error();
+       glBindFramebuffer(GL_FRAMEBUFFER, 0);
+       check_error();
+}
+
+Input *EffectChainTester::add_input(const float *data, ColorSpace color_space, GammaCurve gamma_curve)
 {
        ImageFormat format;
        format.color_space = color_space;
@@ -17,6 +43,7 @@ EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned
        FlatInput *input = new FlatInput(format, FORMAT_GRAYSCALE, GL_FLOAT, width, height);
        input->set_pixel_data(data);
        chain.add_input(input);
+       return input;
 }
 
 void EffectChainTester::run(float *out_data, ColorSpace color_space, GammaCurve gamma_curve)
@@ -27,9 +54,9 @@ void EffectChainTester::run(float *out_data, ColorSpace color_space, GammaCurve
        chain.add_output(format);
        chain.finalize();
 
-       glViewport(0, 0, width, height);
-       chain.render_to_screen();
+       chain.render_to_fbo(fbo, width, height);
 
+       glBindFramebuffer(GL_FRAMEBUFFER, fbo);
        glReadPixels(0, 0, width, height, GL_RED, GL_FLOAT, out_data);
 
        // Flip upside-down to compensate for different origin.
@@ -55,7 +82,7 @@ void expect_equal(const float *ref, const float *result, unsigned width, unsigne
        }
 
        const float largest_difference_limit = 1.5 / 255.0;
-       const float rms_limit = 0.5 / 255.0;
+       const float rms_limit = 0.2 / 255.0;
 
        EXPECT_LT(largest_difference, largest_difference_limit);