Skip to content

Commit 61e3441

Browse files
committed
Merge branch 'main' into clang_format
# Conflicts: # attachments/07_image_views.cpp # attachments/08_graphics_pipeline.cpp # attachments/09_shader_modules.cpp # attachments/10_fixed_functions.cpp # attachments/12_graphics_pipeline_complete.cpp # attachments/14_command_buffers.cpp # attachments/15_hello_triangle.cpp # attachments/16_frames_in_flight.cpp # attachments/17_swap_chain_recreation.cpp # attachments/18_vertex_input.cpp # attachments/19_vertex_buffer.cpp # attachments/20_staging_buffer.cpp # attachments/21_index_buffer.cpp # attachments/22_descriptor_layout.cpp # attachments/23_descriptor_sets.cpp # attachments/24_texture_image.cpp # attachments/25_sampler.cpp # attachments/26_texture_mapping.cpp # attachments/27_depth_buffering.cpp # attachments/28_model_loading.cpp # attachments/29_mipmapping.cpp # attachments/30_multisampling.cpp # attachments/31_compute_shader.cpp # attachments/32_ecosystem_utilities.cpp # attachments/33_vulkan_profiles.cpp # attachments/34_android.cpp # attachments/35_gltf_ktx.cpp # attachments/36_multiple_objects.cpp # attachments/37_multithreading.cpp
2 parents 4309320 + 017a919 commit 61e3441

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+28664
-29848
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@ ebook/*.epub
1111

1212
convert.py
1313

14-
attachments/build/
14+
attachments/build/**
15+
attachments/android/.gradle/**
16+
attachments/android/.idea
17+
attachments/android/.gradle/**
18+
attachments/android/app/.cxx/**
19+
attachments/android/app/build/**
20+
local.properties

attachments/00_base_code.cpp

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,64 @@
11
#include <memory>
2-
#ifdef __INTELLISENSE__
3-
# include <vulkan/vulkan_raii.hpp>
2+
#if defined(__INTELLISENSE__) || !defined(USE_CPP20_MODULES)
3+
#include <vulkan/vulkan_raii.hpp>
44
#else
55
import vulkan_hpp;
66
#endif
77
#include <GLFW/glfw3.h>
8-
#include <vulkan/vk_platform.h>
98

10-
#include <cstdlib>
119
#include <iostream>
1210
#include <stdexcept>
11+
#include <cstdlib>
1312

14-
const uint32_t WIDTH = 800;
13+
const uint32_t WIDTH = 800;
1514
const uint32_t HEIGHT = 600;
1615

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

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

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

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

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

41-
void initVulkan()
42-
{
43-
}
39+
}
4440

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

53-
void cleanup()
54-
{
55-
glfwDestroyWindow(window);
47+
void cleanup() {
48+
glfwDestroyWindow(window);
5649

57-
glfwTerminate();
58-
}
50+
glfwTerminate();
51+
}
5952
};
6053

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-
}
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+
}
7362

74-
return EXIT_SUCCESS;
63+
return EXIT_SUCCESS;
7564
}
Lines changed: 85 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,100 @@
11
#include <algorithm>
2-
#include <cstdlib>
32
#include <iostream>
4-
#include <memory>
53
#include <stdexcept>
4+
#include <cstdlib>
5+
#include <memory>
66

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

13-
#include <vulkan/vk_platform.h>
14-
15-
#define GLFW_INCLUDE_VULKAN // REQUIRED only for GLFW CreateWindowSurface.
13+
#define GLFW_INCLUDE_VULKAN // REQUIRED only for GLFW CreateWindowSurface.
1614
#include <GLFW/glfw3.h>
1715

18-
constexpr uint32_t WIDTH = 800;
16+
constexpr uint32_t WIDTH = 800;
1917
constexpr uint32_t HEIGHT = 600;
2018

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-
}
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+
}
9788
};
9889

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;
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;
113100
}

0 commit comments

Comments
 (0)