Nymph Game Engine
Chaiscript based Game Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
renderable.h
Go to the documentation of this file.
1 #ifndef RENDERABLE_H
2 #define RENDERABLE_H
3 #include <glm/glm.hpp>
4 #include <map>
5 #include <memory>
6 #include <set>
7 #include "component.h"
8 #include "vertex_data.h"
9 #include "shader.h"
10 #include "base_texture.h"
11 #include "transform.h"
12 #include "light.h"
13 #include "events/observer.h"
14 #include "uniform.h"
15 //= SCRIPTABLE
16 //= SCRIPTABLE BASES Component
17 
18 namespace Graphics {
22  class Renderable : public Component {
23  private:
24  unsigned int vertex_array_object;
25  std::shared_ptr<Shader> shader;
26  std::map<unsigned int, std::shared_ptr<BaseTexture>> textures;
27 
28  VertexData vertex_data;
29 
30  bool light_reactive;
31  std::list<std::shared_ptr<Light>> influencing_lights;
32  glm::vec3 ambient_light;
33  float ambient_intensity;
34 
35  void setUniforms();
36  protected:
37  std::set<Uniform> uniforms;
38  void setUniform(const Uniform& uniform) noexcept;
40 
41  public:
48  Renderable(const unsigned int vertex_array_object, const VertexData& vertex_data);
56  static std::shared_ptr<Renderable> create(const VertexData& vertex_data);
57 
58  //Remove copy constructor and assignment
59  Renderable(const Renderable&) = delete;
60  Renderable operator=(Renderable&) = delete;
61 
62  Renderable(Renderable&& renderable);
63  Renderable& operator=(Renderable&& renderable);
64 
65  virtual ~Renderable();
66 
67  //= BEGIN SCRIPTABLE
68 
74  void setShader(std::shared_ptr<Shader> shader_object) noexcept;
80  std::shared_ptr<Shader> getShader() const noexcept;
81 
89  void addTexture(const unsigned int unit, const std::string uniform_name, std::shared_ptr<BaseTexture> texture_object) noexcept;
95  void removeTexture(const unsigned int unit);
101  std::map<unsigned int, std::shared_ptr<BaseTexture>> getTextures() const noexcept;
102 
108  void setLightReactive(const bool reactive) noexcept;
114  bool isLightReactive() const noexcept;
115 
121  void setAmbientLight(const glm::vec3 color) noexcept;
127  glm::vec3 getAmbientLight() const noexcept;
133  void setAmbientIntensity(const float intensity) noexcept;
139  float getAmbientIntensity() const noexcept;
140 
146  void addInfluencingLight(std::shared_ptr<Light> light) noexcept;
150  void clearInfluencingLights();
151 
157  virtual std::string to_string() const noexcept override;
158 
159  virtual std::string className() const noexcept override;
160  //= END SCRIPTABLE
161 
167  float highestZ() const noexcept;
168 
174  unsigned int getVertexArrayBinding() const noexcept;
175 
181  VertexData getVertexData() const noexcept;
182 
183  virtual void onDestroy() override;
184  virtual void onStart() override;
185  virtual bool onUpdate(const double delta) override;
186 
187  void handleQueuedEvent(std::shared_ptr<Events::Event> event) override;
188  void onNotifyNow(std::shared_ptr<Events::Event> event) override;
189  virtual unsigned long long getValueForSorting() const noexcept override;
190 
191  virtual void log(el::base::type::ostream_t& os) const override;
192  };
193 }
194 #endif
virtual void onDestroy() override
Called when the engine is shutting down.
Definition: renderable.cpp:146
virtual std::string className() const noexceptoverride
Returns a string representing the class name.
Definition: renderable.cpp:255
void addTexture(const unsigned int unit, const std::string uniform_name, std::shared_ptr< BaseTexture > texture_object) noexcept
Adds a texture.
Definition: renderable.cpp:63
void setAmbientIntensity(const float intensity) noexcept
Sets the ambient intensity.
Definition: renderable.cpp:95
Base Class for all components.
Definition: component.h:20
float highestZ() const noexcept
The highest possible z value in the renderable.
Definition: renderable.cpp:111
Class for shader uniform.
Definition: uniform.h:10
void setLightReactive(const bool reactive) noexcept
Sets if the renderable should be light reactive.
Definition: renderable.cpp:79
float getAmbientIntensity() const noexcept
Gets the ambient intensity.
Definition: renderable.cpp:99
Class for renderable.
Definition: renderable.h:22
bool isLightReactive() const noexcept
Determines if light reactive.
Definition: renderable.cpp:83
std::set< Uniform > uniforms
Definition: renderable.h:37
void setAmbientLight(const glm::vec3 color) noexcept
Sets the ambient light.
Definition: renderable.cpp:87
void clearInfluencingLights()
Clears all influencing lights.
Definition: renderable.cpp:107
virtual bool onUpdate(const double delta) override
Called every engine loop.
Definition: renderable.cpp:165
Class for vertex data.
Definition: vertex_data.h:17
glm::vec3 getAmbientLight() const noexcept
Gets the ambient light.
Definition: renderable.cpp:91
Renderable operator=(Renderable &)=delete
virtual void onStart() override
Called when the engine starts and when a new scene is loaded.
Definition: renderable.cpp:152
Class for base texture.
Definition: base_texture.h:16
std::map< unsigned int, std::shared_ptr< BaseTexture > > getTextures() const noexcept
Gets the textures.
Definition: renderable.cpp:75
void setShader(std::shared_ptr< Shader > shader_object) noexcept
Sets the shader.
Definition: renderable.cpp:55
virtual void log(el::base::type::ostream_t &os) const override
Definition: renderable.cpp:269
virtual unsigned long long getValueForSorting() const noexceptoverride
Gets the value for sorting.
Definition: renderable.cpp:250
VertexData getVertexData() const noexcept
Gets the vertex data.
Definition: renderable.cpp:119
void removeTexture(const unsigned int unit)
Removes a texture.
Definition: renderable.cpp:71
std::shared_ptr< Shader > getShader() const noexcept
Gets the shader.
Definition: renderable.cpp:59
Class for light.
Definition: light.h:15
virtual ~Renderable()
Definition: renderable.cpp:51
static std::shared_ptr< Renderable > create(const VertexData &vertex_data)
Renderable factory function.
Definition: renderable.cpp:30
void setUniform(const Uniform &uniform) noexcept
Definition: renderable.cpp:132
void onNotifyNow(std::shared_ptr< Events::Event > event) override
When receiving an event that is immediate, onNotifyNow is used. It acts as an interrupt to make sure ...
Definition: renderable.cpp:246
void addInfluencingLight(std::shared_ptr< Light > light) noexcept
Adds an influencing light.
Definition: renderable.cpp:103
Renderable()
Definition: renderable.h:39
virtual std::string to_string() const noexceptoverride
Returns a string representation of the object.
Definition: renderable.cpp:259
void handleQueuedEvent(std::shared_ptr< Events::Event > event) override
HandleQueuedEvent allows derived classes to define behaviour for when queuedEvents are received...
Definition: renderable.cpp:226
unsigned int getVertexArrayBinding() const noexcept
Gets the vertex array binding.
Definition: renderable.cpp:115