Created renderer objects.
[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/gl-resources/texture-units.h>
24 #include <dali/internal/render/renderers/scene-graph-renderer.h>
25 #include <dali/internal/render/renderers/render-geometry.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 namespace SceneGraph
32 {
33 class NodeDataProvider;
34 class ShaderDataProvider;
35 class SamplerDataProvider;
36 class MaterialDataProvider;
37 class GeometryDataProvider;
38 class RenderGeometry;
39
40 /**
41  * The new geometry renderer.
42  *
43  * @todo MESH_REWORK It will be merged into the base class eventually
44  */
45 class NewRenderer : public Renderer
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] geoemtryDataProvider The geometry data provider
54    * @param[in] materialDataProvider The material data provider
55    */
56   static NewRenderer* New( NodeDataProvider& nodeDataProvider,
57                            const GeometryDataProvider* geometryDataProvider,
58                            const MaterialDataProvider* materialDataProvider );
59   /**
60    * Constructor.
61    * @param[in] nodeDataProvider The node data provider
62    * @param[in] geoemtryDataProvider The geometry data provider
63    * @param[in] materialDataProvider The material data provider
64    */
65   NewRenderer( NodeDataProvider& nodeDataProvider,
66                const GeometryDataProvider* geometryDataProvider,
67                const MaterialDataProvider* materialDataProvider );
68
69   virtual ~NewRenderer();
70
71   /**
72    * Change the geometry data provider of the renderer
73    * @param[in] geoemtryDataProvider The geometry data provider
74    */
75   void SetGeometryDataProvider( const GeometryDataProvider* geometryDataProvider );
76
77   /**
78    * Change the material data provider of the renderer
79    * @param[in] materialDataProvider The material data provider
80    */
81   void SetMaterialDataProvider( const MaterialDataProvider* materialDataProvider );
82
83 public: // Implementation of Renderer
84   /**
85    * @copydoc SceneGraph::Renderer::RequiresDepthTest()
86    */
87   virtual bool RequiresDepthTest() const;
88
89   /**
90    * @copydoc SceneGraph::Renderer::CheckResources()
91    */
92   virtual bool CheckResources();
93
94   /**
95    * @copydoc SceneGraph::Renderer::ResolveGeometryTypes()
96    */
97   virtual void ResolveGeometryTypes( BufferIndex bufferIndex,
98                                      GeometryType& outType,
99                                      ShaderSubTypes& outSubType );
100
101   /**
102    * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
103    */
104   virtual bool IsOutsideClipSpace( const Matrix& modelMatrix,
105                                    const Matrix& modelViewProjectionMatrix );
106
107   /**
108    * @copydoc SceneGraph::Renderer::DoRender()
109    */
110   virtual void DoRender( BufferIndex bufferIndex,
111                          Program& program,
112                          const Matrix& modelViewMatrix,
113                          const Matrix& viewMatrix );
114
115 public: // Implementation of GlResourceOwner
116
117   /**
118    * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
119    */
120   virtual void GlContextDestroyed();
121
122   /**
123    * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
124    */
125   virtual void GlCleanup();
126
127 private:
128   /**
129    * Set the uniforms from properties according to the uniform map
130    * @param[in] program The shader program on which to set the uniforms.
131    */
132   void SetUniforms( Program& program );
133
134   /**
135    * Bind the material textures in the samplers and setup the samplers
136    * @param[in] bufferIndex The buffer index
137    * @param[in] program The shader program
138    * @param[in] samplers The samplers to bind
139    */
140   void BindTextures( BufferIndex bufferIndex,
141                      Program& program,
142                      const MaterialDataProvider::Samplers& samplers );
143
144   /**
145    * Bind a material texture to a texture unit, and set the sampler's texture uniform
146    * to that texture unit.
147    * @param[in] program The shader program
148    * @param[in] id The resource id of the texture to bind
149    * @param[in] texture The texture to bind
150    * @param[in] textureUnit The texture unit index to use
151    * @param[in] nameIndex The index of the texture uniform in the program
152    */
153   void BindTexture( Program& program,
154                     ResourceId id,
155                     Texture* texture,
156                     TextureUnit textureUnit,
157                     unsigned int nameIndex );
158
159   /**
160    * Apply the sampler modes to the texture.
161    * @param[in] bufferIndex The current buffer index
162    * @param[in] texture The texture to which to apply the sampler modes
163    * @param[in] textureUnit The texture unit of the texture
164    * @param[in] sampler The sampler from which to get the modes.
165    */
166   void ApplySampler( BufferIndex bufferIndex,
167                      Texture* texture,
168                      TextureUnit textureUnit,
169                      const SamplerDataProvider& sampler );
170
171   /**
172    * Get the texture uniform index of the name sampler in the program.
173    * If not already registered in the program, then this performs the registration
174    * @param[in] program The shader program
175    * @param[in] sampler The sampler holding a texture unit uniform name to search for
176    * @return The texture uniform index in the program
177    */
178   unsigned int GetTextureUnitUniformIndex( Program& program,
179                                            const SamplerDataProvider& sampler );
180
181
182 private:
183   //const NodeDataProvider&     mNodeDataProvider;
184   //const ShaderDataProvider&   mShaderDataProvider;
185   const MaterialDataProvider* mMaterialDataProvider;
186   const GeometryDataProvider* mGeometryDataProvider;
187
188   RenderGeometry mRenderGeometry;
189
190   struct TextureUnitUniformIndex
191   {
192     const SamplerDataProvider* sampler;
193     unsigned int index;
194   };
195
196   typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
197   TextureUnitUniforms mTextureUnitUniforms;
198 };
199
200
201 } // SceneGraph
202 } // Internal
203 } // Dali
204
205 #endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__