diff --git a/Engine/src/Engine/Core/Application.cpp b/Engine/src/Engine/Core/Application.cpp index 7e5e566..3252459 100644 --- a/Engine/src/Engine/Core/Application.cpp +++ b/Engine/src/Engine/Core/Application.cpp @@ -27,8 +27,14 @@ namespace Light { void Application::GameLoop() { + // check LT_ENGINE_ASSERT(!m_LayerStack.IsEmpty(), "Application::GameLoop: Layerstack is empty"); + // Log some data + m_Window->GetGfxContext()->LogDebugData(); + m_Window->GetGfxContext()->GetUserInterface()->LogDebugData(); + + // GAMELOOP // while (m_Window->IsOpen()) { // Events diff --git a/Engine/src/Engine/Events/WindowEvents.h b/Engine/src/Engine/Events/WindowEvents.h index ba6ca1e..41f12f2 100644 --- a/Engine/src/Engine/Events/WindowEvents.h +++ b/Engine/src/Engine/Events/WindowEvents.h @@ -28,7 +28,7 @@ namespace Light { public: WindowMovedEvent(int x, int y): m_Position(x, y) {} - const glm::ivec2& GetPosition() { return m_Position; } + const glm::ivec2& GetPosition() const{ return m_Position; } virtual std::string GetInfoLog() const override { @@ -48,7 +48,7 @@ namespace Light { public: WindowResizedEvent(int width, int height): m_Size(width, height) {} - const glm::ivec2& GetSize() { return m_Size; } + const glm::ivec2& GetSize() const { return m_Size; } virtual std::string GetInfoLog() const override { diff --git a/Engine/src/Engine/Graphics/GraphicsContext.cpp b/Engine/src/Engine/Graphics/GraphicsContext.cpp index efd00c3..a0373ec 100644 --- a/Engine/src/Engine/Graphics/GraphicsContext.cpp +++ b/Engine/src/Engine/Graphics/GraphicsContext.cpp @@ -53,7 +53,6 @@ namespace Light { LT_ENGINE_ASSERT(s_Context->m_RenderCommand, "GraphicsContext::Create: RenderCommand creation failed"); LT_ENGINE_ASSERT(s_Context->m_UserInterface, "GraphicsContext::Create: UserInterface creation failed"); - return s_Context; } diff --git a/Engine/src/Engine/Graphics/GraphicsContext.h b/Engine/src/Engine/Graphics/GraphicsContext.h index 210fb29..d6497e1 100644 --- a/Engine/src/Engine/Graphics/GraphicsContext.h +++ b/Engine/src/Engine/Graphics/GraphicsContext.h @@ -10,6 +10,8 @@ namespace Light { class RenderCommand; class UserInterface; + class WindowResizedEvent; + enum class GraphicsAPI { Default = 0, @@ -32,12 +34,16 @@ namespace Light { GraphicsAPI m_GraphicsAPI; public: + static GraphicsContext* Create(GraphicsAPI api, GLFWwindow* windowHandle); + GraphicsContext(const GraphicsContext&) = delete; GraphicsContext& operator=(const GraphicsContext&) = delete; virtual ~GraphicsContext() = default; - - static GraphicsContext* Create(GraphicsAPI api, GLFWwindow* windowHandle); + + virtual void OnWindowResize(const WindowResizedEvent& event) = 0; + + virtual void LogDebugData() = 0; static inline GraphicsAPI GetGraphicsAPI() { return s_Context->m_GraphicsAPI; } @@ -47,6 +53,7 @@ namespace Light { protected: GraphicsContext() = default; + }; } \ No newline at end of file diff --git a/Engine/src/Engine/UserInterface/UserInterface.h b/Engine/src/Engine/UserInterface/UserInterface.h index 9ae1088..9546e3c 100644 --- a/Engine/src/Engine/UserInterface/UserInterface.h +++ b/Engine/src/Engine/UserInterface/UserInterface.h @@ -11,6 +11,8 @@ namespace Light { class UserInterface { public: + static UserInterface* Create(GLFWwindow* windowHandle); + UserInterface(const UserInterface&) = delete; UserInterface operator=(const UserInterface&) = delete; @@ -21,7 +23,8 @@ namespace Light { virtual void Begin() = 0; virtual void End() = 0; - static UserInterface* Create(GLFWwindow* windowHandle); + virtual void LogDebugData() = 0; + protected: UserInterface() = default; }; diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp index adef5c4..80cd161 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp @@ -9,6 +9,8 @@ #include "Graphics/VertexLayout.h" #include "UserInterface/UserInterface.h" +#include "Events/WindowEvents.h" + #include "Utility/Stringifier.h" #include @@ -26,10 +28,21 @@ namespace Light { "glGraphicsContext::glGraphicsContext: gladLoadGLLoader: failed to initialize opengl context"); SetDebugMessageCallback(); + } - LT_ENGINE_INFO("glGraphicsContext:"); + void glGraphicsContext::OnWindowResize(const WindowResizedEvent& event) + { + glViewport(0, 0, event.GetSize().x, event.GetSize().y); + } + + void glGraphicsContext::LogDebugData() + { + LT_ENGINE_INFO("________________________________________"); + LT_ENGINE_INFO("GraphicsContext::"); + LT_ENGINE_INFO(" API : OpenGL"); + LT_ENGINE_INFO(" Version : {}", glGetString(GL_VERSION)); LT_ENGINE_INFO(" Renderer: {}", glGetString(GL_RENDERER)); - LT_ENGINE_INFO(" Version: {}", glGetString(GL_VERSION)); + LT_ENGINE_INFO("________________________________________"); } void glGraphicsContext::SetDebugMessageCallback() diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.h index 3d94e72..0dfc53f 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.h @@ -7,6 +7,8 @@ struct GLFWwindow; namespace Light { + class WindowResizedEvent; + class glGraphicsContext : public GraphicsContext { private: @@ -15,6 +17,10 @@ namespace Light { public: glGraphicsContext(GLFWwindow* windowHandle); + virtual void OnWindowResize(const WindowResizedEvent& event) override; + + virtual void LogDebugData() override; + private: void SetDebugMessageCallback(); }; diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp index 398ce37..ccbc4d8 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.cpp @@ -1,4 +1,4 @@ -#include "ltpch.h" +#include "ltpch.h" #include "glUserInterface.h" #include @@ -42,4 +42,13 @@ namespace Light { ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); } + void glUserInterface::LogDebugData() + { + LT_ENGINE_INFO("________________________________________"); + LT_ENGINE_INFO("UserInterface::"); + LT_ENGINE_INFO(" API : ImGui"); + LT_ENGINE_INFO(" Version: {}", ImGui::GetVersion()); + LT_ENGINE_INFO("________________________________________"); + } + } \ No newline at end of file diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h index 85685ed..4776b0a 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glUserInterface.h @@ -13,6 +13,8 @@ namespace Light { void Begin() override; void End() override; + + virtual void LogDebugData() override; }; } \ 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 6daa9e7..ee77820 100644 --- a/Engine/src/Platform/OS/Windows/wWindow.cpp +++ b/Engine/src/Platform/OS/Windows/wWindow.cpp @@ -48,6 +48,8 @@ namespace Light { { case EventType::WindowClosed: b_Open = false; + case EventType::WindowResized: + m_GraphicsContext->OnWindowResize((const WindowResizedEvent&)event); } } diff --git a/Sandbox/imgui.ini b/Sandbox/imgui.ini index d7252b9..886a46e 100644 --- a/Sandbox/imgui.ini +++ b/Sandbox/imgui.ini @@ -4,13 +4,13 @@ Size=400,400 Collapsed=0 [Window][Dear ImGui Demo] -Pos=-3,0 -Size=524,134 -Collapsed=1 +Pos=-3,-1 +Size=243,295 +Collapsed=0 [Window][Dear ImGui Metrics/Debugger] -Pos=-5,16 -Size=525,114 +Pos=-1,859 +Size=359,115 Collapsed=0 [Table][0xC9935533,3] diff --git a/Sandbox/src/SandboxLayer.h b/Sandbox/src/SandboxLayer.h index a41f7d2..585fef0 100644 --- a/Sandbox/src/SandboxLayer.h +++ b/Sandbox/src/SandboxLayer.h @@ -5,24 +5,4 @@ class SandboxLayer : public Light::Layer public: SandboxLayer(const std::string& name): Light::Layer(name) {} - // Mouse events - virtual bool OnMouseMoved(const Light::MouseMovedEvent& event) override { LT_ENGINE_TRACE("{}", event.GetInfoLog()); return false; } - virtual bool OnButtonPressed(const Light::ButtonPressedEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; } - virtual bool OnButtonReleased(const Light::ButtonReleasedEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; } - virtual bool OnWheelScrolled(const Light::WheelScrolledEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; } - - // Keyboard events - virtual bool OnKeyPressed(const Light::KeyPressedEvent& event) override - { - LT_ENGINE_TRACE(event.GetInfoLog()); - return true; - } - virtual bool OnKeyReleased(const Light::KeyReleasedEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; } - - // Window events - virtual bool OnWindowClosed(const Light::WindowClosedEvent& event) override { LT_ENGINE_TRACE(event.GetInfoLog()); return false; } - virtual bool OnWindowResized(const Light::WindowResizedEvent& event) { LT_ENGINE_TRACE(event.GetInfoLog()); return false; } - virtual bool OnWindowMoved(const Light::WindowMovedEvent& event) { LT_ENGINE_TRACE(event.GetInfoLog()); return false; } - virtual bool OnWindowLostFocus(const Light::WindowLostFocusEvent& event) { LT_ENGINE_TRACE(event.GetInfoLog()); return false; } - virtual bool OnWindowGainFocus(const Light::WindowGainFocusEvent& event) { LT_ENGINE_TRACE(event.GetInfoLog()); return false; } };