diff --git a/Engine/src/Engine/Base.h b/Engine/src/Engine/Base.h deleted file mode 100644 index 7dadf86..0000000 --- a/Engine/src/Engine/Base.h +++ /dev/null @@ -1,160 +0,0 @@ -#pragma once - -#include - -namespace Light { - - // Ref (Ref) - template - using Ref = std::shared_ptr; - - template - constexpr Ref CreateRef(Args&&... args) - { - return std::make_shared(std::forward(args)...); - } - - template - constexpr Ref MakeRef(T* rawPointer) - { - return std::shared_ptr(rawPointer); - } - - // Scope (std::unique_ptr) - template - using Scope = std::unique_ptr; - - template - constexpr std::unique_ptr CreateScope(Args&&... args) - { - return std::make_unique(std::forward(args)...); - } - - template - constexpr std::unique_ptr MakeScope(T* rawPointer) - { - return std::unique_ptr(rawPointer); - } - -} - -// platform -#define LT_WIN(x) // windows -#define LT_LIN(x) // linux -#define LT_MAC(x) // mac - -#if defined(LIGHT_PLATFORM_WINDOWS) - #define LT_BUILD_PLATFORM "Windows" - #define LT_WIN(x) x - -#elif defined(LIGHT_PLATFORM_LINUX) - #define LT_BUILD_PLATFORM "Linux" - #define LT_LIN(x) x - -#elif defined(LIGHT_PLATFORM_MAC) - #error "Unsupported platform: MAC" - #define LT_MAC(x) x - -#else - #error "Unsupported platform: Unknown" - -#endif - - -// operations -#define BIT(x) 1 << x - -// assertions -#if defined(LIGHT_DIST) - #define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_FILE_CRITICAL(__VA_ARGS__); throw ::Light::FailedEngineAssertion(__FILE__, __LINE__); } } - #define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_FILE_CRITICAL(__VA_ARGS__); throw ::Light::FailedClientAssertion(__FILE__, __LINE__); } } -#else - #define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); LT_BREAK(); throw ::Light::FailedEngineAssertion(__FILE__, __LINE__); } } - #define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); LT_BREAK(); throw ::Light::FailedClientAssertion(__FILE__, __LINE__); } } -#endif - -///*** [ PORTABLES ] ***/// -//** PORTABLE_DEBUG_BREAK **// -// copied from: https://github.com/nemequ/portable-snippets/tree/master/debug-trap -#if defined(__has_builtin) && !defined(__ibmxl__) - #if __has_builtin(__builtin_debugtrap) - #define LT_BREAK() __builtin_debugtrap() - - #elif __has_builtin(__debugbreak) - #define LT_BREAK() __debugbreak() - - #endif -#endif - -#if !defined(LT_BREAK) - #if defined(_MSC_VER) || defined(__INTEL_COMPILER) - #define LT_BREAK() __debugbreak() - - #elif defined(__ARMCC_VERSION) - #define LT_BREAK() __breakpoint(42) - - #elif defined(__ibmxl__) || defined(__xlC__) - #include - #define LT_BREAK() __trap(42) - - #elif defined(__DMC__) && defined(_M_IX86) - static inline void LT_BREAK(void) { __asm int 3h; } - - #elif defined(__i386__) || defined(__x86_64__) - static inline void LT_BREAK(void) { __asm__ __volatile__("int3"); } - - #elif defined(__thumb__) - static inline void LT_BREAK(void) { __asm__ __volatile__(".inst 0xde01"); } - - #elif defined(__aarch64__) - static inline void LT_BREAK(void) { __asm__ __volatile__(".inst 0xd4200000"); } - - #elif defined(__arm__) - static inline void LT_BREAK(void) { __asm__ __volatile__(".inst 0xe7f001f0"); } - - #elif defined (__alpha__) && !defined(__osf__) - static inline void LT_BREAK(void) { __asm__ __volatile__("bpt"); } - - #elif defined(_54_) - static inline void LT_BREAK(void) { __asm__ __volatile__("ESTOP"); } - - #elif defined(_55_) - static inline void LT_BREAK(void) { __asm__ __volatile__(";\n .if (.MNEMONIC)\n ESTOP_1\n .else\n ESTOP_1()\n .endif\n NOP"); } - - #elif defined(_64P_) - static inline void LT_BREAK(void) { __asm__ __volatile__("SWBP 0"); } - - #elif defined(_6x_) - static inline void LT_BREAK(void) { __asm__ __volatile__("NOP\n .word 0x10000000"); } - - #elif defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) && defined(__GNUC__) - #define LT_BREAK() __builtin_trap() - - #else - #include - - #if defined(SIGTRAP) - #define LT_BREAK() raise(SIGTRAP) - - #else - #define LT_BREAK() raise(SIGABRT) - - #endif - #endif -#endif - -#if !defined(LT_BREAK) - #define LT_BERAK LT_ENGINE_WARN("Unable to break!, LT_BREAK macro is undefined") -#endif - -//** PORTABLE_DEBUG_BREAK **// -///*** [ PORTABLES ] ***/// - - -#ifndef LT_LOGGER_H -#include "Debug/Logger.h" -#define LT_LOGGER_H -#endif - -#include "Debug/Exceptions.h" -#include "Utility/Stringifier.h" \ No newline at end of file diff --git a/Engine/src/Engine/Base/Base.h b/Engine/src/Engine/Base/Base.h new file mode 100644 index 0000000..1dcc817 --- /dev/null +++ b/Engine/src/Engine/Base/Base.h @@ -0,0 +1,91 @@ +#pragma once + +#include + +namespace Light { + + // Ref (Ref) + template + using Ref = std::shared_ptr; + + template + constexpr Ref CreateRef(Args&&... args) + { + return std::make_shared(std::forward(args)...); + } + + template + constexpr Ref MakeRef(T* rawPointer) + { + return std::shared_ptr(rawPointer); + } + + // Scope (std::unique_ptr) + template + using Scope = std::unique_ptr; + + template + constexpr std::unique_ptr CreateScope(Args&&... args) + { + return std::make_unique(std::forward(args)...); + } + + template + constexpr std::unique_ptr MakeScope(T* rawPointer) + { + return std::unique_ptr(rawPointer); + } + +} + +//========== PLATFORM ==========// +#define LT_WIN(x) // windows +#define LT_LIN(x) // linux +#define LT_MAC(x) // mac + +#if defined(LIGHT_PLATFORM_WINDOWS) + #define LT_BUILD_PLATFORM "Windows" + #define LT_WIN(x) x + +#elif defined(LIGHT_PLATFORM_LINUX) + #define LT_BUILD_PLATFORM "Linux" + #define LT_LIN(x) x + +#elif defined(LIGHT_PLATFORM_MAC) + #error "Unsupported platform: MAC" + #define LT_MAC(x) x + +#else + #error "Unsupported platform: Unknown" + +#endif +//========== PLATFORM ==========// + +//====================================================================== OPERATIONS ======================================================================// +/* assertions */ +#define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); LT_DEBUG_TRAP(); throw ::Light::FailedEngineAssertion(__FILE__, __LINE__); } } +#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); LT_DEBUG_TRAP(); throw ::Light::FailedClientAssertion(__FILE__, __LINE__); } } + +/* bit-wise */ +#define BIT(x) 1 << x + +/* token */ +#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 ==========// +/* debug */ +#ifndef LT_LOGGER_H +#include "Debug/Logger.h" +#define LT_LOGGER_H +#endif +#include "Debug/Exceptions.h" + +/* portables */ +#include "Base/Portables/DebugTrap.h" + +/* utility */ +#include "Utility/Stringifier.h" +//========== ESSENTIAL_HEADERS ==========// \ No newline at end of file diff --git a/Engine/src/Engine/EntryPoint.h b/Engine/src/Engine/Base/EntryPoint.h similarity index 90% rename from Engine/src/Engine/EntryPoint.h rename to Engine/src/Engine/Base/EntryPoint.h index 1f04b26..63dbb7b 100644 --- a/Engine/src/Engine/EntryPoint.h +++ b/Engine/src/Engine/Base/EntryPoint.h @@ -20,21 +20,25 @@ int main(int argc, char** argv) application->GameLoop(); } + // failed engine assertion catch (Light::FailedEngineAssertion) { LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedEngineAssertion'"); exitCode = -1; } + // failed client assertion catch (Light::FailedClientAssertion) { LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedClientAssertion'"); exitCode = -2; } + // gl exception catch(Light::glException) { LT_ENGINE_CRITICAL("main: exitting due to unhandled 'glException'"); exitCode = -3; } + // dx exception catch (Light::dxException) { LT_ENGINE_CRITICAL("main: exitting due to unhandled 'dxException'"); @@ -65,17 +69,20 @@ int main(int argc, char* argv[]) application->GameLoop(); } + // failed engine assertion catch (Light::FailedEngineAssertion) { LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedEngineAssertion'"); exitCode = -1; } + // failed client assertion catch (Light::FailedClientAssertion) { LT_ENGINE_CRITICAL("main: exitting due to unhandled 'FailedClientAssertion'"); exitCode = -2; } - catch(Light::glException) + // gl exception + catch (Light::glException) { LT_ENGINE_CRITICAL("main: exitting due to unhandled 'glException'"); exitCode = -3; diff --git a/Engine/src/Engine/Base/Portables/DebugTrap.h b/Engine/src/Engine/Base/Portables/DebugTrap.h new file mode 100644 index 0000000..502508d --- /dev/null +++ b/Engine/src/Engine/Base/Portables/DebugTrap.h @@ -0,0 +1,103 @@ +#pragma once + +// https://github.com/nemequ/portable-snippets/tree/master/debug-trap + +#ifdef LIGHT_DIST + #ifdef _MSC_VER + #define LT_DEBUG_TRAP() LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", __FUNCSIG__, __FILE__, __LINE__) // or __FUNCSIG__ + + #else + #define LT_DEBUG_TRAP() LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__ ) + + #endif +#endif + +#if !defined(LT_DEBUG_TRAP) && defined(__has_builtin) && !defined(__ibmxl__) + #if __has_builtin(__builtin_debugtrap) + #define LT_DEBUG_TRAP() __builtin_debugtrap() + + #elif __has_builtin(__debugbreak) + #define LT_DEBUG_TRAP() __debugbreak() + + #endif +#endif + +#if !defined(LT_DEBUG_TRAP) + #if defined(_MSC_VER) || defined(__INTEL_COMPILER) + #define LT_DEBUG_TRAP() __debugbreak() + + #elif defined(__ARMCC_VERSION) + #define LT_DEBUG_TRAP() __breakpoint(42) + + #elif defined(__ibmxl__) || defined(__xlC__) + #include + #define LT_DEBUG_TRAP() __trap(42) + + #elif defined(__DMC__) && defined(_M_IX86) + static inline void LT_DEBUG_TRAP(void) { __asm int 3h; } + + #elif defined(__i386__) || defined(__x86_64__) + static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__("int3"); } + + #elif defined(__thumb__) + static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__(".inst 0xde01"); } + + #elif defined(__aarch64__) + static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__(".inst 0xd4200000"); } + + #elif defined(__arm__) + static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__(".inst 0xe7f001f0"); } + + #elif defined (__alpha__) && !defined(__osf__) + static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__("bpt"); } + + #elif defined(_54_) + static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__("ESTOP"); } + + #elif defined(_55_) + static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__(";\n .if (.MNEMONIC)\n ESTOP_1\n .else\n ESTOP_1()\n .endif\n NOP"); } + + #elif defined(_64P_) + static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__("SWBP 0"); } + + #elif defined(_6x_) + static inline void LT_DEBUG_TRAP(void) { __asm__ __volatile__("NOP\n .word 0x10000000"); } + + #elif defined(__STDC_HOSTED__) && (__STDC_HOSTED__ == 0) && defined(__GNUC__) + #define LT_DEBUG_TRAP() __builtin_trap() + + #else + #include + + #if defined(SIGTRAP) + #define LT_DEBUG_TRAP() raise(SIGTRAP) + + #else + #define LT_DEBUG_TRAP() raise(SIGABRT) + + #endif + #endif +#endif + +#if !defined(LT_DEBUG_TRAP) + #define LT_BERAK LT_ENGINE_ERROR("Unable to break!, LT_BREAK macro is undefined") + #if !defined(LIGHT_IGNORE_UNDEFINED_DEBUG_BREAK) + #error "failed to define LT_BREAK, define LIGHT_IGNORE_UNDEFINED_DEBUG_BREAK to disable this error" + #elif !defined(LIGHT_DIST) + #ifdef _MSC_VER + #define LT_DEBUG_TRAP() LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", __FUNCSIG__, __FILE__, __LINE__) // or __FUNCSIG__ + + #else + #define LT_DEBUG_TRAP() LT_FILE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__ ) + + #endif + #else + #ifdef _MSC_VER + #define LT_DEBUG_TRAP() LT_ENGINE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", __FUNCSIG__, __FILE__, __LINE__) // or __FUNCSIG__ + + #else + #define LT_DEBUG_TRAP() LT_ENGINE_CRITICAL("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__ ) + + #endif +#endif +#endif \ No newline at end of file diff --git a/Engine/src/Engine/Camera/Camera.cpp b/Engine/src/Engine/Camera/Camera.cpp index 41679f7..86c044e 100644 --- a/Engine/src/Engine/Camera/Camera.cpp +++ b/Engine/src/Engine/Camera/Camera.cpp @@ -7,7 +7,11 @@ namespace Light { Camera::Camera(const glm::vec2& position, float aspectRatio, float zoomLevel, const glm::vec4& clearColor /* = glm::vec4(0.1f, 0.3f, 0.7f, 1.0f) */) - : m_Up(0.0f, 1.0f, 0.0f), m_Position(position), m_AspectRatio(aspectRatio), m_ZoomLevel(zoomLevel), m_ClearColor(clearColor) + : m_Up(0.0f, 1.0f, 0.0f), + m_Position(position), + m_AspectRatio(aspectRatio), + m_ZoomLevel(zoomLevel), + m_ClearColor(clearColor) { } diff --git a/Engine/src/Engine/Camera/Camera.h b/Engine/src/Engine/Camera/Camera.h index 5a57e1c..6edc8a7 100644 --- a/Engine/src/Engine/Camera/Camera.h +++ b/Engine/src/Engine/Camera/Camera.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include diff --git a/Engine/src/Engine/Core/Application.cpp b/Engine/src/Engine/Core/Application.cpp index 8944394..0760b31 100644 --- a/Engine/src/Engine/Core/Application.cpp +++ b/Engine/src/Engine/Core/Application.cpp @@ -20,13 +20,19 @@ namespace Light { Application::Application() + : m_Instrumentor(nullptr), + m_LayerStack(nullptr), + m_Input(nullptr), + m_Window(nullptr) { - Logger::Initialize(); + m_Logger = Logger::Create(); + m_Instrumentor = Instrumentor::Create(); + m_Instrumentor->BeginSession("Logs/ProfileResults_Startup.json"); + m_LayerStack = LayerStack::Create(); m_Input = Input::Create(); - m_Instrumentor->BeginSession("Logs/ProfileResults_Startup.json"); m_Window = Window::Create(std::bind(&Application::OnEvent, this, std::placeholders::_1)); } @@ -43,7 +49,7 @@ namespace Light { // log debug data LogDebugData(); - Logger::LogDebugData(); + m_Logger->LogDebugData(); m_Window->GetGfxContext()->LogDebugData(); m_Window->GetGfxContext()->GetUserInterface()->LogDebugData(); @@ -53,7 +59,7 @@ namespace Light { m_Instrumentor->EndSession(); // ProfileResults_GameLoop // m_Instrumentor->BeginSession("Logs/ProfileResults_GameLoop.json"); - //** GAMELOOP **// + /* game loop */ DeltaTimer deltaTimer; while (!m_Window->IsClosed()) { @@ -116,9 +122,9 @@ namespace Light { if (event.HasCategory(InputEventCategory)) m_Input->OnEvent(event); - // layers + /* layers */ // return if the event is an input event and 'Input' has disabled the game events - if (event.HasCategory(InputEventCategory) && !m_Input->IsReceivingGameEvents()) + if (event.HasCategory(InputEventCategory) && !m_Input->IsReceivingGameEvents()) return; for (auto it = m_LayerStack->rbegin(); it != m_LayerStack->rend(); it++) diff --git a/Engine/src/Engine/Core/Application.h b/Engine/src/Engine/Core/Application.h index 22dc91d..bebe61f 100644 --- a/Engine/src/Engine/Core/Application.h +++ b/Engine/src/Engine/Core/Application.h @@ -1,13 +1,13 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include "Debug/Instrumentor.h" -#include "Layer/LayerStack.h" - #include "Input/Input.h" +#include "Layer/LayerStack.h" + namespace Light { class Window; @@ -18,12 +18,13 @@ namespace Light { class Application { private: - Scope m_Instrumentor = nullptr; + Scope m_Logger; + Scope m_Instrumentor; Scope m_LayerStack; Scope m_Input; protected: - Scope m_Window = nullptr; + Scope m_Window; public: Application(const Application&) = delete; diff --git a/Engine/src/Engine/Core/Window.h b/Engine/src/Engine/Core/Window.h index 8cfd3eb..f64a815 100644 --- a/Engine/src/Engine/Core/Window.h +++ b/Engine/src/Engine/Core/Window.h @@ -1,12 +1,13 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include namespace Light { class Event; + class GraphicsContext; struct WindowProperties @@ -20,21 +21,29 @@ namespace Light { { protected: Scope m_GraphicsContext; - WindowProperties m_Properties = {}; - bool b_Closed = false; + WindowProperties m_Properties; + bool b_Closed; public: static Scope Create(std::function callback); + Window() + : m_GraphicsContext(nullptr), + m_Properties{}, + b_Closed(false) + { + } + Window(const Window&) = delete; Window& operator=(const Window&) = delete; virtual ~Window() = default; + /* events */ virtual void PollEvents() = 0; virtual void OnEvent(const Event& event) = 0; - //* SETTERS *// + //======================================== SETTERS ========================================// virtual void SetProperties(const WindowProperties& properties, bool affectVisibility = false) = 0; virtual void SetTitle(const std::string& title) = 0; @@ -44,8 +53,9 @@ namespace Light { inline void Close() { b_Closed = true; } virtual void SetVSync(bool vsync, bool toggle = false) = 0; virtual void SetVisibility(bool visible, bool toggle = false) = 0; + //======================================== SETTERS ========================================// - //* GETTERS *// + //============================== GETTERS ==============================// inline GraphicsContext* GetGfxContext() const { return m_GraphicsContext.get(); } inline const WindowProperties& GetProperties() const { return m_Properties; } @@ -57,9 +67,9 @@ namespace Light { inline bool IsClosed() const { return b_Closed; } inline bool IsVSync() const { return m_Properties.vsync; } inline bool IsVisible() const { return m_Properties.visible; } + //============================== GETTERS ==============================// protected: - Window() = default; }; } \ No newline at end of file diff --git a/Engine/src/Engine/Debug/Instrumentor.h b/Engine/src/Engine/Debug/Instrumentor.h index 2943dd8..a95d0b2 100644 --- a/Engine/src/Engine/Debug/Instrumentor.h +++ b/Engine/src/Engine/Debug/Instrumentor.h @@ -1,10 +1,9 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" -#include #include - +#include #include namespace Light { diff --git a/Engine/src/Engine/Debug/Logger.cpp b/Engine/src/Engine/Debug/Logger.cpp index 04095db..a4f0d39 100644 --- a/Engine/src/Engine/Debug/Logger.cpp +++ b/Engine/src/Engine/Debug/Logger.cpp @@ -6,14 +6,22 @@ namespace Light { - Ref Logger::s_EngineLogger = nullptr; - Ref Logger::s_ClientLogger = nullptr; - Ref Logger::s_FileLogger = nullptr; + Logger* Logger::s_Context = nullptr; - std::string Logger::s_LogFilePath = LT_LOG_FILE_LOCATION; - - void Light::Logger::Initialize() + Scope Logger::Create() { + return MakeScope(new Logger()); + } + + Logger::Logger() + : m_EngineLogger(nullptr), + m_ClientLogger(nullptr), + m_FileLogger(nullptr), + m_LogFilePath(LT_LOG_FILE_LOCATION) + { + LT_ENGINE_ASSERT(!s_Context, "Logger::Logger: an instance of 'Logger' already exists, do not construct this class!"); + s_Context = this; + // set spdlog pattern #if defined(LIGHT_PLATFORM_WINDOWS) spdlog::set_pattern("%^[%M:%S:%e] <%n>: %v%$"); @@ -22,16 +30,16 @@ namespace Light { #endif // create loggers #ifndef LIGHT_DIST - s_EngineLogger = spdlog::stdout_color_mt("Engine"); - s_ClientLogger = spdlog::stdout_color_mt("Client"); + m_EngineLogger = spdlog::stdout_color_mt("Engine"); + m_ClientLogger = spdlog::stdout_color_mt("Client"); #endif - s_FileLogger = spdlog::basic_logger_mt("File", s_LogFilePath); - s_FileLogger->set_pattern("%^[%M:%S:%e] <%l>: %v%$"); + m_FileLogger = spdlog::basic_logger_mt("File", m_LogFilePath); + m_FileLogger->set_pattern("%^[%M:%S:%e] <%l>: %v%$"); // set level #if defined(LIGHT_DEBUG) - s_EngineLogger->set_level(spdlog::level::trace); - s_ClientLogger->set_level(spdlog::level::trace); + m_EngineLogger->set_level(spdlog::level::trace); + m_ClientLogger->set_level(spdlog::level::trace); #elif defined (LIGHT_RELEASE) s_EngineLogger->set_level(spdlog::level::info); s_ClientLogger->set_level(spdlog::level::info); @@ -43,9 +51,9 @@ namespace Light { // #todo: improve LT_ENGINE_INFO("________________________________________"); LT_ENGINE_INFO("Logger::"); - LT_ENGINE_INFO(" ClientLevel : {}", Stringifier::spdlogLevel(s_ClientLogger->level())); - LT_ENGINE_INFO(" EngineLevel : {}", Stringifier::spdlogLevel(s_EngineLogger->level())); - LT_ENGINE_INFO(" FileLevel : {}", Stringifier::spdlogLevel(s_FileLogger->level())); + LT_ENGINE_INFO(" ClientLevel : {}", Stringifier::spdlogLevel(m_ClientLogger->level())); + LT_ENGINE_INFO(" EngineLevel : {}", Stringifier::spdlogLevel(m_EngineLogger->level())); + LT_ENGINE_INFO(" FileLevel : {}", Stringifier::spdlogLevel(m_FileLogger->level())); LT_ENGINE_INFO(" DefaultLevel: {}", Stringifier::spdlogLevel(spdlog::get_level())); LT_ENGINE_INFO("________________________________________"); } diff --git a/Engine/src/Engine/Debug/Logger.h b/Engine/src/Engine/Debug/Logger.h index 3517510..9b12ce1 100644 --- a/Engine/src/Engine/Debug/Logger.h +++ b/Engine/src/Engine/Debug/Logger.h @@ -1,13 +1,13 @@ #pragma once #define LT_LOGGER_H -#include "Base.h" +#include "Base/Base.h" #include // LOGGER MACROS // -#define LT_LOG_FILE_LOCATION "Logs/Logger.txt"; +#define LT_LOG_FILE_LOCATION "Logs/Logger.txt" // File #define LT_FILE_INFO(...) ::Light::Logger::GetFileLogger()->log(spdlog::level::info , __VA_ARGS__) @@ -48,19 +48,22 @@ namespace Light { class Logger { private: - static Ref s_EngineLogger, s_ClientLogger, s_FileLogger; - static std::string s_LogFilePath; + static Logger* s_Context; + + Ref m_EngineLogger, m_ClientLogger, m_FileLogger; + std::string m_LogFilePath; public: - Logger() = delete; + static Scope Create(); - static void Initialize(); + static inline Ref GetEngineLogger() { return s_Context->m_EngineLogger; } + static inline Ref GetClientLogger() { return s_Context->m_ClientLogger; } + static inline Ref GetFileLogger() { return s_Context->m_FileLogger; } - static inline Ref GetEngineLogger() { return s_EngineLogger; } - static inline Ref GetClientLogger() { return s_ClientLogger; } - static inline Ref GetFileLogger() { return s_FileLogger; } + void LogDebugData(); - static void LogDebugData(); + private: + Logger(); }; } diff --git a/Engine/src/Engine/Events/Event.h b/Engine/src/Engine/Events/Event.h index 65a95a5..509ff6f 100644 --- a/Engine/src/Engine/Events/Event.h +++ b/Engine/src/Engine/Events/Event.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { diff --git a/Engine/src/Engine/Events/KeyboardEvents.h b/Engine/src/Engine/Events/KeyboardEvents.h index 839a44c..6f5d9d4 100644 --- a/Engine/src/Engine/Events/KeyboardEvents.h +++ b/Engine/src/Engine/Events/KeyboardEvents.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Event.h" +#include "Base/Base.h" + #include namespace Light { @@ -13,7 +14,10 @@ namespace Light { const int m_Key; public: - KeyPressedEvent(int key): m_Key(key) { } + KeyPressedEvent(int key) + : m_Key(key) + { + } inline int GetKey() const { return m_Key; } @@ -33,7 +37,10 @@ namespace Light { const int m_Key; public: - KeyReleasedEvent(int key): m_Key(key) { } + KeyReleasedEvent(int key) + : m_Key(key) + { + } inline int GetKey() const { return m_Key; } diff --git a/Engine/src/Engine/Events/MouseEvents.h b/Engine/src/Engine/Events/MouseEvents.h index e3732f4..70e2e1b 100644 --- a/Engine/src/Engine/Events/MouseEvents.h +++ b/Engine/src/Engine/Events/MouseEvents.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Event.h" +#include "Base/Base.h" + #include #include @@ -15,7 +16,10 @@ namespace Light { const glm::vec2 m_Position; public: - MouseMovedEvent(float x, float y) : m_Position(x, y) { } + MouseMovedEvent(float x, float y) + : m_Position(x, y) + { + } inline const glm::vec2& GetPosition() const { return m_Position; } @@ -38,7 +42,10 @@ namespace Light { const float m_Offset; public: - WheelScrolledEvent(float offset) : m_Offset(offset) { } + WheelScrolledEvent(float offset) + : m_Offset(offset) + { + } inline float GetOffset() const { return m_Offset; } @@ -58,7 +65,10 @@ namespace Light { const int m_Button; public: - ButtonPressedEvent(int button): m_Button(button) { } + ButtonPressedEvent(int button) + : m_Button(button) + { + } inline int GetButton() const { return m_Button; } @@ -78,7 +88,10 @@ namespace Light { const int m_Button; public: - ButtonReleasedEvent(int button) : m_Button(button) { } + ButtonReleasedEvent(int button) + : m_Button(button) + { + } inline int GetButton() const { return m_Button; } @@ -88,7 +101,6 @@ namespace Light { ss << "ButtonReleased: " << m_Button; return ss.str(); } - EVENT_TYPE(ButtonReleased) EVENT_CATEGORY(InputEventCategory | MouseEventCategory) }; diff --git a/Engine/src/Engine/Events/WindowEvents.h b/Engine/src/Engine/Events/WindowEvents.h index 7ed4d3e..4e79771 100644 --- a/Engine/src/Engine/Events/WindowEvents.h +++ b/Engine/src/Engine/Events/WindowEvents.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Event.h" +#include "Base/Base.h" + #include #include @@ -26,7 +27,10 @@ namespace Light { const glm::ivec2 m_Position; public: - WindowMovedEvent(int x, int y): m_Position(x, y) { } + WindowMovedEvent(int x, int y) + : m_Position(x, y) + { + } const glm::ivec2& GetPosition() const{ return m_Position; } @@ -46,7 +50,10 @@ namespace Light { const glm::uvec2 m_Size; public: - WindowResizedEvent(unsigned int width, unsigned int height): m_Size(width, height) { } + WindowResizedEvent(unsigned int width, unsigned int height) + : m_Size(width, height) + { + } const glm::uvec2& GetSize() const { return m_Size; } diff --git a/Engine/src/Engine/Graphics/Blender.cpp b/Engine/src/Engine/Graphics/Blender.cpp index 16c242f..25542d4 100644 --- a/Engine/src/Engine/Graphics/Blender.cpp +++ b/Engine/src/Engine/Graphics/Blender.cpp @@ -9,7 +9,6 @@ #include "GraphicsContext.h" - namespace Light { Scope Blender::Create(Ref sharedContext) diff --git a/Engine/src/Engine/Graphics/Blender.h b/Engine/src/Engine/Graphics/Blender.h index d310485..c771b40 100644 --- a/Engine/src/Engine/Graphics/Blender.h +++ b/Engine/src/Engine/Graphics/Blender.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { @@ -35,8 +35,6 @@ namespace Light { class Blender { - private: - public: static Scope Create(Ref sharedContext); diff --git a/Engine/src/Engine/Graphics/Buffers.cpp b/Engine/src/Engine/Graphics/Buffers.cpp index cd59060..301e692 100644 --- a/Engine/src/Engine/Graphics/Buffers.cpp +++ b/Engine/src/Engine/Graphics/Buffers.cpp @@ -13,7 +13,7 @@ namespace Light { - //* CONSTANT_BUFFER *// + //================================================== CONSTANT_BUFFER ==================================================// Scope ConstantBuffer::Create(ConstantBufferIndex index, unsigned int size, Ref sharedContext) { switch (GraphicsContext::GetGraphicsAPI()) @@ -29,8 +29,9 @@ namespace Light { return nullptr; } } + //================================================== CONSTANT_BUFFER ==================================================// - //* VERTEX_BUFFER *// + //================================================== VERTEX_BUFFER ==================================================// Ref VertexBuffer::Create(float* vertices, unsigned int stride, unsigned int count, Ref sharedContext) { switch (GraphicsContext::GetGraphicsAPI()) @@ -46,8 +47,9 @@ namespace Light { return nullptr; } } + //================================================== VERTEX_BUFFER ==================================================// - //* INDEX_BUFFER *// + //======================================== INDEX_BUFFER ========================================// Ref IndexBuffer::Create(unsigned int* indices, unsigned int count, Ref sharedContext) { switch (GraphicsContext::GetGraphicsAPI()) @@ -63,5 +65,6 @@ namespace Light { return nullptr; } } + //======================================== INDEX_BUFFER ========================================// } \ No newline at end of file diff --git a/Engine/src/Engine/Graphics/Buffers.h b/Engine/src/Engine/Graphics/Buffers.h index 86e4c5c..d237651 100644 --- a/Engine/src/Engine/Graphics/Buffers.h +++ b/Engine/src/Engine/Graphics/Buffers.h @@ -1,32 +1,32 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { class SharedContext; - enum ConstantBufferIndex + enum class ConstantBufferIndex { ViewProjection = 0u }; - //* CONSTANT_BUFFER *// + //========== CONSTANT_BUFFER ==========// class ConstantBuffer { public: static Scope Create(ConstantBufferIndex index, unsigned int size, Ref sharedContext); - virtual void Bind() = 0; - virtual void* Map() = 0; virtual void UnMap() = 0; + virtual void Bind() = 0; + protected: ConstantBuffer() = default; }; - //* VERTEX_BUFFER *// + //========== VERTEX_BUFFER ==========// class VertexBuffer { public: @@ -44,7 +44,7 @@ namespace Light { VertexBuffer() = default; }; - //* INDEX_BUFFER *// + //========== INDEX_BUFFER ==========// class IndexBuffer { public: diff --git a/Engine/src/Engine/Graphics/Framebuffer.h b/Engine/src/Engine/Graphics/Framebuffer.h index 2ed9a1d..9b9614c 100644 --- a/Engine/src/Engine/Graphics/Framebuffer.h +++ b/Engine/src/Engine/Graphics/Framebuffer.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include @@ -14,8 +14,6 @@ namespace Light { unsigned int samples = 1; glm::uvec4 defaultColor = glm::uvec4(0u); - - bool swapChainTarget = false; // render to the screen }; class Framebuffer @@ -23,12 +21,12 @@ namespace Light { public: static Ref Create(const FramebufferSpecification& specification, Ref sharedContext); - virtual void* GetColorAttachment() = 0; - virtual void BindAsTarget() = 0; virtual void BindAsResource() = 0; - virtual void Resize(const glm::vec2& size) = 0; + virtual void Resize(const glm::uvec2& size) = 0; + + virtual void* GetColorAttachment() = 0; protected: Framebuffer() = default; diff --git a/Engine/src/Engine/Graphics/GraphicsContext.cpp b/Engine/src/Engine/Graphics/GraphicsContext.cpp index ad671dc..ed9de44 100644 --- a/Engine/src/Engine/Graphics/GraphicsContext.cpp +++ b/Engine/src/Engine/Graphics/GraphicsContext.cpp @@ -7,17 +7,22 @@ #include "DirectX/dxSharedContext.h" #endif -// forward declaration -#include "Graphics/Renderer.h" -#include "Graphics/RenderCommand.h" -#include "UserInterface/UserInterface.h" -#include "Utility/ResourceManager.h" +#include "Blender.h" // required for forward declaration +#include "Buffers.h" // required for forward declaration +#include "Renderer.h" // required for forward declaration +#include "RenderCommand.h" // required for forward declaration + +#include "UserInterface/UserInterface.h" // required for forward declaration + +#include "Utility/ResourceManager.h" // required for forward declaration namespace Light { GraphicsContext* GraphicsContext::s_Context = nullptr; - GraphicsContext::~GraphicsContext() {} + GraphicsContext::~GraphicsContext() + { + } Scope GraphicsContext::Create(GraphicsAPI api, GLFWwindow* windowHandle) { @@ -46,11 +51,12 @@ namespace Light { Scope scopeGfx; switch (api) { + // opengl case GraphicsAPI::OpenGL: scopeGfx = CreateScope(windowHandle); s_Context = scopeGfx.get(); break; - + // directx case GraphicsAPI::DirectX: LT_WIN( scopeGfx = CreateScope(windowHandle); s_Context = scopeGfx.get(); diff --git a/Engine/src/Engine/Graphics/GraphicsContext.h b/Engine/src/Engine/Graphics/GraphicsContext.h index 6a5d1ef..bcc03a2 100644 --- a/Engine/src/Engine/Graphics/GraphicsContext.h +++ b/Engine/src/Engine/Graphics/GraphicsContext.h @@ -1,17 +1,18 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" struct GLFWwindow; namespace Light { - class ResourceManager; - class UserInterface; class Renderer; - + class ResourceManager; class SharedContext; + class UserInterface; + + class WindowResizedEvent; enum class GraphicsAPI diff --git a/Engine/src/Engine/Graphics/RenderCommand.h b/Engine/src/Engine/Graphics/RenderCommand.h index 34275bb..449ba0c 100644 --- a/Engine/src/Engine/Graphics/RenderCommand.h +++ b/Engine/src/Engine/Graphics/RenderCommand.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include diff --git a/Engine/src/Engine/Graphics/Renderer.cpp b/Engine/src/Engine/Graphics/Renderer.cpp index 2208394..241c38d 100644 --- a/Engine/src/Engine/Graphics/Renderer.cpp +++ b/Engine/src/Engine/Graphics/Renderer.cpp @@ -3,14 +3,14 @@ #include "Blender.h" #include "Buffers.h" -#include "Texture.h" -#include "RenderCommand.h" #include "Framebuffer.h" - -#include "Events/WindowEvents.h" +#include "RenderCommand.h" +#include "Texture.h" #include "Camera/Camera.h" +#include "Events/WindowEvents.h" + #include #include #include @@ -21,17 +21,20 @@ namespace Light { Renderer::Renderer(GLFWwindow* windowHandle, Ref sharedContext) : m_QuadRenderer(LT_MAX_QUAD_RENDERER_VERTICES, sharedContext), - m_TextureRenderer(LT_MAX_TEXTURE_RENDERER_VERTICES, sharedContext) + m_TextureRenderer(LT_MAX_TEXTURE_RENDERER_VERTICES, sharedContext), + m_ViewProjectionBuffer(nullptr), + m_RenderCommand(nullptr), + m_Blender(nullptr), + m_Camera(nullptr), + m_TargetFramebuffer(nullptr) { LT_ENGINE_ASSERT(!s_Context, "Renderer::Renderer: an instance of 'Renderer' already exists, do not construct this class!"); s_Context = this; - m_RenderCommand = RenderCommand::Create(windowHandle, sharedContext); - m_ViewProjectionBuffer = ConstantBuffer::Create(ConstantBufferIndex::ViewProjection, sizeof(glm::mat4), sharedContext); + m_RenderCommand = RenderCommand::Create(windowHandle, sharedContext); m_Blender = Blender::Create(sharedContext); - m_Blender->Enable(BlendFactor::SRC_ALPHA, BlendFactor::INVERSE_SRC_ALPHA); } Scope Renderer::Create(GLFWwindow* windowHandle, Ref sharedContext) @@ -44,6 +47,7 @@ namespace Light { m_RenderCommand->SetViewport(0u, 0u, event.GetSize().x, event.GetSize().y); } + //======================================== DRAW_QUAD_TINT ========================================// void Renderer::DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint) { // locals @@ -54,19 +58,19 @@ namespace Light { const float xMax = position.x + size.x; const float yMax = position.y + size.y; - //** TOP_LEFT **// + // top left bufferMap[0].position = { xMin, yMin, position.z }; bufferMap[0].tint = tint; - //** TOP_RIGHT **// + // top right bufferMap[1].position = { xMax, yMin, position.z }; bufferMap[1].tint = tint; - //** BOTTOM_RIGHT **// + // bottom right bufferMap[2].position = { xMax, yMax, position.z }; bufferMap[2].tint = tint; - //** BOTTOM_LEFT **// + // bottom left bufferMap[3].position = { xMin, yMax, position.z }; bufferMap[3].tint = tint; @@ -77,7 +81,9 @@ namespace Light { FlushScene(); } } + //======================================== DRAW_QUAD_TINT ========================================// + //============================== DRAW_QUAD_TEXTURE ==============================// void Renderer::DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, Ref texture) { // #todo: implement a proper binding @@ -91,19 +97,19 @@ namespace Light { const float xMax = position.x + size.x; const float yMax = position.y + size.y; - //** TOP_LEFT **// + // top left bufferMap[0].position = { xMin, yMin, position.z }; bufferMap[0].texcoord = { 0.0f, 0.0f }; - //** TOP_RIGHT **// + // top right bufferMap[1].position = { xMax, yMin, position.z }; bufferMap[1].texcoord = { 1.0f, 0.0f }; - //** BOTTOM_RIGHT **// + // bottom right bufferMap[2].position = { xMax, yMax, position.z }; bufferMap[2].texcoord = { 1.0f, 1.0f }; - //** BOTTOM_LEFT **// + // bottom left bufferMap[3].position = { xMin, yMax, position.z }; bufferMap[3].texcoord = { 0.0f, 1.0f }; @@ -114,6 +120,7 @@ namespace Light { FlushScene(); } } + //============================== DRAW_QUAD_TEXTURE ==============================// void Renderer::BeginFrame() { @@ -127,6 +134,7 @@ namespace Light { void Renderer::BeginSceneImpl(const Ref& camera, const Ref& targetFrameBuffer /* = nullptr */) { + // determine the target frame buffer m_TargetFramebuffer = targetFrameBuffer; if (targetFrameBuffer) @@ -134,12 +142,13 @@ namespace Light { else m_RenderCommand->DefaultTargetFramebuffer(); - + // update view projection buffer m_Camera = camera; glm::mat4* map = (glm::mat4*)m_ViewProjectionBuffer->Map(); map[0] = m_Camera->GetProjection() * m_Camera->GetView(); m_ViewProjectionBuffer->UnMap(); + // map renderers m_QuadRenderer.Map(); m_TextureRenderer.Map(); } @@ -154,25 +163,26 @@ namespace Light { void Renderer::EndSceneImpl() { - // m_Blender->Disable(); + // enable blending m_Blender->Enable(BlendFactor::SRC_ALPHA, BlendFactor::INVERSE_SRC_ALPHA); - m_QuadRenderer.UnMap(); - m_TextureRenderer.UnMap(); - //** QUAD_RENDERER **// + /* quad renderer */ + m_QuadRenderer.UnMap(); if (m_QuadRenderer.GetQuadCount()) { m_QuadRenderer.Bind(); m_RenderCommand->DrawIndexed(m_QuadRenderer.GetQuadCount() * 6u); } - //** TEXT_RENDERER **// + /* text renderer */ + m_TextureRenderer.UnMap(); if (m_TextureRenderer.GetQuadCount()) { m_TextureRenderer.Bind(); m_RenderCommand->DrawIndexed(m_TextureRenderer.GetQuadCount() * 6u); } + // reset frame buffer if(m_TargetFramebuffer) { m_TargetFramebuffer = nullptr; diff --git a/Engine/src/Engine/Graphics/Renderer.h b/Engine/src/Engine/Graphics/Renderer.h index 3bfd16f..ecce65b 100644 --- a/Engine/src/Engine/Graphics/Renderer.h +++ b/Engine/src/Engine/Graphics/Renderer.h @@ -1,10 +1,6 @@ #pragma once -#include "Base.h" - -#include "Buffers.h" -#include "Blender.h" -#include "Framebuffer.h" +#include "Base/Base.h" #include "RendererPrograms/QuadRendererProgram.h" #include "RendererPrograms/TextureRendererProgram.h" @@ -16,19 +12,18 @@ struct GLFWwindow; namespace Light { - class RenderCommand; class Blender; - + class ConstantBuffer; class Framebuffer; + class RenderCommand; + class Texture; + + class SharedContext; class Camera; - class Texture; - class WindowResizedEvent; - class SharedContext; - class Renderer { private: @@ -44,15 +39,12 @@ namespace Light { Scope m_RenderCommand; Scope m_Blender; - Ref m_TargetFramebuffer; - Ref m_Camera; + Ref m_TargetFramebuffer; public: static Scope Create(GLFWwindow* windowHandle, Ref sharedContext); - static inline void SetTargetFramebuffer(Ref framebuffer) { s_Context->SetTargetFramebufferImpl(framebuffer); } - static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint) { s_Context->DrawQuadImpl(position, size, tint); } static inline void DrawQuad(const glm::vec3& position, const glm::vec2& size, Ref texture) { s_Context->DrawQuadImpl(position, size, texture); } @@ -67,8 +59,6 @@ namespace Light { private: Renderer(GLFWwindow* windowHandle, Ref sharedContext); - void SetTargetFramebufferImpl(Ref framebuffer); - void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, const glm::vec4& tint); void DrawQuadImpl(const glm::vec3& position, const glm::vec2& size, Ref texture); diff --git a/Engine/src/Engine/Graphics/RendererPrograms/QuadRendererProgram.cpp b/Engine/src/Engine/Graphics/RendererPrograms/QuadRendererProgram.cpp index c587e63..86bc7ad 100644 --- a/Engine/src/Engine/Graphics/RendererPrograms/QuadRendererProgram.cpp +++ b/Engine/src/Engine/Graphics/RendererPrograms/QuadRendererProgram.cpp @@ -12,8 +12,15 @@ namespace Light { QuadRendererProgram::QuadRendererProgram(unsigned int maxVertices, Ref sharedContext) - : m_MaxVertices(maxVertices) + : m_Shader(nullptr), + m_IndexBuffer(nullptr), + m_VertexLayout(nullptr), + m_MapCurrent(nullptr), + m_MapEnd(nullptr), + m_QuadCount(0u), + m_MaxVertices(maxVertices) { + // #todo: don't use relative path ResourceManager::LoadShader("LT_ENGINE_RESOURCES_QUAD_SHADER", "../Engine/res/Shaders/Quad/Quad_VS", "../Engine//res/Shaders/Quad/Quad_PS"); m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_QUAD_SHADER"); @@ -36,12 +43,6 @@ namespace Light { return true; } - void QuadRendererProgram::SetCamera(const Camera& camera) - { - m_Shader->Bind(); - m_Shader->SetUniformMat4("u_ViewProjection", camera.GetProjection() * camera.GetView()); - } - void QuadRendererProgram::Map() { m_QuadCount = 0u; diff --git a/Engine/src/Engine/Graphics/RendererPrograms/QuadRendererProgram.h b/Engine/src/Engine/Graphics/RendererPrograms/QuadRendererProgram.h index e1534e7..41defeb 100644 --- a/Engine/src/Engine/Graphics/RendererPrograms/QuadRendererProgram.h +++ b/Engine/src/Engine/Graphics/RendererPrograms/QuadRendererProgram.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "RendererProgram.h" +#include "Base/Base.h" + #include namespace Light { @@ -41,8 +42,6 @@ namespace Light { QuadRendererProgram(unsigned int maxVertices, Ref sharedContext); bool Advance(); - - void SetCamera(const Camera& camera) override; void Map() override; void UnMap() override; diff --git a/Engine/src/Engine/Graphics/RendererPrograms/RendererProgram.h b/Engine/src/Engine/Graphics/RendererPrograms/RendererProgram.h index c716b00..cee4fdd 100644 --- a/Engine/src/Engine/Graphics/RendererPrograms/RendererProgram.h +++ b/Engine/src/Engine/Graphics/RendererPrograms/RendererProgram.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { @@ -8,9 +8,6 @@ namespace Light { class RendererProgram { - virtual void SetCamera(const Camera& camera) = 0; - - virtual void Map() = 0; virtual void UnMap() = 0; diff --git a/Engine/src/Engine/Graphics/RendererPrograms/TextureRendererProgram.cpp b/Engine/src/Engine/Graphics/RendererPrograms/TextureRendererProgram.cpp index a57f859..04d8dad 100644 --- a/Engine/src/Engine/Graphics/RendererPrograms/TextureRendererProgram.cpp +++ b/Engine/src/Engine/Graphics/RendererPrograms/TextureRendererProgram.cpp @@ -12,8 +12,15 @@ namespace Light { TextureRendererProgram::TextureRendererProgram(unsigned int maxVertices, Ref sharedContext) - : m_MaxVertices(maxVertices) + : m_Shader(nullptr), + m_IndexBuffer(nullptr), + m_VertexLayout(nullptr), + m_MapCurrent(nullptr), + m_MapEnd(nullptr), + m_QuadCount(0u), + m_MaxVertices(maxVertices) { + // #todo: don't use relative path ResourceManager::LoadShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER", "../Engine/res/Shaders/Texture/Texture_VS", "../Engine/res/Shaders/Texture/Texture_PS"); m_Shader = ResourceManager::GetShader("LT_ENGINE_RESOURCES_TEXTURE_SHADER"); @@ -36,12 +43,6 @@ namespace Light { return true; } - void TextureRendererProgram::SetCamera(const Camera& camera) - { - m_Shader->Bind(); - m_Shader->SetUniformMat4("u_ViewProjection", camera.GetProjection() * camera.GetView()); - } - void TextureRendererProgram::Map() { m_QuadCount = 0u; @@ -62,4 +63,5 @@ namespace Light { m_VertexBuffer->Bind(); m_IndexBuffer->Bind(); } + } \ No newline at end of file diff --git a/Engine/src/Engine/Graphics/RendererPrograms/TextureRendererProgram.h b/Engine/src/Engine/Graphics/RendererPrograms/TextureRendererProgram.h index 490997d..7f7e084 100644 --- a/Engine/src/Engine/Graphics/RendererPrograms/TextureRendererProgram.h +++ b/Engine/src/Engine/Graphics/RendererPrograms/TextureRendererProgram.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "RendererProgram.h" +#include "Base/Base.h" + #include namespace Light { @@ -34,23 +35,23 @@ namespace Light { TextureVertexData* m_MapCurrent = nullptr; TextureVertexData* m_MapEnd = nullptr; - unsigned int m_QuadCount = 0u; - unsigned int m_MaxVertices = 0u; + unsigned int m_QuadCount; + unsigned int m_MaxVertices; public: TextureRendererProgram(unsigned int maxVertices, Ref sharedContext); bool Advance(); - void SetCamera(const Camera& camera) override; - void Map() override; void UnMap() override; void Bind() override; inline TextureVertexData* GetMapCurrent() { return m_MapCurrent; } + inline unsigned int GetQuadCount() const { return m_QuadCount; } + inline constexpr unsigned int GetVertexSize() const { return sizeof(TextureVertexData); } }; diff --git a/Engine/src/Engine/Graphics/Shader.h b/Engine/src/Engine/Graphics/Shader.h index e2a07db..cc37914 100644 --- a/Engine/src/Engine/Graphics/Shader.h +++ b/Engine/src/Engine/Graphics/Shader.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include @@ -18,14 +18,8 @@ namespace Light { virtual void Bind() = 0; virtual void UnBind() = 0; - //** #TEMP_SHADER_UNIFORMS_TEMP# **// - virtual void SetUniformMat4(const std::string& name, const glm::mat4& value) = 0; - protected: Shader() = default; - - private: - static void ExtractShaderSource(std::string& src, const std::string& delim); }; } \ No newline at end of file diff --git a/Engine/src/Engine/Graphics/SharedContext.h b/Engine/src/Engine/Graphics/SharedContext.h index 5b5ebbf..a332b86 100644 --- a/Engine/src/Engine/Graphics/SharedContext.h +++ b/Engine/src/Engine/Graphics/SharedContext.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { diff --git a/Engine/src/Engine/Graphics/Texture.h b/Engine/src/Engine/Graphics/Texture.h index 65664cd..1539181 100644 --- a/Engine/src/Engine/Graphics/Texture.h +++ b/Engine/src/Engine/Graphics/Texture.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { diff --git a/Engine/src/Engine/Graphics/VertexLayout.h b/Engine/src/Engine/Graphics/VertexLayout.h index ce874d5..0d4f4d9 100644 --- a/Engine/src/Engine/Graphics/VertexLayout.h +++ b/Engine/src/Engine/Graphics/VertexLayout.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { diff --git a/Engine/src/Engine/Input/Input.cpp b/Engine/src/Engine/Input/Input.cpp index 66f518a..7938650 100644 --- a/Engine/src/Engine/Input/Input.cpp +++ b/Engine/src/Engine/Input/Input.cpp @@ -17,6 +17,13 @@ namespace Light { } Input::Input() + : m_KeyboadKeys{}, + m_MouseButtons{}, + m_MousePosition{}, + m_MouseDelta{}, + m_MouseWheelDelta{}, + m_UserInterfaceEvents(true), + m_GameEvents(true) { LT_ENGINE_ASSERT(!s_Context, "Input::Input: an instance of 'Input' already exists, do not construct this class!"); s_Context = this; diff --git a/Engine/src/Engine/Input/Input.h b/Engine/src/Engine/Input/Input.h index f9454a4..ff2b0b8 100644 --- a/Engine/src/Engine/Input/Input.h +++ b/Engine/src/Engine/Input/Input.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include @@ -20,8 +20,9 @@ namespace Light { glm::vec2 m_MouseDelta; float m_MouseWheelDelta; - bool m_UserInterfaceEvents = true; - bool m_GameEvents = true; + bool m_UserInterfaceEvents; + bool m_GameEvents; + public: static Scope Create(); diff --git a/Engine/src/Engine/Input/KeyCodes.h b/Engine/src/Engine/Input/KeyCodes.h index 773b751..5e68d09 100644 --- a/Engine/src/Engine/Input/KeyCodes.h +++ b/Engine/src/Engine/Input/KeyCodes.h @@ -10,7 +10,7 @@ namespace Light { { enum : uint16_t { - /* DIGITS */ + /* digits */ D0 = 48, D1 = 49, D2 = 50, @@ -24,7 +24,7 @@ namespace Light { Semicolon = 59, // ; Equal = 61, // = - /* LETTERS */ + /* letters */ A = 65, B = 66, C = 67, @@ -52,13 +52,13 @@ namespace Light { Y = 89, Z = 90, - /* BRACKETS */ + /* brackets */ LeftBracket = 91, // [ LBracket = LeftBracket, // [ RightBracket = 93, // ] RBracket = RightBracket, // ] - /* ARROW */ + /* arrow */ Right = 262, RightArrow = Right, RArrow = Right, @@ -72,25 +72,21 @@ namespace Light { UpArrow = Up, UArrow = Up, - /* PAGE */ + /* page */ PageUp = 266, PageDown = 267, - /* HOME/END */ + /* home/end */ Home = 268, End = 269, - /* LOCKS */ + /* toggles */ CapsLock = 280, ScrollLock = 281, NumLock = 282, NumberLock = NumLock, - - PrintScreen = 283, - Pause = 284, - - /* FUNCTION */ + /* function */ F1 = 290, F2 = 291, F3 = 292, @@ -117,7 +113,7 @@ namespace Light { F24 = 313, F25 = 314, - /* KEYPAD */ + /* keypad */ Kp0 = 320, Kp1 = 321, Kp2 = 322, @@ -136,7 +132,7 @@ namespace Light { KpEnter = 335, KpEqual = 336, - /* Modifiers */ + /* modifiers */ LeftShift = 340, LShift = LeftShift, LeftControl = 341, @@ -154,10 +150,17 @@ namespace Light { RightSuper = 347, RSuper = 347, - /* MISC */ + /* misc */ Space = 32, Apostrophe = 39, // ' Quote = Apostrophe, + + Comma = 44, // , + Minus = 45, // - + Period = 46, // . + Slash = 47, // / + ForwardSlash = Slash, // / + BackSlash = 92, // \ GraveAccent = 96, // ` Console = GraveAccent, @@ -171,14 +174,11 @@ namespace Light { Insert = 260, Delete = 261, - Comma = 44, // , - Minus = 45, // - - Period = 46, // . - Slash = 47, // / - ForwardSlash = Slash, // / - BackSlash = 92, // \ + PrintScreen = 283, + Pause = 284, Menu = 348, + }; } diff --git a/Engine/src/Engine/Input/MouseCodes.h b/Engine/src/Engine/Input/MouseCodes.h index 115d048..9528026 100644 --- a/Engine/src/Engine/Input/MouseCodes.h +++ b/Engine/src/Engine/Input/MouseCodes.h @@ -10,18 +10,18 @@ namespace Light { { enum : uint8_t { - Button1 = 0, - Button2 = 1, - Button3 = 2, - Button4 = 3, - Button5 = 4, - Button6 = 5, - Button7 = 6, - Button8 = 7, - - LButton = Button1, - RButton = Button2, - MButton = Button3, + Button1 = 0, + Button2 = 1, + Button3 = 2, + Button4 = 3, + Button5 = 4, + Button6 = 5, + Button7 = 6, + Button8 = 7, + + LButton = Button1, + RButton = Button2, + MButton = Button3, }; } diff --git a/Engine/src/Engine/Layer/Layer.cpp b/Engine/src/Engine/Layer/Layer.cpp index e3cbd76..939d511 100644 --- a/Engine/src/Engine/Layer/Layer.cpp +++ b/Engine/src/Engine/Layer/Layer.cpp @@ -2,17 +2,22 @@ #include "Layer.h" #include "Events/Event.h" -#include "Events/MouseEvents.h" #include "Events/KeyboardEvents.h" +#include "Events/MouseEvents.h" #include "Events/WindowEvents.h" namespace Light { + Layer::Layer(const std::string& name) + : m_LayerName(name) + { + } + bool Layer::OnEvent(const Event& event) { switch (event.GetEventType()) { - //** MOUSE_EVENTS **// + /* mouse */ case EventType::MouseMoved: return OnMouseMoved((MouseMovedEvent&)event); case EventType::ButtonPressed: @@ -22,13 +27,13 @@ namespace Light { case EventType::WheelScrolled: return OnWheelScrolled((WheelScrolledEvent&)event); - //** KEYBOARD_EVENTS **// + /* keyboard */ case EventType::KeyPressed: return OnKeyPressed((KeyPressedEvent&)event); case EventType::KeyReleased: return OnKeyReleased((KeyReleasedEvent&)event); - //** WINDOW_EVENTS **// + /* window */ case EventType::WindowClosed: return OnWindowClosed((WindowClosedEvent&)event); case EventType::WindowResized: diff --git a/Engine/src/Engine/Layer/Layer.h b/Engine/src/Engine/Layer/Layer.h index 2568da6..0879b21 100644 --- a/Engine/src/Engine/Layer/Layer.h +++ b/Engine/src/Engine/Layer/Layer.h @@ -1,19 +1,22 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { class Event; + // mouse class MouseMovedEvent; class ButtonPressedEvent; class ButtonReleasedEvent; class WheelScrolledEvent; + // keyboard class KeyPressedEvent; class KeyReleasedEvent; + // window class WindowClosedEvent; class WindowResizedEvent; class WindowMovedEvent; @@ -26,12 +29,12 @@ namespace Light { std::string m_LayerName; public: - Layer(const std::string& name): m_LayerName(name) {} + Layer(const std::string& name); virtual ~Layer() = default; inline const std::string& GetName() const { return m_LayerName; } - //** UPDATES // + /* update */ virtual void OnUpdate(float deltaTime) {} virtual void OnUserInterfaceUpdate() {} @@ -40,17 +43,17 @@ namespace Light { bool OnEvent(const Event& event); protected: - //** MOUSE_EVENTS // + /* mouse */ virtual bool OnMouseMoved(const MouseMovedEvent& event) { return false; } virtual bool OnButtonPressed(const ButtonPressedEvent& event) { return false; } virtual bool OnButtonReleased(const ButtonReleasedEvent& event) { return false; } virtual bool OnWheelScrolled(const WheelScrolledEvent& event) { return false; } - //** KEYBOARD_EVENTS **// + /* keyboard */ virtual bool OnKeyPressed(const KeyPressedEvent& event) { return false; } virtual bool OnKeyReleased(const KeyReleasedEvent& event) { return false; } - //** WINDOW_EVENTS **/ + /* window */ virtual bool OnWindowClosed(const WindowClosedEvent& event) { return false; } virtual bool OnWindowResized(const WindowResizedEvent& event) { return false; } virtual bool OnWindowMoved(const WindowMovedEvent& event) { return false; } diff --git a/Engine/src/Engine/Layer/LayerStack.cpp b/Engine/src/Engine/Layer/LayerStack.cpp index 5d1c384..41c14ab 100644 --- a/Engine/src/Engine/Layer/LayerStack.cpp +++ b/Engine/src/Engine/Layer/LayerStack.cpp @@ -18,6 +18,9 @@ namespace Light { } LayerStack::LayerStack() + : m_Layers{}, + m_Begin(), + m_End() { LT_ENGINE_ASSERT(!s_Context, "LayerStack::LayerStack: an instance of 'LayerStack' already exists, do not construct this class!") s_Context = this; diff --git a/Engine/src/Engine/Layer/LayerStack.h b/Engine/src/Engine/Layer/LayerStack.h index 80c0bf3..8af8c0c 100644 --- a/Engine/src/Engine/Layer/LayerStack.h +++ b/Engine/src/Engine/Layer/LayerStack.h @@ -1,10 +1,11 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { class Layer; + class Event; class LayerStack @@ -22,7 +23,7 @@ namespace Light { ~LayerStack(); - // #todo: should we keep this? + // #todo: is this needed? template static inline void EmplaceLayer(Args&&... args) { s_Context->AttachLayerImpl(new T((args)...)); } diff --git a/Engine/src/Engine/Scene/Components.h b/Engine/src/Engine/Scene/Components.h index f54ce85..964befb 100644 --- a/Engine/src/Engine/Scene/Components.h +++ b/Engine/src/Engine/Scene/Components.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include diff --git a/Engine/src/Engine/Scene/Entity.h b/Engine/src/Engine/Scene/Entity.h index efd13b1..713e2d7 100644 --- a/Engine/src/Engine/Scene/Entity.h +++ b/Engine/src/Engine/Scene/Entity.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include "Scene.h" @@ -15,8 +15,7 @@ namespace Light { Scene* m_Scene; public: - Entity(){} - Entity(entt::entity handle, Scene* registry); + Entity(entt::entity handle = entt::entity(), Scene* registry = nullptr); ~Entity(); template @@ -24,7 +23,6 @@ namespace Light { { return m_Scene->m_Registry.emplace(m_Handle, std::forward(args)...); } - }; } \ No newline at end of file diff --git a/Engine/src/Engine/Scene/Scene.cpp b/Engine/src/Engine/Scene/Scene.cpp index 2262775..9dfa6b5 100644 --- a/Engine/src/Engine/Scene/Scene.cpp +++ b/Engine/src/Engine/Scene/Scene.cpp @@ -1,8 +1,8 @@ #include "ltpch.h" #include "Scene.h" -#include "Entity.h" #include "Components.h" +#include "Entity.h" #include "Graphics/Renderer.h" @@ -11,6 +11,7 @@ namespace Light { Scene::Scene() + : m_Registry() { } @@ -22,10 +23,9 @@ namespace Light { { auto group = m_Registry.group(entt::get); - group.each([](TransformComponent& transform, SpriteRendererComponent& sprite) { + group.each([](auto& transform, auto& sprite) { Renderer::DrawQuad(glm::vec3(transform.position, 0.0f), transform.size, sprite.texture); }); - } Entity Scene::CreateEntity(const std::string& name, const glm::vec2& position, const glm::vec2& size) @@ -34,7 +34,6 @@ namespace Light { entity.AddComponent(position, size); return entity; - } } diff --git a/Engine/src/Engine/Scene/Scene.h b/Engine/src/Engine/Scene/Scene.h index 5fa0097..9cbb327 100644 --- a/Engine/src/Engine/Scene/Scene.h +++ b/Engine/src/Engine/Scene/Scene.h @@ -1,11 +1,11 @@ #pragma once -#include "Base.h" - -#include +#include "Base/Base.h" #include +#include + namespace Light { class Entity; diff --git a/Engine/src/Engine/Time/Timer.cpp b/Engine/src/Engine/Time/Timer.cpp index 8e379fd..1a75cbc 100644 --- a/Engine/src/Engine/Time/Timer.cpp +++ b/Engine/src/Engine/Time/Timer.cpp @@ -3,6 +3,17 @@ namespace Light { + Timer::Timer() + : m_Start(std::chrono::steady_clock::now()) + { + } + + DeltaTimer::DeltaTimer() + : m_PreviousFrame(NULL), + m_DeltaTime(60.0f / 1000.0f) + { + } + void DeltaTimer::Update() { float currentFrame = timer.GetElapsedTime(); diff --git a/Engine/src/Engine/Time/Timer.h b/Engine/src/Engine/Time/Timer.h index afdb6a3..3e034b0 100644 --- a/Engine/src/Engine/Time/Timer.h +++ b/Engine/src/Engine/Time/Timer.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include @@ -12,7 +12,7 @@ namespace Light { std::chrono::time_point m_Start; public: - Timer() : m_Start(std::chrono::steady_clock::now()) { } + Timer(); inline float GetElapsedTime() const { return (std::chrono::duration_cast(std::chrono::steady_clock::now() - m_Start).count()) / 1000.; } @@ -24,10 +24,12 @@ namespace Light { private: Timer timer; - float m_PreviousFrame = 0.0f; - float m_DeltaTime = 60.0f / 1000.0f; + float m_PreviousFrame; + float m_DeltaTime; public: + DeltaTimer(); + void Update(); inline float GetDeltaTime() const { return m_DeltaTime; } diff --git a/Engine/src/Engine/UserInterface/UserInterface.cpp b/Engine/src/Engine/UserInterface/UserInterface.cpp index e1fde69..aa2ba47 100644 --- a/Engine/src/Engine/UserInterface/UserInterface.cpp +++ b/Engine/src/Engine/UserInterface/UserInterface.cpp @@ -7,12 +7,12 @@ #include "DirectX/dxSharedContext.h" #endif -#include "Graphics/GraphicsContext.h" - #include "Events/Event.h" #include "Events/MouseEvents.h" #include "Events/KeyboardEvents.h" +#include "Graphics/GraphicsContext.h" + #include namespace Light { @@ -38,7 +38,7 @@ namespace Light { ImGuiIO& io = ImGui::GetIO(); switch (inputEvent.GetEventType()) { - //** MOUSE_EVENTS **// + /* mouse events */ case EventType::MouseMoved: { const MouseMovedEvent& event = (const MouseMovedEvent&)inputEvent; @@ -63,7 +63,7 @@ namespace Light { ImGui::GetIO().MouseWheel = event.GetOffset(); return; } - //** MOUSE_EVENTS **// + /* keyboard events */ case EventType::KeyPressed: { const KeyPressedEvent& event = (const KeyPressedEvent&)inputEvent; diff --git a/Engine/src/Engine/UserInterface/UserInterface.h b/Engine/src/Engine/UserInterface/UserInterface.h index f268a3f..f224eb8 100644 --- a/Engine/src/Engine/UserInterface/UserInterface.h +++ b/Engine/src/Engine/UserInterface/UserInterface.h @@ -1,12 +1,13 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" struct GLFWwindow; namespace Light { class Event; + class SharedContext; class UserInterface diff --git a/Engine/src/Engine/Utility/ResourceManager.cpp b/Engine/src/Engine/Utility/ResourceManager.cpp index c02535f..1fb3d9b 100644 --- a/Engine/src/Engine/Utility/ResourceManager.cpp +++ b/Engine/src/Engine/Utility/ResourceManager.cpp @@ -17,7 +17,9 @@ namespace Light { } ResourceManager::ResourceManager(Ref sharedContext) - : m_SharedContext(sharedContext) + : m_SharedGraphicsContext(sharedContext), + m_Shaders{}, + m_Textures{} { LT_ENGINE_ASSERT(!s_Context, "ResourceManager::ResourceManager: an instance of 'ResourceManager' already exists, do not construct this class!"); s_Context = this; @@ -45,7 +47,7 @@ namespace Light { ResourceManager::ExtractShaderSource(psSource, delim); // create shader - m_Shaders[name] = Ref(Shader::Create(vsSource, psSource, m_SharedContext)); + m_Shaders[name] = Ref(Shader::Create(vsSource, psSource, m_SharedGraphicsContext)); } void ResourceManager::LoadShaderImpl(const std::string& name, const std::string& vertexPath, const std::string& pixelPath) @@ -70,7 +72,7 @@ namespace Light { psSS << line << '\n'; // create shader - m_Shaders[name] = Ref(Shader::Create(vsSS.str(), psSS.str(), m_SharedContext)); + m_Shaders[name] = Ref(Shader::Create(vsSS.str(), psSS.str(), m_SharedGraphicsContext)); } void ResourceManager::LoadTextureImpl(const std::string& name, const std::string& path, unsigned int desiredComponents /* = 4u */) @@ -88,7 +90,7 @@ namespace Light { } // create texture - m_Textures[name] = Ref(Texture::Create(width, height, components, pixels, m_SharedContext)); + m_Textures[name] = Ref(Texture::Create(width, height, components, pixels, m_SharedGraphicsContext)); } void ResourceManager::ExtractShaderSource(std::string& src, const std::string& delim) diff --git a/Engine/src/Engine/Utility/ResourceManager.h b/Engine/src/Engine/Utility/ResourceManager.h index 243ea42..0409ce9 100644 --- a/Engine/src/Engine/Utility/ResourceManager.h +++ b/Engine/src/Engine/Utility/ResourceManager.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" namespace Light { @@ -15,11 +15,11 @@ namespace Light { private: static ResourceManager* s_Context; + Ref m_SharedGraphicsContext; + std::unordered_map> m_Shaders; std::unordered_map> m_Textures; - Ref m_SharedContext; - public: static Scope Create(Ref sharedContext); @@ -39,6 +39,7 @@ namespace Light { void LoadShaderImpl(const std::string& name, const std::string& vertexPath, const std::string& pixelPath); void LoadTextureImpl(const std::string& name, const std::string& path, unsigned int desiredComponents = 4u); + private: void ExtractShaderSource(std::string& src, const std::string& delim); }; diff --git a/Engine/src/Engine/Utility/Stringifier.cpp b/Engine/src/Engine/Utility/Stringifier.cpp index c50f6ff..2cf453f 100644 --- a/Engine/src/Engine/Utility/Stringifier.cpp +++ b/Engine/src/Engine/Utility/Stringifier.cpp @@ -9,6 +9,7 @@ namespace Light { + //============================== OPENGL ==============================// std::string Stringifier::glDebugMsgSeverity(unsigned int severity) { switch (severity) @@ -51,7 +52,9 @@ namespace Light { default: return "UNKNOWN"; } } + //============================== OPENGL ==============================// + //==================== SPDLOG ====================// std::string Stringifier::spdlogLevel(unsigned int level) { switch (level) @@ -66,7 +69,9 @@ namespace Light { default: return "UNKNOWN"; } } + //==================== SPDLOG ====================// + //==================== GRAPHICS_API ====================// std::string Stringifier::GraphicsAPIToString(GraphicsAPI api) { switch (api) @@ -79,5 +84,6 @@ namespace Light { default: return "UNKNOWN"; } } + //==================== GRAPHICS_API ====================// } \ No newline at end of file diff --git a/Engine/src/Engine/Utility/Stringifier.h b/Engine/src/Engine/Utility/Stringifier.h index e74db29..7d5152b 100644 --- a/Engine/src/Engine/Utility/Stringifier.h +++ b/Engine/src/Engine/Utility/Stringifier.h @@ -1,7 +1,6 @@ #pragma once - -#include "Base.h" +#include "Base/Base.h" namespace Light { diff --git a/Engine/src/Engine/ltpch.h b/Engine/src/Engine/ltpch.h index 51c2807..20bdbb6 100644 --- a/Engine/src/Engine/ltpch.h +++ b/Engine/src/Engine/ltpch.h @@ -1,17 +1,16 @@ #pragma once -//** ENGINE **// -#include "Base.h" +/* engine */ +#include "Base/Base.h" -//** PLATFORM SPECIFIC **// -// windows +/* windows */ #ifdef _WIN32 #define NOMINMAX #include #undef NOMINMAX #endif -//** CONTAINERS **// +/* containers */ #include #include #include @@ -21,29 +20,29 @@ #include #include -//** MISCELLANEOUS **// +/* misc */ #include #include #include #include #include -//** INPUT_OUTPUT **// +/* input/output */ #include #include #include -//** MULTI_THREADING **// +/* multi threading */ #include #include -//** STRING **// +/* string */ #include #include -//** FILESYSTEM **// +/* filesystem */ #include -//** C_LIBRARIES **// +/* c libraries */ #include #include \ No newline at end of file diff --git a/Engine/src/LightEngine.h b/Engine/src/LightEngine.h index e81905b..05fab01 100644 --- a/Engine/src/LightEngine.h +++ b/Engine/src/LightEngine.h @@ -1,56 +1,56 @@ #pragma once -//** CORE **// +// core #include "Core/Application.h" #include "Core/Window.h" -//** CAMERA **// +// camera #include "Camera/Camera.h" -//** DEBUG **// +// debug #include "Debug/Logger.h" -//** EVENTS **// +// events #include "Events/Event.h" #include "Events/KeyboardEvents.h" #include "Events/MouseEvents.h" #include "Events/WindowEvents.h" -//** GRAPHICS **// +// graphics #include "Graphics/GraphicsContext.h" #include "Graphics/Renderer.h" #include "Graphics/Framebuffer.h" -//** INPUT **// +// input #include "Input/Input.h" #include "Input/KeyCodes.h" #include "Input/MouseCodes.h" -//** LAYER **// +// layer #include "Layer/Layer.h" #include "Layer/LayerStack.h" -//** USER_INTERFACE **// +// user interface #include "UserInterface/UserInterface.h" -//** UTILITY **// +// utility #include "Utility/ResourceManager.h" -//** TIME **// +// time #include "Time/Timer.h" -//** BASE **// -#include "Base.h" +// base +#include "Base/Base.h" -//** THIRD_PARTY **// +// third party #include -//** SCENE **// +// scene #include "Scene/Scene.h" #include "Scene/Entity.h" #include "Scene/Components.h" // entry point #ifdef LIGHT_ENTRY_POINT - #include "EntryPoint.h" + #include "Base/EntryPoint.h" #endif diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxBlender.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxBlender.cpp index d4f494e..1b088d0 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxBlender.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxBlender.cpp @@ -1,41 +1,39 @@ #include "ltpch.h" #include "dxBlender.h" - #include "dxSharedContext.h" namespace Light { dxBlender::dxBlender(Ref sharedContext) - : m_Context(sharedContext) + : m_Context(sharedContext), + m_FactorMap{ // constants + { BlendFactor::ZERO, D3D11_BLEND_ZERO }, + { BlendFactor::ONE, D3D11_BLEND_ONE }, + + // source + { BlendFactor::SRC_COLOR, D3D11_BLEND_SRC_COLOR }, + { BlendFactor::INVERSE_SRC_COLOR, D3D11_BLEND_INV_SRC_COLOR }, + + { BlendFactor::SRC_ALPHA, D3D11_BLEND_SRC_ALPHA }, + { BlendFactor::INVERSE_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA }, + + // destination + { BlendFactor::DST_COLOR, D3D11_BLEND_DEST_COLOR }, + { BlendFactor::INVERSE_DST_COLOR, D3D11_BLEND_INV_DEST_COLOR }, + + { BlendFactor::DST_ALPHA, D3D11_BLEND_DEST_ALPHA }, + { BlendFactor::INVERSE_DST_ALPHA, D3D11_BLEND_INV_DEST_ALPHA }, + + // source1 + { BlendFactor::SRC1_COLOR, D3D11_BLEND_SRC1_COLOR }, + { BlendFactor::INVERSE_SRC1_COLOR, D3D11_BLEND_INV_SRC1_COLOR }, + + { BlendFactor::SRC1_ALPHA, D3D11_BLEND_SRC1_ALPHA }, + { BlendFactor::INVERSE_SRC1_ALPHA, D3D11_BLEND_INV_SRC1_ALPHA } }, + m_BlendState(nullptr), + m_Desc{} { // factor map - m_FactorMap = { - // constants - { BlendFactor::ZERO, D3D11_BLEND_ZERO }, - { BlendFactor::ONE, D3D11_BLEND_ONE }, - - // source - { BlendFactor::SRC_COLOR, D3D11_BLEND_SRC_COLOR }, - { BlendFactor::INVERSE_SRC_COLOR, D3D11_BLEND_INV_SRC_COLOR }, - - { BlendFactor::SRC_ALPHA, D3D11_BLEND_SRC_ALPHA }, - { BlendFactor::INVERSE_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA }, - - // destination - { BlendFactor::DST_COLOR, D3D11_BLEND_DEST_COLOR }, - { BlendFactor::INVERSE_DST_COLOR, D3D11_BLEND_INV_DEST_COLOR }, - - { BlendFactor::DST_ALPHA, D3D11_BLEND_DEST_ALPHA }, - { BlendFactor::INVERSE_DST_ALPHA, D3D11_BLEND_INV_DEST_ALPHA }, - - // source1 - { BlendFactor::SRC1_COLOR, D3D11_BLEND_SRC1_COLOR }, - { BlendFactor::INVERSE_SRC1_COLOR, D3D11_BLEND_INV_SRC1_COLOR }, - - { BlendFactor::SRC1_ALPHA, D3D11_BLEND_SRC1_ALPHA }, - { BlendFactor::INVERSE_SRC1_ALPHA, D3D11_BLEND_INV_SRC1_ALPHA } - }; - // blender desc m_Desc = { }; @@ -57,8 +55,8 @@ namespace Light { { // update desc m_Desc.RenderTarget[0].BlendEnable = true; - m_Desc.RenderTarget[0].SrcBlend = m_FactorMap[srcFactor]; - m_Desc.RenderTarget[0].DestBlend = m_FactorMap[dstFactor]; + m_Desc.RenderTarget[0].SrcBlend = m_FactorMap.at(srcFactor); + m_Desc.RenderTarget[0].DestBlend = m_FactorMap.at(dstFactor); // re-create blind state HRESULT hr; diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxBlender.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxBlender.h index 4d07628..0070702 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxBlender.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxBlender.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Graphics/Blender.h" +#include "Base/Base.h" + #include #include @@ -14,7 +15,8 @@ namespace Light { { private: Ref m_Context; - std::unordered_map m_FactorMap; + + const std::unordered_map m_FactorMap; Microsoft::WRL::ComPtr m_BlendState; diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.cpp index 5ba7493..5908bf8 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.cpp @@ -1,22 +1,25 @@ #include "ltpch.h" #include "dxBuffers.h" - #include "dxSharedContext.h" namespace Light { + //======================================== CONSTANT_BUFFER ========================================// dxConstantBuffer::dxConstantBuffer(ConstantBufferIndex index, unsigned int size, Ref sharedContext) - : m_Context(sharedContext), m_Index((int)index) + : m_Context(sharedContext), + m_Buffer(nullptr), + m_Map{}, + m_Index(static_cast(index)) { - D3D11_BUFFER_DESC bufferDesc = { }; + D3D11_BUFFER_DESC bDesc = {}; - bufferDesc.ByteWidth = size; - bufferDesc.Usage = D3D11_USAGE_DYNAMIC; - bufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - bufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bDesc.ByteWidth = size; + bDesc.Usage = D3D11_USAGE_DYNAMIC; + bDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + bDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; HRESULT hr; - DXC(m_Context->GetDevice()->CreateBuffer(&bufferDesc, nullptr, &m_Buffer)); + DXC(m_Context->GetDevice()->CreateBuffer(&bDesc, nullptr, &m_Buffer)); m_Context->GetDeviceContext()->VSSetConstantBuffers(m_Index, 1u, m_Buffer.GetAddressOf()); } @@ -36,24 +39,28 @@ namespace Light { { m_Context->GetDeviceContext()->Unmap(m_Buffer.Get(), NULL); } + //======================================== CONSTANT_BUFFER ========================================// - //* VERTEX_BUFFER *// + //================================================== VERTEX_BUFFER ==================================================// dxVertexBuffer::dxVertexBuffer(float* vertices, unsigned int stride, unsigned int count, Ref sharedContext) - : m_Stride(stride), m_Context(sharedContext) + : m_Context(sharedContext), + m_Buffer(nullptr), + m_Map{}, + m_Stride(stride) { // buffer desc - D3D11_BUFFER_DESC bd = { 0 }; + D3D11_BUFFER_DESC bDesc = {}; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; - bd.Usage = D3D11_USAGE_DYNAMIC; - bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + bDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + bDesc.Usage = D3D11_USAGE_DYNAMIC; + bDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - bd.ByteWidth = count * stride; - bd.StructureByteStride = stride; + bDesc.ByteWidth = count * stride; + bDesc.StructureByteStride = stride; // create buffer HRESULT hr; - DXC(m_Context->GetDevice()->CreateBuffer(&bd, nullptr, &m_Buffer)); + DXC(m_Context->GetDevice()->CreateBuffer(&bDesc, nullptr, &m_Buffer)); } dxVertexBuffer::~dxVertexBuffer() @@ -85,10 +92,12 @@ namespace Light { m_Context->GetDeviceContext()->IASetVertexBuffers(0u, 1u, &buffer, &m_Stride, &offset); } + //================================================== VERTEX_BUFFER ==================================================// - //* INDEX_BUFFER *// + //======================================== INDEX_BUFFER ========================================// dxIndexBuffer::dxIndexBuffer(unsigned int* indices, unsigned int count, Ref sharedContext) - : m_Context(sharedContext) + : m_Context(sharedContext), + m_Buffer(nullptr) { // generate indices if not provided bool hasIndices = !!indices; @@ -107,33 +116,33 @@ namespace Light { unsigned int offset = 0; for (unsigned int i = 0; i < count; i += 6) { - indices[i + 0] = offset + 0; - indices[i + 1] = offset + 3; - indices[i + 2] = offset + 2; + indices[i + 0] = offset + 0u; + indices[i + 1] = offset + 3u; + indices[i + 2] = offset + 2u; - indices[i + 3] = offset + 2; - indices[i + 4] = offset + 1; - indices[i + 5] = offset + 0; + indices[i + 3] = offset + 2u; + indices[i + 4] = offset + 1u; + indices[i + 5] = offset + 0u; - offset += 4; + offset += 4u; } } // buffer desc - D3D11_BUFFER_DESC bd = { 0 }; - bd.BindFlags = D3D11_BIND_INDEX_BUFFER; - bd.Usage = D3D11_USAGE_DEFAULT; + D3D11_BUFFER_DESC bDesc = {}; + bDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; + bDesc.Usage = D3D11_USAGE_DEFAULT; - bd.ByteWidth = count * sizeof(unsigned int); - bd.StructureByteStride = sizeof(unsigned int); + bDesc.ByteWidth = count * sizeof(unsigned int); + bDesc.StructureByteStride = sizeof(unsigned int); // subresource data - D3D11_SUBRESOURCE_DATA sd = { 0 }; - sd.pSysMem = indices; + D3D11_SUBRESOURCE_DATA sDesc = {}; + sDesc.pSysMem = indices; // create buffer HRESULT hr; - DXC(m_Context->GetDevice()->CreateBuffer(&bd, &sd, &m_Buffer)); + DXC(m_Context->GetDevice()->CreateBuffer(&bDesc, &sDesc, &m_Buffer)); // delete indices if (!hasIndices) @@ -157,5 +166,6 @@ namespace Light { m_Context->GetDeviceContext()->IASetIndexBuffer(buffer, DXGI_FORMAT_R32_UINT, offset); } + //======================================== INDEX_BUFFER ========================================// } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.h index 593c1a5..6e7c7ec 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxBuffers.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Graphics/Buffers.h" +#include "Base/Base.h" + #include #include @@ -10,7 +11,7 @@ namespace Light { class dxSharedContext; - //* INDEX_BUFFER *// + //========== CONSTANT_BUFFER ==========// class dxConstantBuffer : public ConstantBuffer { private: @@ -30,7 +31,7 @@ namespace Light { void UnMap() override; }; - //* VERTEX_BUFFER *// + //========== VERTEX_BUFFER ==========// class dxVertexBuffer : public VertexBuffer { private: @@ -45,14 +46,14 @@ namespace Light { dxVertexBuffer(float* vertices, unsigned int stride, unsigned int count, Ref sharedContext); ~dxVertexBuffer(); - void* Map() override; - void UnMap() override; - void Bind() override; void UnBind() override; + + void* Map() override; + void UnMap() override; }; - //* INDEX_BUFFER *// + //========== INDEX_BUFFER ==========// class dxIndexBuffer : public IndexBuffer { private: diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxFramebuffer.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxFramebuffer.cpp index 0a9ed1a..51b16af 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxFramebuffer.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxFramebuffer.cpp @@ -5,32 +5,39 @@ namespace Light { dxFramebuffer::dxFramebuffer(const FramebufferSpecification& specification, Ref sharedContext) - : m_Specification(specification), m_Context(sharedContext) + : m_Context(sharedContext), + m_Specification(specification), + m_RenderTargetView(nullptr), + m_ColorAttachment(nullptr), + m_DepthStencilAttachment(nullptr), + m_ShaderResourceView(nullptr), + m_DepthStencilView(nullptr) { HRESULT hr; - D3D11_TEXTURE2D_DESC textureDesc = { }; - textureDesc.Width = specification.width; - textureDesc.Height = specification.height; - textureDesc.MipLevels = 1; - textureDesc.ArraySize = 1; - textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - textureDesc.SampleDesc.Count = 1u; - textureDesc.SampleDesc.Quality = 0u; - textureDesc.Usage = D3D11_USAGE_DEFAULT; - textureDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; - textureDesc.CPUAccessFlags = NULL; - textureDesc.MiscFlags = NULL; - DXC(m_Context->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &m_ColorAttachment)); - D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc = { }; - shaderResourceViewDesc.Format = textureDesc.Format; - shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - shaderResourceViewDesc.Texture2D.MipLevels = 1; - shaderResourceViewDesc.Texture2D.MostDetailedMip = 0; - DXC(m_Context->GetDevice()->CreateShaderResourceView(m_ColorAttachment.Get(), &shaderResourceViewDesc, &m_ResourceView)); + D3D11_TEXTURE2D_DESC t2dDesc = {}; + t2dDesc.Width = specification.width; + t2dDesc.Height = specification.height; + t2dDesc.MipLevels = 1; + t2dDesc.ArraySize = 1; + t2dDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + t2dDesc.SampleDesc.Count = 1u; + t2dDesc.SampleDesc.Quality = 0u; + t2dDesc.Usage = D3D11_USAGE_DEFAULT; + t2dDesc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; + t2dDesc.CPUAccessFlags = NULL; + t2dDesc.MiscFlags = NULL; + DXC(m_Context->GetDevice()->CreateTexture2D(&t2dDesc, nullptr, &m_ColorAttachment)); + + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + srvDesc.Format = t2dDesc.Format; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MipLevels = 1; + srvDesc.Texture2D.MostDetailedMip = 0; + DXC(m_Context->GetDevice()->CreateShaderResourceView(m_ColorAttachment.Get(), &srvDesc, &m_ShaderResourceView)); D3D11_RENDER_TARGET_VIEW_DESC rtvDesc = {}; - rtvDesc.Format = textureDesc.Format; + rtvDesc.Format = t2dDesc.Format; rtvDesc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; rtvDesc.Texture2D.MipSlice = 0u; DXC(m_Context->GetDevice()->CreateRenderTargetView(m_ColorAttachment.Get(), &rtvDesc, &m_RenderTargetView)); @@ -68,10 +75,10 @@ namespace Light { LT_ENGINE_ERROR("dxFramebuffer::BindAsResource: NO_IMPLEMENT"); } - void dxFramebuffer::Resize(const glm::vec2& size) + void dxFramebuffer::Resize(const glm::uvec2& size) { - m_Specification.width = std::clamp(size.x, 1.0f, 16384.0f); - m_Specification.height= std::clamp(size.y, 1.0f, 16384.0f); + m_Specification.width = std::clamp(size.x, 1u, 16384u); + m_Specification.height= std::clamp(size.y, 1u, 16384u); D3D11_TEXTURE2D_DESC textureDesc; D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; @@ -79,7 +86,7 @@ namespace Light { m_ColorAttachment->GetDesc(&textureDesc); m_RenderTargetView->GetDesc(&rtvDesc); - m_ResourceView->GetDesc(&srvDesc); + m_ShaderResourceView->GetDesc(&srvDesc); textureDesc.Width = m_Specification.width; textureDesc.Height = m_Specification.height; @@ -87,7 +94,7 @@ namespace Light { HRESULT hr; DXC(m_Context->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &m_ColorAttachment)); DXC(m_Context->GetDevice()->CreateRenderTargetView(m_ColorAttachment.Get(), &rtvDesc, &m_RenderTargetView)); - DXC(m_Context->GetDevice()->CreateShaderResourceView(m_ColorAttachment.Get(), &srvDesc, &m_ResourceView)); + DXC(m_Context->GetDevice()->CreateShaderResourceView(m_ColorAttachment.Get(), &srvDesc, &m_ShaderResourceView)); } } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxFramebuffer.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxFramebuffer.h index 7ef5e87..c43b1a1 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxFramebuffer.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxFramebuffer.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Graphics/Framebuffer.h" +#include "Base/Base.h" + #include #include @@ -20,18 +21,18 @@ namespace Light { Microsoft::WRL::ComPtr m_RenderTargetView; Microsoft::WRL::ComPtr m_ColorAttachment; Microsoft::WRL::ComPtr m_DepthStencilAttachment; - Microsoft::WRL::ComPtr m_ResourceView; + Microsoft::WRL::ComPtr m_ShaderResourceView; Microsoft::WRL::ComPtr m_DepthStencilView; public: dxFramebuffer(const FramebufferSpecification& specification, Ref sharedContext); - inline void* GetColorAttachment() override { return (void*)m_ResourceView.Get(); } + inline void* GetColorAttachment() override { return (void*)m_ShaderResourceView.Get(); } void BindAsTarget() override; void BindAsResource() override; - void Resize(const glm::vec2& size) override; + void Resize(const glm::uvec2& size) override; }; } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp index 7a4277b..97a4e0b 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp @@ -4,11 +4,14 @@ #include "Events/WindowEvents.h" -// forward declaration -#include "Graphics/Renderer.h" -#include "Graphics/RenderCommand.h" -#include "UserInterface/UserInterface.h" -#include "Utility/ResourceManager.h" +#include "Graphics/Blender.h" // required for forward declaration +#include "Graphics/Buffers.h" // required for forward declaration +#include "Graphics/Renderer.h" // required for forward declaration +#include "Graphics/RenderCommand.h" // required for forward declaration + +#include "UserInterface/UserInterface.h" // required for forward declaration + +#include "Utility/ResourceManager.h" // required for forward declaration #define GLFW_EXPOSE_NATIVE_WIN32 #include @@ -17,7 +20,8 @@ namespace Light { dxGraphicsContext::dxGraphicsContext(GLFWwindow* windowHandle) - : m_WindowHandle(windowHandle) + : m_WindowHandle(windowHandle), + m_DebugInterface(nullptr) { // set 'GraphicsAPI'; m_GraphicsAPI = GraphicsAPI::DirectX; diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.h index 9f368ec..b464101 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Graphics/GraphicsContext.h" +#include "Base/Base.h" + #include #include @@ -14,6 +15,7 @@ namespace Light { { private: GLFWwindow* m_WindowHandle; + Microsoft::WRL::ComPtr m_DebugInterface; public: diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.cpp index 12da7cc..727f41e 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.cpp @@ -6,13 +6,14 @@ namespace Light { dxRenderCommand::dxRenderCommand(Ref sharedContext) : m_Context(sharedContext) - { } + { + } void dxRenderCommand::SwapBuffers() { #ifdef LIGHT_DEBUG HRESULT hr; - if (FAILED(hr = m_Context->GetSwapChain()->Present(0u, 0u))) + if (FAILED(hr = m_Context->GetSwapChain()->Present(1u, 0u))) { if (hr == DXGI_ERROR_DEVICE_REMOVED) { @@ -83,8 +84,9 @@ namespace Light { Microsoft::WRL::ComPtr backBuffer = nullptr; DXC(m_Context->GetSwapChain()->GetBuffer(0u, __uuidof(ID3D11Resource), &backBuffer)); DXC(m_Context->GetDevice()->CreateRenderTargetView(backBuffer.Get(), nullptr, &m_Context->GetRenderTargetViewRef())); + // set render target - m_Context->GetDeviceContext()->OMSetRenderTargets(1, m_Context->GetRenderTargetView().GetAddressOf(), nullptr); + m_Context->GetDeviceContext()->OMSetRenderTargets(1u, m_Context->GetRenderTargetView().GetAddressOf(), nullptr); } } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.h index 78800e5..aaaf9e2 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxRenderCommand.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Graphics/RenderCommand.h" +#include "Base/Base.h" + #include #include diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxShader.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxShader.cpp index 2b77340..08b847f 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxShader.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxShader.cpp @@ -7,12 +7,14 @@ namespace Light { dxShader::dxShader(const std::string& vertexSource, const std::string& pixelSource, Ref sharedContext) - : m_Context(sharedContext) + : m_Context(sharedContext), + m_VertexShader(nullptr), + m_PixelShader(nullptr), + m_VertexBlob(nullptr) { Microsoft::WRL::ComPtr ps = nullptr, vsErr = nullptr, psErr = nullptr; - // compile shaders - HRESULT hr; + // compile shaders (we don't use DXC here because if D3DCompile fails it throws a dxException without logging the vsErr/psErr) D3DCompile(vertexSource.c_str(), vertexSource.length(), NULL, nullptr, nullptr, "main", "vs_4_0", NULL, NULL, &m_VertexBlob, &vsErr); D3DCompile(pixelSource.c_str(), pixelSource.length(), NULL, nullptr, nullptr, "main", "ps_4_0", NULL, NULL, &ps, &psErr); @@ -21,6 +23,7 @@ namespace Light { LT_ENGINE_ASSERT(!psErr.Get(), "dxShader::dxShader: pixels shader compile error: {}", (char*)psErr->GetBufferPointer()); // create shaders + HRESULT hr; DXC(m_Context->GetDevice()->CreateVertexShader(m_VertexBlob->GetBufferPointer(), m_VertexBlob->GetBufferSize(), NULL, &m_VertexShader)); DXC(m_Context->GetDevice()->CreatePixelShader(ps->GetBufferPointer(), ps->GetBufferSize(), NULL, &m_PixelShader)); } @@ -42,9 +45,4 @@ namespace Light { m_Context->GetDeviceContext()->PSSetShader(nullptr, nullptr, 0u); } - void dxShader::SetUniformMat4(const std::string& name, const glm::mat4& value) - { - LT_ENGINE_ERROR("dxShader::SetUniformMat4: NOT_IMPLEMENTED"); - } - } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxShader.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxShader.h index b7c915b..13b1b3e 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxShader.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxShader.h @@ -1,9 +1,8 @@ #pragma once -#include "Base.h" #include "Graphics/Shader.h" -#include +#include "Base/Base.h" #include #include @@ -29,9 +28,7 @@ namespace Light { void Bind() override; void UnBind() override; - void SetUniformMat4(const std::string& name, const glm::mat4& value) override; - - Microsoft::WRL::ComPtr GetVertexBlob() { return m_VertexBlob; } + inline Microsoft::WRL::ComPtr GetVertexBlob() { return m_VertexBlob; } }; } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxSharedContext.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxSharedContext.h index d57c9ae..f61cb15 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxSharedContext.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxSharedContext.h @@ -1,6 +1,6 @@ #pragma once -#include "Base.h" +#include "Base/Base.h" #include "Graphics/SharedContext.h" #include @@ -8,7 +8,6 @@ namespace Light { - // #todo: class dxSharedContext : public SharedContext { private: diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxTexture.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxTexture.cpp index ff34123..e629ce3 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxTexture.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxTexture.cpp @@ -5,61 +5,64 @@ namespace Light { dxTexture::dxTexture(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels, Ref sharedContext) - : m_Context(sharedContext) + : m_Context(sharedContext), + m_Texture2D(nullptr), + m_ShaderResourceView(nullptr), + m_SamplerState(nullptr) { - // texture desc - D3D11_TEXTURE2D_DESC textureDesc = { }; - textureDesc.Width = width; - textureDesc.Height = height; - textureDesc.MipLevels = 0u; - textureDesc.ArraySize = 1u; - textureDesc.Format = components == 4u ? DXGI_FORMAT_R8G8B8A8_UNORM : - components == 3u ? DXGI_FORMAT_R8G8B8A8_UNORM : - components == 2u ? DXGI_FORMAT_R8G8B8A8_UNORM : - components == 1u ? DXGI_FORMAT_R8G8B8A8_UNORM : DXGI_FORMAT_UNKNOWN; - textureDesc.SampleDesc.Count = 1u; - textureDesc.SampleDesc.Quality = 0u; - textureDesc.Usage = D3D11_USAGE_DEFAULT; - textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; - textureDesc.CPUAccessFlags = NULL; - textureDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS; + // texture2d desc + D3D11_TEXTURE2D_DESC t2dDesc = {}; + t2dDesc.Width = width; + t2dDesc.Height = height; + t2dDesc.MipLevels = 0u; + t2dDesc.ArraySize = 1u; + t2dDesc.Format = components == 4u ? DXGI_FORMAT_R8G8B8A8_UNORM : + components == 3u ? DXGI_FORMAT_R8G8B8A8_UNORM : // #todo: figure out what to do with this bitch ._. + components == 2u ? DXGI_FORMAT_R8G8_UNORM : + components == 1u ? DXGI_FORMAT_R8_UNORM : DXGI_FORMAT_UNKNOWN; + t2dDesc.SampleDesc.Count = 1u; + t2dDesc.SampleDesc.Quality = 0u; + t2dDesc.Usage = D3D11_USAGE_DEFAULT; + t2dDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET; + t2dDesc.CPUAccessFlags = NULL; + t2dDesc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS; // create texture HRESULT hr; - DXC(m_Context->GetDevice()->CreateTexture2D(&textureDesc, nullptr, &m_Texture)); - m_Context->GetDeviceContext()->UpdateSubresource(m_Texture.Get(), 0u, nullptr, pixels, width * 4u, 0u); - - m_Texture->GetDesc(&textureDesc); + DXC(m_Context->GetDevice()->CreateTexture2D(&t2dDesc, nullptr, &m_Texture2D)); + m_Context->GetDeviceContext()->UpdateSubresource(m_Texture2D.Get(), 0u, nullptr, pixels, width * 4u, 0u); + + m_Texture2D->GetDesc(&t2dDesc); // shader resource view desc - D3D11_SHADER_RESOURCE_VIEW_DESC shaderResourceViewDesc = { }; - shaderResourceViewDesc.Format = textureDesc.Format; - shaderResourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - shaderResourceViewDesc.Texture2D.MostDetailedMip = 0u; - shaderResourceViewDesc.Texture2D.MipLevels = -1; + D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc = {}; + srvDesc.Format = t2dDesc.Format; + srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Texture2D.MostDetailedMip = 0u; + srvDesc.Texture2D.MipLevels = -1; // create shader resource view - m_Context->GetDevice()->CreateShaderResourceView(m_Texture.Get(), &shaderResourceViewDesc, &m_ResourceView); - m_Context->GetDeviceContext()->GenerateMips(m_ResourceView.Get()); + m_Context->GetDevice()->CreateShaderResourceView(m_Texture2D.Get(), &srvDesc, &m_ShaderResourceView); + m_Context->GetDeviceContext()->GenerateMips(m_ShaderResourceView.Get()); // sampler desc - D3D11_SAMPLER_DESC samplerDesc = { }; - samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; - samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; - samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; - samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; - samplerDesc.MinLOD = 0.0f; - samplerDesc.MipLODBias = 0.0f; - samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; + D3D11_SAMPLER_DESC sDesc = {}; + sDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; + sDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; + sDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; + sDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; + sDesc.MinLOD = 0.0f; + sDesc.MipLODBias = 0.0f; + sDesc.MaxLOD = D3D11_FLOAT32_MAX; // create sampler - m_Context->GetDevice()->CreateSamplerState(&samplerDesc, &m_SamplerState); + m_Context->GetDevice()->CreateSamplerState(&sDesc, &m_SamplerState); } void dxTexture::Bind(unsigned int slot /* = 0u */) { m_Context->GetDeviceContext()->PSSetSamplers(slot, 1u, m_SamplerState.GetAddressOf()); - m_Context->GetDeviceContext()->PSSetShaderResources(slot, 1u, m_ResourceView.GetAddressOf()); + m_Context->GetDeviceContext()->PSSetShaderResources(slot, 1u, m_ShaderResourceView.GetAddressOf()); } } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxTexture.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxTexture.h index cdf954b..6ee061b 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxTexture.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxTexture.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Graphics/Texture.h" +#include "Base/Base.h" + #include #include @@ -15,8 +16,8 @@ namespace Light { private: Ref m_Context; - Microsoft::WRL::ComPtr m_Texture; - Microsoft::WRL::ComPtr m_ResourceView; + Microsoft::WRL::ComPtr m_Texture2D; + Microsoft::WRL::ComPtr m_ShaderResourceView; Microsoft::WRL::ComPtr m_SamplerState; public: diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxUserInterface.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxUserInterface.cpp index 3fcd04b..b65dd80 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxUserInterface.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxUserInterface.cpp @@ -2,14 +2,14 @@ #include "dxUserInterface.h" #include "dxSharedContext.h" -#include -#include -#include - #define GLFW_EXPOSE_NATIVE_WIN32 #include #include +#include +#include +#include + namespace Light { dxUserInterface::dxUserInterface(GLFWwindow* windowHandle, Ref sharedContext) @@ -61,7 +61,7 @@ namespace Light { ImGui_ImplWin32_NewFrame(); ImGui::NewFrame(); - //** #TEMP_IMGUI_DEMO_TEMP# **// + /* #TEMP_IMGUI_DEMO_TEMP# */ ImGui::ShowDemoWindow(); } diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxUserInterface.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxUserInterface.h index 11c2476..33af08c 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxUserInterface.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxUserInterface.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "UserInterface/UserInterface.h" +#include "Base/Base.h" + #include #include diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.cpp b/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.cpp index 2c5db2a..d35cbec 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.cpp @@ -7,7 +7,8 @@ namespace Light { dxVertexLayout::dxVertexLayout(Ref shader, const std::vector>& elements, Ref sharedContext) - : m_Context(sharedContext) + : m_Context(sharedContext), + m_InputLayout(nullptr) { // occupy space for input elements std::vector inputElementsDesc; @@ -16,14 +17,13 @@ namespace Light { // extract elements desc for (const auto& element : elements) { - inputElementsDesc.emplace_back(D3D11_INPUT_ELEMENT_DESC{ - element.first.c_str(), - 0u, - GetDxgiFormat(element.second), - 0u, - D3D11_APPEND_ALIGNED_ELEMENT, - D3D11_INPUT_PER_VERTEX_DATA, - 0u }); + inputElementsDesc.emplace_back(D3D11_INPUT_ELEMENT_DESC{ element.first.c_str(), + NULL, + GetDxgiFormat(element.second), + 0u, + D3D11_APPEND_ALIGNED_ELEMENT, + D3D11_INPUT_PER_VERTEX_DATA, + 0u }); } Ref dxpShader = std::dynamic_pointer_cast(shader); diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.h index 3ded273..4b87071 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxVertexLayout.h @@ -1,14 +1,16 @@ #pragma once -#include "Base.h" #include "Graphics/VertexLayout.h" +#include "Base/Base.h" + #include #include namespace Light { class Shader; + class dxSharedContext; class dxVertexLayout : public VertexLayout diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glBlender.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glBlender.cpp index 40ae77a..20bb917 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glBlender.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glBlender.cpp @@ -6,39 +6,37 @@ namespace Light { glBlender::glBlender() + : m_FactorMap{ // constants + { BlendFactor::ZERO , GL_ZERO }, + { BlendFactor::ONE , GL_ONE }, + + // source , + { BlendFactor::SRC_COLOR , GL_SRC_COLOR }, + { BlendFactor::INVERSE_SRC_COLOR , GL_ONE_MINUS_SRC_COLOR }, + + { BlendFactor::SRC_ALPHA , GL_SRC_ALPHA }, + { BlendFactor::INVERSE_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA }, + + // destination , + { BlendFactor::DST_COLOR , GL_DST_COLOR }, + { BlendFactor::INVERSE_DST_COLOR , GL_ONE_MINUS_DST_COLOR }, + + { BlendFactor::DST_ALPHA , GL_DST_ALPHA }, + { BlendFactor::INVERSE_DST_ALPHA , GL_ONE_MINUS_DST_ALPHA }, + + // source1 , + { BlendFactor::SRC1_COLOR , GL_SRC1_COLOR }, + { BlendFactor::INVERSE_SRC1_COLOR, GL_ONE_MINUS_SRC1_COLOR }, + + { BlendFactor::SRC1_ALPHA , GL_SRC1_ALPHA }, + { BlendFactor::INVERSE_SRC1_ALPHA, GL_ONE_MINUS_SRC_ALPHA } } { - m_FactorMap = { - // constants - { BlendFactor::ZERO, GL_ZERO }, - { BlendFactor::ONE, GL_ZERO }, - - // source - { BlendFactor::SRC_COLOR, GL_SRC_COLOR }, - { BlendFactor::INVERSE_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR }, - - { BlendFactor::SRC_ALPHA, GL_SRC_ALPHA }, - { BlendFactor::INVERSE_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA }, - - // destination - { BlendFactor::DST_COLOR, GL_DST_COLOR }, - { BlendFactor::INVERSE_DST_COLOR, GL_ONE_MINUS_DST_COLOR }, - - { BlendFactor::DST_ALPHA, GL_DST_ALPHA }, - { BlendFactor::INVERSE_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA }, - - // source1 - { BlendFactor::SRC1_COLOR, GL_SRC1_COLOR }, - { BlendFactor::INVERSE_SRC1_COLOR, GL_ONE_MINUS_SRC1_COLOR }, - - { BlendFactor::SRC1_ALPHA, GL_SRC1_ALPHA }, - { BlendFactor::INVERSE_SRC1_ALPHA, GL_ONE_MINUS_SRC_ALPHA } - }; } void glBlender::Enable(BlendFactor srcFactor, BlendFactor dstFactor) { glEnable(GL_BLEND); - glBlendFunc(m_FactorMap[srcFactor], m_FactorMap[dstFactor]); + glBlendFunc(m_FactorMap.at(srcFactor), m_FactorMap.at(dstFactor)); } void glBlender::Disable() diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glBlender.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glBlender.h index 8b8b6e3..fc9dc69 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glBlender.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glBlender.h @@ -1,8 +1,9 @@ -#pragma pnce +#pragma once -#include "Base.h" #include "Graphics/Blender.h" +#include "Base/Base.h" + namespace Light { class glBlender : public Blender diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.cpp index 4a434fd..778d584 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.cpp @@ -5,9 +5,10 @@ namespace Light { - //** CONSTANT_BUFFER **// + //==================== CONSTANT_BUFFER ====================// glConstantBuffer::glConstantBuffer(ConstantBufferIndex index, unsigned int size) - : m_Index((int)index) + : m_BufferID(NULL), + m_Index(static_cast(index)) { glCreateBuffers(1, &m_BufferID); glNamedBufferData(m_BufferID, size, nullptr, GL_DYNAMIC_DRAW); @@ -35,9 +36,11 @@ namespace Light { { glUnmapNamedBuffer(m_BufferID); } + //==================== CONSTANT_BUFFER ====================// - //** VERTEX_BUFFER **// + //==================== VERTEX_BUFFER ====================// glVertexBuffer::glVertexBuffer(float* vertices, unsigned int count) + : m_BufferID(NULL) { glCreateBuffers(1, &m_BufferID); glNamedBufferData(m_BufferID, count * sizeof(float), vertices, GL_DYNAMIC_DRAW); @@ -48,16 +51,6 @@ namespace Light { glDeleteBuffers(1, &m_BufferID); } - void* glVertexBuffer::Map() - { - return glMapNamedBuffer(m_BufferID, GL_WRITE_ONLY); - } - - void glVertexBuffer::UnMap() - { - glUnmapNamedBuffer(m_BufferID); - } - void glVertexBuffer::Bind() { glBindBuffer(GL_ARRAY_BUFFER, m_BufferID); @@ -68,8 +61,20 @@ namespace Light { glBindBuffer(GL_ARRAY_BUFFER, NULL); } - //** INDEX_BUFFER **// + void* glVertexBuffer::Map() + { + return glMapNamedBuffer(m_BufferID, GL_WRITE_ONLY); + } + + void glVertexBuffer::UnMap() + { + glUnmapNamedBuffer(m_BufferID); + } + //==================== VERTEX_BUFFER ====================// + + //==================== INDEX_BUFFER ====================// glIndexBuffer::glIndexBuffer(unsigned int* indices, unsigned int count) + : m_BufferID(NULL) { // generate indices if not provided bool hasIndices = !!indices; @@ -85,18 +90,18 @@ namespace Light { // create indices indices = new unsigned int[count]; - unsigned int offset = 0; - for (unsigned int i = 0; i < count; i += 6) + unsigned int offset = 0u; + for (unsigned int i = 0u; i < count; i += 6u) { - indices[i + 0] = offset + 0; - indices[i + 1] = offset + 1; - indices[i + 2] = offset + 2; + indices[i + 0] = offset + 0u; + indices[i + 1] = offset + 1u; + indices[i + 2] = offset + 2u; - indices[i + 3] = offset + 2; - indices[i + 4] = offset + 3; - indices[i + 5] = offset + 0; + indices[i + 3] = offset + 2u; + indices[i + 4] = offset + 3u; + indices[i + 5] = offset + 0u; - offset += 4; + offset += 4u; } } @@ -123,5 +128,6 @@ namespace Light { { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL); } + //==================== INDEX_BUFFER ====================// } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.h index 23db170..a53511e 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glBuffers.h @@ -1,14 +1,17 @@ #pragma once -#include "Base.h" #include "Graphics/Buffers.h" +#include "Base/Base.h" + namespace Light { + //========== CONSTANT_BUFFER ==========// class glConstantBuffer : public ConstantBuffer { private: - unsigned int m_BufferID, m_Index; + unsigned int m_BufferID; + unsigned int m_Index; public: glConstantBuffer(ConstantBufferIndex index, unsigned int size); @@ -20,7 +23,7 @@ namespace Light { void UnMap() override; }; - //** VERTEX_BUFFER **// + //========== VERTEX_BUFFER ==========// class glVertexBuffer : public VertexBuffer { private: @@ -30,14 +33,14 @@ namespace Light { glVertexBuffer(float* vertices, unsigned int count); ~glVertexBuffer(); - void* Map() override; - void UnMap() override; - void Bind() override; void UnBind() override; + + void* Map() override; + void UnMap() override; }; - //** INDEX_BUFFER **// + //========== INDEX_BUFFER ==========// class glIndexBuffer : public IndexBuffer { private: diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glFramebuffer.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glFramebuffer.cpp index c5094de..9d3e8d1 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glFramebuffer.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glFramebuffer.cpp @@ -1,14 +1,17 @@ #include "ltpch.h" #include "glFramebuffer.h" -#include - #include +#include + namespace Light { glFramebuffer::glFramebuffer(const FramebufferSpecification& specification) - : m_Specification(specification), m_BufferID(0u), m_ColorAttachment(0u), m_DepthStencilAttachment(0u) + : m_Specification(specification), + m_BufferID(NULL), + m_ColorAttachmentID(NULL), + m_DepthStencilAttachmentID(NULL) { Resize({ specification.width, specification.height }); } @@ -16,12 +19,13 @@ namespace Light { glFramebuffer::~glFramebuffer() { glDeleteFramebuffers(1, &m_BufferID); - glDeleteTextures(1, &m_ColorAttachment); - // glDeleteTextures(1, &m_DepthStencilAttachment); + glDeleteTextures(1, &m_ColorAttachmentID); + // glDeleteTextures(1, &m_DepthStencilAttachmentID); } void glFramebuffer::BindAsTarget() { + // #todo: use viewport instead of default x=0, y=0 glBindFramebuffer(GL_FRAMEBUFFER, m_BufferID); glViewport(0, 0, m_Specification.width, m_Specification.height); @@ -34,33 +38,36 @@ namespace Light { LT_ENGINE_ERROR("glFramebuffer::BindAsResource: NO_IMPLEMENT!"); } - void glFramebuffer::Resize(const glm::vec2& size) + void glFramebuffer::Resize(const glm::uvec2& size) { if (m_BufferID) { glDeleteFramebuffers(1, &m_BufferID); - glDeleteTextures(1, &m_ColorAttachment); - // glDeleteTextures(1, &m_DepthStencilAttachment); + glDeleteTextures(1, &m_ColorAttachmentID); + // glDeleteTextures(1, &m_DepthStencilAttachmentID); } + m_Specification.width = std::clamp(size.x, 1u, (unsigned int)GL_MAX_TEXTURE_SIZE); + m_Specification.height = std::clamp(size.y, 1u, (unsigned int)GL_MAX_TEXTURE_SIZE); + glCreateFramebuffers(1, &m_BufferID); glBindFramebuffer(GL_FRAMEBUFFER, m_BufferID); // create color attachment - glCreateTextures(GL_TEXTURE_2D, 1, &m_ColorAttachment); - glBindTexture(GL_TEXTURE_2D, m_ColorAttachment); + glCreateTextures(GL_TEXTURE_2D, 1, &m_ColorAttachmentID); + glBindTexture(GL_TEXTURE_2D, m_ColorAttachmentID); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Specification.width, m_Specification.height, NULL, GL_RGBA, GL_UNSIGNED_BYTE, nullptr); - glTextureParameteri(m_ColorAttachment, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTextureParameteri(m_ColorAttachment, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_ColorAttachment, 0); + glTextureParameteri(m_ColorAttachmentID, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTextureParameteri(m_ColorAttachmentID, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_ColorAttachmentID, 0); - // glTextureStorage2D(m_ColorAttachment, 0, GL_RGBA8, m_Specification.width, m_Specification.height); + // glTextureStorage2D(m_ColorAttachmentID, 0, GL_RGBA8, m_Specification.width, m_Specification.height); - // glCreateTextures(GL_TEXTURE_2D, 1, &m_DepthStencilAttachment); - // glBindTexture(GL_TEXTURE_2D, m_DepthStencilAttachment); - // glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_Specification.width, m_Specification.height, NULL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr); - // // glTextureStorage2D(m_DepthStencilAttachment, 0, GL_DEPTH24_STENCIL8, m_Specification.width, m_Specification.height); - // glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_DepthStencilAttachment, 0); + // glCreateTextures(GL_TEXTURE_2D, 1, &m_DepthStencilAttachmentID); + // glBindTexture(GL_TEXTURE_2D, m_DepthStencilAttachmentID); + // glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, m_Specification.width, m_Specification.height, NULL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, nullptr); + // // glTextureStorage2D(m_DepthStencilAttachmentID, 0, GL_DEPTH24_STENCIL8, m_Specification.width, m_Specification.height); + // glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, m_DepthStencilAttachmentID, 0); LT_ENGINE_ASSERT((glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE), "glFramebuffer::Validate: framebuffer is incomplete"); diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glFramebuffer.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glFramebuffer.h index a314d48..f76e82d 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glFramebuffer.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glFramebuffer.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Graphics/Framebuffer.h" +#include "Base/Base.h" + namespace Light { class glFramebuffer : public Framebuffer @@ -10,18 +11,19 @@ namespace Light { private: FramebufferSpecification m_Specification; - unsigned int m_BufferID, m_ColorAttachment, m_DepthStencilAttachment; + unsigned int m_BufferID; + unsigned int m_ColorAttachmentID, m_DepthStencilAttachmentID; public: glFramebuffer(const FramebufferSpecification& specification); ~glFramebuffer(); - inline void* GetColorAttachment() override { return (void*)m_ColorAttachment; } - void BindAsTarget() override; void BindAsResource() override; - void Resize(const glm::vec2& size) override; + void Resize(const glm::uvec2& size) override; + + inline void* GetColorAttachment() override { return (void*)m_ColorAttachmentID; } }; } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp index fe18410..a46d07b 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp @@ -3,11 +3,14 @@ #include "Events/WindowEvents.h" -// forward declaration -#include "Graphics/Renderer.h" -#include "Graphics/RenderCommand.h" -#include "UserInterface/UserInterface.h" -#include "Utility/ResourceManager.h" +#include "Graphics/Blender.h" // required for forward declaration +#include "Graphics/Buffers.h" // required for forward declaration +#include "Graphics/Renderer.h" // required for forward declaration +#include "Graphics/RenderCommand.h" // required for forward declaration + +#include "UserInterface/UserInterface.h" // required for forward declaration + +#include "Utility/ResourceManager.h" // required for forward declaration #include #include @@ -50,11 +53,12 @@ namespace Light { glEnable(GL_DEBUG_OUTPUT); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_FALSE); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_HIGH, 0, nullptr, GL_TRUE); -#else // LT_DIST + glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_MEDIUM, 0, nullptr, GL_TRUE); +#else // LIGHT_DIST return; #endif - // setup message callback + /* setup message callback */ glDebugMessageCallback([](unsigned int source, unsigned int type, unsigned int id, unsigned int severity, int length, const char* message, diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.h index 6a558fb..0f1789e 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.h @@ -1,14 +1,13 @@ #pragma once -#include "Base.h" #include "Graphics/GraphicsContext.h" +#include "Base/Base.h" + struct GLFWwindow; namespace Light { - class WindowResizedEvent; - class glGraphicsContext : public GraphicsContext { private: @@ -17,7 +16,7 @@ namespace Light { public: glGraphicsContext(GLFWwindow* windowHandle); - virtual void LogDebugData() override; + void LogDebugData() override; private: void SetDebugMessageCallback(); diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.cpp index 4ef8d19..87d2613 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.cpp @@ -8,7 +8,8 @@ namespace Light { glRenderCommand::glRenderCommand(GLFWwindow* windowHandle) : m_WindowHandle(windowHandle) - { } + { + } void glRenderCommand::SwapBuffers() { diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.h index 657ab2f..e20f9f8 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glRenderCommand.h @@ -1,8 +1,11 @@ #pragma once -#include "Base.h" #include "Graphics/RenderCommand.h" +#include "Base/Base.h" + +struct GLFWwindow; + namespace Light { class glRenderCommand : public RenderCommand @@ -19,9 +22,9 @@ namespace Light { void Draw(unsigned int count) override; void DrawIndexed(unsigned int count) override; - virtual void DefaultTargetFramebuffer() override; + void DefaultTargetFramebuffer() override; - virtual void SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) override; + void SetViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) override; }; } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.cpp index 5f463f6..f93c503 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.cpp @@ -10,6 +10,7 @@ namespace Light { glShader::glShader(const std::string& vertexSource, const std::string& fragmentSource) + : m_ShaderID(NULL) { m_ShaderID = glCreateProgram(); @@ -29,7 +30,7 @@ namespace Light { glCompileShader(vertexShader); glCompileShader(fragmentShader); - //** #TEMP_HANDLE_SHADER_COMPILE_FAILURE# **// + /* #TEMP_HANDLE_SHADER_COMPILE_FAILURE# */ int isCompiled = 0; glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &isCompiled); if (isCompiled == GL_FALSE) @@ -64,7 +65,7 @@ namespace Light { return; } - //** #TEMP_HANDLE_SHADER_COMPILE_FAILURE# **// + /* #TEMP_HANDLE_SHADER_COMPILE_FAILURE# */ // attach shaders glAttachShader(m_ShaderID, vertexShader); @@ -93,14 +94,4 @@ namespace Light { glUseProgram(NULL); } - void glShader::SetUniformMat4(const std::string& name, const glm::mat4& value) - { - int location = glGetUniformLocation(m_ShaderID, name.c_str()); - - if (location == -1) - LT_ENGINE_ERROR("glShader::SetUniformMat4: failed to find uniform: {}", name); - - glUniformMatrix4fv(location, 1, GL_FALSE, &(value[0][0])); - } - } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.h index 2f26af9..54a7207 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.h @@ -1,9 +1,8 @@ #pragma once -#include "Base.h" #include "Graphics/Shader.h" -#include +#include "Base/Base.h" namespace Light { @@ -18,8 +17,6 @@ namespace Light { void Bind() override; void UnBind() override; - - void SetUniformMat4(const std::string& name, const glm::mat4& value) override; }; } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glSharedContext.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glSharedContext.h index dac0238..e5cbcac 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glSharedContext.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glSharedContext.h @@ -1,9 +1,13 @@ #pragma once -#include "Base.h" +#include "Graphics/SharedContext.h" + +#include "Base/Base.h" namespace Light { - struct glSharedContext { }; + class glSharedContext : public SharedContext + { + }; } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glTexture.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glTexture.cpp index a1a0459..09a520b 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glTexture.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glTexture.cpp @@ -6,6 +6,7 @@ namespace Light { glTexture::glTexture(unsigned int width, unsigned int height, unsigned int components, unsigned char* pixels) + : m_TextureID(NULL) { // create texture glCreateTextures(GL_TEXTURE_2D, 1, &m_TextureID); diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glTexture.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glTexture.h index 09f756d..34d7dfc 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glTexture.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glTexture.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Graphics/Texture.h" +#include "Base/Base.h" + namespace Light { class glTexture : public Texture diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp index 7fcf69d..f62318b 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp @@ -1,12 +1,13 @@ -#include "ltpch.h" + +#include "ltpch.h" #include "glUserInterface.h" +#include + #include #include #include -#include - namespace Light { glUserInterface::glUserInterface(GLFWwindow* windowHandle) @@ -58,7 +59,7 @@ namespace Light { ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); - //** #TEMP_IMGUI_DEMO_TEMP# **// + /* #TEMP_IMGUI_DEMO_TEMP# */ ImGui::ShowDemoWindow(); } diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h index 540c07a..9c9c266 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h @@ -1,9 +1,10 @@ #pragma once -#include "Base.h" #include "UserInterface/UserInterface.h" -class GLFWwindow; +#include "Base/Base.h" + +struct GLFWwindow; namespace Light { diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexLayout.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexLayout.cpp index eb71d1b..f4434f4 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexLayout.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexLayout.cpp @@ -8,6 +8,7 @@ namespace Light { glVertexLayout::glVertexLayout(Ref buffer, const std::vector>& elements) + : m_ArrayID(NULL) { // check LT_ENGINE_ASSERT(std::dynamic_pointer_cast(buffer), "glVertexLayout::glVertexLayout: failed to cast 'VertexBuffer' to 'glVertexBuffer'"); diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexLayout.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexLayout.h index 4d4f959..72b2d6a 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexLayout.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glVertexLayout.h @@ -1,10 +1,13 @@ #pragma once -#include "Base.h" #include "Graphics/VertexLayout.h" +#include "Base/Base.h" + namespace Light { + class VertexBuffer; + struct glVertexElementDesc { unsigned int type; diff --git a/Engine/src/Platform/OS/Linux/lWindow.cpp b/Engine/src/Platform/OS/Linux/lWindow.cpp index b3518c7..472ee47 100644 --- a/Engine/src/Platform/OS/Linux/lWindow.cpp +++ b/Engine/src/Platform/OS/Linux/lWindow.cpp @@ -18,7 +18,8 @@ namespace Light { } lWindow::lWindow(std::function callback) - : m_EventCallback(callback) + : m_Handle(nullptr), + m_EventCallback(callback) { // init glfw LT_ENGINE_ASSERT(glfwInit(), "lWindow::lWindow: failed to initialize 'glfw'"); @@ -32,11 +33,11 @@ namespace Light { m_Handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr); LT_ENGINE_ASSERT(m_Handle, "lWindow::lWindow: failed to create 'GLFWwindow'"); - // manage events + // bind event stuff glfwSetWindowUserPointer(m_Handle, &m_EventCallback); BindGlfwEvents(); - // create graphics contextG + // create graphics context m_GraphicsContext = GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle); LT_ENGINE_ASSERT(m_GraphicsContext, "lWindow::lWindow: failed to create 'GraphicsContext'"); } @@ -55,12 +56,12 @@ namespace Light { { switch (event.GetEventType()) { - // closed + /* closed */ case EventType::WindowClosed: b_Closed = true; break; - // resized + /* resized */ case EventType::WindowResized: OnWindowResize((const WindowResizedEvent&)event); break; @@ -72,10 +73,10 @@ namespace Light { m_Properties.size = event.GetSize(); } - void lWindow::SetProperties(const WindowProperties& properties, bool affectsVisiblity /* = false */) + void lWindow::SetProperties(const WindowProperties& properties, bool overrideVisibility /* = false */) { - // save the visibility status and re-assign if 'affectVisibility' is false - bool visible = affectsVisiblity ? properties.visible : m_Properties.visible; + // save the visibility status and re-assign if 'overrideVisibility' is false + bool visible = overrideVisibility ? properties.visible : m_Properties.visible; m_Properties = properties; m_Properties.visible = visible; @@ -121,8 +122,8 @@ namespace Light { void lWindow::BindGlfwEvents() { - //** MOUSE_EVENTS **// - // cursor position + //============================== MOUSE_EVENTS ==============================// + /* cursor position */ glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -131,7 +132,7 @@ namespace Light { callback(event); }); - // button + /* mouse button */ glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -148,7 +149,7 @@ namespace Light { } }); - // scroll + /* scroll */ glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -156,9 +157,10 @@ namespace Light { WheelScrolledEvent event(yoffset); callback(event); }); - - //** KEYBOARD_EVENTS **// - // key + //============================== MOUSE_EVENTS ==============================// + + //============================== KEYBOARD_EVENTS ==============================// + /* key */ glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -174,9 +176,10 @@ namespace Light { callback(event); } }); - - //** WINDOW_EVENTS **// - // position + //============================== KEYBOARD_EVENTS ==============================// + + //============================== WINDOW_EVENTS ==============================// + /* window position */ glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -185,8 +188,8 @@ namespace Light { callback(event); }); - // size - glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height) + /* window size */ + glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); WindowResizedEvent event(width, height); @@ -194,7 +197,7 @@ namespace Light { callback(event); }); - // close + /* window close */ glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -203,7 +206,7 @@ namespace Light { callback(event); }); - // focus + /* window focus */ glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -219,6 +222,7 @@ namespace Light { callback(event); } }); + //============================== WINDOW_EVENTS ==============================// } } \ No newline at end of file diff --git a/Engine/src/Platform/OS/Linux/lWindow.h b/Engine/src/Platform/OS/Linux/lWindow.h index 9e8558d..b727f23 100644 --- a/Engine/src/Platform/OS/Linux/lWindow.h +++ b/Engine/src/Platform/OS/Linux/lWindow.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Core/Window.h" +#include "Base/Base.h" + struct GLFWwindow; namespace Light { @@ -13,19 +14,20 @@ namespace Light { class lWindow : public Window { private: - GLFWwindow* m_Handle = nullptr; + GLFWwindow* m_Handle; std::function m_EventCallback; public: lWindow(std::function callback); - ~lWindow(); + /* events */ void PollEvents() override; void OnEvent(const Event& event) override; - void SetProperties(const WindowProperties& properties, bool affectsVisiblity = false) override; + //======================================== SETTERS ========================================// + void SetProperties(const WindowProperties& properties, bool overrideVisibility = false) override; void SetTitle(const std::string& title) override; @@ -33,11 +35,12 @@ namespace Light { void SetVSync(bool vsync, bool toggle = false) override; void SetVisibility(bool visible, bool toggle = false); - - private: - void BindGlfwEvents(); + //======================================== SETTERS ========================================// + private: void OnWindowResize(const WindowResizedEvent& event); + + void BindGlfwEvents(); }; } \ No newline at end of file diff --git a/Engine/src/Platform/OS/Windows/wWindow.cpp b/Engine/src/Platform/OS/Windows/wWindow.cpp index 77eb874..f651b8d 100644 --- a/Engine/src/Platform/OS/Windows/wWindow.cpp +++ b/Engine/src/Platform/OS/Windows/wWindow.cpp @@ -18,7 +18,8 @@ namespace Light { } wWindow::wWindow(std::function callback) - : m_EventCallback(callback) + : m_Handle(nullptr), + m_EventCallback(callback) { // init glfw LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: failed to initialize 'glfw'"); @@ -46,10 +47,36 @@ namespace Light { glfwDestroyWindow(m_Handle); } - void wWindow::SetProperties(const WindowProperties& properties, bool affectVisibility /* = false */) + void wWindow::PollEvents() { - // save the visibility status and re-assign if 'affectVisibility' is false - bool visible = affectVisibility ? properties.visible : m_Properties.visible; + glfwPollEvents(); + } + + void wWindow::OnEvent(const Event& event) + { + switch (event.GetEventType()) + { + /* closed */ + case EventType::WindowClosed: + b_Closed = true; + break; + + /* resized */ + case EventType::WindowResized: + OnWindowResize((const WindowResizedEvent&)event); + break; + } + } + + void wWindow::OnWindowResize(const WindowResizedEvent& event) + { + m_Properties.size = event.GetSize(); + } + + void wWindow::SetProperties(const WindowProperties& properties, bool overrideVisiblity /* = false */) + { + // save the visibility status and re-assign if 'overrideVisibility' is false + bool visible = overrideVisiblity ? properties.visible : m_Properties.visible; m_Properties = properties; m_Properties.visible = visible; @@ -60,6 +87,29 @@ namespace Light { SetVisibility(visible); } + void wWindow::SetTitle(const std::string& title) + { + m_Properties.title = title; + + glfwSetWindowTitle(m_Handle, m_Properties.title.c_str()); + } + + void wWindow::SetSize(const glm::uvec2& size, bool additive /* = false */) + { + m_Properties.size.x = size.x == 0u ? m_Properties.size.x : additive ? m_Properties.size.x + size.x : size.x; + m_Properties.size.y = size.y == 0u ? m_Properties.size.y : additive ? m_Properties.size.y + size.y : size.y; + + + glfwSetWindowSize(m_Handle, size.x, size.y); + } + + void wWindow::SetVSync(bool vsync, bool toggle /* = false */) + { + m_Properties.vsync = toggle ? !m_Properties.vsync : vsync; + + glfwSwapInterval(m_Properties.vsync); + } + void wWindow::SetVisibility(bool visible, bool toggle) { m_Properties.visible = toggle ? !m_Properties.visible : visible; @@ -70,63 +120,17 @@ namespace Light { glfwHideWindow(m_Handle); } - void wWindow::PollEvents() - { - glfwPollEvents(); - } - - void wWindow::OnEvent(const Event& event) - { - switch (event.GetEventType()) - { - // closed - case EventType::WindowClosed: - b_Closed = true; - break; - - // resized - case EventType::WindowResized: - OnWindowResize((const WindowResizedEvent&)event); - break; - } - } - - void wWindow::OnWindowResize(const WindowResizedEvent& event) - { - m_Properties.size = event.GetSize(); - } - - void wWindow::SetTitle(const std::string& title) - { - m_Properties.title = title; - - glfwSetWindowTitle(m_Handle, m_Properties.title.c_str()); - } - - void wWindow::SetVSync(bool vsync, bool toggle /* = false */) - { - m_Properties.vsync = toggle ? !m_Properties.vsync : vsync; - - glfwSwapInterval(m_Properties.vsync); - } - - void wWindow::SetSize(const glm::uvec2& size, bool additive /* = false */) - { - glfwSetWindowSize(m_Handle, size.x == 0u ? m_Properties.size.x : additive ? m_Properties.size.x + size.x : size.x, - size.y == 0u ? m_Properties.size.y : additive ? m_Properties.size.y + size.y : size.y); - } - void wWindow::BindGlfwEvents() { - //** MOUSE_EVENTS **// - // cursor position + //============================== MOUSE_EVENTS ==============================// + /* cursor position */ glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); callback(MouseMovedEvent(xpos, ypos)); }); - // button + /* mouse button */ glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -137,15 +141,16 @@ namespace Light { callback(ButtonReleasedEvent (button)); }); - // scroll + /* scroll */ glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); callback(WheelScrolledEvent (yoffset)); }); + //============================== MOUSE_EVENTS ==============================// - //** KEYBOARD_EVENTS **// - // key + //============================== KEYBOARD_EVENTS ==============================// + /* key */ glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -155,30 +160,31 @@ namespace Light { else if(action == GLFW_RELEASE) callback(KeyReleasedEvent(key)); }); + //============================== KEYBOARD_EVENTS ==============================// - // Window Events // - // position + //============================== WINDOW_EVENTS ==============================// + /* window position */ glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); callback(WindowMovedEvent(xpos, ypos)); }); - // size + /* window size */ glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); callback(WindowResizedEvent(width, height)); }); - // close + /* window close */ glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); callback(WindowClosedEvent()); }); - // focus + /* window focus */ glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); @@ -188,5 +194,6 @@ namespace Light { else callback(WindowLostFocusEvent()); }); + //============================== WINDOW_EVENTS ==============================// } } \ No newline at end of file diff --git a/Engine/src/Platform/OS/Windows/wWindow.h b/Engine/src/Platform/OS/Windows/wWindow.h index 57d8c93..be9adf6 100644 --- a/Engine/src/Platform/OS/Windows/wWindow.h +++ b/Engine/src/Platform/OS/Windows/wWindow.h @@ -1,8 +1,9 @@ #pragma once -#include "Base.h" #include "Core/Window.h" +#include "Base/Base.h" + struct GLFWwindow; namespace Light { @@ -13,20 +14,20 @@ namespace Light { class wWindow : public Window { private: - GLFWwindow* m_Handle = nullptr; + GLFWwindow* m_Handle; std::function m_EventCallback; public: wWindow(std::function callback); - ~wWindow(); + /* events */ void PollEvents() override; void OnEvent(const Event& event) override; - //** SETTERS **// - void SetProperties(const WindowProperties& properties, bool affectVisibility = false) override; + //======================================== SETTERS ========================================// + void SetProperties(const WindowProperties& properties, bool overrideVisibility = false) override; void SetTitle(const std::string& title) override; @@ -34,11 +35,12 @@ namespace Light { void SetVSync(bool vsync, bool toggle = false) override; void SetVisibility(bool visible, bool toggle = false) override; + //======================================== SETTERS ========================================// private: - void BindGlfwEvents(); - void OnWindowResize(const WindowResizedEvent& event); + + void BindGlfwEvents(); }; } \ No newline at end of file diff --git a/Mirror/src/MirrorApp.cpp b/Mirror/src/MirrorApp.cpp index 60a8597..27dc7b8 100644 --- a/Mirror/src/MirrorApp.cpp +++ b/Mirror/src/MirrorApp.cpp @@ -1,6 +1,5 @@ #define LIGHT_ENTRY_POINT #include -#include #include "MirrorLayer.h" @@ -31,7 +30,7 @@ namespace Light { } }; - ::Light::Application* ::Light::CreateApplication() + Application* CreateApplication() { return new Mirror(); } diff --git a/Mirror/src/MirrorLayer.h b/Mirror/src/MirrorLayer.h index dc8ffb4..24fabcf 100644 --- a/Mirror/src/MirrorLayer.h +++ b/Mirror/src/MirrorLayer.h @@ -32,7 +32,7 @@ namespace Light { ResourceManager::LoadTexture("awesomeface", "res/Textures/awesomeface.png"); m_AwesomefaceTexture = ResourceManager::GetTexture("awesomeface"); - m_Framebuffer = std::shared_ptr(Framebuffer::Create({ 800u, 600u, 1, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f), false }, GraphicsContext::GetSharedContext())); + m_Framebuffer = std::shared_ptr(Framebuffer::Create({ 800u, 600u, 1, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f) }, GraphicsContext::GetSharedContext())); for (int i = 0; i < 250; i++) { diff --git a/Sandbox/default_gui_layout.ini b/Sandbox/default_gui_layout.ini new file mode 100644 index 0000000..ee99ff8 --- /dev/null +++ b/Sandbox/default_gui_layout.ini @@ -0,0 +1,13 @@ +[Window][Debug##Default] +Pos=60,60 +Size=400,400 +Collapsed=0 + +[Window][Dear ImGui Demo] +ViewportPos=259,212 +ViewportId=0xE927CF2F +Size=388,391 +Collapsed=0 + +[Docking][Data] + diff --git a/Sandbox/src/SandboxApp.cpp b/Sandbox/src/SandboxApp.cpp index 62d8c7d..b057cb4 100644 --- a/Sandbox/src/SandboxApp.cpp +++ b/Sandbox/src/SandboxApp.cpp @@ -1,11 +1,13 @@ #define LIGHT_ENTRY_POINT #include -#include #include "SandboxLayer.h" class Sandbox : public Light::Application { +private: + SandboxLayer* m_SandboxLayer; + public: Sandbox() { @@ -20,7 +22,8 @@ public: m_Window->SetProperties(properties); // Attach the sandbox layer - Light::LayerStack::AttachLayer(new SandboxLayer("SandboxLayer")); + m_SandboxLayer = new SandboxLayer("SandboxLayer"); + Light::LayerStack::AttachLayer(m_SandboxLayer); } ~Sandbox() @@ -31,5 +34,6 @@ public: Light::Application* Light::CreateApplication() { + // note: don't use the logger here, it is not initialized yet return new Sandbox(); } \ No newline at end of file diff --git a/Sandbox/src/SandboxLayer.h b/Sandbox/src/SandboxLayer.h index 4c7fcb1..ea95622 100644 --- a/Sandbox/src/SandboxLayer.h +++ b/Sandbox/src/SandboxLayer.h @@ -3,54 +3,48 @@ class SandboxLayer : public Light::Layer { private: - std::shared_ptr m_AwesomefaceTexture; - - std::vector positions; - std::vector sizes; - - glm::vec2 m_Direction; - float m_Speed = 1.2f; + // scene + Light::Scope m_SandboxScene; + // camera Light::Ref m_Camera; + glm::vec2 m_Direction = { 0.0f, 0.0f }; + float m_Speed = 1.2f; public: SandboxLayer(const std::string& name) - : Light::Layer(name), m_Direction(glm::vec2(0.0f, 0.0f)) + : Light::Layer(name) { - m_Camera = std::make_shared(glm::vec2(0.0f), 800.0f / 600.0f, 1.0f); + // initialize scene & camera + m_SandboxScene = Light::CreateScope(); + m_Camera = Light::CreateRef(glm::vec2(0.0f), 800.0f / 600.0f, 1.0f); + // initialize test quads Light::ResourceManager::LoadTexture("awesomeface", "res/Textures/awesomeface.png"); - m_AwesomefaceTexture = Light::ResourceManager::GetTexture("awesomeface"); + Light::Ref awesomeface = Light::ResourceManager::GetTexture("awesomeface"); for (int i = 0; i < 100; i++) { glm::vec3 position = glm::vec3(-1.0f + (-100.0f / 400.0f) + ((rand() % 1000) / 400.0f), -1.0f + (-100.0f / 300.0f) + ((rand() % 800) / 300.0f), 0.0f); glm::vec2 size = glm::vec2(100 / 400.0f, 100 / 300.0f); - positions.push_back(position); - sizes.push_back(size); + m_SandboxScene->CreateEntity("awesomeface" + i, position, size).AddComponent(awesomeface); } } void OnRender() override { - m_Camera->CalculateProjection(); - m_Camera->CalculateView(); - Light::Renderer::BeginScene(m_Camera); - - for (int i = 0; i < 100; i++) - Light::Renderer::DrawQuad(positions[i], sizes[i], m_AwesomefaceTexture); - + m_SandboxScene->OnRender(); Light::Renderer::EndScene(); } bool OnKeyPressed(const Light::KeyPressedEvent& event) override { if (event.GetKey() == Light::Key::A) - m_Direction.x += -1.0f; + m_Direction.x += -1.0f; if(event.GetKey() == Light::Key::D) - m_Direction.x += 1.0f; + m_Direction.x += 1.0f; if (event.GetKey() == Light::Key::W) m_Direction.y += 1.0f; @@ -66,7 +60,7 @@ public: if (event.GetKey() == Light::Key::A) m_Direction.x -= -1.0f; if (event.GetKey() == Light::Key::D) - m_Direction.x -= 1.0f; + m_Direction.x -= 1.0f; if (event.GetKey() == Light::Key::W) m_Direction.y -= 1.0f; @@ -79,6 +73,9 @@ public: void OnUpdate(float deltaTime) override { m_Camera->Move(m_Direction * m_Speed * deltaTime); + + m_Camera->CalculateProjection(); + m_Camera->CalculateView(); } };