Move new mesh API to devel-api
[platform/core/uifw/dali-core.git] / dali / devel-api / object / property-buffer.h
1 #ifndef DALI_PROPERTY_BUFFER_H
2 #define DALI_PROPERTY_BUFFER_H
3
4 /*
5  * Copyright (c) 2015 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 // EXTERNAL INCLUDES
22 #include <cstddef> // std::size_t
23 #include <string> // std::string
24
25 // INTERNAL INCLUDES
26 #include <dali/public-api/object/handle.h> // Dali::Handle
27 #include <dali/public-api/object/property.h> // Dali::Property::Index
28 #include <dali/public-api/object/property-index-ranges.h> // DEFAULT_DERIVED_HANDLE_PROPERTY_START_INDEX
29 #include <dali/public-api/object/property-map.h> // Dali::Property::Map
30
31 namespace Dali
32 {
33
34 namespace Internal DALI_INTERNAL
35 {
36 class PropertyBuffer;
37 }
38
39 /**
40  * @brief PropertyBuffer is a handle to an object that contains a buffer of structured properties
41  *
42  * PropertyBuffers can be used to provide data to Geometry objects.
43  *
44  * Example:
45  *
46  *  const float halfQuadSize = .5f;
47  *  struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; };
48  *  TexturedQuadVertex texturedQuadVertexData[4] = {
49  *    { Vector2(-halfQuadSize, -halfQuadSize), Vector2(0.f, 0.f) },
50  *    { Vector2( halfQuadSize, -halfQuadSize), Vector2(1.f, 0.f) },
51  *    { Vector2(-halfQuadSize,  halfQuadSize), Vector2(0.f, 1.f) },
52  *    { Vector2( halfQuadSize,  halfQuadSize), Vector2(1.f, 1.f) } };
53  *
54  *  Property::Map texturedQuadVertexFormat;
55  *  texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
56  *  texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2;
57  *  PropertyBuffer texturedQuadVertices = PropertyBuffer::New( texturedQuadVertexFormat, 4 );
58  *  texturedQuadVertices.SetData(texturedQuadVertexData);
59  *
60  *  // Create indices
61  *  unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 };
62  *  Property::Map indexFormat;
63  *  indexFormat["indices"] = Property::UNSIGNED_INTEGER;
64  *  PropertyBuffer indices = PropertyBuffer::New( indexFormat, 6 );
65  *  indices.SetData(indexData);
66  *
67  *  // Create the geometry object
68  *  Geometry texturedQuadGeometry = Geometry::New();
69  *  texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
70  *  texturedQuadGeometry.SetIndexBuffer( indices );
71  *
72  */
73 class DALI_IMPORT_API PropertyBuffer : public Handle
74 {
75 public:
76
77   /**
78    * @brief An enumeration of properties belonging to the PropertyBuffer class.
79    */
80   struct Property
81   {
82     enum
83     {
84       SIZE = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "size",           type UNSIGNED_INT
85       BUFFER_FORMAT,                              ///< name "buffer-format",  type MAP
86     };
87   };
88
89   /**
90    * @brief Create a PropertyBuffer
91    *
92    * Static property buffers use less memory.
93    *
94    * @param[in] bufferFormat Map of names and types that describes the components of the buffer
95    * @param[in] size The number of elements in the property buffer
96    * @return Handle to a newly allocated PropertyBuffer
97    */
98   static PropertyBuffer New( Dali::Property::Map& bufferFormat, std::size_t size );
99
100   /**
101    * @brief Default constructor, creates an empty handle
102    */
103   PropertyBuffer();
104
105   /**
106    * @brief Destructor
107    */
108   ~PropertyBuffer();
109
110   /**
111    * @brief Copy constructor, creates a new handle to the same object
112    *
113    * @param[in] handle Handle to an object
114    */
115   PropertyBuffer( const PropertyBuffer& handle );
116
117   /**
118    * @brief Downcast to a property buffer handle.
119    *
120    * If not a property buffer the returned property buffer handle is left uninitialized.
121    * @param[in] handle to an object
122    * @return property buffer handle or an uninitialized handle
123    */
124   static PropertyBuffer DownCast( BaseHandle handle );
125
126   /**
127    * @brief Assignment operator, changes this handle to point at the same object
128    *
129    * @param[in] handle Handle to an object
130    * @return Reference to the assigned object
131    */
132   PropertyBuffer& operator=( const PropertyBuffer& handle );
133
134   /**
135    * @brief Set the number of elements in the buffer
136    *
137    * Calling this function is equivalent to setting the property SIZE
138    *
139    * @param[in] size Number of elements to expand or contract the buffer
140    */
141   void SetSize( std::size_t size );
142
143   /**
144    * @brief Get the number of elements in the buffer
145    *
146    * @return Number of elements to expand or contract the buffer
147    */
148   std::size_t GetSize() const;
149
150   /**
151    * @brief Update the whole buffer information
152    *
153    * This function expects a pointer to an array of structures with the same
154    * format that was given in the construction, and the number of elements to
155    * be the sane as the size of the buffer.
156    *
157    * If the initial structure was: { { "position", VECTOR3}, { "uv", VECTOR2 } }
158    * and a size of 10 elements, this function should be called with a pointer equivalent to:
159    * <pre>
160    * struct Vertex {
161    *   Dali::Vector3 position;
162    *   Dali::Vector2 uv;
163    * };
164    * Vertex vertices[ 10 ] = { ... };
165    * propertyBuffer.SetData( vertices );
166    * </pre>
167    *
168    * @param[in] data A pointer to the data that will be copied to the buffer.
169    */
170   void SetData( void* data );
171
172 public:
173   /**
174    * @brief The constructor
175    *
176    * @param [in] pointer A pointer to a newly allocated PropertyBuffer
177    */
178   explicit DALI_INTERNAL PropertyBuffer( Internal::PropertyBuffer* pointer );
179 };
180
181 } // namespace Dali
182
183 #endif // DALI_PROPERTY_BUFFER_H