extend geometry API

This commit is contained in:
ohyzha
2024-07-24 10:47:52 +03:00
parent 775c49c197
commit abf1b72990
3 changed files with 137 additions and 23 deletions

View File

@@ -8,6 +8,7 @@
#include "Base/ICloseable.hpp"
#include "Math/AABB.hpp"
#include "Base/Utils.hpp"
#include <string>
class aiMesh;
@@ -27,18 +28,19 @@ namespace OpenVulkano
{
public:
uint32_t vertexCount = 0, indexCount = 0;
Vertex* vertices;
void* indices;
VertexIndexType indexType;
Vertex* vertices = nullptr;
void* indices = nullptr;
VertexIndexType indexType = VertexIndexType::UINT16;
bool ownsMemory = true, freeAfterUpload = true;
Math::AABB aabb;
ICloseable* renderGeo = nullptr;
Vertex* GetVertices() const { return vertices; }
void* GetIndices() const { return indices; }
uint16_t* GetIndices16() const { return static_cast<uint16_t*>(indices); }
uint32_t* GetIndices32() const { return static_cast<uint32_t*>(indices); }
uint32_t GetIndexCount() const { return indexCount; }
uint32_t GetVertexCount() const { return vertexCount; }
public:
Geometry() = default;
Geometry(const Geometry& other);
Geometry& operator=(const Geometry& other);
Geometry(Geometry&& other) noexcept;
Geometry& operator=(Geometry&& other) noexcept;
~Geometry();
static Geometry* LoadFromFile(const std::string& file)
{
@@ -47,13 +49,6 @@ namespace OpenVulkano
return mesh;
}
Geometry() : vertexCount(0), indexCount(0), vertices(nullptr), indices(nullptr), indexType(VertexIndexType::UINT16) {}
~Geometry()
{
if (vertices) Geometry::Close();
}
void InitFromFile(const std::string& file);
/**
@@ -68,8 +63,21 @@ namespace OpenVulkano
void SetIndices(const uint32_t* data, uint32_t size, uint32_t offset = 0) const;
void Close() override;
void Free();
Vertex* GetVertices() const { return vertices; }
void* GetIndices() const { return indices; }
uint16_t* GetIndices16() const { return static_cast<uint16_t*>(indices); }
uint32_t* GetIndices32() const { return static_cast<uint32_t*>(indices); }
uint32_t GetIndexCount() const { return indexCount; }
uint32_t GetVertexCount() const { return vertexCount; }
bool OwnsMemory() const { return ownsMemory; }
void SetOwnsMemory(bool val) { ownsMemory = val; }
bool FreeAfterUpload() const { return freeAfterUpload; }
void SetFreeAfterUpload(bool val) { freeAfterUpload = val; }
private:
void Swap(Geometry& other) noexcept;
};
}
}