1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_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/devel-api/common/mutex.h>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/internal/common/shader-saver.h>
25 #include <dali/internal/render/common/post-process-resource-dispatcher.h>
26 #include <dali/internal/update/resources/resource-manager-declarations.h>
27 #include <dali/internal/render/gl-resources/gpu-buffer.h>
50 class NodeDataProvider;
53 class RenderInstruction;
54 class RenderInstructionContainer;
58 class PropertyBufferDataProvider;
61 * RenderManager is responsible for rendering the result of the previous "update", which
62 * is provided in a RenderCommand during UpdateManager::Update().
64 class RenderManager : public PostProcessResourceDispatcher
69 * Construct a new RenderManager.
70 * @param[in] glAbstraction The GL abstraction used for rendering.
71 * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
73 static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
76 * Non-virtual destructor; not intended as a base class
81 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
82 * @return The render queue.
84 RenderQueue& GetRenderQueue();
87 * Retrieve the texture cache. Messages should only be sent to this from the update thread,
88 * accessor methods should only be used from the render thread.
89 * @return The texture cache
91 TextureCache& GetTextureCache();
94 * @copydoc Dali::Integration::Core::ContextCreated()
96 void ContextCreated();
99 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
101 void ContextDestroyed();
104 * Dispatch requests onto the postProcessResourcesQueue
105 * @param[in] request The request to dispatch
107 virtual void DispatchPostProcessRequest( ResourcePostProcessRequest& request );
110 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
111 * caching and saving.
112 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
113 * @note This should be called during core initialisation if shader binaries are to be used.
115 void SetShaderSaver( ShaderSaver& upstream );
118 * Retrieve the render instructions; these should be set during each "update" traversal.
119 * @return The render instruction container.
121 RenderInstructionContainer& GetRenderInstructionContainer();
123 // The following methods should be called via RenderQueue messages
126 * Set the background color i.e. the glClear color used at the beginning of each frame.
127 * @param[in] color The new background color.
129 void SetBackgroundColor( const Vector4& color );
132 * Set the frame time delta (time elapsed since the last frame.
133 * @param[in] deltaTime the delta time
135 void SetFrameDeltaTime( float deltaTime );
138 * Returns the rectangle for the default surface (probably the application window).
139 * @return Rectangle for the surface.
141 void SetDefaultSurfaceRect( const Rect<int>& rect );
144 * Add a Renderer to the render manager.
145 * @param[in] renderer The renderer to add.
146 * @post renderer is owned by RenderManager
148 void AddRenderer( Renderer* renderer );
151 * Remove a Renderer from the render manager.
152 * @param[in] renderer The renderer to remove.
153 * @post renderer is destroyed.
155 void RemoveRenderer( Renderer* renderer );
158 * Add an image renderer in the render-thread.
159 * ImageRenderers are not owned by render-manager; this is just for initialization.
160 * @param[in] renderer The renderer to add.
161 * @param[in] dataProvider The Node using this image renderer.
163 void AddImageRenderer( ImageRenderer* renderer, NodeDataProvider* dataProvider );
166 * Remove an image renderer in the render-thread.
167 * ImageRenderers are not owned by render-manager; this is just for GL cleanup.
168 * @param[in] renderer The renderer to remove.
170 void RemoveImageRenderer( ImageRenderer* renderer );
173 * Add a geometry to the render manager.
174 * @param[in] geometry The geometry to add.
175 * @post geometry is owned by RenderManager
177 void AddGeometry( RenderGeometry* geometry );
180 * Remove a geometry from the render manager.
181 * @param[in] geometry The geometry to remove.
182 * @post geometry is destroyed.
184 void RemoveGeometry( RenderGeometry* geometry );
187 * Adds a property buffer to a RenderGeometry from the render manager.
188 * @param[in] geometry The geometry
189 * @param[in] propertyBuffer The property buffer to remove.
190 * @param[in] target Specifies the type of the buffer
191 * @param[in] usage Specifies how will the buffer be used
193 void AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer, const GpuBuffer::Target& target, const GpuBuffer::Usage& usage );
196 * Remove a property buffer from a RenderGeometry from the render manager.
197 * @param[in] geometry The geometry
198 * @param[in] propertyBuffer The property buffer to remove.
199 * @post property buffer is destroyed.
201 void RemovePropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer );
204 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
205 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
206 * object, usually an offscreen render task.
207 * @param[in] renderTracker The render tracker
209 void AddRenderTracker( RenderTracker* renderTracker );
212 * Removes a render tracker from the RenderManager.
213 * @param[in] renderTracker The render tracker to remove.
215 void RemoveRenderTracker( RenderTracker* renderTracker );
218 * Set the default shader that is to be used in absence of custom shader
219 * @param[in] shader that is the default one
221 void SetDefaultShader( Shader* shader );
224 * returns the Program controller for sending program messages
225 * @return the ProgramController
227 ProgramCache* GetProgramCache();
229 // This method should be called from Core::Render()
232 * Renders the results of the previous "update" traversal.
233 * @param[out] status contains the flag that indicates if render instructions exist
234 * @return true if a further update is required
236 bool Render( Integration::RenderStatus& status );
241 * @copydoc Dali::Integration::Core::SetPixmapYInverted()
243 void SetPixmapYInverted( bool yInverted );
248 * Helper to process a single RenderInstruction.
249 * @param[in] instruction A description of the rendering operation.
250 * @param[in] defaultShader default shader to use.
251 * @param[in] elapsedTime from previous render.
253 void DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime );
258 * Construct a new RenderManager.
263 RenderManager( const RenderManager& );
266 RenderManager& operator=( const RenderManager& rhs );
268 // Set the last frame time while locking access
269 void SetLastFrameTime();
279 } // namespace SceneGraph
281 } // namespace Internal
285 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__