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