]> git.tdb.fi Git - libs/gl.git/blob - source/render/view.cpp
Require conditions to be booleans
[libs/gl.git] / source / render / view.cpp
1 #include "camera.h"
2 #include "renderable.h"
3 #include "renderer.h"
4 #include "view.h"
5
6 namespace Msp {
7 namespace GL {
8
9 View::View(Framebuffer &t):
10         target(t),
11         camera(0),
12         content(0),
13         internal_renderer(0)
14 { }
15
16 View::~View()
17 {
18         delete internal_renderer;
19 }
20
21 void View::set_camera(Camera *c)
22 {
23         camera = c;
24         if(camera)
25                 camera->set_aspect_ratio(get_aspect_ratio());
26 }
27
28 void View::set_content(Renderable *r)
29 {
30         content = r;
31 }
32
33 void View::render()
34 {
35         if(!internal_renderer)
36                 internal_renderer = new Renderer;
37         render(*internal_renderer);
38 }
39
40 void View::render(Renderer &renderer)
41 {
42         Bind bind_fbo(target);
43         target.clear();
44         if(content)
45         {
46                 Renderer::Push push(renderer);
47                 if(camera)
48                         renderer.set_camera(*camera);
49                 content->setup_frame(renderer);
50                 content->render(renderer);
51                 content->finish_frame();
52                 renderer.flush_shader_data();
53         }
54 }
55
56 } // namespace GL
57 } // namespace Msp