X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Fnodes%2Fnode.h;h=5cd607379cb0f3aad78b3e45f76e48a4e5cee400;hb=e08e2992259823c5f9832ad959ffa510b0445a6c;hp=5d4d19ee2163220986b09260f213e0bcfc63e790;hpb=e0ac4c8d992e74028efb7ff67b86427f1cf7059f;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/nodes/node.h b/dali/internal/update/nodes/node.h old mode 100644 new mode 100755 index 5d4d19e..5cd6073 --- a/dali/internal/update/nodes/node.h +++ b/dali/internal/update/nodes/node.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_H__ -#define __DALI_INTERNAL_SCENE_GRAPH_NODE_H__ +#ifndef DALI_INTERNAL_SCENE_GRAPH_NODE_H +#define DALI_INTERNAL_SCENE_GRAPH_NODE_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,21 +21,20 @@ // INTERNAL INCLUDES #include #include -#include #include #include #include +#include #include #include +#include #include #include -#include #include #include -#include +#include +#include #include -#include -#include #include namespace Dali @@ -44,44 +43,21 @@ namespace Dali namespace Internal { -// value types used by messages +// Value types used by messages. template <> struct ParameterType< ColorMode > : public BasicType< ColorMode > {}; -template <> struct ParameterType< PositionInheritanceMode > : public BasicType< PositionInheritanceMode > {}; +template <> struct ParameterType< ClippingMode::Type > : public BasicType< ClippingMode::Type > {}; namespace SceneGraph { class DiscardQueue; class Layer; -class NodeAttachment; class RenderTask; class UpdateManager; -/** - * Flag whether property has changed, during the Update phase. - */ -enum NodePropertyFlags -{ - NothingFlag = 0x000, - TransformFlag = 0x001, - VisibleFlag = 0x002, - ColorFlag = 0x004, - SizeFlag = 0x008, - OverlayFlag = 0x010, - SortModifierFlag = 0x020, - ChildDeletedFlag = 0x040 -}; - -static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags - -/** - * Size is not inherited. - * VisibleFlag is inherited so that attachments can be synchronized with nodes after they become visible - */ -static const int InheritedDirtyFlags = TransformFlag | VisibleFlag | ColorFlag | OverlayFlag; // Flags which require the scene renderable lists to be updated -static const int RenderableUpdateFlags = TransformFlag | SortModifierFlag | ChildDeletedFlag; +static NodePropertyFlags RenderableUpdateFlags = NodePropertyFlags::TRANSFORM | NodePropertyFlags::CHILD_DELETED; /** * Node is the base class for all nodes in the Scene Graph. @@ -96,7 +72,6 @@ class Node : public PropertyOwner, public NodeDataProvider public: // Defaults - static const PositionInheritanceMode DEFAULT_POSITION_INHERITANCE_MODE; static const ColorMode DEFAULT_COLOR_MODE; // Creation methods @@ -107,33 +82,19 @@ public: static Node* New(); /** - * Virtual destructor + * Deletes a Node. */ - virtual ~Node(); + static void Delete( Node* node ); /** - * When a Node is marked "active" it has been disconnected, but its properties have been modified. - * @note An inactive Node will be skipped during the UpdateManager ResetProperties stage. - * @param[in] isActive True if the Node is active. - */ - void SetActive( bool isActive ) - { - mIsActive = isActive; - } - - /** - * Query whether the Node is active. - * @return True if the Node is active. + * Called during UpdateManager::DestroyNode shortly before Node is destroyed. */ - bool IsActive() const - { - return mIsActive; - } + void OnDestroy(); /** - * Called during UpdateManager::DestroyNode shortly before Node is destroyed. + * @return the unique ID of the node */ - void OnDestroy(); + uint32_t GetId() const; // Layer interface @@ -143,7 +104,7 @@ public: */ bool IsLayer() { - return (GetLayer() != NULL); + return mIsLayer; } /** @@ -155,62 +116,101 @@ public: return NULL; } - // Attachments + /** + * This method sets clipping information on the node based on its hierarchy in the scene-graph. + * A value is calculated that can be used during sorting to increase sort speed. + * @param[in] clippingId The Clipping ID of the node to set + * @param[in] clippingDepth The Clipping Depth of the node to set + * @param[in] scissorDepth The Scissor Clipping Depth of the node to set + */ + void SetClippingInformation( const uint32_t clippingId, const uint32_t clippingDepth, const uint32_t scissorDepth ) + { + // We only set up the sort value if we have a stencil clipping depth, IE. At least 1 clipping node has been hit. + // If not, if we traverse down a clipping tree and back up, and there is another + // node on the parent, this will have a non-zero clipping ID that must be ignored + if( clippingDepth > 0u ) + { + mClippingDepth = clippingDepth; + + // Calculate the sort value here on write, as when read (during sort) it may be accessed several times. + // The items must be sorted by Clipping ID first (so the ID is kept in the most-significant bits). + // For the same ID, the clipping nodes must be first, so we negate the + // clipping enabled flag and set it as the least significant bit. + mClippingSortModifier = ( clippingId << 1u ) | ( mClippingMode == ClippingMode::DISABLED ? 1u : 0u ); + } + else + { + // If we do not have a clipping depth, then set this to 0 so we do not have a Clipping ID either. + mClippingSortModifier = 0u; + } + + // The scissor depth does not modify the clipping sort modifier (as scissor clips are 2D only). + // For this reason we can always update the member variable. + mScissorDepth = scissorDepth; + } /** - * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode. - * @pre The Node does not already have an attachment. - * @param[in] attachment The object to attach. + * Gets the Clipping ID for this node. + * @return The Clipping ID for this node. */ - void Attach( NodeAttachment& attachment ); + uint32_t GetClippingId() const + { + return mClippingSortModifier >> 1u; + } /** - * Query the node if it has an attachment. - * @return True if it has an attachment. + * Gets the Clipping Depth for this node. + * @return The Clipping Depth for this node. */ - bool HasAttachment() const + uint32_t GetClippingDepth() const { - return mAttachment; + return mClippingDepth; } /** - * Add a renderer to the node - * @param[in] renderer The renderer added to the node + * Gets the Scissor Clipping Depth for this node. + * @return The Scissor Clipping Depth for this node. */ - void AddRenderer( Renderer* renderer ) + uint32_t GetScissorDepth() const { - //Check that it has not been already added - unsigned int rendererCount( mRenderer.Size() ); - for( unsigned int i(0); i( mRenderer.Size() ); } // Containment methods @@ -271,6 +262,14 @@ public: } /** + * @return true if the node is connected to SceneGraph + */ + bool ConnectedToScene() + { + return IsRoot() || GetParent(); + } + + /** * Connect a node to the scene-graph. * @pre A node cannot be added to itself. * @pre The parent node is connected to the scene-graph. @@ -285,10 +284,8 @@ public: * @pre childNode is a child of this Node. * @param[in] updateBufferIndex The current update buffer index. * @param[in] childNode The node to disconnect. - * @param[in] connectedNodes Disconnected Node attachments should be removed from here. - * @param[in] disconnectedNodes Disconnected Node attachments should be added here. */ - void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode, std::set& connectedNodes, std::set& disconnectedNodes ); + void DisconnectChild( BufferIndex updateBufferIndex, Node& childNode ); /** * Retrieve the children a Node. @@ -314,7 +311,7 @@ public: * Flag that one of the node values has changed in the current frame. * @param[in] flag The flag to set. */ - void SetDirtyFlag(NodePropertyFlags flag) + void SetDirtyFlag( NodePropertyFlags flag ) { mDirtyFlags |= flag; } @@ -324,23 +321,22 @@ public: */ void SetAllDirtyFlags() { - mDirtyFlags = AllFlags; + mDirtyFlags = NodePropertyFlags::ALL; } /** * Query whether a node is dirty. * @return The dirty flags */ - int GetDirtyFlags() const; + NodePropertyFlags GetDirtyFlags() const; /** - * Query whether a node is clean. - * @return True if the node is clean. + * Query inherited dirty flags. + * + * @param The parentFlags to or with + * @return The inherited dirty flags */ - bool IsClean() const - { - return ( NothingFlag == GetDirtyFlags() ); - } + NodePropertyFlags GetInheritedDirtyFlags( NodePropertyFlags parentFlags ) const; /** * Retrieve the parent-origin of the node. @@ -348,7 +344,7 @@ public: */ const Vector3& GetParentOrigin() const { - return mParentOrigin.mValue; + return mParentOrigin.Get(0); } /** @@ -357,8 +353,7 @@ public: */ void SetParentOrigin(const Vector3& origin) { - mParentOrigin.mValue = origin; - mParentOrigin.OnSet(); + mParentOrigin.Set(0,origin ); } /** @@ -367,7 +362,7 @@ public: */ const Vector3& GetAnchorPoint() const { - return mAnchorPoint.mValue; + return mAnchorPoint.Get(0); } /** @@ -376,8 +371,7 @@ public: */ void SetAnchorPoint(const Vector3& anchor) { - mAnchorPoint.mValue = anchor; - mAnchorPoint.OnSet(); + mAnchorPoint.Set(0, anchor ); } /** @@ -387,128 +381,12 @@ public: */ const Vector3& GetPosition(BufferIndex bufferIndex) const { - return mPosition[bufferIndex]; - } - - /** - * Sets both the local & base positions of the node. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] position The new local & base position. - */ - void BakePosition(BufferIndex updateBufferIndex, const Vector3& position) - { - mPosition.Bake( updateBufferIndex, position ); - } - - /** - * Sets the world of the node derived from the position of all its parents. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] position The world position. - */ - void SetWorldPosition( BufferIndex updateBufferIndex, const Vector3& position ) - { - mWorldPosition.Set( updateBufferIndex, position ); - } - - /** - * Sets the position of the node derived from the position of all its parents. - * This method should only be called when the parent's world position is up-to-date. - * With a non-central anchor-point, the local orientation and scale affects the world position. - * Therefore the world orientation & scale must be updated before the world position. - * @pre The node has a parent. - * @param[in] updateBufferIndex The current update buffer index. - */ - void InheritWorldPosition(BufferIndex updateBufferIndex) - { - DALI_ASSERT_DEBUG(mParent != NULL); - - switch( mPositionInheritanceMode ) + if( mTransformId != INVALID_TRANSFORM_ID ) { - case INHERIT_PARENT_POSITION : ///@see Dali::PositionInheritanceMode for how these modes are expected to work - { - Vector3 finalPosition(-0.5f, -0.5f, -0.5f); - - finalPosition += mParentOrigin.mValue; - finalPosition *= mParent->GetSize(updateBufferIndex); - finalPosition += mPosition[updateBufferIndex]; - finalPosition *= mParent->GetWorldScale(updateBufferIndex); - const Quaternion& parentWorldOrientation = mParent->GetWorldOrientation(updateBufferIndex); - if(!parentWorldOrientation.IsIdentity()) - { - finalPosition *= parentWorldOrientation; - } - - // check if a node needs to be offsetted locally (only applies when AnchorPoint is not central) - // dont use operator== as that does a slower comparison (and involves function calls) - Vector3 localOffset(0.5f, 0.5f, 0.5f); // AnchorPoint::CENTER - localOffset -= mAnchorPoint.mValue; - - if( ( fabsf( localOffset.x ) >= Math::MACHINE_EPSILON_0 ) || - ( fabsf( localOffset.y ) >= Math::MACHINE_EPSILON_0 ) || - ( fabsf( localOffset.z ) >= Math::MACHINE_EPSILON_0 ) ) - { - localOffset *= mSize[updateBufferIndex]; - - Vector3 scale = mWorldScale[updateBufferIndex]; - - // Pick up sign of local scale - if (mScale[updateBufferIndex].x < 0.0f) - { - scale.x = -scale.x; - } - if (mScale[updateBufferIndex].y < 0.0f) - { - scale.y = -scale.y; - } - if (mScale[updateBufferIndex].z < 0.0f) - { - scale.z = -scale.z; - } - - // If the anchor-point is not central, then position is affected by the local orientation & scale - localOffset *= scale; - const Quaternion& localWorldOrientation = mWorldOrientation[updateBufferIndex]; - if(!localWorldOrientation.IsIdentity()) - { - localOffset *= localWorldOrientation; - } - finalPosition += localOffset; - } - - finalPosition += mParent->GetWorldPosition(updateBufferIndex); - mWorldPosition.Set( updateBufferIndex, finalPosition ); - break; - } - case USE_PARENT_POSITION_PLUS_LOCAL_POSITION : - { - // copy parents position plus local transform - mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) + mPosition[updateBufferIndex] ); - break; - } - case USE_PARENT_POSITION : - { - // copy parents position - mWorldPosition.Set( updateBufferIndex, mParent->GetWorldPosition(updateBufferIndex) ); - break; - } - case DONT_INHERIT_POSITION : - { - // use local position as world position - mWorldPosition.Set( updateBufferIndex, mPosition[updateBufferIndex] ); - break; - } + return mPosition.Get(bufferIndex); } - } - /** - * Copies the previous inherited position, if this changed in the previous frame. - * This method should be called instead of InheritWorldPosition i.e. if the inherited position - * does not need to be recalculated in the current frame. - * @param[in] updateBufferIndex The current update buffer index. - */ - void CopyPreviousWorldPosition( BufferIndex updateBufferIndex ) - { - mWorldPosition.CopyPrevious( updateBufferIndex ); + return Vector3::ZERO; } /** @@ -517,27 +395,19 @@ public: */ const Vector3& GetWorldPosition( BufferIndex bufferIndex ) const { - return mWorldPosition[bufferIndex]; - } - - /** - * Set the position inheritance mode. - * @see Dali::Actor::PositionInheritanceMode - * @param[in] mode The new position inheritance mode. - */ - void SetPositionInheritanceMode( PositionInheritanceMode mode ) - { - mPositionInheritanceMode = mode; - - SetDirtyFlag(TransformFlag); + return mWorldPosition.Get(bufferIndex); } /** - * @return The position inheritance mode. + * Set whether the Node inherits position. + * @param[in] inherit True if the parent position is inherited. */ - PositionInheritanceMode GetPositionInheritanceMode() const + void SetInheritPosition(bool inherit) { - return mPositionInheritanceMode; + if( mTransformId != INVALID_TRANSFORM_ID ) + { + mTransformManager->SetInheritPosition( mTransformId, inherit ); + } } /** @@ -547,62 +417,12 @@ public: */ const Quaternion& GetOrientation(BufferIndex bufferIndex) const { - return mOrientation[bufferIndex]; - } - - /** - * Sets both the local & base orientations of the node. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] orientation The new local & base orientation. - */ - void BakeOrientation(BufferIndex updateBufferIndex, const Quaternion& orientation) - { - mOrientation.Bake( updateBufferIndex, orientation ); - } - - /** - * Sets the orientation of the node derived from the rotation of all its parents. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] orientation The world orientation. - */ - void SetWorldOrientation( BufferIndex updateBufferIndex, const Quaternion& orientation ) - { - mWorldOrientation.Set( updateBufferIndex, orientation ); - } - - /** - * Sets the orientation of the node derived from the rotation of all its parents. - * This method should only be called when the parents world orientation is up-to-date. - * @pre The node has a parent. - * @param[in] updateBufferIndex The current update buffer index. - */ - void InheritWorldOrientation( BufferIndex updateBufferIndex ) - { - DALI_ASSERT_DEBUG(mParent != NULL); - - const Quaternion& localOrientation = mOrientation[updateBufferIndex]; - - if(localOrientation.IsIdentity()) - { - mWorldOrientation.Set( updateBufferIndex, mParent->GetWorldOrientation(updateBufferIndex) ); - } - else + if( mTransformId != INVALID_TRANSFORM_ID ) { - Quaternion finalOrientation( mParent->GetWorldOrientation(updateBufferIndex) ); - finalOrientation *= localOrientation; - mWorldOrientation.Set( updateBufferIndex, finalOrientation ); + return mOrientation.Get(0); } - } - /** - * Copies the previous inherited orientation, if this changed in the previous frame. - * This method should be called instead of InheritWorldOrientation i.e. if the inherited orientation - * does not need to be recalculated in the current frame. - * @param[in] updateBufferIndex The current update buffer index. - */ - void CopyPreviousWorldOrientation( BufferIndex updateBufferIndex ) - { - mWorldOrientation.CopyPrevious( updateBufferIndex ); + return Quaternion::IDENTITY; } /** @@ -612,7 +432,7 @@ public: */ const Quaternion& GetWorldOrientation( BufferIndex bufferIndex ) const { - return mWorldOrientation[bufferIndex]; + return mWorldOrientation.Get(0); } /** @@ -621,66 +441,27 @@ public: */ void SetInheritOrientation(bool inherit) { - if (inherit != mInheritOrientation) + if( mTransformId != INVALID_TRANSFORM_ID ) { - mInheritOrientation = inherit; - - SetDirtyFlag(TransformFlag); + mTransformManager->SetInheritOrientation(mTransformId, inherit ); } } /** - * Query whether the node inherits orientation from its parent. - * @return True if the parent orientation is inherited. - */ - bool IsOrientationInherited() const - { - return mInheritOrientation; - } - - /** * Retrieve the local scale of the node, relative to its parent. * @param[in] bufferIndex The buffer to read from. * @return The local scale. */ const Vector3& GetScale(BufferIndex bufferIndex) const { - return mScale[bufferIndex]; - } - - /** - * Sets the scale of the node derived from the scale of all its parents and a pre-scale - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] scale The world scale. - */ - void SetWorldScale(BufferIndex updateBufferIndex, const Vector3& scale) - { - mWorldScale.Set( updateBufferIndex, scale ); - } - - /** - * Sets the scale of the node derived from the scale of all its parents and a pre-scale. - * This method should only be called when the parents world scale is up-to-date. - * @pre The node has a parent. - * @param[in] updateBufferIndex The current update buffer index. - */ - void InheritWorldScale(BufferIndex updateBufferIndex) - { - DALI_ASSERT_DEBUG(mParent != NULL); + if( mTransformId != INVALID_TRANSFORM_ID ) + { + return mScale.Get(0); + } - mWorldScale.Set( updateBufferIndex, mParent->GetWorldScale(updateBufferIndex) * mScale[updateBufferIndex] ); + return Vector3::ONE; } - /** - * Copies the previous inherited scale, if this changed in the previous frame. - * This method should be called instead of InheritWorldScale i.e. if the inherited scale - * does not need to be recalculated in the current frame. - * @param[in] updateBufferIndex The current update buffer index. - */ - void CopyPreviousWorldScale( BufferIndex updateBufferIndex ) - { - mWorldScale.CopyPrevious( updateBufferIndex ); - } /** * Retrieve the scale of the node derived from the scale of all its parents. @@ -689,7 +470,7 @@ public: */ const Vector3& GetWorldScale( BufferIndex bufferIndex ) const { - return mWorldScale[bufferIndex]; + return mWorldScale.Get(0); } /** @@ -698,33 +479,13 @@ public: */ void SetInheritScale( bool inherit ) { - if( inherit != mInheritScale ) + if( mTransformId != INVALID_TRANSFORM_ID ) { - mInheritScale = inherit; - - SetDirtyFlag( TransformFlag ); + mTransformManager->SetInheritScale(mTransformId, inherit ); } } /** - * Query whether the Node inherits scale. - * @return if scale is inherited - */ - bool IsScaleInherited() const - { - return mInheritScale; - } - - /** - * Copies the previously used size, if this changed in the previous frame. - * @param[in] updateBufferIndex The current update buffer index. - */ - void CopyPreviousSize( BufferIndex updateBufferIndex ) - { - SetSize( updateBufferIndex, GetSize( 1u - updateBufferIndex ) ); - } - - /** * Retrieve the visibility of the node. * @param[in] bufferIndex The buffer to read from. * @return True if the node is visible. @@ -735,14 +496,6 @@ public: } /** - * Retrieves whether a node is fully visible. - * A node is fully visible if is visible and all its ancestors are visible. - * @param[in] updateBufferIndex The current update buffer index. - * @return True if the node is fully visible. - */ - bool IsFullyVisible( BufferIndex updateBufferIndex ) const; - - /** * Retrieve the opacity of the node. * @param[in] bufferIndex The buffer to read from. * @return The opacity. @@ -829,11 +582,11 @@ public: * or inherits its parent color. * @param[in] colorMode The new color mode. */ - void SetColorMode(ColorMode colorMode) + void SetColorMode( ColorMode colorMode ) { mColorMode = colorMode; - SetDirtyFlag(ColorFlag); + SetDirtyFlag( NodePropertyFlags::COLOR ); } /** @@ -846,57 +599,65 @@ public: } /** - * Sets the size of the node. - * @param[in] bufferIndex The buffer to write to. - * @param[in] size The size to write. + * Retrieve the size of the node. + * @param[in] bufferIndex The buffer to read from. + * @return The size. */ - void SetSize( BufferIndex bufferIndex, const Vector3& size ) + const Vector3& GetSize(BufferIndex bufferIndex) const { - mSize[bufferIndex] = size; + if( mTransformId != INVALID_TRANSFORM_ID ) + { + return mSize.Get(0); + } + + return Vector3::ZERO; } /** - * Retrieve the size of the node. - * @param[in] bufferIndex The buffer to read from. - * @return The size. + * Retrieve the bounding sphere of the node + * @return A vector4 describing the bounding sphere. XYZ is the center and W is the radius */ - const Vector3& GetSize(BufferIndex bufferIndex) const + const Vector4& GetBoundingSphere() const { - return mSize[bufferIndex]; + if( mTransformId != INVALID_TRANSFORM_ID ) + { + return mTransformManager->GetBoundingSphere( mTransformId ); + } + + return Vector4::ZERO; } /** - * Set the world-matrix of a node, with scale + rotation + translation. - * Scale and rotation are centered at the origin. - * Translation is applied independently of the scale or rotatation axis. - * @param[in] updateBufferIndex The current update buffer index. - * @param[in] scale The scale. - * @param[in] rotation The rotation. - * @param[in] translation The translation. + * Retrieve world matrix and size of the node + * @param[out] The local to world matrix of the node + * @param[out] size The current size of the node */ - void SetWorldMatrix( BufferIndex updateBufferIndex, const Vector3& scale, const Quaternion& rotation, const Vector3& translation ) + void GetWorldMatrixAndSize( Matrix& worldMatrix, Vector3& size ) const { - mWorldMatrix.Get( updateBufferIndex ).SetTransformComponents( scale, rotation, translation ); - mWorldMatrix.SetDirty( updateBufferIndex ); + if( mTransformId != INVALID_TRANSFORM_ID ) + { + mTransformManager->GetWorldMatrixAndSize( mTransformId, worldMatrix, size ); + } } /** - * Retrieve the cached world-matrix of a node. - * @param[in] bufferIndex The buffer to read from. - * @return The world-matrix. + * Checks if local matrix has changed since last update + * @return true if local matrix has changed, false otherwise */ - const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const + bool IsLocalMatrixDirty() const { - return mWorldMatrix[ bufferIndex ]; + return (mTransformId != INVALID_TRANSFORM_ID) && + (mTransformManager->IsLocalMatrixDirty( mTransformId )); } /** - * Copy previous frames world matrix - * @param[in] updateBufferIndex The current update buffer index. + * Retrieve the cached world-matrix of a node. + * @param[in] bufferIndex The buffer to read from. + * @return The world-matrix. */ - void CopyPreviousWorldMatrix( BufferIndex updateBufferIndex ) + const Matrix& GetWorldMatrix( BufferIndex bufferIndex ) const { - mWorldMatrix.CopyPrevious( updateBufferIndex ); + return mWorldMatrix.Get(bufferIndex); } /** @@ -935,29 +696,80 @@ public: return mDrawMode; } + /* + * Returns the transform id of the node + * @return The transform component id of the node + */ + TransformId GetTransformId() const + { + return mTransformId; + } + /** * Equality operator, checks for identity, not values. - * + * @param[in] */ bool operator==( const Node* rhs ) const { - if ( this == rhs ) + return ( this == rhs ); + } + + /** + * @brief Sets the sibling order of the node + * @param[in] order The new order + */ + void SetDepthIndex( uint32_t depthIndex ) + { + mDepthIndex = depthIndex; + } + + /** + * @brief Get the depth index of the node + * @return Current depth index + */ + uint32_t GetDepthIndex() const + { + return mDepthIndex; + } + + /** + * @brief Sets the boolean which states whether the position should use the anchor-point. + * @param[in] positionUsesAnchorPoint True if the position should use the anchor-point + */ + void SetPositionUsesAnchorPoint( bool positionUsesAnchorPoint ) + { + if( mTransformId != INVALID_TRANSFORM_ID && mPositionUsesAnchorPoint != positionUsesAnchorPoint ) { - return true; + mPositionUsesAnchorPoint = positionUsesAnchorPoint; + mTransformManager->SetPositionUsesAnchorPoint( mTransformId, mPositionUsesAnchorPoint ); } - return false; } - unsigned short GetDepth() const + /** + * @brief Sets whether the node is culled or not. + * @param[in] bufferIndex The buffer to read from. + * @param[in] culled True if the node is culled. + */ + void SetCulled( BufferIndex bufferIndex, bool culled ) + { + mCulled[bufferIndex] = culled; + } + + /** + * @brief Retrieves whether the node is culled or not. + * @param[in] bufferIndex The buffer to read from. + * @return True if the node is culled. + */ + bool IsCulled( BufferIndex bufferIndex ) const { - return mDepth; + return mCulled[bufferIndex]; } public: /** * @copydoc UniformMap::Add */ - void AddUniformMapping( UniformPropertyMapping* map ); + void AddUniformMapping( OwnerPointer< UniformPropertyMapping >& map ); /** * @copydoc UniformMap::Remove @@ -971,40 +783,56 @@ public: */ void PrepareRender( BufferIndex bufferIndex ); + /** + * Called by UpdateManager when the node is added. + * Creates a new transform component in the transform manager and initialize all the properties + * related to the transformation + * @param[in] transformManager A pointer to the trnasform manager (Owned by UpdateManager) + */ + void CreateTransform( SceneGraph::TransformManager* transformManager ); + + /** + * Reset dirty flags + */ + void ResetDirtyFlags( BufferIndex updateBufferIndex ); + protected: /** * Set the parent of a Node. * @param[in] parentNode the new parent. */ - void SetParent(Node& parentNode); + void SetParent( Node& parentNode ); + +protected: /** * Protected constructor; See also Node::New() */ Node(); + /** + * Protected virtual destructor; See also Node::Delete( Node* ) + * Kept protected to allow destructor chaining from layer + */ + virtual ~Node(); + private: // from NodeDataProvider /** * @copydoc NodeDataProvider::GetModelMatrix */ - virtual const Matrix& GetModelMatrix( unsigned int bufferId ) const + virtual const Matrix& GetModelMatrix( BufferIndex bufferIndex ) const { - return GetWorldMatrix( bufferId ); + return GetWorldMatrix( bufferIndex ); } /** * @copydoc NodeDataProvider::GetRenderColor */ - virtual const Vector4& GetRenderColor( unsigned int bufferId ) const + virtual const Vector4& GetRenderColor( BufferIndex bufferIndex ) const { - return GetWorldColor( bufferId ); - } - - virtual const Vector3& GetRenderSize( unsigned int bufferId ) const - { - return GetSize( bufferId ); + return GetWorldColor( bufferIndex ); } public: // From UniformMapDataProvider @@ -1033,65 +861,65 @@ private: Node& operator=(const Node& rhs); /** - * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties() - */ - virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ); - - /** * Recursive helper to disconnect a Node and its children. * Disconnected Nodes have no parent or children. * @param[in] updateBufferIndex The current update buffer index. - * @param[in] connectedNodes Disconnected Node attachments should be removed from here. - * @param[in] disconnectedNodes Disconnected Node attachments should be added here. */ - void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex, std::set& connectedNodes, std::set& disconnectedNodes ); + void RecursiveDisconnectFromSceneGraph( BufferIndex updateBufferIndex ); public: // Default properties - PropertyVector3 mParentOrigin; ///< Local transform; the position is relative to this. Sets the TransformFlag dirty when changed - PropertyVector3 mAnchorPoint; ///< Local transform; local center of rotation. Sets the TransformFlag dirty when changed + TransformManager* mTransformManager; + TransformId mTransformId; + TransformManagerPropertyVector3 mParentOrigin; ///< Local transform; the position is relative to this. Sets the Transform flag dirty when changed + TransformManagerPropertyVector3 mAnchorPoint; ///< Local transform; local center of rotation. Sets the Transform flag dirty when changed + TransformManagerPropertyVector3 mSize; ///< Size is provided for layouting + TransformManagerPropertyVector3 mPosition; ///< Local transform; distance between parent-origin & anchor-point + TransformManagerPropertyQuaternion mOrientation; ///< Local transform; rotation relative to parent node + TransformManagerPropertyVector3 mScale; ///< Local transform; scale relative to parent node - AnimatableProperty mSize; ///< Size is provided for layouting - AnimatableProperty mPosition; ///< Local transform; distance between parent-origin & anchor-point - AnimatableProperty mOrientation; ///< Local transform; rotation relative to parent node - AnimatableProperty mScale; ///< Local transform; scale relative to parent node - AnimatableProperty mVisible; ///< Visibility can be inherited from the Node hierachy - AnimatableProperty mColor; ///< Color can be inherited from the Node hierarchy + AnimatableProperty mVisible; ///< Visibility can be inherited from the Node hierachy + AnimatableProperty mCulled; ///< True if the node is culled. This is not animatable. It is just double-buffered. + AnimatableProperty mColor; ///< Color can be inherited from the Node hierarchy // Inherited properties; read-only from public API - InheritedVector3 mWorldPosition; ///< Full inherited position - InheritedQuaternion mWorldOrientation; ///< Full inherited orientation - InheritedVector3 mWorldScale; ///< Full inherited scale - InheritedMatrix mWorldMatrix; ///< Full inherited world matrix - InheritedColor mWorldColor; ///< Full inherited color + TransformManagerVector3Input mWorldPosition; ///< Full inherited position + TransformManagerVector3Input mWorldScale; + TransformManagerQuaternionInput mWorldOrientation; ///< Full inherited orientation + TransformManagerMatrixInput mWorldMatrix; ///< Full inherited world matrix + InheritedColor mWorldColor; ///< Full inherited color + + uint32_t mClippingSortModifier; ///< Contains bit-packed clipping information for quick access when sorting + const uint32_t mId; ///< The Unique ID of the node. protected: - Node* mParent; ///< Pointer to parent node (a child is owned by its parent) - RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask + static uint32_t mNodeCounter; ///< count of total nodes, used for unique ids - NodeAttachmentOwner mAttachment; ///< Optional owned attachment - RendererContainer mRenderer; ///< Container of renderers; not owned + Node* mParent; ///< Pointer to parent node (a child is owned by its parent) + RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask - NodeContainer mChildren; ///< Container of children; not owned + RendererContainer mRenderer; ///< Container of renderers; not owned - CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps of the node - unsigned int mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame - unsigned int mRegenerateUniformMap : 2; ///< Indicate if the uniform map has to be regenerated this frame + NodeContainer mChildren; ///< Container of children; not owned - // flags, compressed to bitfield - unsigned short mDepth: 12; ///< Depth in the hierarchy - int mDirtyFlags:8; ///< A composite set of flags for each of the Node properties + CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps of the node + uint32_t mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame + uint32_t mClippingDepth; ///< The number of stencil clipping nodes deep this node is + uint32_t mScissorDepth; ///< The number of scissor clipping nodes deep this node is - bool mIsRoot:1; ///< True if the node cannot have a parent - bool mInheritOrientation:1; ///< Whether the parent's orientation should be inherited. - bool mInheritScale:1; ///< Whether the parent's scale should be inherited. - bool mIsActive:1; ///< When a Node is marked "active" it has been disconnected, and its properties have not been modified + uint32_t mDepthIndex; ///< Depth index of the node - DrawMode::Type mDrawMode:2; ///< How the Node and its children should be drawn - PositionInheritanceMode mPositionInheritanceMode:2;///< Determines how position is inherited, 2 bits is enough - ColorMode mColorMode:2; ///< Determines whether mWorldColor is inherited, 2 bits is enough + // flags, compressed to bitfield + NodePropertyFlags mDirtyFlags; ///< Dirty flags for each of the Node properties + uint32_t mRegenerateUniformMap:2; ///< Indicate if the uniform map has to be regenerated this frame + DrawMode::Type mDrawMode:3; ///< How the Node and its children should be drawn + ColorMode mColorMode:3; ///< Determines whether mWorldColor is inherited, 2 bits is enough + ClippingMode::Type mClippingMode:3; ///< The clipping mode of this node + bool mIsRoot:1; ///< True if the node cannot have a parent + bool mIsLayer:1; ///< True if the node is a layer + bool mPositionUsesAnchorPoint:1; ///< True if the node should use the anchor-point when calculating the position // Changes scope, should be at end of class DALI_LOG_OBJECT_STRING_DECLARATION; @@ -1104,7 +932,7 @@ inline void SetInheritOrientationMessage( EventThreadServices& eventThreadServic typedef MessageValue1< Node, bool > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit ); @@ -1115,7 +943,7 @@ inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, co typedef MessageValue1< Node, Vector3 > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value new (slot) LocalType( &node, &Node::SetParentOrigin, origin ); @@ -1126,21 +954,21 @@ inline void SetAnchorPointMessage( EventThreadServices& eventThreadServices, con typedef MessageValue1< Node, Vector3 > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value new (slot) LocalType( &node, &Node::SetAnchorPoint, anchor ); } -inline void SetPositionInheritanceModeMessage( EventThreadServices& eventThreadServices, const Node& node, PositionInheritanceMode mode ) +inline void SetInheritPositionMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit ) { - typedef MessageValue1< Node, PositionInheritanceMode > LocalType; + typedef MessageValue1< Node, bool > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &node, &Node::SetPositionInheritanceMode, mode ); + new (slot) LocalType( &node, &Node::SetInheritPosition, inherit ); } inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, const Node& node, bool inherit ) @@ -1148,7 +976,7 @@ inline void SetInheritScaleMessage( EventThreadServices& eventThreadServices, co typedef MessageValue1< Node, bool > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value new (slot) LocalType( &node, &Node::SetInheritScale, inherit ); @@ -1159,7 +987,7 @@ inline void SetColorModeMessage( EventThreadServices& eventThreadServices, const typedef MessageValue1< Node, ColorMode > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value new (slot) LocalType( &node, &Node::SetColorMode, colorMode ); @@ -1170,37 +998,87 @@ inline void SetDrawModeMessage( EventThreadServices& eventThreadServices, const typedef MessageValue1< Node, DrawMode::Type > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value new (slot) LocalType( &node, &Node::SetDrawMode, drawMode ); } -inline void AddRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer ) +inline void AttachRendererMessage( EventThreadServices& eventThreadServices, const Node& node, const Renderer& renderer ) { typedef MessageValue1< Node, Renderer* > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &node, &Node::AddRenderer, renderer ); + new (slot) LocalType( &node, &Node::AddRenderer, const_cast( &renderer ) ); } -inline void RemoveRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer ) +inline void DetachRendererMessage( EventThreadServices& eventThreadServices, const Node& node, const Renderer& renderer ) { - typedef MessageValue1< Node, Renderer* > LocalType; + typedef MessageValue1< Node, const Renderer* > LocalType; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &node, &Node::RemoveRenderer, &renderer ); +} + +inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Node& node, uint32_t depthIndex ) +{ + typedef MessageValue1< Node, uint32_t > LocalType; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &node, &Node::SetDepthIndex, depthIndex ); +} + +inline void SetClippingModeMessage( EventThreadServices& eventThreadServices, const Node& node, ClippingMode::Type clippingMode ) +{ + typedef MessageValue1< Node, ClippingMode::Type > LocalType; + + // Reserve some memory inside the message queue + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + + // Construct message in the message queue memory; note that delete should not be called on the return value + new (slot) LocalType( &node, &Node::SetClippingMode, clippingMode ); +} + +inline void SetPositionUsesAnchorPointMessage( EventThreadServices& eventThreadServices, const Node& node, bool positionUsesAnchorPoint ) +{ + typedef MessageValue1< Node, bool > LocalType; // Reserve some memory inside the message queue - unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); + uint32_t* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) ); // Construct message in the message queue memory; note that delete should not be called on the return value - new (slot) LocalType( &node, &Node::RemoveRenderer, renderer ); + new (slot) LocalType( &node, &Node::SetPositionUsesAnchorPoint, positionUsesAnchorPoint ); } + } // namespace SceneGraph +// Template specialisation for OwnerPointer, because delete is protected +template <> +inline void OwnerPointer::Reset() +{ + if (mObject != NULL) + { + Dali::Internal::SceneGraph::Node::Delete(mObject); + mObject = NULL; + } +} } // namespace Internal +// Template specialisations for OwnerContainer, because delete is protected +template <> +inline void OwnerContainer::Delete( Dali::Internal::SceneGraph::Node* pointer ) +{ + Dali::Internal::SceneGraph::Node::Delete(pointer); +} } // namespace Dali -#endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_H_ +#endif // DALI_INTERNAL_SCENE_GRAPH_NODE_H