Conversion to Apache 2.0 license
[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
40 namespace SceneGraph
41 {
42 class SceneController;
43 class Shader;
44 class TextureCache;
45 class RenderDataProvider;
46
47 /**
48  * Renderers are used to render images, text, & meshes etc.
49  * These objects are used during RenderManager::Render(), so properties modified during
50  * the Update must either be double-buffered, or set via a message added to the RenderQueue.
51  */
52 class Renderer : public GlResourceOwner
53 {
54 public:
55
56   /**
57    * Second-phase construction.
58    * This is called when the renderer is inside render thread
59    * @param[in] context to use
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    * Query whether the derived type of Renderer requires depth testing.
101    * @return True if the renderer requires depth testing.
102    */
103   virtual bool RequiresDepthTest() const = 0;
104
105   /**
106    * Called to render during RenderManager::Render().
107    * @param[in] bufferIndex The index of the previous update buffer.
108    * @param[in] modelViewMatrix The model-view matrix.
109    * @param[in] viewMatrix The view matrix.
110    * @param[in] projectionMatrix The projection matrix.
111    * @param[in] frametime The elapsed time between the last two updates.
112    */
113   void Render( BufferIndex bufferIndex,
114                const Matrix& modelViewMatrix,
115                const Matrix& viewMatrix,
116                const Matrix& projectionMatrix,
117                float frametime );
118
119 protected:
120
121   /**
122    * Protected constructor; only derived classes can be instantiated.
123    * @param dataprovider for rendering
124    */
125   Renderer( RenderDataProvider& dataprovider );
126
127 private:
128
129   // Undefined
130   Renderer( const Renderer& );
131
132   // Undefined
133   Renderer& operator=( const Renderer& rhs );
134
135   /**
136    * Checks if renderer's resources are ready to be used.
137    *
138    * @return \e true if they are. Otherwise \e false.
139    */
140   virtual bool CheckResources() = 0;
141
142   /**
143    * Called from Render; implemented in derived classes.
144    * @param[in] bufferIndex The index of the previous update buffer.
145    * @param[in] modelViewMatrix The model-view matrix.
146    * @param[in] modelMatrix The model matrix.
147    * @param[in] viewMatrix The view matrix.
148    * @param[in] projectionMatrix The projection matrix.
149    * @param[in] color to use
150    */
151   virtual void DoRender( BufferIndex bufferIndex, const Matrix& modelViewMatrix, const Matrix& modelMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, const Vector4& color ) = 0;
152
153 protected:
154
155   RenderDataProvider& mDataProvider;
156   Context* mContext;
157   TextureCache* mTextureCache;
158   Shader* mShader;
159
160 private:
161
162   BlendingOptions mBlendingOptions;
163   bool mUseBlend:1;                 ///< True if blending should be enabled, 1 bit is enough
164   CullFaceMode mCullFaceMode:3;     ///< cullface enum, 3 bits is enough
165
166 };
167
168 } // namespace SceneGraph
169
170 } // namespace Internal
171
172 } // namespace Dali
173
174 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__