mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
removing GLFW support
This commit is contained in:
9
Makefile
9
Makefile
@@ -6,7 +6,7 @@
|
|||||||
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
|
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
|
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
|
||||||
# Updated: 2024/03/27 21:30:44 by maldavid ### ########.fr #
|
# Updated: 2024/05/25 16:08:57 by maldavid ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
@@ -16,7 +16,6 @@ SRCS = $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Core))
|
|||||||
SRCS += $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Platform))
|
SRCS += $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Platform))
|
||||||
SRCS += $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Renderer))
|
SRCS += $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Renderer))
|
||||||
SRCS += $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Renderer/**))
|
SRCS += $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Renderer/**))
|
||||||
SRCS += $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Drivers/**))
|
|
||||||
|
|
||||||
OBJ_DIR = objs/makefile
|
OBJ_DIR = objs/makefile
|
||||||
OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
|
OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
|
||||||
@@ -31,7 +30,7 @@ IMAGES_OPTIMIZED ?= true
|
|||||||
FORCE_INTEGRATED_GPU ?= false
|
FORCE_INTEGRATED_GPU ?= false
|
||||||
GRAPHICS_MEMORY_DUMP ?= false
|
GRAPHICS_MEMORY_DUMP ?= false
|
||||||
PROFILER ?= false
|
PROFILER ?= false
|
||||||
LEGACY ?= false
|
FORCE_WAYLAND ?= false
|
||||||
|
|
||||||
MODE = "release"
|
MODE = "release"
|
||||||
|
|
||||||
@@ -73,8 +72,8 @@ ifeq ($(PROFILER), true)
|
|||||||
CXXFLAGS += -D PROFILER
|
CXXFLAGS += -D PROFILER
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(LEGACY), true)
|
ifeq ($(FORCE_WAYLAND), true)
|
||||||
CXXFLAGS += -D LEGACY
|
CXXFLAGS += -D FORCE_WAYLAND
|
||||||
endif
|
endif
|
||||||
|
|
||||||
RM = rm -rf
|
RM = rm -rf
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/04/21 20:39:33 by maldavid ### ########.fr */
|
/* Updated: 2024/05/25 15:26:36 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
#include <Core/Graphics.h>
|
#include <Core/Graphics.h>
|
||||||
#include <Platform/Inputs.h>
|
#include <Platform/Inputs.h>
|
||||||
#include <Core/DriverLoader.h>
|
|
||||||
#include <Core/ImagesRegistry.h>
|
#include <Core/ImagesRegistry.h>
|
||||||
#include <Core/Fps.h>
|
#include <Core/Fps.h>
|
||||||
|
|
||||||
@@ -61,7 +60,6 @@ namespace mlx
|
|||||||
private:
|
private:
|
||||||
FpsManager m_fps;
|
FpsManager m_fps;
|
||||||
Input m_in;
|
Input m_in;
|
||||||
DriverLoader m_driver_loader;
|
|
||||||
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(void*)> f_loop_hook;
|
std::function<int(void*)> f_loop_hook;
|
||||||
@@ -69,6 +67,6 @@ namespace mlx
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <core/application.inl>
|
#include <Core/Application.inl>
|
||||||
|
|
||||||
#endif // __MLX_APPLICATION__
|
#endif // __MLX_APPLICATION__
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
/* **************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* DriverLoader.inl :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/04/03 14:55:01 by maldavid #+# #+# */
|
|
||||||
/* Updated: 2024/04/03 14:55:01 by maldavid ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* **************************************************************************** */
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
#include <Core/DriverLoader.h>
|
|
||||||
|
|
||||||
namespace mlx
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
bool DriverLoader::LoadDriver()
|
|
||||||
{
|
|
||||||
m_instances.emplace_back(new T)->InitDriver();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DriverLoader::ShutdownAllDrivers()
|
|
||||||
{
|
|
||||||
for(auto& driver : m_instances)
|
|
||||||
driver->ShutdownDriver();
|
|
||||||
m_instances.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
|
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/04/23 14:02:48 by maldavid ### ########.fr */
|
/* Updated: 2024/05/25 01:00:10 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -70,6 +70,6 @@ namespace mlx
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <core/graphics.inl>
|
#include <Core/Graphics.inl>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,39 +1,41 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* DriverLoader.h :+: :+: :+: */
|
/* SDLManager.h :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/04/02 16:56:10 by maldavid #+# #+# */
|
/* Created: 2024/05/25 15:28:59 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/04/03 15:02:44 by maldavid ### ########.fr */
|
/* Updated: 2024/05/25 16:11:50 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef __MLX_CORE_DRIVER_LOADER__
|
#ifndef __MLX_SDL_MANAGER__
|
||||||
#define __MLX_CORE_DRIVER_LOADER__
|
#define __MLX_SDL_MANAGER__
|
||||||
|
|
||||||
#include <Drivers/DriverInstance.h>
|
#include <Utils/Singleton.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
class DriverLoader
|
class SDLManager : public Singleton<SDLManager>
|
||||||
{
|
{
|
||||||
|
friend class Singleton<SDLManager>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DriverLoader() = default;
|
void Init() noexcept;
|
||||||
|
void Shutdown() noexcept;
|
||||||
|
|
||||||
template <typename T>
|
void* CreateWindow(const std::string& title, std::size_t w, std::size_t h);
|
||||||
inline bool LoadDriver();
|
void DestroyWindow(void* window) noexcept;
|
||||||
|
|
||||||
inline void ShutdownAllDrivers();
|
|
||||||
|
|
||||||
~DriverLoader() = default;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::unique_ptr<DriverInstance> > m_instances;
|
SDLManager() = default;
|
||||||
|
~SDLManager() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unordered_set<void*> m_windows_registry;
|
||||||
|
bool m_drop_sdl_responsability = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <Core/DriverLoader.inl>
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* DriverInstance.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/04/02 16:57:20 by maldavid #+# #+# */
|
|
||||||
/* Updated: 2024/04/02 17:01:03 by maldavid ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef __MLX_DRIVER_INSTANCE__
|
|
||||||
#define __MLX_DRIVER_INSTANCE__
|
|
||||||
|
|
||||||
namespace mlx
|
|
||||||
{
|
|
||||||
class DriverInstance
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DriverInstance() = default;
|
|
||||||
|
|
||||||
virtual bool InitDriver() { m_is_up = true; return true; }
|
|
||||||
virtual void ShutdownDriver() { m_is_up = false; }
|
|
||||||
|
|
||||||
inline bool IsRunning() const noexcept { return m_is_up; }
|
|
||||||
|
|
||||||
virtual ~DriverInstance() = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_is_up = false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* GLFWDriverInstance.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/04/02 17:01:51 by maldavid #+# #+# */
|
|
||||||
/* Updated: 2024/04/02 17:04:12 by maldavid ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef __MLX_GLFW_DRIVER_INSTANCE__
|
|
||||||
#define __MLX_GLFW_DRIVER_INSTANCE__
|
|
||||||
|
|
||||||
#include <Drivers/DriverInstance.h>
|
|
||||||
|
|
||||||
namespace mlx
|
|
||||||
{
|
|
||||||
class GLFWDriverInstance : public DriverInstance
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GLFWDriverInstance() = default;
|
|
||||||
|
|
||||||
inline bool InitDriver() override;
|
|
||||||
inline void ShutdownDriver() override;
|
|
||||||
|
|
||||||
~GLFWDriverInstance() override = default;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#include <Drivers/GLFW/GLFWDriverInstance.inl>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
/* **************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* GLFWDriverInstance.inl :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/04/02 17:04:23 by maldavid #+# #+# */
|
|
||||||
/* Updated: 2024/04/02 17:04:23 by maldavid ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* **************************************************************************** */
|
|
||||||
|
|
||||||
#include <Drivers/GLFW/GLFWDriverInstance.h>
|
|
||||||
|
|
||||||
namespace mlx
|
|
||||||
{
|
|
||||||
bool GLFWDriverInstance::InitDriver()
|
|
||||||
{
|
|
||||||
glfwSetErrorCallback([]([[maybe_unused]] int code, const char* desc)
|
|
||||||
{
|
|
||||||
FatalError("GLFW Driver Error : %", desc);
|
|
||||||
});
|
|
||||||
glfwInit();
|
|
||||||
DebugLog("GLFW Driver loaded");
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLFWDriverInstance::ShutdownDriver()
|
|
||||||
{
|
|
||||||
glfwTerminate();
|
|
||||||
DebugLog("GLFW Driver shutted down");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* GLFWInputs.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2024/03/27 18:32:29 by maldavid #+# #+# */
|
|
||||||
/* Updated: 2024/03/27 18:37:58 by maldavid ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef __MLX_GLFW_INPUTS__
|
|
||||||
#define __MLX_GLFW_INPUTS__
|
|
||||||
|
|
||||||
#include <Platform/Inputs.h>
|
|
||||||
|
|
||||||
namespace mlx
|
|
||||||
{
|
|
||||||
class GLFWInputs : public Inputs
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
GLFWInputs() = default;
|
|
||||||
|
|
||||||
void Update() override noexcept;
|
|
||||||
|
|
||||||
void RegisterWindow(std::shared_ptr<Window> window) override;
|
|
||||||
|
|
||||||
inline std::int32_t GetX() override const noexcept { return m_x; }
|
|
||||||
inline std::int32_t GetY() override const noexcept { return m_y; }
|
|
||||||
inline std::int32_t GetXRel() override const noexcept { return m_x_rel; }
|
|
||||||
inline std::int32_t GetYRel() override const noexcept { return m_y_rel; }
|
|
||||||
|
|
||||||
~GLFWInputs() override = default;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::int32_t m_x = 0;
|
|
||||||
std::int32_t m_y = 0;
|
|
||||||
std::int32_t m_x_rel = 0;
|
|
||||||
std::int32_t m_y_rel = 0;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
|
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/03/27 21:58:18 by maldavid ### ########.fr */
|
/* Updated: 2024/05/25 16:11:00 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,18 +15,12 @@
|
|||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
#ifdef LEGACY
|
|
||||||
using WindowHandle = SDL_Window;
|
|
||||||
#else
|
|
||||||
using WindowHandle = GLFWwindow;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class Window
|
class Window
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Window(std::size_t w, std::size_t h, const std::string& title);
|
Window(std::size_t w, std::size_t h, const std::string& title);
|
||||||
|
|
||||||
inline NonOwningPtr<WindowHandle> GetWindowHandle() const noexcept = 0;
|
inline void* GetWindowHandle() const noexcept { return p_window; }
|
||||||
inline int GetWidth() const noexcept { return m_width; }
|
inline int GetWidth() const noexcept { return m_width; }
|
||||||
inline int GetHeight() const noexcept { return m_height; }
|
inline int GetHeight() const noexcept { return m_height; }
|
||||||
inline std::uint32_t GetID() const noexcept { return m_id; }
|
inline std::uint32_t GetID() const noexcept { return m_id; }
|
||||||
@@ -36,6 +30,7 @@ namespace mlx
|
|||||||
~Window() = default;
|
~Window() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void* p_window = nullptr;
|
||||||
std::uint32_t m_id = -1;
|
std::uint32_t m_id = -1;
|
||||||
int m_width = 0;
|
int m_width = 0;
|
||||||
int m_height = 0;
|
int m_height = 0;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/25 17:37:23 by maldavid #+# #+# */
|
/* Created: 2024/03/25 17:37:23 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/04/23 13:49:52 by maldavid ### ########.fr */
|
/* Updated: 2024/05/25 15:46:37 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -23,12 +23,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <volk.h>
|
#include <volk.h>
|
||||||
|
|
||||||
#ifdef MLX_LEGACY
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_vulkan.h>
|
#include <SDL2/SDL_vulkan.h>
|
||||||
#else
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
/* 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 <Renderer/Core/RenderCore.h>
|
||||||
#include <Core/Memory.h>
|
#include <Core/Memory.h>
|
||||||
#include <Core/EventBus.h>
|
#include <Core/EventBus.h>
|
||||||
|
#include <Core/SDLManager.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
@@ -29,6 +30,7 @@ namespace mlx
|
|||||||
}, "__internal_application" });
|
}, "__internal_application" });
|
||||||
|
|
||||||
m_fps.init();
|
m_fps.init();
|
||||||
|
SDLManager::Get().Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::Run() noexcept
|
void Application::Run() noexcept
|
||||||
@@ -111,5 +113,6 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
TextLibrary::Get().ClearLibrary();
|
TextLibrary::Get().ClearLibrary();
|
||||||
FontLibrary::Get().ClearLibrary();
|
FontLibrary::Get().ClearLibrary();
|
||||||
|
SDLManager::Get().Shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
94
runtime/Sources/Core/SDLManager.cpp
git.filemode.normal_file
94
runtime/Sources/Core/SDLManager.cpp
git.filemode.normal_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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +1,38 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* window.cpp :+: :+: :+: */
|
/* Window.cpp :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
|
/* 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/SDLManager.h>
|
||||||
#include <core/errors.h>
|
#include <Platform/Window.h>
|
||||||
#include <utils/icon_mlx.h>
|
|
||||||
|
|
||||||
namespace mlx
|
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;
|
static std::uint64_t ids = 0;
|
||||||
|
|
||||||
if(title.find("vvaas") != std::string::npos)
|
if(title.find("vvaas") != std::string::npos)
|
||||||
core::error::report(e_kind::message, "vvaas est mauvais");
|
Message("vvaas est mauvais");
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
p_window = SDLManager::Get().CreateWindow(title, w, h);
|
||||||
_win = glfwCreateWindow(_width, _height, title.c_str(), NULL, NULL);;
|
m_id = ids++;
|
||||||
_id = ids++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::destroy() noexcept
|
void Window::Destroy() noexcept
|
||||||
{
|
{
|
||||||
if(_win != nullptr)
|
if(p_window != nullptr)
|
||||||
{
|
{
|
||||||
glfwDestroyWindow(_win);
|
SDLManager::Get().DestroyWindow(p_window);
|
||||||
_win = nullptr;
|
p_window = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user