|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <cstring>
|
|
|
|
#include <optional>
|
|
|
|
#include <set>
|
|
|
|
#include <fstream>
|
|
|
|
#include <numeric>
|
|
|
|
#include <chrono>
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
|
|
|
#include <vulkan/vulkan_core.h>
|
|
|
|
#include <map>
|
|
|
|
#include <glm/vec2.hpp>
|
|
|
|
#include "constraints.hpp"
|
|
|
|
#include <glm/mat4x4.hpp>
|
|
|
|
#include <glm/vec3.hpp>
|
|
|
|
|
|
|
|
using std::unique_ptr, std::make_unique;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
class SoftBody;
|
|
|
|
class Instance;
|
|
|
|
class Swapchain;
|
|
|
|
class GraphicsPipeline;
|
|
|
|
class Buffer;
|
|
|
|
class CommandPool;
|
|
|
|
class Image;
|
|
|
|
class ComputePipeline;
|
|
|
|
class Fence;
|
|
|
|
class Semaphore;
|
|
|
|
class Camera;
|
|
|
|
class DescriptorPool;
|
|
|
|
class Grabber;
|
|
|
|
|
|
|
|
class Application {
|
|
|
|
public:
|
|
|
|
explicit Application();
|
|
|
|
void mainLoop();
|
|
|
|
~Application();
|
|
|
|
private:
|
|
|
|
|
|
|
|
void createSyncObjects();
|
|
|
|
unique_ptr<Semaphore> imageAvailable;
|
|
|
|
unique_ptr<Semaphore> renderFinished;
|
|
|
|
unique_ptr<Semaphore> computeSemaphore;
|
|
|
|
unique_ptr<Semaphore> transferFinished;
|
|
|
|
unique_ptr<Fence> renderFence;
|
|
|
|
unique_ptr<Fence> computeFence;
|
|
|
|
unique_ptr<Fence> transferFence;
|
|
|
|
std::mutex submitMutex;
|
|
|
|
|
|
|
|
unique_ptr<Swapchain> swapchain;
|
|
|
|
unique_ptr<DescriptorPool> descriptorPool;
|
|
|
|
unique_ptr<GraphicsPipeline> graphicsPipeline;
|
|
|
|
|
|
|
|
struct CameraUniformData {
|
|
|
|
glm::mat4 view;
|
|
|
|
glm::mat4 projection;
|
|
|
|
glm::vec2 viewport;
|
|
|
|
};
|
|
|
|
unique_ptr<Buffer> cameraUniformBuffer;
|
|
|
|
|
|
|
|
unique_ptr<Camera> camera;
|
|
|
|
unique_ptr<Grabber> grabber;
|
|
|
|
unique_ptr<Buffer> grabBuffer;
|
|
|
|
|
|
|
|
void createMeshBuffers();
|
|
|
|
size_t currentDrawVertexBuffer = 0;
|
|
|
|
unique_ptr<Buffer> vertexBuffers[2];
|
|
|
|
unique_ptr<Buffer> faceBuffer;
|
|
|
|
unique_ptr<Buffer> edgeBuffer;
|
|
|
|
unique_ptr<Buffer> triangleBuffer;
|
|
|
|
unique_ptr<Buffer> tetrahedronBuffer;
|
|
|
|
ConstraintData constraintData {};
|
|
|
|
vector<unique_ptr<SoftBody>> softBodies;
|
|
|
|
|
|
|
|
struct SizeInformation {
|
|
|
|
uint32_t vertexCount;
|
|
|
|
uint32_t faceCount;
|
|
|
|
uint32_t edgeCount;
|
|
|
|
uint32_t triangleCount;
|
|
|
|
uint32_t tetrahedronCount;
|
|
|
|
};
|
|
|
|
unique_ptr<Buffer> sizeInformationBuffer;
|
|
|
|
|
|
|
|
struct Properties {
|
|
|
|
glm::vec3 gravity;
|
|
|
|
// Delta time in seconds
|
|
|
|
float dt;
|
|
|
|
uint32_t k;
|
|
|
|
};
|
|
|
|
unique_ptr<Buffer> propertiesBuffer;
|
|
|
|
Properties properties {};
|
|
|
|
|
|
|
|
struct GrabPushConstants {
|
|
|
|
uint32_t state;
|
|
|
|
alignas(8) glm::vec2 screenPosition;
|
|
|
|
glm::vec2 screenDelta;
|
|
|
|
};
|
|
|
|
|
|
|
|
void createComputePipelines();
|
|
|
|
unique_ptr<ComputePipeline> grabPipeline;
|
|
|
|
unique_ptr<ComputePipeline> pbdPipeline;
|
|
|
|
unique_ptr<ComputePipeline> normalPipeline;
|
|
|
|
|
|
|
|
void updateUniformBuffer();
|
|
|
|
void recordDrawCommands(VkCommandBuffer cmdBuffer);
|
|
|
|
void drawFrame();
|
|
|
|
|
|
|
|
void recordGrabCommands(VkCommandBuffer cmdBuffer);
|
|
|
|
void recordPBDCommands(VkCommandBuffer cmdBuffer);
|
|
|
|
void recordNormalCommands(VkCommandBuffer cmdBuffer);
|
|
|
|
struct PBDPushData {
|
|
|
|
uint32_t state;
|
|
|
|
ConstraintData::Partition edgePartition;
|
|
|
|
ConstraintData::Partition tetrahedronPartition;
|
|
|
|
};
|
|
|
|
|
|
|
|
void update();
|
|
|
|
|
|
|
|
static uint32_t GetGroupCount(uint32_t threads, uint32_t blockSize);
|
|
|
|
};
|