#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "constraints.hpp" #include "fixed_list.hpp" #include #include #include using std::unique_ptr, std::make_unique; using std::vector; using std::optional; class SoftBody; class Instance; class Swapchain; class GraphicsPipeline; class Buffer; class SimulationBuffer; class CommandPool; class Image; class ComputePipeline; class Fence; class Semaphore; class Camera; class DescriptorPool; class Grabber; struct SizesUniformData; class Application { public: explicit Application(); void mainLoop(); ~Application(); private: void imGuiWindows(); struct PerformanceInformation { static const size_t saves = 30; FixedList recentTotalUpdateDurations = FixedList(saves); float updateDuration; FixedList recentFrameDurations = FixedList(saves); } performanceInformation; void createSyncObjects(); unique_ptr imageAvailable; unique_ptr renderSemaphore; unique_ptr computeSemaphore; unique_ptr transferSemaphore; unique_ptr renderFence; unique_ptr computeFence; unique_ptr transferFence; std::mutex submitMutex; unique_ptr swapchain; unique_ptr descriptorPool; unique_ptr graphicsPipeline; unique_ptr cameraUniformBuffer; unique_ptr firstImage; unique_ptr camera; unique_ptr grabber; unique_ptr grabBuffer; void addSoftBody(const std::string& modelFile, size_t count=1); void removeSoftBody(const unique_ptr& softBody); void updateConstraintBuffers(VkCommandBuffer commandBuffer); size_t currentDrawVertexBuffer = 0; unique_ptr vertexBuffers[2]; unique_ptr faceBuffer; unique_ptr edgeBuffer; unique_ptr triangleBuffer; unique_ptr tetrahedronBuffer; ConstraintData constraintData {}; vector> softBodies; unique_ptr sizeInformationBuffer; SizesUniformData *sizeInformation = nullptr; unique_ptr simulationPropertiesBuffer; void createComputePipelines(); unique_ptr grabPipeline; unique_ptr pbdPipeline; unique_ptr normalPipeline; void updateCameraBuffer(); void recordDrawCommands(VkCommandBuffer commandBuffer); void drawFrame(float dt); void recordGrabCommands(VkCommandBuffer commandBuffer); void recordPBDCommands(VkCommandBuffer commandBuffer); void recordNormalCommands(VkCommandBuffer commandBuffer); void computePipelineBarrier(VkCommandBuffer commandBuffer); void update(); static uint32_t GetGroupCount(uint32_t threads, uint32_t blockSize); };