mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 08:15:38 +07:00
bind_context window function. move vsync option to swap_buffers.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace e2d
|
||||
};
|
||||
using event_listener_uptr = std::unique_ptr<event_listener>;
|
||||
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 >
|
||||
|
||||
@@ -10,8 +10,7 @@ using namespace e2d;
|
||||
int e2d_main() {
|
||||
input& i = modules::initialize<input>();
|
||||
debug& d = modules::initialize<debug>();
|
||||
window& w = modules::initialize<window>(
|
||||
v2u{640, 480}, "Enduro2D", true, false);
|
||||
window& w = modules::initialize<window>(v2u{640, 480}, "Enduro2D", false);
|
||||
|
||||
d.add_sink<debug_console_sink>();
|
||||
w.register_event_listener<window_input_source>(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;
|
||||
|
||||
@@ -10,8 +10,7 @@ using namespace e2d;
|
||||
int e2d_main() {
|
||||
input& i = modules::initialize<input>();
|
||||
debug& d = modules::initialize<debug>();
|
||||
window& w = modules::initialize<window>(
|
||||
v2u{640, 480}, "Enduro2D", true, false);
|
||||
window& w = modules::initialize<window>(v2u{640, 480}, "Enduro2D", false);
|
||||
|
||||
d.add_sink<debug_console_sink>();
|
||||
w.register_event_listener<window_input_source>(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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
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<std::recursive_mutex> guard(state_->rmutex);
|
||||
return state_->vsync;
|
||||
}
|
||||
|
||||
bool window::fullscreen() const noexcept {
|
||||
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
|
||||
return state_->fullscreen;
|
||||
}
|
||||
|
||||
bool window::toggle_vsync(bool yesno) noexcept {
|
||||
std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> guard(state_->rmutex);
|
||||
E2D_ASSERT(state_->window);
|
||||
glfwMakeContextCurrent(state_->window.get());
|
||||
}
|
||||
|
||||
void window::swap_buffers(bool vsync) noexcept {
|
||||
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
|
||||
E2D_ASSERT(state_->window);
|
||||
glfwSwapInterval(vsync ? 1 : 0);
|
||||
glfwSwapBuffers(state_->window.get());
|
||||
}
|
||||
|
||||
|
||||
@@ -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<std::recursive_mutex> guard(state_->rmutex);
|
||||
return state_->vsync;
|
||||
}
|
||||
|
||||
bool window::fullscreen() const noexcept {
|
||||
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
|
||||
return state_->fullscreen;
|
||||
}
|
||||
|
||||
bool window::toggle_vsync(bool yesno) noexcept {
|
||||
std::lock_guard<std::recursive_mutex> guard(state_->rmutex);
|
||||
state_->vsync = yesno;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool window::toggle_fullscreen(bool yesno) noexcept {
|
||||
std::lock_guard<std::recursive_mutex> 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 {
|
||||
|
||||
Reference in New Issue
Block a user