]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipeline.cpp
Remove the deprecated ProgramBuilder class
[libs/gl.git] / source / pipeline.cpp
index ce9c8f689a0feecd55214590f2dff25c3851850a..a7f4130bbab1fffd2605521426f562dbf42a92bf 100644 (file)
@@ -9,20 +9,38 @@
 #include "renderer.h"
 #include "tests.h"
 #include "texture2d.h"
+#include "view.h"
 
 using namespace std;
 
 namespace Msp {
 namespace GL {
 
-Pipeline::Pipeline(unsigned w, unsigned h, bool d):
-       camera(0),
-       width(w),
-       height(h),
-       hdr(d),
-       samples(0),
-       target_ms(0)
+Pipeline::Pipeline(unsigned w, unsigned h, bool d)
 {
+       init(w, h);
+       hdr = d;
+}
+
+Pipeline::Pipeline(const View &view)
+{
+       init(view.get_width(), view.get_height());
+}
+
+Pipeline::Pipeline(const Framebuffer &fbo)
+{
+       init(fbo.get_width(), fbo.get_height());
+}
+
+void Pipeline::init(unsigned w, unsigned h)
+{
+       camera = 0;
+       width = w;
+       height = h;
+       hdr = false;
+       alpha = false;
+       samples = 0;
+       target_ms = 0;
        target[0] = 0;
        target[1] = 0;
 }
@@ -39,7 +57,7 @@ void Pipeline::set_hdr(bool h)
        if(h==hdr)
                return;
 
-       bool old_hdr= hdr;
+       bool old_hdr = hdr;
        hdr = h;
        try
        {
@@ -52,6 +70,24 @@ void Pipeline::set_hdr(bool h)
        }
 }
 
+void Pipeline::set_alpha(bool a)
+{
+       if(a==alpha)
+               return;
+
+       bool old_alpha = alpha;
+       alpha = a;
+       try
+       {
+               create_targets(2);
+       }
+       catch(...)
+       {
+               alpha = old_alpha;
+               throw;
+       }
+}
+
 void Pipeline::set_multisample(unsigned s)
 {
        if(s==samples)
@@ -70,61 +106,27 @@ void Pipeline::set_multisample(unsigned s)
        }
 }
 
-void Pipeline::set_camera(const Camera *c)
-{
-       camera = c;
-}
-
-Pipeline::Pass &Pipeline::add_pass(const Tag &tag)
+Pipeline::Pass &Pipeline::add_pass(const Tag &tag, Renderable &r)
 {
-       passes.push_back(Pass(tag, 0));
+       passes.push_back(Pass(tag, &r));
        return passes.back();
 }
 
-void Pipeline::add_renderable(Renderable &r)
-{
-       for(vector<Slot>::iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               if(i->renderable==&r)
-               {
-                       i->passes.clear();
-                       return;
-               }
-
-       renderables.push_back(&r);
-}
-
-void Pipeline::add_renderable_for_pass(Renderable &r, const Tag &tag)
-{
-       for(vector<Slot>::iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               if(i->renderable==&r)
-               {
-                       i->passes.insert(tag);
-                       return;
-               }
-
-       renderables.push_back(&r);
-       renderables.back().passes.insert(tag);
-}
-
-void Pipeline::remove_renderable(Renderable &r)
+void Pipeline::add_postprocessor(PostProcessor &pp)
 {
-       for(vector<Slot>::iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               if(i->renderable==&r)
-               {
-                       renderables.erase(i);
-                       return;
-               }
+       add_postprocessor(&pp, true);
 }
 
-Pipeline::Pass &Pipeline::add_pass(const Tag &tag, Renderable &r)
+void Pipeline::add_postprocessor_owned(PostProcessor *pp)
 {
-       passes.push_back(Pass(tag, &r));
-       return passes.back();
+       add_postprocessor(pp, false);
 }
 
-void Pipeline::add_postprocessor(PostProcessor &pp)
+void Pipeline::add_postprocessor(PostProcessor *pp, bool keep)
 {
-       postproc.push_back(&pp);
+       postproc.push_back(pp);
+       if(keep)
+               postproc.back().keep();
        try
        {
                create_targets(0);
@@ -136,39 +138,31 @@ void Pipeline::add_postprocessor(PostProcessor &pp)
        }
 }
 
-void Pipeline::setup_frame() const
+void Pipeline::setup_frame(Renderer &renderer)
 {
        for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i)
-               if(const Renderable *renderable = i->get_renderable())
-                       renderable->setup_frame();
+               if(Renderable *renderable = i->get_renderable())
+                       renderable->setup_frame(renderer);
        for(vector<Slot>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               i->renderable->setup_frame();
+               i->renderable->setup_frame(renderer);
 }
 
-void Pipeline::finish_frame() const
+void Pipeline::finish_frame()
 {
        for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i)
-               if(const Renderable *renderable = i->get_renderable())
+               if(Renderable *renderable = i->get_renderable())
                        renderable->finish_frame();
        for(vector<Slot>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
                i->renderable->finish_frame();
 }
 
-void Pipeline::render() const
-{
-       Renderer renderer(camera);
-       setup_frame();
-       render(renderer);
-       finish_frame();
-}
-
 void Pipeline::render(Renderer &renderer, const Tag &tag) const
 {
        if(tag.id)
                return;
 
        const Framebuffer *out_fbo = Framebuffer::current();
-       // These is a no-ops but will ensure the related state gets restored
+       // 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());
@@ -177,10 +171,9 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
        {
                Framebuffer &fbo = (samples ? target_ms : target[0])->get_framebuffer();
                fbo.bind();
-               fbo.clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
+               fbo.clear();
        }
 
-
        for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i)
        {
                if(const DepthTest *dt = i->get_depth_test())
@@ -241,7 +234,7 @@ void Pipeline::create_targets(unsigned recreate)
                target_ms = 0;
        }
 
-       PixelFormat color_pf = (hdr ? RGB16F : RGB);
+       PixelFormat color_pf = (hdr ? (alpha ? RGBA16F : RGB16F) : (alpha ? RGBA8 : RGB8));
        RenderTargetFormat fmt = (RENDER_COLOR,color_pf, RENDER_DEPTH);
        if(!postproc.empty() || samples)
        {