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/update/resources/resource-manager-declarations.h>
25 #include <dali/internal/render/common/texture-uploaded-dispatcher.h>
26 #include <dali/internal/render/gl-resources/gpu-buffer.h>
27 #include <dali/internal/render/renderers/render-property-buffer.h>
35 class GlSyncAbstraction;
59 class RenderInstruction;
60 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 TextureUploadedDispatcher
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 LockedResourceQueue& 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] resource The Id of the resource to dispatch
114 virtual void DispatchTextureUploaded( ResourceId resource );
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( Render::Geometry* 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( Render::Geometry* geometry );
221 * Adds a property buffer to a geometry from the render manager.
222 * @param[in] geometry The geometry
223 * @param[in] propertyBuffer The property buffer to remove.
225 void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
228 * Remove a property buffer from a Render::Geometry from the render manager.
229 * @param[in] geometry The geometry
230 * @param[in] propertyBuffer The property buffer to remove.
231 * @post property buffer is destroyed.
233 void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
236 * Sets the format of an existing property buffer
237 * @param[in] propertyBuffer The property buffer.
238 * @param[in] format The new format of the buffer
240 void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
243 * Sets the data of an existing property buffer
244 * @param[in] propertyBuffer The property buffer.
245 * @param[in] data The new data of the buffer
246 * @param[in] size The new size of the buffer
248 void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size );
251 * Sets the data for the index buffer of an existing geometry
252 * @param[in] geometry The geometry
253 * @param[in] data A vector containing the indices
255 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& data );
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( Render::Geometry* geometry, unsigned int geometryType );
265 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
266 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
267 * object, usually an offscreen render task.
268 * @param[in] renderTracker The render tracker
270 void AddRenderTracker( Render::RenderTracker* renderTracker );
273 * Removes a render tracker from the RenderManager.
274 * @param[in] renderTracker The render tracker to remove.
276 void RemoveRenderTracker( Render::RenderTracker* renderTracker );
279 * Set the default shader that is to be used in absence of custom shader
280 * @param[in] shader that is the default one
282 void SetDefaultShader( Shader* shader );
285 * returns the Program controller for sending program messages
286 * @return the ProgramController
288 ProgramCache* GetProgramCache();
290 // This method should be called from Core::Render()
293 * Renders the results of the previous "update" traversal.
294 * @param[out] status contains the flag that indicates if render instructions exist
295 * @return true if a further update is required
297 bool Render( Integration::RenderStatus& status );
302 * Helper to process a single RenderInstruction.
303 * @param[in] instruction A description of the rendering operation.
304 * @param[in] defaultShader default shader to use.
306 void DoRender( RenderInstruction& instruction, Shader& defaultShader );
311 * Construct a new RenderManager.
316 RenderManager( const RenderManager& );
319 RenderManager& operator=( const RenderManager& rhs );
328 } // namespace SceneGraph
330 } // namespace Internal
334 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__