-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathscene.cpp
More file actions
125 lines (97 loc) · 3.29 KB
/
Copy pathscene.cpp
File metadata and controls
125 lines (97 loc) · 3.29 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
////////////////////////////////////////////////////////////////////////////////
// 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/scene.h"
#include <vector>
#include "core/colour.h"
#include "core/error_handling.h"
#include "graphics/lights/lighting_rig.h"
#include "graphics/render_entity.h"
#include "graphics/render_graph/render_graph.h"
namespace iris
{
Scene::Scene(RenderGraph *default_render_graph, bool *dirty_pipeline)
: entities_()
, render_graphs_()
, lighting_rig_()
, default_render_graph_(default_render_graph)
, dirty_pipeline_(dirty_pipeline)
{
lighting_rig_.ambient_light = std::make_unique<AmbientLight>(Colour{1.0f, 1.0f, 1.0f});
}
RenderEntity *Scene::add(RenderGraph *render_graph, std::unique_ptr<RenderEntity> entity)
{
*dirty_pipeline_ = true;
if (render_graph == nullptr)
{
render_graph = default_render_graph_;
entity->set_receive_shadow(false);
}
entities_.emplace_back(render_graph, std::move(entity));
return std::get<1>(entities_.back()).get();
}
RenderEntity *Scene::add_at_front(RenderGraph *render_graph, std::unique_ptr<RenderEntity> entity)
{
*dirty_pipeline_ = true;
if (render_graph == nullptr)
{
render_graph = default_render_graph_;
entity->set_receive_shadow(false);
}
entities_.insert(std::begin(entities_), {render_graph, std::move(entity)});
return std::get<1>(entities_.front()).get();
}
void Scene::remove(RenderEntity *entity)
{
*dirty_pipeline_ = true;
entities_.erase(
std::remove_if(
std::begin(entities_),
std::end(entities_),
[entity](const auto &e) { return std::get<1>(e).get() == entity; }),
std::end(entities_));
}
PointLight *Scene::add(std::unique_ptr<PointLight> light)
{
*dirty_pipeline_ = true;
lighting_rig_.point_lights.emplace_back(std::move(light));
return lighting_rig_.point_lights.back().get();
}
DirectionalLight *Scene::add(std::unique_ptr<DirectionalLight> light)
{
*dirty_pipeline_ = true;
lighting_rig_.directional_lights.emplace_back(std::move(light));
return lighting_rig_.directional_lights.back().get();
}
Colour Scene::ambient_light() const
{
return lighting_rig_.ambient_light->colour();
}
void Scene::set_ambient_light(const Colour &colour)
{
*dirty_pipeline_ = true;
lighting_rig_.ambient_light->set_colour(colour);
}
RenderGraph *Scene::render_graph(RenderEntity *entity) const
{
auto found = std::find_if(std::cbegin(entities_), std::cend(entities_), [entity](const auto &element) {
return std::get<1>(element).get() == entity;
});
expect(found == std::cend(entities_), "entity not in scene");
return std::get<0>(*found);
}
std::vector<std::tuple<RenderGraph *, std::unique_ptr<RenderEntity>>> &Scene::entities()
{
return entities_;
}
const std::vector<std::tuple<RenderGraph *, std::unique_ptr<RenderEntity>>> &Scene::entities() const
{
return entities_;
}
const LightingRig *Scene::lighting_rig() const
{
return &lighting_rig_;
}
}