]> git.tdb.fi Git - libs/gl.git/commitdiff
Use Renderer for rendering PostProcessors
authorMikko Rasa <tdb@tdb.fi>
Sat, 26 Nov 2016 11:09:00 +0000 (13:09 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 26 Nov 2016 11:09:00 +0000 (13:09 +0200)
source/ambientocclusion.cpp
source/ambientocclusion.h
source/bloom.cpp
source/bloom.h
source/colorcurve.cpp
source/colorcurve.h
source/pipeline.cpp
source/postprocessor.cpp
source/postprocessor.h

index 5aba53dde9231b02decd1bf302d04f0ada796cac..53b51e127d0993ce8e15093d1d1b1dc25c59c192 100644 (file)
@@ -2,6 +2,7 @@
 #include <cmath>
 #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
index c080eb24579d9bdf9a4560eb53f8cde6eac8e911..aae5fb29b8c45449759e590da4d4bced27f0dfd5 100644 (file)
@@ -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
index 2160e147cb1b8877f1a657f7f15651362ebf26fa..733b14a2e5a0fe5245c4b7a362bbc802f6b40916 100644 (file)
@@ -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
index b96fddfc52abeed4c1ce60da16c3fb99f09d8deb..957febb20923670ebe53bd99aeb6b31de4faa059 100644 (file)
@@ -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
index ad2c51ca337f35340974226253e706a58f58b088..81b5a43e7a6ef4d6724a39e2ea182e7ecd63586a 100644 (file)
@@ -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
index d7589cb565b8bacd4f63c0f60d672b294ec7d9bf..2b854bec8b6f8ac5392f010e64a06b5269b83415 100644 (file)
@@ -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
index 92d80a97c3c11ef7406bd2701816407a3ea7d552..dc1eba1d117cdcca5d6b190c53b3545ed31fd86c 100644 (file)
@@ -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<DepthTest *>(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);
                }
        }
 
index d4f7bd2ebd32d048db9e988a70323437c61e02af..26330a4d08b3d03a1f5df88711e681f519482327 100644 (file)
@@ -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);
index ffc9045dbed954119262218441eba1cc6e32e66f..15cdc271149265e171da1b2cdf4ef6ce6a3b842d 100644 (file)
@@ -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.