]> git.tdb.fi Git - libs/gl.git/blobdiff - source/render/sequence.cpp
Remove obsolete stuff from Sequence
[libs/gl.git] / source / render / sequence.cpp
index 06b1403bd827e934400a550cd29f2bcef919e64b..e6dafa0e91b4bd507bebea79a5906b1d0ea12dc2 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;
@@ -160,32 +156,26 @@ 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);
-       BindRestore restore_depth_test(DepthTest::current());
-       BindRestore restore_blend(Blend::current());
+       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)
        {
-               if(const DepthTest *dt = i->get_depth_test())
-                       dt->bind();
-               else
-                       DepthTest::unbind();
+               Renderer::Push _push2(renderer);
 
-               if(const Blend *b = i->get_blend())
-                       b->bind();
-               else
-                       Blend::unbind();
+               renderer.set_depth_test(&i->get_depth_test());
+               renderer.set_stencil_test(&i->get_stencil_test());
+               renderer.set_blend(&i->get_blend());
 
-               renderer.set_lighting(i->get_lighting());
+               if (const Lighting *lighting = i->get_lighting())
+                       renderer.add_shader_data(lighting->get_shader_data());
                renderer.set_clipping(i->get_clipping());
 
                if(const Renderable *renderable = i->get_renderable())
@@ -194,21 +184,19 @@ void Sequence::render(Renderer &renderer, Tag tag) const
 
        if(target[0])
        {
-               DepthTest::unbind();
-               Blend::unbind();
-
                if(samples)
-                       target[0]->blit_from(*target_ms);
+                       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);
 
                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);
                }
        }
@@ -230,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])
@@ -240,15 +228,40 @@ 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())
+               set_target_debug_names();
+#endif
+}
+
+void Sequence::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+       debug_name = name;
+       if(!name.empty())
+               set_target_debug_names();
+#else
+       (void)name;
+#endif
+}
+
+void Sequence::set_target_debug_names()
+{
+#ifdef DEBUG
+       for(unsigned i=0; i<2; ++i)
+               if(target[i])
+                       target[i]->set_debug_name(format("%s [RT:%d]", debug_name, i));
+       if(target_ms)
+               target_ms->set_debug_name(debug_name+" [RT:ms]");
+#endif
 }
 
 
 Sequence::Step::Step(Tag t, Renderable *r):
        tag(t),
        lighting(0),
-       depth_test(0),
-       blend(0),
        clipping(0),
        renderable(r)
 { }
@@ -258,19 +271,24 @@ void Sequence::Step::set_lighting(const Lighting *l)
        lighting = l;
 }
 
-void Sequence::Step::set_depth_test(const DepthTest *d)
+void Sequence::Step::set_depth_test(const DepthTest &dt)
+{
+       depth_test = dt;
+}
+
+void Sequence::Step::set_stencil_test(const StencilTest &st)
 {
-       depth_test = d;
+       stencil_test = st;
 }
 
-void Sequence::Step::set_blend(const Blend *b)
+void Sequence::Step::set_blend(const Blend &b)
 {
        blend = b;
 }
 
 void Sequence::Step::set_clipping(const Clipping *c)
 {
-       clipping =c;
+       clipping = c;
 }
 
 } // namespace GL