Ocean
GLESLightSource.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_RENDERING_GLES_LIGHT_SOURCE_H
9 #define META_OCEAN_RENDERING_GLES_LIGHT_SOURCE_H
10 
14 
17 
19 
20 #include <vector>
21 
22 namespace Ocean
23 {
24 
25 namespace Rendering
26 {
27 
28 namespace GLESceneGraph
29 {
30 
31 // Forward declaration.
32 class GLESLightSource;
33 
34 /**
35  * Definition of a pair combinding light sources with transformation matrices.
36  * @ingroup renderinggles
37  */
38 typedef std::pair<SmartObjectRef<GLESLightSource>, HomogenousMatrix4> LightPair;
39 
40 /**
41  * Definition of a set holding light sources.
42  * @ingroup renderinggles
43  */
44 typedef std::vector<LightPair> Lights;
45 
46 /**
47  * This class is the base class for all GLESceneGraph light sources.
48  * @ingroup renderinggles
49  */
50 class OCEAN_RENDERING_GLES_EXPORT GLESLightSource :
51  virtual public GLESObject,
52  virtual public LightSource
53 {
54  public:
55 
56  /**
57  * Returns the ambient color of this light source.
58  * @see LightSource::ambientColor().
59  */
60  RGBAColor ambientColor() const override;
61 
62  /**
63  * Returns the diffuse color of this light source.
64  * @see LightSource::diffuseColor().
65  */
66  RGBAColor diffuseColor() const override;
67 
68  /**
69  * Returns the specular color of this light source.
70  * @see LightSource::specularColor().
71  */
72  RGBAColor specularColor() const override;
73 
74  /**
75  * Returns the intensity of this light source.
76  * @see LightSource::intensity().
77  */
78  Scalar intensity() const override;
79 
80  /**
81  * Returns the transformation type of this light.
82  * @see LightSource::transformationType().
83  */
85 
86  /**
87  * Returns whether this light source is enabled.
88  * @see LightSource::enabled().
89  */
90  bool enabled() const override;
91 
92  /**
93  * Gets all color values of the light at once.
94  * @see LightSource::get().
95  */
96  void get(RGBAColor& ambient, RGBAColor& diffuse, RGBAColor& specular, Scalar& intensity) override;
97 
98  /**
99  * Sets the ambient color of the light source.
100  * @see LightSource::setAmbientcolor().
101  */
102  bool setAmbientColor(const RGBAColor& color) override;
103 
104  /**
105  * Sets the diffuse color of the light source.
106  * @see LightSource::setDiffuseColor().
107  */
108  bool setDiffuseColor(const RGBAColor& color) override;
109 
110  /**
111  * Sets the specular color of the light source.
112  * @see LightSource::setSpecularColor().
113  */
114  bool setSpecularColor(const RGBAColor& color) override;
115 
116  /**
117  * Sets the specular exponent of this material.
118  * @see LightSource::setIntensity().
119  */
120  bool setIntensity(const Scalar intensity) override;
121 
122  /**
123  * Sets all color values of the light source at once.
124  * @see LightSource::set().
125  */
126  bool set(const RGBAColor& ambient, const RGBAColor& diffuse, const RGBAColor& specular, const Scalar intensity) override;
127 
128  /**
129  * Sets the transformation type of this light.
130  * @see LightSource::setTransformationType().
131  */
132  void setTransformationType(const TransformationType transformationType) override;
133 
134  /**
135  * Sets whether the light source is enabled.
136  * @see LightSource::setEnabled().
137  */
138  void setEnabled(const bool state) override;
139 
140  /**
141  * Binds this light source to the shader.
142  * @param shaderProgram Shader program receiving the light source information
143  * @param camera_T_model The transformation between model and camera (aka Modelview matrix), must be valid
144  * @param camera_T_world The transformation between world and camera,(aka View matrix) must be valid
145  * @param normalMatrix Normal transformation matrix with is the transposed inverse of the upper 3x3 model Modelview matrix, must be valid
146  * @param index Light source index inside the shader
147  */
148  virtual void bindLight(GLESShaderProgram& shaderProgram, const HomogenousMatrix4& camera_T_model, const HomogenousMatrix4& camera_T_world, const SquareMatrix3& normalMatrix, const unsigned int index);
149 
150  protected:
151 
152  /**
153  * Creates a new GLESceneGraph light source.
154  */
156 
157  /**
158  * Destructs a GLESceneGraph light source.
159  */
160  ~GLESLightSource() override;
161 
162  protected:
163 
164  /// Ambient light color.
166 
167  /// Diffuse light color.
169 
170  /// Specular light color.
172 
173  /// Light intensity.
175 
176  /// The transformation type of this light source.
177  TransformationType transformationType_ = TT_PARENT;
178 
179  /// Determines whether the light is enabled.
180  bool enabled_;
181 };
182 
183 }
184 
185 }
186 
187 }
188 
189 #endif // META_OCEAN_RENDERING_GLES_LIGHT_SOURCE_H
This class implements a color defined by red, green, blue and alpha parameters.
Definition: RGBAColor.h:41
This class is the base class for all GLESceneGraph light sources.
Definition: GLESLightSource.h:53
GLESLightSource()
Creates a new GLESceneGraph light source.
void get(RGBAColor &ambient, RGBAColor &diffuse, RGBAColor &specular, Scalar &intensity) override
Gets all color values of the light at once.
bool setDiffuseColor(const RGBAColor &color) override
Sets the diffuse color of the light source.
RGBAColor diffuseColor() const override
Returns the diffuse color of this light source.
bool enabled_
Determines whether the light is enabled.
Definition: GLESLightSource.h:180
virtual void bindLight(GLESShaderProgram &shaderProgram, const HomogenousMatrix4 &camera_T_model, const HomogenousMatrix4 &camera_T_world, const SquareMatrix3 &normalMatrix, const unsigned int index)
Binds this light source to the shader.
bool setIntensity(const Scalar intensity) override
Sets the specular exponent of this material.
bool enabled() const override
Returns whether this light source is enabled.
TransformationType transformationType() const override
Returns the transformation type of this light.
void setEnabled(const bool state) override
Sets whether the light source is enabled.
RGBAColor ambientColor_
Ambient light color.
Definition: GLESLightSource.h:165
bool set(const RGBAColor &ambient, const RGBAColor &diffuse, const RGBAColor &specular, const Scalar intensity) override
Sets all color values of the light source at once.
Scalar intensity() const override
Returns the intensity of this light source.
~GLESLightSource() override
Destructs a GLESceneGraph light source.
bool setAmbientColor(const RGBAColor &color) override
Sets the ambient color of the light source.
RGBAColor specularColor() const override
Returns the specular color of this light source.
RGBAColor ambientColor() const override
Returns the ambient color of this light source.
void setTransformationType(const TransformationType transformationType) override
Sets the transformation type of this light.
RGBAColor diffuseColor_
Diffuse light color.
Definition: GLESLightSource.h:168
Scalar intensity_
Light intensity.
Definition: GLESLightSource.h:174
bool setSpecularColor(const RGBAColor &color) override
Sets the specular color of the light source.
RGBAColor specularColor_
Specular light color.
Definition: GLESLightSource.h:171
This class is the base class for all GLESceneGraph objects.
Definition: GLESObject.h:57
This class implements a container for an OpenGL ES shader program.
Definition: GLESShaderProgram.h:53
This is the base class for all lights.
Definition: LightSource.h:38
TransformationType
Defines different transformation types.
Definition: LightSource.h:45
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< LightPair > Lights
Definition of a set holding light sources.
Definition: GLESLightSource.h:44
std::pair< SmartObjectRef< GLESLightSource >, HomogenousMatrix4 > LightPair
Definition of a pair combinding light sources with transformation matrices.
Definition: GLESLightSource.h:32
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15