diff --git a/samples/sources/sample_00/sample_00.cpp b/samples/sources/sample_00/sample_00.cpp index c0fdfe8a..e85e2519 100644 --- a/samples/sources/sample_00/sample_00.cpp +++ b/samples/sources/sample_00/sample_00.cpp @@ -186,7 +186,7 @@ namespace the().execute(render::command_block<64>() .add_command(render::viewport_command( - the().real_size())) + the().framebuffer_size())) .add_command(render::clear_command() .color_value({1.f, 0.4f, 0.f, 1.f})) .add_command(render::draw_command(material_, geometry_))); diff --git a/samples/sources/sample_01/sample_01.cpp b/samples/sources/sample_01/sample_01.cpp index ff692a15..63f315b7 100644 --- a/samples/sources/sample_01/sample_01.cpp +++ b/samples/sources/sample_01/sample_01.cpp @@ -252,7 +252,7 @@ namespace the().execute(render::command_block<64>() .add_command(render::viewport_command( - the().real_size())) + the().framebuffer_size())) .add_command(render::clear_command() .color_value({1.f, 0.4f, 0.f, 1.f})) .add_command(render::draw_command(material_, geometry_))); diff --git a/samples/sources/sample_02/sample_02.cpp b/samples/sources/sample_02/sample_02.cpp index 539578a1..1fd0a8a3 100644 --- a/samples/sources/sample_02/sample_02.cpp +++ b/samples/sources/sample_02/sample_02.cpp @@ -231,8 +231,8 @@ namespace .add_command(render::target_command(nullptr)) .add_command(render::clear_command() .color_value(color::blue())) - .add_command(render::viewport_command(the().real_size()) - .scissor_rect(make_rect(v2u{100u}, the().real_size() - 200u))) + .add_command(render::viewport_command(the().framebuffer_size()) + .scissor_rect(make_rect(v2u{100u}, the().framebuffer_size() - 200u))) .add_command(render::clear_command() .color_value({1.f, 0.4f, 0.f, 1.f})) .add_command(render::draw_command(material_, geometry_, rt_props_))); diff --git a/samples/sources/sample_03/sample_03.cpp b/samples/sources/sample_03/sample_03.cpp index 66babb27..f703da1a 100644 --- a/samples/sources/sample_03/sample_03.cpp +++ b/samples/sources/sample_03/sample_03.cpp @@ -47,7 +47,7 @@ namespace [](const ecs::const_entity&, camera& cam){ if ( !cam.target() ) { cam.viewport( - the().real_size()); + the().framebuffer_size()); cam.projection(math::make_orthogonal_lh_matrix4( the().real_size().cast_to(), 0.f, 1000.f)); } diff --git a/samples/sources/sample_04/sample_04.cpp b/samples/sources/sample_04/sample_04.cpp index c334f89e..49d6df4c 100644 --- a/samples/sources/sample_04/sample_04.cpp +++ b/samples/sources/sample_04/sample_04.cpp @@ -43,7 +43,7 @@ namespace [](const ecs::const_entity&, camera& cam){ if ( !cam.target() ) { cam.viewport( - the().real_size()); + the().framebuffer_size()); cam.projection(math::make_orthogonal_lh_matrix4( the().real_size().cast_to(), 0.f, 1000.f)); } diff --git a/samples/sources/sample_05/sample_05.cpp b/samples/sources/sample_05/sample_05.cpp index f78f3231..5d736c47 100644 --- a/samples/sources/sample_05/sample_05.cpp +++ b/samples/sources/sample_05/sample_05.cpp @@ -67,7 +67,7 @@ namespace void frame_render() final { the().execute(render::command_block<64>() .add_command(render::viewport_command( - the().real_size())) + the().framebuffer_size())) .add_command(render::clear_command() .color_value({1.f, 0.4f, 0.f, 1.f}))); } diff --git a/samples/sources/sample_06/sample_06.cpp b/samples/sources/sample_06/sample_06.cpp index d0f1ac62..761ce38c 100644 --- a/samples/sources/sample_06/sample_06.cpp +++ b/samples/sources/sample_06/sample_06.cpp @@ -82,7 +82,7 @@ namespace [](const ecs::const_entity&, camera& cam){ if ( !cam.target() ) { cam.viewport( - the().real_size()); + the().framebuffer_size()); cam.projection(math::make_orthogonal_lh_matrix4( the().real_size().cast_to(), 0.f, 1000.f)); } diff --git a/sources/enduro2d/core/dbgui.cpp b/sources/enduro2d/core/dbgui.cpp index 7b2d7dd7..a941c6fa 100644 --- a/sources/enduro2d/core/dbgui.cpp +++ b/sources/enduro2d/core/dbgui.cpp @@ -130,8 +130,12 @@ namespace e2d k.is_key_pressed(keyboard_key::lsuper) || k.is_key_pressed(keyboard_key::rsuper); - io.DisplaySize = window_.real_size().cast_to(); - io.DisplayFramebufferScale = v2f::unit(); + io.DisplaySize = + window_.real_size().cast_to(); + + io.DisplayFramebufferScale = + window_.framebuffer_size().cast_to() / + window_.real_size().cast_to(); if ( ImGui::GetFrameCount() > 0 ) { ImGui::EndFrame(); @@ -149,7 +153,7 @@ namespace e2d } const v2f display_size = draw_data->DisplaySize; - const b2f display_size_r = make_rect(display_size); + const v2f framebuffer_size = display_size * v2f(draw_data->FramebufferScale); const m4f projection = math::make_translation_matrix4(display_size * v2f(-0.5f, 0.5f)) * @@ -175,13 +179,14 @@ namespace e2d const ImDrawCmd& pcmd = cmd_list->CmdBuffer[cmd_i]; const b2f clip_r( - pcmd.ClipRect.x, - display_size.y - pcmd.ClipRect.w, - pcmd.ClipRect.z - pcmd.ClipRect.x, - pcmd.ClipRect.w - pcmd.ClipRect.y); + (pcmd.ClipRect.x) * draw_data->FramebufferScale.x, + (display_size.y - pcmd.ClipRect.w) * draw_data->FramebufferScale.y, + (pcmd.ClipRect.z - pcmd.ClipRect.x) * draw_data->FramebufferScale.x, + (pcmd.ClipRect.w - pcmd.ClipRect.y) * draw_data->FramebufferScale.y); if ( math::minimum(clip_r.position) >= 0.f - && math::overlaps(clip_r, display_size_r) ) + && clip_r.position.x + clip_r.size.x <= framebuffer_size.x + && clip_r.position.y + clip_r.size.y <= framebuffer_size.y ) { texture_ptr texture = pcmd.TextureId ? *static_cast(pcmd.TextureId) @@ -196,7 +201,7 @@ namespace e2d render_.execute(render::command_block<8>() .add_command(render::viewport_command( - display_size_r.cast_to(), + framebuffer_size.cast_to(), clip_r.cast_to())) .add_command(render::draw_command(material_, geometry, mprops_) .index_range(first_index, pcmd.ElemCount))); diff --git a/sources/enduro2d/core/window_impl/window_glfw.cpp b/sources/enduro2d/core/window_impl/window_glfw.cpp index bbd112a9..f7da53d0 100644 --- a/sources/enduro2d/core/window_impl/window_glfw.cpp +++ b/sources/enduro2d/core/window_impl/window_glfw.cpp @@ -283,7 +283,9 @@ namespace e2d throw bad_window_operation(); } - update_window_sizes(); + update_window_size(); + update_framebuffer_size(); + glfwSetWindowUserPointer(window.get(), this); glfwSetCharCallback(window.get(), input_char_callback_); @@ -291,7 +293,10 @@ namespace e2d glfwSetScrollCallback(window.get(), mouse_scroll_callback_); glfwSetMouseButtonCallback(window.get(), mouse_button_callback_); glfwSetKeyCallback(window.get(), keyboard_key_callback_); + glfwSetWindowSizeCallback(window.get(), window_size_callback_); + glfwSetFramebufferSizeCallback(window.get(), window_framebuffer_callback_); + glfwSetWindowCloseCallback(window.get(), window_close_callback_); glfwSetWindowFocusCallback(window.get(), window_focus_callback_); glfwSetWindowIconifyCallback(window.get(), window_minimize_callback_); @@ -302,19 +307,20 @@ namespace e2d window.reset(); } - void update_window_sizes() noexcept { + void update_window_size() noexcept { std::lock_guard guard(rmutex); E2D_ASSERT(window); - { - int w = 0, h = 0; - glfwGetWindowSize(window.get(), &w, &h); - real_size = make_vec2(w, h).cast_to(); - } - { - int w = 0, h = 0; - glfwGetFramebufferSize(window.get(), &w, &h); - framebuffer_size = make_vec2(w, h).cast_to(); - } + int w = 0, h = 0; + glfwGetWindowSize(window.get(), &w, &h); + real_size = make_vec2(w, h).cast_to(); + } + + void update_framebuffer_size() noexcept { + std::lock_guard guard(rmutex); + E2D_ASSERT(window); + int w = 0, h = 0; + glfwGetFramebufferSize(window.get(), &w, &h); + framebuffer_size = make_vec2(w, h).cast_to(); } template < typename F, typename... Args > @@ -352,9 +358,6 @@ namespace e2d glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); - glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE); - glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_FALSE); - glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, GLFW_FALSE); #if defined(E2D_BUILD_MODE) && E2D_BUILD_MODE == E2D_BUILD_MODE_DEBUG glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); #endif @@ -428,7 +431,15 @@ namespace e2d E2D_UNUSED(w, h); state* self = static_cast(glfwGetWindowUserPointer(window)); if ( self ) { - self->update_window_sizes(); + self->update_window_size(); + } + } + + static void window_framebuffer_callback_(GLFWwindow* window, int w, int h) noexcept { + E2D_UNUSED(w, h); + state* self = static_cast(glfwGetWindowUserPointer(window)); + if ( self ) { + self->update_framebuffer_size(); } }