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