[dali_1.0.1] Merge branch '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    * Query whether the derived type of Renderer requires depth testing.
102    * @return True if the renderer requires depth testing.
103    */
104   virtual bool RequiresDepthTest() const = 0;
105
106   /**
107    * Called to render during RenderManager::Render().
108    * @param[in] bufferIndex The index of the previous update buffer.
109    * @param[in] modelViewMatrix The model-view matrix.
110    * @param[in] viewMatrix The view matrix.
111    * @param[in] projectionMatrix The projection matrix.
112    * @param[in] frametime The elapsed time between the last two updates.
113    * @param[in] cull Whether to frustum cull this renderer
114    */
115   void Render( BufferIndex bufferIndex,
116                const Matrix& modelViewMatrix,
117                const Matrix& viewMatrix,
118                const Matrix& projectionMatrix,
119                float frametime,
120                bool cull );
121
122 protected:
123
124   /**
125    * Protected constructor; only derived classes can be instantiated.
126    * @param dataprovider for rendering
127    */
128   Renderer( RenderDataProvider& dataprovider );
129
130 private:
131
132   // Undefined
133   Renderer( const Renderer& );
134
135   // Undefined
136   Renderer& operator=( const Renderer& rhs );
137
138   /**
139    * Checks if renderer's resources are ready to be used.
140    *
141    * @return \e true if they are. Otherwise \e false.
142    */
143   virtual bool CheckResources() = 0;
144
145   /**
146    * Resolve the derived renderers geometry type and subtype
147    * @param[in] bufferIndex The index of the previous update buffer.
148    * @param[out] outType    The geometry type
149    * @param[out] outSubType The geometry subtype
150    */
151   virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType ) = 0;
152
153   /**
154    * Checks if renderer's is culled.
155    * @param[in] modelMatrix The model matrix.
156    * @param[in] modelViewProjectionMatrix The MVP matrix.
157    * @return \e true if it is. Otherwise \e false.
158    */
159   virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
160
161   /**
162    * Called from Render; implemented in derived classes.
163    * @param[in] bufferIndex The index of the previous update buffer.
164    * @param[in] program to use.
165    * @param[in] modelViewMatrix The model-view matrix.
166    * @param[in] viewMatrix The view matrix.
167    */
168   virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
169
170 protected:
171
172   RenderDataProvider& mDataProvider;
173   Context* mContext;
174   TextureCache* mTextureCache;
175   Shader* mShader;
176
177 private:
178
179   BlendingOptions mBlendingOptions;
180   bool mUseBlend:1;                 ///< True if blending should be enabled, 1 bit is enough
181   CullFaceMode mCullFaceMode:3;     ///< cullface enum, 3 bits is enough
182
183 };
184
185 } // namespace SceneGraph
186
187 } // namespace Internal
188
189 } // namespace Dali
190
191 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__