#pragma once #include "xe_device.hpp" #include "xe_buffer.hpp" #include #include #define GLM_FORCE_RADIANS #define GLM_FORCE_DEPTH_ZERO_TO_ONE #include namespace xe { class Model { public: struct Data { std::vector data{}; template void write(T d) { unsigned char const * p = reinterpret_cast(&d); for(std::size_t i = 0; i < sizeof(T); i++){ data.push_back(p[i]); } } }; struct Builder { Model::Data vertexData{}; uint32_t vertexSize; std::vector indices{}; void loadModel(const std::string &filepath); }; Model(Device &device, const Model::Builder &builder); ~Model(); Model(const Model &) = delete; Model operator=(const Model &) = delete; static std::unique_ptr createModelFromFile(Device &device, const std::string &filepath); void bind(VkCommandBuffer commandBuffer); void draw(VkCommandBuffer commandBuffer); private: void createVertexBuffers(const std::vector &vertexData, uint32_t vertexSize); void createIndexBuffers(const std::vector &indexData); Device &xeDevice; std::unique_ptr vertexBuffer; uint32_t vertexCount; bool hasIndexBuffer = false; std::unique_ptr indexBuffer; uint32_t indexCount; }; }