From 1a595d0396e943d09a1459707785d66406deb354 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 12 Oct 2012 22:04:48 +0200 Subject: [PATCH] Make unit tests render to a floating-point FBO, so that we get full precision. --- test_util.cpp | 25 +++++++++++++++++++++++-- test_util.h | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test_util.cpp b/test_util.cpp index 8fa6714..4e37cec 100644 --- a/test_util.cpp +++ b/test_util.cpp @@ -11,6 +11,27 @@ EffectChainTester::EffectChainTester(const float *data, unsigned width, unsigned : 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) @@ -33,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. diff --git a/test_util.h b/test_util.h index 0c2e7b9..ab52c63 100644 --- a/test_util.h +++ b/test_util.h @@ -12,6 +12,7 @@ public: private: EffectChain chain; + GLuint fbo, texnum; unsigned width, height; }; -- 2.39.2