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
53 * Protected constructor; only derived classes can be instantiated.
54 * @param usesGeometryScaling should be false if the derived class does not need geometry scaling
56 RenderableAttachment( bool usesGeometryScaling );
59 * Virtual destructor, no deletion through this interface
61 virtual ~RenderableAttachment();
63 private: // From NodeAttachment
66 * @copydoc NodeAttachment::Initialize().
68 virtual void Initialize( SceneController& sceneController, BufferIndex updateBufferIndex );
71 * @copydoc NodeAttachment::OnDestroy().
73 virtual void OnDestroy();
76 * @copydoc NodeAttachment::GetRenderable()
78 virtual RenderableAttachment* GetRenderable();
80 public: // Connection API for derived classes
82 * Chained from RenderableAttachment::Initialize()
84 virtual void Initialize2( BufferIndex updateBufferIndex ) = 0;
87 * Chained from RenderableAttachment::OnDestroy()
89 virtual void OnDestroy2() = 0;
95 * @See Dali::RenderableActor::SetBlendMode().
97 void SetBlendingMode( BlendingMode::Type mode );
100 * @copydoc Dali::RenderableActor::GetBlendMode().
102 BlendingMode::Type GetBlendingMode() const;
105 * Flag to check if any geometry scaling is needed, inlined as called from update algorithm often
106 * @return true if the derived renderable uses geometry scaling
108 bool UsesGeometryScaling() const
110 return mUsesGeometryScaling;
114 * Triggers scale for size update. GetScaleForSize will be called in this frame
116 void SetRecalculateScaleForSize();
119 * Returns the scaling dirty flag, inlined as called from update algorithm often
120 * @return if scale for size is dirty, i.e. scaling has changed
122 bool IsScaleForSizeDirty() const
124 return mScaleForSizeDirty;
128 * Retrieve scale-for-size for given node size
129 * Clears the scale for size flag
130 * @param[in] nodeSize to scale to
131 * @param[out] scaling factors
133 void GetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
136 public: // For use during in the update algorithm only
139 * @param[in] updateBufferIndex The current update buffer index.
140 * @return visible tells if this renderer can be potentially seen
142 bool ResolveVisibility( BufferIndex updateBufferIndex );
145 * if this renderable actor has visible size and color
146 * @return true if you can potentially see this actor
148 bool HasVisibleSizeAndColor() const
150 return mHasSizeAndColorFlag;
154 * Prepare the object resources.
155 * This must be called by the UpdateManager before calling PrepareRender, for each frame.
156 * @param[in] updateBufferIndex The current update buffer index.
157 * @param[in] resourceManager The resource manager.
159 void PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
162 * If the resource is being tracked, then follow it. ( Further ready tests will use this
163 * list ) Otherwise, if it's not complete, set mHasUntrackedResources.
164 * @param[in] The resource id
166 void FollowTracker( Integration::ResourceId id );
169 * Check whether the attachment has been marked as ready to render
170 * @param[out] ready TRUE if the attachment has resources to render
171 * @param[out] complete TRUE if the attachment's resources are complete
172 * (e.g. image has finished loading, framebuffer is ready to render, native image
173 * framebuffer has been rendered)
175 void GetReadyAndComplete(bool& ready, bool& complete) const;
178 * Prepare the object for rendering.
179 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
180 * @param[in] updateBufferIndex The current update buffer index.
182 void PrepareRender( BufferIndex updateBufferIndex );
184 public: // API for derived classes
187 * Retrieve a Renderer used by this attachment; implemented in derived classes.
188 * @note The first Renderer is the main renderer for the attachment, and
189 * should always exist during the lifetime of the RenderableAttachment.
190 * @return A Renderer.
192 virtual Renderer& GetRenderer() = 0;
195 * Retrieve a Renderer used by this attachment.
196 * @note The first Renderer is the main renderer for the attachment, and
197 * should always exist during the lifetime of the RenderableAttachment.
198 * Other renderers are for effects such as shadows and reflections.
199 * @return A Renderer.
201 virtual const Renderer& GetRenderer() const = 0;
204 * Prepare the object resources.
205 * This must be called by the UpdateManager before calling PrepareRender, for each frame.
206 * @param[in] updateBufferIndex The current buffer index.
207 * @param[in] resourceManager The resource manager.
208 * @return True if resources are ready, false will prevent PrepareRender being called for this attachment.
210 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager ) = 0;
213 * @copydoc RenderableAttachment::PrepareRender()
215 virtual void DoPrepareRender( BufferIndex updateBufferIndex ) = 0;
218 * Query whether the attachment is fully opaque.
219 * @param[in] updateBufferIndex The current update buffer index.
220 * @return True if fully opaque.
222 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex ) = 0;
225 * Called to notify that the size has been changed
226 * The implementation may tell the renderer to recalculate scale
227 * based on the new size
228 * @param[in] updateBufferIndex The current update buffer index.
230 virtual void SizeChanged( BufferIndex updateBufferIndex ) = 0;
233 * Retrieve the scale-for-size for given node size. Default implementation returns Vector3::ZERO
234 * @param[in] nodeSize to scale to
235 * @param[out] scaling factors
237 virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
241 * Set the sort-modifier for the attachment.
242 * @param[in] modifier The depth-sort modifier.
244 void SetSortModifier(float modifier);
247 * Retrieve the sort-modifier for the attachment.
248 * @return The sort-modifier.
250 float GetSortModifier() const
252 // inlined as its called a lot when sorting transparent renderers
253 return mSortModifier;
259 RenderableAttachment( const RenderableAttachment& );
262 RenderableAttachment& operator=( const RenderableAttachment& rhs );
265 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
266 Shader* mShader; ///< A pointer to the shader
268 Dali::Vector< Integration::ResourceId > mTrackedResources; ///< Filled during PrepareResources if there are uncomplete, tracked resources.
272 BlendingMode::Type mBlendingMode:2; ///< Whether blending is used to render the renderable attachment. 2 bits is enough for 3 values
274 bool mUsesGeometryScaling:1; ///< True if the derived renderer uses scaling.
275 bool mScaleForSizeDirty:1; ///< True if mScaleForSize has changed in the current frame.
276 bool mUseBlend:1; ///< True if the attachment & renderer should be considered opaque for sorting and blending.
277 bool mHasSizeAndColorFlag:1; ///< Set during the update algorithm to tell whether this renderer can potentially be seen
278 bool mResourcesReady:1; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
279 bool mFinishedResourceAcquisition:1; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
280 bool mHasUntrackedResources:1; ///< Set during PrepareResources, true if have tried to follow untracked resources
283 // Messages for RenderableAttachment
285 inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const RenderableAttachment& attachment, BlendingMode::Type mode )
287 typedef MessageValue1< RenderableAttachment, BlendingMode::Type > LocalType;
289 // Reserve some memory inside the message queue
290 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
292 new (slot) LocalType( &attachment, &RenderableAttachment::SetBlendingMode, mode );
295 } // namespace SceneGraph
297 } // namespace Internal
301 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_H__