Maintenance
- Some tidying - Minor fixes
This commit is contained in:
		
							parent
							
								
									31560897cd
								
							
						
					
					
						commit
						21e4432c60
					
				
					 16 changed files with 158 additions and 83 deletions
				
			
		| 
						 | 
					@ -7,53 +7,57 @@ project "Engine"
 | 
				
			||||||
	objdir    ("%{wks.location}/bin-int/" .. outputdir)
 | 
						objdir    ("%{wks.location}/bin-int/" .. outputdir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	-- Compiler --
 | 
						-- Compiler --
 | 
				
			||||||
 | 
						-- kind
 | 
				
			||||||
	kind "StaticLib"
 | 
						kind "StaticLib"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-- language
 | 
				
			||||||
	language "C++"
 | 
						language "C++"
 | 
				
			||||||
	cppdialect "C++17"
 | 
						cppdialect "C++17"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						-- pch
 | 
				
			||||||
	pchsource "src/Engine/ltpch.cpp"
 | 
						pchsource "src/Engine/ltpch.cpp"
 | 
				
			||||||
	pchheader "ltpch.h"
 | 
						pchheader "ltpch.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	-- Project Files ---
 | 
						-- Project Files ---
 | 
				
			||||||
	files
 | 
						files
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		"%{prj.location}/src/**.h",
 | 
							"%{prj.location}/src/**.h"      ,
 | 
				
			||||||
		"%{prj.location}/src/**.cpp",
 | 
							"%{prj.location}/src/**.cpp"    ,
 | 
				
			||||||
		"%{prj.location}/**.lua",
 | 
							"%{prj.location}/**.lua"        ,
 | 
				
			||||||
 | 
							"%{prj.location}/dxgidebug.dll" ,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	-- Dependencies --
 | 
						-- Dependencies --
 | 
				
			||||||
	includedirs
 | 
						includedirs
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		-- Engine
 | 
							-- engine
 | 
				
			||||||
		"%{prj.location}/src/",
 | 
							"%{prj.location}/src/"                     ,
 | 
				
			||||||
		"%{prj.location}/src/Engine/",
 | 
							"%{prj.location}/src/Engine/"              ,
 | 
				
			||||||
		"%{prj.location}/src/Platform/GraphicsAPI",
 | 
							"%{prj.location}/src/Platform/GraphicsAPI" ,
 | 
				
			||||||
		"%{prj.location}/src/Platform/OS",
 | 
							"%{prj.location}/src/Platform/OS"          ,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		-- 3rd party
 | 
							-- 3rd party
 | 
				
			||||||
		(dependenciesdir .. "spdlog/include/"),
 | 
							(dependenciesdir .. "spdlog/include/"),
 | 
				
			||||||
		(dependenciesdir .. "glfw/include/"),
 | 
							(dependenciesdir .. "glfw/include/"  ),
 | 
				
			||||||
		(dependenciesdir .. "glad/include"),
 | 
							(dependenciesdir .. "glad/include"   ),
 | 
				
			||||||
		(dependenciesdir .. "imgui/"),
 | 
							(dependenciesdir .. "imgui/backends" ),
 | 
				
			||||||
		(dependenciesdir .. "imgui/backends"),
 | 
							(dependenciesdir .. "imgui/"         ),
 | 
				
			||||||
		(dependenciesdir .. "glm/"),
 | 
							(dependenciesdir .. "glm/"           ),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	links
 | 
						links
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		"GLFW",
 | 
							"GLFW"  ,
 | 
				
			||||||
		"GLAD",
 | 
							"GLAD"  ,
 | 
				
			||||||
		"ImGui",
 | 
							"ImGui" ,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	--- Filters ---
 | 
						--- Filters ---
 | 
				
			||||||
	-- windows
 | 
						-- windows
 | 
				
			||||||
 | 
					 | 
				
			||||||
	filter "system:windows"
 | 
						filter "system:windows"
 | 
				
			||||||
		defines "LIGHT_PLATFORM_WINDOWS"
 | 
							defines "LIGHT_PLATFORM_WINDOWS"
 | 
				
			||||||
		systemversion "latest"
 | 
							systemversion "latest"
 | 
				
			||||||
		staticruntime "On"
 | 
							staticruntime "on"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		links
 | 
							links
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
| 
						 | 
					@ -62,10 +66,6 @@ project "Engine"
 | 
				
			||||||
			"D3DCompiler.lib" ,
 | 
								"D3DCompiler.lib" ,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	filter "system:not windows"
 | 
					 | 
				
			||||||
		excludes "%{prj.location}/src/Platform/GraphicsAPI/DirectX**"
 | 
					 | 
				
			||||||
		excludes "%{prj.location}/src/Platform/OS/Windows**"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	-- debug
 | 
						-- debug
 | 
				
			||||||
	filter "configurations:Debug"
 | 
						filter "configurations:Debug"
 | 
				
			||||||
		defines "LIGHT_DEBUG"
 | 
							defines "LIGHT_DEBUG"
 | 
				
			||||||
| 
						 | 
					@ -80,3 +80,11 @@ project "Engine"
 | 
				
			||||||
	filter "configurations:Distribution"
 | 
						filter "configurations:Distribution"
 | 
				
			||||||
		defines "LIGHT_DIST"
 | 
							defines "LIGHT_DIST"
 | 
				
			||||||
		optimize "on"
 | 
							optimize "on"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						--- Excludes ---
 | 
				
			||||||
 | 
						-- !windows
 | 
				
			||||||
 | 
						filter "system:not windows"
 | 
				
			||||||
 | 
							excludes "%{prj.location}/src/Platform/GraphicsAPI/DirectX**"
 | 
				
			||||||
 | 
							excludes "%{prj.location}/src/Platform/OS/Windows**"
 | 
				
			||||||
 | 
						-- !linux #todo:
 | 
				
			||||||
 | 
						-- !mac #todo:
 | 
				
			||||||
| 
						 | 
					@ -8,9 +8,9 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define LT_WIN(x) 
 | 
					#define LT_WIN(x) // Windows
 | 
				
			||||||
#define LT_LIN(x)
 | 
					#define LT_LIN(x) // Linux
 | 
				
			||||||
#define LT_MAC(x)
 | 
					#define LT_MAC(x) // Mac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined(LIGHT_PLATFORM_WINDOWS)
 | 
					#if defined(LIGHT_PLATFORM_WINDOWS)
 | 
				
			||||||
	#define LT_BUILD_PLATFORM "Windows"
 | 
						#define LT_BUILD_PLATFORM "Windows"
 | 
				
			||||||
| 
						 | 
					@ -27,5 +27,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define BIT(x) 1 << x
 | 
					#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(); } }
 | 
					#define LT_ENGINE_ASSERT(x, ...) { if(!(x)) { LT_ENGINE_CRITICAL(__VA_ARGS__); __debugbreak(); } }
 | 
				
			||||||
#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); __debugbreak(); } }
 | 
					#define LT_CLIENT_ASSERT(x, ...) { if(!(x)) { LT_CLIENT_CRITICAL(__VA_ARGS__); __debugbreak(); } }
 | 
				
			||||||
| 
						 | 
					@ -30,15 +30,16 @@ namespace Light {
 | 
				
			||||||
		LT_ENGINE_ASSERT(!m_LayerStack.IsEmpty(), "Application::GameLoop: Layerstack is empty");
 | 
							LT_ENGINE_ASSERT(!m_LayerStack.IsEmpty(), "Application::GameLoop: Layerstack is empty");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Log window data
 | 
							// Log window data
 | 
				
			||||||
 | 
							Logger::LogDebugData();
 | 
				
			||||||
		LogDebugData();
 | 
							LogDebugData();
 | 
				
			||||||
		m_Window->GetGfxContext()->LogDebugData();
 | 
							m_Window->GetGfxContext()->LogDebugData();
 | 
				
			||||||
		m_Window->GetGfxContext()->GetUserInterface()->LogDebugData();
 | 
							m_Window->GetGfxContext()->GetUserInterface()->LogDebugData();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Show window
 | 
							// Show window
 | 
				
			||||||
		m_Window->SetVisible(true);
 | 
							m_Window->SetVisibility(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		//  GAMELOOP  //
 | 
							//  GAMELOOP  //
 | 
				
			||||||
		while (m_Window->IsOpen())
 | 
							while (!m_Window->IsClosed())
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			// Events
 | 
								// Events
 | 
				
			||||||
			m_Window->PollEvents();
 | 
								m_Window->PollEvents();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,8 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "Base.h"
 | 
					#include "Base.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <glm/glm.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Light {
 | 
					namespace Light {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	class Event;
 | 
						class Event;
 | 
				
			||||||
| 
						 | 
					@ -10,15 +12,16 @@ namespace Light {
 | 
				
			||||||
	struct WindowProperties
 | 
						struct WindowProperties
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		std::string title;
 | 
							std::string title;
 | 
				
			||||||
		unsigned int width, height;
 | 
							glm::uvec2 size;
 | 
				
			||||||
		bool vsync;
 | 
							bool vsync, visible;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	class Window
 | 
						class Window
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	protected:
 | 
						protected:
 | 
				
			||||||
		std::unique_ptr<GraphicsContext> m_GraphicsContext;
 | 
							std::unique_ptr<GraphicsContext> m_GraphicsContext;
 | 
				
			||||||
		bool b_Open;
 | 
							WindowProperties m_Properties = {};
 | 
				
			||||||
 | 
							bool b_Closed = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
		static Window* Create(std::function<void(Event&)> callback);
 | 
							static Window* Create(std::function<void(Event&)> callback);
 | 
				
			||||||
| 
						 | 
					@ -28,21 +31,33 @@ namespace Light {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual ~Window() = default;
 | 
							virtual ~Window() = default;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual void SetProperties(const WindowProperties& properties) = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		virtual void SetVisible(bool visible) = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		inline GraphicsContext* GetGfxContext() { return m_GraphicsContext.get(); }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		inline bool IsOpen() const { return b_Open; }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		virtual void PollEvents() = 0;
 | 
							virtual void PollEvents() = 0;
 | 
				
			||||||
		virtual void OnEvent(const Event& event) = 0;
 | 
							virtual void OnEvent(const Event& event) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual unsigned int GetHeight() = 0;
 | 
							// Setters //
 | 
				
			||||||
		virtual unsigned int GetWidth()  = 0;
 | 
							virtual void SetProperties(const WindowProperties& properties) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual inline void* GetNativeHandle() = 0;
 | 
							virtual void SetTitle(const std::string& title) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							virtual void SetSize(const glm::uvec2& size) = 0; // pass 0 for width or height for single dimension resizing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							inline void Close() { b_Closed = true; }
 | 
				
			||||||
 | 
							virtual void SetVSync(bool vsync, bool toggle = false) = 0;
 | 
				
			||||||
 | 
							virtual void SetVisibility(bool visible, bool toggle = false) = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Getters //
 | 
				
			||||||
 | 
							inline GraphicsContext* GetGfxContext() const { return m_GraphicsContext.get(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							inline const WindowProperties& GetProperties() const { return m_Properties; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							inline const std::string& GetTitle() const { return m_Properties.title; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							inline const glm::uvec2& GetSize() const { return m_Properties.size; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							inline bool IsClosed() const { return b_Closed; }
 | 
				
			||||||
 | 
							inline bool IsVSync() const { return m_Properties.vsync; }
 | 
				
			||||||
 | 
							inline bool IsVisible() const { return m_Properties.visible; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected:
 | 
						protected:
 | 
				
			||||||
		Window() = default;
 | 
							Window() = default;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,7 @@ namespace Light {
 | 
				
			||||||
		LT_ENGINE_CRITICAL("________________________________________");
 | 
							LT_ENGINE_CRITICAL("________________________________________");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						LT_WIN(
 | 
				
			||||||
	dxException::dxException(long hr, const char* file, int line)
 | 
						dxException::dxException(long hr, const char* file, int line)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		char* message;
 | 
							char* message;
 | 
				
			||||||
| 
						 | 
					@ -44,6 +45,6 @@ namespace Light {
 | 
				
			||||||
		LT_ENGINE_CRITICAL("________________________________________");
 | 
							LT_ENGINE_CRITICAL("________________________________________");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		LocalFree(message);
 | 
							LocalFree(message);
 | 
				
			||||||
	}
 | 
						})
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -10,10 +10,12 @@ namespace Light {
 | 
				
			||||||
		glException(unsigned int source, unsigned int type, unsigned int id, const char* msg);
 | 
							glException(unsigned int source, unsigned int type, unsigned int id, const char* msg);
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef LIGHT_PLATFORM_WINDOWS
 | 
				
			||||||
	// DirectX
 | 
						// DirectX
 | 
				
			||||||
	struct dxException : std::exception
 | 
						struct dxException : std::exception
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		dxException(long hr, const char* file, int line);
 | 
							dxException(long hr, const char* file, int line);
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -12,16 +12,30 @@ namespace Light {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void Light::Logger::Initialize()
 | 
						void Light::Logger::Initialize()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// Set spdlog pattern
 | 
							// set spdlog pattern
 | 
				
			||||||
		spdlog::set_pattern("%^[%M:%S:%e] <%n>: %v%$");
 | 
							spdlog::set_pattern("%^[%M:%S:%e] <%n>: %v%$");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Create loggers and set levels to minimum
 | 
							// create loggers
 | 
				
			||||||
		s_EngineLogger = spdlog::stdout_color_mt("Engine");
 | 
							s_EngineLogger = spdlog::stdout_color_mt("Engine");
 | 
				
			||||||
		s_EngineLogger->set_level(spdlog::level::trace);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		s_ClientLogger = spdlog::stdout_color_mt("Client");
 | 
							s_ClientLogger = spdlog::stdout_color_mt("Client");
 | 
				
			||||||
		s_ClientLogger->set_level(spdlog::level::trace);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// set level
 | 
				
			||||||
 | 
					#if defined(LIGHT_DEBUG)
 | 
				
			||||||
 | 
							s_EngineLogger->set_level(spdlog::level::trace);
 | 
				
			||||||
 | 
							s_ClientLogger->set_level(spdlog::level::trace);
 | 
				
			||||||
 | 
					#elif defined (LIGHT_RELEASE)
 | 
				
			||||||
 | 
							s_EngineLogger->set_level(spdlog::level::info);
 | 
				
			||||||
 | 
							s_ClientLogger->set_level(spdlog::level::info);
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
							s_EngineLogger->set_level(spdlog::level::off);
 | 
				
			||||||
 | 
							s_ClientLogger->set_level(spdlog::level::off);
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void Logger::LogDebugData()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
		LT_ENGINE_INFO("________________________________________");
 | 
							LT_ENGINE_INFO("________________________________________");
 | 
				
			||||||
		LT_ENGINE_INFO("Logger::");
 | 
							LT_ENGINE_INFO("Logger::");
 | 
				
			||||||
		LT_ENGINE_INFO("        ClientLevel: {}", Stringifier::spdlogLevel(s_ClientLogger->level()));
 | 
							LT_ENGINE_INFO("        ClientLevel: {}", Stringifier::spdlogLevel(s_ClientLogger->level()));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,6 +34,7 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Light {
 | 
					namespace Light {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// #todo: add a FileLogger
 | 
				
			||||||
	class Logger
 | 
						class Logger
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
| 
						 | 
					@ -46,6 +47,8 @@ namespace Light {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		static inline std::shared_ptr<spdlog::logger> GetEngineLogger() { return s_EngineLogger; }
 | 
							static inline std::shared_ptr<spdlog::logger> GetEngineLogger() { return s_EngineLogger; }
 | 
				
			||||||
		static inline std::shared_ptr<spdlog::logger> GetClientLogger() { return s_ClientLogger; }
 | 
							static inline std::shared_ptr<spdlog::logger> GetClientLogger() { return s_ClientLogger; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							static void LogDebugData();
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -18,8 +18,8 @@ namespace Light {
 | 
				
			||||||
		case GraphicsAPI::OpenGL:
 | 
							case GraphicsAPI::OpenGL:
 | 
				
			||||||
			return new glVertexBuffer(vertices, count);
 | 
								return new glVertexBuffer(vertices, count);
 | 
				
			||||||
			
 | 
								
 | 
				
			||||||
		case GraphicsAPI::DirectX:
 | 
							case GraphicsAPI::DirectX: LT_WIN(
 | 
				
			||||||
			return new dxVertexBuffer(vertices, stride, count, sharedContext);
 | 
								return new dxVertexBuffer(vertices, stride, count, sharedContext);)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		default:
 | 
							default:
 | 
				
			||||||
			LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported GraphicsAPI {}", GraphicsContext::GetGraphicsAPI());
 | 
								LT_ENGINE_ASSERT(false, "VertexBuffer::Create: invalid/unsupported GraphicsAPI {}", GraphicsContext::GetGraphicsAPI());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -49,16 +49,19 @@ namespace Light {
 | 
				
			||||||
		const float xMax = position.x + size.x;
 | 
							const float xMax = position.x + size.x;
 | 
				
			||||||
		const float yMax = position.y + size.y;
 | 
							const float yMax = position.y + size.y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		
 | 
							// TOP_LEFT
 | 
				
			||||||
		m_QuadRenderer.mapCurrent[0].position = { xMin, yMin, position.z };
 | 
							m_QuadRenderer.mapCurrent[0].position = { xMin, yMin, position.z };
 | 
				
			||||||
		m_QuadRenderer.mapCurrent[0].tint = glm::vec4(0.1f, 0.1f, 1.0f, 1.0f);
 | 
							m_QuadRenderer.mapCurrent[0].tint = glm::vec4(0.1f, 0.1f, 1.0f, 1.0f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// TOP_RIGHT
 | 
				
			||||||
		m_QuadRenderer.mapCurrent[1].position = { xMax, yMin, position.z };
 | 
							m_QuadRenderer.mapCurrent[1].position = { xMax, yMin, position.z };
 | 
				
			||||||
		m_QuadRenderer.mapCurrent[1].tint = glm::vec4(0.3f, 0.3f, 0.3f, 1.0f);
 | 
							m_QuadRenderer.mapCurrent[1].tint = glm::vec4(0.3f, 0.3f, 0.3f, 1.0f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// BOTTOM_RIGHT
 | 
				
			||||||
		m_QuadRenderer.mapCurrent[2].position = { xMax, yMax, position.z };
 | 
							m_QuadRenderer.mapCurrent[2].position = { xMax, yMax, position.z };
 | 
				
			||||||
		m_QuadRenderer.mapCurrent[2].tint = glm::vec4(0.1f, 1.0f, 0.1f, 1.0f);
 | 
							m_QuadRenderer.mapCurrent[2].tint = glm::vec4(0.1f, 1.0f, 0.1f, 1.0f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// BOTTOM_LEFT
 | 
				
			||||||
		m_QuadRenderer.mapCurrent[3].position = { xMin, yMax, position.z };
 | 
							m_QuadRenderer.mapCurrent[3].position = { xMin, yMax, position.z };
 | 
				
			||||||
		m_QuadRenderer.mapCurrent[3].tint = glm::vec4(1.0f, 0.1f, 0.1f, 1.0f);
 | 
							m_QuadRenderer.mapCurrent[3].tint = glm::vec4(1.0f, 0.1f, 0.1f, 1.0f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,7 +14,8 @@ namespace Light {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	LayerStack::LayerStack()
 | 
						LayerStack::LayerStack()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		s_Context = this; // TODO: ASSERT
 | 
							LT_ENGINE_ASSERT(!s_Context, "LayerStack::LayerStack: context re-initialization")
 | 
				
			||||||
 | 
							s_Context = this;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	LayerStack::~LayerStack()
 | 
						LayerStack::~LayerStack()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,33 +1,39 @@
 | 
				
			||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Core
 | 
					// Core -------------------------
 | 
				
			||||||
#include "Core/Application.h"
 | 
					#include "Core/Application.h"
 | 
				
			||||||
#include "Core/Window.h"
 | 
					#include "Core/Window.h"
 | 
				
			||||||
 | 
					// -----------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Debug 
 | 
					// Debug 
 | 
				
			||||||
#include "Debug/Logger.h"
 | 
					#include "Debug/Logger.h"
 | 
				
			||||||
 | 
					// -----------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Events
 | 
					// Events ----------------------
 | 
				
			||||||
#include "Events/Event.h"
 | 
					#include "Events/Event.h"
 | 
				
			||||||
#include "Events/KeyboardEvents.h"
 | 
					#include "Events/KeyboardEvents.h"
 | 
				
			||||||
#include "Events/MouseEvents.h"
 | 
					#include "Events/MouseEvents.h"
 | 
				
			||||||
#include "Events/WindowEvents.h"
 | 
					#include "Events/WindowEvents.h"
 | 
				
			||||||
 | 
					// -----------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Graphics
 | 
					// Graphics --------------------
 | 
				
			||||||
#include "Graphics/GraphicsContext.h"
 | 
					#include "Graphics/GraphicsContext.h"
 | 
				
			||||||
#include "Graphics/RenderCommand.h"
 | 
					 | 
				
			||||||
#include "Graphics/Renderer.h"
 | 
					#include "Graphics/Renderer.h"
 | 
				
			||||||
 | 
					// -----------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Layer
 | 
					// Layer -----------------------
 | 
				
			||||||
#include "Layer/Layer.h"
 | 
					#include "Layer/Layer.h"
 | 
				
			||||||
#include "Layer/LayerStack.h"
 | 
					#include "Layer/LayerStack.h"
 | 
				
			||||||
 | 
					// -----------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UserInterface
 | 
					// UserInterface ---------------
 | 
				
			||||||
#include "UserInterface/UserInterface.h"
 | 
					#include "UserInterface/UserInterface.h"
 | 
				
			||||||
 | 
					// -----------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Base
 | 
					// Base -----------------------
 | 
				
			||||||
#include "Base.h"
 | 
					#include "Base.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef LIGHT_ENTRY_POINT
 | 
					#ifdef LIGHT_ENTRY_POINT
 | 
				
			||||||
	#include "EntryPoint.h"
 | 
						#include "EntryPoint.h"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					// -----------------------------
 | 
				
			||||||
| 
						 | 
					@ -9,8 +9,9 @@ namespace Light {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	glVertexLayout::glVertexLayout(VertexBuffer* buffer, const std::vector<std::pair<std::string, VertexElementType>>& elements)
 | 
						glVertexLayout::glVertexLayout(VertexBuffer* buffer, const std::vector<std::pair<std::string, VertexElementType>>& elements)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		// sanity check
 | 
							// check
 | 
				
			||||||
		LT_ENGINE_ASSERT(dynamic_cast<glVertexBuffer*>(buffer), "glVertexLayout::glVertexLayout: failed to cast VertexBuffer to glVertexBuffer");
 | 
							LT_ENGINE_ASSERT(dynamic_cast<glVertexBuffer*>(buffer), "glVertexLayout::glVertexLayout: failed to cast VertexBuffer to glVertexBuffer");
 | 
				
			||||||
 | 
							LT_ENGINE_ASSERT(!elements.empty(), "glVertexLayout::glVertexLayout: elements is empty");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// elements desc
 | 
							// elements desc
 | 
				
			||||||
		std::vector<glVertexElementDesc> elementsDesc;
 | 
							std::vector<glVertexElementDesc> elementsDesc;
 | 
				
			||||||
| 
						 | 
					@ -22,7 +23,7 @@ namespace Light {
 | 
				
			||||||
			stride += elementsDesc.back().typeSize * elementsDesc.back().count;
 | 
								stride += elementsDesc.back().typeSize * elementsDesc.back().count;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// bind
 | 
							// prepare
 | 
				
			||||||
		glCreateVertexArrays(1, &m_ArrayID);
 | 
							glCreateVertexArrays(1, &m_ArrayID);
 | 
				
			||||||
		buffer->Bind();
 | 
							buffer->Bind();
 | 
				
			||||||
		Bind();
 | 
							Bind();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,7 +20,7 @@ namespace Light {
 | 
				
			||||||
	wWindow::wWindow(std::function<void(Event&)> callback)
 | 
						wWindow::wWindow(std::function<void(Event&)> callback)
 | 
				
			||||||
		: m_EventCallback(callback)
 | 
							: m_EventCallback(callback)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: glfwInit: failed to initialize glfw");
 | 
							LT_ENGINE_ASSERT(glfwInit(), "wWindow::wWindow: failed to initialize glfw");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
 | 
							glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,7 +31,7 @@ namespace Light {
 | 
				
			||||||
		BindGlfwEvents();
 | 
							BindGlfwEvents();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		m_GraphicsContext = std::unique_ptr<GraphicsContext>(GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle));
 | 
							m_GraphicsContext = std::unique_ptr<GraphicsContext>(GraphicsContext::Create(GraphicsAPI::DirectX, m_Handle));
 | 
				
			||||||
		LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: graphics context creation failed");
 | 
							LT_ENGINE_ASSERT(m_GraphicsContext, "wWindow::wWindow: failed to create graphics context");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wWindow::~wWindow()
 | 
						wWindow::~wWindow()
 | 
				
			||||||
| 
						 | 
					@ -43,14 +43,16 @@ namespace Light {
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		m_Properties = properties;
 | 
							m_Properties = properties;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		glfwSetWindowSize(m_Handle, properties.width, properties.height);
 | 
							glfwSetWindowSize(m_Handle, properties.size.x, properties.size.y);
 | 
				
			||||||
		glfwSetWindowTitle(m_Handle, properties.title.c_str());
 | 
							glfwSetWindowTitle(m_Handle, properties.title.c_str());
 | 
				
			||||||
		glfwSwapInterval((int)properties.vsync);
 | 
							glfwSwapInterval((int)properties.vsync);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void wWindow::SetVisible(bool visible)
 | 
						void wWindow::SetVisibility(bool visible, bool toggle)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if (visible)
 | 
							m_Properties.visible = toggle ? !m_Properties.visible : visible;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (m_Properties.visible)
 | 
				
			||||||
			glfwShowWindow(m_Handle);
 | 
								glfwShowWindow(m_Handle);
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
			glfwHideWindow(m_Handle);
 | 
								glfwHideWindow(m_Handle);
 | 
				
			||||||
| 
						 | 
					@ -66,24 +68,40 @@ namespace Light {
 | 
				
			||||||
		switch (event.GetEventType())
 | 
							switch (event.GetEventType())
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
		case EventType::WindowClosed:
 | 
							case EventType::WindowClosed:
 | 
				
			||||||
			b_Open = false;
 | 
								b_Closed = true;
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		case EventType::WindowResized:
 | 
							case EventType::WindowResized:
 | 
				
			||||||
			m_GraphicsContext->OnWindowResize((const WindowResizedEvent&)event);
 | 
								m_GraphicsContext->OnWindowResize((const WindowResizedEvent&)event);
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	unsigned int wWindow::GetWidth()
 | 
						void wWindow::SetTitle(const std::string& title)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		return m_Properties.width;
 | 
							m_Properties.title = title;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							glfwSetWindowTitle(m_Handle, m_Properties.title.c_str());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	unsigned int wWindow::GetHeight()
 | 
						void wWindow::SetVSync(bool vsync, bool toggle /*= false*/)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		return m_Properties.height;
 | 
							m_Properties.vsync = toggle ? !m_Properties.vsync : vsync;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							glfwSwapInterval(m_Properties.vsync);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						void wWindow::SetSize(const glm::uvec2& size)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							m_Properties.size.x = size.x == 0u ? m_Properties.size.x : size.x;
 | 
				
			||||||
 | 
							m_Properties.size.y = size.y == 0u ? m_Properties.size.y : size.y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							glfwSetWindowSize(m_Handle, m_Properties.size.x, m_Properties.size.y);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void wWindow::BindGlfwEvents()
 | 
						void wWindow::BindGlfwEvents()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							// Mouse Events //
 | 
				
			||||||
		glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos)
 | 
							glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
 | 
								std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
 | 
				
			||||||
| 
						 | 
					@ -106,6 +124,7 @@ namespace Light {
 | 
				
			||||||
			callback(WheelScrolledEvent(yoffset));
 | 
								callback(WheelScrolledEvent(yoffset));
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Keyboard Events //
 | 
				
			||||||
		glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods)
 | 
							glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
 | 
								std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
 | 
				
			||||||
| 
						 | 
					@ -116,6 +135,7 @@ namespace Light {
 | 
				
			||||||
				callback(KeyReleasedEvent(key));
 | 
									callback(KeyReleasedEvent(key));
 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Window Events //
 | 
				
			||||||
		glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) 
 | 
							glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) 
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
 | 
								std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,6 @@ namespace Light {
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		GLFWwindow* m_Handle = nullptr;
 | 
							GLFWwindow* m_Handle = nullptr;
 | 
				
			||||||
		WindowProperties m_Properties = {};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		std::function<void(Event&)> m_EventCallback;
 | 
							std::function<void(Event&)> m_EventCallback;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,17 +21,18 @@ namespace Light {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		~wWindow();
 | 
							~wWindow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual void SetProperties(const WindowProperties& properties) override;
 | 
							void PollEvents() override;
 | 
				
			||||||
 | 
							void OnEvent(const Event& event) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual void SetVisible(bool visible) override;
 | 
							// Setters //
 | 
				
			||||||
 | 
							void SetProperties(const WindowProperties& properties) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual void PollEvents() override;
 | 
							void SetTitle(const std::string& title) override;
 | 
				
			||||||
		virtual void OnEvent(const Event& event) override;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual unsigned int GetWidth() override;
 | 
							void SetSize(const glm::uvec2& size) override;
 | 
				
			||||||
		virtual unsigned int GetHeight() override;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		virtual inline void* GetNativeHandle() override { return m_Handle; }
 | 
							void SetVSync(bool vsync, bool toggle = false) override;
 | 
				
			||||||
 | 
							void SetVisibility(bool visible, bool toggle = false) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private:
 | 
						private:
 | 
				
			||||||
		void BindGlfwEvents();
 | 
							void BindGlfwEvents();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,8 +13,7 @@ public:
 | 
				
			||||||
		// Set window properties
 | 
							// Set window properties
 | 
				
			||||||
		Light::WindowProperties properties;
 | 
							Light::WindowProperties properties;
 | 
				
			||||||
		properties.title = "Sandbox";
 | 
							properties.title = "Sandbox";
 | 
				
			||||||
		properties.width = 800u;
 | 
							properties.size = glm::uvec2(800u, 600u);
 | 
				
			||||||
		properties.height = 600u;
 | 
					 | 
				
			||||||
		properties.vsync = true;
 | 
							properties.vsync = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		m_Window->SetProperties(properties);
 | 
							m_Window->SetProperties(properties);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue