]> git.tdb.fi Git - libs/gl.git/blobdiff - source/shadowmap.cpp
Verify framebuffer completeness in effect constructors
[libs/gl.git] / source / shadowmap.cpp
index ad40442f8e911fd0bd908c4d81b39a028a5bbbd9..c4dd07b03dbdb288fa55bda158dc305386813d70 100644 (file)
@@ -29,6 +29,7 @@ ShadowMap::ShadowMap(unsigned s, const Renderable &r, const Light &l):
        depth_buf.set_wrap(CLAMP_TO_EDGE);
        depth_buf.storage(DEPTH_COMPONENT, size, size);
        fbo.attach(DEPTH_ATTACHMENT, depth_buf, 0);
+       fbo.require_complete();
 
        set_darkness(0.7);
        set_texture_unit(3);
@@ -74,6 +75,7 @@ void ShadowMap::setup_frame() const
        rendered = true;
 
        Vector4 lpos = light.get_position();
+
        if(lpos.w)
        {
                /* XXX Not really proper way to support positional lights, but good
@@ -81,12 +83,13 @@ void ShadowMap::setup_frame() const
                lpos.x -= target.x;
                lpos.y -= target.y;
                lpos.z -= target.z;
-               float d = sqrt(lpos.x*lpos.x+lpos.y*lpos.y+lpos.z*lpos.z);
-               lpos.x /= d;
-               lpos.y /= d;
-               lpos.z /= d;
        }
 
+       float l = sqrt(lpos.x*lpos.x+lpos.y*lpos.y+lpos.z*lpos.z);
+       lpos.x /= l;
+       lpos.y /= l;
+       lpos.z /= l;
+
        float matrix[16];
        if(abs(lpos.z)>=abs(lpos.x) && abs(lpos.z)>=abs(lpos.y))
        {