Fixed some issues with dali_env script
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-new-renderer.h
1 #ifndef __DALI_INTERNAL_RENDER_NEW_RENDERER_H__
2 #define __DALI_INTERNAL_RENDER_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/render-renderer.h>
26 #include <dali/internal/render/renderers/render-geometry.h>
27 #include <dali/internal/update/manager/prepare-render-instructions.h>
28
29
30 namespace Dali
31 {
32 namespace Internal
33 {
34 class Context;
35 class PropertyInputImpl;
36
37 namespace Render
38 {
39
40 /**
41  * The new geometry renderer.
42  *
43  */
44 class NewRenderer : public Renderer
45 {
46 public:
47   typedef Integration::ResourceId ResourceId;
48
49 public:
50   /**
51    * Create a new renderer instance
52    * @param[in] dataProviders The data providers for the renderer
53    * @param[in] renderGeometry The geometry for the renderer
54    */
55   static NewRenderer* New( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
56
57   /**
58    * Constructor.
59    * @param[in] dataProviders The data providers for the renderer
60    * @param[in] renderGeometry The geometry for the renderer
61    */
62   NewRenderer( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
63
64   /**
65    * Virtual destructor
66    */
67   virtual ~NewRenderer();
68
69   /**
70    * Change the data providers of the renderer
71    * @param[in] dataProviders The data providers
72    */
73   void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
74
75   /**
76    * Change the geometry used by the renderer
77    * @param[in] renderGeometry The new geometry
78    */
79   void SetGeometry( SceneGraph::RenderGeometry* renderGeometry );
80
81   /**
82    * Write the renderer's sort attributes to the passed in reference.
83    * @param[in] bufferIndex The buffer index
84    * @param[out] sortAttributes
85    */
86   void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const
87   {
88     sortAttributes.shader = &( mRenderDataProvider->GetShader() );
89     const std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
90     if( !textures.empty() )
91     {
92       sortAttributes.textureResourceId = textures[0].GetTextureId();
93     }
94     else
95     {
96       sortAttributes.textureResourceId = Integration::InvalidResourceId;
97     }
98
99     sortAttributes.geometry = mRenderGeometry;
100   }
101
102 public: // Implementation of Renderer
103
104   /**
105    * @copydoc SceneGraph::Renderer::GetNewRenderer()
106    */
107   virtual NewRenderer* GetNewRenderer()
108   {
109     return this;
110   }
111
112   /**
113    * @copydoc SceneGraph::Renderer::RequiresDepthTest()
114    */
115   virtual bool RequiresDepthTest() const;
116
117   /**
118    * @copydoc SceneGraph::Renderer::CheckResources()
119    */
120   virtual bool CheckResources();
121
122   /**
123    * @copydoc SceneGraph::Renderer::DoSetUniforms()
124    */
125   virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program, unsigned int programIndex );
126
127   /**
128    * @copydoc SceneGraph::Renderer::DoSetCullFaceMode
129    */
130   virtual void DoSetCullFaceMode( Context& context );
131
132   /**
133    * @copydoc SceneGraph::Renderer::DoSetBlending
134    */
135   virtual void DoSetBlending( Context& context );
136
137   /**
138    * @copydoc SceneGraph::Renderer::DoRender()
139    */
140   virtual void DoRender( Context& context,
141                          SceneGraph::TextureCache& textureCache,
142                          const SceneGraph::NodeDataProvider& node,
143                          BufferIndex bufferIndex,
144                          Program& program,
145                          const Matrix& modelViewMatrix,
146                          const Matrix& viewMatrix );
147
148 public: // Implementation of GlResourceOwner
149
150   /**
151    * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
152    */
153   virtual void GlContextDestroyed();
154
155   /**
156    * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
157    */
158   virtual void GlCleanup();
159
160 private:
161   struct UniformIndexMap;
162
163   /**
164    * Set the uniforms from properties according to the uniform map
165    * @param[in] node The node using the renderer
166    * @param[in] program The shader program on which to set the uniforms.
167    */
168   void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program );
169
170   /**
171    * Set the program uniform in the map from the mapped property
172    */
173   void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
174
175   /**
176    * Bind the material textures in the samplers and setup the samplers
177    * @param[in] textureCache The texture cache
178    * @param[in] program The shader program
179    */
180   void BindTextures( SceneGraph::TextureCache& textureCache, Program& program );
181
182 public:
183
184   OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
185
186 private:
187
188   SceneGraph::RenderGeometry* mRenderGeometry;
189
190   struct UniformIndexMap
191   {
192     unsigned int uniformIndex; // The index of the cached location in the Program
193     const PropertyInputImpl* propertyValue;
194   };
195
196   typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
197   UniformIndexMappings mUniformIndexMap;
198
199   Vector<GLint> mAttributesLocation;
200   bool mUpdateAttributesLocation;
201
202 };
203
204
205 } // SceneGraph
206 } // Internal
207 } // Dali
208
209 #endif // __DALI_INTERNAL_RENDER_NEW_RENDERER_H__