1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_CAMERA_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/actors/camera-actor.h>
24 #include <dali/internal/common/message.h>
25 #include <dali/internal/event/common/event-thread-services.h>
26 #include <dali/internal/update/common/double-buffered.h>
27 #include <dali/internal/update/node-attachments/node-attachment.h>
28 #include <dali/internal/update/common/animatable-property.h>
29 #include <dali/internal/update/common/inherited-property.h>
37 // value types used by messages
38 template <> struct ParameterType< Dali::Camera::Type >
39 : public BasicType< Dali::Camera::Type > {};
40 template <> struct ParameterType< Dali::Camera::ProjectionMode >
41 : public BasicType< Dali::Camera::ProjectionMode > {};
46 class RenderableAttachment;
47 class SceneController;
50 * An attachment for camera objects and their properties.
52 class CameraAttachment : public NodeAttachment
55 static const Dali::Camera::Type DEFAULT_TYPE;
56 static const Dali::Camera::ProjectionMode DEFAULT_MODE;
57 static const bool DEFAULT_INVERT_Y_AXIS;
58 static const float DEFAULT_FIELD_OF_VIEW;
59 static const float DEFAULT_ASPECT_RATIO;
60 static const float DEFAULT_LEFT_CLIPPING_PLANE;
61 static const float DEFAULT_RIGHT_CLIPPING_PLANE;
62 static const float DEFAULT_TOP_CLIPPING_PLANE;
63 static const float DEFAULT_BOTTOM_CLIPPING_PLANE;
64 static const float DEFAULT_NEAR_CLIPPING_PLANE;
65 static const float DEFAULT_FAR_CLIPPING_PLANE;
66 static const Vector2 DEFAULT_STEREO_BIAS;
67 static const Vector3 DEFAULT_TARGET_POSITION;
70 * Construct a new CameraAttachment.
71 * @return a new camera.
73 static CameraAttachment* New();
76 * @copydoc NodeAttachment::Initialize().
78 virtual void Initialize( SceneController& sceneController, BufferIndex updateBufferIndex );
81 * @copydoc NodeAttachment::OnDestroy().
83 virtual void OnDestroy();
86 * @copydoc NodeAttachment::ConnectedToSceneGraph()
88 virtual void ConnectedToSceneGraph();
91 * @copydoc NodeAttachment::DisconnectedFromSceneGraph()
93 virtual void DisconnectedFromSceneGraph();
98 virtual ~CameraAttachment();
101 * @copydoc NodeAttachment::GetRenderable.
102 * @return Always NULL.
104 virtual RenderableAttachment* GetRenderable();
107 * @copydoc Dali::Internal::CameraAttachment::SetType
109 void SetType( Dali::Camera::Type type );
112 * @copydoc Dali::Internal::CameraAttachment::SetInvertYAxis
114 void SetInvertYAxis( bool invertYAxis );
117 * @copydoc Dali::Internal::CameraAttachment::SetProjectionMode
119 void SetProjectionMode( Dali::Camera::ProjectionMode projectionMode );
122 * @copydoc Dali::Internal::CameraAttachment::SetFieldOfView
124 void SetFieldOfView( float fieldOfView );
127 * @copydoc Dali::Internal::CameraAttachment::SetAspectRatio
129 void SetAspectRatio( float aspectRatio );
132 * @copydoc Dali::Internal::CameraAttachment::SetStereoBias
134 void SetStereoBias(const Vector2& stereoBias);
137 * @copydoc Dali::Internal::CameraAttachment::SetLeftClippingPlane
139 void SetLeftClippingPlane( float leftClippingPlane );
142 * @copydoc Dali::Internal::CameraAttachment::SetRightClippingPlane
144 void SetRightClippingPlane( float rightClippingPlane );
147 * @copydoc Dali::Internal::CameraAttachment::SetTopClippingPlane
149 void SetTopClippingPlane( float topClippingPlane );
152 * @copydoc Dali::Internal::CameraAttachment::SetBottomClippingPlane
154 void SetBottomClippingPlane( float bottomClippingPlane );
157 * @copydoc Dali::Internal::CameraAttachment::SetNearClippingPlane
159 void SetNearClippingPlane( float nearClippingPlane );
162 * @copydoc Dali::Internal::CameraAttachment::SetFarClippingPlane
164 void SetFarClippingPlane( float farClippingPlane );
167 * @copydoc Dali::Internal::CameraAttachment::SetTarget
169 void SetTargetPosition( const Vector3& targetPosition );
174 Vector3 GetTargetPosition() const;
177 * Retrieve the view-matrix; this is double buffered for input handling.
178 * @param[in] bufferIndex The buffer to read from.
179 * @return The view-matrix.
181 const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
184 * Retrieve the projection-matrix; this is double buffered for input handling.
185 * @param[in] bufferIndex The buffer to read from.
186 * @return The projection-matrix.
188 const Matrix& GetProjectionMatrix( BufferIndex bufferIndex ) const;
191 * Retrieve the inverted view-projection-matrix; this is double buffered for input handling.
192 * @param[in] bufferIndex The buffer to read from.
193 * @return The inverse view-projection-matrix.
195 const Matrix& GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const;
198 * Retrieve the projection-matrix property querying interface.
199 * @pre The attachment is on-stage.
200 * @return The projection-matrix property querying interface.
202 const PropertyInputImpl* GetProjectionMatrix() const;
205 * Retrieve the view-matrix property querying interface.
206 * @pre The attachment is on-stage.
207 * @return The view-matrix property querying interface.
209 const PropertyInputImpl* GetViewMatrix() const;
212 * @copydoc NodeAttachment::Update
214 virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags );
217 * @return true if the view matrix of camera is updated this or the previous frame
219 bool ViewMatrixUpdated();
224 * Protected constructor, see New().
231 CameraAttachment(const CameraAttachment&);
234 CameraAttachment& operator=(const CameraAttachment& rhs);
237 * Recalculates the view matrix.
238 * @param[in] bufferIndex The current update buffer index.
239 * @param[in] owningNode to use for calculations.
240 * @return count how many frames ago the matrix was changed.
242 unsigned int UpdateViewMatrix( BufferIndex updateBufferIndex, const Node& owningNode );
245 * Recalculates the projection matrix.
246 * @param[in] bufferIndex The current update buffer index.
247 * @return count how many frames ago the matrix was changed.
249 unsigned int UpdateProjection( BufferIndex updateBufferIndex );
253 unsigned int mUpdateViewFlag; ///< This is non-zero if the view matrix requires an update
254 unsigned int mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update
256 public: // PROPERTIES
257 Dali::Camera::Type mType; // Non-animatable
258 Dali::Camera::ProjectionMode mProjectionMode; // Non-animatable
259 bool mInvertYAxis; // Non-animatable
263 float mLeftClippingPlane;
264 float mRightClippingPlane;
265 float mTopClippingPlane;
266 float mBottomClippingPlane;
267 float mNearClippingPlane;
268 float mFarClippingPlane;
270 Vector3 mTargetPosition;
272 InheritedMatrix mViewMatrix; ///< The view-matrix; this is double buffered for input handling.
273 InheritedMatrix mProjectionMatrix; ///< The projection-matrix; this is double buffered for input handling.
275 DoubleBuffered< Matrix > mInverseViewProjection;///< Inverted viewprojection; double buffered for input handling
279 // Messages for CameraAttachment
281 inline void SetTypeMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, Dali::Camera::Type parameter )
283 typedef MessageValue1< CameraAttachment, Dali::Camera::Type > LocalType;
285 // Reserve some memory inside the message queue
286 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
288 // Construct message in the message queue memory; note that delete should not be called on the return value
289 new (slot) LocalType( &attachment, &CameraAttachment::SetType, parameter );
292 inline void SetProjectionModeMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, Dali::Camera::ProjectionMode parameter )
294 typedef MessageValue1< CameraAttachment, Dali::Camera::ProjectionMode > LocalProjectionMode;
296 // Reserve some memory inside the message queue
297 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalProjectionMode ) );
299 // Construct message in the message queue memory; note that delete should not be called on the return value
300 new (slot) LocalProjectionMode( &attachment, &CameraAttachment::SetProjectionMode, parameter );
304 inline void SetFieldOfViewMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
306 typedef MessageValue1< CameraAttachment, float > LocalType;
308 // Reserve some memory inside the message queue
309 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
311 // Construct message in the message queue memory; note that delete should not be called on the return value
312 new (slot) LocalType( &attachment, &CameraAttachment::SetFieldOfView, parameter );
315 inline void SetAspectRatioMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
317 typedef MessageValue1< CameraAttachment, float > LocalType;
319 // Reserve some memory inside the message queue
320 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
322 // Construct message in the message queue memory; note that delete should not be called on the return value
323 new (slot) LocalType( &attachment, &CameraAttachment::SetAspectRatio, parameter );
326 inline void SetStereoBiasMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, const Vector2& parameter )
328 typedef MessageValue1< CameraAttachment, Vector2 > LocalType;
330 // Reserve some memory inside the message queue
331 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
333 // Construct message in the message queue memory; note that delete should not be called on the return value
334 new (slot) LocalType( &attachment, &CameraAttachment::SetStereoBias, parameter );
337 inline void SetLeftClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
339 typedef MessageValue1< CameraAttachment, float > LocalType;
341 // Reserve some memory inside the message queue
342 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
344 // Construct message in the message queue memory; note that delete should not be called on the return value
345 new (slot) LocalType( &attachment, &CameraAttachment::SetLeftClippingPlane, parameter );
348 inline void SetRightClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
350 typedef MessageValue1< CameraAttachment, float > LocalType;
352 // Reserve some memory inside the message queue
353 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
355 // Construct message in the message queue memory; note that delete should not be called on the return value
356 new (slot) LocalType( &attachment, &CameraAttachment::SetRightClippingPlane, parameter );
359 inline void SetTopClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
361 typedef MessageValue1< CameraAttachment, float > LocalType;
363 // Reserve some memory inside the message queue
364 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
366 // Construct message in the message queue memory; note that delete should not be called on the return value
367 new (slot) LocalType( &attachment, &CameraAttachment::SetTopClippingPlane, parameter );
370 inline void SetBottomClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
372 typedef MessageValue1< CameraAttachment, float > LocalType;
374 // Reserve some memory inside the message queue
375 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
377 // Construct message in the message queue memory; note that delete should not be called on the return value
378 new (slot) LocalType( &attachment, &CameraAttachment::SetBottomClippingPlane, parameter );
381 inline void SetNearClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
383 typedef MessageValue1< CameraAttachment, float > LocalType;
385 // Reserve some memory inside the message queue
386 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
388 // Construct message in the message queue memory; note that delete should not be called on the return value
389 new (slot) LocalType( &attachment, &CameraAttachment::SetNearClippingPlane, parameter );
392 inline void SetFarClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
394 typedef MessageValue1< CameraAttachment, float > LocalType;
396 // Reserve some memory inside the message queue
397 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
399 // Construct message in the message queue memory; note that delete should not be called on the return value
400 new (slot) LocalType( &attachment, &CameraAttachment::SetFarClippingPlane, parameter );
403 inline void SetTargetPositionMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, const Vector3& parameter )
405 typedef MessageValue1< CameraAttachment, Vector3 > LocalType;
407 // Reserve some memory inside the message queue
408 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
410 // Construct message in the message queue memory; note that delete should not be called on the return value
411 new (slot) LocalType( &attachment, &CameraAttachment::SetTargetPosition, parameter );
415 inline void SetInvertYAxisMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, bool parameter )
417 typedef MessageValue1< CameraAttachment, bool > LocalType;
419 // Reserve some memory inside the message queue
420 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
422 // Construct message in the message queue memory; note that delete should not be called on the return value
423 new (slot) LocalType( &attachment, &CameraAttachment::SetInvertYAxis, parameter );
427 } // namespace SceneGraph
429 } // namespace Internal
433 #endif // __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__