1 #ifndef DALI_VERTEX_BUFFER_H
2 #define DALI_VERTEX_BUFFER_H
5 * Copyright (c) 2020 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 * @addtogroup dali_core_rendering_effects
36 namespace Internal DALI_INTERNAL
42 * @brief VertexBuffer is a handle to an object that contains a buffer of structured data.
44 * VertexBuffers can be used to provide data to Geometry objects.
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) } };
56 * Property::Map texturedQuadVertexFormat;
57 * texturedQuadVertexFormat["aPosition"] = Property::VECTOR2;
58 * texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2;
59 * VertexBuffer texturedQuadVertices = VertexBuffer::New( texturedQuadVertexFormat );
60 * texturedQuadVertices.SetData( texturedQuadVertexData, 4 );
63 * uint32_t indexData[6] = { 0, 3, 1, 0, 2, 3 };
65 * // Create the geometry object
66 * Geometry texturedQuadGeometry = Geometry::New();
67 * texturedQuadGeometry.AddVertexBuffer( texturedQuadVertices );
68 * texturedQuadGeometry.SetIndexBuffer( indexData, sizeof(indexData)/sizeof(indexData[0] );
72 class DALI_CORE_API VertexBuffer : public BaseHandle
77 * @brief Creates a VertexBuffer.
80 * @param[in] bufferFormat Map of names and types that describes the components of the buffer
81 * @return Handle to a newly allocated VertexBuffer
83 static VertexBuffer New( Dali::Property::Map& bufferFormat );
86 * @brief Default constructor, creates an empty handle.
100 * @brief Copy constructor, creates a new handle to the same object.
103 * @param[in] handle Handle to an object
105 VertexBuffer( const VertexBuffer& handle );
108 * @brief Downcasts to a property buffer handle.
109 * If not, a property buffer the returned property buffer handle is left uninitialized.
112 * @param[in] handle Handle to an object
113 * @return Property buffer handle or an uninitialized handle
115 static VertexBuffer DownCast( BaseHandle handle );
118 * @brief Assignment operator, changes this handle to point at the same object.
121 * @param[in] handle Handle to an object
122 * @return Reference to the assigned object
124 VertexBuffer& operator=( const VertexBuffer& handle );
127 * @brief Move constructor.
130 * @param[in] rhs A reference to the moved handle
132 VertexBuffer( VertexBuffer&& rhs );
135 * @brief Move assignment operator.
138 * @param[in] rhs A reference to the moved handle
139 * @return A reference to this handle
141 VertexBuffer& operator=( VertexBuffer&& rhs );
144 * @brief Updates the whole buffer information.
146 * This function expects a pointer to an array of structures with the same
147 * format that was given in the construction, and the number of elements to
148 * be the same as the size of the buffer.
150 * If the initial structure was: { { "position", VECTOR3}, { "uv", VECTOR2 } }
151 * and a size of 10 elements, this function should be called with a pointer equivalent to:
154 * Dali::Vector3 position;
157 * Vertex vertices[ 10 ] = { ... };
158 * vertexBuffer.SetData( vertices );
162 * @param[in] data A pointer to the data that will be copied to the buffer
163 * @param[in] size Number of elements to expand or contract the buffer
165 void SetData( const void* data, std::size_t size );
168 * @brief Gets the number of elements in the buffer.
171 * @return Number of elements to expand or contract the buffer
173 std::size_t GetSize() const;
178 * @brief The constructor.
179 * @note Not intended for application developers.
181 * @param[in] pointer A pointer to a newly allocated VertexBuffer
183 explicit DALI_INTERNAL VertexBuffer( Internal::VertexBuffer* pointer );
191 #endif // DALI_VERTEX_BUFFER_H