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/gl-resources/gpu-buffer.h>
27 #include <dali/internal/render/renderers/render-vertex-buffer.h>
28 #include <dali/public-api/math/rect.h>
35 class GlSyncAbstraction;
36 class GlContextHelperAbstraction;
39 } // namespace Integration
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().
75 * Construct a new RenderManager.
76 * @param[in] graphicsController The graphics controller for a given rendering backend
77 * @param[in] depthBufferAvailable Whether the depth buffer is available
78 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
80 static RenderManager* New(Graphics::Controller& graphicsController,
81 Integration::DepthBufferAvailable depthBufferAvailable,
82 Integration::StencilBufferAvailable stencilBufferAvailable,
83 Integration::PartialUpdateAvailable partialUpdateAvailable);
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 * @copydoc Dali::Integration::Core::ContextCreated()
99 void ContextCreated();
102 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
104 void ContextDestroyed();
107 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
108 * caching and saving.
109 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
110 * @note This should be called during core initialisation if shader binaries are to be used.
112 void SetShaderSaver(ShaderSaver& upstream);
114 // The foltlowing methods should be called via RenderQueue messages
117 * Set the frame time delta (time elapsed since the last frame.
118 * @param[in] deltaTime the delta time
120 void SetFrameDeltaTime(float deltaTime);
123 * Returns the rectangle for the default surface (probably the application window).
124 * @return Rectangle for the surface.
126 void SetDefaultSurfaceRect(const Rect<int>& rect);
129 * Returns the orintation for the default surface (probably the application window).
130 * @param[in] orientation the surface's orientation.
132 void SetDefaultSurfaceOrientation(int orientation);
135 * Add a Renderer to the render manager.
136 * @param[in] renderer The renderer to add.
137 * @post renderer is owned by RenderManager
139 void AddRenderer(OwnerPointer<Render::Renderer>& renderer);
142 * Remove a Renderer from the render manager.
143 * @param[in] renderer The renderer to remove.
144 * @post renderer is destroyed.
146 void RemoveRenderer(Render::Renderer* renderer);
149 * Add a sampler to the render manager.
150 * @param[in] sampler The sampler to add.
151 * @post sampler is owned by RenderManager
153 void AddSampler(OwnerPointer<Render::Sampler>& sampler);
156 * Remove a sampler from the render manager.
157 * @param[in] sampler The sampler to remove.
158 * @post sampler is destroyed.
160 void RemoveSampler(Render::Sampler* sampler);
163 * Set minification and magnification filter modes for a sampler
164 * @param[in] minFilterMode Filter mode to use when the texture is minificated
165 * @param[in] magFilterMode Filter mode to use when the texture is magnified
167 void SetFilterMode(Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode);
170 * Set wrapping mode for a sampler
171 * @param[in] rWrapMode Wrap mode in the z direction
172 * @param[in] uWrapMode Wrap mode in the x direction
173 * @param[in] vWrapMode Wrap mode in the y direction
175 void SetWrapMode(Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode);
178 * Add a property buffer to the render manager.
179 * @param[in] vertexBuffer The property buffer to add.
180 * @post propertBuffer is owned by RenderManager
182 void AddVertexBuffer(OwnerPointer<Render::VertexBuffer>& vertexBuffer);
185 * Remove a property buffer from the render manager.
186 * @param[in] vertexBuffer The property buffer to remove.
187 * @post vertexBuffer is destroyed.
189 void RemoveVertexBuffer(Render::VertexBuffer* vertexBuffer);
192 * Add a geometry to the render manager.
193 * @param[in] geometry The geometry to add.
194 * @post geometry is owned by RenderManager
196 void AddGeometry(OwnerPointer<Render::Geometry>& geometry);
199 * Remove a geometry from the render manager.
200 * @param[in] geometry The geometry to remove.
201 * @post geometry is destroyed.
203 void RemoveGeometry(Render::Geometry* geometry);
206 * Adds a property buffer to a geometry from the render manager.
207 * @param[in] geometry The geometry
208 * @param[in] vertexBuffer The property buffer to remove.
210 void AttachVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
213 * Remove a property buffer from a Render::Geometry from the render manager.
214 * @param[in] geometry The geometry
215 * @param[in] vertexBuffer The property buffer to remove.
216 * @post property buffer is destroyed.
218 void RemoveVertexBuffer(Render::Geometry* geometry, Render::VertexBuffer* vertexBuffer);
221 * Sets the format of an existing property buffer
222 * @param[in] vertexBuffer The property buffer.
223 * @param[in] format The new format of the buffer
225 void SetVertexBufferFormat(Render::VertexBuffer* vertexBuffer, OwnerPointer<Render::VertexBuffer::Format>& format);
228 * Sets the data of an existing property buffer
229 * @param[in] vertexBuffer The property buffer.
230 * @param[in] data The new data of the buffer
231 * @param[in] size The new size of the buffer
233 void SetVertexBufferData(Render::VertexBuffer* vertexBuffer, OwnerPointer<Vector<uint8_t>>& data, uint32_t size);
236 * Sets the data for the index buffer of an existing geometry
237 * @param[in] geometry The geometry
238 * @param[in] data A vector containing the indices
240 void SetIndexBuffer(Render::Geometry* geometry, Dali::Vector<uint16_t>& data);
243 * Set the geometry type of an existing render geometry
244 * @param[in] geometry The render geometry
245 * @param[in] geometryType The new geometry type
247 void SetGeometryType(Render::Geometry* geometry, uint32_t geometryType);
250 * Adds a texture to the render manager
251 * @param[in] texture The texture to add
253 void AddTexture(OwnerPointer<Render::Texture>& texture);
256 * Removes a texture from the render manager
257 * @param[in] texture The texture to remove
259 void RemoveTexture(Render::Texture* texture);
262 * Uploads data to an existing texture
263 * @param[in] texture The texture
264 * @param[in] pixelData The pixel data object
265 * @param[in] params The parameters for the upload
267 void UploadTexture(Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params);
270 * Generates mipmaps for a given texture
271 * @param[in] texture The texture
273 void GenerateMipmaps(Render::Texture* texture);
276 * Adds a framebuffer to the render manager
277 * @param[in] frameBuffer The framebuffer to add
279 void AddFrameBuffer(OwnerPointer<Render::FrameBuffer>& frameBuffer);
282 * Removes a framebuffer from the render manager
283 * @param[in] frameBuffer The framebuffer to remove
285 void RemoveFrameBuffer(Render::FrameBuffer* frameBuffer);
288 * Attaches a texture as color output to the existing frame buffer
289 * @param[in] frameBuffer The FrameBuffer
290 * @param[in] texture The texture that will be used as output when rendering
291 * @param[in] mipmapLevel The mipmap of the texture to be attached
292 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
294 void AttachColorTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer);
297 * Attaches a texture as depth output to the existing frame buffer
298 * @param[in] frameBuffer The FrameBuffer
299 * @param[in] texture The texture that will be used as output when rendering
300 * @param[in] mipmapLevel The mipmap of the texture to be attached
302 void AttachDepthTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
305 * Attaches a texture as depth/stencil output to the existing frame buffer
306 * @param[in] frameBuffer The FrameBuffer
307 * @param[in] texture The texture that will be used as output when rendering
308 * @param[in] mipmapLevel The mipmap of the texture to be attached
310 void AttachDepthStencilTextureToFrameBuffer(Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel);
313 * Initializes a Scene to the render manager
314 * @param[in] scene The Scene to initialize
316 void InitializeScene(SceneGraph::Scene* scene);
319 * Uninitializes a Scene to the render manager
320 * @param[in] scene The Scene to uninitialize
322 void UninitializeScene(SceneGraph::Scene* scene);
325 * This is called when the surface of the scene has been replaced.
326 * @param[in] scene The scene.
328 void SurfaceReplaced(SceneGraph::Scene* scene);
331 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
332 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
333 * object, usually an offscreen render task.
334 * @param[in] renderTracker The render tracker
336 void AddRenderTracker(Render::RenderTracker* renderTracker);
339 * Removes a render tracker from the RenderManager.
340 * @param[in] renderTracker The render tracker to remove.
342 void RemoveRenderTracker(Render::RenderTracker* renderTracker);
345 * returns the Program controller for sending program messages
346 * @return the ProgramController
348 ProgramCache* GetProgramCache();
350 // This method should be called from Core::PreRender()
353 * This is called before rendering any scene in the next frame. This method should be preceded
354 * by a call up Update.
355 * Multi-threading note: this method should be called from a dedicated rendering thread.
356 * @pre The GL context must have been created, and made current.
357 * @param[out] status showing whether update is required to run.
358 * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
359 * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
361 void PreRender(Integration::RenderStatus& status, bool forceClear, bool uploadOnly);
363 // This method should be called from Core::PreRender()
366 * This is called before rendering any scene in the next frame. This method should be preceded
367 * by a call up Update.
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[out] damagedRects The list of damaged rects for the current render pass.
373 void PreRender(Integration::Scene& scene, std::vector<Rect<int>>& damagedRects);
375 // This method should be called from Core::RenderScene()
378 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
379 * This method should be called twice. The first pass to render off-screen frame buffers if any,
380 * and the second pass to render the surface.
381 * Multi-threading note: this method should be called from a dedicated rendering thread.
382 * @pre The GL context must have been created, and made current.
383 * @param[out] status contains the rendering flags.
384 * @param[in] scene The scene to be rendered.
385 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
387 void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo);
390 * Render a scene in the next frame. This method should be preceded by a call up PreRender.
391 * This method should be called twice. The first pass to render off-screen frame buffers if any,
392 * and the second pass to render the surface.
393 * Multi-threading note: this method should be called from a dedicated rendering thread.
394 * @pre The GL context must have been created, and made current.
395 * @param[out] status contains the rendering flags.
396 * @param[in] scene The scene to be rendered.
397 * @param[in] renderToFbo True to render off-screen frame buffers only if any, and False to render the surface only.
398 * @param[in] clippingRect The clipping rect for the rendered scene.
400 void RenderScene(Integration::RenderStatus& status, Integration::Scene& scene, bool renderToFbo, Rect<int>& clippingRect);
402 // This method should be called from Core::PostRender()
405 * This is called after rendering all the scenes in the next frame. This method should be
406 * followed by a call up RenderScene.
407 * Multi-threading note: this method should be called from a dedicated rendering thread.
408 * @pre The GL context must have been created, and made current.
409 * @param[in] uploadOnly uploadOnly Upload the resource only without rendering.
411 void PostRender(bool uploadOnly);
416 * Construct a new RenderManager.
421 RenderManager(const RenderManager&);
424 RenderManager& operator=(const RenderManager& rhs);
431 } // namespace SceneGraph
433 } // namespace Internal
437 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H