]> git.tdb.fi Git - libs/gl.git/blobdiff - source/ambientocclusion.cpp
Use RenderTarget objects to manage FBOs in postprocessors
[libs/gl.git] / source / ambientocclusion.cpp
index 5aba53dde9231b02decd1bf302d04f0ada796cac..cb4bc9d29ff381685e37c713aa8fd9d2200942b9 100644 (file)
@@ -2,6 +2,7 @@
 #include <cmath>
 #include "ambientocclusion.h"
 #include "blend.h"
+#include "renderer.h"
 #include "shader.h"
 #include "tests.h"
 
@@ -9,18 +10,12 @@ namespace Msp {
 namespace GL {
 
 AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float depth_ratio):
+       occlude_target(w, h, (RENDER_COLOR,RGB)),
        occlude_shader("ambientocclusion_occlude.glsl"),
        combine_shader("ambientocclusion_combine.glsl"),
        quad(get_fullscreen_quad())
 {
-       occlusion.storage(RGB, w, h);
-       occlusion.set_min_filter(NEAREST);
-       occlusion.set_mag_filter(NEAREST);
-       occlusion.set_wrap(CLAMP_TO_EDGE);
-       fbo.attach(COLOR_ATTACHMENT0, occlusion, 0);
-       fbo.require_complete();
-
-       combine_texturing.attach(2, occlusion);
+       combine_texturing.attach(2, occlude_target.get_target_texture(RENDER_COLOR));
 
        rotate_lookup.storage(RGBA, 4, 4);
        rotate_lookup.set_min_filter(NEAREST);
@@ -66,26 +61,24 @@ 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);
-
        {
-               BindRestore bind_fbo(fbo);
-               Bind bind_tex(occlude_texturing);
-               Bind bind_shader(occlude_shader);
-               occlude_shdata.apply();
-               quad.draw();
+               Renderer::Push push(renderer);
+               BindRestore bind_fbo(occlude_target.get_framebuffer());
+               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