Property - Allow the custom property to be INTEGER type
[platform/core/uifw/dali-core.git] / dali / internal / update / node-attachments / scene-graph-camera-attachment.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
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/common/event-to-update.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>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
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 > {};
42
43 namespace SceneGraph
44 {
45
46 class RenderableAttachment;
47 class SceneController;
48
49 /**
50  * An attachment for camera objects and their properties.
51  */
52 class CameraAttachment : public NodeAttachment
53 {
54 public:
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_STEREO_BIAS;
61   static const float DEFAULT_LEFT_CLIPPING_PLANE;
62   static const float DEFAULT_RIGHT_CLIPPING_PLANE;
63   static const float DEFAULT_TOP_CLIPPING_PLANE;
64   static const float DEFAULT_BOTTOM_CLIPPING_PLANE;
65   static const float DEFAULT_NEAR_CLIPPING_PLANE;
66   static const float DEFAULT_FAR_CLIPPING_PLANE;
67   static const Vector3 DEFAULT_TARGET_POSITION;
68
69   /**
70    * Construct a new CameraAttachment.
71    * @return a new camera.
72    */
73   static CameraAttachment* New();
74
75   /**
76    * @copydoc NodeAttachment::ConnectToSceneGraph().
77    */
78   virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex );
79
80   /**
81    * @copydoc NodeAttachment::OnDestroy().
82    */
83   virtual void OnDestroy();
84
85   /**
86    * Virtual destructor
87    */
88   virtual ~CameraAttachment();
89
90   /**
91    * @copydoc NodeAttachment::GetRenderable.
92    * @return Always NULL.
93    */
94   virtual RenderableAttachment* GetRenderable();
95
96   /**
97    * @copydoc Dali::Internal::CameraAttachment::SetType
98    */
99   void SetType( Dali::Camera::Type type );
100
101   /**
102    * @copydoc Dali::Internal::CameraAttachment::SetInvertYAxis
103    */
104   void SetInvertYAxis( bool invertYAxis );
105
106   /**
107    * @copydoc Dali::Internal::CameraAttachment::SetProjectionMode
108    */
109   void SetProjectionMode( Dali::Camera::ProjectionMode projectionMode );
110
111   /**
112    * @copydoc Dali::Internal::CameraAttachment::SetFieldOfView
113    */
114   void SetFieldOfView( float fieldOfView );
115
116   /**
117    * @copydoc Dali::Internal::CameraAttachment::SetAspectRatio
118    */
119   void SetAspectRatio( float aspectRatio );
120
121   /**
122    * @copydoc Dali::Internal::CameraAttachment::SetStereoBias
123    */
124   void SetStereoBias(float stereoBias);
125
126    /**
127    * @copydoc Dali::Internal::CameraAttachment::SetLeftClippingPlane
128    */
129   void SetLeftClippingPlane( float leftClippingPlane );
130
131   /**
132    * @copydoc Dali::Internal::CameraAttachment::SetRightClippingPlane
133    */
134   void SetRightClippingPlane( float rightClippingPlane );
135
136   /**
137    * @copydoc Dali::Internal::CameraAttachment::SetTopClippingPlane
138    */
139   void SetTopClippingPlane( float topClippingPlane );
140
141   /**
142    * @copydoc Dali::Internal::CameraAttachment::SetBottomClippingPlane
143    */
144   void SetBottomClippingPlane( float bottomClippingPlane );
145
146   /**
147    * @copydoc Dali::Internal::CameraAttachment::SetNearClippingPlane
148    */
149   void SetNearClippingPlane( float nearClippingPlane );
150
151   /**
152    * @copydoc Dali::Internal::CameraAttachment::SetFarClippingPlane
153    */
154   void SetFarClippingPlane( float farClippingPlane );
155
156   /**
157    * @copydoc Dali::Internal::CameraAttachment::SetTarget
158    */
159   void SetTargetPosition( const Vector3& targetPosition );
160
161   /**
162    * Get Camera Target
163    */
164   Vector3 GetTargetPosition() const;
165
166   /**
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.
170    */
171   const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
172
173   /**
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.
177    */
178   const Matrix& GetProjectionMatrix( BufferIndex bufferIndex ) const;
179
180   /**
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.
184    */
185   const Matrix& GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const;
186
187   /**
188    * Retrieve the projection-matrix property querying interface.
189    * @pre The attachment is on-stage.
190    * @return The projection-matrix property querying interface.
191    */
192   const PropertyInputImpl* GetProjectionMatrix() const;
193
194   /**
195    * Retrieve the view-matrix property querying interface.
196    * @pre The attachment is on-stage.
197    * @return The view-matrix property querying interface.
198    */
199   const PropertyInputImpl* GetViewMatrix() const;
200
201   /**
202    * @copydoc NodeAttachment::Update
203    */
204   virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags );
205
206   /**
207    * @return true if the view matrix of camera is updated this or the previous frame
208    */
209   bool ViewMatrixUpdated();
210
211 protected:
212
213   /**
214    * Protected constructor, see New().
215    */
216   CameraAttachment();
217
218 private:
219
220   // Undefined
221   CameraAttachment(const CameraAttachment&);
222
223   // Undefined
224   CameraAttachment& operator=(const CameraAttachment& rhs);
225
226   /**
227    * Recalculates the view & projection matrices.
228    * @param[in] bufferIndex The current update buffer index.
229    */
230   void UpdateProjection( BufferIndex updateBufferIndex );
231
232   /**
233    * Recalculates the inverse modelview matrix, which is used for hit testing
234    * @param[in] updateBufferIndex The current update buffer index.
235    */
236   void UpdateInverseViewProjection( BufferIndex updateBufferIndex );
237
238 private:
239   unsigned int                  mUpdateViewFlag;       ///< This is non-zero if the view matrix requires an update
240   unsigned int                  mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update
241
242 public:  // PROPERTIES
243   Dali::Camera::Type            mType;                 // Non-animatable
244   Dali::Camera::ProjectionMode  mProjectionMode;       // Non-animatable
245   bool                          mInvertYAxis;          // Non-animatable
246
247   float                         mFieldOfView;
248   float                         mAspectRatio;
249   float                         mStereoBias;
250   float                         mLeftClippingPlane;
251   float                         mRightClippingPlane;
252   float                         mTopClippingPlane;
253   float                         mBottomClippingPlane;
254   float                         mNearClippingPlane;
255   float                         mFarClippingPlane;
256   Vector3                       mTargetPosition;
257
258   InheritedProperty<Matrix>     mViewMatrix;           ///< The view-matrix; this is double buffered for input handling.
259   InheritedProperty<Matrix>     mProjectionMatrix;     ///< The projection-matrix; this is double buffered for input handling.
260
261   DoubleBuffered< Matrix >      mInverseViewProjection;///< Inverted viewprojection; double buffered for input handling
262
263 };
264
265 // Messages for CameraAttachment
266
267 inline void SetTypeMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, Dali::Camera::Type parameter )
268 {
269   typedef MessageValue1< CameraAttachment, Dali::Camera::Type > LocalType;
270
271   // Reserve some memory inside the message queue
272   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
273
274   // Construct message in the message queue memory; note that delete should not be called on the return value
275   new (slot) LocalType( &attachment, &CameraAttachment::SetType, parameter );
276 }
277
278 inline void SetProjectionModeMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, Dali::Camera::ProjectionMode parameter )
279 {
280   typedef MessageValue1< CameraAttachment, Dali::Camera::ProjectionMode > LocalProjectionMode;
281
282   // Reserve some memory inside the message queue
283   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalProjectionMode ) );
284
285   // Construct message in the message queue memory; note that delete should not be called on the return value
286   new (slot) LocalProjectionMode( &attachment, &CameraAttachment::SetProjectionMode, parameter );
287 }
288
289
290 inline void SetFieldOfViewMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
291 {
292   typedef MessageValue1< CameraAttachment, float > LocalType;
293
294   // Reserve some memory inside the message queue
295   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
296
297   // Construct message in the message queue memory; note that delete should not be called on the return value
298   new (slot) LocalType( &attachment, &CameraAttachment::SetFieldOfView, parameter );
299 }
300
301 inline void SetAspectRatioMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
302 {
303   typedef MessageValue1< CameraAttachment, float > LocalType;
304
305   // Reserve some memory inside the message queue
306   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
307
308   // Construct message in the message queue memory; note that delete should not be called on the return value
309   new (slot) LocalType( &attachment, &CameraAttachment::SetAspectRatio, parameter );
310 }
311
312 inline void SetStereoBiasMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
313 {
314   typedef MessageValue1< CameraAttachment, float > LocalType;
315
316   // Reserve some memory inside the message queue
317   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
318
319   // Construct message in the message queue memory; note that delete should not be called on the return value
320   new (slot) LocalType( &attachment, &CameraAttachment::SetStereoBias, parameter );
321 }
322
323 inline void SetLeftClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
324 {
325   typedef MessageValue1< CameraAttachment, float > LocalType;
326
327   // Reserve some memory inside the message queue
328   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
329
330   // Construct message in the message queue memory; note that delete should not be called on the return value
331   new (slot) LocalType( &attachment, &CameraAttachment::SetLeftClippingPlane, parameter );
332 }
333
334 inline void SetRightClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
335 {
336   typedef MessageValue1< CameraAttachment, float > LocalType;
337
338   // Reserve some memory inside the message queue
339   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
340
341   // Construct message in the message queue memory; note that delete should not be called on the return value
342   new (slot) LocalType( &attachment, &CameraAttachment::SetRightClippingPlane, parameter );
343 }
344
345 inline void SetTopClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
346 {
347   typedef MessageValue1< CameraAttachment, float > LocalType;
348
349   // Reserve some memory inside the message queue
350   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
351
352   // Construct message in the message queue memory; note that delete should not be called on the return value
353   new (slot) LocalType( &attachment, &CameraAttachment::SetTopClippingPlane, parameter );
354 }
355
356 inline void SetBottomClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
357 {
358   typedef MessageValue1< CameraAttachment, float > LocalType;
359
360   // Reserve some memory inside the message queue
361   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
362
363   // Construct message in the message queue memory; note that delete should not be called on the return value
364   new (slot) LocalType( &attachment, &CameraAttachment::SetBottomClippingPlane, parameter );
365 }
366
367 inline void SetNearClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
368 {
369   typedef MessageValue1< CameraAttachment, float > LocalType;
370
371   // Reserve some memory inside the message queue
372   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
373
374   // Construct message in the message queue memory; note that delete should not be called on the return value
375   new (slot) LocalType( &attachment, &CameraAttachment::SetNearClippingPlane, parameter );
376 }
377
378 inline void SetFarClippingPlaneMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, float parameter )
379 {
380   typedef MessageValue1< CameraAttachment, float > LocalType;
381
382   // Reserve some memory inside the message queue
383   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
384
385   // Construct message in the message queue memory; note that delete should not be called on the return value
386   new (slot) LocalType( &attachment, &CameraAttachment::SetFarClippingPlane, parameter );
387 }
388
389 inline void SetTargetPositionMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, const Vector3& parameter )
390 {
391   typedef MessageValue1< CameraAttachment, Vector3 > LocalType;
392
393   // Reserve some memory inside the message queue
394   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
395
396   // Construct message in the message queue memory; note that delete should not be called on the return value
397   new (slot) LocalType( &attachment, &CameraAttachment::SetTargetPosition, parameter );
398 }
399
400
401 inline void SetInvertYAxisMessage( EventToUpdate& eventToUpdate, const CameraAttachment& attachment, bool parameter )
402 {
403   typedef MessageValue1< CameraAttachment, bool > LocalType;
404
405   // Reserve some memory inside the message queue
406   unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
407
408   // Construct message in the message queue memory; note that delete should not be called on the return value
409   new (slot) LocalType( &attachment, &CameraAttachment::SetInvertYAxis, parameter );
410 }
411
412
413 } // namespace SceneGraph
414
415 } // namespace Internal
416
417 } // namespace Dali
418
419 #endif // __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__