Skip to content

Commit adf6d32

Browse files
committed
Apply clang format to all C++ source files
1 parent 14e266f commit adf6d32

35 files changed

+26317
-25105
lines changed

attachments/00_base_code.cpp

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,75 @@
11
#include <memory>
22
#ifdef __INTELLISENSE__
3-
#include <vulkan/vulkan_raii.hpp>
3+
# include <vulkan/vulkan_raii.hpp>
44
#else
55
import vulkan_hpp;
66
#endif
7-
#include <vulkan/vk_platform.h>
87
#include <GLFW/glfw3.h>
8+
#include <vulkan/vk_platform.h>
99

10+
#include <cstdlib>
1011
#include <iostream>
1112
#include <stdexcept>
12-
#include <cstdlib>
1313

14-
const uint32_t WIDTH = 800;
14+
const uint32_t WIDTH = 800;
1515
const uint32_t HEIGHT = 600;
1616

17-
class HelloTriangleApplication {
18-
public:
19-
void run() {
20-
initWindow();
21-
initVulkan();
22-
mainLoop();
23-
cleanup();
24-
}
25-
26-
private:
27-
GLFWwindow* window = nullptr;
17+
class HelloTriangleApplication
18+
{
19+
public:
20+
void run()
21+
{
22+
initWindow();
23+
initVulkan();
24+
mainLoop();
25+
cleanup();
26+
}
2827

29-
void initWindow() {
30-
glfwInit();
28+
private:
29+
GLFWwindow *window = nullptr;
3130

32-
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
33-
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
31+
void initWindow()
32+
{
33+
glfwInit();
3434

35-
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
36-
}
35+
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
36+
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
3737

38-
void initVulkan() {
38+
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
39+
}
3940

40-
}
41+
void initVulkan()
42+
{
43+
}
4144

42-
void mainLoop() {
43-
while (!glfwWindowShouldClose(window)) {
44-
glfwPollEvents();
45-
}
46-
}
45+
void mainLoop()
46+
{
47+
while (!glfwWindowShouldClose(window))
48+
{
49+
glfwPollEvents();
50+
}
51+
}
4752

48-
void cleanup() {
49-
glfwDestroyWindow(window);
53+
void cleanup()
54+
{
55+
glfwDestroyWindow(window);
5056

51-
glfwTerminate();
52-
}
57+
glfwTerminate();
58+
}
5359
};
5460

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

64-
return EXIT_SUCCESS;
74+
return EXIT_SUCCESS;
6575
}
Lines changed: 95 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,113 @@
11
#include <algorithm>
2-
#include <iostream>
3-
#include <stdexcept>
42
#include <cstdlib>
3+
#include <iostream>
54
#include <memory>
5+
#include <stdexcept>
66

77
#ifdef __INTELLISENSE__
8-
#include <vulkan/vulkan_raii.hpp>
8+
# include <vulkan/vulkan_raii.hpp>
99
#else
1010
import vulkan_hpp;
1111
#endif
1212

1313
#include <vulkan/vk_platform.h>
1414

15-
#define GLFW_INCLUDE_VULKAN // REQUIRED only for GLFW CreateWindowSurface.
15+
#define GLFW_INCLUDE_VULKAN // REQUIRED only for GLFW CreateWindowSurface.
1616
#include <GLFW/glfw3.h>
1717

18-
constexpr uint32_t WIDTH = 800;
18+
constexpr uint32_t WIDTH = 800;
1919
constexpr uint32_t HEIGHT = 600;
2020

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

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

0 commit comments

Comments
 (0)