Radium Engine  1.5.0
RenderObject.hpp
1 #pragma once
2 
3 #include <Engine/RaEngine.hpp>
4 
5 #include <memory>
6 #include <mutex>
7 #include <string>
8 
9 #include <Core/Types.hpp>
10 #include <Core/Utils/IndexedObject.hpp>
11 
12 #include <Engine/Data/ShaderProgram.hpp>
13 #include <Engine/Rendering/RenderObjectTypes.hpp>
14 #include <Engine/Rendering/RenderTechnique.hpp>
15 
16 namespace Ra {
17 namespace Engine {
18 
19 namespace Scene {
20 class Component;
21 } // namespace Scene
22 
23 namespace Data {
24 class Displayable;
25 class Material;
26 struct ViewingParameters;
27 class RenderParameters;
28 } // namespace Data
29 
30 namespace Rendering {
31 
36 class RA_ENGINE_API RenderObject final : public Core::Utils::IndexedObject
37 {
38  public:
39  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
40 
52  RenderObject( const std::string& name,
53  Scene::Component* comp,
54  const RenderObjectType& type,
55  int lifetime = -1 );
56 
57  ~RenderObject() override;
58 
85  static RenderObject* createRenderObject(
86  const std::string& name,
87  Scene::Component* comp,
88  const RenderObjectType& type,
89  std::shared_ptr<Data::Displayable> mesh,
91 
95  void updateGL();
96 
99  const std::string& getName() const;
100  const Scene::Component* getComponent() const;
101  Scene::Component* getComponent();
102 
103  const RenderObjectType& getType() const;
104  void setType( const RenderObjectType& t );
105 
106  void setVisible( bool visible );
107  void toggleVisible();
108  bool isVisible() const;
109 
110  void setPickable( bool pickable );
111  void togglePickable();
112  bool isPickable() const;
113 
114  void setXRay( bool xray );
115  void toggleXRay();
116  bool isXRay() const;
117 
118  void setTransparent( bool transparent );
119  void toggleTransparent();
120  bool isTransparent() const;
121 
123  void setColoredByVertexAttrib( bool state );
125  void toggleColoredByVertexAttrib();
127  bool isColoredByVertexAttrib() const;
128 
129  bool isDirty() const;
130 
131  void setRenderTechnique( std::shared_ptr<RenderTechnique> technique );
132  std::shared_ptr<const RenderTechnique> getRenderTechnique() const;
133  std::shared_ptr<RenderTechnique> getRenderTechnique();
134 
135  void setMaterial( std::shared_ptr<Data::Material> material );
136  std::shared_ptr<const Data::Material> getMaterial() const;
137  std::shared_ptr<Data::Material> getMaterial();
138 
139  void setMesh( std::shared_ptr<Data::Displayable> mesh );
140  std::shared_ptr<const Data::Displayable> getMesh() const;
141  const std::shared_ptr<Data::Displayable>& getMesh();
142 
143  Core::Transform getTransform() const;
144  Core::Matrix4 getTransformAsMatrix() const;
145 
146  Core::Aabb computeAabb();
147 
148  void setLocalTransform( const Core::Transform& transform );
149  void setLocalTransform( const Core::Matrix4& transform );
150  const Core::Transform& getLocalTransform() const;
151  const Core::Matrix4& getLocalTransformAsMatrix() const;
153 
157  void hasBeenRenderedOnce();
158 
160  void hasExpired();
161 
163  void setLifetime( int t );
164 
172  void render( const Data::RenderParameters& lightParams,
173  const Data::ViewingParameters& viewParams,
174  const Data::ShaderProgram* shader,
175  const Data::RenderParameters& shaderParams );
176 
184  void render( const Data::RenderParameters& lightParams,
185  const Data::ViewingParameters& viewParams,
186  Core::Utils::Index passId = DefaultRenderingPasses::LIGHTING_OPAQUE );
187 
188  void invalidateAabb();
189 
190  private:
191  Core::Transform m_localTransform { Core::Transform::Identity() };
192 
193  Scene::Component* m_component { nullptr };
194  std::string m_name {};
195 
196  RenderObjectType m_type { RenderObjectType::Geometry };
197  std::shared_ptr<RenderTechnique> m_renderTechnique { nullptr };
198  std::shared_ptr<Data::Displayable> m_mesh { nullptr };
199  std::shared_ptr<Data::Material> m_material { nullptr };
200 
201  mutable std::mutex m_updateMutex;
202 
203  int m_lifetime { -1 };
204  bool m_visible { true };
205  bool m_pickable { true };
206  bool m_xray { false };
207  bool m_transparent { false };
208  bool m_dirty { true };
209  bool m_hasLifetime { false };
210 
211  bool m_isAabbValid { false };
212  Core::Aabb m_aabb;
213  int m_aabbObserverIndex { -1 };
214 };
215 
216 } // namespace Rendering
217 } // namespace Engine
218 } // namespace Ra
static RenderTechnique createDefaultRenderTechnique()
A component is an element that can be updated by a system. It is also linked to some other components...
Definition: Component.hpp:31
Definition: Cage.cpp:3
the set of viewing parameters extracted from the camera and given to the renderer