minecraftvulkan/engine/xe_model.hpp

71 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 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-28 13:38:25 +00:00
static Model* createModel(const std::string &filepath);
static Model* createModel(Builder& builder);
static void deleteModel(Model* model);
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
void bind(VkCommandBuffer commandBuffer);
void draw(VkCommandBuffer commandBuffer);
private:
2022-09-28 13:38:25 +00:00
static void submitDeleteQueue(bool purge);
Model(const Model::Builder &builder);
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;
2022-09-28 13:38:25 +00:00
friend class SwapChain;
friend class Engine;
2022-09-19 01:20:51 +00:00
};
}