Skip to content

Commit 7e999cf

Browse files
authored
Merge pull request #12 from ZzzhHe/refactor-model-loading
Refactor model loading
2 parents d5c6576 + 0703564 commit 7e999cf

31 files changed

Lines changed: 665 additions & 781 deletions

.github/workflows/workflow.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: |
2727
sudo apt update
2828
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck lcov
29-
sudo apt install --fix-missing -y gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev
29+
sudo apt install --fix-missing -y gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev libassimp-dev
3030
3131
- name: Build
3232
run: |
@@ -48,7 +48,7 @@ jobs:
4848
run: |
4949
sudo apt update
5050
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck lcov
51-
sudo apt install --fix-missing -y gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev
51+
sudo apt install --fix-missing -y gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev libassimp-dev
5252
5353
- name: Build
5454
run: |

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ tools/opensbi/build
1414
.idea
1515
3rd
1616
Doxyfile
17-
src/include/config.h
17+
src/include/config.h

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# 设置最小 cmake 版本
88
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)
99

10+
1011
# 设置项目名与版本
1112
project(SimpleRenderer
1213
VERSION 0.0.1)
@@ -53,4 +54,4 @@ configure_file(
5354
# 添加要编译的目录
5455
add_subdirectory(src)
5556
add_subdirectory(test)
56-
add_subdirectory(doc)
57+
add_subdirectory(doc)

CMakePresets.json

Lines changed: 80 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,84 @@
11
{
2-
"version": 6,
3-
"cmakeMinimumRequired": {
4-
"major": 3,
5-
"minor": 27,
6-
"patch": 0
7-
},
8-
"configurePresets": [
9-
{
10-
"name": "host",
11-
"description": "Linux Only",
12-
"hidden": true,
13-
"condition": {
14-
"type": "equals",
15-
"lhs": "${hostSystemName}",
16-
"rhs": "Linux"
17-
}
18-
},
19-
{
20-
"name": "std",
21-
"description": "This preset makes sure the project actually builds with at least the specified standard",
22-
"hidden": true,
23-
"cacheVariables": {
24-
"CMAKE_C_EXTENSIONS": "OFF",
25-
"CMAKE_C_STANDARD": "23",
26-
"CMAKE_C_STANDARD_REQUIRED": "ON",
27-
"CMAKE_CXX_EXTENSIONS": "OFF",
28-
"CMAKE_CXX_STANDARD": "23",
29-
"CMAKE_CXX_STANDARD_REQUIRED": "ON"
30-
}
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 23,
6+
"patch": 0
317
},
32-
{
33-
"name": "configurePresets_base",
34-
"hidden": true,
35-
"inherits": [
36-
"host",
37-
"std"
38-
],
39-
"displayName": "configurePresets_base",
40-
"description": "base configurePresets",
41-
"binaryDir": "${sourceDir}/build",
42-
"cacheVariables": {
43-
"CMAKE_EXPORT_COMPILE_COMMANDS": {
44-
"type": "BOOL",
45-
"value": "ON"
46-
},
47-
"EXECUTABLE_OUTPUT_PATH": {
48-
"type": "STRING",
49-
"value": "${sourceDir}/build/bin"
50-
},
51-
"LIBRARY_OUTPUT_PATH": {
52-
"type": "STRING",
53-
"value": "${sourceDir}/build/lib"
54-
},
55-
"COVERAGE_OUTPUT_DIR": {
56-
"type": "STRING",
57-
"value": "${sourceDir}/build/coverage"
8+
"configurePresets": [
9+
{
10+
"name": "std",
11+
"description": "This preset makes sure the project actually builds with at least the specified standard",
12+
"hidden": true,
13+
"cacheVariables": {
14+
"CMAKE_C_EXTENSIONS": "OFF",
15+
"CMAKE_C_STANDARD": "23",
16+
"CMAKE_C_STANDARD_REQUIRED": "ON",
17+
"CMAKE_CXX_EXTENSIONS": "OFF",
18+
"CMAKE_CXX_STANDARD": "23",
19+
"CMAKE_CXX_STANDARD_REQUIRED": "ON"
5820
}
21+
},
22+
{
23+
"name": "config-base",
24+
"hidden": true,
25+
"inherits": [ "std" ],
26+
"displayName": "config-base",
27+
"description": "base configurePresets",
28+
"binaryDir": "${sourceDir}/build",
29+
"cacheVariables": {
30+
"CMAKE_EXPORT_COMPILE_COMMANDS": {
31+
"type": "BOOL",
32+
"value": "ON"
33+
},
34+
"EXECUTABLE_OUTPUT_PATH": {
35+
"type": "STRING",
36+
"value": "${sourceDir}/build/bin"
37+
},
38+
"LIBRARY_OUTPUT_PATH": {
39+
"type": "STRING",
40+
"value": "${sourceDir}/build/lib"
41+
},
42+
"COVERAGE_OUTPUT_DIR": {
43+
"type": "STRING",
44+
"value": "${sourceDir}/build/coverage"
45+
}
46+
}
47+
},
48+
{
49+
"name": "config-macos",
50+
"hidden": true,
51+
"inherits": [ "config-base" ],
52+
"displayName": "config-base",
53+
"description": "macOS configurePresets",
54+
"condition": {
55+
"type": "equals",
56+
"lhs": "${hostSystemName}",
57+
"rhs": "Darwin"
58+
},
59+
"cacheVariables": {
60+
"CMAKE_MACOSX_RPATH": "1",
61+
"CMAKE_INSTALL_RPATH": "/Library/Frameworks",
62+
"CMAKE_BUILD_WITH_INSTALL_RPATH": "TRUE"
63+
}
64+
},
65+
{
66+
"name": "build",
67+
"hidden": false,
68+
"inherits": [
69+
"config-base"
70+
],
71+
"displayName": "build-base",
72+
"description": "build base configurePresets"
73+
},
74+
{
75+
"name": "build-macos",
76+
"hidden": false,
77+
"inherits": [
78+
"config-macos"
79+
],
80+
"displayName": "build-macos",
81+
"description": "macOS build configurePresets"
5982
}
60-
},
61-
{
62-
"name": "build",
63-
"hidden": false,
64-
"inherits": [
65-
"configurePresets_base"
66-
],
67-
"displayName": "build",
68-
"description": "build"
69-
}
70-
]
71-
}
83+
]
84+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ A software renderer
5252
## 依赖
5353

5454
```shell
55-
sudo apt install doxygen graphviz clang-format clang-tidy cppcheck lcov gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev cmake vim
55+
sudo apt install doxygen graphviz clang-format clang-tidy cppcheck lcov gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev cmake vim libassimp-dev
5656
```
5757

5858
## 使用

cmake/3rd.cmake

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -46,54 +46,35 @@ endif ()
4646
include(${CPM_DOWNLOAD_LOCATION})
4747
# -------- get_cpm.cmake --------
4848

49-
# https://github.com/google/googletest
5049
CPMAddPackage(
5150
NAME googletest
52-
GITHUB_REPOSITORY google/googletest
53-
GIT_TAG v1.14.0
54-
VERSION 1.14.0
51+
GIT_REPOSITORY https://github.com/google/googletest.git
52+
GIT_TAG v1.15.2
53+
VERSION 1.15.2
5554
OPTIONS
5655
"INSTALL_GTEST OFF"
5756
"gtest_force_shared_crt ON"
5857
)
5958

60-
# https://github.com/aminosbh/sdl2-cmake-modules.git
59+
# https://github.com/libsdl-org/SDL
6160
CPMAddPackage(
62-
NAME sdl2-cmake-modules
63-
GIT_REPOSITORY https://github.com/aminosbh/sdl2-cmake-modules.git
64-
GIT_TAG ad006a3daae65a612ed87415037e32188b81071e
65-
DOWNLOAD_ONLY True
61+
NAME SDL2
62+
GITHUB_REPOSITORY libsdl-org/SDL
63+
GIT_TAG release-2.30.6
64+
OPTIONS
65+
"SDL2_DISABLE_INSTALL ON"
66+
"SDL_SHARED OFF"
67+
"SDL_STATIC ON"
68+
"SDL_STATIC_PIC ON"
69+
"SDL_WERROR OFF"
6670
)
67-
if (sdl2-cmake-modules_ADDED)
68-
list(APPEND CMAKE_MODULE_PATH ${sdl2-cmake-modules_SOURCE_DIR})
69-
endif ()
7071

71-
## https://github.com/freetype/freetype
72-
#CPMAddPackage(
73-
# NAME freetype
74-
# GIT_REPOSITORY https://github.com/freetype/freetype.git
75-
# GIT_TAG VER-2-13-0
76-
# VERSION 2.13.0
77-
#)
78-
#if (freetype_ADDED)
79-
# add_library(Freetype::Freetype ALIAS freetype)
80-
#endif ()
81-
82-
# https://github.com/tinyobjloader/tinyobjloader.git
72+
# https://github.com/g-truc/glm
8373
CPMAddPackage(
84-
NAME tinyobjloader
85-
GIT_REPOSITORY https://github.com/tinyobjloader/tinyobjloader.git
86-
GIT_TAG 853f059d778058a43c954850e561a231934b33a7
87-
DOWNLOAD_ONLY True
74+
NAME glm
75+
GITHUB_REPOSITORY g-truc/glm
76+
GIT_TAG 1.0.1
8877
)
89-
if (tinyobjloader_ADDED)
90-
add_library(tinyobjloader INTERFACE)
91-
target_sources(tinyobjloader INTERFACE
92-
FILE_SET HEADERS
93-
BASE_DIRS ${tinyobjloader_SOURCE_DIR}
94-
FILES tiny_obj_loader.h
95-
)
96-
endif ()
9778

9879
# https://github.com/nothings/stb.git
9980
CPMAddPackage(
@@ -111,19 +92,6 @@ if (stb_ADDED)
11192
)
11293
endif ()
11394

114-
# https://gitlab.com/libeigen/eigen.git
115-
CPMAddPackage(
116-
NAME Eigen
117-
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
118-
GIT_TAG 3.4.0
119-
VERSION 3.4.0
120-
DOWNLOAD_ONLY True
121-
)
122-
if (Eigen_ADDED)
123-
add_library(Eigen INTERFACE IMPORTED)
124-
target_include_directories(Eigen INTERFACE ${Eigen_SOURCE_DIR})
125-
endif ()
126-
12795
# http://wenq.org/wqy2/index.cgi?ZenHei
12896
CPMAddPackage(
12997
NAME wqy_font
@@ -235,20 +203,24 @@ if (NOT LCOV_EXE)
235203
"Following https://github.com/linux-test-project/lcov to install.")
236204
endif ()
237205

238-
find_package(SDL2 REQUIRED)
239-
if (NOT SDL2_FOUND)
240-
message(FATAL_ERROR "sdl2 not found.\n"
241-
"Following https://github.com/libsdl-org/SDL to install.")
242-
endif ()
243-
244-
find_package(OpenMP REQUIRED)
245-
if (NOT OpenMP_FOUND)
246-
message(FATAL_ERROR "OpenMP not found.\n"
247-
"Following https://www.openmp.org to install.")
248-
endif ()
249-
250206
find_package(spdlog REQUIRED)
251207
if (NOT spdlog_FOUND)
252208
message(FATAL_ERROR "spdlog not found.\n"
253209
"Following https://github.com/gabime/spdlog to install.")
254210
endif ()
211+
212+
find_package(assimp REQUIRED)
213+
if (NOT assimp_FOUND)
214+
message(FATAL_ERROR "assimp not found.\n"
215+
"Following https://github.com/assimp/assimp to install.")
216+
endif ()
217+
218+
find_package(OpenMP REQUIRED)
219+
if (APPLE)
220+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
221+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
222+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${OPENMP_LIBRARIES} -lomp")
223+
endif ()
224+
if (NOT OpenMP_FOUND)
225+
message(FATAL_ERROR "OpenMP not found. Please install OpenMP.")
226+
endif ()

cmake/add_header.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
# 将头文件路径添加到 _target 的搜索路径中
77

88
function(add_header_3rd _target)
9-
target_include_directories(${_target} PRIVATE
10-
${tinyobjloader_SOURCE_DIR})
9+
target_include_directories(${_target} PRIVATE)
1110
endfunction()

cmake/compile_config.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ list(APPEND DEFAULT_COMPILE_OPTIONS
1616
list(APPEND DEFAULT_LINK_LIB
1717
spdlog::spdlog
1818
stb
19-
tinyobjloader
20-
Eigen
19+
glm::glm
2120
${glog_LIBRARIES}
22-
SDL2::Main
21+
SDL2::SDL2
2322
OpenMP::OpenMP_CXX
23+
assimp
2424
)

src/CMakeLists.txt

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,21 @@
55
# CMakeLists.txt for Simple-XX/SimpleRenderer.
66

77
# 生成静态库
8-
add_library(${PROJECT_NAME} STATIC
9-
log_system.cpp
10-
color.cpp
11-
include/vector.hpp
12-
include/matrix.hpp
13-
include/model.hpp
14-
include/shader_base.h
15-
include/default_shader.h
16-
include/light.h
17-
model.cpp
18-
light.cpp
19-
shader_base.cpp
20-
default_shader.cpp
21-
simple_renderer.cpp
8+
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
9+
"*.cpp"
10+
"*.c"
2211
)
12+
add_library(${PROJECT_NAME} STATIC ${SRC_FILES})
2313

2414
target_include_directories(${PROJECT_NAME} PRIVATE
25-
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/include>
26-
$<INSTALL_INTERFACE:include>
15+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/include>
16+
$<INSTALL_INTERFACE:include>
2717
)
2818

2919
target_compile_options(${PROJECT_NAME} PRIVATE
30-
${DEFAULT_COMPILE_OPTIONS}
20+
${DEFAULT_COMPILE_OPTIONS}
3121
)
3222

3323
target_link_libraries(${PROJECT_NAME} PRIVATE
34-
${DEFAULT_LINK_LIB}
35-
)
24+
${DEFAULT_LINK_LIB}
25+
)

0 commit comments

Comments
 (0)