Remove Sampler scene object
[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) 2014 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/common/post-process-resource-dispatcher.h>
25 #include <dali/internal/update/resources/resource-manager-declarations.h>
26 #include <dali/internal/render/gl-resources/gpu-buffer.h>
27
28 namespace Dali
29 {
30
31 namespace Integration
32 {
33 class GlAbstraction;
34 class RenderStatus;
35 }
36
37 struct Vector4;
38
39 namespace Internal
40 {
41 class Context;
42 class ProgramCache;
43 class ShaderSaver;
44
45 namespace Render
46 {
47 class Renderer;
48 class Sampler;
49 }
50
51 namespace SceneGraph
52 {
53 class RenderQueue;
54 class TextureCache;
55 class RenderInstruction;
56 class RenderInstructionContainer;
57 class RenderTracker;
58 class Shader;
59 class RenderGeometry;
60 class PropertyBufferDataProvider;
61
62 /**
63  * RenderManager is responsible for rendering the result of the previous "update", which
64  * is provided in a RenderCommand during UpdateManager::Update().
65  */
66 class RenderManager : public PostProcessResourceDispatcher
67 {
68 public:
69
70   /**
71    * Construct a new RenderManager.
72    * @param[in]  glAbstraction The GL abstraction used for rendering.
73    * @param[out] resourcePostProcessQueue A queue for sending rendered texture ids to the update-thread.
74    */
75   static RenderManager* New( Dali::Integration::GlAbstraction& glAbstraction, ResourcePostProcessList& resourcePostProcessQueue );
76
77   /**
78    * Non-virtual destructor; not intended as a base class
79    */
80   ~RenderManager();
81
82   /**
83    * Retrieve the RenderQueue. Messages should only be added to this from the update-thread.
84    * @return The render queue.
85    */
86   RenderQueue& GetRenderQueue();
87
88   /**
89    * Retrieve the texture cache. Messages should only be sent to this from the update thread,
90    * accessor methods should only be used from the render thread.
91    * @return The texture cache
92    */
93   TextureCache& GetTextureCache();
94
95   /**
96    * @copydoc Dali::Integration::Core::ContextCreated()
97    */
98   void ContextCreated();
99
100   /**
101    * @copydoc Dali::Integration::Core::ContextToBeDestroyed()
102    */
103   void ContextDestroyed();
104
105   /**
106    * Dispatch requests onto the postProcessResourcesQueue
107    * @param[in] request The request to dispatch
108    */
109   virtual void DispatchPostProcessRequest( ResourcePostProcessRequest& request );
110
111   /**
112    * Set the upstream interface for compiled shader binaries to be sent back to for eventual
113    * caching and saving.
114    * @param[in] upstream The abstract interface to send any received ShaderDatas onwards to..
115    * @note This should be called during core initialisation if shader binaries are to be used.
116    */
117   void SetShaderSaver( ShaderSaver& upstream );
118
119   /**
120    * Retrieve the render instructions; these should be set during each "update" traversal.
121    * @return The render instruction container.
122    */
123   RenderInstructionContainer& GetRenderInstructionContainer();
124
125   // The following methods should be called via RenderQueue messages
126
127   /**
128    * Set the background color i.e. the glClear color used at the beginning of each frame.
129    * @param[in] color The new background color.
130    */
131   void SetBackgroundColor( const Vector4& color );
132
133   /*
134    * Set the frame time delta (time elapsed since the last frame.
135    * @param[in] deltaTime the delta time
136    */
137   void SetFrameDeltaTime( float deltaTime );
138
139   /**
140    * Returns the rectangle for the default surface (probably the application window).
141    * @return Rectangle for the surface.
142    */
143   void SetDefaultSurfaceRect( const Rect<int>& rect );
144
145   /**
146    * Add a Renderer to the render manager.
147    * @param[in] renderer The renderer to add.
148    * @post renderer is owned by RenderManager
149    */
150   void AddRenderer( Render::Renderer* renderer );
151
152   /**
153    * Remove a Renderer from the render manager.
154    * @param[in] renderer The renderer to remove.
155    * @post renderer is destroyed.
156    */
157   void RemoveRenderer( Render::Renderer* renderer );
158
159   /**
160    * Add a sampler to the render manager.
161    * @param[in] sampler The sampler to add.
162    * @post sampler is owned by RenderManager
163    */
164   void AddSampler( Render::Sampler* sampler );
165
166   /**
167    * Remove a sampler from the render manager.
168    * @param[in] sampler The sampler to remove.
169    * @post sampler is destroyed.
170    */
171   void RemoveSampler( Render::Sampler* sampler );
172
173   /**
174    * Set minification and magnification filter modes for a sampler
175    * @param[in] minFilterMode Filter mode to use when the texture is minificated
176    * @param[in] magFilterMode Filter mode to use when the texture is magnified
177    */
178   void SetFilterMode( Render::Sampler* sampler, unsigned int minFilterMode, unsigned int magFilterMode );
179
180   /**
181    * Set wrapping mode for a sampler
182    * @param[in] uWrapMode Wrap mode in the x direction
183    * @param[in] vWrapMode Wrap mode in the y direction
184    */
185   void SetWrapMode( Render::Sampler* sampler, unsigned int uWrapMode, unsigned int vWrapMode );
186
187   /**
188    * Add a geometry to the render manager.
189    * @param[in] geometry The geometry to add.
190    * @post geometry is owned by RenderManager
191    */
192   void AddGeometry( RenderGeometry* geometry );
193
194   /**
195    * Remove a geometry from the render manager.
196    * @param[in] geometry The geometry to remove.
197    * @post geometry is destroyed.
198    */
199   void RemoveGeometry( RenderGeometry* geometry );
200
201   /**
202    * Adds a property buffer to a RenderGeometry from the render manager.
203    * @param[in] geometry The geometry
204    * @param[in] propertyBuffer The property buffer to remove.
205    * @param[in] target Specifies the type of the buffer
206    * @param[in] usage Specifies how will the buffer be used
207    */
208   void AddPropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer, const GpuBuffer::Target& target, const GpuBuffer::Usage& usage );
209
210   /**
211    * Remove a property buffer from a RenderGeometry from the render manager.
212    * @param[in] geometry The geometry
213    * @param[in] propertyBuffer The property buffer to remove.
214    * @post property buffer is destroyed.
215    */
216   void RemovePropertyBuffer( RenderGeometry* renderGeometry, PropertyBufferDataProvider* propertyBuffer );
217
218   /**
219    * Adds a render tracker to the RenderManager. RenderManager takes ownership of the
220    * tracker. The lifetime of the tracker is related to the lifetime of the tracked
221    * object, usually an offscreen render task.
222    * @param[in] renderTracker The render tracker
223    */
224   void AddRenderTracker( RenderTracker* renderTracker );
225
226   /**
227    * Removes a render tracker from the RenderManager.
228    * @param[in] renderTracker The render tracker to remove.
229    */
230   void RemoveRenderTracker( RenderTracker* renderTracker );
231
232   /**
233    * Set the default shader that is to be used in absence of custom shader
234    * @param[in] shader that is the default one
235    */
236   void SetDefaultShader( Shader* shader );
237
238   /**
239    * returns the Program controller for sending program messages
240    * @return the ProgramController
241    */
242   ProgramCache* GetProgramCache();
243
244   // This method should be called from Core::Render()
245
246   /**
247    * Renders the results of the previous "update" traversal.
248    * @param[out] status contains the flag that indicates if render instructions exist
249    * @return true if a further update is required
250    */
251   bool Render( Integration::RenderStatus& status );
252
253 private:
254
255   /**
256    * Helper to process a single RenderInstruction.
257    * @param[in] instruction A description of the rendering operation.
258    * @param[in] defaultShader default shader to use.
259    * @param[in] elapsedTime from previous render.
260    */
261   void DoRender( RenderInstruction& instruction, Shader& defaultShader, float elapsedTime );
262
263 private:
264
265   /**
266    * Construct a new RenderManager.
267    */
268   RenderManager();
269
270   // Undefined
271   RenderManager( const RenderManager& );
272
273   // Undefined
274   RenderManager& operator=( const RenderManager& rhs );
275
276 private:
277
278   struct Impl;
279   Impl* mImpl;
280
281 };
282
283 } // namespace SceneGraph
284
285 } // namespace Internal
286
287 } // namespace Dali
288
289 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MANAGER_H__