1 #ifndef DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
2 #define DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H
5 * Copyright (c) 2019 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;
61 class RenderInstruction;
62 class RenderInstructionContainer;
64 class PropertyBufferDataProvider;
67 * RenderManager is responsible for rendering the result of the previous "update", which
68 * is provided in a RenderCommand during UpdateManager::Update().
75 * Construct a new RenderManager.
76 * @param[in] glAbstraction The GL abstraction used for rendering.
77 * @param[in] glSyncAbstraction The GL sync abstraction used fence sync creation/deletion.
78 * @param[in] glContextHelperAbstraction The GL context helper abstraction for accessing GL context.
79 * @param[in] depthBufferAvailable Whether the depth buffer is available
80 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
82 static RenderManager* New( Integration::GlAbstraction& glAbstraction,
83 Integration::GlSyncAbstraction& glSyncAbstraction,
84 Integration::GlContextHelperAbstraction& glContextHelperAbstraction,
85 Integration::DepthBufferAvailable depthBufferAvailable,
86 Integration::StencilBufferAvailable stencilBufferAvailable );
89 * Non-virtual destructor; not intended as a base class
94 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
95 * @return The render queue.
97 RenderQueue& GetRenderQueue();
100 * @copydoc Dali::Integration::Core::ContextCreated()
102 void ContextCreated();
105 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
107 void ContextDestroyed();
110 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
111 * caching and saving.
112 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
113 * @note This should be called during core initialisation if shader binaries are to be used.
115 void SetShaderSaver( ShaderSaver& upstream );
118 * Retrieve the render instructions; these should be set during each "update" traversal.
119 * @return The render instruction container.
121 RenderInstructionContainer& GetRenderInstructionContainer();
123 // The following methods should be called via RenderQueue messages
126 * Set the frame time delta (time elapsed since the last frame.
127 * @param[in] deltaTime the delta time
129 void SetFrameDeltaTime( float deltaTime );
132 * Returns the rectangle for the default surface (probably the application window).
133 * @return Rectangle for the surface.
135 void SetDefaultSurfaceRect( const Rect<int>& rect );
138 * Add a Renderer to the render manager.
139 * @param[in] renderer The renderer to add.
140 * @post renderer is owned by RenderManager
142 void AddRenderer( OwnerPointer< Render::Renderer >& renderer );
145 * Remove a Renderer from the render manager.
146 * @param[in] renderer The renderer to remove.
147 * @post renderer is destroyed.
149 void RemoveRenderer( Render::Renderer* renderer );
152 * Add a sampler to the render manager.
153 * @param[in] sampler The sampler to add.
154 * @post sampler is owned by RenderManager
156 void AddSampler( OwnerPointer< Render::Sampler >& sampler );
159 * Remove a sampler from the render manager.
160 * @param[in] sampler The sampler to remove.
161 * @post sampler is destroyed.
163 void RemoveSampler( Render::Sampler* sampler );
166 * Set minification and magnification filter modes for a sampler
167 * @param[in] minFilterMode Filter mode to use when the texture is minificated
168 * @param[in] magFilterMode Filter mode to use when the texture is magnified
170 void SetFilterMode( Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode );
173 * Set wrapping mode for a sampler
174 * @param[in] rWrapMode Wrap mode in the z direction
175 * @param[in] uWrapMode Wrap mode in the x direction
176 * @param[in] vWrapMode Wrap mode in the y direction
178 void SetWrapMode( Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode );
181 * Add a property buffer to the render manager.
182 * @param[in] propertyBuffer The property buffer to add.
183 * @post propertBuffer is owned by RenderManager
185 void AddPropertyBuffer( OwnerPointer< Render::PropertyBuffer >& propertyBuffer );
188 * Remove a property buffer from the render manager.
189 * @param[in] propertyBuffer The property buffer to remove.
190 * @post propertyBuffer is destroyed.
192 void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
195 * Add a geometry to the render manager.
196 * @param[in] geometry The geometry to add.
197 * @post geometry is owned by RenderManager
199 void AddGeometry( OwnerPointer< Render::Geometry >& geometry );
202 * Remove a geometry from the render manager.
203 * @param[in] geometry The geometry to remove.
204 * @post geometry is destroyed.
206 void RemoveGeometry( Render::Geometry* geometry );
209 * Adds a property buffer to a geometry from the render manager.
210 * @param[in] geometry The geometry
211 * @param[in] propertyBuffer The property buffer to remove.
213 void AttachVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
216 * Remove a property buffer from a Render::Geometry from the render manager.
217 * @param[in] geometry The geometry
218 * @param[in] propertyBuffer The property buffer to remove.
219 * @post property buffer is destroyed.
221 void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
224 * Sets the format of an existing property buffer
225 * @param[in] propertyBuffer The property buffer.
226 * @param[in] format The new format of the buffer
228 void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Render::PropertyBuffer::Format>& format );
231 * Sets the data of an existing property buffer
232 * @param[in] propertyBuffer The property buffer.
233 * @param[in] data The new data of the buffer
234 * @param[in] size The new size of the buffer
236 void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Vector<uint8_t> >& data, uint32_t size );
239 * Sets the data for the index buffer of an existing geometry
240 * @param[in] geometry The geometry
241 * @param[in] data A vector containing the indices
243 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<uint16_t>& data );
246 * Set the geometry type of an existing render geometry
247 * @param[in] geometry The render geometry
248 * @param[in] geometryType The new geometry type
250 void SetGeometryType( Render::Geometry* geometry, uint32_t geometryType );
253 * Adds a texture to the render manager
254 * @param[in] texture The texture to add
256 void AddTexture( OwnerPointer< Render::Texture >& texture );
259 * Removes a texture from the render manager
260 * @param[in] texture The texture to remove
262 void RemoveTexture( Render::Texture* texture );
265 * Uploads data to an existing texture
266 * @param[in] texture The texture
267 * @param[in] pixelData The pixel data object
268 * @param[in] params The parameters for the upload
270 void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
273 * Generates mipmaps for a given texture
274 * @param[in] texture The texture
276 void GenerateMipmaps( Render::Texture* texture );
279 * Adds a framebuffer to the render manager
280 * @param[in] frameBuffer The framebuffer to add
282 void AddFrameBuffer( OwnerPointer< Render::FrameBuffer >& frameBuffer );
285 * Removes a framebuffer from the render manager
286 * @param[in] frameBuffer The framebuffer to remove
288 void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
291 * Attach a texture as color output to an existing FrameBuffer
292 * @param[in] frameBuffer The FrameBuffer
293 * @param[in] texture The texture that will be used as output when rendering
294 * @param[in] mipmapLevel The mipmap of the texture to be attached
295 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
297 void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
300 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
301 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
302 * object, usually an offscreen render task.
303 * @param[in] renderTracker The render tracker
305 void AddRenderTracker( Render::RenderTracker* renderTracker );
308 * Removes a render tracker from the RenderManager.
309 * @param[in] renderTracker The render tracker to remove.
311 void RemoveRenderTracker( Render::RenderTracker* renderTracker );
314 * returns the Program controller for sending program messages
315 * @return the ProgramController
317 ProgramCache* GetProgramCache();
319 // This method should be called from Core::Render()
322 * Renders the results of the previous "update" traversal.
323 * @param[out] status contains the rendering flags.
324 * @param[in] forceClear Force the Clear on the framebuffer even if nothing is rendered.
325 * @param[in] uploadOnly Upload the resource only without rendering.
327 void Render( Integration::RenderStatus& status, bool forceClear, bool uploadOnly );
332 * Helper to process a single RenderInstruction.
333 * @param[in] instruction A description of the rendering operation.
335 void DoRender( RenderInstruction& instruction );
340 * Construct a new RenderManager.
345 RenderManager( const RenderManager& );
348 RenderManager& operator=( const RenderManager& rhs );
357 } // namespace SceneGraph
359 } // namespace Internal
363 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H