1 #ifndef __DALI_RENDER_TASK_H__
2 #define __DALI_RENDER_TASK_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/viewport.h>
23 #include <dali/public-api/object/constrainable.h>
24 #include <dali/public-api/signals/dali-signal-v2.h>
26 namespace Dali DALI_IMPORT_API
31 class FrameBufferImage;
34 namespace Internal DALI_INTERNAL
40 * @brief RenderTasks describe how the Dali scene should be rendered.
42 * The Stage::GetRenderTaskList() method provides access to an ordered list of render-tasks.
44 * Each RenderTask must specify the source actors to be rendered, and a camera actor from
45 * which the scene is viewed.
47 * RenderTasks may optionally target a frame-buffer, otherwise the default GL surface is used;
48 * typically this is a window provided by the native system.
50 * By default Dali provides a single RenderTask, which renders the entire actor hierachy using
51 * a default camera actor and GL surface. If stereoscopic rendering is enabled, Dali will create
52 * two additional render tasks, on for each eye. Each render task will have its own camera parented
53 * to the default camera actor.
55 * The first RenderTask used for input handling will be the last one rendered, which also has input enabled,
56 * and has a valid source & camera actor; see SetInputEnabled().
58 * If none of the actors are hit in the last RenderTask rendered, then input handling will continue
59 * with the second last RenderTask rendered, and so on.
61 * All RenderTasks which target a frame-buffer (i.e. off screen) will be rendered before all RenderTasks
62 * which target the default GL surface. This allows the user to render intermediate targets which are used
63 * later when targetting the screen.
65 * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the
66 * screen->frame-buffer coordinate conversion is successful; see SetScreenToFrameBufferFunction().
68 * If the refresh rate id REFRESH_ONCE and a "Finish" signal is connected, it will be emitted when the RenderTask is completed.
69 * Note that all connected signals must be disconnected before the object is destroyed. This is typically done in the
70 * object destructor, and requires either the Dali::Connection object or Dali::RenderTask handle to be stored.
72 class RenderTask : public Constrainable
76 * @brief Typedef for signals sent by this class.
78 typedef SignalV2< void (RenderTask& source) > RenderTaskSignalV2;
81 static const Property::Index VIEWPORT_POSITION; ///< Property 0, name "viewport-position", type VECTOR2
82 static const Property::Index VIEWPORT_SIZE; ///< Property 1, name "viewport-size", type VECTOR2
83 static const Property::Index CLEAR_COLOR; ///< Property 2, name "clear-color", type VECTOR4
86 static const char* const SIGNAL_FINISHED; ///< Name for Finished signal
89 * @brief A pointer to a function for converting screen to frame-buffer coordinates.
90 * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
91 * @return True if the conversion was successful, otherwise coordinates should be unmodified.
93 typedef bool (* ScreenToFrameBufferFunction)( Vector2& coordinates );
96 * @brief A pointer to a function for converting screen to frame-buffer coordinates.
97 * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
98 * @return True if the conversion was successful, otherwise coordinates should be unmodified.
100 typedef bool (* const ConstScreenToFrameBufferFunction)( Vector2& coordinates );
103 * @brief The default conversion function returns false for any screen coordinates.
105 * This effectively disables hit-testing for RenderTasks rendering to a frame buffer.
106 * See also FULLSCREEN_FRAMEBUFFER_FUNCTION below.
108 static ConstScreenToFrameBufferFunction DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION;
111 * @brief This conversion function outputs the (unmodified) screen coordinates as frame-buffer coordinates.
113 * Therefore the contents of an off-screen image is expected to be rendered "full screen".
115 static ConstScreenToFrameBufferFunction FULLSCREEN_FRAMEBUFFER_FUNCTION;
118 * @brief The refresh-rate of the RenderTask.
122 REFRESH_ONCE = 0, ///< Process once only e.g. take a snap-shot of the scene.
123 REFRESH_ALWAYS = 1 ///< Process every frame.
126 static const bool DEFAULT_EXCLUSIVE; ///< false
127 static const bool DEFAULT_INPUT_ENABLED; ///< true
128 static const Vector4 DEFAULT_CLEAR_COLOR; ///< Color::BLACK
129 static const bool DEFAULT_CLEAR_ENABLED; ///< false
130 static const bool DEFAULT_CULL_MODE; ///< true
131 static const unsigned int DEFAULT_REFRESH_RATE; ///< REFRESH_ALWAYS
134 * @brief Create an empty RenderTask handle.
136 * This can be initialised with RenderTaskList::CreateRenderTask().
141 * @brief Downcast a handle to RenderTask handle.
143 * If handle points to a RenderTask the
144 * downcast produces valid handle. If not the returned handle is left uninitialized.
145 * @param[in] handle A handle to an object.
146 * @return A handle to a RenderTask or an uninitialized handle.
148 static RenderTask DownCast( BaseHandle handle );
153 * This is non-virtual since derived Handle types must not contain data or virtual methods.
158 * @brief This copy constructor is required for (smart) pointer semantics.
160 * @param [in] handle A reference to the copied handle
162 RenderTask(const RenderTask& handle);
165 * @brief This assignment operator is required for (smart) pointer semantics.
167 * @param [in] rhs A reference to the copied handle
168 * @return A reference to this
170 RenderTask& operator=(const RenderTask& rhs);
173 * @brief This method is defined to allow assignment of the NULL value,
174 * and will throw an exception if passed any other value.
176 * Assigning to NULL is an alias for Reset().
177 * @param [in] rhs A NULL pointer
178 * @return A reference to this handle
180 RenderTask& operator=(BaseHandle::NullType* rhs);
183 * @brief Set the actors to be rendered.
184 * @param[in] actor This actor and its children will be rendered.
185 * If actor is an empty handle, then nothing will be rendered.
187 void SetSourceActor( Actor actor );
190 * @brief Retrieve the actors to be rendered.
191 * @return This actor and its children will be rendered.
193 Actor GetSourceActor() const;
196 * @brief Set whether the RenderTask has exclusive access to the source actors; the default is false.
197 * @param[in] exclusive True if the source actors will only be rendered by this render-task.
199 void SetExclusive( bool exclusive );
202 * @brief Query whether the RenderTask has exclusive access to the source actors.
203 * @return True if the source actors will only be rendered by this render-task.
205 bool IsExclusive() const;
208 * @brief Set whether the render-task should be considered for input handling; the default is true.
210 * The task used for input handling will be last task in the RenderTaskList which has input enabled,
211 * and has a valid source & camera actor.
212 * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the screen->frame-buffer
213 * coordinate conversion is successful; see also SetScreenToFrameBufferFunction().
214 * @param[in] enabled True if the render-task should be considered for input handling.
216 void SetInputEnabled( bool enabled );
219 * @brief Query whether the render-task should be considered for input handling.
220 * @return True if the render-task should be considered for input handling.
222 bool GetInputEnabled() const;
225 * @brief Set the actor from which the scene is viewed.
226 * @param[in] cameraActor The scene is viewed from the perspective of this actor.
228 void SetCameraActor( CameraActor cameraActor );
231 * @brief Retrieve the actor from which the scene is viewed.
232 * @return The scene is viewed from the perspective of this actor.
234 CameraActor GetCameraActor() const;
237 * @brief Set the frame-buffer used as a render target.
238 * @param[in] frameBuffer A valid frame-buffer handle to enable off-screen rendering, or an uninitialized handle to disable.
240 void SetTargetFrameBuffer( FrameBufferImage frameBuffer );
243 * @brief Retrieve the frame-buffer used as a render target.
244 * @return A valid frame-buffer handle, or an uninitialised handle if off-screen rendering is disabled.
246 FrameBufferImage GetTargetFrameBuffer() const;
249 * @brief Set the function used to convert screen coordinates to frame-buffer coordinates.
251 * This is useful for hit-testing actors which are rendered off-screen.
252 * @param[in] conversionFunction The conversion function.
254 void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
257 * @brief Retrieve the function used to convert screen coordinates to frame-buffer coordinates.
258 * @return The conversion function.
260 ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
263 * @brief Set the actor used to convert screen coordinates to frame-buffer coordinates.
265 * The local coordinates of the actor are mapped as frame-buffer coordinates.
266 * This is useful for hit-testing actors which are rendered off-screen.
267 * Note: The mapping actor needs to be rendered by the default render task to make the mapping work properly.
268 * @param[in] mappingActor The actor used for conversion.
270 void SetScreenToFrameBufferMappingActor( Actor mappingActor );
273 * @brief Retrieve the actor used to convert screen coordinates to frame-buffer coordinates.
274 * @return The actor used for conversion.
276 Actor GetScreenToFrameBufferMappingActor() const;
279 * @brief Set the GL viewport position used when rendering.
281 * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
282 * By default this will match the target window or frame-buffer size.
283 * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
284 * @param[in] position The viewports position (x,y)
286 void SetViewportPosition( Vector2 position );
289 * @brief Retrieve the GL viewport position used when rendering.
290 * @return The viewport.
292 Vector2 GetCurrentViewportPosition() const;
295 * @brief Set the GL viewport size used when rendering.
297 * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
298 * By default this will match the target window or frame-buffer size.
299 * @param[in] size The viewports size (width,height)
301 void SetViewportSize( Vector2 size );
304 * @brief Retrieve the GL viewport size used when rendering.
305 * @return The viewport.
307 Vector2 GetCurrentViewportSize() const;
310 * @brief Set the GL viewport used when rendering.
312 * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
313 * By default this will match the target window or frame-buffer size.
314 * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
315 * @param[in] viewport The new viewport.
317 void SetViewport( Viewport viewport );
320 * @brief Retrieve the GL viewport used when rendering.
321 * @return The viewport.
323 Viewport GetViewport() const;
326 * @brief Set the clear color used when SetClearEnabled(true) is used.
327 * @param[in] color The new clear color.
329 void SetClearColor( const Vector4& color );
332 * @brief Retrieve the clear color used when SetClearEnabled(true) is used.
333 * @note This property can be animated; the return value may not match the value written with SetClearColor().
334 * @return The clear color.
336 Vector4 GetClearColor() const;
339 * @brief Set whether the render-task will clear the results of previous render-tasks.
341 * The default is false.
343 * @note The default GL surface is cleared automatically at the
344 * beginning of each frame; this setting is only useful when 2+
345 * render-tasks are used, and the result of the first task needs to
346 * be (partially) cleared before rendering the second.
348 * @param[in] enabled True if the render-task should clear.
350 void SetClearEnabled( bool enabled );
353 * @brief Query whether the render-task will clear the results of previous render-tasks.
354 * @return True if the render-task should clear.
356 bool GetClearEnabled() const;
359 * @brief Set whether the render task will cull the actors to the camera's view frustum.
361 * Note that this will only affect image actors that use the default vertex shader.
362 * The default mode is to cull actors.
363 * @param[in] cullMode True if the renderers should be culled.
365 void SetCullMode( bool cullMode );
368 * @brief Get the cull mode.
370 * @return True if the render task should cull the actors to the camera's view frustum
372 bool GetCullMode() const;
375 * @brief Set the refresh-rate of the RenderTask.
377 * The default is REFRESH_ALWAYS (1), meaning that the RenderTask will be processed every frame.
378 * It may be desirable to process less frequently e.g. SetRefreshRate(3) will process once every 3 frames.
379 * The REFRESH_ONCE value means that the RenderTask will be processed once only, to take a snap-shot of the scene.
380 * Repeatedly calling SetRefreshRate(REFRESH_ONCE) will cause more snap-shots to be taken.
381 * @param[in] refreshRate The new refresh rate.
383 void SetRefreshRate( unsigned int refreshRate );
386 * @brief Query the refresh-rate of the RenderTask.
387 * @return The refresh-rate.
389 unsigned int GetRefreshRate() const;
394 * @brief If the refresh rate is REFRESH_ONCE, connect to this signal to be notified when a RenderTask has finished.
396 RenderTaskSignalV2& FinishedSignal();
398 public: // Not intended for application developers
401 * @brief This constructor is used by Dali New() methods.
402 * @param [in] renderTask A pointer to a newly allocated render-task
404 explicit DALI_INTERNAL RenderTask( Internal::RenderTask* renderTask );
409 #endif //__DALI_RENDER_TASK_H__