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/render/gl-resources/gpu-buffer.h>
26 #include <dali/internal/render/renderers/render-property-buffer.h>
27 #include <dali/internal/event/rendering/texture-impl.h>
35 class GlSyncAbstraction;
36 class GlContextHelperAbstraction;
62 class RenderInstruction;
63 class RenderInstructionContainer;
65 class PropertyBufferDataProvider;
69 * RenderManager is responsible for rendering the result of the previous "update", which
70 * is provided in a RenderCommand during UpdateManager::Update().
77 * Construct a new RenderManager.
78 * @param[in] glAbstraction The GL abstraction used for rendering.
79 * @param[in] glSyncAbstraction The GL sync abstraction used fence sync creation/deletion.
80 * @param[in] glContextHelperAbstraction The GL context helper abstraction for accessing GL context.
81 * @param[in] depthBufferAvailable Whether the depth buffer is available
82 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
84 static RenderManager* New( Integration::GlAbstraction& glAbstraction,
85 Integration::GlSyncAbstraction& glSyncAbstraction,
86 Integration::GlContextHelperAbstraction& glContextHelperAbstraction,
87 Integration::DepthBufferAvailable depthBufferAvailable,
88 Integration::StencilBufferAvailable stencilBufferAvailable );
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 * Add a Renderer to the render manager.
135 * @param[in] renderer The renderer to add.
136 * @post renderer is owned by RenderManager
138 void AddRenderer( OwnerPointer< Render::Renderer >& renderer );
141 * Remove a Renderer from the render manager.
142 * @param[in] renderer The renderer to remove.
143 * @post renderer is destroyed.
145 void RemoveRenderer( Render::Renderer* renderer );
148 * Add a sampler to the render manager.
149 * @param[in] sampler The sampler to add.
150 * @post sampler is owned by RenderManager
152 void AddSampler( OwnerPointer< Render::Sampler >& sampler );
155 * Remove a sampler from the render manager.
156 * @param[in] sampler The sampler to remove.
157 * @post sampler is destroyed.
159 void RemoveSampler( Render::Sampler* sampler );
162 * Set minification and magnification filter modes for a sampler
163 * @param[in] minFilterMode Filter mode to use when the texture is minificated
164 * @param[in] magFilterMode Filter mode to use when the texture is magnified
166 void SetFilterMode( Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode );
169 * Set wrapping mode for a sampler
170 * @param[in] rWrapMode Wrap mode in the z direction
171 * @param[in] uWrapMode Wrap mode in the x direction
172 * @param[in] vWrapMode Wrap mode in the y direction
174 void SetWrapMode( Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode );
177 * Add a property buffer to the render manager.
178 * @param[in] propertyBuffer The property buffer to add.
179 * @post propertBuffer is owned by RenderManager
181 void AddPropertyBuffer( OwnerPointer< Render::PropertyBuffer >& propertyBuffer );
184 * Remove a property buffer from the render manager.
185 * @param[in] propertyBuffer The property buffer to remove.
186 * @post propertyBuffer is destroyed.
188 void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
191 * Add a geometry to the render manager.
192 * @param[in] geometry The geometry to add.
193 * @post geometry is owned by RenderManager
195 void AddGeometry( OwnerPointer< Render::Geometry >& geometry );
198 * Remove a geometry from the render manager.
199 * @param[in] geometry The geometry to remove.
200 * @post geometry is destroyed.
202 void RemoveGeometry( Render::Geometry* geometry );
205 * Adds a property buffer to a geometry from the render manager.
206 * @param[in] geometry The geometry
207 * @param[in] propertyBuffer The property buffer to remove.
209 void AttachVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
212 * Remove a property buffer from a Render::Geometry from the render manager.
213 * @param[in] geometry The geometry
214 * @param[in] propertyBuffer The property buffer to remove.
215 * @post property buffer is destroyed.
217 void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
220 * Sets the format of an existing property buffer
221 * @param[in] propertyBuffer The property buffer.
222 * @param[in] format The new format of the buffer
224 void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Render::PropertyBuffer::Format>& format );
227 * Sets the data of an existing property buffer
228 * @param[in] propertyBuffer The property buffer.
229 * @param[in] data The new data of the buffer
230 * @param[in] size The new size of the buffer
232 void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Vector<uint8_t> >& data, uint32_t size );
235 * Sets the data for the index buffer of an existing geometry
236 * @param[in] geometry The geometry
237 * @param[in] data A vector containing the indices
239 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<uint16_t>& data );
242 * Set the geometry type of an existing render geometry
243 * @param[in] geometry The render geometry
244 * @param[in] geometryType The new geometry type
246 void SetGeometryType( Render::Geometry* geometry, uint32_t geometryType );
249 * Adds a texture to the render manager
250 * @param[in] texture The texture to add
252 void AddTexture( OwnerPointer< Render::Texture >& texture );
255 * Removes a texture from the render manager
256 * @param[in] texture The texture to remove
258 void RemoveTexture( Render::Texture* texture );
261 * Uploads data to an existing texture
262 * @param[in] texture The texture
263 * @param[in] pixelData The pixel data object
264 * @param[in] params The parameters for the upload
266 void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
269 * Generates mipmaps for a given texture
270 * @param[in] texture The texture
272 void GenerateMipmaps( Render::Texture* texture );
275 * Adds a framebuffer to the render manager
276 * @param[in] frameBuffer The framebuffer to add
278 void AddFrameBuffer( OwnerPointer< Render::FrameBuffer >& frameBuffer );
281 * Removes a framebuffer from the render manager
282 * @param[in] frameBuffer The framebuffer to remove
284 void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
287 * Attaches a texture as color output to the existing frame buffer
288 * @param[in] frameBuffer The FrameBuffer
289 * @param[in] texture The texture that will be used as output when rendering
290 * @param[in] mipmapLevel The mipmap of the texture to be attached
291 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
293 void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
296 * Attaches a texture as depth output to the existing frame buffer
297 * @param[in] frameBuffer The FrameBuffer
298 * @param[in] texture The texture that will be used as output when rendering
299 * @param[in] mipmapLevel The mipmap of the texture to be attached
301 void AttachDepthTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel );
304 * Attaches a texture as depth/stencil output to the existing frame buffer
305 * @param[in] frameBuffer The FrameBuffer
306 * @param[in] texture The texture that will be used as output when rendering
307 * @param[in] mipmapLevel The mipmap of the texture to be attached
309 void AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel );
312 * Initializes a Scene to the render manager
313 * @param[in] scene The Scene to initialize
315 void InitializeScene( SceneGraph::Scene* scene );
318 * Uninitializes a Scene to the render manager
319 * @param[in] scene The Scene to uninitialize
321 void UninitializeScene( SceneGraph::Scene* scene );
324 * This is called when the surface of the scene has been replaced.
325 * @param[in] scene The scene.
327 void SurfaceReplaced( SceneGraph::Scene* scene );
330 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
331 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
332 * object, usually an offscreen render task.
333 * @param[in] renderTracker The render tracker
335 void AddRenderTracker( Render::RenderTracker* renderTracker );
338 * Removes a render tracker from the RenderManager.
339 * @param[in] renderTracker The render tracker to remove.
341 void RemoveRenderTracker( Render::RenderTracker* renderTracker );
344 * returns the Program controller for sending program messages
345 * @return the ProgramController
347 ProgramCache* GetProgramCache();
349 // This method should be called from Core::PreRender()
352 * This is called before rendering any scene in the next frame. This method should be preceded
353 * by a call up Update.
354 * Multi-threading note: this method should be called from a dedicated rendering thread.
355 * @pre The GL context must have been created, and made current.
356 * @param[out] status showing whether update is required to run.
357 * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
358 * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
360 void PreRender( Integration::RenderStatus& status, bool forceClear, bool uploadOnly );
362 // This method should be called from Core::RenderScene()
365 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
366 * This method should be called twice. The first pass to render off-screen frame buffers if any,
367 * and the second pass to render the surface.
368 * Multi-threading note: this method should be called from a dedicated rendering thread.
369 * @pre The GL context must have been created, and made current.
370 * @param[in] scene The scene to be rendered.
371 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
373 void RenderScene( Integration::Scene& scene, bool renderToFbo );
375 // This method should be called from Core::PostRender()
378 * This is called after rendering all the scenes in the next frame. This method should be
379 * followed by a call up RenderScene.
380 * Multi-threading note: this method should be called from a dedicated rendering thread.
381 * @pre The GL context must have been created, and made current.
382 * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
384 void PostRender( bool uploadOnly );
392 * Construct a new RenderManager.
397 RenderManager( const RenderManager& );
400 RenderManager& operator=( const RenderManager& rhs );
409 } // namespace SceneGraph
411 } // namespace Internal
415 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H