Fillwave  10.0.0
Light.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/flc/rendering/Texture2DRenderable.h>
25 #include <flw/cmn/scene/Moveable.h>
26 #include <flw/cmn/IObserver.h>
27 
28 namespace flw {
29 
30 constexpr size_t MAX_LIGHTS = 4;
31 constexpr size_t USED_LIGHT_SLOTS = 4;
32 
38  GLfloat position[4];
39  GLfloat intensity[4];
40  GLfloat mvp[16];
41 };
42 
47  GLfloat mLinear;
48  GLfloat mExp;
49 };
50 
55 class Light : public Moveable, public IObserver {
56 public:
57  Light(glm::vec3 pos, glm::vec4 intensity, Moveable* observed);
58 
59  ~Light() override;
60 
61  Light(const Light&) = delete;
62 
63  Light operator=(const Light&) = delete;
64 
65  void updateFromFollowed();
66 
67  void setAttenuation(LightAttenuationData &attenuation);
68 
69  LightAttenuationData getAttenuation();
70 
71  void setIntensity(glm::vec4 intensity);
72 
73  glm::vec4 getIntensity();
74 
75  void log();
76 
77  void onDestroy(Observable* observable) override;
78 
79  void onChanged(Observable* observable) override;
80 
81 protected:
82  Moveable* mObserved;
83  bool mIsFollowedUpdated;
84  glm::vec4 mIntensity;
85  LightAttenuationData mAttenuation;
86 };
87 
88 } /* flw */
Definition: Aliases.h:30
Light attenuation data.
Definition: Light.h:46
Implementation of Observer pattern.
Definition: IObserver.h:32
Base for every object which has a 3D position.
Definition: Moveable.h:43
Implementation of Observable pattern.
Definition: Observable.h:34
Light UBO data.
Definition: Light.h:37
Base for all lights.
Definition: Light.h:55