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/public-api/math/rect.h>
23 #include <dali/internal/common/shader-saver.h>
24 #include <dali/internal/render/common/post-process-resource-dispatcher.h>
25 #include <dali/internal/update/resources/resource-manager-declarations.h>
26 #include <dali/internal/render/gl-resources/gpu-buffer.h>
27 #include <dali/internal/render/renderers/render-property-buffer.h>
56 class RenderInstruction;
57 class RenderInstructionContainer;
61 class PropertyBufferDataProvider;
64 * RenderManager is responsible for rendering the result of the previous "update", which
65 * is provided in a RenderCommand during UpdateManager::Update().
67 class RenderManager : public PostProcessResourceDispatcher
72 * Construct a new RenderManager.
73 * @param[in] glAbstraction The GL abstraction used for rendering.
74 * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
76 static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
79 * Non-virtual destructor; not intended as a base class
84 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
85 * @return The render queue.
87 RenderQueue& GetRenderQueue();
90 * Retrieve the texture cache. Messages should only be sent to this from the update thread,
91 * accessor methods should only be used from the render thread.
92 * @return The texture cache
94 TextureCache& GetTextureCache();
97 * @copydoc Dali::Integration::Core::ContextCreated()
99 void ContextCreated();
102 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
104 void ContextDestroyed();
107 * Dispatch requests onto the postProcessResourcesQueue
108 * @param[in] request The request to dispatch
110 virtual void DispatchPostProcessRequest( ResourcePostProcessRequest& request );
113 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
114 * caching and saving.
115 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
116 * @note This should be called during core initialisation if shader binaries are to be used.
118 void SetShaderSaver( ShaderSaver& upstream );
121 * Retrieve the render instructions; these should be set during each "update" traversal.
122 * @return The render instruction container.
124 RenderInstructionContainer& GetRenderInstructionContainer();
126 // The following methods should be called via RenderQueue messages
129 * Set the background color i.e. the glClear color used at the beginning of each frame.
130 * @param[in] color The new background color.
132 void SetBackgroundColor( const Vector4& color );
135 * Set the frame time delta (time elapsed since the last frame.
136 * @param[in] deltaTime the delta time
138 void SetFrameDeltaTime( float deltaTime );
141 * Returns the rectangle for the default surface (probably the application window).
142 * @return Rectangle for the surface.
144 void SetDefaultSurfaceRect( const Rect<int>& rect );
147 * Add a Renderer to the render manager.
148 * @param[in] renderer The renderer to add.
149 * @post renderer is owned by RenderManager
151 void AddRenderer( Render::Renderer* renderer );
154 * Remove a Renderer from the render manager.
155 * @param[in] renderer The renderer to remove.
156 * @post renderer is destroyed.
158 void RemoveRenderer( Render::Renderer* renderer );
161 * Add a sampler to the render manager.
162 * @param[in] sampler The sampler to add.
163 * @post sampler is owned by RenderManager
165 void AddSampler( Render::Sampler* sampler );
168 * Remove a sampler from the render manager.
169 * @param[in] sampler The sampler to remove.
170 * @post sampler is destroyed.
172 void RemoveSampler( Render::Sampler* sampler );
175 * Set minification and magnification filter modes for a sampler
176 * @param[in] minFilterMode Filter mode to use when the texture is minificated
177 * @param[in] magFilterMode Filter mode to use when the texture is magnified
179 void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
182 * Set wrapping mode for a sampler
183 * @param[in] uWrapMode Wrap mode in the x direction
184 * @param[in] vWrapMode Wrap mode in the y direction
186 void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode );
189 * Add a property buffer to the render manager.
190 * @param[in] propertyBuffer The property buffer to add.
191 * @post propertBuffer is owned by RenderManager
193 void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer );
196 * Remove a property buffer from the render manager.
197 * @param[in] propertyBuffer The property buffer to remove.
198 * @post propertyBuffer is destroyed.
200 void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
203 * Add a geometry to the render manager.
204 * @param[in] geometry The geometry to add.
205 * @post geometry is owned by RenderManager
207 void AddGeometry( RenderGeometry* geometry );
210 * Remove a geometry from the render manager.
211 * @param[in] geometry The geometry to remove.
212 * @post geometry is destroyed.
214 void RemoveGeometry( RenderGeometry* geometry );
217 * Adds a property buffer to a RenderGeometry from the render manager.
218 * @param[in] geometry The geometry
219 * @param[in] propertyBuffer The property buffer to remove.
220 * @param[in] isIndexBuffer True if the property buffer is intended to be used as an index buffer
222 void AddPropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer );
225 * Remove a property buffer from a RenderGeometry from the render manager.
226 * @param[in] geometry The geometry
227 * @param[in] propertyBuffer The property buffer to remove.
228 * @post property buffer is destroyed.
230 void RemovePropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer );
233 * Sets the format of an existing property buffer
234 * @param[in] propertyBuffer The property buffer.
235 * @param[in] format The new format of the buffer
237 void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
240 * Sets the data of an existing property buffer
241 * @param[in] propertyBuffer The property buffer.
242 * @param[in] data The new data of the buffer
244 void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data);
247 * Sets the size of an existing property buffer
248 * @param[in] propertyBuffer The property buffer.
249 * @param[in] size The new size of the buffer
251 void SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size );
254 * Set the geometry type of an existing render geometry
255 * @param[in] geometry The render geometry
256 * @param[in] geometryType The new geometry type
258 void SetGeometryType( RenderGeometry* geometry, int geometryType );
261 * Set if an existing geometry requires depth testing
262 * @param[in] geometry The render geometry
263 * @param[in] requiresDepthTest True if depth testing is required, false otherwise
265 void SetGeometryRequiresDepthTest( RenderGeometry* geometry, bool requiresDepthTest );
268 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
269 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
270 * object, usually an offscreen render task.
271 * @param[in] renderTracker The render tracker
273 void AddRenderTracker( RenderTracker* renderTracker );
276 * Removes a render tracker from the RenderManager.
277 * @param[in] renderTracker The render tracker to remove.
279 void RemoveRenderTracker( RenderTracker* renderTracker );
282 * Set the default shader that is to be used in absence of custom shader
283 * @param[in] shader that is the default one
285 void SetDefaultShader( Shader* shader );
288 * returns the Program controller for sending program messages
289 * @return the ProgramController
291 ProgramCache* GetProgramCache();
293 // This method should be called from Core::Render()
296 * Renders the results of the previous "update" traversal.
297 * @param[out] status contains the flag that indicates if render instructions exist
298 * @return true if a further update is required
300 bool Render( Integration::RenderStatus& status );
305 * Helper to process a single RenderInstruction.
306 * @param[in] instruction A description of the rendering operation.
307 * @param[in] defaultShader default shader to use.
309 void DoRender( RenderInstruction& instruction, Shader& defaultShader );
314 * Construct a new RenderManager.
319 RenderManager( const RenderManager& );
322 RenderManager& operator=( const RenderManager& rhs );
331 } // namespace SceneGraph
333 } // namespace Internal
337 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__