Change Epsilon 0 and 1 to use the compiler provided values
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / scene-graph-renderer.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__
3
4 /*
5  * Copyright (c) 2014 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/internal/common/blending-options.h>
25 #include <dali/internal/common/message.h>
26 #include <dali/internal/event/effects/shader-declarations.h>
27 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
28 #include <dali/internal/render/renderers/scene-graph-renderer-declarations.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/internal/common/type-abstraction-enums.h>
31
32 namespace Dali
33 {
34
35 namespace Internal
36 {
37 class Context;
38 class Texture;
39 class Program;
40
41 namespace SceneGraph
42 {
43 class SceneController;
44 class Shader;
45 class TextureCache;
46 class NodeDataProvider;
47
48 /**
49  * Renderers are used to render images, text, & meshes etc.
50  * These objects are used during RenderManager::Render(), so properties modified during
51  * the Update must either be double-buffered, or set via a message added to the RenderQueue.
52  */
53 class Renderer : public GlResourceOwner
54 {
55 public:
56
57   /**
58    * Second-phase construction.
59    * This is called when the renderer is inside render thread
60    * @param[in] textureCache to use
61    */
62   void Initialize( Context& context, TextureCache& textureCache );
63
64   /**
65    * Virtual destructor
66    */
67   virtual ~Renderer();
68
69   /**
70    * Set the Shader used to render.
71    * @param[in] shader The shader used to render.
72    */
73   void SetShader( Shader* shader );
74
75   /**
76    * Set whether the ImageRenderer should use blending
77    * @param[in] useBlend True if blending should be used.
78    */
79   void SetUseBlend( bool useBlend );
80
81   /**
82    * Set the blending options.
83    * @param[in] options A bitmask of blending options.
84    */
85   void SetBlendingOptions( unsigned int options );
86
87   /**
88    * Set the blend color.
89    * @param[in] color The new blend-color.
90    */
91   void SetBlendColor( const Vector4& color );
92
93   /**
94    * Set the face-culling mode.
95    * @param[in] mode The face-culling mode.
96    */
97   void SetCullFace( CullFaceMode mode );
98
99   /**
100    * Set the sampler used to render the set texture.
101    * @param[in] samplerBitfield The packed sampler options used to render.
102    */
103   void SetSampler( unsigned int samplerBitfield );
104
105   /**
106    * Query whether the derived type of Renderer requires depth testing.
107    * @return True if the renderer requires depth testing.
108    */
109   virtual bool RequiresDepthTest() const = 0;
110
111   /**
112    * Called to render during RenderManager::Render().
113    * @param[in] context The context used for rendering
114    * @param[in] textureCache The texture cache used to get textures
115    * @param[in] bufferIndex The index of the previous update buffer.
116    * @param[in] defaultShader in case there is no custom shader
117    * @param[in] modelViewMatrix The model-view matrix.
118    * @param[in] viewMatrix The view matrix.
119    * @param[in] projectionMatrix The projection matrix.
120    * @param[in] frametime The elapsed time between the last two updates.
121    * @param[in] cull Whether to frustum cull this renderer
122    */
123   void Render( Context& context,
124                TextureCache& textureCache,
125                BufferIndex bufferIndex,
126                Shader& defaultShader,
127                const Matrix& modelViewMatrix,
128                const Matrix& viewMatrix,
129                const Matrix& projectionMatrix,
130                float frametime,
131                bool cull );
132
133 protected:
134   /**
135    * Protected constructor; only derived classes can be instantiated.
136    * @param dataprovider for rendering
137    */
138   Renderer( NodeDataProvider& dataprovider );
139
140 private:
141
142   // Undefined
143   Renderer( const Renderer& );
144
145   // Undefined
146   Renderer& operator=( const Renderer& rhs );
147
148   /**
149    * Checks if renderer's resources are ready to be used.
150    *
151    * @return \e true if they are. Otherwise \e false.
152    */
153   virtual bool CheckResources() = 0;
154
155   /**
156    * Checks if renderer is culled.
157    * @param[in] modelMatrix The model matrix.
158    * @param[in] modelViewProjectionMatrix The MVP matrix.
159    * @return \e true if it is. Otherwise \e false.
160    */
161   virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
162
163   /**
164    * Called from Render prior to DoRender().
165    * @todo MESH_REWORK Remove after merge
166    */
167   virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program );
168
169   /**
170    * Called from Render prior to DoRender(). Default method to set CullFaceMode
171    * @todo MESH_REWORK Remove after merge
172    */
173   virtual void DoSetCullFaceMode( Context& context, BufferIndex bufferIndex );
174
175   /**
176    * Called from Render prior to DoRender(). Default method to set blending options
177    * @todo MESH_REWORK Remove after merge
178    */
179   virtual void DoSetBlending( Context& context, BufferIndex bufferIndex );
180
181   /**
182    * Called from Render; implemented in derived classes.
183    * @param[in] context The context used for rendering
184    * @param[in] textureCache The texture cache used to get textures
185    * @param[in] bufferIndex The index of the previous update buffer.
186    * @param[in] program to use.
187    * @param[in] modelViewMatrix The model-view matrix.
188    * @param[in] viewMatrix The view matrix.
189    */
190   virtual void DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
191
192 protected:
193
194   NodeDataProvider& mDataProvider;        // @todo MESH_REWORK rename to mNodeDataProvider. Shouldn't it be const?
195
196   Context* mContextDELETEME; // TODO: MESH_REWORK DELETE THIS
197   TextureCache* mTextureCacheDELETEME; // TODO: MESH_REWORK DELETE THIS
198   Shader* mShader;
199   unsigned int mSamplerBitfield;          ///< Sampler options used for texture filtering
200
201   bool mUseBlend:1;                 ///< True if blending should be enabled, 1 bit is enough
202 private:
203
204   BlendingOptions mBlendingOptions;
205   CullFaceMode mCullFaceMode:3;     ///< cullface enum, 3 bits is enough
206 };
207
208 } // namespace SceneGraph
209
210 } // namespace Internal
211
212 } // namespace Dali
213
214 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__