[Tizen] Support Client Rotation and Screen Rotation
[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) 2019 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/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>
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 Texture;
55 }
56
57 namespace SceneGraph
58 {
59 class RenderQueue;
60 class RenderInstruction;
61 class RenderInstructionContainer;
62 class Shader;
63 class PropertyBufferDataProvider;
64
65 /**
66  * RenderManager is responsible for rendering the result of the previous "update", which
67  * is provided in a RenderCommand during UpdateManager::Update().
68  */
69 class RenderManager
70 {
71 public:
72
73   /**
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
79    */
80   static RenderManager* New( Integration::GlAbstraction& glAbstraction,
81                              Integration::GlSyncAbstraction& glSyncAbstraction,
82                              Integration::DepthBufferAvailable depthBufferAvailable,
83                              Integration::StencilBufferAvailable stencilBufferAvailable );
84
85   /**
86    * Non-virtual destructor; not intended as a base class
87    */
88   ~RenderManager();
89
90   /**
91    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
92    * @return The render queue.
93    */
94   RenderQueue& GetRenderQueue();
95
96   /**
97    * @copydoc Dali::Integration::Core::ContextCreated()
98    */
99   void ContextCreated();
100
101   /**
102    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
103    */
104   void ContextDestroyed();
105
106   /**
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.
111    */
112   void SetShaderSaver( ShaderSaver& upstream );
113
114   /**
115    * Retrieve the render instructions; these should be set during each "update" traversal.
116    * @return The render instruction container.
117    */
118   RenderInstructionContainer& GetRenderInstructionContainer();
119
120   // The following methods should be called via RenderQueue messages
121
122   /**
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.
125    */
126   void SetBackgroundColor( const Vector4& color );
127
128   /*
129    * Set the frame time delta (time elapsed since the last frame.
130    * @param[in] deltaTime the delta time
131    */
132   void SetFrameDeltaTime( float deltaTime );
133
134   /**
135    * Returns the rectangle for the default surface (probably the application window).
136    * @return Rectangle for the surface.
137    */
138   void SetDefaultSurfaceRect( const Rect<int>& rect );
139
140   /**
141    * Returns the orintation for the default surface (probably the application window).
142    * @return Orientation for the surface.
143    */
144   void SetDefaultSurfaceOrientation( int orientation );
145
146   /**
147    * Add a Renderer to the render manager.
148    * @param[in] renderer The renderer to add.
149    * @post renderer is owned by RenderManager
150    */
151   void AddRenderer( OwnerPointer< Render::Renderer >& renderer );
152
153   /**
154    * Remove a Renderer from the render manager.
155    * @param[in] renderer The renderer to remove.
156    * @post renderer is destroyed.
157    */
158   void RemoveRenderer( Render::Renderer* renderer );
159
160   /**
161    * Add a sampler to the render manager.
162    * @param[in] sampler The sampler to add.
163    * @post sampler is owned by RenderManager
164    */
165   void AddSampler( OwnerPointer< Render::Sampler >& sampler );
166
167   /**
168    * Remove a sampler from the render manager.
169    * @param[in] sampler The sampler to remove.
170    * @post sampler is destroyed.
171    */
172   void RemoveSampler( Render::Sampler* sampler );
173
174   /**
175    * Set minification and magnification filter modes for a sampler
176    * @param[in] minFilterMode Filter mode to use when the texture is minificated
177    * @param[in] magFilterMode Filter mode to use when the texture is magnified
178    */
179   void SetFilterMode( Render::Sampler* sampler, uint32_t minFilterMode, uint32_t magFilterMode );
180
181   /**
182    * Set wrapping mode for a sampler
183    * @param[in] rWrapMode Wrap mode in the z direction
184    * @param[in] uWrapMode Wrap mode in the x direction
185    * @param[in] vWrapMode Wrap mode in the y direction
186    */
187   void SetWrapMode( Render::Sampler* sampler, uint32_t rWrapMode, uint32_t sWrapMode, uint32_t tWrapMode );
188
189   /**
190    * Add a property buffer to the render manager.
191    * @param[in] propertyBuffer The property buffer to add.
192    * @post propertBuffer is owned by RenderManager
193    */
194   void AddPropertyBuffer( OwnerPointer< Render::PropertyBuffer >& propertyBuffer );
195
196   /**
197    * Remove a property buffer from the render manager.
198    * @param[in] propertyBuffer The property buffer to remove.
199    * @post propertyBuffer is destroyed.
200    */
201   void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
202
203   /**
204    * Add a geometry to the render manager.
205    * @param[in] geometry The geometry to add.
206    * @post geometry is owned by RenderManager
207    */
208   void AddGeometry( OwnerPointer< Render::Geometry >& geometry );
209
210   /**
211    * Remove a geometry from the render manager.
212    * @param[in] geometry The geometry to remove.
213    * @post geometry is destroyed.
214    */
215   void RemoveGeometry( Render::Geometry* geometry );
216
217   /**
218    * Adds a property buffer to a geometry from the render manager.
219    * @param[in] geometry The geometry
220    * @param[in] propertyBuffer The property buffer to remove.
221    */
222   void AttachVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
223
224   /**
225    * Remove a property buffer from a Render::Geometry from the render manager.
226    * @param[in] geometry The geometry
227    * @param[in] propertyBuffer The property buffer to remove.
228    * @post property buffer is destroyed.
229    */
230   void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
231
232   /**
233    * Sets the format of an existing property buffer
234    * @param[in] propertyBuffer The property buffer.
235    * @param[in] format The new format of the buffer
236    */
237   void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Render::PropertyBuffer::Format>& format );
238
239   /**
240    * Sets the data of an existing property buffer
241    * @param[in] propertyBuffer The property buffer.
242    * @param[in] data The new data of the buffer
243    * @param[in] size The new size of the buffer
244    */
245   void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, OwnerPointer< Vector<uint8_t> >& data, uint32_t size );
246
247   /**
248    * Sets the data for the index buffer of an existing geometry
249    * @param[in] geometry The geometry
250    * @param[in] data A vector containing the indices
251    */
252   void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<uint16_t>& data );
253
254   /**
255    * Set the geometry type of an existing render geometry
256    * @param[in] geometry The render geometry
257    * @param[in] geometryType The new geometry type
258    */
259   void SetGeometryType( Render::Geometry* geometry, uint32_t geometryType );
260
261   /**
262    * Adds a texture to the render manager
263    * @param[in] texture The texture to add
264    */
265   void AddTexture( OwnerPointer< Render::Texture >& texture );
266
267   /**
268    * Removes a texture from the render manager
269    * @param[in] texture The texture to remove
270    */
271   void RemoveTexture( Render::Texture* texture );
272
273   /**
274    * Uploads data to an existing texture
275    * @param[in] texture The texture
276    * @param[in] pixelData The pixel data object
277    * @param[in] params The parameters for the upload
278    */
279   void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
280
281   /**
282    * Generates mipmaps for a given texture
283    * @param[in] texture The texture
284    */
285   void GenerateMipmaps( Render::Texture* texture );
286
287   /**
288    * Adds a framebuffer to the render manager
289    * @param[in] frameBuffer The framebuffer to add
290    */
291   void AddFrameBuffer( OwnerPointer< Render::FrameBuffer >& frameBuffer );
292
293   /**
294    * Removes a framebuffer from the render manager
295    * @param[in] frameBuffer The framebuffer to remove
296    */
297   void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
298
299   /**
300    * Attach a texture as color output to an existing FrameBuffer
301    * @param[in] frameBuffer The FrameBuffer
302    * @param[in] texture The texture that will be used as output when rendering
303    * @param[in] mipmapLevel The mipmap of the texture to be attached
304    * @param[in] layer Indicates which layer of a cube map or array texture to attach. Unused for 2D textures
305    */
306   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, uint32_t mipmapLevel, uint32_t layer );
307
308   /**
309    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
310    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
311    * object, usually an offscreen render task.
312    * @param[in] renderTracker The render tracker
313    */
314   void AddRenderTracker( Render::RenderTracker* renderTracker );
315
316   /**
317    * Removes a render tracker from the RenderManager.
318    * @param[in] renderTracker The render tracker to remove.
319    */
320   void RemoveRenderTracker( Render::RenderTracker* renderTracker );
321
322   /**
323    * returns the Program controller for sending program messages
324    * @return the ProgramController
325    */
326   ProgramCache* GetProgramCache();
327
328   // This method should be called from Core::Render()
329
330   /**
331    * Renders the results of the previous "update" traversal.
332    * @param[out] status contains the rendering flags.
333    * @param[in] forceClear force the Clear on the framebuffer even if nothing is rendered.
334    */
335   void Render( Integration::RenderStatus& status, bool forceClear );
336
337 private:
338
339   /**
340    * Helper to process a single RenderInstruction.
341    * @param[in] instruction A description of the rendering operation.
342    */
343   void DoRender( RenderInstruction& instruction );
344
345 private:
346
347   /**
348    * Construct a new RenderManager.
349    */
350   RenderManager();
351
352   // Undefined
353   RenderManager( const RenderManager& );
354
355   // Undefined
356   RenderManager& operator=( const RenderManager& rhs );
357
358 private:
359
360   struct Impl;
361   Impl* mImpl;
362
363 };
364
365 } // namespace SceneGraph
366
367 } // namespace Internal
368
369 } // namespace Dali
370
371 #endif // DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H