[dali_1.1.11] 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/devel-api/rendering/material.h>
25 #include <dali/internal/common/blending-options.h>
26 #include <dali/internal/common/message.h>
27 #include <dali/internal/event/effects/shader-declarations.h>
28 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/internal/common/type-abstraction-enums.h>
31 #include <dali/internal/update/manager/prepare-render-instructions.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38 class Context;
39 class Texture;
40 class Program;
41
42 namespace SceneGraph
43 {
44 class SceneController;
45 class Shader;
46 class TextureCache;
47 class NodeDataProvider;
48 }
49
50
51 namespace Render
52 {
53 class UniformNameCache;
54 class NewRenderer;
55
56 /**
57  * Renderers are used to render meshes
58  * These objects are used during RenderManager::Render(), so properties modified during
59  * the Update must either be double-buffered, or set via a message added to the RenderQueue.
60  */
61 class Renderer : public GlResourceOwner
62 {
63 public:
64
65   /**
66    * Second-phase construction.
67    * This is called when the renderer is inside render thread
68    * @param[in] context to use
69    * @param[in] textureCache to use
70    * @param[in] uniformNameCache to use
71    */
72   void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
73
74   /**
75    * Virtual destructor
76    */
77   virtual ~Renderer();
78
79   /**
80    * Set the Shader used to render.
81    * @param[in] shader The shader used to render.
82    */
83   void SetShader( SceneGraph::Shader* shader );
84
85   /**
86    * Set the face-culling mode.
87    * @param[in] mode The face-culling mode.
88    */
89   void SetCullFace( Dali::Material::FaceCullingMode mode );
90
91   /**
92    * Set the sampler used to render the set texture.
93    * @param[in] samplerBitfield The packed sampler options used to render.
94    */
95   void SetSampler( unsigned int samplerBitfield );
96
97   /**
98    * Query whether the derived type of Renderer requires depth testing.
99    * @return True if the renderer requires depth testing.
100    */
101   virtual bool RequiresDepthTest() const = 0;
102
103   /**
104    * Called to render during RenderManager::Render().
105    * @param[in] context The context used for rendering
106    * @param[in] textureCache The texture cache used to get textures
107    * @param[in] bufferIndex The index of the previous update buffer.
108    * @param[in] node The node using this renderer
109    * @param[in] defaultShader in case there is no custom shader
110    * @param[in] modelViewMatrix The model-view matrix.
111    * @param[in] viewMatrix The view matrix.
112    * @param[in] projectionMatrix The projection matrix.
113    * @param[in] cull Whether to frustum cull this renderer
114    */
115   void Render( Context& context,
116                SceneGraph::TextureCache& textureCache,
117                BufferIndex bufferIndex,
118                const SceneGraph::NodeDataProvider& node,
119                SceneGraph::Shader& defaultShader,
120                const Matrix& modelViewMatrix,
121                const Matrix& viewMatrix,
122                const Matrix& projectionMatrix,
123                bool cull,
124                bool blend);
125
126   /**
127    * Write the renderer's sort attributes to the passed in reference
128    *
129    * @param[in] bufferIndex The current update buffer index.
130    * @param[out] sortAttributes
131    */
132   virtual void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
133
134 protected:
135   /**
136    * Protected constructor; only derived classes can be instantiated.
137    * @param dataprovider for rendering
138    */
139   Renderer();
140
141 private:
142
143   // Undefined
144   Renderer( const Renderer& );
145
146   // Undefined
147   Renderer& operator=( const Renderer& rhs );
148
149   /**
150    * @return NewRenderer or NULL if this is an old renderer
151    */
152   virtual NewRenderer* GetNewRenderer()
153   {
154     return NULL;
155   }
156
157   /**
158    * Checks if renderer's resources are ready to be used.
159    *
160    * @return \e true if they are. Otherwise \e false.
161    */
162   virtual bool CheckResources() = 0;
163
164   /**
165    * Called from Render prior to DoRender().
166    * @todo MESH_REWORK Remove after merge
167    */
168   virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program );
169
170   /**
171    * Called from Render prior to DoRender(). Default method to set CullFaceMode
172    * @param context to use
173    */
174   virtual void DoSetCullFaceMode( Context& context );
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   Dali::Material::FaceCullingMode 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__