begenning the refactor

This commit is contained in:
2024-03-27 23:03:54 +01:00
parent e5ff232065
commit 6bbf1e196d
131 changed files with 2135 additions and 1192 deletions

View File

@@ -6,22 +6,23 @@
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
# Updated: 2024/03/25 18:57:44 by maldavid ### ########.fr #
# Updated: 2024/03/27 21:30:44 by maldavid ### ########.fr #
# #
# **************************************************************************** #
NAME = libmlx.so
SRCS = $(wildcard $(addsuffix /*.cpp, ./src/core))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/platform))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer))
SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer/**))
SRCS = $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Core))
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/Drivers/**))
OBJ_DIR = objs/makefile
OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
PCH = ./src/pre_compiled.h
GCH = ./src/pre_compiled.h.gch
PCH = ./runtime/Includes/PreCompiled.h
GCH = ./runtime/Includes/PreCompiled.h.gch
OS = $(shell uname -s)
DEBUG ?= false
@@ -30,13 +31,14 @@ IMAGES_OPTIMIZED ?= true
FORCE_INTEGRATED_GPU ?= false
GRAPHICS_MEMORY_DUMP ?= false
PROFILER ?= false
LEGACY ?= false
MODE = "release"
CXX = clang++
CXXFLAGS = -std=c++17 -O3 -fPIC -Wall -Wextra -Wno-deprecated -DSDL_MAIN_HANDLED
INCLUDES = -I./includes -I./src -I./third_party
INCLUDES = -I./includes -I./runtime/Includes -I./third_party
LDLIBS =
@@ -71,6 +73,10 @@ ifeq ($(PROFILER), true)
CXXFLAGS += -D PROFILER
endif
ifeq ($(LEGACY), true)
CXXFLAGS += -D LEGACY
endif
RM = rm -rf
$(OBJ_DIR)/%.o: %.cpp $(GCH)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/10 08:49:17 by maldavid #+# #+# */
/* Updated: 2024/01/03 15:33:35 by maldavid ### ########.fr */
/* Updated: 2024/03/27 18:25:59 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -138,6 +138,16 @@
#endif
#endif
#if !defined(MLX_FORCEINLINE)
#if defined(MLX_COMPILER_CLANG) || defined(MLX_COMPILER_GCC)
#define MLX_FORCEINLINE __attribute__((always_inline)) inline
#elif defined(MLX_COMPILER_MSVC)
#define MLX_FORCEINLINE __forceinline
#else
#define MLX_FORCEINLINE inline
#endif
#endif
// Checking common assumptions
#ifdef __cplusplus
#include <climits>

71
runtime/Includes/Core/Application.h git.filemode.normal_file
View File

@@ -0,0 +1,71 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Application.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2024/03/27 21:00:53 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_APPLICATION__
#define __MLX_APPLICATION__
#include <Core/Graphics.h>
#include <Platform/Inputs.h>
#include <Core/Fps.h>
namespace mlx
{
class Application
{
public:
Application();
inline void GetMousePos(int* x, int* y) noexcept;
inline void MouseMove(void* win, int x, int y) noexcept;
inline void OnEvent(void* win, int event, int (*funct_ptr)(int, void*), void* param) noexcept;
inline void GetScreenSize(void* win, int* w, int* h) noexcept;
inline void SetFPSCap(std::uint32_t fps) noexcept;
inline void* NewGraphicsSuport(std::size_t w, std::size_t h, const char* title);
inline void ClearGraphicsSupport(void* win);
inline void DestroyGraphicsSupport(void* win);
inline void PixelPut(void* win, int x, int y, std::uint32_t color) const noexcept;
inline void StringPut(void* win, int x, int y, std::uint32_t color, char* str);
void* NewTexture(int w, int h);
void* NewStbTexture(char* file, int* w, int* h); // stb textures are image files (png, jpg, bpm, ...)
inline void TexturePut(void* win, void* img, int x, int y);
inline int GetTexturePixel(void* img, int x, int y);
inline void SetTexturePixel(void* img, int x, int y, std::uint32_t color);
void DestroyTexture(void* ptr);
inline void LoopHook(int (*f)(void*), void* param);
inline void LoopEnd() noexcept;
inline void LoadFont(void* win, const std::filesystem::path& filepath, float scale);
void Run() noexcept;
~Application();
private:
FpsManager m_fps;
std::list<Texture> m_textures;
std::vector<std::unique_ptr<GraphicsSupport>> m_graphics;
std::function<int(void*)> f_loop_hook;
std::unique_ptr<Input> p_in;
void* p_param = nullptr;
};
}
#include <core/application.inl>
#endif // __MLX_APPLICATION__

196
runtime/Includes/Core/Application.inl git.filemode.normal_file
View File

@@ -0,0 +1,196 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* application.inl :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2023/04/02 14:56:27 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <Core/Application.h>
#define CHECK_WINDOW_PTR(win) \
if(win == nullptr) \
{ \
Error("invalid window ptr (NULL)"); \
return; \
} \
else if(*static_cast<int*>(win) < 0 || *static_cast<int*>(win) > static_cast<int>(_graphics.size()))\
{ \
Error("invalid window ptr"); \
return; \
} else {}
#define CHECK_IMAGE_PTR(img, retval) \
if(img == nullptr) \
{ \
Error("invalid image ptr (NULL)"); \
retval; \
} \
else if(std::find_if(_textures.begin(), _textures.end(), [=](const Texture& texture) \
{ \
return &texture == img; \
}) == _textures.end()) \
{ \
Error(e_kind::error, "invalid image ptr"); \
retval; \
} else {}
namespace mlx
{
void Application::GetMousePos(int* x, int* y) noexcept
{
*x = p_in->GetX();
*y = p_in->GetY();
}
void Application::MouseMove(void* win, int x, int y) noexcept
{
CHECK_WINDOW_PTR(win);
if(!m_graphics[*static_cast<int*>(win)]->HasWindow())
{
Warning("trying to move the mouse relative to a window that is targeting an image and not a real window, this is not allowed (move ignored)");
return;
}
}
void Application::OnEvent(void* win, int event, int (*funct_ptr)(int, void*), void* param) noexcept
{
CHECK_WINDOW_PTR(win);
if(!m_graphics[*static_cast<int*>(win)]->HasWindow())
{
Warning("trying to add event hook for a window that is targeting an image and not a real window, this is not allowed (hook ignored)");
return;
}
p_in->OnEvent(m_graphics[*static_cast<int*>(win)]->GetWindow()->GetID(), event, funct_ptr, param);
}
void Application::GetScreenSize(void* win, int* w, int* h) noexcept
{
CHECK_WINDOW_PTR(win);
*w = 0;
*h = 0;
}
void Application::SetFPSCap(std::uint32_t fps) noexcept
{
m_fps.SetMaxFPS(fps);
}
void* Application::NewGraphicsSuport(std::size_t w, std::size_t h, const char* title)
{
MLX_PROFILE_FUNCTION();
auto it = std::find_if(m_textures.begin(), m_textures.end(), [=](const Texture& texture)
{
return &texture == reinterpret_cast<Texture*>(const_cast<char*>(title));
});
if(it != _textures.end())
m_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, reinterpret_cast<Texture*>(const_cast<char*>(title)), m_graphics.size()));
else
{
if(title == NULL)
{
FatalError("invalid window title (NULL)");
return nullptr;
}
m_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, m_graphics.size()));
p_in->RegisterWindow(m_graphics.back()->GetWindow());
}
return static_cast<void*>(&m_graphics.back()->GetID());
}
void Application::ClearGraphicsSupport(void* win)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
m_graphics[*static_cast<int*>(win)]->ClearRenderData();
}
void Application::DestroyGraphicsSupport(void* win)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
m_graphics[*static_cast<int*>(win)].reset();
}
void Application::PixelPut(void* win, int x, int y, std::uint32_t color) const noexcept
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
m_graphics[*static_cast<int*>(win)]->PixelPut(x, y, color);
}
void Application::StringPut(void* win, int x, int y, std::uint32_t color, char* str)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
if(str == nullptr)
{
Error("wrong text (NULL)");
return;
}
if(std::strlen(str) == 0)
{
Warning("trying to put an empty text");
return;
}
m_graphics[*static_cast<int*>(win)]->StringPut(x, y, color, str);
}
void Application::LoadFont(void* win, const std::filesystem::path& filepath, float scale)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
m_graphics[*static_cast<int*>(win)]->LoadFont(filepath, scale);
}
void Application::TexturePut(void* win, void* img, int x, int y)
{
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
CHECK_IMAGE_PTR(img, return);
NonOwningPtr<Texture> texture = static_cast<Texture*>(img);
if(!texture->IsInit())
Error("trying to put a texture that has been destroyed");
else
m_graphics[*static_cast<int*>(win)]->TexturePut(texture, x, y);
}
int Application::GetTexturePixel(void* img, int x, int y)
{
MLX_PROFILE_FUNCTION();
CHECK_IMAGE_PTR(img, return 0);
NonOwningPtr<Texture> texture = static_cast<Texture*>(img);
if(!texture->IsInit())
{
Error("trying to get a pixel from texture that has been destroyed");
return 0;
}
return texture->GetPixel(x, y);
}
void Application::setTexturePixel(void* img, int x, int y, std::uint32_t color)
{
MLX_PROFILE_FUNCTION();
CHECK_IMAGE_PTR(img, return);
NonOwningPtr<Texture> texture = static_cast<Texture*>(img);
if(!texture->IsInit())
Error("trying to set a pixel on texture that has been destroyed");
else
texture->SetPixel(x, y, color);
}
void Application::LoopHook(int (*f)(void*), void* param)
{
f_loop_hook = f;
p_param = param;
}
void Application::LoopEnd() noexcept
{
p_in->Finish();
}
}

33
runtime/Includes/Core/Enums.h git.filemode.normal_file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Enums.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:15:24 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:16:03 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_CORE_ENUMS__
#define __MLX_CORE_ENUMS__
#include <cstddef>
namespace mlx
{
enum class LogType
{
Message = 0,
Warning,
Error,
FatalError,
EndEnum
};
constexpr std::size_t LogTypeCount = static_cast<std::size_t>(LogType::EndEnum) + 1;
}
#endif

View File

@@ -1,29 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* errors.h :+: :+: :+: */
/* EventBase.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:42:32 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:13:19 by maldavid ### ########.fr */
/* Created: 2024/03/27 17:27:22 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:31:16 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_ERRORS__
#define __MLX_ERRORS__
#ifndef __MLX_BASE_EVENT__
#define __MLX_BASE_EVENT__
enum class e_kind
namespace mlx
{
message,
warning,
error,
fatal_error
};
namespace mlx::core::error
{
void report(e_kind kind, std::string msg, ...);
struct EventBase
{
virtual std::uint32_t What() const = 0;
};
}
#endif // __MLX_ERRORS__
#endif

35
runtime/Includes/Core/EventBus.h git.filemode.normal_file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* EventBus.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:30:36 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:31:41 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_EVENT_BUS__
#define __MLX_EVENT_BUS__
#include <Core/EventBase.h>
#include <Core/EventListener.h>
namespace mlx
{
class EventBus
{
public:
EventBus() = delete;
static void Send(const std::string& listener_name, const EventBase& event);
static void SendBroadcast(const EventBase& event);
inline static void RegisterListener(const EventListener& listener) { s_listeners.push_back(listener); }
~EventBus() = delete;
private:
inline static std::vector<EventListener> s_listeners;
};
}
#endif

37
runtime/Includes/Core/EventListener.h git.filemode.normal_file
View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* EventListener.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:28:17 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:37:53 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_EVENT_LISTENER__
#define __MLX_EVENT_LISTENER__
#include <Core/EventBase.h>
namespace mlx
{
class EventListener
{
public:
EventListener() = delete;
EventListener(func::function<void(const EventBase&)> functor, std::string name);
inline const std::string& GetName() const { return m_name; }
inline void Call(const EventBase& event) const noexcept { m_listen_functor(event); }
~EventListener() = default;
private:
func::function<void(const EventBase&)> m_listen_functor;
std::string m_name;
};
}
#endif

33
runtime/Includes/Core/Format.h git.filemode.normal_file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Format.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:11:09 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:12:03 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_FORMAT__
#define __MLX_FORMAT__
#include <type_traits>
#include <string_view>
namespace mlx
{
template<typename T, typename = void>
struct IsOstreamable : std::false_type {};
template<typename T>
struct IsOstreamable<T, std::void_t<decltype(std::declval<std::ostream>() << std::declval<T>())>> : std::true_type {};
template<typename... Args, std::enable_if_t<std::conjunction_v<IsOstreamable<Args>...>, int> = 0>
auto Format(std::string_view format, const Args&... args);
}
#include <Core/Format.inl>
#endif

146
runtime/Includes/Core/Format.inl git.filemode.normal_file
View File

@@ -0,0 +1,146 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Format.inl :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:11:09 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:12:03 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <Core/Format.h>
#include <sstream>
#include <ostream>
namespace mlx
{
namespace Internal
{
template<typename It>
void Format(std::stringstream& ss, It first, It last)
{
for(auto it = first; it != last; ++it)
{
switch(*it)
{
case '%':
throw std::invalid_argument{"too few arguments"};
case '/':
++it;
if(it == last)
throw std::invalid_argument{"stray '/'"};
[[fallthrough]];
default: ss << *it;
}
}
}
template<typename It, typename T, typename... Args>
void Format(std::stringstream& ss, It first, It last, const T& arg, const Args&... args)
{
for(auto it = first; it != last; ++it)
{
switch(*it)
{
case '%':
ss << arg;
return Format(ss, ++it, last, args...);
case '/':
++it;
if(it == last)
throw std::invalid_argument{"stray '/'"};
[[fallthrough]];
default: ss << *it;
}
}
throw std::invalid_argument{"too many arguments"};
}
template<typename It>
void Format(std::ostream& os, It first, It last)
{
for(auto it = first; it != last; ++it)
{
switch(*it)
{
case '%':
throw std::invalid_argument{"too few arguments"};
case '/':
++it;
if(it == last)
throw std::invalid_argument{"stray '/'"};
[[fallthrough]];
default: os << *it;
}
}
}
template<typename It, typename T, typename... Args>
void Format(std::ostream& os, It first, It last, const T& arg, const Args&... args)
{
for(auto it = first; it != last; ++it)
{
switch(*it)
{
case '%':
os << arg;
return Format(os, ++it, last, args...);
case '/':
++it;
if(it == last)
throw std::invalid_argument{"stray '/'"};
[[fallthrough]];
default: os << *it;
}
}
throw std::invalid_argument{"too many arguments"};
}
template<typename... Args>
struct Formatter
{
std::string_view format;
std::tuple<const Args&...> args;
};
template<typename... Args, std::size_t... Is>
void FormatHelper(std::stringstream& ss, const Formatter<Args...>& formatter, std::index_sequence<Is...>)
{
Format(ss, formatter.format.begin(), formatter.format.end(),
std::get<Is>(formatter.args)...);
}
template<typename... Args>
std::stringstream& operator<<(std::stringstream& ss, const Formatter<Args...>& printer)
{
FormatHelper(ss, printer, std::index_sequence_for<Args...>{});
return ss;
}
template<typename... Args, std::size_t... Is>
void FormatHelper(std::ostream& os, const Formatter<Args...>& formatter, std::index_sequence<Is...>)
{
Format(os, formatter.format.begin(), formatter.format.end(),
std::get<Is>(formatter.args)...);
}
template<typename... Args>
std::ostream& operator<<(std::ostream& os, const Formatter<Args...>& printer)
{
FormatHelper(os, printer, std::index_sequence_for<Args...>{});
return os;
}
}
template<typename... Args, std::enable_if_t<std::conjunction_v<IsOstreamable<Args>...>, int>>
auto Format(std::string_view format, const Args&... args)
{
return Internal::Formatter<Args...>{format, std::forward_as_tuple(args...)};
}
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fps.h :+: :+: :+: */
/* Fps.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 14:53:30 by maldavid #+# #+# */
/* Updated: 2024/03/25 22:58:32 by maldavid ### ########.fr */
/* Updated: 2024/03/27 20:52:06 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,19 +20,19 @@ namespace mlx
public:
FpsManager() = default;
void init();
bool update();
inline void setMaxFPS(std::uint32_t fps) noexcept { _max_fps = fps; _ns = 1000000000.0 / fps; }
void Init();
bool Update();
inline void SetMaxFPS(std::uint32_t fps) noexcept { m_max_fps = fps; m_ns = 1000000000.0 / fps; }
~FpsManager() = default;
private:
double _ns = 1000000000.0 / 1'337'000.0;
std::int64_t _fps_before = 0;
std::int64_t _fps_now = 0;
std::int64_t _timer = 0;
std::uint32_t _max_fps = 1'337'000;
std::uint32_t _fps_elapsed_time = 0;
double m_ns = 1000000000.0 / 1'337'000.0;
std::int64_t m_fps_before = 0;
std::int64_t m_fps_now = 0;
std::int64_t m_timer = 0;
std::uint32_t m_max_fps = 1'337'000;
std::uint32_t m_fps_elapsed_time = 0;
};
}

75
runtime/Includes/Core/Graphics.h git.filemode.normal_file
View File

@@ -0,0 +1,75 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Graphics.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
/* Updated: 2024/03/27 21:16:11 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_GRAPHICS__
#define __MLX_GRAPHICS__
#include <Platform/Window.h>
#include <Renderer/Renderer.h>
#include <Renderer/PixelPut.h>
#include <Renderer/Core/DrawableResource.h>
#include <Renderer/Images/TextureManager.h>
#include <Renderer/Texts/TextManager.h>
#include <Utils/NonCopyable.h>
#include <Renderer/Images/Texture.h>
namespace mlx
{
class GraphicsSupport : public NonCopyable
{
public:
GraphicsSupport(std::size_t w, std::size_t h, NonOwningPtr<Texture> render_target, int id);
GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id);
inline int& GetID() noexcept;
inline std::shared_ptr<Window> GetWindow();
void Render() noexcept;
inline void ClearRenderData() noexcept;
inline void PixelPut(int x, int y, std::uint32_t color) noexcept;
inline void StringPut(int x, int y, std::uint32_t color, std::string str);
inline void TexturePut(NonOwningPtr<class Texture> texture, int x, int y);
inline void LoadFont(const std::filesystem::path& filepath, float scale);
inline void TryEraseTextureFromManager(NonOwningPtr<Texture> texture) noexcept;
inline bool HasWindow() const noexcept { return _has_window; }
inline Renderer& GetRenderer() { return *_renderer; }
~GraphicsSupport();
private:
PixelPutPipeline m_pixel_put_pipeline;
std::vector<NonOwningPtr<DrawableResource>> m_drawlist;
TextManager m_text_manager;
TextureManager m_texture_manager;
glm::mat4 m_proj = glm::mat4(1.0);
std::shared_ptr<Window> p_window;
std::unique_ptr<Renderer> p_renderer;
std::size_t m_width = 0;
std::size_t m_height = 0;
int m_id;
bool m_has_window;
};
}
#include <core/graphics.inl>
#endif

79
runtime/Includes/Core/Graphics.inl git.filemode.normal_file
View File

@@ -0,0 +1,79 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* graphics.inl :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
/* Updated: 2023/04/02 15:26:16 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <Core/Graphics.h>
namespace mlx
{
int& GraphicsSupport::GetID() noexcept { return m_id; }
std::shared_ptr<Window> GraphicsSupport::GetWindow() { return p_window; }
void GraphicsSupport::ClearRenderData() noexcept
{
MLX_PROFILE_FUNCTION();
m_drawlist.clear();
m_pixel_put_pipeline.Clear();
m_text_manager.Clear();
m_texture_manager.Clear();
}
void GraphicsSupport::PixelPut(int x, int y, std::uint32_t color) noexcept
{
MLX_PROFILE_FUNCTION();
m_pixel_put_pipeline.SetPixel(x, y, color);
}
void GraphicsSupport::StringPut(int x, int y, std::uint32_t color, std::string str)
{
MLX_PROFILE_FUNCTION();
std::pair<NonOwningPtr<DrawableResource>, bool> res = m_text_manager.RegisterText(x, y, color, str);
if(!res.second) // if this is not a completly new text draw
{
auto it = std::find(m_drawlist.begin(), m_drawlist.end(), res.first);
if(it != m_drawlist.end())
m_drawlist.erase(it);
}
m_drawlist.push_back(res.first);
}
void GraphicsSupport::TexturePut(NonOwningPtr<Texture> texture, int x, int y)
{
MLX_PROFILE_FUNCTION();
auto res = m_texture_manager.RegisterTexture(texture, x, y);
if(!res.second) // if this is not a completly new texture draw
{
auto it = std::find(m_drawlist.begin(), m_drawlist.end(), res.first);
if(it != m_drawlist.end())
m_drawlist.erase(it);
}
m_drawlist.push_back(res.first);
}
void GraphicsSupport::LoadFont(const std::filesystem::path& filepath, float scale)
{
MLX_PROFILE_FUNCTION();
m_text_manager.LoadFont(*_renderer, filepath, scale);
}
void GraphicsSupport::TryEraseTextureFromManager(NonOwningPtr<Texture> texture) noexcept
{
MLX_PROFILE_FUNCTION();
for(auto it = m_drawlist.begin(); it != m_drawlist.end();)
{
if(m_texture_manager.IsTextureKnown(texture))
it = m_drawlist.erase(it);
else
++it;
}
m_texture_manager.EraseTextures(texture);
}
}

84
runtime/Includes/Core/Logs.h git.filemode.normal_file
View File

@@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Logs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:14:10 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:19:23 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_LOGS__
#define __MLX_LOGS__
#include <Core/Enums.h>
namespace mlx
{
template<typename... Args>
void DebugLog(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
template<typename... Args>
void Error(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
template<typename... Args>
void Warning(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
template<typename... Args>
void Message(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
template<typename... Args>
void FatalError(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
template<typename... Args>
void Verify(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
class Logs
{
public:
Logs() = delete;
static void Report(LogType type, std::string message);
static void Report(LogType type, unsigned int line, std::string_view file, std::string_view function, std::string message);
~Logs() = delete;
};
#if defined(DEBUG)
template<typename... Args>
void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
#else
template<typename... Args>
void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args) {}
#endif
}
#include <Core/Logs.inl>
namespace mlx
{
#undef DebugLog
#define DebugLog(...) DebugLog(__LINE__, __FILE__, AK_FUNC_SIG, __VA_ARGS__)
#undef Message
#define Message(...) Message(__LINE__, __FILE__, __func__, __VA_ARGS__)
#undef Warning
#define Warning(...) Warning(__LINE__, __FILE__, __func__, __VA_ARGS__)
#undef Error
#define Error(...) Error(__LINE__, __FILE__, __func__, __VA_ARGS__)
#undef FatalError
#define FatalError(...) FatalError(__LINE__, __FILE__, __func__, __VA_ARGS__)
#undef Verify
#define Verify(cond, ...) Verify(cond, __LINE__, __FILE__, __func__, __VA_ARGS__)
#undef Assert
#define Assert(cond, ...) Assert(cond, __LINE__, __FILE__, __func__, __VA_ARGS__)
}
#endif

135
runtime/Includes/Core/Logs.inl git.filemode.normal_file
View File

@@ -0,0 +1,135 @@
/* **************************************************************************** */
/* */
/* ::: :::::::: */
/* Logs.inl :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:19:47 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:19:47 by maldavid ### ########.fr */
/* */
/* **************************************************************************** */
#include <Core/Logs.h>
#include <Core/Format.h>
namespace mlx
{
template<typename... Args>
void DebugLog(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args)
{
using namespace std::literals;
try
{
std::stringstream ss;
ss << Format(message, args...);
Logs::Report(LogType::Debug, line, file, function, ss.str());
}
catch(const std::exception& e)
{
Logs::Report(LogType::Error, "formatter exception catched in the log printer : "s + e.what());
}
}
template<typename... Args>
void Error(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args)
{
using namespace std::literals;
try
{
std::stringstream ss;
ss << Format(message, args...);
Logs::Report(LogType::Error, line, file, function, ss.str());
}
catch(const std::exception& e)
{
Logs::Report(LogType::Error, "formatter exception catched in the log printer : "s + e.what());
}
}
template<typename... Args>
void Warning(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args)
{
using namespace std::literals;
try
{
std::stringstream ss;
ss << Format(message, args...);
Logs::Report(LogType::Warning, line, file, function, ss.str());
}
catch(const std::exception& e)
{
Logs::Report(LogType::Error, "formatter exception catched in the log printer : "s + e.what());
}
}
template<typename... Args>
void Message(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args)
{
using namespace std::literals;
try
{
std::stringstream ss;
ss << Format(message, args...);
Logs::Report(LogType::Message, line, file, function, ss.str());
}
catch(const std::exception& e)
{
Logs::Report(LogType::Error, "formatter exception catched in the log printer : "s + e.what());
}
}
template<typename... Args>
void FatalError(unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args)
{
using namespace std::literals;
try
{
std::stringstream ss;
ss << Format(message, args...);
Logs::Report(LogType::FatalError, line, file, function, ss.str());
}
catch(const std::exception& e)
{
Logs::Report(LogType::Error, "formatter exception catched in the log printer : "s + e.what());
}
}
template<typename... Args>
void Verify(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args)
{
using namespace std::literals;
if(cond)
return;
try
{
std::stringstream ss;
ss << Format("Verification failed : %", message, args...);
Logs::Report(LogType::FatalError, line, file, function, ss.str());
}
catch(const std::exception& e)
{
Logs::Report(LogType::Error, "formatter exception catched in the log printer : "s + e.what());
}
}
#if defined(DEBUG)
template<typename... Args>
void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args)
{
using namespace std::literals;
if(cond)
return;
try
{
std::stringstream ss;
ss << Format("Assertion failed : %", message, args...);
Logs::Report(LogType::FatalError, line, file, function, ss.str());
}
catch(const std::exception& e)
{
Logs::Report(LogType::Error, "formatter exception catched in the log printer : "s + e.what());
}
}
#endif
}

View File

@@ -1,19 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* memory.h :+: :+: :+: */
/* Memory.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/07 16:31:51 by kbz_8 #+# #+# */
/* Updated: 2024/03/25 19:13:05 by maldavid ### ########.fr */
/* Updated: 2024/03/27 21:16:44 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_MEMORY__
#define __MLX_MEMORY__
#include <utils/singleton.h>
#include <Utils/Singleton.h>
namespace mlx
{
@@ -22,17 +22,17 @@ namespace mlx
friend class Singleton<MemManager>;
public:
static void* malloc(std::size_t size);
static void* calloc(std::size_t n, std::size_t size);
static void* realloc(void* ptr, std::size_t size);
static void free(void* ptr);
static void* Malloc(std::size_t size);
static void* Calloc(std::size_t n, std::size_t size);
static void* Realloc(void* ptr, std::size_t size);
static void Free(void* ptr);
private:
MemManager() = default;
~MemManager();
private:
inline static std::list<void*> _blocks;
inline static std::list<void*> s_blocks;
};
}

View File

@@ -1,19 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* profiler.h :+: :+: :+: */
/* Profiler.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 13:35:45 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:12:57 by maldavid ### ########.fr */
/* Updated: 2024/03/27 21:19:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_PROFILER__
#define __MLX_PROFILER__
#include <utils/singleton.h>
#include <Utils/Singleton.h>
namespace mlx
{
@@ -34,63 +34,63 @@ namespace mlx
Profiler(const Profiler&) = delete;
Profiler(Profiler&&) = delete;
void appendProfileData(ProfileResult&& result);
void AppendProfileData(ProfileResult&& result);
private:
Profiler() { beginRuntimeSession(); }
Profiler() { BeginRuntimeSession(); }
~Profiler();
void beginRuntimeSession();
void writeProfile(const ProfileResult& result);
void endRuntimeSession();
inline void writeHeader()
void BeginRuntimeSession();
void WriteProfile(const ProfileResult& result);
void EndRuntimeSession();
inline void WriteHeader()
{
_output_stream << "{\"profileData\":[{}";
_output_stream.flush();
m_output_stream << "{\"profileData\":[{}";
m_output_stream.flush();
}
inline void writeFooter()
inline void WriteFooter()
{
_output_stream << "]}";
_output_stream.flush();
m_output_stream << "]}";
m_output_stream.flush();
}
private:
std::unordered_map<std::string, std::pair<std::size_t, ProfileResult>> _profile_data;
std::ofstream _output_stream;
std::mutex _mutex;
bool _runtime_session_began = false;
std::unordered_map<std::string, std::pair<std::size_t, ProfileResult>> m_profile_data;
std::ofstream m_output_stream;
std::mutex m_mutex;
bool m_runtime_session_began = false;
};
class ProfilerTimer
{
public:
ProfilerTimer(const char* name) : _name(name)
ProfilerTimer(const char* name) : m_name(name)
{
_start_timepoint = std::chrono::steady_clock::now();
m_start_timepoint = std::chrono::steady_clock::now();
}
inline void stop()
inline void Stop()
{
auto end_timepoint = std::chrono::steady_clock::now();
auto high_res_start = FloatingPointMilliseconds{ _start_timepoint.time_since_epoch() };
auto elapsed_time = std::chrono::time_point_cast<std::chrono::milliseconds>(end_timepoint).time_since_epoch() - std::chrono::time_point_cast<std::chrono::milliseconds>(_start_timepoint).time_since_epoch();
auto high_res_start = FloatingPointMilliseconds{ m_start_timepoint.time_since_epoch() };
auto elapsed_time = std::chrono::time_point_cast<std::chrono::milliseconds>(end_timepoint).time_since_epoch() - std::chrono::time_point_cast<std::chrono::milliseconds>(m_start_timepoint).time_since_epoch();
Profiler::get().appendProfileData({ _name, elapsed_time, std::this_thread::get_id() });
Profiler::get().appendProfileData({ m_name, elapsed_time, std::this_thread::get_id() });
_stopped = true;
m_stopped = true;
}
~ProfilerTimer()
{
if(!_stopped)
if(!m_stopped)
stop();
}
private:
std::chrono::time_point<std::chrono::steady_clock> _start_timepoint;
const char* _name;
bool _stopped = false;
std::chrono::time_point<std::chrono::steady_clock> m_start_timepoint;
const char* m_name;
bool m_stopped = false;
};
namespace ProfilerUtils
@@ -102,7 +102,7 @@ namespace mlx
};
template <std::size_t N, std::size_t K>
constexpr auto cleanupOutputString(const char(&expr)[N], const char(&remove)[K])
constexpr auto CleanupOutputString(const char(&expr)[N], const char(&remove)[K])
{
ChangeResult<N> result = {};
@@ -124,8 +124,8 @@ namespace mlx
}
#ifdef PROFILER
#define MLX_PROFILE_SCOPE_LINE2(name, line) constexpr auto fixedName##line = ::mlx::ProfilerUtils::cleanupOutputString(name, "__cdecl ");\
::mlx::ProfilerTimer timer##line(fixedName##line.data)
#define MLX_PROFILE_SCOPE_LINE2(name, line) constexpr auto fixed_name_##line = ::mlx::ProfilerUtils::CleanupOutputString(name, "__cdecl ");\
::mlx::ProfilerTimer timer##line(fixed_name_##line.data)
#define MLX_PROFILE_SCOPE_LINE(name, line) MLX_PROFILE_SCOPE_LINE2(name, line)
#define MLX_PROFILE_SCOPE(name) MLX_PROFILE_SCOPE_LINE(name, __LINE__)
#define MLX_PROFILE_FUNCTION() MLX_PROFILE_SCOPE(MLX_FUNC_SIG)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/06 11:13:23 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:12:53 by maldavid ### ########.fr */
/* Updated: 2024/03/27 21:19:18 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,10 +21,10 @@ namespace mlx
UUID();
UUID(std::uint64_t uuid);
inline operator std::uint64_t() const { return _uuid; }
inline operator std::uint64_t() const { return m_uuid; }
private:
std::uint64_t _uuid;
std::uint64_t m_uuid;
};
}

44
runtime/Includes/Drivers/GLFW/GLFWInputs.h git.filemode.normal_file
View File

@@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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

62
runtime/Includes/Platform/Inputs.h git.filemode.normal_file
View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Inputs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */
/* Updated: 2024/03/27 18:36:21 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_INPUTS__
#define __MLX_INPUTS__
#include <mlx_profile.h>
#include <Platform/Window.h>
namespace mlx
{
class Inputs
{
public:
struct Hook
{
func::function<int(int, void*)> hook;
void* param = nullptr;
};
public:
Inputs() = default;
virtual void Update() noexcept = 0;
virtual void RegisterWindow(std::shared_ptr<Window> window) = 0;
virtual std::int32_t GetX() const noexcept = 0;
virtual std::int32_t GetY() const noexcept = 0;
virtual std::int32_t GetXRel() const noexcept = 0;
virtual std::int32_t GetYRel() const noexcept = 0;
inline bool IsMouseMoving() const noexcept { return GetXRel() || GetYRel(); }
MLX_FORCEINLINE bool IsRunning() const noexcept { return m_run; }
MLX_FORCEINLINE constexpr void Finish() noexcept { m_run = false; }
MLX_FORCEINLINE constexpr void Run() noexcept { m_run = true; }
inline void OnEvent(std::uint32_t id, int event, int (*funct_ptr)(int, void*), void* param) noexcept
{
m_events_hooks[id][event].hook = funct_ptr;
m_events_hooks[id][event].param = param;
}
virtual ~Inputs() = default;
protected:
std::unordered_map<std::uint32_t, std::shared_ptr<Window>> m_windows;
std::unordered_map<std::uint32_t, std::array<Hook, 6>> m_events_hooks;
bool m_run = false;
};
}
#endif

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* window.h :+: :+: :+: */
/* Window.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
/* Updated: 2024/03/26 23:03:50 by maldavid ### ########.fr */
/* Updated: 2024/03/27 21:58:18 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,26 +15,30 @@
namespace mlx
{
#ifdef LEGACY
using WindowHandle = SDL_Window;
#else
using WindowHandle = GLFWwindow;
#endif
class Window
{
public:
Window(std::size_t w, std::size_t h, const std::string& title);
inline GLFWwindow* getNativeWindow() const noexcept { return _win; }
inline int getWidth() const noexcept { return _width; }
inline int getHeight() const noexcept { return _height; }
inline std::uint32_t getID() const noexcept { return _id; }
inline NonOwningPtr<WindowHandle> GetWindowHandle() const noexcept = 0;
inline int GetWidth() const noexcept { return m_width; }
inline int GetHeight() const noexcept { return m_height; }
inline std::uint32_t GetID() const noexcept { return m_id; }
void destroy() noexcept;
void Destroy() noexcept;
~Window() = default;
private:
GLFWimage _icon;
GLFWwindow* _win = nullptr;
int _width = 0;
int _height = 0;
std::uint32_t _id = -1;
std::uint32_t m_id = -1;
int m_width = 0;
int m_height = 0;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pre_compiled.h :+: :+: :+: */
/* PreCompiled.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/25 17:37:23 by maldavid #+# #+# */
/* Updated: 2024/03/27 00:39:13 by maldavid ### ########.fr */
/* Updated: 2024/03/27 21:33:47 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,7 +22,14 @@
#include <cstdarg>
#include <iostream>
#include <volk.h>
#include <GLFW/glfw3.h>
#ifdef LEGACY
#include <SDL2/SDL.h>
#include <SDL2/SDL_vulkan.h>
#else
#include <GLFW/glfw3.h>
#endif
#include <functional>
#include <memory>
#include <list>
@@ -74,4 +81,9 @@
#undef Window
#include <Core/Logs.h>
#include <EventBus.h>
#include <Core/Profiler.h>
#include <?Utils/NonOwningPtr.h>
#endif

66
runtime/Includes/Renderer/Buffers/Buffer.h git.filemode.normal_file
View File

@@ -0,0 +1,66 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Buffer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 23:18:52 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:09:07 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_BUFFER__
#define __MLX_VK_BUFFER__
#include <Renderer/Enums.h>
#include <Renderer/Core/RenderCore.h>
#include <Renderer/Command/CommandResource.h>
namespace mlx
{
class Buffer : public CommandResource
{
public:
Buffer() = default;
void Create(BufferType type, VkDeviceSize size, VkBufferUsageFlags usage, const char* name, const void* data = nullptr);
void Destroy() noexcept;
inline void MapMem(void** data) noexcept { Render_Core::get().getAllocator().mapMemory(m_allocation, data); m_is_mapped = true; }
inline bool IsMapped() const noexcept { return m_is_mapped; }
inline void UnmapMem() noexcept { Render_Core::get().getAllocator().unmapMemory(m_allocation); m_is_mapped = false; }
void Flush(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0);
bool CopyFromBuffer(const Buffer& buffer) noexcept;
inline VkBuffer& operator()() noexcept { return m_buffer; }
inline VkBuffer& Get() noexcept { return m_buffer; }
inline VkDeviceSize GetSize() const noexcept { return m_size; }
inline VkDeviceSize GetOffset() const noexcept { return m_offset; }
~Buffer() = default;
protected:
void PushToGPU() noexcept;
void Swap(Buffer& buffer) noexcept;
protected:
VmaAllocation m_allocation;
VkBuffer m_buffer = VK_NULL_HANDLE;
VkDeviceSize m_offset = 0;
VkDeviceSize m_size = 0;
private:
void CreateBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info, VkDeviceSize size, const char* name);
private:
#ifdef DEBUG
std::string m_name;
#endif
VkBufferUsageFlags m_usage = 0;
bool m_is_mapped = false;
};
}
#endif

View File

@@ -1,28 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_ibo.h :+: :+: :+: */
/* IndexBuffer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/25 15:05:05 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:12:35 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:11:57 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __VK_IBO__
#define __VK_IBO__
#include "vk_buffer.h"
#include <renderer/renderer.h>
#include <Renderer/Buffer/Buffer.h>
#include <Renderer/Renderer.h>
namespace mlx
{
class C_IBO : public Buffer
{
public:
inline void create(std::uint32_t size, const std::uint16_t* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, name, data); }
inline void bind(Renderer& renderer) noexcept { renderer.getActiveCmdBuffer().bindIndexBuffer(*this); }
inline void Create(std::uint32_t size, const std::uint16_t* data, const char* name) { Buffer::Create(BufferType::Constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, name, data); }
inline void Bind(Renderer& renderer) noexcept { renderer.GetActiveCmdBuffer().BindIndexBuffer(*this); }
};
}

View File

@@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* UniformBuffer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:45:29 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:15:23 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_UBO__
#define __MLX_VK_UBO__
#include <Renderer/Buffer/Buffer.h>
namespace mlx
{
class UniformBuffer
{
public:
UniformBuffer() = default;
void Create(NonOwningPtr<class Renderer> renderer, std::uint32_t size, const char* name);
void Destroy() noexcept;
void SetData(std::uint32_t size, const void* data);
VkDeviceSize GetSize() noexcept;
VkDeviceSize GetOffset() noexcept;
VkDeviceMemory GetDeviceMemory() noexcept;
VkBuffer& operator()() noexcept;
VkBuffer& Get() noexcept;
inline VkDeviceSize GetSize(int i) noexcept { return m_buffers[i].getSize(); }
inline VkDeviceSize GetOffset(int i) noexcept { return m_buffers[i].getOffset(); }
inline VkBuffer& operator()(int i) noexcept { return m_buffers[i].get(); }
inline VkBuffer& Get(int i) noexcept { return m_buffers[i].get(); }
~UniformBuffer() = default;
private:
std::array<Buffer, MAX_FRAMES_IN_FLIGHT> m_buffers;
std::array<void*, MAX_FRAMES_IN_FLIGHT> m_maps;
NonOwningPtr<class Renderer> m_renderer;
};
}
#endif // __MLX_VK_UBO__

View File

@@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* VertexBuffer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:27:38 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:18:23 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_VBO__
#define __MLX_VK_VBO__
#include <Renderer/Enums.h>
#include <Renderer/Buffer/Buffer.h>
#include <Renderer/Renderer.h>
namespace mlx
{
class VertexBuffer : public Buffer
{
public:
inline void Create(std::uint32_t size, const void* data, const char* name) { Buffer::Create(BufferType::HighDynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
void SetData(std::uint32_t size, const void* data);
inline void Bind(Renderer& renderer) noexcept { renderer.GetActiveCmdBuffer().BindVertexBuffer(*this); }
};
class DeviceVertexBuffer : public Buffer
{
public:
inline void create(std::uint32_t size, const void* data, const char* name) { Buffer::Create(BufferType::LowDynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
void SetData(std::uint32_t size, const void* data);
inline void Bind(Renderer& renderer) noexcept { renderer.GetActiveCmdBuffer().BindVertexBuffer(*this); }
};
class ConstantVertexBuffer : public Buffer
{
public:
inline void Create(std::uint32_t size, const void* data, const char* name) { Buffer::Create(BufferType::Constant, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
inline void Bind(Renderer& renderer) noexcept { renderer.GetActiveCmdBuffer().BindVertexBuffer(*this); }
};
}
#endif // __MLX_VK_VBO__

View File

@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* CommandBuffer.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:25:42 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:44:58 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_CMD_BUFFER__
#define __MLX_VK_CMD_BUFFER__
#include <Renderer/Core/Fence.h>
#include <Renderer/Enums.h>
namespace mlx
{
class Buffer;
class Image;
class CommandBuffer
{
public:
void Init(CommandBufferType type, NonOwningPtr<class CommandManager> manager);
void Init(CommandBufferType type, NonOwningPtr<class CommandPool> pool);
void Destroy() noexcept;
void BeginRecord(VkCommandBufferUsageFlags usage = 0);
void Submit(class Semaphore* semaphores) noexcept;
void SubmitIdle(bool shouldWaitForExecution = true) noexcept; // TODO : handle `shouldWaitForExecution` as false by default (needs to modify CmdResources lifetimes to do so)
void UpdateSubmitState() noexcept;
inline void WaitForExecution() noexcept { m_fence.wait(); UpdateSubmitState(); m_state = CommandBufferState::Ready; }
inline void Reset() noexcept { vkResetCommandBuffer(m_cmd_buffer, 0); }
void EndRecord();
void BindVertexBuffer(Buffer& buffer) noexcept;
void BindIndexBuffer(Buffer& buffer) noexcept;
void CopyBuffer(Buffer& dst, Buffer& src) noexcept;
void CopyBufferToImage(Buffer& buffer, Image& image) noexcept;
void CopyImagetoBuffer(Image& image, Buffer& buffer) noexcept;
void TransitionImageLayout(Image& image, VkImageLayout new_layout) noexcept;
inline bool IsInit() const noexcept { return m_state != CommandBufferState::Uninit; }
inline bool IsReadyToBeUsed() const noexcept { return m_state == CommandBufferState::Ready; }
inline bool IsRecording() const noexcept { return m_state == CommandBufferState::Recording; }
inline bool HasBeenSubmitted() const noexcept { return m_state == CommandBufferState::Submitted; }
inline CommandBufferState GetCurrentState() const noexcept { return m_state; }
inline VkCommandBuffer& operator()() noexcept { return m_cmd_buffer; }
inline VkCommandBuffer& Get() noexcept { return m_cmd_buffer; }
inline Fence& GetFence() noexcept { return m_fence; }
private:
void PreTransferBarrier() noexcept;
void PostTransferBarrier() noexcept;
private:
std::vector<class CmdResource*> m_cmd_resources;
Fence m_fence;
VkCommandBuffer m_cmd_buffer = VK_NULL_HANDLE;
NonOwningPtr<class CmdPool> m_pool;
CommandBufferState m_state = CommandBufferState::Uninit;
CommandBufferType m_type;
};
}
#endif // __MLX_VK_CMD_BUFFER__

View File

@@ -1,42 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_manager.h :+: :+: :+: */
/* CommandManager.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 17:48:52 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:12:23 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:20:53 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_COMMAND_MANAGER__
#define __MLX_COMMAND_MANAGER__
#include <renderer/core/render_core.h>
#include <renderer/command/vk_cmd_pool.h>
#include <renderer/command/vk_cmd_buffer.h>
#include <Renderer/Core/RenderCore.h>
#include <Renderer/Command/CommandPool.h>
#include <Renderer/Command/CommandBuffer.h>
namespace mlx
{
class CmdManager
class CommandManager
{
public:
CmdManager() = default;
CommandManager() = default;
void init() noexcept;
void beginRecord(int active_image_index);
void endRecord(int active_image_index);
void destroy() noexcept;
void Init() noexcept;
void BeginRecord(int active_image_index);
void EndRecord(int active_image_index);
void Destroy() noexcept;
inline CmdPool& getCmdPool() noexcept { return _cmd_pool; }
inline CmdBuffer& getCmdBuffer(int i) noexcept { return _cmd_buffers[i]; }
inline CommandPool& GetCmdPool() noexcept { return m_cmd_pool; }
inline CommandBuffer& GetCmdBuffer(int i) noexcept { return m_cmd_buffers[i]; }
~CmdManager() = default;
~CommandManager() = default;
private:
std::array<CmdBuffer, MAX_FRAMES_IN_FLIGHT> _cmd_buffers;
CmdPool _cmd_pool;
std::array<CommandBuffer, MAX_FRAMES_IN_FLIGHT> m_cmd_buffers;
CommandPool m_cmd_pool;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_cmd_pool.h :+: :+: :+: */
/* CommandPool.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:24:12 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:12:14 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:33:15 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,17 +15,21 @@
namespace mlx
{
class CmdPool
class CommandPool
{
public:
void init();
void destroy() noexcept;
CommandPool() = default;
inline VkCommandPool& operator()() noexcept { return _cmd_pool; }
inline VkCommandPool& get() noexcept { return _cmd_pool; }
void Init();
void Destroy() noexcept;
inline VkCommandPool& operator()() noexcept { return m_cmd_pool; }
inline VkCommandPool& Get() noexcept { return m_cmd_pool; }
~CommandPool() = default;
private:
VkCommandPool _cmd_pool = VK_NULL_HANDLE;
VkCommandPool m_cmd_pool = VK_NULL_HANDLE;
};
}

View File

@@ -1,42 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cmd_resource.h :+: :+: :+: */
/* CommandResource.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/16 20:44:29 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:12:08 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:37:06 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_COMMAND_RESOURCE__
#define __MLX_COMMAND_RESOURCE__
#include <core/UUID.h>
#include <Renderer/Enums.h>
#include <Core/UUID.h>
namespace mlx
{
class CmdResource
class CommandResource
{
friend class SingleTimeCmdManager;
public:
enum class state
{
in_cmd_buffer = 0,
out_cmd_buffer,
};
public:
CmdResource() : _uuid() {}
inline void recordedInCmdBuffer() noexcept { _state = state::in_cmd_buffer; }
inline void removedFromCmdBuffer() noexcept { _state = state::out_cmd_buffer; }
inline UUID getUUID() const noexcept { return _uuid; }
virtual ~CmdResource() = default;
CommandResource() : m_uuid() {}
inline void RecordedInCmdBuffer() noexcept { m_state = CommandResourceState::Held; }
inline void RemovedFromCmdBuffer() noexcept { m_state = CommandResourceState::Free; }
inline UUID GetUUID() const noexcept { return m_uuid; }
virtual ~CommandResource() = default;
private:
UUID _uuid;
state _state = state::out_cmd_buffer;
UUID m_uuid;
CommandResourceState m_state = CommandResourceState::Free;
};
}

View File

@@ -1,48 +1,48 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* single_time_cmd_manager.h :+: :+: :+: */
/* SingleTimeCmdManager.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/15 18:25:57 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:12:20 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:46:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_SINGLE_TIME_CMD_MANAGER__
#define __MLX_SINGLE_TIME_CMD_MANAGER__
#include <renderer/command/vk_cmd_buffer.h>
#include <renderer/command/vk_cmd_pool.h>
#include <Renderer/Command/CommandBuffer.h>
#include <Renderer/Command/CommandPool.h>
namespace mlx
{
class CmdBuffer;
class CommandBuffer;
class SingleTimeCmdManager
{
friend class Render_Core;
friend class RenderCore;
public:
SingleTimeCmdManager() = default;
void init() noexcept;
void destroy() noexcept;
void Init() noexcept;
void Destroy() noexcept;
void updateSingleTimesCmdBuffersSubmitState() noexcept;
void waitForAllExecutions() noexcept;
void UpdateSingleTimesCmdBuffersSubmitState() noexcept;
void WaitForAllExecutions() noexcept;
inline CmdPool& getCmdPool() noexcept { return _pool; }
CmdBuffer& getCmdBuffer() noexcept;
inline CommandPool& GetCmdPool() noexcept { return m_pool; }
CommanddBuffer& GetCmdBuffer() noexcept;
~SingleTimeCmdManager() = default;
inline static constexpr const std::uint8_t BASE_POOL_SIZE = 16;
private:
std::vector<CmdBuffer> _buffers;
CmdPool _pool;
std::vector<CommanddBuffer> m_buffers;
CommanddPool m_pool;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_device.h :+: :+: :+: */
/* Device.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:13:42 by maldavid #+# #+# */
/* Updated: 2024/03/25 22:31:46 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:47:21 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,22 +18,22 @@ namespace mlx
class Device
{
public:
void init();
void destroy() noexcept;
void Init();
void Destroy() noexcept;
inline VkDevice& operator()() noexcept { return _device; }
inline VkDevice& get() noexcept { return _device; }
inline VkDevice& operator()() noexcept { return m_device; }
inline VkDevice& Get() noexcept { return m_device; }
inline VkPhysicalDevice& getPhysicalDevice() noexcept { return _physical_device; }
inline VkPhysicalDevice& GetPhysicalDevice() noexcept { return m_physical_device; }
private:
void pickPhysicalDevice();
bool checkDeviceExtensionSupport(VkPhysicalDevice device);
int deviceScore(VkPhysicalDevice device);
void PickPhysicalDevice();
bool CheckDeviceExtensionSupport(VkPhysicalDevice device);
int DeviceScore(VkPhysicalDevice device);
private:
VkPhysicalDevice _physical_device = VK_NULL_HANDLE;
VkDevice _device = VK_NULL_HANDLE;
VkPhysicalDevice m_physical_device = VK_NULL_HANDLE;
VkDevice m_device = VK_NULL_HANDLE;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* drawable_resource.h :+: :+: :+: */
/* DrawableResource.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 21:00:37 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:12:05 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:47:32 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,8 +19,8 @@ namespace mlx
{
public:
DrawableResource() = default;
virtual void render(std::array<VkDescriptorSet, 2>& sets, class Renderer& renderer) = 0;
virtual void resetUpdate() {}
virtual void Render(std::array<VkDescriptorSet, 2>& sets, class Renderer& renderer) = 0;
virtual void ResetUpdate() {}
virtual ~DrawableResource() = default;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_fence.h :+: :+: :+: */
/* Fence.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 17:52:09 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:11:53 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:48:31 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,20 +20,20 @@ namespace mlx
public:
Fence() = default;
void init();
void Init();
inline VkFence& get() noexcept { return _fence; }
void wait() noexcept;
void reset() noexcept;
bool isReady() const noexcept;
inline void waitAndReset() noexcept { wait(); reset(); }
inline VkFence& Get() noexcept { return m_fence; }
void Wait() noexcept;
void Reset() noexcept;
bool IsReady() const noexcept;
MLX_FORCEINLINE void WaitAndReset() noexcept { Wait(); Reset(); }
void destroy() noexcept;
void Destroy() noexcept;
~Fence() = default;
private:
VkFence _fence = VK_NULL_HANDLE;
VkFence m_fence = VK_NULL_HANDLE;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_instance.h :+: :+: :+: */
/* Instance.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:03:04 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:11:50 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:48:55 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,15 +18,17 @@ namespace mlx
class Instance
{
public:
void init();
void destroy() noexcept;
void Init();
void Destroy() noexcept;
inline VkInstance& operator()() noexcept { return _instance; }
inline VkInstance& get() noexcept { return _instance; }
inline VkInstance& operator()() noexcept { return m_instance; }
inline VkInstance& Get() noexcept { return m_instance; }
private:
std::vector<const char*> getRequiredExtensions();
VkInstance _instance = VK_NULL_HANDLE;
std::vector<const char*> GetRequiredExtensions();
private:
VkInstance m_instance = VK_NULL_HANDLE;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* memory.h :+: :+: :+: */
/* Memory.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 02:13:03 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:12:02 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:49:57 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,28 +20,28 @@ namespace mlx
public:
GPUallocator() = default;
void init() noexcept;
void destroy() noexcept;
void Init() noexcept;
void Destroy() noexcept;
VmaAllocation createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name = nullptr) noexcept;
void destroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept;
VmaAllocation CreateBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name = nullptr) noexcept;
void DestroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept;
VmaAllocation createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name = nullptr) noexcept;
void destroyImage(VmaAllocation allocation, VkImage image) noexcept;
VmaAllocation CreateImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name = nullptr) noexcept;
void DestroyImage(VmaAllocation allocation, VkImage image) noexcept;
void mapMemory(VmaAllocation allocation, void** data) noexcept;
void unmapMemory(VmaAllocation allocation) noexcept;
void MapMemory(VmaAllocation allocation, void** data) noexcept;
void UnmapMemory(VmaAllocation allocation) noexcept;
void dumpMemoryToJson();
void DumpMemoryToJson();
void flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept;
void Flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept;
~GPUallocator() = default;
private:
VmaAllocator _allocator;
std::int32_t _active_buffers_allocations = 0;
std::int32_t _active_images_allocations = 0;
VmaAllocator m_allocator;
std::int32_t m_active_buffers_allocations = 0;
std::int32_t m_active_images_allocations = 0;
};
}

View File

@@ -1,20 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_queues.h :+: :+: :+: */
/* Queues.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:01:49 by maldavid #+# #+# */
/* Updated: 2024/03/25 22:29:26 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:50:52 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_VK_QUEUES__
#define __MLX_VK_QUEUES__
#include <core/errors.h>
namespace mlx
{
class Queues
@@ -28,24 +26,25 @@ namespace mlx
inline bool isComplete() { return graphics_family.has_value() && present_family.has_value(); }
};
QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device);
public:
QueueFamilyIndices FindQueueFamilies(VkPhysicalDevice device);
void init();
void Init();
inline VkQueue& getGraphic() noexcept { return _graphics_queue; }
inline VkQueue& getPresent() noexcept { return _present_queue; }
inline QueueFamilyIndices getFamilies() noexcept
inline VkQueue& GetGraphic() noexcept { return _graphics_queue; }
inline VkQueue& GetPresent() noexcept { return _present_queue; }
inline QueueFamilyIndices GetFamilies() noexcept
{
if(_families.has_value())
return *_families;
core::error::report(e_kind::fatal_error, "Vulkan : cannot get queue families, not init");
if(m_families.has_value())
return *m_families;
FatalError("Vulkan : cannot get queue families, not init");
return {}; // just to avoid warnings
}
private:
VkQueue _graphics_queue;
VkQueue _present_queue;
std::optional<QueueFamilyIndices> _families;
VkQueue m_graphics_queue;
VkQueue m_present_queue;
std::optional<QueueFamilyIndices> m_families;
};
}

78
runtime/Includes/Renderer/Core/RenderCore.h git.filemode.normal_file
View File

@@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* RenderCore.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:55:43 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_RENDER_CORE__
#define __MLX_RENDER_CORE__
#include <Renderer/Command/SingleTimeCmdManager.h>
#include <Renderer/Descriptors/DescriptorPoolManager.h>
#include <Renderer/Descriptors/DescriptorPool.h>
#include <Renderer/Core/Queues.h>
#include <Renderer/Core/Device.h>
#include <Renderer/Core/Instance.h>
#include <Renderer/Core/ValidationLayers.h>
#include <Renderer/Core/memory.h>
#include <Utils/Singleton.h>
namespace mlx
{
const char* VerbaliseVkResult(VkResult result);
VkPipelineStageFlags AccessFlagsToPipelineStage(VkAccessFlags access_flags, VkPipelineStageFlags stage_flags);
#ifdef DEBUG
constexpr const bool enable_validation_layers = true;
#else
constexpr const bool enable_validation_layers = false;
#endif
const std::vector<const char*> validation_layers = { "VK_LAYER_KHRONOS_validation" };
constexpr const int MAX_FRAMES_IN_FLIGHT = 3;
constexpr const int MAX_SETS_PER_POOL = 512;
constexpr const int NUMBER_OF_UNIFORM_BUFFERS = 1; // change this if for wathever reason more than one uniform buffer is needed
class RenderCore : public Singleton<RenderCore>
{
friend class Singleton<RenderCore>;
public:
void Init();
void Destroy();
inline bool IsInit() const noexcept { return m_is_init; }
inline Instance& GetInstance() noexcept { return m_instance; }
inline Device& GetDevice() noexcept { return m_device; }
inline Queues& GetQueue() noexcept { return m_queues; }
inline GPUallocator& GetAllocator() noexcept { return m_allocator; }
inline ValidationLayers& GetLayers() noexcept { return m_layers; }
inline CommandBuffer& GetSingleTimeCmdBuffer() noexcept { return m_cmd_manager.GetCmdBuffer(); }
inline SingleTimeCmdManager& GetSingleTimeCmdManager() noexcept { return m_cmd_manager; }
inline DescriptorPool& GetDescriptorPool() { return m_pool_manager.GetAvailablePool(); }
private:
RenderCore() = default;
~RenderCore() = default;
private:
ValidationLayers m_layers;
SingleTimeCmdManager m_cmd_manager;
Queues m_queues;
DescriptorPoolManager m_pool_manager;
Device m_device;
Instance m_instance;
GPUallocator m_allocator;
bool m_is_init = false;
};
}
#endif // __MLX_RENDER_CORE__

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_semaphore.h :+: :+: :+: */
/* Semaphore.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 18:59:38 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:11:43 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:56:51 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,15 +18,13 @@ namespace mlx
class Semaphore
{
public:
void init();
void destroy() noexcept;
void Init();
void Destroy() noexcept;
inline VkSemaphore& getImageSemaphore() noexcept { return _image_available_semaphore; }
inline VkSemaphore& getRenderImageSemaphore() noexcept { return _render_finished_semaphore; }
inline VkSemaphore& Get() noexcept { return m_semaphore; }
private:
VkSemaphore _image_available_semaphore = VK_NULL_HANDLE;
VkSemaphore _render_finished_semaphore = VK_NULL_HANDLE;
VkSemaphore m_semaphore = VK_NULL_HANDLE;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_surface.h :+: :+: :+: */
/* Surface.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 18:57:55 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:10:59 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:58:15 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,16 +18,16 @@ namespace mlx
class Surface
{
public:
void create(class Renderer& renderer);
void destroy() noexcept;
void Create(class Renderer& renderer);
void Destroy() noexcept;
VkSurfaceFormatKHR chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats);
VkSurfaceFormatKHR ChooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& available_formats);
inline VkSurfaceKHR& operator()() noexcept { return _surface; }
inline VkSurfaceKHR& get() noexcept { return _surface; }
inline VkSurfaceKHR& operator()() noexcept { return m_surface; }
inline VkSurfaceKHR& Get() noexcept { return m_surface; }
private:
VkSurfaceKHR _surface = VK_NULL_HANDLE;
VkSurfaceKHR m_surface = VK_NULL_HANDLE;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_validation_layers.h :+: :+: :+: */
/* ValidationLayers.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/19 14:04:25 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:00:00 by maldavid ### ########.fr */
/* Updated: 2024/03/27 22:59:00 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,24 +20,24 @@ namespace mlx
public:
ValidationLayers() = default;
void init();
void destroy();
void Init();
void Destroy();
bool checkValidationLayerSupport();
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
bool CheckValidationLayerSupport();
void PopulateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& create_info);
VkResult setDebugUtilsObjectNameEXT(VkObjectType object_type, std::uint64_t object_handle, const char* object_name);
VkResult SetDebugUtilsObjectNameEXT(VkObjectType object_type, std::uint64_t object_handle, const char* object_name);
~ValidationLayers() = default;
private:
VkResult createDebugUtilsMessengerEXT(const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator);
static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData);
void destroyDebugUtilsMessengerEXT(const VkAllocationCallbacks* pAllocator);
VkResult CreateDebugUtilsMessengerEXT(const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator);
static VKAPI_ATTR VkBool32 VKAPI_CALL DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT message_severity, VkDebugUtilsMessageTypeFlagsEXT message_type, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData);
void DestroyDebugUtilsMessengerEXT(const VkAllocationCallbacks* pAllocator);
private:
VkDebugUtilsMessengerEXT _debug_messenger;
PFN_vkSetDebugUtilsObjectNameEXT _vkSetDebugUtilsObjectNameEXT = nullptr;
VkDebugUtilsMessengerEXT m_debug_messenger;
PFN_vkSetDebugUtilsObjectNameEXT f_vkSetDebugUtilsObjectNameEXT = nullptr;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_descriptor_pool.h :+: :+: :+: */
/* DescriptorPool.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:32:43 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:10:09 by maldavid ### ########.fr */
/* Updated: 2024/03/27 23:00:29 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,21 +20,21 @@ namespace mlx
public:
DescriptorPool() = default;
void init(std::size_t n, VkDescriptorPoolSize* size);
void freeDescriptor(const class DescriptorSet& set);
void destroy() noexcept;
void Init(std::size_t n, NonOwningPtr<VkDescriptorPoolSize> size);
void FreeDescriptor(const class DescriptorSet& set);
void Destroy() noexcept;
inline VkDescriptorPool& operator()() noexcept { return _pool; }
inline VkDescriptorPool& get() noexcept { return _pool; }
inline std::size_t getNumberOfSetsAllocated() const noexcept { return _allocated_sets; }
inline VkDescriptorPool& operator()() noexcept { return m_pool; }
inline VkDescriptorPool& Get() noexcept { return m_pool; }
inline std::size_t GetNumberOfSetsAllocated() const noexcept { return m_allocated_sets; }
inline bool isInit() const noexcept { return _pool != VK_NULL_HANDLE; }
inline bool IsInit() const noexcept { return m_pool != VK_NULL_HANDLE; }
~DescriptorPool() = default;
private:
VkDescriptorPool _pool = VK_NULL_HANDLE;
std::size_t _allocated_sets = 0;
VkDescriptorPool m_pool = VK_NULL_HANDLE;
std::size_t m_allocated_sets = 0;
};
}

View File

@@ -1,19 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* descriptor_pool_manager.h :+: :+: :+: */
/* DescriptorPoolManager.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/20 06:26:26 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:10:12 by maldavid ### ########.fr */
/* Updated: 2024/03/27 23:00:56 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_DESCRIPTOR_POOL_MANAGER__
#define __MLX_DESCRIPTOR_POOL_MANAGER__
#include <renderer/descriptors/vk_descriptor_pool.h>
#include <Renderer/Descriptors/DescriptorPool.h>
namespace mlx
{
@@ -22,13 +22,13 @@ namespace mlx
public:
DescriptorPoolManager() = default;
DescriptorPool& getAvailablePool(); // assumes the pool is for only one set allocation, may cause some issues if this is for more than one
void destroyAllPools();
DescriptorPool& GetAvailablePool(); // assumes the pool is for only one set allocation, may cause some issues if this is for more than one
void DestroyAllPools();
~DescriptorPoolManager() = default;
private:
std::list<DescriptorPool> _pools;
std::list<DescriptorPool> m_pools;
};
}

View File

@@ -1,19 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_descriptor_set.h :+: :+: :+: */
/* DescriptorSet.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:39:36 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:10:06 by maldavid ### ########.fr */
/* Updated: 2024/03/27 23:02:38 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __VK_DESCRIPTOR_SET__
#define __VK_DESCRIPTOR_SET__
#include <renderer/core/render_core.h>
#include <Renderer/Core/RenderCore.h>
namespace mlx
{
@@ -22,29 +22,29 @@ namespace mlx
public:
DescriptorSet() = default;
void init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);
void Init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);
void writeDescriptor(int binding, class UBO* ubo) const noexcept;
void writeDescriptor(int binding, const class Image& image) const noexcept;
void WriteDescriptor(int binding, NonOwningPtr<class UniformBuffer> ubo) const noexcept;
void WriteDescriptor(int binding, const class Image& image) const noexcept;
inline bool isInit() const noexcept { return _pool != nullptr && _renderer != nullptr; }
inline bool IsInit() const noexcept { return m_pool != nullptr && m_renderer != nullptr; }
DescriptorSet duplicate();
DescriptorSet Duplicate();
VkDescriptorSet& operator()() noexcept;
VkDescriptorSet& get() noexcept;
VkDescriptorSet& Get() noexcept;
inline const std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT>& getAllFramesDescriptorSets() const { return _desc_set; }
inline const std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT>& GetAllFramesDescriptorSets() const { return m_desc_set; }
void destroy() noexcept;
void Destroy() noexcept;
~DescriptorSet() = default;
private:
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> _desc_set;
class DescriptorPool* _pool = nullptr;
class DescriptorSetLayout* _layout = nullptr;
class Renderer* _renderer = nullptr;
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> m_desc_set;
NonOwningPtr<class DescriptorPool> p_pool;
NonOwningPtr<class DescriptorSetLayout> p_layout;
NonOwningPtr<class Renderer> p_renderer;
};
}

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* vk_descriptor_set_layout.h :+: :+: :+: */
/* DescriptorSetLayout.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:36:22 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:10:03 by maldavid ### ########.fr */
/* Updated: 2024/03/27 23:03:04 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,18 +20,18 @@ namespace mlx
public:
DescriptorSetLayout() = default;
void init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage);
void destroy() noexcept;
void Init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage);
void Destroy() noexcept;
inline VkDescriptorSetLayout& operator()() noexcept { return _layout; }
inline VkDescriptorSetLayout& get() noexcept { return _layout; }
inline const std::vector<std::pair<int, VkDescriptorType>>& getBindings() const noexcept { return _bindings; }
inline VkDescriptorSetLayout& operator()() noexcept { return m_layout; }
inline VkDescriptorSetLayout& Get() noexcept { return m_layout; }
inline const std::vector<std::pair<int, VkDescriptorType>>& GetBindings() const noexcept { return m_bindings; }
~DescriptorSetLayout() = default;
private:
VkDescriptorSetLayout _layout = VK_NULL_HANDLE;
std::vector<std::pair<int, VkDescriptorType>> _bindings;
std::vector<std::pair<int, VkDescriptorType>> m_bindings;
VkDescriptorSetLayout m_layout = VK_NULL_HANDLE;
};
}

59
runtime/Includes/Renderer/Enums.h git.filemode.normal_file
View File

@@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Enums.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 22:02:58 by maldavid #+# #+# */
/* Updated: 2024/03/27 22:39:31 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_RENDERER_ENUMS__
#define __MLX_RENDERER_ENUMS__
namespace mlx
{
enum class BufferType
{
Constant = 0,
HighDynamic, // typically stored in RAM
LowDynamic, // typically stored in VRAM
EndEnum
};
constexpr std::size_t BufferTypeCount = static_cast<std::size_t>(BufferType::EndEnum);
enum class CommandResourceState
{
Held = 0,
Free,
EndEnum
};
constexpr std::size_t CommandResourceStateCount = static_cast<std::size_t>(CommandResourceState::EndEnum);
enum class CommandBufferState
{
Uninit = 0, // buffer not initialized or destroyed
Ready, // buffer ready to be used after having been submitted
Idle, // buffer has recorded informations but has not been submitted
Recording, // buffer is currently recording
Submitted, // buffer has been submitted
EndEnum
};
constexpr std::size_t CommandBufferStateCount = static_cast<std::size_t>(CommandBufferState::EndEnum);
enum class CommandBufferType
{
SingleTime = 0,
LongTime,
EndEnum
};
constexpr std::size_t CommandBufferTypeCount = static_cast<std::size_t>(CommandBufferType::EndEnum);
}
#endif

56
runtime/Includes/Utils/Ansi.h git.filemode.normal_file
View File

@@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Ansi.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:22:41 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:23:34 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_ANSI__
#define __MLX_ANSI__
#include <ostream>
#include <cstdint>
namespace mlx
{
enum class Ansi : std::uint32_t
{
red = 31,
green = 32,
blue = 34,
def = 0,
black = 30,
yellow = 33,
magenta = 35,
cyan = 36,
white = 37,
bg_red = 41,
bg_green = 42,
bg_blue = 44,
bg_def = 0,
bg_black = 40,
bg_yellow = 43,
bg_magenta = 45,
bg_cyan = 46,
bg_white = 47,
reset = 0,
bold = 1,
underline = 4,
inverse = 7,
bold_off = 21,
underline_off = 24,
inverse_off = 27
};
inline std::ostream& operator<<(std::ostream& os, Ansi ansi)
{
return os << "\033[1;" << std::to_string(static_cast<std::uint32_t>(ansi)) << "m";
}
}
#endif

View File

@@ -1,31 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* combine_hash.h :+: :+: :+: */
/* CombineHash.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/14 16:16:06 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:06:37 by maldavid ### ########.fr */
/* Updated: 2024/03/27 21:59:30 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_HASH__
#define __MLX_HASH__
#include <cstddef>
#include <functional>
namespace mlx
{
inline void hashCombine([[maybe_unused]] std::size_t& seed) noexcept {}
inline void HashCombine([[maybe_unused]] std::size_t& seed) noexcept {}
template <typename T, typename... Rest>
inline void hashCombine(std::size_t& seed, const T& v, Rest... rest)
inline void HashCombine(std::size_t& seed, const T& v, Rest... rest)
{
std::hash<T> hasher;
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
hashCombine(seed, rest...);
HashCombine(seed, rest...);
}
}

69
runtime/Includes/Utils/ConstMap.h git.filemode.normal_file
View File

@@ -0,0 +1,69 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ConstMap.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 15:26:39 by maldavid #+# #+# */
/* Updated: 2024/03/27 21:59:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_CONST_MAP__
#define __MLX_CONST_MAP__
namespace mlx
{
template<typename Key, typename Value>
class ConstMap
{
public:
using ValueType = std::pair<Key, Value>;
using ContainerType = std::vector<ValueType>;
using iterator = typename ContainerType::const_iterator;
using const_iterator = iterator;
public:
ConstMap(std::initializer_list<ValueType> init) : m_container(init)
{
std::sort(m_container.begin(), m_container.end());
}
ConstMap(ContainerType container) : m_container(std::move(container))
{
std::sort(m_container.begin(), m_container.end());
}
inline const_iterator begin() const { return m_container.begin(); }
inline const_iterator end() const { return m_container.end(); }
template<typename K>
inline const_iterator Find(const K& key) const
{
const_iterator it = std::lower_bound(begin(), end(), key,
[](const ValueType& p, const K& key)
{
return p.first < key;
}
);
return it != end() && it->first == key ? it : end();
}
template<typename K>
inline bool Has(const K& key) const
{
return Find(key) != end();
}
inline std::size_t Size() const { return m_container.size(); }
~ConstMap() = default;
private:
ContainerType m_container;
};
}
#endif

View File

@@ -1,20 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* dogica_ttf.h :+: :+: :+: */
/* DogicaTTF.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 16:20:25 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:05:36 by maldavid ### ########.fr */
/* Updated: 2024/03/27 21:59:40 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_DOGICA_TTF__
#define __MLX_DOGICA_TTF__
#include <vector>
constexpr const unsigned int dogica_ttf_len = 33860;
static const std::vector<unsigned char> dogica_ttf = {

View File

@@ -1,20 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* icon_mlx.h :+: :+: :+: */
/* IconMlx.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/25 11:23:16 by maldavid #+# #+# */
/* Updated: 2024/03/25 19:05:28 by maldavid ### ########.fr */
/* Updated: 2024/03/27 21:59:45 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __ICON_MLX__
#define __ICON_MLX__
#include <cstdint>
constexpr const int logo_mlx_height = 125;
constexpr const int logo_mlx_width = 125;
constexpr const int logo_mlx_size = logo_mlx_height * logo_mlx_width * 4;

45
runtime/Includes/Utils/NonOwningPtr.h git.filemode.normal_file
View File

@@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* NonOwningPtr.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 21:03:37 by maldavid #+# #+# */
/* Updated: 2024/03/27 21:05:05 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_NON_OWNING_PTR__
#define __MLX_NON_OWNING_PTR__
namespace mlx
{
template<typename T>
class NonOwningPtr
{
public:
NonOwningPtr(T* ptr = nullptr);
NonOwningPtr(const NonOwningPtr&) = default;
NonOwningPtr(NonOwningPtr&& ptr) noexcept;
NonOwningPtr& operator=(T* ptr);
NonOwningPtr& operator=(const NonOwningPtr&) = default;
NonOwningPtr& operator=(NonOwningPtr&& ptr) noexcept;
inline operator bool() const noexcept;
inline T* Get() const noexcept;
inline T* operator->() const noexcept;
inline T& operator*() const noexcept;
~NonOwningPtr() = default;
private:
T* p_ptr = nullptr;
};
}
#include <Utils/NonOwningPtr.inl>
#endif

62
runtime/Includes/Utils/NonOwningPtr.inl git.filemode.normal_file
View File

@@ -0,0 +1,62 @@
/* **************************************************************************** */
/* */
/* ::: :::::::: */
/* NonOwningPtr.inl :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 21:04:00 by maldavid #+# #+# */
/* Updated: 2024/03/27 21:04:00 by maldavid ### ########.fr */
/* */
/* **************************************************************************** */
#include <Utils/NonOwningPtr.h>
namespace mlx
{
template<typename T>
NonOwningPtr<T>::NonOwningPtr(T* ptr) : p_ptr(ptr) {}
template<typename T>
NonOwningPtr<T>::NonOwningPtr(NonOwningPtr<T>&& ptr) noexcept : p_ptr(ptr.p_ptr)
{
ptr.p_ptr = nullptr;
}
template<typename T>
NonOwningPtr<T>& NonOwningPtr<T>::operator=(T* ptr)
{
p_ptr = ptr;
}
template<typename T>
NonOwningPtr<T>& NonOwningPtr<T>::operator=(NonOwningPtr&& ptr) noexcept
{
p_ptr = ptr.p_ptr;
ptr.p_ptr = nullptr;
}
template<typename T>
NonOwningPtr<T>::operator bool() const noexcept
{
return p_ptr != nullptr;
}
template<typename T>
T* NonOwningPtr<T>::Get() const noexcept
{
return p_ptr;
}
template<typename T>
T* NonOwningPtr<T>::operator->() const noexcept
{
return p_ptr;
}
template<typename T>
T& NonOwningPtr<T>::operator*() const noexcept
{
return *p_ptr;
}
}

View File

@@ -1,19 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* singleton.h :+: :+: :+: */
/* Singleton.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:18:46 by maldavid #+# #+# */
/* Updated: 2024/03/24 14:42:56 by maldavid ### ########.fr */
/* Updated: 2024/03/27 18:20:11 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_SINGLETON__
#define __MLX_SINGLETON__
#include "non_copyable.h"
#include <Utils/NonCopyable.h>
namespace mlx
{
@@ -21,7 +21,7 @@ namespace mlx
class Singleton : public NonCopyable
{
public:
inline static T& get()
inline static T& Get()
{
static T instance;
return instance;

View File

@@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* application.cpp :+: :+: :+: */
/* Application.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2024/03/25 22:16:24 by maldavid ### ########.fr */
/* Updated: 2024/03/27 17:43:18 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <pre_compiled.h>
#include <PreCompiled.h>
#include "application.h"
#include <Core/Application.h>
#include <renderer/texts/text_library.h>
#include <renderer/texts/font_library.h>
#include <renderer/images/texture.h>
@@ -20,11 +20,17 @@
#include <core/errors.h>
#include <mlx_profile.h>
#include <core/memory.h>
#include <Core/EventBus.h>
namespace mlx::core
{
Application::Application() : _fps(), _in(std::make_unique<Input>())
{
EventBus::RegisterListener({[](const EventBase& event)
{
}, "__internal_application" });
_fps.init();
glfwSetErrorCallback([]([[maybe_unused]] int code, const char* desc)
{

37
runtime/Sources/Core/EventBus.cpp git.filemode.normal_file
View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* EventBus.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:36:05 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:37:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <PreCompiled.h>
#include <Core/EventBus.h>
#include <Core/Logs.h>
namespace mlx
{
void EventBus::Send(const std::string& listener_name, const EventBase& event)
{
for(const EventListener& listener : s_listeners)
{
if(listener.GetName() == listener_name)
{
listener.Call(event);
return;
}
}
Warning("Event Bus : listener not found, '%'", listener_name);
}
void EventBus::SendBroadcast(const EventBase& event)
{
for(const EventListener& listener : s_listeners)
listener.Call(event);
}
}

21
runtime/Sources/Core/EventListener.cpp git.filemode.normal_file
View File

@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* EventListener.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:37:09 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:37:38 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <PreCompiled.h>
#include <Core/EventListener.h>
namespace mlx
{
EventListener::EventListener(func::function<void(const EventBase&)> functor, std::string name)
: m_listen_functor(std::move(functor)), m_name(std::move(name))
{}
}

View File

@@ -1,43 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fps.cpp :+: :+: :+: */
/* Fps.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/18 14:56:17 by maldavid #+# #+# */
/* Updated: 2024/03/25 22:59:13 by maldavid ### ########.fr */
/* Updated: 2024/03/27 20:53:11 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <pre_compiled.h>
#include <core/fps.h>
#include <PreCompiled.h>
#include <Core/Fps.h>
namespace mlx
{
void FpsManager::init()
void FpsManager::Init()
{
_timer = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
_fps_before = _timer;
_fps_now = _timer;
m_timer = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
m_fps_before = m_timer;
m_fps_now = m_timer;
}
bool FpsManager::update()
bool FpsManager::Update()
{
using namespace std::chrono_literals;
_fps_now = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
m_fps_now = static_cast<std::uint64_t>(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count());
if(std::chrono::duration<std::uint64_t>{_fps_now - _timer} >= 1s)
_timer += _fps_now;
if(std::chrono::duration<std::uint64_t>{m_fps_now - m_timer} >= 1s)
m_timer += m_fps_now;
_fps_elapsed_time = _fps_now - _fps_before;
if(_fps_elapsed_time >= _ns)
m_fps_elapsed_time = m_fps_now - m_fps_before;
if(m_fps_elapsed_time >= m_ns)
{
_fps_before += _ns;
m_fps_before += m_ns;
return true;
}
std::this_thread::sleep_for(std::chrono::duration<double, std::nano>(_ns - 1));
std::this_thread::sleep_for(std::chrono::duration<double, std::nano>(m_ns - 1));
return false;
}
}

68
runtime/Sources/Core/Logs.cpp git.filemode.normal_file
View File

@@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Logs.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/27 17:20:55 by maldavid #+# #+# */
/* Updated: 2024/03/27 17:26:59 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <Core/Logs.h>
#include <Utils/Ansi.h>
#include <Core/EventBase.h>
#include <Core/EventBus.h>
namespace mlx
{
namespace Internal
{
struct FatalErrorEvent : public EventBase
{
std::uint32_t What() const override { return 167; }
};
}
void Logs::Report(LogType type, std::string message)
{
Report(type, 0, {}, {}, std::move(message));
}
void Logs::Report(LogType type, unsigned int line, std::string_view file, std::string_view function, std::string message)
{
using namespace std::literals;
#ifndef DEBUG
if(type == LogType::Debug)
return;
#endif
std::string code_infos;
if((type == LogType::Error || type == LogType::FatalError) && !file.empty() && !function.empty())
{
code_infos += "{in file '"s;
code_infos += file;
code_infos += "', line "s + std::to_string(line) + ", in function '"s;
code_infos += function;
code_infos += "'} "s;
}
switch(type)
{
case LogType::Debug: std::cout << Ansi::blue << "[Akel Debug] " << Ansi::def << code_infos << message << '\n'; break;
case LogType::Message: std::cout << Ansi::blue << "[Akel Message] " << Ansi::def << code_infos << message << '\n'; break;
case LogType::Warning: std::cout << Ansi::magenta << "[Akel Warning] " << Ansi::def << code_infos << message << '\n'; break;
case LogType::Error: std::cerr << Ansi::red << "[Akel Error] " << Ansi::def << code_infos << message << '\n'; break;
case LogType::FatalError: std::cerr << Ansi::red << "[Akel Fatal Error] " << Ansi::def << code_infos << message << '\n'; break;
default: break;
}
if(type == LogType::FatalError)
{
std::cout << Ansi::bg_red << "Fatal Error: emergency exit" << Ansi::bg_def << std::endl;
EventBus::Send("__internal_application", Internal::FatalErrorEvent{});
}
}
}

22
runtime/Sources/Drivers/GLFW/GLFWInputs.cpp git.filemode.normal_file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */
/* Updated: 2024/03/25 23:13:16 by maldavid ### ########.fr */
/* Updated: 2024/03/27 15:50:07 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,9 +24,11 @@ namespace mlx
_xRel = 0;
_yRel = 0;
glfwPollEvents();
static int i = 0;
i++;
if(i >= 150)
if(i >= 500)
{
auto& hooks = _events_hooks[0];
auto& win_hook = hooks[MLX_WINDOW_EVENT];

Some files were not shown because too many files have changed in this diff Show More