From 104704391b534c3108b26c2d990a561a67a2fd03 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Fri, 5 Oct 2018 00:02:36 +0200 Subject: [PATCH] SDL: allow fullscreen applications. If resolution is set to (0,0) then a fullscreen app is created. --- src/application/application.cpp | 56 ++++++++++++++------------------- src/application/application.h | 4 ++- src/platform/sdl/sdlapp.cpp | 25 ++++++++++----- src/platform/sdl/sdlapp.h | 7 +++-- src/scene.h | 4 ++- 5 files changed, 51 insertions(+), 45 deletions(-) diff --git a/src/application/application.cpp b/src/application/application.cpp index 1bc2331f..c6cc780e 100644 --- a/src/application/application.cpp +++ b/src/application/application.cpp @@ -41,7 +41,7 @@ public: virtual ~null_display() {} protected: - void SetResolution(ivec2) {} + void set_resolution(ivec2) {} void SetPosition(ivec2) {} void Enable() {} @@ -63,28 +63,11 @@ class ApplicationDisplayData { friend class ApplicationDisplay; - ApplicationDisplayData(char const *name, ivec2 resolution) - : display(name, resolution) + ApplicationDisplayData(char const *name, ivec2 res) + : display(name, res) { } protected: - void SetResolution(ivec2 resolution) - { - display.SetResolution(resolution); - } - void SetPosition(ivec2 position) - { - display.SetPosition(position); - } - void Enable() - { - display.Enable(); - } - void Disable() - { - display.Disable(); - } - #if __native_client__ //NOT HANDLED YET #elif __ANDROID__ @@ -99,9 +82,9 @@ protected: #endif }; -ApplicationDisplay::ApplicationDisplay(char const *name, ivec2 resolution) +ApplicationDisplay::ApplicationDisplay(char const *name, ivec2 res) { - data = new ApplicationDisplayData(name, resolution); + data = new ApplicationDisplayData(name, res); } ApplicationDisplay::~ApplicationDisplay() @@ -109,29 +92,35 @@ ApplicationDisplay::~ApplicationDisplay() delete data; } -void ApplicationDisplay::SetResolution(ivec2 resolution) +ivec2 ApplicationDisplay::resolution() const { - super::SetResolution(resolution); + return data->display.resolution(); +} - data->SetResolution(resolution); +void ApplicationDisplay::set_resolution(ivec2 res) +{ + super::set_resolution(res); + + data->display.set_resolution(res); } + void ApplicationDisplay::SetPosition(ivec2 position) { super::SetPosition(position); - data->SetPosition(position); + data->display.SetPosition(position); } void ApplicationDisplay::Enable() { super::Enable(); - data->Enable(); + data->display.Enable(); } void ApplicationDisplay::Disable() { - data->Disable(); + data->display.Disable(); super::Disable(); } @@ -141,8 +130,8 @@ class ApplicationData { friend class Application; - ApplicationData(char const *name, ivec2 resolution, float framerate) - : app(name, resolution, framerate) + ApplicationData(char const *name, ivec2 res, float framerate) + : app(name, res, framerate) { } #if __native_client__ @@ -172,10 +161,11 @@ static void AppCallback() * Public Application class */ -Application::Application(char const *name, ivec2 resolution, float framerate) +Application::Application(char const *name, ivec2 res, float framerate) { - SceneDisplay::Add(new ApplicationDisplay(name, resolution)); - data = new ApplicationData(name, resolution, framerate); + auto app_display = new ApplicationDisplay(name, res); + SceneDisplay::Add(app_display); + data = new ApplicationData(name, app_display->resolution(), framerate); } bool Application::MustTick() diff --git a/src/application/application.h b/src/application/application.h index 64fa7d66..d279fb8e 100644 --- a/src/application/application.h +++ b/src/application/application.h @@ -31,7 +31,9 @@ public: virtual ~ApplicationDisplay(); /* pos/size/... methods */ - virtual void SetResolution(ivec2 resolution); + virtual void set_resolution(ivec2 resolution); + virtual ivec2 resolution() const; + virtual void SetPosition(ivec2 position); protected: diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index 96e66316..feeb0727 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -54,7 +54,6 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) { #if LOL_USE_SDL ivec2 window_size = res; - ivec2 screen_size = res; /* Initialise SDL */ if (!SDL_WasInit(0)) @@ -66,15 +65,16 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) } } -#if LOL_USE_SDL /* This seems to fix the swap context bug. * However, perfs warning have been may occur. */ SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); - data->m_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, - SDL_WINDOWPOS_UNDEFINED, - window_size.x, window_size.y, - SDL_WINDOW_OPENGL); + int flags = SDL_WINDOW_OPENGL; + if (window_size == ivec2(0)) + flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + data->m_window = SDL_CreateWindow(title, + SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + window_size.x, window_size.y, flags); if (!data->m_window) { msg::error("cannot create rendering window: %s\n", SDL_GetError()); @@ -84,7 +84,6 @@ SdlAppDisplay::SdlAppDisplay(char const *title, ivec2 res) SDL_GetWindowSize(data->m_window, &res.x, &res.y); data->m_glcontext = SDL_GL_CreateContext(data->m_window); -#endif /* Initialise everything */ Video::Setup(res); //TODO ?? Should it be here ? @@ -104,12 +103,22 @@ SdlAppDisplay::~SdlAppDisplay() delete data; } -void SdlAppDisplay::SetResolution(ivec2 resolution) +ivec2 SdlAppDisplay::resolution() const +{ + ivec2 ret(0); +#if LOL_USE_SDL + SDL_GetWindowSize(data->m_window, &ret.x, &ret.y); +#endif + return ret; +} + +void SdlAppDisplay::set_resolution(ivec2 resolution) { #if LOL_USE_SDL SDL_SetWindowSize(data->m_window, resolution.x, resolution.y); #endif } + void SdlAppDisplay::SetPosition(ivec2 position) { #if LOL_USE_SDL diff --git a/src/platform/sdl/sdlapp.h b/src/platform/sdl/sdlapp.h index 89029112..3f6d49ae 100644 --- a/src/platform/sdl/sdlapp.h +++ b/src/platform/sdl/sdlapp.h @@ -25,13 +25,16 @@ class SdlAppDisplayData; class SdlAppDisplay { - friend class ApplicationDisplayData; + friend class ApplicationDisplay; + public: SdlAppDisplay(char const *title, ivec2 resolution); virtual ~SdlAppDisplay(); protected: - void SetResolution(ivec2 resolution); + virtual void set_resolution(ivec2 resolution); + virtual ivec2 resolution() const; + void SetPosition(ivec2 position); void Enable(); diff --git a/src/scene.h b/src/scene.h index 58867e5e..b1180388 100644 --- a/src/scene.h +++ b/src/scene.h @@ -68,7 +68,9 @@ public: virtual ~SceneDisplay() { } /* pos/size/... methods */ - virtual void SetResolution(ivec2 resolution) { UNUSED(resolution); } + virtual void set_resolution(ivec2 resolution) { UNUSED(resolution); } + virtual ivec2 resolution() const { return ivec2(0); } + virtual void SetPosition(ivec2 position) { UNUSED(position); } /* TODO: Should that be there or in Video ? */