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;
179 public: // API for derived classes
182 * Retrieve a Renderer used by this attachment; implemented in derived classes.
183 * @note The first Renderer is the main renderer for the attachment, and
184 * should always exist during the lifetime of the RenderableAttachment.
185 * @return A Renderer.
187 virtual Renderer& GetRenderer() = 0;
190 * Retrieve a Renderer used by this attachment.
191 * @note The first Renderer is the main renderer for the attachment, and
192 * should always exist during the lifetime of the RenderableAttachment.
193 * Other renderers are for effects such as shadows and reflections.
194 * @return A Renderer.
196 virtual const Renderer& GetRenderer() const = 0;
199 * Prepare the object resources.
200 * This must be called by the UpdateManager before calling PrepareRender, for each frame.
201 * @param[in] updateBufferIndex The current buffer index.
202 * @param[in] resourceManager The resource manager.
203 * @return True if resources are ready, false will prevent PrepareRender being called for this attachment.
205 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager ) = 0;
208 * Prepare the object for rendering.
209 * This is called by the UpdateManager when an object is due to be rendered in the current frame.
210 * @param[in] updateBufferIndex The current update buffer index.
212 virtual void DoPrepareRender( BufferIndex updateBufferIndex ) = 0;
215 * Query whether the attachment is fully opaque.
216 * @param[in] updateBufferIndex The current update buffer index.
217 * @return True if fully opaque.
219 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex ) = 0;
222 * Called to notify that the size has been changed
223 * The implementation may tell the renderer to recalculate scale
224 * based on the new size
225 * @param[in] updateBufferIndex The current update buffer index.
227 virtual void SizeChanged( BufferIndex updateBufferIndex ) = 0;
230 * Retrieve the scale-for-size for given node size. Default implementation returns Vector3::ZERO
231 * @param[in] nodeSize to scale to
232 * @param[out] scaling factors
234 virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
237 * Set the sort-modifier for the attachment.
238 * @param[in] modifier The depth-sort modifier.
240 void SetSortModifier(float modifier);
243 * Get the depth index for the attachment
244 * @param[in] bufferIndex The current update buffer index.
246 virtual int GetDepthIndex()
248 return static_cast<int>( mSortModifier );
252 * Write the attachment's sort attributes to the passed in reference
253 * @todo MESH_REWORK Consider removing this after merge with scene-graph-renderer-attachment,
254 * and allowing PrepareRenderInstruction to read directly from this object
256 * @param[in] bufferIndex The current update buffer index.
257 * @param[out] sortAttributes
259 virtual void SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes );
264 RenderableAttachment( const RenderableAttachment& );
267 RenderableAttachment& operator=( const RenderableAttachment& rhs );
270 SceneController* mSceneController; ///< Used for initializing renderers whilst attached
271 Shader* mShader; ///< A pointer to the shader
273 Dali::Vector< Integration::ResourceId > mTrackedResources; ///< Filled during PrepareResources if there are uncomplete, tracked resources.
277 BlendingMode::Type mBlendingMode:2; ///< Whether blending is used to render the renderable attachment. 2 bits is enough for 3 values
279 bool mUsesGeometryScaling:1; ///< True if the derived renderer uses scaling.
280 bool mScaleForSizeDirty:1; ///< True if mScaleForSize has changed in the current frame.
281 bool mHasSizeAndColorFlag:1; ///< Set during the update algorithm to tell whether this renderer can potentially be seen
282 bool mResourcesReady:1; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
283 bool mFinishedResourceAcquisition:1; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
284 bool mHasUntrackedResources:1; ///< Set during PrepareResources, true if have tried to follow untracked resources
287 // Messages for RenderableAttachment
289 inline void SetBlendingModeMessage( EventThreadServices& eventThreadServices, const RenderableAttachment& attachment, BlendingMode::Type mode )
291 typedef MessageValue1< RenderableAttachment, BlendingMode::Type > LocalType;
293 // Reserve some memory inside the message queue
294 unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
296 new (slot) LocalType( &attachment, &RenderableAttachment::SetBlendingMode, mode );
299 } // namespace SceneGraph
301 } // namespace Internal
305 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERABLE_ATTACHMENT_H__