Ocular Engine
LightManager.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_CORE_LIGHT_MANAGER__H__
19 #define __H__OCULAR_CORE_LIGHT_MANAGER__H__
20 
21 #include "Scene/Light/LightSource.hpp"
22 #include "Scene/Light/GPULight.hpp"
23 #include "Math/Geometry/Frustum.hpp"
24 
25 #include <vector>
26 #include <unordered_map>
27 
28 //------------------------------------------------------------------------------------------
29 
34 namespace Ocular
35 {
36  namespace Graphics
37  {
38  class GPUBuffer;
39  }
40 
45  namespace Core
46  {
67  {
68  friend class LightSource;
69 
70  public:
71 
72  LightManager();
73  ~LightManager();
74 
82  void updateLights(bool cullVisible = true);
83 
88  void setAmbientLightColor(Color const& color);
89 
94 
99  void setAmbientLightIntensity(float intensity);
100 
104  float getAmbientLightIntensity() const;
105 
106  static const uint32_t LightBufferSlot;
107 
108  protected:
109 
110  void registerLightSource(LightSource* light);
111  void unregisterLightSource(LightSource* light);
112  void updateUUID(UUID const& uuid);
113 
114  void getVisibleLights(std::vector<LightSource*>& visibleLights, bool cull);
115  bool isLightVisible(LightSource const* light, Math::Frustum const& frustum) const;
116  bool isPointLightVisible(LightSource const* light, Math::Frustum const& frustum) const;
117  bool isSpotlightVisible(LightSource const* light, Math::Frustum const& frustum) const;
118  bool isDirectionalLightVisible(LightSource const* light, Math::Frustum const& frustum) const;
119 
120  void buildGPUBuffer(uint32_t visibleCount);
121  void fillGPUBuffer(std::vector<LightSource*> const& visibleLights);
122 
123  //------------------------------------------------------------
124 
125  std::unordered_map<std::string, LightSource*> m_Lights; // Key is UUID string
126  std::vector<GPULight> m_GPULights;
127 
128  Graphics::GPUBuffer* m_GPUBuffer; // Buffer to store light data for GPU use
129  uint32_t m_BufferLightCapacity; // Maximum number of lights the current GPU buffer can store
130  uint32_t m_PrevNumVisible; // Number of visible lights at last update (used to determine if we need to clear GPU buffer)
131 
132  GPULight m_GPUAmbientLight;
133 
134  private:
135  };
136  }
140 }
145 //------------------------------------------------------------------------------------------
146 
147 #endif
void setAmbientLightColor(Color const &color)
Definition: LightManager.cpp:70
Definition: Frustum.hpp:57
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
void updateLights(bool cullVisible=true)
Definition: LightManager.cpp:58
Definition: Color.hpp:40
A generic buffer that can be uploaded to the GPU.
Definition: GPUBuffer.hpp:81
Definition: LightManager.hpp:66
float getAmbientLightIntensity() const
Definition: LightManager.cpp:85
Definition: UUID.hpp:45
static const uint32_t LightBufferSlot
The GPUBuffer slot used by the LightManager to pass light data.
Definition: LightManager.hpp:106
Structure of generic light data passed to the GPU.
Definition: GPULight.hpp:44
void setAmbientLightIntensity(float intensity)
Definition: LightManager.cpp:80
Definition: LightSource.hpp:43
Color getAmbientLightColor() const
Definition: LightManager.cpp:75