1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_LIGHT_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_LIGHT_ATTACHMENT_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://floralicense.org/license/
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
21 #include <dali/public-api/math/rect.h>
22 #include <dali/public-api/math/vector2.h>
23 #include <dali/internal/common/buffer-index.h>
24 #include <dali/internal/common/event-to-update.h>
25 #include <dali/internal/event/modeling/light-impl.h>
26 #include <dali/internal/update/node-attachments/node-attachment.h>
27 #include <dali/internal/update/controllers/light-controller.h>
35 // value types used by messages
36 template <> struct ParameterType< LightType > : public BasicType< LightType > {};
41 class RenderableAttachment;
44 * An attachment for light objects and their properties.
46 class LightAttachment : public NodeAttachment
50 * Construct a new LightAttachment.
51 * @return a new LightAttachment.
53 static LightAttachment* New()
55 return new LightAttachment();
59 * @copydoc NodeAttachment::ConnectToSceneGraph().
61 virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex );
64 * @copydoc NodeAttachment::DisconnectFromSceneGraph().
66 virtual void OnDestroy();
71 virtual ~LightAttachment();
74 * @copydoc NodeAttachment::GetRenderable.
75 * @return Always NULL.
77 virtual RenderableAttachment* GetRenderable()
83 * @copydoc Dali::Internal::LightAttachment::SetLight
85 void SetLight(Internal::LightPtr light)
87 mLight = new Internal::Light(*light.Get());
88 mUpdateRequired = true;
92 * @copydoc Dali::Internal::LightAttachment::GetLight
94 Internal::LightPtr GetLight() const
100 * @copydoc Dali::Light::SetName
102 void SetName(const std::string& name)
104 mLight->SetName(name);
107 * @copydoc Dali::Light::GetName
109 const std::string& GetName() const
111 return mLight->GetName();
115 * @copydoc Dali::Light::SetType
117 void SetType(Dali::LightType type)
119 if (mLight->GetType() != type)
121 mLight->SetType(type);
122 mUpdateRequired = true;
127 * @copydoc Dali::Light::GetType
129 Dali::LightType GetType() const
131 return mLight->GetType();
135 * @copydoc Dali::Light::SetFallOff
137 void SetFallOff(const Vector2& fallOff)
139 if (mLight->GetFallOff() != fallOff)
141 mLight->SetFallOff(fallOff);
142 mUpdateRequired = true;
147 * @copydoc Dali::Light::GetFallOff
149 const Vector2& GetFallOff() const
151 return mLight->GetFallOff();
155 * @copydoc Dali::Light::SetSpotAngle
157 void SetSpotAngle(const Vector2& angle)
159 if (mLight->GetSpotAngle() != angle)
161 mLight->SetSpotAngle(angle);
162 mUpdateRequired = true;
167 * @copydoc Dali::Light::GetSpotAngle
169 const Vector2& GetSpotAngle() const
171 return mLight->GetSpotAngle();
175 * @copydoc Dali::Light::SetAmbientColor
177 void SetAmbientColor(const Vector3& color)
179 if (mLight->GetAmbientColor() != color)
181 mLight->SetAmbientColor(color);
182 mUpdateRequired = true;
187 * @copydoc Dali::Light::GetAmbientColor
189 const Vector3& GetAmbientColor() const
191 return mLight->GetAmbientColor();
195 * @copydoc Dali::Light::SetDiffuseColor
197 void SetDiffuseColor(const Vector3& color)
199 if (mLight->GetDiffuseColor() != color)
201 mLight->SetDiffuseColor(color);
202 mUpdateRequired = true;
207 * @copydoc Dali::Light::GetDiffuseColor
209 const Vector3& GetDiffuseColor() const
211 return mLight->GetDiffuseColor();
215 * @copydoc Dali::Light::SetSpecularColor
217 void SetSpecularColor(const Vector3& color)
219 if (mLight->GetSpecularColor() != color)
221 mLight->SetSpecularColor(color);
222 mUpdateRequired = true;
227 * @copydoc Dali::Light::GetSpecularColor
229 const Vector3& GetSpecularColor() const
231 return mLight->GetSpecularColor();
235 * @copydoc Dali::Light::SetDirection
237 void SetDirection(const Vector3& direction)
239 if (mLight->GetDirection() != direction)
241 mLight->SetDirection(direction);
242 mUpdateRequired = true;
247 * @copydoc Dali::Light::GetDirection
249 const Vector3& GetDirection() const
251 return mLight->GetDirection();
256 * @copydoc Dali::LightActor::SetActive
258 void SetActive(bool active)
260 Node& lightNode(GetParent());
263 mLightController->AddLight(lightNode); // Add to list of active lights
267 mLightController->RemoveLight(lightNode); // Remove from list of active lights
271 virtual void Update( BufferIndex /*updateBufferIndex*/, const Node& /*owningNode*/, int /*nodeDirtyFlags*/ )
275 mUpdateRequired = false;
282 * Protected constructor; see also LightAttachment::New().
289 LightAttachment(const LightAttachment&);
292 LightAttachment& operator=(const LightAttachment& rhs);
295 Internal::LightPtr mLight;
296 bool mUpdateRequired; ///< This is set to true if the projection matrix requires an update
297 LightController* mLightController; ///< required to add / remove lights
300 // Messages for LightAttachment
302 inline void SetLightMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Internal::LightPtr& parameter )
304 typedef MessageValue1< LightAttachment, Internal::LightPtr > LocalType;
306 // Reserve some memory inside the message queue
307 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
309 // Construct message in the message queue memory; note that delete should not be called on the return value
310 new (slot) LocalType( &attachment, &LightAttachment::SetLight, parameter );
313 inline void SetNameMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const std::string& parameter )
315 typedef MessageValue1< LightAttachment, std::string > LocalType;
317 // Reserve some memory inside the message queue
318 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
320 // Construct message in the message queue memory; note that delete should not be called on the return value
321 new (slot) LocalType( &attachment, &LightAttachment::SetName, parameter );
324 inline void SetTypeMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, LightType parameter )
326 typedef MessageValue1< LightAttachment, LightType > LocalType;
328 // Reserve some memory inside the message queue
329 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
331 // Construct message in the message queue memory; note that delete should not be called on the return value
332 new (slot) LocalType( &attachment, &LightAttachment::SetType, parameter );
335 inline void SetFallOffMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector2 ¶meter )
337 typedef MessageValue1< LightAttachment, Vector2 > LocalType;
339 // Reserve some memory inside the message queue
340 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
342 // Construct message in the message queue memory; note that delete should not be called on the return value
343 new (slot) LocalType( &attachment, &LightAttachment::SetFallOff, parameter );
346 inline void SetSpotAngleMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector2 ¶meter )
348 typedef MessageValue1< LightAttachment, Vector2 > LocalType;
350 // Reserve some memory inside the message queue
351 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
353 // Construct message in the message queue memory; note that delete should not be called on the return value
354 new (slot) LocalType( &attachment, &LightAttachment::SetSpotAngle, parameter );
357 inline void SetAmbientColorMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector3 ¶meter )
359 typedef MessageValue1< LightAttachment, Vector3 > LocalType;
361 // Reserve some memory inside the message queue
362 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
364 // Construct message in the message queue memory; note that delete should not be called on the return value
365 new (slot) LocalType( &attachment, &LightAttachment::SetAmbientColor, parameter );
368 inline void SetDiffuseColorMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector3 ¶meter )
370 typedef MessageValue1< LightAttachment, Vector3 > LocalType;
372 // Reserve some memory inside the message queue
373 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
375 // Construct message in the message queue memory; note that delete should not be called on the return value
376 new (slot) LocalType( &attachment, &LightAttachment::SetDiffuseColor, parameter );
379 inline void SetSpecularColorMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector3 ¶meter )
381 typedef MessageValue1< LightAttachment, Vector3 > LocalType;
383 // Reserve some memory inside the message queue
384 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
386 // Construct message in the message queue memory; note that delete should not be called on the return value
387 new (slot) LocalType( &attachment, &LightAttachment::SetSpecularColor, parameter );
390 inline void SetDirectionMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector3 ¶meter )
392 typedef MessageValue1< LightAttachment, Vector3 > LocalType;
394 // Reserve some memory inside the message queue
395 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
397 // Construct message in the message queue memory; note that delete should not be called on the return value
398 new (slot) LocalType( &attachment, &LightAttachment::SetDirection, parameter );
401 inline void SetActiveMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, bool parameter )
403 typedef MessageValue1< LightAttachment, bool > LocalType;
405 // Reserve some memory inside the message queue
406 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
408 // Construct message in the message queue memory; note that delete should not be called on the return value
409 new (slot) LocalType( &attachment, &LightAttachment::SetActive, parameter );
412 } // namespace SceneGraph
414 } // namespace Internal
418 #endif // __DALI_INTERNAL_SCENE_GRAPH_LIGHT_ATTACHMENT_H__