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;
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.
59 class Renderer : public GlResourceOwner
64 * Second-phase construction.
65 * This is called when the renderer is inside render thread
66 * @param[in] textureCache to use
68 void Initialize( Context& context, SceneGraph::TextureCache& textureCache );
76 * Set the Shader used to render.
77 * @param[in] shader The shader used to render.
79 void SetShader( SceneGraph::Shader* shader );
82 * Set the face-culling mode.
83 * @param[in] mode The face-culling mode.
85 void SetCullFace( CullFaceMode mode );
88 * Set the sampler used to render the set texture.
89 * @param[in] samplerBitfield The packed sampler options used to render.
91 void SetSampler( unsigned int samplerBitfield );
94 * Query whether the derived type of Renderer requires depth testing.
95 * @return True if the renderer requires depth testing.
97 virtual bool RequiresDepthTest() const = 0;
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] cull Whether to frustum cull this renderer
111 void Render( Context& context,
112 SceneGraph::TextureCache& textureCache,
113 BufferIndex bufferIndex,
114 const SceneGraph::NodeDataProvider& node,
115 SceneGraph::Shader& defaultShader,
116 const Matrix& modelViewMatrix,
117 const Matrix& viewMatrix,
118 const Matrix& projectionMatrix,
123 * Write the renderer's sort attributes to the passed in reference
125 * @param[in] bufferIndex The current update buffer index.
126 * @param[out] sortAttributes
128 virtual void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
132 * Protected constructor; only derived classes can be instantiated.
133 * @param dataprovider for rendering
140 Renderer( const Renderer& );
143 Renderer& operator=( const Renderer& rhs );
146 * Checks if renderer's resources are ready to be used.
148 * @return \e true if they are. Otherwise \e false.
150 virtual bool CheckResources() = 0;
153 * Checks if renderer is culled.
154 * @param[in] modelViewProjectionMatrix The MVP matrix.
155 * @return \e true if it is. Otherwise \e false.
157 virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelViewProjectionMatrix ) = 0;
160 * Called from Render prior to DoRender().
161 * @todo MESH_REWORK Remove after merge
163 virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program );
166 * Called from Render prior to DoRender(). Default method to set CullFaceMode
167 * @todo MESH_REWORK Remove after merge
169 virtual void DoSetCullFaceMode( Context& context, BufferIndex bufferIndex );
172 * Called from Render prior to DoRender(). Default method to set blending options
173 * @todo MESH_REWORK Remove after merge
175 virtual void DoSetBlending( Context& context, BufferIndex bufferIndex, bool blend ) = 0;
178 * Called from Render; implemented in derived classes.
179 * @param[in] context The context used for rendering
180 * @param[in] textureCache The texture cache used to get textures
181 * @param[in] bufferIndex The index of the previous update buffer.
182 * @param[in] program to use.
183 * @param[in] modelViewMatrix The model-view matrix.
184 * @param[in] viewMatrix The view matrix.
186 virtual void DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
191 SceneGraph::TextureCache* mTextureCache;
192 SceneGraph::Shader* mShader;
193 unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
197 CullFaceMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough
200 } // namespace SceneGraph
202 } // namespace Internal
206 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__