From: Mikko Rasa Date: Sat, 27 Jul 2019 23:05:05 +0000 (+0300) Subject: Add an alpha channel flag to Pipeline X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=39488946c441f4007396e438f522609a8b2943ce;p=libs%2Fgl.git Add an alpha channel flag to Pipeline --- diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 53b51d79..fa06fc5c 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -38,6 +38,7 @@ void Pipeline::init(unsigned w, unsigned h) width = w; height = h; hdr = false; + alpha = false; samples = 0; target_ms = 0; target[0] = 0; @@ -69,6 +70,24 @@ void Pipeline::set_hdr(bool h) } } +void Pipeline::set_alpha(bool a) +{ + if(a==alpha) + return; + + bool old_alpha = alpha; + alpha = a; + try + { + create_targets(2); + } + catch(...) + { + alpha = old_alpha; + throw; + } +} + void Pipeline::set_multisample(unsigned s) { if(s==samples) @@ -269,7 +288,7 @@ void Pipeline::create_targets(unsigned recreate) target_ms = 0; } - PixelFormat color_pf = (hdr ? RGB16F : RGB); + PixelFormat color_pf = (hdr ? (alpha ? RGBA16F : RGB16F) : (alpha ? RGBA : RGB)); RenderTargetFormat fmt = (RENDER_COLOR,color_pf, RENDER_DEPTH); if(!postproc.empty() || samples) { diff --git a/source/pipeline.h b/source/pipeline.h index 0d38aaec..e8ffaf5e 100644 --- a/source/pipeline.h +++ b/source/pipeline.h @@ -80,6 +80,7 @@ private: unsigned width; unsigned height; bool hdr; + bool alpha; unsigned samples; RenderTarget *target[2]; RenderTarget *target_ms; @@ -97,6 +98,10 @@ public: A ColorCurve postprocessor is recommended for full benefit. */ void set_hdr(bool); + /* Enable or disable alpha channel. When enabled, all render targets are + created with an RGBA pixel format instead of RGB. */ + void set_alpha(bool); + void set_multisample(unsigned); unsigned get_width() const { return width; } diff --git a/source/pipelinebuilder.cpp b/source/pipelinebuilder.cpp index fcd5efbc..51e9cc85 100644 --- a/source/pipelinebuilder.cpp +++ b/source/pipelinebuilder.cpp @@ -36,6 +36,7 @@ void PipelineBuilder::set_postprocessor(const string &name, PostProcessor &pproc void PipelineBuilder::build(Pipeline &pipeline) const { pipeline.set_hdr(tmpl.get_hdr()); + pipeline.set_alpha(tmpl.get_alpha()); unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples()); if(samples PostProcessorRegistry; bool hdr; + bool alpha; unsigned required_multisample; unsigned max_multisample; PassArray passes; @@ -116,6 +117,7 @@ public: ~PipelineTemplate(); bool get_hdr() const { return hdr; } + bool get_alpha() const { return alpha; } unsigned get_required_multisample() const { return required_multisample; } unsigned get_maximum_multisample() const { return max_multisample; } const PassArray &get_passes() const { return passes; }