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>
32 #include <dali/internal/render/renderers/render-geometry.h>
45 class SceneController;
48 class NodeDataProvider;
54 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 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
68 void GlContextDestroyed();
71 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
76 * Create a new renderer instance
77 * @param[in] dataProviders The data providers for the renderer
78 * @param[in] renderGeometry The geometry for the renderer
80 static Renderer* New( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
84 * @param[in] dataProviders The data providers for the renderer
85 * @param[in] renderGeometry The geometry for the renderer
87 Renderer( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
90 * Change the data providers of the renderer
91 * @param[in] dataProviders The data providers
93 void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
96 * Change the geometry used by the renderer
97 * @param[in] renderGeometry The new geometry
99 void SetGeometry( SceneGraph::RenderGeometry* renderGeometry );
101 * Second-phase construction.
102 * This is called when the renderer is inside render thread
103 * @param[in] context to use
104 * @param[in] textureCache to use
105 * @param[in] uniformNameCache to use
107 void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
115 * Set the face-culling mode.
116 * @param[in] mode The face-culling mode.
118 void SetCullFace( Dali::Material::FaceCullingMode mode );
121 * Set the sampler used to render the set texture.
122 * @param[in] samplerBitfield The packed sampler options used to render.
124 void SetSampler( unsigned int samplerBitfield );
127 * Query whether the derived type of Renderer requires depth testing.
128 * @return True if the renderer requires depth testing.
130 bool RequiresDepthTest() const;
133 * Called to render during RenderManager::Render().
134 * @param[in] context The context used for rendering
135 * @param[in] textureCache The texture cache used to get textures
136 * @param[in] bufferIndex The index of the previous update buffer.
137 * @param[in] node The node using this renderer
138 * @param[in] defaultShader in case there is no custom shader
139 * @param[in] modelViewMatrix The model-view matrix.
140 * @param[in] viewMatrix The view matrix.
141 * @param[in] projectionMatrix The projection matrix.
142 * @param[in] cull Whether to frustum cull this renderer
144 void Render( Context& context,
145 SceneGraph::TextureCache& textureCache,
146 BufferIndex bufferIndex,
147 const SceneGraph::NodeDataProvider& node,
148 SceneGraph::Shader& defaultShader,
149 const Matrix& modelViewMatrix,
150 const Matrix& viewMatrix,
151 const Matrix& projectionMatrix,
156 * Write the renderer's sort attributes to the passed in reference
158 * @param[in] bufferIndex The current update buffer index.
159 * @param[out] sortAttributes
161 void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
165 struct UniformIndexMap;
168 Renderer( const Renderer& );
171 Renderer& operator=( const Renderer& rhs );
174 * Sets blending options
175 * @param context to use
176 * @param blend Wheter blending should be enabled or not
178 void SetBlending( Context& context, bool blend );
181 * Set the uniforms from properties according to the uniform map
182 * @param[in] node The node using the renderer
183 * @param[in] program The shader program on which to set the uniforms.
185 void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program );
188 * Set the program uniform in the map from the mapped property
190 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
193 * Bind the material textures in the samplers and setup the samplers
194 * @param[in] textureCache The texture cache
195 * @param[in] program The shader program
197 void BindTextures( SceneGraph::TextureCache& textureCache, Program& program );
201 OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
206 SceneGraph::TextureCache* mTextureCache;
207 Render::UniformNameCache* mUniformNameCache;
208 SceneGraph::RenderGeometry* mRenderGeometry;
210 struct UniformIndexMap
212 unsigned int uniformIndex; // The index of the cached location in the Program
213 const PropertyInputImpl* propertyValue;
216 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
217 UniformIndexMappings mUniformIndexMap;
219 Vector<GLint> mAttributesLocation;
221 unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
222 bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed
223 Dali::Material::FaceCullingMode mCullFaceMode:2; ///< cullface enum, 3 bits is enough
226 } // namespace SceneGraph
228 } // namespace Internal
232 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__