Pipeline::Pass &Pipeline::add_pass(const Tag &tag)
{
- Pass &pass = insert_unique(passes, tag, Pass())->second;
- pass_order.push_back(tag);
- return pass;
-}
-
-Pipeline::Pass &Pipeline::get_pass(const Tag &tag)
-{
- return get_item(passes, tag);
-}
-
-const Pipeline::Pass &Pipeline::get_pass(const Tag &tag) const
-{
- return get_item(passes, tag);
+ passes.push_back(Pass(tag));
+ return passes.back();
}
void Pipeline::add_renderable(const Renderable &r)
}
}
-void Pipeline::render(Renderer &renderer, const Tag &tag) const
+void Pipeline::render(const Tag &tag) const
{
- const Pass &pass = get_pass(tag);
+ if(tag.id)
+ return;
- Bind bind_depth_test(pass.get_depth_test());
- Bind bind_blend(pass.get_blend());
- Bind bind_lighting(pass.get_lighting());
-
- for(vector<Slot>::const_iterator i=renderables.begin(); i!=renderables.end(); ++i)
- if(i->passes.empty() || i->passes.count(tag))
- i->renderable->render(renderer, tag);
+ Renderer renderer(camera);
+ render(renderer, tag);
}
-void Pipeline::render_all() const
+void Pipeline::render(Renderer &renderer, const Tag &tag) const
{
- if(camera)
- camera->apply();
+ if(tag.id)
+ return;
if(fbo)
{
Framebuffer *f = (fbo_ms ? fbo_ms : fbo);
+ // XXX exception safety
f->bind();
f->clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
}
- Renderer renderer(camera);
- for(vector<Tag>::const_iterator i=pass_order.begin(); i!=pass_order.end(); ++i)
- render(renderer, *i);
+ 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());
+ Bind bind_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()))
+ j->renderable->render(renderer, i->get_tag());
+ }
if(fbo)
{
}
-Pipeline::Pass::Pass():
+Pipeline::Pass::Pass(const Tag &t):
+ tag(t),
lighting(0),
depth_test(0),
blend(0)
class Pass
{
private:
+ Tag tag;
const Lighting *lighting;
const DepthTest *depth_test;
const Blend *blend;
public:
- Pass();
+ Pass(const Tag &);
+
+ const Tag &get_tag() const { return tag; }
void set_lighting(const Lighting *);
void set_depth_test(const DepthTest *);
Slot(const Renderable *);
};
- typedef std::map<Tag, Pass> PassMap;
+ typedef std::list<Pass> PassList;
- PassMap passes;
- std::vector<Tag> pass_order;
+ PassList passes;
const Camera *camera;
std::vector<Slot> renderables;
std::vector<PostProcessor *> postproc;
void set_camera(const Camera *);
Pass &add_pass(const Tag &tag);
- Pass &get_pass(const Tag &tag);
- const Pass &get_pass(const Tag &tag) const;
void add_renderable(const Renderable &);
void add_renderable_for_pass(const Renderable &, const Tag &);
void remove_renderable(const Renderable &);
void add_postprocessor(PostProcessor &);
+ virtual void render(const Tag &tag = Tag()) const;
virtual void render(Renderer &, const Tag &tag = Tag()) const;
- void render_all() const;
private:
void create_fbos();