1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_MESH_ATTACHMENT_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_MESH_ATTACHMENT_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/internal/common/buffer-index.h>
22 #include <dali/internal/common/event-to-update.h>
23 #include <dali/internal/update/common/property-owner.h>
24 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
25 #include <dali/internal/update/modeling/bone-transforms.h>
26 #include <dali/internal/event/actor-attachments/mesh-attachment-impl.h>
27 #include <dali/internal/event/actors/mesh-actor-impl.h>
28 #include <dali/public-api/geometry/mesh.h>
29 #include <dali/public-api/math/matrix.h>
37 class ResourceManager;
47 * An attachment for rendering a mesh with a material.
49 class MeshAttachment : public RenderableAttachment, public PropertyOwner::Observer
53 typedef std::vector<Node*> BoneNodeContainer;
58 : meshResourceId( 0 ),
65 ResourceId meshResourceId;
66 SceneGraph::Mesh* mesh;
67 const SceneGraph::Material* material;
68 std::size_t boneCount;
69 BoneNodeContainer boneNodes;
73 * Construct a new MeshAttachment.
74 * @return a new MeshAttachment
76 static MeshAttachment* New();
81 virtual ~MeshAttachment();
84 * TODO: remove geometry scaling and this method can be gone
85 * @copydoc RenderableAttachment::ResolveVisibility
87 virtual bool ResolveVisibility( BufferIndex updateBufferIndex )
89 mHasSizeAndColorFlag = false;
90 const Vector4& color = mParent->GetWorldColor( updateBufferIndex );
91 if( color.a > FULLY_TRANSPARENT ) // not fully transparent
93 mHasSizeAndColorFlag = true;
95 return mHasSizeAndColorFlag;
99 * @copydoc RenderableAttachment::GetRenderer().
101 virtual Renderer& GetRenderer();
104 * @copydoc RenderableAttachment::GetRenderer().
106 virtual const Renderer& GetRenderer() const;
109 * @copydoc Dali::Internal::SceneGraph::RenderableAttachment::ShaderChanged()
111 virtual void ShaderChanged( BufferIndex updateBufferIndex );
114 * @copydoc RenderableAttachment::SizeChanged()
116 virtual void SizeChanged( BufferIndex updateBufferIndex );
119 * @copydoc Dali::Internal::SceneGraph::RenderableAttachment::DoPrepareRender()
121 virtual void DoPrepareRender( BufferIndex updateBufferIndex );
124 * @copydoc RenderableAttachment::IsFullyOpaque()
126 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex );
129 * @copydoc Dali::Internal::SceneGraph::RenderableAttachment::DoGetScaleForSize()
131 virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
134 * Set the mesh to be rendererd by this attachment
135 * @param[in] meshId The resource id of the mesh
136 * @param[in] material The material
137 * @param[in] boneCount The bone count
139 void SetMesh( ResourceId meshId, const SceneGraph::Material* material, std::size_t boneCount );
142 * @copydoc Dali::Internal::MeshActor::SetMaterial(Material material)
144 void SetMaterial( const SceneGraph::Material* material );
147 * @copydoc Dali::Internal::MeshAttachment::SetAffectedByLighting(bool);
149 void SetAffectedByLighting( bool affectedByLighting );
152 * Set the node for the given mesh index and bone index
154 void SetBoneNode( Node* boneNode, size_t boneIdx, size_t boneCount );
157 * Calculate matrices for bones based on bone node transforms.
159 void CalculateBoneTransforms( BufferIndex updateBufferIndex,
161 const BoneNodeContainer& boneNodes,
162 BoneTransforms& boneTransforms );
166 * @copydoc PropertyOwner::Observer::PropertyOwnerDestroyed()
168 virtual void PropertyOwnerDestroyed( PropertyOwner& owner );
171 * @copydoc RenderableAttachment::ConnectToSceneGraph2()
173 virtual void ConnectToSceneGraph2( BufferIndex updateBufferIndex );
176 * @copydoc RenderableAttachment::OnDestroy2()
178 virtual void OnDestroy2();
181 * @copydoc Dali::Internal::SceneGraph::RenderableAttachment::DoPrepareResources()
183 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
186 * Protected constructor. See New()
191 MeshAttachment(const MeshAttachment&);
194 MeshAttachment& operator=(const MeshAttachment& rhs);
198 MeshRenderer* mRenderer; ///< Raw-pointer to renderer that is owned by RenderManager
200 MeshMatBones mMesh; ///< The mesh used to prepare for rendering, with associated materials and bones
202 bool mAffectedByLighting:1; ///< lighting mode.
203 bool mLastLightingState:1; ///< lighting state used at the last update.
204 bool mLightInitialized:1; ///< whether the light state has been transmitted to the mesh renderer
208 // Messages for MeshAttachment
210 inline void SetMeshMessage( EventToUpdate& eventToUpdate, const MeshAttachment& attachment, ResourceId meshId, const Material* material, std::size_t boneCount )
212 typedef MessageValue3< MeshAttachment, ResourceId, const Material*, std::size_t > LocalType;
214 // Reserve some memory inside the message queue
215 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
217 // Construct message in the message queue memory; note that delete should not be called on the return value
218 new (slot) LocalType( &attachment, &MeshAttachment::SetMesh, meshId, material, boneCount );
221 inline void SetMaterialMessage( EventToUpdate& eventToUpdate, const MeshAttachment& attachment, const Material* material )
223 typedef MessageValue1< MeshAttachment, const Material* > LocalType;
225 // Reserve some memory inside the message queue
226 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
228 // Construct message in the message queue memory; note that delete should not be called on the return value
229 new (slot) LocalType( &attachment, &MeshAttachment::SetMaterial, material );
232 inline void SetAffectedByLightingMessage( EventToUpdate& eventToUpdate, const MeshAttachment& attachment, bool affectedByLighting )
234 typedef MessageValue1< MeshAttachment, bool > LocalType;
236 // Reserve some memory inside the message queue
237 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
239 // Construct message in the message queue memory; note that delete should not be called on the return value
240 new (slot) LocalType( &attachment, &MeshAttachment::SetAffectedByLighting, affectedByLighting );
243 inline void SetBoneNodeMessage( EventToUpdate& eventToUpdate, const MeshAttachment& attachment, Node* boneNode, size_t boneIdx, size_t boneCount )
245 typedef MessageValue3< MeshAttachment, Node*, size_t, size_t > LocalType;
247 // Reserve some memory inside the message queue
248 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
250 // Construct message in the message queue memory; note that delete should not be called on the return value
251 new (slot) LocalType( &attachment, &MeshAttachment::SetBoneNode, boneNode, boneIdx, boneCount );
254 } // namespace SceneGraph
256 } // namespace Internal
260 #endif // __DALI_INTERNAL_SCENE_GRAPH_MESH_ATTACHMENT_H__