Simulant  21.12-1292
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
renderable.h
1 /* * Copyright (c) 2011-2017 Luke Benstead https://simulant-engine.appspot.com
2  *
3  * This file is part of Simulant.
4  *
5  * Simulant is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Simulant is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with Simulant. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <memory>
22 #include "../../generic/property.h"
23 #include "../../types.h"
24 #include "../../interfaces.h"
25 #include "../../interfaces/boundable.h"
26 #include "render_queue.h"
27 #include "../../generic/uniquely_identifiable.h"
28 
29 namespace smlt {
30 
31 class VertexData;
32 class IndexData;
33 struct VertexRange;
34 
35 typedef sig::signal<void (RenderPriority, RenderPriority)> RenderPriorityChangedSignal;
36 
37 
39  DEFINE_SIGNAL(RenderPriorityChangedSignal, signal_render_priority_changed);
40 
41 public:
42  virtual ~HasMutableRenderPriority() {}
43 
44  void set_render_priority(RenderPriority priority) {
45  if(priority != render_priority_) {
46  auto old = render_priority_;
47  render_priority_ = priority;
48 
49  on_render_priority_changed(old, render_priority_);
50  signal_render_priority_changed_(old, render_priority_);
51  }
52  }
53 
54  virtual RenderPriority render_priority() const { return render_priority_; }
55 
56 private:
57  RenderPriority render_priority_ = RENDER_PRIORITY_MAIN;
58 
59  virtual void on_render_priority_changed(
60  RenderPriority old_priority, RenderPriority new_priority
61  ) {
62  _S_UNUSED(old_priority);
63  _S_UNUSED(new_priority);
64  }
65 };
66 
67 struct alignas(8) Renderable final {
68  MeshArrangement arrangement = MESH_ARRANGEMENT_TRIANGLES;
69  const VertexData* vertex_data = nullptr;
70 
71  const IndexData* index_data = nullptr;
72  std::size_t index_element_count = 0;
73 
74  const VertexRange* vertex_ranges = nullptr;
75  std::size_t vertex_range_count = 0;
76 
77  RenderPriority render_priority = RENDER_PRIORITY_MAIN;
78  Mat4 final_transformation;
79  Material* material = nullptr;
80  bool is_visible = true;
81 
82  LightPtr lights_affecting_this_frame[MAX_LIGHTS_PER_RENDERABLE];
83  uint8_t light_count = 0;
84 
85  smlt::Vec3 center;
86  float precedence = 0.0f;
87 };
88 
89 typedef std::shared_ptr<Renderable> RenderablePtr;
90 
91 }
smlt::VertexData
Definition: vertex_data.h:60
smlt::Mat4
Definition: mat4.h:35
smlt::Vec3
Definition: vec3.h:25
smlt::Material
Definition: material.h:199
smlt
Definition: animation.cpp:25
smlt::Light
Definition: light.h:34
smlt::HasMutableRenderPriority
Definition: renderable.h:38
smlt::VertexRange
Definition: submesh.h:32
smlt::IndexData
Definition: vertex_data.h:339
smlt::Renderable
Definition: renderable.h:67
smlt::sig::signal
Definition: signal.h:330