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>
28 #include <dali/internal/event/rendering/texture-impl.h>
36 class GlSyncAbstraction;
62 class RenderInstruction;
63 class RenderInstructionContainer;
65 class PropertyBufferDataProvider;
68 * RenderManager is responsible for rendering the result of the previous "update", which
69 * is provided in a RenderCommand during UpdateManager::Update().
71 class RenderManager : public TextureUploadedDispatcher
76 * Construct a new RenderManager.
77 * @param[in] glAbstraction The GL abstraction used for rendering.
78 * @param[in] glSyncAbstraction The GL sync abstraction used fence sync creation/deletion.
79 * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.*
81 static RenderManager* New( Integration::GlAbstraction& glAbstraction,
82 Integration::GlSyncAbstraction& glSyncAbstraction,
83 LockedResourceQueue& resourcePostProcessQueue );
86 * Non-virtual destructor; not intended as a base class
91 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
92 * @return The render queue.
94 RenderQueue& GetRenderQueue();
97 * Retrieve the texture cache. Messages should only be sent to this from the update thread,
98 * accessor methods should only be used from the render thread.
99 * @return The texture cache
101 TextureCache& GetTextureCache();
104 * @copydoc Dali::Integration::Core::ContextCreated()
106 void ContextCreated();
109 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
111 void ContextDestroyed();
114 * Dispatch requests onto the postProcessResourcesQueue
115 * @param[in] resource The Id of the resource to dispatch
117 virtual void DispatchTextureUploaded( ResourceId resource );
120 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
121 * caching and saving.
122 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
123 * @note This should be called during core initialisation if shader binaries are to be used.
125 void SetShaderSaver( ShaderSaver& upstream );
128 * Retrieve the render instructions; these should be set during each "update" traversal.
129 * @return The render instruction container.
131 RenderInstructionContainer& GetRenderInstructionContainer();
133 // The following methods should be called via RenderQueue messages
136 * Set the background color i.e. the glClear color used at the beginning of each frame.
137 * @param[in] color The new background color.
139 void SetBackgroundColor( const Vector4& color );
142 * Set the frame time delta (time elapsed since the last frame.
143 * @param[in] deltaTime the delta time
145 void SetFrameDeltaTime( float deltaTime );
148 * Returns the rectangle for the default surface (probably the application window).
149 * @return Rectangle for the surface.
151 void SetDefaultSurfaceRect( const Rect<int>& rect );
154 * Add a Renderer to the render manager.
155 * @param[in] renderer The renderer to add.
156 * @post renderer is owned by RenderManager
158 void AddRenderer( Render::Renderer* renderer );
161 * Remove a Renderer from the render manager.
162 * @param[in] renderer The renderer to remove.
163 * @post renderer is destroyed.
165 void RemoveRenderer( Render::Renderer* renderer );
168 * Add a sampler to the render manager.
169 * @param[in] sampler The sampler to add.
170 * @post sampler is owned by RenderManager
172 void AddSampler( Render::Sampler* sampler );
175 * Remove a sampler from the render manager.
176 * @param[in] sampler The sampler to remove.
177 * @post sampler is destroyed.
179 void RemoveSampler( Render::Sampler* sampler );
182 * Set minification and magnification filter modes for a sampler
183 * @param[in] minFilterMode Filter mode to use when the texture is minificated
184 * @param[in] magFilterMode Filter mode to use when the texture is magnified
186 void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
189 * Set wrapping mode for a sampler
190 * @param[in] rWrapMode Wrap mode in the z direction
191 * @param[in] uWrapMode Wrap mode in the x direction
192 * @param[in] vWrapMode Wrap mode in the y direction
194 void SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode );
197 * Add a property buffer to the render manager.
198 * @param[in] propertyBuffer The property buffer to add.
199 * @post propertBuffer is owned by RenderManager
201 void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer );
204 * Remove a property buffer from the render manager.
205 * @param[in] propertyBuffer The property buffer to remove.
206 * @post propertyBuffer is destroyed.
208 void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
211 * Add a geometry to the render manager.
212 * @param[in] geometry The geometry to add.
213 * @post geometry is owned by RenderManager
215 void AddGeometry( Render::Geometry* geometry );
218 * Remove a geometry from the render manager.
219 * @param[in] geometry The geometry to remove.
220 * @post geometry is destroyed.
222 void RemoveGeometry( Render::Geometry* geometry );
225 * Adds a property buffer to a geometry from the render manager.
226 * @param[in] geometry The geometry
227 * @param[in] propertyBuffer The property buffer to remove.
229 void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
232 * Remove a property buffer from a Render::Geometry from the render manager.
233 * @param[in] geometry The geometry
234 * @param[in] propertyBuffer The property buffer to remove.
235 * @post property buffer is destroyed.
237 void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
240 * Sets the format of an existing property buffer
241 * @param[in] propertyBuffer The property buffer.
242 * @param[in] format The new format of the buffer
244 void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
247 * Sets the data of an existing property buffer
248 * @param[in] propertyBuffer The property buffer.
249 * @param[in] data The new data of the buffer
250 * @param[in] size The new size of the buffer
252 void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size );
255 * Sets the data for the index buffer of an existing geometry
256 * @param[in] geometry The geometry
257 * @param[in] data A vector containing the indices
259 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& data );
262 * Set the geometry type of an existing render geometry
263 * @param[in] geometry The render geometry
264 * @param[in] geometryType The new geometry type
266 void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
269 * Adds a texture to the render manager
270 * @param[in] texture The texture to add
272 void AddTexture( Render::NewTexture* texture );
275 * Removes a texture from the render manager
276 * @param[in] texture The texture to remove
278 void RemoveTexture( Render::NewTexture* texture );
281 * Uploads data to an existing texture
282 * @param[in] texture The texture
283 * @param[in] pixelData The pixel data object
284 * @param[in] params The parameters for the upload
286 void UploadTexture( Render::NewTexture* texture, PixelDataPtr pixelData, const NewTexture::UploadParams& params );
289 * Generates mipmaps for a given texture
290 * @param[in] texture The texture
292 void GenerateMipmaps( Render::NewTexture* texture );
295 * Adds a framebuffer to the render manager
296 * @param[in] frameBuffer The framebuffer to add
298 void AddFrameBuffer( Render::FrameBuffer* frameBuffer );
301 * Removes a framebuffer from the render manager
302 * @param[in] frameBuffer The framebuffer to remove
304 void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
307 * Attach a texture as color output to an existing FrameBuffer
308 * @param[in] frameBuffer The FrameBuffer
309 * @param[in] texture The texture that will be used as output when rendering
310 * @param[in] mipmapLevel The mipmap of the texture to be attached
311 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
313 void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int layer );
316 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
317 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
318 * object, usually an offscreen render task.
319 * @param[in] renderTracker The render tracker
321 void AddRenderTracker( Render::RenderTracker* renderTracker );
324 * Removes a render tracker from the RenderManager.
325 * @param[in] renderTracker The render tracker to remove.
327 void RemoveRenderTracker( Render::RenderTracker* renderTracker );
330 * Set the default shader that is to be used in absence of custom shader
331 * @param[in] shader that is the default one
333 void SetDefaultShader( Shader* shader );
336 * returns the Program controller for sending program messages
337 * @return the ProgramController
339 ProgramCache* GetProgramCache();
341 // This method should be called from Core::Render()
344 * Renders the results of the previous "update" traversal.
345 * @param[out] status contains the flag that indicates if render instructions exist
346 * @return true if a further update is required
348 bool Render( Integration::RenderStatus& status );
353 * Helper to process a single RenderInstruction.
354 * @param[in] instruction A description of the rendering operation.
355 * @param[in] defaultShader default shader to use.
357 void DoRender( RenderInstruction& instruction, Shader& defaultShader );
362 * Construct a new RenderManager.
367 RenderManager( const RenderManager& );
370 RenderManager& operator=( const RenderManager& rhs );
379 } // namespace SceneGraph
381 } // namespace Internal
385 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__