From b8b7f286300668679e61a25beb48f353b5a83f43 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 12 Oct 2012 21:27:43 +0200 Subject: [PATCH] Support rendering to a given FBO instead of to the screen. --- effect_chain.cpp | 20 ++++++++++++++------ effect_chain.h | 9 ++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/effect_chain.cpp b/effect_chain.cpp index b5d136b..c3776e8 100644 --- a/effect_chain.cpp +++ b/effect_chain.cpp @@ -961,13 +961,21 @@ void EffectChain::finalize() finalized = true; } -void EffectChain::render_to_screen() +void EffectChain::render_to_fbo(GLuint fbo, unsigned width, unsigned height) { assert(finalized); // Save original viewport. - GLint viewport[4]; - glGetIntegerv(GL_VIEWPORT, viewport); + GLuint x = 0, y = 0; + + if (width == 0 && height == 0) { + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + x = viewport[0]; + y = viewport[1]; + width = viewport[2]; + height = viewport[3]; + } // Basic state. glDisable(GL_BLEND); @@ -1045,10 +1053,10 @@ void EffectChain::render_to_screen() // And now the output. if (phase == phases.size() - 1) { - // Last phase goes directly to the screen. - glBindFramebuffer(GL_FRAMEBUFFER, 0); + // Last phase goes to the output the user specified. + glBindFramebuffer(GL_FRAMEBUFFER, fbo); check_error(); - glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); + glViewport(x, y, width, height); } else { Node *output_node = phases[phase]->effects.back(); glFramebufferTexture2D( diff --git a/effect_chain.h b/effect_chain.h index 1c50b16..989a019 100644 --- a/effect_chain.h +++ b/effect_chain.h @@ -92,7 +92,14 @@ public: void finalize(); //void render(unsigned char *src, unsigned char *dst); - void render_to_screen(); + void render_to_screen() + { + render_to_fbo(0, 0, 0); + } + + // Render the effect chain to the given FBO. If width=height=0, keeps + // the current viewport. + void render_to_fbo(GLuint fbo, unsigned width, unsigned height); Effect *last_added_effect() { if (nodes.empty()) { -- 2.39.2