1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_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/internal/common/blending-options.h>
23 #include <dali/internal/common/internal-constants.h>
24 #include <dali/internal/common/type-abstraction-enums.h>
25 #include <dali/internal/event/common/event-thread-services.h>
26 #include <dali/internal/update/controllers/scene-controller.h>
27 #include <dali/internal/update/nodes/node.h>
28 #include <dali/internal/update/node-attachments/node-attachment.h>
29 #include <dali/internal/update/resources/resource-manager-declarations.h>
30 #include <dali/internal/render/renderers/scene-graph-renderer-declarations.h>
37 class ResourceManager;
38 class ResourceTracker;
46 * RenderableAttachments are responsible for preparing textures, meshes, matrices etc. during the Update.
47 * These resources are then passed to a renderer, for use in the next Render.
49 class RenderableAttachment : public NodeAttachment
54 * @See Dali::RenderableActor::SetBlendMode().
56 void SetBlendingMode( BlendingMode::Type mode );
59 * @copydoc Dali::RenderableActor::GetBlendMode().
61 BlendingMode::Type GetBlendingMode() const;
64 * Flag to check if any geometry scaling is needed, inlined as called from update algorithm often
65 * @return true if the derived renderable uses geometry scaling
67 bool UsesGeometryScaling() const
69 return mUsesGeometryScaling;
73 * Triggers scale for size update. GetScaleForSize will be called in this frame
75 void SetRecalculateScaleForSize();
78 * Returns the scaling dirty flag, inlined as called from update algorithm often
79 * @return if scale for size is dirty, i.e. scaling has changed
81 bool IsScaleForSizeDirty() const
83 return mScaleForSizeDirty;
87 * Retrieve scale-for-size for given node size
88 * Clears the scale for size flag
89 * @param[in] nodeSize to scale to
90 * @param[out] scaling factors
92 void GetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
95 public: // For use during in the update algorithm only
98 * @param[in] updateBufferIndex The current update buffer index.
99 * @return visible tells if this renderer can be potentially seen
101 bool ResolveVisibility( BufferIndex updateBufferIndex );
104 * if this renderable actor has visible size and color
105 * @return true if you can potentially see this actor
107 bool HasVisibleSizeAndColor() const
109 return mHasSizeAndColorFlag;
113 * Check whether the attachment has been marked as ready to render
114 * @param[out] ready TRUE if the attachment has resources to render
115 * @param[out] complete TRUE if the attachment's resources are complete
116 * (e.g. image has finished loading, framebuffer is ready to render, native image
117 * framebuffer has been rendered)
119 void GetReadyAndComplete(bool& ready, bool& complete) const;
122 * Query whether the attachment has blending enabled.
123 * @param[in] updateBufferIndex The current update buffer index.
124 * @return true if blending is enabled, false otherwise.
126 bool IsBlendingOn( BufferIndex updateBufferIndex );
129 * Check if the blending mode has changed - if it has, send message to renderer
130 * @param[in] updateBufferIndex The current update buffer index.
131 * @param[in] useBlending True if the renderer should use blending option
133 void ChangeBlending( BufferIndex updateBufferIndex, bool useBlending );
136 * Prepare the object for rendering.
137 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
138 * @param[in] updateBufferIndex The current update buffer index.
140 void PrepareRender( BufferIndex updateBufferIndex );
142 public: // API for derived classes
145 * Retrieve a Renderer used by this attachment; implemented in derived classes.
146 * @note The first Renderer is the main renderer for the attachment, and
147 * should always exist during the lifetime of the RenderableAttachment.
148 * @return A Renderer.
150 virtual Renderer& GetRenderer() = 0;
153 * Retrieve a Renderer used by this attachment.
154 * @note The first Renderer is the main renderer for the attachment, and
155 * should always exist during the lifetime of the RenderableAttachment.
156 * Other renderers are for effects such as shadows and reflections.
157 * @return A Renderer.
159 virtual const Renderer& GetRenderer() const = 0;
162 * Prepare the object resources.
163 * This must be called by the UpdateManager before calling PrepareRender, for each frame.
164 * @param[in] updateBufferIndex The current update buffer index.
165 * @param[in] resourceManager The resource manager.
167 void PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
170 * If the resource is being tracked, then follow it. ( Further ready tests will use this
171 * list ) Otherwise, if it's not complete, set mHasUntrackedResources.
172 * @param[in] The resource id
174 void FollowTracker( Integration::ResourceId id );
177 * @copydoc RenderableAttachment::PrepareRender()
179 virtual void DoPrepareRender( BufferIndex updateBufferIndex ) = 0;
182 * Query whether the attachment is fully opaque.
183 * @param[in] updateBufferIndex The current update buffer index.
184 * @return True if fully opaque.
186 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex ) = 0;
189 * Called to notify that the size has been changed
190 * The implementation may tell the renderer to recalculate scale
191 * based on the new size
192 * @param[in] updateBufferIndex The current update buffer index.
194 virtual void SizeChanged( BufferIndex updateBufferIndex ) = 0;
197 * Chained from NodeAttachment::ConnectToSceneGraph()
199 virtual void ConnectToSceneGraph2( BufferIndex updateBufferIndex ) = 0;
202 * Chained from NodeAttachment::OnDestroy()
204 virtual void OnDestroy2() = 0;
207 * Retrieve the scale-for-size for given node size. Default implementation returns Vector3::ZERO
208 * @param[in] nodeSize to scale to
209 * @param[out] scaling factors
211 virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
215 * Set the sort-modifier for the attachment.
216 * @param[in] modifier The depth-sort modifier.
218 void SetSortModifier(float modifier);
221 * Retrieve the sort-modifier for the attachment.
222 * @return The sort-modifier.
224 float GetSortModifier() const
226 // inlined as its called a lot when sorting transparent renderers
227 return mSortModifier;
233 * Protected constructor; only base classes can be instantiated.
234 * @param usesGeometryScaling should be false if the derived class does not need geometry scaling
236 RenderableAttachment( bool usesGeometryScaling );
239 * Virtual destructor, no deletion through this interface
241 virtual ~RenderableAttachment();
243 private: // From NodeAttachment
246 * @copydoc NodeAttachment::ConnectToSceneGraph().
248 virtual void ConnectToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex );
251 * @copydoc NodeAttachment::DisconnectFromSceneGraph().
253 virtual void OnDestroy();
256 * @copydoc NodeAttachment::GetRenderable()
258 virtual RenderableAttachment* GetRenderable();
263 * Prepare the object resources.
264 * This must be called by the UpdateManager before calling PrepareRender, for each frame.
265 * @param[in] updateBufferIndex The current buffer index.
266 * @param[in] resourceManager The resource manager.
267 * @return True if resources are ready, false will prevent PrepareRender being called for this attachment.
269 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager ) = 0;
272 RenderableAttachment( const RenderableAttachment& );
275 RenderableAttachment& operator=( const RenderableAttachment& rhs );
278 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
279 Shader* mShader; ///< A pointer to the shader
281 Dali::Vector< Integration::ResourceId > mTrackedResources; ///< Filled during PrepareResources if there are uncomplete, tracked resources.
285 BlendingMode::Type mBlendingMode:2; ///< Whether blending is used to render the renderable attachment. 2 bits is enough for 3 values
287 bool mUsesGeometryScaling:1; ///< True if the derived renderer uses scaling.
288 bool mScaleForSizeDirty:1; ///< True if mScaleForSize has changed in the current frame.
289 bool mUseBlend:1; ///< True if the attachment & renderer should be considered opaque for sorting and blending.
290 bool mHasSizeAndColorFlag:1; ///< Set during the update algorithm to tell whether this renderer can potentially be seen
291 bool mResourcesReady:1; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
292 bool mFinishedResourceAcquisition:1; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
293 bool mHasUntrackedResources:1; ///< Set during PrepareResources, true if have tried to follow untracked resources
296 // Messages for RenderableAttachment
298 inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const RenderableAttachment& attachment, BlendingMode::Type mode )
300 typedef MessageValue1< RenderableAttachment, BlendingMode::Type > LocalType;
302 // Reserve some memory inside the message queue
303 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
305 new (slot) LocalType( &attachment, &RenderableAttachment::SetBlendingMode, mode );
308 } // namespace SceneGraph
310 } // namespace Internal
314 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_H__