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/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>
44 class SceneController;
47 class NodeDataProvider;
53 class UniformNameCache;
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.
61 class Renderer : public GlResourceOwner
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
72 void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
80 * Set the Shader used to render.
81 * @param[in] shader The shader used to render.
83 void SetShader( SceneGraph::Shader* shader );
86 * Set the face-culling mode.
87 * @param[in] mode The face-culling mode.
89 void SetCullFace( Dali::Material::FaceCullingMode mode );
92 * Set the sampler used to render the set texture.
93 * @param[in] samplerBitfield The packed sampler options used to render.
95 void SetSampler( unsigned int samplerBitfield );
98 * Query whether the derived type of Renderer requires depth testing.
99 * @return True if the renderer requires depth testing.
101 virtual bool RequiresDepthTest() const = 0;
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
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,
127 * Write the renderer's sort attributes to the passed in reference
129 * @param[in] bufferIndex The current update buffer index.
130 * @param[out] sortAttributes
132 virtual void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
136 * Protected constructor; only derived classes can be instantiated.
137 * @param dataprovider for rendering
144 Renderer( const Renderer& );
147 Renderer& operator=( const Renderer& rhs );
150 * @return NewRenderer or NULL if this is an old renderer
152 virtual NewRenderer* GetNewRenderer()
158 * Checks if renderer's resources are ready to be used.
160 * @return \e true if they are. Otherwise \e false.
162 virtual bool CheckResources() = 0;
165 * Called from Render prior to DoRender().
166 * @todo MESH_REWORK Remove after merge
168 virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program );
171 * Called from Render prior to DoRender(). Default method to set CullFaceMode
172 * @param context to use
174 virtual void DoSetCullFaceMode( Context& context );
177 * Called from Render prior to DoRender(). Default method to set blending options
178 * @param context to use
180 virtual void DoSetBlending( Context& context ) = 0;
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.
191 virtual void DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
196 SceneGraph::TextureCache* mTextureCache;
197 Render::UniformNameCache* mUniformNameCache;
198 SceneGraph::Shader* mShader;
199 unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
203 Dali::Material::FaceCullingMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough
206 } // namespace SceneGraph
208 } // namespace Internal
212 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__