-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reorganization: GLM Integration, SDL2 on macOS Build Fix, and Structural Enhancements #11
base: main
Are you sure you want to change the base?
Changes from 6 commits
cebca18
78ba9f3
cebb066
049e985
ecdb542
c877b4d
890c15c
b502e5c
b380f8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ tools/opensbi/build | |
.idea | ||
3rd | ||
Doxyfile | ||
src/include/config.h | ||
include/config.h | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
# 设置最小 cmake 版本 | ||
cmake_minimum_required(VERSION 3.27 FATAL_ERROR) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这两个在 CMakePresets.json 里面设置过了,可以删掉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 但是删掉之后,就会在std::span的地方报错
参考这个链接 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我发现了,是因为CMakePresets.json这个文件我没设置好,导致在跑命令
&
这两个地方都可以按照原本的代码直接跑,我下个commit会删掉我的更改 |
||
# 设置项目名与版本 | ||
project(SimpleRenderer | ||
VERSION 0.0.1) | ||
|
@@ -39,15 +42,15 @@ set(FONT_FILE_PATH "${wqy_font_SOURCE_DIR}/wqy-zenhei.ttc") | |
include(ProcessorCount) | ||
ProcessorCount(NPROC) | ||
# 日志文件路径 | ||
set(LOG_FILE_PATH "${EXECUTABLE_OUTPUT_PATH}/logs/SimpleRendererLog.log") | ||
set(LOG_FILE_PATH "${PROJECT_SOURCE_DIR}/build/logs/SimpleRendererLog.log") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EXECUTABLE_OUTPUT_PATH 这个值同样在 CMakePresets.json 中,如果构建目录不在 build 下可能有问题,建议使用 CMakePresets.json 下的值 |
||
# 日志文件大小 | ||
set(LOG_FILE_MAX_SIZE 1024*1024*4) | ||
# 日志文件数量 | ||
set(LOG_FILE_MAX_COUNT 8) | ||
# 生成配置头文件 | ||
configure_file( | ||
"${PROJECT_SOURCE_DIR}/cmake/config.h.in" | ||
"${PROJECT_SOURCE_DIR}/src/include/config.h" | ||
"${PROJECT_SOURCE_DIR}/include/config.h" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里还是 include 目录的问题,后面不再专门说了~ |
||
) | ||
|
||
# 添加要编译的目录 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,28 +57,36 @@ CPMAddPackage( | |
"gtest_force_shared_crt ON" | ||
) | ||
|
||
# SDL2 | ||
|
||
CPMAddPackage( | ||
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" | ||
) | ||
find_package(SDL2 REQUIRED) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 239 行还有一个 find_package(SDL2 REQUIRED),是不是重复了? |
||
# https://github.com/aminosbh/sdl2-cmake-modules.git | ||
CPMAddPackage( | ||
NAME sdl2-cmake-modules | ||
GIT_REPOSITORY https://github.com/aminosbh/sdl2-cmake-modules.git | ||
GIT_TAG ad006a3daae65a612ed87415037e32188b81071e | ||
DOWNLOAD_ONLY True | ||
) | ||
if (SDL2_ADDED) | ||
add_library(SDL2::SDL2) | ||
endif() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 目前的习惯是 CPMAddPackage 放在一起,find_package 放在一起,最好统一格式,改成旧有的分开或者改成按模块 |
||
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 | ||
CPMAddPackage( | ||
NAME tinyobjloader | ||
|
@@ -95,6 +103,12 @@ if (tinyobjloader_ADDED) | |
) | ||
endif () | ||
|
||
CPMAddPackage( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加一个 github 链接 |
||
NAME glm | ||
GITHUB_REPOSITORY g-truc/glm | ||
GIT_TAG 1.0.1 | ||
) | ||
|
||
# https://github.com/nothings/stb.git | ||
CPMAddPackage( | ||
NAME stb | ||
|
@@ -111,19 +125,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 | ||
|
@@ -252,3 +253,9 @@ if (NOT spdlog_FOUND) | |
message(FATAL_ERROR "spdlog not found.\n" | ||
"Following https://github.com/gabime/spdlog to install.") | ||
endif () | ||
|
||
find_package(glm REQUIRED) | ||
if (NOT glm_FOUND) | ||
message(FATAL_ERROR "glm not found.\n" | ||
"Following https://github.com/g-truc/glm tp install") | ||
endif () | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里 glm 的 CPMAddPackage 和 find_package 又分开写了,注意统一哈 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 生成的文件加到 gitignore 里比较好 |
||
/** | ||
* @file config.h | ||
* @brief 项目配置 | ||
* @author Zone.N ([email protected]) | ||
* @version 1.0 | ||
* @date 2023-08-24 | ||
* @copyright MIT LICENSE | ||
* https://github.com/Simple-XX/SimpleRenderer | ||
* @par change log: | ||
* <table> | ||
* <tr><th>Date<th>Author<th>Description | ||
* <tr><td>2023-08-24<td>Zone.N<td>创建文件 | ||
* </table> | ||
*/ | ||
|
||
#ifndef SIMPLERENDER_SRC_INCLUDE_CONFIG_H_ | ||
#define SIMPLERENDER_SRC_INCLUDE_CONFIG_H_ | ||
|
||
#include <string> | ||
#include <string_view> | ||
|
||
namespace simple_renderer { | ||
|
||
/// 线程数 | ||
static constexpr const size_t kNProc = 8; | ||
|
||
/// 日志文件路径 | ||
static const std::string kLogFilePath = | ||
std::string("/Users/hezhohao/Programming/SimpleRenderer/build/logs/SimpleRendererLog.log"); | ||
/// 日志文件大小 | ||
static constexpr const size_t kLogFileMaxSize = 1024*1024*4; | ||
/// 日志文件数量 | ||
static constexpr const size_t kLogFileMaxCount = 8; | ||
|
||
} // namespace simple_renderer | ||
|
||
#endif /* SIMPLERENDER_SRC_INCLUDE_CONFIG_H_ */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ class DefaultShader : public ShaderBase { | |
*/ | ||
static auto InterpolateColor(const Color &color0, const Color &color1, | ||
const Color &color2, | ||
const Vector3f &barycentric_coord) -> Color; | ||
const glm::vec3 &barycentric_coord) -> Color; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 之前的 Vector3f 是
直接修改一下即可,不需要在源码里改这么多 |
||
}; | ||
|
||
} // namespace simple_renderer | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,26 +17,27 @@ | |
#ifndef SIMPLERENDER_SRC_INCLUDE_MATRIX_HPP_ | ||
#define SIMPLERENDER_SRC_INCLUDE_MATRIX_HPP_ | ||
|
||
#include <Eigen/Dense> | ||
#define GLM_ENABLE_EXPERIMENTAL | ||
#include <glm/gtx/string_cast.hpp> | ||
|
||
#include "log_system.h" | ||
|
||
namespace simple_renderer { | ||
|
||
using Matrix4f = Eigen::Matrix4f; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 所以为啥不用 using,要删掉呢 |
||
|
||
} // namespace simple_renderer | ||
|
||
/** | ||
* spdlog 输出矩阵实现 | ||
*/ | ||
template <> | ||
struct fmt::formatter<simple_renderer::Matrix4f> : fmt::formatter<std::string> { | ||
auto format(simple_renderer::Matrix4f matrix, format_context &format_context) | ||
const -> decltype(format_context.out()) { | ||
std::stringstream buf; | ||
buf << matrix; | ||
return fmt::format_to(format_context.out(), "\n{}", buf.str()); | ||
struct fmt::formatter<glm::mat4> : fmt::formatter<std::string> { | ||
auto format(const glm::mat4 &matrix, fmt::format_context &ctx) const -> decltype(ctx.out()) { | ||
// Convert the glm::mat4 to a string using glm::to_string | ||
std::string matrix_str = glm::to_string(matrix); | ||
|
||
// Format and output the string | ||
return fmt::format_to(ctx.out(), "\n{}", matrix_str); | ||
} | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为啥要把 include 放在 src 外面呢?
我的理解是 src 下包括源码+头文件,include 与 src 同级的话感觉会与 tools/cmake 等辅助文件搞混
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
收到🫡