- for(vector<Effect *>::const_iterator i=effects.begin(); i!=effects.end(); ++i)
- (*i)->prepare();
- for(vector<Tag>::const_iterator i=pass_order.begin(); i!=pass_order.end(); ++i)
- render(*i);
- for(vector<Effect *>::const_iterator i=effects.end(); i--!=effects.begin();)
- (*i)->cleanup();
- if(fbo)
- Framebuffer::unbind();
- // XXX Need two color buffer textures to handle multiple post-processors correctly
- for(vector<PostProcessor *>::const_iterator i=postproc.begin(); i!=postproc.end(); ++i)
- (*i)->render(*color_buf);
+
+ for(PassList::const_iterator i=passes.begin(); i!=passes.end(); ++i)
+ {
+ if(const DepthTest *dt = i->get_depth_test())
+ dt->bind();
+ else
+ DepthTest::unbind();
+
+ if(const Blend *b = i->get_blend())
+ b->bind();
+ else
+ Blend::unbind();
+
+ renderer.set_lighting(i->get_lighting());
+ renderer.set_clipping(i->get_clipping());
+
+ if(const Renderable *renderable = i->get_renderable())
+ renderer.render(*renderable, i->get_tag());
+
+ 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])
+ {
+ DepthTest::unbind();
+ Blend::unbind();
+
+ 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);
+ postproc[i]->render(renderer, color, depth);
+ }
+ }
+}
+
+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 color_pf = (hdr ? (alpha ? RGBA16F : RGB16F) : (alpha ? RGBA : RGB));
+ RenderTargetFormat fmt = (RENDER_COLOR,color_pf, RENDER_DEPTH);
+ 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 RenderTarget(width, height, samples, fmt);
+}
+
+
+Pipeline::Pass::Pass(const Tag &t, Renderable *r):
+ tag(t),
+ lighting(0),
+ depth_test(0),
+ blend(0),
+ clipping(0),
+ renderable(r)
+{ }
+
+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;
+}
+
+void Pipeline::Pass::set_clipping(const Clipping *c)
+{
+ clipping =c;