Wrapped ShaderHints enum inside a struct
[platform/core/uifw/dali-core.git] / dali / public-api / render-tasks / render-task.h
1 #ifndef __DALI_RENDER_TASK_H__
2 #define __DALI_RENDER_TASK_H__
3
4 /*
5  * Copyright (c) 2015 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/viewport.h>
23 #include <dali/public-api/object/handle.h>
24 #include <dali/public-api/object/property-index-ranges.h>
25 #include <dali/public-api/signals/dali-signal.h>
26
27 namespace Dali
28 {
29 /**
30  * @addtogroup dali_core_rendering_effects
31  * @{
32  */
33
34 class Actor;
35 class CameraActor;
36 class FrameBufferImage;
37 class FrameBuffer;
38 struct Vector4;
39
40 namespace Internal DALI_INTERNAL
41 {
42 class RenderTask;
43 }
44
45 /**
46  * @brief RenderTasks describe how the Dali scene should be rendered.
47  *
48  * The Stage::GetRenderTaskList() method provides access to an ordered list of render-tasks.
49  *
50  * Each RenderTask must specify the source actors to be rendered, and a camera actor from
51  * which the scene is viewed.
52  *
53  * RenderTasks may optionally target a frame-buffer, otherwise the default GL surface is used;
54  * typically this is a window provided by the native system.
55  *
56  * By default Dali provides a single RenderTask, which renders the entire actor hierachy using
57  * a default camera actor and GL surface. If stereoscopic rendering is enabled, Dali will create
58  * two additional render tasks, on for each eye. Each render task will have its own camera parented
59  * to the default camera actor.
60  *
61  * The first RenderTask used for input handling will be the last one rendered, which also has input enabled,
62  * and has a valid source & camera actor; see SetInputEnabled().
63  *
64  * If none of the actors are hit in the last RenderTask rendered, then input handling will continue
65  * with the second last RenderTask rendered, and so on.
66  *
67  * All RenderTasks which target a frame-buffer (i.e. off screen) will be rendered before all RenderTasks
68  * which target the default GL surface. This allows the user to render intermediate targets which are used
69  * later when targetting the screen.
70  *
71  * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the
72  * screen->frame-buffer coordinate conversion is successful; see SetScreenToFrameBufferFunction().
73  *
74  * If the refresh rate id REFRESH_ONCE and a "Finish" signal is connected, it will be emitted when the RenderTask is completed.
75  * Note that all connected signals must be disconnected before the object is destroyed. This is typically done in the
76  * object destructor, and requires either the Dali::Connection object or Dali::RenderTask handle to be stored.
77  *
78  * Signals
79  * | %Signal Name | Method                |
80  * |--------------|-----------------------|
81  * | finished     | @ref FinishedSignal() |
82  * @SINCE_1_0.0
83  */
84 class DALI_IMPORT_API RenderTask : public Handle
85 {
86 public:
87
88   /**
89    * @brief An enumeration of properties belonging to the RenderTask class.
90    * @SINCE_1_0.0
91    */
92   struct Property
93   {
94     enum
95     {
96       /**
97        * @brief name "viewportPosition", type Vector2
98        * @SINCE_1_0.0
99        */
100       VIEWPORT_POSITION = DEFAULT_OBJECT_PROPERTY_START_INDEX,
101       /**
102        * @brief name "viewportSize", type Vector2
103        * @SINCE_1_0.0
104        */
105       VIEWPORT_SIZE,
106       /**
107        * @brief name "clearColor", type Vector4
108        * @SINCE_1_0.0
109        */
110       CLEAR_COLOR,
111       /**
112        * @brief name "requiresSync", type BOOLEAN
113        * @details By default, the sync object is not created.
114        *  When native image source is used as render target, in order to track when the render to pixmap is completed, the GL sync should be enabled.
115        *  Thus the RENDER_ONCE finished signal can be emit at the correct timing.
116        * @note The use of GL sync might cause deadlock with multiple access to the single pixmap happening in the same time.
117        * @SINCE_1_1.29
118        */
119       REQUIRES_SYNC,
120     };
121   };
122
123   /**
124    * @brief Typedef for signals sent by this class.
125    * @SINCE_1_0.0
126    */
127   typedef Signal< void (RenderTask& source) > RenderTaskSignalType;
128
129   /**
130    * @brief A pointer to a function for converting screen to frame-buffer coordinates.
131    * @SINCE_1_0.0
132    * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
133    * @return True if the conversion was successful, otherwise coordinates should be unmodified.
134    */
135   typedef bool (* ScreenToFrameBufferFunction)( Vector2& coordinates );
136
137   /**
138    * @brief A pointer to a function for converting screen to frame-buffer coordinates.
139    * @SINCE_1_0.0
140    * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
141    * @return True if the conversion was successful, otherwise coordinates should be unmodified.
142    */
143   typedef bool (* const ConstScreenToFrameBufferFunction)( Vector2& coordinates );
144
145   /**
146    * @brief The default conversion function returns false for any screen coordinates.
147    *
148    * This effectively disables hit-testing for RenderTasks rendering to a frame buffer.
149    * See also FULLSCREEN_FRAMEBUFFER_FUNCTION below.
150    */
151   static ConstScreenToFrameBufferFunction DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION;
152
153   /**
154    * @brief This conversion function outputs the (unmodified) screen coordinates as frame-buffer coordinates.
155    *
156    * Therefore the contents of an off-screen image is expected to be rendered "full screen".
157    */
158   static ConstScreenToFrameBufferFunction FULLSCREEN_FRAMEBUFFER_FUNCTION;
159
160   /**
161    * @brief The refresh-rate of the RenderTask.
162    * @SINCE_1_0.0
163    */
164   enum RefreshRate
165   {
166     REFRESH_ONCE   = 0, ///< Process once only e.g. take a snap-shot of the scene. @SINCE_1_0.0
167     REFRESH_ALWAYS = 1  ///< Process every frame. @SINCE_1_0.0
168   };
169
170   static const bool         DEFAULT_EXCLUSIVE;     ///< false
171   static const bool         DEFAULT_INPUT_ENABLED; ///< true
172   static const Vector4      DEFAULT_CLEAR_COLOR;   ///< Color::BLACK
173   static const bool         DEFAULT_CLEAR_ENABLED; ///< false
174   static const bool         DEFAULT_CULL_MODE;     ///< true
175   static const unsigned int DEFAULT_REFRESH_RATE;  ///< REFRESH_ALWAYS
176
177   /**
178    * @brief Create an empty RenderTask handle.
179    *
180    * This can be initialised with RenderTaskList::CreateRenderTask().
181    * @SINCE_1_0.0
182    */
183   RenderTask();
184
185   /**
186    * @brief Downcast a handle to RenderTask handle.
187    *
188    * If handle points to a RenderTask the
189    * downcast produces valid handle. If not the returned handle is left uninitialized.
190    * @SINCE_1_0.0
191    * @param[in] handle A handle to an object.
192    * @return A handle to a RenderTask or an uninitialized handle.
193    */
194   static RenderTask DownCast( BaseHandle handle );
195
196   /**
197    * @brief Destructor
198    *
199    * This is non-virtual since derived Handle types must not contain data or virtual methods.
200    * @SINCE_1_0.0
201    */
202   ~RenderTask();
203
204   /**
205    * @brief This copy constructor is required for (smart) pointer semantics.
206    *
207    * @SINCE_1_0.0
208    * @param [in] handle A reference to the copied handle
209    */
210   RenderTask(const RenderTask& handle);
211
212   /**
213    * @brief This assignment operator is required for (smart) pointer semantics.
214    *
215    * @SINCE_1_0.0
216    * @param [in] rhs  A reference to the copied handle
217    * @return A reference to this
218    */
219   RenderTask& operator=(const RenderTask& rhs);
220
221   /**
222    * @brief Set the actors to be rendered.
223    * @SINCE_1_0.0
224    * @param[in] actor This actor and its children will be rendered.
225    * If actor is an empty handle, then nothing will be rendered.
226    */
227   void SetSourceActor( Actor actor );
228
229   /**
230    * @brief Retrieve the actors to be rendered.
231    * @SINCE_1_0.0
232    * @return This actor and its children will be rendered.
233    */
234   Actor GetSourceActor() const;
235
236   /**
237    * @brief Set whether the RenderTask has exclusive access to the source actors; the default is false.
238    * @SINCE_1_0.0
239    * @param[in] exclusive True if the source actors will only be rendered by this render-task.
240    */
241   void SetExclusive( bool exclusive );
242
243   /**
244    * @brief Query whether the RenderTask has exclusive access to the source actors.
245    * @SINCE_1_0.0
246    * @return True if the source actors will only be rendered by this render-task.
247    */
248   bool IsExclusive() const;
249
250   /**
251    * @brief Set whether the render-task should be considered for input handling; the default is true.
252    *
253    * The task used for input handling will be last task in the RenderTaskList which has input enabled,
254    * and has a valid source & camera actor.
255    * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the screen->frame-buffer
256    * coordinate conversion is successful; see also SetScreenToFrameBufferFunction().
257    * @SINCE_1_0.0
258    * @param[in] enabled True if the render-task should be considered for input handling.
259    */
260   void SetInputEnabled( bool enabled );
261
262   /**
263    * @brief Query whether the render-task should be considered for input handling.
264    * @SINCE_1_0.0
265    * @return True if the render-task should be considered for input handling.
266    */
267   bool GetInputEnabled() const;
268
269   /**
270    * @brief Set the actor from which the scene is viewed.
271    * @SINCE_1_0.0
272    * @param[in] cameraActor The scene is viewed from the perspective of this actor.
273    */
274   void SetCameraActor( CameraActor cameraActor );
275
276   /**
277    * @brief Retrieve the actor from which the scene is viewed.
278    * @SINCE_1_0.0
279    * @return The scene is viewed from the perspective of this actor.
280    */
281   CameraActor GetCameraActor() const;
282
283   /**
284    * @brief Set the frame-buffer used as a render target.
285    * @SINCE_1_0.0
286    * @param[in] frameBuffer A valid frame-buffer handle to enable off-screen rendering, or an uninitialized handle to disable.
287    */
288   void SetTargetFrameBuffer( FrameBufferImage frameBuffer );
289
290   /**
291    * @brief Retrieve the frame-buffer used as a render target.
292    * @SINCE_1_0.0
293    * @return A valid frame-buffer handle, or an uninitialised handle if off-screen rendering is disabled.
294    */
295   FrameBufferImage GetTargetFrameBuffer() const;
296
297   /**
298    * @brief Set the frame-buffer used as a render target.
299    * @SINCE_1_1.38
300    * @param[in] frameBuffer er A valid FrameBuffer handle to enable off-screen rendering, or an uninitialized handle to disable it.
301    */
302   void SetFrameBuffer( FrameBuffer frameBuffer );
303
304   /**
305    * @brief Retrieve the frame-buffer used as a render target.
306    * @SINCE_1_1.38
307    * @return The framebuffer
308    */
309   FrameBuffer GetFrameBuffer() const;
310
311   /**
312    * @brief Set the function used to convert screen coordinates to frame-buffer coordinates.
313    *
314    * This is useful for hit-testing actors which are rendered off-screen.
315    * @SINCE_1_0.0
316    * @param[in] conversionFunction The conversion function.
317    */
318   void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
319
320   /**
321    * @brief Retrieve the function used to convert screen coordinates to frame-buffer coordinates.
322    * @SINCE_1_0.0
323    * @return The conversion function.
324    */
325   ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
326
327   /**
328    * @brief Set the actor used to convert screen coordinates to frame-buffer coordinates.
329    *
330    * The local coordinates of the actor are mapped as frame-buffer coordinates.
331    * This is useful for hit-testing actors which are rendered off-screen.
332    * @SINCE_1_0.0
333    * @param[in] mappingActor The actor used for conversion.
334    * @note The mapping actor needs to be rendered by the default render task to make the mapping work properly.
335    */
336   void SetScreenToFrameBufferMappingActor( Actor mappingActor );
337
338   /**
339    * @brief Retrieve the actor used to convert screen coordinates to frame-buffer coordinates.
340    * @SINCE_1_0.0
341    * @return The actor used for conversion.
342    */
343   Actor GetScreenToFrameBufferMappingActor() const;
344
345   /**
346    * @brief Set the GL viewport position used when rendering.
347    *
348    * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
349    * By default this will match the target window or frame-buffer size.
350    * @SINCE_1_0.0
351    * @param[in] position The viewports position (x,y)
352    * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
353    */
354   void SetViewportPosition( Vector2 position );
355
356   /**
357    * @brief Retrieve the GL viewport position used when rendering.
358    * @SINCE_1_0.0
359    * @return The viewport.
360    */
361   Vector2 GetCurrentViewportPosition() const;
362
363   /**
364    * @brief Set the GL viewport size used when rendering.
365    *
366    * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
367    * By default this will match the target window or frame-buffer size.
368    * @SINCE_1_0.0
369    * @param[in] size The viewports size (width,height)
370    */
371   void SetViewportSize( Vector2 size );
372
373   /**
374    * @brief Retrieve the GL viewport size used when rendering.
375    * @SINCE_1_0.0
376    * @return The viewport.
377    */
378   Vector2 GetCurrentViewportSize() const;
379
380   /**
381    * @brief Set the GL viewport used when rendering.
382    *
383    * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
384    * By default this will match the target window or frame-buffer size.
385    * @SINCE_1_0.0
386    * @param[in] viewport The new viewport.
387    * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
388    */
389   void SetViewport( Viewport viewport );
390
391   /**
392    * @brief Retrieve the GL viewport used when rendering.
393    * @SINCE_1_0.0
394    * @return The viewport.
395    */
396   Viewport GetViewport() const;
397
398   /**
399    * @brief Set the clear color used when SetClearEnabled(true) is used.
400    * @SINCE_1_0.0
401    * @param[in] color The new clear color.
402    */
403   void SetClearColor( const Vector4& color );
404
405   /**
406    * @brief Retrieve the clear color used when SetClearEnabled(true) is used.
407    * @SINCE_1_0.0
408    * @return The clear color.
409    * @note This property can be animated; the return value may not match the value written with SetClearColor().
410    */
411   Vector4 GetClearColor() const;
412
413   /**
414    * @brief Set whether the render-task will clear the results of previous render-tasks.
415    *
416    * The default is false.
417    *
418    * @SINCE_1_0.0
419    * @param[in] enabled True if the render-task should clear.
420    * @note The default GL surface is cleared automatically at the
421    * beginning of each frame; this setting is only useful when 2+
422    * render-tasks are used, and the result of the first task needs to
423    * be (partially) cleared before rendering the second.
424    *
425    */
426   void SetClearEnabled( bool enabled );
427
428   /**
429    * @brief Query whether the render-task will clear the results of previous render-tasks.
430    * @SINCE_1_0.0
431    * @return True if the render-task should clear.
432    */
433   bool GetClearEnabled() const;
434
435   /**
436    * @brief Set whether the render task will cull the actors to the camera's view frustum.
437    *
438    * @SINCE_1_0.0
439    * @param[in] cullMode True if the renderers should be culled.
440    * @note The default mode is to cull actors.
441    * @note If the shader uses @ref Shader::Hint::MODIFIES_GEOMETRY then culling optimizations are disabled.
442    * @see Shader::Hint
443    */
444   void SetCullMode( bool cullMode );
445
446   /**
447    * @brief Get the cull mode.
448    *
449    * @SINCE_1_0.0
450    * @return True if the render task should cull the actors to the camera's view frustum
451    */
452   bool GetCullMode() const;
453
454   /**
455    * @brief Set the refresh-rate of the RenderTask.
456    *
457    * The default is REFRESH_ALWAYS (1), meaning that the RenderTask
458    * will be processed every frame if the scene graph is changing.  It
459    * may be desirable to process less frequently. For example,
460    * SetRefreshRate(3) will process once every 3 frames if the scene
461    * graph is changing.  If the scene graph is not changing, then the
462    * render task will not be rendered, regardless of this value.
463    *
464    * The REFRESH_ONCE value means that the RenderTask will be
465    * processed once only, to take a snap-shot of the scene.
466    * Repeatedly calling SetRefreshRate(REFRESH_ONCE) will cause more
467    * snap-shots to be taken.
468    *
469    * @SINCE_1_0.0
470    * @param[in] refreshRate The new refresh rate.
471    */
472   void SetRefreshRate( unsigned int refreshRate );
473
474   /**
475    * @brief Query the refresh-rate of the RenderTask.
476    * @SINCE_1_0.0
477    * @return The refresh-rate.
478    */
479   unsigned int GetRefreshRate() const;
480
481   /*
482    * @brief Get viewport coordinates for given world position
483    *
484    * @SINCE_1_1.13
485    *
486    * @param[in] position The world position.
487    * @param[out] viewportX The viewport x position.
488    * @param[out] viewportY The viewport y position.
489    * @return true if the position has a screen coordinate
490    */
491   bool WorldToViewport(const Vector3 &position, float& viewportX, float& viewportY) const;
492
493   /*
494    * @brief Get actor local coordinates for given viewport coordinates
495    *
496    * @SINCE_1_1.13
497    *
498    * @param[in] actor The actor describing local coordinate system.
499    * @param[in] viewportX The viewport x position.
500    * @param[in] viewportY The viewport y position.
501    * @param[out] localX The local x position.
502    * @param[out] localY The local y position.
503    * @return true if the screen position has a local coordinate
504    */
505   bool ViewportToLocal(Actor actor, float viewportX, float viewportY, float &localX, float &localY) const;
506
507 public: // Signals
508
509   /**
510    * @brief If the refresh rate is REFRESH_ONCE, connect to this signal to be notified when a RenderTask has finished.
511    * @SINCE_1_0.0
512    */
513   RenderTaskSignalType& FinishedSignal();
514
515 public: // Not intended for application developers
516
517   /**
518    * @brief This constructor is used by Dali New() methods.
519    * @SINCE_1_0.0
520    * @param [in] renderTask A pointer to a newly allocated render-task
521    */
522   explicit DALI_INTERNAL RenderTask( Internal::RenderTask* renderTask );
523 };
524
525 /**
526  * @}
527  */
528 } // namespace Dali
529
530 #endif //__DALI_RENDER_TASK_H__