ca8b913a403dc7e997afda042d3d765ae10b586f
[platform/core/uifw/dali-core.git] / dali / public-api / rendering / property-buffer.h
1 #ifndef DALI_PROPERTY_BUFFER_H
2 #define DALI_PROPERTY_BUFFER_H
3
4 /*
5  * Copyright (c) 2018 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  *
61  *  // Create the geometry object
62  *  Geometry texturedQuadGeometry = Geometry::New();
63  *  texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
64  *  texturedQuadGeometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0] );
65  *
66  * @SINCE_1_1.43
67  */
68 class DALI_CORE_API PropertyBuffer : public BaseHandle
69 {
70 public:
71
72   /**
73    * @brief Creates a PropertyBuffer.
74    * Static property buffers use less memory.
75    *
76    * @SINCE_1_1.43
77    * @param[in] bufferFormat Map of names and types that describes the components of the buffer
78    * @return Handle to a newly allocated PropertyBuffer
79    */
80   static PropertyBuffer New( Dali::Property::Map& bufferFormat );
81
82   /**
83    * @brief Default constructor, creates an empty handle.
84    *
85    * @SINCE_1_1.43
86    */
87   PropertyBuffer();
88
89   /**
90    * @brief Destructor.
91    *
92    * @SINCE_1_1.43
93    */
94   ~PropertyBuffer();
95
96   /**
97    * @brief Copy constructor, creates a new handle to the same object.
98    *
99    * @SINCE_1_1.43
100    * @param[in] handle Handle to an object
101    */
102   PropertyBuffer( const PropertyBuffer& handle );
103
104   /**
105    * @brief Downcasts to a property buffer handle.
106    * If not, a property buffer the returned property buffer handle is left uninitialized.
107    *
108    * @SINCE_1_1.43
109    * @param[in] handle Handle to an object
110    * @return Property buffer handle or an uninitialized handle
111    */
112   static PropertyBuffer DownCast( BaseHandle handle );
113
114   /**
115    * @brief Assignment operator, changes this handle to point at the same object.
116    *
117    * @SINCE_1_1.43
118    * @param[in] handle Handle to an object
119    * @return Reference to the assigned object
120    */
121   PropertyBuffer& operator=( const PropertyBuffer& handle );
122
123   /**
124    * @brief Updates the whole buffer information.
125    *
126    * This function expects a pointer to an array of structures with the same
127    * format that was given in the construction, and the number of elements to
128    * be the same as the size of the buffer.
129    *
130    * If the initial structure was: { { "position", VECTOR3}, { "uv", VECTOR2 } }
131    * and a size of 10 elements, this function should be called with a pointer equivalent to:
132    * <pre>
133    * struct Vertex {
134    *   Dali::Vector3 position;
135    *   Dali::Vector2 uv;
136    * };
137    * Vertex vertices[ 10 ] = { ... };
138    * propertyBuffer.SetData( vertices );
139    * </pre>
140    *
141    * @SINCE_1_1.43
142    * @param[in] data A pointer to the data that will be copied to the buffer
143    * @param[in] size Number of elements to expand or contract the buffer
144    */
145   void SetData( const void* data, std::size_t size );
146
147   /**
148    * @brief Gets the number of elements in the buffer.
149    *
150    * @SINCE_1_1.43
151    * @return Number of elements to expand or contract the buffer
152    */
153   std::size_t GetSize() const;
154
155 public:
156
157   /**
158    * @brief The constructor.
159    * @note  Not intended for application developers.
160    * @SINCE_1_1.43
161    * @param[in] pointer A pointer to a newly allocated PropertyBuffer
162    */
163   explicit DALI_INTERNAL PropertyBuffer( Internal::PropertyBuffer* pointer );
164 };
165
166 } // namespace Dali
167
168 #endif // DALI_PROPERTY_BUFFER_H