diff --git a/.gitignore b/.gitignore index 959882a..cb22b9f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,18 @@ bin-int/ # VS Files **.vcxproj** -**.sln \ No newline at end of file +**.sln + +.codelite/ +.build-debug/ +**.workspace + +Makefile + +**/**.mk + +**/**.project + +**/Engine.txt +**/GLAD.txt +**/Sandbox.txt \ No newline at end of file diff --git a/Dependencies/GLFW b/Dependencies/GLFW index 23f9926..59a32ba 160000 --- a/Dependencies/GLFW +++ b/Dependencies/GLFW @@ -1 +1 @@ -Subproject commit 23f99263cdb8db054db5202f605e5730aec4e3c3 +Subproject commit 59a32baf70eadf12bfc22234c3bb1c5c28931a2c diff --git a/Dependencies/imgui b/Dependencies/imgui index e401b8f..b238424 160000 --- a/Dependencies/imgui +++ b/Dependencies/imgui @@ -1 +1 @@ -Subproject commit e401b8f2c0e89ddd783245a88549f5c5e23a2c21 +Subproject commit b238424f840544f64b0597f86c59b8810ca2b933 diff --git a/Engine/premake5.lua b/Engine/premake5.lua index 9d1ed2c..fa8f989 100644 --- a/Engine/premake5.lua +++ b/Engine/premake5.lua @@ -31,15 +31,15 @@ project "Engine" includedirs { -- engine - "%{prj.location}/src/" , - "%{prj.location}/src/Engine/" , + "%{prj.location}/src" , + "%{prj.location}/src/Engine" , "%{prj.location}/src/Platform/GraphicsAPI" , "%{prj.location}/src/Platform/OS" , -- 3rd party (dependenciesdir .. "spdlog/include/"), - (dependenciesdir .. "glfw/include/" ), - (dependenciesdir .. "glad/include" ), + (dependenciesdir .. "GLFW/include/" ), + (dependenciesdir .. "GLAD/include" ), (dependenciesdir .. "imgui/backends" ), (dependenciesdir .. "imgui/" ), (dependenciesdir .. "glm/" ), @@ -65,6 +65,26 @@ project "Engine" "dxguid.lib" , "D3DCompiler.lib" , } + + -- linux + filter "system:linux" + defines "LIGHT_PLATFORM_LINUX" + + links + { + "dl", + } + + buildoptions + { + "-lgtest", + "-lpthread", + } + excludes + { + "%{prj.location}/src/Platform/GraphicsAPI/DirectX/**", + "%{prj.location}/src/Platform/OS/Windows/**", + } -- debug filter "configurations:Debug" @@ -83,8 +103,7 @@ project "Engine" --- Excludes --- -- !windows - filter "system:not windows" - excludes "%{prj.location}/src/Platform/GraphicsAPI/DirectX**" - excludes "%{prj.location}/src/Platform/OS/Windows**" + filter "system:not linux" + -- !linux #todo: -- !mac #todo: \ No newline at end of file diff --git a/Engine/src/Engine/Base.h b/Engine/src/Engine/Base.h index e1cc347..34fa9d5 100644 --- a/Engine/src/Engine/Base.h +++ b/Engine/src/Engine/Base.h @@ -13,11 +13,13 @@ #define LT_MAC(x) // Mac #if defined(LIGHT_PLATFORM_WINDOWS) + #error "test" #define LT_BUILD_PLATFORM "Windows" #define LT_WIN(x) x #elif defined(LIGHT_PLATFORM_LINUX) - #error "Unsupported platform: UNIX" - #define LT_LIN(x) + #define LT_BUILD_PLATFORM "Linux" + + #define LT_LIN(x) x #elif defined(LIGHT_PLATFORM_MAC) #error "Unsupported platform: MAC" #define LT_MAC(x) x @@ -28,5 +30,5 @@ #define BIT(x) 1 << x // #todo: log to file in distribution builds -#define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); __debugbreak(); throw ::Light::FailedAssertion(__FILE__, __LINE__); } } -#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); __debugbreak(); } } \ No newline at end of file +#define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); /* __builtin_trap() */; throw ::Light::FailedAssertion(__FILE__, __LINE__); } } +#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); __builtin_trap(); } } \ No newline at end of file diff --git a/Engine/src/Engine/Debug/Logger.cpp b/Engine/src/Engine/Debug/Logger.cpp index 5a59cb0..faec667 100644 --- a/Engine/src/Engine/Debug/Logger.cpp +++ b/Engine/src/Engine/Debug/Logger.cpp @@ -17,8 +17,11 @@ namespace Light { void Light::Logger::Initialize() { // set spdlog pattern +#if defined(LIGHT_PLATFORM_WINDOWS) spdlog::set_pattern("%^[%M:%S:%e] <%n>: %v%$"); - +#elif defined(LIGHT_PLATFORM_LINUX) + spdlog::set_pattern("%^{%l} - [%M:%S:%e] <%n>: %v%$"); +#endif // create loggers #ifndef LIGHT_DIST s_EngineLogger = spdlog::stdout_color_mt("Engine"); @@ -28,7 +31,7 @@ namespace Light { s_FileLogger->set_pattern("%^[%M:%S:%e] <%l>: %v%$"); // set level -#if defined(LIGHT_DEBUG) +#if defined(LIGHT_DEBUG) s_EngineLogger->set_level(spdlog::level::trace); s_ClientLogger->set_level(spdlog::level::trace); #elif defined (LIGHT_RELEASE) diff --git a/Engine/src/Engine/EntryPoint.h b/Engine/src/Engine/EntryPoint.h index 895d09c..d97b5b8 100644 --- a/Engine/src/Engine/EntryPoint.h +++ b/Engine/src/Engine/EntryPoint.h @@ -7,6 +7,7 @@ // To be defined in client project extern Light::Application* Light::CreateApplication(); +// #todo: use windows specific stuff int main(int argc, char** argv) { Light::Application* application = nullptr; @@ -39,4 +40,39 @@ int main(int argc, char** argv) return exitCode; } +#elif defined(LIGHT_PLATFORM_LINUX) + +#include + +// To be defined in client project +extern Light::Application* Light::CreateApplication(); + +// #todo: use linux specific stuff +int main(int argc, char* argv[]) +{ + Light::Application* application = nullptr; + int exitCode = 0; + + try + { + application = Light::CreateApplication(); + LT_ENGINE_ASSERT(application, "main: Light::Application is not intialized"); + + application->GameLoop(); + } + catch (Light::FailedAssertion) + { + LT_ENGINE_CRITICAL("main: exitting due to unhandled FailedAssertion"); + exitCode = -1; + } + catch(Light::glException) + { + LT_ENGINE_CRITICAL("main: exitting due to unhandled glException"); + exitCode = -2; + } + + delete application; + return exitCode; +} + #endif \ No newline at end of file diff --git a/Engine/src/Engine/Events/Event.h b/Engine/src/Engine/Events/Event.h index 7828cf1..f454c8d 100644 --- a/Engine/src/Engine/Events/Event.h +++ b/Engine/src/Engine/Events/Event.h @@ -24,9 +24,9 @@ namespace Light { InputEventCategory = BIT(1), KeyboardEventCategory = BIT(2), MouseEventCategory = BIT(3), - }; + }; -#define EVENT_TYPE(type) EventType GetEventType() const override { return EventType::##type; } +#define EVENT_TYPE(type) EventType GetEventType() const override { return ::Light::EventType:: type; } #define EVENT_CATEGORY(eCategory) inline bool HasCategory(EventCategory category) const override { return (eCategory) & category; } class Event diff --git a/Engine/src/Engine/Graphics/Buffers.cpp b/Engine/src/Engine/Graphics/Buffers.cpp index 7649ab6..20af7ab 100644 --- a/Engine/src/Engine/Graphics/Buffers.cpp +++ b/Engine/src/Engine/Graphics/Buffers.cpp @@ -22,8 +22,8 @@ namespace Light { case GraphicsAPI::OpenGL: return new glVertexBuffer(vertices, count); - case GraphicsAPI::DirectX: - return new dxVertexBuffer(vertices, stride, count, std::static_pointer_cast(sharedContext)); + case GraphicsAPI::DirectX: LT_WIN( + return new dxVertexBuffer(vertices, stride, count, std::static_pointer_cast(sharedContext));) default: LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported GraphicsAPI {}", GraphicsContext::GetGraphicsAPI()); diff --git a/Engine/src/Engine/Graphics/GraphicsContext.cpp b/Engine/src/Engine/Graphics/GraphicsContext.cpp index 10b8867..304e9e8 100644 --- a/Engine/src/Engine/Graphics/GraphicsContext.cpp +++ b/Engine/src/Engine/Graphics/GraphicsContext.cpp @@ -18,6 +18,8 @@ namespace Light { GraphicsContext* GraphicsContext::s_Context = nullptr; + GraphicsContext::~GraphicsContext() { } + GraphicsContext* GraphicsContext::Create(GraphicsAPI api, GLFWwindow* windowHandle) { // terminate gfx context dependent classes diff --git a/Engine/src/Engine/Graphics/GraphicsContext.h b/Engine/src/Engine/Graphics/GraphicsContext.h index 716ca9b..9db420b 100644 --- a/Engine/src/Engine/Graphics/GraphicsContext.h +++ b/Engine/src/Engine/Graphics/GraphicsContext.h @@ -42,7 +42,7 @@ namespace Light { GraphicsContext(const GraphicsContext&) = delete; GraphicsContext& operator=(const GraphicsContext&) = delete; - virtual ~GraphicsContext() = default; + virtual ~GraphicsContext(); virtual void OnWindowResize(const WindowResizedEvent& event) = 0; diff --git a/Engine/src/Engine/Graphics/Renderer.cpp b/Engine/src/Engine/Graphics/Renderer.cpp index 85e318f..ffb7692 100644 --- a/Engine/src/Engine/Graphics/Renderer.cpp +++ b/Engine/src/Engine/Graphics/Renderer.cpp @@ -51,19 +51,20 @@ namespace Light { // TOP_LEFT m_QuadRenderer.mapCurrent[0].position = { xMin, yMin, position.z }; - m_QuadRenderer.mapCurrent[0].tint = tint; + m_QuadRenderer.mapCurrent[0].tint = glm::vec4((float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, 1.0f); + // TOP_RIGHT m_QuadRenderer.mapCurrent[1].position = { xMax, yMin, position.z }; - m_QuadRenderer.mapCurrent[1].tint = tint; + m_QuadRenderer.mapCurrent[1].tint = glm::vec4((float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, 1.0f); // BOTTOM_RIGHT m_QuadRenderer.mapCurrent[2].position = { xMax, yMax, position.z }; - m_QuadRenderer.mapCurrent[2].tint = tint; + m_QuadRenderer.mapCurrent[2].tint = glm::vec4((float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, 1.0f); // BOTTOM_LEFT m_QuadRenderer.mapCurrent[3].position = { xMin, yMax, position.z }; - m_QuadRenderer.mapCurrent[3].tint = tint; + m_QuadRenderer.mapCurrent[3].tint = glm::vec4((float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, (float)(rand() % 100) / 100.0f, 1.0f); // advance m_QuadRenderer.mapCurrent += 4; diff --git a/Engine/src/Engine/UserInterface/UserInterface.h b/Engine/src/Engine/UserInterface/UserInterface.h index 50b73f6..a4669e3 100644 --- a/Engine/src/Engine/UserInterface/UserInterface.h +++ b/Engine/src/Engine/UserInterface/UserInterface.h @@ -15,7 +15,7 @@ namespace Light { static UserInterface* Create(GLFWwindow* windowHandle, std::shared_ptr sharedContext); UserInterface(const UserInterface&) = delete; - UserInterface operator=(const UserInterface&) = delete; + UserInterface& operator=(const UserInterface&) = delete; virtual ~UserInterface() = default; diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp index 216c754..39de6ef 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp @@ -14,7 +14,7 @@ #include "Utility/Stringifier.h" #include -#include +#include namespace Light { @@ -24,10 +24,11 @@ namespace Light { m_GraphicsAPI = GraphicsAPI::OpenGL; glfwMakeContextCurrent(windowHandle); - LT_ENGINE_ASSERT(gladLoadGLLoader((GLADloadproc)glfwGetProcAddress), - "glGraphicsContext::glGraphicsContext: gladLoadGLLoader: failed to initialize opengl context"); + + if(!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) + { exit(1); } - SetDebugMessageCallback(); + } void glGraphicsContext::OnWindowResize(const WindowResizedEvent& event) diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.cpp index 6f470a1..8c2777c 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glShader.cpp @@ -36,6 +36,9 @@ namespace Light { std::vector errorLog(maxLength); glGetShaderInfoLog(vertexShader, maxLength, &maxLength, &errorLog[0]); + for(int i = 0; i < errorLog.size() -1; i++) + std::cout << errorLog[i]; + glDeleteShader(vertexShader); } diff --git a/Engine/src/Platform/OS/Windows/wWindow.cpp b/Engine/src/Platform/OS/Windows/wWindow.cpp index 2534ee9..ba09115 100644 --- a/Engine/src/Platform/OS/Windows/wWindow.cpp +++ b/Engine/src/Platform/OS/Windows/wWindow.cpp @@ -24,8 +24,12 @@ namespace Light { LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: failed to initialize glfw"); // create window - glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); - m_Handle = glfwCreateWindow(1u, 1u, "", nullptr, nullptr); + + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + + m_Handle = glfwCreateWindow(800u, 600u, "", nullptr, nullptr); LT_ENGINE_ASSERT(m_Handle, "wWindow::wWindow: glfwCreateWindow: failed to create glfw window"); @@ -34,7 +38,7 @@ namespace Light { BindGlfwEvents(); // create graphics context - m_GraphicsContext = std::unique_ptr(GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle)); + m_GraphicsContext = std::unique_ptr(GraphicsContext::Create(GraphicsAPI::OpenGL, m_Handle)); LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create graphics context"); } @@ -109,7 +113,8 @@ namespace Light { glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); - callback(MouseMovedEvent(xpos, ypos)); + MouseMovedEvent event(xpos, ypos); + callback(event); }); glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods) @@ -117,15 +122,25 @@ namespace Light { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); if (action == GLFW_PRESS) - callback(ButtonPressedEvent(button)); + { + ButtonPressedEvent event(button); + callback(event); + } + else - callback(ButtonReleasedEvent(button)); + { + ButtonReleasedEvent event(button); + callback(event); + } + }); glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); - callback(WheelScrolledEvent(yoffset)); + + WheelScrolledEvent event(yoffset); + callback(event); }); // Keyboard Events // @@ -134,28 +149,41 @@ namespace Light { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); if (action == GLFW_PRESS) - callback(KeyPressedEvent(key)); + { + KeyPressedEvent event(key); + callback(event); + } else - callback(KeyReleasedEvent(key)); + { + KeyReleasedEvent event(key); + callback(event); + } + }); // Window Events // glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); - callback(WindowMovedEvent(xpos, ypos)); + WindowMovedEvent event(xpos, ypos); + + callback(event); }); glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); - callback(WindowResizedEvent(width, height)); + WindowResizedEvent event(width, height); + + callback(event); }); glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); - callback(WindowClosedEvent()); + WindowClosedEvent event; + + callback(event); }); glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus) @@ -163,10 +191,15 @@ namespace Light { std::function callback = *(std::function*)glfwGetWindowUserPointer(window); if(focus == GLFW_TRUE) - callback(WindowGainFocusEvent()); + { + WindowGainFocusEvent event; + callback(event); + } else - callback(WindowLostFocusEvent()); - }); + { + WindowLostFocusEvent event; + callback(event); + } + }); } - } \ No newline at end of file diff --git a/Sandbox/imgui.ini b/Sandbox/imgui.ini index ad68c9b..7e523c2 100644 --- a/Sandbox/imgui.ini +++ b/Sandbox/imgui.ini @@ -4,8 +4,8 @@ Size=400,400 Collapsed=0 [Window][Dear ImGui Demo] -Pos=-16,5 -Size=405,290 +Pos=556,321 +Size=241,281 Collapsed=0 [Window][Dear ImGui Metrics/Debugger] diff --git a/Sandbox/premake5.lua b/Sandbox/premake5.lua index e40641e..c33c05d 100644 --- a/Sandbox/premake5.lua +++ b/Sandbox/premake5.lua @@ -51,6 +51,16 @@ project "Sandbox" systemversion "latest" staticruntime "On" + -- linux + filter "system:linux" + defines "LIGHT_PLATFORM_LINUX" + + links + { + "dl", + "pthread", + } + -- debug filter "configurations:Debug" defines "LIGHT_DEBUG" diff --git a/Sandbox/src/SandboxApp.cpp b/Sandbox/src/SandboxApp.cpp index af04a1e..8e686e7 100644 --- a/Sandbox/src/SandboxApp.cpp +++ b/Sandbox/src/SandboxApp.cpp @@ -1,5 +1,6 @@ #define LIGHT_ENTRY_POINT #include +#include #include "SandboxLayer.h"