Skip to content

Commit 422c1ee

Browse files
authored
Merge pull request #39 from tomezpl/32-scene-graph
feat: added a basic scene graph
2 parents 71ff1ad + 2da67c9 commit 422c1ee

21 files changed

+1309
-698
lines changed

.clang-format

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
AllowShortFunctionsOnASingleLine: InlineOnly
2+
BreakBeforeBraces: Allman
3+
Language: Cpp
4+
SpaceAroundPointerQualifiers: Default
5+
PointerAlignment: Left
6+
NamespaceIndentation: All
7+
IndentWidth: 4
8+
AccessModifierOffset: 0
9+
ColumnLimit: 0
10+
UseTab: ForIndentation
11+
AllowShortBlocksOnASingleLine: Always
12+
BreakInheritanceList: AfterComma
13+
BreakBeforeInheritanceComma: false
14+
BreakConstructorInitializersBeforeComma: false
15+
SortIncludes: Never

CMakeLists.txt

+58-85
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@
88
### Be sure to define your system's triplet to ensure correct target architecture (32/64-bit). https://vcpkg.readthedocs.io/en/latest/users/triplets/#additional-remarks
99

1010
# min. required CMake version
11-
cmake_minimum_required (VERSION 3.26)
11+
cmake_minimum_required(VERSION 3.26)
1212
include(FindOpenGL)
1313
include(CMakePrintHelpers)
1414

1515
set(VCPKG_FEATURE_FLAGS "manifests,registries,versions")
1616

1717
# VCPKG directory
18-
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
19-
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
20-
CACHE STRING "")
21-
endif()
18+
if (DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
19+
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
20+
CACHE STRING "")
21+
endif ()
2222

2323
# VCPKG triplet to use (architecture, e.g. x86-windows)
24-
if(DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
25-
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
26-
endif()
24+
if (DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET)
25+
set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "")
26+
endif ()
2727

2828
# C++ standard
2929
set(CMAKE_CXX_STANDARD 17)
3030

3131
# Ensure correct library bitness if running Windows
32-
if(${CMAKE_HOST_WIN32})
33-
if(ENV{VCPKG_DEFAULT_TRIPLET} STREQUAL "x64-windows")
34-
set(CMAKE_SIZEOF_VOID_P 8)
35-
endif()
36-
endif()
32+
if (${CMAKE_HOST_WIN32})
33+
if (ENV{VCPKG_DEFAULT_TRIPLET} STREQUAL "x64-windows")
34+
set(CMAKE_SIZEOF_VOID_P 8)
35+
endif ()
36+
endif ()
3737

3838
project(Lepus)
3939

@@ -56,7 +56,6 @@ set(LEPUS_SRC_DIR ${CMAKE_SOURCE_DIR}/src/lepus)
5656
# Engine-wide include directories
5757
include_directories(${CMAKE_SOURCE_DIR}/include src ${CMAKE_SOURCE_DIR}/3rdparty)
5858
include_directories(${VCPKG_INCLUDE_PATH})
59-
include_directories(${VCPKG_INCLUDE_PATH}/bullet)
6059

6160
link_directories(${VCPKG_LIB_PATH})
6261

@@ -109,57 +108,28 @@ add_dependencies(LepusDemo LepusGfx)
109108
# Dependency libraries
110109
## LepusGfx: GL3W (core profile loading)
111110
add_library(GL3W
112-
3rdparty/gl3w/src/gl3w.c
111+
3rdparty/gl3w/src/gl3w.c
113112
)
114113
include_directories(3rdparty/gl3w/include)
115114
## LepusGfx: GLFW libraries
116115
find_package(glfw3 CONFIG REQUIRED)
117116

118-
## LepusGfx: GLEW includes
119-
include_directories(LepusGfx ${GLEW_INCLUDES})
120-
121117
## LepusGfx: GLFW includes
122118
include_directories(LepusGfx ${GLFW_INCLUDES})
123119

124120
# LepusEngine sources
125-
## LepusEngine: PhysX includes
126-
set(PHYSX_INCLUDES ${VCPKG_DEPS_PATH}/include/physx)
127-
include_directories(${PHYSX_INCLUDES})
128-
129-
## LepusEngine: Bullet3 libraries
130-
131-
#find_library(BULLET_COMMON_LIB Bullet3Common ${VCPKG_LIBS_REL_PATH} NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
132-
set(BULLET_COMMON_LIB ${Bullet3Common})
133-
#find_library(BULLET_COLLISION_LIB BulletCollision ${VCPKG_LIBS_REL_PATH} NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
134-
set(BULLET_COLLISION_LIB ${BulletCollision})
135-
#find_library(BULLET_DYNAMICS_LIB BulletDynamics ${VCPKG_LIBS_REL_PATH} NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
136-
set(BULLET_DYNAMICS_LIB ${BulletDynamics})
137-
#find_library(BULLET_LINMATH_LIB LinearMath ${VCPKG_LIBS_REL_PATH} NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
138-
set(BULLET_LINMATH_LIB ${LinearMath})
139-
140-
#find_library(BULLET_COMMON_LIB_DBG Bullet3Common_Debug ${VCPKG_LIBS_DBG_PATH} NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
141-
#find_library(BULLET_COLLISION_LIB_DBG BulletCollision_Debug ${VCPKG_LIBS_DBG_PATH} NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
142-
#find_library(BULLET_DYNAMICS_LIB_DBG BulletDynamics_Debug ${VCPKG_LIBS_DBG_PATH} NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
143-
#find_library(BULLET_LINMATH_LIB_DBG LinearMath_Debug ${VCPKG_LIBS_DBG_PATH} NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH)
144-
145-
# Link Bullet for debug and release targets
146-
target_link_libraries(LepusEngine PRIVATE LinearMath Bullet3Common BulletDynamics BulletCollision)
147-
148-
#target_link_libraries(LepusEngine debug Bullet3Common_Debug optimized Bullet3Common)
149-
#target_link_libraries(LepusEngine debug BulletDynamics_Debug optimized BulletDynamics)
150-
#target_link_libraries(LepusEngine debug BulletCollision_Debug optimized BulletCollision)
151121

152122
file(MAKE_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/Release)
153123
file(MAKE_DIRECTORY ${EXECUTABLE_OUTPUT_PATH}/Debug)
154124

155125
# Set working directory for debugger
156126
set_property(TARGET LepusDemo PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}/Debug")
157127

158-
if(OpenGL::GL)
159-
set(GL_LIBRARY OpenGL::GL)
160-
elseif(OpenGL::OpenGL)
161-
set(GL_LIBRARY OpenGL::OpenGL)
162-
endif(OpenGL::GL)
128+
if (OpenGL::GL)
129+
set(GL_LIBRARY OpenGL::GL)
130+
elseif (OpenGL::OpenGL)
131+
set(GL_LIBRARY OpenGL::OpenGL)
132+
endif (OpenGL::GL)
163133
target_link_libraries(LepusGfx PRIVATE GL3W glfw ${GL_LIBRARY} DearImgui LepusEngine LepusUtility LepusSystem)
164134
target_link_libraries(LepusDemo PRIVATE DearImgui LepusGfx LepusUtility LepusEngine)
165135

@@ -170,9 +140,9 @@ add_custom_command(TARGET LepusDemo POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_
170140
# Unit testing framework
171141
include(FetchContent)
172142
FetchContent_Declare(
173-
googletest
174-
GIT_REPOSITORY https://github.com/google/googletest.git
175-
GIT_TAG release-1.12.1
143+
googletest
144+
GIT_REPOSITORY https://github.com/google/googletest.git
145+
GIT_TAG release-1.12.1
176146
)
177147
# For Windows: Prevent overriding the parent project's compiler/linker settings
178148
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
@@ -182,21 +152,23 @@ enable_testing()
182152

183153
# Unit test projects for each library
184154
add_executable(LepusGfx_Tests
185-
tests/L3D/GraphicsEngine/GraphicsApiTests.h
186-
tests/L3D/GraphicsEngine/GraphicsApiTests.cpp
187-
tests/L3D/GraphicsEngine/GraphicsApiOptionsTests.h
188-
tests/L3D/GraphicsEngine/GraphicsApiOptionsTests.cpp
155+
tests/L3D/GraphicsEngine/GraphicsApiTests.h
156+
tests/L3D/GraphicsEngine/GraphicsApiTests.cpp
157+
tests/L3D/GraphicsEngine/GraphicsApiOptionsTests.h
158+
tests/L3D/GraphicsEngine/GraphicsApiOptionsTests.cpp
159+
tests/L3D/SceneGraph/SceneGraphTests.h
160+
tests/L3D/SceneGraph/SceneGraphTests.cpp
189161
)
190162

191163
add_executable(LepusSystem_Tests
192-
tests/LSystem/IO/FileSystemTests.h
193-
tests/LSystem/IO/FileSystemTests.cpp
164+
tests/LSystem/IO/FileSystemTests.h
165+
tests/LSystem/IO/FileSystemTests.cpp
194166
)
195167

196168
add_executable(LepusUtility_Tests
197-
tests/LUtility/MathTests/MatrixTests.cpp
198-
tests/LUtility/MathTests/VectorTests.cpp
199-
tests/LUtility/MathTests/TransformTests.cpp
169+
tests/LUtility/MathTests/MatrixTests.cpp
170+
tests/LUtility/MathTests/VectorTests.cpp
171+
tests/LUtility/MathTests/TransformTests.cpp
200172
)
201173

202174
add_custom_command(TARGET LepusSystem_Tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/tests/Content" ${CMAKE_BINARY_DIR}/tests/Content)
@@ -212,27 +184,28 @@ gtest_discover_tests(LepusUtility_Tests)
212184

213185
# Warnings
214186
set(LepusTargets LepusEngine LepusSystem LepusGfx LepusSystem_Tests LepusGfx_Tests LepusUtility_Tests)
215-
if(MSVC)
216-
# Ignore warnings:
217-
# 4100: unreferenced param,
218-
# 4514: unreferenced inline function removed,
219-
# 4464: parent relative include,
220-
# 4820: struct padding,
221-
# 4263: member not overriding base class virtual
222-
# 4265-5027: copy ctor, move ctor, assignment, move assignment implicitly deleted (this messes up gtest projects)
223-
# 5045: "compiler will insert Spectre mitigation for memory load"
224-
set(MSVCDisabledWarnings 4100 4514 4464 4820 4263 4625 5026 4626 5027 5045)
225-
226-
set(MSVCDisabledWarningsFormatted "")
227-
foreach(Warning IN LISTS MSVCDisabledWarnings)
228-
set(MSVCDisabledWarningsFormatted ${MSVCDisabledWarningsFormatted} /wd${Warning})
229-
endforeach()
230-
231-
foreach(Target IN LISTS LepusTargets)
232-
target_compile_options(${Target} PRIVATE /Wall ${MSVCDisabledWarningsFormatted} /WX /external:W3)
233-
endforeach()
234-
else()
235-
foreach(Target IN LISTS LepusTargets)
236-
target_compile_options(${Target} PRIVATE -Wall -Wextra -Wpedantic)
237-
endforeach()
238-
endif()
187+
if (MSVC)
188+
# Ignore warnings:
189+
# 4100: unreferenced param,
190+
# 4514: unreferenced inline function removed,
191+
# 4464: parent relative include,
192+
# 4820: struct padding,
193+
# 4263: member not overriding base class virtual
194+
# 4265-5027: copy ctor, move ctor, assignment, move assignment implicitly deleted (this messes up gtest projects)
195+
# 5045: "compiler will insert Spectre mitigation for memory load"
196+
# 5262: implicit switch fallback
197+
set(MSVCDisabledWarnings 4100 4514 4464 4820 4263 4625 5026 4626 5027 5045 5262)
198+
199+
set(MSVCDisabledWarningsFormatted "")
200+
foreach (Warning IN LISTS MSVCDisabledWarnings)
201+
set(MSVCDisabledWarningsFormatted ${MSVCDisabledWarningsFormatted} /wd${Warning})
202+
endforeach ()
203+
204+
foreach (Target IN LISTS LepusTargets)
205+
target_compile_options(${Target} PRIVATE /Wall ${MSVCDisabledWarningsFormatted} /WX /external:W3)
206+
endforeach ()
207+
else ()
208+
foreach (Target IN LISTS LepusTargets)
209+
target_compile_options(${Target} PRIVATE -Wall -Wextra -Wpedantic)
210+
endforeach ()
211+
endif ()

Content/GLSL/Unlit/RGBVertex.vert

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ layout (location = 0) in vec3 position;
44

55
uniform mat4 PROJ;
66
uniform mat4 VIEW;
7+
uniform mat4 MODEL;
78

89
out vec3 vertColor;
910

1011
void main()
1112
{
12-
gl_Position = PROJ * VIEW * vec4(position, 1.0);
13+
gl_Position = PROJ * VIEW * MODEL * vec4(position, 1.0);
1314

1415
float normalisedIndex = mod(float(gl_VertexID), 3.0f);
1516
float r = step(normalisedIndex, 0.0f);

README.md

+16-72
Original file line numberDiff line numberDiff line change
@@ -3,88 +3,32 @@
33
### About
44
LepusEngine is a game engine developed in C++ and modern OpenGL (versions >= 3.3).
55

6-
The renderer uses a programmable pipeline and as a result comes with a bundled set of GLSL shaders.
7-
86
### Building
9-
The engine now uses CMake (tested version 3.15.2). Download and install it if you don't have it already.
10-
11-
General use of CMake comes down to running `cmake configure` and `cmake generate` (please look up KitWare's documentation to learn more).
12-
13-
Currently the engine only builds on Windows during to its reliance on PhysX. On Windows, you can also use CMake-gui.
14-
15-
#### Dependencies
16-
Download binaries for these libraries and place them in `<lepus_root>/build/deps`:
17-
18-
* GLFW (*build/deps/glfw-x.x.x.bin.WIN64*)
19-
* The root directory of a 64-bit pre-compiled binary GLFW package for MSVC++ (folder name usually *glfw-x.x.x.bin.WIN64*).
20-
* For example, *build/deps/glfw-x.x.x.bin.WIN64/lib-vc2015/* should contain your 64-bit *glfw3.lib* files
21-
* GLFW32 (*build/deps/glfw-x.x.x.bin.WIN32*)
22-
* The root directory of a 32-bit pre-compiled binary GLFW package for MSVC++ (folder name usually *glfw-x.x.x.bin.WIN32*).
23-
* For example, *build/deps/glfw-x.x.x.bin.WIN32/lib-vc2015/* should contain your 32-bit *glfw3.lib* files
24-
* GLEW (*build/deps/glew-x.x.x-win32*)
25-
* The root directory of a GLEW package for Win32 (folder name usually *glew-x.x.x-win32/glew-x.x.x*).
26-
* For example, *build/deps/glew-x.x.x-win32/glew-x.x.x/lib/* should contain the *glew.lib* files
27-
* PHYSX (*build/deps/PhysX-x.x/physx/install/vcxxwin64*)
28-
* The root directory of the *compiled binaries* for PhysX for 64-bit Visual C++ (folder name usually *PhysX-x.x/physx/install/vcxxwin64*).
29-
* For example, *build/deps/PhysX-x.x/physx/install/vcxxwin64/PhysX/include/* should contain the *PxPhysXConfig.h* header file.
30-
* You can find info regarding building PhysX SDK from source on [NVIDIA's official PhysX repository](https://github.com/NVIDIAGameWorks/PhysX).
31-
* PHYSX32 (*build/deps/PhysX-x.x/physx/install/vcxxwin32*)
32-
* The root directory of the *compiled binaries* for PhysX for 32-bit Visual C++ (folder name usually *PhysX-x.x/physx/install/vcxxwin32*).
33-
* For example, *build/deps/PhysX-x.x/physx/install/vcxxwin32/PhysX/include/* should contain the *PxPhysXConfig.h* header file.
34-
* You can find info regarding building PhysX SDK from source on [NVIDIA's official PhysX repository](https://github.com/NVIDIAGameWorks/PhysX).
35-
36-
### Usage
37-
The __RenderEngine__ class (from the _LepusEngine_::_Lepus3D_ namespace) is responsible for drawing pretty much anything to your screen.
38-
39-
__RenderEngine__ also creates and updates a GL context and window.
40-
41-
An example app using the engine would look like this:
42-
43-
```c++
44-
#include <L3D/RenderEngine.h>
7+
The engine uses CMake (>= 3.26) to generate build files. [Download and install it](https://cmake.org/download/) if you don't have it already.
458

46-
using namespace LepusEngine;
47-
using namespace Lepus3D;
9+
Dependencies for the project are resolved and installed using [vcpkg](https://vcpkg.io/). See [Dependencies](#dependencies) for more info.
4810

49-
int main()
50-
{
51-
Lepus3D::RenderEngine engine("LepusDemo", 800, 600);
11+
General use of CMake comes down to running `cmake configure` and `cmake generate` (please look up [KitWare's documentation](https://cmake.org/documentation/) to learn more).
5212

53-
Lepus3D::Material testMat("Test material", "PerVertexUnlit");
54-
Lepus3D::BoxMesh testMesh;
13+
Some IDEs such as Visual Studio, Visual Studio Code, and CLion come with CMake support or offer "CMake Tools" extensions that allow you to generate the build files from your IDE.
14+
On Windows, you can also use CMake-gui.
5515

56-
// Be sure to get your own images, these are not provided with the Git repository
57-
Lepus3D::Texture2D firstTx("container.jpg"); // Loads from Solution/Content/
58-
testMat.SetAttributeTex("_Texture1", firstTx);
16+
The project is primarily built with Visual C++ 2022 during development and [GCC 11.4.0 on GitHub Actions](https://github.com/tomezpl/LepusEngine/actions),
17+
and as such those are the "officially supported" compilers at this time.
5918

60-
Lepus3D::Transform transform;
61-
62-
sf::Clock timer;
19+
#### Dependencies
20+
This project uses [vcpkg](https://vcpkg.io/) to locate and install dependencies, such as code libraries, while keeping the need for platform-specific configuration down to a minimum (or none).
6321

64-
bool running = true;
65-
while (running)
66-
{
67-
float timeSeconds = timer.getElapsedTime().asSeconds();
68-
testMat.SetAttributeF("_Time", timeSeconds);
69-
transform.SetRotation(Vector3(timeSeconds * 25.f, timeSeconds * 50.f, 0.f));
70-
transform.SetScale(sin(timeSeconds));
71-
engine.Update(); // Update window events etc.
72-
engine.StartScene(); // Start drawing (clear buffers etc.)
73-
engine.DrawMesh(testMesh, testMat, transform);
74-
engine.EndScene(); // Finish drawing (display in window)
75-
running = engine.Update();
76-
}
77-
engine.Shutdown();
78-
return 0;
79-
}
80-
```
22+
vcpkg integrates with CMake via a CMake toolchain file. Provided you have a `VCPKG_ROOT` environment variable pointing at your **bootstrapped vcpkg** path,
23+
the CMakeLists script for LepusEngine should automatically pick up the toolchain file and install the dependencies as needed.
24+
See [Microsoft's vcpkg documentation](https://learn.microsoft.com/en-gb/vcpkg/get_started/get-started?pivots=shell-powershell) for more details.
8125

82-
Check the header files to see how things work. [RenderEngine.h](https://github.com/tomezpl/LepusEngine/blob/master/Lepus3D/Source/RenderEngine.h) is usually a good place to start.
26+
Additionally, some open-source cross-platform dependencies, such as gl3w and imgui are included in the `3rdparty` directory.
27+
For imgui, you'll need to run `git submodule update` in order to fetch code from the imgui repository before building LepusEngine.
8328

84-
### Contributing
85-
I myself am focused on creating the renderer. However, I plan on making this a full game engine, and any help would be appreciated.
29+
### Usage
30+
See the ["demo" example program](https://github.com/tomezpl/LepusEngine/tree/master/src/examples/demo) for an example of how to use the engine's API.
8631

87-
If you have any questions you can contact me at **[email protected]**. If there are any pull requests I'll try to merge them into **master** (assuming they work).
8832

8933
### Licensing
9034
LepusEngine is licensed under the MIT license. This means you are free to use LepusEngine in any way you want, but you must include the copyright notice and the permission notice.

scripts/install-ubuntu.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ sudo apt install git
1414

1515
# OpenGL
1616
echo "Installing OpenGL and Xorg dependencies"
17-
sudo apt install libopengl-dev libgl-dev libgl1-mesa-dev libgl1-mesa-glx libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev
17+
sudo apt install libopengl-dev libgl-dev libgl1-mesa-dev libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev libwayland-dev libxkbcommon-dev pkg-config
1818

1919
# VCPKG
2020
echo "Installing vcpkg"

0 commit comments

Comments
 (0)