]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipeline.cpp
Notify Renderables about the start and end of a frame
[libs/gl.git] / source / pipeline.cpp
index 2dd178f247a53b97d26f74bbfe526292e21ae4d2..466aa23c69b6b3107457817f8efea8f33aa829ac 100644 (file)
@@ -21,7 +21,8 @@ Pipeline::Pipeline(unsigned w, unsigned h, bool d):
        height(h),
        hdr(d),
        samples(0),
-       target_ms(0)
+       target_ms(0),
+       in_frame(false)
 {
        target[0] = 0;
        target[1] = 0;
@@ -98,6 +99,20 @@ void Pipeline::add_postprocessor(PostProcessor &pp)
        create_targets(false);
 }
 
+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)
@@ -112,6 +127,10 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
        if(tag.id)
                return;
 
+       bool was_in_frame = in_frame;
+       if(!in_frame)
+               setup_frame();
+
        if(target[0])
        {
                Framebuffer &fbo = (samples ? target_ms->fbo : target[0]->fbo);
@@ -148,6 +167,9 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
 
                Framebuffer::unbind();
        }
+
+       if(!was_in_frame)
+               finish_frame();
 }
 
 void Pipeline::create_targets(bool recreate)