/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #pragma once #include "Base/Render/RenderResource.hpp" #include "Scene/UpdateFrequency.hpp" namespace OpenVulkano::Scene { class VertexBuffer final : public RenderResourceHolder { public: size_t size = 0; const void* data = nullptr; UpdateFrequency updateFrequency = UpdateFrequency::Never; bool updated = true; bool ownsMemory = true; ~VertexBuffer() { Close(); } void Init(size_t size, const void* data) { this->size = size; this->data = data; this->ownsMemory = false; } void Init(size_t size) { this->size = size; this->data = malloc(size); this->ownsMemory = true; } template T* Init(size_t count) { Init(count * sizeof(T)); return static_cast(const_cast(data)); } void Close() { if (ownsMemory && data) free(const_cast(data)); data = nullptr; } UpdateFrequency GetUpdateFrequency() const { return updateFrequency; } }; }