diff options
author | tylermurphy534 <tylermurphy534@gmail.com> | 2022-09-18 21:20:51 -0400 |
---|---|---|
committer | tylermurphy534 <tylermurphy534@gmail.com> | 2022-09-18 21:20:51 -0400 |
commit | 8045b8ba04aae39a4cf9733e72413f648b6ebe2b (patch) | |
tree | f90a9bd50a2316d5077df99c9e8584afc76ed656 /engine/xe_model.hpp | |
download | minecraftvulkan-8045b8ba04aae39a4cf9733e72413f648b6ebe2b.tar.gz minecraftvulkan-8045b8ba04aae39a4cf9733e72413f648b6ebe2b.tar.bz2 minecraftvulkan-8045b8ba04aae39a4cf9733e72413f648b6ebe2b.zip |
stanford dragon rendering
Diffstat (limited to 'engine/xe_model.hpp')
-rw-r--r-- | engine/xe_model.hpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/engine/xe_model.hpp b/engine/xe_model.hpp new file mode 100644 index 0000000..2ffe298 --- /dev/null +++ b/engine/xe_model.hpp @@ -0,0 +1,63 @@ +#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 { + +class XeModel { + 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); + }; + + XeModel(XeDevice &device, const XeModel::Builder &builder); + ~XeModel(); + + XeModel(const XeModel &) = delete; + XeModel operator=(const XeModel &) = delete; + + static std::unique_ptr<XeModel> createModelFromFile(XeDevice &device, const std::string &filepath); + + void bind(VkCommandBuffer commandBuffer); + void draw(VkCommandBuffer commandBuffer); + + private: + void createVertexBuffers(const std::vector<Vertex> &vertices); + void createIndexBuffers(const std::vector<uint32_t> &indices); + + XeDevice &xeDevice; + + std::unique_ptr<XeBuffer> vertexBuffer; + uint32_t vertexCount; + + bool hasIndexBuffer = false; + std::unique_ptr<XeBuffer> indexBuffer; + uint32_t indexCount; +}; + +}
\ No newline at end of file |