Fillwave  10.0.0
LightSystem.h
1 #pragma once
2 
3 /*
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2018 Filip Wasil and Fillwave community members
7  *
8  * Permission is hereby granted, free of charge, to any person
9  * obtaining a copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include <flw/flf/management/base/TCacheVector.h>
25 #include <flw/flf/space/LightDirectional.h>
26 #include <flw/flf/space/LightPoint.h>
27 #include <flw/flf/space/LightSpot.h>
28 
29 namespace flw {
30 class Engine;
31 namespace flf {
32 
33 using CacheSpotLights = TManager<LightSpot, MAX_LIGHTS, flc::Texture2DRenderable*, glm::vec3, glm::quat, glm::vec4, Moveable*>;
34 using CacheDirectionalLights = TManager<LightDirectional, MAX_LIGHTS, flc::Texture2DRenderable*, glm::vec3, glm::quat, glm::vec4, Moveable*>;
35 using CachePointLights = TManager<LightPoint, MAX_LIGHTS, flc::Texture3DRenderable*, glm::vec3, glm::vec4, Moveable*>;
36 
40 class LightSystem final {
41 public:
42  LightSystem();
43 
44  CacheSpotLights mLightsSpot;
45  CacheDirectionalLights mLightsDirectional;
46  CachePointLights mLightsPoint;
47 
48  bool isLightsRefresh() const;
49 
50  void resetLightsRefresh();
51 
52  void removeLights();
53 
54  void updateLightEntities();
55 
56  void pushLightUniformsDR();
57 
58  void pushLightUniforms(flc::Program *program);
59 
60  void pushLightUniformBuffers(flc::Program *program);
61 
62  void clear();
63 
64  void bindShadowmaps();
65 
66  /* Deferred rendering */
67  void updateDeferredBufferSpot(GLuint lightID, flc::Program *program, GLint currentShadowUnit);
68 
69  void updateDeferredBufferDirectional(GLuint lightID, flc::Program *program, GLint currentShadowUnit);
70 
71  void updateDeferredBufferPoint(GLuint lightID, flc::Program *program, GLint currentShadowUnit);
72 
73 private:
74  std::array<LighUniformData, MAX_LIGHTS> mLightBufferData;
75 
76  bool isRefreshLightSpot() const;
77 
78  bool isRefreshLightDirectional() const;
79 
80  bool isRefreshLightPoint() const;
81 
82  GLfloat computePointLightBoundingSphere(LightPoint *light);
83 };
84 
85 } /* flf */
86 } /* flw */
Definition: Aliases.h:30
Light system knows about all light related stuff.
Definition: LightSystem.h:40
Single GLSL program object.
Definition: Program.h:37
Not used.
Definition: LightPoint.h:37