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