Merge "Combine Internal::ProxyObject & Internal::Object" into tizen
[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/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>
33
34 namespace Dali
35 {
36 namespace Internal
37 {
38
39 MeshIPtr Mesh::New( const Dali::MeshData& meshData, bool discardable, bool scalingRequired )
40 {
41   MeshIPtr mesh( new Mesh( meshData, discardable, scalingRequired ) );
42
43   return mesh;
44 }
45
46 Mesh::Mesh( const Dali::MeshData& publicMeshData, bool discardable, bool scalingRequired )
47 : mBoneContainer( publicMeshData.GetBones() )
48 {
49   ThreadLocalStorage tls = ThreadLocalStorage::Get();
50   ResourceClient& resourceClient = tls.GetResourceClient();
51   ResourcePolicy::DataRetention dataRetentionPolicy = resourceClient.GetResourceDataRetentionPolicy();
52
53   ResourcePolicy::Discardable discard = ResourcePolicy::DISCARD;
54   if( ! (dataRetentionPolicy == ResourcePolicy::DALI_DISCARDS_ALL_DATA) ||
55       ! discardable )
56   {
57     discard = ResourcePolicy::RETAIN;
58   }
59
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 );
63
64   mTicket = ticket.Get();
65   mTicket->AddObserver( *this );
66
67   Dali::Material materialHandle( publicMeshData.GetMaterial() );
68   Material& material( GetImplementation( materialHandle ) );
69   mMaterial = &material;
70 }
71
72 Mesh::~Mesh()
73 {
74   mTicket->RemoveObserver(*this);
75 }
76
77 ResourceId Mesh::GetResourceId() const
78 {
79   return mTicket->GetId();
80 }
81
82 MaterialIPtr Mesh::GetMaterial() const
83 {
84   return mMaterial;
85 }
86
87 const BoneContainer& Mesh::GetBones() const
88 {
89   return mBoneContainer;
90 }
91
92 void Mesh::UpdateMeshData( const Dali::MeshData& meshData )
93 {
94   DALI_ASSERT_DEBUG(meshData.GetFaceCount());
95
96   ResourceClient &resourceClient = ThreadLocalStorage::Get().GetResourceClient();
97   resourceClient.UpdateMesh( mTicket, meshData );
98 }
99
100 void Mesh::ResourceLoadingFailed(const ResourceTicket& ticket)
101 {
102   // This class is for programmatic meshes defined by the application
103   // and is not currently used by the model resource loader
104 }
105
106 void Mesh::ResourceLoadingSucceeded(const ResourceTicket& ticket)
107 {
108   // This class is for programmatic meshes defined by the application
109   // and is not currently used by the model resource loader
110 }
111
112 void Mesh::ResourceUploaded(const ResourceTicket& ticket)
113 {
114 }
115
116 void Mesh::ResourceSavingSucceeded( const ResourceTicket& ticket )
117 {
118   // do nothing
119 }
120
121 void Mesh::ResourceSavingFailed( const ResourceTicket& ticket )
122 {
123   // do nothing
124 }
125
126 } // namespace Internal
127
128 } // namespace Dali