Merge "DALi Version 1.1.37" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / common / render-manager.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/math/rect.h>
23 #include <dali/internal/common/shader-saver.h>
24 #include <dali/internal/update/resources/resource-manager-declarations.h>
25 #include <dali/internal/render/common/texture-uploaded-dispatcher.h>
26 #include <dali/internal/render/gl-resources/gpu-buffer.h>
27 #include <dali/internal/render/renderers/render-property-buffer.h>
28
29 namespace Dali
30 {
31
32 namespace Integration
33 {
34 class GlAbstraction;
35 class GlSyncAbstraction;
36 class RenderStatus;
37 }
38
39 struct Vector4;
40
41 namespace Internal
42 {
43 class Context;
44 class ProgramCache;
45 class ShaderSaver;
46
47 namespace Render
48 {
49 class FrameBuffer;
50 class Renderer;
51 struct Sampler;
52 class RenderTracker;
53 class Geometry;
54 class NewTexture;
55 }
56
57 namespace SceneGraph
58 {
59 class RenderQueue;
60 class TextureCache;
61 class RenderInstruction;
62 class RenderInstructionContainer;
63 class Shader;
64 class PropertyBufferDataProvider;
65
66 /**
67  * RenderManager is responsible for rendering the result of the previous "update", which
68  * is provided in a RenderCommand during UpdateManager::Update().
69  */
70 class RenderManager : public TextureUploadedDispatcher
71 {
72 public:
73
74   /**
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[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
79    */
80   static RenderManager* New( Integration::GlAbstraction& glAbstraction,
81                              Integration::GlSyncAbstraction& glSyncAbstraction,
82                              LockedResourceQueue& resourcePostProcessQueue );
83
84   /**
85    * Non-virtual destructor; not intended as a base class
86    */
87   ~RenderManager();
88
89   /**
90    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
91    * @return The render queue.
92    */
93   RenderQueue& GetRenderQueue();
94
95   /**
96    * Retrieve the texture cache. Messages should only be sent to this from the update thread,
97    * accessor methods should only be used from the render thread.
98    * @return The texture cache
99    */
100   TextureCache& GetTextureCache();
101
102   /**
103    * @copydoc Dali::Integration::Core::ContextCreated()
104    */
105   void ContextCreated();
106
107   /**
108    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
109    */
110   void ContextDestroyed();
111
112   /**
113    * Dispatch requests onto the postProcessResourcesQueue
114    * @param[in] resource The Id of the resource to dispatch
115    */
116   virtual void DispatchTextureUploaded( ResourceId resource );
117
118   /**
119    * Set the upstream interface for compiled shader binaries to be sent back to for eventual
120    * caching and saving.
121    * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
122    * @note This should be called during core initialisation if shader binaries are to be used.
123    */
124   void SetShaderSaver( ShaderSaver& upstream );
125
126   /**
127    * Retrieve the render instructions; these should be set during each "update" traversal.
128    * @return The render instruction container.
129    */
130   RenderInstructionContainer& GetRenderInstructionContainer();
131
132   // The following methods should be called via RenderQueue messages
133
134   /**
135    * Set the background color i.e. the glClear color used at the beginning of each frame.
136    * @param[in] color The new background color.
137    */
138   void SetBackgroundColor( const Vector4& color );
139
140   /*
141    * Set the frame time delta (time elapsed since the last frame.
142    * @param[in] deltaTime the delta time
143    */
144   void SetFrameDeltaTime( float deltaTime );
145
146   /**
147    * Returns the rectangle for the default surface (probably the application window).
148    * @return Rectangle for the surface.
149    */
150   void SetDefaultSurfaceRect( const Rect<int>& rect );
151
152   /**
153    * Add a Renderer to the render manager.
154    * @param[in] renderer The renderer to add.
155    * @post renderer is owned by RenderManager
156    */
157   void AddRenderer( Render::Renderer* renderer );
158
159   /**
160    * Remove a Renderer from the render manager.
161    * @param[in] renderer The renderer to remove.
162    * @post renderer is destroyed.
163    */
164   void RemoveRenderer( Render::Renderer* renderer );
165
166   /**
167    * Add a sampler to the render manager.
168    * @param[in] sampler The sampler to add.
169    * @post sampler is owned by RenderManager
170    */
171   void AddSampler( Render::Sampler* sampler );
172
173   /**
174    * Remove a sampler from the render manager.
175    * @param[in] sampler The sampler to remove.
176    * @post sampler is destroyed.
177    */
178   void RemoveSampler( Render::Sampler* sampler );
179
180   /**
181    * Set minification and magnification filter modes for a sampler
182    * @param[in] minFilterMode Filter mode to use when the texture is minificated
183    * @param[in] magFilterMode Filter mode to use when the texture is magnified
184    */
185   void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
186
187   /**
188    * Set wrapping mode for a sampler
189    * @param[in] rWrapMode Wrap mode in the z direction
190    * @param[in] uWrapMode Wrap mode in the x direction
191    * @param[in] vWrapMode Wrap mode in the y direction
192    */
193   void SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode );
194
195   /**
196    * Add a property buffer to the render manager.
197    * @param[in] propertyBuffer The property buffer to add.
198    * @post propertBuffer is owned by RenderManager
199    */
200   void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer );
201
202   /**
203    * Remove a property buffer from the render manager.
204    * @param[in] propertyBuffer The property buffer to remove.
205    * @post propertyBuffer is destroyed.
206    */
207   void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
208
209   /**
210    * Add a geometry to the render manager.
211    * @param[in] geometry The geometry to add.
212    * @post geometry is owned by RenderManager
213    */
214   void AddGeometry( Render::Geometry* geometry );
215
216   /**
217    * Remove a geometry from the render manager.
218    * @param[in] geometry The geometry to remove.
219    * @post geometry is destroyed.
220    */
221   void RemoveGeometry( Render::Geometry* geometry );
222
223   /**
224    * Adds a property buffer to a geometry from the render manager.
225    * @param[in] geometry The geometry
226    * @param[in] propertyBuffer The property buffer to remove.
227    */
228   void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
229
230   /**
231    * Remove a property buffer from a Render::Geometry from the render manager.
232    * @param[in] geometry The geometry
233    * @param[in] propertyBuffer The property buffer to remove.
234    * @post property buffer is destroyed.
235    */
236   void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
237
238   /**
239    * Sets the format of an existing property buffer
240    * @param[in] propertyBuffer The property buffer.
241    * @param[in] format The new format of the buffer
242    */
243   void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
244
245   /**
246    * Sets the data of an existing property buffer
247    * @param[in] propertyBuffer The property buffer.
248    * @param[in] data The new data of the buffer
249    * @param[in] size The new size of the buffer
250    */
251   void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size );
252
253   /**
254    * Sets the data for the index buffer of an existing geometry
255    * @param[in] geometry The geometry
256    * @param[in] data A vector containing the indices
257    */
258   void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& data );
259
260   /**
261    * Set the geometry type of an existing render geometry
262    * @param[in] geometry The render geometry
263    * @param[in] geometryType The new geometry type
264    */
265   void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
266
267   /**
268    * Adds a texture to the render manager
269    * @param[in] texture The texture to add
270    */
271   void AddTexture( Render::NewTexture* texture );
272
273   /**
274    * Removes a texture from the render manager
275    * @param[in] texture The texture to remove
276    */
277   void RemoveTexture( Render::NewTexture* texture );
278
279   /**
280    * Uploads data to an existing texture
281    * @param[in] texture The texture
282    * @param[in] buffer Vector with the data to be uploaded
283    * @param[in] params The parameters for the upload
284    */
285   void UploadTexture( Render::NewTexture* texture, Vector<unsigned char>& buffer, const TextureUploadParams& params );
286
287   /**
288    * Generates mipmaps for a given texture
289    * @param[in] texture The texture
290    */
291   void GenerateMipmaps( Render::NewTexture* texture );
292
293   /**
294    * Adds a framebuffer to the render manager
295    * @param[in] frameBuffer The framebuffer to add
296    */
297   void AddFrameBuffer( Render::FrameBuffer* frameBuffer );
298
299   /**
300    * Removes a framebuffer from the render manager
301    * @param[in] frameBuffer The framebuffer to remove
302    */
303   void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
304
305   /**
306    * Attach a texture as color output to an existing FrameBuffer
307    * @param[in] frameBuffer The FrameBuffer
308    * @param[in] texture The texture that will be used as output when rendering
309    * @param[in] mipmapLevel The mipmap of the texture to be attached
310    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
311    */
312   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture, unsigned int mipmapLevel, unsigned int layer );
313
314   /**
315    * Attach a texture as depth-stencil to an existing FrameBuffer
316    * @param[in] frameBuffer The FrameBuffer
317    * @param[in] texture The texture that will be used as depth-stencil buffer when rendering
318    */
319   void AttachDepthStencilTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::NewTexture* texture );
320
321   /**
322    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
323    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
324    * object, usually an offscreen render task.
325    * @param[in] renderTracker The render tracker
326    */
327   void AddRenderTracker( Render::RenderTracker* renderTracker );
328
329   /**
330    * Removes a render tracker from the RenderManager.
331    * @param[in] renderTracker The render tracker to remove.
332    */
333   void RemoveRenderTracker( Render::RenderTracker* renderTracker );
334
335   /**
336    * Set the default shader that is to be used in absence of custom shader
337    * @param[in] shader that is the default one
338    */
339   void SetDefaultShader( Shader* shader );
340
341   /**
342    * returns the Program controller for sending program messages
343    * @return the ProgramController
344    */
345   ProgramCache* GetProgramCache();
346
347   // This method should be called from Core::Render()
348
349   /**
350    * Renders the results of the previous "update" traversal.
351    * @param[out] status contains the flag that indicates if render instructions exist
352    * @return true if a further update is required
353    */
354   bool Render( Integration::RenderStatus& status );
355
356 private:
357
358   /**
359    * Helper to process a single RenderInstruction.
360    * @param[in] instruction A description of the rendering operation.
361    * @param[in] defaultShader default shader to use.
362    */
363   void DoRender( RenderInstruction& instruction, Shader& defaultShader );
364
365 private:
366
367   /**
368    * Construct a new RenderManager.
369    */
370   RenderManager();
371
372   // Undefined
373   RenderManager( const RenderManager& );
374
375   // Undefined
376   RenderManager& operator=( const RenderManager& rhs );
377
378 private:
379
380   struct Impl;
381   Impl* mImpl;
382
383 };
384
385 } // namespace SceneGraph
386
387 } // namespace Internal
388
389 } // namespace Dali
390
391 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__