Friendly janitor cleaning up unnecessary header dependencies
[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/render/renderers/scene-graph-renderer-declarations.h>
28 #include <dali/integration-api/debug.h>
29 #include <dali/internal/common/type-abstraction-enums.h>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36 class Context;
37 class Texture;
38 class Program;
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    * 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] bufferIndex The index of the previous update buffer.
114    * @param[in] defaultShader in case there is no custom shader
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                Shader& defaultShader,
123                const Matrix& modelViewMatrix,
124                const Matrix& viewMatrix,
125                const Matrix& projectionMatrix,
126                float frametime,
127                bool cull );
128
129 protected:
130
131   /**
132    * Protected constructor; only derived classes can be instantiated.
133    * @param dataprovider for rendering
134    */
135   Renderer( RenderDataProvider& dataprovider );
136
137 private:
138
139   // Undefined
140   Renderer( const Renderer& );
141
142   // Undefined
143   Renderer& operator=( const Renderer& rhs );
144
145   /**
146    * Checks if renderer's resources are ready to be used.
147    *
148    * @return \e true if they are. Otherwise \e false.
149    */
150   virtual bool CheckResources() = 0;
151
152   /**
153    * Resolve the derived renderers geometry type and subtype
154    * @param[in] bufferIndex The index of the previous update buffer.
155    * @param[out] outType    The geometry type
156    * @param[out] outSubType The geometry subtype
157    */
158   virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType ) = 0;
159
160   /**
161    * Checks if renderer is culled.
162    * @param[in] modelMatrix The model matrix.
163    * @param[in] modelViewProjectionMatrix The MVP matrix.
164    * @return \e true if it is. Otherwise \e false.
165    */
166   virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
167
168   /**
169    * Called from Render; implemented in derived classes.
170    * @param[in] bufferIndex The index of the previous update buffer.
171    * @param[in] program to use.
172    * @param[in] modelViewMatrix The model-view matrix.
173    * @param[in] viewMatrix The view matrix.
174    */
175   virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
176
177 protected:
178
179   RenderDataProvider& mDataProvider;
180   Context* mContext;
181   TextureCache* mTextureCache;
182   Shader* mShader;
183   unsigned int mSamplerBitfield;          ///< Sampler options used for texture filtering
184
185 private:
186
187   BlendingOptions mBlendingOptions;
188   bool mUseBlend:1;                 ///< True if blending should be enabled, 1 bit is enough
189   CullFaceMode mCullFaceMode:3;     ///< cullface enum, 3 bits is enough
190 };
191
192 } // namespace SceneGraph
193
194 } // namespace Internal
195
196 } // namespace Dali
197
198 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__