1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
5 * Copyright (c) 2020 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/integration-api/core-enumerations.h>
24 #include <dali/internal/common/shader-saver.h>
25 #include <dali/internal/event/rendering/texture-impl.h>
26 #include <dali/internal/render/gl-resources/gpu-buffer.h>
27 #include <dali/internal/render/renderers/render-vertex-buffer.h>
35 class GlSyncAbstraction;
36 class GlContextHelperAbstraction;
62 class RenderInstruction;
63 class RenderInstructionContainer;
68 * RenderManager is responsible for rendering the result of the previous "update", which
69 * is provided in a RenderCommand during UpdateManager::Update().
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[in] glContextHelperAbstraction The GL context helper abstraction for accessing GL context.
80 * @param[in] depthBufferAvailable Whether the depth buffer is available
81 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
83 static RenderManager* New( Integration::GlAbstraction& glAbstraction,
84 Integration::GlSyncAbstraction& glSyncAbstraction,
85 Integration::GlContextHelperAbstraction& glContextHelperAbstraction,
86 Integration::DepthBufferAvailable depthBufferAvailable,
87 Integration::StencilBufferAvailable stencilBufferAvailable,
88 Integration::PartialUpdateAvailable partialUpdateAvailable );
91 * Non-virtual destructor; not intended as a base class
96 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
97 * @return The render queue.
99 RenderQueue& GetRenderQueue();
102 * @copydoc Dali::Integration::Core::ContextCreated()
104 void ContextCreated();
107 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
109 void ContextDestroyed();
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 );
119 // The following methods should be called via RenderQueue messages
122 * Set the frame time delta (time elapsed since the last frame.
123 * @param[in] deltaTime the delta time
125 void SetFrameDeltaTime( float deltaTime );
128 * Returns the rectangle for the default surface (probably the application window).
129 * @return Rectangle for the surface.
131 void SetDefaultSurfaceRect( const Rect<int>& rect );
134 * Returns the orintation for the default surface (probably the application window).
135 * @return Orientation for the surface.
137 void SetDefaultSurfaceOrientation( int orientation );
140 * Add a Renderer to the render manager.
141 * @param[in] renderer The renderer to add.
142 * @post renderer is owned by RenderManager
144 void AddRenderer( OwnerPointer< Render::Renderer >& renderer );
147 * Remove a Renderer from the render manager.
148 * @param[in] renderer The renderer to remove.
149 * @post renderer is destroyed.
151 void RemoveRenderer( Render::Renderer* renderer );
154 * Add a sampler to the render manager.
155 * @param[in] sampler The sampler to add.
156 * @post sampler is owned by RenderManager
158 void AddSampler( OwnerPointer< Render::Sampler >& sampler );
161 * Remove a sampler from the render manager.
162 * @param[in] sampler The sampler to remove.
163 * @post sampler is destroyed.
165 void RemoveSampler( Render::Sampler* sampler );
168 * Set minification and magnification filter modes for a sampler
169 * @param[in] minFilterMode Filter mode to use when the texture is minificated
170 * @param[in] magFilterMode Filter mode to use when the texture is magnified
172 void SetFilterMode( Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode );
175 * Set wrapping mode for a sampler
176 * @param[in] rWrapMode Wrap mode in the z direction
177 * @param[in] uWrapMode Wrap mode in the x direction
178 * @param[in] vWrapMode Wrap mode in the y direction
180 void SetWrapMode( Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode );
183 * Add a property buffer to the render manager.
184 * @param[in] vertexBuffer The property buffer to add.
185 * @post propertBuffer is owned by RenderManager
187 void AddVertexBuffer( OwnerPointer< Render::VertexBuffer >& vertexBuffer );
190 * Remove a property buffer from the render manager.
191 * @param[in] vertexBuffer The property buffer to remove.
192 * @post vertexBuffer is destroyed.
194 void RemoveVertexBuffer( Render::VertexBuffer* vertexBuffer );
197 * Add a geometry to the render manager.
198 * @param[in] geometry The geometry to add.
199 * @post geometry is owned by RenderManager
201 void AddGeometry( OwnerPointer< Render::Geometry >& geometry );
204 * Remove a geometry from the render manager.
205 * @param[in] geometry The geometry to remove.
206 * @post geometry is destroyed.
208 void RemoveGeometry( Render::Geometry* geometry );
211 * Adds a property buffer to a geometry from the render manager.
212 * @param[in] geometry The geometry
213 * @param[in] vertexBuffer The property buffer to remove.
215 void AttachVertexBuffer( Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer );
218 * Remove a property buffer from a Render::Geometry from the render manager.
219 * @param[in] geometry The geometry
220 * @param[in] vertexBuffer The property buffer to remove.
221 * @post property buffer is destroyed.
223 void RemoveVertexBuffer( Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer );
226 * Sets the format of an existing property buffer
227 * @param[in] vertexBuffer The property buffer.
228 * @param[in] format The new format of the buffer
230 void SetVertexBufferFormat( Render::VertexBuffer* vertexBuffer, OwnerPointer< Render::VertexBuffer::Format>& format );
233 * Sets the data of an existing property buffer
234 * @param[in] vertexBuffer The property buffer.
235 * @param[in] data The new data of the buffer
236 * @param[in] size The new size of the buffer
238 void SetVertexBufferData( Render::VertexBuffer* vertexBuffer, OwnerPointer< Vector<uint8_t> >& data, uint32_t size );
241 * Sets the data for the index buffer of an existing geometry
242 * @param[in] geometry The geometry
243 * @param[in] data A vector containing the indices
245 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<uint16_t>& data );
248 * Set the geometry type of an existing render geometry
249 * @param[in] geometry The render geometry
250 * @param[in] geometryType The new geometry type
252 void SetGeometryType( Render::Geometry* geometry, uint32_t geometryType );
255 * Adds a texture to the render manager
256 * @param[in] texture The texture to add
258 void AddTexture( OwnerPointer< Render::Texture >& texture );
261 * Removes a texture from the render manager
262 * @param[in] texture The texture to remove
264 void RemoveTexture( Render::Texture* texture );
267 * Uploads data to an existing texture
268 * @param[in] texture The texture
269 * @param[in] pixelData The pixel data object
270 * @param[in] params The parameters for the upload
272 void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
275 * Generates mipmaps for a given texture
276 * @param[in] texture The texture
278 void GenerateMipmaps( Render::Texture* texture );
281 * Adds a framebuffer to the render manager
282 * @param[in] frameBuffer The framebuffer to add
284 void AddFrameBuffer( OwnerPointer< Render::FrameBuffer >& frameBuffer );
287 * Removes a framebuffer from the render manager
288 * @param[in] frameBuffer The framebuffer to remove
290 void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
293 * Attaches a texture as color output to the existing frame buffer
294 * @param[in] frameBuffer The FrameBuffer
295 * @param[in] texture The texture that will be used as output when rendering
296 * @param[in] mipmapLevel The mipmap of the texture to be attached
297 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
299 void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
302 * Attaches a texture as depth output to the existing frame buffer
303 * @param[in] frameBuffer The FrameBuffer
304 * @param[in] texture The texture that will be used as output when rendering
305 * @param[in] mipmapLevel The mipmap of the texture to be attached
307 void AttachDepthTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel );
310 * Attaches a texture as depth/stencil output to the existing frame buffer
311 * @param[in] frameBuffer The FrameBuffer
312 * @param[in] texture The texture that will be used as output when rendering
313 * @param[in] mipmapLevel The mipmap of the texture to be attached
315 void AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel );
318 * Initializes a Scene to the render manager
319 * @param[in] scene The Scene to initialize
321 void InitializeScene( SceneGraph::Scene* scene );
324 * Uninitializes a Scene to the render manager
325 * @param[in] scene The Scene to uninitialize
327 void UninitializeScene( SceneGraph::Scene* scene );
330 * This is called when the surface of the scene has been replaced.
331 * @param[in] scene The scene.
333 void SurfaceReplaced( SceneGraph::Scene* scene );
336 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
337 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
338 * object, usually an offscreen render task.
339 * @param[in] renderTracker The render tracker
341 void AddRenderTracker( Render::RenderTracker* renderTracker );
344 * Removes a render tracker from the RenderManager.
345 * @param[in] renderTracker The render tracker to remove.
347 void RemoveRenderTracker( Render::RenderTracker* renderTracker );
350 * returns the Program controller for sending program messages
351 * @return the ProgramController
353 ProgramCache* GetProgramCache();
355 // This method should be called from Core::PreRender()
358 * This is called before rendering any scene in the next frame. This method should be preceded
359 * by a call up Update.
360 * Multi-threading note: this method should be called from a dedicated rendering thread.
361 * @pre The GL context must have been created, and made current.
362 * @param[out] status showing whether update is required to run.
363 * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
364 * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
366 void PreRender( Integration::RenderStatus& status, bool forceClear, bool uploadOnly );
368 // This method should be called from Core::PreRender()
371 * This is called before rendering any scene in the next frame. This method should be preceded
372 * by a call up Update.
373 * Multi-threading note: this method should be called from a dedicated rendering thread.
374 * @pre The GL context must have been created, and made current.
375 * @param[in] scene The scene to be rendered.
376 * @param[out] damagedRects The list of damaged rects for the current render pass.
378 void PreRender( Integration::Scene& scene, std::vector<Rect<int>>& damagedRects );
380 // This method should be called from Core::RenderScene()
383 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
384 * This method should be called twice. The first pass to render off-screen frame buffers if any,
385 * and the second pass to render the surface.
386 * Multi-threading note: this method should be called from a dedicated rendering thread.
387 * @pre The GL context must have been created, and made current.
388 * @param[out] status contains the rendering flags.
389 * @param[in] scene The scene to be rendered.
390 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
392 void RenderScene( Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo );
395 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
396 * This method should be called twice. The first pass to render off-screen frame buffers if any,
397 * and the second pass to render the surface.
398 * Multi-threading note: this method should be called from a dedicated rendering thread.
399 * @pre The GL context must have been created, and made current.
400 * @param[out] status contains the rendering flags.
401 * @param[in] scene The scene to be rendered.
402 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
403 * @param[in] clippingRect The clipping rect for the rendered scene.
405 void RenderScene( Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect );
407 // This method should be called from Core::PostRender()
410 * This is called after rendering all the scenes in the next frame. This method should be
411 * followed by a call up RenderScene.
412 * Multi-threading note: this method should be called from a dedicated rendering thread.
413 * @pre The GL context must have been created, and made current.
414 * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
416 void PostRender( bool uploadOnly );
424 * Construct a new RenderManager.
429 RenderManager( const RenderManager& );
432 RenderManager& operator=( const RenderManager& rhs );
441 } // namespace SceneGraph
443 } // namespace Internal
447 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H