Files
OpenVulkano/openVulkanoCpp/Scene/VertexBuffer.hpp
2025-01-04 20:58:22 +01:00

54 lines
1.1 KiB
C++

/*
* 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<VertexBuffer>
{
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<typename T>
T* Init(size_t count)
{
Init(count * sizeof(T));
return static_cast<T*>(const_cast<void*>(data));
}
void Close()
{
if (ownsMemory && data) free(const_cast<void*>(data));
data = nullptr;
}
UpdateFrequency GetUpdateFrequency() const { return updateFrequency; }
};
}