Browse Source

Since the SDL window is not API-specific, move it into Graphics from GraphicsImpl to simplify code.

Lasse Öörni 9 years ago
parent
commit
fd5bac385a

+ 1 - 2
Source/Urho3D/Engine/Application.cpp

@@ -28,7 +28,6 @@
 
 
 #ifdef IOS
 #ifdef IOS
 #include "../Graphics/Graphics.h"
 #include "../Graphics/Graphics.h"
-#include "../Graphics/GraphicsImpl.h"
 #include <SDL/SDL.h>
 #include <SDL/SDL.h>
 #endif
 #endif
 
 
@@ -92,7 +91,7 @@ int Application::Run()
         // support calling the Stop() function, as the application will never stop manually
         // support calling the Stop() function, as the application will never stop manually
 #else
 #else
 #if defined(IOS)
 #if defined(IOS)
-        SDL_iPhoneSetAnimationCallback(GetSubsystem<Graphics>()->GetImpl()->GetWindow(), 1, &RunFrame, engine_);
+        SDL_iPhoneSetAnimationCallback(GetSubsystem<Graphics>()->GetWindow(), 1, &RunFrame, engine_);
 #elif defined(__EMSCRIPTEN__)
 #elif defined(__EMSCRIPTEN__)
         emscripten_set_main_loop_arg(RunFrame, engine_, 0, 1);
         emscripten_set_main_loop_arg(RunFrame, engine_, 0, 1);
 #endif
 #endif

+ 30 - 29
Source/Urho3D/Graphics/Direct3D11/D3D11Graphics.cpp

@@ -198,6 +198,7 @@ bool Graphics::gl3Support = false;
 Graphics::Graphics(Context* context) :
 Graphics::Graphics(Context* context) :
     Object(context),
     Object(context),
     impl_(new GraphicsImpl()),
     impl_(new GraphicsImpl()),
+    window_(0),
     windowIcon_(0),
     windowIcon_(0),
     externalWindow_(0),
     externalWindow_(0),
     width_(0),
     width_(0),
@@ -282,11 +283,11 @@ Graphics::~Graphics()
     URHO3D_SAFE_RELEASE(impl_->deviceContext_);
     URHO3D_SAFE_RELEASE(impl_->deviceContext_);
     URHO3D_SAFE_RELEASE(impl_->device_);
     URHO3D_SAFE_RELEASE(impl_->device_);
 
 
-    if (impl_->window_)
+    if (window_)
     {
     {
         SDL_ShowCursor(SDL_TRUE);
         SDL_ShowCursor(SDL_TRUE);
-        SDL_DestroyWindow(impl_->window_);
-        impl_->window_ = 0;
+        SDL_DestroyWindow(window_);
+        window_ = 0;
     }
     }
 
 
     delete impl_;
     delete impl_;
@@ -341,7 +342,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
 
 
     SDL_SetHint(SDL_HINT_ORIENTATIONS, orientations_.CString());
     SDL_SetHint(SDL_HINT_ORIENTATIONS, orientations_.CString());
 
 
-    if (!impl_->window_)
+    if (!window_)
     {
     {
         if (!OpenWindow(width, height, resizable, borderless))
         if (!OpenWindow(width, height, resizable, borderless))
             return false;
             return false;
@@ -376,7 +377,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     if (maximize)
     if (maximize)
     {
     {
         Maximize();
         Maximize();
-        SDL_GetWindowSize(impl_->window_, &width, &height);
+        SDL_GetWindowSize(window_, &width, &height);
     }
     }
 
 
     if (!impl_->device_ || multiSample_ != multiSample)
     if (!impl_->device_ || multiSample_ != multiSample)
@@ -463,11 +464,11 @@ void Graphics::SetForceGL2(bool enable)
 
 
 void Graphics::Close()
 void Graphics::Close()
 {
 {
-    if (impl_->window_)
+    if (window_)
     {
     {
         SDL_ShowCursor(SDL_TRUE);
         SDL_ShowCursor(SDL_TRUE);
-        SDL_DestroyWindow(impl_->window_);
-        impl_->window_ = 0;
+        SDL_DestroyWindow(window_);
+        window_ = 0;
     }
     }
 }
 }
 
 
@@ -561,7 +562,7 @@ bool Graphics::BeginFrame()
     {
     {
         int width, height;
         int width, height;
 
 
-        SDL_GetWindowSize(impl_->window_, &width, &height);
+        SDL_GetWindowSize(window_, &width, &height);
         if (width != width_ || height != height_)
         if (width != width_ || height != height_)
             SetMode(width, height);
             SetMode(width, height);
     }
     }
@@ -569,7 +570,7 @@ bool Graphics::BeginFrame()
     {
     {
         // To prevent a loop of endless device loss and flicker, do not attempt to render when in fullscreen
         // To prevent a loop of endless device loss and flicker, do not attempt to render when in fullscreen
         // and the window is minimized
         // and the window is minimized
-        if (fullscreen_ && (SDL_GetWindowFlags(impl_->window_) & SDL_WINDOW_MINIMIZED))
+        if (fullscreen_ && (SDL_GetWindowFlags(window_) & SDL_WINDOW_MINIMIZED))
             return false;
             return false;
     }
     }
 
 
@@ -1666,7 +1667,7 @@ void Graphics::PrecacheShaders(Deserializer& source)
 
 
 bool Graphics::IsInitialized() const
 bool Graphics::IsInitialized() const
 {
 {
-    return impl_->window_ != 0 && impl_->GetDevice() != 0;
+    return window_ != 0 && impl_->GetDevice() != 0;
 }
 }
 
 
 PODVector<int> Graphics::GetMultiSampleLevels() const
 PODVector<int> Graphics::GetMultiSampleLevels() const
@@ -1804,12 +1805,12 @@ bool Graphics::IsDeviceLost() const
 
 
 void Graphics::OnWindowResized()
 void Graphics::OnWindowResized()
 {
 {
-    if (!impl_->device_ || !impl_->window_)
+    if (!impl_->device_ || !window_)
         return;
         return;
 
 
     int newWidth, newHeight;
     int newWidth, newHeight;
 
 
-    SDL_GetWindowSize(impl_->window_, &newWidth, &newHeight);
+    SDL_GetWindowSize(window_, &newWidth, &newHeight);
     if (newWidth == width_ && newHeight == height_)
     if (newWidth == width_ && newHeight == height_)
         return;
         return;
 
 
@@ -1833,12 +1834,12 @@ void Graphics::OnWindowResized()
 
 
 void Graphics::OnWindowMoved()
 void Graphics::OnWindowMoved()
 {
 {
-    if (!impl_->device_ || !impl_->window_ || fullscreen_)
+    if (!impl_->device_ || !window_ || fullscreen_)
         return;
         return;
 
 
     int newX, newY;
     int newX, newY;
 
 
-    SDL_GetWindowPosition(impl_->window_, &newX, &newY);
+    SDL_GetWindowPosition(window_, &newX, &newY);
     if (newX == position_.x_ && newY == position_.y_)
     if (newX == position_.x_ && newY == position_.y_)
         return;
         return;
 
 
@@ -2032,18 +2033,18 @@ bool Graphics::OpenWindow(int width, int height, bool resizable, bool borderless
         if (borderless)
         if (borderless)
             flags |= SDL_WINDOW_BORDERLESS;
             flags |= SDL_WINDOW_BORDERLESS;
 
 
-        impl_->window_ = SDL_CreateWindow(windowTitle_.CString(), position_.x_, position_.y_, width, height, flags);
+        window_ = SDL_CreateWindow(windowTitle_.CString(), position_.x_, position_.y_, width, height, flags);
     }
     }
     else
     else
-        impl_->window_ = SDL_CreateWindowFrom(externalWindow_, 0);
+        window_ = SDL_CreateWindowFrom(externalWindow_, 0);
 
 
-    if (!impl_->window_)
+    if (!window_)
     {
     {
         URHO3D_LOGERRORF("Could not create window, root cause: '%s'", SDL_GetError());
         URHO3D_LOGERRORF("Could not create window, root cause: '%s'", SDL_GetError());
         return false;
         return false;
     }
     }
 
 
-    SDL_GetWindowPosition(impl_->window_, &position_.x_, &position_.y_);
+    SDL_GetWindowPosition(window_, &position_.x_, &position_.y_);
 
 
     CreateWindowIcon();
     CreateWindowIcon();
 
 
@@ -2056,22 +2057,22 @@ void Graphics::AdjustWindow(int& newWidth, int& newHeight, bool& newFullscreen,
     {
     {
         if (!newWidth || !newHeight)
         if (!newWidth || !newHeight)
         {
         {
-            SDL_MaximizeWindow(impl_->window_);
-            SDL_GetWindowSize(impl_->window_, &newWidth, &newHeight);
+            SDL_MaximizeWindow(window_);
+            SDL_GetWindowSize(window_, &newWidth, &newHeight);
         }
         }
         else
         else
-            SDL_SetWindowSize(impl_->window_, newWidth, newHeight);
+            SDL_SetWindowSize(window_, newWidth, newHeight);
 
 
         // Hack fix: on SDL 2.0.4 a fullscreen->windowed transition results in a maximized window when the D3D device is reset, so hide before
         // Hack fix: on SDL 2.0.4 a fullscreen->windowed transition results in a maximized window when the D3D device is reset, so hide before
-        SDL_HideWindow(impl_->window_);
-        SDL_SetWindowFullscreen(impl_->window_, newFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
-        SDL_SetWindowBordered(impl_->window_, newBorderless ? SDL_FALSE : SDL_TRUE);
-        SDL_ShowWindow(impl_->window_);
+        SDL_HideWindow(window_);
+        SDL_SetWindowFullscreen(window_, newFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
+        SDL_SetWindowBordered(window_, newBorderless ? SDL_FALSE : SDL_TRUE);
+        SDL_ShowWindow(window_);
     }
     }
     else
     else
     {
     {
         // If external window, must ask its dimensions instead of trying to set them
         // If external window, must ask its dimensions instead of trying to set them
-        SDL_GetWindowSize(impl_->window_, &newWidth, &newHeight);
+        SDL_GetWindowSize(window_, &newWidth, &newHeight);
         newFullscreen = false;
         newFullscreen = false;
     }
     }
 }
 }
@@ -2126,7 +2127,7 @@ bool Graphics::CreateDevice(int width, int height, int multiSample)
     swapChainDesc.BufferDesc.Height = (UINT)height;
     swapChainDesc.BufferDesc.Height = (UINT)height;
     swapChainDesc.BufferDesc.Format = sRGB_ ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM;
     swapChainDesc.BufferDesc.Format = sRGB_ ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM;
     swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
     swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
-    swapChainDesc.OutputWindow = GetWindowHandle(impl_->window_);
+    swapChainDesc.OutputWindow = GetWindowHandle(window_);
     swapChainDesc.SampleDesc.Count = (UINT)multiSample;
     swapChainDesc.SampleDesc.Count = (UINT)multiSample;
     swapChainDesc.SampleDesc.Quality = multiSample > 1 ? 0xffffffff : 0;
     swapChainDesc.SampleDesc.Quality = multiSample > 1 ? 0xffffffff : 0;
     swapChainDesc.Windowed = TRUE;
     swapChainDesc.Windowed = TRUE;
@@ -2141,7 +2142,7 @@ bool Graphics::CreateDevice(int width, int height, int multiSample)
     HRESULT hr = dxgiFactory->CreateSwapChain(impl_->device_, &swapChainDesc, &impl_->swapChain_);
     HRESULT hr = dxgiFactory->CreateSwapChain(impl_->device_, &swapChainDesc, &impl_->swapChain_);
     // After creating the swap chain, disable automatic Alt-Enter fullscreen/windowed switching
     // After creating the swap chain, disable automatic Alt-Enter fullscreen/windowed switching
     // (the application will switch manually if it wants to)
     // (the application will switch manually if it wants to)
-    dxgiFactory->MakeWindowAssociation(GetWindowHandle(impl_->window_), DXGI_MWA_NO_ALT_ENTER);
+    dxgiFactory->MakeWindowAssociation(GetWindowHandle(window_), DXGI_MWA_NO_ALT_ENTER);
 
 
     dxgiFactory->Release();
     dxgiFactory->Release();
     dxgiAdapter->Release();
     dxgiAdapter->Release();

+ 0 - 1
Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.cpp

@@ -31,7 +31,6 @@ namespace Urho3D
 {
 {
 
 
 GraphicsImpl::GraphicsImpl() :
 GraphicsImpl::GraphicsImpl() :
-    window_(0),
     device_(0),
     device_(0),
     deviceContext_(0),
     deviceContext_(0),
     swapChain_(0),
     swapChain_(0),

+ 0 - 7
Source/Urho3D/Graphics/Direct3D11/D3D11GraphicsImpl.h

@@ -31,8 +31,6 @@
 #include <d3d11.h>
 #include <d3d11.h>
 #include <dxgi.h>
 #include <dxgi.h>
 
 
-struct SDL_Window;
-
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -62,12 +60,7 @@ public:
     /// Return swapchain.
     /// Return swapchain.
     IDXGISwapChain* GetSwapChain() const { return swapChain_; }
     IDXGISwapChain* GetSwapChain() const { return swapChain_; }
 
 
-    /// Return window.
-    SDL_Window* GetWindow() const { return window_; }
-
 private:
 private:
-    /// SDL window.
-    SDL_Window* window_;
     /// Graphics device.
     /// Graphics device.
     ID3D11Device* device_;
     ID3D11Device* device_;
     /// Immediate device context.
     /// Immediate device context.

+ 31 - 30
Source/Urho3D/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -242,6 +242,7 @@ bool Graphics::gl3Support = false;
 Graphics::Graphics(Context* context) :
 Graphics::Graphics(Context* context) :
     Object(context),
     Object(context),
     impl_(new GraphicsImpl()),
     impl_(new GraphicsImpl()),
+    window_(0),
     windowIcon_(0),
     windowIcon_(0),
     externalWindow_(0),
     externalWindow_(0),
     width_(0),
     width_(0),
@@ -302,11 +303,11 @@ Graphics::~Graphics()
     URHO3D_SAFE_RELEASE(impl_->device_);
     URHO3D_SAFE_RELEASE(impl_->device_);
     URHO3D_SAFE_RELEASE(impl_->interface_);
     URHO3D_SAFE_RELEASE(impl_->interface_);
 
 
-    if (impl_->window_)
+    if (window_)
     {
     {
         SDL_ShowCursor(SDL_TRUE);
         SDL_ShowCursor(SDL_TRUE);
-        SDL_DestroyWindow(impl_->window_);
-        impl_->window_ = 0;
+        SDL_DestroyWindow(window_);
+        window_ = 0;
     }
     }
 
 
     delete impl_;
     delete impl_;
@@ -363,7 +364,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
 
 
     SDL_SetHint(SDL_HINT_ORIENTATIONS, orientations_.CString());
     SDL_SetHint(SDL_HINT_ORIENTATIONS, orientations_.CString());
 
 
-    if (!impl_->window_)
+    if (!window_)
     {
     {
         if (!OpenWindow(width, height, resizable, borderless))
         if (!OpenWindow(width, height, resizable, borderless))
             return false;
             return false;
@@ -417,7 +418,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     if (maximize)
     if (maximize)
     {
     {
         Maximize();
         Maximize();
-        SDL_GetWindowSize(impl_->window_, &width, &height);
+        SDL_GetWindowSize(window_, &width, &height);
     }
     }
 
 
     if (fullscreen)
     if (fullscreen)
@@ -437,7 +438,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     impl_->presentParams_.MultiSampleType = multiSample > 1 ? (D3DMULTISAMPLE_TYPE)multiSample : D3DMULTISAMPLE_NONE;
     impl_->presentParams_.MultiSampleType = multiSample > 1 ? (D3DMULTISAMPLE_TYPE)multiSample : D3DMULTISAMPLE_NONE;
     impl_->presentParams_.MultiSampleQuality = 0;
     impl_->presentParams_.MultiSampleQuality = 0;
     impl_->presentParams_.SwapEffect = D3DSWAPEFFECT_DISCARD;
     impl_->presentParams_.SwapEffect = D3DSWAPEFFECT_DISCARD;
-    impl_->presentParams_.hDeviceWindow = GetWindowHandle(impl_->window_);
+    impl_->presentParams_.hDeviceWindow = GetWindowHandle(window_);
     impl_->presentParams_.EnableAutoDepthStencil = TRUE;
     impl_->presentParams_.EnableAutoDepthStencil = TRUE;
     impl_->presentParams_.AutoDepthStencilFormat = D3DFMT_D24S8;
     impl_->presentParams_.AutoDepthStencilFormat = D3DFMT_D24S8;
     impl_->presentParams_.Flags = D3DPRESENT_LINEAR_CONTENT;
     impl_->presentParams_.Flags = D3DPRESENT_LINEAR_CONTENT;
@@ -536,11 +537,11 @@ void Graphics::SetForceGL2(bool enable)
 
 
 void Graphics::Close()
 void Graphics::Close()
 {
 {
-    if (impl_->window_)
+    if (window_)
     {
     {
         SDL_ShowCursor(SDL_TRUE);
         SDL_ShowCursor(SDL_TRUE);
-        SDL_DestroyWindow(impl_->window_);
-        impl_->window_ = 0;
+        SDL_DestroyWindow(window_);
+        window_ = 0;
     }
     }
 }
 }
 
 
@@ -610,7 +611,7 @@ bool Graphics::TakeScreenShot(Image& destImage)
     }
     }
     else
     else
     {
     {
-        HWND hwnd = GetWindowHandle(impl_->window_);
+        HWND hwnd = GetWindowHandle(window_);
         GetClientRect(hwnd, &sourceRect);
         GetClientRect(hwnd, &sourceRect);
         ClientToScreen(hwnd, (LPPOINT)&sourceRect);
         ClientToScreen(hwnd, (LPPOINT)&sourceRect);
     }
     }
@@ -683,7 +684,7 @@ bool Graphics::BeginFrame()
     {
     {
         int width, height;
         int width, height;
 
 
-        SDL_GetWindowSize(impl_->window_, &width, &height);
+        SDL_GetWindowSize(window_, &width, &height);
         if (width != width_ || height != height_)
         if (width != width_ || height != height_)
             SetMode(width, height);
             SetMode(width, height);
     }
     }
@@ -691,7 +692,7 @@ bool Graphics::BeginFrame()
     {
     {
         // To prevent a loop of endless device loss and flicker, do not attempt to render when in fullscreen
         // To prevent a loop of endless device loss and flicker, do not attempt to render when in fullscreen
         // and the window is minimized
         // and the window is minimized
-        if (fullscreen_ && (SDL_GetWindowFlags(impl_->window_) & SDL_WINDOW_MINIMIZED))
+        if (fullscreen_ && (SDL_GetWindowFlags(window_) & SDL_WINDOW_MINIMIZED))
             return false;
             return false;
     }
     }
 
 
@@ -1873,7 +1874,7 @@ void Graphics::PrecacheShaders(Deserializer& source)
 
 
 bool Graphics::IsInitialized() const
 bool Graphics::IsInitialized() const
 {
 {
-    return impl_->window_ != 0 && impl_->GetDevice() != 0;
+    return window_ != 0 && impl_->GetDevice() != 0;
 }
 }
 
 
 PODVector<int> Graphics::GetMultiSampleLevels() const
 PODVector<int> Graphics::GetMultiSampleLevels() const
@@ -2002,12 +2003,12 @@ bool Graphics::IsDeviceLost() const
 
 
 void Graphics::OnWindowResized()
 void Graphics::OnWindowResized()
 {
 {
-    if (!impl_->device_ || !impl_->window_)
+    if (!impl_->device_ || !window_)
         return;
         return;
 
 
     int newWidth, newHeight;
     int newWidth, newHeight;
 
 
-    SDL_GetWindowSize(impl_->window_, &newWidth, &newHeight);
+    SDL_GetWindowSize(window_, &newWidth, &newHeight);
     if (newWidth == width_ && newHeight == height_)
     if (newWidth == width_ && newHeight == height_)
         return;
         return;
 
 
@@ -2036,12 +2037,12 @@ void Graphics::OnWindowResized()
 
 
 void Graphics::OnWindowMoved()
 void Graphics::OnWindowMoved()
 {
 {
-    if (!impl_->device_ || !impl_->window_ || fullscreen_)
+    if (!impl_->device_ || !window_ || fullscreen_)
         return;
         return;
 
 
     int newX, newY;
     int newX, newY;
 
 
-    SDL_GetWindowPosition(impl_->window_, &newX, &newY);
+    SDL_GetWindowPosition(window_, &newX, &newY);
     if (newX == position_.x_ && newY == position_.y_)
     if (newX == position_.x_ && newY == position_.y_)
         return;
         return;
 
 
@@ -2233,18 +2234,18 @@ bool Graphics::OpenWindow(int width, int height, bool resizable, bool borderless
         if (borderless)
         if (borderless)
             flags |= SDL_WINDOW_BORDERLESS;
             flags |= SDL_WINDOW_BORDERLESS;
 
 
-        impl_->window_ = SDL_CreateWindow(windowTitle_.CString(), position_.x_, position_.y_, width, height, flags);
+        window_ = SDL_CreateWindow(windowTitle_.CString(), position_.x_, position_.y_, width, height, flags);
     }
     }
     else
     else
-        impl_->window_ = SDL_CreateWindowFrom(externalWindow_, 0);
+        window_ = SDL_CreateWindowFrom(externalWindow_, 0);
 
 
-    if (!impl_->window_)
+    if (!window_)
     {
     {
         URHO3D_LOGERRORF("Could not create window, root cause: '%s'", SDL_GetError());
         URHO3D_LOGERRORF("Could not create window, root cause: '%s'", SDL_GetError());
         return false;
         return false;
     }
     }
 
 
-    SDL_GetWindowPosition(impl_->window_, &position_.x_, &position_.y_);
+    SDL_GetWindowPosition(window_, &position_.x_, &position_.y_);
 
 
     CreateWindowIcon();
     CreateWindowIcon();
 
 
@@ -2257,22 +2258,22 @@ void Graphics::AdjustWindow(int& newWidth, int& newHeight, bool& newFullscreen,
     {
     {
         if (!newWidth || !newHeight)
         if (!newWidth || !newHeight)
         {
         {
-            SDL_MaximizeWindow(impl_->window_);
-            SDL_GetWindowSize(impl_->window_, &newWidth, &newHeight);
+            SDL_MaximizeWindow(window_);
+            SDL_GetWindowSize(window_, &newWidth, &newHeight);
         }
         }
         else
         else
-            SDL_SetWindowSize(impl_->window_, newWidth, newHeight);
+            SDL_SetWindowSize(window_, newWidth, newHeight);
 
 
         // Hack fix: on SDL 2.0.4 a fullscreen->windowed transition results in a maximized window when the D3D device is reset, so hide before
         // Hack fix: on SDL 2.0.4 a fullscreen->windowed transition results in a maximized window when the D3D device is reset, so hide before
-        SDL_HideWindow(impl_->window_);
-        SDL_SetWindowFullscreen(impl_->window_, newFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
-        SDL_SetWindowBordered(impl_->window_, newBorderless ? SDL_FALSE : SDL_TRUE);
-        SDL_ShowWindow(impl_->window_);
+        SDL_HideWindow(window_);
+        SDL_SetWindowFullscreen(window_, newFullscreen ? SDL_WINDOW_FULLSCREEN : 0);
+        SDL_SetWindowBordered(window_, newBorderless ? SDL_FALSE : SDL_TRUE);
+        SDL_ShowWindow(window_);
     }
     }
     else
     else
     {
     {
         // If external window, must ask its dimensions instead of trying to set them
         // If external window, must ask its dimensions instead of trying to set them
-        SDL_GetWindowSize(impl_->window_, &newWidth, &newHeight);
+        SDL_GetWindowSize(window_, &newWidth, &newHeight);
         newFullscreen = false;
         newFullscreen = false;
     }
     }
 }
 }
@@ -2328,7 +2329,7 @@ bool Graphics::CreateDevice(unsigned adapter, unsigned deviceType)
     HRESULT hr = impl_->interface_->CreateDevice(
     HRESULT hr = impl_->interface_->CreateDevice(
         adapter,
         adapter,
         (D3DDEVTYPE)deviceType,
         (D3DDEVTYPE)deviceType,
-        GetWindowHandle(impl_->window_),
+        GetWindowHandle(window_),
         behaviorFlags,
         behaviorFlags,
         &impl_->presentParams_,
         &impl_->presentParams_,
         &impl_->device_);
         &impl_->device_);

+ 0 - 1
Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.cpp

@@ -31,7 +31,6 @@ namespace Urho3D
 {
 {
 
 
 GraphicsImpl::GraphicsImpl() :
 GraphicsImpl::GraphicsImpl() :
-    window_(0),
     interface_(0),
     interface_(0),
     device_(0),
     device_(0),
     defaultColorSurface_(0),
     defaultColorSurface_(0),

+ 0 - 7
Source/Urho3D/Graphics/Direct3D9/D3D9GraphicsImpl.h

@@ -28,8 +28,6 @@
 
 
 #include <d3d9.h>
 #include <d3d9.h>
 
 
-struct SDL_Window;
-
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -55,9 +53,6 @@ public:
     /// Return device capabilities.
     /// Return device capabilities.
     const D3DCAPS9& GetDeviceCaps() const { return deviceCaps_; }
     const D3DCAPS9& GetDeviceCaps() const { return deviceCaps_; }
 
 
-    /// Return window.
-    SDL_Window* GetWindow() const { return window_; }
-
     /// Return adapter identifier.
     /// Return adapter identifier.
     const D3DADAPTER_IDENTIFIER9& GetAdapterIdentifier() const { return adapterIdentifier_; }
     const D3DADAPTER_IDENTIFIER9& GetAdapterIdentifier() const { return adapterIdentifier_; }
 
 
@@ -65,8 +60,6 @@ public:
     bool CheckFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type);
     bool CheckFormatSupport(D3DFORMAT format, DWORD usage, D3DRESOURCETYPE type);
 
 
 private:
 private:
-    /// SDL window.
-    SDL_Window* window_;
     /// Direct3D interface.
     /// Direct3D interface.
     IDirect3D9* interface_;
     IDirect3D9* interface_;
     /// Direct3D device.
     /// Direct3D device.

+ 12 - 12
Source/Urho3D/Graphics/Graphics.cpp

@@ -59,7 +59,7 @@ namespace Urho3D
 
 
 void Graphics::SetExternalWindow(void* window)
 void Graphics::SetExternalWindow(void* window)
 {
 {
-    if (!impl_->window_)
+    if (!window_)
         externalWindow_ = window;
         externalWindow_ = window;
     else
     else
         URHO3D_LOGERROR("Window already opened, can not set external window");
         URHO3D_LOGERROR("Window already opened, can not set external window");
@@ -68,21 +68,21 @@ void Graphics::SetExternalWindow(void* window)
 void Graphics::SetWindowTitle(const String& windowTitle)
 void Graphics::SetWindowTitle(const String& windowTitle)
 {
 {
     windowTitle_ = windowTitle;
     windowTitle_ = windowTitle;
-    if (impl_->window_)
-        SDL_SetWindowTitle(impl_->window_, windowTitle_.CString());
+    if (window_)
+        SDL_SetWindowTitle(window_, windowTitle_.CString());
 }
 }
 
 
 void Graphics::SetWindowIcon(Image* windowIcon)
 void Graphics::SetWindowIcon(Image* windowIcon)
 {
 {
     windowIcon_ = windowIcon;
     windowIcon_ = windowIcon;
-    if (impl_->window_)
+    if (window_)
         CreateWindowIcon();
         CreateWindowIcon();
 }
 }
 
 
 void Graphics::SetWindowPosition(const IntVector2& position)
 void Graphics::SetWindowPosition(const IntVector2& position)
 {
 {
-    if (impl_->window_)
-        SDL_SetWindowPosition(impl_->window_, position.x_, position.y_);
+    if (window_)
+        SDL_SetWindowPosition(window_, position.x_, position.y_);
     else
     else
         position_ = position; // Sets as initial position for OpenWindow()
         position_ = position; // Sets as initial position for OpenWindow()
 }
 }
@@ -105,7 +105,7 @@ bool Graphics::ToggleFullscreen()
 
 
 IntVector2 Graphics::GetWindowPosition() const
 IntVector2 Graphics::GetWindowPosition() const
 {
 {
-    if (impl_->window_)
+    if (window_)
         return position_;
         return position_;
     return IntVector2::ZERO;
     return IntVector2::ZERO;
 }
 }
@@ -157,18 +157,18 @@ IntVector2 Graphics::GetDesktopResolution() const
 
 
 void Graphics::Maximize()
 void Graphics::Maximize()
 {
 {
-    if (!impl_->window_)
+    if (!window_)
         return;
         return;
 
 
-    SDL_MaximizeWindow(impl_->window_);
+    SDL_MaximizeWindow(window_);
 }
 }
 
 
 void Graphics::Minimize()
 void Graphics::Minimize()
 {
 {
-    if (!impl_->window_)
+    if (!window_)
         return;
         return;
 
 
-    SDL_MinimizeWindow(impl_->window_);
+    SDL_MinimizeWindow(window_);
 }
 }
 
 
 void Graphics::AddGPUObject(GPUObject* object)
 void Graphics::AddGPUObject(GPUObject* object)
@@ -269,7 +269,7 @@ void Graphics::CreateWindowIcon()
         SDL_Surface* surface = windowIcon_->GetSDLSurface();
         SDL_Surface* surface = windowIcon_->GetSDLSurface();
         if (surface)
         if (surface)
         {
         {
-            SDL_SetWindowIcon(impl_->window_, surface);
+            SDL_SetWindowIcon(window_, surface);
             SDL_FreeSurface(surface);
             SDL_FreeSurface(surface);
         }
         }
     }
     }

+ 7 - 0
Source/Urho3D/Graphics/Graphics.h

@@ -33,6 +33,8 @@
 #include "../Math/Rect.h"
 #include "../Math/Rect.h"
 #include "../Resource/Image.h"
 #include "../Resource/Image.h"
 
 
+struct SDL_Window;
+
 namespace Urho3D
 namespace Urho3D
 {
 {
 
 
@@ -247,6 +249,9 @@ public:
     /// Return OS-specific external window handle. Null if not in use.
     /// Return OS-specific external window handle. Null if not in use.
     void* GetExternalWindow() const { return externalWindow_; }
     void* GetExternalWindow() const { return externalWindow_; }
 
 
+    /// Return SDL window.
+    SDL_Window* GetWindow() const { return window_; }
+
     /// Return window title.
     /// Return window title.
     const String& GetWindowTitle() const { return windowTitle_; }
     const String& GetWindowTitle() const { return windowTitle_; }
 
 
@@ -582,6 +587,8 @@ private:
     Mutex gpuObjectMutex_;
     Mutex gpuObjectMutex_;
     /// Implementation.
     /// Implementation.
     GraphicsImpl* impl_;
     GraphicsImpl* impl_;
+    /// SDL window.
+    SDL_Window* window_;
     /// Window title.
     /// Window title.
     String windowTitle_;
     String windowTitle_;
     /// Window icon image.
     /// Window icon image.

+ 24 - 23
Source/Urho3D/Graphics/OpenGL/OGLGraphics.cpp

@@ -222,6 +222,7 @@ bool Graphics::gl3Support = false;
 Graphics::Graphics(Context* context_) :
 Graphics::Graphics(Context* context_) :
     Object(context_),
     Object(context_),
     impl_(new GraphicsImpl()),
     impl_(new GraphicsImpl()),
+    window_(0),
     windowIcon_(0),
     windowIcon_(0),
     externalWindow_(0),
     externalWindow_(0),
     width_(0),
     width_(0),
@@ -434,17 +435,17 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
         for (;;)
         for (;;)
         {
         {
             if (!externalWindow_)
             if (!externalWindow_)
-                impl_->window_ = SDL_CreateWindow(windowTitle_.CString(), x, y, width, height, flags);
+                window_ = SDL_CreateWindow(windowTitle_.CString(), x, y, width, height, flags);
             else
             else
             {
             {
 #ifndef __EMSCRIPTEN__
 #ifndef __EMSCRIPTEN__
-                if (!impl_->window_)
-                    impl_->window_ = SDL_CreateWindowFrom(externalWindow_, SDL_WINDOW_OPENGL);
+                if (!window_)
+                    window_ = SDL_CreateWindowFrom(externalWindow_, SDL_WINDOW_OPENGL);
                 fullscreen = false;
                 fullscreen = false;
 #endif
 #endif
             }
             }
 
 
-            if (impl_->window_)
+            if (window_)
                 break;
                 break;
             else
             else
             {
             {
@@ -468,7 +469,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
         if (maximize)
         if (maximize)
         {
         {
             Maximize();
             Maximize();
-            SDL_GL_GetDrawableSize(impl_->window_, &width, &height);
+            SDL_GL_GetDrawableSize(window_, &width, &height);
         }
         }
 
 
         // Create/restore context and GPU objects and set initial renderstate
         // Create/restore context and GPU objects and set initial renderstate
@@ -495,16 +496,16 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     tripleBuffer_ = tripleBuffer;
     tripleBuffer_ = tripleBuffer;
     multiSample_ = multiSample;
     multiSample_ = multiSample;
 
 
-    SDL_GL_GetDrawableSize(impl_->window_, &width_, &height_);
+    SDL_GL_GetDrawableSize(window_, &width_, &height_);
     if (!fullscreen)
     if (!fullscreen)
-        SDL_GetWindowPosition(impl_->window_, &position_.x_, &position_.y_);
+        SDL_GetWindowPosition(window_, &position_.x_, &position_.y_);
 
 
     // Reset rendertargets and viewport for the new screen mode
     // Reset rendertargets and viewport for the new screen mode
     ResetRenderTargets();
     ResetRenderTargets();
 
 
     // Clear the initial window contents to black
     // Clear the initial window contents to black
     Clear(CLEAR_COLOR);
     Clear(CLEAR_COLOR);
-    SDL_GL_SwapWindow(impl_->window_);
+    SDL_GL_SwapWindow(window_);
 
 
     CheckFeatureSupport();
     CheckFeatureSupport();
 
 
@@ -607,7 +608,7 @@ bool Graphics::BeginFrame()
     {
     {
         int width, height;
         int width, height;
 
 
-        SDL_GL_GetDrawableSize(impl_->window_, &width, &height);
+        SDL_GL_GetDrawableSize(window_, &width, &height);
         if (width != width_ || height != height_)
         if (width != width_ || height != height_)
             SetMode(width, height);
             SetMode(width, height);
     }
     }
@@ -644,7 +645,7 @@ void Graphics::EndFrame()
 
 
     SendEvent(E_ENDRENDERING);
     SendEvent(E_ENDRENDERING);
 
 
-    SDL_GL_SwapWindow(impl_->window_);
+    SDL_GL_SwapWindow(window_);
 
 
     // Clean up too large scratch buffers
     // Clean up too large scratch buffers
     CleanupScratchBuffers();
     CleanupScratchBuffers();
@@ -1912,14 +1913,14 @@ void Graphics::PrecacheShaders(Deserializer& source)
 
 
 bool Graphics::IsInitialized() const
 bool Graphics::IsInitialized() const
 {
 {
-    return impl_->window_ != 0;
+    return window_ != 0;
 }
 }
 
 
 bool Graphics::IsDeviceLost() const
 bool Graphics::IsDeviceLost() const
 {
 {
     // On iOS treat window minimization as device loss, as it is forbidden to access OpenGL when minimized
     // On iOS treat window minimization as device loss, as it is forbidden to access OpenGL when minimized
 #ifdef IOS
 #ifdef IOS
-    if (impl_->window_ && (SDL_GetWindowFlags(impl_->window_) & SDL_WINDOW_MINIMIZED) != 0)
+    if (window_ && (SDL_GetWindowFlags(window_) & SDL_WINDOW_MINIMIZED) != 0)
         return true;
         return true;
 #endif
 #endif
 
 
@@ -2077,12 +2078,12 @@ IntVector2 Graphics::GetRenderTargetDimensions() const
 
 
 void Graphics::OnWindowResized()
 void Graphics::OnWindowResized()
 {
 {
-    if (!impl_->window_)
+    if (!window_)
         return;
         return;
 
 
     int newWidth, newHeight;
     int newWidth, newHeight;
 
 
-    SDL_GL_GetDrawableSize(impl_->window_, &newWidth, &newHeight);
+    SDL_GL_GetDrawableSize(window_, &newWidth, &newHeight);
     if (newWidth == width_ && newHeight == height_)
     if (newWidth == width_ && newHeight == height_)
         return;
         return;
 
 
@@ -2108,12 +2109,12 @@ void Graphics::OnWindowResized()
 
 
 void Graphics::OnWindowMoved()
 void Graphics::OnWindowMoved()
 {
 {
-    if (!impl_->window_ || fullscreen_)
+    if (!window_ || fullscreen_)
         return;
         return;
 
 
     int newX, newY;
     int newX, newY;
 
 
-    SDL_GetWindowPosition(impl_->window_, &newX, &newY);
+    SDL_GetWindowPosition(window_, &newX, &newY);
     if (newX == position_.x_ && newY == position_.y_)
     if (newX == position_.x_ && newY == position_.y_)
         return;
         return;
 
 
@@ -2208,7 +2209,7 @@ ConstantBuffer* Graphics::GetOrCreateConstantBuffer(ShaderType /*type*/,  unsign
 
 
 void Graphics::Release(bool clearGPUObjects, bool closeWindow)
 void Graphics::Release(bool clearGPUObjects, bool closeWindow)
 {
 {
-    if (!impl_->window_)
+    if (!window_)
         return;
         return;
 
 
     {
     {
@@ -2244,7 +2245,7 @@ void Graphics::Release(bool clearGPUObjects, bool closeWindow)
     // End fullscreen mode first to counteract transition and getting stuck problems on OS X
     // End fullscreen mode first to counteract transition and getting stuck problems on OS X
 #if defined(__APPLE__) && !defined(IOS)
 #if defined(__APPLE__) && !defined(IOS)
     if (closeWindow && fullscreen_ && !externalWindow_)
     if (closeWindow && fullscreen_ && !externalWindow_)
-        SDL_SetWindowFullscreen(impl_->window_, 0);
+        SDL_SetWindowFullscreen(window_, 0);
 #endif
 #endif
 
 
     if (impl_->context_)
     if (impl_->context_)
@@ -2264,15 +2265,15 @@ void Graphics::Release(bool clearGPUObjects, bool closeWindow)
         // Do not destroy external window except when shutting down
         // Do not destroy external window except when shutting down
         if (!externalWindow_ || clearGPUObjects)
         if (!externalWindow_ || clearGPUObjects)
         {
         {
-            SDL_DestroyWindow(impl_->window_);
-            impl_->window_ = 0;
+            SDL_DestroyWindow(window_);
+            window_ = 0;
         }
         }
     }
     }
 }
 }
 
 
 void Graphics::Restore()
 void Graphics::Restore()
 {
 {
-    if (!impl_->window_)
+    if (!window_)
         return;
         return;
 
 
 #ifdef __ANDROID__
 #ifdef __ANDROID__
@@ -2289,7 +2290,7 @@ void Graphics::Restore()
     // Ensure first that the context exists
     // Ensure first that the context exists
     if (!impl_->context_)
     if (!impl_->context_)
     {
     {
-        impl_->context_ = SDL_GL_CreateContext(impl_->window_);
+        impl_->context_ = SDL_GL_CreateContext(window_);
 
 
 #ifndef GL_ES_VERSION_2_0
 #ifndef GL_ES_VERSION_2_0
         // If we're trying to use OpenGL 3, but context creation fails, retry with 2
         // If we're trying to use OpenGL 3, but context creation fails, retry with 2
@@ -2299,7 +2300,7 @@ void Graphics::Restore()
             SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
             SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
             SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
             SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
             SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
             SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, 0);
-            impl_->context_ = SDL_GL_CreateContext(impl_->window_);
+            impl_->context_ = SDL_GL_CreateContext(window_);
         }
         }
 #endif
 #endif
 
 

+ 0 - 1
Source/Urho3D/Graphics/OpenGL/OGLGraphicsImpl.cpp

@@ -31,7 +31,6 @@ namespace Urho3D
 {
 {
 
 
 GraphicsImpl::GraphicsImpl() :
 GraphicsImpl::GraphicsImpl() :
-    window_(0),
     context_(0),
     context_(0),
     systemFBO_(0),
     systemFBO_(0),
     activeTexture_(0),
     activeTexture_(0),

+ 0 - 5
Source/Urho3D/Graphics/OpenGL/OGLGraphicsImpl.h

@@ -64,7 +64,6 @@
 #define COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8c03
 #define COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8c03
 #endif
 #endif
 
 
-struct SDL_Window;
 typedef void *SDL_GLContext;
 typedef void *SDL_GLContext;
 
 
 namespace Urho3D
 namespace Urho3D
@@ -109,14 +108,10 @@ public:
     /// Construct.
     /// Construct.
     GraphicsImpl();
     GraphicsImpl();
 
 
-    /// Return the SDL window.
-    SDL_Window* GetWindow() const { return window_; }
     /// Return the GL Context.
     /// Return the GL Context.
     const SDL_GLContext& GetGLContext() { return context_; }
     const SDL_GLContext& GetGLContext() { return context_; }
 
 
 private:
 private:
-    /// SDL window.
-    SDL_Window* window_;
     /// SDL OpenGL context.
     /// SDL OpenGL context.
     SDL_GLContext context_;
     SDL_GLContext context_;
     /// IOS system framebuffer handle.
     /// IOS system framebuffer handle.

+ 7 - 8
Source/Urho3D/Input/Input.cpp

@@ -30,7 +30,6 @@
 #include "../Core/StringUtils.h"
 #include "../Core/StringUtils.h"
 #include "../Graphics/Graphics.h"
 #include "../Graphics/Graphics.h"
 #include "../Graphics/GraphicsEvents.h"
 #include "../Graphics/GraphicsEvents.h"
-#include "../Graphics/GraphicsImpl.h"
 #include "../Input/Input.h"
 #include "../Input/Input.h"
 #include "../IO/FileSystem.h"
 #include "../IO/FileSystem.h"
 #include "../IO/Log.h"
 #include "../IO/Log.h"
@@ -395,7 +394,7 @@ void Input::Update()
 #endif
 #endif
 
 
     // Check for focus change this frame
     // Check for focus change this frame
-    SDL_Window* window = graphics_->GetImpl()->GetWindow();
+    SDL_Window* window = graphics_->GetWindow();
     unsigned flags = window ? SDL_GetWindowFlags(window) & (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS) : 0;
     unsigned flags = window ? SDL_GetWindowFlags(window) & (SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS) : 0;
 #ifndef __EMSCRIPTEN__
 #ifndef __EMSCRIPTEN__
     if (window)
     if (window)
@@ -791,14 +790,14 @@ void Input::ResetMouseGrabbed()
 #ifndef __EMSCRIPTEN__
 #ifndef __EMSCRIPTEN__
 void Input::SetMouseModeAbsolute(SDL_bool enable)
 void Input::SetMouseModeAbsolute(SDL_bool enable)
 {
 {
-    SDL_Window* const window = graphics_->GetImpl()->GetWindow();
+    SDL_Window* const window = graphics_->GetWindow();
 
 
     SDL_SetWindowGrab(window, enable);
     SDL_SetWindowGrab(window, enable);
 }
 }
 
 
 void Input::SetMouseModeRelative(SDL_bool enable)
 void Input::SetMouseModeRelative(SDL_bool enable)
 {
 {
-    SDL_Window* const window = graphics_->GetImpl()->GetWindow();
+    SDL_Window* const window = graphics_->GetWindow();
 
 
     int result = SDL_SetRelativeMouseMode(enable);
     int result = SDL_SetRelativeMouseMode(enable);
     sdlMouseRelative_ = enable && (result == 0);
     sdlMouseRelative_ = enable && (result == 0);
@@ -820,7 +819,7 @@ void Input::SetMouseMode(MouseMode mode, bool suppressEvent)
         SuppressNextMouseMove();
         SuppressNextMouseMove();
 
 
         mouseMode_ = mode;
         mouseMode_ = mode;
-        SDL_Window* const window = graphics_->GetImpl()->GetWindow();
+        SDL_Window* const window = graphics_->GetWindow();
 
 
         UI* const ui = GetSubsystem<UI>();
         UI* const ui = GetSubsystem<UI>();
         Cursor* const cursor = ui->GetCursor();
         Cursor* const cursor = ui->GetCursor();
@@ -1448,7 +1447,7 @@ bool Input::IsScreenKeyboardVisible() const
 {
 {
     if (graphics_)
     if (graphics_)
     {
     {
-        SDL_Window* window = graphics_->GetImpl()->GetWindow();
+        SDL_Window* window = graphics_->GetWindow();
         return SDL_IsScreenKeyboardShown(window) != SDL_FALSE;
         return SDL_IsScreenKeyboardShown(window) != SDL_FALSE;
     }
     }
     else
     else
@@ -1785,7 +1784,7 @@ void Input::SetMousePosition(const IntVector2& position)
     if (!graphics_)
     if (!graphics_)
         return;
         return;
 
 
-    SDL_WarpMouseInWindow(graphics_->GetImpl()->GetWindow(), position.x_, position.y_);
+    SDL_WarpMouseInWindow(graphics_->GetWindow(), position.x_, position.y_);
 }
 }
 
 
 void Input::CenterMousePosition()
 void Input::CenterMousePosition()
@@ -2331,7 +2330,7 @@ void Input::HandleScreenMode(StringHash eventType, VariantMap& eventData)
 
 
     // Re-enable cursor clipping, and re-center the cursor (if needed) to the new screen size, so that there is no erroneous
     // Re-enable cursor clipping, and re-center the cursor (if needed) to the new screen size, so that there is no erroneous
     // mouse move event. Also get new window ID if it changed
     // mouse move event. Also get new window ID if it changed
-    SDL_Window* window = graphics_->GetImpl()->GetWindow();
+    SDL_Window* window = graphics_->GetWindow();
     windowID_ = SDL_GetWindowID(window);
     windowID_ = SDL_GetWindowID(window);
 
 
     // If screen mode happens due to mouse drag resize, do not recenter the mouse as that would lead to erratic window sizes
     // If screen mode happens due to mouse drag resize, do not recenter the mouse as that would lead to erratic window sizes