"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[]=
for(unsigned i=0; i<2; ++i)
{
blur_shdata[i].uniform(loc, 0);
- tex[i].storage(RGB16F, w, h, 0);
- tex[i].image(0, RGB, UNSIGNED_BYTE, 0);
tex[i].set_min_filter(NEAREST);
+ 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();
}
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);
- disable(DEPTH_TEST);
- disable(BLEND);
- for(unsigned i=0; i<2; ++i)
+ Bind unbind_dtest(static_cast<DepthTest *>(0), true);
+ Bind unbind_blend(static_cast<Blend *>(0), true);
+
{
- 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();
- TexUnit::activate(0);
- Texture::unbind();
- // XXX Should check if the modes were enabled in the first place
- enable(DEPTH_TEST);
- enable(BLEND);
}
} // namespace GL