From 38f704c3ed0c3cced19bf7129d3e5f31cbe0fea6 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 28 May 2021 12:14:41 +0300 Subject: [PATCH] Add app::options structure with creation options & add highdpi support --- libs/app/include/psemek/app/app.hpp | 7 +++++++ libs/app/source/app.cpp | 21 ++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libs/app/include/psemek/app/app.hpp b/libs/app/include/psemek/app/app.hpp index 7c4d9c2b..72ec4f16 100644 --- a/libs/app/include/psemek/app/app.hpp +++ b/libs/app/include/psemek/app/app.hpp @@ -14,8 +14,15 @@ namespace psemek::app struct app : scene_base { + struct options + { + int multisampling = 0; + bool highdpi = false; + }; + app(std::string const & name); app(std::string const & name, int multisampling); + app(std::string const & name, options const & opts); ~app() override; virtual bool running() const; diff --git a/libs/app/source/app.cpp b/libs/app/source/app.cpp index d92a3038..7bc63c1e 100644 --- a/libs/app/source/app.cpp +++ b/libs/app/source/app.cpp @@ -52,6 +52,10 @@ namespace psemek::app {} app::app(std::string const & name, int multisampling) + : app(name, options{multisampling}) + {} + + app::app(std::string const & name, options const & opts) : pimpl_{make_impl(this)} { impl().start_time = clock::now(); @@ -65,17 +69,20 @@ namespace psemek::app SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - if (multisampling == 0) + if (opts.multisampling == 0) { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); } else { SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); - SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, multisampling); + SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, opts.multisampling); } - impl().window = SDL_CreateWindow(name.data(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_MAXIMIZED | SDL_WINDOW_HIDDEN); + std::uint32_t flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_MAXIMIZED | SDL_WINDOW_HIDDEN; + if (opts.highdpi) flags |= SDL_WINDOW_ALLOW_HIGHDPI; + + impl().window = SDL_CreateWindow(name.data(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, flags); if (!impl().window) sdl2::fail("Failed to create window: "); @@ -97,7 +104,7 @@ namespace psemek::app log::info() << "Initialized OpenGL " << major << '.' << minor << ", " << vendor << ", " << renderer; int width, height; - SDL_GetWindowSize(impl().window, &width, &height); + SDL_GL_GetDrawableSize(impl().window, &width, &height); scene_base::on_resize(width, height); } @@ -138,7 +145,11 @@ namespace psemek::app { case SDL_WINDOWEVENT_RESIZED: impl().had_initial_resize = true; - handler()->on_resize(e.window.data1, e.window.data2); + { + int width, height; + SDL_GL_GetDrawableSize(impl().window, &width, &height); + handler()->on_resize(width, height); + } break; case SDL_WINDOWEVENT_FOCUS_GAINED: handler()->on_focus_gained();