removing GLFW support

This commit is contained in:
Kbz-8
2024-05-25 16:47:28 +02:00
parent edb44070a9
commit 37e9410d12
17 changed files with 153 additions and 260 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2024/04/23 15:06:26 by maldavid ### ########.fr */
/* Updated: 2024/05/25 16:06:57 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,7 @@
#include <Renderer/Core/RenderCore.h>
#include <Core/Memory.h>
#include <Core/EventBus.h>
#include <Core/SDLManager.h>
namespace mlx
{
@@ -29,6 +30,7 @@ namespace mlx
}, "__internal_application" });
m_fps.init();
SDLManager::Get().Init();
}
void Application::Run() noexcept
@@ -111,5 +113,6 @@ namespace mlx
{
TextLibrary::Get().ClearLibrary();
FontLibrary::Get().ClearLibrary();
SDLManager::Get().Shutdown();
}
}

94
runtime/Sources/Core/SDLManager.cpp git.filemode.normal_file
View File

@@ -0,0 +1,94 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* SDLManager.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/25 15:44:03 by maldavid #+# #+# */
/* Updated: 2024/05/25 16:46:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <PreCompiled.h>
#include <Core/SDLManager.h>
#include <Core/Memory.h>
#include <Utils/IconMlx.h>
namespace mlx
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
constexpr const std::uint32_t rmask = 0xff000000;
constexpr const std::uint32_t gmask = 0x00ff0000;
constexpr const std::uint32_t bmask = 0x0000ff00;
constexpr const std::uint32_t amask = 0x000000ff;
#else
constexpr const std::uint32_t rmask = 0x000000ff;
constexpr const std::uint32_t gmask = 0x0000ff00;
constexpr const std::uint32_t bmask = 0x00ff0000;
constexpr const std::uint32_t amask = 0xff000000;
#endif
namespace details
{
struct WindowInfos
{
SDL_Window* window;
SDL_Surface* icon;
};
}
void SDLManager::Init() noexcept
{
MLX_PROFILE_FUNCTION();
m_drop_sdl_responsability = SDL_WasInit(SDL_INIT_VIDEO);
if(m_drop_sdl_responsability) // is case the mlx is running in a sandbox like MacroUnitTester where SDL is already init
return;
SDL_SetMemoryFunctions(MemManager::malloc, MemManager::calloc, MemManager::realloc, MemManager::free);
#ifdef FORCE_WAYLAND
SDL_SetHint(SDL_HINT_VIDEODRIVER, "wayland,x11");
#endif
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
FatalError("SDL : unable to init all subsystems; %", SDL_GetError());
}
void* SDLManager::CreateWindow(const std::string& title, std::size_t w, std::size_t h)
{
details::WindowInfos* infos = new details::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 | SDL_WINDOW_SHOWN);
if(!infos->window)
FatalError("SDL : unable to open a new window; %", SDL_GetError());
infos->icon = SDL_CreateRGBSurfaceFrom(static_cast<void*>(logo_mlx), logo_mlx_width, logo_mlx_height, 32, 4 * logo_mlx_width, rmask, gmask, bmask, amask);
SDL_SetWindowIcon(infos->window, infos->icon);
m_windows_registry.insert(infos);
return infos;
}
void SDLManager::DestroyWindow(void* window) noexcept
{
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);
if(infos->window != nullptr)
SDL_DestroyWindow(infos->window);
if(infos->icon != nullptr)
SDL_FreeSurface(infos->icon);
m_windows_registry.erase(infos);
delete infos;
}
void SDLManager::Shutdown() noexcept
{
if(m_drop_sdl_responsability)
return;
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);
SDL_Quit();
}
}

View File

@@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* GLFWInputs.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 18:39:32 by maldavid #+# #+# */
/* Updated: 2024/03/27 18:42:18 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <PreCompiled.h>
#include <Drivers/GLFW/GLFWInputs.h>
namespace mlx
{
void GLFWInputs::Update() noexcept
{
glfwPollEvents();
}
}

View File

@@ -1,40 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* window.cpp :+: :+: :+: */
/* Window.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
/* Updated: 2024/03/26 23:03:59 by maldavid ### ########.fr */
/* Updated: 2024/05/25 16:13:31 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <pre_compiled.h>
#include <PreCompiled.h>
#include <platform/window.h>
#include <core/errors.h>
#include <utils/icon_mlx.h>
#include <Core/SDLManager.h>
#include <Platform/Window.h>
namespace mlx
{
Window::Window(std::size_t w, std::size_t h, const std::string& title) : _width(w), _height(h)
Window::Window(std::size_t w, std::size_t h, const std::string& title) : m_width(w), m_height(h)
{
static std::uint64_t ids = 0;
if(title.find("vvaas") != std::string::npos)
core::error::report(e_kind::message, "vvaas est mauvais");
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
_win = glfwCreateWindow(_width, _height, title.c_str(), NULL, NULL);;
_id = ids++;
Message("vvaas est mauvais");
p_window = SDLManager::Get().CreateWindow(title, w, h);
m_id = ids++;
}
void Window::destroy() noexcept
void Window::Destroy() noexcept
{
if(_win != nullptr)
if(p_window != nullptr)
{
glfwDestroyWindow(_win);
_win = nullptr;
SDLManager::Get().DestroyWindow(p_window);
p_window = nullptr;
}
}
}