forked from SaschaWillems/Vulkan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vulkangear.h
105 lines (84 loc) · 2.04 KB
/
vulkangear.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
/*
* Vulkan Example - Animated gears using multiple uniform buffers
*
* See readme.md for details
*
* Copyright (C) 2015 by Sascha Willems - www.saschawillems.de
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
#pragma once
#include <math.h>
#include <vector>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_inverse.hpp>
#include "vulkan/vulkan.h"
#include "vulkantools.h"
#include "vulkandevice.hpp"
#include "vulkanbuffer.hpp"
struct Vertex
{
float pos[3];
float normal[3];
float color[3];
Vertex(const glm::vec3& p, const glm::vec3& n, const glm::vec3& c)
{
pos[0] = p.x;
pos[1] = p.y;
pos[2] = p.z;
color[0] = c.x;
color[1] = c.y;
color[2] = c.z;
normal[0] = n.x;
normal[1] = n.y;
normal[2] = n.z;
}
};
struct GearInfo
{
float innerRadius;
float outerRadius;
float width;
int numTeeth;
float toothDepth;
glm::vec3 color;
glm::vec3 pos;
float rotSpeed;
float rotOffset;
};
class VulkanGear
{
private:
struct UBO
{
glm::mat4 projection;
glm::mat4 model;
glm::mat4 normal;
glm::mat4 view;
glm::vec3 lightPos;
};
vk::VulkanDevice *vulkanDevice;
glm::vec3 color;
glm::vec3 pos;
float rotSpeed;
float rotOffset;
vk::Buffer vertexBuffer;
vk::Buffer indexBuffer;
uint32_t indexCount;
UBO ubo;
vkTools::UniformData uniformData;
int32_t newVertex(std::vector<Vertex> *vBuffer, float x, float y, float z, const glm::vec3& normal);
void newFace(std::vector<uint32_t> *iBuffer, int a, int b, int c);
void prepareUniformBuffer();
public:
VkDescriptorSet descriptorSet;
void draw(VkCommandBuffer cmdbuffer, VkPipelineLayout pipelineLayout);
void updateUniformBuffer(glm::mat4 perspective, glm::vec3 rotation, float zoom, float timer);
void setupDescriptorSet(VkDescriptorPool pool, VkDescriptorSetLayout descriptorSetLayout);
VulkanGear(vk::VulkanDevice *vulkanDevice) : vulkanDevice(vulkanDevice) {};
~VulkanGear();
void generate(GearInfo *gearinfo, VkQueue queue);
};