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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/math/rect.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/internal/common/buffer-index.h>
25 #include <dali/internal/common/event-to-update.h>
26 #include <dali/internal/event/modeling/light-impl.h>
27 #include <dali/internal/update/node-attachments/node-attachment.h>
28 #include <dali/internal/update/controllers/light-controller.h>
36 // value types used by messages
37 template <> struct ParameterType< LightType > : public BasicType< LightType > {};
42 class RenderableAttachment;
45 * An attachment for light objects and their properties.
47 class LightAttachment : public NodeAttachment
51 * Construct a new LightAttachment.
52 * @return a new LightAttachment.
54 static LightAttachment* New()
56 return new LightAttachment();
60 * @copydoc NodeAttachment::ConnectToSceneGraph().
62 virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex );
65 * @copydoc NodeAttachment::DisconnectFromSceneGraph().
67 virtual void OnDestroy();
72 virtual ~LightAttachment();
75 * @copydoc NodeAttachment::GetRenderable.
76 * @return Always NULL.
78 virtual RenderableAttachment* GetRenderable()
84 * @copydoc Dali::Internal::LightAttachment::SetLight
86 void SetLight(Internal::LightPtr light)
88 mLight = new Internal::Light(*light.Get());
89 mUpdateRequired = true;
93 * @copydoc Dali::Internal::LightAttachment::GetLight
95 Internal::LightPtr GetLight() const
101 * @copydoc Dali::Light::SetName
103 void SetName(const std::string& name)
105 mLight->SetName(name);
108 * @copydoc Dali::Light::GetName
110 const std::string& GetName() const
112 return mLight->GetName();
116 * @copydoc Dali::Light::SetType
118 void SetType(Dali::LightType type)
120 if (mLight->GetType() != type)
122 mLight->SetType(type);
123 mUpdateRequired = true;
128 * @copydoc Dali::Light::GetType
130 Dali::LightType GetType() const
132 return mLight->GetType();
136 * @copydoc Dali::Light::SetFallOff
138 void SetFallOff(const Vector2& fallOff)
140 if (mLight->GetFallOff() != fallOff)
142 mLight->SetFallOff(fallOff);
143 mUpdateRequired = true;
148 * @copydoc Dali::Light::GetFallOff
150 const Vector2& GetFallOff() const
152 return mLight->GetFallOff();
156 * @copydoc Dali::Light::SetSpotAngle
158 void SetSpotAngle(const Vector2& angle)
160 if (mLight->GetSpotAngle() != angle)
162 mLight->SetSpotAngle(angle);
163 mUpdateRequired = true;
168 * @copydoc Dali::Light::GetSpotAngle
170 const Vector2& GetSpotAngle() const
172 return mLight->GetSpotAngle();
176 * @copydoc Dali::Light::SetAmbientColor
178 void SetAmbientColor(const Vector3& color)
180 if (mLight->GetAmbientColor() != color)
182 mLight->SetAmbientColor(color);
183 mUpdateRequired = true;
188 * @copydoc Dali::Light::GetAmbientColor
190 const Vector3& GetAmbientColor() const
192 return mLight->GetAmbientColor();
196 * @copydoc Dali::Light::SetDiffuseColor
198 void SetDiffuseColor(const Vector3& color)
200 if (mLight->GetDiffuseColor() != color)
202 mLight->SetDiffuseColor(color);
203 mUpdateRequired = true;
208 * @copydoc Dali::Light::GetDiffuseColor
210 const Vector3& GetDiffuseColor() const
212 return mLight->GetDiffuseColor();
216 * @copydoc Dali::Light::SetSpecularColor
218 void SetSpecularColor(const Vector3& color)
220 if (mLight->GetSpecularColor() != color)
222 mLight->SetSpecularColor(color);
223 mUpdateRequired = true;
228 * @copydoc Dali::Light::GetSpecularColor
230 const Vector3& GetSpecularColor() const
232 return mLight->GetSpecularColor();
236 * @copydoc Dali::Light::SetDirection
238 void SetDirection(const Vector3& direction)
240 if (mLight->GetDirection() != direction)
242 mLight->SetDirection(direction);
243 mUpdateRequired = true;
248 * @copydoc Dali::Light::GetDirection
250 const Vector3& GetDirection() const
252 return mLight->GetDirection();
257 * @copydoc Dali::LightActor::SetActive
259 void SetActive(bool active)
261 Node& lightNode(GetParent());
264 mLightController->AddLight(lightNode); // Add to list of active lights
268 mLightController->RemoveLight(lightNode); // Remove from list of active lights
272 virtual void Update( BufferIndex /*updateBufferIndex*/, const Node& /*owningNode*/, int /*nodeDirtyFlags*/ )
276 mUpdateRequired = false;
283 * Protected constructor; see also LightAttachment::New().
290 LightAttachment(const LightAttachment&);
293 LightAttachment& operator=(const LightAttachment& rhs);
296 Internal::LightPtr mLight;
297 bool mUpdateRequired; ///< This is set to true if the projection matrix requires an update
298 LightController* mLightController; ///< required to add / remove lights
301 // Messages for LightAttachment
303 inline void SetLightMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Internal::LightPtr& parameter )
305 typedef MessageValue1< LightAttachment, Internal::LightPtr > LocalType;
307 // Reserve some memory inside the message queue
308 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
310 // Construct message in the message queue memory; note that delete should not be called on the return value
311 new (slot) LocalType( &attachment, &LightAttachment::SetLight, parameter );
314 inline void SetNameMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const std::string& parameter )
316 typedef MessageValue1< LightAttachment, std::string > LocalType;
318 // Reserve some memory inside the message queue
319 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
321 // Construct message in the message queue memory; note that delete should not be called on the return value
322 new (slot) LocalType( &attachment, &LightAttachment::SetName, parameter );
325 inline void SetTypeMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, LightType parameter )
327 typedef MessageValue1< LightAttachment, LightType > LocalType;
329 // Reserve some memory inside the message queue
330 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
332 // Construct message in the message queue memory; note that delete should not be called on the return value
333 new (slot) LocalType( &attachment, &LightAttachment::SetType, parameter );
336 inline void SetFallOffMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector2 ¶meter )
338 typedef MessageValue1< LightAttachment, Vector2 > LocalType;
340 // Reserve some memory inside the message queue
341 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
343 // Construct message in the message queue memory; note that delete should not be called on the return value
344 new (slot) LocalType( &attachment, &LightAttachment::SetFallOff, parameter );
347 inline void SetSpotAngleMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector2 ¶meter )
349 typedef MessageValue1< LightAttachment, Vector2 > LocalType;
351 // Reserve some memory inside the message queue
352 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
354 // Construct message in the message queue memory; note that delete should not be called on the return value
355 new (slot) LocalType( &attachment, &LightAttachment::SetSpotAngle, parameter );
358 inline void SetAmbientColorMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector3 ¶meter )
360 typedef MessageValue1< LightAttachment, Vector3 > LocalType;
362 // Reserve some memory inside the message queue
363 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
365 // Construct message in the message queue memory; note that delete should not be called on the return value
366 new (slot) LocalType( &attachment, &LightAttachment::SetAmbientColor, parameter );
369 inline void SetDiffuseColorMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector3 ¶meter )
371 typedef MessageValue1< LightAttachment, Vector3 > LocalType;
373 // Reserve some memory inside the message queue
374 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
376 // Construct message in the message queue memory; note that delete should not be called on the return value
377 new (slot) LocalType( &attachment, &LightAttachment::SetDiffuseColor, parameter );
380 inline void SetSpecularColorMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector3 ¶meter )
382 typedef MessageValue1< LightAttachment, Vector3 > LocalType;
384 // Reserve some memory inside the message queue
385 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
387 // Construct message in the message queue memory; note that delete should not be called on the return value
388 new (slot) LocalType( &attachment, &LightAttachment::SetSpecularColor, parameter );
391 inline void SetDirectionMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, const Vector3 ¶meter )
393 typedef MessageValue1< LightAttachment, Vector3 > LocalType;
395 // Reserve some memory inside the message queue
396 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
398 // Construct message in the message queue memory; note that delete should not be called on the return value
399 new (slot) LocalType( &attachment, &LightAttachment::SetDirection, parameter );
402 inline void SetActiveMessage( EventToUpdate& eventToUpdate, const LightAttachment& attachment, bool parameter )
404 typedef MessageValue1< LightAttachment, bool > LocalType;
406 // Reserve some memory inside the message queue
407 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
409 // Construct message in the message queue memory; note that delete should not be called on the return value
410 new (slot) LocalType( &attachment, &LightAttachment::SetActive, parameter );
413 } // namespace SceneGraph
415 } // namespace Internal
419 #endif // __DALI_INTERNAL_SCENE_GRAPH_LIGHT_ATTACHMENT_H__