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;
45 struct RendererWithSortAttributes;
48 * RenderableAttachments are responsible for preparing textures, meshes, matrices etc. during the Update.
49 * These resources are then passed to a renderer, for use in the next Render.
51 class RenderableAttachment : public NodeAttachment
55 * Protected constructor; only derived classes can be instantiated.
56 * @param usesGeometryScaling should be false if the derived class does not need geometry scaling
58 RenderableAttachment( bool usesGeometryScaling );
61 * Virtual destructor, no deletion through this interface
63 virtual ~RenderableAttachment();
65 private: // From NodeAttachment
68 * @copydoc NodeAttachment::Initialize().
70 virtual void Initialize( SceneController& sceneController, BufferIndex updateBufferIndex );
73 * @copydoc NodeAttachment::OnDestroy().
75 virtual void OnDestroy();
78 * @copydoc NodeAttachment::GetRenderable()
80 virtual RenderableAttachment* GetRenderable();
82 public: // Connection API for derived classes
84 * Chained from RenderableAttachment::Initialize()
86 virtual void Initialize2( BufferIndex updateBufferIndex ) = 0;
89 * Chained from RenderableAttachment::OnDestroy()
91 virtual void OnDestroy2() = 0;
97 * @See Dali::RenderableActor::SetBlendMode().
99 void SetBlendingMode( BlendingMode::Type mode );
102 * @copydoc Dali::RenderableActor::GetBlendMode().
104 BlendingMode::Type GetBlendingMode() const;
107 * Flag to check if any geometry scaling is needed, inlined as called from update algorithm often
108 * @return true if the derived renderable uses geometry scaling
110 bool UsesGeometryScaling() const
112 return mUsesGeometryScaling;
116 * Triggers scale for size update. GetScaleForSize will be called in this frame
118 void SetRecalculateScaleForSize();
121 * Returns the scaling dirty flag, inlined as called from update algorithm often
122 * @return if scale for size is dirty, i.e. scaling has changed
124 bool IsScaleForSizeDirty() const
126 return mScaleForSizeDirty;
130 * Retrieve scale-for-size for given node size
131 * Clears the scale for size flag
132 * @param[in] nodeSize to scale to
133 * @param[out] scaling factors
135 void GetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
138 public: // For use during in the update algorithm only
141 * @param[in] updateBufferIndex The current update buffer index.
142 * @return visible tells if this renderer can be potentially seen
144 bool ResolveVisibility( BufferIndex updateBufferIndex );
147 * if this renderable actor has visible size and color
148 * @return true if you can potentially see this actor
150 bool HasVisibleSizeAndColor() const
152 return mHasSizeAndColorFlag;
156 * Prepare the object resources.
157 * This must be called by the UpdateManager before calling PrepareRender, for each frame.
158 * @param[in] updateBufferIndex The current update buffer index.
159 * @param[in] resourceManager The resource manager.
161 void PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
164 * If the resource is being tracked, then follow it. ( Further ready tests will use this
165 * list ) Otherwise, if it's not complete, set mHasUntrackedResources.
166 * @param[in] The resource id
168 void FollowTracker( Integration::ResourceId id );
171 * Check whether the attachment has been marked as ready to render
172 * @param[out] ready TRUE if the attachment has resources to render
173 * @param[out] complete TRUE if the attachment's resources are complete
174 * (e.g. image has finished loading, framebuffer is ready to render, native image
175 * framebuffer has been rendered)
177 void GetReadyAndComplete(bool& ready, bool& complete) const;
180 * Prepare the object for rendering.
181 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
182 * @param[in] updateBufferIndex The current update buffer index.
184 void PrepareRender( BufferIndex updateBufferIndex );
186 public: // API for derived classes
189 * Retrieve a Renderer used by this attachment; implemented in derived classes.
190 * @note The first Renderer is the main renderer for the attachment, and
191 * should always exist during the lifetime of the RenderableAttachment.
192 * @return A Renderer.
194 virtual Renderer& GetRenderer() = 0;
197 * Retrieve a Renderer used by this attachment.
198 * @note The first Renderer is the main renderer for the attachment, and
199 * should always exist during the lifetime of the RenderableAttachment.
200 * Other renderers are for effects such as shadows and reflections.
201 * @return A Renderer.
203 virtual const Renderer& GetRenderer() const = 0;
206 * Prepare the object resources.
207 * This must be called by the UpdateManager before calling PrepareRender, for each frame.
208 * @param[in] updateBufferIndex The current buffer index.
209 * @param[in] resourceManager The resource manager.
210 * @return True if resources are ready, false will prevent PrepareRender being called for this attachment.
212 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager ) = 0;
215 * @copydoc RenderableAttachment::PrepareRender()
217 virtual void DoPrepareRender( BufferIndex updateBufferIndex ) = 0;
220 * Query whether the attachment is fully opaque.
221 * @param[in] updateBufferIndex The current update buffer index.
222 * @return True if fully opaque.
224 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex ) = 0;
227 * Called to notify that the size has been changed
228 * The implementation may tell the renderer to recalculate scale
229 * based on the new size
230 * @param[in] updateBufferIndex The current update buffer index.
232 virtual void SizeChanged( BufferIndex updateBufferIndex ) = 0;
235 * Retrieve the scale-for-size for given node size. Default implementation returns Vector3::ZERO
236 * @param[in] nodeSize to scale to
237 * @param[out] scaling factors
239 virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
242 * Set the sort-modifier for the attachment.
243 * @param[in] modifier The depth-sort modifier.
245 void SetSortModifier(float modifier);
248 * Get the depth index for the attachment
249 * @param[in] bufferIndex The current update buffer index.
251 virtual int GetDepthIndex()
253 return static_cast<int>( mSortModifier );
257 * Write the attachment's sort attributes to the passed in reference
258 * @todo MESH_REWORK Consider removing this after merge with scene-graph-renderer-attachment,
259 * and allowing PrepareRenderInstruction to read directly from this object
261 * @param[in] bufferIndex The current update buffer index.
262 * @param[out] sortAttributes
264 virtual void SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes );
269 RenderableAttachment( const RenderableAttachment& );
272 RenderableAttachment& operator=( const RenderableAttachment& rhs );
275 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
276 Shader* mShader; ///< A pointer to the shader
278 Dali::Vector< Integration::ResourceId > mTrackedResources; ///< Filled during PrepareResources if there are uncomplete, tracked resources.
282 BlendingMode::Type mBlendingMode:2; ///< Whether blending is used to render the renderable attachment. 2 bits is enough for 3 values
284 bool mUsesGeometryScaling:1; ///< True if the derived renderer uses scaling.
285 bool mScaleForSizeDirty:1; ///< True if mScaleForSize has changed in the current frame.
286 bool mUseBlend:1; ///< True if the attachment & renderer should be considered opaque for sorting and blending.
287 bool mHasSizeAndColorFlag:1; ///< Set during the update algorithm to tell whether this renderer can potentially be seen
288 bool mResourcesReady:1; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
289 bool mFinishedResourceAcquisition:1; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
290 bool mHasUntrackedResources:1; ///< Set during PrepareResources, true if have tried to follow untracked resources
293 // Messages for RenderableAttachment
295 inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const RenderableAttachment& attachment, BlendingMode::Type mode )
297 typedef MessageValue1< RenderableAttachment, BlendingMode::Type > LocalType;
299 // Reserve some memory inside the message queue
300 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
302 new (slot) LocalType( &attachment, &RenderableAttachment::SetBlendingMode, mode );
305 } // namespace SceneGraph
307 } // namespace Internal
311 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_H__