clang format

This commit is contained in:
Sascha Willems 2020-06-06 11:05:56 +02:00
parent a1afaf3de5
commit 9e96aeaa5f
2 changed files with 521 additions and 421 deletions

File diff suppressed because it is too large Load diff

View file

@ -15,10 +15,10 @@
* If you are looking for a complete glTF implementation, check out https://github.com/SaschaWillems/Vulkan-glTF-PBR/ * If you are looking for a complete glTF implementation, check out https://github.com/SaschaWillems/Vulkan-glTF-PBR/
*/ */
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <vector> #include <vector>
#define GLM_FORCE_RADIANS #define GLM_FORCE_RADIANS
@ -31,89 +31,93 @@
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#define TINYGLTF_NO_STB_IMAGE_WRITE #define TINYGLTF_NO_STB_IMAGE_WRITE
#ifdef VK_USE_PLATFORM_ANDROID_KHR #ifdef VK_USE_PLATFORM_ANDROID_KHR
#define TINYGLTF_ANDROID_LOAD_FROM_ASSETS # define TINYGLTF_ANDROID_LOAD_FROM_ASSETS
#endif #endif
#include "tiny_gltf.h" #include "tiny_gltf.h"
#include <vulkan/vulkan.h>
#include "vulkanexamplebase.h"
#include "VulkanTexture.hpp" #include "VulkanTexture.hpp"
#include "vulkanexamplebase.h"
#include <vulkan/vulkan.h>
#define ENABLE_VALIDATION false #define ENABLE_VALIDATION false
// Contains everything required to render a glTF model in Vulkan // Contains everything required to render a glTF model in Vulkan
// This class is heavily simplified (compared to glTF's feature set) but retains the basic glTF structure // This class is heavily simplified (compared to glTF's feature set) but retains the basic glTF structure
class VulkanglTFModel class VulkanglTFModel
{ {
public: public:
vks::VulkanDevice* vulkanDevice; vks::VulkanDevice *vulkanDevice;
VkQueue copyQueue; VkQueue copyQueue;
/* /*
Base glTF structures, see gltfscene sample for details Base glTF structures, see gltfscene sample for details
*/ */
struct Vertices { struct Vertices
VkBuffer buffer; {
VkBuffer buffer;
VkDeviceMemory memory; VkDeviceMemory memory;
} vertices; } vertices;
struct Indices { struct Indices
int count; {
VkBuffer buffer; int count;
VkBuffer buffer;
VkDeviceMemory memory; VkDeviceMemory memory;
} indices; } indices;
struct Node; struct Node;
struct Material { struct Material
{
glm::vec4 baseColorFactor = glm::vec4(1.0f); glm::vec4 baseColorFactor = glm::vec4(1.0f);
uint32_t baseColorTextureIndex; uint32_t baseColorTextureIndex;
}; };
struct Image { struct Image
vks::Texture2D texture; {
vks::Texture2D texture;
VkDescriptorSet descriptorSet; VkDescriptorSet descriptorSet;
}; };
struct Texture { struct Texture
{
int32_t imageIndex; int32_t imageIndex;
}; };
struct Primitive { struct Primitive
{
uint32_t firstIndex; uint32_t firstIndex;
uint32_t indexCount; uint32_t indexCount;
int32_t materialIndex; int32_t materialIndex;
}; };
struct Mesh { struct Mesh
{
std::vector<Primitive> primitives; std::vector<Primitive> primitives;
}; };
struct Node { struct Node
Node* parent; {
uint32_t index; Node * parent;
std::vector<Node*> children; uint32_t index;
Mesh mesh; std::vector<Node *> children;
// Matrix components are stored separately as they are affected by animations Mesh mesh;
glm::vec3 translation{}; glm::vec3 translation{};
glm::vec3 scale{ 1.0f }; glm::vec3 scale{1.0f};
glm::quat rotation{}; glm::quat rotation{};
// Index of the skin for this node int32_t skin = -1;
int32_t skin = -1; glm::mat4 matrix;
glm::mat4 matrix; glm::mat4 getLocalMatrix();
// Gets the current local matrix based on translation, rotation and scale, which can all be affected by animations
glm::mat4 getLocalMatrix();
}; };
struct Vertex { struct Vertex
{
glm::vec3 pos; glm::vec3 pos;
glm::vec3 normal; glm::vec3 normal;
glm::vec2 uv; glm::vec2 uv;
glm::vec3 color; glm::vec3 color;
// Contains indices of the joints that effect this vertex
glm::vec4 jointIndices; glm::vec4 jointIndices;
// Contains the weights that define how strongly this vertex is affected by above joints
glm::vec4 jointWeights; glm::vec4 jointWeights;
}; };
@ -121,74 +125,79 @@ public:
Skin structure Skin structure
*/ */
struct Skin { struct Skin
std::string name; {
Node* skeletonRoot = nullptr; std::string name;
Node * skeletonRoot = nullptr;
std::vector<glm::mat4> inverseBindMatrices; std::vector<glm::mat4> inverseBindMatrices;
std::vector<Node*> joints; std::vector<Node *> joints;
// The joint matrices for this skin are stored in an shader storage buffer vks::Buffer ssbo;
vks::Buffer ssbo; VkDescriptorSet descriptorSet;
VkDescriptorSet descriptorSet;
}; };
/* /*
Animation related structures Animation related structures
*/ */
struct AnimationSampler { struct AnimationSampler
std::string interpolation; {
std::vector<float> inputs; std::string interpolation;
std::vector<float> inputs;
std::vector<glm::vec4> outputsVec4; std::vector<glm::vec4> outputsVec4;
}; };
struct AnimationChannel { struct AnimationChannel
{
std::string path; std::string path;
Node* node; Node * node;
uint32_t samplerIndex; uint32_t samplerIndex;
}; };
struct Animation { struct Animation
std::string name; {
std::string name;
std::vector<AnimationSampler> samplers; std::vector<AnimationSampler> samplers;
std::vector<AnimationChannel> channels; std::vector<AnimationChannel> channels;
float start = std::numeric_limits<float>::max(); float start = std::numeric_limits<float>::max();
float end = std::numeric_limits<float>::min(); float end = std::numeric_limits<float>::min();
float currentTime = 0.0f; float currentTime = 0.0f;
}; };
std::vector<Image> images; std::vector<Image> images;
std::vector<Texture> textures; std::vector<Texture> textures;
std::vector<Material> materials; std::vector<Material> materials;
std::vector<Node*> nodes; std::vector<Node *> nodes;
std::vector<Skin> skins; std::vector<Skin> skins;
std::vector<Animation> animations; std::vector<Animation> animations;
uint32_t activeAnimation = 0; uint32_t activeAnimation = 0;
~VulkanglTFModel(); ~VulkanglTFModel();
void loadImages(tinygltf::Model& input); void loadImages(tinygltf::Model &input);
void loadTextures(tinygltf::Model& input); void loadTextures(tinygltf::Model &input);
void loadMaterials(tinygltf::Model& input); void loadMaterials(tinygltf::Model &input);
Node* findNode(Node* parent, uint32_t index); Node * findNode(Node *parent, uint32_t index);
Node* nodeFromIndex(uint32_t index); Node * nodeFromIndex(uint32_t index);
void loadSkins(tinygltf::Model& input); void loadSkins(tinygltf::Model &input);
void loadAnimations(tinygltf::Model& input); void loadAnimations(tinygltf::Model &input);
void loadNode(const tinygltf::Node& inputNode, const tinygltf::Model& input, VulkanglTFModel::Node* parent, uint32_t nodeIndex, std::vector<uint32_t>& indexBuffer, std::vector<VulkanglTFModel::Vertex>& vertexBuffer); void loadNode(const tinygltf::Node &inputNode, const tinygltf::Model &input, VulkanglTFModel::Node *parent, uint32_t nodeIndex, std::vector<uint32_t> &indexBuffer, std::vector<VulkanglTFModel::Vertex> &vertexBuffer);
glm::mat4 getNodeMatrix(VulkanglTFModel::Node* node); glm::mat4 getNodeMatrix(VulkanglTFModel::Node *node);
void updateJoints(VulkanglTFModel::Node* node); void updateJoints(VulkanglTFModel::Node *node);
void updateAnimation(float deltaTime); void updateAnimation(float deltaTime);
void drawNode(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout, VulkanglTFModel::Node node); void drawNode(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout, VulkanglTFModel::Node node);
void draw(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout); void draw(VkCommandBuffer commandBuffer, VkPipelineLayout pipelineLayout);
}; };
class VulkanExample : public VulkanExampleBase class VulkanExample : public VulkanExampleBase
{ {
public: public:
bool wireframe = false; bool wireframe = false;
struct ShaderData { struct ShaderData
{
vks::Buffer buffer; vks::Buffer buffer;
struct Values { struct Values
{
glm::mat4 projection; glm::mat4 projection;
glm::mat4 model; glm::mat4 model;
glm::vec4 lightPos = glm::vec4(5.0f, 5.0f, 5.0f, 1.0f); glm::vec4 lightPos = glm::vec4(5.0f, 5.0f, 5.0f, 1.0f);
@ -196,12 +205,14 @@ public:
} shaderData; } shaderData;
VkPipelineLayout pipelineLayout; VkPipelineLayout pipelineLayout;
struct Pipelines { struct Pipelines
{
VkPipeline solid; VkPipeline solid;
VkPipeline wireframe = VK_NULL_HANDLE; VkPipeline wireframe = VK_NULL_HANDLE;
} pipelines; } pipelines;
struct DescriptorSetLayouts { struct DescriptorSetLayouts
{
VkDescriptorSetLayout matrices; VkDescriptorSetLayout matrices;
VkDescriptorSetLayout textures; VkDescriptorSetLayout textures;
VkDescriptorSetLayout jointMatrices; VkDescriptorSetLayout jointMatrices;
@ -212,15 +223,15 @@ public:
VulkanExample(); VulkanExample();
~VulkanExample(); ~VulkanExample();
void loadglTFFile(std::string filename); void loadglTFFile(std::string filename);
virtual void getEnabledFeatures(); virtual void getEnabledFeatures();
void buildCommandBuffers(); void buildCommandBuffers();
void loadAssets(); void loadAssets();
void setupDescriptors(); void setupDescriptors();
void preparePipelines(); void preparePipelines();
void prepareUniformBuffers(); void prepareUniformBuffers();
void updateUniformBuffers(); void updateUniformBuffers();
void prepare(); void prepare();
virtual void render(); virtual void render();
virtual void OnUpdateUIOverlay(vks::UIOverlay* overlay); virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay);
}; };