Changed passing of data providers to renderers
[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/common/owner-pointer.h>
23 #include <dali/internal/render/data-providers/render-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
37 /**
38  * The new geometry renderer.
39  *
40  * @todo MESH_REWORK It will be merged into the base class eventually
41  */
42 class NewRenderer : public Renderer
43 {
44 private:
45   struct UniformIndexMap;
46
47 public:
48   typedef Integration::ResourceId ResourceId;
49
50   /**
51    * Create a new renderer instance
52    * @param[in] nodeDataProvider The node data provider
53    * @param[in] dataProviders The data providers for the renderer
54    */
55   static NewRenderer* New( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders );
56   /**
57    * Constructor.
58    * @param[in] nodeDataProvider The node data provider
59    * @param[in] dataProviders The data providers for the renderer
60    */
61   NewRenderer( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders );
62
63   virtual ~NewRenderer();
64
65   /**
66    * Change the data providers of the renderer
67    * @param[in] dataProviders The data providers
68    */
69   void SetRenderDataProvider( RenderDataProvider* dataProviders );
70
71 public: // Implementation of Renderer
72   /**
73    * @copydoc SceneGraph::Renderer::RequiresDepthTest()
74    */
75   virtual bool RequiresDepthTest() const;
76
77   /**
78    * @copydoc SceneGraph::Renderer::CheckResources()
79    */
80   virtual bool CheckResources();
81
82   /**
83    * @copydoc SceneGraph::Renderer::ResolveGeometryTypes()
84    */
85   virtual void ResolveGeometryTypes( BufferIndex bufferIndex,
86                                      GeometryType& outType,
87                                      ShaderSubTypes& outSubType );
88
89   /**
90    * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
91    */
92   virtual bool IsOutsideClipSpace( Context& context,
93                                    const Matrix& modelMatrix,
94                                    const Matrix& modelViewProjectionMatrix );
95
96   /**
97    * @copydoc SceneGraph::Renderer::DoSetUniforms()
98    */
99   virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType );
100
101   /**
102    * @copydoc SceneGraph::Renderer::DoRender()
103    */
104   virtual void DoRender( Context& context,
105                          TextureCache& textureCache,
106                          BufferIndex bufferIndex,
107                          Program& program,
108                          const Matrix& modelViewMatrix,
109                          const Matrix& viewMatrix );
110
111 public: // Implementation of GlResourceOwner
112
113   /**
114    * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
115    */
116   virtual void GlContextDestroyed();
117
118   /**
119    * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
120    */
121   virtual void GlCleanup();
122
123 private:
124   /**
125    * Set the uniforms from properties according to the uniform map
126    * @param[in] program The shader program on which to set the uniforms.
127    */
128   void SetUniforms( BufferIndex bufferIndex, Program& program );
129
130   /**
131    * Set the program uniform in the map from the mapped property
132    */
133   void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
134
135   /**
136    * Bind the material textures in the samplers and setup the samplers
137    * @param[in] textureCache The texture cache
138    * @param[in] bufferIndex The buffer index
139    * @param[in] program The shader program
140    * @param[in] samplers The samplers to bind
141    */
142   void BindTextures( TextureCache& textureCache,
143                      BufferIndex bufferIndex,
144                      Program& program,
145                      const RenderDataProvider::Samplers& samplers );
146
147   /**
148    * Bind a material texture to a texture unit, and set the sampler's texture uniform
149    * to that texture unit.
150    * @param[in] textureCache The texture cache
151    * @param[in] program The shader program
152    * @param[in] id The resource id of the texture to bind
153    * @param[in] texture The texture to bind
154    * @param[in] textureUnit The texture unit index to use
155    * @param[in] nameIndex The index of the texture uniform in the program
156    */
157   void BindTexture( TextureCache& textureCache,
158                     Program& program,
159                     ResourceId id,
160                     Texture* texture,
161                     TextureUnit textureUnit,
162                     unsigned int nameIndex );
163
164   /**
165    * Apply the sampler modes to the texture.
166    * @param[in] bufferIndex The current buffer index
167    * @param[in] texture The texture to which to apply the sampler modes
168    * @param[in] textureUnit The texture unit of the texture
169    * @param[in] sampler The sampler from which to get the modes.
170    */
171   void ApplySampler( BufferIndex bufferIndex,
172                      Texture* texture,
173                      TextureUnit textureUnit,
174                      const SamplerDataProvider& sampler );
175
176   /**
177    * Get the texture uniform index of the name sampler in the program.
178    * If not already registered in the program, then this performs the registration
179    * @param[in] program The shader program
180    * @param[in] sampler The sampler holding a texture unit uniform name to search for
181    * @return The texture uniform index in the program
182    */
183   unsigned int GetTextureUnitUniformIndex( Program& program,
184                                            const SamplerDataProvider& sampler );
185
186 public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer
187   OwnerPointer< RenderDataProvider > mRenderDataProvider;
188
189 private:
190   RenderGeometry mRenderGeometry;
191
192   struct TextureUnitUniformIndex
193   {
194     const SamplerDataProvider* sampler;
195     unsigned int index;
196   };
197
198   typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
199   TextureUnitUniforms mTextureUnitUniforms;
200
201   struct UniformIndexMap
202   {
203     unsigned int uniformIndex; // The index of the cached location in the Program
204     const PropertyInputImpl* propertyValue;
205   };
206
207   typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
208   UniformIndexMappings mUniformIndexMap;
209 };
210
211
212 } // SceneGraph
213 } // Internal
214 } // Dali
215
216 #endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__