-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrenderer.cpp
More file actions
105 lines (85 loc) · 2.63 KB
/
Copy pathrenderer.cpp
File metadata and controls
105 lines (85 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
////////////////////////////////////////////////////////////////////////////////
// Distributed under the Boost Software License, Version 1.0. //
// (See accompanying file LICENSE or copy at //
// https://www.boost.org/LICENSE_1_0.txt) //
////////////////////////////////////////////////////////////////////////////////
#include "graphics/renderer.h"
#include <cassert>
#include "core/exception.h"
#include "graphics/material_manager.h"
namespace iris
{
Renderer::Renderer(MaterialManager &material_manager)
: render_queue_()
, render_pipeline_()
, start_(std::chrono::steady_clock::now())
, time_(0u)
, material_manager_(material_manager)
{
}
void Renderer::render()
{
if (render_pipeline_->is_dirty())
{
render_queue_ = render_pipeline_->rebuild();
render_pipeline_->clear_dirty_bit();
}
pre_render();
// update time
// this is calculated here rather than in time() so all calls to time() produce the same value for a given frame
time_ = std::chrono::steady_clock::now() - start_;
// call each command with the appropriate handler
for (auto &command : render_queue_)
{
switch (command.type())
{
case RenderCommandType::PASS_START: execute_pass_start(command); break;
case RenderCommandType::DRAW: execute_draw(command); break;
case RenderCommandType::PASS_END: execute_pass_end(command); break;
case RenderCommandType::PRESENT: execute_present(command); break;
default: throw Exception("unknown render queue command");
}
}
post_render();
}
void Renderer::set_render_pipeline(std::unique_ptr<RenderPipeline> render_pipeline)
{
material_manager_.clear();
start_ = std::chrono::steady_clock::now();
render_pipeline_ = std::move(render_pipeline);
do_set_render_pipeline(
[this]
{
render_queue_ = render_pipeline_->build();
render_pipeline_->clear_dirty_bit();
});
}
std::chrono::milliseconds Renderer::time() const
{
return std::chrono::duration_cast<std::chrono::milliseconds>(time_);
}
void Renderer::pre_render()
{
// default is to do nothing
}
void Renderer::execute_pass_start(RenderCommand &)
{
// default is to do nothing
}
void Renderer::execute_draw(RenderCommand &)
{
// default is to do nothing
}
void Renderer::execute_pass_end(RenderCommand &)
{
// default is to do nothing
}
void Renderer::execute_present(RenderCommand &)
{
// default is to do nothing
}
void Renderer::post_render()
{
// default is to do nothing
}
}