diff --git a/Engine/src/Engine/Base.h b/Engine/src/Engine/Base.h index e306895..d4bbbe0 100644 --- a/Engine/src/Engine/Base.h +++ b/Engine/src/Engine/Base.h @@ -1,9 +1,11 @@ #pragma once #ifndef LOGGER_H - #include "Core/Logger.h" + #include "Debug/Logger.h" #endif +#include "Debug/Exceptions.h" + #include #define LT_WIN(x) diff --git a/Engine/src/Engine/Core/Application.cpp b/Engine/src/Engine/Core/Application.cpp index 494438b..36bdf96 100644 --- a/Engine/src/Engine/Core/Application.cpp +++ b/Engine/src/Engine/Core/Application.cpp @@ -1,7 +1,6 @@ #include "ltpch.h" #include "Application.h" -#include "Logger.h" #include "Window.h" #include "Events/Event.h" diff --git a/Engine/src/Engine/Debug/Exceptions.cpp b/Engine/src/Engine/Debug/Exceptions.cpp new file mode 100644 index 0000000..ce6d7a0 --- /dev/null +++ b/Engine/src/Engine/Debug/Exceptions.cpp @@ -0,0 +1,49 @@ +#include "ltpch.h" +#include "Exceptions.h" + +#include "Utility/Stringifier.h" + +#include + +#ifdef LIGHT_PLATFORM_WINDOWS + #include +#endif + +namespace Light { + + glException::glException(unsigned int source, unsigned int type, unsigned int id, const char* msg) + { + LT_ENGINE_CRITICAL("________________________________________"); + LT_ENGINE_CRITICAL("glException::glException::"); + LT_ENGINE_CRITICAL(" Severity: {}", Stringifier::glDebugMsgSeverity(GL_DEBUG_SEVERITY_HIGH)); + LT_ENGINE_CRITICAL(" Source : {}", Stringifier::glDebugMsgSource(source)); + LT_ENGINE_CRITICAL(" Type : {}", Stringifier::glDebugMsgType(type)); + LT_ENGINE_CRITICAL(" ID : {}", id); + LT_ENGINE_CRITICAL(" Vendor : {}", glGetString(GL_VENDOR)); + LT_ENGINE_CRITICAL(" Renderer: {}", glGetString(GL_RENDERER)); + LT_ENGINE_CRITICAL(" Version : {}", glGetString(GL_VERSION)); + LT_ENGINE_CRITICAL(" SVersion: {}", glGetString(GL_SHADING_LANGUAGE_VERSION)); + LT_ENGINE_CRITICAL(" {}", msg); + + LT_ENGINE_CRITICAL("________________________________________"); + } + + dxException::dxException(long hr, const char* file, int line) + { + char* message; + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, hr, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)(&message), NULL, nullptr); + + // #todo: format better + LT_ENGINE_CRITICAL("________________________________________"); + LT_ENGINE_CRITICAL("dxException::dxException::"); + LT_ENGINE_CRITICAL(" File: {}, Line: {}", file, line); + LT_ENGINE_CRITICAL(" {}", message); + LT_ENGINE_CRITICAL("________________________________________"); + + LocalFree(message); + } + +} \ No newline at end of file diff --git a/Engine/src/Engine/Debug/Exceptions.h b/Engine/src/Engine/Debug/Exceptions.h new file mode 100644 index 0000000..392bca6 --- /dev/null +++ b/Engine/src/Engine/Debug/Exceptions.h @@ -0,0 +1,19 @@ +#pragma once + +#define DXC(x) hr = x; if(FAILED(x)) throw dxException(hr, __FILE__, __LINE__) + +namespace Light { + + // OpenGL + struct glException : std::exception + { + glException(unsigned int source, unsigned int type, unsigned int id, const char* msg); + }; + + // DirectX + struct dxException : std::exception + { + dxException(long hr, const char* file, int line); + }; + +} \ No newline at end of file diff --git a/Engine/src/Engine/Core/Logger.cpp b/Engine/src/Engine/Debug/Logger.cpp similarity index 100% rename from Engine/src/Engine/Core/Logger.cpp rename to Engine/src/Engine/Debug/Logger.cpp diff --git a/Engine/src/Engine/Core/Logger.h b/Engine/src/Engine/Debug/Logger.h similarity index 100% rename from Engine/src/Engine/Core/Logger.h rename to Engine/src/Engine/Debug/Logger.h diff --git a/Engine/src/Engine/EntryPoint.h b/Engine/src/Engine/EntryPoint.h index 08f9117..f8c812f 100644 --- a/Engine/src/Engine/EntryPoint.h +++ b/Engine/src/Engine/EntryPoint.h @@ -2,14 +2,36 @@ #ifdef LIGHT_PLATFORM_WINDOWS +#include + // To be defined in client project extern Light::Application* Light::CreateApplication(); int main(int argc, char** argv) { - auto application = Light::CreateApplication(); - application->GameLoop(); + 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::glException) + { + LT_ENGINE_CRITICAL("main: exitting due to unhandled glException"); + exitCode = -2; + } + catch (Light::dxException) + { + LT_ENGINE_CRITICAL("main: exitting due to unhandled dxException"); + exitCode = -3; + } + delete application; + return exitCode; } #endif \ No newline at end of file diff --git a/Engine/src/LightEngine.h b/Engine/src/LightEngine.h index 512e628..3755a02 100644 --- a/Engine/src/LightEngine.h +++ b/Engine/src/LightEngine.h @@ -3,7 +3,9 @@ // Core #include "Core/Application.h" #include "Core/Window.h" -#include "Core/Logger.h" + +// Debug +#include "Debug/Logger.h" // Events #include "Events/Event.h" diff --git a/Engine/src/Platform/GraphicsAPI/DirectX/dxBase.h b/Engine/src/Platform/GraphicsAPI/DirectX/dxBase.h index 3e856ee..840119e 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxBase.h +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxBase.h @@ -3,4 +3,3 @@ #include "Base.h" // DirectX Call -#define DXC(x) hr = x; if(FAILED(x)) __debugbreak() \ 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 86bb1ed..fbdb1e6 100644 --- a/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp +++ b/Engine/src/Platform/GraphicsAPI/DirectX/dxGraphicsContext.cpp @@ -107,13 +107,11 @@ namespace Light { void dxGraphicsContext::LogDebugData() { - // log some information about dx context // // locals IDXGIDevice* DXGIDevice; IDXGIAdapter* DXGIAdapter; DXGI_ADAPTER_DESC DXGIAdapterDesc; - // initialize Locals m_Device->QueryInterface(__uuidof(IDXGIDevice), (void**)&DXGIDevice); DXGIDevice->GetAdapter(&DXGIAdapter); DXGIAdapter->GetDesc(&DXGIAdapterDesc); diff --git a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp index 51c40b8..071a661 100644 --- a/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp +++ b/Engine/src/Platform/GraphicsAPI/OpenGL/glGraphicsContext.cpp @@ -43,6 +43,7 @@ namespace Light { void glGraphicsContext::LogDebugData() { + // #todo: log more information LT_ENGINE_INFO("________________________________________"); LT_ENGINE_INFO("GraphicsContext::"); LT_ENGINE_INFO(" API : OpenGL"); @@ -53,10 +54,10 @@ namespace Light { void glGraphicsContext::SetDebugMessageCallback() { -#if defined(LT_DEBUG) +#if defined(LIGHT_DEBUG) glEnable(GL_DEBUG_OUTPUT); glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE); -#elif defined(LT_RELEASE) +#elif defined(LIGHT_RELEASE) 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); @@ -72,14 +73,9 @@ namespace Light { switch (severity) { case GL_DEBUG_SEVERITY_HIGH: - LT_ENGINE_CRITICAL("glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}", - Stringifier::glDebugMsgSeverity(severity), - Stringifier::glDebugMsgSource(source), - Stringifier::glDebugMsgType(type), - id); - __debugbreak(); - LT_ENGINE_CRITICAL(" {}", message); + throw glException(source, type, id, message); return; + case GL_DEBUG_SEVERITY_MEDIUM: case GL_DEBUG_SEVERITY_LOW: LT_ENGINE_WARN("glMessageCallback: Severity: {} :: Source: {} :: Type: {} :: ID: {}", Stringifier::glDebugMsgSeverity(severity),