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 * Query whether the derived type of Renderer requires depth testing.
102 * @return True if the renderer requires depth testing.
104 virtual bool RequiresDepthTest() const = 0;
107 * Called to render during RenderManager::Render().
108 * @param[in] bufferIndex The index of the previous update buffer.
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] frametime The elapsed time between the last two updates.
113 * @param[in] cull Whether to frustum cull this renderer
115 void Render( BufferIndex bufferIndex,
116 const Matrix& modelViewMatrix,
117 const Matrix& viewMatrix,
118 const Matrix& projectionMatrix,
125 * Protected constructor; only derived classes can be instantiated.
126 * @param dataprovider for rendering
128 Renderer( RenderDataProvider& dataprovider );
133 Renderer( const Renderer& );
136 Renderer& operator=( const Renderer& rhs );
139 * Checks if renderer's resources are ready to be used.
141 * @return \e true if they are. Otherwise \e false.
143 virtual bool CheckResources() = 0;
146 * Resolve the derived renderers geometry type and subtype
147 * @param[in] bufferIndex The index of the previous update buffer.
148 * @param[out] outType The geometry type
149 * @param[out] outSubType The geometry subtype
151 virtual void ResolveGeometryTypes( BufferIndex bufferIndex, GeometryType& outType, ShaderSubTypes& outSubType ) = 0;
154 * Checks if renderer's is culled.
155 * @param[in] modelMatrix The model matrix.
156 * @param[in] modelViewProjectionMatrix The MVP matrix.
157 * @return \e true if it is. Otherwise \e false.
159 virtual bool IsOutsideClipSpace( const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
162 * Called from Render; implemented in derived classes.
163 * @param[in] bufferIndex The index of the previous update buffer.
164 * @param[in] program to use.
165 * @param[in] modelViewMatrix The model-view matrix.
166 * @param[in] viewMatrix The view matrix.
168 virtual void DoRender( BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
172 RenderDataProvider& mDataProvider;
174 TextureCache* mTextureCache;
179 BlendingOptions mBlendingOptions;
180 bool mUseBlend:1; ///< True if blending should be enabled, 1 bit is enough
181 CullFaceMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough
185 } // namespace SceneGraph
187 } // namespace Internal
191 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__