1 #ifndef DALI_INTERNAL_RENDER_VERTEX_BUFFER_H
2 #define DALI_INTERNAL_RENDER_VERTEX_BUFFER_H
5 * Copyright (c) 2021 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.
21 #include <dali/public-api/common/vector-wrapper.h>
22 #include <dali/public-api/object/property.h>
24 #include <dali/graphics-api/graphics-types.h>
25 #include <dali/internal/common/const-string.h>
26 #include <dali/internal/common/owner-pointer.h>
27 #include <dali/internal/render/renderers/gpu-buffer.h>
47 * Structure that holds the meta-data of the format of VertexBuffer.
51 std::vector<Component> components;
56 * @brief Default constructor
66 * @brief Set the format of the buffer
68 * This function takes ownership of the pointer
70 * @param[in] format The format for the VertexBuffer
72 void SetFormat(VertexBuffer::Format* format);
75 * @brief Set the data of the VertexBuffer
77 * This function takes ownership of the pointer
78 * @param[in] data The new data of the VertexBuffer
79 * @param[in] size The new size of the buffer
81 void SetData(Dali::Vector<uint8_t>* data, uint32_t size);
84 * Perform the upload of the buffer only when required
85 * @param[in] graphicsController The controller
87 bool Update(Graphics::Controller& graphicsController);
90 * Get the number of attributes present in the buffer
91 * @return The number of attributes stored in this buffer
93 [[nodiscard]] inline uint32_t GetAttributeCount() const
95 DALI_ASSERT_DEBUG(mFormat && "Format should be set ");
96 return static_cast<uint32_t>(mFormat->components.size());
100 * Retrieve the i-essim attribute name
101 * @param[in] index The index of the attribute
102 * @return The name of the attribute
104 [[nodiscard]] inline ConstString GetAttributeName(uint32_t index) const
106 DALI_ASSERT_DEBUG(mFormat && "Format should be set ");
107 return mFormat->components[index].name;
111 * Retrieve the size of the buffer in bytes
112 * @return The total size of the buffer
114 [[nodiscard]] inline uint32_t GetDataSize() const
116 DALI_ASSERT_DEBUG(mFormat && "Format should be set ");
117 return mFormat->size * mSize;
121 * Retrieve the size of one element of the buffer
122 * @return The size of one element
124 [[nodiscard]] inline uint32_t GetElementSize() const
126 DALI_ASSERT_DEBUG(mFormat && "Format should be set ");
127 return mFormat->size;
131 * Retrieve the number of elements in the buffer
132 * @return The total number of elements
134 [[nodiscard]] inline uint32_t GetElementCount() const
139 [[nodiscard]] inline const VertexBuffer::Format* GetFormat() const
141 return mFormat.Get();
144 [[nodiscard]] inline const GpuBuffer* GetGpuBuffer() const
146 return mGpuBuffer.Get();
150 OwnerPointer<VertexBuffer::Format> mFormat; ///< Format of the buffer
151 OwnerPointer<Dali::Vector<uint8_t> > mData; ///< Data
152 OwnerPointer<GpuBuffer> mGpuBuffer; ///< Pointer to the GpuBuffer associated with this RenderVertexBuffer
154 uint32_t mSize; ///< Number of Elements in the buffer
155 bool mDataChanged; ///< Flag to know if data has changed in a frame
158 } // namespace Render
160 } // namespace Internal
164 #endif // DALI_INTERNAL_RENDER_VERTEX_BUFFER_H