X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fbloom.cpp;h=1760a6b2940568d95f5d17f9d1cda55fae29dda9;hb=89451c28c2c3fcd7c1cedbe136b5f19ef9347d7c;hp=040fd6c7b1fa5ea5f995aafc4e45784665a87269;hpb=12ac9bec8e03029c1042fd7732a2cfc04c9a9584;p=libs%2Fgl.git diff --git a/source/bloom.cpp b/source/bloom.cpp index 040fd6c7..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[]= @@ -76,22 +76,23 @@ Bloom::Bloom(unsigned w, unsigned h): { blur_shdata[i].uniform(loc, 0); tex[i].set_min_filter(NEAREST); - tex[i].storage(RGB16F, w, h, 0); - tex[i].image(0, RGB, UNSIGNED_BYTE, 0); + tex[i].storage(RGB16F, w, 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(); } @@ -127,34 +128,28 @@ void Bloom::set_strength(float s) combine_shdata.uniform(combine_shader.get_uniform_location("strength"), s); } -void Bloom::render(const Texture2D &src) +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