1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_MESH_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_MESH_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/public-api/object/ref-object.h>
22 #include <dali/internal/common/buffer-index.h>
23 #include <dali/internal/common/message.h>
24 #include <dali/internal/update/nodes/node.h>
25 #include <dali/internal/update/modeling/internal-mesh-data.h>
26 #include <dali/internal/render/gl-resources/gpu-buffer.h>
27 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
28 #include <dali/internal/update/resources/resource-manager-declarations.h>
29 #include <dali/internal/update/modeling/scene-graph-mesh-declarations.h>
40 class PostProcessResourceDispatcher;
44 * Mesh resources consist of vertices, face indices and normals; they are shared (weakly referenced) by Nodes.
46 class Mesh : public GlResourceOwner
57 * Create a new scene graph mesh.
58 * @param[in] id The resource ID of the mesh
59 * @param[in] postProcessResourceDispatcher The dispatcher
60 * @param[in] meshData The mesh data
61 * @return A smart-pointer to the newly allocated Mesh.
63 static Mesh* New( ResourceId id,
64 PostProcessResourceDispatcher& postProcessResourceDispatcher,
67 return new Mesh( id, postProcessResourceDispatcher, meshData );
77 * @pre Should only be called in the update thread
78 * @param[in] meshData The mesh data
80 void SetMeshData( MeshData* meshData );
84 * The caller can modify this data. If they do, they should call
85 * MeshDataUpdated() when finished. This should only be done in the update thread.
86 * @param[in] threadBuffer indicates what buffer should be returned
89 MeshData& GetMeshData( ThreadBuffer threadBuffer );
93 * @param[in] threadBuffer indicates what buffer should be returned
96 const MeshData& GetMeshData( ThreadBuffer threadBuffer ) const;
99 * The mesh data has been updated. Allows the renderer to update
100 * the vertex buffer objects the next time they are needed.
101 * @param[in] bufferIndex to be used in double buffered values.
102 * @param[in] threadBuffer indicates what buffer should be used
103 * @param[in] meshData The mesh data ownership is passed in through a message, if threadBuffer is UPDATE it should be NULL
105 void MeshDataUpdated( BufferIndex bufferIndex, ThreadBuffer threadBuffer, MeshData* meshData );
108 * Sends the vertex data to GL
109 * @pre this function should only be called from the render thread
110 * @param[in] context The GL context.
111 * @param[in] renderBufferIndex The index that should be accessed in double buffered values.
113 void UploadVertexData( Context& context, BufferIndex renderBufferIndex );
116 * Bind the vertex and index buffers.
117 * @pre this function should only be called from the render thread
118 * @param[in] context The GL context.
120 void BindBuffers( Context& context );
123 * Get the number of face / line indices. (Note, this is not the number of faces)
124 * @param[in] threadBuffer indicates what buffer should be used
125 * @return the number of indices
127 size_t GetFaceIndexCount( ThreadBuffer threadBuffer ) const;
131 * @param[in] threadBuffer indicates what buffer should be used
132 * @return true if there is any geometry
134 bool HasGeometry( ThreadBuffer threadBuffer ) const;
136 public: // from GlResourceOwner
139 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
141 virtual void GlContextDestroyed();
144 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
146 virtual void GlCleanup();
151 * Private constructor; see also Mesh::New()
154 PostProcessResourceDispatcher& postProcessResourceDispatcher,
155 MeshData* meshData );
161 Mesh& operator=(const Mesh& rhs);
165 ResourceId mResourceId;
168 * The mUpdateMeshData will point to a mesh data that was just received
169 * or to the MeshData pointed by mRenderMeshData if it's more that one frame old
171 MeshData* mUpdateMeshData; ///< Pointer to MeshData object
172 OwnerPointer<MeshData> mRenderMeshData; ///< Owner of the MeshData Object
174 bool mRefreshVertexBuffer; ///< True when GpuBuffers need updating
175 OwnerPointer<GpuBuffer> mVertexBuffer; ///< Vertex buffer
176 OwnerPointer<GpuBuffer> mIndicesBuffer; ///< Index buffer
178 size_t mNumberOfVertices; ///< Number of vertices
179 size_t mNumberOfFaces; ///< Number of faces
181 PostProcessResourceDispatcher& mPostProcessResourceDispatcher;
184 } // namespace SceneGraph
186 // value types used by messages
187 template <> struct ParameterType< SceneGraph::Mesh::ThreadBuffer >
188 : public BasicType< SceneGraph::Mesh::ThreadBuffer > {};
191 } // namespace Internal
195 #endif // __DALI_INTERNAL_SCENE_GRAPH_MESH_H__