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>
51 class RenderInstruction;
52 class RenderInstructionContainer;
56 class PropertyBufferDataProvider;
59 * RenderManager is responsible for rendering the result of the previous "update", which
60 * is provided in a RenderCommand during UpdateManager::Update().
62 class RenderManager : public PostProcessResourceDispatcher
67 * Construct a new RenderManager.
68 * @param[in] glAbstraction The GL abstraction used for rendering.
69 * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
71 static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
74 * Non-virtual destructor; not intended as a base class
79 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
80 * @return The render queue.
82 RenderQueue& GetRenderQueue();
85 * Retrieve the texture cache. Messages should only be sent to this from the update thread,
86 * accessor methods should only be used from the render thread.
87 * @return The texture cache
89 TextureCache& GetTextureCache();
92 * @copydoc Dali::Integration::Core::ContextCreated()
94 void ContextCreated();
97 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
99 void ContextDestroyed();
102 * Dispatch requests onto the postProcessResourcesQueue
103 * @param[in] request The request to dispatch
105 virtual void DispatchPostProcessRequest( ResourcePostProcessRequest& request );
108 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
109 * caching and saving.
110 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
111 * @note This should be called during core initialisation if shader binaries are to be used.
113 void SetShaderSaver( ShaderSaver& upstream );
116 * Retrieve the render instructions; these should be set during each "update" traversal.
117 * @return The render instruction container.
119 RenderInstructionContainer& GetRenderInstructionContainer();
121 // The following methods should be called via RenderQueue messages
124 * Set the background color i.e. the glClear color used at the beginning of each frame.
125 * @param[in] color The new background color.
127 void SetBackgroundColor( const Vector4& color );
130 * Set the frame time delta (time elapsed since the last frame.
131 * @param[in] deltaTime the delta time
133 void SetFrameDeltaTime( float deltaTime );
136 * Returns the rectangle for the default surface (probably the application window).
137 * @return Rectangle for the surface.
139 void SetDefaultSurfaceRect( const Rect<int>& rect );
142 * Add a Renderer to the render manager.
143 * @param[in] renderer The renderer to add.
144 * @post renderer is owned by RenderManager
146 void AddRenderer( Renderer* renderer );
149 * Remove a Renderer from the render manager.
150 * @param[in] renderer The renderer to remove.
151 * @post renderer is destroyed.
153 void RemoveRenderer( Renderer* renderer );
156 * Add a geometry to the render manager.
157 * @param[in] geometry The geometry to add.
158 * @post geometry is owned by RenderManager
160 void AddGeometry( RenderGeometry* geometry );
163 * Remove a geometry from the render manager.
164 * @param[in] geometry The geometry to remove.
165 * @post geometry is destroyed.
167 void RemoveGeometry( RenderGeometry* geometry );
170 * Adds a property buffer to a RenderGeometry from the render manager.
171 * @param[in] geometry The geometry
172 * @param[in] propertyBuffer The property buffer to remove.
173 * @param[in] target Specifies the type of the buffer
174 * @param[in] usage Specifies how will the buffer be used
176 void AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer, const GpuBuffer::Target& target, const GpuBuffer::Usage& usage );
179 * Remove a property buffer from a RenderGeometry from the render manager.
180 * @param[in] geometry The geometry
181 * @param[in] propertyBuffer The property buffer to remove.
182 * @post property buffer is destroyed.
184 void RemovePropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer );
187 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
188 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
189 * object, usually an offscreen render task.
190 * @param[in] renderTracker The render tracker
192 void AddRenderTracker( RenderTracker* renderTracker );
195 * Removes a render tracker from the RenderManager.
196 * @param[in] renderTracker The render tracker to remove.
198 void RemoveRenderTracker( RenderTracker* renderTracker );
201 * Set the default shader that is to be used in absence of custom shader
202 * @param[in] shader that is the default one
204 void SetDefaultShader( Shader* shader );
207 * returns the Program controller for sending program messages
208 * @return the ProgramController
210 ProgramCache* GetProgramCache();
212 // This method should be called from Core::Render()
215 * Renders the results of the previous "update" traversal.
216 * @param[out] status contains the flag that indicates if render instructions exist
217 * @return true if a further update is required
219 bool Render( Integration::RenderStatus& status );
224 * Helper to process a single RenderInstruction.
225 * @param[in] instruction A description of the rendering operation.
226 * @param[in] defaultShader default shader to use.
227 * @param[in] elapsedTime from previous render.
229 void DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime );
234 * Construct a new RenderManager.
239 RenderManager( const RenderManager& );
242 RenderManager& operator=( const RenderManager& rhs );
244 // Set the last frame time while locking access
245 void SetLastFrameTime();
255 } // namespace SceneGraph
257 } // namespace Internal
261 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__