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