Changed RendererAttachment to use blend flag from RenderDataProvider rather than...
[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 the face-culling mode.
77    * @param[in] mode The face-culling mode.
78    */
79   void SetCullFace( CullFaceMode mode );
80
81   /**
82    * Set the sampler used to render the set texture.
83    * @param[in] samplerBitfield The packed sampler options used to render.
84    */
85   void SetSampler( unsigned int samplerBitfield );
86
87   /**
88    * Query whether the derived type of Renderer requires depth testing.
89    * @return True if the renderer requires depth testing.
90    */
91   virtual bool RequiresDepthTest() const = 0;
92
93   /**
94    * Called to render during RenderManager::Render().
95    * @param[in] context The context used for rendering
96    * @param[in] textureCache The texture cache used to get textures
97    * @param[in] bufferIndex The index of the previous update buffer.
98    * @param[in] defaultShader in case there is no custom shader
99    * @param[in] modelViewMatrix The model-view matrix.
100    * @param[in] viewMatrix The view matrix.
101    * @param[in] projectionMatrix The projection matrix.
102    * @param[in] frametime The elapsed time between the last two updates.
103    * @param[in] cull Whether to frustum cull this renderer
104    */
105   void Render( Context& context,
106                TextureCache& textureCache,
107                BufferIndex bufferIndex,
108                Shader& defaultShader,
109                const Matrix& modelViewMatrix,
110                const Matrix& viewMatrix,
111                const Matrix& projectionMatrix,
112                float frametime,
113                bool cull );
114
115 protected:
116   /**
117    * Protected constructor; only derived classes can be instantiated.
118    * @param dataprovider for rendering
119    */
120   Renderer( NodeDataProvider& dataprovider );
121
122 private:
123
124   // Undefined
125   Renderer( const Renderer& );
126
127   // Undefined
128   Renderer& operator=( const Renderer& rhs );
129
130   /**
131    * Checks if renderer's resources are ready to be used.
132    *
133    * @return \e true if they are. Otherwise \e false.
134    */
135   virtual bool CheckResources() = 0;
136
137   /**
138    * Checks if renderer is culled.
139    * @param[in] modelMatrix The model matrix.
140    * @param[in] modelViewProjectionMatrix The MVP matrix.
141    * @return \e true if it is. Otherwise \e false.
142    */
143   virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
144
145   /**
146    * Called from Render prior to DoRender().
147    * @todo MESH_REWORK Remove after merge
148    */
149   virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program );
150
151   /**
152    * Called from Render prior to DoRender(). Default method to set CullFaceMode
153    * @todo MESH_REWORK Remove after merge
154    */
155   virtual void DoSetCullFaceMode( Context& context, BufferIndex bufferIndex );
156
157   /**
158    * Called from Render prior to DoRender(). Default method to set blending options
159    * @todo MESH_REWORK Remove after merge
160    */
161   virtual void DoSetBlending( Context& context, BufferIndex bufferIndex ) = 0;
162
163   /**
164    * Called from Render; implemented in derived classes.
165    * @param[in] context The context used for rendering
166    * @param[in] textureCache The texture cache used to get textures
167    * @param[in] bufferIndex The index of the previous update buffer.
168    * @param[in] program to use.
169    * @param[in] modelViewMatrix The model-view matrix.
170    * @param[in] viewMatrix The view matrix.
171    */
172   virtual void DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
173
174 protected:
175
176   NodeDataProvider& mDataProvider;        // @todo MESH_REWORK rename to mNodeDataProvider. Shouldn't it be const?
177
178   Context* mContextDELETEME; // TODO: MESH_REWORK DELETE THIS
179   TextureCache* mTextureCacheDELETEME; // TODO: MESH_REWORK DELETE THIS
180   Shader* mShader;
181   unsigned int mSamplerBitfield;          ///< Sampler options used for texture filtering
182
183 private:
184
185   CullFaceMode mCullFaceMode:3;     ///< cullface enum, 3 bits is enough
186 };
187
188 } // namespace SceneGraph
189
190 } // namespace Internal
191
192 } // namespace Dali
193
194 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__