From: Mikko Rasa Date: Sat, 29 Dec 2012 15:09:17 +0000 (+0200) Subject: Improve pipeline render target management X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=812c37a8aef84f8720a3e1efedebecd993ec75b2;p=libs%2Fgl.git Improve pipeline render target management 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. --- diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 466aa23c..59e6bbb8 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -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 diff --git a/source/pipeline.h b/source/pipeline.h index 2c5b6c64..515ca1a4 100644 --- a/source/pipeline.h +++ b/source/pipeline.h @@ -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