1 #ifndef DALI_PROPERTY_BUFFER_H
2 #define DALI_PROPERTY_BUFFER_H
5 * Copyright (c) 2016 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-map.h> // Dali::Property::Map
32 namespace Internal DALI_INTERNAL
38 * @brief PropertyBuffer is a handle to an object that contains a buffer of structured properties
40 * PropertyBuffers can be used to provide data to Geometry objects.
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) } };
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 );
59 * unsigned int indexData[6] = { 0, 3, 1, 0, 2, 3 };
61 * // Create the geometry object
62 * Geometry texturedQuadGeometry = Geometry::New();
63 * texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
64 * texturedQuadGeometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0] );
68 class DALI_IMPORT_API PropertyBuffer : public BaseHandle
73 * @brief Create a PropertyBuffer
74 * Static property buffers use less memory.
77 * @param[in] bufferFormat Map of names and types that describes the components of the buffer
78 * @return Handle to a newly allocated PropertyBuffer
80 static PropertyBuffer New( Dali::Property::Map& bufferFormat );
83 * @brief Default constructor, creates an empty handle
97 * @brief Copy constructor, creates a new handle to the same object
100 * @param[in] handle Handle to an object
102 PropertyBuffer( const PropertyBuffer& handle );
105 * @brief Downcast to a property buffer handle.
106 * If not a property buffer the returned property buffer handle is left uninitialized.
109 * @param[in] handle Handle to an object
110 * @return Property buffer handle or an uninitialized handle
112 static PropertyBuffer DownCast( BaseHandle handle );
115 * @brief Assignment operator, changes this handle to point at the same object
118 * @param[in] handle Handle to an object
119 * @return Reference to the assigned object
121 PropertyBuffer& operator=( const PropertyBuffer& handle );
124 * @brief Update the whole buffer information
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.
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:
134 * Dali::Vector3 position;
137 * Vertex vertices[ 10 ] = { ... };
138 * propertyBuffer.SetData( vertices );
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.
145 void SetData( const void* data, std::size_t size );
148 * @brief Get the number of elements in the buffer
151 * @return Number of elements to expand or contract the buffer
153 std::size_t GetSize() const;
158 * @brief The constructor
159 * @note Not intended for application developers.
161 * @param[in] pointer A pointer to a newly allocated PropertyBuffer
163 explicit DALI_INTERNAL PropertyBuffer( Internal::PropertyBuffer* pointer );
168 #endif // DALI_PROPERTY_BUFFER_H