Skip to content

Commit

Permalink
update according to the reviews
Browse files Browse the repository at this point in the history
Signed-off-by: ZhuohaoHe <[email protected]>
  • Loading branch information
ZzzhHe committed Aug 9, 2024
1 parent c877b4d commit 890c15c
Show file tree
Hide file tree
Showing 26 changed files with 276 additions and 297 deletions.
8 changes: 8 additions & 0 deletions $EXECUTABLE_OUTPUT_PATH/logs/SimpleRendererLog.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[2024-08-09 15:04:13.936] [simple_renderer.cpp:57 SimpleRenderer] [info] SimpleRenderer init with 1920, 1080
[2024-08-09 15:04:13.949] [model.cpp:115 Model] [info] 加载模型: obj/utah-teapot/utah-teapot.obj, 顶点数: 2082, 法线数: 2082, 颜色数: 2082, UV数: 1036, 子模型数: 1, 材质数: 1
[2024-08-09 15:04:13.960] [simple_renderer.cpp:61 render] [info] render model: obj/utah-teapot/utah-teapot.obj
[2024-08-09 15:04:13.961] [simple_renderer.cpp:197 DrawModel] [info] draw obj/utah-teapot/utah-teapot.obj
[2024-08-09 15:37:12.808] [simple_renderer.cpp:57 SimpleRenderer] [info] SimpleRenderer init with 1920, 1080
[2024-08-09 15:37:12.821] [model.cpp:118 Model] [info] 加载模型: obj/utah-teapot/utah-teapot.obj, 顶点数: 2082, 法线数: 2082, 颜色数: 2082, UV数: 1036, 子模型数: 1, 材质数: 1
[2024-08-09 15:37:12.833] [simple_renderer.cpp:61 render] [info] render model: obj/utah-teapot/utah-teapot.obj
[2024-08-09 15:37:12.835] [simple_renderer.cpp:197 DrawModel] [info] draw obj/utah-teapot/utah-teapot.obj
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
include/config.h
src/include/config.h
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
# 设置最小 cmake 版本
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 设置项目名与版本
project(SimpleRenderer
Expand Down Expand Up @@ -42,15 +40,15 @@ set(FONT_FILE_PATH "${wqy_font_SOURCE_DIR}/wqy-zenhei.ttc")
include(ProcessorCount)
ProcessorCount(NPROC)
# 日志文件路径
set(LOG_FILE_PATH "${PROJECT_SOURCE_DIR}/build/logs/SimpleRendererLog.log")
set(LOG_FILE_PATH "$EXECUTABLE_OUTPUT_PATH/logs/SimpleRendererLog.log")
# 日志文件大小
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}/include/config.h"
"${PROJECT_SOURCE_DIR}/src/include/config.h"
)

# 添加要编译的目录
Expand Down
60 changes: 40 additions & 20 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,10 @@
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 27,
"minor": 23,
"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",
Expand All @@ -30,13 +20,10 @@
}
},
{
"name": "configurePresets_base",
"name": "config-base",
"hidden": true,
"inherits": [
"host",
"std"
],
"displayName": "configurePresets_base",
"inherits": [ "std" ],
"displayName": "config-base",
"description": "base configurePresets",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
Expand All @@ -58,14 +45,47 @@
}
}
},
{
"name": "config-mac",
"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": [
"configurePresets_base"
"config-base"
],
"displayName": "build-base",
"description": "build base configurePresets"
},
{
"name": "build-mac",
"hidden": false,
"inherits": [
"config-mac"
],
"displayName": "build",
"description": "build"
"displayName": "build-mac",
"description": "macOS build configurePresets"
}
],
"buildPresets": [
{
"name": "build",
"displayName": "Build",
"configurePreset": "config-base"
}
]
}
45 changes: 16 additions & 29 deletions cmake/3rd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ CPMAddPackage(
"gtest_force_shared_crt ON"
)

# SDL2

# https://github.com/libsdl-org/SDL
CPMAddPackage(
NAME SDL2
GITHUB_REPOSITORY libsdl-org/SDL
Expand All @@ -70,22 +69,17 @@ CPMAddPackage(
"SDL_STATIC_PIC ON"
"SDL_WERROR OFF"
)
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()

if (sdl2-cmake-modules_ADDED)
list(APPEND CMAKE_MODULE_PATH ${sdl2-cmake-modules_SOURCE_DIR})
endif ()
# # 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-cmake-modules_ADDED)
# list(APPEND CMAKE_MODULE_PATH ${sdl2-cmake-modules_SOURCE_DIR})
# endif ()

# https://github.com/tinyobjloader/tinyobjloader.git
CPMAddPackage(
Expand All @@ -103,11 +97,16 @@ if (tinyobjloader_ADDED)
)
endif ()

# https://github.com/g-truc/glm
CPMAddPackage(
NAME glm
GITHUB_REPOSITORY g-truc/glm
GIT_TAG 1.0.1
)
if (glm_ADDED)
add_library(glm INTERFACE)
target_include_directories(glm INTERFACE ${glm_SOURCE_DIR})
endif ()

# https://github.com/nothings/stb.git
CPMAddPackage(
Expand Down Expand Up @@ -236,12 +235,6 @@ 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"
Expand All @@ -252,10 +245,4 @@ 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(glm REQUIRED)
if (NOT glm_FOUND)
message(FATAL_ERROR "glm not found.\n"
"Following https://github.com/g-truc/glm tp install")
endif ()
38 changes: 0 additions & 38 deletions include/config.h

This file was deleted.

57 changes: 0 additions & 57 deletions include/vector.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS
add_library(${PROJECT_NAME} STATIC ${SRC_FILES})

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

Expand Down
5 changes: 3 additions & 2 deletions src/default_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace simple_renderer {

auto DefaultShader::InterpolateColor(
const Color &color0, const Color &color1, const Color &color2,
const glm::vec3 &barycentric_coord) -> Color {
const Vector3f &barycentric_coord) -> Color {
return Color(
static_cast<uint8_t>(static_cast<float>(color0[Color::kColorIndexRed]) *
barycentric_coord.x +
Expand Down Expand Up @@ -56,7 +56,8 @@ auto DefaultShader::Vertex(const ShaderVertexIn &shader_vertex_in) const

auto DefaultShader::Fragment(const ShaderFragmentIn &shader_fragment_in) const
-> ShaderFragmentOut {
auto intensity = glm::dot(shader_fragment_in.normal_,shader_fragment_in.light_);
auto intensity =
glm::dot(shader_fragment_in.normal_, shader_fragment_in.light_);
auto is_need_draw = true;
// 光照方向为正,不绘制背面
if (intensity <= 0) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion include/default_shader.h → src/include/default_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class DefaultShader : public ShaderBase {
*/
static auto InterpolateColor(const Color &color0, const Color &color1,
const Color &color2,
const glm::vec3 &barycentric_coord) -> Color;
const Vector3f &barycentric_coord) -> Color;
};

} // namespace simple_renderer
Expand Down
8 changes: 4 additions & 4 deletions include/light.h → src/include/light.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class Light {
/// 光照名称
std::string name_ = "default light name";
/// 位置
glm::vec3 pos = kDefaultPos;
Vector3f pos = kDefaultPos;
/// 方向
glm::vec3 dir = kDefaultDir;
Vector3f dir = kDefaultDir;
/// 颜色
Color color = kDefaultColor;

Expand All @@ -57,9 +57,9 @@ class Light {

private:
/// 默认位置
static const glm::vec3 kDefaultPos;
static const Vector3f kDefaultPos;
/// 默认方向,左手系,x 向右,y 向下,z 正方向为屏幕由内向外
static const glm::vec3 kDefaultDir;
static const Vector3f kDefaultDir;
/// 默认颜色
static const Color kDefaultColor;
};
Expand Down
File renamed without changes.
Loading

0 comments on commit 890c15c

Please sign in to comment.