extend geometry API
This commit is contained in:
@@ -19,6 +19,102 @@
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
Geometry::Geometry(const Geometry& other)
|
||||
{
|
||||
this->vertexCount = other.vertexCount;
|
||||
this->indexCount = other.indexCount;
|
||||
this->indexType = other.indexType;
|
||||
this->aabb = other.aabb;
|
||||
this->ownsMemory = other.ownsMemory;
|
||||
this->freeAfterUpload = other.freeAfterUpload;
|
||||
this->renderGeo = nullptr;
|
||||
this->vertices = new Vertex[vertexCount];
|
||||
if (other.vertices)
|
||||
{
|
||||
std::copy(other.vertices, other.vertices + other.vertexCount, this->vertices);
|
||||
}
|
||||
this->indices = malloc(static_cast<size_t>(Utils::EnumAsInt(other.indexType)) * other.indexCount);
|
||||
if (other.indices)
|
||||
{
|
||||
if (other.indexType == VertexIndexType::UINT16)
|
||||
{
|
||||
std::copy(static_cast<uint16_t*>(other.indices),
|
||||
static_cast<uint16_t*>(other.indices) + other.indexCount,
|
||||
static_cast<uint16_t*>(this->indices));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::copy(static_cast<uint32_t*>(other.indices),
|
||||
static_cast<uint32_t*>(other.indices) + other.indexCount,
|
||||
static_cast<uint32_t*>(this->indices));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Geometry& Geometry::operator=(const Geometry& other)
|
||||
{
|
||||
Geometry tmp(other);
|
||||
this->Swap(tmp);
|
||||
return *this;
|
||||
}
|
||||
|
||||
Geometry::Geometry(Geometry&& other) noexcept
|
||||
{
|
||||
this->vertexCount = other.vertexCount;
|
||||
this->indexCount = other.indexCount;
|
||||
this->indexType = other.indexType;
|
||||
this->ownsMemory = other.ownsMemory;
|
||||
this->freeAfterUpload = other.freeAfterUpload;
|
||||
this->aabb = std::move(other.aabb);
|
||||
this->vertices = other.vertices;
|
||||
this->indices = other.indices;
|
||||
this->renderGeo = other.renderGeo;
|
||||
other.vertexCount = other.indexCount = 0;
|
||||
other.vertices = nullptr;
|
||||
other.indices = nullptr;
|
||||
other.renderGeo = nullptr;
|
||||
}
|
||||
|
||||
Geometry& Geometry::operator=(Geometry&& other) noexcept
|
||||
{
|
||||
if (this != &other)
|
||||
{
|
||||
Close();
|
||||
this->vertexCount = other.vertexCount;
|
||||
this->indexCount = other.indexCount;
|
||||
this->indexType = other.indexType;
|
||||
this->ownsMemory = other.ownsMemory;
|
||||
this->freeAfterUpload = other.freeAfterUpload;
|
||||
this->aabb = std::move(other.aabb);
|
||||
this->vertices = other.vertices;
|
||||
this->indices = other.indices;
|
||||
this->renderGeo = other.renderGeo;
|
||||
other.vertexCount = other.indexCount = 0;
|
||||
other.vertices = nullptr;
|
||||
other.indices = nullptr;
|
||||
other.renderGeo = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Geometry::~Geometry()
|
||||
{
|
||||
Geometry::Close();
|
||||
}
|
||||
|
||||
void Geometry::Swap(Geometry& other) noexcept
|
||||
{
|
||||
std::swap(this->vertexCount, other.vertexCount);
|
||||
std::swap(this->indexCount, other.indexCount);
|
||||
std::swap(this->aabb, other.aabb);
|
||||
std::swap(this->indexType, other.indexType);
|
||||
std::swap(this->vertices, other.vertices);
|
||||
std::swap(this->indices, other.indices);
|
||||
std::swap(this->renderGeo, other.renderGeo);
|
||||
std::swap(this->ownsMemory, other.ownsMemory);
|
||||
std::swap(this->freeAfterUpload, other.freeAfterUpload);
|
||||
}
|
||||
|
||||
void Geometry::Init(uint32_t vertexCount, uint32_t indexCount)
|
||||
{
|
||||
if (this->vertexCount || this->indexCount) throw std::runtime_error("Geometry is already initialized.");
|
||||
@@ -110,11 +206,17 @@ namespace OpenVulkano::Scene
|
||||
|
||||
void Geometry::Close()
|
||||
{
|
||||
vertexCount = 0;
|
||||
indexCount = 0;
|
||||
Free();
|
||||
renderGeo->Close();
|
||||
renderGeo = nullptr;
|
||||
if (ownsMemory)
|
||||
{
|
||||
vertexCount = 0;
|
||||
indexCount = 0;
|
||||
Free();
|
||||
}
|
||||
if (renderGeo)
|
||||
{
|
||||
renderGeo->Close();
|
||||
renderGeo = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Geometry::Free()
|
||||
|
||||
Reference in New Issue
Block a user