Debug
- Added the Debug folder - Moved the Logger from Core to Debug - Added Exceptions ( glException & dxException ) - Debugging the graphics is now a bit easier
This commit is contained in:
		
							parent
							
								
									bb604e9540
								
							
						
					
					
						commit
						31560897cd
					
				
					 11 changed files with 103 additions and 17 deletions
				
			
		| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
#pragma once
 | 
			
		||||
 | 
			
		||||
#ifndef LOGGER_H
 | 
			
		||||
	#include "Core/Logger.h"
 | 
			
		||||
	#include "Debug/Logger.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "Debug/Exceptions.h"
 | 
			
		||||
 | 
			
		||||
#include <memory>
 | 
			
		||||
 | 
			
		||||
#define LT_WIN(x) 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,6 @@
 | 
			
		|||
#include "ltpch.h"
 | 
			
		||||
#include "Application.h"
 | 
			
		||||
 | 
			
		||||
#include "Logger.h"
 | 
			
		||||
#include "Window.h"
 | 
			
		||||
 | 
			
		||||
#include "Events/Event.h"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										49
									
								
								Engine/src/Engine/Debug/Exceptions.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								Engine/src/Engine/Debug/Exceptions.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,49 @@
 | 
			
		|||
#include "ltpch.h"
 | 
			
		||||
#include "Exceptions.h"
 | 
			
		||||
 | 
			
		||||
#include "Utility/Stringifier.h"
 | 
			
		||||
 | 
			
		||||
#include <glad/glad.h>
 | 
			
		||||
 | 
			
		||||
#ifdef LIGHT_PLATFORM_WINDOWS
 | 
			
		||||
	#include <Windows.h>
 | 
			
		||||
#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);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								Engine/src/Engine/Debug/Exceptions.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								Engine/src/Engine/Debug/Exceptions.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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);
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,14 +2,36 @@
 | 
			
		|||
 | 
			
		||||
#ifdef LIGHT_PLATFORM_WINDOWS
 | 
			
		||||
 | 
			
		||||
#include <LightEngine.h>
 | 
			
		||||
 | 
			
		||||
// 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
 | 
			
		||||
| 
						 | 
				
			
			@ -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"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,4 +3,3 @@
 | 
			
		|||
#include "Base.h"
 | 
			
		||||
 | 
			
		||||
// DirectX Call
 | 
			
		||||
#define DXC(x) hr = x; if(FAILED(x)) __debugbreak()
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue