#include <cmath>
#include <msp/strings/format.h>
-#include "blend.h"
#include "bloom.h"
-#include "misc.h"
+#include "mesh.h"
#include "renderer.h"
#include "resources.h"
-#include "shader.h"
-#include "tests.h"
-#include "texunit.h"
+#include "texture2d.h"
using namespace std;
namespace Msp {
namespace GL {
-Bloom::Bloom(Resources &resources, unsigned w, unsigned h):
- blur_shader(resources.get<Program>("_bloom_blur.glsl")),
- combine_shader(resources.get<Program>("_bloom_combine.glsl")),
- quad(resources.get<Mesh>("_fullscreen_quad.mesh")),
- nearest_sampler(resources.get<Sampler>("_nearest_clamp.samp")),
- linear_sampler(resources.get<Sampler>("_linear_clamp.samp"))
+Bloom::Bloom(unsigned w, unsigned h):
+ blur_shader(Resources::get_global().get<Program>("_bloom_blur.glsl.shader")),
+ combine_shader(Resources::get_global().get<Program>("_bloom_combine.glsl.shader")),
+ quad(Resources::get_global().get<Mesh>("_fullscreen_quad.mesh")),
+ nearest_sampler(Resources::get_global().get<Sampler>("_nearest_clamp.samp")),
+ linear_sampler(Resources::get_global().get<Sampler>("_linear_clamp.samp"))
{
blur_shdata[0].uniform("delta", 1.0f/w, 0.0f);
blur_shdata[1].uniform("delta", 0.0f, 1.0f/h);
for(unsigned i=0; i<2; ++i)
- target[i] = new RenderTarget(w, h, (RENDER_COLOR,RGB16F));
-
- common_shdata.uniform("source", 0);
- common_shdata.uniform("blurred", 1);
-
- combine_texturing.attach(1, target[1]->get_target_texture(RENDER_COLOR), &linear_sampler);
+ target[i] = new RenderTarget(w, h, (COLOR_ATTACHMENT,RGB16F));
set_radius(2.0f);
set_strength(0.2f);
renderer.set_shader_program(&blur_shader, &common_shdata);
for(unsigned i=0; i<2; ++i)
{
- BindRestore bind_fbo(target[i]->get_framebuffer());
Renderer::Push push2(renderer);
- renderer.set_texture(i ? &target[0]->get_target_texture(RENDER_COLOR) : &src, &nearest_sampler);
+ renderer.set_framebuffer(&target[i]->get_framebuffer());
+ renderer.set_texture("source", (i ? &target[0]->get_target_texture(COLOR_ATTACHMENT) : &src), &nearest_sampler);
renderer.add_shader_data(blur_shdata[i]);
quad.draw(renderer);
}
- combine_texturing.attach(0, src, &nearest_sampler);
- renderer.set_texturing(&combine_texturing);
+ renderer.set_texture("source", &src, &nearest_sampler);
+ renderer.set_texture("blurred", &target[1]->get_target_texture(COLOR_ATTACHMENT), &linear_sampler);
renderer.set_shader_program(&combine_shader);
quad.draw(renderer);
}
+void Bloom::set_debug_name(const string &name)
+{
+#ifdef DEBUG
+ for(unsigned i=0; i<2; ++i)
+ target[i]->set_debug_name(format("%s [RT:%d]", name, i));
+ common_shdata.set_debug_name(name+" [UBO:common]");
+ blur_shdata[0].set_debug_name(name+" [UBO:blur_x]");
+ blur_shdata[1].set_debug_name(name+" [UBO:blur_y]");
+#else
+ (void)name;
+#endif
+}
-Bloom::Template::Template():
- radius(2.0f),
- strength(0.2f)
-{ }
-Bloom *Bloom::Template::create(Resources &res, unsigned width, unsigned height) const
+Bloom *Bloom::Template::create(unsigned width, unsigned height) const
{
- RefPtr<Bloom> bloom = new Bloom(res, width/size_divisor, height/size_divisor);
+ RefPtr<Bloom> bloom = new Bloom(width/size_divisor, height/size_divisor);
bloom->set_radius(radius);
bloom->set_strength(strength);
return bloom.release();