minecraftvulkan/engine/xe_model.hpp

63 lines
1.5 KiB
C++
Raw Normal View History

2022-09-19 01:20:51 +00:00
#pragma once
#include "xe_device.hpp"
#include "xe_buffer.hpp"
#include <vector>
#include <memory>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
namespace xe {
2022-09-25 01:16:13 +00:00
class Model {
2022-09-19 01:20:51 +00:00
public:
struct Vertex {
glm::vec3 position;
glm::vec3 color;
glm::vec3 normal;
glm::vec2 uv;
static std::vector<VkVertexInputBindingDescription> getBindingDescriptions();
static std::vector<VkVertexInputAttributeDescription> getAttributeDescriptions();
bool operator==(const Vertex &other) const {
return position == other.position && color == other.color && normal == other.normal && uv == other.uv;
}
};
struct Builder {
std::vector<Vertex> vertices{};
std::vector<uint32_t> indices{};
void loadModel(const std::string &filepath);
};
2022-09-25 01:16:13 +00:00
Model(Device &device, const Model::Builder &builder);
~Model();
2022-09-19 01:20:51 +00:00
2022-09-25 01:16:13 +00:00
Model(const Model &) = delete;
Model operator=(const Model &) = delete;
2022-09-19 01:20:51 +00:00
2022-09-25 01:16:13 +00:00
static std::unique_ptr<Model> createModelFromFile(Device &device, const std::string &filepath);
2022-09-19 01:20:51 +00:00
void bind(VkCommandBuffer commandBuffer);
void draw(VkCommandBuffer commandBuffer);
private:
void createVertexBuffers(const std::vector<Vertex> &vertices);
void createIndexBuffers(const std::vector<uint32_t> &indices);
2022-09-25 01:16:13 +00:00
Device &xeDevice;
2022-09-19 01:20:51 +00:00
2022-09-25 01:16:13 +00:00
std::unique_ptr<Buffer> vertexBuffer;
2022-09-19 01:20:51 +00:00
uint32_t vertexCount;
bool hasIndexBuffer = false;
2022-09-25 01:16:13 +00:00
std::unique_ptr<Buffer> indexBuffer;
2022-09-19 01:20:51 +00:00
uint32_t indexCount;
};
}