22 using size_type = uint32_t;
23 using index_type = uint32_t;
24 using difference_type = uint32_t;
28 void operator++(
int discard) {
44 difference_type operator-(
const iterator& other)
const{
45 return data - other.data;
54 const T& operator*() {
62 void operator++(
int discard) {
70 constexpr static uint32_t initialSize = 16;
74 {.StorageBuffer =
true, .VertexBuffer =
true},
76 RGL::BufferAccess::Shared,
78 .Transfersource =
true,
80 .debugName =
"VRAMVector Buffer"
84 size_type nValues = 0;
90 VRAMVector(size_type numValues){
94 VRAMVector(
const VRAMVector&) =
delete;
96 VRAMVector(VRAMVector&& other){
98 TrashOldVector(buffer);
100 buffer = std::move(other.buffer);
101 nValues = other.nValues;
102 settings = other.settings;
105 VRAMVector& operator=(VRAMVector&& other){
108 TrashOldVector(buffer);
110 buffer = std::move(other.buffer);
111 nValues = other.nValues;
112 settings = other.settings;
118 TrashOldVector(buffer);
122 return static_cast<T*
>(buffer->GetMappedDataPtr());
126 return static_cast<T*
>(buffer->GetMappedDataPtr());
133 auto capacity()
const {
134 return settings.nElements;
152 buffer = owningDevice->CreateBuffer(settings);
156 buffer->UpdateBufferData({
oldbuffer->GetMappedDataPtr(), size() *
sizeof(T)});
159 assert(buffer->GetMappedDataPtr() !=
nullptr);
172 reserve(settings.nElements * 2);
175 bool reserveIfNeeded() {
176 if (nValues == settings.nElements) {
183 template<
typename ... Args>
184 auto& emplace_back(Args&& ... args) {
185 auto didreserve = reserveIfNeeded();
186 T* newAddr = data() + size();
187 auto valueptr =
new(newAddr) T{ args... };
188 assert(newAddr == valueptr);
193 void push_back(
const T& value) {
195 this->operator[](size()) = value;
199 void at(index_type i) {
200 if (i >= 0 && i < size()) {
201 return this->operator[](i);
204 throw std::out_of_range(
"index out of bounds");
208 auto& operator[](index_type i) {
209 return *(data() + i);
212 const auto& operator[](index_type i)
const {
213 return *(data() + i);
216 void erase(index_type i) {
218 if (i == size() - 1) {
223 void erase(iterator i) {
224 erase(uintptr_t(i.data - data()));
227 void erase(const_iterator i) {
228 erase(uintptr_t(i.data - data()));
236 return iterator{data()};
239 return iterator{data() + nValues };
247 return this->operator[](i - 1);
251 return const_iterator{ data()};
255 return const_iterator{ data() + nValues };