Remove API to set if a geometry requires writing to the depth buffer
[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/texture-set.h>
25 #include <dali/internal/common/blending-options.h>
26 #include <dali/internal/common/message.h>
27 #include <dali/internal/event/common/property-input-impl.h>
28 #include <dali/internal/event/effects/shader-declarations.h>
29 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
30 #include <dali/integration-api/debug.h>
31 #include <dali/internal/common/type-abstraction-enums.h>
32 #include <dali/internal/update/manager/prepare-render-instructions.h>
33 #include <dali/internal/render/data-providers/render-data-provider.h>
34 #include <dali/internal/render/renderers/render-geometry.h>
35
36 namespace Dali
37 {
38
39 namespace Internal
40 {
41 class Context;
42 class Texture;
43 class Program;
44
45 namespace SceneGraph
46 {
47 class SceneController;
48 class Shader;
49 class TextureCache;
50 class NodeDataProvider;
51 }
52
53
54 namespace Render
55 {
56 class UniformNameCache;
57
58 /**
59  * Renderers are used to render meshes
60  * These objects are used during RenderManager::Render(), so properties modified during
61  * the Update must either be double-buffered, or set via a message added to the RenderQueue.
62  */
63 class Renderer : public GlResourceOwner
64 {
65 public:
66
67   /**
68    * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
69    */
70   void GlContextDestroyed();
71
72   /**
73    * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
74    */
75   void GlCleanup();
76
77   /**
78    * Create a new renderer instance
79    * @param[in] dataProviders The data providers for the renderer
80    * @param[in] geometry The geometry for the renderer
81    * @param[in] blendingBitmask A bitmask of blending options.
82    * @param[in] blendColor The blend color to pass to GL
83    * @param[in] faceCullingMode The face-culling mode.
84    * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
85    * @param[in] depthWriteMode Depth buffer write mode
86    */
87   static Renderer* New( SceneGraph::RenderDataProvider* dataProviders,
88                         Render::Geometry* geometry,
89                         unsigned int blendingBitmask,
90                         const Vector4* blendColor,
91                         Dali::Renderer::FaceCullingMode faceCullingMode,
92                         bool preMultipliedAlphaEnabled,
93                         Dali::Renderer::DepthWriteMode depthWriteMode );
94
95   /**
96    * Constructor.
97    * @param[in] dataProviders The data providers for the renderer
98    * @param[in] geometry The geometry for the renderer
99    * @param[in] blendingBitmask A bitmask of blending options.
100    * @param[in] blendColor The blend color to pass to GL
101    * @param[in] faceCullingMode The face-culling mode.
102    * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
103    * @param[in] depthWriteMode Depth buffer write mode
104    */
105   Renderer( SceneGraph::RenderDataProvider* dataProviders,
106             Render::Geometry* geometry,
107             unsigned int blendingBitmask,
108             const Vector4* blendColor,
109             Dali::Renderer::FaceCullingMode faceCullingMode,
110             bool preMultipliedAlphaEnabled,
111             Dali::Renderer::DepthWriteMode depthWriteMode );
112
113   /**
114    * Change the data providers of the renderer
115    * @param[in] dataProviders The data providers
116    */
117   void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
118
119   /**
120    * Change the geometry used by the renderer
121    * @param[in] geometry The new geometry
122    */
123   void SetGeometry( Render::Geometry* geometry );
124   /**
125    * Second-phase construction.
126    * This is called when the renderer is inside render thread
127    * @param[in] context to use
128    * @param[in] textureCache to use
129    * @param[in] uniformNameCache to use
130    */
131   void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
132
133   /**
134    * Destructor
135    */
136   ~Renderer();
137
138   /**
139    * Set the face-culling mode.
140    * @param[in] mode The face-culling mode.
141    */
142   void SetFaceCullingMode( Dali::Renderer::FaceCullingMode mode );
143
144   /**
145    * Set the bitmask for blending options
146    * @param[in] bitmask A bitmask of blending options.
147    */
148   void SetBlendingBitMask( unsigned int bitmask );
149
150   /**
151    * Set the blend color for blending options
152    * @param[in] blendColor The blend color to pass to GL
153    */
154   void SetBlendColor( const Vector4* color );
155
156   /**
157    * Set the first element index to draw by the indexed draw
158    * @param[in] firstElement index of first element to draw
159    */
160   void SetIndexedDrawFirstElement( size_t firstElement );
161
162   /**
163    * Set the number of elements to draw by the indexed draw
164    * @param[in] elementsCount number of elements to draw
165    */
166   void SetIndexedDrawElementsCount( size_t elementsCount );
167
168   /**
169    * @brief Set whether the Pre-multiplied Alpha Blending is required
170    *
171    * @param[in] preMultipled whether alpha is pre-multiplied.
172    */
173   void EnablePreMultipliedAlpha( bool preMultipled );
174
175   /**
176    * Query the Renderer's depth write mode
177    * @return The renderer depth write mode
178    */
179   Dali::Renderer::DepthWriteMode GetDepthWriteMode() const;
180
181   /**
182    * Sets the depth write mode
183    * @param[in] depthWriteMode The depth write mode
184    */
185   void SetDepthWriteMode( Dali::Renderer::DepthWriteMode depthWriteMode );
186
187   /**
188    * Called to render during RenderManager::Render().
189    * @param[in] context The context used for rendering
190    * @param[in] textureCache The texture cache used to get textures
191    * @param[in] bufferIndex The index of the previous update buffer.
192    * @param[in] node The node using this renderer
193    * @param[in] defaultShader in case there is no custom shader
194    * @param[in] modelViewMatrix The model-view matrix.
195    * @param[in] viewMatrix The view matrix.
196    * @param[in] projectionMatrix The projection matrix.
197    */
198   void Render( Context& context,
199                SceneGraph::TextureCache& textureCache,
200                BufferIndex bufferIndex,
201                const SceneGraph::NodeDataProvider& node,
202                SceneGraph::Shader& defaultShader,
203                const Matrix& modelViewMatrix,
204                const Matrix& viewMatrix,
205                const Matrix& projectionMatrix,
206                const Vector3& size,
207                bool blend);
208
209   /**
210    * Write the renderer's sort attributes to the passed in reference
211    *
212    * @param[in] bufferIndex The current update buffer index.
213    * @param[out] sortAttributes
214    */
215   void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
216
217 private:
218
219   struct UniformIndexMap;
220
221   // Undefined
222   Renderer( const Renderer& );
223
224   // Undefined
225   Renderer& operator=( const Renderer& rhs );
226
227   /**
228    * Sets blending options
229    * @param context to use
230    * @param blend Wheter blending should be enabled or not
231    */
232   void SetBlending( Context& context, bool blend );
233
234   /**
235    * Set the uniforms from properties according to the uniform map
236    * @param[in] bufferIndex The index of the previous update buffer.
237    * @param[in] node The node using the renderer
238    * @param[in] size The size of the renderer
239    * @param[in] program The shader program on which to set the uniforms.
240    */
241   void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program );
242
243   /**
244    * Set the program uniform in the map from the mapped property
245    * @param[in] bufferIndex The index of the previous update buffer.
246    * @param[in] program The shader program
247    * @param[in] map The uniform
248    */
249   void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
250
251   /**
252    * Bind the textures and setup the samplers
253    * @param[in] textureCache The texture cache
254    * @param[in] program The shader program
255    * @return False if create or bind failed, true if success.
256    */
257   bool BindTextures( SceneGraph::TextureCache& textureCache, Program& program );
258
259 private:
260
261   OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
262
263   Context* mContext;
264   SceneGraph::TextureCache* mTextureCache;
265   Render::UniformNameCache* mUniformNameCache;
266   Render::Geometry* mGeometry;
267
268   struct UniformIndexMap
269   {
270     unsigned int uniformIndex; // The index of the cached location in the Program
271     const PropertyInputImpl* propertyValue;
272   };
273
274   typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
275   UniformIndexMappings mUniformIndexMap;
276
277   Vector<GLint> mAttributesLocation;
278
279   BlendingOptions                 mBlendingOptions; /// Blending options including blend color, blend func and blend equation
280   Dali::Renderer::FaceCullingMode mFaceCullingMode; /// Mode of face culling
281   Dali::Renderer::DepthWriteMode  mDepthWriteMode;  /// Depth write mode
282
283   size_t mIndexedDrawFirstElement;                  /// Offset of first element to draw
284   size_t mIndexedDrawElementsCount;                 /// Number of elements to draw
285
286   bool mUpdateAttributesLocation:1;                 ///< Indicates attribute locations have changed
287   bool mPremultipledAlphaEnabled:1;                 ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
288 };
289
290 } // namespace SceneGraph
291
292 } // namespace Internal
293
294 } // namespace Dali
295
296 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__