1 #ifndef __DALI_INTERNAL_RENDER_RENDERER_H__
2 #define __DALI_INTERNAL_RENDER_RENDERER_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
43 class SceneController;
46 class NodeDataProvider;
52 class UniformNameCache;
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.
60 class Renderer : public GlResourceOwner
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
71 void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
79 * Set the Shader used to render.
80 * @param[in] shader The shader used to render.
82 void SetShader( SceneGraph::Shader* shader );
85 * Set the face-culling mode.
86 * @param[in] mode The face-culling mode.
88 void SetCullFace( CullFaceMode mode );
91 * Set the sampler used to render the set texture.
92 * @param[in] samplerBitfield The packed sampler options used to render.
94 void SetSampler( unsigned int samplerBitfield );
97 * Query whether the derived type of Renderer requires depth testing.
98 * @return True if the renderer requires depth testing.
100 virtual bool RequiresDepthTest() const = 0;
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
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,
126 * Write the renderer's sort attributes to the passed in reference
128 * @param[in] bufferIndex The current update buffer index.
129 * @param[out] sortAttributes
131 virtual void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
135 * Protected constructor; only derived classes can be instantiated.
136 * @param dataprovider for rendering
143 Renderer( const Renderer& );
146 Renderer& operator=( const Renderer& rhs );
149 * @return NewRenderer or NULL if this is an old renderer
151 virtual NewRenderer* GetNewRenderer()
157 * Checks if renderer's resources are ready to be used.
159 * @return \e true if they are. Otherwise \e false.
161 virtual bool CheckResources() = 0;
164 * Called from Render prior to DoRender().
165 * @todo MESH_REWORK Remove after merge
167 virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program );
170 * Called from Render prior to DoRender(). Default method to set CullFaceMode
171 * @todo MESH_REWORK Remove after merge
173 virtual void DoSetCullFaceMode( Context& context, BufferIndex bufferIndex );
176 * Called from Render prior to DoRender(). Default method to set blending options
177 * @todo MESH_REWORK Remove after merge
179 virtual void DoSetBlending( Context& context, BufferIndex bufferIndex, bool blend ) = 0;
182 * Called from Render; implemented in derived classes.
183 * @param[in] context The context used for rendering
184 * @param[in] textureCache The texture cache used to get textures
185 * @param[in] bufferIndex The index of the previous update buffer.
186 * @param[in] program to use.
187 * @param[in] modelViewMatrix The model-view matrix.
188 * @param[in] viewMatrix The view matrix.
190 virtual void DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
195 SceneGraph::TextureCache* mTextureCache;
196 Render::UniformNameCache* mUniformNameCache;
197 SceneGraph::Shader* mShader;
198 unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
202 CullFaceMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough
205 } // namespace SceneGraph
207 } // namespace Internal
211 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__