1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__
5 * Copyright (c) 2014 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/render/gl-resources/gl-resource-owner.h>
27 #include <dali/internal/update/common/double-buffered.h>
28 #include <dali/internal/render/renderers/scene-graph-renderer-declarations.h>
29 #include <dali/integration-api/debug.h>
30 #include <dali/internal/common/type-abstraction-enums.h>
43 class SceneController;
46 class RenderDataProvider;
49 * Renderers are used to render images, text, & meshes etc.
50 * These objects are used during RenderManager::Render(), so properties modified during
51 * the Update must either be double-buffered, or set via a message added to the RenderQueue.
53 class Renderer : public GlResourceOwner
58 * Second-phase construction.
59 * This is called when the renderer is inside render thread
60 * @param[in] context to use
61 * @param[in] textureCache to use
63 void Initialize( Context& context, TextureCache& textureCache );
71 * Set the Shader used to render.
72 * @param[in] shader The shader used to render.
74 void SetShader( Shader* shader );
77 * Set whether the ImageRenderer should use blending
78 * @param[in] useBlend True if blending should be used.
80 void SetUseBlend( bool useBlend );
83 * Set the blending options.
84 * @param[in] options A bitmask of blending options.
86 void SetBlendingOptions( unsigned int options );
89 * Set the blend color.
90 * @param[in] color The new blend-color.
92 void SetBlendColor( const Vector4& color );
95 * Set the face-culling mode.
96 * @param[in] mode The face-culling mode.
98 void SetCullFace( CullFaceMode mode );
101 * Set the sampler used to render the set texture.
102 * @param[in] samplerBitfield The packed sampler options used to render.
104 void SetSampler( unsigned int samplerBitfield );
107 * Query whether the derived type of Renderer requires depth testing.
108 * @return True if the renderer requires depth testing.
110 virtual bool RequiresDepthTest() const = 0;
113 * Called to render during RenderManager::Render().
114 * @param[in] bufferIndex The index of the previous update buffer.
115 * @param[in] modelViewMatrix The model-view matrix.
116 * @param[in] viewMatrix The view matrix.
117 * @param[in] projectionMatrix The projection matrix.
118 * @param[in] frametime The elapsed time between the last two updates.
119 * @param[in] cull Whether to frustum cull this renderer
121 void Render( BufferIndex bufferIndex,
122 const Matrix& modelViewMatrix,
123 const Matrix& viewMatrix,
124 const Matrix& projectionMatrix,
131 * Protected constructor; only derived classes can be instantiated.
132 * @param dataprovider for rendering
134 Renderer( RenderDataProvider& dataprovider );
139 Renderer( const Renderer& );
142 Renderer& operator=( const Renderer& rhs );
145 * Checks if renderer's resources are ready to be used.
147 * @return \e true if they are. Otherwise \e false.
149 virtual bool CheckResources() = 0;
152 * Resolve the derived renderers geometry type and subtype
153 * @param[in] bufferIndex The index of the previous update buffer.
154 * @param[out] outType The geometry type
155 * @param[out] outSubType The geometry subtype
157 virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType ) = 0;
160 * Checks if renderer is culled.
161 * @param[in] modelMatrix The model matrix.
162 * @param[in] modelViewProjectionMatrix The MVP matrix.
163 * @return \e true if it is. Otherwise \e false.
165 virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
168 * Called from Render; implemented in derived classes.
169 * @param[in] bufferIndex The index of the previous update buffer.
170 * @param[in] program to use.
171 * @param[in] modelViewMatrix The model-view matrix.
172 * @param[in] viewMatrix The view matrix.
174 virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
178 RenderDataProvider& mDataProvider;
180 TextureCache* mTextureCache;
182 unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
186 BlendingOptions mBlendingOptions;
187 bool mUseBlend:1; ///< True if blending should be enabled, 1 bit is enough
188 CullFaceMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough
191 } // namespace SceneGraph
193 } // namespace Internal
197 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__