Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-core.git] / dali / internal / update / modeling / scene-graph-mesh.h
1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_MESH_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_MESH_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
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
10 //
11 //     http://floralicense.org/license/
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 // INTERNAL INCLUDES
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>
30
31 namespace Dali
32 {
33
34 namespace Internal
35 {
36
37 namespace SceneGraph
38 {
39
40 class PostProcessResourceDispatcher;
41 class Mesh;
42
43 /**
44  * Mesh resources consist of vertices, face indices and normals; they are shared (weakly referenced) by Nodes.
45  */
46 class Mesh : public GlResourceOwner
47 {
48 public:
49
50   enum ThreadBuffer
51   {
52     UPDATE_THREAD,
53     RENDER_THREAD
54   };
55
56   /**
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.
62    */
63   static Mesh* New( ResourceId id,
64                     PostProcessResourceDispatcher& postProcessResourceDispatcher,
65                     MeshData* meshData )
66   {
67     return new Mesh( id, postProcessResourceDispatcher, meshData );
68   }
69
70   /**
71    * Virtual destructor
72    */
73   virtual ~Mesh();
74
75   /**
76    * Set the mesh data
77    * @pre Should only be called in the update thread
78    * @param[in] meshData The mesh data
79    */
80   void SetMeshData( MeshData* meshData );
81
82   /**
83    * Get the mesh data.
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
87    * @return meshData.
88    */
89   MeshData& GetMeshData( ThreadBuffer threadBuffer );
90
91   /**
92    * Get the mesh data.
93    * @param[in] threadBuffer indicates what buffer should be returned
94    * @return meshData.
95    */
96   const MeshData& GetMeshData( ThreadBuffer threadBuffer ) const;
97
98   /**
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
104    */
105   void MeshDataUpdated( BufferIndex bufferIndex, ThreadBuffer threadBuffer, MeshData* meshData );
106
107   /**
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.
112    */
113   void UploadVertexData( Context& context, BufferIndex renderBufferIndex );
114
115   /**
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.
119    */
120   void BindBuffers( Context& context );
121
122   /**
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
126    */
127   size_t GetFaceIndexCount( ThreadBuffer threadBuffer ) const;
128
129   /**
130    * Returns a new
131    * @param[in] threadBuffer indicates what buffer should be used
132    * @return true if there is any geometry
133    **/
134   bool HasGeometry( ThreadBuffer threadBuffer ) const;
135
136 public: // from GlResourceOwner
137
138   /**
139    * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
140    */
141   virtual void GlContextDestroyed();
142
143   /**
144    * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
145    */
146   virtual void GlCleanup();
147
148 private:
149
150   /**
151    * Private constructor; see also Mesh::New()
152    */
153   Mesh( ResourceId id,
154         PostProcessResourceDispatcher& postProcessResourceDispatcher,
155         MeshData* meshData );
156
157   // Undefined
158   Mesh(const Mesh&);
159
160   // Undefined
161   Mesh& operator=(const Mesh& rhs);
162
163 protected:
164
165   ResourceId mResourceId;
166
167   /**
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
170    **/
171   MeshData* mUpdateMeshData;              ///< Pointer to MeshData object
172   OwnerPointer<MeshData> mRenderMeshData; ///< Owner of the MeshData Object
173
174   bool mRefreshVertexBuffer;              ///< True when GpuBuffers need updating
175   OwnerPointer<GpuBuffer> mVertexBuffer;  ///< Vertex buffer
176   OwnerPointer<GpuBuffer> mIndicesBuffer; ///< Index buffer
177
178   size_t     mNumberOfVertices;    ///< Number of vertices
179   size_t     mNumberOfFaces;       ///< Number of faces
180
181   PostProcessResourceDispatcher& mPostProcessResourceDispatcher;
182 };
183
184 } // namespace SceneGraph
185
186 // value types used by messages
187 template <> struct ParameterType< SceneGraph::Mesh::ThreadBuffer >
188 : public BasicType< SceneGraph::Mesh::ThreadBuffer > {};
189 class Context;
190
191 } // namespace Internal
192
193 } // namespace Dali
194
195 #endif // __DALI_INTERNAL_SCENE_GRAPH_MESH_H__