Remove Geometry scene object
[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  *
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  */
67 class DALI_IMPORT_API PropertyBuffer : public BaseHandle
68 {
69 public:
70
71   /**
72    * @brief Create a PropertyBuffer
73    *
74    * Static property buffers use less memory.
75    *
76    * @param[in] bufferFormat Map of names and types that describes the components of the buffer
77    * @return Handle to a newly allocated PropertyBuffer
78    */
79   static PropertyBuffer New( Dali::Property::Map& bufferFormat );
80
81   /**
82    * @brief Default constructor, creates an empty handle
83    */
84   PropertyBuffer();
85
86   /**
87    * @brief Destructor
88    */
89   ~PropertyBuffer();
90
91   /**
92    * @brief Copy constructor, creates a new handle to the same object
93    *
94    * @param[in] handle Handle to an object
95    */
96   PropertyBuffer( const PropertyBuffer& handle );
97
98   /**
99    * @brief Downcast to a property buffer handle.
100    *
101    * If not a property buffer the returned property buffer handle is left uninitialized.
102    * @param[in] handle to an object
103    * @return property buffer handle or an uninitialized handle
104    */
105   static PropertyBuffer DownCast( BaseHandle handle );
106
107   /**
108    * @brief Assignment operator, changes this handle to point at the same object
109    *
110    * @param[in] handle Handle to an object
111    * @return Reference to the assigned object
112    */
113   PropertyBuffer& operator=( const PropertyBuffer& handle );
114
115   /**
116    * @brief Update the whole buffer information
117    *
118    * This function expects a pointer to an array of structures with the same
119    * format that was given in the construction, and the number of elements to
120    * be the same as the size of the buffer.
121    *
122    * If the initial structure was: { { "position", VECTOR3}, { "uv", VECTOR2 } }
123    * and a size of 10 elements, this function should be called with a pointer equivalent to:
124    * <pre>
125    * struct Vertex {
126    *   Dali::Vector3 position;
127    *   Dali::Vector2 uv;
128    * };
129    * Vertex vertices[ 10 ] = { ... };
130    * propertyBuffer.SetData( vertices );
131    * </pre>
132    *
133    * @param[in] data A pointer to the data that will be copied to the buffer.
134    * @param[in] size Number of elements to expand or contract the buffer.
135    */
136   void SetData( const void* data, std::size_t size );
137
138   /**
139    * @brief Get the number of elements in the buffer
140    *
141    * @return Number of elements to expand or contract the buffer
142    */
143   std::size_t GetSize() const;
144
145 public:
146   /**
147    * @brief The constructor
148    *
149    * @param [in] pointer A pointer to a newly allocated PropertyBuffer
150    */
151   explicit DALI_INTERNAL PropertyBuffer( Internal::PropertyBuffer* pointer );
152 };
153
154 } // namespace Dali
155
156 #endif // DALI_PROPERTY_BUFFER_H