Files
OpenVulkano/openVulkanoCpp/Scene/Geometry.hpp

77 lines
2.0 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/ICloseable.hpp"
#include "AABB.hpp"
#include <string>
class aiMesh;
namespace openVulkanoCpp
{
struct Vertex;
namespace Scene
{
enum class VertexIndexType
{
UINT16 = sizeof(uint16_t), UINT32 = sizeof(uint32_t)
};
struct Geometry : public virtual ICloseable
{
uint32_t vertexCount = 0, indexCount = 0;
Vertex* vertices;
void* indices;
VertexIndexType indexType;
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; }
static Geometry* LoadFromFile(const std::string& file)
{
Geometry* mesh = new Geometry();
mesh->InitFromFile(file);
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);
/**
* \brief Creates the arrays for the vertices and indices. They will not be filled!
* \param vertexCount The amount of vertices that will be used
* \param indexCount The amount of indices that will be used
*/
void Init(uint32_t vertexCount, uint32_t indexCount);
void Init(aiMesh* mesh);
void InitCube(float x = 1, float y = 1, float z = 1, const Math::Vector4f& color = Math::Vector4f(1));
void SetIndices(const uint32_t* data, uint32_t size, uint32_t offset = 0) const;
void Close() override;
void Free();
};
}
}