Changed SceneGraph::CompareItems and CompareItems3D to compare the render items based...
[platform/core/uifw/dali-core.git] / dali / internal / render / renderers / render-renderer.h
1 #ifndef __DALI_INTERNAL_RENDER_RENDERER_H__
2 #define __DALI_INTERNAL_RENDER_RENDERER_H__
3
4 /*
5  * Copyright (c) 2015 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/integration-api/debug.h>
29 #include <dali/internal/common/type-abstraction-enums.h>
30 #include <dali/internal/update/manager/prepare-render-instructions.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
50 namespace Render
51 {
52
53
54 /**
55  * Renderers are used to render meshes
56  * These objects are used during RenderManager::Render(), so properties modified during
57  * the Update must either be double-buffered, or set via a message added to the RenderQueue.
58  */
59 class Renderer : public GlResourceOwner
60 {
61 public:
62
63   /**
64    * Second-phase construction.
65    * This is called when the renderer is inside render thread
66    * @param[in] textureCache to use
67    */
68   void Initialize( Context& context, SceneGraph::TextureCache& textureCache );
69
70   /**
71    * Virtual destructor
72    */
73   virtual ~Renderer();
74
75   /**
76    * Set the Shader used to render.
77    * @param[in] shader The shader used to render.
78    */
79   void SetShader( SceneGraph::Shader* shader );
80
81   /**
82    * Set the face-culling mode.
83    * @param[in] mode The face-culling mode.
84    */
85   void SetCullFace( CullFaceMode mode );
86
87   /**
88    * Set the sampler used to render the set texture.
89    * @param[in] samplerBitfield The packed sampler options used to render.
90    */
91   void SetSampler( unsigned int samplerBitfield );
92
93   /**
94    * Query whether the derived type of Renderer requires depth testing.
95    * @return True if the renderer requires depth testing.
96    */
97   virtual bool RequiresDepthTest() const = 0;
98
99   /**
100    * Called to render during RenderManager::Render().
101    * @param[in] context The context used for rendering
102    * @param[in] textureCache The texture cache used to get textures
103    * @param[in] bufferIndex The index of the previous update buffer.
104    * @param[in] node The node using this renderer
105    * @param[in] defaultShader in case there is no custom shader
106    * @param[in] modelViewMatrix The model-view matrix.
107    * @param[in] viewMatrix The view matrix.
108    * @param[in] projectionMatrix The projection matrix.
109    * @param[in] frametime The elapsed time between the last two updates.
110    * @param[in] cull Whether to frustum cull this renderer
111    */
112   void Render( Context& context,
113                SceneGraph::TextureCache& textureCache,
114                BufferIndex bufferIndex,
115                const SceneGraph::NodeDataProvider& node,
116                SceneGraph::Shader& defaultShader,
117                const Matrix& modelViewMatrix,
118                const Matrix& viewMatrix,
119                const Matrix& projectionMatrix,
120                float frametime,
121                bool cull,
122                bool blend);
123
124   /**
125    * Write the renderer's sort attributes to the passed in reference
126    *
127    * @param[in] bufferIndex The current update buffer index.
128    * @param[out] sortAttributes
129    */
130   virtual void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
131
132 protected:
133   /**
134    * Protected constructor; only derived classes can be instantiated.
135    * @param dataprovider for rendering
136    */
137   Renderer();
138
139 private:
140
141   // Undefined
142   Renderer( const Renderer& );
143
144   // Undefined
145   Renderer& operator=( const Renderer& rhs );
146
147   /**
148    * Checks if renderer's resources are ready to be used.
149    *
150    * @return \e true if they are. Otherwise \e false.
151    */
152   virtual bool CheckResources() = 0;
153
154   /**
155    * Checks if renderer is culled.
156    * @param[in] modelViewProjectionMatrix The MVP matrix.
157    * @return \e true if it is. Otherwise \e false.
158    */
159   virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelViewProjectionMatrix ) = 0;
160
161   /**
162    * Called from Render prior to DoRender().
163    * @todo MESH_REWORK Remove after merge
164    */
165   virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program );
166
167   /**
168    * Called from Render prior to DoRender(). Default method to set CullFaceMode
169    * @todo MESH_REWORK Remove after merge
170    */
171   virtual void DoSetCullFaceMode( Context& context, BufferIndex bufferIndex );
172
173   /**
174    * Called from Render prior to DoRender(). Default method to set blending options
175    * @todo MESH_REWORK Remove after merge
176    */
177   virtual void DoSetBlending( Context& context, BufferIndex bufferIndex, bool blend ) = 0;
178
179   /**
180    * Called from Render; implemented in derived classes.
181    * @param[in] context The context used for rendering
182    * @param[in] textureCache The texture cache used to get textures
183    * @param[in] bufferIndex The index of the previous update buffer.
184    * @param[in] program to use.
185    * @param[in] modelViewMatrix The model-view matrix.
186    * @param[in] viewMatrix The view matrix.
187    */
188   virtual void DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
189
190 protected:
191
192   Context* mContext;
193   SceneGraph::TextureCache* mTextureCache;
194   SceneGraph::Shader* mShader;
195   unsigned int mSamplerBitfield;          ///< Sampler options used for texture filtering
196
197 private:
198
199   CullFaceMode mCullFaceMode:3;     ///< cullface enum, 3 bits is enough
200 };
201
202 } // namespace SceneGraph
203
204 } // namespace Internal
205
206 } // namespace Dali
207
208 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__