2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/event/modeling/mesh-impl.h>
25 #include <dali/public-api/math/matrix.h>
26 #include <dali/public-api/geometry/mesh.h>
27 #include <dali/integration-api/platform-abstraction.h>
28 #include <dali/internal/event/common/thread-local-storage.h>
29 #include <dali/internal/event/modeling/material-impl.h>
30 #include <dali/internal/update/modeling/scene-graph-mesh.h>
31 #include <dali/internal/update/manager/update-manager.h>
32 #include <dali/internal/update/modeling/internal-mesh-data.h>
39 MeshIPtr Mesh::New( const Dali::MeshData& meshData, bool discardable, bool scalingRequired )
41 MeshIPtr mesh( new Mesh( meshData, discardable, scalingRequired ) );
46 Mesh::Mesh( const Dali::MeshData& publicMeshData, bool discardable, bool scalingRequired )
47 : mBoneContainer( publicMeshData.GetBones() )
49 ThreadLocalStorage tls = ThreadLocalStorage::Get();
50 ResourceClient& resourceClient = tls.GetResourceClient();
51 ResourcePolicy::DataRetention dataRetentionPolicy = resourceClient.GetResourceDataRetentionPolicy();
53 ResourcePolicy::Discardable discard = ResourcePolicy::DISCARD;
54 if( ! (dataRetentionPolicy == ResourcePolicy::DALI_DISCARDS_ALL_DATA) ||
57 discard = ResourcePolicy::RETAIN;
60 // Copy the mesh-data into an internal structure, and pass ownership to the resourceClient
61 OwnerPointer<MeshData> meshDataPtr( new MeshData( publicMeshData, discard, scalingRequired ) );
62 const ResourceTicketPtr& ticket = resourceClient.AllocateMesh( meshDataPtr );
64 mTicket = ticket.Get();
65 mTicket->AddObserver( *this );
67 Dali::Material materialHandle( publicMeshData.GetMaterial() );
68 Material& material( GetImplementation( materialHandle ) );
69 mMaterial = &material;
74 mTicket->RemoveObserver(*this);
77 ResourceId Mesh::GetResourceId() const
79 return mTicket->GetId();
82 MaterialIPtr Mesh::GetMaterial() const
87 const BoneContainer& Mesh::GetBones() const
89 return mBoneContainer;
92 void Mesh::UpdateMeshData( const Dali::MeshData& meshData )
94 DALI_ASSERT_DEBUG(meshData.GetFaceCount());
96 ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
97 resourceClient.UpdateMesh( mTicket, meshData );
100 void Mesh::ResourceLoadingFailed(const ResourceTicket& ticket)
102 // This class is for programmatic meshes defined by the application
103 // and is not currently used by the model resource loader
106 void Mesh::ResourceLoadingSucceeded(const ResourceTicket& ticket)
108 // This class is for programmatic meshes defined by the application
109 // and is not currently used by the model resource loader
112 void Mesh::ResourceUploaded(const ResourceTicket& ticket)
116 void Mesh::ResourceSavingSucceeded( const ResourceTicket& ticket )
121 void Mesh::ResourceSavingFailed( const ResourceTicket& ticket )
126 } // namespace Internal