-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
148 lines (110 loc) · 4.73 KB
/
main.cpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//
// Created by Nikita on 12.04.2021.
//
#include "UnitTests/Example.h"
int main() {
auto* kernel = new VulkanExample();
auto printMemory = [kernel]() -> std::string {
if (!kernel->GetDevice() || !kernel->GetAllocator())
return std::string();
else
return "{" + std::to_string(kernel->GetAllocator()->GetAllocatedMemorySize() / 1024 / 1024) + "MB} ";
};
EvoVulkan::Tools::VkDebug::Instance().ErrorCallback = std::function<void(const std::string& msg)>([printMemory](const std::string& msg) {
std::cout << printMemory() << "[Error] " << msg << std::endl;
});
EvoVulkan::Tools::VkDebug::Instance().AssertCallback = std::function<bool(const std::string& msg)>([printMemory](const std::string& msg) -> bool {
std::cout << printMemory() << "[Assert] " << msg << std::endl;
return true;
});
EvoVulkan::Tools::VkDebug::Instance().GraphCallback = std::function<void(const std::string& msg)>([printMemory](const std::string& msg) {
std::cout << printMemory() << "[Graph] " << msg << std::endl;
});
EvoVulkan::Tools::VkDebug::Instance().LogCallback = std::function<void(const std::string& msg)>([printMemory](const std::string& msg) {
std::cout << printMemory() << "[Log] " << msg << std::endl;
});
EvoVulkan::Tools::VkDebug::Instance().WarnCallback = std::function<void(const std::string& msg)>([printMemory](const std::string& msg) {
std::cout << printMemory() << "[Warn] " << msg << std::endl;
});
if (!EvoVulkan::Tools::VkDebug::Instance().Ready()) {
return -1;
}
//!=================================================================================================================
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
unsigned int width = 600; //1280
unsigned int height = 600; //820
bool validationEnabled = true;
auto window = glfwCreateWindow((int)width, (int)height, "Vulkan application", nullptr, nullptr); //1280, 1024
glfwSetWindowSizeCallback(window, [](GLFWwindow* window, int width, int height) {
auto kernel = static_cast<Core::VulkanKernel*>(glfwGetWindowUserPointer(window));
kernel->SetSize(width, height);
});
//!=================================================================================================================
glfwSetWindowUserPointer(window, (void*)kernel);
kernel->SetValidationLayersEnabled(validationEnabled);
kernel->SetSize(width, height);
kernel->SetMultisampling(8);
std::vector<const char*> extensions;
extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME);
if (validationEnabled)
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
if (!kernel->PreInit("Simple engine", "NoEngine",
R"(C:\VulkanSDK\1.2.170.0\Bin\glslc.exe)",
{ extensions },
{ "VK_LAYER_KHRONOS_validation" }))
{
std::cout << "Failed to pre-initialize Evo Vulkan!\n";
return -1;
}
std::function<VkSurfaceKHR(const VkInstance& instance)> surfCreate = [window](const VkInstance& instance) -> VkSurfaceKHR {
VkSurfaceKHR surfaceKhr = {};
if (glfwCreateWindowSurface(instance, window, nullptr, &surfaceKhr) != VK_SUCCESS) {
VK_ERROR("VulkanKernel::Init(lambda) : failed to create glfw window surface!");
return VK_NULL_HANDLE;
}
else
return surfaceKhr;
};
if (!kernel->Init(
surfCreate,
glfwGetWin32Window(window),
{ VK_KHR_SWAPCHAIN_EXTENSION_NAME },
true, // sample shading
true // vsync
)) {
std::cout << "Failed to initialize Evo Vulkan!\n";
return -1;
}
if (!kernel->PostInit()) {
std::cout << "Failed to post-initialize Evo Vulkan!\n";
return -1;
}
//!=================================================================================================================
if (!kernel->LoadTexture())
return -1;
if (!kernel->LoadCubeMap())
return -1;
if (!kernel->SetupShader())
return -1;
if (!kernel->SetupUniforms())
return -1;
if (!kernel->GenerateGeometry())
return -1;
kernel->LoadSkybox();
kernel->BuildCmdBuffers();
while (!glfwWindowShouldClose(window) && !kernel->HasErrors()) {
glfwPollEvents();
kernel->NextFrame();
kernel->UpdateUBO();
}
kernel->Destroy();
delete kernel;
glfwDestroyWindow(window);
glfwTerminate();
EvoVulkan::Tools::VkDebug::Destroy();
EvoVulkan::Complexes::GLSLCompiler::Destroy();
return 0;
}