-
Notifications
You must be signed in to change notification settings - Fork 0
/
VulkanModel.h
105 lines (76 loc) · 2.99 KB
/
VulkanModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once
#include "glm/glm.hpp"
#include "fast_obj.h"
#include "Vertex.h"
#include <memory>
namespace CinderVk {
struct TextureStruct { //Basic texture structure for e.g PBR maps, other info maps
vk::DeviceMemory textureImageMemory;
vk::Image texture;
vk::ImageView textureImageView;
vk::Sampler textureSampler;
};
struct VulkanModelData { //A structure made to contain singular model data in memory
VulkanModelData(const std::string& modelLocation, vk::Device& logicalDevice, vk::Queue& graphicsQueue, vk::CommandPool& commandPool, vk::PhysicalDevice& physicalDevice) :
modelFileLocation(modelLocation), logicalDevicePtr(&logicalDevice), graphicsQueuePtr(&graphicsQueue), commandPoolPtr(&commandPool), physicalDevicePtr(&physicalDevice)
{};
~VulkanModelData() {
logicalDevicePtr->destroyBuffer(vertexBuffer, nullptr);
logicalDevicePtr->freeMemory(vertexBufferMemory, nullptr);
logicalDevicePtr->destroyBuffer(indexBuffer, nullptr);
logicalDevicePtr->freeMemory(indexBufferMemory, nullptr);
for (auto tStruct : textureStructs) {
logicalDevicePtr->destroySampler(tStruct.textureSampler, nullptr);
logicalDevicePtr->destroyImage(tStruct.texture, nullptr);
logicalDevicePtr->destroyImageView(tStruct.textureImageView, nullptr);
logicalDevicePtr->freeMemory(tStruct.textureImageMemory, nullptr);
}
};
vk::Device* logicalDevicePtr;
vk::Queue* graphicsQueuePtr;
vk::CommandPool* commandPoolPtr;
vk::PhysicalDevice* physicalDevicePtr;
std::vector<fastObjMaterial> materialLayers;
std::vector<TextureStruct> textureStructs;
std::string modelFileLocation;
vk::Buffer vertexBuffer;
vk::Buffer indexBuffer;
vk::DeviceMemory vertexBufferMemory;
vk::DeviceMemory indexBufferMemory;
uint32_t modelIndicesSize, modelVerticesSize; //set these in setupBuffers
uint32_t getModelIndicesSize();
uint32_t getModelVerticesSize();
vk::ImageView getImageView(size_t idx);
vk::Sampler getTextureSampler(size_t idx);
vk::Buffer getVertexBuffer();
vk::Buffer getIndexBuffer();
void loadModelData();
void setupBuffers(std::vector<Vertex>& verts, std::vector<uint32_t>& indices);
void setupTextures();
void createVertexBuffer(std::vector<Vertex>& verts);
void createIndexBuffer(std::vector<uint32_t>& indices);
};
class VulkanModel {
public:
VulkanModel(VulkanModelData* modelDataPtr) : dataPtr(modelDataPtr) {
worldTransform = glm::mat4(1.0f);
localTransform = glm::mat4(0.0f);
}
~VulkanModel() {
}
glm::vec3 getPosition();
glm::quat getRotation();
float getScale();
void setPosition(glm::vec3 pos);
void setRotation(glm::quat rot);
void update();
void rotate(glm::vec3 rotateVec, float angle);
void translate(glm::vec3 translateVec);
void scale(float scaleFactor);
private:
glm::mat4 localTransform;
glm::mat4 worldTransform;
std::shared_ptr<VulkanModelData> dataPtr;
void setupDescriptorSets();
};
}