Add app::options structure with creation options & add highdpi support
This commit is contained in:
parent
773bfc6971
commit
38f704c3ed
2 changed files with 23 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue