mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
fixing SDLManager
This commit is contained in:
@@ -47,12 +47,12 @@ namespace mlx
|
|||||||
~Application();
|
~Application();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RenderCore m_render_core;
|
|
||||||
FpsManager m_fps;
|
FpsManager m_fps;
|
||||||
Inputs m_in;
|
Inputs m_in;
|
||||||
ImageRegistry m_image_registry;
|
ImageRegistry m_image_registry;
|
||||||
std::vector<std::unique_ptr<GraphicsSupport>> m_graphics;
|
std::vector<std::unique_ptr<GraphicsSupport>> m_graphics;
|
||||||
std::function<int(Handle)> f_loop_hook;
|
std::function<int(Handle)> f_loop_hook;
|
||||||
|
std::unique_ptr<RenderCore> p_render_core;
|
||||||
Handle p_param = nullptr;
|
Handle p_param = nullptr;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,9 @@ namespace mlx
|
|||||||
|
|
||||||
class RenderCore
|
class RenderCore
|
||||||
{
|
{
|
||||||
friend class Application;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
RenderCore();
|
||||||
|
|
||||||
[[nodiscard]] MLX_FORCEINLINE VkInstance GetInstance() const noexcept { return m_instance; }
|
[[nodiscard]] MLX_FORCEINLINE VkInstance GetInstance() const noexcept { return m_instance; }
|
||||||
[[nodiscard]] MLX_FORCEINLINE VkInstance& GetInstanceRef() noexcept { return m_instance; }
|
[[nodiscard]] MLX_FORCEINLINE VkInstance& GetInstanceRef() noexcept { return m_instance; }
|
||||||
[[nodiscard]] MLX_FORCEINLINE VkDevice GetDevice() const noexcept { return m_device; }
|
[[nodiscard]] MLX_FORCEINLINE VkDevice GetDevice() const noexcept { return m_device; }
|
||||||
@@ -31,12 +31,12 @@ namespace mlx
|
|||||||
#undef MLX_VULKAN_INSTANCE_FUNCTION
|
#undef MLX_VULKAN_INSTANCE_FUNCTION
|
||||||
#undef MLX_VULKAN_DEVICE_FUNCTION
|
#undef MLX_VULKAN_DEVICE_FUNCTION
|
||||||
|
|
||||||
|
~RenderCore();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RenderCore();
|
|
||||||
void LoadKVFGlobalVulkanFunctionPointers() const noexcept;
|
void LoadKVFGlobalVulkanFunctionPointers() const noexcept;
|
||||||
void LoadKVFInstanceVulkanFunctionPointers() const noexcept;
|
void LoadKVFInstanceVulkanFunctionPointers() const noexcept;
|
||||||
void LoadKVFDeviceVulkanFunctionPointers() const noexcept;
|
void LoadKVFDeviceVulkanFunctionPointers() const noexcept;
|
||||||
~RenderCore();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static RenderCore* s_instance;
|
static RenderCore* s_instance;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
Application::Application() : m_render_core(), m_fps(), m_in()
|
Application::Application() : m_fps(), m_in()
|
||||||
{
|
{
|
||||||
EventBus::RegisterListener({[](const EventBase& event)
|
EventBus::RegisterListener({[](const EventBase& event)
|
||||||
{
|
{
|
||||||
@@ -18,6 +18,7 @@ namespace mlx
|
|||||||
|
|
||||||
m_fps.Init();
|
m_fps.Init();
|
||||||
SDLManager::Get().Init();
|
SDLManager::Get().Init();
|
||||||
|
p_render_core = std::make_unique<RenderCore>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::Run() noexcept
|
void Application::Run() noexcept
|
||||||
@@ -87,6 +88,7 @@ namespace mlx
|
|||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
{
|
{
|
||||||
|
p_render_core.reset();
|
||||||
SDLManager::Get().Shutdown();
|
SDLManager::Get().Shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace mlx
|
|||||||
constexpr const std::uint32_t amask = 0xff000000;
|
constexpr const std::uint32_t amask = 0xff000000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace details
|
namespace Internal
|
||||||
{
|
{
|
||||||
struct WindowInfos
|
struct WindowInfos
|
||||||
{
|
{
|
||||||
@@ -101,9 +101,9 @@ namespace mlx
|
|||||||
DebugLog("SDL Manager initialized");
|
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");
|
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));
|
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;
|
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");
|
Verify(m_windows_registry.find(window) != m_windows_registry.end(), "SDL : cannot destroy window; unknown window pointer");
|
||||||
|
|
||||||
details::WindowInfos* infos = static_cast<details::WindowInfos*>(window);
|
Internal::WindowInfos* infos = static_cast<Internal::WindowInfos*>(window);
|
||||||
if(infos->window != nullptr)
|
if(infos->window != nullptr)
|
||||||
SDL_DestroyWindow(infos->window);
|
SDL_DestroyWindow(infos->window);
|
||||||
if(infos->icon != nullptr)
|
if(infos->icon != nullptr)
|
||||||
@@ -134,7 +134,7 @@ namespace mlx
|
|||||||
VkSurfaceKHR SDLManager::CreateVulkanSurface(Handle window, VkInstance instance) const noexcept
|
VkSurfaceKHR SDLManager::CreateVulkanSurface(Handle window, VkInstance instance) const noexcept
|
||||||
{
|
{
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
if(!SDL_Vulkan_CreateSurface(static_cast<SDL_Window*>(window), instance, &surface))
|
if(!SDL_Vulkan_CreateSurface(static_cast<Internal::WindowInfos*>(window)->window, instance, &surface))
|
||||||
FatalError("SDL : could not create a Vulkan surface; %", SDL_GetError());
|
FatalError("SDL : could not create a Vulkan surface; %", SDL_GetError());
|
||||||
return surface;
|
return surface;
|
||||||
}
|
}
|
||||||
@@ -169,27 +169,27 @@ namespace mlx
|
|||||||
Vec2ui SDLManager::GetVulkanDrawableSize(Handle window) const noexcept
|
Vec2ui SDLManager::GetVulkanDrawableSize(Handle window) const noexcept
|
||||||
{
|
{
|
||||||
Vec2i extent;
|
Vec2i extent;
|
||||||
SDL_Vulkan_GetDrawableSize(static_cast<SDL_Window*>(window), &extent.x, &extent.y);
|
SDL_Vulkan_GetDrawableSize(static_cast<Internal::WindowInfos*>(window)->window, &extent.x, &extent.y);
|
||||||
return Vec2ui{ extent };
|
return Vec2ui{ extent };
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLManager::MoveMouseOnWindow(Handle window, int x, int y) const noexcept
|
void SDLManager::MoveMouseOnWindow(Handle window, int x, int y) const noexcept
|
||||||
{
|
{
|
||||||
SDL_WarpMouseInWindow(static_cast<SDL_Window*>(window), x, y);
|
SDL_WarpMouseInWindow(static_cast<Internal::WindowInfos*>(window)->window, x, y);
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLManager::GetScreenSizeWindowIsOn(Handle window, int* x, int* y) const noexcept
|
void SDLManager::GetScreenSizeWindowIsOn(Handle window, int* x, int* y) const noexcept
|
||||||
{
|
{
|
||||||
SDL_DisplayMode DM;
|
SDL_DisplayMode DM;
|
||||||
SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(static_cast<SDL_Window*>(window)), &DM);
|
SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(static_cast<Internal::WindowInfos*>(window)->window), &DM);
|
||||||
*x = DM.w;
|
*x = DM.w;
|
||||||
*y = DM.h;
|
*y = DM.h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLManager::SetWindowPosition(Handle window, int x, int y) const noexcept
|
void SDLManager::SetWindowPosition(Handle window, int x, int y) const noexcept
|
||||||
{
|
{
|
||||||
SDL_SetWindowPosition(static_cast<SDL_Window*>(window), x, y);
|
SDL_SetWindowPosition(static_cast<Internal::WindowInfos*>(window)->window, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t SDLManager::GetX() const noexcept
|
std::int32_t SDLManager::GetX() const noexcept
|
||||||
|
|||||||
@@ -27,19 +27,19 @@ namespace mlx
|
|||||||
|
|
||||||
void ErrorCallback(const char* message) noexcept
|
void ErrorCallback(const char* message) noexcept
|
||||||
{
|
{
|
||||||
FatalError(message, 0, "", "");
|
Logs::Report(LogType::FatalError, 0, "", "", message);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidationErrorCallback(const char* message) noexcept
|
void ValidationErrorCallback(const char* message) noexcept
|
||||||
{
|
{
|
||||||
Error(message, 0, "", "");
|
Logs::Report(LogType::Error, 0, "", "", message);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidationWarningCallback(const char* message) noexcept
|
void ValidationWarningCallback(const char* message) noexcept
|
||||||
{
|
{
|
||||||
Warning(message, 0, "", "");
|
Logs::Report(LogType::Warning, 0, "", "", message);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user