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