diff --git a/CMakeLists.txt b/CMakeLists.txt index 362ed62c..f66569c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,7 @@ if(APPLE) find_library(Foundation Foundation) endif(APPLE) +set(GLFW_INSTALL OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) diff --git a/headers/enduro2d/core/window.hpp b/headers/enduro2d/core/window.hpp index a9c00b19..c02ba712 100644 --- a/headers/enduro2d/core/window.hpp +++ b/headers/enduro2d/core/window.hpp @@ -33,7 +33,7 @@ namespace e2d }; using event_listener_uptr = std::unique_ptr; public: - window(const v2u& size, str_view title, bool vsync, bool fullscreen); + window(const v2u& size, str_view title, bool fullscreen); ~window() noexcept; void hide() noexcept; @@ -45,10 +45,7 @@ namespace e2d bool focused() const noexcept; bool minimized() const noexcept; - bool vsync() const noexcept; bool fullscreen() const noexcept; - - bool toggle_vsync(bool yesno) noexcept; bool toggle_fullscreen(bool yesno) noexcept; void hide_cursor() noexcept; @@ -65,7 +62,8 @@ namespace e2d bool should_close() const noexcept; void set_should_close(bool yesno) noexcept; - void swap_buffers() noexcept; + void bind_context() noexcept; + void swap_buffers(bool vsync) noexcept; static bool frame_tick() noexcept; template < typename T, typename... Args > diff --git a/samples/sources/sample_00/sample_00.cpp b/samples/sources/sample_00/sample_00.cpp index 52e7c92a..66f96cfe 100644 --- a/samples/sources/sample_00/sample_00.cpp +++ b/samples/sources/sample_00/sample_00.cpp @@ -10,8 +10,7 @@ using namespace e2d; int e2d_main() { input& i = modules::initialize(); debug& d = modules::initialize(); - window& w = modules::initialize( - v2u{640, 480}, "Enduro2D", true, false); + window& w = modules::initialize(v2u{640, 480}, "Enduro2D", false); d.add_sink(); w.register_event_listener(i); @@ -24,7 +23,7 @@ int e2d_main() { const keyboard& k = i.keyboard(); while ( !w.should_close() && !k.is_key_just_released(keyboard_key::escape) ) { i.frame_tick(); - w.swap_buffers(); + w.swap_buffers(true); window::frame_tick(); } return 0; diff --git a/samples/sources/sample_01/sample_01.cpp b/samples/sources/sample_01/sample_01.cpp index 52e7c92a..66f96cfe 100644 --- a/samples/sources/sample_01/sample_01.cpp +++ b/samples/sources/sample_01/sample_01.cpp @@ -10,8 +10,7 @@ using namespace e2d; int e2d_main() { input& i = modules::initialize(); debug& d = modules::initialize(); - window& w = modules::initialize( - v2u{640, 480}, "Enduro2D", true, false); + window& w = modules::initialize(v2u{640, 480}, "Enduro2D", false); d.add_sink(); w.register_event_listener(i); @@ -24,7 +23,7 @@ int e2d_main() { const keyboard& k = i.keyboard(); while ( !w.should_close() && !k.is_key_just_released(keyboard_key::escape) ) { i.frame_tick(); - w.swap_buffers(); + w.swap_buffers(true); window::frame_tick(); } return 0; diff --git a/sources/enduro2d/core/window_impl/window_glfw.cpp b/sources/enduro2d/core/window_impl/window_glfw.cpp index cd5c395d..3522c8c5 100644 --- a/sources/enduro2d/core/window_impl/window_glfw.cpp +++ b/sources/enduro2d/core/window_impl/window_glfw.cpp @@ -257,17 +257,15 @@ namespace e2d window_uptr window; v2u virtual_size; str title; - bool vsync = false; bool fullscreen = false; bool cursor_hidden = false; - char _pad[5]; + char _pad[6]; public: - state(const v2u& size, str_view title, bool vsync, bool fullscreen) + state(const v2u& size, str_view title, bool fullscreen) : shared_state(glfw_state::get_shared_state()) - , window(open_window_(size, make_utf8(title), vsync, fullscreen)) + , window(open_window_(size, make_utf8(title), fullscreen)) , virtual_size(size) , title(title) - , vsync(vsync) , fullscreen(fullscreen) , cursor_hidden(false) { @@ -309,7 +307,7 @@ namespace e2d } private: static window_uptr open_window_( - const v2u& virtual_size, const str& title, bool vsync, bool fullscreen) noexcept + const v2u& virtual_size, const str& title, bool fullscreen) noexcept { GLFWmonitor* monitor = glfwGetPrimaryMonitor(); if ( !monitor ) { @@ -333,10 +331,7 @@ namespace e2d title.c_str(), fullscreen ? monitor : nullptr, nullptr); - if ( w ) { - glfwMakeContextCurrent(w); - glfwSwapInterval(vsync ? 1 : 0); - } + glfwMakeContextCurrent(w); return {w, glfwDestroyWindow}; } @@ -421,8 +416,8 @@ namespace e2d // class window // - window::window(const v2u& size, str_view title, bool vsync, bool fullscreen) - : state_(new state(size, title, vsync, fullscreen)) {} + window::window(const v2u& size, str_view title, bool fullscreen) + : state_(new state(size, title, fullscreen)) {} window::~window() noexcept = default; void window::hide() noexcept { @@ -467,25 +462,11 @@ namespace e2d return GLFW_TRUE == glfwGetWindowAttrib(state_->window.get(), GLFW_ICONIFIED); } - bool window::vsync() const noexcept { - std::lock_guard guard(state_->rmutex); - return state_->vsync; - } - bool window::fullscreen() const noexcept { std::lock_guard guard(state_->rmutex); return state_->fullscreen; } - bool window::toggle_vsync(bool yesno) noexcept { - std::lock_guard guard(state_->rmutex); - E2D_ASSERT(state_->window); - glfwMakeContextCurrent(state_->window.get()); - glfwSwapInterval(yesno ? 1 : 0); - state_->vsync = yesno; - return true; - } - bool window::toggle_fullscreen(bool yesno) noexcept { std::lock_guard guard(state_->rmutex); if ( state_->fullscreen == yesno ) { @@ -579,9 +560,16 @@ namespace e2d glfwSetWindowShouldClose(state_->window.get(), yesno ? GLFW_TRUE : GLFW_FALSE); } - void window::swap_buffers() noexcept { + void window::bind_context() noexcept { std::lock_guard guard(state_->rmutex); E2D_ASSERT(state_->window); + glfwMakeContextCurrent(state_->window.get()); + } + + void window::swap_buffers(bool vsync) noexcept { + std::lock_guard guard(state_->rmutex); + E2D_ASSERT(state_->window); + glfwSwapInterval(vsync ? 1 : 0); glfwSwapBuffers(state_->window.get()); } diff --git a/sources/enduro2d/core/window_impl/window_none.cpp b/sources/enduro2d/core/window_impl/window_none.cpp index 0b025aa6..01218052 100644 --- a/sources/enduro2d/core/window_impl/window_none.cpp +++ b/sources/enduro2d/core/window_impl/window_none.cpp @@ -18,19 +18,17 @@ namespace e2d std::recursive_mutex rmutex; v2u virtual_size; str title; - bool vsync = false; bool fullscreen = false; bool cursor_hidden = false; bool should_close = false; bool visible = true; bool focused = true; bool minimized = false; - char _pad[1]; + char _pad[2]; public: - state(const v2u& size, str_view title, bool vsync, bool fullscreen) + state(const v2u& size, str_view title, bool fullscreen) : virtual_size(size) , title(make_utf8(title)) - , vsync(vsync) , fullscreen(fullscreen) {} ~state() noexcept = default; @@ -45,8 +43,8 @@ namespace e2d } }; - window::window(const v2u& size, str_view title, bool vsync, bool fullscreen) - : state_(new state(size, title, vsync, fullscreen)) {} + window::window(const v2u& size, str_view title, bool fullscreen) + : state_(new state(size, title, fullscreen)) {} window::~window() noexcept = default; void window::hide() noexcept { @@ -98,22 +96,11 @@ namespace e2d return state_->minimized; } - bool window::vsync() const noexcept { - std::lock_guard guard(state_->rmutex); - return state_->vsync; - } - bool window::fullscreen() const noexcept { std::lock_guard guard(state_->rmutex); return state_->fullscreen; } - bool window::toggle_vsync(bool yesno) noexcept { - std::lock_guard guard(state_->rmutex); - state_->vsync = yesno; - return true; - } - bool window::toggle_fullscreen(bool yesno) noexcept { std::lock_guard guard(state_->rmutex); state_->fullscreen = yesno; @@ -170,7 +157,11 @@ namespace e2d state_->should_close = yesno; } - void window::swap_buffers() noexcept { + void window::bind_context() noexcept { + } + + void window::swap_buffers(bool vsync) noexcept { + E2D_UNUSED(vsync); } bool window::frame_tick() noexcept {