From 89451c28c2c3fcd7c1cedbe136b5f19ef9347d7c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 9 Dec 2010 20:55:25 +0000 Subject: [PATCH] Modernize the Bloom code --- source/bloom.cpp | 44 ++++++++++++++++++++------------------------ source/bloom.h | 2 ++ 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/source/bloom.cpp b/source/bloom.cpp index db10c3b2..1760a6b2 100644 --- a/source/bloom.cpp +++ b/source/bloom.cpp @@ -35,8 +35,8 @@ static const char blur_fs[]= "void main()\n" "{\n" " gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);\n" - " for(int i=-size; i<=size; ++i)\n" - " gl_FragColor += texture2D(source, texcoord+delta*i)*factors[i+size];\n" + " for(int i=0; i<=size*2; ++i)\n" + " gl_FragColor += texture2D(source, texcoord+delta*float(i-size))*factors[i];\n" "}"; static const char combine_vs[]= @@ -82,15 +82,17 @@ Bloom::Bloom(unsigned w, unsigned h): combine_shdata.uniform(combine_shader.get_uniform_location("source"), 1); combine_shdata.uniform(combine_shader.get_uniform_location("blurred"), 0); + combine_texturing.attach(0, tex[1]); + set_radius(2.0f); set_strength(0.2f); MeshBuilder mbld(quad); - mbld.begin(QUADS); + mbld.begin(TRIANGLE_STRIP); + mbld.vertex(0, 1); mbld.vertex(0, 0); - mbld.vertex(1, 0); mbld.vertex(1, 1); - mbld.vertex(0, 1); + mbld.vertex(1, 0); mbld.end(); } @@ -128,32 +130,26 @@ void Bloom::set_strength(float s) void Bloom::render(const Texture2D &src, const Texture2D &) { - const Framebuffer *dest = Framebuffer::current(); - blur_shader.bind(); - fbo.bind(); - src.bind_to(0); Bind unbind_dtest(static_cast(0), true); Bind unbind_blend(static_cast(0), true); - for(unsigned i=0; i<2; ++i) + { - fbo.attach(COLOR_ATTACHMENT0, tex[i], 0); - blur_shdata[i].apply(); - quad.draw(); - tex[i].bind_to(0); + Bind bind_shader(blur_shader); + Bind bind_fbo(fbo, true); + for(unsigned i=0; i<2; ++i) + { + Bind bind_tex(i ? tex[0] : src); + fbo.attach(COLOR_ATTACHMENT0, tex[i], 0); + blur_shdata[i].apply(); + quad.draw(); + } } - if(dest) - dest->bind(); - else - Framebuffer::unbind(); - - combine_shader.bind(); + combine_texturing.attach(1, src); + Bind bind_texturing(combine_texturing); + Bind bind_shader(combine_shader); combine_shdata.apply(); - src.bind_to(1); quad.draw(); - Program::unbind(); - Texture::unbind_from(1); - Texture::unbind_from(0); } } // namespace GL diff --git a/source/bloom.h b/source/bloom.h index b763809a..f930f1cd 100644 --- a/source/bloom.h +++ b/source/bloom.h @@ -12,6 +12,7 @@ Distributed under the LGPL #include "mesh.h" #include "postprocessor.h" #include "texture2d.h" +#include "texturing.h" #include "program.h" #include "programdata.h" @@ -35,6 +36,7 @@ private: ProgramData blur_shdata[2]; Program combine_shader; ProgramData combine_shdata; + Texturing combine_texturing; Mesh quad; public: -- 2.45.2