diff --git a/example/build.sh b/example/build.sh index b332c18..1b95a5d 100755 --- a/example/build.sh +++ b/example/build.sh @@ -5,8 +5,8 @@ if [ -e a.out ]; then fi if [ $(uname -s) = 'Darwin' ]; then - clang main.c ../libmlx.dylib -L /opt/homebrew/lib -lSDL2 -g; + clang main.c ../libmlx.dylib -L /opt/homebrew/lib -lglfw -g; else - clang main.c ../libmlx.so -lSDL2 -g -Wall -Wextra -Werror; + clang main.c ../libmlx.so -lglfw -g -Wall -Wextra -Werror; fi diff --git a/src/core/application.cpp b/src/core/application.cpp index ec9a4bd..e14379d 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:00:40 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:16:24 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,20 +23,14 @@ namespace mlx::core { - static bool __drop_sdl_responsability = false; Application::Application() : _fps(), _in(std::make_unique()) { _fps.init(); - __drop_sdl_responsability = SDL_WasInit(SDL_INIT_VIDEO); - if(__drop_sdl_responsability) // is case the mlx is running in a sandbox like MacroUnitTester where SDL is already init - return; - SDL_SetMemoryFunctions(MemManager::malloc, MemManager::calloc, MemManager::realloc, MemManager::free); - - /* Remove this comment if you want to prioritise Wayland over X11/XWayland, at your own risks */ - //SDL_SetHint(SDL_HINT_VIDEODRIVER, "wayland,x11"); - - if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0) - error::report(e_kind::fatal_error, "SDL error : unable to init all subsystems : %s", SDL_GetError()); + glfwSetErrorCallback([]([[maybe_unused]] int code, const char* desc) + { + error::report(e_kind::fatal_error, "GLFW error : %s", desc); + }); + glfwInit(); } void Application::run() noexcept @@ -111,9 +105,6 @@ namespace mlx::core { TextLibrary::get().clearLibrary(); FontLibrary::get().clearLibrary(); - if(__drop_sdl_responsability) - return; - SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS); - SDL_Quit(); + glfwTerminate(); } } diff --git a/src/core/application.inl b/src/core/application.inl index a3ccec1..f98d510 100644 --- a/src/core/application.inl +++ b/src/core/application.inl @@ -55,8 +55,6 @@ namespace mlx::core error::report(e_kind::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; } - SDL_WarpMouseInWindow(_graphics[*static_cast(win)]->getWindow()->getNativeWindow(), x, y); - SDL_PumpEvents(); } void Application::onEvent(void* win, int event, int (*funct_ptr)(int, void*), void* param) noexcept @@ -73,10 +71,8 @@ namespace mlx::core void Application::getScreenSize(void* win, int* w, int* h) noexcept { CHECK_WINDOW_PTR(win); - SDL_DisplayMode DM; - SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(_graphics[*static_cast(win)]->getWindow()->getNativeWindow()), &DM); - *w = DM.w; - *h = DM.h; + *w = 0; + *h = 0; } void Application::setFPSCap(std::uint32_t fps) noexcept diff --git a/src/core/bridge.cpp b/src/core/bridge.cpp index 43fbfa7..f81b738 100644 --- a/src/core/bridge.cpp +++ b/src/core/bridge.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:00:45 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 23:05:46 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,13 +78,11 @@ extern "C" int mlx_mouse_show() { - SDL_ShowCursor(SDL_ENABLE); return 0; } int mlx_mouse_hide() { - SDL_ShowCursor(SDL_DISABLE); return 0; } diff --git a/src/core/fps.cpp b/src/core/fps.cpp index 2a585e3..e88b489 100644 --- a/src/core/fps.cpp +++ b/src/core/fps.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/18 14:56:17 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:00:54 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:59:13 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,9 +18,9 @@ namespace mlx { void FpsManager::init() { - _timer = SDL_GetTicks64(); - _fps_before = static_cast(std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count()); - _fps_now = static_cast(std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count()); + _timer = static_cast(std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count()); + _fps_before = _timer; + _fps_now = _timer; } bool FpsManager::update() @@ -28,8 +28,8 @@ namespace mlx using namespace std::chrono_literals; _fps_now = static_cast(std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count()); - if(SDL_GetTicks64() - _timer > 1000) - _timer += 1000; + if(std::chrono::duration{_fps_now - _timer} >= 1s) + _timer += _fps_now; _fps_elapsed_time = _fps_now - _fps_before; if(_fps_elapsed_time >= _ns) diff --git a/src/core/fps.h b/src/core/fps.h index 6dacc77..f0d6fbb 100644 --- a/src/core/fps.h +++ b/src/core/fps.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/01/18 14:53:30 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:13:16 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:58:32 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,9 +28,9 @@ namespace mlx private: double _ns = 1000000000.0 / 1'337'000.0; - std::uint64_t _timer = 0; - std::uint64_t _fps_before = 0; - std::uint64_t _fps_now = 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; }; diff --git a/src/core/graphics.cpp b/src/core/graphics.cpp index 66e5fd3..3b8604d 100644 --- a/src/core/graphics.cpp +++ b/src/core/graphics.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:00:58 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 23:02:43 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,11 +71,12 @@ namespace mlx #ifdef GRAPHICS_MEMORY_DUMP // dump memory to file every two seconds - static std::uint64_t timer = SDL_GetTicks64(); - if(SDL_GetTicks64() - timer > 2000) + using namespace std::chrono_literals; + static std::int64_t timer = static_cast(std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count()); + if(std::chrono::duration{static_cast(std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count()) - timer} >= 1s) { Render_Core::get().getAllocator().dumpMemoryToJson(); - timer += 2000; + timer = static_cast(std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count()); } #endif } diff --git a/src/core/graphics.h b/src/core/graphics.h index a23a96d..25b0aa6 100644 --- a/src/core/graphics.h +++ b/src/core/graphics.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:13:11 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 23:00:43 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,18 +53,18 @@ namespace mlx PixelPutPipeline _pixel_put_pipeline; std::vector _drawlist; - + TextManager _text_manager; TextureManager _texture_manager; - + glm::mat4 _proj = glm::mat4(1.0); - + std::shared_ptr _window; std::unique_ptr _renderer; std::size_t _width = 0; std::size_t _height = 0; - + int _id; bool _has_window; diff --git a/src/platform/inputs.cpp b/src/platform/inputs.cpp index fab695a..790b59b 100644 --- a/src/platform/inputs.cpp +++ b/src/platform/inputs.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/05 16:30:19 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:01:09 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 23:13:16 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,130 +24,14 @@ namespace mlx _xRel = 0; _yRel = 0; - while(SDL_PollEvent(&_event)) + static int i = 0; + i++; + if(i >= 150) { - if(_event.type == SDL_MOUSEMOTION) - { - _x = _event.motion.x; - _y = _event.motion.y; - - _xRel = _event.motion.xrel; - _yRel = _event.motion.yrel; - } - - std::uint32_t id = _event.window.windowID; - if(_events_hooks.find(id) == _events_hooks.end()) - continue; - auto& hooks = _events_hooks[id]; - - switch(_event.type) - { - case SDL_KEYDOWN: - { - if(hooks[MLX_KEYDOWN].hook) - hooks[MLX_KEYDOWN].hook(_event.key.keysym.scancode, hooks[MLX_KEYDOWN].param); - break; - } - - case SDL_KEYUP: - { - if(hooks[MLX_KEYUP].hook) - hooks[MLX_KEYUP].hook(_event.key.keysym.scancode, hooks[MLX_KEYUP].param); - break; - } - - case SDL_MOUSEBUTTONDOWN: - { - if(hooks[MLX_MOUSEDOWN].hook) - hooks[MLX_MOUSEDOWN].hook(_event.button.button, hooks[MLX_MOUSEDOWN].param); - break; - } - - case SDL_MOUSEBUTTONUP: - { - if(hooks[MLX_MOUSEUP].hook) - hooks[MLX_MOUSEUP].hook(_event.button.button, hooks[MLX_MOUSEUP].param); - break; - } - - case SDL_MOUSEWHEEL: - { - if(hooks[MLX_MOUSEWHEEL].hook) - { - if(_event.wheel.y > 0) // scroll up - hooks[MLX_MOUSEWHEEL].hook(1, hooks[MLX_MOUSEWHEEL].param); - else if(_event.wheel.y < 0) // scroll down - hooks[MLX_MOUSEWHEEL].hook(2, hooks[MLX_MOUSEWHEEL].param); - - if(_event.wheel.x > 0) // scroll right - hooks[MLX_MOUSEWHEEL].hook(3, hooks[MLX_MOUSEWHEEL].param); - else if(_event.wheel.x < 0) // scroll left - hooks[MLX_MOUSEWHEEL].hook(4, hooks[MLX_MOUSEWHEEL].param); - } - break; - } - - case SDL_WINDOWEVENT: - { - auto& win_hook = hooks[MLX_WINDOW_EVENT]; - switch(_event.window.event) - { - case SDL_WINDOWEVENT_CLOSE: - { - if(win_hook.hook) - win_hook.hook(0, win_hook.param); - break; - } - case SDL_WINDOWEVENT_MOVED: - { - if(win_hook.hook) - win_hook.hook(1, win_hook.param); - break; - } - case SDL_WINDOWEVENT_MINIMIZED: - { - if(win_hook.hook) - win_hook.hook(2, win_hook.param); - break; - } - case SDL_WINDOWEVENT_MAXIMIZED: - { - if(win_hook.hook) - win_hook.hook(3, win_hook.param); - break; - } - case SDL_WINDOWEVENT_ENTER: - { - if(win_hook.hook) - win_hook.hook(4, win_hook.param); - break; - } - case SDL_WINDOWEVENT_FOCUS_GAINED: - { - if(win_hook.hook) - win_hook.hook(5, win_hook.param); - break; - } - case SDL_WINDOWEVENT_LEAVE: - { - if(win_hook.hook) - win_hook.hook(6, win_hook.param); - break; - } - case SDL_WINDOWEVENT_FOCUS_LOST: - { - if(win_hook.hook) - win_hook.hook(7, win_hook.param); - break; - } - - default : break; - } - break; - } - - default: break; - } + auto& hooks = _events_hooks[0]; + auto& win_hook = hooks[MLX_WINDOW_EVENT]; + if(win_hook.hook) + win_hook.hook(0, win_hook.param); } } } diff --git a/src/platform/inputs.h b/src/platform/inputs.h index 39d4e0c..2359dce 100644 --- a/src/platform/inputs.h +++ b/src/platform/inputs.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/05 16:27:35 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:12:44 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 23:03:39 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,7 +58,6 @@ namespace mlx private: std::unordered_map> _windows; std::unordered_map> _events_hooks; - SDL_Event _event; int _x = 0; int _y = 0; diff --git a/src/platform/window.cpp b/src/platform/window.cpp index 5ab88b3..01f031d 100644 --- a/src/platform/window.cpp +++ b/src/platform/window.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:01:14 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:17:34 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,41 +18,23 @@ namespace mlx { - #if SDL_BYTEORDER == SDL_BIG_ENDIAN - constexpr const std::uint32_t rmask = 0xff000000; - constexpr const std::uint32_t gmask = 0x00ff0000; - constexpr const std::uint32_t bmask = 0x0000ff00; - constexpr const std::uint32_t amask = 0x000000ff; - #else - constexpr const std::uint32_t rmask = 0x000000ff; - constexpr const std::uint32_t gmask = 0x0000ff00; - constexpr const std::uint32_t bmask = 0x00ff0000; - constexpr const std::uint32_t amask = 0xff000000; - #endif - MLX_Window::MLX_Window(std::size_t w, std::size_t h, const std::string& title) : _width(w), _height(h) { + static std::uint64_t ids = 0; + if(title.find("vvaas") != std::string::npos) core::error::report(e_kind::message, "vvaas est mauvais"); - _win = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN); - if(!_win) - core::error::report(e_kind::fatal_error, std::string("unable to open a new window, ") + SDL_GetError()); - _id = SDL_GetWindowID(_win); - _icon = SDL_CreateRGBSurfaceFrom(static_cast(logo_mlx), logo_mlx_width, logo_mlx_height, 32, 4 * logo_mlx_width, rmask, gmask, bmask, amask); - SDL_SetWindowIcon(_win, _icon); + glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); + _win = glfwCreateWindow(_width, _height, title.c_str(), NULL, NULL);; + _id = ids++; } void MLX_Window::destroy() noexcept { if(_win != nullptr) { - SDL_DestroyWindow(_win); + glfwDestroyWindow(_win); _win = nullptr; } - if(_icon != nullptr) - { - SDL_FreeSurface(_icon); - _icon = nullptr; - } } } diff --git a/src/platform/window.h b/src/platform/window.h index 754151b..07c4bb2 100644 --- a/src/platform/window.h +++ b/src/platform/window.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:12:46 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:11:21 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ namespace mlx public: MLX_Window(std::size_t w, std::size_t h, const std::string& title); - inline SDL_Window* getNativeWindow() const noexcept { return _win; } + 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; } @@ -30,8 +30,8 @@ namespace mlx ~MLX_Window() = default; private: - SDL_Surface* _icon = nullptr; - SDL_Window* _win = nullptr; + GLFWimage _icon; + GLFWwindow* _win = nullptr; int _width = 0; int _height = 0; std::uint32_t _id = -1; diff --git a/src/pre_compiled.h b/src/pre_compiled.h index 1554c4b..e27194e 100644 --- a/src/pre_compiled.h +++ b/src/pre_compiled.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/25 17:37:23 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:24:26 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:03:44 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,8 +18,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -41,7 +41,6 @@ #include #include #include -#include #include #include #include diff --git a/src/renderer/core/vk_device.cpp b/src/renderer/core/vk_device.cpp index 910b904..7ed8850 100644 --- a/src/renderer/core/vk_device.cpp +++ b/src/renderer/core/vk_device.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:14:29 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:02:11 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:31:54 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,19 +71,11 @@ namespace mlx std::vector devices(deviceCount); vkEnumeratePhysicalDevices(Render_Core::get().getInstance().get(), &deviceCount, devices.data()); - SDL_Window* window = SDL_CreateWindow("", 0, 0, 1, 1, SDL_WINDOW_VULKAN | SDL_WINDOW_HIDDEN); - if(!window) - core::error::report(e_kind::fatal_error, "Vulkan : failed to create a window to pick physical device"); - - VkSurfaceKHR surface = VK_NULL_HANDLE; - if(SDL_Vulkan_CreateSurface(window, Render_Core::get().getInstance().get(), &surface) != SDL_TRUE) - core::error::report(e_kind::fatal_error, "Vulkan : failed to create a surface to pick physical device"); - std::multimap devices_score; for(const auto& device : devices) { - int score = deviceScore(device, surface); + int score = deviceScore(device); devices_score.insert(std::make_pair(score, device)); } @@ -97,23 +89,17 @@ namespace mlx vkGetPhysicalDeviceProperties(_physical_device, &props); core::error::report(e_kind::message, "Vulkan : picked a physical device, %s", props.deviceName); #endif - Render_Core::get().getQueue().findQueueFamilies(_physical_device, surface); // update queue indicies to current physical device - vkDestroySurfaceKHR(Render_Core::get().getInstance().get(), surface, nullptr); - SDL_DestroyWindow(window); + Render_Core::get().getQueue().findQueueFamilies(_physical_device); // update queue indicies to current physical device } - int Device::deviceScore(VkPhysicalDevice device, VkSurfaceKHR surface) + int Device::deviceScore(VkPhysicalDevice device) { - Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(device, surface); + Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(device); bool extensionsSupported = checkDeviceExtensionSupport(device); - std::uint32_t formatCount = 0; - if(extensionsSupported) - vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr); - VkPhysicalDeviceProperties props; vkGetPhysicalDeviceProperties(device, &props); - if(!indices.isComplete() || !extensionsSupported || formatCount == 0) + if(!indices.isComplete() || !extensionsSupported) return -1; VkPhysicalDeviceFeatures features; diff --git a/src/renderer/core/vk_device.h b/src/renderer/core/vk_device.h index 2352f03..564fba1 100644 --- a/src/renderer/core/vk_device.h +++ b/src/renderer/core/vk_device.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:13:42 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:11:56 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:31:46 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,7 +29,7 @@ namespace mlx private: void pickPhysicalDevice(); bool checkDeviceExtensionSupport(VkPhysicalDevice device); - int deviceScore(VkPhysicalDevice device, VkSurfaceKHR surface); + int deviceScore(VkPhysicalDevice device); private: VkPhysicalDevice _physical_device = VK_NULL_HANDLE; diff --git a/src/renderer/core/vk_instance.cpp b/src/renderer/core/vk_instance.cpp index 92b6b36..ad758ae 100644 --- a/src/renderer/core/vk_instance.cpp +++ b/src/renderer/core/vk_instance.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:04:21 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:02:18 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 23:10:37 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -59,34 +59,19 @@ namespace mlx std::vector Instance::getRequiredExtensions() { - std::vector extensions; + std::uint32_t glfw_extension_count = 0; + const char** glfw_extensions = glfwGetRequiredInstanceExtensions(&glfw_extension_count); + + std::vector extensions(glfw_extensions, glfw_extensions + glfw_extension_count); + extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); - - #ifdef VK_USE_PLATFORM_XCB_KHR - extensions.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); - #endif - - #ifdef VK_USE_PLATFORM_XLIB_KHR - extensions.push_back(VK_KHR_XLIB_SURFACE_EXTENSION_NAME); - #endif - - #ifdef VK_USE_PLATFORM_WAYLAND_KHR - extensions.push_back(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME); - #endif - - #ifdef VK_USE_PLATFORM_WIN32_KHR - extensions.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); - #endif - - #ifdef VK_USE_PLATFORM_METAL_EXT - extensions.push_back(VK_EXT_METAL_SURFACE_EXTENSION_NAME); - #endif if constexpr(enableValidationLayers) { extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); } + return extensions; } diff --git a/src/renderer/core/vk_queues.cpp b/src/renderer/core/vk_queues.cpp index 6f89926..b47fcf0 100644 --- a/src/renderer/core/vk_queues.cpp +++ b/src/renderer/core/vk_queues.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:02:42 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:02:20 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:29:19 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ namespace mlx { - Queues::QueueFamilyIndices Queues::findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface) + Queues::QueueFamilyIndices Queues::findQueueFamilies(VkPhysicalDevice device) { std::uint32_t queueFamilyCount = 0; vkGetPhysicalDeviceQueueFamilyProperties(device, &queueFamilyCount, nullptr); @@ -31,10 +31,7 @@ namespace mlx if(queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) _families->graphics_family = i; - VkBool32 presentSupport = false; - vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport); - - if(presentSupport) + if(glfwGetPhysicalDevicePresentationSupport(Render_Core::get().getInstance().get(), device, i)) _families->present_family = i; if(_families->isComplete()) @@ -48,20 +45,7 @@ namespace mlx void Queues::init() { if(!_families.has_value()) - { - SDL_Window* window = SDL_CreateWindow("", 0, 0, 1, 1, SDL_WINDOW_VULKAN | SDL_WINDOW_HIDDEN); - if(!window) - core::error::report(e_kind::fatal_error, "Vulkan : failed to create a window to init queues"); - - VkSurfaceKHR surface = VK_NULL_HANDLE; - if(SDL_Vulkan_CreateSurface(window, Render_Core::get().getInstance().get(), &surface) != SDL_TRUE) - core::error::report(e_kind::fatal_error, "Vulkan : failed to create a surface to init queues"); - - findQueueFamilies(Render_Core::get().getDevice().getPhysicalDevice(), surface); - - vkDestroySurfaceKHR(Render_Core::get().getInstance().get(), surface, nullptr); - SDL_DestroyWindow(window); - } + findQueueFamilies(Render_Core::get().getDevice().getPhysicalDevice()); vkGetDeviceQueue(Render_Core::get().getDevice().get(), _families->graphics_family.value(), 0, &_graphics_queue); vkGetDeviceQueue(Render_Core::get().getDevice().get(), _families->present_family.value(), 0, &_present_queue); #ifdef DEBUG diff --git a/src/renderer/core/vk_queues.h b/src/renderer/core/vk_queues.h index 832bc50..4895c9c 100644 --- a/src/renderer/core/vk_queues.h +++ b/src/renderer/core/vk_queues.h @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 19:01:49 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:11:46 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:29:26 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,7 @@ namespace mlx inline bool isComplete() { return graphics_family.has_value() && present_family.has_value(); } }; - QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device, VkSurfaceKHR surface); + QueueFamilyIndices findQueueFamilies(VkPhysicalDevice device); void init(); diff --git a/src/renderer/core/vk_surface.cpp b/src/renderer/core/vk_surface.cpp index e1708a6..b50a5f2 100644 --- a/src/renderer/core/vk_surface.cpp +++ b/src/renderer/core/vk_surface.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/08 18:58:49 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:00:11 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 22:25:55 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,8 @@ namespace mlx { void Surface::create(Renderer& renderer) { - if(SDL_Vulkan_CreateSurface(renderer.getWindow()->getNativeWindow(), Render_Core::get().getInstance().get(), &_surface) != SDL_TRUE) - core::error::report(e_kind::fatal_error, "Vulkan : failed to create a surface : %s", SDL_GetError()); + if(glfwCreateWindowSurface(Render_Core::get().getInstance().get(), renderer.getWindow()->getNativeWindow(), NULL, &_surface) != VK_SUCCESS) + core::error::report(e_kind::fatal_error, "Vulkan : failed to create a surface"); #ifdef DEBUG core::error::report(e_kind::message, "Vulkan : created new surface"); #endif diff --git a/src/renderer/swapchain/vk_swapchain.cpp b/src/renderer/swapchain/vk_swapchain.cpp index 223f8bc..485d413 100644 --- a/src/renderer/swapchain/vk_swapchain.cpp +++ b/src/renderer/swapchain/vk_swapchain.cpp @@ -6,7 +6,7 @@ /* By: maldavid +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/10/06 18:22:28 by maldavid #+# #+# */ -/* Updated: 2024/03/25 19:03:41 by maldavid ### ########.fr */ +/* Updated: 2024/03/25 23:09:33 by maldavid ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ namespace mlx if(_swapchain_support.capabilities.maxImageCount > 0 && imageCount > _swapchain_support.capabilities.maxImageCount) imageCount = _swapchain_support.capabilities.maxImageCount; - Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(Render_Core::get().getDevice().getPhysicalDevice(), renderer->getSurface().get()); + Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(Render_Core::get().getDevice().getPhysicalDevice()); std::uint32_t queueFamilyIndices[] = { indices.graphics_family.value(), indices.present_family.value() }; VkSwapchainCreateInfoKHR createInfo{}; @@ -123,7 +123,7 @@ namespace mlx return capabilities.currentExtent; int width, height; - SDL_Vulkan_GetDrawableSize(_renderer->getWindow()->getNativeWindow(), &width, &height); + glfwGetFramebufferSize(_renderer->getWindow()->getNativeWindow(), &width, &height); VkExtent2D actualExtent = { static_cast(width), static_cast(height) };