]> git.tdb.fi Git - libs/gl.git/blobdiff - source/effects/ambientocclusion.cpp
Load various built-in things through Resources
[libs/gl.git] / source / effects / ambientocclusion.cpp
index 8c1dd616c4b53ba40b49aea69bfd237bd89e1b17..e5de04b4846eebf5fe5ff24569e637f1760ce4ee 100644 (file)
@@ -3,6 +3,7 @@
 #include "blend.h"
 #include "camera.h"
 #include "renderer.h"
+#include "resources.h"
 #include "shader.h"
 #include "tests.h"
 
@@ -11,15 +12,15 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float):
+AmbientOcclusion::AmbientOcclusion(Resources &resources, unsigned w, unsigned h, float):
        occlude_target(w, h, (RENDER_COLOR,R8)),
-       occlude_shader("ambientocclusion_occlude.glsl"),
-       combine_shader("ambientocclusion_combine.glsl"),
-       quad(get_fullscreen_quad()),
-       linear_sampler(get_linear_sampler()),
-       nearest_sampler(get_nearest_sampler())
+       occlude_shader(resources.get<Program>("_ambientocclusion_occlude.glsl")),
+       combine_shader(resources.get<Program>("_ambientocclusion_combine.glsl")),
+       quad(resources.get<Mesh>("_fullscreen_quad.mesh")),
+       linear_sampler(resources.get<Sampler>("_linear_clamp.samp")),
+       nearest_sampler(resources.get<Sampler>("_nearest_clamp.samp"))
 {
-       texturing.attach(2, occlude_target.get_target_texture(RENDER_COLOR), linear_sampler.get());
+       texturing.attach(2, occlude_target.get_target_texture(RENDER_COLOR), &linear_sampler);
 
        unsigned seed = 1;
        rotate_lookup.storage(RGBA8, 4, 4, 1);
@@ -36,7 +37,7 @@ AmbientOcclusion::AmbientOcclusion(unsigned w, unsigned h, float):
        }
        rotate_lookup.image(0, data);
 
-       texturing.attach(3, rotate_lookup, nearest_sampler.get());
+       texturing.attach(3, rotate_lookup, &nearest_sampler);
 
        shdata.uniform("source", 0);
        shdata.uniform("depth", 1);
@@ -91,8 +92,8 @@ void AmbientOcclusion::set_edge_depth_threshold(float edt)
 
 void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const Texture2D &depth)
 {
-       texturing.attach(0, color, nearest_sampler.get());
-       texturing.attach(1, depth, nearest_sampler.get());
+       texturing.attach(0, color, &nearest_sampler);
+       texturing.attach(1, depth, &nearest_sampler);
 
        if(renderer.get_camera())
                shdata.uniform("inverse_projection", invert(renderer.get_camera()->get_projection_matrix()));
@@ -103,11 +104,11 @@ void AmbientOcclusion::render(Renderer &renderer, const Texture2D &color, const
 
        {
                BindRestore bind_fbo(occlude_target.get_framebuffer());
-               quad->draw(renderer);
+               quad.draw(renderer);
        }
 
        renderer.set_shader_program(&combine_shader);
-       quad->draw(renderer);
+       quad.draw(renderer);
 }
 
 
@@ -118,9 +119,9 @@ AmbientOcclusion::Template::Template():
        edge_depth_threshold(0.1f)
 { }
 
-AmbientOcclusion *AmbientOcclusion::Template::create(unsigned width, unsigned height) const
+AmbientOcclusion *AmbientOcclusion::Template::create(Resources &res, unsigned width, unsigned height) const
 {
-       RefPtr<AmbientOcclusion> ao = new AmbientOcclusion(width/size_divisor, height/size_divisor);
+       RefPtr<AmbientOcclusion> ao = new AmbientOcclusion(res, width/size_divisor, height/size_divisor);
        ao->set_n_samples(n_samples);
        ao->set_occlusion_radius(occlusion_radius);
        ao->set_darkness(darkness);