]> git.tdb.fi Git - libs/gl.git/commitdiff
Use the external Renderer to render ShadowMap and EnvironmentMap
authorMikko Rasa <tdb@tdb.fi>
Mon, 5 Dec 2016 17:20:17 +0000 (19:20 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 5 Dec 2016 17:50:14 +0000 (19:50 +0200)
source/environmentmap.cpp
source/shadowmap.cpp

index cbb097eaa6370e3b944a73124639b9ca72d5d42c..9ca4d45253580134e59a060a7936a9f04c6fbbf2 100644 (file)
@@ -39,10 +39,17 @@ void EnvironmentMap::setup_frame(Renderer &renderer)
        renderable.setup_frame(renderer);
        environment.setup_frame(renderer);
 
-       Renderer env_renderer(0);
        const Matrix *matrix = renderable.get_matrix();
-       Vector3 position = (*matrix)*Vector3();
-       camera.set_position(position);
+       if(!matrix)
+               return;
+
+       Renderer::Push push(renderer);
+       Renderer::Exclude exclude1(renderer, renderable);
+       Renderer::Exclude exclude2(renderer, *this);
+
+       camera.set_position(*matrix*Vector3());
+
+       BindRestore bind_fbo(fbo[0]);
        for(unsigned i=0; i<6; ++i)
        {
                TextureCubeFace face = TextureCube::enumerate_faces(i);
@@ -50,12 +57,9 @@ void EnvironmentMap::setup_frame(Renderer &renderer)
                fbo[i].clear(COLOR_BUFFER_BIT|DEPTH_BUFFER_BIT);
                camera.set_look_direction(env_tex.get_face_direction(face));
                camera.set_up_direction(env_tex.get_t_direction(face));
-               env_renderer.begin(&camera);
-               env_renderer.exclude(renderable);
-               env_renderer.exclude(*this);
-               env_renderer.render(environment);
+               renderer.set_camera(camera);
+               renderer.render(environment);
        }
-       Framebuffer::unbind();
 }
 
 void EnvironmentMap::finish_frame()
index f461c88a4279155604b0ba519f7ea98ff3d096b1..6056141f763376edaa39531b0070d348c9effb9f 100644 (file)
@@ -84,8 +84,10 @@ void ShadowMap::setup_frame(Renderer &renderer)
        Bind bind_depth(DepthTest::lequal());
        fbo.clear(DEPTH_BUFFER_BIT);
 
-       Renderer shadow_renderer(&camera);
-       renderable.render(shadow_renderer, "shadow");
+       Renderer::Push push(renderer);
+       renderer.set_camera(camera);
+
+       renderer.render(renderable, "shadow");
 }
 
 void ShadowMap::finish_frame()