|
|
@@ -242,6 +242,7 @@ bool Graphics::gl3Support = false;
|
|
|
Graphics::Graphics(Context* context) :
|
|
|
Object(context),
|
|
|
impl_(new GraphicsImpl()),
|
|
|
+ window_(0),
|
|
|
windowIcon_(0),
|
|
|
externalWindow_(0),
|
|
|
width_(0),
|
|
|
@@ -302,11 +303,11 @@ Graphics::~Graphics()
|
|
|
URHO3D_SAFE_RELEASE(impl_->device_);
|
|
|
URHO3D_SAFE_RELEASE(impl_->interface_);
|
|
|
|
|
|
- if (impl_->window_)
|
|
|
+ if (window_)
|
|
|
{
|
|
|
SDL_ShowCursor(SDL_TRUE);
|
|
|
- SDL_DestroyWindow(impl_->window_);
|
|
|
- impl_->window_ = 0;
|
|
|
+ SDL_DestroyWindow(window_);
|
|
|
+ window_ = 0;
|
|
|
}
|
|
|
|
|
|
delete impl_;
|
|
|
@@ -363,7 +364,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
|
|
|
|
|
|
SDL_SetHint(SDL_HINT_ORIENTATIONS, orientations_.CString());
|
|
|
|
|
|
- if (!impl_->window_)
|
|
|
+ if (!window_)
|
|
|
{
|
|
|
if (!OpenWindow(width, height, resizable, borderless))
|
|
|
return false;
|
|
|
@@ -417,7 +418,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
|
|
|
if (maximize)
|
|
|
{
|
|
|
Maximize();
|
|
|
- SDL_GetWindowSize(impl_->window_, &width, &height);
|
|
|
+ SDL_GetWindowSize(window_, &width, &height);
|
|
|
}
|
|
|
|
|
|
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_.MultiSampleQuality = 0;
|
|
|
impl_->presentParams_.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
|
|
- impl_->presentParams_.hDeviceWindow = GetWindowHandle(impl_->window_);
|
|
|
+ impl_->presentParams_.hDeviceWindow = GetWindowHandle(window_);
|
|
|
impl_->presentParams_.EnableAutoDepthStencil = TRUE;
|
|
|
impl_->presentParams_.AutoDepthStencilFormat = D3DFMT_D24S8;
|
|
|
impl_->presentParams_.Flags = D3DPRESENT_LINEAR_CONTENT;
|
|
|
@@ -536,11 +537,11 @@ void Graphics::SetForceGL2(bool enable)
|
|
|
|
|
|
void Graphics::Close()
|
|
|
{
|
|
|
- if (impl_->window_)
|
|
|
+ if (window_)
|
|
|
{
|
|
|
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
|
|
|
{
|
|
|
- HWND hwnd = GetWindowHandle(impl_->window_);
|
|
|
+ HWND hwnd = GetWindowHandle(window_);
|
|
|
GetClientRect(hwnd, &sourceRect);
|
|
|
ClientToScreen(hwnd, (LPPOINT)&sourceRect);
|
|
|
}
|
|
|
@@ -683,7 +684,7 @@ bool Graphics::BeginFrame()
|
|
|
{
|
|
|
int width, height;
|
|
|
|
|
|
- SDL_GetWindowSize(impl_->window_, &width, &height);
|
|
|
+ SDL_GetWindowSize(window_, &width, &height);
|
|
|
if (width != width_ || height != 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
|
|
|
// and the window is minimized
|
|
|
- if (fullscreen_ && (SDL_GetWindowFlags(impl_->window_) & SDL_WINDOW_MINIMIZED))
|
|
|
+ if (fullscreen_ && (SDL_GetWindowFlags(window_) & SDL_WINDOW_MINIMIZED))
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -1873,7 +1874,7 @@ void Graphics::PrecacheShaders(Deserializer& source)
|
|
|
|
|
|
bool Graphics::IsInitialized() const
|
|
|
{
|
|
|
- return impl_->window_ != 0 && impl_->GetDevice() != 0;
|
|
|
+ return window_ != 0 && impl_->GetDevice() != 0;
|
|
|
}
|
|
|
|
|
|
PODVector<int> Graphics::GetMultiSampleLevels() const
|
|
|
@@ -2002,12 +2003,12 @@ bool Graphics::IsDeviceLost() const
|
|
|
|
|
|
void Graphics::OnWindowResized()
|
|
|
{
|
|
|
- if (!impl_->device_ || !impl_->window_)
|
|
|
+ if (!impl_->device_ || !window_)
|
|
|
return;
|
|
|
|
|
|
int newWidth, newHeight;
|
|
|
|
|
|
- SDL_GetWindowSize(impl_->window_, &newWidth, &newHeight);
|
|
|
+ SDL_GetWindowSize(window_, &newWidth, &newHeight);
|
|
|
if (newWidth == width_ && newHeight == height_)
|
|
|
return;
|
|
|
|
|
|
@@ -2036,12 +2037,12 @@ void Graphics::OnWindowResized()
|
|
|
|
|
|
void Graphics::OnWindowMoved()
|
|
|
{
|
|
|
- if (!impl_->device_ || !impl_->window_ || fullscreen_)
|
|
|
+ if (!impl_->device_ || !window_ || fullscreen_)
|
|
|
return;
|
|
|
|
|
|
int newX, newY;
|
|
|
|
|
|
- SDL_GetWindowPosition(impl_->window_, &newX, &newY);
|
|
|
+ SDL_GetWindowPosition(window_, &newX, &newY);
|
|
|
if (newX == position_.x_ && newY == position_.y_)
|
|
|
return;
|
|
|
|
|
|
@@ -2233,18 +2234,18 @@ bool Graphics::OpenWindow(int width, int height, bool resizable, bool borderless
|
|
|
if (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
|
|
|
- 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());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- SDL_GetWindowPosition(impl_->window_, &position_.x_, &position_.y_);
|
|
|
+ SDL_GetWindowPosition(window_, &position_.x_, &position_.y_);
|
|
|
|
|
|
CreateWindowIcon();
|
|
|
|
|
|
@@ -2257,22 +2258,22 @@ void Graphics::AdjustWindow(int& newWidth, int& newHeight, bool& newFullscreen,
|
|
|
{
|
|
|
if (!newWidth || !newHeight)
|
|
|
{
|
|
|
- SDL_MaximizeWindow(impl_->window_);
|
|
|
- SDL_GetWindowSize(impl_->window_, &newWidth, &newHeight);
|
|
|
+ SDL_MaximizeWindow(window_);
|
|
|
+ SDL_GetWindowSize(window_, &newWidth, &newHeight);
|
|
|
}
|
|
|
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
|
|
|
- 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
|
|
|
{
|
|
|
// 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;
|
|
|
}
|
|
|
}
|
|
|
@@ -2328,7 +2329,7 @@ bool Graphics::CreateDevice(unsigned adapter, unsigned deviceType)
|
|
|
HRESULT hr = impl_->interface_->CreateDevice(
|
|
|
adapter,
|
|
|
(D3DDEVTYPE)deviceType,
|
|
|
- GetWindowHandle(impl_->window_),
|
|
|
+ GetWindowHandle(window_),
|
|
|
behaviorFlags,
|
|
|
&impl_->presentParams_,
|
|
|
&impl_->device_);
|