Support rendering to a given FBO instead of to the screen.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Oct 2012 19:27:43 +0000 (21:27 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Fri, 12 Oct 2012 19:27:43 +0000 (21:27 +0200)
effect_chain.cpp
effect_chain.h

index b5d136b..c3776e8 100644 (file)
@@ -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(
index 1c50b16..989a019 100644 (file)
@@ -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()) {