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>
55 class RenderInstruction;
56 class RenderInstructionContainer;
60 class PropertyBufferDataProvider;
63 * RenderManager is responsible for rendering the result of the previous "update", which
64 * is provided in a RenderCommand during UpdateManager::Update().
66 class RenderManager : public PostProcessResourceDispatcher
71 * Construct a new RenderManager.
72 * @param[in] glAbstraction The GL abstraction used for rendering.
73 * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
75 static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
78 * Non-virtual destructor; not intended as a base class
83 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
84 * @return The render queue.
86 RenderQueue& GetRenderQueue();
89 * Retrieve the texture cache. Messages should only be sent to this from the update thread,
90 * accessor methods should only be used from the render thread.
91 * @return The texture cache
93 TextureCache& GetTextureCache();
96 * @copydoc Dali::Integration::Core::ContextCreated()
98 void ContextCreated();
101 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
103 void ContextDestroyed();
106 * Dispatch requests onto the postProcessResourcesQueue
107 * @param[in] request The request to dispatch
109 virtual void DispatchPostProcessRequest( ResourcePostProcessRequest& request );
112 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
113 * caching and saving.
114 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
115 * @note This should be called during core initialisation if shader binaries are to be used.
117 void SetShaderSaver( ShaderSaver& upstream );
120 * Retrieve the render instructions; these should be set during each "update" traversal.
121 * @return The render instruction container.
123 RenderInstructionContainer& GetRenderInstructionContainer();
125 // The following methods should be called via RenderQueue messages
128 * Set the background color i.e. the glClear color used at the beginning of each frame.
129 * @param[in] color The new background color.
131 void SetBackgroundColor( const Vector4& color );
134 * Set the frame time delta (time elapsed since the last frame.
135 * @param[in] deltaTime the delta time
137 void SetFrameDeltaTime( float deltaTime );
140 * Returns the rectangle for the default surface (probably the application window).
141 * @return Rectangle for the surface.
143 void SetDefaultSurfaceRect( const Rect<int>& rect );
146 * Add a Renderer to the render manager.
147 * @param[in] renderer The renderer to add.
148 * @post renderer is owned by RenderManager
150 void AddRenderer( Render::Renderer* renderer );
153 * Remove a Renderer from the render manager.
154 * @param[in] renderer The renderer to remove.
155 * @post renderer is destroyed.
157 void RemoveRenderer( Render::Renderer* renderer );
160 * Add a geometry to the render manager.
161 * @param[in] geometry The geometry to add.
162 * @post geometry is owned by RenderManager
164 void AddGeometry( RenderGeometry* geometry );
167 * Remove a geometry from the render manager.
168 * @param[in] geometry The geometry to remove.
169 * @post geometry is destroyed.
171 void RemoveGeometry( RenderGeometry* geometry );
174 * Adds a property buffer to a RenderGeometry from the render manager.
175 * @param[in] geometry The geometry
176 * @param[in] propertyBuffer The property buffer to remove.
177 * @param[in] target Specifies the type of the buffer
178 * @param[in] usage Specifies how will the buffer be used
180 void AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer, const GpuBuffer::Target& target, const GpuBuffer::Usage& usage );
183 * Remove a property buffer from a RenderGeometry from the render manager.
184 * @param[in] geometry The geometry
185 * @param[in] propertyBuffer The property buffer to remove.
186 * @post property buffer is destroyed.
188 void RemovePropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer );
191 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
192 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
193 * object, usually an offscreen render task.
194 * @param[in] renderTracker The render tracker
196 void AddRenderTracker( RenderTracker* renderTracker );
199 * Removes a render tracker from the RenderManager.
200 * @param[in] renderTracker The render tracker to remove.
202 void RemoveRenderTracker( RenderTracker* renderTracker );
205 * Set the default shader that is to be used in absence of custom shader
206 * @param[in] shader that is the default one
208 void SetDefaultShader( Shader* shader );
211 * returns the Program controller for sending program messages
212 * @return the ProgramController
214 ProgramCache* GetProgramCache();
216 // This method should be called from Core::Render()
219 * Renders the results of the previous "update" traversal.
220 * @param[out] status contains the flag that indicates if render instructions exist
221 * @return true if a further update is required
223 bool Render( Integration::RenderStatus& status );
228 * Helper to process a single RenderInstruction.
229 * @param[in] instruction A description of the rendering operation.
230 * @param[in] defaultShader default shader to use.
231 * @param[in] elapsedTime from previous render.
233 void DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime );
238 * Construct a new RenderManager.
243 RenderManager( const RenderManager& );
246 RenderManager& operator=( const RenderManager& rhs );
248 // Set the last frame time while locking access
249 void SetLastFrameTime();
259 } // namespace SceneGraph
261 } // namespace Internal
265 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__