2016-02-16 15:07:25 +01:00
|
|
|
/*
|
|
|
|
|
* 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
|
2016-03-08 21:52:40 +01:00
|
|
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
2016-02-16 15:07:25 +01:00
|
|
|
#include <glm/glm.hpp>
|
|
|
|
|
#include <glm/gtc/matrix_transform.hpp>
|
|
|
|
|
#include <glm/gtc/matrix_inverse.hpp>
|
|
|
|
|
|
|
|
|
|
#include "vulkan/vulkan.h"
|
|
|
|
|
|
2017-02-12 13:10:05 +01:00
|
|
|
#include "VulkanTools.h"
|
2017-02-12 10:16:07 +01:00
|
|
|
#include "VulkanDevice.hpp"
|
2017-02-12 10:44:51 +01:00
|
|
|
#include "VulkanBuffer.hpp"
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-06 10:38:03 +02:00
|
|
|
struct GearInfo
|
|
|
|
|
{
|
|
|
|
|
float innerRadius;
|
|
|
|
|
float outerRadius;
|
|
|
|
|
float width;
|
|
|
|
|
int numTeeth;
|
|
|
|
|
float toothDepth;
|
|
|
|
|
glm::vec3 color;
|
|
|
|
|
glm::vec3 pos;
|
|
|
|
|
float rotSpeed;
|
|
|
|
|
float rotOffset;
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-16 15:07:25 +01:00
|
|
|
class VulkanGear
|
|
|
|
|
{
|
|
|
|
|
private:
|
|
|
|
|
struct UBO
|
|
|
|
|
{
|
|
|
|
|
glm::mat4 projection;
|
|
|
|
|
glm::mat4 model;
|
|
|
|
|
glm::mat4 normal;
|
|
|
|
|
glm::mat4 view;
|
|
|
|
|
glm::vec3 lightPos;
|
|
|
|
|
};
|
|
|
|
|
|
2017-02-12 10:16:07 +01:00
|
|
|
vks::VulkanDevice *vulkanDevice;
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
glm::vec3 color;
|
|
|
|
|
glm::vec3 pos;
|
|
|
|
|
float rotSpeed;
|
|
|
|
|
float rotOffset;
|
|
|
|
|
|
2017-02-12 10:44:51 +01:00
|
|
|
vks::Buffer vertexBuffer;
|
|
|
|
|
vks::Buffer indexBuffer;
|
2016-07-23 23:24:59 +02:00
|
|
|
uint32_t indexCount;
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
UBO ubo;
|
2017-02-12 10:44:51 +01:00
|
|
|
vks::Buffer uniformBuffer;
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2017-02-12 10:16:07 +01:00
|
|
|
VulkanGear(vks::VulkanDevice *vulkanDevice) : vulkanDevice(vulkanDevice) {};
|
2016-02-16 15:07:25 +01:00
|
|
|
~VulkanGear();
|
|
|
|
|
|
2016-06-06 10:38:03 +02:00
|
|
|
void generate(GearInfo *gearinfo, VkQueue queue);
|
2016-02-16 15:07:25 +01:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|