Repository navigation
Expand file tree
/
Copy pathMain.cpp
More file actions
86 lines (73 loc) · 3.06 KB
/
Copy pathMain.cpp
File metadata and controls
86 lines (73 loc) · 3.06 KB
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
/**
* @file Main.cpp
* @brief This example demonstrates GPU cloth simulation in Vulkan using a ping-pong compute pipeline, where 3 compute
* shaders (integration, Jacobi constraint solving, and update) run each frame to simulate a cloth grid under
* gravity with structural, shear, and bend constraints, plus collision against sphere and ground plane.
* @author Mustafa Yemural (myemural)
* @date 24.08.2026
*
* Copyright (c) 2025 Mustafa Yemural - www.mustafayemural.com
* Released under the MIT License
* https://opensource.org/licenses/MIT
*/
#include "AppCommonConfig.h"
#include "AppConfig.h"
#include "ShaderLoader.h"
#include "VulkanApplication.h"
#include "Window.h"
using namespace common::utility;
using namespace common::window_wrapper;
using namespace common::vulkan_framework;
using namespace examples::advanced_shader_programming::advanced_compute_shaders::cloth_simulation_compute;
inline ParameterSchema CreateParameterSchema()
{
ParameterSchema schema;
SetCommonParamSchema(schema);
// Register Customizable Settings
schema.RegisterParam<VkClearColorValue>(AppSettings::ClearColor);
schema.RegisterParam<float>(AppSettings::MouseSensitivity);
schema.RegisterParam<float>(AppSettings::CameraSpeed);
return schema;
}
bool SetParams(ParameterServer& params)
{
try {
// Initial window settings
params.Set<std::uint32_t>(WindowParams::Width, 1280);
params.Set<std::uint32_t>(WindowParams::Height, 720);
params.Set(WindowParams::Title, std::string(EXAMPLE_APPLICATION_NAME));
// Vulkan settings
params.Set<std::string>(VulkanParams::ApplicationName, params.Get<std::string>(WindowParams::Title));
params.Set<std::vector<std::string>>(VulkanParams::InstanceLayers, {"VK_LAYER_KHRONOS_validation"});
// Project customizable settings
params.Set(AppSettings::ClearColor, VkClearColorValue{0.175f, 0.175f, 0.175f, 1.0f});
params.Set(AppSettings::MouseSensitivity, 3.0f);
params.Set(AppSettings::CameraSpeed, 3.0f);
} catch (const std::exception& e) {
std::cerr << e.what() << '\n';
return false;
}
return true;
}
int main()
{
ParameterServer params{CreateParameterSchema()};
if (!SetParams(params)) {
std::cerr << "Failed to set parameters!" << std::endl;
return -1;
}
// Create a window
const auto window = std::make_shared<Window>(params.Get<std::string>(WindowParams::Title));
if (!window->Init(params.Get<std::uint32_t>(WindowParams::Width), params.Get<std::uint32_t>(WindowParams::Height),
params.Get<bool>(WindowParams::Resizable))) {
std::cerr << "Failed to initialize window." << std::endl;
return -1;
}
params.Set<std::vector<std::string>>(VulkanParams::InstanceExtensions, Window::GetVulkanInstanceExtensions());
params.Set<std::uint32_t>(VulkanParams::VulkanApiVersion, VK_API_VERSION_1_2);
// Init Vulkan application
VulkanApplication app{std::move(params)};
app.SetWindow(window);
app.Run();
return 0;
}