71 lines
1.6 KiB
C++
71 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <sophia/asset_registry.hpp>
|
|
#include <sophia/types.hpp>
|
|
#include <vector>
|
|
|
|
#define GLM_FORCE_RADIANS
|
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
|
#include <glm/glm.hpp>
|
|
|
|
#include "buffer.hpp"
|
|
#include "device.hpp"
|
|
|
|
namespace sophia {
|
|
|
|
class Mesh {
|
|
public:
|
|
using HandleType = MeshHandle;
|
|
|
|
struct Vertex {
|
|
glm::vec2 position{};
|
|
glm::vec3 color{};
|
|
// glm::vec3 normal{};
|
|
// glm::vec2 uv{};
|
|
|
|
static std::vector<vk::VertexInputBindingDescription>
|
|
getBindingDescriptions();
|
|
static std::vector<vk::VertexInputAttributeDescription>
|
|
getAttributeDescriptions();
|
|
|
|
// bool operator==(const Vertex& other) const {
|
|
// return position == other.position && color == other.color;
|
|
// }
|
|
};
|
|
|
|
struct Builder {
|
|
std::vector<Vertex> vertices{};
|
|
std::vector<uint32_t> indices{};
|
|
|
|
// void loadModel(const std::string& filepath);
|
|
};
|
|
|
|
Mesh(Device& device, const Mesh::Builder& builder);
|
|
~Mesh();
|
|
|
|
Mesh(const Mesh&) = delete;
|
|
Mesh& operator=(const Mesh&) = delete;
|
|
|
|
// static std::unique_ptr<Mesh> createMeshFromFile(
|
|
// Device& device, const std::string& filepath);
|
|
|
|
void bind(vk::CommandBuffer commandBuffer) const;
|
|
void draw(vk::CommandBuffer commandBuffer) const;
|
|
|
|
private:
|
|
void createVertexBuffers(const std::vector<Vertex>& vertices);
|
|
void createIndexBuffers(const std::vector<u32>& indices);
|
|
|
|
Device& device;
|
|
|
|
std::unique_ptr<Buffer> vertexBuffer;
|
|
u32 vertexCount;
|
|
|
|
bool hasIndexBuffer = false;
|
|
std::unique_ptr<Buffer> indexBuffer;
|
|
u32 indexCount;
|
|
};
|
|
|
|
} // namespace sophia
|