Merge "Added RenderTask WorldToViewport coordinates" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-renderer.h
1 #ifndef __DALI_INTERNAL_RENDER_RENDERER_H__
2 #define __DALI_INTERNAL_RENDER_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 // INTERNAL INCLUDES
22 #include <dali/public-api/math/matrix.h>
23 #include <dali/public-api/math/vector4.h>
24 #include <dali/devel-api/rendering/material.h>
25 #include <dali/internal/common/blending-options.h>
26 #include <dali/internal/common/message.h>
27 #include <dali/internal/event/effects/shader-declarations.h>
28 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/internal/common/type-abstraction-enums.h>
31 #include <dali/internal/update/manager/prepare-render-instructions.h>
32 #include <dali/internal/render/renderers/render-geometry.h>
33
34 namespace Dali
35 {
36
37 namespace Internal
38 {
39 class Context;
40 class Texture;
41 class Program;
42
43 namespace SceneGraph
44 {
45 class SceneController;
46 class Shader;
47 class TextureCache;
48 class NodeDataProvider;
49 }
50
51
52 namespace Render
53 {
54 class UniformNameCache;
55
56 /**
57  * Renderers are used to render meshes
58  * These objects are used during RenderManager::Render(), so properties modified during
59  * the Update must either be double-buffered, or set via a message added to the RenderQueue.
60  */
61 class Renderer : public GlResourceOwner
62 {
63 public:
64
65   /**
66    * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
67    */
68   void GlContextDestroyed();
69
70   /**
71    * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
72    */
73   void GlCleanup();
74
75   /**
76    * Create a new renderer instance
77    * @param[in] dataProviders The data providers for the renderer
78    * @param[in] renderGeometry The geometry for the renderer
79    */
80   static Renderer* New( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
81
82   /**
83    * Constructor.
84    * @param[in] dataProviders The data providers for the renderer
85    * @param[in] renderGeometry The geometry for the renderer
86    */
87   Renderer( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
88
89   /**
90    * Change the data providers of the renderer
91    * @param[in] dataProviders The data providers
92    */
93   void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
94
95   /**
96    * Change the geometry used by the renderer
97    * @param[in] renderGeometry The new geometry
98    */
99   void SetGeometry( SceneGraph::RenderGeometry* renderGeometry );
100   /**
101    * Second-phase construction.
102    * This is called when the renderer is inside render thread
103    * @param[in] context to use
104    * @param[in] textureCache to use
105    * @param[in] uniformNameCache to use
106    */
107   void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
108
109   /**
110    * Destructor
111    */
112   ~Renderer();
113
114   /**
115    * Set the face-culling mode.
116    * @param[in] mode The face-culling mode.
117    */
118   void SetCullFace( Dali::Material::FaceCullingMode mode );
119
120   /**
121    * Set the sampler used to render the set texture.
122    * @param[in] samplerBitfield The packed sampler options used to render.
123    */
124   void SetSampler( unsigned int samplerBitfield );
125
126   /**
127    * Query whether the derived type of Renderer requires depth testing.
128    * @return True if the renderer requires depth testing.
129    */
130   bool RequiresDepthTest() const;
131
132   /**
133    * Called to render during RenderManager::Render().
134    * @param[in] context The context used for rendering
135    * @param[in] textureCache The texture cache used to get textures
136    * @param[in] bufferIndex The index of the previous update buffer.
137    * @param[in] node The node using this renderer
138    * @param[in] defaultShader in case there is no custom shader
139    * @param[in] modelViewMatrix The model-view matrix.
140    * @param[in] viewMatrix The view matrix.
141    * @param[in] projectionMatrix The projection matrix.
142    */
143   void Render( Context& context,
144                SceneGraph::TextureCache& textureCache,
145                BufferIndex bufferIndex,
146                const SceneGraph::NodeDataProvider& node,
147                SceneGraph::Shader& defaultShader,
148                const Matrix& modelViewMatrix,
149                const Matrix& viewMatrix,
150                const Matrix& projectionMatrix,
151                bool blend);
152
153   /**
154    * Write the renderer's sort attributes to the passed in reference
155    *
156    * @param[in] bufferIndex The current update buffer index.
157    * @param[out] sortAttributes
158    */
159   void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
160
161 private:
162
163   struct UniformIndexMap;
164
165   // Undefined
166   Renderer( const Renderer& );
167
168   // Undefined
169   Renderer& operator=( const Renderer& rhs );
170
171   /**
172    * Sets blending options
173    * @param context to use
174    * @param blend Wheter blending should be enabled or not
175    */
176   void SetBlending( Context& context, bool blend );
177
178   /**
179    * Set the uniforms from properties according to the uniform map
180    * @param[in] node The node using the renderer
181    * @param[in] program The shader program on which to set the uniforms.
182    */
183   void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program );
184
185   /**
186    * Set the program uniform in the map from the mapped property
187    */
188   void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
189
190   /**
191    * Bind the material textures in the samplers and setup the samplers
192    * @param[in] textureCache The texture cache
193    * @param[in] program The shader program
194    */
195   void BindTextures( SceneGraph::TextureCache& textureCache, Program& program );
196
197 public:
198
199   OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
200
201 private:
202
203   Context* mContext;
204   SceneGraph::TextureCache* mTextureCache;
205   Render::UniformNameCache* mUniformNameCache;
206   SceneGraph::RenderGeometry* mRenderGeometry;
207
208   struct UniformIndexMap
209   {
210     unsigned int uniformIndex; // The index of the cached location in the Program
211     const PropertyInputImpl* propertyValue;
212   };
213
214   typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
215   UniformIndexMappings mUniformIndexMap;
216
217   Vector<GLint> mAttributesLocation;
218
219   unsigned int mSamplerBitfield;                    ///< Sampler options used for texture filtering
220   bool mUpdateAttributesLocation:1;                 ///< Indicates attribute locations have changed
221   Dali::Material::FaceCullingMode mCullFaceMode:2;  ///< cullface enum, 3 bits is enough
222 };
223
224 } // namespace SceneGraph
225
226 } // namespace Internal
227
228 } // namespace Dali
229
230 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__