Skip to content

Commit

Permalink
Merge pull request #12 from ZzzhHe/refactor-model-loading
Browse files Browse the repository at this point in the history
Refactor model loading
  • Loading branch information
MRNIU authored Sep 9, 2024
2 parents d5c6576 + 0703564 commit 7e999cf
Show file tree
Hide file tree
Showing 31 changed files with 665 additions and 781 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: |
sudo apt update
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck lcov
sudo apt install --fix-missing -y gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev
sudo apt install --fix-missing -y gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev libassimp-dev
- name: Build
run: |
Expand All @@ -48,7 +48,7 @@ jobs:
run: |
sudo apt update
sudo apt install --fix-missing -y doxygen graphviz clang-format clang-tidy cppcheck lcov
sudo apt install --fix-missing -y gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev
sudo apt install --fix-missing -y gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev libassimp-dev
- name: Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ tools/opensbi/build
.idea
3rd
Doxyfile
src/include/config.h
src/include/config.h
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# 设置最小 cmake 版本
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)


# 设置项目名与版本
project(SimpleRenderer
VERSION 0.0.1)
Expand Down Expand Up @@ -53,4 +54,4 @@ configure_file(
# 添加要编译的目录
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(doc)
add_subdirectory(doc)
147 changes: 80 additions & 67 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,71 +1,84 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 27,
"patch": 0
},
"configurePresets": [
{
"name": "host",
"description": "Linux Only",
"hidden": true,
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
},
{
"name": "std",
"description": "This preset makes sure the project actually builds with at least the specified standard",
"hidden": true,
"cacheVariables": {
"CMAKE_C_EXTENSIONS": "OFF",
"CMAKE_C_STANDARD": "23",
"CMAKE_C_STANDARD_REQUIRED": "ON",
"CMAKE_CXX_EXTENSIONS": "OFF",
"CMAKE_CXX_STANDARD": "23",
"CMAKE_CXX_STANDARD_REQUIRED": "ON"
}
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
{
"name": "configurePresets_base",
"hidden": true,
"inherits": [
"host",
"std"
],
"displayName": "configurePresets_base",
"description": "base configurePresets",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": {
"type": "BOOL",
"value": "ON"
},
"EXECUTABLE_OUTPUT_PATH": {
"type": "STRING",
"value": "${sourceDir}/build/bin"
},
"LIBRARY_OUTPUT_PATH": {
"type": "STRING",
"value": "${sourceDir}/build/lib"
},
"COVERAGE_OUTPUT_DIR": {
"type": "STRING",
"value": "${sourceDir}/build/coverage"
"configurePresets": [
{
"name": "std",
"description": "This preset makes sure the project actually builds with at least the specified standard",
"hidden": true,
"cacheVariables": {
"CMAKE_C_EXTENSIONS": "OFF",
"CMAKE_C_STANDARD": "23",
"CMAKE_C_STANDARD_REQUIRED": "ON",
"CMAKE_CXX_EXTENSIONS": "OFF",
"CMAKE_CXX_STANDARD": "23",
"CMAKE_CXX_STANDARD_REQUIRED": "ON"
}
},
{
"name": "config-base",
"hidden": true,
"inherits": [ "std" ],
"displayName": "config-base",
"description": "base configurePresets",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": {
"type": "BOOL",
"value": "ON"
},
"EXECUTABLE_OUTPUT_PATH": {
"type": "STRING",
"value": "${sourceDir}/build/bin"
},
"LIBRARY_OUTPUT_PATH": {
"type": "STRING",
"value": "${sourceDir}/build/lib"
},
"COVERAGE_OUTPUT_DIR": {
"type": "STRING",
"value": "${sourceDir}/build/coverage"
}
}
},
{
"name": "config-macos",
"hidden": true,
"inherits": [ "config-base" ],
"displayName": "config-base",
"description": "macOS configurePresets",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"cacheVariables": {
"CMAKE_MACOSX_RPATH": "1",
"CMAKE_INSTALL_RPATH": "/Library/Frameworks",
"CMAKE_BUILD_WITH_INSTALL_RPATH": "TRUE"
}
},
{
"name": "build",
"hidden": false,
"inherits": [
"config-base"
],
"displayName": "build-base",
"description": "build base configurePresets"
},
{
"name": "build-macos",
"hidden": false,
"inherits": [
"config-macos"
],
"displayName": "build-macos",
"description": "macOS build configurePresets"
}
},
{
"name": "build",
"hidden": false,
"inherits": [
"configurePresets_base"
],
"displayName": "build",
"description": "build"
}
]
}
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ A software renderer
## 依赖

```shell
sudo apt install doxygen graphviz clang-format clang-tidy cppcheck lcov gcc g++ libsdl2-dev libsdl2-ttf-dev libomp-dev libspdlog-dev cmake vim
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
```

## 使用
Expand Down
94 changes: 33 additions & 61 deletions cmake/3rd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,54 +46,35 @@ endif ()
include(${CPM_DOWNLOAD_LOCATION})
# -------- get_cpm.cmake --------

# https://github.com/google/googletest
CPMAddPackage(
NAME googletest
GITHUB_REPOSITORY google/googletest
GIT_TAG v1.14.0
VERSION 1.14.0
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.15.2
VERSION 1.15.2
OPTIONS
"INSTALL_GTEST OFF"
"gtest_force_shared_crt ON"
)

# https://github.com/aminosbh/sdl2-cmake-modules.git
# https://github.com/libsdl-org/SDL
CPMAddPackage(
NAME sdl2-cmake-modules
GIT_REPOSITORY https://github.com/aminosbh/sdl2-cmake-modules.git
GIT_TAG ad006a3daae65a612ed87415037e32188b81071e
DOWNLOAD_ONLY True
NAME SDL2
GITHUB_REPOSITORY libsdl-org/SDL
GIT_TAG release-2.30.6
OPTIONS
"SDL2_DISABLE_INSTALL ON"
"SDL_SHARED OFF"
"SDL_STATIC ON"
"SDL_STATIC_PIC ON"
"SDL_WERROR OFF"
)
if (sdl2-cmake-modules_ADDED)
list(APPEND CMAKE_MODULE_PATH ${sdl2-cmake-modules_SOURCE_DIR})
endif ()

## https://github.com/freetype/freetype
#CPMAddPackage(
# NAME freetype
# GIT_REPOSITORY https://github.com/freetype/freetype.git
# GIT_TAG VER-2-13-0
# VERSION 2.13.0
#)
#if (freetype_ADDED)
# add_library(Freetype::Freetype ALIAS freetype)
#endif ()

# https://github.com/tinyobjloader/tinyobjloader.git
# https://github.com/g-truc/glm
CPMAddPackage(
NAME tinyobjloader
GIT_REPOSITORY https://github.com/tinyobjloader/tinyobjloader.git
GIT_TAG 853f059d778058a43c954850e561a231934b33a7
DOWNLOAD_ONLY True
NAME glm
GITHUB_REPOSITORY g-truc/glm
GIT_TAG 1.0.1
)
if (tinyobjloader_ADDED)
add_library(tinyobjloader INTERFACE)
target_sources(tinyobjloader INTERFACE
FILE_SET HEADERS
BASE_DIRS ${tinyobjloader_SOURCE_DIR}
FILES tiny_obj_loader.h
)
endif ()

# https://github.com/nothings/stb.git
CPMAddPackage(
Expand All @@ -111,19 +92,6 @@ if (stb_ADDED)
)
endif ()

# https://gitlab.com/libeigen/eigen.git
CPMAddPackage(
NAME Eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
GIT_TAG 3.4.0
VERSION 3.4.0
DOWNLOAD_ONLY True
)
if (Eigen_ADDED)
add_library(Eigen INTERFACE IMPORTED)
target_include_directories(Eigen INTERFACE ${Eigen_SOURCE_DIR})
endif ()

# http://wenq.org/wqy2/index.cgi?ZenHei
CPMAddPackage(
NAME wqy_font
Expand Down Expand Up @@ -235,20 +203,24 @@ if (NOT LCOV_EXE)
"Following https://github.com/linux-test-project/lcov to install.")
endif ()

find_package(SDL2 REQUIRED)
if (NOT SDL2_FOUND)
message(FATAL_ERROR "sdl2 not found.\n"
"Following https://github.com/libsdl-org/SDL to install.")
endif ()

find_package(OpenMP REQUIRED)
if (NOT OpenMP_FOUND)
message(FATAL_ERROR "OpenMP not found.\n"
"Following https://www.openmp.org to install.")
endif ()

find_package(spdlog REQUIRED)
if (NOT spdlog_FOUND)
message(FATAL_ERROR "spdlog not found.\n"
"Following https://github.com/gabime/spdlog to install.")
endif ()

find_package(assimp REQUIRED)
if (NOT assimp_FOUND)
message(FATAL_ERROR "assimp not found.\n"
"Following https://github.com/assimp/assimp to install.")
endif ()

find_package(OpenMP REQUIRED)
if (APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L${OPENMP_LIBRARIES} -lomp")
endif ()
if (NOT OpenMP_FOUND)
message(FATAL_ERROR "OpenMP not found. Please install OpenMP.")
endif ()
3 changes: 1 addition & 2 deletions cmake/add_header.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
# 将头文件路径添加到 _target 的搜索路径中

function(add_header_3rd _target)
target_include_directories(${_target} PRIVATE
${tinyobjloader_SOURCE_DIR})
target_include_directories(${_target} PRIVATE)
endfunction()
6 changes: 3 additions & 3 deletions cmake/compile_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ list(APPEND DEFAULT_COMPILE_OPTIONS
list(APPEND DEFAULT_LINK_LIB
spdlog::spdlog
stb
tinyobjloader
Eigen
glm::glm
${glog_LIBRARIES}
SDL2::Main
SDL2::SDL2
OpenMP::OpenMP_CXX
assimp
)
28 changes: 9 additions & 19 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,21 @@
# CMakeLists.txt for Simple-XX/SimpleRenderer.

# 生成静态库
add_library(${PROJECT_NAME} STATIC
log_system.cpp
color.cpp
include/vector.hpp
include/matrix.hpp
include/model.hpp
include/shader_base.h
include/default_shader.h
include/light.h
model.cpp
light.cpp
shader_base.cpp
default_shader.cpp
simple_renderer.cpp
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
"*.cpp"
"*.c"
)
add_library(${PROJECT_NAME} STATIC ${SRC_FILES})

target_include_directories(${PROJECT_NAME} PRIVATE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/include>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src/include>
$<INSTALL_INTERFACE:include>
)

target_compile_options(${PROJECT_NAME} PRIVATE
${DEFAULT_COMPILE_OPTIONS}
${DEFAULT_COMPILE_OPTIONS}
)

target_link_libraries(${PROJECT_NAME} PRIVATE
${DEFAULT_LINK_LIB}
)
${DEFAULT_LINK_LIB}
)
Loading

0 comments on commit 7e999cf

Please sign in to comment.