diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 2935070..bd6661c 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -1,7 +1,17 @@ +add_subdirectory(./base) add_subdirectory(./logger) +add_subdirectory(./debug) add_subdirectory(./asset_baker) add_subdirectory(./asset_parser) +add_subdirectory(./asset_manager) +add_subdirectory(./camera) +add_subdirectory(./input) +add_subdirectory(./ui) + +add_subdirectory(./renderer) add_subdirectory(./engine) + add_subdirectory(./mirror) + diff --git a/modules/asset_manager/CMakeLists.txt b/modules/asset_manager/CMakeLists.txt new file mode 100644 index 0000000..bba44b1 --- /dev/null +++ b/modules/asset_manager/CMakeLists.txt @@ -0,0 +1,9 @@ +add_library_module(asset_manager + asset_manager.cpp +) + +target_link_libraries( + asset_manager + PUBLIC asset_parser + PRIVATE renderer +) diff --git a/modules/engine/include/engine/utils/resource_manager.hpp b/modules/asset_manager/include/asset_manager/asset_manager.hpp similarity index 84% rename from modules/engine/include/engine/utils/resource_manager.hpp rename to modules/asset_manager/include/asset_manager/asset_manager.hpp index dc042ba..1c8e840 100644 --- a/modules/engine/include/engine/utils/resource_manager.hpp +++ b/modules/asset_manager/include/asset_manager/asset_manager.hpp @@ -1,20 +1,18 @@ #pragma once -#include #include namespace Light { class Shader; class Texture; -class SharedContext; -class ResourceManager +class AssetManager { public: - static auto instance() -> ResourceManager & + static auto instance() -> AssetManager & { - static auto instance = ResourceManager {}; + static auto instance = AssetManager {}; return instance; } @@ -43,7 +41,7 @@ public: } private: - ResourceManager() = default; + AssetManager() = default; void load_shader_impl( const std::string &name, diff --git a/modules/engine/src/utils/resource_manager.cpp b/modules/asset_manager/src/asset_manager.cpp similarity index 88% rename from modules/engine/src/utils/resource_manager.cpp rename to modules/asset_manager/src/asset_manager.cpp index 9ee7683..3b23267 100644 --- a/modules/engine/src/utils/resource_manager.cpp +++ b/modules/asset_manager/src/asset_manager.cpp @@ -1,14 +1,14 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include namespace Light { -void ResourceManager::load_shader_impl( +void AssetManager::load_shader_impl( const std::string &name, const std::filesystem::path &vertex_path, const std::filesystem::path &pixel_path @@ -49,7 +49,7 @@ void ResourceManager::load_shader_impl( } } -void ResourceManager::load_texture_impl(const std::string &name, const std::filesystem::path &path) +void AssetManager::load_texture_impl(const std::string &name, const std::filesystem::path &path) { try { diff --git a/modules/asset_parser/CMakeLists.txt b/modules/asset_parser/CMakeLists.txt index d64bc24..bea89d5 100644 --- a/modules/asset_parser/CMakeLists.txt +++ b/modules/asset_parser/CMakeLists.txt @@ -6,7 +6,7 @@ add_library_module(asset_parser target_link_libraries( asset_parser - PRIVATE LZ4::lz4_static - PRIVATE nlohmann_json::nlohmann_json - PRIVATE logger + PUBLIC LZ4::lz4_static + PUBLIC nlohmann_json::nlohmann_json + PUBLIC logger ) diff --git a/modules/base/CMakeLists.txt b/modules/base/CMakeLists.txt new file mode 100644 index 0000000..b520576 --- /dev/null +++ b/modules/base/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library_module(base) + +target_precompile_headers(base INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.hpp) diff --git a/modules/engine/include/engine/base/base.hpp b/modules/base/include/base/base.hpp similarity index 62% rename from modules/engine/include/engine/base/base.hpp rename to modules/base/include/base/base.hpp index eb563a6..5bb7097 100644 --- a/modules/engine/include/engine/base/base.hpp +++ b/modules/base/include/base/base.hpp @@ -42,7 +42,6 @@ constexpr std::unique_ptr make_scope(t *rawPointer) #define lt_lin(x) // linux #define lt_mac(x) // mac - enum class Platform : uint8_t { windows, @@ -53,7 +52,6 @@ enum class Platform : uint8_t mac, }; - namespace constants { #if defined(LIGHT_PLATFORM_WINDOWS) @@ -91,16 +89,6 @@ auto linux_only(auto value) } } -#define lt_assert(x, ...) \ - { \ - if (!(x)) \ - { \ - log_crt(__VA_ARGS__); \ - lt_debug_trap(); \ - throw ::Light::FailedAssertion(__FILE__, __LINE__); \ - } \ - } - /* bit-wise */ constexpr auto bit(auto x) { @@ -111,28 +99,3 @@ constexpr auto bit(auto x) #define lt_pair_token_value_to_name(token) { token, #token } #define lt_pair_token_name_to_value(token) { #token, token } #define lt_token_name(token) #token -//====================================================================== OPERATIONS -//======================================================================// - -//========== ESSENTIAL_HEADERS ==========// -/* config */ -#ifndef LIGHT_CONFIG_H - #include -#endif - -/* debug */ -#ifndef LIGHT_LOGGER_H - #include -#endif -#include - -/* portables */ -#ifndef LIGHT_DEBUG_TRAP_H - #include -#endif - -/* utility */ -#ifndef LIGHT_STRINGIFIER_H - #include -#endif -//========== ESSENTIAL_HEADERS ==========// diff --git a/modules/engine/include/engine/base/config.hpp b/modules/base/include/base/config.hpp similarity index 100% rename from modules/engine/include/engine/base/config.hpp rename to modules/base/include/base/config.hpp diff --git a/modules/engine/include/engine/base/portables/debug_trap.hpp b/modules/base/include/base/portables/debug_trap.hpp similarity index 88% rename from modules/engine/include/engine/base/portables/debug_trap.hpp rename to modules/base/include/base/portables/debug_trap.hpp index cbd757c..89bef66 100644 --- a/modules/engine/include/engine/base/portables/debug_trap.hpp +++ b/modules/base/include/base/portables/debug_trap.hpp @@ -2,8 +2,6 @@ #ifndef LIGHT_DEBUG_TRAP_H #define LIGHT_DEBUG_TRAP_H - #include - // https://github.com/nemequ/portable-snippets/tree/master/debug-trap #ifdef LIGHT_DIST @@ -127,29 +125,29 @@ static inline void lt_debug_trap(void) #elif defined(LIGHT_DIST) #ifdef _MSC_VER #define lt_debug_trap() \ - log_crt( \ + log_crt( \ "DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \ __FUNCSIG__, \ __FILE__, \ - __LINE__) // or __FUNCSIG__ + __LINE__ \ + ) // or __FUNCSIG__ #else - #define lt_debug_trap() \ - log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) + #define lt_debug_trap() log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) #endif #else /* !defined(LIGHT_DIST) */ #ifdef _MSC_VER #define lt_debug_trap() \ - log_crt( \ + log_crt( \ "DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \ __FUNCSIG__, \ __FILE__, \ - __LINE__) // or __FUNCSIG__ + __LINE__ \ + ) // or __FUNCSIG__ #else - #define lt_debug_trap() \ - log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) + #define lt_debug_trap() log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) #endif #endif diff --git a/modules/engine/src/ltpch.hpp b/modules/base/src/pch.hpp similarity index 76% rename from modules/engine/src/ltpch.hpp rename to modules/base/src/pch.hpp index d3f2722..7257c69 100644 --- a/modules/engine/src/ltpch.hpp +++ b/modules/base/src/pch.hpp @@ -1,7 +1,6 @@ #pragma once -/* engine */ -#include +#include /* windows */ #ifdef _WIN32 @@ -10,39 +9,27 @@ #undef NOMINMAX #endif -/* containers */ +/** Stdlib */ +#include #include +#include #include +#include +#include +#include +#include #include #include -#include -#include -#include -#include - -/* misc */ -#include -#include +#include #include -#include -#include - -/* input/output */ -#include -#include +#include #include - -/* multi threading */ -#include -#include - -/* string */ #include #include - -/* filesystem */ -#include - -/* c libraries */ -#include +#include #include +#include +#include +#include +#include +#include diff --git a/modules/camera/CMakeLists.txt b/modules/camera/CMakeLists.txt new file mode 100644 index 0000000..59223f7 --- /dev/null +++ b/modules/camera/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library_module(camera camera.cpp ortho.cpp scene.cpp) + +target_link_libraries(camera PUBLIC glm::glm) diff --git a/modules/engine/include/engine/camera/camera.hpp b/modules/camera/include/camera/camera.hpp similarity index 89% rename from modules/engine/include/engine/camera/camera.hpp rename to modules/camera/include/camera/camera.hpp index f9f5f93..5f84296 100644 --- a/modules/engine/include/engine/camera/camera.hpp +++ b/modules/camera/include/camera/camera.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include namespace Light { @@ -26,7 +25,7 @@ public: } protected: - glm::mat4 m_projection{}; + glm::mat4 m_projection {}; private: glm::vec4 m_background_color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); diff --git a/modules/engine/include/engine/camera/ortho.hpp b/modules/camera/include/camera/ortho.hpp similarity index 91% rename from modules/engine/include/engine/camera/ortho.hpp rename to modules/camera/include/camera/ortho.hpp index 42dd064..76d3cae 100644 --- a/modules/engine/include/engine/camera/ortho.hpp +++ b/modules/camera/include/camera/ortho.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include namespace Light { @@ -47,9 +46,9 @@ private: const glm::vec3 m_up; - glm::mat4 m_projection{}; + glm::mat4 m_projection {}; - glm::mat4 m_view{}; + glm::mat4 m_view {}; glm::vec4 m_clear_color; }; diff --git a/modules/engine/include/engine/camera/scene.hpp b/modules/camera/include/camera/scene.hpp similarity index 93% rename from modules/engine/include/engine/camera/scene.hpp rename to modules/camera/include/camera/scene.hpp index 9810096..89a0ec6 100644 --- a/modules/engine/include/engine/camera/scene.hpp +++ b/modules/camera/include/camera/scene.hpp @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include namespace Light { @@ -93,7 +92,7 @@ private: float m_aspect_ratio; - ProjectionType m_projection_type{ProjectionType::Orthographic}; + ProjectionType m_projection_type { ProjectionType::Orthographic }; void calculate_projection(); }; diff --git a/modules/camera/src/camera.cpp b/modules/camera/src/camera.cpp new file mode 100644 index 0000000..2cf5642 --- /dev/null +++ b/modules/camera/src/camera.cpp @@ -0,0 +1,6 @@ +#include + +namespace Light { + + +} diff --git a/modules/engine/src/camera/ortho.cpp b/modules/camera/src/ortho.cpp similarity index 96% rename from modules/engine/src/camera/ortho.cpp rename to modules/camera/src/ortho.cpp index ea2fcff..385dd15 100644 --- a/modules/engine/src/camera/ortho.cpp +++ b/modules/camera/src/ortho.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/modules/engine/src/camera/scene.cpp b/modules/camera/src/scene.cpp similarity index 98% rename from modules/engine/src/camera/scene.cpp rename to modules/camera/src/scene.cpp index 3022ee7..9d3d43b 100644 --- a/modules/engine/src/camera/scene.cpp +++ b/modules/camera/src/scene.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace Light { diff --git a/modules/debug/CMakeLists.txt b/modules/debug/CMakeLists.txt new file mode 100644 index 0000000..0558102 --- /dev/null +++ b/modules/debug/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library_module(lt_debug) +target_link_libraries(lt_debug INTERFACE logger) +target_precompile_headers(lt_debug INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.hpp) diff --git a/modules/debug/include/ltdebug/assertions.hpp b/modules/debug/include/ltdebug/assertions.hpp new file mode 100644 index 0000000..4fafcd2 --- /dev/null +++ b/modules/debug/include/ltdebug/assertions.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include + +namespace Light { + +struct FailedAssertion: std::exception +{ + FailedAssertion(const char *file, int line); +}; + +// OpenGL +struct glException: std::exception +{ + glException(unsigned int source, unsigned int type, unsigned int id, const char *msg); +}; + +#define lt_assert(x, ...) \ + { \ + if (!(x)) \ + { \ + log_crt(__VA_ARGS__); \ + throw ::Light::FailedAssertion(__FILE__, __LINE__); \ + } \ + } + +} // namespace Light diff --git a/modules/debug/src/pch.hpp b/modules/debug/src/pch.hpp new file mode 100644 index 0000000..5ac58a4 --- /dev/null +++ b/modules/debug/src/pch.hpp @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/modules/engine/CMakeLists.txt b/modules/engine/CMakeLists.txt index 777850e..1a98039 100644 --- a/modules/engine/CMakeLists.txt +++ b/modules/engine/CMakeLists.txt @@ -1,95 +1,30 @@ -cmake_minimum_required(VERSION 3.16) - if(NOT WIN32) add_library_module(engine - camera/camera.cpp - camera/ortho.cpp - camera/scene.cpp core/application.cpp core/uuid.cpp debug/exceptions.cpp debug/instrumentor.cpp - graphics/blender.cpp - graphics/buffers.cpp - graphics/framebuffer.cpp - graphics/graphics_context.cpp - graphics/render_command.cpp - graphics/renderer.cpp - graphics/renderer_programs/quad.cpp - graphics/renderer_programs/texture.cpp - graphics/renderer_programs/tinted_texture.cpp - graphics/shader.cpp - graphics/texture.cpp - graphics/vertex_layout.cpp - input/input.cpp layer/layer.cpp layer/layer_stack.cpp - platform/graphics/opengl/blender.cpp - platform/graphics/opengl/buffers.cpp - platform/graphics/opengl/framebuffers.cpp - platform/graphics/opengl/graphics_context.cpp - platform/graphics/opengl/render_command.cpp - platform/graphics/opengl/shader.cpp - platform/graphics/opengl/texture.cpp - platform/graphics/opengl/user_interface.cpp - platform/graphics/opengl/vertex_layout.cpp - platform/os/linux/l_window.cpp + os/linux/l_window.cpp scene/entity.cpp scene/scene.cpp time/timer.cpp - user_interface/user_interface.cpp - utils/resource_manager.cpp utils/serializer.cpp utils/stringifier.cpp ) else() add_library_module(engine - camera/camera.cpp - camera/ortho.cpp - camera/scene.cpp core/application.cpp core/uuid.cpp debug/exceptions.cpp debug/instrumentor.cpp - graphics/blender.cpp - graphics/buffers.cpp - graphics/framebuffer.cpp - graphics/graphics_context.cpp - graphics/render_command.cpp - graphics/renderer.cpp - graphics/renderer_programs/quad.cpp - graphics/renderer_programs/texture.cpp - graphics/renderer_programs/tinted_texture.cpp - graphics/shader.cpp - graphics/texture.cpp - graphics/vertex_layout.cpp - input/input.cpp layer/layer.cpp layer/layer_stack.cpp - platform/graphics/directx/blender.cpp - platform/graphics/directx/buffers.cpp - platform/graphics/directx/framebuffers.cpp - platform/graphics/directx/graphics_context.cpp - platform/graphics/directx/render_command.cpp - platform/graphics/directx/shader.cpp - platform/graphics/directx/texture.cpp - platform/graphics/directx/user_interface.cpp - platform/graphics/directx/vertex_layout.cpp - platform/graphics/opengl/blender.cpp - platform/graphics/opengl/buffers.cpp - platform/graphics/opengl/framebuffers.cpp - platform/graphics/opengl/graphics_context.cpp - platform/graphics/opengl/render_command.cpp - platform/graphics/opengl/shader.cpp - platform/graphics/opengl/texture.cpp - platform/graphics/opengl/user_interface.cpp - platform/graphics/opengl/vertex_layout.cpp - platform/os/windows/w_window.cpp + os/windows/w_window.cpp scene/entity.cpp scene/scene.cpp time/timer.cpp - user_interface/user_interface.cpp - utils/resource_manager.cpp utils/serializer.cpp utils/stringifier.cpp ) @@ -97,14 +32,15 @@ endif() target_link_libraries( engine + PUBLIC renderer PUBLIC glad PUBLIC logger PUBLIC opengl::opengl PUBLIC glfw - PUBLIC imgui + PUBLIC ui PUBLIC asset_parser + PUBLIC asset_manager PUBLIC yaml-cpp::yaml-cpp PUBLIC EnTT::EnTT + PUBLIC lt_debug ) - -target_precompile_headers(engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/ltpch.hpp) diff --git a/modules/engine/include/engine/core/application.hpp b/modules/engine/include/engine/core/application.hpp index 2a54ef5..3a3b528 100644 --- a/modules/engine/include/engine/core/application.hpp +++ b/modules/engine/include/engine/core/application.hpp @@ -1,13 +1,16 @@ #pragma once -#include -#include + #include +#include namespace Light { +class Renderer; class Window; class Event; +class UserInterface; +class GraphicsContext; extern Scope create_application(); @@ -43,6 +46,12 @@ private: Scope m_window; + Scope m_user_interface; + + Scope m_graphics_context; + + Scope m_renderer; + static Application *s_instance; }; diff --git a/modules/engine/include/engine/core/window.hpp b/modules/engine/include/engine/core/window.hpp index 9708eba..aa71fe9 100644 --- a/modules/engine/include/engine/core/window.hpp +++ b/modules/engine/include/engine/core/window.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include + #include +#include namespace Light { @@ -20,9 +20,9 @@ struct WindowProperties class Window { public: - static Scope create(const std::function& callback); + static Scope create(const std::function &callback); - Window(): m_graphics_context(nullptr), m_properties {} + Window(): m_properties {} { } @@ -55,11 +55,6 @@ public: virtual void set_visibility(bool visible, bool toggle = false) = 0; - [[nodiscard]] auto get_graphics_context() const -> GraphicsContext * - { - return m_graphics_context.get(); - } - [[nodiscard]] auto get_properties() const -> const WindowProperties & { return m_properties; @@ -90,12 +85,12 @@ public: return m_properties.visible; } -protected: - Scope m_graphics_context; + virtual auto get_handle() -> void * = 0; +protected: WindowProperties m_properties; - bool b_Closed{false}; + bool b_Closed { false }; }; } // namespace Light diff --git a/modules/engine/include/engine/debug/exceptions.hpp b/modules/engine/include/engine/debug/exceptions.hpp index a202b02..3f7a574 100644 --- a/modules/engine/include/engine/debug/exceptions.hpp +++ b/modules/engine/include/engine/debug/exceptions.hpp @@ -11,22 +11,11 @@ namespace Light { -struct FailedAssertion: std::exception -{ - FailedAssertion(const char* file, int line); -}; - -// OpenGL -struct glException: std::exception -{ - glException(unsigned int source, unsigned int type, unsigned int id, const char* msg); -}; - #ifdef LIGHT_PLATFORM_WINDOWS // DirectX struct dxException: std::exception { - dxException(long hr, const char* file, int line); + dxException(long hr, const char *file, int line); }; #endif diff --git a/modules/engine/include/engine/debug/instrumentor.hpp b/modules/engine/include/engine/debug/instrumentor.hpp index 9bb6939..81deb7a 100644 --- a/modules/engine/include/engine/debug/instrumentor.hpp +++ b/modules/engine/include/engine/debug/instrumentor.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include + #include namespace Light { diff --git a/modules/engine/include/engine/engine.hpp b/modules/engine/include/engine/engine.hpp index 2658e31..16141e5 100644 --- a/modules/engine/include/engine/engine.hpp +++ b/modules/engine/include/engine/engine.hpp @@ -4,45 +4,24 @@ #include #include -// camera -#include - // debug #include -// events -#include -#include -#include -#include -#include - // graphics -#include -#include -#include -#include - -// input -#include -#include -#include +#include +#include +#include +#include // layer #include #include -// user interface -#include - -// utility -#include - // time #include // base -#include + // third party #include diff --git a/modules/engine/include/engine/layer/layer.hpp b/modules/engine/include/engine/layer/layer.hpp index 2f77b77..2255cdf 100644 --- a/modules/engine/include/engine/layer/layer.hpp +++ b/modules/engine/include/engine/layer/layer.hpp @@ -1,6 +1,6 @@ #pragma once -#include + namespace Light { diff --git a/modules/engine/include/engine/layer/layer_stack.hpp b/modules/engine/include/engine/layer/layer_stack.hpp index f7a575c..68ca755 100644 --- a/modules/engine/include/engine/layer/layer_stack.hpp +++ b/modules/engine/include/engine/layer/layer_stack.hpp @@ -1,6 +1,6 @@ #pragma once -#include + namespace Light { diff --git a/modules/engine/include/engine/platform/os/linux/l_window.hpp b/modules/engine/include/engine/os/linux/l_window.hpp similarity index 88% rename from modules/engine/include/engine/platform/os/linux/l_window.hpp rename to modules/engine/include/engine/os/linux/l_window.hpp index b40ba38..366013e 100644 --- a/modules/engine/include/engine/platform/os/linux/l_window.hpp +++ b/modules/engine/include/engine/os/linux/l_window.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include struct GLFWwindow; @@ -32,8 +31,13 @@ public: void set_visibility(bool visible, bool toggle = false) override; + [[nodiscard]] auto get_handle() -> void * override + { + return m_handle; + } + private: - GLFWwindow *m_handle{nullptr}; + GLFWwindow *m_handle { nullptr }; std::function m_event_callback; diff --git a/modules/engine/include/engine/platform/os/windows/w_window.cpp b/modules/engine/include/engine/os/windows/w_window.cpp similarity index 99% rename from modules/engine/include/engine/platform/os/windows/w_window.cpp rename to modules/engine/include/engine/os/windows/w_window.cpp index 1eae06f..c748592 100644 --- a/modules/engine/include/engine/platform/os/windows/w_window.cpp +++ b/modules/engine/include/engine/os/windows/w_window.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include extern "C" diff --git a/modules/engine/include/engine/platform/os/windows/w_window.hpp b/modules/engine/include/engine/os/windows/w_window.hpp similarity index 96% rename from modules/engine/include/engine/platform/os/windows/w_window.hpp rename to modules/engine/include/engine/os/windows/w_window.hpp index 7ac1c00..e3b1feb 100644 --- a/modules/engine/include/engine/platform/os/windows/w_window.hpp +++ b/modules/engine/include/engine/os/windows/w_window.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include struct GLFWwindow; diff --git a/modules/engine/include/engine/scene/components.hpp b/modules/engine/include/engine/scene/components.hpp index 0f20091..a9d5793 100644 --- a/modules/engine/include/engine/scene/components.hpp +++ b/modules/engine/include/engine/scene/components.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include #include #include diff --git a/modules/engine/include/engine/scene/components/camera.hpp b/modules/engine/include/engine/scene/components/camera.hpp index b8d805c..08d25da 100644 --- a/modules/engine/include/engine/scene/components/camera.hpp +++ b/modules/engine/include/engine/scene/components/camera.hpp @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include #include namespace Light { @@ -25,7 +24,7 @@ struct CameraComponent SceneCamera camera; - bool isPrimary{}; + bool isPrimary {}; }; } // namespace Light diff --git a/modules/engine/include/engine/scene/components/native_script.hpp b/modules/engine/include/engine/scene/components/native_script.hpp index 0be3aac..ab24b7f 100644 --- a/modules/engine/include/engine/scene/components/native_script.hpp +++ b/modules/engine/include/engine/scene/components/native_script.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include namespace Light { diff --git a/modules/engine/include/engine/scene/components/scriptable_entity.hpp b/modules/engine/include/engine/scene/components/scriptable_entity.hpp index 0da6670..bb4ed96 100644 --- a/modules/engine/include/engine/scene/components/scriptable_entity.hpp +++ b/modules/engine/include/engine/scene/components/scriptable_entity.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include namespace Light { diff --git a/modules/engine/include/engine/scene/components/sprite_renderer.hpp b/modules/engine/include/engine/scene/components/sprite_renderer.hpp index b06b69a..bb74463 100644 --- a/modules/engine/include/engine/scene/components/sprite_renderer.hpp +++ b/modules/engine/include/engine/scene/components/sprite_renderer.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include #include #include diff --git a/modules/engine/include/engine/scene/components/tag.hpp b/modules/engine/include/engine/scene/components/tag.hpp index 45cdf61..397307d 100644 --- a/modules/engine/include/engine/scene/components/tag.hpp +++ b/modules/engine/include/engine/scene/components/tag.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include namespace Light { diff --git a/modules/engine/include/engine/scene/components/transform.hpp b/modules/engine/include/engine/scene/components/transform.hpp index da18f28..b12a351 100644 --- a/modules/engine/include/engine/scene/components/transform.hpp +++ b/modules/engine/include/engine/scene/components/transform.hpp @@ -2,7 +2,7 @@ #define GLM_ENABLE_EXPERIMENTAL -#include + #include #include #include diff --git a/modules/engine/include/engine/scene/components/uuid.hpp b/modules/engine/include/engine/scene/components/uuid.hpp index 6eee4ef..c5ec786 100644 --- a/modules/engine/include/engine/scene/components/uuid.hpp +++ b/modules/engine/include/engine/scene/components/uuid.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include namespace Light { diff --git a/modules/engine/include/engine/scene/entity.hpp b/modules/engine/include/engine/scene/entity.hpp index e3ba30c..4c987fb 100644 --- a/modules/engine/include/engine/scene/entity.hpp +++ b/modules/engine/include/engine/scene/entity.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include #include #include diff --git a/modules/engine/include/engine/scene/scene.hpp b/modules/engine/include/engine/scene/scene.hpp index 01dc92a..2cecef7 100644 --- a/modules/engine/include/engine/scene/scene.hpp +++ b/modules/engine/include/engine/scene/scene.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include #include #include diff --git a/modules/engine/include/engine/time/timer.hpp b/modules/engine/include/engine/time/timer.hpp index 248307f..5a9097e 100644 --- a/modules/engine/include/engine/time/timer.hpp +++ b/modules/engine/include/engine/time/timer.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include + namespace Light { diff --git a/modules/engine/include/engine/utils/serializer.hpp b/modules/engine/include/engine/utils/serializer.hpp index f26e8df..baa2384 100644 --- a/modules/engine/include/engine/utils/serializer.hpp +++ b/modules/engine/include/engine/utils/serializer.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include #include #include diff --git a/modules/engine/include/engine/utils/stringifier.hpp b/modules/engine/include/engine/utils/stringifier.hpp index 750e139..d708192 100644 --- a/modules/engine/include/engine/utils/stringifier.hpp +++ b/modules/engine/include/engine/utils/stringifier.hpp @@ -2,7 +2,7 @@ #ifndef LIGHT_STRINGIFIER_H #define LIGHT_STRINGIFIER_H - #include + namespace Light { diff --git a/modules/engine/src/camera/camera.cpp b/modules/engine/src/camera/camera.cpp deleted file mode 100644 index 80744ec..0000000 --- a/modules/engine/src/camera/camera.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -namespace Light { - - -} diff --git a/modules/engine/src/core/application.cpp b/modules/engine/src/core/application.cpp index 1ec15e0..b16d5af 100644 --- a/modules/engine/src/core/application.cpp +++ b/modules/engine/src/core/application.cpp @@ -1,16 +1,19 @@ +#include #include #include #include -#include -#include -#include -#include -#include -#include #include #include -#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include namespace Light { @@ -26,6 +29,48 @@ Application::Application(): m_window(nullptr) Light::Instrumentor::begin_session("data/logs/profile_startup.json"); m_window = Window::create([this](auto &&PH1) { on_event(std::forward(PH1)); }); + + // create graphics context + m_graphics_context = GraphicsContext::create( + GraphicsAPI::OpenGL, + (GLFWwindow *)m_window->get_handle() + ); + + AssetManager::load_shader( + "LT_ENGINE_RESOURCES_TEXTURE_SHADER", + "data/assets/shaders/texture/vs.asset", + "data/assets/shaders/texture/ps.asset" + ); + + AssetManager::load_shader( + "LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER", + "data/assets/shaders/tinted_texture/vs.asset", + "data/assets/shaders/tinted_texture/ps.asset" + ); + + AssetManager::load_shader( + "LT_ENGINE_RESOURCES_QUAD_SHADER", + "data/assets/shaders/quads/vs.asset", + "data/assets/shaders/quads/ps.asset" + ); + + m_renderer = Renderer::create( + (GLFWwindow *)m_window->get_handle(), + m_graphics_context->get_shared_context(), + Renderer::CreateInfo { + .quad_renderer_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_QUAD_SHADER"), + .texture_renderer_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_TEXTURE_SHADER" + ), + .tinted_texture_renderer_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_TINTED_" + "TEXTURE_SHADER"), + } + ); + lt_assert(m_graphics_context, "lWindow::lWindow: failed to create 'GraphicsContext'"); + + m_user_interface = UserInterface::create( + (GLFWwindow *)m_window->get_handle(), + m_graphics_context->get_shared_context() + ); } Application::~Application() @@ -40,8 +85,8 @@ void Application::game_loop() lt_assert(!LayerStack::instance().is_empty(), "layer_stack is empty"); // log debug data - m_window->get_graphics_context()->log_debug_data(); - m_window->get_graphics_context()->get_user_interface()->log_debug_data(); + m_graphics_context->log_debug_data(); + m_user_interface->log_debug_data(); // reveal window m_window->set_visibility(true); @@ -69,27 +114,27 @@ void Application::game_loop() { // render layers lt_profile_scope("game_loop::Render"); - m_window->get_graphics_context()->get_renderer()->begin_frame(); + m_renderer->begin_frame(); for (auto &it : LayerStack::instance()) { it->on_render(); } - m_window->get_graphics_context()->get_renderer()->end_frame(); + m_renderer->end_frame(); } { // render user interface lt_profile_scope("game_loop::UserInterface"); - m_window->get_graphics_context()->get_user_interface()->begin(); + m_user_interface->begin(); for (auto &it : LayerStack::instance()) { it->on_user_interface_update(); } - m_window->get_graphics_context()->get_user_interface()->end(); + m_user_interface->end(); } { @@ -117,9 +162,7 @@ void Application::on_event(const Event &event) if (event.get_event_type() == EventType::WindowResized) { - m_window->get_graphics_context()->get_renderer()->on_window_resize( - dynamic_cast(event) - ); + m_renderer->on_window_resize(dynamic_cast(event)); } } diff --git a/modules/engine/src/graphics/graphics_context.cpp b/modules/engine/src/graphics/graphics_context.cpp deleted file mode 100644 index 9f3bd3c..0000000 --- a/modules/engine/src/graphics/graphics_context.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include - -#ifdef LIGHT_PLATFORM_WINDOWS - #include - #include -#endif - -#include // required for forward declaratio> -#include // required for forward declaratio> -#include // required for forward declaratio> -#include // required for forward declaratio> -#include // required for forward declaratio> -#include - -namespace Light { - -GraphicsContext *GraphicsContext::s_context = nullptr; - -GraphicsContext::~GraphicsContext() -= default; - -auto GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle) -> Scope -{ - // terminate 'GraphicsContext' dependent classes - if (s_context) - { - s_context->m_renderer.reset(); - s_context->m_user_interface.reset(); - - delete s_context; - } - - // determine the default api - if (api == GraphicsAPI::Default) - { -#if defined(LIGHT_PLATFORM_WINDOWS) - api = GraphicsAPI::DirectX; -#elif defined(LIGHT_PLATFORM_LINUX) - api = GraphicsAPI::OpenGL; -#elif defined(LIGHT_PLATFORM_MAC) - api = GraphicsAPI::OpenGL; -#endif - } - - // create gfx context - auto scope_gfx = Scope {}; - switch (api) - { - // opengl - case GraphicsAPI::OpenGL: - scope_gfx = create_scope(windowHandle); - s_context = scope_gfx.get(); - break; - // directx - case GraphicsAPI::DirectX: - lt_win(scope_gfx = create_scope(windowHandle); - s_context = scope_gfx.get(); - break;) - - default - : lt_assert( - false, - "Invalid/unsupported 'GraphicsAPI' {}", - Stringifier::graphics_api_to_string(api) - ); - return nullptr; - } - - // create 'GraphicsContext' dependent classes - s_context->m_user_interface = UserInterface::create(windowHandle, s_context->m_shared_context); - s_context->m_renderer = Renderer::create(windowHandle, s_context->m_shared_context); - - // check - lt_assert(s_context->m_user_interface, "Failed to create UserInterface"); - lt_assert(s_context->m_renderer, "Failed to create renderer"); - - return std::move(scope_gfx); -} - -} // namespace Light diff --git a/modules/engine/src/layer/layer.cpp b/modules/engine/src/layer/layer.cpp index 0c8698c..e80a3f2 100644 --- a/modules/engine/src/layer/layer.cpp +++ b/modules/engine/src/layer/layer.cpp @@ -1,9 +1,9 @@ -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include namespace Light { diff --git a/modules/engine/src/layer/layer_stack.cpp b/modules/engine/src/layer/layer_stack.cpp index 30c793f..1735435 100644 --- a/modules/engine/src/layer/layer_stack.cpp +++ b/modules/engine/src/layer/layer_stack.cpp @@ -1,9 +1,9 @@ -#include -#include -#include -#include #include #include +#include +#include +#include +#include namespace Light { diff --git a/modules/engine/src/platform/os/linux/l_window.cpp b/modules/engine/src/os/linux/l_window.cpp similarity index 76% rename from modules/engine/src/platform/os/linux/l_window.cpp rename to modules/engine/src/os/linux/l_window.cpp index 37c7056..7935de1 100644 --- a/modules/engine/src/platform/os/linux/l_window.cpp +++ b/modules/engine/src/os/linux/l_window.cpp @@ -1,24 +1,21 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace Light { -auto Window::create(const std::function& callback) -> Scope +auto Window::create(const std::function &callback) -> Scope { return create_scope(callback); } lWindow::lWindow(std::function callback) - : - m_event_callback(std::move(std::move(callback))) + : m_event_callback(std::move(std::move(callback))) { // init glfw lt_assert(glfwInit(), "lWindow::lWindow: failed to initialize 'glfw'"); @@ -35,10 +32,6 @@ lWindow::lWindow(std::function callback) // bind event stuff glfwSetWindowUserPointer(m_handle, &m_event_callback); bind_glfw_events(); - - // create graphics context - m_graphics_context = GraphicsContext::create(GraphicsAPI::OpenGL, m_handle); - lt_assert(m_graphics_context, "lWindow::lWindow: failed to create 'GraphicsContext'"); } lWindow::~lWindow() @@ -59,7 +52,9 @@ void lWindow::on_event(const Event &event) case EventType::WindowClosed: b_Closed = true; break; /* resized */ - case EventType::WindowResized: on_window_resize(dynamic_cast(event)); break; + case EventType::WindowResized: + on_window_resize(dynamic_cast(event)); + break; } } @@ -114,11 +109,14 @@ void lWindow::set_visibility(bool visible, bool toggle) { m_properties.visible = toggle ? !m_properties.visible : visible; - if (m_properties.visible) { + if (m_properties.visible) + { glfwShowWindow(m_handle); - } else { + } + else + { glfwHideWindow(m_handle); -} + } } void lWindow::bind_glfw_events() @@ -133,23 +131,26 @@ void lWindow::bind_glfw_events() callback(event); }); - glfwSetMouseButtonCallback(m_handle, [](GLFWwindow *window, int button, int action, int /*mods*/) { - std::function const callback = *(std::function *) - glfwGetWindowUserPointer(window); + glfwSetMouseButtonCallback( + m_handle, + [](GLFWwindow *window, int button, int action, int /*mods*/) { + std::function const callback = *(std::function *) + glfwGetWindowUserPointer(window); - if (action == GLFW_PRESS) - { - auto event = ButtonPressedEvent { button }; - callback(event); - } - else if (action == GLFW_RELEASE) - { - auto event = ButtonReleasedEvent { button }; - callback(event); - } - }); + if (action == GLFW_PRESS) + { + auto event = ButtonPressedEvent { button }; + callback(event); + } + else if (action == GLFW_RELEASE) + { + auto event = ButtonReleasedEvent { button }; + callback(event); + } + } + ); - glfwSetScrollCallback(m_handle, [](GLFWwindow *window, double /*xoffset*/, double yoffset) { + glfwSetScrollCallback(m_handle, [](GLFWwindow *window, double /*xoffset*/, double yoffset) { auto callback = *(std::function *)glfwGetWindowUserPointer(window); auto event = WheelScrolledEvent { static_cast(yoffset) }; @@ -158,7 +159,7 @@ void lWindow::bind_glfw_events() glfwSetKeyCallback( m_handle, - [](GLFWwindow *window, int key, int /*scancode*/, int action, int /*mods*/) { + [](GLFWwindow *window, int key, int /*scancode*/, int action, int /*mods*/) { auto callback = *(std::function *)glfwGetWindowUserPointer(window); if (action == GLFW_PRESS) diff --git a/modules/engine/src/platform/os/windows/w_window.cpp b/modules/engine/src/os/windows/w_window.cpp similarity index 99% rename from modules/engine/src/platform/os/windows/w_window.cpp rename to modules/engine/src/os/windows/w_window.cpp index 1eae06f..c748592 100644 --- a/modules/engine/src/platform/os/windows/w_window.cpp +++ b/modules/engine/src/os/windows/w_window.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include extern "C" diff --git a/modules/engine/src/platform/graphics/opengl/vertex_layout.cpp b/modules/engine/src/platform/graphics/opengl/vertex_layout.cpp deleted file mode 100644 index 2cba45f..0000000 --- a/modules/engine/src/platform/graphics/opengl/vertex_layout.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include -#include -#include - -namespace Light { - -glVertexLayout::glVertexLayout( - const Ref& buffer, - const std::vector> &elements -) - : m_array_id(NULL) -{ - // check - lt_assert( - std::dynamic_pointer_cast(buffer), - "Failed to cast 'VertexBuffer' to 'glVertexBuffer'" - ); - lt_assert(!elements.empty(), "'elements' is empty"); - - // local - auto elementsDesc = std::vector {}; - elementsDesc.reserve(elements.size()); - auto stride = 0u; - - // extract elements desc - for (const auto &element : elements) - { - elementsDesc.push_back(get_element_desc(element.second, stride)); - stride += elementsDesc.back().typeSize * elementsDesc.back().count; - } - - // create vertex array - glCreateVertexArrays(1, &m_array_id); - - // bind buffer and array - buffer->bind(); - bind(); - - // enable vertex attributes - auto index = 0u; - for (const auto &elementDesc : elementsDesc) - { - glVertexAttribPointer( - index, - elementDesc.count, - elementDesc.type, - GL_FALSE, - stride, - (const void *)elementDesc.offset - ); - glEnableVertexAttribArray(index++); - } -} - -glVertexLayout::~glVertexLayout() -{ - glDeleteVertexArrays(1, &m_array_id); -} - -void glVertexLayout::bind() -{ - glBindVertexArray(m_array_id); -} - -void glVertexLayout::un_bind() -{ - glBindVertexArray(NULL); -} - -auto glVertexLayout::get_element_desc(VertexElementType type, unsigned int offset) - -> glVertexElementDesc -{ - switch (type) - { - /* byte */ - case Light::VertexElementType::Byte1: return { .type=GL_BYTE, .count=1u, .typeSize=sizeof(GLbyte), .offset=offset }; - case Light::VertexElementType::Byte2: return { .type=GL_BYTE, .count=1u, .typeSize=sizeof(GLbyte), .offset=offset }; - case Light::VertexElementType::Byte4: return { .type=GL_BYTE, .count=1u, .typeSize=sizeof(GLbyte), .offset=offset }; - - /* ubyte */ - case Light::VertexElementType::UByte1: return { .type=GL_UNSIGNED_BYTE, .count=1u, .typeSize=sizeof(GLubyte), .offset=offset }; - case Light::VertexElementType::UByte2: return { .type=GL_UNSIGNED_BYTE, .count=2u, .typeSize=sizeof(GLubyte), .offset=offset }; - case Light::VertexElementType::UByte4: return { .type=GL_UNSIGNED_BYTE, .count=4u, .typeSize=sizeof(GLubyte), .offset=offset }; - - /* int */ - case VertexElementType::Int1: return { .type=GL_INT, .count=1u, .typeSize=sizeof(GLint), .offset=offset }; - case VertexElementType::Int2: return { .type=GL_INT, .count=2u, .typeSize=sizeof(GLint), .offset=offset }; - case VertexElementType::Int3: return { .type=GL_INT, .count=3u, .typeSize=sizeof(GLint), .offset=offset }; - case VertexElementType::Int4: return { .type=GL_INT, .count=4u, .typeSize=sizeof(GLint), .offset=offset }; - - /* uint */ - case VertexElementType::UInt1: return { .type=GL_UNSIGNED_INT, .count=1u, .typeSize=sizeof(GLuint), .offset=offset }; - case VertexElementType::UInt2: return { .type=GL_UNSIGNED_INT, .count=2u, .typeSize=sizeof(GLuint), .offset=offset }; - case VertexElementType::UInt3: return { .type=GL_UNSIGNED_INT, .count=3u, .typeSize=sizeof(GLuint), .offset=offset }; - case VertexElementType::UInt4: return { .type=GL_UNSIGNED_INT, .count=4u, .typeSize=sizeof(GLuint), .offset=offset }; - - /* float */ - case VertexElementType::Float1: return { .type=GL_FLOAT, .count=1u, .typeSize=sizeof(GLfloat), .offset=offset }; - case VertexElementType::Float2: return { .type=GL_FLOAT, .count=2u, .typeSize=sizeof(GLfloat), .offset=offset }; - case VertexElementType::Float3: return { .type=GL_FLOAT, .count=3u, .typeSize=sizeof(GLfloat), .offset=offset }; - case VertexElementType::Float4: return { .type=GL_FLOAT, .count=4u, .typeSize=sizeof(GLfloat), .offset=offset }; - - default: lt_assert(false, "Invalid 'VertexElementType'"); return {}; - } -} - -} // namespace Light diff --git a/modules/engine/src/scene/scene.cpp b/modules/engine/src/scene/scene.cpp index 0fe8e24..ab362e6 100644 --- a/modules/engine/src/scene/scene.cpp +++ b/modules/engine/src/scene/scene.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/modules/engine/src/utils/serializer.cpp b/modules/engine/src/utils/serializer.cpp index a5c9c2f..8072ee0 100644 --- a/modules/engine/src/utils/serializer.cpp +++ b/modules/engine/src/utils/serializer.cpp @@ -1,6 +1,6 @@ -#include +#include #include -#include +#include #include namespace YAML { @@ -173,11 +173,11 @@ auto SceneSerializer::deserialize(const std::string &file_path) -> bool if (!texturePaths.contains(texturePath)) { - ResourceManager::load_texture(texturePath, texturePath); + AssetManager::load_texture(texturePath, texturePath); texturePaths.insert(texturePath); } - entitySpriteRendererComponent.texture = ResourceManager::get_texture(texturePath); + entitySpriteRendererComponent.texture = AssetManager::get_texture(texturePath); } /* #TEMPORARY SOLUTION# */ diff --git a/modules/engine/src/utils/stringifier.cpp b/modules/engine/src/utils/stringifier.cpp index 0c0abe3..92c3a92 100644 --- a/modules/engine/src/utils/stringifier.cpp +++ b/modules/engine/src/utils/stringifier.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/modules/input/CMakeLists.txt b/modules/input/CMakeLists.txt new file mode 100644 index 0000000..1ece084 --- /dev/null +++ b/modules/input/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library_module(input input.cpp) +target_link_libraries(input PUBLIC spdlog::spdlog glm::glm imgui logger) diff --git a/modules/engine/include/engine/events/char.hpp b/modules/input/include/input/events/char.hpp similarity index 89% rename from modules/engine/include/engine/events/char.hpp rename to modules/input/include/input/events/char.hpp index d530118..2a4f788 100644 --- a/modules/engine/include/engine/events/char.hpp +++ b/modules/input/include/input/events/char.hpp @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include #include namespace Light { diff --git a/modules/engine/include/engine/events/event.hpp b/modules/input/include/input/events/event.hpp similarity index 97% rename from modules/engine/include/engine/events/event.hpp rename to modules/input/include/input/events/event.hpp index edd957b..9df04ca 100644 --- a/modules/engine/include/engine/events/event.hpp +++ b/modules/input/include/input/events/event.hpp @@ -1,7 +1,5 @@ #pragma once -#include - namespace Light { enum class EventType diff --git a/modules/engine/include/engine/events/keyboard.hpp b/modules/input/include/input/events/keyboard.hpp similarity index 95% rename from modules/engine/include/engine/events/keyboard.hpp rename to modules/input/include/input/events/keyboard.hpp index 3e2385d..0393cc6 100644 --- a/modules/engine/include/engine/events/keyboard.hpp +++ b/modules/input/include/input/events/keyboard.hpp @@ -1,7 +1,6 @@ #pragma once -#include -#include +#include #include namespace Light { diff --git a/modules/engine/include/engine/events/mouse.hpp b/modules/input/include/input/events/mouse.hpp similarity index 96% rename from modules/engine/include/engine/events/mouse.hpp rename to modules/input/include/input/events/mouse.hpp index a112f73..c4c4f9a 100644 --- a/modules/engine/include/engine/events/mouse.hpp +++ b/modules/input/include/input/events/mouse.hpp @@ -1,8 +1,7 @@ #pragma once -#include -#include #include +#include #include namespace Light { diff --git a/modules/engine/include/engine/events/window.hpp b/modules/input/include/input/events/window.hpp similarity index 96% rename from modules/engine/include/engine/events/window.hpp rename to modules/input/include/input/events/window.hpp index 91547b0..fdefaaa 100644 --- a/modules/engine/include/engine/events/window.hpp +++ b/modules/input/include/input/events/window.hpp @@ -1,8 +1,7 @@ #pragma once -#include -#include #include +#include #include namespace Light { diff --git a/modules/engine/include/engine/input/input.hpp b/modules/input/include/input/input.hpp similarity index 97% rename from modules/engine/include/engine/input/input.hpp rename to modules/input/include/input/input.hpp index c638e94..2db46ce 100644 --- a/modules/engine/include/engine/input/input.hpp +++ b/modules/input/include/input/input.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include namespace Light { diff --git a/modules/engine/include/engine/input/key_codes.hpp b/modules/input/include/input/key_codes.hpp similarity index 99% rename from modules/engine/include/engine/input/key_codes.hpp rename to modules/input/include/input/key_codes.hpp index ce6e247..da80e78 100644 --- a/modules/engine/include/engine/input/key_codes.hpp +++ b/modules/input/include/input/key_codes.hpp @@ -1,10 +1,9 @@ #pragma once -#include - - +#include namespace Light::Key { + enum : uint16_t { /* digits */ @@ -177,6 +176,5 @@ enum : uint16_t Menu = 348, }; + } - - diff --git a/modules/engine/include/engine/input/mouse_codes.hpp b/modules/input/include/input/mouse_codes.hpp similarity index 91% rename from modules/engine/include/engine/input/mouse_codes.hpp rename to modules/input/include/input/mouse_codes.hpp index 01d00d5..18f284f 100644 --- a/modules/engine/include/engine/input/mouse_codes.hpp +++ b/modules/input/include/input/mouse_codes.hpp @@ -1,10 +1,9 @@ #pragma once -#include - - +#include namespace Light::Mouse { + enum : uint8_t { Button1 = 0, @@ -20,6 +19,5 @@ enum : uint8_t RButton = Button2, MButton = Button3, }; + } - - diff --git a/modules/engine/src/input/input.cpp b/modules/input/src/input.cpp similarity index 93% rename from modules/engine/src/input/input.cpp rename to modules/input/src/input.cpp index 4b1ac41..f800512 100644 --- a/modules/engine/src/input/input.cpp +++ b/modules/input/src/input.cpp @@ -1,10 +1,11 @@ -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include +#include namespace Light { diff --git a/modules/mirror/CMakeLists.txt b/modules/mirror/CMakeLists.txt index a5e367c..6e85429 100644 --- a/modules/mirror/CMakeLists.txt +++ b/modules/mirror/CMakeLists.txt @@ -10,5 +10,7 @@ target_link_libraries( mirror PUBLIC engine PUBLIC opengl::opengl + PUBLIC ui PUBLIC imgui + PUBLIC input ) diff --git a/modules/mirror/include/mirror/panel/scene_hierarchy.hpp b/modules/mirror/include/mirror/panel/scene_hierarchy.hpp index 0d4a8c2..3da6e70 100644 --- a/modules/mirror/include/mirror/panel/scene_hierarchy.hpp +++ b/modules/mirror/include/mirror/panel/scene_hierarchy.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include #include #include diff --git a/modules/mirror/src/editor_layer.cpp b/modules/mirror/src/editor_layer.cpp index d623013..9676a5f 100644 --- a/modules/mirror/src/editor_layer.cpp +++ b/modules/mirror/src/editor_layer.cpp @@ -1,5 +1,8 @@ +#include #include +#include #include +#include namespace Light { @@ -28,11 +31,11 @@ EditorLayer::EditorLayer(const std::string &name) m_camera_entity = m_scene->create_entity("Camera"); m_camera_entity.add_component(SceneCamera(), true); - ResourceManager::load_texture("Awesomeface", "data/assets/textures/awesomeface.asset"); + AssetManager::load_texture("Awesomeface", "data/assets/textures/awesomeface.asset"); auto entity = Entity { m_scene->create_entity("Awesomeface", {}) }; entity.add_component( - ResourceManager::get_texture("Awesomeface"), + AssetManager::get_texture("Awesomeface"), glm::vec4 { 0.0f, 1.0f, 1.0f, 1.0f } ); } diff --git a/modules/mirror/src/panel/asset_browser.cpp b/modules/mirror/src/panel/asset_browser.cpp index 7656263..ec5e2fd 100644 --- a/modules/mirror/src/panel/asset_browser.cpp +++ b/modules/mirror/src/panel/asset_browser.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -10,15 +11,15 @@ AssetBrowserPanel::AssetBrowserPanel(Ref active_scene) , m_assets_path("./data/assets") , m_active_scene(std::move(active_scene)) { - ResourceManager::load_texture("_Assets_Directory", "data/engine/icons/asset/dir.asset"); - ResourceManager::load_texture("_Assets_Scene", "data/engine/icons/asset/scene.asset"); - ResourceManager::load_texture("_Assets_Image", "data/engine/icons/asset/img.asset"); - ResourceManager::load_texture("_Assets_Text", "data/engine/icons/asset/txt.asset"); + AssetManager::load_texture("_Assets_Directory", "data/engine/icons/asset/dir.asset"); + AssetManager::load_texture("_Assets_Scene", "data/engine/icons/asset/scene.asset"); + AssetManager::load_texture("_Assets_Image", "data/engine/icons/asset/img.asset"); + AssetManager::load_texture("_Assets_Text", "data/engine/icons/asset/txt.asset"); - m_directory_texture = ResourceManager::get_texture("_Assets_Directory"); - m_scene_texture = ResourceManager::get_texture("_Assets_Scene"); - m_image_texture = ResourceManager::get_texture("_Assets_Image"); - m_text_texture = ResourceManager::get_texture("_Assets_Text"); + m_directory_texture = AssetManager::get_texture("_Assets_Directory"); + m_scene_texture = AssetManager::get_texture("_Assets_Scene"); + m_image_texture = AssetManager::get_texture("_Assets_Image"); + m_text_texture = AssetManager::get_texture("_Assets_Text"); } void AssetBrowserPanel::on_user_interface_update() diff --git a/modules/mirror/src/panel/properties.cpp b/modules/mirror/src/panel/properties.cpp index 16a83b2..f2b24ae 100644 --- a/modules/mirror/src/panel/properties.cpp +++ b/modules/mirror/src/panel/properties.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -47,7 +47,7 @@ void PropertiesPanel::on_user_interface_update() )) { m_entity_context.add_component( - Light::ResourceManager::get_texture("awesomeface") + Light::AssetManager::get_texture("awesomeface") ); } diff --git a/modules/renderer/CMakeLists.txt b/modules/renderer/CMakeLists.txt new file mode 100644 index 0000000..cf41490 --- /dev/null +++ b/modules/renderer/CMakeLists.txt @@ -0,0 +1,37 @@ +add_library_module(renderer + blender.cpp + buffers.cpp + framebuffer.cpp + graphics_context.cpp + render_command.cpp + renderer.cpp + renderer_programs/quad.cpp + renderer_programs/texture.cpp + renderer_programs/tinted_texture.cpp + shader.cpp + texture.cpp + vertex_layout.cpp + gl/blender.cpp + gl/buffers.cpp + gl/framebuffers.cpp + gl/graphics_context.cpp + gl/render_command.cpp + gl/shader.cpp + gl/texture.cpp + gl/vertex_layout.cpp +) + +target_link_libraries( + renderer + PUBLIC camera + PUBLIC input + PUBLIC glad + PUBLIC logger + PUBLIC opengl::opengl + PUBLIC glfw + PUBLIC imgui + PUBLIC asset_parser + PUBLIC yaml-cpp::yaml-cpp + PUBLIC EnTT::EnTT + PRIVATE lt_debug +) diff --git a/modules/engine/include/engine/graphics/blender.hpp b/modules/renderer/include/renderer/blender.hpp similarity index 95% rename from modules/engine/include/engine/graphics/blender.hpp rename to modules/renderer/include/renderer/blender.hpp index 3dd8d5d..a761fb0 100644 --- a/modules/engine/include/engine/graphics/blender.hpp +++ b/modules/renderer/include/renderer/blender.hpp @@ -1,6 +1,6 @@ #pragma once -#include + namespace Light { diff --git a/modules/engine/include/engine/graphics/buffers.hpp b/modules/renderer/include/renderer/buffers.hpp similarity index 97% rename from modules/engine/include/engine/graphics/buffers.hpp rename to modules/renderer/include/renderer/buffers.hpp index eff7243..318a4ca 100644 --- a/modules/engine/include/engine/graphics/buffers.hpp +++ b/modules/renderer/include/renderer/buffers.hpp @@ -1,6 +1,6 @@ #pragma once -#include + namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/directx/blender.hpp b/modules/renderer/include/renderer/dx/blender.hpp similarity index 87% rename from modules/engine/include/engine/platform/graphics/directx/blender.hpp rename to modules/renderer/include/renderer/dx/blender.hpp index 54f3313..c99de0a 100644 --- a/modules/engine/include/engine/platform/graphics/directx/blender.hpp +++ b/modules/renderer/include/renderer/dx/blender.hpp @@ -1,8 +1,7 @@ #pragma once #include -#include -#include +#include #include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/directx/buffers.hpp b/modules/renderer/include/renderer/dx/buffers.hpp similarity index 94% rename from modules/engine/include/engine/platform/graphics/directx/buffers.hpp rename to modules/renderer/include/renderer/dx/buffers.hpp index c53c98c..e36ba0c 100644 --- a/modules/engine/include/engine/platform/graphics/directx/buffers.hpp +++ b/modules/renderer/include/renderer/dx/buffers.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include + +#include #include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp b/modules/renderer/include/renderer/dx/framebuffers.hpp similarity index 92% rename from modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp rename to modules/renderer/include/renderer/dx/framebuffers.hpp index 097d2a0..b0380d9 100644 --- a/modules/engine/include/engine/platform/graphics/directx/framebuffers.hpp +++ b/modules/renderer/include/renderer/dx/framebuffers.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include + +#include #include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/directx/graphics_context.hpp b/modules/renderer/include/renderer/dx/graphics_context.hpp similarity index 85% rename from modules/engine/include/engine/platform/graphics/directx/graphics_context.hpp rename to modules/renderer/include/renderer/dx/graphics_context.hpp index da7a9f7..35c3dca 100644 --- a/modules/engine/include/engine/platform/graphics/directx/graphics_context.hpp +++ b/modules/renderer/include/renderer/dx/graphics_context.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include + +#include #include struct GLFWwindow; diff --git a/modules/engine/include/engine/platform/graphics/directx/render_command.hpp b/modules/renderer/include/renderer/dx/render_command.hpp similarity index 90% rename from modules/engine/include/engine/platform/graphics/directx/render_command.hpp rename to modules/renderer/include/renderer/dx/render_command.hpp index ca14789..b9a08da 100644 --- a/modules/engine/include/engine/platform/graphics/directx/render_command.hpp +++ b/modules/renderer/include/renderer/dx/render_command.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include + +#include #include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/directx/shader.hpp b/modules/renderer/include/renderer/dx/shader.hpp similarity index 90% rename from modules/engine/include/engine/platform/graphics/directx/shader.hpp rename to modules/renderer/include/renderer/dx/shader.hpp index 8b236a1..a0cf2e8 100644 --- a/modules/engine/include/engine/platform/graphics/directx/shader.hpp +++ b/modules/renderer/include/renderer/dx/shader.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include + +#include #include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp b/modules/renderer/include/renderer/dx/shared_context.hpp similarity index 94% rename from modules/engine/include/engine/platform/graphics/directx/shared_context.hpp rename to modules/renderer/include/renderer/dx/shared_context.hpp index 9c41a31..503759b 100644 --- a/modules/engine/include/engine/platform/graphics/directx/shared_context.hpp +++ b/modules/renderer/include/renderer/dx/shared_context.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include + +#include #include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/directx/texture.hpp b/modules/renderer/include/renderer/dx/texture.hpp similarity index 90% rename from modules/engine/include/engine/platform/graphics/directx/texture.hpp rename to modules/renderer/include/renderer/dx/texture.hpp index f708926..f4d6f18 100644 --- a/modules/engine/include/engine/platform/graphics/directx/texture.hpp +++ b/modules/renderer/include/renderer/dx/texture.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include + +#include #include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/directx/user_interface.hpp b/modules/renderer/include/renderer/dx/user_interface.hpp similarity index 83% rename from modules/engine/include/engine/platform/graphics/directx/user_interface.hpp rename to modules/renderer/include/renderer/dx/user_interface.hpp index ba6ba41..5ca3a64 100644 --- a/modules/engine/include/engine/platform/graphics/directx/user_interface.hpp +++ b/modules/renderer/include/renderer/dx/user_interface.hpp @@ -1,8 +1,7 @@ #pragma once #include -#include -#include +#include #include struct GLFWwindow; diff --git a/modules/engine/include/engine/platform/graphics/directx/vertex_layout.hpp b/modules/renderer/include/renderer/dx/vertex_layout.hpp similarity index 88% rename from modules/engine/include/engine/platform/graphics/directx/vertex_layout.hpp rename to modules/renderer/include/renderer/dx/vertex_layout.hpp index c2b91d8..6cb7252 100644 --- a/modules/engine/include/engine/platform/graphics/directx/vertex_layout.hpp +++ b/modules/renderer/include/renderer/dx/vertex_layout.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include -#include + +#include #include namespace Light { diff --git a/modules/engine/include/engine/graphics/framebuffer.hpp b/modules/renderer/include/renderer/framebuffer.hpp similarity index 95% rename from modules/engine/include/engine/graphics/framebuffer.hpp rename to modules/renderer/include/renderer/framebuffer.hpp index 695a62a..13b82d6 100644 --- a/modules/engine/include/engine/graphics/framebuffer.hpp +++ b/modules/renderer/include/renderer/framebuffer.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/opengl/blender.hpp b/modules/renderer/include/renderer/gl/blender.hpp similarity index 81% rename from modules/engine/include/engine/platform/graphics/opengl/blender.hpp rename to modules/renderer/include/renderer/gl/blender.hpp index ebf412d..e99531f 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/blender.hpp +++ b/modules/renderer/include/renderer/gl/blender.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp b/modules/renderer/include/renderer/gl/buffers.hpp similarity index 92% rename from modules/engine/include/engine/platform/graphics/opengl/buffers.hpp rename to modules/renderer/include/renderer/gl/buffers.hpp index cb83c89..a7a1fdb 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/buffers.hpp +++ b/modules/renderer/include/renderer/gl/buffers.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp b/modules/renderer/include/renderer/gl/framebuffers.hpp similarity index 88% rename from modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp rename to modules/renderer/include/renderer/gl/framebuffers.hpp index 0866204..f4a150c 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/framebuffers.hpp +++ b/modules/renderer/include/renderer/gl/framebuffers.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/opengl/graphics_context.hpp b/modules/renderer/include/renderer/gl/graphics_context.hpp similarity index 78% rename from modules/engine/include/engine/platform/graphics/opengl/graphics_context.hpp rename to modules/renderer/include/renderer/gl/graphics_context.hpp index 70eb8e7..720701d 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/graphics_context.hpp +++ b/modules/renderer/include/renderer/gl/graphics_context.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include struct GLFWwindow; diff --git a/modules/engine/include/engine/platform/graphics/opengl/render_command.hpp b/modules/renderer/include/renderer/gl/render_command.hpp similarity index 87% rename from modules/engine/include/engine/platform/graphics/opengl/render_command.hpp rename to modules/renderer/include/renderer/gl/render_command.hpp index 74fa34b..ce66cef 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/render_command.hpp +++ b/modules/renderer/include/renderer/gl/render_command.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include struct GLFWwindow; diff --git a/modules/engine/include/engine/platform/graphics/opengl/shader.hpp b/modules/renderer/include/renderer/gl/shader.hpp similarity index 83% rename from modules/engine/include/engine/platform/graphics/opengl/shader.hpp rename to modules/renderer/include/renderer/gl/shader.hpp index a214306..3791081 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/shader.hpp +++ b/modules/renderer/include/renderer/gl/shader.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/opengl/shared_context.hpp b/modules/renderer/include/renderer/gl/shared_context.hpp similarity index 57% rename from modules/engine/include/engine/platform/graphics/opengl/shared_context.hpp rename to modules/renderer/include/renderer/gl/shared_context.hpp index c4c1c0e..420bbbc 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/shared_context.hpp +++ b/modules/renderer/include/renderer/gl/shared_context.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/opengl/texture.hpp b/modules/renderer/include/renderer/gl/texture.hpp similarity index 85% rename from modules/engine/include/engine/platform/graphics/opengl/texture.hpp rename to modules/renderer/include/renderer/gl/texture.hpp index 2571b79..c8f8b72 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/texture.hpp +++ b/modules/renderer/include/renderer/gl/texture.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include namespace Light { diff --git a/modules/engine/include/engine/platform/graphics/opengl/user_interface.hpp b/modules/renderer/include/renderer/gl/user_interface.hpp similarity index 77% rename from modules/engine/include/engine/platform/graphics/opengl/user_interface.hpp rename to modules/renderer/include/renderer/gl/user_interface.hpp index 0a17c16..63a7adf 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/user_interface.hpp +++ b/modules/renderer/include/renderer/gl/user_interface.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include struct GLFWwindow; @@ -24,7 +24,7 @@ public: void log_debug_data() override; private: - GLFWwindow *m_window_handle{}; + GLFWwindow *m_window_handle {}; }; } // namespace Light diff --git a/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp b/modules/renderer/include/renderer/gl/vertex_layout.hpp similarity index 88% rename from modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp rename to modules/renderer/include/renderer/gl/vertex_layout.hpp index c662719..6b1ee9c 100644 --- a/modules/engine/include/engine/platform/graphics/opengl/vertex_layout.hpp +++ b/modules/renderer/include/renderer/gl/vertex_layout.hpp @@ -1,7 +1,7 @@ #pragma once -#include -#include + +#include namespace Light { diff --git a/modules/engine/include/engine/graphics/graphics_context.hpp b/modules/renderer/include/renderer/graphics_context.hpp similarity index 65% rename from modules/engine/include/engine/graphics/graphics_context.hpp rename to modules/renderer/include/renderer/graphics_context.hpp index 22c8a14..e177728 100644 --- a/modules/engine/include/engine/graphics/graphics_context.hpp +++ b/modules/renderer/include/renderer/graphics_context.hpp @@ -1,15 +1,10 @@ #pragma once -#include - struct GLFWwindow; namespace Light { -class Renderer; -class resource_manager; class SharedContext; -class UserInterface; class WindowResizedEvent; enum class GraphicsAPI @@ -24,7 +19,11 @@ enum class GraphicsAPI class GraphicsContext { public: - static auto create(GraphicsAPI api, GLFWwindow *windowHandle) -> Scope; + static auto create( + GraphicsAPI api, + GLFWwindow *window_handle + + ) -> Scope; GraphicsContext(const GraphicsContext &) = delete; @@ -44,16 +43,6 @@ public: return s_context->m_shared_context; } - auto get_renderer() -> Renderer * - { - return m_renderer.get(); - } - - auto get_user_interface() -> UserInterface * - { - return m_user_interface.get(); - } - protected: GraphicsContext() = default; @@ -63,10 +52,6 @@ protected: private: static GraphicsContext *s_context; - - Scope m_user_interface; - - Scope m_renderer; }; } // namespace Light diff --git a/modules/engine/include/engine/graphics/render_command.hpp b/modules/renderer/include/renderer/render_command.hpp similarity index 96% rename from modules/engine/include/engine/graphics/render_command.hpp rename to modules/renderer/include/renderer/render_command.hpp index 3bce766..cc48bd1 100644 --- a/modules/engine/include/engine/graphics/render_command.hpp +++ b/modules/renderer/include/renderer/render_command.hpp @@ -1,6 +1,6 @@ #pragma once -#include + #include struct GLFWwindow; diff --git a/modules/engine/include/engine/graphics/renderer.hpp b/modules/renderer/include/renderer/renderer.hpp similarity index 81% rename from modules/engine/include/engine/graphics/renderer.hpp rename to modules/renderer/include/renderer/renderer.hpp index 1970296..9f42a18 100644 --- a/modules/engine/include/engine/graphics/renderer.hpp +++ b/modules/renderer/include/renderer/renderer.hpp @@ -1,9 +1,15 @@ #pragma once -#include -#include -#include -#include +// +#include +#include +#include +#include +/// + +#include +#include +#include #include #define LT_MAX_QUAD_RENDERER_VERTICES (1028u * 4u) @@ -14,7 +20,6 @@ struct GLFWwindow; namespace Light { -class Blender; class ConstantBuffer; class Framebuffer; class RenderCommand; @@ -22,12 +27,25 @@ class Texture; class SharedContext; class Camera; class WindowResizedEvent; +class Shader; class Renderer { public: - static auto create(GLFWwindow *windowHandle, Ref sharedContext) - -> Scope; + struct CreateInfo + { + Ref quad_renderer_shader; + + Ref texture_renderer_shader; + + Ref tinted_texture_renderer_shader; + }; + + static auto create( + GLFWwindow *window_handle, + Ref shared_context, + CreateInfo create_info + ) -> Scope; static void draw_quad( const glm::vec3 &position, @@ -105,7 +123,7 @@ private: bool m_should_clear_backbuffer { false }; - Renderer(GLFWwindow *windowHandle, const Ref &sharedContext); + Renderer(GLFWwindow *windowHandle, Ref sharedContext, CreateInfo create_info); void draw_quad_impl( const glm::vec3 &position, diff --git a/modules/engine/include/engine/graphics/renderer_programs/quad.hpp b/modules/renderer/include/renderer/renderer_programs/quad.hpp similarity index 83% rename from modules/engine/include/engine/graphics/renderer_programs/quad.hpp rename to modules/renderer/include/renderer/renderer_programs/quad.hpp index 7d96653..c177821 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/quad.hpp +++ b/modules/renderer/include/renderer/renderer_programs/quad.hpp @@ -1,8 +1,7 @@ #pragma once -#include -#include #include +#include namespace Light { @@ -12,6 +11,7 @@ class IndexBuffer; class VertexLayout; class OrthographicCamera; class SharedContext; +class Shader; class QuadRendererProgram: RendererProgram { @@ -24,7 +24,11 @@ public: glm::vec4 tint; }; - QuadRendererProgram(unsigned int maxVertices, const Ref &sharedContext); + QuadRendererProgram( + unsigned int maxVertices, + const Ref &shared_context, + Ref shader + ); auto advance() -> bool; diff --git a/modules/engine/include/engine/graphics/renderer_programs/renderer_program.hpp b/modules/renderer/include/renderer/renderer_programs/renderer_program.hpp similarity index 63% rename from modules/engine/include/engine/graphics/renderer_programs/renderer_program.hpp rename to modules/renderer/include/renderer/renderer_programs/renderer_program.hpp index fe674f4..6a80a87 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/renderer_program.hpp +++ b/modules/renderer/include/renderer/renderer_programs/renderer_program.hpp @@ -1,11 +1,7 @@ #pragma once -#include - namespace Light { -class OrthographicCamera; - class RendererProgram { virtual void map() = 0; @@ -13,8 +9,9 @@ class RendererProgram virtual void un_map() = 0; virtual void bind() = 0; + public: -virtual ~RendererProgram() = default; + virtual ~RendererProgram() = default; }; } // namespace Light diff --git a/modules/engine/include/engine/graphics/renderer_programs/texture.hpp b/modules/renderer/include/renderer/renderer_programs/texture.hpp similarity index 84% rename from modules/engine/include/engine/graphics/renderer_programs/texture.hpp rename to modules/renderer/include/renderer/renderer_programs/texture.hpp index d12c044..3d4a315 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/texture.hpp +++ b/modules/renderer/include/renderer/renderer_programs/texture.hpp @@ -1,8 +1,7 @@ #pragma once -#include -#include #include +#include namespace Light { @@ -25,7 +24,11 @@ public: glm::vec2 texcoord; }; - TextureRendererProgram(unsigned int maxVertices, const Ref &sharedContext); + TextureRendererProgram( + unsigned int maxVertices, + const Ref &shared_context, + Ref shader + ); auto advance() -> bool; diff --git a/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp b/modules/renderer/include/renderer/renderer_programs/tinted_texture.hpp similarity index 84% rename from modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp rename to modules/renderer/include/renderer/renderer_programs/tinted_texture.hpp index 3a8a1bb..ead57b4 100644 --- a/modules/engine/include/engine/graphics/renderer_programs/tinted_texture.hpp +++ b/modules/renderer/include/renderer/renderer_programs/tinted_texture.hpp @@ -1,8 +1,7 @@ #pragma once -#include -#include #include +#include namespace Light { @@ -26,7 +25,11 @@ public: glm::vec2 texcoord; }; - TintedTextureRendererProgram(unsigned int maxVertices, const Ref &sharedContext); + TintedTextureRendererProgram( + unsigned int maxVertices, + const Ref &sharedContext, + Ref shader + ); auto advance() -> bool; diff --git a/modules/engine/include/engine/graphics/shader.hpp b/modules/renderer/include/renderer/shader.hpp similarity index 93% rename from modules/engine/include/engine/graphics/shader.hpp rename to modules/renderer/include/renderer/shader.hpp index 00194d3..8e43e5f 100644 --- a/modules/engine/include/engine/graphics/shader.hpp +++ b/modules/renderer/include/renderer/shader.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include + #include namespace Light { diff --git a/modules/engine/include/engine/graphics/shared_context.hpp b/modules/renderer/include/renderer/shared_context.hpp similarity index 79% rename from modules/engine/include/engine/graphics/shared_context.hpp rename to modules/renderer/include/renderer/shared_context.hpp index 53a3d83..6dec168 100644 --- a/modules/engine/include/engine/graphics/shared_context.hpp +++ b/modules/renderer/include/renderer/shared_context.hpp @@ -1,6 +1,6 @@ #pragma once -#include + namespace Light { diff --git a/modules/engine/include/engine/graphics/texture.hpp b/modules/renderer/include/renderer/texture.hpp similarity index 95% rename from modules/engine/include/engine/graphics/texture.hpp rename to modules/renderer/include/renderer/texture.hpp index 9d9ef75..83d7e87 100644 --- a/modules/engine/include/engine/graphics/texture.hpp +++ b/modules/renderer/include/renderer/texture.hpp @@ -1,6 +1,6 @@ #pragma once -#include + namespace Light { diff --git a/modules/engine/include/engine/graphics/vertex_layout.hpp b/modules/renderer/include/renderer/vertex_layout.hpp similarity index 78% rename from modules/engine/include/engine/graphics/vertex_layout.hpp rename to modules/renderer/include/renderer/vertex_layout.hpp index be55c94..b8f993c 100644 --- a/modules/engine/include/engine/graphics/vertex_layout.hpp +++ b/modules/renderer/include/renderer/vertex_layout.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace Light { @@ -34,10 +34,10 @@ class VertexLayout { public: static auto create( - const Ref& vertexBuffer, - const Ref& shader, + const Ref &vertexBuffer, + const Ref &shader, const std::vector> &elements, - const Ref& sharedContext + const Ref &sharedContext ) -> Ref; virtual ~VertexLayout() = default; diff --git a/modules/engine/src/graphics/blender.cpp b/modules/renderer/src/blender.cpp similarity index 63% rename from modules/engine/src/graphics/blender.cpp rename to modules/renderer/src/blender.cpp index b17f9a8..3e2a99f 100644 --- a/modules/engine/src/graphics/blender.cpp +++ b/modules/renderer/src/blender.cpp @@ -1,16 +1,16 @@ -#include -#include +#include +#include #ifdef LIGHT_PLATFORM_WINDOWS - #include - #include + #include + #include #endif -#include +#include namespace Light { -auto Blender::create(const Ref& /*sharedContext*/) -> Scope +auto Blender::create(const Ref & /*sharedContext*/) -> Scope { switch (GraphicsContext::get_graphics_api()) { diff --git a/modules/engine/src/graphics/buffers.cpp b/modules/renderer/src/buffers.cpp similarity index 82% rename from modules/engine/src/graphics/buffers.cpp rename to modules/renderer/src/buffers.cpp index 7f71719..5d52c88 100644 --- a/modules/engine/src/graphics/buffers.cpp +++ b/modules/renderer/src/buffers.cpp @@ -1,20 +1,21 @@ -#include -#include -#include +#include +#include +#include +#include #ifdef LIGHT_PLATFORM_WINDOWS - #include - #include + #include + #include #endif -#include +#include namespace Light { auto ConstantBuffer::create( ConstantBufferIndex index, unsigned int size, - const Ref& /*sharedContext*/ + const Ref & /*sharedContext*/ ) -> Scope { switch (GraphicsContext::get_graphics_api()) @@ -42,7 +43,7 @@ auto VertexBuffer::create( float *vertices, unsigned int stride, unsigned int count, - const Ref& /*sharedContext*/ + const Ref & /*sharedContext*/ ) -> Ref { switch (GraphicsContext::get_graphics_api()) @@ -70,7 +71,7 @@ auto VertexBuffer::create( auto IndexBuffer::create( unsigned int *indices, unsigned int count, - const Ref& /*sharedContext*/ + const Ref & /*sharedContext*/ ) -> Ref { switch (GraphicsContext::get_graphics_api()) diff --git a/modules/engine/src/platform/graphics/directx/blender.cpp b/modules/renderer/src/dx/blender.cpp similarity index 96% rename from modules/engine/src/platform/graphics/directx/blender.cpp rename to modules/renderer/src/dx/blender.cpp index 7e8e53d..dc651dc 100644 --- a/modules/engine/src/platform/graphics/directx/blender.cpp +++ b/modules/renderer/src/dx/blender.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include namespace Light { diff --git a/modules/engine/src/platform/graphics/directx/buffers.cpp b/modules/renderer/src/dx/buffers.cpp similarity index 97% rename from modules/engine/src/platform/graphics/directx/buffers.cpp rename to modules/renderer/src/dx/buffers.cpp index 745692c..ec62fd9 100644 --- a/modules/engine/src/platform/graphics/directx/buffers.cpp +++ b/modules/renderer/src/dx/buffers.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include namespace Light { diff --git a/modules/engine/src/platform/graphics/directx/framebuffers.cpp b/modules/renderer/src/dx/framebuffers.cpp similarity index 96% rename from modules/engine/src/platform/graphics/directx/framebuffers.cpp rename to modules/renderer/src/dx/framebuffers.cpp index 4b1e956..7b3e7ae 100644 --- a/modules/engine/src/platform/graphics/directx/framebuffers.cpp +++ b/modules/renderer/src/dx/framebuffers.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include namespace Light { diff --git a/modules/engine/src/platform/graphics/directx/graphics_context.cpp b/modules/renderer/src/dx/graphics_context.cpp similarity index 86% rename from modules/engine/src/platform/graphics/directx/graphics_context.cpp rename to modules/renderer/src/dx/graphics_context.cpp index 763ae90..13fe73f 100644 --- a/modules/engine/src/platform/graphics/directx/graphics_context.cpp +++ b/modules/renderer/src/dx/graphics_context.cpp @@ -1,12 +1,11 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include // required for forward declaratio> +#include // required for forward declaratio> +#include // required for forward declaratio> #define GLFW_EXPOSE_NATIVE_WIN32 #include diff --git a/modules/engine/src/platform/graphics/directx/render_command.cpp b/modules/renderer/src/dx/render_command.cpp similarity index 95% rename from modules/engine/src/platform/graphics/directx/render_command.cpp rename to modules/renderer/src/dx/render_command.cpp index eb89cad..abea283 100644 --- a/modules/engine/src/platform/graphics/directx/render_command.cpp +++ b/modules/renderer/src/dx/render_command.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include namespace Light { diff --git a/modules/engine/src/platform/graphics/directx/shader.cpp b/modules/renderer/src/dx/shader.cpp similarity index 94% rename from modules/engine/src/platform/graphics/directx/shader.cpp rename to modules/renderer/src/dx/shader.cpp index 8dc458a..13ffd74 100644 --- a/modules/engine/src/platform/graphics/directx/shader.cpp +++ b/modules/renderer/src/dx/shader.cpp @@ -1,6 +1,6 @@ #include -#include -#include +#include +#include namespace Light { diff --git a/modules/engine/src/platform/graphics/directx/texture.cpp b/modules/renderer/src/dx/texture.cpp similarity index 95% rename from modules/engine/src/platform/graphics/directx/texture.cpp rename to modules/renderer/src/dx/texture.cpp index 026febf..ea61638 100644 --- a/modules/engine/src/platform/graphics/directx/texture.cpp +++ b/modules/renderer/src/dx/texture.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include namespace Light { diff --git a/modules/engine/src/platform/graphics/directx/user_interface.cpp b/modules/renderer/src/dx/user_interface.cpp similarity index 90% rename from modules/engine/src/platform/graphics/directx/user_interface.cpp rename to modules/renderer/src/dx/user_interface.cpp index 7afd057..8f1f8ac 100644 --- a/modules/engine/src/platform/graphics/directx/user_interface.cpp +++ b/modules/renderer/src/dx/user_interface.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #define GLFW_EXPOSE_NATIVE_WIN32 #include diff --git a/modules/engine/src/platform/graphics/directx/vertex_layout.cpp b/modules/renderer/src/dx/vertex_layout.cpp similarity index 94% rename from modules/engine/src/platform/graphics/directx/vertex_layout.cpp rename to modules/renderer/src/dx/vertex_layout.cpp index 081d6cc..e8f0b59 100644 --- a/modules/engine/src/platform/graphics/directx/vertex_layout.cpp +++ b/modules/renderer/src/dx/vertex_layout.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include namespace Light { diff --git a/modules/engine/src/graphics/framebuffer.cpp b/modules/renderer/src/framebuffer.cpp similarity index 72% rename from modules/engine/src/graphics/framebuffer.cpp rename to modules/renderer/src/framebuffer.cpp index c4651f0..8a62ba6 100644 --- a/modules/engine/src/graphics/framebuffer.cpp +++ b/modules/renderer/src/framebuffer.cpp @@ -1,12 +1,12 @@ -#include -#include +#include +#include #ifdef LIGHT_PLATFORM_WINDOWS - #include - #include + #include + #include #endif -#include +#include namespace Light { diff --git a/modules/engine/src/platform/graphics/opengl/blender.cpp b/modules/renderer/src/gl/blender.cpp similarity index 96% rename from modules/engine/src/platform/graphics/opengl/blender.cpp rename to modules/renderer/src/gl/blender.cpp index 19e66c8..430ccbe 100644 --- a/modules/engine/src/platform/graphics/opengl/blender.cpp +++ b/modules/renderer/src/gl/blender.cpp @@ -1,4 +1,4 @@ -#include +#include #include namespace Light { diff --git a/modules/engine/src/platform/graphics/opengl/buffers.cpp b/modules/renderer/src/gl/buffers.cpp similarity index 97% rename from modules/engine/src/platform/graphics/opengl/buffers.cpp rename to modules/renderer/src/gl/buffers.cpp index 1062a87..71f5838 100644 --- a/modules/engine/src/platform/graphics/opengl/buffers.cpp +++ b/modules/renderer/src/gl/buffers.cpp @@ -1,6 +1,7 @@ #include -#include #include +#include +#include namespace Light { diff --git a/modules/engine/src/platform/graphics/opengl/framebuffers.cpp b/modules/renderer/src/gl/framebuffers.cpp similarity index 97% rename from modules/engine/src/platform/graphics/opengl/framebuffers.cpp rename to modules/renderer/src/gl/framebuffers.cpp index 4440b38..27854d0 100644 --- a/modules/engine/src/platform/graphics/opengl/framebuffers.cpp +++ b/modules/renderer/src/gl/framebuffers.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/modules/engine/src/platform/graphics/opengl/graphics_context.cpp b/modules/renderer/src/gl/graphics_context.cpp similarity index 71% rename from modules/engine/src/platform/graphics/opengl/graphics_context.cpp rename to modules/renderer/src/gl/graphics_context.cpp index dd44674..ce9abca 100644 --- a/modules/engine/src/platform/graphics/opengl/graphics_context.cpp +++ b/modules/renderer/src/gl/graphics_context.cpp @@ -1,12 +1,10 @@ -#include -#include // required for forward declaratio> -#include // required for forward declaratio> -#include // required for forward declaratio> -#include // required for forward declaratio> -#include -#include // required for forward declaratio> -#include // required for forward declaratio> #include +#include +#include // required for forward declaratio> +#include // required for forward declaratio> +#include +#include // required for forward declaratio> +#include // required for forward declaratio> #ifndef STOP_FUCKING_ORDERING_THESE_THE_WRONG_WAY_CLANG_FORMAT____ #include @@ -70,7 +68,7 @@ void glGraphicsContext::set_debug_message_callback() unsigned int type, unsigned int id, unsigned int severity, - int /*length*/, + int /*length*/, const char *message, const void * /*userParam*/) { switch (severity) @@ -83,9 +81,10 @@ void glGraphicsContext::set_debug_message_callback() case GL_DEBUG_SEVERITY_LOW: log_wrn( "glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}", - Stringifier::glDebugMsgSeverity(severity), - Stringifier::glDebugMsgSource(source), - Stringifier::glDebugMsgType(type), + // TODO(Light): Stringify! + severity, + source, + type, id ); log_wrn(" {}", message); @@ -94,9 +93,10 @@ void glGraphicsContext::set_debug_message_callback() case GL_DEBUG_SEVERITY_NOTIFICATION: log_wrn( "Severity: {} :: Source: {} :: Type: {} :: ID: {}", - Stringifier::glDebugMsgSeverity(severity), - Stringifier::glDebugMsgSource(source), - Stringifier::glDebugMsgType(type), + // TODO(Light): Stringify! + severity, + source, + type, id ); log_trc(" {}", message); diff --git a/modules/engine/src/platform/graphics/opengl/render_command.cpp b/modules/renderer/src/gl/render_command.cpp similarity index 94% rename from modules/engine/src/platform/graphics/opengl/render_command.cpp rename to modules/renderer/src/gl/render_command.cpp index c9e4f03..e553720 100644 --- a/modules/engine/src/platform/graphics/opengl/render_command.cpp +++ b/modules/renderer/src/gl/render_command.cpp @@ -1,4 +1,4 @@ -#include +#include #include #ifndef DONT_FUCKING_ORDER_THESSE_PLEASE_FOR_THE_LOVE_OF_GOD_CLANG_FORMAT #include diff --git a/modules/engine/src/platform/graphics/opengl/shader.cpp b/modules/renderer/src/gl/shader.cpp similarity index 97% rename from modules/engine/src/platform/graphics/opengl/shader.cpp rename to modules/renderer/src/gl/shader.cpp index 9fe299e..7b0b8b5 100644 --- a/modules/engine/src/platform/graphics/opengl/shader.cpp +++ b/modules/renderer/src/gl/shader.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/modules/engine/src/platform/graphics/opengl/texture.cpp b/modules/renderer/src/gl/texture.cpp similarity index 96% rename from modules/engine/src/platform/graphics/opengl/texture.cpp rename to modules/renderer/src/gl/texture.cpp index b5f23bd..0ecda37 100644 --- a/modules/engine/src/platform/graphics/opengl/texture.cpp +++ b/modules/renderer/src/gl/texture.cpp @@ -1,5 +1,6 @@ -#include #include +#include +#include namespace Light { diff --git a/modules/renderer/src/gl/user_interface.cpp b/modules/renderer/src/gl/user_interface.cpp new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/modules/renderer/src/gl/user_interface.cpp @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/renderer/src/gl/vertex_layout.cpp b/modules/renderer/src/gl/vertex_layout.cpp new file mode 100644 index 0000000..1a41f2a --- /dev/null +++ b/modules/renderer/src/gl/vertex_layout.cpp @@ -0,0 +1,147 @@ +#include +#include +#include +#include + +namespace Light { + +glVertexLayout::glVertexLayout( + const Ref &buffer, + const std::vector> &elements +) + : m_array_id(NULL) +{ + // check + lt_assert( + std::dynamic_pointer_cast(buffer), + "Failed to cast 'VertexBuffer' to 'glVertexBuffer'" + ); + lt_assert(!elements.empty(), "'elements' is empty"); + + // local + auto elementsDesc = std::vector {}; + elementsDesc.reserve(elements.size()); + auto stride = 0u; + + // extract elements desc + for (const auto &element : elements) + { + elementsDesc.push_back(get_element_desc(element.second, stride)); + stride += elementsDesc.back().typeSize * elementsDesc.back().count; + } + + // create vertex array + glCreateVertexArrays(1, &m_array_id); + + // bind buffer and array + buffer->bind(); + bind(); + + // enable vertex attributes + auto index = 0u; + for (const auto &elementDesc : elementsDesc) + { + glVertexAttribPointer( + index, + elementDesc.count, + elementDesc.type, + GL_FALSE, + stride, + (const void *)elementDesc.offset + ); + glEnableVertexAttribArray(index++); + } +} + +glVertexLayout::~glVertexLayout() +{ + glDeleteVertexArrays(1, &m_array_id); +} + +void glVertexLayout::bind() +{ + glBindVertexArray(m_array_id); +} + +void glVertexLayout::un_bind() +{ + glBindVertexArray(NULL); +} + +auto glVertexLayout::get_element_desc(VertexElementType type, unsigned int offset) + -> glVertexElementDesc +{ + switch (type) + { + /* byte */ + case Light::VertexElementType::Byte1: + return { .type = GL_BYTE, .count = 1u, .typeSize = sizeof(GLbyte), .offset = offset }; + case Light::VertexElementType::Byte2: + return { .type = GL_BYTE, .count = 1u, .typeSize = sizeof(GLbyte), .offset = offset }; + case Light::VertexElementType::Byte4: + return { .type = GL_BYTE, .count = 1u, .typeSize = sizeof(GLbyte), .offset = offset }; + + /* ubyte */ + case Light::VertexElementType::UByte1: + return { .type = GL_UNSIGNED_BYTE, + .count = 1u, + .typeSize = sizeof(GLubyte), + .offset = offset }; + case Light::VertexElementType::UByte2: + return { .type = GL_UNSIGNED_BYTE, + .count = 2u, + .typeSize = sizeof(GLubyte), + .offset = offset }; + case Light::VertexElementType::UByte4: + return { .type = GL_UNSIGNED_BYTE, + .count = 4u, + .typeSize = sizeof(GLubyte), + .offset = offset }; + + /* int */ + case VertexElementType::Int1: + return { .type = GL_INT, .count = 1u, .typeSize = sizeof(GLint), .offset = offset }; + case VertexElementType::Int2: + return { .type = GL_INT, .count = 2u, .typeSize = sizeof(GLint), .offset = offset }; + case VertexElementType::Int3: + return { .type = GL_INT, .count = 3u, .typeSize = sizeof(GLint), .offset = offset }; + case VertexElementType::Int4: + return { .type = GL_INT, .count = 4u, .typeSize = sizeof(GLint), .offset = offset }; + + /* uint */ + case VertexElementType::UInt1: + return { .type = GL_UNSIGNED_INT, + .count = 1u, + .typeSize = sizeof(GLuint), + .offset = offset }; + case VertexElementType::UInt2: + return { .type = GL_UNSIGNED_INT, + .count = 2u, + .typeSize = sizeof(GLuint), + .offset = offset }; + case VertexElementType::UInt3: + return { .type = GL_UNSIGNED_INT, + .count = 3u, + .typeSize = sizeof(GLuint), + .offset = offset }; + case VertexElementType::UInt4: + return { .type = GL_UNSIGNED_INT, + .count = 4u, + .typeSize = sizeof(GLuint), + .offset = offset }; + + /* float */ + case VertexElementType::Float1: + return { .type = GL_FLOAT, .count = 1u, .typeSize = sizeof(GLfloat), .offset = offset }; + case VertexElementType::Float2: + return { .type = GL_FLOAT, .count = 2u, .typeSize = sizeof(GLfloat), .offset = offset }; + case VertexElementType::Float3: + return { .type = GL_FLOAT, .count = 3u, .typeSize = sizeof(GLfloat), .offset = offset }; + case VertexElementType::Float4: + return { .type = GL_FLOAT, .count = 4u, .typeSize = sizeof(GLfloat), .offset = offset }; + + default: lt_assert(false, "Invalid 'VertexElementType'"); return {}; + } +} + +} // namespace Light diff --git a/modules/renderer/src/graphics_context.cpp b/modules/renderer/src/graphics_context.cpp new file mode 100644 index 0000000..c901206 --- /dev/null +++ b/modules/renderer/src/graphics_context.cpp @@ -0,0 +1,57 @@ +#include +#include + +#ifdef LIGHT_PLATFORM_WINDOWS + #include + #include +#endif + +namespace Light { + +GraphicsContext *GraphicsContext::s_context = nullptr; + +GraphicsContext::~GraphicsContext() = default; + +auto GraphicsContext::create(GraphicsAPI api, GLFWwindow *window_handle) -> Scope +{ + delete s_context; + + if (api == GraphicsAPI::Default) + { +#if defined(LIGHT_PLATFORM_WINDOWS) + api = GraphicsAPI::DirectX; +#elif defined(LIGHT_PLATFORM_LINUX) + api = GraphicsAPI::OpenGL; +#elif defined(LIGHT_PLATFORM_MAC) + api = GraphicsAPI::OpenGL; +#endif + } + + auto scope_gfx = Scope {}; + switch (api) + { + // opengl + case GraphicsAPI::OpenGL: + scope_gfx = create_scope(window_handle); + s_context = scope_gfx.get(); + break; + // directx + case GraphicsAPI::DirectX: + lt_win(scope_gfx = create_scope(window_handle); + s_context = scope_gfx.get(); + break;) + + default + : lt_assert( + false, + "Invalid/unsupported 'GraphicsAPI' {}", + // TODO(Light): Stringifier::graphics_api_to_string(api), + "TODO" + ); + return nullptr; + } + + return std::move(scope_gfx); +} + +} // namespace Light diff --git a/modules/engine/src/graphics/render_command.cpp b/modules/renderer/src/render_command.cpp similarity index 67% rename from modules/engine/src/graphics/render_command.cpp rename to modules/renderer/src/render_command.cpp index f573b76..d7c9476 100644 --- a/modules/engine/src/graphics/render_command.cpp +++ b/modules/renderer/src/render_command.cpp @@ -1,16 +1,17 @@ -#include -#include +#include +#include +#include #ifdef LIGHT_PLATFORM_WINDOWS - #include - #include + #include + #include #endif -#include +#include namespace Light { -auto RenderCommand::create(GLFWwindow *windowHandle, const Ref& /*sharedContext*/) +auto RenderCommand::create(GLFWwindow *windowHandle, const Ref & /*sharedContext*/) -> Scope { switch (GraphicsContext::get_graphics_api()) diff --git a/modules/engine/src/graphics/renderer.cpp b/modules/renderer/src/renderer.cpp similarity index 84% rename from modules/engine/src/graphics/renderer.cpp rename to modules/renderer/src/renderer.cpp index bd2e64f..0b38052 100644 --- a/modules/engine/src/graphics/renderer.cpp +++ b/modules/renderer/src/renderer.cpp @@ -1,24 +1,42 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include namespace Light { Renderer *Renderer::s_context = nullptr; -Renderer::Renderer(GLFWwindow *windowHandle, const Ref &sharedContext) - : m_quad_renderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext) - , m_texture_renderer(LT_MAX_TEXTURE_RENDERER_VERTICES, sharedContext) - , m_tinted_texture_renderer(LT_MAX_TINTED_TEXTURE_RENDERER_VERTICES, sharedContext) +Renderer::Renderer( + GLFWwindow *window_handle, + Ref shared_context, + CreateInfo create_info +) + : m_quad_renderer( + LT_MAX_QUAD_RENDERER_VERTICES, + shared_context, + std::move(create_info.quad_renderer_shader) + ) + , m_texture_renderer( + LT_MAX_TEXTURE_RENDERER_VERTICES, + shared_context, + std::move(create_info.texture_renderer_shader) + ) + , m_tinted_texture_renderer( + LT_MAX_TINTED_TEXTURE_RENDERER_VERTICES, + shared_context, + std::move(create_info.tinted_texture_renderer_shader) + ) , m_view_projection_buffer(nullptr) , m_render_command(nullptr) , m_blender(nullptr) @@ -31,17 +49,23 @@ Renderer::Renderer(GLFWwindow *windowHandle, const Ref &sharedCon m_view_projection_buffer = ConstantBuffer::create( ConstantBufferIndex::ViewProjection, sizeof(glm::mat4), - sharedContext + shared_context ); - m_render_command = RenderCommand::create(windowHandle, sharedContext); - m_blender = Blender::create(sharedContext); + m_render_command = RenderCommand::create(window_handle, shared_context); + m_blender = Blender::create(shared_context); m_blender->enable(BlendFactor::SRC_ALPHA, BlendFactor::INVERSE_SRC_ALPHA); } -auto Renderer::create(GLFWwindow *windowHandle, Ref sharedContext) -> Scope +auto Renderer::create( + GLFWwindow *windowHandle, + Ref sharedContext, + CreateInfo create_info +) -> Scope { - return make_scope(new Renderer(windowHandle, std::move(sharedContext))); + return make_scope( + new Renderer(windowHandle, std::move(sharedContext), std::move(create_info)) + ); } void Renderer::on_window_resize(const WindowResizedEvent &event) diff --git a/modules/engine/src/graphics/renderer_programs/quad.cpp b/modules/renderer/src/renderer_programs/quad.cpp similarity index 67% rename from modules/engine/src/graphics/renderer_programs/quad.cpp rename to modules/renderer/src/renderer_programs/quad.cpp index ee36e88..0612d7c 100644 --- a/modules/engine/src/graphics/renderer_programs/quad.cpp +++ b/modules/renderer/src/renderer_programs/quad.cpp @@ -1,29 +1,21 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace Light { QuadRendererProgram::QuadRendererProgram( unsigned int max_vertices, - const Ref &shared_context + const Ref &shared_context, + Ref shader ) - : m_shader(nullptr) - , m_index_buffer(nullptr) + : m_index_buffer(nullptr) , m_vertex_layout(nullptr) , m_max_vertices(max_vertices) + , m_shader(std::move(shader)) { - // #todo: don't use relative path - ResourceManager::load_shader( - "LT_ENGINE_RESOURCES_QUAD_SHADER", - "data/assets/shaders/quads/vs.asset", - "data/assets/shaders/quads/ps.asset" - ); - - m_shader = ResourceManager::get_shader("LT_ENGINE_RESOURCES_QUAD_SHADER"); m_vertex_buffer = Ref( VertexBuffer::create(nullptr, sizeof(QuadVertexData), max_vertices, shared_context) ); diff --git a/modules/engine/src/graphics/renderer_programs/texture.cpp b/modules/renderer/src/renderer_programs/texture.cpp similarity index 56% rename from modules/engine/src/graphics/renderer_programs/texture.cpp rename to modules/renderer/src/renderer_programs/texture.cpp index ea8c0e4..dc804fd 100644 --- a/modules/engine/src/graphics/renderer_programs/texture.cpp +++ b/modules/renderer/src/renderer_programs/texture.cpp @@ -1,29 +1,45 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace Light { TextureRendererProgram::TextureRendererProgram( unsigned int max_vertices, - const Ref &shared_context + const Ref &shared_context, + Ref shader ) - : m_shader(nullptr) + : m_shader(std::move(shader)) , m_index_buffer(nullptr) , m_vertex_layout(nullptr) , m_max_vertices(max_vertices) { // #todo: don't use relative path - ResourceManager::load_shader( - "LT_ENGINE_RESOURCES_TEXTURE_SHADER", - "data/assets/shaders/texture/vs.asset", - "data/assets/shaders/texture/ps.asset" - ); + // AssetManager::load_shader( + // "LT_ENGINE_RESOURCES_TEXTURE_SHADER", + // "data/assets/shaders/texture/vs.asset", + // "data/assets/shaders/texture/ps.asset" + // ); + // + // AssetManager::load_shader( + // "LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER", + // "data/assets/shaders/tinted_texture/vs.asset", + // "data/assets/shaders/tinted_texture/ps.asset" + // ); + // + // AssetManager::load_shader( + // "LT_ENGINE_RESOURCES_QUAD_SHADER", + // "data/assets/shaders/quads/vs.asset", + // "data/assets/shaders/quads/ps.asset" + // ); + // + // m_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_TEXTURE_SHADER"); + // m_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER"); + // m_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_QUAD_SHADER"); + - m_shader = ResourceManager::get_shader("LT_ENGINE_RESOURCES_TEXTURE_SHADER"); m_vertex_buffer = Ref( VertexBuffer::create(nullptr, sizeof(TextureVertexData), max_vertices, shared_context) ); diff --git a/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp b/modules/renderer/src/renderer_programs/tinted_texture.cpp similarity index 68% rename from modules/engine/src/graphics/renderer_programs/tinted_texture.cpp rename to modules/renderer/src/renderer_programs/tinted_texture.cpp index 36fac1d..a080e2e 100644 --- a/modules/engine/src/graphics/renderer_programs/tinted_texture.cpp +++ b/modules/renderer/src/renderer_programs/tinted_texture.cpp @@ -1,29 +1,22 @@ -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include namespace Light { TintedTextureRendererProgram::TintedTextureRendererProgram( unsigned int max_vertices, - const Ref &shared_context + const Ref &shared_context, + Ref shader + ) - : m_shader(nullptr) + : m_shader(std::move(shader)) , m_index_buffer(nullptr) , m_vertex_layout(nullptr) , m_max_vertices(max_vertices) { - // #todo: don't use relative path - ResourceManager::load_shader( - "LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER", - "data/assets/shaders/tinted_texture/vs.asset", - "data/assets/shaders/tinted_texture/ps.asset" - ); - - m_shader = ResourceManager::get_shader("LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER"); m_vertex_buffer = Ref( VertexBuffer::create(nullptr, sizeof(TintedTextureVertexData), max_vertices, shared_context) ); diff --git a/modules/engine/src/graphics/shader.cpp b/modules/renderer/src/shader.cpp similarity index 76% rename from modules/engine/src/graphics/shader.cpp rename to modules/renderer/src/shader.cpp index 408ec10..4b257e6 100644 --- a/modules/engine/src/graphics/shader.cpp +++ b/modules/renderer/src/shader.cpp @@ -1,12 +1,12 @@ -#include -#include +#include +#include #ifdef LIGHT_PLATFORM_WINDOWS - #include - #include + #include + #include #endif -#include +#include namespace Light { diff --git a/modules/engine/src/graphics/texture.cpp b/modules/renderer/src/texture.cpp similarity index 76% rename from modules/engine/src/graphics/texture.cpp rename to modules/renderer/src/texture.cpp index 297bd1a..03b48f3 100644 --- a/modules/engine/src/graphics/texture.cpp +++ b/modules/renderer/src/texture.cpp @@ -1,12 +1,13 @@ -#include -#include +#include +#include +#include #ifdef LIGHT_PLATFORM_WINDOWS - #include - #include + #include + #include #endif -#include +#include #include namespace Light { @@ -16,7 +17,7 @@ auto Texture::create( unsigned int height, unsigned int components, unsigned char *pixels, - const Ref& /*sharedContext*/, + const Ref & /*sharedContext*/, const std::string &filePath ) -> Ref { diff --git a/modules/engine/src/graphics/vertex_layout.cpp b/modules/renderer/src/vertex_layout.cpp similarity index 65% rename from modules/engine/src/graphics/vertex_layout.cpp rename to modules/renderer/src/vertex_layout.cpp index 6aa8a25..a7bd2f3 100644 --- a/modules/engine/src/graphics/vertex_layout.cpp +++ b/modules/renderer/src/vertex_layout.cpp @@ -1,20 +1,21 @@ -#include -#include +#include +#include +#include #ifdef LIGHT_PLATFORM_WINDOWS - #include - #include + #include + #include #endif -#include +#include namespace Light { auto VertexLayout::create( - const Ref& vertexBuffer, - const Ref& /*shader*/, + const Ref &vertexBuffer, + const Ref & /*shader*/, const std::vector> &elements, - const Ref& /*sharedContext*/ + const Ref & /*sharedContext*/ ) -> Ref { switch (GraphicsContext::get_graphics_api()) diff --git a/modules/ui/CMakeLists.txt b/modules/ui/CMakeLists.txt new file mode 100644 index 0000000..a4ac704 --- /dev/null +++ b/modules/ui/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library_module(ui ui.cpp gl/ui.cpp) +target_link_libraries(ui PUBLIC spdlog::spdlog imgui renderer logger lt_debug) diff --git a/modules/ui/include/ui/gl/ui.hpp b/modules/ui/include/ui/gl/ui.hpp new file mode 100644 index 0000000..5c18320 --- /dev/null +++ b/modules/ui/include/ui/gl/ui.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +struct GLFWwindow; + +namespace Light { + +class glUserInterface: public UserInterface +{ +public: + glUserInterface() = default; + + ~glUserInterface() override; + + void platform_implementation(GLFWwindow *windowHandle, Ref sharedContext) + override; + + void begin() override; + + void end() override; + + void log_debug_data() override; + +private: + GLFWwindow *m_window_handle {}; +}; + +} // namespace Light diff --git a/modules/engine/include/engine/user_interface/user_interface.hpp b/modules/ui/include/ui/ui.hpp similarity index 71% rename from modules/engine/include/engine/user_interface/user_interface.hpp rename to modules/ui/include/ui/ui.hpp index 5973e56..eaacf67 100644 --- a/modules/engine/include/engine/user_interface/user_interface.hpp +++ b/modules/ui/include/ui/ui.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include struct GLFWwindow; @@ -10,11 +9,10 @@ namespace Light { class Event; class SharedContext; -// #todo: fix the UserIntreface mess!! -class UserInterface /* singleton */ +class UserInterface { public: - static auto create(GLFWwindow *windowHandle, Ref sharedContext) + static auto create(GLFWwindow *window_handle, Ref shared_context) -> Scope; static void dockspace_begin(); @@ -27,10 +25,10 @@ public: virtual ~UserInterface() = default; - void init(GLFWwindow *windowHandle, Ref sharedContext); + void init(GLFWwindow *window_handle, Ref sharedContext); virtual void platform_implementation( - GLFWwindow *windowHandle, + GLFWwindow *window_handle, Ref sharedContext ) = 0; diff --git a/modules/engine/src/platform/graphics/opengl/user_interface.cpp b/modules/ui/src/gl/ui.cpp similarity index 84% rename from modules/engine/src/platform/graphics/opengl/user_interface.cpp rename to modules/ui/src/gl/ui.cpp index b8ed810..a48115f 100644 --- a/modules/engine/src/platform/graphics/opengl/user_interface.cpp +++ b/modules/ui/src/gl/ui.cpp @@ -1,15 +1,15 @@ -#include +#include #include #include -#include -#include #include +#include +#include namespace Light { void glUserInterface::platform_implementation( GLFWwindow *windowHandle, - Ref /*sharedContext*/ + Ref /* shared_context */ ) { m_window_handle = windowHandle; @@ -23,9 +23,10 @@ glUserInterface::~glUserInterface() // #todo: handle this in a better way auto &io = ImGui::GetIO(); - if (io.IniFilename == "default_gui_layout.ini") { + if (io.IniFilename == "default_gui_layout.ini") + { io.IniFilename = "user_gui_layout.ini"; -} + } ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); diff --git a/modules/engine/src/user_interface/user_interface.cpp b/modules/ui/src/ui.cpp similarity index 94% rename from modules/engine/src/user_interface/user_interface.cpp rename to modules/ui/src/ui.cpp index fd2250c..c885cb7 100644 --- a/modules/engine/src/user_interface/user_interface.cpp +++ b/modules/ui/src/ui.cpp @@ -1,18 +1,18 @@ -#include -#include +#include +#include #ifdef LIGHT_PLATFORM_WINDOWS - #include - #include + #include + #include #endif -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include #include diff --git a/tools/cmake/macros.cmake b/tools/cmake/macros.cmake index ab01d62..2e0973e 100644 --- a/tools/cmake/macros.cmake +++ b/tools/cmake/macros.cmake @@ -4,6 +4,11 @@ macro (add_library_module libname) add_library(${libname} INTERFACE) target_include_directories(${libname} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) + # Do not link base against base :D + if (NOT ${libname} STREQUAL "base") + target_link_libraries(${libname} INTERFACE base) + endif () + else () # Compiled library set(source_files) set(source_directory "${CMAKE_CURRENT_SOURCE_DIR}/src") @@ -14,6 +19,11 @@ macro (add_library_module libname) message("Adding library ${libname} with source files: ${source_files}") add_library(${libname} ${source_files}) target_include_directories(${libname} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) + + # Do not link base against base :D + if (NOT ${libname} STREQUAL "base") + target_link_libraries(${libname} PUBLIC base) + endif () endif () endmacro () @@ -27,4 +37,5 @@ macro (add_executable_module exename) message("Adding executable ${exename} with source files: ${source_files}") add_executable(${exename} ${source_files}) target_include_directories(${exename} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) + target_link_libraries(${exename} PUBLIC base) endmacro ()