Cleanup: Remove handling for default shader as it has been long gone from dali-core
[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/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>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 class GlAbstraction;
34 class GlSyncAbstraction;
35 class RenderStatus;
36 }
37
38 struct Vector4;
39
40 namespace Internal
41 {
42 class Context;
43 class ProgramCache;
44 class ShaderSaver;
45
46 namespace Render
47 {
48 class FrameBuffer;
49 class Renderer;
50 struct Sampler;
51 class RenderTracker;
52 class Geometry;
53 class Texture;
54 }
55
56 namespace SceneGraph
57 {
58 class RenderQueue;
59 class RenderInstruction;
60 class RenderInstructionContainer;
61 class Shader;
62 class PropertyBufferDataProvider;
63
64 /**
65  * RenderManager is responsible for rendering the result of the previous "update", which
66  * is provided in a RenderCommand during UpdateManager::Update().
67  */
68 class RenderManager
69 {
70 public:
71
72   /**
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.*
77    */
78   static RenderManager* New( Integration::GlAbstraction& glAbstraction,
79                              Integration::GlSyncAbstraction& glSyncAbstraction );
80
81   /**
82    * Non-virtual destructor; not intended as a base class
83    */
84   ~RenderManager();
85
86   /**
87    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
88    * @return The render queue.
89    */
90   RenderQueue& GetRenderQueue();
91
92   /**
93    * @copydoc Dali::Integration::Core::ContextCreated()
94    */
95   void ContextCreated();
96
97   /**
98    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
99    */
100   void ContextDestroyed();
101
102   /**
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.
107    */
108   void SetShaderSaver( ShaderSaver& upstream );
109
110   /**
111    * Retrieve the render instructions; these should be set during each "update" traversal.
112    * @return The render instruction container.
113    */
114   RenderInstructionContainer& GetRenderInstructionContainer();
115
116   // The following methods should be called via RenderQueue messages
117
118   /**
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.
121    */
122   void SetBackgroundColor( const Vector4& color );
123
124   /*
125    * Set the frame time delta (time elapsed since the last frame.
126    * @param[in] deltaTime the delta time
127    */
128   void SetFrameDeltaTime( float deltaTime );
129
130   /**
131    * Returns the rectangle for the default surface (probably the application window).
132    * @return Rectangle for the surface.
133    */
134   void SetDefaultSurfaceRect( const Rect<int>& rect );
135
136   /**
137    * Add a Renderer to the render manager.
138    * @param[in] renderer The renderer to add.
139    * @post renderer is owned by RenderManager
140    */
141   void AddRenderer( Render::Renderer* renderer );
142
143   /**
144    * Remove a Renderer from the render manager.
145    * @param[in] renderer The renderer to remove.
146    * @post renderer is destroyed.
147    */
148   void RemoveRenderer( Render::Renderer* renderer );
149
150   /**
151    * Add a sampler to the render manager.
152    * @param[in] sampler The sampler to add.
153    * @post sampler is owned by RenderManager
154    */
155   void AddSampler( Render::Sampler* sampler );
156
157   /**
158    * Remove a sampler from the render manager.
159    * @param[in] sampler The sampler to remove.
160    * @post sampler is destroyed.
161    */
162   void RemoveSampler( Render::Sampler* sampler );
163
164   /**
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
168    */
169   void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
170
171   /**
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
176    */
177   void SetWrapMode( Render::Sampler* sampler, unsigned int rWrapMode, unsigned int sWrapMode, unsigned int tWrapMode );
178
179   /**
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
183    */
184   void AddPropertyBuffer( Render::PropertyBuffer* propertyBuffer );
185
186   /**
187    * Remove a property buffer from the render manager.
188    * @param[in] propertyBuffer The property buffer to remove.
189    * @post propertyBuffer is destroyed.
190    */
191   void RemovePropertyBuffer( Render::PropertyBuffer* propertyBuffer );
192
193   /**
194    * Add a geometry to the render manager.
195    * @param[in] geometry The geometry to add.
196    * @post geometry is owned by RenderManager
197    */
198   void AddGeometry( Render::Geometry* geometry );
199
200   /**
201    * Remove a geometry from the render manager.
202    * @param[in] geometry The geometry to remove.
203    * @post geometry is destroyed.
204    */
205   void RemoveGeometry( Render::Geometry* geometry );
206
207   /**
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.
211    */
212   void AddVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
213
214   /**
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.
219    */
220   void RemoveVertexBuffer( Render::Geometry* geometry, Render::PropertyBuffer* propertyBuffer );
221
222   /**
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
226    */
227   void SetPropertyBufferFormat( Render::PropertyBuffer* propertyBuffer, Render::PropertyBuffer::Format* format );
228
229   /**
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
234    */
235   void SetPropertyBufferData( Render::PropertyBuffer* propertyBuffer, Dali::Vector<char>* data, size_t size );
236
237   /**
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
241    */
242   void SetIndexBuffer( Render::Geometry* geometry, Dali::Vector<unsigned short>& data );
243
244   /**
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
248    */
249   void SetGeometryType( Render::Geometry* geometry, unsigned int geometryType );
250
251   /**
252    * Adds a texture to the render manager
253    * @param[in] texture The texture to add
254    */
255   void AddTexture( Render::Texture* texture );
256
257   /**
258    * Removes a texture from the render manager
259    * @param[in] texture The texture to remove
260    */
261   void RemoveTexture( Render::Texture* texture );
262
263   /**
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
268    */
269   void UploadTexture( Render::Texture* texture, PixelDataPtr pixelData, const Texture::UploadParams& params );
270
271   /**
272    * Generates mipmaps for a given texture
273    * @param[in] texture The texture
274    */
275   void GenerateMipmaps( Render::Texture* texture );
276
277   /**
278    * Adds a framebuffer to the render manager
279    * @param[in] frameBuffer The framebuffer to add
280    */
281   void AddFrameBuffer( Render::FrameBuffer* frameBuffer );
282
283   /**
284    * Removes a framebuffer from the render manager
285    * @param[in] frameBuffer The framebuffer to remove
286    */
287   void RemoveFrameBuffer( Render::FrameBuffer* frameBuffer );
288
289   /**
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
295    */
296   void AttachColorTextureToFrameBuffer( Render::FrameBuffer* frameBuffer, Render::Texture* texture, unsigned int mipmapLevel, unsigned int layer );
297
298   /**
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
303    */
304   void AddRenderTracker( Render::RenderTracker* renderTracker );
305
306   /**
307    * Removes a render tracker from the RenderManager.
308    * @param[in] renderTracker The render tracker to remove.
309    */
310   void RemoveRenderTracker( Render::RenderTracker* renderTracker );
311
312   /**
313    * returns the Program controller for sending program messages
314    * @return the ProgramController
315    */
316   ProgramCache* GetProgramCache();
317
318   // This method should be called from Core::Render()
319
320   /**
321    * Renders the results of the previous "update" traversal.
322    * @param[out] status contains the flag that indicates if render instructions exist
323    * @return true if a further update is required
324    */
325   bool Render( Integration::RenderStatus& status );
326
327 private:
328
329   /**
330    * Helper to process a single RenderInstruction.
331    * @param[in] instruction A description of the rendering operation.
332    */
333   void DoRender( RenderInstruction& instruction );
334
335 private:
336
337   /**
338    * Construct a new RenderManager.
339    */
340   RenderManager();
341
342   // Undefined
343   RenderManager( const RenderManager& );
344
345   // Undefined
346   RenderManager& operator=( const RenderManager& rhs );
347
348 private:
349
350   struct Impl;
351   Impl* mImpl;
352
353 };
354
355 } // namespace SceneGraph
356
357 } // namespace Internal
358
359 } // namespace Dali
360
361 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__