1 #ifndef DALI_PROPERTY_BUFFER_H
2 #define DALI_PROPERTY_BUFFER_H
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <cstddef> // std::size_t
23 #include <string> // std::string
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
34 namespace Internal DALI_INTERNAL
40 * @brief PropertyBuffer is a handle to an object that contains a buffer of structured properties
42 * PropertyBuffers can be used to provide data to Geometry objects.
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) } };
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);
61 * unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 };
62 * Property::Map indexFormat;
63 * indexFormat["indices"] = Property::INTEGER;
64 * PropertyBuffer indices = PropertyBuffer::New( indexFormat, 6 );
65 * indices.SetData(indexData);
67 * // Create the geometry object
68 * Geometry texturedQuadGeometry = Geometry::New();
69 * texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
70 * texturedQuadGeometry.SetIndexBuffer( indices );
73 class DALI_IMPORT_API PropertyBuffer : public Handle
78 * @brief An enumeration of properties belonging to the PropertyBuffer class.
84 SIZE = DEFAULT_OBJECT_PROPERTY_START_INDEX, ///< name "size", type INTEGER
85 BUFFER_FORMAT, ///< name "buffer-format", type MAP
90 * @brief Create a PropertyBuffer
92 * Static property buffers use less memory.
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
98 static PropertyBuffer New( Dali::Property::Map& bufferFormat, std::size_t size );
101 * @brief Default constructor, creates an empty handle
111 * @brief Copy constructor, creates a new handle to the same object
113 * @param[in] handle Handle to an object
115 PropertyBuffer( const PropertyBuffer& handle );
118 * @brief Downcast to a property buffer handle.
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
124 static PropertyBuffer DownCast( BaseHandle handle );
127 * @brief Assignment operator, changes this handle to point at the same object
129 * @param[in] handle Handle to an object
130 * @return Reference to the assigned object
132 PropertyBuffer& operator=( const PropertyBuffer& handle );
135 * @brief Set the number of elements in the buffer
137 * Calling this function is equivalent to setting the property SIZE
139 * @param[in] size Number of elements to expand or contract the buffer
141 void SetSize( std::size_t size );
144 * @brief Get the number of elements in the buffer
146 * @return Number of elements to expand or contract the buffer
148 std::size_t GetSize() const;
151 * @brief Update the whole buffer information
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 same as the size of the buffer.
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:
161 * Dali::Vector3 position;
164 * Vertex vertices[ 10 ] = { ... };
165 * propertyBuffer.SetData( vertices );
168 * @param[in] data A pointer to the data that will be copied to the buffer.
170 void SetData( void* data );
174 * @brief The constructor
176 * @param [in] pointer A pointer to a newly allocated PropertyBuffer
178 explicit DALI_INTERNAL PropertyBuffer( Internal::PropertyBuffer* pointer );
183 #endif // DALI_PROPERTY_BUFFER_H