Skip to content

Commit 1631450

Browse files
authored
Merge pull request #65 from bobis33/Feat/Renderer/3d-objects
2 parents 7552824 + 247c50a commit 1631450

74 files changed

Lines changed: 1805 additions & 313 deletions

Some content is hidden

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

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@
33
.vs/
44

55
cmake-build-*
6-
7-
include/CAE/Generated/

CMakeLists.txt

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
1313
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib")
1414
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/lib")
1515
set(PLUGIN_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
16-
set(PATH_VERSION "${PROJECT_SOURCE_DIR}/include/CAE/Generated/Version.hpp")
16+
set(PATH_VERSION "${PROJECT_BINARY_DIR}/include/CAE/Version.hpp")
1717
set(TEMPLATE_PATH "${PROJECT_SOURCE_DIR}/cmake/config/Version.hpp.in")
1818

1919
add_compile_definitions(PLUGINS_DIR="${PLUGIN_DIR}")
@@ -34,64 +34,46 @@ include(MakeDoc)
3434
include(ClangTidy)
3535
include(ClangFormat)
3636
include(CopyAssets)
37+
include(CompileOptions)
38+
39+
find_package(nlohmann_json QUIET CONFIG)
40+
if (NOT nlohmann_json_FOUND)
41+
include(FetchContent)
42+
FetchContent_Declare(
43+
nlohmann-json
44+
GIT_REPOSITORY "https://github.com/nlohmann/json.git"
45+
GIT_TAG "v3.12.0"
46+
GIT_SHALLOW TRUE
47+
GIT_PROGRESS TRUE
48+
)
49+
FetchContent_MakeAvailable(nlohmann-json)
50+
endif ()
51+
find_package(glm QUIET CONFIG)
52+
if (NOT glm_FOUND)
53+
FetchContent_Declare(
54+
glm
55+
GIT_REPOSITORY "https://github.com/g-truc/glm.git"
56+
GIT_TAG 1.0.3
57+
GIT_SHALLOW TRUE
58+
GIT_PROGRESS TRUE
59+
)
60+
set(GLM_BUILD_TESTS OFF CACHE BOOL "" FORCE)
61+
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
62+
FetchContent_MakeAvailable(glm)
63+
endif ()
3764

3865
add_subdirectory(modules)
3966
add_subdirectory(plugins)
4067
add_subdirectory(tests)
4168

42-
include(FetchContent)
43-
FetchContent_Declare(
44-
nlohmann-json
45-
GIT_REPOSITORY "https://github.com/nlohmann/json.git"
46-
GIT_TAG "v3.12.0"
47-
GIT_SHALLOW TRUE
48-
GIT_PROGRESS TRUE
49-
)
50-
FetchContent_MakeAvailable(nlohmann-json)
51-
5269
add_executable(${PROJECT_NAME} ${SOURCES})
5370
add_dependencies(${PROJECT_NAME} cae-modules)
54-
target_include_directories(${PROJECT_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/include")
71+
target_include_directories(${PROJECT_NAME} PRIVATE "${PROJECT_SOURCE_DIR}/include" "${PROJECT_BINARY_DIR}/include" ${glm_SOURCE_DIR})
5572
target_link_libraries(${PROJECT_NAME} PRIVATE
5673
cae-modules
5774
nlohmann_json::nlohmann_json
75+
glm::glm
5876
)
59-
if (NOT WIN32 AND NOT APPLE)
60-
set(WARNING_FLAGS
61-
-Wall
62-
-Wextra
63-
-Wdeprecated-copy
64-
-Wmisleading-indentation
65-
-Wnull-dereference
66-
-Woverloaded-virtual
67-
-Wpedantic
68-
-Wshadow
69-
-Wsign-conversion
70-
-Wnon-virtual-dtor
71-
-Wunused
72-
-Wcast-align
73-
-Wno-padded
74-
-Wconversion
75-
-Wformat
76-
-Winit-self
77-
-Wmissing-include-dirs
78-
-Wold-style-cast
79-
-Wredundant-decls
80-
-Wswitch-default
81-
-Wundef
82-
)
83-
else ()
84-
if (MSVC)
85-
set(WARNING_FLAGS /W3)
86-
else()
87-
set(WARNING_FLAGS -Wno-error)
88-
endif()
89-
endif()
90-
if (MSVC)
91-
target_compile_options(${PROJECT_NAME} PRIVATE ${WARNING_FLAGS} /O2)
92-
else ()
93-
target_compile_options(${PROJECT_NAME} PRIVATE ${WARNING_FLAGS} -O3)
94-
endif ()
9577

9678
copy_directory_to_target(
9779
cae

assets/config/default.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
"masterVolume": 0.8,
44
"muted": false
55
},
6+
"camera": {
7+
"position": [0.0, 0.0, 1.0],
8+
"rotation": [0.0, 0.0, 0.0],
9+
"direction": [0.0, 0.0, -1.0],
10+
"movementSpeed": 2.5,
11+
"rotationSpeed": 7.5,
12+
"fov": 45,
13+
"nearPlane": 0.1,
14+
"farPlane": 1000.0
15+
},
616
"log": {
717
"fps": false
818
},
@@ -13,10 +23,7 @@
1323
"renderer": {
1424
"vsync": false,
1525
"frameRateLimit": 90,
16-
"clearColor": [1.0, 1.0, 1.0, 1.0]
17-
},
18-
"user": {
19-
"name": "User"
26+
"clearColor": [0.2, 0.2, 0.2, 1.0]
2027
},
2128
"window": {
2229
"name": "CAE - Cross API Engine",

assets/shaders/glsl/texture.frag

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#version 450 core
22

3-
layout(location = 0) in vec2 vUV;
3+
layout(location = 0) in vec3 vColor;
44
layout(location = 0) out vec4 FragColor;
55

6-
layout(binding = 0) uniform sampler2D uTexture;
7-
86
void main()
97
{
10-
FragColor = texture(uTexture, vUV);
8+
FragColor = vec4(vColor, 1.0);
119
}

assets/shaders/glsl/texture.vert

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#version 450 core
22

3-
layout(location = 0) in vec2 aPos;
4-
layout(location = 1) in vec2 aUV;
3+
layout(location = 0) in vec3 aPos;
4+
layout(location = 1) in vec3 aColor;
55

6-
layout(location = 0) out vec2 vUV;
6+
layout(location = 0) out vec3 vColor;
7+
8+
layout(set = 0, binding = 0) uniform Matrices
9+
{
10+
mat4 uMVP;
11+
};
712

813
void main()
914
{
10-
gl_Position = vec4(aPos, 0.0, 1.0);
11-
vUV = aUV;
15+
vColor = aColor;
16+
gl_Position = uMVP * vec4(aPos, 1.0);
1217
}

cmake/modules/CompileOptions.cmake

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
add_library(cae-compile-options INTERFACE)
2+
3+
target_compile_features(cae-compile-options INTERFACE cxx_std_23)
4+
5+
option(CAE_STRICT_WARNINGS "Enable strict warning level" OFF)
6+
option(CAE_ENABLE_SANITIZERS "Enable address and undefined sanitizers" OFF)
7+
option(CAE_ENABLE_LTO "Enable LTO on final targets" OFF)
8+
9+
target_compile_options(cae-compile-options INTERFACE
10+
# Strict warnings
11+
$<$<AND:$<CXX_COMPILER_ID:GNU,Clang,AppleClang>,$<BOOL:${CAE_STRICT_WARNINGS}>,$<NOT:$<PLATFORM_ID:Android,Emscripten,iOS>>>:
12+
-Wall
13+
-Wextra
14+
-Wpedantic
15+
-Wshadow
16+
-Wconversion
17+
-Wsign-conversion
18+
-Wold-style-cast
19+
-Woverloaded-virtual
20+
-Wnull-dereference
21+
-Wformat=2
22+
-Wundef
23+
-Wswitch-default
24+
>
25+
# mobile / web
26+
$<$<AND:$<CXX_COMPILER_ID:GNU,Clang,AppleClang>,$<BOOL:${CAE_STRICT_WARNINGS}>,$<PLATFORM_ID:Android,Emscripten,iOS>>:
27+
-Wall
28+
-Wextra
29+
-Wshadow
30+
-Wsign-conversion
31+
-Wold-style-cast
32+
>
33+
# Default warnings
34+
$<$<AND:$<CXX_COMPILER_ID:GNU,Clang,AppleClang>,$<NOT:$<BOOL:${CAE_STRICT_WARNINGS}>>>:
35+
-Wall
36+
-Wextra
37+
>
38+
# MSVC
39+
$<$<CXX_COMPILER_ID:MSVC>:
40+
/W4
41+
/permissive-
42+
/Zc:__cplusplus
43+
/Zc:preprocessor
44+
>
45+
)
46+
47+
# GCC / Clang
48+
target_compile_options(cae-compile-options INTERFACE
49+
$<$<AND:$<CONFIG:RelWithDebInfo>,$<CXX_COMPILER_ID:GNU,Clang,AppleClang>>:-O2>
50+
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:GNU,Clang,AppleClang>>:-O0 -g>
51+
)
52+
53+
# MSVC
54+
target_compile_options(cae-compile-options INTERFACE
55+
$<$<AND:$<CONFIG:Release>,$<CXX_COMPILER_ID:MSVC>>:/O2>
56+
$<$<AND:$<CONFIG:RelWithDebInfo>,$<CXX_COMPILER_ID:MSVC>>:/O2 /Zi>
57+
$<$<AND:$<CONFIG:Debug>,$<CXX_COMPILER_ID:MSVC>>:/Od /Zi>
58+
)
59+
60+
target_compile_definitions(cae-compile-options INTERFACE
61+
$<$<CONFIG:Debug>:
62+
CAE_DEBUG
63+
>
64+
)
65+
66+
if(CAE_ENABLE_SANITIZERS)
67+
target_compile_options(cae-compile-options INTERFACE
68+
$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<NOT:$<PLATFORM_ID:Android,Emscripten,Windows>>>:
69+
-fsanitize=address,undefined
70+
>
71+
)
72+
target_link_options(cae-compile-options INTERFACE
73+
$<$<AND:$<CXX_COMPILER_ID:GNU,Clang>,$<NOT:$<PLATFORM_ID:Android,Emscripten,Windows>>>:
74+
-fsanitize=address,undefined
75+
>
76+
)
77+
endif()
78+
79+
function(cae_enable_lto target)
80+
if (CAE_ENABLE_LTO)
81+
include(CheckIPOSupported)
82+
check_ipo_supported(RESULT CAE_LTO_SUPPORTED OUTPUT CAE_LTO_ERROR)
83+
if (CAE_LTO_SUPPORTED)
84+
set_property(TARGET ${target} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
85+
else()
86+
message(WARNING "CAE: LTO not supported: ${CAE_LTO_ERROR}")
87+
endif()
88+
endif()
89+
endfunction()
90+
91+
if (EMSCRIPTEN)
92+
target_compile_definitions(cae-compile-options INTERFACE
93+
CAE_PLATFORM_WEB
94+
CAE_PLATFORM_EMSCRIPTEN
95+
)
96+
elseif (ANDROID)
97+
target_compile_definitions(cae-compile-options INTERFACE CAE_PLATFORM_ANDROID)
98+
elseif (APPLE)
99+
if (IOS)
100+
target_compile_definitions(cae-compile-options INTERFACE CAE_PLATFORM_IOS)
101+
else()
102+
target_compile_definitions(cae-compile-options INTERFACE CAE_PLATFORM_MACOS)
103+
endif()
104+
elseif (WIN32)
105+
target_compile_definitions(cae-compile-options INTERFACE
106+
CAE_PLATFORM_WINDOWS
107+
NOMINMAX
108+
WIN32_LEAN_AND_MEAN
109+
)
110+
elseif (UNIX)
111+
target_compile_definitions(cae-compile-options INTERFACE CAE_PLATFORM_LINUX)
112+
endif()
113+

include/CAE/Application.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace cae
5050
///
5151
/// @brief Start the application
5252
///
53-
void start() const;
53+
void start();
5454

5555
///
5656
/// @brief Stop the application
@@ -75,10 +75,16 @@ namespace cae
7575
///
7676
static EngineConfig parseEngineConf(const std::string &path);
7777

78+
///
79+
/// @brief main loop
80+
///
81+
void mainLoop();
82+
7883
std::unique_ptr<utl::PluginLoader> m_pluginLoader = nullptr;
7984
std::unique_ptr<Engine> m_engine = nullptr;
8085

8186
AppConfig m_appConfig;
87+
std::unordered_map<KeyCode, bool> m_keyState;
8288

8389
}; // class Application
8490

include/CAE/Common.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#pragma once
88

9-
#include "CAE/Generated/Version.hpp"
9+
#include "CAE/Version.hpp"
1010

1111
#include "Engine/Common.hpp"
1212

@@ -47,6 +47,7 @@ namespace cae
4747

4848
namespace WINDOW
4949
{
50+
inline constexpr auto COCOA = "Cocoa";
5051
inline constexpr auto GLFW = "GLFW";
5152
inline constexpr auto WIN32_ = "Win32";
5253
inline constexpr auto X11 = "X11";

modules/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ add_subdirectory(Engine)
66
target_link_libraries(cae-modules INTERFACE
77
cae-utils
88
cae-engine
9+
cae-compile-options
910
)
1011
target_include_directories(cae-modules SYSTEM INTERFACE
1112
"${CMAKE_CURRENT_SOURCE_DIR}/Interfaces/include"

modules/Engine/CMakeLists.txt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,6 @@ project(cae-engine
44
LANGUAGES CXX
55
)
66

7-
include(FetchContent)
8-
9-
set(GLM_BUILD_TESTS OFF CACHE INTERNAL "")
10-
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
11-
12-
FetchContent_Declare(
13-
glm
14-
GIT_REPOSITORY https://github.com/g-truc/glm.git
15-
GIT_TAG 1.0.3
16-
GIT_SHALLOW TRUE
17-
GIT_PROGRESS TRUE
18-
)
19-
20-
FetchContent_MakeAvailable(glm)
21-
227
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
238
set(INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include")
249

@@ -36,6 +21,7 @@ target_sources(${PROJECT_NAME}
3621

3722
target_link_libraries(${PROJECT_NAME} PRIVATE
3823
cae-utils
24+
cae-compile-options
3925
glm::glm
4026
)
4127
target_include_directories(${PROJECT_NAME}
@@ -47,8 +33,6 @@ target_include_directories(${PROJECT_NAME}
4733
"${CMAKE_SOURCE_DIR}/modules/Interfaces/include"
4834
)
4935

50-
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_23)
51-
target_compile_options(${PROJECT_NAME} PRIVATE ${WARNING_FLAGS})
5236
set_target_properties(${PROJECT_NAME} PROPERTIES
5337
POSITION_INDEPENDENT_CODE ON
5438
CXX_EXTENSIONS OFF

0 commit comments

Comments
 (0)