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::ConnectToSceneGraph().
78 virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex );
81 * @copydoc NodeAttachment::OnDestroy().
83 virtual void OnDestroy();
88 virtual ~CameraAttachment();
91 * @copydoc NodeAttachment::GetRenderable.
92 * @return Always NULL.
94 virtual RenderableAttachment* GetRenderable();
97 * @copydoc Dali::Internal::CameraAttachment::SetType
99 void SetType( Dali::Camera::Type type );
102 * @copydoc Dali::Internal::CameraAttachment::SetInvertYAxis
104 void SetInvertYAxis( bool invertYAxis );
107 * @copydoc Dali::Internal::CameraAttachment::SetProjectionMode
109 void SetProjectionMode( Dali::Camera::ProjectionMode projectionMode );
112 * @copydoc Dali::Internal::CameraAttachment::SetFieldOfView
114 void SetFieldOfView( float fieldOfView );
117 * @copydoc Dali::Internal::CameraAttachment::SetAspectRatio
119 void SetAspectRatio( float aspectRatio );
122 * @copydoc Dali::Internal::CameraAttachment::SetStereoBias
124 void SetStereoBias(const Vector2& stereoBias);
127 * @copydoc Dali::Internal::CameraAttachment::SetLeftClippingPlane
129 void SetLeftClippingPlane( float leftClippingPlane );
132 * @copydoc Dali::Internal::CameraAttachment::SetRightClippingPlane
134 void SetRightClippingPlane( float rightClippingPlane );
137 * @copydoc Dali::Internal::CameraAttachment::SetTopClippingPlane
139 void SetTopClippingPlane( float topClippingPlane );
142 * @copydoc Dali::Internal::CameraAttachment::SetBottomClippingPlane
144 void SetBottomClippingPlane( float bottomClippingPlane );
147 * @copydoc Dali::Internal::CameraAttachment::SetNearClippingPlane
149 void SetNearClippingPlane( float nearClippingPlane );
152 * @copydoc Dali::Internal::CameraAttachment::SetFarClippingPlane
154 void SetFarClippingPlane( float farClippingPlane );
157 * @copydoc Dali::Internal::CameraAttachment::SetTarget
159 void SetTargetPosition( const Vector3& targetPosition );
164 Vector3 GetTargetPosition() const;
167 * Retrieve the view-matrix; this is double buffered for input handling.
168 * @param[in] bufferIndex The buffer to read from.
169 * @return The view-matrix.
171 const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
174 * Retrieve the projection-matrix; this is double buffered for input handling.
175 * @param[in] bufferIndex The buffer to read from.
176 * @return The projection-matrix.
178 const Matrix& GetProjectionMatrix( BufferIndex bufferIndex ) const;
181 * Retrieve the inverted view-projection-matrix; this is double buffered for input handling.
182 * @param[in] bufferIndex The buffer to read from.
183 * @return The inverse view-projection-matrix.
185 const Matrix& GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const;
188 * Retrieve the projection-matrix property querying interface.
189 * @pre The attachment is on-stage.
190 * @return The projection-matrix property querying interface.
192 const PropertyInputImpl* GetProjectionMatrix() const;
195 * Retrieve the view-matrix property querying interface.
196 * @pre The attachment is on-stage.
197 * @return The view-matrix property querying interface.
199 const PropertyInputImpl* GetViewMatrix() const;
202 * @copydoc NodeAttachment::Update
204 virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags );
207 * @return true if the view matrix of camera is updated this or the previous frame
209 bool ViewMatrixUpdated();
214 * Protected constructor, see New().
221 CameraAttachment(const CameraAttachment&);
224 CameraAttachment& operator=(const CameraAttachment& rhs);
227 * Recalculates the view matrix.
228 * @param[in] bufferIndex The current update buffer index.
229 * @param[in] owningNode to use for calculations.
230 * @return count how many frames ago the matrix was changed.
232 unsigned int UpdateViewMatrix( BufferIndex updateBufferIndex, const Node& owningNode );
235 * Recalculates the projection matrix.
236 * @param[in] bufferIndex The current update buffer index.
237 * @return count how many frames ago the matrix was changed.
239 unsigned int UpdateProjection( BufferIndex updateBufferIndex );
243 unsigned int mUpdateViewFlag; ///< This is non-zero if the view matrix requires an update
244 unsigned int mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update
246 public: // PROPERTIES
247 Dali::Camera::Type mType; // Non-animatable
248 Dali::Camera::ProjectionMode mProjectionMode; // Non-animatable
249 bool mInvertYAxis; // Non-animatable
253 float mLeftClippingPlane;
254 float mRightClippingPlane;
255 float mTopClippingPlane;
256 float mBottomClippingPlane;
257 float mNearClippingPlane;
258 float mFarClippingPlane;
260 Vector3 mTargetPosition;
262 InheritedMatrix mViewMatrix; ///< The view-matrix; this is double buffered for input handling.
263 InheritedMatrix mProjectionMatrix; ///< The projection-matrix; this is double buffered for input handling.
265 DoubleBuffered< Matrix > mInverseViewProjection;///< Inverted viewprojection; double buffered for input handling
269 // Messages for CameraAttachment
271 inline void SetTypeMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, Dali::Camera::Type parameter )
273 typedef MessageValue1< CameraAttachment, Dali::Camera::Type > LocalType;
275 // Reserve some memory inside the message queue
276 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
278 // Construct message in the message queue memory; note that delete should not be called on the return value
279 new (slot) LocalType( &attachment, &CameraAttachment::SetType, parameter );
282 inline void SetProjectionModeMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, Dali::Camera::ProjectionMode parameter )
284 typedef MessageValue1< CameraAttachment, Dali::Camera::ProjectionMode > LocalProjectionMode;
286 // Reserve some memory inside the message queue
287 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalProjectionMode ) );
289 // Construct message in the message queue memory; note that delete should not be called on the return value
290 new (slot) LocalProjectionMode( &attachment, &CameraAttachment::SetProjectionMode, parameter );
294 inline void SetFieldOfViewMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
296 typedef MessageValue1< CameraAttachment, float > LocalType;
298 // Reserve some memory inside the message queue
299 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
301 // Construct message in the message queue memory; note that delete should not be called on the return value
302 new (slot) LocalType( &attachment, &CameraAttachment::SetFieldOfView, parameter );
305 inline void SetAspectRatioMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
307 typedef MessageValue1< CameraAttachment, float > LocalType;
309 // Reserve some memory inside the message queue
310 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
312 // Construct message in the message queue memory; note that delete should not be called on the return value
313 new (slot) LocalType( &attachment, &CameraAttachment::SetAspectRatio, parameter );
316 inline void SetStereoBiasMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, const Vector2& parameter )
318 typedef MessageValue1< CameraAttachment, Vector2 > LocalType;
320 // Reserve some memory inside the message queue
321 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
323 // Construct message in the message queue memory; note that delete should not be called on the return value
324 new (slot) LocalType( &attachment, &CameraAttachment::SetStereoBias, parameter );
327 inline void SetLeftClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
329 typedef MessageValue1< CameraAttachment, float > LocalType;
331 // Reserve some memory inside the message queue
332 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
334 // Construct message in the message queue memory; note that delete should not be called on the return value
335 new (slot) LocalType( &attachment, &CameraAttachment::SetLeftClippingPlane, parameter );
338 inline void SetRightClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
340 typedef MessageValue1< CameraAttachment, float > LocalType;
342 // Reserve some memory inside the message queue
343 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
345 // Construct message in the message queue memory; note that delete should not be called on the return value
346 new (slot) LocalType( &attachment, &CameraAttachment::SetRightClippingPlane, parameter );
349 inline void SetTopClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
351 typedef MessageValue1< CameraAttachment, float > LocalType;
353 // Reserve some memory inside the message queue
354 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
356 // Construct message in the message queue memory; note that delete should not be called on the return value
357 new (slot) LocalType( &attachment, &CameraAttachment::SetTopClippingPlane, parameter );
360 inline void SetBottomClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
362 typedef MessageValue1< CameraAttachment, float > LocalType;
364 // Reserve some memory inside the message queue
365 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
367 // Construct message in the message queue memory; note that delete should not be called on the return value
368 new (slot) LocalType( &attachment, &CameraAttachment::SetBottomClippingPlane, parameter );
371 inline void SetNearClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
373 typedef MessageValue1< CameraAttachment, float > LocalType;
375 // Reserve some memory inside the message queue
376 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
378 // Construct message in the message queue memory; note that delete should not be called on the return value
379 new (slot) LocalType( &attachment, &CameraAttachment::SetNearClippingPlane, parameter );
382 inline void SetFarClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
384 typedef MessageValue1< CameraAttachment, float > LocalType;
386 // Reserve some memory inside the message queue
387 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
389 // Construct message in the message queue memory; note that delete should not be called on the return value
390 new (slot) LocalType( &attachment, &CameraAttachment::SetFarClippingPlane, parameter );
393 inline void SetTargetPositionMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, const Vector3& parameter )
395 typedef MessageValue1< CameraAttachment, Vector3 > LocalType;
397 // Reserve some memory inside the message queue
398 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
400 // Construct message in the message queue memory; note that delete should not be called on the return value
401 new (slot) LocalType( &attachment, &CameraAttachment::SetTargetPosition, parameter );
405 inline void SetInvertYAxisMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, bool parameter )
407 typedef MessageValue1< CameraAttachment, bool > LocalType;
409 // Reserve some memory inside the message queue
410 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
412 // Construct message in the message queue memory; note that delete should not be called on the return value
413 new (slot) LocalType( &attachment, &CameraAttachment::SetInvertYAxis, parameter );
417 } // namespace SceneGraph
419 } // namespace Internal
423 #endif // __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__