Radium Engine  1.5.0
DebugRender.hpp
1 #pragma once
2 
3 #include <Engine/RaEngine.hpp>
4 
5 #include <memory>
6 #include <vector>
7 
8 #include <Core/Containers/VectorArray.hpp>
9 #include <Core/Types.hpp>
10 #include <Core/Utils/Color.hpp>
11 #include <Core/Utils/Singleton.hpp>
12 #include <Engine/Data/ShaderProgram.hpp>
13 
14 namespace Ra {
15 namespace Engine {
16 namespace Data {
17 class AttribArrayDisplayable;
18 class ShaderProgram;
19 } // namespace Data
20 
21 namespace Rendering {
22 
26 class RA_ENGINE_API DebugRender final
27 {
28  RA_SINGLETON_INTERFACE( DebugRender );
29 
30  public:
31  DebugRender();
32  ~DebugRender();
33 
34  void initialize();
35  void render( const Core::Matrix4& view, const Core::Matrix4& proj );
36 
37  void
38  addLine( const Core::Vector3& from, const Core::Vector3& to, const Core::Utils::Color& color );
39  void addPoint( const Core::Vector3& p, const Core::Utils::Color& color );
40  void addPoints( const Core::Vector3Array& p, const Core::Utils::Color& color );
41  void addPoints( const Core::Vector3Array& p, const Core::Vector4Array& colors );
42  void addMesh( const std::shared_ptr<Data::AttribArrayDisplayable>& mesh,
43  const Core::Transform& transform = Core::Transform::Identity() );
44 
45  // Shortcuts
46  void addCross( const Core::Vector3& position, Scalar size, const Core::Utils::Color& color );
47 
48  void addSphere( const Core::Vector3& center, Scalar radius, const Core::Utils::Color& color );
49 
50  void addCircle( const Core::Vector3& center,
51  const Core::Vector3& normal,
52  Scalar radius,
53  const Core::Utils::Color& color );
54 
55  void addFrame( const Core::Transform& transform, Scalar size );
56 
57  void addTriangle( const Core::Vector3& p0,
58  const Core::Vector3& p1,
59  const Core::Vector3& p2,
60  const Core::Utils::Color& color );
61 
62  void addAABB( const Core::Aabb& box, const Core::Utils::Color& color );
63 
64  void addOBB( const Core::Aabb& box,
65  const Core::Transform& transform,
66  const Core::Utils::Color& color );
67 
68  private:
69  struct Line {
70  Line( const Core::Vector3& la, const Core::Vector3& lb, const Core::Utils::Color& lcol ) :
71  a { la }, b { lb }, col { lcol } {}
72 
73  Core::Vector3 a, b;
75  };
76 
77  struct Point {
78  Core::Vector3 p;
79  Core::Vector3 c;
80  };
81 
82  struct DbgMesh {
83  std::shared_ptr<Data::AttribArrayDisplayable> mesh;
84  Core::Transform transform;
85  };
86 
87  void renderLines( const Core::Matrix4f& view, const Core::Matrix4f& proj );
88  void renderPoints( const Core::Matrix4f& view, const Core::Matrix4f& proj );
89  void renderMeshes( const Core::Matrix4f& view, const Core::Matrix4f& proj );
90 
91  private:
92  // these shaders are owned by the manager, just keep a raw copy, since the
93  // manager is available during whole execution.
94  const Data::ShaderProgram* m_lineProg { nullptr };
95  const Data::ShaderProgram* m_pointProg { nullptr };
96  const Data::ShaderProgram* m_meshProg { nullptr };
97 
98  std::vector<Line> m_lines;
99  std::vector<DbgMesh> m_meshes;
100 
101  std::vector<Point> m_points;
102 };
103 
104 } // namespace Rendering
105 } // namespace Engine
106 } // namespace Ra
Definition: Cage.cpp:3