refactor: modularization of the engine (wip)
This commit is contained in:
		
							parent
							
								
									fc2fe26160
								
							
						
					
					
						commit
						3c87b1cd06
					
				
					 141 changed files with 907 additions and 820 deletions
				
			
		|  | @ -1,7 +1,17 @@ | |||
| add_subdirectory(./base) | ||||
| add_subdirectory(./logger) | ||||
| add_subdirectory(./debug) | ||||
| 
 | ||||
| add_subdirectory(./asset_baker) | ||||
| add_subdirectory(./asset_parser) | ||||
| add_subdirectory(./asset_manager) | ||||
| 
 | ||||
| add_subdirectory(./camera) | ||||
| add_subdirectory(./input) | ||||
| add_subdirectory(./ui) | ||||
| 
 | ||||
| add_subdirectory(./renderer) | ||||
| add_subdirectory(./engine) | ||||
| 
 | ||||
| add_subdirectory(./mirror) | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										9
									
								
								modules/asset_manager/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								modules/asset_manager/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | |||
| add_library_module(asset_manager  | ||||
|     asset_manager.cpp | ||||
| ) | ||||
| 
 | ||||
| target_link_libraries( | ||||
|   asset_manager | ||||
|   PUBLIC asset_parser | ||||
|   PRIVATE renderer | ||||
| ) | ||||
|  | @ -1,20 +1,18 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <filesystem> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| class Shader; | ||||
| class Texture; | ||||
| class SharedContext; | ||||
| 
 | ||||
| class ResourceManager | ||||
| class AssetManager | ||||
| { | ||||
| public: | ||||
| 	static auto instance() -> ResourceManager & | ||||
| 	static auto instance() -> AssetManager & | ||||
| 	{ | ||||
| 		static auto instance = ResourceManager {}; | ||||
| 		static auto instance = AssetManager {}; | ||||
| 		return instance; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -43,7 +41,7 @@ public: | |||
| 	} | ||||
| 
 | ||||
| private: | ||||
| 	ResourceManager() = default; | ||||
| 	AssetManager() = default; | ||||
| 
 | ||||
| 	void load_shader_impl( | ||||
| 	    const std::string &name, | ||||
|  | @ -1,14 +1,14 @@ | |||
| #include <asset_parser/assets/text.hpp> | ||||
| #include <asset_parser/assets/texture.hpp> | ||||
| #include <engine/graphics/graphics_context.hpp> | ||||
| #include <engine/graphics/shader.hpp> | ||||
| #include <engine/graphics/texture.hpp> | ||||
| #include <engine/utils/resource_manager.hpp> | ||||
| #include <renderer/graphics_context.hpp> | ||||
| #include <renderer/shader.hpp> | ||||
| #include <renderer/texture.hpp> | ||||
| #include <asset_manager/asset_manager.hpp> | ||||
| #include <logger/logger.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| void ResourceManager::load_shader_impl( | ||||
| void AssetManager::load_shader_impl( | ||||
|     const std::string &name, | ||||
|     const std::filesystem::path &vertex_path, | ||||
|     const std::filesystem::path &pixel_path | ||||
|  | @ -49,7 +49,7 @@ void ResourceManager::load_shader_impl( | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| void ResourceManager::load_texture_impl(const std::string &name, const std::filesystem::path &path) | ||||
| void AssetManager::load_texture_impl(const std::string &name, const std::filesystem::path &path) | ||||
| { | ||||
| 	try | ||||
| 	{ | ||||
|  | @ -6,7 +6,7 @@ add_library_module(asset_parser | |||
| 
 | ||||
| target_link_libraries( | ||||
|     asset_parser | ||||
|     PRIVATE LZ4::lz4_static  | ||||
|     PRIVATE nlohmann_json::nlohmann_json  | ||||
|     PRIVATE logger | ||||
|     PUBLIC LZ4::lz4_static  | ||||
|     PUBLIC nlohmann_json::nlohmann_json  | ||||
|     PUBLIC logger | ||||
| ) | ||||
|  |  | |||
							
								
								
									
										3
									
								
								modules/base/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								modules/base/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| add_library_module(base) | ||||
| 
 | ||||
| target_precompile_headers(base INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.hpp) | ||||
|  | @ -42,7 +42,6 @@ constexpr std::unique_ptr<t> make_scope(t *rawPointer) | |||
| #define lt_lin(x) // linux
 | ||||
| #define lt_mac(x) // mac
 | ||||
| 
 | ||||
| 
 | ||||
| enum class Platform : uint8_t | ||||
| { | ||||
| 	windows, | ||||
|  | @ -53,7 +52,6 @@ enum class Platform : uint8_t | |||
| 	mac, | ||||
| }; | ||||
| 
 | ||||
| 
 | ||||
| namespace constants { | ||||
| 
 | ||||
| #if defined(LIGHT_PLATFORM_WINDOWS) | ||||
|  | @ -91,16 +89,6 @@ auto linux_only(auto value) | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| #define lt_assert(x, ...)                                       \ | ||||
| 	{                                                           \ | ||||
| 		if (!(x))                                               \ | ||||
| 		{                                                       \ | ||||
| 			log_crt(__VA_ARGS__);                               \ | ||||
| 			lt_debug_trap();                                    \ | ||||
| 			throw ::Light::FailedAssertion(__FILE__, __LINE__); \ | ||||
| 		}                                                       \ | ||||
| 	} | ||||
| 
 | ||||
| /* bit-wise */ | ||||
| constexpr auto bit(auto x) | ||||
| { | ||||
|  | @ -111,28 +99,3 @@ constexpr auto bit(auto x) | |||
| #define lt_pair_token_value_to_name(token) { token, #token } | ||||
| #define lt_pair_token_name_to_value(token) { #token, token } | ||||
| #define lt_token_name(token)               #token | ||||
| //====================================================================== OPERATIONS
 | ||||
| //======================================================================//
 | ||||
| 
 | ||||
| //========== ESSENTIAL_HEADERS ==========//
 | ||||
| /* config */ | ||||
| #ifndef LIGHT_CONFIG_H | ||||
| 	#include <engine/base/config.hpp> | ||||
| #endif | ||||
| 
 | ||||
| /* debug */ | ||||
| #ifndef LIGHT_LOGGER_H | ||||
| 	#include <logger/logger.hpp> | ||||
| #endif | ||||
| #include <engine/debug/exceptions.hpp> | ||||
| 
 | ||||
| /* portables */ | ||||
| #ifndef LIGHT_DEBUG_TRAP_H | ||||
| 	#include <engine/base/portables/debug_trap.hpp> | ||||
| #endif | ||||
| 
 | ||||
| /* utility */ | ||||
| #ifndef LIGHT_STRINGIFIER_H | ||||
| 	#include <engine/utils/stringifier.hpp> | ||||
| #endif | ||||
| //========== ESSENTIAL_HEADERS ==========//
 | ||||
|  | @ -2,8 +2,6 @@ | |||
| #ifndef LIGHT_DEBUG_TRAP_H | ||||
| 	#define LIGHT_DEBUG_TRAP_H | ||||
| 
 | ||||
| 	#include <engine/base/base.hpp> | ||||
| 
 | ||||
| // https://github.com/nemequ/portable-snippets/tree/master/debug-trap
 | ||||
| 
 | ||||
| 	#ifdef LIGHT_DIST | ||||
|  | @ -127,29 +125,29 @@ static inline void lt_debug_trap(void) | |||
| 		#elif defined(LIGHT_DIST) | ||||
| 			#ifdef _MSC_VER | ||||
| 				#define lt_debug_trap()                                    \ | ||||
| 					log_crt(                                         \ | ||||
| 					log_crt(                                               \ | ||||
| 					    "DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \ | ||||
| 					    __FUNCSIG__,                                       \ | ||||
| 					    __FILE__,                                          \ | ||||
| 					    __LINE__) // or __FUNCSIG__
 | ||||
| 					    __LINE__                                           \ | ||||
| 					) // or __FUNCSIG__
 | ||||
| 
 | ||||
| 			#else | ||||
| 				#define lt_debug_trap() \ | ||||
| 					log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) | ||||
| 				#define lt_debug_trap() log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) | ||||
| 
 | ||||
| 			#endif | ||||
| 		#else /* !defined(LIGHT_DIST) */ | ||||
| 			#ifdef _MSC_VER | ||||
| 				#define lt_debug_trap()                                    \ | ||||
| 					log_crt(                                         \ | ||||
| 					log_crt(                                               \ | ||||
| 					    "DEBUG_TRAP REQUESTED AT: {}, FILE: {}, LINE: {}", \ | ||||
| 					    __FUNCSIG__,                                       \ | ||||
| 					    __FILE__,                                          \ | ||||
| 					    __LINE__) // or __FUNCSIG__
 | ||||
| 					    __LINE__                                           \ | ||||
| 					) // or __FUNCSIG__
 | ||||
| 
 | ||||
| 			#else | ||||
| 				#define lt_debug_trap() \ | ||||
| 					log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) | ||||
| 				#define lt_debug_trap() log_crt("DEBUG_TRAP REQUESTED AT: {}", __PRETTY_FUNCTION__) | ||||
| 
 | ||||
| 			#endif | ||||
| 		#endif | ||||
|  | @ -1,7 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| /* engine */ | ||||
| #include <engine/base/base.hpp> | ||||
| #include <base/base.hpp> | ||||
| 
 | ||||
| /* windows */ | ||||
| #ifdef _WIN32 | ||||
|  | @ -10,39 +9,27 @@ | |||
| 	#undef NOMINMAX | ||||
| #endif | ||||
| 
 | ||||
| /* containers */ | ||||
| /** Stdlib */ | ||||
| #include <algorithm> | ||||
| #include <array> | ||||
| #include <atomic> | ||||
| #include <bitset> | ||||
| #include <filesystem> | ||||
| #include <fstream> | ||||
| #include <functional> | ||||
| #include <iostream> | ||||
| #include <list> | ||||
| #include <map> | ||||
| #include <set> | ||||
| #include <unordered_map> | ||||
| #include <unordered_set> | ||||
| #include <vector> | ||||
| 
 | ||||
| /* misc */ | ||||
| #include <algorithm> | ||||
| #include <functional> | ||||
| #include <math.h> | ||||
| #include <memory> | ||||
| #include <tuple> | ||||
| #include <utility> | ||||
| 
 | ||||
| /* input/output */ | ||||
| #include <fstream> | ||||
| #include <iostream> | ||||
| #include <set> | ||||
| #include <sstream> | ||||
| 
 | ||||
| /* multi threading */ | ||||
| #include <atomic> | ||||
| #include <thread> | ||||
| 
 | ||||
| /* string */ | ||||
| #include <string> | ||||
| #include <string_view> | ||||
| 
 | ||||
| /* filesystem */ | ||||
| #include <filesystem> | ||||
| 
 | ||||
| /* c libraries */ | ||||
| #include <math.h> | ||||
| #include <thread> | ||||
| #include <time.h> | ||||
| #include <tuple> | ||||
| #include <unordered_map> | ||||
| #include <unordered_set> | ||||
| #include <utility> | ||||
| #include <vector> | ||||
							
								
								
									
										3
									
								
								modules/camera/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								modules/camera/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| add_library_module(camera camera.cpp ortho.cpp scene.cpp) | ||||
| 
 | ||||
| target_link_libraries(camera PUBLIC glm::glm) | ||||
|  | @ -1,6 +1,5 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <glm/glm.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -26,7 +25,7 @@ public: | |||
| 	} | ||||
| 
 | ||||
| protected: | ||||
| 	glm::mat4 m_projection{}; | ||||
| 	glm::mat4 m_projection {}; | ||||
| 
 | ||||
| private: | ||||
| 	glm::vec4 m_background_color = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); | ||||
|  | @ -1,6 +1,5 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <glm/glm.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -47,9 +46,9 @@ private: | |||
| 
 | ||||
| 	const glm::vec3 m_up; | ||||
| 
 | ||||
| 	glm::mat4 m_projection{}; | ||||
| 	glm::mat4 m_projection {}; | ||||
| 
 | ||||
| 	glm::mat4 m_view{}; | ||||
| 	glm::mat4 m_view {}; | ||||
| 
 | ||||
| 	glm::vec4 m_clear_color; | ||||
| }; | ||||
|  | @ -1,7 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/camera/camera.hpp> | ||||
| #include <camera/camera.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -93,7 +92,7 @@ private: | |||
| 
 | ||||
| 	float m_aspect_ratio; | ||||
| 
 | ||||
| 	ProjectionType m_projection_type{ProjectionType::Orthographic}; | ||||
| 	ProjectionType m_projection_type { ProjectionType::Orthographic }; | ||||
| 
 | ||||
| 	void calculate_projection(); | ||||
| }; | ||||
							
								
								
									
										6
									
								
								modules/camera/src/camera.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								modules/camera/src/camera.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| #include <camera/camera.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | @ -1,4 +1,4 @@ | |||
| #include <engine/camera/ortho.hpp> | ||||
| #include <camera/ortho.hpp> | ||||
| #include <glm/gtc/matrix_transform.hpp> | ||||
| #include <glm/matrix.hpp> | ||||
| 
 | ||||
|  | @ -1,4 +1,4 @@ | |||
| #include <engine/camera/scene.hpp> | ||||
| #include <camera/scene.hpp> | ||||
| #include <glm/gtc/matrix_transform.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
							
								
								
									
										3
									
								
								modules/debug/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								modules/debug/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| add_library_module(lt_debug) | ||||
| target_link_libraries(lt_debug INTERFACE logger) | ||||
| target_precompile_headers(lt_debug INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/src/pch.hpp) | ||||
							
								
								
									
										27
									
								
								modules/debug/include/ltdebug/assertions.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								modules/debug/include/ltdebug/assertions.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <logger/logger.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| struct FailedAssertion: std::exception | ||||
| { | ||||
| 	FailedAssertion(const char *file, int line); | ||||
| }; | ||||
| 
 | ||||
| // OpenGL
 | ||||
| struct glException: std::exception | ||||
| { | ||||
| 	glException(unsigned int source, unsigned int type, unsigned int id, const char *msg); | ||||
| }; | ||||
| 
 | ||||
| #define lt_assert(x, ...)                                       \ | ||||
| 	{                                                           \ | ||||
| 		if (!(x))                                               \ | ||||
| 		{                                                       \ | ||||
| 			log_crt(__VA_ARGS__);                               \ | ||||
| 			throw ::Light::FailedAssertion(__FILE__, __LINE__); \ | ||||
| 		}                                                       \ | ||||
| 	} | ||||
| 
 | ||||
| } // namespace Light
 | ||||
							
								
								
									
										3
									
								
								modules/debug/src/pch.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								modules/debug/src/pch.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <ltdebug/assertions.hpp> | ||||
|  | @ -1,95 +1,30 @@ | |||
| cmake_minimum_required(VERSION 3.16) | ||||
| 
 | ||||
| if(NOT WIN32) | ||||
|     add_library_module(engine  | ||||
|         camera/camera.cpp | ||||
|         camera/ortho.cpp | ||||
|         camera/scene.cpp | ||||
|         core/application.cpp | ||||
|         core/uuid.cpp | ||||
|         debug/exceptions.cpp | ||||
|         debug/instrumentor.cpp | ||||
|         graphics/blender.cpp | ||||
|         graphics/buffers.cpp | ||||
|         graphics/framebuffer.cpp | ||||
|         graphics/graphics_context.cpp | ||||
|         graphics/render_command.cpp | ||||
|         graphics/renderer.cpp | ||||
|         graphics/renderer_programs/quad.cpp | ||||
|         graphics/renderer_programs/texture.cpp | ||||
|         graphics/renderer_programs/tinted_texture.cpp | ||||
|         graphics/shader.cpp | ||||
|         graphics/texture.cpp | ||||
|         graphics/vertex_layout.cpp | ||||
|         input/input.cpp | ||||
|         layer/layer.cpp | ||||
|         layer/layer_stack.cpp | ||||
|         platform/graphics/opengl/blender.cpp | ||||
|         platform/graphics/opengl/buffers.cpp | ||||
|         platform/graphics/opengl/framebuffers.cpp | ||||
|         platform/graphics/opengl/graphics_context.cpp | ||||
|         platform/graphics/opengl/render_command.cpp | ||||
|         platform/graphics/opengl/shader.cpp | ||||
|         platform/graphics/opengl/texture.cpp | ||||
|         platform/graphics/opengl/user_interface.cpp | ||||
|         platform/graphics/opengl/vertex_layout.cpp | ||||
|         platform/os/linux/l_window.cpp | ||||
|         os/linux/l_window.cpp | ||||
|         scene/entity.cpp | ||||
|         scene/scene.cpp | ||||
|         time/timer.cpp | ||||
|         user_interface/user_interface.cpp | ||||
|         utils/resource_manager.cpp | ||||
|         utils/serializer.cpp | ||||
|         utils/stringifier.cpp | ||||
|     ) | ||||
| else() | ||||
|     add_library_module(engine  | ||||
|         camera/camera.cpp | ||||
|         camera/ortho.cpp | ||||
|         camera/scene.cpp | ||||
|         core/application.cpp | ||||
|         core/uuid.cpp | ||||
|         debug/exceptions.cpp | ||||
|         debug/instrumentor.cpp | ||||
|         graphics/blender.cpp | ||||
|         graphics/buffers.cpp | ||||
|         graphics/framebuffer.cpp | ||||
|         graphics/graphics_context.cpp | ||||
|         graphics/render_command.cpp | ||||
|         graphics/renderer.cpp | ||||
|         graphics/renderer_programs/quad.cpp | ||||
|         graphics/renderer_programs/texture.cpp | ||||
|         graphics/renderer_programs/tinted_texture.cpp | ||||
|         graphics/shader.cpp | ||||
|         graphics/texture.cpp | ||||
|         graphics/vertex_layout.cpp | ||||
|         input/input.cpp | ||||
|         layer/layer.cpp | ||||
|         layer/layer_stack.cpp | ||||
|         platform/graphics/directx/blender.cpp | ||||
|         platform/graphics/directx/buffers.cpp | ||||
|         platform/graphics/directx/framebuffers.cpp | ||||
|         platform/graphics/directx/graphics_context.cpp | ||||
|         platform/graphics/directx/render_command.cpp | ||||
|         platform/graphics/directx/shader.cpp | ||||
|         platform/graphics/directx/texture.cpp | ||||
|         platform/graphics/directx/user_interface.cpp | ||||
|         platform/graphics/directx/vertex_layout.cpp | ||||
|         platform/graphics/opengl/blender.cpp | ||||
|         platform/graphics/opengl/buffers.cpp | ||||
|         platform/graphics/opengl/framebuffers.cpp | ||||
|         platform/graphics/opengl/graphics_context.cpp | ||||
|         platform/graphics/opengl/render_command.cpp | ||||
|         platform/graphics/opengl/shader.cpp | ||||
|         platform/graphics/opengl/texture.cpp | ||||
|         platform/graphics/opengl/user_interface.cpp | ||||
|         platform/graphics/opengl/vertex_layout.cpp | ||||
|         platform/os/windows/w_window.cpp | ||||
|         os/windows/w_window.cpp | ||||
|         scene/entity.cpp | ||||
|         scene/scene.cpp | ||||
|         time/timer.cpp | ||||
|         user_interface/user_interface.cpp | ||||
|         utils/resource_manager.cpp | ||||
|         utils/serializer.cpp | ||||
|         utils/stringifier.cpp | ||||
|     ) | ||||
|  | @ -97,14 +32,15 @@ endif() | |||
| 
 | ||||
| target_link_libraries( | ||||
|   engine | ||||
|   PUBLIC renderer | ||||
|   PUBLIC glad | ||||
|   PUBLIC logger | ||||
|   PUBLIC opengl::opengl | ||||
|   PUBLIC glfw | ||||
|   PUBLIC imgui | ||||
|   PUBLIC ui | ||||
|   PUBLIC asset_parser | ||||
|   PUBLIC asset_manager | ||||
|   PUBLIC yaml-cpp::yaml-cpp | ||||
|   PUBLIC EnTT::EnTT | ||||
|   PUBLIC lt_debug  | ||||
| ) | ||||
| 
 | ||||
| target_precompile_headers(engine PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/ltpch.hpp) | ||||
|  |  | |||
|  | @ -1,13 +1,16 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/input/input.hpp> | ||||
| 
 | ||||
| #include <engine/layer/layer_stack.hpp> | ||||
| #include <input/input.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| class Renderer; | ||||
| class Window; | ||||
| class Event; | ||||
| class UserInterface; | ||||
| class GraphicsContext; | ||||
| 
 | ||||
| extern Scope<class Application> create_application(); | ||||
| 
 | ||||
|  | @ -43,6 +46,12 @@ private: | |||
| 
 | ||||
| 	Scope<Window> m_window; | ||||
| 
 | ||||
| 	Scope<UserInterface> m_user_interface; | ||||
| 
 | ||||
| 	Scope<GraphicsContext> m_graphics_context; | ||||
| 
 | ||||
| 	Scope<Renderer> m_renderer; | ||||
| 
 | ||||
| 	static Application *s_instance; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,8 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/graphics_context.hpp> | ||||
| 
 | ||||
| #include <glm/glm.hpp> | ||||
| #include <renderer/graphics_context.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -20,9 +20,9 @@ struct WindowProperties | |||
| class Window | ||||
| { | ||||
| public: | ||||
| 	static Scope<Window> create(const std::function<void(Event &)>& callback); | ||||
| 	static Scope<Window> create(const std::function<void(Event &)> &callback); | ||||
| 
 | ||||
| 	Window(): m_graphics_context(nullptr), m_properties {}  | ||||
| 	Window(): m_properties {} | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
|  | @ -55,11 +55,6 @@ public: | |||
| 
 | ||||
| 	virtual void set_visibility(bool visible, bool toggle = false) = 0; | ||||
| 
 | ||||
| 	[[nodiscard]] auto get_graphics_context() const -> GraphicsContext * | ||||
| 	{ | ||||
| 		return m_graphics_context.get(); | ||||
| 	} | ||||
| 
 | ||||
| 	[[nodiscard]] auto get_properties() const -> const WindowProperties & | ||||
| 	{ | ||||
| 		return m_properties; | ||||
|  | @ -90,12 +85,12 @@ public: | |||
| 		return m_properties.visible; | ||||
| 	} | ||||
| 
 | ||||
| protected: | ||||
| 	Scope<GraphicsContext> m_graphics_context; | ||||
| 	virtual auto get_handle() -> void * = 0; | ||||
| 
 | ||||
| protected: | ||||
| 	WindowProperties m_properties; | ||||
| 
 | ||||
| 	bool b_Closed{false}; | ||||
| 	bool b_Closed { false }; | ||||
| }; | ||||
| 
 | ||||
| } // namespace Light
 | ||||
|  |  | |||
|  | @ -11,22 +11,11 @@ | |||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| struct FailedAssertion: std::exception | ||||
| { | ||||
| 	FailedAssertion(const char* file, int line); | ||||
| }; | ||||
| 
 | ||||
| // OpenGL
 | ||||
| struct glException: std::exception | ||||
| { | ||||
| 	glException(unsigned int source, unsigned int type, unsigned int id, const char* msg); | ||||
| }; | ||||
| 
 | ||||
| #ifdef LIGHT_PLATFORM_WINDOWS | ||||
| // DirectX
 | ||||
| struct dxException: std::exception | ||||
| { | ||||
| 	dxException(long hr, const char* file, int line); | ||||
| 	dxException(long hr, const char *file, int line); | ||||
| }; | ||||
| #endif | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <chrono> | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <fstream> | ||||
| 
 | ||||
| namespace Light { | ||||
|  |  | |||
|  | @ -4,45 +4,24 @@ | |||
| #include <engine/core/application.hpp> | ||||
| #include <engine/core/window.hpp> | ||||
| 
 | ||||
| // camera
 | ||||
| #include <engine/camera/camera.hpp> | ||||
| 
 | ||||
| // debug
 | ||||
| #include <logger/logger.hpp> | ||||
| 
 | ||||
| // events
 | ||||
| #include <engine/events/char.hpp> | ||||
| #include <engine/events/event.hpp> | ||||
| #include <engine/events/keyboard.hpp> | ||||
| #include <engine/events/mouse.hpp> | ||||
| #include <engine/events/window.hpp> | ||||
| 
 | ||||
| // graphics
 | ||||
| #include <engine/graphics/framebuffer.hpp> | ||||
| #include <engine/graphics/graphics_context.hpp> | ||||
| #include <engine/graphics/renderer.hpp> | ||||
| #include <engine/graphics/texture.hpp> | ||||
| 
 | ||||
| // input
 | ||||
| #include <engine/input/input.hpp> | ||||
| #include <engine/input/key_codes.hpp> | ||||
| #include <engine/input/mouse_codes.hpp> | ||||
| #include <renderer/framebuffer.hpp> | ||||
| #include <renderer/graphics_context.hpp> | ||||
| #include <renderer/renderer.hpp> | ||||
| #include <renderer/texture.hpp> | ||||
| 
 | ||||
| // layer
 | ||||
| #include <engine/layer/layer.hpp> | ||||
| #include <engine/layer/layer_stack.hpp> | ||||
| 
 | ||||
| // user interface
 | ||||
| #include <engine/user_interface/user_interface.hpp> | ||||
| 
 | ||||
| // utility
 | ||||
| #include <engine/utils/resource_manager.hpp> | ||||
| 
 | ||||
| // time
 | ||||
| #include <engine/time/timer.hpp> | ||||
| 
 | ||||
| // base
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| 
 | ||||
| // third party
 | ||||
| #include <imgui.h> | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,5 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/core/window.hpp> | ||||
| 
 | ||||
| struct GLFWwindow; | ||||
|  | @ -32,8 +31,13 @@ public: | |||
| 
 | ||||
| 	void set_visibility(bool visible, bool toggle = false) override; | ||||
| 
 | ||||
| 	[[nodiscard]] auto get_handle() -> void * override | ||||
| 	{ | ||||
| 		return m_handle; | ||||
| 	} | ||||
| 
 | ||||
| private: | ||||
| 	GLFWwindow *m_handle{nullptr}; | ||||
| 	GLFWwindow *m_handle { nullptr }; | ||||
| 
 | ||||
| 	std::function<void(Event &)> m_event_callback; | ||||
| 
 | ||||
|  | @ -4,7 +4,7 @@ | |||
| #include <engine/events/keyboard.hpp> | ||||
| #include <engine/events/mouse.hpp> | ||||
| #include <engine/events/window.hpp> | ||||
| #include <engine/graphics/graphics_context.hpp> | ||||
| #include <renderer/graphics_context.hpp> | ||||
| #include <engine/platform/os/windows/w_window.hpp> | ||||
| 
 | ||||
| extern "C" | ||||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <engine/core/window.hpp> | ||||
| 
 | ||||
| struct GLFWwindow; | ||||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <engine/scene/components/camera.hpp> | ||||
| #include <engine/scene/components/native_script.hpp> | ||||
| #include <engine/scene/components/sprite_renderer.hpp> | ||||
|  |  | |||
|  | @ -1,7 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/camera/scene.hpp> | ||||
| #include <camera/scene.hpp> | ||||
| #include <glm/glm.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -25,7 +24,7 @@ struct CameraComponent | |||
| 
 | ||||
| 	SceneCamera camera; | ||||
| 
 | ||||
| 	bool isPrimary{}; | ||||
| 	bool isPrimary {}; | ||||
| }; | ||||
| 
 | ||||
| } // namespace Light
 | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <engine/scene/components/scriptable_entity.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <engine/scene/entity.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <glm/glm.hpp> | ||||
| #include <utility> | ||||
| #include <utility> | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <utility> | ||||
| 
 | ||||
| namespace Light { | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ | |||
| 
 | ||||
| #define GLM_ENABLE_EXPERIMENTAL | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <glm/glm.hpp> | ||||
| #include <glm/gtc/matrix_transform.hpp> | ||||
| #include <glm/gtx/transform.hpp> | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <engine/core/uuid.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <engine/scene/components/uuid.hpp> | ||||
| #include <engine/scene/scene.hpp> | ||||
| #include <entt/entt.hpp> | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <engine/core/uuid.hpp> | ||||
| #include <engine/scene/components/transform.hpp> | ||||
| #include <entt/entt.hpp> | ||||
|  |  | |||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <chrono> | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <engine/scene/entity.hpp> | ||||
| #include <engine/scene/scene.hpp> | ||||
| #include <yaml-cpp/yaml.h> | ||||
|  |  | |||
|  | @ -2,7 +2,7 @@ | |||
| #ifndef LIGHT_STRINGIFIER_H | ||||
| 	#define LIGHT_STRINGIFIER_H | ||||
| 
 | ||||
| 	#include <engine/base/base.hpp> | ||||
| 	 | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,6 +0,0 @@ | |||
| #include <engine/camera/camera.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
|  | @ -1,16 +1,19 @@ | |||
| #include <asset_manager/asset_manager.hpp> | ||||
| #include <engine/core/application.hpp> | ||||
| #include <engine/core/window.hpp> | ||||
| #include <engine/debug/instrumentor.hpp> | ||||
| #include <engine/events/event.hpp> | ||||
| #include <engine/events/keyboard.hpp> | ||||
| #include <engine/events/window.hpp> | ||||
| #include <engine/graphics/graphics_context.hpp> | ||||
| #include <engine/graphics/render_command.hpp> | ||||
| #include <engine/graphics/renderer.hpp> | ||||
| #include <engine/layer/layer.hpp> | ||||
| #include <engine/time/timer.hpp> | ||||
| #include <engine/user_interface/user_interface.hpp> | ||||
| #include <input/events/event.hpp> | ||||
| #include <input/events/keyboard.hpp> | ||||
| #include <input/events/window.hpp> | ||||
| #include <ltdebug/assertions.hpp> | ||||
| #include <ranges> | ||||
| #include <renderer/blender.hpp> | ||||
| #include <renderer/graphics_context.hpp> | ||||
| #include <renderer/render_command.hpp> | ||||
| #include <renderer/renderer.hpp> | ||||
| #include <ui/ui.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -26,6 +29,48 @@ Application::Application(): m_window(nullptr) | |||
| 	Light::Instrumentor::begin_session("data/logs/profile_startup.json"); | ||||
| 
 | ||||
| 	m_window = Window::create([this](auto &&PH1) { on_event(std::forward<decltype(PH1)>(PH1)); }); | ||||
| 
 | ||||
| 	// create graphics context
 | ||||
| 	m_graphics_context = GraphicsContext::create( | ||||
| 	    GraphicsAPI::OpenGL, | ||||
| 	    (GLFWwindow *)m_window->get_handle() | ||||
| 	); | ||||
| 
 | ||||
| 	AssetManager::load_shader( | ||||
| 	    "LT_ENGINE_RESOURCES_TEXTURE_SHADER", | ||||
| 	    "data/assets/shaders/texture/vs.asset", | ||||
| 	    "data/assets/shaders/texture/ps.asset" | ||||
| 	); | ||||
| 
 | ||||
| 	AssetManager::load_shader( | ||||
| 	    "LT_ENGINE_RESOURCES_TINTED_TEXTURE_SHADER", | ||||
| 	    "data/assets/shaders/tinted_texture/vs.asset", | ||||
| 	    "data/assets/shaders/tinted_texture/ps.asset" | ||||
| 	); | ||||
| 
 | ||||
| 	AssetManager::load_shader( | ||||
| 	    "LT_ENGINE_RESOURCES_QUAD_SHADER", | ||||
| 	    "data/assets/shaders/quads/vs.asset", | ||||
| 	    "data/assets/shaders/quads/ps.asset" | ||||
| 	); | ||||
| 
 | ||||
| 	m_renderer = Renderer::create( | ||||
| 	    (GLFWwindow *)m_window->get_handle(), | ||||
| 	    m_graphics_context->get_shared_context(), | ||||
| 	    Renderer::CreateInfo { | ||||
| 	        .quad_renderer_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_QUAD_SHADER"), | ||||
| 	        .texture_renderer_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_TEXTURE_SHADER" | ||||
| 	        ), | ||||
| 	        .tinted_texture_renderer_shader = AssetManager::get_shader("LT_ENGINE_RESOURCES_TINTED_" | ||||
| 	                                                                   "TEXTURE_SHADER"), | ||||
| 	    } | ||||
| 	); | ||||
| 	lt_assert(m_graphics_context, "lWindow::lWindow: failed to create 'GraphicsContext'"); | ||||
| 
 | ||||
| 	m_user_interface = UserInterface::create( | ||||
| 	    (GLFWwindow *)m_window->get_handle(), | ||||
| 	    m_graphics_context->get_shared_context() | ||||
| 	); | ||||
| } | ||||
| 
 | ||||
| Application::~Application() | ||||
|  | @ -40,8 +85,8 @@ void Application::game_loop() | |||
| 	lt_assert(!LayerStack::instance().is_empty(), "layer_stack is empty"); | ||||
| 
 | ||||
| 	// log debug data
 | ||||
| 	m_window->get_graphics_context()->log_debug_data(); | ||||
| 	m_window->get_graphics_context()->get_user_interface()->log_debug_data(); | ||||
| 	m_graphics_context->log_debug_data(); | ||||
| 	m_user_interface->log_debug_data(); | ||||
| 
 | ||||
| 	// reveal window
 | ||||
| 	m_window->set_visibility(true); | ||||
|  | @ -69,27 +114,27 @@ void Application::game_loop() | |||
| 		{ | ||||
| 			// render layers
 | ||||
| 			lt_profile_scope("game_loop::Render"); | ||||
| 			m_window->get_graphics_context()->get_renderer()->begin_frame(); | ||||
| 			m_renderer->begin_frame(); | ||||
| 
 | ||||
| 			for (auto &it : LayerStack::instance()) | ||||
| 			{ | ||||
| 				it->on_render(); | ||||
| 			} | ||||
| 
 | ||||
| 			m_window->get_graphics_context()->get_renderer()->end_frame(); | ||||
| 			m_renderer->end_frame(); | ||||
| 		} | ||||
| 
 | ||||
| 		{ | ||||
| 			// render user interface
 | ||||
| 			lt_profile_scope("game_loop::UserInterface"); | ||||
| 			m_window->get_graphics_context()->get_user_interface()->begin(); | ||||
| 			m_user_interface->begin(); | ||||
| 
 | ||||
| 			for (auto &it : LayerStack::instance()) | ||||
| 			{ | ||||
| 				it->on_user_interface_update(); | ||||
| 			} | ||||
| 
 | ||||
| 			m_window->get_graphics_context()->get_user_interface()->end(); | ||||
| 			m_user_interface->end(); | ||||
| 		} | ||||
| 
 | ||||
| 		{ | ||||
|  | @ -117,9 +162,7 @@ void Application::on_event(const Event &event) | |||
| 
 | ||||
| 		if (event.get_event_type() == EventType::WindowResized) | ||||
| 		{ | ||||
| 			m_window->get_graphics_context()->get_renderer()->on_window_resize( | ||||
| 			    dynamic_cast<const WindowResizedEvent &>(event) | ||||
| 			); | ||||
| 			m_renderer->on_window_resize(dynamic_cast<const WindowResizedEvent &>(event)); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,81 +0,0 @@ | |||
| #include <engine/graphics/graphics_context.hpp> | ||||
| #include <engine/platform/graphics/opengl/graphics_context.hpp> | ||||
| 
 | ||||
| #ifdef LIGHT_PLATFORM_WINDOWS | ||||
| 	#include <engine/platform/graphics/directx/graphics_context.hpp> | ||||
| 	#include <engine/platform/graphics/directx/shared_context.hpp> | ||||
| #endif | ||||
| 
 | ||||
| #include <engine/graphics/blender.hpp>              // required for forward declaratio>
 | ||||
| #include <engine/graphics/buffers.hpp>              // required for forward declaratio>
 | ||||
| #include <engine/graphics/render_command.hpp>       // required for forward declaratio>
 | ||||
| #include <engine/graphics/renderer.hpp>             // required for forward declaratio>
 | ||||
| #include <engine/user_interface/user_interface.hpp> // required for forward declaratio>
 | ||||
| #include <engine/utils/resource_manager.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| GraphicsContext *GraphicsContext::s_context = nullptr; | ||||
| 
 | ||||
| GraphicsContext::~GraphicsContext() | ||||
| = default; | ||||
| 
 | ||||
| auto GraphicsContext::create(GraphicsAPI api, GLFWwindow *windowHandle) -> Scope<GraphicsContext> | ||||
| { | ||||
| 	// terminate 'GraphicsContext' dependent classes
 | ||||
| 	if (s_context) | ||||
| 	{ | ||||
| 		s_context->m_renderer.reset(); | ||||
| 		s_context->m_user_interface.reset(); | ||||
| 
 | ||||
| 		delete s_context; | ||||
| 	} | ||||
| 
 | ||||
| 	// determine the default api
 | ||||
| 	if (api == GraphicsAPI::Default) | ||||
| 	{ | ||||
| #if defined(LIGHT_PLATFORM_WINDOWS) | ||||
| 		api = GraphicsAPI::DirectX; | ||||
| #elif defined(LIGHT_PLATFORM_LINUX) | ||||
| 		api = GraphicsAPI::OpenGL; | ||||
| #elif defined(LIGHT_PLATFORM_MAC) | ||||
| 		api = GraphicsAPI::OpenGL; | ||||
| #endif | ||||
| 	} | ||||
| 
 | ||||
| 	// create gfx context
 | ||||
| 	auto scope_gfx = Scope<GraphicsContext> {}; | ||||
| 	switch (api) | ||||
| 	{ | ||||
| 	// opengl
 | ||||
| 	case GraphicsAPI::OpenGL: | ||||
| 		scope_gfx = create_scope<glGraphicsContext>(windowHandle); | ||||
| 		s_context = scope_gfx.get(); | ||||
| 		break; | ||||
| 	// directx
 | ||||
| 	case GraphicsAPI::DirectX: | ||||
| 		lt_win(scope_gfx = create_scope<dxGraphicsContext>(windowHandle); | ||||
| 		       s_context = scope_gfx.get(); | ||||
| 		       break;) | ||||
| 
 | ||||
| 		    default | ||||
| 		    : lt_assert( | ||||
| 		          false, | ||||
| 		          "Invalid/unsupported 'GraphicsAPI' {}", | ||||
| 		          Stringifier::graphics_api_to_string(api) | ||||
| 		      ); | ||||
| 		return nullptr; | ||||
| 	} | ||||
| 
 | ||||
| 	// create 'GraphicsContext' dependent classes
 | ||||
| 	s_context->m_user_interface = UserInterface::create(windowHandle, s_context->m_shared_context); | ||||
| 	s_context->m_renderer = Renderer::create(windowHandle, s_context->m_shared_context); | ||||
| 
 | ||||
| 	// check
 | ||||
| 	lt_assert(s_context->m_user_interface, "Failed to create UserInterface"); | ||||
| 	lt_assert(s_context->m_renderer, "Failed to create renderer"); | ||||
| 
 | ||||
| 	return std::move(scope_gfx); | ||||
| } | ||||
| 
 | ||||
| } // namespace Light
 | ||||
|  | @ -1,9 +1,9 @@ | |||
| #include <engine/events/char.hpp> | ||||
| #include <engine/events/event.hpp> | ||||
| #include <engine/events/keyboard.hpp> | ||||
| #include <engine/events/mouse.hpp> | ||||
| #include <engine/events/window.hpp> | ||||
| #include <engine/layer/layer.hpp> | ||||
| #include <input/events/char.hpp> | ||||
| #include <input/events/event.hpp> | ||||
| #include <input/events/keyboard.hpp> | ||||
| #include <input/events/mouse.hpp> | ||||
| #include <input/events/window.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,9 +1,9 @@ | |||
| #include <engine/events/event.hpp> | ||||
| #include <engine/events/keyboard.hpp> | ||||
| #include <engine/events/mouse.hpp> | ||||
| #include <engine/events/window.hpp> | ||||
| #include <engine/layer/layer.hpp> | ||||
| #include <engine/layer/layer_stack.hpp> | ||||
| #include <input/events/event.hpp> | ||||
| #include <input/events/keyboard.hpp> | ||||
| #include <input/events/mouse.hpp> | ||||
| #include <input/events/window.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,24 +1,21 @@ | |||
| #include <GLFW/glfw3.h> | ||||
| #include <engine/events/char.hpp> | ||||
| #include <engine/events/event.hpp> | ||||
| #include <engine/events/keyboard.hpp> | ||||
| #include <engine/events/mouse.hpp> | ||||
| #include <engine/events/window.hpp> | ||||
| #include <engine/graphics/graphics_context.hpp> | ||||
| #include <engine/platform/os/linux/l_window.hpp> | ||||
| #include <utility> | ||||
| #include <utility> | ||||
| #include <engine/os/linux/l_window.hpp> | ||||
| #include <input/events/char.hpp> | ||||
| #include <input/events/event.hpp> | ||||
| #include <input/events/keyboard.hpp> | ||||
| #include <input/events/mouse.hpp> | ||||
| #include <input/events/window.hpp> | ||||
| #include <renderer/graphics_context.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| auto Window::create(const std::function<void(Event &)>& callback) -> Scope<Window> | ||||
| auto Window::create(const std::function<void(Event &)> &callback) -> Scope<Window> | ||||
| { | ||||
| 	return create_scope<lWindow>(callback); | ||||
| } | ||||
| 
 | ||||
| lWindow::lWindow(std::function<void(Event &)> callback) | ||||
|     :  | ||||
|      m_event_callback(std::move(std::move(callback))) | ||||
|     : m_event_callback(std::move(std::move(callback))) | ||||
| { | ||||
| 	// init glfw
 | ||||
| 	lt_assert(glfwInit(), "lWindow::lWindow: failed to initialize 'glfw'"); | ||||
|  | @ -35,10 +32,6 @@ lWindow::lWindow(std::function<void(Event &)> callback) | |||
| 	// bind event stuff
 | ||||
| 	glfwSetWindowUserPointer(m_handle, &m_event_callback); | ||||
| 	bind_glfw_events(); | ||||
| 
 | ||||
| 	// create graphics context
 | ||||
| 	m_graphics_context = GraphicsContext::create(GraphicsAPI::OpenGL, m_handle); | ||||
| 	lt_assert(m_graphics_context, "lWindow::lWindow: failed to create 'GraphicsContext'"); | ||||
| } | ||||
| 
 | ||||
| lWindow::~lWindow() | ||||
|  | @ -59,7 +52,9 @@ void lWindow::on_event(const Event &event) | |||
| 	case EventType::WindowClosed: b_Closed = true; break; | ||||
| 
 | ||||
| 	/* resized */ | ||||
| 	case EventType::WindowResized: on_window_resize(dynamic_cast<const WindowResizedEvent &>(event)); break; | ||||
| 	case EventType::WindowResized: | ||||
| 		on_window_resize(dynamic_cast<const WindowResizedEvent &>(event)); | ||||
| 		break; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | @ -114,11 +109,14 @@ void lWindow::set_visibility(bool visible, bool toggle) | |||
| { | ||||
| 	m_properties.visible = toggle ? !m_properties.visible : visible; | ||||
| 
 | ||||
| 	if (m_properties.visible) { | ||||
| 	if (m_properties.visible) | ||||
| 	{ | ||||
| 		glfwShowWindow(m_handle); | ||||
| 	} else { | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		glfwHideWindow(m_handle); | ||||
| } | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void lWindow::bind_glfw_events() | ||||
|  | @ -133,23 +131,26 @@ void lWindow::bind_glfw_events() | |||
| 		callback(event); | ||||
| 	}); | ||||
| 
 | ||||
| 	glfwSetMouseButtonCallback(m_handle, [](GLFWwindow *window, int button, int action, int  /*mods*/) { | ||||
| 		std::function<void(Event &)> const callback = *(std::function<void(Event &)> *) | ||||
| 		                                            glfwGetWindowUserPointer(window); | ||||
| 	glfwSetMouseButtonCallback( | ||||
| 	    m_handle, | ||||
| 	    [](GLFWwindow *window, int button, int action, int /*mods*/) { | ||||
| 		    std::function<void(Event &)> const callback = *(std::function<void(Event &)> *) | ||||
| 		                                                      glfwGetWindowUserPointer(window); | ||||
| 
 | ||||
| 		if (action == GLFW_PRESS) | ||||
| 		{ | ||||
| 			auto event = ButtonPressedEvent { button }; | ||||
| 			callback(event); | ||||
| 		} | ||||
| 		else if (action == GLFW_RELEASE) | ||||
| 		{ | ||||
| 			auto event = ButtonReleasedEvent { button }; | ||||
| 			callback(event); | ||||
| 		} | ||||
| 	}); | ||||
| 		    if (action == GLFW_PRESS) | ||||
| 		    { | ||||
| 			    auto event = ButtonPressedEvent { button }; | ||||
| 			    callback(event); | ||||
| 		    } | ||||
| 		    else if (action == GLFW_RELEASE) | ||||
| 		    { | ||||
| 			    auto event = ButtonReleasedEvent { button }; | ||||
| 			    callback(event); | ||||
| 		    } | ||||
| 	    } | ||||
| 	); | ||||
| 
 | ||||
| 	glfwSetScrollCallback(m_handle, [](GLFWwindow *window, double  /*xoffset*/, double yoffset) { | ||||
| 	glfwSetScrollCallback(m_handle, [](GLFWwindow *window, double /*xoffset*/, double yoffset) { | ||||
| 		auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window); | ||||
| 
 | ||||
| 		auto event = WheelScrolledEvent { static_cast<float>(yoffset) }; | ||||
|  | @ -158,7 +159,7 @@ void lWindow::bind_glfw_events() | |||
| 
 | ||||
| 	glfwSetKeyCallback( | ||||
| 	    m_handle, | ||||
| 	    [](GLFWwindow *window, int key, int  /*scancode*/, int action, int  /*mods*/) { | ||||
| 	    [](GLFWwindow *window, int key, int /*scancode*/, int action, int /*mods*/) { | ||||
| 		    auto callback = *(std::function<void(Event &)> *)glfwGetWindowUserPointer(window); | ||||
| 
 | ||||
| 		    if (action == GLFW_PRESS) | ||||
|  | @ -4,7 +4,7 @@ | |||
| #include <engine/events/keyboard.hpp> | ||||
| #include <engine/events/mouse.hpp> | ||||
| #include <engine/events/window.hpp> | ||||
| #include <engine/graphics/graphics_context.hpp> | ||||
| #include <renderer/graphics_context.hpp> | ||||
| #include <engine/platform/os/windows/w_window.hpp> | ||||
| 
 | ||||
| extern "C" | ||||
|  | @ -1,107 +0,0 @@ | |||
| #include <engine/platform/graphics/opengl/buffers.hpp> | ||||
| #include <engine/platform/graphics/opengl/vertex_layout.hpp> | ||||
| #include <glad/gl.h> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| glVertexLayout::glVertexLayout( | ||||
|     const Ref<VertexBuffer>& buffer, | ||||
|     const std::vector<std::pair<std::string, VertexElementType>> &elements | ||||
| ) | ||||
|     : m_array_id(NULL) | ||||
| { | ||||
| 	// check
 | ||||
| 	lt_assert( | ||||
| 	    std::dynamic_pointer_cast<glVertexBuffer>(buffer), | ||||
| 	    "Failed to cast 'VertexBuffer' to 'glVertexBuffer'" | ||||
| 	); | ||||
| 	lt_assert(!elements.empty(), "'elements' is empty"); | ||||
| 
 | ||||
| 	// local
 | ||||
| 	auto elementsDesc = std::vector<glVertexElementDesc> {}; | ||||
| 	elementsDesc.reserve(elements.size()); | ||||
| 	auto stride = 0u; | ||||
| 
 | ||||
| 	// extract elements desc
 | ||||
| 	for (const auto &element : elements) | ||||
| 	{ | ||||
| 		elementsDesc.push_back(get_element_desc(element.second, stride)); | ||||
| 		stride += elementsDesc.back().typeSize * elementsDesc.back().count; | ||||
| 	} | ||||
| 
 | ||||
| 	// create vertex array
 | ||||
| 	glCreateVertexArrays(1, &m_array_id); | ||||
| 
 | ||||
| 	// bind buffer and array
 | ||||
| 	buffer->bind(); | ||||
| 	bind(); | ||||
| 
 | ||||
| 	// enable vertex attributes
 | ||||
| 	auto index = 0u; | ||||
| 	for (const auto &elementDesc : elementsDesc) | ||||
| 	{ | ||||
| 		glVertexAttribPointer( | ||||
| 		    index, | ||||
| 		    elementDesc.count, | ||||
| 		    elementDesc.type, | ||||
| 		    GL_FALSE, | ||||
| 		    stride, | ||||
| 		    (const void *)elementDesc.offset | ||||
| 		); | ||||
| 		glEnableVertexAttribArray(index++); | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| glVertexLayout::~glVertexLayout() | ||||
| { | ||||
| 	glDeleteVertexArrays(1, &m_array_id); | ||||
| } | ||||
| 
 | ||||
| void glVertexLayout::bind() | ||||
| { | ||||
| 	glBindVertexArray(m_array_id); | ||||
| } | ||||
| 
 | ||||
| void glVertexLayout::un_bind() | ||||
| { | ||||
| 	glBindVertexArray(NULL); | ||||
| } | ||||
| 
 | ||||
| auto glVertexLayout::get_element_desc(VertexElementType type, unsigned int offset) | ||||
|     -> glVertexElementDesc | ||||
| { | ||||
| 	switch (type) | ||||
| 	{ | ||||
| 	/* byte */ | ||||
| 	case Light::VertexElementType::Byte1: return { .type=GL_BYTE, .count=1u, .typeSize=sizeof(GLbyte), .offset=offset }; | ||||
| 	case Light::VertexElementType::Byte2: return { .type=GL_BYTE, .count=1u, .typeSize=sizeof(GLbyte), .offset=offset }; | ||||
| 	case Light::VertexElementType::Byte4: return { .type=GL_BYTE, .count=1u, .typeSize=sizeof(GLbyte), .offset=offset }; | ||||
| 
 | ||||
| 	/* ubyte */ | ||||
| 	case Light::VertexElementType::UByte1: return { .type=GL_UNSIGNED_BYTE, .count=1u, .typeSize=sizeof(GLubyte), .offset=offset }; | ||||
| 	case Light::VertexElementType::UByte2: return { .type=GL_UNSIGNED_BYTE, .count=2u, .typeSize=sizeof(GLubyte), .offset=offset }; | ||||
| 	case Light::VertexElementType::UByte4: return { .type=GL_UNSIGNED_BYTE, .count=4u, .typeSize=sizeof(GLubyte), .offset=offset }; | ||||
| 
 | ||||
| 	/* int */ | ||||
| 	case VertexElementType::Int1: return { .type=GL_INT, .count=1u, .typeSize=sizeof(GLint), .offset=offset }; | ||||
| 	case VertexElementType::Int2: return { .type=GL_INT, .count=2u, .typeSize=sizeof(GLint), .offset=offset }; | ||||
| 	case VertexElementType::Int3: return { .type=GL_INT, .count=3u, .typeSize=sizeof(GLint), .offset=offset }; | ||||
| 	case VertexElementType::Int4: return { .type=GL_INT, .count=4u, .typeSize=sizeof(GLint), .offset=offset }; | ||||
| 
 | ||||
| 	/* uint */ | ||||
| 	case VertexElementType::UInt1: return { .type=GL_UNSIGNED_INT, .count=1u, .typeSize=sizeof(GLuint), .offset=offset }; | ||||
| 	case VertexElementType::UInt2: return { .type=GL_UNSIGNED_INT, .count=2u, .typeSize=sizeof(GLuint), .offset=offset }; | ||||
| 	case VertexElementType::UInt3: return { .type=GL_UNSIGNED_INT, .count=3u, .typeSize=sizeof(GLuint), .offset=offset }; | ||||
| 	case VertexElementType::UInt4: return { .type=GL_UNSIGNED_INT, .count=4u, .typeSize=sizeof(GLuint), .offset=offset }; | ||||
| 
 | ||||
| 	/* float */ | ||||
| 	case VertexElementType::Float1: return { .type=GL_FLOAT, .count=1u, .typeSize=sizeof(GLfloat), .offset=offset }; | ||||
| 	case VertexElementType::Float2: return { .type=GL_FLOAT, .count=2u, .typeSize=sizeof(GLfloat), .offset=offset }; | ||||
| 	case VertexElementType::Float3: return { .type=GL_FLOAT, .count=3u, .typeSize=sizeof(GLfloat), .offset=offset }; | ||||
| 	case VertexElementType::Float4: return { .type=GL_FLOAT, .count=4u, .typeSize=sizeof(GLfloat), .offset=offset }; | ||||
| 
 | ||||
| 	default: lt_assert(false, "Invalid 'VertexElementType'"); return {}; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| } // namespace Light
 | ||||
|  | @ -1,4 +1,4 @@ | |||
| #include <engine/graphics/renderer.hpp> | ||||
| #include <renderer/renderer.hpp> | ||||
| #include <engine/scene/components.hpp> | ||||
| #include <engine/scene/entity.hpp> | ||||
| #include <engine/scene/scene.hpp> | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #include <engine/graphics/texture.hpp> | ||||
| #include <renderer/texture.hpp> | ||||
| #include <engine/scene/components.hpp> | ||||
| #include <engine/utils/resource_manager.hpp> | ||||
| #include <asset_manager/asset_manager.hpp> | ||||
| #include <engine/utils/serializer.hpp> | ||||
| 
 | ||||
| namespace YAML { | ||||
|  | @ -173,11 +173,11 @@ auto SceneSerializer::deserialize(const std::string &file_path) -> bool | |||
| 
 | ||||
| 				if (!texturePaths.contains(texturePath)) | ||||
| 				{ | ||||
| 					ResourceManager::load_texture(texturePath, texturePath); | ||||
| 					AssetManager::load_texture(texturePath, texturePath); | ||||
| 					texturePaths.insert(texturePath); | ||||
| 				} | ||||
| 
 | ||||
| 				entitySpriteRendererComponent.texture = ResourceManager::get_texture(texturePath); | ||||
| 				entitySpriteRendererComponent.texture = AssetManager::get_texture(texturePath); | ||||
| 			} | ||||
| 			/* #TEMPORARY SOLUTION# */ | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include <engine/graphics/graphics_context.hpp> | ||||
| #include <renderer/graphics_context.hpp> | ||||
| #include <engine/utils/stringifier.hpp> | ||||
| #include <glad/gl.h> | ||||
| #include <spdlog/common.h> | ||||
|  |  | |||
							
								
								
									
										2
									
								
								modules/input/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								modules/input/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| add_library_module(input input.cpp) | ||||
| target_link_libraries(input PUBLIC spdlog::spdlog glm::glm imgui logger) | ||||
|  | @ -1,7 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/events/event.hpp> | ||||
| #include <input/events/event.hpp> | ||||
| #include <sstream> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,7 +1,5 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| enum class EventType | ||||
|  | @ -1,7 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/events/event.hpp> | ||||
| #include <input/events/event.hpp> | ||||
| #include <sstream> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,8 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/events/event.hpp> | ||||
| #include <glm/glm.hpp> | ||||
| #include <input/events/event.hpp> | ||||
| #include <sstream> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,8 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/events/event.hpp> | ||||
| #include <glm/glm.hpp> | ||||
| #include <input/events/event.hpp> | ||||
| #include <sstream> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,7 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <array> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <glm/glm.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,10 +1,9 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| 
 | ||||
| 
 | ||||
| #include <cstdint> | ||||
| 
 | ||||
| namespace Light::Key { | ||||
| 
 | ||||
| enum : uint16_t | ||||
| { | ||||
| 	/* digits */ | ||||
|  | @ -177,6 +176,5 @@ enum : uint16_t | |||
| 	Menu = 348, | ||||
| 
 | ||||
| }; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -1,10 +1,9 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| 
 | ||||
| 
 | ||||
| #include <cstdint> | ||||
| 
 | ||||
| namespace Light::Mouse { | ||||
| 
 | ||||
| enum : uint8_t | ||||
| { | ||||
| 	Button1 = 0, | ||||
|  | @ -20,6 +19,5 @@ enum : uint8_t | |||
| 	RButton = Button2, | ||||
| 	MButton = Button3, | ||||
| }; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | @ -1,10 +1,11 @@ | |||
| #include <engine/events/char.hpp> | ||||
| #include <engine/events/event.hpp> | ||||
| #include <engine/events/keyboard.hpp> | ||||
| #include <engine/events/mouse.hpp> | ||||
| #include <engine/input/input.hpp> | ||||
| #include <engine/input/key_codes.hpp> | ||||
| #include <imgui.h> | ||||
| #include <input/events/char.hpp> | ||||
| #include <input/events/event.hpp> | ||||
| #include <input/events/keyboard.hpp> | ||||
| #include <input/events/mouse.hpp> | ||||
| #include <input/input.hpp> | ||||
| #include <input/key_codes.hpp> | ||||
| #include <logger/logger.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -10,5 +10,7 @@ target_link_libraries( | |||
|   mirror | ||||
|   PUBLIC engine | ||||
|   PUBLIC opengl::opengl | ||||
|   PUBLIC ui | ||||
|   PUBLIC imgui | ||||
|   PUBLIC input | ||||
| ) | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <engine/scene/entity.hpp> | ||||
| #include <engine/scene/scene.hpp> | ||||
| #include <mirror/panel/panel.hpp> | ||||
|  |  | |||
|  | @ -1,5 +1,8 @@ | |||
| #include <asset_manager/asset_manager.hpp> | ||||
| #include <engine/utils/serializer.hpp> | ||||
| #include <input/key_codes.hpp> | ||||
| #include <mirror/editor_layer.hpp> | ||||
| #include <ui/ui.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -28,11 +31,11 @@ EditorLayer::EditorLayer(const std::string &name) | |||
| 		m_camera_entity = m_scene->create_entity("Camera"); | ||||
| 		m_camera_entity.add_component<CameraComponent>(SceneCamera(), true); | ||||
| 
 | ||||
| 		ResourceManager::load_texture("Awesomeface", "data/assets/textures/awesomeface.asset"); | ||||
| 		AssetManager::load_texture("Awesomeface", "data/assets/textures/awesomeface.asset"); | ||||
| 
 | ||||
| 		auto entity = Entity { m_scene->create_entity("Awesomeface", {}) }; | ||||
| 		entity.add_component<SpriteRendererComponent>( | ||||
| 		    ResourceManager::get_texture("Awesomeface"), | ||||
| 		    AssetManager::get_texture("Awesomeface"), | ||||
| 		    glm::vec4 { 0.0f, 1.0f, 1.0f, 1.0f } | ||||
| 		); | ||||
| 	} | ||||
|  |  | |||
|  | @ -1,3 +1,4 @@ | |||
| #include <asset_manager/asset_manager.hpp> | ||||
| #include <engine/engine.hpp> | ||||
| #include <engine/utils/serializer.hpp> | ||||
| #include <imgui.h> | ||||
|  | @ -10,15 +11,15 @@ AssetBrowserPanel::AssetBrowserPanel(Ref<Scene> active_scene) | |||
|     , m_assets_path("./data/assets") | ||||
|     , m_active_scene(std::move(active_scene)) | ||||
| { | ||||
| 	ResourceManager::load_texture("_Assets_Directory", "data/engine/icons/asset/dir.asset"); | ||||
| 	ResourceManager::load_texture("_Assets_Scene", "data/engine/icons/asset/scene.asset"); | ||||
| 	ResourceManager::load_texture("_Assets_Image", "data/engine/icons/asset/img.asset"); | ||||
| 	ResourceManager::load_texture("_Assets_Text", "data/engine/icons/asset/txt.asset"); | ||||
| 	AssetManager::load_texture("_Assets_Directory", "data/engine/icons/asset/dir.asset"); | ||||
| 	AssetManager::load_texture("_Assets_Scene", "data/engine/icons/asset/scene.asset"); | ||||
| 	AssetManager::load_texture("_Assets_Image", "data/engine/icons/asset/img.asset"); | ||||
| 	AssetManager::load_texture("_Assets_Text", "data/engine/icons/asset/txt.asset"); | ||||
| 
 | ||||
| 	m_directory_texture = ResourceManager::get_texture("_Assets_Directory"); | ||||
| 	m_scene_texture = ResourceManager::get_texture("_Assets_Scene"); | ||||
| 	m_image_texture = ResourceManager::get_texture("_Assets_Image"); | ||||
| 	m_text_texture = ResourceManager::get_texture("_Assets_Text"); | ||||
| 	m_directory_texture = AssetManager::get_texture("_Assets_Directory"); | ||||
| 	m_scene_texture = AssetManager::get_texture("_Assets_Scene"); | ||||
| 	m_image_texture = AssetManager::get_texture("_Assets_Image"); | ||||
| 	m_text_texture = AssetManager::get_texture("_Assets_Text"); | ||||
| } | ||||
| 
 | ||||
| void AssetBrowserPanel::on_user_interface_update() | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| #include <engine/scene/components.hpp> | ||||
| #include <engine/utils/resource_manager.hpp> | ||||
| #include <asset_manager/asset_manager.hpp> | ||||
| #include <glm/glm.hpp> | ||||
| #include <glm/gtc/type_ptr.hpp> | ||||
| #include <imgui.h> | ||||
|  | @ -47,7 +47,7 @@ void PropertiesPanel::on_user_interface_update() | |||
| 			    )) | ||||
| 			{ | ||||
| 				m_entity_context.add_component<SpriteRendererComponent>( | ||||
| 				    Light::ResourceManager::get_texture("awesomeface") | ||||
| 				    Light::AssetManager::get_texture("awesomeface") | ||||
| 				); | ||||
| 			} | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										37
									
								
								modules/renderer/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								modules/renderer/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,37 @@ | |||
| add_library_module(renderer | ||||
|     blender.cpp | ||||
|     buffers.cpp | ||||
|     framebuffer.cpp | ||||
|     graphics_context.cpp | ||||
|     render_command.cpp | ||||
|     renderer.cpp | ||||
|     renderer_programs/quad.cpp | ||||
|     renderer_programs/texture.cpp | ||||
|     renderer_programs/tinted_texture.cpp | ||||
|     shader.cpp | ||||
|     texture.cpp | ||||
|     vertex_layout.cpp | ||||
|     gl/blender.cpp | ||||
|     gl/buffers.cpp | ||||
|     gl/framebuffers.cpp | ||||
|     gl/graphics_context.cpp | ||||
|     gl/render_command.cpp | ||||
|     gl/shader.cpp | ||||
|     gl/texture.cpp | ||||
|     gl/vertex_layout.cpp | ||||
| ) | ||||
| 
 | ||||
| target_link_libraries( | ||||
|   renderer | ||||
|   PUBLIC camera | ||||
|   PUBLIC input | ||||
|   PUBLIC glad | ||||
|   PUBLIC logger | ||||
|   PUBLIC opengl::opengl | ||||
|   PUBLIC glfw | ||||
|   PUBLIC imgui | ||||
|   PUBLIC asset_parser | ||||
|   PUBLIC yaml-cpp::yaml-cpp | ||||
|   PUBLIC EnTT::EnTT | ||||
|   PRIVATE lt_debug  | ||||
| ) | ||||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -1,8 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/blender.hpp> | ||||
| #include <renderer/blender.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,8 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/buffers.hpp> | ||||
| 
 | ||||
| #include <renderer/buffers.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,8 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/framebuffer.hpp> | ||||
| 
 | ||||
| #include <renderer/framebuffer.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,8 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/graphics_context.hpp> | ||||
| 
 | ||||
| #include <renderer/graphics_context.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| struct GLFWwindow; | ||||
|  | @ -1,8 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/render_command.hpp> | ||||
| 
 | ||||
| #include <renderer/render_command.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,8 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/shader.hpp> | ||||
| 
 | ||||
| #include <renderer/shader.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,8 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/shared_context.hpp> | ||||
| 
 | ||||
| #include <renderer/shared_context.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,8 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/texture.hpp> | ||||
| 
 | ||||
| #include <renderer/texture.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,8 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/user_interface/user_interface.hpp> | ||||
| #include <ui/ui.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| struct GLFWwindow; | ||||
|  | @ -1,8 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <d3d11.h> | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/vertex_layout.hpp> | ||||
| 
 | ||||
| #include <renderer/vertex_layout.hpp> | ||||
| #include <wrl.h> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <glm/glm.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/blender.hpp> | ||||
| 
 | ||||
| #include <renderer/blender.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/buffers.hpp> | ||||
| 
 | ||||
| #include <renderer/buffers.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/framebuffer.hpp> | ||||
| 
 | ||||
| #include <renderer/framebuffer.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/graphics_context.hpp> | ||||
| 
 | ||||
| #include <renderer/graphics_context.hpp> | ||||
| 
 | ||||
| struct GLFWwindow; | ||||
| 
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/render_command.hpp> | ||||
| 
 | ||||
| #include <renderer/render_command.hpp> | ||||
| 
 | ||||
| struct GLFWwindow; | ||||
| 
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/shader.hpp> | ||||
| 
 | ||||
| #include <renderer/shader.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/shared_context.hpp> | ||||
| 
 | ||||
| #include <renderer/shared_context.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/texture.hpp> | ||||
| 
 | ||||
| #include <renderer/texture.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/user_interface/user_interface.hpp> | ||||
| 
 | ||||
| #include <ui/ui.hpp> | ||||
| 
 | ||||
| struct GLFWwindow; | ||||
| 
 | ||||
|  | @ -24,7 +24,7 @@ public: | |||
| 	void log_debug_data() override; | ||||
| 
 | ||||
| private: | ||||
| 	GLFWwindow *m_window_handle{}; | ||||
| 	GLFWwindow *m_window_handle {}; | ||||
| }; | ||||
| 
 | ||||
| } // namespace Light
 | ||||
|  | @ -1,7 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/vertex_layout.hpp> | ||||
| 
 | ||||
| #include <renderer/vertex_layout.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -1,15 +1,10 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| struct GLFWwindow; | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| class Renderer; | ||||
| class resource_manager; | ||||
| class SharedContext; | ||||
| class UserInterface; | ||||
| class WindowResizedEvent; | ||||
| 
 | ||||
| enum class GraphicsAPI | ||||
|  | @ -24,7 +19,11 @@ enum class GraphicsAPI | |||
| class GraphicsContext | ||||
| { | ||||
| public: | ||||
| 	static auto create(GraphicsAPI api, GLFWwindow *windowHandle) -> Scope<GraphicsContext>; | ||||
| 	static auto create( | ||||
| 	    GraphicsAPI api, | ||||
| 	    GLFWwindow *window_handle | ||||
| 
 | ||||
| 	) -> Scope<GraphicsContext>; | ||||
| 
 | ||||
| 	GraphicsContext(const GraphicsContext &) = delete; | ||||
| 
 | ||||
|  | @ -44,16 +43,6 @@ public: | |||
| 		return s_context->m_shared_context; | ||||
| 	} | ||||
| 
 | ||||
| 	auto get_renderer() -> Renderer * | ||||
| 	{ | ||||
| 		return m_renderer.get(); | ||||
| 	} | ||||
| 
 | ||||
| 	auto get_user_interface() -> UserInterface * | ||||
| 	{ | ||||
| 		return m_user_interface.get(); | ||||
| 	} | ||||
| 
 | ||||
| protected: | ||||
| 	GraphicsContext() = default; | ||||
| 
 | ||||
|  | @ -63,10 +52,6 @@ protected: | |||
| 
 | ||||
| private: | ||||
| 	static GraphicsContext *s_context; | ||||
| 
 | ||||
| 	Scope<UserInterface> m_user_interface; | ||||
| 
 | ||||
| 	Scope<Renderer> m_renderer; | ||||
| }; | ||||
| 
 | ||||
| } // namespace Light
 | ||||
|  | @ -1,6 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| #include <glm/glm.hpp> | ||||
| 
 | ||||
| struct GLFWwindow; | ||||
|  | @ -1,9 +1,15 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/renderer_programs/quad.hpp> | ||||
| #include <engine/graphics/renderer_programs/texture.hpp> | ||||
| #include <engine/graphics/renderer_programs/tinted_texture.hpp> | ||||
| //
 | ||||
| #include <renderer/blender.hpp> | ||||
| #include <renderer/buffers.hpp> | ||||
| #include <renderer/render_command.hpp> | ||||
| #include <renderer/renderer.hpp> | ||||
| ///
 | ||||
| 
 | ||||
| #include <renderer/renderer_programs/quad.hpp> | ||||
| #include <renderer/renderer_programs/texture.hpp> | ||||
| #include <renderer/renderer_programs/tinted_texture.hpp> | ||||
| #include <utility> | ||||
| 
 | ||||
| #define LT_MAX_QUAD_RENDERER_VERTICES           (1028u * 4u) | ||||
|  | @ -14,7 +20,6 @@ struct GLFWwindow; | |||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| class Blender; | ||||
| class ConstantBuffer; | ||||
| class Framebuffer; | ||||
| class RenderCommand; | ||||
|  | @ -22,12 +27,25 @@ class Texture; | |||
| class SharedContext; | ||||
| class Camera; | ||||
| class WindowResizedEvent; | ||||
| class Shader; | ||||
| 
 | ||||
| class Renderer | ||||
| { | ||||
| public: | ||||
| 	static auto create(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext) | ||||
| 	    -> Scope<Renderer>; | ||||
| 	struct CreateInfo | ||||
| 	{ | ||||
| 		Ref<Shader> quad_renderer_shader; | ||||
| 
 | ||||
| 		Ref<Shader> texture_renderer_shader; | ||||
| 
 | ||||
| 		Ref<Shader> tinted_texture_renderer_shader; | ||||
| 	}; | ||||
| 
 | ||||
| 	static auto create( | ||||
| 	    GLFWwindow *window_handle, | ||||
| 	    Ref<SharedContext> shared_context, | ||||
| 	    CreateInfo create_info | ||||
| 	) -> Scope<Renderer>; | ||||
| 
 | ||||
| 	static void draw_quad( | ||||
| 	    const glm::vec3 &position, | ||||
|  | @ -105,7 +123,7 @@ private: | |||
| 
 | ||||
| 	bool m_should_clear_backbuffer { false }; | ||||
| 
 | ||||
| 	Renderer(GLFWwindow *windowHandle, const Ref<SharedContext> &sharedContext); | ||||
| 	Renderer(GLFWwindow *windowHandle, Ref<SharedContext> sharedContext, CreateInfo create_info); | ||||
| 
 | ||||
| 	void draw_quad_impl( | ||||
| 	    const glm::vec3 &position, | ||||
|  | @ -1,8 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/renderer_programs/renderer_program.hpp> | ||||
| #include <glm/glm.hpp> | ||||
| #include <renderer/renderer_programs/renderer_program.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -12,6 +11,7 @@ class IndexBuffer; | |||
| class VertexLayout; | ||||
| class OrthographicCamera; | ||||
| class SharedContext; | ||||
| class Shader; | ||||
| 
 | ||||
| class QuadRendererProgram: RendererProgram | ||||
| { | ||||
|  | @ -24,7 +24,11 @@ public: | |||
| 		glm::vec4 tint; | ||||
| 	}; | ||||
| 
 | ||||
| 	QuadRendererProgram(unsigned int maxVertices, const Ref<SharedContext> &sharedContext); | ||||
| 	QuadRendererProgram( | ||||
| 	    unsigned int maxVertices, | ||||
| 	    const Ref<SharedContext> &shared_context, | ||||
| 	    Ref<Shader> shader | ||||
| 	); | ||||
| 
 | ||||
| 	auto advance() -> bool; | ||||
| 
 | ||||
|  | @ -1,11 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
| class OrthographicCamera; | ||||
| 
 | ||||
| class RendererProgram | ||||
| { | ||||
| 	virtual void map() = 0; | ||||
|  | @ -13,8 +9,9 @@ class RendererProgram | |||
| 	virtual void un_map() = 0; | ||||
| 
 | ||||
| 	virtual void bind() = 0; | ||||
| 
 | ||||
| public: | ||||
| virtual ~RendererProgram() = default; | ||||
| 	virtual ~RendererProgram() = default; | ||||
| }; | ||||
| 
 | ||||
| } // namespace Light
 | ||||
|  | @ -1,8 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <engine/base/base.hpp> | ||||
| #include <engine/graphics/renderer_programs/renderer_program.hpp> | ||||
| #include <glm/glm.hpp> | ||||
| #include <renderer/renderer_programs/renderer_program.hpp> | ||||
| 
 | ||||
| namespace Light { | ||||
| 
 | ||||
|  | @ -25,7 +24,11 @@ public: | |||
| 		glm::vec2 texcoord; | ||||
| 	}; | ||||
| 
 | ||||
| 	TextureRendererProgram(unsigned int maxVertices, const Ref<SharedContext> &sharedContext); | ||||
| 	TextureRendererProgram( | ||||
| 	    unsigned int maxVertices, | ||||
| 	    const Ref<SharedContext> &shared_context, | ||||
| 	    Ref<Shader> shader | ||||
| 	); | ||||
| 
 | ||||
| 	auto advance() -> bool; | ||||
| 
 | ||||
Some files were not shown because too many files have changed in this diff Show more
		Loading…
	
	Add table
		
		Reference in a new issue