1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
5 * Copyright (c) 2015 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/internal/common/shader-saver.h>
24 #include <dali/internal/render/gl-resources/gpu-buffer.h>
25 #include <dali/internal/render/renderers/render-property-buffer.h>
26 #include <dali/internal/event/rendering/texture-impl.h>
34 class GlSyncAbstraction;
59 class RenderInstruction;
60 class RenderInstructionContainer;
62 class PropertyBufferDataProvider;
65 * RenderManager is responsible for rendering the result of the previous "update", which
66 * is provided in a RenderCommand during UpdateManager::Update().
73 * Construct a new RenderManager.
74 * @param[in] glAbstraction The GL abstraction used for rendering.
75 * @param[in] glSyncAbstraction The GL sync abstraction used fence sync creation/deletion.
76 * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.*
78 static RenderManager* New( Integration::GlAbstraction& glAbstraction,
79 Integration::GlSyncAbstraction& glSyncAbstraction );
82 * Non-virtual destructor; not intended as a base class
87 * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
88 * @return The render queue.
90 RenderQueue& GetRenderQueue();
93 * @copydoc Dali::Integration::Core::ContextCreated()
95 void ContextCreated();
98 * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
100 void ContextDestroyed();
103 * Set the upstream interface for compiled shader binaries to be sent back to for eventual
104 * caching and saving.
105 * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
106 * @note This should be called during core initialisation if shader binaries are to be used.
108 void SetShaderSaver( ShaderSaver& upstream );
111 * Retrieve the render instructions; these should be set during each "update" traversal.
112 * @return The render instruction container.
114 RenderInstructionContainer& GetRenderInstructionContainer();
116 // The following methods should be called via RenderQueue messages
119 * Set the background color i.e. the glClear color used at the beginning of each frame.
120 * @param[in] color The new background color.
122 void SetBackgroundColor( const Vector4& color );
125 * Set the frame time delta (time elapsed since the last frame.
126 * @param[in] deltaTime the delta time
128 void SetFrameDeltaTime( float deltaTime );
131 * Returns the rectangle for the default surface (probably the application window).
132 * @return Rectangle for the surface.
134 void SetDefaultSurfaceRect( const Rect<int>& rect );
137 * Add a Renderer to the render manager.
138 * @param[in] renderer The renderer to add.
139 * @post renderer is owned by RenderManager
141 void AddRenderer( OwnerPointer< Render::Renderer >& renderer );
144 * Remove a Renderer from the render manager.
145 * @param[in] renderer The renderer to remove.
146 * @post renderer is destroyed.
148 void RemoveRenderer( Render::Renderer* renderer );
151 * Add a sampler to the render manager.
152 * @param[in] sampler The sampler to add.
153 * @post sampler is owned by RenderManager
155 void AddSampler( OwnerPointer< Render::Sampler >& sampler );
158 * Remove a sampler from the render manager.
159 * @param[in] sampler The sampler to remove.
160 * @post sampler is destroyed.
162 void RemoveSampler( Render::Sampler* sampler );
165 * Set minification and magnification filter modes for a sampler
166 * @param[in] minFilterMode Filter mode to use when the texture is minificated
167 * @param[in] magFilterMode Filter mode to use when the texture is magnified
169 void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
172 * Set wrapping mode for a sampler
173 * @param[in] rWrapMode Wrap mode in the z direction
174 * @param[in] uWrapMode Wrap mode in the x direction
175 * @param[in] vWrapMode Wrap mode in the y direction
177 void SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode );
180 * Add a property buffer to the render manager.
181 * @param[in] propertyBuffer The property buffer to add.
182 * @post propertBuffer is owned by RenderManager
184 void AddPropertyBuffer( OwnerPointer< Render::PropertyBuffer >& propertyBuffer );
187 * Remove a property buffer from the render manager.
188 * @param[in] propertyBuffer The property buffer to remove.
189 * @post propertyBuffer is destroyed.
191 void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
194 * Add a geometry to the render manager.
195 * @param[in] geometry The geometry to add.
196 * @post geometry is owned by RenderManager
198 void AddGeometry( OwnerPointer< Render::Geometry >& geometry );
201 * Remove a geometry from the render manager.
202 * @param[in] geometry The geometry to remove.
203 * @post geometry is destroyed.
205 void RemoveGeometry( Render::Geometry* geometry );
208 * Adds a property buffer to a geometry from the render manager.
209 * @param[in] geometry The geometry
210 * @param[in] propertyBuffer The property buffer to remove.
212 void AttachVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
215 * Remove a property buffer from a Render::Geometry from the render manager.
216 * @param[in] geometry The geometry
217 * @param[in] propertyBuffer The property buffer to remove.
218 * @post property buffer is destroyed.
220 void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
223 * Sets the format of an existing property buffer
224 * @param[in] propertyBuffer The property buffer.
225 * @param[in] format The new format of the buffer
227 void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Render::PropertyBuffer::Format>& format );
230 * Sets the data of an existing property buffer
231 * @param[in] propertyBuffer The property buffer.
232 * @param[in] data The new data of the buffer
233 * @param[in] size The new size of the buffer
235 void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Vector<char> >& data, size_t size );
238 * Sets the data for the index buffer of an existing geometry
239 * @param[in] geometry The geometry
240 * @param[in] data A vector containing the indices
242 void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& data );
245 * Set the geometry type of an existing render geometry
246 * @param[in] geometry The render geometry
247 * @param[in] geometryType The new geometry type
249 void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
252 * Adds a texture to the render manager
253 * @param[in] texture The texture to add
255 void AddTexture( OwnerPointer< Render::Texture >& texture );
258 * Removes a texture from the render manager
259 * @param[in] texture The texture to remove
261 void RemoveTexture( Render::Texture* texture );
264 * Uploads data to an existing texture
265 * @param[in] texture The texture
266 * @param[in] pixelData The pixel data object
267 * @param[in] params The parameters for the upload
269 void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
272 * Generates mipmaps for a given texture
273 * @param[in] texture The texture
275 void GenerateMipmaps( Render::Texture* texture );
278 * Adds a framebuffer to the render manager
279 * @param[in] frameBuffer The framebuffer to add
281 void AddFrameBuffer( Render::FrameBuffer* frameBuffer );
284 * Removes a framebuffer from the render manager
285 * @param[in] frameBuffer The framebuffer to remove
287 void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
290 * Attach a texture as color output to an existing FrameBuffer
291 * @param[in] frameBuffer The FrameBuffer
292 * @param[in] texture The texture that will be used as output when rendering
293 * @param[in] mipmapLevel The mipmap of the texture to be attached
294 * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
296 void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, unsigned int mipmapLevel, unsigned int layer );
299 * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
300 * tracker. The lifetime of the tracker is related to the lifetime of the tracked
301 * object, usually an offscreen render task.
302 * @param[in] renderTracker The render tracker
304 void AddRenderTracker( Render::RenderTracker* renderTracker );
307 * Removes a render tracker from the RenderManager.
308 * @param[in] renderTracker The render tracker to remove.
310 void RemoveRenderTracker( Render::RenderTracker* renderTracker );
313 * returns the Program controller for sending program messages
314 * @return the ProgramController
316 ProgramCache* GetProgramCache();
318 // This method should be called from Core::Render()
321 * Renders the results of the previous "update" traversal.
322 * @param[out] status contains the rendering flags.
324 void Render( Integration::RenderStatus& status );
329 * Helper to process a single RenderInstruction.
330 * @param[in] instruction A description of the rendering operation.
332 void DoRender( RenderInstruction& instruction );
337 * Construct a new RenderManager.
342 RenderManager( const RenderManager& );
345 RenderManager& operator=( const RenderManager& rhs );
354 } // namespace SceneGraph
356 } // namespace Internal
360 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__