]> git.tdb.fi Git - libs/gl.git/blobdiff - source/pipeline.cpp
Add a RenderTarget class to manage and annotate FBOs
[libs/gl.git] / source / pipeline.cpp
index e468825748a640ed53cab215c6fc0ebee8c14fb3..a5d7436aaace7cd48074d6c6c02a9ecefda94948 100644 (file)
@@ -183,7 +183,7 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
 
        if(target[0])
        {
-               Framebuffer &fbo = (samples ? target_ms->fbo : target[0]->fbo);
+               Framebuffer &fbo = (samples ? target_ms : target[0])->get_framebuffer();
                fbo.bind();
                fbo.clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
        }
@@ -218,16 +218,18 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
                Blend::unbind();
 
                if(samples)
-                       target[0]->fbo.blit_from(target_ms->fbo, COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT, false);
+                       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]->fbo.bind();
+                               target[1-j]->get_framebuffer().bind();
                        else
                                out_fbo->bind();
-                       postproc[i]->render(renderer, target[j]->color, target[j]->depth);
+                       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);
                }
        }
 
@@ -250,7 +252,8 @@ void Pipeline::create_targets(unsigned recreate)
                target_ms = 0;
        }
 
-       PixelFormat fmt = (hdr ? RGB16F : RGB);
+       PixelFormat color_pf = (hdr ? RGB16F : RGB);
+       RenderTargetFormat fmt = (RENDER_COLOR,color_pf, RENDER_DEPTH);
        if(!postproc.empty() || samples)
        {
                if(!target[0])
@@ -260,7 +263,7 @@ void Pipeline::create_targets(unsigned recreate)
        }
 
        if(!target_ms && samples)
-               target_ms = new MultisampleTarget(width, height, samples, fmt);
+               target_ms = new RenderTarget(width, height, samples, fmt);
 }
 
 
@@ -298,35 +301,5 @@ 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