Skip to content

Commit 736bcab

Browse files
committed
Improve
Refactor Refactor 0103 Refactor 3 Refactor 4 Refactor 5 Refactor 5
1 parent ec84f9c commit 736bcab

File tree

195 files changed

+14042
-19091
lines changed

Some content is hidden

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

195 files changed

+14042
-19091
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
${{ runner.os }}-pip-
3232
3333
- name: Install MkDocs and dependencies
34-
run: pip install mkdocs-material pygments
34+
run: pip install mkdocs-material
3535

3636
- name: Build Docs
3737
run: mkdocs build --site-dir public

CMakeLists.txt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,34 @@ set(CMAKE_TOOLCHAIN_FILE "${VCPKG_CMAKE_PATH}/scripts/buildsystems/vcpkg.cmake")
1111

1212
project(HelloVulkan LANGUAGES CXX)
1313

14-
set(CMAKE_CXX_STANDARD 20)
15-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
14+
set(CMAKE_CXX_STANDARD 23)
1615

16+
#################################################################################
17+
#### Search for Vulkan package.
18+
# CMake provides FindVulkan support, but requires the VULKAN_SDK environment variable
19+
# Setting by default during Vulkan SDK installation, such as E: \ Vulkan \ 1.4.309.0
20+
find_package(Vulkan REQUIRED)
21+
#################################################################################
1722

18-
include(cmake/VulkanHppModule.cmake)
19-
23+
#################################################################################
24+
#### add_executable
25+
# Import third-party libraries through vcpkg
2026
find_package(glfw3 CONFIG REQUIRED)
2127
find_package(glm CONFIG REQUIRED)
2228
find_package(Stb REQUIRED)
2329
find_package(tinyobjloader CONFIG REQUIRED)
2430

25-
file(GLOB_RECURSE MODULE_SOURCES src/*.cppm)
26-
2731
# Add executable program targets
28-
add_executable( main src/main.cpp )
29-
target_sources( main PRIVATE
30-
FILE_SET CXX_MODULES
31-
FILES ${MODULE_SOURCES}
32-
)
33-
34-
target_link_libraries(main PRIVATE VulkanHppModule )
35-
target_link_libraries(main PRIVATE glm::glm)
36-
target_link_libraries(main PRIVATE glfw )
37-
target_include_directories(main PRIVATE ${Stb_INCLUDE_DIR})
38-
target_link_libraries(main PRIVATE tinyobjloader::tinyobjloader)
32+
add_executable(${PROJECT_NAME} src/main.cpp)
3933

40-
add_subdirectory(shaders)
34+
target_link_libraries(${PROJECT_NAME} PRIVATE Vulkan::Vulkan )
35+
target_link_libraries(${PROJECT_NAME} PRIVATE glm::glm )
36+
target_link_libraries(${PROJECT_NAME} PRIVATE glfw )
37+
target_include_directories(${PROJECT_NAME} PRIVATE ${Stb_INCLUDE_DIR})
38+
target_link_libraries(${PROJECT_NAME} PRIVATE tinyobjloader::tinyobjloader)
39+
#################################################################################
4140

41+
#################################################################################
42+
#### shader compilation
43+
add_subdirectory(shaders)
44+
#################################################################################

CMakePresets.json

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
}
1919
},
2020
{
21-
"name": "win-x64",
22-
"description": "Windows x64 config presets(MSVC + Ninja Multi-Config)",
21+
"name": "win-msvc",
22+
"description": "Windows x64 config (MSVC + Ninja Multi-Config)",
2323
"inherits": "ninja-base",
2424
"generator": "Ninja Multi-Config",
2525
"cacheVariables": {
@@ -37,6 +37,17 @@
3737
"rhs": "Windows"
3838
}
3939
},
40+
{
41+
"name": "win-clang",
42+
"description": "Windows x64 config (Clang + MinGW + Ninja Multi-Config), not support STD Module",
43+
"inherits": "win-msvc",
44+
"generator": "Ninja Multi-Config",
45+
"cacheVariables": {
46+
"CMAKE_CONFIGURATION_TYPES": "Debug;Release",
47+
"CMAKE_CXX_COMPILER": "clang++",
48+
"CMAKE_C_COMPILER": "clang"
49+
}
50+
},
4051
{
4152
"name": "unix-gnu-debug",
4253
"description": "Linux/macOS GNU Debug config presets(GNU + Ninja)",
@@ -82,17 +93,31 @@
8293
],
8394
"buildPresets": [
8495
{
85-
"name": "win-x64-build-debug",
86-
"displayName": "win-x64 Build Debug",
87-
"description": "win-x64 build Debug preset",
88-
"configurePreset": "win-x64",
96+
"name": "win-msvc-build-debug",
97+
"displayName": "win-msvc Build Debug",
98+
"description": "win-msvc build Debug preset",
99+
"configurePreset": "win-msvc",
100+
"configuration": "Debug"
101+
},
102+
{
103+
"name": "win-msvc-build-release",
104+
"displayName": "win-msvc Build Release",
105+
"description": "win-msvc build Release preset",
106+
"configurePreset": "win-msvc",
107+
"configuration": "Release"
108+
},
109+
{
110+
"name": "win-clang-build-debug",
111+
"displayName": "win-clang Build Debug",
112+
"description": "win-clang build Debug preset",
113+
"configurePreset": "win-clang",
89114
"configuration": "Debug"
90115
},
91116
{
92-
"name": "win-x64-build-release",
93-
"displayName": "win-x64 Build Release",
94-
"description": "win-x64 build Release preset",
95-
"configurePreset": "win-x64",
117+
"name": "win-clang-build-release",
118+
"displayName": "win-clang Build Release",
119+
"description": "win-clang build Release preset",
120+
"configurePreset": "win-clang",
96121
"configuration": "Release"
97122
},
98123
{

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,18 @@
5757

5858
### 安装构建依赖
5959

60-
项目使用 material-mkdocs 构建,还需要 pymdownx 扩展。请使用 pip 或 conda 安装下面的两个库:
60+
项目使用 material-mkdocs 构建,请使用 pip 或 conda 安装下面的两个库:
6161

6262
pip:
6363

6464
```shell
6565
pip install mkdocs-material
66-
pip install pygments
6766
```
6867

6968
conda(请先选择并激活合适的虚拟环境):
7069

7170
```shell
7271
conda install conda-forge::mkdocs-material
73-
conda install conda-forge::pygments
7472
```
7573

7674
### 生成静态网页资源

docs/codes/00/01_env/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(CMAKE_TOOLCHAIN_FILE "${VCPKG_CMAKE_PATH}/scripts/buildsystems/vcpkg.cmake")
1111

1212
project(HelloVulkan LANGUAGES CXX)
1313

14-
set(CMAKE_CXX_STANDARD 20)
14+
set(CMAKE_CXX_STANDARD 23)
1515

1616
#################################################################################
1717
#### Search for Vulkan package.

docs/codes/00/01_env/CMakePresets.json

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
}
1919
},
2020
{
21-
"name": "win-x64",
22-
"description": "Windows x64 config presets(MSVC + Ninja Multi-Config)",
21+
"name": "win-msvc",
22+
"description": "Windows x64 config (MSVC + Ninja Multi-Config)",
2323
"inherits": "ninja-base",
2424
"generator": "Ninja Multi-Config",
2525
"cacheVariables": {
@@ -37,6 +37,17 @@
3737
"rhs": "Windows"
3838
}
3939
},
40+
{
41+
"name": "win-clang",
42+
"description": "Windows x64 config (Clang + MinGW + Ninja Multi-Config), not support STD Module",
43+
"inherits": "win-msvc",
44+
"generator": "Ninja Multi-Config",
45+
"cacheVariables": {
46+
"CMAKE_CONFIGURATION_TYPES": "Debug;Release",
47+
"CMAKE_CXX_COMPILER": "clang++",
48+
"CMAKE_C_COMPILER": "clang"
49+
}
50+
},
4051
{
4152
"name": "unix-gnu-debug",
4253
"description": "Linux/macOS GNU Debug config presets(GNU + Ninja)",
@@ -82,17 +93,31 @@
8293
],
8394
"buildPresets": [
8495
{
85-
"name": "win-x64-build-debug",
86-
"displayName": "win-x64 Build Debug",
87-
"description": "win-x64 build Debug preset",
88-
"configurePreset": "win-x64",
96+
"name": "win-msvc-build-debug",
97+
"displayName": "win-msvc Build Debug",
98+
"description": "win-msvc build Debug preset",
99+
"configurePreset": "win-msvc",
100+
"configuration": "Debug"
101+
},
102+
{
103+
"name": "win-msvc-build-release",
104+
"displayName": "win-msvc Build Release",
105+
"description": "win-msvc build Release preset",
106+
"configurePreset": "win-msvc",
107+
"configuration": "Release"
108+
},
109+
{
110+
"name": "win-clang-build-debug",
111+
"displayName": "win-clang Build Debug",
112+
"description": "win-clang build Debug preset",
113+
"configurePreset": "win-clang",
89114
"configuration": "Debug"
90115
},
91116
{
92-
"name": "win-x64-build-release",
93-
"displayName": "win-x64 Build Release",
94-
"description": "win-x64 build Release preset",
95-
"configurePreset": "win-x64",
117+
"name": "win-clang-build-release",
118+
"displayName": "win-clang Build Release",
119+
"description": "win-clang build Release preset",
120+
"configurePreset": "win-clang",
96121
"configuration": "Release"
97122
},
98123
{

docs/codes/00/01_env/main.cpp

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,42 @@
11
// main.cpp
2+
#include <iostream>
3+
#include <string_view>
4+
#include <print>
5+
26
#include <vulkan/vulkan.hpp>
37
#include <vulkan/vulkan_raii.hpp>
8+
49
#include <GLFW/glfw3.h>
10+
511
#define GLM_FORCE_RADIANS
612
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
713
#include <glm/vec4.hpp>
814
#include <glm/mat4x4.hpp>
915

10-
#include <iostream>
11-
1216
int main() {
13-
glfwInit();
14-
15-
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
16-
GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);
17-
18-
uint32_t extensionCount = 0;
19-
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
17+
// vulkan test
18+
const vk::raii::Context context;
19+
const auto extensions = context.enumerateInstanceExtensionProperties();
20+
std::cout << "vulkan available extensions:" << std::endl;
21+
for (const auto& extension : extensions) {
22+
std::println("{}", std::string_view( extension.extensionName ));
23+
}
2024

21-
std::cout << extensionCount << " extensions supported\n";
25+
vk::raii::Semaphore semaphore( nullptr );
2226

23-
glm::mat4 matrix;
24-
glm::vec4 vec;
25-
auto test = matrix * vec;
27+
// glm test
28+
constexpr glm::mat4 matrix(1.0f);
29+
constexpr glm::vec4 vec(1.0f, 2.0f, 3.0f, 4.0f);
30+
constexpr glm::vec4 test = matrix * vec;
31+
std::println("{} {} {} {}", test.x, test.y, test.z, test.w);
2632

33+
// glfw test
34+
glfwInit();
35+
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
36+
GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);
2737
while(!glfwWindowShouldClose(window)) {
2838
glfwPollEvents();
2939
}
30-
3140
glfwDestroyWindow(window);
32-
3341
glfwTerminate();
34-
35-
return 0;
36-
}
42+
}

docs/codes/01/00_base/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set(CMAKE_TOOLCHAIN_FILE "${VCPKG_CMAKE_PATH}/scripts/buildsystems/vcpkg.cmake")
1111

1212
project(HelloVulkan LANGUAGES CXX)
1313

14-
set(CMAKE_CXX_STANDARD 20)
14+
set(CMAKE_CXX_STANDARD 23)
1515

1616
#################################################################################
1717
#### Search for Vulkan package.

docs/codes/01/00_base/main.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
#include <iostream>
2+
#include <print>
3+
#include <stdexcept>
4+
15
#include <vulkan/vulkan.hpp>
26
#include <vulkan/vulkan_raii.hpp>
37
#include <GLFW/glfw3.h>
48

5-
#include <iostream>
6-
#include <vector>
7-
#include <memory>
8-
#include <stdexcept>
9+
10+
11+
constexpr uint32_t WIDTH = 800;
12+
constexpr uint32_t HEIGHT = 600;
13+
14+
915

1016
class HelloTriangleApplication {
1117
public:
@@ -17,16 +23,10 @@ class HelloTriangleApplication {
1723
}
1824

1925
private:
20-
/////////////////////////////////////////////////////////////////
21-
/// static values
22-
static constexpr uint32_t WIDTH = 800;
23-
static constexpr uint32_t HEIGHT = 600;
24-
/////////////////////////////////////////////////////////////////
25-
26-
/////////////////////////////////////////////////////////////////
27-
/// class member
26+
/////////////////////////////////////////////////////////////
27+
//// class member
2828
GLFWwindow* m_window{ nullptr };
29-
/////////////////////////////////////////////////////////////////
29+
/////////////////////////////////////////////////////////////
3030

3131
void initWindow() {
3232
glfwInit();
@@ -51,21 +51,17 @@ class HelloTriangleApplication {
5151
glfwDestroyWindow( m_window );
5252
glfwTerminate();
5353
}
54-
55-
5654
};
5755

5856
int main() {
59-
HelloTriangleApplication app;
60-
6157
try {
58+
HelloTriangleApplication app;
6259
app.run();
63-
} catch(const vk::SystemError & err ){
60+
} catch(const vk::SystemError& err ) {
6461
// use err.code() to check err type
65-
std::cout << "vk::SystemError: " << err.what() << std::endl;
66-
} catch (const std::exception & err ){
67-
std::cout << "std::exception: " << err.what() << std::endl;
62+
std::println( std::cerr, "vk::SystemError - code: {} ",err.code().message());
63+
std::println( std::cerr, "vk::SystemError - what: {}",err.what());
64+
} catch (const std::exception& err ) {
65+
std::println( std::cerr, "std::exception: {}", err.what());
6866
}
69-
70-
return 0;
7167
}

0 commit comments

Comments
 (0)