]> git.tdb.fi Git - libs/gl.git/commitdiff
Improve pipeline render target management
authorMikko Rasa <tdb@tdb.fi>
Sat, 29 Dec 2012 15:09:17 +0000 (17:09 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 29 Dec 2012 15:09:17 +0000 (17:09 +0200)
Recreate render targets if number of samples is changed.

Don't create render targets if neither postprocessing nor multisampling is
active.  HDR is only useful with postprocessors (maybe postprocessors
should be able to request HDR?).

Call fbo.require_complete to allow trial-and-error autodetection of
rendering configuration.

source/pipeline.cpp
source/pipeline.h

index 466aa23c69b6b3107457817f8efea8f33aa829ac..59e6bbb843c40bbf470087eb63b7bf9a8fa9f987 100644 (file)
@@ -37,14 +37,20 @@ Pipeline::~Pipeline()
 
 void Pipeline::set_hdr(bool h)
 {
+       if(h==hdr)
+               return;
+
        hdr = h;
-       create_targets(true);
+       create_targets(2);
 }
 
 void Pipeline::set_multisample(unsigned s)
 {
+       if(s==samples)
+               return;
+
        samples = s;
-       create_targets(false);
+       create_targets(1);
 }
 
 void Pipeline::set_camera(const Camera *c)
@@ -96,7 +102,7 @@ void Pipeline::remove_renderable(const Renderable &r)
 void Pipeline::add_postprocessor(PostProcessor &pp)
 {
        postproc.push_back(&pp);
-       create_targets(false);
+       create_targets(0);
 }
 
 void Pipeline::setup_frame() const
@@ -172,23 +178,29 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const
                finish_frame();
 }
 
-void Pipeline::create_targets(bool recreate)
+void Pipeline::create_targets(unsigned recreate)
 {
-       if(recreate)
+       if(recreate>=2)
        {
                delete target[0];
                delete target[1];
-               delete target_ms;
                target[0] = 0;
                target[1] = 0;
+       }
+       if(recreate>=1)
+       {
+               delete target_ms;
                target_ms = 0;
        }
 
        PixelFormat fmt = (hdr ? RGB16F : RGB);
-       if(!target[0])
-               target[0] = new RenderTarget(width, height, fmt);
-       if(!target[1] && postproc.size()>1)
-               target[1] = new RenderTarget(width, height, fmt);
+       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 MultisampleTarget(width, height, samples, fmt);
@@ -236,6 +248,8 @@ Pipeline::RenderTarget::RenderTarget(unsigned w, unsigned h, PixelFormat f)
        depth.set_wrap(CLAMP_TO_EDGE);
        depth.storage(DEPTH_COMPONENT, w, h);
        fbo.attach(DEPTH_ATTACHMENT, depth, 0);
+
+       fbo.require_complete();
 }
 
 
@@ -246,6 +260,8 @@ Pipeline::MultisampleTarget::MultisampleTarget(unsigned w, unsigned h, unsigned
 
        depth.storage_multisample(s, DEPTH_COMPONENT, w, h);
        fbo.attach(DEPTH_ATTACHMENT, depth);
+
+       fbo.require_complete();
 }
 
 } // namespace GL
index 2c5b6c6490fac43a85ce054cfdd78f69fe186f83..515ca1a48db7992c1ae8c3bebc1a6bfd9fd10085 100644 (file)
@@ -126,7 +126,7 @@ public:
        virtual void render(Renderer &, const Tag &tag = Tag()) const;
 
 private:
-       void create_targets(bool);
+       void create_targets(unsigned);
 };
 
 } // namespace GL