minecraftvulkan/engine/xe_model.hpp

62 lines
1.4 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 Data {
std::vector<unsigned char> data{};
template <typename T>
void write(T d) {
unsigned char const * p = reinterpret_cast<unsigned char const *>(&d);
for(std::size_t i = 0; i < sizeof(T); i++){
data.push_back(p[i]);
}
}
};
2022-09-19 01:20:51 +00:00
struct Builder {
Model::Data vertexData{};
2022-09-25 16:07:49 +00:00
uint32_t vertexSize;
2022-09-19 01:20:51 +00:00
std::vector<uint32_t> indices{};
void loadModel(const std::string &filepath);
};
2022-09-27 21:03:43 +00:00
Model(const Model::Builder &builder);
2022-09-25 01:16:13 +00:00
~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-27 21:03:43 +00:00
static Model* createModelFromFile(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<unsigned char> &vertexData, uint32_t vertexSize);
2022-09-25 16:07:49 +00:00
void createIndexBuffers(const std::vector<uint32_t> &indexData);
2022-09-19 01:20:51 +00:00
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;
};
}