1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
5 * Copyright (c) 2017 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;
60 class RenderInstruction;
61 class RenderInstructionContainer;
63 class PropertyBufferDataProvider;
66 * RenderManager is responsible for rendering the result of the previous "update", which
67 * is provided in a RenderCommand during UpdateManager::Update().
74 * Construct a new RenderManager.
75 * @param[in] glAbstraction The GL abstraction used for rendering.
76 * @param[in] glSyncAbstraction The GL sync abstraction used fence sync creation/deletion.
77 * @param[in] depthBufferAvailable Whether the depth buffer is available
78 * @param[in] stencilBufferAvailable Whether the stencil buffer is available
80 static RenderManager* New( Integration::GlAbstraction& glAbstraction,
81 Integration::GlSyncAbstraction& glSyncAbstraction,
82 Integration::DepthBufferAvailable depthBufferAvailable,
83 Integration::StencilBufferAvailable stencilBufferAvailable );
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 );
115 * Retrieve the render instructions; these should be set during each "update" traversal.
116 * @return The render instruction container.
118 RenderInstructionContainer& GetRenderInstructionContainer();
120 // The following methods should be called via RenderQueue messages
123 * Set the background color i.e. the glClear color used at the beginning of each frame.
124 * @param[in] color The new background color.
126 void SetBackgroundColor( const Vector4& color );
129 * Set the frame time delta (time elapsed since the last frame.
130 * @param[in] deltaTime the delta time
132 void SetFrameDeltaTime( float deltaTime );
135 * Returns the rectangle for the default surface (probably the application window).
136 * @return Rectangle for the surface.
138 void SetDefaultSurfaceRect( const Rect<int>& rect );
141 * Add a Renderer to the render manager.
142 * @param[in] renderer The renderer to add.
143 * @post renderer is owned by RenderManager
145 void AddRenderer( OwnerPointer< Render::Renderer >& renderer );
148 * Remove a Renderer from the render manager.
149 * @param[in] renderer The renderer to remove.
150 * @post renderer is destroyed.
152 void RemoveRenderer( Render::Renderer* renderer );
155 * Add a sampler to the render manager.
156 * @param[in] sampler The sampler to add.
157 * @post sampler is owned by RenderManager
159 void AddSampler( OwnerPointer< Render::Sampler >& sampler );
162 * Remove a sampler from the render manager.
163 * @param[in] sampler The sampler to remove.
164 * @post sampler is destroyed.
166 void RemoveSampler( Render::Sampler* sampler );
169 * Set minification and magnification filter modes for a sampler
170 * @param[in] minFilterMode Filter mode to use when the texture is minificated
171 * @param[in] magFilterMode Filter mode to use when the texture is magnified
173 void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
176 * Set wrapping mode for a sampler
177 * @param[in] rWrapMode Wrap mode in the z direction
178 * @param[in] uWrapMode Wrap mode in the x direction
179 * @param[in] vWrapMode Wrap mode in the y direction
181 void SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode );
184 * Add a property buffer to the render manager.
185 * @param[in] propertyBuffer The property buffer to add.
186 * @post propertBuffer is owned by RenderManager
188 void AddPropertyBuffer( OwnerPointer< Render::PropertyBuffer >& propertyBuffer );
191 * Remove a property buffer from the render manager.
192 * @param[in] propertyBuffer The property buffer to remove.
193 * @post propertyBuffer is destroyed.
195 void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
198 * Add a geometry to the render manager.
199 * @param[in] geometry The geometry to add.
200 * @post geometry is owned by RenderManager
202 void AddGeometry( OwnerPointer< Render::Geometry >& geometry );
205 * Remove a geometry from the render manager.
206 * @param[in] geometry The geometry to remove.
207 * @post geometry is destroyed.
209 void RemoveGeometry( Render::Geometry* geometry );
212 * Adds a property buffer to a geometry from the render manager.
213 * @param[in] geometry The geometry
214 * @param[in] propertyBuffer The property buffer to remove.
216 void AttachVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
219 * Remove a property buffer from a Render::Geometry from the render manager.
220 * @param[in] geometry The geometry
221 * @param[in] propertyBuffer The property buffer to remove.
222 * @post property buffer is destroyed.
224 void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
227 * Sets the format of an existing property buffer
228 * @param[in] propertyBuffer The property buffer.
229 * @param[in] format The new format of the buffer
231 void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Render::PropertyBuffer::Format>& format );
234 * Sets the data of an existing property buffer
235 * @param[in] propertyBuffer The property buffer.
236 * @param[in] data The new data of the buffer
237 * @param[in] size The new size of the buffer
239 void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Vector<char> >& data, size_t size );
242 * Sets the data for the index buffer of an existing geometry
243 * @param[in] geometry The geometry
244 * @param[in] data A vector containing the indices
246 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& data );
249 * Set the geometry type of an existing render geometry
250 * @param[in] geometry The render geometry
251 * @param[in] geometryType The new geometry type
253 void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
256 * Adds a texture to the render manager
257 * @param[in] texture The texture to add
259 void AddTexture( OwnerPointer< Render::Texture >& texture );
262 * Removes a texture from the render manager
263 * @param[in] texture The texture to remove
265 void RemoveTexture( Render::Texture* texture );
268 * Uploads data to an existing texture
269 * @param[in] texture The texture
270 * @param[in] pixelData The pixel data object
271 * @param[in] params The parameters for the upload
273 void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
276 * Generates mipmaps for a given texture
277 * @param[in] texture The texture
279 void GenerateMipmaps( Render::Texture* texture );
282 * Adds a framebuffer to the render manager
283 * @param[in] frameBuffer The framebuffer to add
285 void AddFrameBuffer( Render::FrameBuffer* frameBuffer );
288 * Removes a framebuffer from the render manager
289 * @param[in] frameBuffer The framebuffer to remove
291 void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
294 * Attach a texture as color output to an existing FrameBuffer
295 * @param[in] frameBuffer The FrameBuffer
296 * @param[in] texture The texture that will be used as output when rendering
297 * @param[in] mipmapLevel The mipmap of the texture to be attached
298 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
300 void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, unsigned int mipmapLevel, unsigned int layer );
303 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
304 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
305 * object, usually an offscreen render task.
306 * @param[in] renderTracker The render tracker
308 void AddRenderTracker( Render::RenderTracker* renderTracker );
311 * Removes a render tracker from the RenderManager.
312 * @param[in] renderTracker The render tracker to remove.
314 void RemoveRenderTracker( Render::RenderTracker* renderTracker );
317 * returns the Program controller for sending program messages
318 * @return the ProgramController
320 ProgramCache* GetProgramCache();
322 // This method should be called from Core::Render()
325 * Renders the results of the previous "update" traversal.
326 * @param[out] status contains the rendering flags.
327 * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
329 void Render( Integration::RenderStatus& status, bool forceClear );
334 * Helper to process a single RenderInstruction.
335 * @param[in] instruction A description of the rendering operation.
337 void DoRender( RenderInstruction& instruction );
342 * Construct a new RenderManager.
347 RenderManager( const RenderManager& );
350 RenderManager& operator=( const RenderManager& rhs );
359 } // namespace SceneGraph
361 } // namespace Internal
365 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__