Merge "Combine Internal::ProxyObject & Internal::Object" into tizen
[platform/core/uifw/dali-core.git] / dali / internal / event / modeling / mesh-impl.h
1 #ifndef __DALI_INTERNAL_MESH_H__
2 #define __DALI_INTERNAL_MESH_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/math/vector4.h>
24 #include <dali/public-api/geometry/mesh.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/object/handle.h>
27 #include <dali/internal/event/modeling/modeling-declarations.h>
28 #include <dali/internal/event/resources/resource-ticket.h>
29 #include <dali/internal/event/resources/resource-ticket-observer.h>
30 #include <dali/internal/event/resources/resource-client.h>
31 #include <dali/internal/update/modeling/scene-graph-mesh-declarations.h>
32
33 namespace Dali
34 {
35
36 class Matrix;
37 class MeshData;
38
39 namespace Internal
40 {
41
42 class Mesh;
43
44 namespace SceneGraph
45 {
46 class Mesh;
47 }
48
49
50 typedef std::vector<MeshIPtr>              MeshContainer;      ///< Container of Mesh pointers
51 typedef MeshContainer::iterator            MeshIter;           ///< iterator for Mesh container
52 typedef MeshContainer::const_iterator      MeshConstIter;      ///< const_iterator for Mesh container
53
54 typedef Dali::MeshData::VertexContainer    VertexContainer;
55 typedef Dali::MeshData::FaceIndex          FaceIndex;
56 typedef Dali::MeshData::FaceIndices        FaceIndices;
57
58
59 /**
60  * A single mesh in a 3D model
61  */
62 class Mesh : public BaseObject, public ResourceTicketObserver
63 {
64 public: // construction, destruction and initialisation
65
66   /**
67    * Create a new mesh.
68    * @param[in] meshData - data provided from public API.
69    * @param[in] discardable - If true mesh will be discardable after being uploaded to GL.
70    * @param[in] scalingRequired - True if this Mesh should be scaled to fit actor size.
71    * @return A smart-pointer to the newly allocated Mesh.
72    */
73   static MeshIPtr New( const Dali::MeshData& meshData, bool discardable, bool scalingRequired );
74
75 protected:
76
77   /**
78    * Construct a new Mesh.
79    * @param[in] meshData - data provided from public API.
80    * @param[in] discardable - If true mesh will be discardable after being uploaded to GL.
81    * @param[in] scalingRequired - True if this Mesh should be scaled to fit actor size.
82    */
83   Mesh( const Dali::MeshData& meshData, bool discardable, bool scalingRequired );
84
85   /**
86    * A reference counted object may only be deleted by calling Unreference()
87    */
88   virtual ~Mesh();
89
90 private:
91
92   // Undefined
93   Mesh(const Mesh&);
94
95   // Undefined
96   Mesh& operator=(const Mesh& rhs);
97
98 public:
99
100   /**
101    * @copydoc Dali::Mesh::SetData()
102    */
103   void SetData( const Dali::MeshData& meshData );
104
105   /**
106    * If the application changes it's mesh data, ensure the GL vertex data is updated
107    */
108   void Update();
109
110   /**
111    * returns the Id used for lookups
112    * @return the unique ID of the resource.
113    */
114   ResourceId GetResourceId() const;
115
116   /**
117    * Get the default material for this mesh.
118    * @return the default material for this mesh.
119    */
120   MaterialIPtr GetMaterial() const;
121
122   /**
123    * Get the container of bones associated with this mesh.
124    * @return the container of bones for the mesh.
125    */
126   const BoneContainer& GetBones() const;
127
128   /**
129    * @copydoc Dali::Mesh::UpdateMeshData()
130    */
131   void UpdateMeshData( const Dali::MeshData& meshData );
132
133 public: // From ResourceTicketObserver
134
135   /**
136    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingFailed()
137    */
138   virtual void ResourceLoadingFailed(const ResourceTicket& ticket);
139
140   /**
141    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingSucceeded()
142    */
143   virtual void ResourceLoadingSucceeded(const ResourceTicket& ticket);
144
145   /**
146    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceUploaded()
147    */
148   virtual void ResourceUploaded(const ResourceTicket& ticket);
149
150   /**
151    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceSavingSucceeded()
152    */
153   virtual void ResourceSavingSucceeded( const ResourceTicket& ticket );
154
155   /**
156    * @copydoc Dali::Internal::ResourceTicketObserver::ResourceSavingFailed()
157    */
158   virtual void ResourceSavingFailed( const ResourceTicket& ticket );
159
160 protected:
161
162   ResourceTicketPtr mTicket;
163
164   MaterialIPtr mMaterial;       /// Default material for this mesh
165   BoneContainer mBoneContainer;   /// List of bones that affect this mesh
166 };
167
168 } // namespace Internal
169
170 // Helpers for public-api forwarding methods
171
172 inline Internal::Mesh& GetImplementation(Dali::Mesh& mesh)
173 {
174   DALI_ASSERT_ALWAYS( mesh && "Mesh handle is empty" );
175
176   BaseObject& handle = mesh.GetBaseObject();
177
178   return static_cast<Internal::Mesh&>(handle);
179 }
180
181 inline const Internal::Mesh& GetImplementation(const Dali::Mesh& mesh)
182 {
183   DALI_ASSERT_ALWAYS( mesh && "Mesh handle is empty" );
184
185   const BaseObject& handle = mesh.GetBaseObject();
186
187   return static_cast<const Internal::Mesh&>(handle);
188 }
189
190 } // namespace Dali
191
192 #endif // __DALI_INTERNAL_MESH_H__