]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipeline.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / pipeline.cpp
diff --git a/source/pipeline.cpp b/source/pipeline.cpp
deleted file mode 100644 (file)
index d7e175d..0000000
+++ /dev/null
@@ -1,281 +0,0 @@
-#include <msp/core/maputils.h>
-#include "blend.h"
-#include "camera.h"
-#include "framebuffer.h"
-#include "lighting.h"
-#include "pipeline.h"
-#include "postprocessor.h"
-#include "renderbuffer.h"
-#include "renderer.h"
-#include "tests.h"
-#include "texture2d.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),
-       in_frame(false)
-{
-       target[0] = 0;
-       target[1] = 0;
-}
-
-Pipeline::~Pipeline()
-{
-       delete target[0];
-       delete target[1];
-       delete target_ms;
-}
-
-void Pipeline::set_hdr(bool h)
-{
-       if(h==hdr)
-               return;
-
-       hdr = h;
-       create_targets(2);
-}
-
-void Pipeline::set_multisample(unsigned s)
-{
-       if(s==samples)
-               return;
-
-       unsigned old_samples = samples;
-       samples = s;
-       try
-       {
-               create_targets(1);
-       }
-       catch(...)
-       {
-               samples = old_samples;
-               throw;
-       }
-}
-
-void Pipeline::set_camera(const Camera *c)
-{
-       camera = c;
-}
-
-Pipeline::Pass &Pipeline::add_pass(const Tag &tag)
-{
-       passes.push_back(Pass(tag));
-       return passes.back();
-}
-
-void Pipeline::add_renderable(const 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(const 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(const Renderable &r)
-{
-       for(vector<Slot>::iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               if(i->renderable==&r)
-               {
-                       renderables.erase(i);
-                       return;
-               }
-}
-
-void Pipeline::add_postprocessor(PostProcessor &pp)
-{
-       postproc.push_back(&pp);
-       create_targets(0);
-}
-
-void Pipeline::setup_frame() const
-{
-       in_frame = true;
-       for(vector<Slot>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               i->renderable->setup_frame();
-}
-
-void Pipeline::finish_frame() const
-{
-       in_frame = false;
-       for(vector<Slot>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
-               i->renderable->finish_frame();
-}
-
-void Pipeline::render(const Tag &tag) const
-{
-       if(tag.id)
-               return;
-
-       Renderer renderer(camera);
-       render(renderer, tag);
-}
-
-void Pipeline::render(Renderer &renderer, const Tag &tag) const
-{
-       if(tag.id)
-               return;
-
-       bool was_in_frame = in_frame;
-       if(!in_frame)
-               setup_frame();
-
-       const Framebuffer *out_fbo = Framebuffer::current();
-       /* Binding the current object is a no-op, but this will restore the original
-       FBO in case an exception is thrown. */
-       Bind restore_fbo(out_fbo, true);
-
-       if(target[0])
-       {
-               Framebuffer &fbo = (samples ? target_ms->fbo : target[0]->fbo);
-               fbo.bind();
-               fbo.clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
-       }
-
-       for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i)
-       {
-               Bind bind_depth_test(i->get_depth_test());
-               Bind bind_blend(i->get_blend());
-               renderer.set_lighting(i->get_lighting());
-
-               for(vector<Slot>::const_iterator j=renderables.begin(); j!=renderables.end(); ++j)
-                       if(j->passes.empty() || j->passes.count(i->get_tag()))
-                               renderer.render(*j->renderable, i->get_tag());
-       }
-
-       if(target[0])
-       {
-               if(samples)
-                       target[0]->fbo.blit_from(target_ms->fbo, COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT, false);
-
-               for(unsigned i=0; i<postproc.size(); ++i)
-               {
-                       unsigned j = i%2;
-                       if(i+1<postproc.size())
-                               target[1-j]->fbo.bind();
-                       else
-                               out_fbo->bind();
-                       postproc[i]->render(target[j]->color, target[j]->depth);
-               }
-
-               out_fbo->bind();
-       }
-
-       if(!was_in_frame)
-               finish_frame();
-}
-
-void Pipeline::create_targets(unsigned recreate)
-{
-       if(recreate>=2)
-       {
-               delete target[0];
-               delete target[1];
-               target[0] = 0;
-               target[1] = 0;
-       }
-       if(recreate>=1)
-       {
-               delete target_ms;
-               target_ms = 0;
-       }
-
-       PixelFormat fmt = (hdr ? RGB16F : RGB);
-       if(!postproc.empty() || samples)
-       {
-               if(!target[0])
-                       target[0] = new RenderTarget(width, height, fmt);
-               if(!target[1] && postproc.size()>1)
-                       target[1] = new RenderTarget(width, height, fmt);
-       }
-
-       if(!target_ms && samples)
-               target_ms = new MultisampleTarget(width, height, samples, fmt);
-}
-
-
-Pipeline::Pass::Pass(const Tag &t):
-       tag(t),
-       lighting(0),
-       depth_test(0),
-       blend(0)
-{ }
-
-void Pipeline::Pass::set_lighting(const Lighting *l)
-{
-       lighting = l;
-}
-
-void Pipeline::Pass::set_depth_test(const DepthTest *d)
-{
-       depth_test = d;
-}
-
-void Pipeline::Pass::set_blend(const Blend *b)
-{
-       blend = b;
-}
-
-
-Pipeline::Slot::Slot(const Renderable *r):
-       renderable(r)
-{ }
-
-
-Pipeline::RenderTarget::RenderTarget(unsigned w, unsigned h, PixelFormat f)
-{
-       color.set_min_filter(NEAREST);
-       color.set_mag_filter(NEAREST);
-       color.set_wrap(CLAMP_TO_EDGE);
-       color.storage(f, w, h);
-       fbo.attach(COLOR_ATTACHMENT0, color, 0);
-
-       depth.set_min_filter(NEAREST);
-       depth.set_mag_filter(NEAREST);
-       depth.set_wrap(CLAMP_TO_EDGE);
-       depth.storage(DEPTH_COMPONENT, w, h);
-       fbo.attach(DEPTH_ATTACHMENT, depth, 0);
-
-       fbo.require_complete();
-}
-
-
-Pipeline::MultisampleTarget::MultisampleTarget(unsigned w, unsigned h, unsigned s, PixelFormat f)
-{
-       color.storage_multisample(s, f, w, h);
-       fbo.attach(COLOR_ATTACHMENT0, color);
-
-       depth.storage_multisample(s, DEPTH_COMPONENT, w, h);
-       fbo.attach(DEPTH_ATTACHMENT, depth);
-
-       fbo.require_complete();
-}
-
-} // namespace GL
-} // namespace Msp