From d1e3975c163694d7bca6417463462be950019e5e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 26 Nov 2016 13:09:00 +0200 Subject: [PATCH] Use Renderer for rendering PostProcessors --- source/ambientocclusion.cpp | 20 ++++++++++---------- source/ambientocclusion.h | 2 +- source/bloom.cpp | 24 ++++++++++++------------ source/bloom.h | 2 +- source/colorcurve.cpp | 16 +++++++++------- source/colorcurve.h | 4 +++- source/pipeline.cpp | 4 +--- source/postprocessor.cpp | 5 +++++ source/postprocessor.h | 5 ++++- 9 files changed, 46 insertions(+), 36 deletions(-) diff --git a/source/ambientocclusion.cpp b/source/ambientocclusion.cpp index 5aba53dd..53b51e12 100644 --- a/source/ambientocclusion.cpp +++ b/source/ambientocclusion.cpp @@ -2,6 +2,7 @@ #include #include "ambientocclusion.h" #include "blend.h" +#include "renderer.h" #include "shader.h" #include "tests.h" @@ -66,26 +67,25 @@ void AmbientOcclusion::set_darkness(float darkness) occlude_shdata.uniform("darkness", darkness); } -void AmbientOcclusion::render(const Texture2D &color, const Texture2D &depth) +void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const Texture2D &depth) { occlude_texturing.attach(0, depth); combine_texturing.attach(0, depth); combine_texturing.attach(1, color); - Bind bind_mesh(quad); { + Renderer::Push push(renderer); BindRestore bind_fbo(fbo); - Bind bind_tex(occlude_texturing); - Bind bind_shader(occlude_shader); - occlude_shdata.apply(); - quad.draw(); + renderer.set_texturing(&occlude_texturing); + renderer.set_shader_program(&occlude_shader, &occlude_shdata); + quad.draw(renderer); } - Bind bind_tex(combine_texturing); - Bind bind_shader(combine_shader); - combine_shdata.apply(); - quad.draw(); + Renderer::Push push(renderer); + renderer.set_texturing(&combine_texturing); + renderer.set_shader_program(&combine_shader, &combine_shdata); + quad.draw(renderer); } } // namespace GL diff --git a/source/ambientocclusion.h b/source/ambientocclusion.h index c080eb24..aae5fb29 100644 --- a/source/ambientocclusion.h +++ b/source/ambientocclusion.h @@ -37,7 +37,7 @@ public: void set_depth_ratio(float); void set_darkness(float); - virtual void render(const Texture2D &, const Texture2D &); + virtual void render(Renderer &, const Texture2D &, const Texture2D &); }; } // namespace GL diff --git a/source/bloom.cpp b/source/bloom.cpp index 2160e147..733b14a2 100644 --- a/source/bloom.cpp +++ b/source/bloom.cpp @@ -3,6 +3,7 @@ #include "blend.h" #include "bloom.h" #include "misc.h" +#include "renderer.h" #include "shader.h" #include "tests.h" #include "texunit.h" @@ -65,27 +66,26 @@ void Bloom::set_strength(float s) combine_shdata.uniform("strength", s); } -void Bloom::render(const Texture2D &src, const Texture2D &) +void Bloom::render(Renderer &renderer, const Texture2D &src, const Texture2D &) { - Bind bind_mesh(quad); - { - Bind bind_shader(blur_shader); - blur_shdata_common.apply(); + Renderer::Push push(renderer); + renderer.set_shader_program(&blur_shader, &blur_shdata_common); for(unsigned i=0; i<2; ++i) { BindRestore bind_fbo(fbo[i]); - Bind bind_tex(i ? tex[0] : src); - blur_shdata[i].apply(); - quad.draw(); + Renderer::Push push2(renderer); + renderer.set_texture(i ? &tex[0] : &src); + renderer.add_shader_data(blur_shdata[i]); + quad.draw(renderer); } } + Renderer::Push push(renderer); combine_texturing.attach(1, src); - Bind bind_texturing(combine_texturing); - Bind bind_shader(combine_shader); - combine_shdata.apply(); - quad.draw(); + renderer.set_texturing(&combine_texturing); + renderer.set_shader_program(&combine_shader, &combine_shdata); + quad.draw(renderer); } } // namespace GL diff --git a/source/bloom.h b/source/bloom.h index b96fddfc..957febb2 100644 --- a/source/bloom.h +++ b/source/bloom.h @@ -44,7 +44,7 @@ public: values mean more blurriness. */ void set_strength(float); - virtual void render(const Texture2D &, const Texture2D &); + virtual void render(Renderer &, const Texture2D &, const Texture2D &); }; } // namespace GL diff --git a/source/colorcurve.cpp b/source/colorcurve.cpp index ad2c51ca..81b5a43e 100644 --- a/source/colorcurve.cpp +++ b/source/colorcurve.cpp @@ -2,6 +2,7 @@ #include "color.h" #include "colorcurve.h" #include "mesh.h" +#include "renderer.h" #include "shader.h" #include "texture2d.h" @@ -20,6 +21,7 @@ ColorCurve::ColorCurve(): curve.storage(LUMINANCE, 256); curve.set_min_filter(LINEAR); curve.set_wrap(CLAMP_TO_EDGE); + texturing.attach(1, curve); set_peak(0.2); set_brightness(1.5); @@ -68,14 +70,14 @@ void ColorCurve::set_linear() curve.image(0, LUMINANCE, UNSIGNED_BYTE, curve_data); } -void ColorCurve::render(const Texture2D &color_buf, const Texture2D &) +void ColorCurve::render(Renderer &renderer, const Texture2D &color_buf, const Texture2D &) { - Bind _bind_shader(shprog); - shdata.apply(); - Bind _bind_mesh(quad); - Bind _bind_tex(color_buf); - Bind _bind_curve(curve, 1); - quad.draw(); + texturing.attach(0, color_buf); + + Renderer::Push push(renderer); + renderer.set_shader_program(&shprog, &shdata); + renderer.set_texturing(&texturing); + quad.draw(renderer); } } // namespace GL diff --git a/source/colorcurve.h b/source/colorcurve.h index d7589cb5..2b854bec 100644 --- a/source/colorcurve.h +++ b/source/colorcurve.h @@ -5,6 +5,7 @@ #include "program.h" #include "programdata.h" #include "texture1d.h" +#include "texturing.h" namespace Msp { namespace GL { @@ -24,6 +25,7 @@ private: Program shprog; ProgramData shdata; Texture1D curve; + Texturing texturing; const Mesh &quad; public: @@ -48,7 +50,7 @@ public: /// Sets output mapping to linear. This is equivalent to set_gamma(1). void set_linear(); - virtual void render(const Texture2D &, const Texture2D &); + virtual void render(Renderer &, const Texture2D &, const Texture2D &); }; } // namespace GL diff --git a/source/pipeline.cpp b/source/pipeline.cpp index 92d80a97..dc1eba1d 100644 --- a/source/pipeline.cpp +++ b/source/pipeline.cpp @@ -212,8 +212,6 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const renderer.render(*j->renderable, i->get_tag()); } - renderer.end(); - if(target[0]) { BindRestore unbind_depth_test(static_cast(0)); @@ -229,7 +227,7 @@ void Pipeline::render(Renderer &renderer, const Tag &tag) const target[1-j]->fbo.bind(); else out_fbo->bind(); - postproc[i]->render(target[j]->color, target[j]->depth); + postproc[i]->render(renderer, target[j]->color, target[j]->depth); } } diff --git a/source/postprocessor.cpp b/source/postprocessor.cpp index d4f7bd2e..26330a4d 100644 --- a/source/postprocessor.cpp +++ b/source/postprocessor.cpp @@ -20,6 +20,11 @@ const char fullscreen_vs_source[] = namespace Msp { namespace GL { +void PostProcessor::render(Renderer &, const Texture2D &color, const Texture2D &depth) +{ + render(color, depth); +} + Shader &PostProcessor::get_fullscreen_vertex_shader() { static VertexShader shader(fullscreen_vs_source); diff --git a/source/postprocessor.h b/source/postprocessor.h index ffc9045d..15cdc271 100644 --- a/source/postprocessor.h +++ b/source/postprocessor.h @@ -5,6 +5,7 @@ namespace Msp { namespace GL { class Mesh; +class Renderer; class Shader; class Texture2D; @@ -21,7 +22,9 @@ public: virtual ~PostProcessor() { } /// Renders the effect. - virtual void render(const Texture2D &color, const Texture2D &depth) = 0; + virtual void render(const Texture2D &, const Texture2D &) { } + + virtual void render(Renderer &, const Texture2D &, const Texture2D &); protected: /** Returns a vertex shader suitable for rendering a full-screen quad. -- 2.45.2