1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
5 * Copyright (c) 2021 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/graphics-api/graphics-controller.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/renderers/render-vertex-buffer.h>
27 #include <dali/public-api/math/rect.h>
34 class GlSyncAbstraction;
35 class GlContextHelperAbstraction;
38 } // namespace Integration
60 class RenderInstruction;
61 class RenderInstructionContainer;
66 * RenderManager is responsible for rendering the result of the previous "update", which
67 * is provided in a RenderCommand during UpdateManager::Update().
73 * Construct a new RenderManager.
74 * @param[in] graphicsController The graphics controller for a given rendering backend
75 * @param[in] depthBufferAvailable Whether the depth buffer is available
76 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
78 static RenderManager* New(Graphics::Controller& graphicsController,
79 Integration::DepthBufferAvailable depthBufferAvailable,
80 Integration::StencilBufferAvailable stencilBufferAvailable,
81 Integration::PartialUpdateAvailable partialUpdateAvailable);
84 * Non-virtual destructor; not intended as a base class
89 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
90 * @return The render queue.
92 RenderQueue& GetRenderQueue();
95 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
97 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
98 * @note This should be called during core initialisation if shader binaries are to be used.
100 void SetShaderSaver(ShaderSaver& upstream);
102 // The foltlowing methods should be called via RenderQueue messages
105 * Set the frame time delta (time elapsed since the last frame.
106 * @param[in] deltaTime the delta time
108 void SetFrameDeltaTime(float deltaTime);
111 * Add a Renderer to the render manager.
112 * @param[in] renderer The renderer to add.
113 * @post renderer is owned by RenderManager
115 void AddRenderer(OwnerPointer<Render::Renderer>& renderer);
118 * Remove a Renderer from the render manager.
119 * @param[in] renderer The renderer to remove.
120 * @post renderer is destroyed.
122 void RemoveRenderer(Render::Renderer* renderer);
125 * Add a sampler to the render manager.
126 * @param[in] sampler The sampler to add.
127 * @post sampler is owned by RenderManager
129 void AddSampler(OwnerPointer<Render::Sampler>& sampler);
132 * Remove a sampler from the render manager.
133 * @param[in] sampler The sampler to remove.
134 * @post sampler is destroyed.
136 void RemoveSampler(Render::Sampler* sampler);
139 * Set minification and magnification filter modes for a sampler
140 * @param[in] minFilterMode Filter mode to use when the texture is minificated
141 * @param[in] magFilterMode Filter mode to use when the texture is magnified
143 void SetFilterMode(Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode);
146 * Set wrapping mode for a sampler
147 * @param[in] rWrapMode Wrap mode in the z direction
148 * @param[in] uWrapMode Wrap mode in the x direction
149 * @param[in] vWrapMode Wrap mode in the y direction
151 void SetWrapMode(Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode);
154 * Add a property buffer to the render manager.
155 * @param[in] vertexBuffer The property buffer to add.
156 * @post propertBuffer is owned by RenderManager
158 void AddVertexBuffer(OwnerPointer<Render::VertexBuffer>& vertexBuffer);
161 * Remove a property buffer from the render manager.
162 * @param[in] vertexBuffer The property buffer to remove.
163 * @post vertexBuffer is destroyed.
165 void RemoveVertexBuffer(Render::VertexBuffer* vertexBuffer);
168 * Add a geometry to the render manager.
169 * @param[in] geometry The geometry to add.
170 * @post geometry is owned by RenderManager
172 void AddGeometry(OwnerPointer<Render::Geometry>& geometry);
175 * Remove a geometry from the render manager.
176 * @param[in] geometry The geometry to remove.
177 * @post geometry is destroyed.
179 void RemoveGeometry(Render::Geometry* geometry);
182 * Adds a property buffer to a geometry from the render manager.
183 * @param[in] geometry The geometry
184 * @param[in] vertexBuffer The property buffer to remove.
186 void AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
189 * Remove a property buffer from a Render::Geometry from the render manager.
190 * @param[in] geometry The geometry
191 * @param[in] vertexBuffer The property buffer to remove.
192 * @post property buffer is destroyed.
194 void RemoveVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
197 * Sets the format of an existing property buffer
198 * @param[in] vertexBuffer The property buffer.
199 * @param[in] format The new format of the buffer
201 void SetVertexBufferFormat(Render::VertexBuffer* vertexBuffer, OwnerPointer<Render::VertexBuffer::Format>& format);
204 * Sets the data of an existing property buffer
205 * @param[in] vertexBuffer The property buffer.
206 * @param[in] data The new data of the buffer
207 * @param[in] size The new size of the buffer
209 void SetVertexBufferData(Render::VertexBuffer* vertexBuffer, OwnerPointer<Vector<uint8_t>>& data, uint32_t size);
212 * Sets the data for the index buffer of an existing geometry
213 * @param[in] geometry The geometry
214 * @param[in] data A vector containing the indices
216 void SetIndexBuffer(Render::Geometry* geometry, Dali::Vector<uint16_t>& data);
219 * Set the geometry type of an existing render geometry
220 * @param[in] geometry The render geometry
221 * @param[in] geometryType The new geometry type
223 void SetGeometryType(Render::Geometry* geometry, uint32_t geometryType);
226 * Adds a texture to the render manager
227 * @param[in] texture The texture to add
229 void AddTexture(OwnerPointer<Render::Texture>& texture);
232 * Removes a texture from the render manager
233 * @param[in] texture The texture to remove
235 void RemoveTexture(Render::Texture* texture);
238 * Uploads data to an existing texture
239 * @param[in] texture The texture
240 * @param[in] pixelData The pixel data object
241 * @param[in] params The parameters for the upload
243 void UploadTexture(Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
246 * Generates mipmaps for a given texture
247 * @param[in] texture The texture
249 void GenerateMipmaps(Render::Texture* texture);
252 * Adds a framebuffer to the render manager
253 * @param[in] frameBuffer The framebuffer to add
255 void AddFrameBuffer(OwnerPointer<Render::FrameBuffer>& frameBuffer);
258 * Removes a framebuffer from the render manager
259 * @param[in] frameBuffer The framebuffer to remove
261 void RemoveFrameBuffer(Render::FrameBuffer* frameBuffer);
264 * Attaches a texture as color output to the existing frame buffer
265 * @param[in] frameBuffer The FrameBuffer
266 * @param[in] texture The texture that will be used as output when rendering
267 * @param[in] mipmapLevel The mipmap of the texture to be attached
268 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
270 void AttachColorTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer);
273 * Attaches a texture as depth output to the existing frame buffer
274 * @param[in] frameBuffer The FrameBuffer
275 * @param[in] texture The texture that will be used as output when rendering
276 * @param[in] mipmapLevel The mipmap of the texture to be attached
278 void AttachDepthTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
281 * Attaches a texture as depth/stencil output to the existing frame buffer
282 * @param[in] frameBuffer The FrameBuffer
283 * @param[in] texture The texture that will be used as output when rendering
284 * @param[in] mipmapLevel The mipmap of the texture to be attached
286 void AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
289 * Initializes a Scene to the render manager
290 * @param[in] scene The Scene to initialize
292 void InitializeScene(SceneGraph::Scene* scene);
295 * Uninitializes a Scene to the render manager
296 * @param[in] scene The Scene to uninitialize
298 void UninitializeScene(SceneGraph::Scene* scene);
301 * This is called when the surface of the scene has been replaced.
302 * @param[in] scene The scene.
304 void SurfaceReplaced(SceneGraph::Scene* scene);
307 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
308 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
309 * object, usually an offscreen render task.
310 * @param[in] renderTracker The render tracker
312 void AddRenderTracker(Render::RenderTracker* renderTracker);
315 * Removes a render tracker from the RenderManager.
316 * @param[in] renderTracker The render tracker to remove.
318 void RemoveRenderTracker(Render::RenderTracker* renderTracker);
321 * returns the Program controller for sending program messages
322 * @return the ProgramController
324 ProgramCache* GetProgramCache();
326 // This method should be called from Core::PreRender()
329 * This is called before rendering any scene in the next frame. This method should be preceded
330 * by a call up Update.
331 * Multi-threading note: this method should be called from a dedicated rendering thread.
332 * @pre The graphics implementation must be initialized
333 * @param[out] status showing whether update is required to run.
334 * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
335 * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
337 void PreRender(Integration::RenderStatus& status, bool forceClear, bool uploadOnly);
339 // This method should be called from Core::PreRender()
342 * This is called before rendering any scene in the next frame. This method should be preceded
343 * by a call up Update.
344 * Multi-threading note: this method should be called from a dedicated rendering thread.
345 * @pre The graphics implementation must be initialized
346 * @param[in] scene The scene to be rendered.
347 * @param[out] damagedRects The list of damaged rects for the current render pass.
349 void PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects);
351 // This method should be called from Core::RenderScene()
354 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
355 * This method should be called twice. The first pass to render off-screen frame buffers if any,
356 * and the second pass to render the surface.
357 * Multi-threading note: this method should be called from a dedicated rendering thread.
358 * @pre The graphics implementation must be initialized
359 * @param[out] status contains the rendering flags.
360 * @param[in] scene The scene to be rendered.
361 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
363 void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo);
366 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
367 * This method should be called twice. The first pass to render off-screen frame buffers if any,
368 * and the second pass to render the surface.
369 * Multi-threading note: this method should be called from a dedicated rendering thread.
370 * @pre The graphics implementation must be initialized
371 * @param[out] status contains the rendering flags.
372 * @param[in] scene The scene to be rendered.
373 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
374 * @param[in] clippingRect The clipping rect for the rendered scene.
376 void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect);
378 // This method should be called from Core::PostRender()
381 * This is called after rendering all the scenes in the next frame. This method should be
382 * followed by a call up RenderScene.
383 * Multi-threading note: this method should be called from a dedicated rendering thread.
384 * @pre The graphics implementation must be initialized
385 * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
387 void PostRender(bool uploadOnly);
391 * Construct a new RenderManager.
396 RenderManager(const RenderManager&);
399 RenderManager& operator=(const RenderManager& rhs);
406 } // namespace SceneGraph
408 } // namespace Internal
412 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H