X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fpipeline.cpp;h=f05d15b8271fe0ce9f216b62258f50d10758f231;hb=4d3bee9264c4e60fb811019fc1699e17a338d13d;hp=0256850844fef66ebd3d32fb117d73d6be7d6dd0;hpb=8f2430208cfa7bb9dc5bd655dde88acc21db54d2;p=libs%2Fgl.git diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 02568508..f05d15b8 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -1,10 +1,11 @@ /* $Id$ This file is part of libmspgl -Copyright © 2009 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#include "blend.h" #include "camera.h" #include "effect.h" #include "except.h" @@ -13,6 +14,7 @@ Distributed under the LGPL #include "pipeline.h" #include "postprocessor.h" #include "renderbuffer.h" +#include "tests.h" #include "texture2d.h" using namespace std; @@ -47,14 +49,14 @@ PipelinePass &Pipeline::add_pass(const Tag &tag) if(passes.count(tag)) throw KeyError("Pass already exists"); - PipelinePass &pass=passes[tag]; + PipelinePass &pass = passes[tag]; pass_order.push_back(tag); return pass; } PipelinePass &Pipeline::get_pass(const Tag &tag) { - PassMap::iterator i=passes.find(tag); + PassMap::iterator i = passes.find(tag); if(i==passes.end()) throw KeyError("Unknown pass"); return i->second; @@ -62,7 +64,7 @@ PipelinePass &Pipeline::get_pass(const Tag &tag) const PipelinePass &Pipeline::get_pass(const Tag &tag) const { - PassMap::const_iterator i=passes.find(tag); + PassMap::const_iterator i = passes.find(tag); if(i==passes.end()) throw KeyError("Unknown pass"); return i->second; @@ -70,7 +72,37 @@ const PipelinePass &Pipeline::get_pass(const Tag &tag) const void Pipeline::add_renderable(const Renderable &r) { + for(vector::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::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::iterator i=renderables.begin(); i!=renderables.end(); ++i) + if(i->renderable==&r) + { + renderables.erase(i); + return; + } } void Pipeline::add_effect(Effect &e) @@ -83,33 +115,36 @@ void Pipeline::add_postprocessor(PostProcessor &pp) postproc.push_back(&pp); if(!fbo) { - fbo=new Framebuffer; - color_buf=new Texture2D; + fbo = new Framebuffer; + color_buf = new Texture2D; color_buf->set_min_filter(NEAREST); color_buf->set_mag_filter(NEAREST); color_buf->storage((hdr ? RGB16F : RGB), width, height, 0); color_buf->image(0, RGB, UNSIGNED_BYTE, 0); fbo->attach(COLOR_ATTACHMENT0, *color_buf, 0); - depth_buf=new Renderbuffer; + depth_buf = new Renderbuffer; depth_buf->storage(DEPTH_COMPONENT, width, height); fbo->attach(DEPTH_ATTACHMENT, *depth_buf); - Framebuffer::unbind(); } } void Pipeline::render(const Tag &tag) const { - const PipelinePass &pass=get_pass(tag); - if(pass.lighting) - pass.lighting->bind(); + const PipelinePass &pass = get_pass(tag); + + Bind bind_depth_test(pass.depth_test); + Bind bind_blend(pass.blend); + Bind bind_lighting(pass.lighting); + for(vector::const_iterator i=pass.effects.begin(); i!=pass.effects.end(); ++i) (*i)->prepare(); - for(vector::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) - (*i)->render(tag); - for(vector::const_iterator i=pass.effects.end(); i--!=pass.effects.begin();) - (*i)->cleanup(); - if(pass.lighting) - Lighting::unbind(); + + for(vector::const_iterator i=renderables.begin(); i!=renderables.end(); ++i) + if(i->passes.empty() || i->passes.count(tag)) + i->renderable->render(tag); + + for(vector::const_iterator i=pass.effects.end(); i!=pass.effects.begin();) + (*--i)->cleanup(); } void Pipeline::render_all() const @@ -120,15 +155,17 @@ void Pipeline::render_all() const if(fbo) { fbo->bind(); - clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); + fbo->clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT); } for(vector::const_iterator i=effects.begin(); i!=effects.end(); ++i) (*i)->prepare(); + for(vector::const_iterator i=pass_order.begin(); i!=pass_order.end(); ++i) render(*i); - for(vector::const_iterator i=effects.end(); i--!=effects.begin();) - (*i)->cleanup(); + + for(vector::const_iterator i=effects.end(); i!=effects.begin();) + (*--i)->cleanup(); if(fbo) Framebuffer::unbind(); @@ -138,5 +175,10 @@ void Pipeline::render_all() const (*i)->render(*color_buf); } + +Pipeline::Slot::Slot(const Renderable *r): + renderable(r) +{ } + } // namespace GL } // namespace Msp