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 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/buffer-index.h>
23 #include <dali/internal/common/event-to-update.h>
24 #include <dali/internal/update/common/property-owner.h>
25 #include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
26 #include <dali/internal/update/modeling/bone-transforms.h>
27 #include <dali/internal/event/actor-attachments/mesh-attachment-impl.h>
28 #include <dali/internal/event/actors/mesh-actor-impl.h>
29 #include <dali/public-api/geometry/mesh.h>
30 #include <dali/public-api/math/matrix.h>
38 class ResourceManager;
48 * An attachment for rendering a mesh with a material.
50 class MeshAttachment : public RenderableAttachment, public PropertyOwner::Observer
54 typedef std::vector<Node*> BoneNodeContainer;
59 : meshResourceId( 0 ),
66 ResourceId meshResourceId;
67 SceneGraph::Mesh* mesh;
68 const SceneGraph::Material* material;
69 std::size_t boneCount;
70 BoneNodeContainer boneNodes;
74 * Construct a new MeshAttachment.
75 * @return a new MeshAttachment
77 static MeshAttachment* New();
82 virtual ~MeshAttachment();
85 * TODO: remove geometry scaling and this method can be gone
86 * @copydoc RenderableAttachment::ResolveVisibility
88 virtual bool ResolveVisibility( BufferIndex updateBufferIndex )
90 mHasSizeAndColorFlag = false;
91 const Vector4& color = mParent->GetWorldColor( updateBufferIndex );
92 if( color.a > FULLY_TRANSPARENT ) // not fully transparent
94 mHasSizeAndColorFlag = true;
96 return mHasSizeAndColorFlag;
100 * @copydoc RenderableAttachment::GetRenderer().
102 virtual Renderer& GetRenderer();
105 * @copydoc RenderableAttachment::GetRenderer().
107 virtual const Renderer& GetRenderer() const;
110 * @copydoc Dali::Internal::SceneGraph::RenderableAttachment::ShaderChanged()
112 virtual void ShaderChanged( BufferIndex updateBufferIndex );
115 * @copydoc RenderableAttachment::SizeChanged()
117 virtual void SizeChanged( BufferIndex updateBufferIndex );
120 * @copydoc Dali::Internal::SceneGraph::RenderableAttachment::DoPrepareRender()
122 virtual void DoPrepareRender( BufferIndex updateBufferIndex );
125 * @copydoc RenderableAttachment::IsFullyOpaque()
127 virtual bool IsFullyOpaque( BufferIndex updateBufferIndex );
130 * @copydoc Dali::Internal::SceneGraph::RenderableAttachment::DoGetScaleForSize()
132 virtual void DoGetScaleForSize( const Vector3& nodeSize, Vector3& scaling );
135 * Set the mesh to be rendererd by this attachment
136 * @param[in] meshId The resource id of the mesh
137 * @param[in] material The material
138 * @param[in] boneCount The bone count
140 void SetMesh( ResourceId meshId, const SceneGraph::Material* material, std::size_t boneCount );
143 * @copydoc Dali::Internal::MeshActor::SetMaterial(Material material)
145 void SetMaterial( const SceneGraph::Material* material );
148 * @copydoc Dali::Internal::MeshAttachment::SetAffectedByLighting(bool);
150 void SetAffectedByLighting( bool affectedByLighting );
153 * Set the node for the given mesh index and bone index
155 void SetBoneNode( Node* boneNode, size_t boneIdx, size_t boneCount );
158 * Calculate matrices for bones based on bone node transforms.
160 void CalculateBoneTransforms( BufferIndex updateBufferIndex,
162 const BoneNodeContainer& boneNodes,
163 BoneTransforms& boneTransforms );
167 * @copydoc PropertyOwner::Observer::PropertyOwnerDestroyed()
169 virtual void PropertyOwnerDestroyed( PropertyOwner& owner );
172 * @copydoc RenderableAttachment::ConnectToSceneGraph2()
174 virtual void ConnectToSceneGraph2( BufferIndex updateBufferIndex );
177 * @copydoc RenderableAttachment::OnDestroy2()
179 virtual void OnDestroy2();
182 * @copydoc Dali::Internal::SceneGraph::RenderableAttachment::DoPrepareResources()
184 virtual bool DoPrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
187 * Protected constructor. See New()
192 MeshAttachment(const MeshAttachment&);
195 MeshAttachment& operator=(const MeshAttachment& rhs);
199 MeshRenderer* mRenderer; ///< Raw-pointer to renderer that is owned by RenderManager
201 MeshMatBones mMesh; ///< The mesh used to prepare for rendering, with associated materials and bones
203 bool mAffectedByLighting:1; ///< lighting mode.
204 bool mLastLightingState:1; ///< lighting state used at the last update.
205 bool mLightInitialized:1; ///< whether the light state has been transmitted to the mesh renderer
209 // Messages for MeshAttachment
211 inline void SetMeshMessage( EventToUpdate& eventToUpdate, const MeshAttachment& attachment, ResourceId meshId, const Material* material, std::size_t boneCount )
213 typedef MessageValue3< MeshAttachment, ResourceId, const Material*, std::size_t > LocalType;
215 // Reserve some memory inside the message queue
216 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
218 // Construct message in the message queue memory; note that delete should not be called on the return value
219 new (slot) LocalType( &attachment, &MeshAttachment::SetMesh, meshId, material, boneCount );
222 inline void SetMaterialMessage( EventToUpdate& eventToUpdate, const MeshAttachment& attachment, const Material* material )
224 typedef MessageValue1< MeshAttachment, const Material* > LocalType;
226 // Reserve some memory inside the message queue
227 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
229 // Construct message in the message queue memory; note that delete should not be called on the return value
230 new (slot) LocalType( &attachment, &MeshAttachment::SetMaterial, material );
233 inline void SetAffectedByLightingMessage( EventToUpdate& eventToUpdate, const MeshAttachment& attachment, bool affectedByLighting )
235 typedef MessageValue1< MeshAttachment, bool > LocalType;
237 // Reserve some memory inside the message queue
238 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
240 // Construct message in the message queue memory; note that delete should not be called on the return value
241 new (slot) LocalType( &attachment, &MeshAttachment::SetAffectedByLighting, affectedByLighting );
244 inline void SetBoneNodeMessage( EventToUpdate& eventToUpdate, const MeshAttachment& attachment, Node* boneNode, size_t boneIdx, size_t boneCount )
246 typedef MessageValue3< MeshAttachment, Node*, size_t, size_t > LocalType;
248 // Reserve some memory inside the message queue
249 unsigned int* slot = eventToUpdate.ReserveMessageSlot( sizeof( LocalType ) );
251 // Construct message in the message queue memory; note that delete should not be called on the return value
252 new (slot) LocalType( &attachment, &MeshAttachment::SetBoneNode, boneNode, boneIdx, boneCount );
255 } // namespace SceneGraph
257 } // namespace Internal
261 #endif // __DALI_INTERNAL_SCENE_GRAPH_MESH_ATTACHMENT_H__