]> git.tdb.fi Git - libs/gl.git/blobdiff - source/shadowmap.cpp
Turn Effect into a Renderable
[libs/gl.git] / source / shadowmap.cpp
index 11403c6dfb8cb1d48225cd619f01153eec263956..5b2bacad4c4617ad7d617fd333edad7f5232f568 100644 (file)
@@ -3,6 +3,7 @@
 #include "light.h"
 #include "matrix.h"
 #include "misc.h"
+#include "renderer.h"
 #include "scene.h"
 #include "shadowmap.h"
 #include "texunit.h"
@@ -12,9 +13,9 @@ using namespace std;
 namespace Msp {
 namespace GL {
 
-ShadowMap::ShadowMap(unsigned s, const Scene &c, const Light &l):
+ShadowMap::ShadowMap(unsigned s, const Renderable &r, const Light &l):
+       Effect(r),
        size(s),
-       scene(c),
        light(l),
        unit(3),
        radius(1)
@@ -38,8 +39,11 @@ void ShadowMap::set_texture_unit(unsigned u)
        unit = u;
 }
 
-void ShadowMap::prepare()
+void ShadowMap::render(Renderer &renderer, const Tag &tag) const
 {
+       if(!enabled_passes.count(tag))
+               return renderable.render(renderer, tag);
+
        Vector4 lpos = light.get_position();
        if(lpos.w)
        {
@@ -88,6 +92,8 @@ void ShadowMap::prepare()
        matrix[11] = 0;
        matrix[15] = 1;
 
+       renderer.escape();
+
        {
                MatrixStack::Push push_mv(MatrixStack::modelview());
                MatrixStack::Push push_proj(MatrixStack::projection());
@@ -97,7 +103,7 @@ void ShadowMap::prepare()
 
                Bind bind_fbo(fbo, true);
                fbo.clear(DEPTH_BUFFER_BIT);
-               scene.render("shadow");
+               renderable.render("shadow");
        }
 
        depth_buf.bind_to(unit);
@@ -116,10 +122,9 @@ void ShadowMap::prepare()
        enable(GL_TEXTURE_GEN_R);
 
        TexUnit::activate(0);
-}
 
-void ShadowMap::cleanup()
-{
+       renderable.render(renderer, tag);
+
        Texture::unbind_from(unit);
        disable(GL_TEXTURE_GEN_S);
        disable(GL_TEXTURE_GEN_T);