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.
53 * The first RenderTask used for input handling will be the last one rendered, which also has input enabled,
54 * and has a valid source & camera actor; see SetInputEnabled().
56 * If none of the actors are hit in the last RenderTask rendered, then input handling will continue
57 * with the second last RenderTask rendered, and so on.
59 * All RenderTasks which target a frame-buffer (i.e. off screen) will be rendered before all RenderTasks
60 * which target the default GL surface. This allows the user to render intermediate targets which are used
61 * later when targetting the screen.
63 * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the
64 * screen->frame-buffer coordinate conversion is successful; see SetScreenToFrameBufferFunction().
66 * If the refresh rate id REFRESH_ONCE and a "Finish" signal is connected, it will be emitted when the RenderTask is completed.
67 * Note that all connected signals must be disconnected before the object is destroyed. This is typically done in the
68 * object destructor, and requires either the Dali::Connection object or Dali::RenderTask handle to be stored.
70 class RenderTask : public Constrainable
74 * @brief Typedef for signals sent by this class.
76 typedef SignalV2< void (RenderTask& source) > RenderTaskSignalV2;
79 static const Property::Index VIEWPORT_POSITION; ///< Property 0, name "viewport-position", type VECTOR2
80 static const Property::Index VIEWPORT_SIZE; ///< Property 1, name "viewport-size", type VECTOR2
81 static const Property::Index CLEAR_COLOR; ///< Property 2, name "clear-color", type VECTOR4
84 static const char* const SIGNAL_FINISHED; ///< Name for Finished signal
87 * @brief A pointer to a function for converting screen to frame-buffer coordinates.
88 * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
89 * @return True if the conversion was successful, otherwise coordinates should be unmodified.
91 typedef bool (* ScreenToFrameBufferFunction)( Vector2& coordinates );
94 * @brief A pointer to a function for converting screen to frame-buffer coordinates.
95 * @param[in,out] coordinates The screen coordinates to convert where (0,0) is the top-left of the screen.
96 * @return True if the conversion was successful, otherwise coordinates should be unmodified.
98 typedef bool (* const ConstScreenToFrameBufferFunction)( Vector2& coordinates );
101 * @brief The default conversion function returns false for any screen coordinates.
103 * This effectively disables hit-testing for RenderTasks rendering to a frame buffer.
104 * See also FULLSCREEN_FRAMEBUFFER_FUNCTION below.
106 static ConstScreenToFrameBufferFunction DEFAULT_SCREEN_TO_FRAMEBUFFER_FUNCTION;
109 * @brief This conversion function outputs the (unmodified) screen coordinates as frame-buffer coordinates.
111 * Therefore the contents of an off-screen image is expected to be rendered "full screen".
113 static ConstScreenToFrameBufferFunction FULLSCREEN_FRAMEBUFFER_FUNCTION;
116 * @brief The refresh-rate of the RenderTask.
120 REFRESH_ONCE = 0, ///< Process once only e.g. take a snap-shot of the scene.
121 REFRESH_ALWAYS = 1 ///< Process every frame.
124 static const bool DEFAULT_EXCLUSIVE; ///< false
125 static const bool DEFAULT_INPUT_ENABLED; ///< true
126 static const Vector4 DEFAULT_CLEAR_COLOR; ///< Color::BLACK
127 static const bool DEFAULT_CLEAR_ENABLED; ///< false
128 static const bool DEFAULT_CULL_MODE; ///< true
129 static const unsigned int DEFAULT_REFRESH_RATE; ///< REFRESH_ALWAYS
132 * @brief Create an empty RenderTask handle.
134 * This can be initialised with RenderTaskList::CreateRenderTask().
139 * @brief Downcast a handle to RenderTask handle.
141 * If handle points to a RenderTask the
142 * downcast produces valid handle. If not the returned handle is left uninitialized.
143 * @param[in] handle A handle to an object.
144 * @return A handle to a RenderTask or an uninitialized handle.
146 static RenderTask DownCast( BaseHandle handle );
151 * This is non-virtual since derived Handle types must not contain data or virtual methods.
156 * @copydoc Dali::BaseHandle::operator=
158 using BaseHandle::operator=;
161 * @brief Set the actors to be rendered.
162 * @param[in] actor This actor and its children will be rendered.
163 * If actor is an empty handle, then nothing will be rendered.
165 void SetSourceActor( Actor actor );
168 * @brief Retrieve the actors to be rendered.
169 * @return This actor and its children will be rendered.
171 Actor GetSourceActor() const;
174 * @brief Set whether the RenderTask has exclusive access to the source actors; the default is false.
175 * @param[in] exclusive True if the source actors will only be rendered by this render-task.
177 void SetExclusive( bool exclusive );
180 * @brief Query whether the RenderTask has exclusive access to the source actors.
181 * @return True if the source actors will only be rendered by this render-task.
183 bool IsExclusive() const;
186 * @brief Set whether the render-task should be considered for input handling; the default is true.
188 * The task used for input handling will be last task in the RenderTaskList which has input enabled,
189 * and has a valid source & camera actor.
190 * A RenderTask targetting a frame-buffer can still be hit-tested, provided that the screen->frame-buffer
191 * coordinate conversion is successful; see also SetScreenToFrameBufferFunction().
192 * @param[in] enabled True if the render-task should be considered for input handling.
194 void SetInputEnabled( bool enabled );
197 * @brief Query whether the render-task should be considered for input handling.
198 * @return True if the render-task should be considered for input handling.
200 bool GetInputEnabled() const;
203 * @brief Set the actor from which the scene is viewed.
204 * @param[in] cameraActor The scene is viewed from the perspective of this actor.
206 void SetCameraActor( CameraActor cameraActor );
209 * @brief Retrieve the actor from which the scene is viewed.
210 * @return The scene is viewed from the perspective of this actor.
212 CameraActor GetCameraActor() const;
215 * @brief Set the frame-buffer used as a render target.
216 * @param[in] frameBuffer A valid frame-buffer handle to enable off-screen rendering, or an uninitialized handle to disable.
218 void SetTargetFrameBuffer( FrameBufferImage frameBuffer );
221 * @brief Retrieve the frame-buffer used as a render target.
222 * @return A valid frame-buffer handle, or an uninitialised handle if off-screen rendering is disabled.
224 FrameBufferImage GetTargetFrameBuffer() const;
227 * @brief Set the function used to convert screen coordinates to frame-buffer coordinates.
229 * This is useful for hit-testing actors which are rendered off-screen.
230 * @param[in] conversionFunction The conversion function.
232 void SetScreenToFrameBufferFunction( ScreenToFrameBufferFunction conversionFunction );
235 * @brief Retrieve the function used to convert screen coordinates to frame-buffer coordinates.
236 * @return The conversion function.
238 ScreenToFrameBufferFunction GetScreenToFrameBufferFunction() const;
241 * @brief Set the actor used to convert screen coordinates to frame-buffer coordinates.
243 * The local coordinates of the actor are mapped as frame-buffer coordinates.
244 * This is useful for hit-testing actors which are rendered off-screen.
245 * Note: The mapping actor needs to be rendered by the default render task to make the mapping work properly.
246 * @param[in] mappingActor The actor used for conversion.
248 void SetScreenToFrameBufferMappingActor( Actor mappingActor );
251 * @brief Retrieve the actor used to convert screen coordinates to frame-buffer coordinates.
252 * @return The actor used for conversion.
254 Actor GetScreenToFrameBufferMappingActor() const;
257 * @brief Set the GL viewport position used when rendering.
259 * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
260 * By default this will match the target window or frame-buffer size.
261 * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
262 * @param[in] position The viewports position (x,y)
264 void SetViewportPosition( Vector2 position );
267 * @brief Retrieve the GL viewport position used when rendering.
268 * @return The viewport.
270 Vector2 GetCurrentViewportPosition() const;
273 * @brief Set the GL viewport size used when rendering.
275 * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
276 * By default this will match the target window or frame-buffer size.
277 * @param[in] size The viewports size (width,height)
279 void SetViewportSize( Vector2 size );
282 * @brief Retrieve the GL viewport size used when rendering.
283 * @return The viewport.
285 Vector2 GetCurrentViewportSize() const;
288 * @brief Set the GL viewport used when rendering.
290 * This specifies the transformation between normalized device coordinates and target window (or frame-buffer) coordinates.
291 * By default this will match the target window or frame-buffer size.
292 * @note Unlike the glViewport method, the x & y coordinates refer to the top-left of the viewport rectangle.
293 * @param[in] viewport The new viewport.
295 void SetViewport( Viewport viewport );
298 * @brief Retrieve the GL viewport used when rendering.
299 * @return The viewport.
301 Viewport GetViewport() const;
304 * @brief Set the clear color used when SetClearEnabled(true) is used.
305 * @param[in] color The new clear color.
307 void SetClearColor( const Vector4& color );
310 * @brief Retrieve the clear color used when SetClearEnabled(true) is used.
311 * @note This property can be animated; the return value may not match the value written with SetClearColor().
312 * @return The clear color.
314 Vector4 GetClearColor() const;
317 * @brief Set whether the render-task will clear the results of previous render-tasks.
319 * The default is false.
321 * @note The default GL surface is cleared automatically at the
322 * beginning of each frame; this setting is only useful when 2+
323 * render-tasks are used, and the result of the first task needs to
324 * be (partially) cleared before rendering the second.
326 * @param[in] enabled True if the render-task should clear.
328 void SetClearEnabled( bool enabled );
331 * @brief Query whether the render-task will clear the results of previous render-tasks.
332 * @return True if the render-task should clear.
334 bool GetClearEnabled() const;
337 * @brief Set whether the render task will cull the actors to the camera's view frustum.
339 * Note that this will only affect image actors that use the default vertex shader.
340 * The default mode is to cull actors.
341 * @param[in] cullMode True if the renderers should be culled.
343 void SetCullMode( bool cullMode );
346 * @brief Get the cull mode.
348 * @return True if the render task should cull the actors to the camera's view frustum
350 bool GetCullMode() const;
353 * @brief Set the refresh-rate of the RenderTask.
355 * The default is REFRESH_ALWAYS (1), meaning that the RenderTask will be processed every frame.
356 * It may be desirable to process less frequently e.g. SetRefreshRate(3) will process once every 3 frames.
357 * The REFRESH_ONCE value means that the RenderTask will be processed once only, to take a snap-shot of the scene.
358 * Repeatedly calling SetRefreshRate(REFRESH_ONCE) will cause more snap-shots to be taken.
359 * @param[in] refreshRate The new refresh rate.
361 void SetRefreshRate( unsigned int refreshRate );
364 * @brief Query the refresh-rate of the RenderTask.
365 * @return The refresh-rate.
367 unsigned int GetRefreshRate() const;
372 * @brief If the refresh rate is REFRESH_ONCE, connect to this signal to be notified when a RenderTask has finished.
374 RenderTaskSignalV2& FinishedSignal();
376 public: // Not intended for application developers
379 * @brief This constructor is used by Dali New() methods.
380 * @param [in] renderTask A pointer to a newly allocated render-task
382 explicit DALI_INTERNAL RenderTask( Internal::RenderTask* renderTask );
387 #endif //__DALI_RENDER_TASK_H__