Skip to content
Merged

P0 #23

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 46 additions & 49 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,68 @@ on:
push:
branches:
- master
- development
- c-i
pull_request:
branches:
- master
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
- development

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
name: build-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest]

os: [windows-latest, ubuntu-latest]
env:
BUILD_TYPE: Release
steps:
- uses: actions/checkout@v2
- name: Linux dev lib
- uses: actions/checkout@v4

- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install -y gcc-10 g++-10
sudo apt-get install -y libxrandr-dev xorg-dev libglu1-mesa-dev
sudo apt-get install -y libgtk-3-dev
export CC=gcc-10
export CXX=g++-10
run: |
sudo apt-get update
sudo apt-get install -y libxrandr-dev xorg-dev libglu1-mesa-dev libgtk-3-dev

sudo apt-get install libgtest-dev
cd /usr/src/gtest
sudo mkdir build
cd build
sudo cmake ..
sudo make

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{runner.workspace}}/build
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
shell: bash
working-directory: ${{runner.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}

- name: Build
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute the build. You can specify a specific target with "--target <NAME>"
run: cmake --build . --config $BUILD_TYPE
run: cmake --build build --config ${{ env.BUILD_TYPE }}

- name: Test
working-directory: ${{runner.workspace}}/build
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C $BUILD_TYPE --rerun-failed --output-on-failure
working-directory: build
run: ctest -C ${{ env.BUILD_TYPE }} --output-on-failure

sanitizers:
name: asan-ubsan (ubuntu)
runs-on: ubuntu-latest
env:
BUILD_TYPE: Debug
CC: clang
CXX: clang++
CXXFLAGS: -fsanitize=address,undefined -fno-omit-frame-pointer
LDFLAGS: -fsanitize=address,undefined
steps:
- uses: actions/checkout@v4

- name: Install Linux dependencies
run: |
sudo apt-get update
sudo apt-get install -y libxrandr-dev xorg-dev libglu1-mesa-dev libgtk-3-dev

- name: Configure CMake
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}

- name: Build
run: cmake --build build --config ${{ env.BUILD_TYPE }}

- name: Test
working-directory: build
env:
ASAN_OPTIONS: detect_leaks=1:halt_on_error=0
UBSAN_OPTIONS: print_stacktrace=1
run: ctest -C ${{ env.BUILD_TYPE }} --output-on-failure
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ build/

.vscode/
/.vs

docs/REMEDIATION_PLAN.md
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.19)
project(ICE_ROOT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(cmake/fetch_dependencies.cmake)
enable_testing()
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(BUILD_IMXML_EXAMPLE OFF CACHE BOOL "" FORCE)
include(cmake/fetch_dependencies.cmake)
enable_testing()


if(APPLE)
find_library(COCOA_LIBRARY Cocoa REQUIRED)
Expand Down
7 changes: 3 additions & 4 deletions ICE/Assets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ target_sources(${PROJECT_NAME} PRIVATE
src/GPURegistry.cpp
src/Texture.cpp)

target_link_libraries(${PROJECT_NAME}
PUBLIC
graphics
target_link_libraries(${PROJECT_NAME}
PUBLIC
graphics
util
io
storage
math
)
Expand Down
8 changes: 8 additions & 0 deletions ICE/Assets/include/AssetBank.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ class AssetBank {
public:
AssetBank();

// Registration seam for asset loaders. The concrete loaders live in the `io`
// module; the composition layer wires them in via this method so that `assets`
// does not depend on `io` (see registerDefaultLoaders in the io module).
template<typename T>
void addLoader(const std::shared_ptr<IAssetLoader<T>>& asset_loader) {
loader.AddLoader<T>(asset_loader);
}

template<typename T>
std::shared_ptr<T> getAsset(AssetUID uid) {
return dynamic_pointer_cast<T>(getAsset(uid));
Expand Down
File renamed without changes.
20 changes: 3 additions & 17 deletions ICE/Assets/src/AssetBank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,11 @@

#include "AssetBank.h"

#include <ICEException.h>
#include <Model.h>

#include "MaterialLoader.h"
#include "MeshLoader.h"
#include "ModelLoader.h"
#include "ShaderLoader.h"
#include "TextureLoader.h"

namespace ICE {

AssetBank::AssetBank() {
loader.AddLoader<Texture2D>(std::make_shared<Texture2DLoader>());
loader.AddLoader<TextureCube>(std::make_shared<TextureCubeLoader>());
loader.AddLoader<Model>(std::make_shared<ModelLoader>(*this));
loader.AddLoader<Shader>(std::make_shared<ShaderLoader>());
loader.AddLoader<Material>(std::make_shared<MaterialLoader>());
loader.AddLoader<Mesh>(std::make_shared<MeshLoader>());
}
// Loaders are registered by the composition layer (io::registerDefaultLoaders),
// not here, so that the `assets` module does not depend on `io`.
AssetBank::AssetBank() = default;

bool AssetBank::nameInUse(const AssetPath &name) {
return !(nameMapping.find(name) == nameMapping.end());
Expand Down
22 changes: 12 additions & 10 deletions ICE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_subdirectory(Graphics)
add_subdirectory(GraphicsAPI)
add_subdirectory(IO)
add_subdirectory(Math)
add_subdirectory(Multithreading)
add_subdirectory(Platform)
add_subdirectory(Scene)
add_subdirectory(Storage)
Expand All @@ -38,20 +39,21 @@ elseif(WIN32)
${ICE_LIBS}
)
else()
find_package(GTK REQUIRED)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
find_package(PkgConfig REQUIRED)

add_definitions(${GTK3_CFLAGS_OTHER})
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)

find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIRS})

target_link_libraries(${PROJECT_NAME}
INTERFACE
glfw
${GTK3_LIBRARIES}
${OPENGL_LIBRARIES}
target_include_directories(${PROJECT_NAME} INTERFACE ${GTK3_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIRS})
target_compile_options(${PROJECT_NAME} INTERFACE ${GTK3_CFLAGS_OTHER})

target_link_libraries(${PROJECT_NAME}
INTERFACE
glfw
${GTK3_LIBRARIES}
${OPENGL_LIBRARIES}
stdc++fs
${ICE_LIBS}
)
endif()
5 changes: 3 additions & 2 deletions ICE/Components/include/RenderComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@

namespace ICE {
struct RenderComponent : public Component {
RenderComponent() = default;
RenderComponent(AssetUID mesh_id, AssetUID material_id) : mesh(mesh_id), material(material_id) {}
AssetUID mesh;
AssetUID material;
AssetUID mesh = NO_ASSET_ID;
AssetUID material = NO_ASSET_ID;
};
} // namespace ICE

Expand Down
6 changes: 4 additions & 2 deletions ICE/Components/include/TransformComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ struct TransformComponent : public Component {
m_rotation(rot),
m_scale(sca) {}

TransformComponent(const Eigen::Vector3f& pos = Eigen::Vector3f::Zero(), const Eigen::Vector3f& rot = Eigen::Vector3f::Zero(),
const Eigen::Vector3f& sca = Eigen::Vector3f::Ones())
// Euler-rotation overload: pos and rot are required (no defaults) so that the
// zero- and single-Vector3f-argument cases resolve unambiguously to the
// quaternion-rotation constructor above.
TransformComponent(const Eigen::Vector3f& pos, const Eigen::Vector3f& rot, const Eigen::Vector3f& sca = Eigen::Vector3f::Ones())
: m_position(pos),
m_scale(sca) {
setRotationEulerDeg(rot);
Expand Down
1 change: 1 addition & 0 deletions ICE/Entity/include/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ICE_ENTITY_H

#include <bitset>
#include <cstdint>
#include <cstdlib>
#include <queue>
#include <typeindex>
Expand Down
13 changes: 7 additions & 6 deletions ICE/Graphics/include/ForwardRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <GraphicsAPI.h>
#include <Registry.h>

#include <optional>
#include <vector>

#include "Camera.h"
Expand All @@ -23,13 +24,13 @@ namespace ICE {

class ForwardRenderer : public Renderer {
public:
ForwardRenderer(const std::shared_ptr<RendererAPI>& api, const std::shared_ptr<GraphicsFactory>& factory);
ForwardRenderer(const std::shared_ptr<RendererAPI> &api, const std::shared_ptr<GraphicsFactory> &factory);

void submitSkybox(const Skybox& e) override;
void submitDrawable(const Drawable& e) override;
void submitLight(const Light& e) override;
void submitSkybox(const Skybox &e) override;
void submitDrawable(const Drawable &e) override;
void submitLight(const Light &e) override;

void prepareFrame(Camera& camera) override;
void prepareFrame(Camera &camera) override;

std::shared_ptr<Framebuffer> render() override;

Expand All @@ -52,7 +53,7 @@ class ForwardRenderer : public Renderer {
std::optional<Skybox> m_skybox;
std::vector<Drawable> m_drawables;
std::vector<Light> m_lights;

// Instance batching storage
std::unordered_map<uint64_t, std::vector<InstanceData>> m_instance_batches;

Expand Down
2 changes: 1 addition & 1 deletion ICE/GraphicsAPI/OpenGL/include/OpenGLShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class OpenGLShader : public ShaderProgram {

void compileAndAttachStage(ShaderStage stage, const std::string &source);

constexpr GLenum stageToGLStage(ShaderStage stage);
GLenum stageToGLStage(ShaderStage stage);

uint32_t m_programID;
std::unordered_map<std::string, uint32_t> m_locations;
Expand Down
2 changes: 1 addition & 1 deletion ICE/GraphicsAPI/OpenGL/src/OpenGLShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void OpenGLShader::compileAndAttachStage(ShaderStage stage, const std::string &s
}


constexpr GLenum OpenGLShader::stageToGLStage(ShaderStage stage) {
GLenum OpenGLShader::stageToGLStage(ShaderStage stage) {
switch (stage) {
case ShaderStage::Vertex:
return GL_VERTEX_SHADER;
Expand Down
1 change: 1 addition & 0 deletions ICE/IO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_library(${PROJECT_NAME} STATIC)

target_sources(${PROJECT_NAME} PRIVATE
src/EngineConfig.cpp
src/DefaultLoaders.cpp
src/Project.cpp
src/MaterialExporter.cpp
src/TextureLoader.cpp
Expand Down
11 changes: 11 additions & 0 deletions ICE/IO/include/DefaultLoaders.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

namespace ICE {
class AssetBank;

// Registers the engine's built-in asset loaders (mesh, model, material, shader,
// textures) onto the given bank. Lives in the `io` module because that is where
// the concrete loaders (and their Assimp/JSON dependencies) live; keeping this
// out of AssetBank's constructor is what breaks the assets <-> io dependency cycle.
void registerDefaultLoaders(AssetBank &bank);
} // namespace ICE
2 changes: 1 addition & 1 deletion ICE/IO/include/ModelLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ModelLoader : public IAssetLoader<Model> {
Eigen::Vector3f aiVec3ToEigen(const aiVector3D &vec);
Eigen::Quaternionf aiQuatToEigen(const aiQuaternion &q);

constexpr TextureFormat getTextureFormat(aiTextureType type, int channels);
TextureFormat getTextureFormat(aiTextureType type, int channels);

AssetBank &ref_bank;
};
Expand Down
2 changes: 1 addition & 1 deletion ICE/IO/include/ShaderExporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ShaderExporter : public AssetExporter<Shader> {
void writeToJson(const std::filesystem::path &path, const Shader &object) override;
void writeToBin(const std::filesystem::path &path, const Shader &object) override;

constexpr std::string stageToString(ShaderStage stage) {
std::string stageToString(ShaderStage stage) {
switch (stage) {
case ShaderStage::Vertex:
return "vertex";
Expand Down
2 changes: 1 addition & 1 deletion ICE/IO/include/ShaderLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ class ShaderLoader : public IAssetLoader<Shader> {
ShaderLoader() = default;
std::shared_ptr<Shader> load(const std::vector<std::filesystem::path> &file) override;
std::string readAndResolveIncludes(const std::filesystem::path &file);
constexpr ShaderStage stageFromString(const std::string &str);
ShaderStage stageFromString(const std::string &str);
};
} // namespace ICE
21 changes: 21 additions & 0 deletions ICE/IO/src/DefaultLoaders.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "DefaultLoaders.h"

#include <memory>

#include "AssetBank.h"
#include "MaterialLoader.h"
#include "MeshLoader.h"
#include "ModelLoader.h"
#include "ShaderLoader.h"
#include "TextureLoader.h"

namespace ICE {
void registerDefaultLoaders(AssetBank &bank) {
bank.addLoader<Texture2D>(std::make_shared<Texture2DLoader>());
bank.addLoader<TextureCube>(std::make_shared<TextureCubeLoader>());
bank.addLoader<Model>(std::make_shared<ModelLoader>(bank));
bank.addLoader<Shader>(std::make_shared<ShaderLoader>());
bank.addLoader<Material>(std::make_shared<MaterialLoader>());
bank.addLoader<Mesh>(std::make_shared<MeshLoader>());
}
} // namespace ICE
Loading
Loading