]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/sequence.cpp
Fix a logic error in Sequence
[libs/gl.git] / source / render / sequence.cpp
index 2c32db86518b14033c9452a64be2ed0fb0106397..9a50b8f6f405648ff7b857af03f394b4a85d2eb7 100644 (file)
@@ -1,13 +1,10 @@
 #include <msp/core/maputils.h>
 #include "blend.h"
-#include "camera.h"
 #include "framebuffer.h"
 #include "lighting.h"
 #include "postprocessor.h"
-#include "renderbuffer.h"
 #include "renderer.h"
 #include "sequence.h"
-#include "tests.h"
 #include "texture2d.h"
 #include "view.h"
 
@@ -34,7 +31,6 @@ Sequence::Sequence(const Framebuffer &fbo)
 
 void Sequence::init(unsigned w, unsigned h)
 {
-       camera = 0;
        width = w;
        height = h;
        hdr = false;
@@ -134,7 +130,7 @@ void Sequence::add_postprocessor(PostProcessor *pp, bool owned)
        }
        catch(...)
        {
-               if(!owned)
+               if(owned)
                        delete pp;
                postproc.pop_back();
                throw;
@@ -160,20 +156,19 @@ void Sequence::render(Renderer &renderer, Tag tag) const
        if(tag.id)
                return;
 
-       const Framebuffer *out_fbo = Framebuffer::current();
-       // These are no-ops but will ensure the related state gets restored
-       BindRestore restore_fbo(out_fbo);
+       Renderer::Push _push(renderer);
+
+       const Framebuffer *out_fbo = renderer.get_framebuffer();
 
        if(target[0])
        {
-               Framebuffer &fbo = (samples ? target_ms : target[0])->get_framebuffer();
-               fbo.bind();
-               fbo.clear();
+               renderer.set_framebuffer(&(samples ? target_ms : target[0])->get_framebuffer());
+               renderer.clear();
        }
 
        for(vector<Step>::const_iterator i=steps.begin(); i!=steps.end(); ++i)
        {
-               Renderer::Push push(renderer);
+               Renderer::Push _push2(renderer);
 
                renderer.set_depth_test(&i->get_depth_test());
                renderer.set_stencil_test(&i->get_stencil_test());
@@ -189,22 +184,19 @@ void Sequence::render(Renderer &renderer, Tag tag) const
 
        if(target[0])
        {
+               if(samples)
+                       renderer.resolve_multisample(target[0]->get_framebuffer(), COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
+
                renderer.set_depth_test(0);
                renderer.set_stencil_test(0);
                renderer.set_blend(0);
 
-               if(samples)
-                       target[0]->blit_from(*target_ms);
-
                for(unsigned i=0; i<postproc.size(); ++i)
                {
                        unsigned j = i%2;
-                       if(i+1<postproc.size())
-                               target[1-j]->get_framebuffer().bind();
-                       else
-                               out_fbo->bind();
-                       const Texture2D &color = target[j]->get_target_texture(RENDER_COLOR);
-                       const Texture2D &depth = target[j]->get_target_texture(RENDER_DEPTH);
+                       renderer.set_framebuffer(i+1<postproc.size() ? &target[1-j]->get_framebuffer() : out_fbo);
+                       const Texture2D &color = target[j]->get_target_texture(COLOR_ATTACHMENT);
+                       const Texture2D &depth = target[j]->get_target_texture(DEPTH_ATTACHMENT);
                        postproc[i].postproc->render(renderer, color, depth);
                }
        }
@@ -226,7 +218,7 @@ void Sequence::create_targets(unsigned recreate)
        }
 
        PixelFormat color_pf = (hdr ? (alpha ? RGBA16F : RGB16F) : (alpha ? RGBA8 : RGB8));
-       RenderTargetFormat fmt = (RENDER_COLOR,color_pf, RENDER_DEPTH);
+       FrameFormat fmt = (COLOR_ATTACHMENT,color_pf, DEPTH_ATTACHMENT);
        if(!postproc.empty() || samples)
        {
                if(!target[0])
@@ -236,7 +228,7 @@ void Sequence::create_targets(unsigned recreate)
        }
 
        if(!target_ms && samples)
-               target_ms = new RenderTarget(width, height, samples, fmt);
+               target_ms = new RenderTarget(width, height, fmt.set_samples(samples));
 
 #ifdef DEBUG
        if(!debug_name.empty())
@@ -296,7 +288,7 @@ void Sequence::Step::set_blend(const Blend &b)
 
 void Sequence::Step::set_clipping(const Clipping *c)
 {
-       clipping =c;
+       clipping = c;
 }
 
 } // namespace GL