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-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 };
60 * Property::Map indexFormat;
61 * indexFormat["indices"] = Property::INTEGER;
62 * PropertyBuffer indices = PropertyBuffer::New( indexFormat );
63 * indices.SetData( indexData, 6 );
65 * // Create the geometry object
66 * Geometry texturedQuadGeometry = Geometry::New();
67 * texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
68 * texturedQuadGeometry.SetIndexBuffer( indices );
71 class DALI_IMPORT_API PropertyBuffer : public BaseHandle
76 * @brief Create a PropertyBuffer
78 * Static property buffers use less memory.
80 * @param[in] bufferFormat Map of names and types that describes the components of the buffer
81 * @return Handle to a newly allocated PropertyBuffer
83 static PropertyBuffer New( Dali::Property::Map& bufferFormat );
86 * @brief Default constructor, creates an empty handle
96 * @brief Copy constructor, creates a new handle to the same object
98 * @param[in] handle Handle to an object
100 PropertyBuffer( const PropertyBuffer& handle );
103 * @brief Downcast to a property buffer handle.
105 * If not a property buffer the returned property buffer handle is left uninitialized.
106 * @param[in] handle to an object
107 * @return property buffer handle or an uninitialized handle
109 static PropertyBuffer DownCast( BaseHandle handle );
112 * @brief Assignment operator, changes this handle to point at the same object
114 * @param[in] handle Handle to an object
115 * @return Reference to the assigned object
117 PropertyBuffer& operator=( const PropertyBuffer& handle );
120 * @brief Update the whole buffer information
122 * This function expects a pointer to an array of structures with the same
123 * format that was given in the construction, and the number of elements to
124 * be the same as the size of the buffer.
126 * If the initial structure was: { { "position", VECTOR3}, { "uv", VECTOR2 } }
127 * and a size of 10 elements, this function should be called with a pointer equivalent to:
130 * Dali::Vector3 position;
133 * Vertex vertices[ 10 ] = { ... };
134 * propertyBuffer.SetData( vertices );
137 * @param[in] data A pointer to the data that will be copied to the buffer.
138 * @param[in] size Number of elements to expand or contract the buffer.
140 void SetData( const void* data, std::size_t size );
143 * @brief Get the number of elements in the buffer
145 * @return Number of elements to expand or contract the buffer
147 std::size_t GetSize() const;
151 * @brief The constructor
153 * @param [in] pointer A pointer to a newly allocated PropertyBuffer
155 explicit DALI_INTERNAL PropertyBuffer( Internal::PropertyBuffer* pointer );
160 #endif // DALI_PROPERTY_BUFFER_H