diff --git a/runtime/Includes/Core/Application.h b/runtime/Includes/Core/Application.h index 7521d77..f0b265d 100644 --- a/runtime/Includes/Core/Application.h +++ b/runtime/Includes/Core/Application.h @@ -47,12 +47,12 @@ namespace mlx ~Application(); private: - RenderCore m_render_core; FpsManager m_fps; Inputs m_in; ImageRegistry m_image_registry; std::vector> m_graphics; std::function f_loop_hook; + std::unique_ptr p_render_core; Handle p_param = nullptr; }; } diff --git a/runtime/Includes/Renderer/RenderCore.h b/runtime/Includes/Renderer/RenderCore.h index 36947a6..a119534 100644 --- a/runtime/Includes/Renderer/RenderCore.h +++ b/runtime/Includes/Renderer/RenderCore.h @@ -9,9 +9,9 @@ namespace mlx class RenderCore { - friend class Application; - public: + RenderCore(); + [[nodiscard]] MLX_FORCEINLINE VkInstance GetInstance() const noexcept { return m_instance; } [[nodiscard]] MLX_FORCEINLINE VkInstance& GetInstanceRef() noexcept { return m_instance; } [[nodiscard]] MLX_FORCEINLINE VkDevice GetDevice() const noexcept { return m_device; } @@ -31,12 +31,12 @@ namespace mlx #undef MLX_VULKAN_INSTANCE_FUNCTION #undef MLX_VULKAN_DEVICE_FUNCTION + ~RenderCore(); + private: - RenderCore(); void LoadKVFGlobalVulkanFunctionPointers() const noexcept; void LoadKVFInstanceVulkanFunctionPointers() const noexcept; void LoadKVFDeviceVulkanFunctionPointers() const noexcept; - ~RenderCore(); private: static RenderCore* s_instance; diff --git a/runtime/Sources/Core/Application.cpp b/runtime/Sources/Core/Application.cpp index 29ffbbb..b854f34 100644 --- a/runtime/Sources/Core/Application.cpp +++ b/runtime/Sources/Core/Application.cpp @@ -8,7 +8,7 @@ namespace mlx { - Application::Application() : m_render_core(), m_fps(), m_in() + Application::Application() : m_fps(), m_in() { EventBus::RegisterListener({[](const EventBase& event) { @@ -18,6 +18,7 @@ namespace mlx m_fps.Init(); SDLManager::Get().Init(); + p_render_core = std::make_unique(); } void Application::Run() noexcept @@ -87,6 +88,7 @@ namespace mlx Application::~Application() { + p_render_core.reset(); SDLManager::Get().Shutdown(); } } diff --git a/runtime/Sources/Core/SDLManager.cpp b/runtime/Sources/Core/SDLManager.cpp index fa0801f..f96fa58 100644 --- a/runtime/Sources/Core/SDLManager.cpp +++ b/runtime/Sources/Core/SDLManager.cpp @@ -17,7 +17,7 @@ namespace mlx constexpr const std::uint32_t amask = 0xff000000; #endif - namespace details + namespace Internal { struct WindowInfos { @@ -101,9 +101,9 @@ namespace mlx DebugLog("SDL Manager initialized"); } - void* SDLManager::CreateWindow(const std::string& title, std::size_t w, std::size_t h, bool hidden) + Handle SDLManager::CreateWindow(const std::string& title, std::size_t w, std::size_t h, bool hidden) { - details::WindowInfos* infos = new details::WindowInfos; + Internal::WindowInfos* infos = new Internal::WindowInfos; Verify(infos != nullptr, "SDL : window allocation failed"); infos->window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | (hidden ? SDL_WINDOW_HIDDEN : SDL_WINDOW_SHOWN)); @@ -117,11 +117,11 @@ namespace mlx return infos; } - void SDLManager::DestroyWindow(void* window) noexcept + void SDLManager::DestroyWindow(Handle window) noexcept { Verify(m_windows_registry.find(window) != m_windows_registry.end(), "SDL : cannot destroy window; unknown window pointer"); - details::WindowInfos* infos = static_cast(window); + Internal::WindowInfos* infos = static_cast(window); if(infos->window != nullptr) SDL_DestroyWindow(infos->window); if(infos->icon != nullptr) @@ -134,7 +134,7 @@ namespace mlx VkSurfaceKHR SDLManager::CreateVulkanSurface(Handle window, VkInstance instance) const noexcept { VkSurfaceKHR surface; - if(!SDL_Vulkan_CreateSurface(static_cast(window), instance, &surface)) + if(!SDL_Vulkan_CreateSurface(static_cast(window)->window, instance, &surface)) FatalError("SDL : could not create a Vulkan surface; %", SDL_GetError()); return surface; } @@ -169,27 +169,27 @@ namespace mlx Vec2ui SDLManager::GetVulkanDrawableSize(Handle window) const noexcept { Vec2i extent; - SDL_Vulkan_GetDrawableSize(static_cast(window), &extent.x, &extent.y); + SDL_Vulkan_GetDrawableSize(static_cast(window)->window, &extent.x, &extent.y); return Vec2ui{ extent }; } void SDLManager::MoveMouseOnWindow(Handle window, int x, int y) const noexcept { - SDL_WarpMouseInWindow(static_cast(window), x, y); + SDL_WarpMouseInWindow(static_cast(window)->window, x, y); SDL_PumpEvents(); } void SDLManager::GetScreenSizeWindowIsOn(Handle window, int* x, int* y) const noexcept { SDL_DisplayMode DM; - SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(static_cast(window)), &DM); + SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(static_cast(window)->window), &DM); *x = DM.w; *y = DM.h; } void SDLManager::SetWindowPosition(Handle window, int x, int y) const noexcept { - SDL_SetWindowPosition(static_cast(window), x, y); + SDL_SetWindowPosition(static_cast(window)->window, x, y); } std::int32_t SDLManager::GetX() const noexcept diff --git a/runtime/Sources/Renderer/RenderCore.cpp b/runtime/Sources/Renderer/RenderCore.cpp index c04c52f..bb7bc80 100644 --- a/runtime/Sources/Renderer/RenderCore.cpp +++ b/runtime/Sources/Renderer/RenderCore.cpp @@ -27,19 +27,19 @@ namespace mlx void ErrorCallback(const char* message) noexcept { - FatalError(message, 0, "", ""); + Logs::Report(LogType::FatalError, 0, "", "", message); std::cout << std::endl; } void ValidationErrorCallback(const char* message) noexcept { - Error(message, 0, "", ""); + Logs::Report(LogType::Error, 0, "", "", message); std::cout << std::endl; } void ValidationWarningCallback(const char* message) noexcept { - Warning(message, 0, "", ""); + Logs::Report(LogType::Warning, 0, "", "", message); std::cout << std::endl; }