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/internal/common/const-string.h>
22 #include <dali/internal/common/owner-pointer.h>
23 #include <dali/internal/render/gl-resources/gpu-buffer.h>
24 #include <dali/internal/render/renderers/render-sampler.h>
25 #include <dali/public-api/actors/sampling.h>
26 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali/public-api/rendering/sampler.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 * @brief Set the number of elements
85 * @param[in] size The number of elements
87 void SetSize(uint32_t size);
90 * Perform the upload of the buffer only when required
91 * @param graphicsController The controller
93 bool Update(Graphics::Controller& graphicsController);
96 * Enable the vertex attributes for each vertex buffer from the corresponding
98 * @param[in] context The GL context
99 * @param[in] vAttributeLocation Vector containing attributes location for current program
100 * @param[in] locationBase Index in vAttributeLocation corresponding to the first attribute defined by this buffer
102 uint32_t EnableVertexAttributes(Context& context, Vector<GLint>& vAttributeLocation, uint32_t locationBase);
105 * Get the number of attributes present in the buffer
106 * @return The number of attributes stored in this buffer
108 inline uint32_t GetAttributeCount() const
110 DALI_ASSERT_DEBUG(mFormat && "Format should be set ");
111 return static_cast<uint32_t>(mFormat->components.size());
115 * Retrieve the i-essim attribute name
116 * @param[in] index The index of the attribute
117 * @return The name of the attribute
119 inline ConstString GetAttributeName(uint32_t index) const
121 DALI_ASSERT_DEBUG(mFormat && "Format should be set ");
122 return mFormat->components[index].name;
126 * Retrieve the size of the buffer in bytes
127 * @return The total size of the buffer
129 inline uint32_t GetDataSize() const
131 DALI_ASSERT_DEBUG(mFormat && "Format should be set ");
132 return mFormat->size * mSize;
136 * Retrieve the size of one element of the buffer
137 * @return The size of one element
139 inline uint32_t GetElementSize() const
141 DALI_ASSERT_DEBUG(mFormat && "Format should be set ");
142 return mFormat->size;
146 * Retrieve the number of elements in the buffer
147 * @return The total number of elements
149 inline uint32_t GetElementCount() const
155 * Retrieve reference to the data storage vector
156 * @return Reference to the data storage
158 inline const Dali::Vector<uint8_t>& GetData() const
164 * Retrieve data writeable pointer ( direct access to the buffer data )
165 * @return Pointer to data converted to requested type
168 inline T* GetDataTypedPtr()
170 Dali::Vector<uint8_t>* data = mData.Release();
172 return reinterpret_cast<T*>(&data->operator[](0));
175 inline const VertexBuffer::Format* GetFormat() const
177 return mFormat.Get();
180 inline GpuBuffer& GetGpuBuffer()
182 return *(const_cast<GpuBuffer*>(mGpuBuffer.Get())); // @todo change to unique_ptr to avoid const cast?
186 OwnerPointer<VertexBuffer::Format> mFormat; ///< Format of the buffer
187 OwnerPointer<Dali::Vector<uint8_t> > mData; ///< Data
188 OwnerPointer<GpuBuffer> mGpuBuffer; ///< Pointer to the GpuBuffer associated with this RenderVertexBuffer
190 uint32_t mSize; ///< Number of Elements in the buffer
191 bool mDataChanged; ///< Flag to know if data has changed in a frame
194 } // namespace Render
196 } // namespace Internal
200 #endif // DALI_INTERNAL_RENDER_VERTEX_BUFFER_H