]> git.tdb.fi Git - libs/gl.git/blobdiff - source/shadowmap.cpp
Add get_width() / get_height() methods to Renderbuffer and Framebuffer
[libs/gl.git] / source / shadowmap.cpp
index 3691773ad3f58d9ae41ffb1148291b10acd08d32..5f66d8984279ce55f9cfc98fcf2298d34fa31337 100644 (file)
@@ -24,6 +24,7 @@ ShadowMap::ShadowMap(unsigned s, const Scene &c, const Light &l):
        size(s),
        scene(c),
        light(l),
+       unit(3),
        radius(1)
 {
        depth_buf.set_min_filter(LINEAR);
@@ -35,7 +36,7 @@ ShadowMap::ShadowMap(unsigned s, const Scene &c, const Light &l):
        depth_buf.parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        depth_buf.parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        fbo.attach(DEPTH_ATTACHMENT, depth_buf, 0);
-       glDrawBuffer(GL_NONE);
+       draw_buffer(NO_BUFFER);
        Framebuffer::unbind();
        Texture::unbind();
 }
@@ -46,6 +47,11 @@ void ShadowMap::set_target(const Vector3 &t, float r)
        radius=r;
 }
 
+void ShadowMap::set_texture_unit(unsigned u)
+{
+       unit=u;
+}
+
 void ShadowMap::prepare()
 {
        const Vector4 &lpos=light.get_position();
@@ -97,8 +103,7 @@ void ShadowMap::prepare()
 
                const Framebuffer *old_fbo=Framebuffer::current();
                fbo.bind();
-               glViewport(0, 0, size, size);
-               glClear(GL_DEPTH_BUFFER_BIT);
+               clear(DEPTH_BUFFER_BIT);
                scene.render("shadow");
 
                matrix_mode(PROJECTION);
@@ -111,7 +116,7 @@ void ShadowMap::prepare()
                        Framebuffer::unbind();
        }
 
-       depth_buf.bind_to(3);
+       depth_buf.bind_to(unit);
        float diam=radius*2;
        float s_eq[4]={ matrix[0]/diam, matrix[4]/diam, matrix[8]/diam, matrix[12]/diam+0.5 };
        float t_eq[4]={ matrix[1]/diam, matrix[5]/diam, matrix[9]/diam, matrix[13]/diam+0.5 };
@@ -131,7 +136,7 @@ void ShadowMap::prepare()
 
 void ShadowMap::cleanup()
 {
-       TexUnit::activate(3);
+       TexUnit::activate(unit);
        Texture::unbind();
        disable(GL_TEXTURE_GEN_S);
        disable(GL_TEXTURE_GEN_T);