License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-core.git] / dali / internal / event / modeling / mesh-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/modeling/mesh-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <stdio.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/math/matrix.h>
26 #include <dali/public-api/geometry/mesh.h>
27 #include <dali/internal/event/common/thread-local-storage.h>
28 #include <dali/internal/event/modeling/material-impl.h>
29 #include <dali/internal/update/modeling/scene-graph-mesh.h>
30 #include <dali/internal/update/manager/update-manager.h>
31 #include <dali/internal/update/modeling/internal-mesh-data.h>
32
33 using namespace std;
34
35 namespace Dali
36 {
37 namespace Internal
38 {
39
40 MeshIPtr Mesh::New( const Dali::MeshData& meshData, bool discardable, bool scalingRequired )
41 {
42   MeshIPtr mesh( new Mesh( meshData, discardable, scalingRequired ) );
43
44   return mesh;
45 }
46
47 Mesh::Mesh( const Dali::MeshData& publicMeshData, bool discardable, bool scalingRequired )
48 : mBoneContainer( publicMeshData.GetBones() )
49 {
50   ResourceClient& resourceClient = ThreadLocalStorage::Get().GetResourceClient();
51
52   // Copy the mesh-data into an internal structure, and pass ownership to the resourceClient
53   OwnerPointer<MeshData> meshDataPtr( new MeshData( publicMeshData, discardable, scalingRequired ) );
54   const ResourceTicketPtr& ticket = resourceClient.AllocateMesh( meshDataPtr );
55
56   mTicket = ticket.Get();
57   mTicket->AddObserver( *this );
58
59   Dali::Material materialHandle( publicMeshData.GetMaterial() );
60   Material& material( GetImplementation( materialHandle ) );
61   mMaterial = &material;
62 }
63
64 Mesh::~Mesh()
65 {
66   mTicket->RemoveObserver(*this);
67 }
68
69 ResourceId Mesh::GetResourceId() const
70 {
71   return mTicket->GetId();
72 }
73
74 MaterialIPtr Mesh::GetMaterial() const
75 {
76   return mMaterial;
77 }
78
79 const BoneContainer& Mesh::GetBones() const
80 {
81   return mBoneContainer;
82 }
83
84 void Mesh::UpdateMeshData( const Dali::MeshData& meshData )
85 {
86   DALI_ASSERT_DEBUG(meshData.GetFaceCount());
87
88   ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
89   resourceClient.UpdateMesh( mTicket, meshData );
90 }
91
92 void Mesh::ResourceLoadingFailed(const ResourceTicket& ticket)
93 {
94   // This class is for programmatic meshes defined by the application
95   // and is not currently used by the model resource loader
96 }
97
98 void Mesh::ResourceLoadingSucceeded(const ResourceTicket& ticket)
99 {
100   // This class is for programmatic meshes defined by the application
101   // and is not currently used by the model resource loader
102 }
103
104 void Mesh::ResourceUploaded(const ResourceTicket& ticket)
105 {
106 }
107
108 void Mesh::ResourceSavingSucceeded( const ResourceTicket& ticket )
109 {
110   // do nothing
111 }
112
113 void Mesh::ResourceSavingFailed( const ResourceTicket& ticket )
114 {
115   // do nothing
116 }
117
118 } // namespace Internal
119
120 } // namespace Dali
121