]> git.tdb.fi Git - libs/gl.git/commitdiff
Modernize the Bloom code
authorMikko Rasa <tdb@tdb.fi>
Thu, 9 Dec 2010 20:55:25 +0000 (20:55 +0000)
committerMikko Rasa <tdb@tdb.fi>
Thu, 9 Dec 2010 20:55:25 +0000 (20:55 +0000)
source/bloom.cpp
source/bloom.h

index db10c3b26fc45b3c7b0c28ba4c51687ef964a13d..1760a6b2940568d95f5d17f9d1cda55fae29dda9 100644 (file)
@@ -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<DepthTest *>(0), true);
        Bind unbind_blend(static_cast<Blend *>(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
index b763809aca7422feba10f52be9f402f4a97f5962..f930f1cd20449d883e194e9654cbc8a86350c087 100644 (file)
@@ -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: