Skip to content

Commit 49965da

Browse files
committed
Reapply clang format
1 parent 61e3441 commit 49965da

37 files changed

+29902
-28402
lines changed

attachments/00_base_code.cpp

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <memory>
22
#if defined(__INTELLISENSE__) || !defined(USE_CPP20_MODULES)
3-
#include <vulkan/vulkan_raii.hpp>
3+
# include <vulkan/vulkan_raii.hpp>
44
#else
55
import vulkan_hpp;
66
#endif
@@ -10,55 +10,65 @@ import vulkan_hpp;
1010
#include <stdexcept>
1111
#include <cstdlib>
1212

13-
const uint32_t WIDTH = 800;
13+
const uint32_t WIDTH = 800;
1414
const uint32_t HEIGHT = 600;
1515

16-
class HelloTriangleApplication {
17-
public:
18-
void run() {
19-
initWindow();
20-
initVulkan();
21-
mainLoop();
22-
cleanup();
23-
}
16+
class HelloTriangleApplication
17+
{
18+
public:
19+
void run()
20+
{
21+
initWindow();
22+
initVulkan();
23+
mainLoop();
24+
cleanup();
25+
}
2426

25-
private:
26-
GLFWwindow* window = nullptr;
27+
private:
28+
GLFWwindow *window = nullptr;
2729

28-
void initWindow() {
29-
glfwInit();
30+
void initWindow()
31+
{
32+
glfwInit();
3033

31-
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
32-
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
34+
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
35+
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
3336

34-
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
35-
}
37+
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
38+
}
3639

37-
void initVulkan() {
40+
void initVulkan()
41+
{
42+
}
3843

39-
}
44+
void mainLoop()
45+
{
46+
while (!glfwWindowShouldClose(window))
47+
{
48+
glfwPollEvents();
49+
}
50+
}
4051

41-
void mainLoop() {
42-
while (!glfwWindowShouldClose(window)) {
43-
glfwPollEvents();
44-
}
45-
}
52+
void cleanup()
53+
{
54+
glfwDestroyWindow(window);
4655

47-
void cleanup() {
48-
glfwDestroyWindow(window);
49-
50-
glfwTerminate();
51-
}
56+
glfwTerminate();
57+
}
5258
};
5359

54-
int main() {
55-
try {
56-
HelloTriangleApplication app;
57-
app.run();
58-
} catch (const std::exception& e) {
59-
std::cerr << e.what() << std::endl;
60-
return EXIT_FAILURE;
61-
}
60+
int main()
61+
{
62+
try
63+
{
64+
HelloTriangleApplication app;
65+
app.run();
66+
}
67+
catch (const std::exception &e)
68+
{
69+
std::cerr << e.what() << std::endl;
70+
return EXIT_FAILURE;
71+
}
6272

63-
return EXIT_SUCCESS;
73+
return EXIT_SUCCESS;
6474
}

attachments/01_instance_creation.cpp

Lines changed: 93 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -5,96 +5,107 @@
55
#include <memory>
66

77
#if defined(__INTELLISENSE__) || !defined(USE_CPP20_MODULES)
8-
#include <vulkan/vulkan_raii.hpp>
8+
# include <vulkan/vulkan_raii.hpp>
99
#else
1010
import vulkan_hpp;
1111
#endif
1212

13-
#define GLFW_INCLUDE_VULKAN // REQUIRED only for GLFW CreateWindowSurface.
13+
#define GLFW_INCLUDE_VULKAN // REQUIRED only for GLFW CreateWindowSurface.
1414
#include <GLFW/glfw3.h>
1515

16-
constexpr uint32_t WIDTH = 800;
16+
constexpr uint32_t WIDTH = 800;
1717
constexpr uint32_t HEIGHT = 600;
1818

19-
class HelloTriangleApplication {
20-
public:
21-
void run() {
22-
initWindow();
23-
initVulkan();
24-
mainLoop();
25-
cleanup();
26-
}
27-
28-
private:
29-
GLFWwindow* window = nullptr;
30-
31-
vk::raii::Context context;
32-
vk::raii::Instance instance = nullptr;
33-
34-
void initWindow() {
35-
glfwInit();
36-
37-
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
38-
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
39-
40-
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
41-
}
42-
43-
void initVulkan() {
44-
createInstance();
45-
}
46-
47-
void mainLoop() {
48-
while (!glfwWindowShouldClose(window)) {
49-
glfwPollEvents();
50-
}
51-
}
52-
53-
void cleanup() {
54-
glfwDestroyWindow(window);
55-
56-
glfwTerminate();
57-
}
58-
59-
void createInstance() {
60-
constexpr vk::ApplicationInfo appInfo{ .pApplicationName = "Hello Triangle",
61-
.applicationVersion = VK_MAKE_VERSION( 1, 0, 0 ),
62-
.pEngineName = "No Engine",
63-
.engineVersion = VK_MAKE_VERSION( 1, 0, 0 ),
64-
.apiVersion = vk::ApiVersion14 };
65-
66-
// Get the required instance extensions from GLFW.
67-
uint32_t glfwExtensionCount = 0;
68-
auto glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
69-
70-
// Check if the required GLFW extensions are supported by the Vulkan implementation.
71-
auto extensionProperties = context.enumerateInstanceExtensionProperties();
72-
for (uint32_t i = 0; i < glfwExtensionCount; ++i)
73-
{
74-
if (std::ranges::none_of(extensionProperties,
75-
[glfwExtension = glfwExtensions[i]](auto const& extensionProperty)
76-
{ return strcmp(extensionProperty.extensionName, glfwExtension) == 0; }))
77-
{
78-
throw std::runtime_error("Required GLFW extension not supported: " + std::string(glfwExtensions[i]));
79-
}
80-
}
81-
82-
vk::InstanceCreateInfo createInfo{
83-
.pApplicationInfo = &appInfo,
84-
.enabledExtensionCount = glfwExtensionCount,
85-
.ppEnabledExtensionNames = glfwExtensions};
86-
instance = vk::raii::Instance(context, createInfo);
87-
}
19+
class HelloTriangleApplication
20+
{
21+
public:
22+
void run()
23+
{
24+
initWindow();
25+
initVulkan();
26+
mainLoop();
27+
cleanup();
28+
}
29+
30+
private:
31+
GLFWwindow *window = nullptr;
32+
33+
vk::raii::Context context;
34+
vk::raii::Instance instance = nullptr;
35+
36+
void initWindow()
37+
{
38+
glfwInit();
39+
40+
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
41+
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
42+
43+
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
44+
}
45+
46+
void initVulkan()
47+
{
48+
createInstance();
49+
}
50+
51+
void mainLoop()
52+
{
53+
while (!glfwWindowShouldClose(window))
54+
{
55+
glfwPollEvents();
56+
}
57+
}
58+
59+
void cleanup()
60+
{
61+
glfwDestroyWindow(window);
62+
63+
glfwTerminate();
64+
}
65+
66+
void createInstance()
67+
{
68+
constexpr vk::ApplicationInfo appInfo{.pApplicationName = "Hello Triangle",
69+
.applicationVersion = VK_MAKE_VERSION(1, 0, 0),
70+
.pEngineName = "No Engine",
71+
.engineVersion = VK_MAKE_VERSION(1, 0, 0),
72+
.apiVersion = vk::ApiVersion14};
73+
74+
// Get the required instance extensions from GLFW.
75+
uint32_t glfwExtensionCount = 0;
76+
auto glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
77+
78+
// Check if the required GLFW extensions are supported by the Vulkan implementation.
79+
auto extensionProperties = context.enumerateInstanceExtensionProperties();
80+
for (uint32_t i = 0; i < glfwExtensionCount; ++i)
81+
{
82+
if (std::ranges::none_of(extensionProperties,
83+
[glfwExtension = glfwExtensions[i]](auto const &extensionProperty) { return strcmp(extensionProperty.extensionName, glfwExtension) == 0; }))
84+
{
85+
throw std::runtime_error("Required GLFW extension not supported: " + std::string(glfwExtensions[i]));
86+
}
87+
}
88+
89+
vk::InstanceCreateInfo createInfo{
90+
.pApplicationInfo = &appInfo,
91+
.enabledExtensionCount = glfwExtensionCount,
92+
.ppEnabledExtensionNames = glfwExtensions};
93+
instance = vk::raii::Instance(context, createInfo);
94+
}
8895
};
8996

90-
int main() {
91-
try {
92-
HelloTriangleApplication app;
93-
app.run();
94-
} catch (const std::exception& e) {
95-
std::cerr << e.what() << std::endl;
96-
return EXIT_FAILURE;
97-
}
98-
99-
return EXIT_SUCCESS;
97+
int main()
98+
{
99+
try
100+
{
101+
HelloTriangleApplication app;
102+
app.run();
103+
}
104+
catch (const std::exception &e)
105+
{
106+
std::cerr << e.what() << std::endl;
107+
return EXIT_FAILURE;
108+
}
109+
110+
return EXIT_SUCCESS;
100111
}

0 commit comments

Comments
 (0)