Remove mContext and mTextureCache from Renderer.
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-renderer.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_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 #include <dali/integration-api/resource-declarations.h> // For resource id
22 #include <dali/internal/render/data-providers/material-data-provider.h>
23 #include <dali/internal/render/data-providers/uniform-map-data-provider.h>
24 #include <dali/internal/render/gl-resources/texture-units.h>
25 #include <dali/internal/render/renderers/scene-graph-renderer.h>
26 #include <dali/internal/render/renderers/render-geometry.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 class PropertyInputImpl;
33
34 namespace SceneGraph
35 {
36 class GeometryDataProvider;
37 class MaterialDataProvider;
38 class NodeDataProvider;
39 class RenderGeometry;
40 class SamplerDataProvider;
41 class ShaderDataProvider;
42 class UniformMapDataProvider;
43
44 /**
45  * The new geometry renderer.
46  *
47  * @todo MESH_REWORK It will be merged into the base class eventually
48  */
49 class NewRenderer : public Renderer
50 {
51 private:
52   struct UniformIndexMap;
53
54 public:
55   typedef Integration::ResourceId ResourceId;
56
57   /**
58    * Create a new renderer instance
59    * @param[in] nodeDataProvider The node data provider
60    * @param[in] uniformMapDataProvider The uniform map data provider
61    * @param[in] geometryDataProvider The geometry data provider
62    * @param[in] materialDataProvider The material data provider
63    */
64   static NewRenderer* New( NodeDataProvider& nodeDataProvider,
65                            const UniformMapDataProvider& uniformMapDataProvider,
66                            const GeometryDataProvider* geometryDataProvider,
67                            const MaterialDataProvider* materialDataProvider );
68   /**
69    * Constructor.
70    * @param[in] nodeDataProvider The node data provider
71    * @param[in] uniformMapDataProvider The uniform map data provider
72    * @param[in] geometryDataProvider The geometry data provider
73    * @param[in] materialDataProvider The material data provider
74    */
75   NewRenderer( NodeDataProvider& nodeDataProvider,
76                const UniformMapDataProvider& uniformMapDataProvider,
77                const GeometryDataProvider* geometryDataProvider,
78                const MaterialDataProvider* materialDataProvider );
79
80   virtual ~NewRenderer();
81
82   /**
83    * Change the geometry data provider of the renderer
84    * @param[in] geoemtryDataProvider The geometry data provider
85    */
86   void SetGeometryDataProvider( const GeometryDataProvider* geometryDataProvider );
87
88   /**
89    * Change the material data provider of the renderer
90    * @param[in] materialDataProvider The material data provider
91    */
92   void SetMaterialDataProvider( const MaterialDataProvider* materialDataProvider );
93
94 public: // Implementation of Renderer
95   /**
96    * @copydoc SceneGraph::Renderer::RequiresDepthTest()
97    */
98   virtual bool RequiresDepthTest() const;
99
100   /**
101    * @copydoc SceneGraph::Renderer::CheckResources()
102    */
103   virtual bool CheckResources();
104
105   /**
106    * @copydoc SceneGraph::Renderer::ResolveGeometryTypes()
107    */
108   virtual void ResolveGeometryTypes( BufferIndex bufferIndex,
109                                      GeometryType& outType,
110                                      ShaderSubTypes& outSubType );
111
112   /**
113    * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
114    */
115   virtual bool IsOutsideClipSpace( Context& context,
116                                    const Matrix& modelMatrix,
117                                    const Matrix& modelViewProjectionMatrix );
118
119   /**
120    * @copydoc SceneGraph::Renderer::DoSetUniforms()
121    */
122   virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType );
123
124   /**
125    * @copydoc SceneGraph::Renderer::DoRender()
126    */
127   virtual void DoRender( Context& context,
128                          TextureCache& textureCache,
129                          BufferIndex bufferIndex,
130                          Program& program,
131                          const Matrix& modelViewMatrix,
132                          const Matrix& viewMatrix );
133
134 public: // Implementation of GlResourceOwner
135
136   /**
137    * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
138    */
139   virtual void GlContextDestroyed();
140
141   /**
142    * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
143    */
144   virtual void GlCleanup();
145
146 private:
147   /**
148    * Set the uniforms from properties according to the uniform map
149    * @param[in] program The shader program on which to set the uniforms.
150    */
151   void SetUniforms( BufferIndex bufferIndex, Program& program );
152
153   /**
154    * Set the program uniform in the map from the mapped property
155    */
156   void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
157
158   /**
159    * Bind the material textures in the samplers and setup the samplers
160    * @param[in] textureCache The texture cache
161    * @param[in] bufferIndex The buffer index
162    * @param[in] program The shader program
163    * @param[in] samplers The samplers to bind
164    */
165   void BindTextures( TextureCache& textureCache,
166                      BufferIndex bufferIndex,
167                      Program& program,
168                      const MaterialDataProvider::Samplers& samplers );
169
170   /**
171    * Bind a material texture to a texture unit, and set the sampler's texture uniform
172    * to that texture unit.
173    * @param[in] textureCache The texture cache
174    * @param[in] program The shader program
175    * @param[in] id The resource id of the texture to bind
176    * @param[in] texture The texture to bind
177    * @param[in] textureUnit The texture unit index to use
178    * @param[in] nameIndex The index of the texture uniform in the program
179    */
180   void BindTexture( TextureCache& textureCache,
181                     Program& program,
182                     ResourceId id,
183                     Texture* texture,
184                     TextureUnit textureUnit,
185                     unsigned int nameIndex );
186
187   /**
188    * Apply the sampler modes to the texture.
189    * @param[in] bufferIndex The current buffer index
190    * @param[in] texture The texture to which to apply the sampler modes
191    * @param[in] textureUnit The texture unit of the texture
192    * @param[in] sampler The sampler from which to get the modes.
193    */
194   void ApplySampler( BufferIndex bufferIndex,
195                      Texture* texture,
196                      TextureUnit textureUnit,
197                      const SamplerDataProvider& sampler );
198
199   /**
200    * Get the texture uniform index of the name sampler in the program.
201    * If not already registered in the program, then this performs the registration
202    * @param[in] program The shader program
203    * @param[in] sampler The sampler holding a texture unit uniform name to search for
204    * @return The texture uniform index in the program
205    */
206   unsigned int GetTextureUnitUniformIndex( Program& program,
207                                            const SamplerDataProvider& sampler );
208
209
210 public:
211   // @todo MESH_REWORK Make private - add getters
212   //const NodeDataProvider&     mNodeDataProvider;
213   //const ShaderDataProvider&   mShaderDataProvider;
214   const UniformMapDataProvider& mUniformMapDataProvider;
215   const MaterialDataProvider* mMaterialDataProvider;
216   const GeometryDataProvider* mGeometryDataProvider;
217
218 private:
219
220   RenderGeometry mRenderGeometry;
221
222   struct TextureUnitUniformIndex
223   {
224     const SamplerDataProvider* sampler;
225     unsigned int index;
226   };
227
228   typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
229   TextureUnitUniforms mTextureUnitUniforms;
230
231   struct UniformIndexMap
232   {
233     unsigned int uniformIndex; // The index of the cached location in the Program
234     const PropertyInputImpl* propertyValue;
235   };
236
237   typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
238   UniformIndexMappings mUniformIndexMap;
239 };
240
241
242 } // SceneGraph
243 } // Internal
244 } // Dali
245
246 #endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__