Merge "Add some constants that show the version of the library" into tizen
[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/render/gl-resources/gl-resource-owner.h>
27 #include <dali/internal/update/common/double-buffered.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 RenderDataProvider;
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] context to use
61    * @param[in] textureCache to use
62    */
63   void Initialize( Context& context, TextureCache& textureCache );
64
65   /**
66    * Virtual destructor
67    */
68   virtual ~Renderer();
69
70   /**
71    * Set the Shader used to render.
72    * @param[in] shader The shader used to render.
73    */
74   void SetShader( Shader* shader );
75
76   /**
77    * Set whether the ImageRenderer should use blending
78    * @param[in] useBlend True if blending should be used.
79    */
80   void SetUseBlend( bool useBlend );
81
82   /**
83    * Set the blending options.
84    * @param[in] options A bitmask of blending options.
85    */
86   void SetBlendingOptions( unsigned int options );
87
88   /**
89    * Set the blend color.
90    * @param[in] color The new blend-color.
91    */
92   void SetBlendColor( const Vector4& color );
93
94   /**
95    * Set the face-culling mode.
96    * @param[in] mode The face-culling mode.
97    */
98   void SetCullFace( CullFaceMode mode );
99
100   /**
101    * Set the sampler used to render the set texture.
102    * @param[in] samplerBitfield The packed sampler options used to render.
103    */
104   void SetSampler( unsigned int samplerBitfield );
105
106   /**
107    * Query whether the derived type of Renderer requires depth testing.
108    * @return True if the renderer requires depth testing.
109    */
110   virtual bool RequiresDepthTest() const = 0;
111
112   /**
113    * Called to render during RenderManager::Render().
114    * @param[in] bufferIndex The index of the previous update buffer.
115    * @param[in] modelViewMatrix The model-view matrix.
116    * @param[in] viewMatrix The view matrix.
117    * @param[in] projectionMatrix The projection matrix.
118    * @param[in] frametime The elapsed time between the last two updates.
119    * @param[in] cull Whether to frustum cull this renderer
120    */
121   void Render( BufferIndex bufferIndex,
122                const Matrix& modelViewMatrix,
123                const Matrix& viewMatrix,
124                const Matrix& projectionMatrix,
125                float frametime,
126                bool cull );
127
128 protected:
129
130   /**
131    * Protected constructor; only derived classes can be instantiated.
132    * @param dataprovider for rendering
133    */
134   Renderer( RenderDataProvider& dataprovider );
135
136 private:
137
138   // Undefined
139   Renderer( const Renderer& );
140
141   // Undefined
142   Renderer& operator=( const Renderer& rhs );
143
144   /**
145    * Checks if renderer's resources are ready to be used.
146    *
147    * @return \e true if they are. Otherwise \e false.
148    */
149   virtual bool CheckResources() = 0;
150
151   /**
152    * Resolve the derived renderers geometry type and subtype
153    * @param[in] bufferIndex The index of the previous update buffer.
154    * @param[out] outType    The geometry type
155    * @param[out] outSubType The geometry subtype
156    */
157   virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType ) = 0;
158
159   /**
160    * Checks if renderer is culled.
161    * @param[in] modelMatrix The model matrix.
162    * @param[in] modelViewProjectionMatrix The MVP matrix.
163    * @return \e true if it is. Otherwise \e false.
164    */
165   virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
166
167   /**
168    * Called from Render; implemented in derived classes.
169    * @param[in] bufferIndex The index of the previous update buffer.
170    * @param[in] program to use.
171    * @param[in] modelViewMatrix The model-view matrix.
172    * @param[in] viewMatrix The view matrix.
173    */
174   virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
175
176 protected:
177
178   RenderDataProvider& mDataProvider;
179   Context* mContext;
180   TextureCache* mTextureCache;
181   Shader* mShader;
182   unsigned int mSamplerBitfield;          ///< Sampler options used for texture filtering
183
184 private:
185
186   BlendingOptions mBlendingOptions;
187   bool mUseBlend:1;                 ///< True if blending should be enabled, 1 bit is enough
188   CullFaceMode mCullFaceMode:3;     ///< cullface enum, 3 bits is enough
189 };
190
191 } // namespace SceneGraph
192
193 } // namespace Internal
194
195 } // namespace Dali
196
197 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__