1 #ifndef __DALI_INTERNAL_MESH_H__
2 #define __DALI_INTERNAL_MESH_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/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>
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
54 typedef Dali::MeshData::VertexContainer VertexContainer;
55 typedef Dali::MeshData::FaceIndex FaceIndex;
56 typedef Dali::MeshData::FaceIndices FaceIndices;
60 * A single mesh in a 3D model
62 class Mesh : public BaseObject, public ResourceTicketObserver
64 public: // construction, destruction and initialisation
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.
73 static MeshIPtr New( const Dali::MeshData& meshData, bool discardable, bool scalingRequired );
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.
83 Mesh( const Dali::MeshData& meshData, bool discardable, bool scalingRequired );
86 * A reference counted object may only be deleted by calling Unreference()
96 Mesh& operator=(const Mesh& rhs);
101 * @copydoc Dali::Mesh::SetData()
103 void SetData( const Dali::MeshData& meshData );
106 * If the application changes it's mesh data, ensure the GL vertex data is updated
111 * returns the Id used for lookups
112 * @return the unique ID of the resource.
114 ResourceId GetResourceId() const;
117 * Get the default material for this mesh.
118 * @return the default material for this mesh.
120 MaterialIPtr GetMaterial() const;
123 * Get the container of bones associated with this mesh.
124 * @return the container of bones for the mesh.
126 const BoneContainer& GetBones() const;
129 * @copydoc Dali::Mesh::UpdateMeshData()
131 void UpdateMeshData( const Dali::MeshData& meshData );
133 public: // From ResourceTicketObserver
136 * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingFailed()
138 virtual void ResourceLoadingFailed(const ResourceTicket& ticket);
141 * @copydoc Dali::Internal::ResourceTicketObserver::ResourceLoadingSucceeded()
143 virtual void ResourceLoadingSucceeded(const ResourceTicket& ticket);
146 * @copydoc Dali::Internal::ResourceTicketObserver::ResourceUploaded()
148 virtual void ResourceUploaded(const ResourceTicket& ticket);
151 * @copydoc Dali::Internal::ResourceTicketObserver::ResourceSavingSucceeded()
153 virtual void ResourceSavingSucceeded( const ResourceTicket& ticket );
156 * @copydoc Dali::Internal::ResourceTicketObserver::ResourceSavingFailed()
158 virtual void ResourceSavingFailed( const ResourceTicket& ticket );
162 ResourceTicketPtr mTicket;
164 MaterialIPtr mMaterial; /// Default material for this mesh
165 BoneContainer mBoneContainer; /// List of bones that affect this mesh
168 } // namespace Internal
170 // Helpers for public-api forwarding methods
172 inline Internal::Mesh& GetImplementation(Dali::Mesh& mesh)
174 DALI_ASSERT_ALWAYS( mesh && "Mesh handle is empty" );
176 BaseObject& handle = mesh.GetBaseObject();
178 return static_cast<Internal::Mesh&>(handle);
181 inline const Internal::Mesh& GetImplementation(const Dali::Mesh& mesh)
183 DALI_ASSERT_ALWAYS( mesh && "Mesh handle is empty" );
185 const BaseObject& handle = mesh.GetBaseObject();
187 return static_cast<const Internal::Mesh&>(handle);
192 #endif // __DALI_INTERNAL_MESH_H__