1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
5 * Copyright (c) 2015 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>
35 class GlSyncAbstraction;
58 class RenderInstruction;
59 class RenderInstructionContainer;
62 class PropertyBufferDataProvider;
65 * RenderManager is responsible for rendering the result of the previous "update", which
66 * is provided in a RenderCommand during UpdateManager::Update().
68 class RenderManager : public PostProcessResourceDispatcher
73 * Construct a new RenderManager.
74 * @param[in] glAbstraction The GL abstraction used for rendering.
75 * @param[in] glSyncAbstraction The GL sync abstraction used fence sync creation/deletion.
76 * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
78 static RenderManager* New( Integration::GlAbstraction& glAbstraction,
79 Integration::GlSyncAbstraction& glSyncAbstraction,
80 ResourcePostProcessList& resourcePostProcessQueue );
83 * Non-virtual destructor; not intended as a base class
88 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
89 * @return The render queue.
91 RenderQueue& GetRenderQueue();
94 * Retrieve the texture cache. Messages should only be sent to this from the update thread,
95 * accessor methods should only be used from the render thread.
96 * @return The texture cache
98 TextureCache& GetTextureCache();
101 * @copydoc Dali::Integration::Core::ContextCreated()
103 void ContextCreated();
106 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
108 void ContextDestroyed();
111 * Dispatch requests onto the postProcessResourcesQueue
112 * @param[in] request The request to dispatch
114 virtual void DispatchPostProcessRequest( ResourcePostProcessRequest& request );
117 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
118 * caching and saving.
119 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
120 * @note This should be called during core initialisation if shader binaries are to be used.
122 void SetShaderSaver( ShaderSaver& upstream );
125 * Retrieve the render instructions; these should be set during each "update" traversal.
126 * @return The render instruction container.
128 RenderInstructionContainer& GetRenderInstructionContainer();
130 // The following methods should be called via RenderQueue messages
133 * Set the background color i.e. the glClear color used at the beginning of each frame.
134 * @param[in] color The new background color.
136 void SetBackgroundColor( const Vector4& color );
139 * Set the frame time delta (time elapsed since the last frame.
140 * @param[in] deltaTime the delta time
142 void SetFrameDeltaTime( float deltaTime );
145 * Returns the rectangle for the default surface (probably the application window).
146 * @return Rectangle for the surface.
148 void SetDefaultSurfaceRect( const Rect<int>& rect );
151 * Add a Renderer to the render manager.
152 * @param[in] renderer The renderer to add.
153 * @post renderer is owned by RenderManager
155 void AddRenderer( Render::Renderer* renderer );
158 * Remove a Renderer from the render manager.
159 * @param[in] renderer The renderer to remove.
160 * @post renderer is destroyed.
162 void RemoveRenderer( Render::Renderer* renderer );
165 * Add a sampler to the render manager.
166 * @param[in] sampler The sampler to add.
167 * @post sampler is owned by RenderManager
169 void AddSampler( Render::Sampler* sampler );
172 * Remove a sampler from the render manager.
173 * @param[in] sampler The sampler to remove.
174 * @post sampler is destroyed.
176 void RemoveSampler( Render::Sampler* sampler );
179 * Set minification and magnification filter modes for a sampler
180 * @param[in] minFilterMode Filter mode to use when the texture is minificated
181 * @param[in] magFilterMode Filter mode to use when the texture is magnified
183 void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
186 * Set wrapping mode for a sampler
187 * @param[in] uWrapMode Wrap mode in the x direction
188 * @param[in] vWrapMode Wrap mode in the y direction
190 void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode );
193 * Add a property buffer to the render manager.
194 * @param[in] propertyBuffer The property buffer to add.
195 * @post propertBuffer is owned by RenderManager
197 void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer );
200 * Remove a property buffer from the render manager.
201 * @param[in] propertyBuffer The property buffer to remove.
202 * @post propertyBuffer is destroyed.
204 void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
207 * Add a geometry to the render manager.
208 * @param[in] geometry The geometry to add.
209 * @post geometry is owned by RenderManager
211 void AddGeometry( RenderGeometry* geometry );
214 * Remove a geometry from the render manager.
215 * @param[in] geometry The geometry to remove.
216 * @post geometry is destroyed.
218 void RemoveGeometry( RenderGeometry* geometry );
221 * Adds a property buffer to a RenderGeometry from the render manager.
222 * @param[in] geometry The geometry
223 * @param[in] propertyBuffer The property buffer to remove.
224 * @param[in] isIndexBuffer True if the property buffer is intended to be used as an index buffer
226 void AddPropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer, bool isIndexBuffer );
229 * Remove a property buffer from a RenderGeometry from the render manager.
230 * @param[in] geometry The geometry
231 * @param[in] propertyBuffer The property buffer to remove.
232 * @post property buffer is destroyed.
234 void RemovePropertyBuffer( RenderGeometry* renderGeometry, Render::PropertyBuffer* propertyBuffer );
237 * Sets the format of an existing property buffer
238 * @param[in] propertyBuffer The property buffer.
239 * @param[in] format The new format of the buffer
241 void SetPropertyBufferFormat(Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
244 * Sets the data of an existing property buffer
245 * @param[in] propertyBuffer The property buffer.
246 * @param[in] data The new data of the buffer
248 void SetPropertyBufferData(Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data);
251 * Sets the size of an existing property buffer
252 * @param[in] propertyBuffer The property buffer.
253 * @param[in] size The new size of the buffer
255 void SetPropertyBufferSize(Render::PropertyBuffer* propertyBuffer, size_t size );
258 * Set the geometry type of an existing render geometry
259 * @param[in] geometry The render geometry
260 * @param[in] geometryType The new geometry type
262 void SetGeometryType( RenderGeometry* geometry, int geometryType );
265 * Set if an existing geometry requires depth testing
266 * @param[in] geometry The render geometry
267 * @param[in] requiresDepthTest True if depth testing is required, false otherwise
269 void SetGeometryRequiresDepthTest( RenderGeometry* geometry, bool requiresDepthTest );
272 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
273 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
274 * object, usually an offscreen render task.
275 * @param[in] renderTracker The render tracker
277 void AddRenderTracker( Render::RenderTracker* renderTracker );
280 * Removes a render tracker from the RenderManager.
281 * @param[in] renderTracker The render tracker to remove.
283 void RemoveRenderTracker( Render::RenderTracker* renderTracker );
286 * Set the default shader that is to be used in absence of custom shader
287 * @param[in] shader that is the default one
289 void SetDefaultShader( Shader* shader );
292 * returns the Program controller for sending program messages
293 * @return the ProgramController
295 ProgramCache* GetProgramCache();
297 // This method should be called from Core::Render()
300 * Renders the results of the previous "update" traversal.
301 * @param[out] status contains the flag that indicates if render instructions exist
302 * @return true if a further update is required
304 bool Render( Integration::RenderStatus& status );
309 * Helper to process a single RenderInstruction.
310 * @param[in] instruction A description of the rendering operation.
311 * @param[in] defaultShader default shader to use.
313 void DoRender( RenderInstruction& instruction, Shader& defaultShader );
318 * Construct a new RenderManager.
323 RenderManager( const RenderManager& );
326 RenderManager& operator=( const RenderManager& rhs );
335 } // namespace SceneGraph
337 } // namespace Internal
341 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__