|
|
@@ -15,56 +15,45 @@
|
|
|
|
|
|
namespace BansheeEngine
|
|
|
{
|
|
|
- D3D11RenderWindow::D3D11RenderWindow(const RENDER_WINDOW_DESC& desc,D3D11Device& device, IDXGIFactory* DXGIFactory)
|
|
|
- : RenderWindow(desc), mDevice(device), mDXGIFactory(DXGIFactory), mIsExternal(false), mSizing(false),
|
|
|
- mClosed(false), mRenderTargetView(nullptr), mBackBuffer(nullptr), mSwapChain(nullptr), mHWnd(0),
|
|
|
+ D3D11RenderWindowCore::D3D11RenderWindowCore(D3D11RenderWindow* parent, RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc, D3D11Device& device, IDXGIFactory* DXGIFactory)
|
|
|
+ : RenderWindowCore(parent, properties), mDevice(device), mDXGIFactory(DXGIFactory), mIsExternal(false), mSizing(false),
|
|
|
+ mRenderTargetView(nullptr), mBackBuffer(nullptr), mSwapChain(nullptr), mHWnd(0),
|
|
|
mDepthStencilView(nullptr), mIsChild(false), mRefreshRateNumerator(0), mRefreshRateDenominator(0)
|
|
|
{
|
|
|
ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
|
|
|
- }
|
|
|
|
|
|
- D3D11RenderWindow::~D3D11RenderWindow()
|
|
|
- {
|
|
|
- }
|
|
|
+ D3D11RenderWindowProperties* props = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
|
|
|
- void D3D11RenderWindow::initialize_internal()
|
|
|
- {
|
|
|
mMultisampleType.Count = 1;
|
|
|
mMultisampleType.Quality = 0;
|
|
|
- mMultisampleCount = 0;
|
|
|
- mMultisampleHint = "";
|
|
|
- mVSync = false;
|
|
|
- mVSyncInterval = 1;
|
|
|
HWND parentHWnd = 0;
|
|
|
HWND externalHandle = 0;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
NameValuePairList::const_iterator opt;
|
|
|
- opt = mDesc.platformSpecific.find("parentWindowHandle");
|
|
|
- if(opt != mDesc.platformSpecific.end())
|
|
|
+ opt = desc.platformSpecific.find("parentWindowHandle");
|
|
|
+ if (opt != desc.platformSpecific.end())
|
|
|
parentHWnd = (HWND)parseUnsignedInt(opt->second);
|
|
|
|
|
|
- opt = mDesc.platformSpecific.find("externalWindowHandle");
|
|
|
- if(opt != mDesc.platformSpecific.end())
|
|
|
+ opt = desc.platformSpecific.find("externalWindowHandle");
|
|
|
+ if (opt != desc.platformSpecific.end())
|
|
|
externalHandle = (HWND)parseUnsignedInt(opt->second);
|
|
|
|
|
|
- mName = mDesc.title;
|
|
|
+ props->mName = desc.title;
|
|
|
mIsChild = parentHWnd != 0;
|
|
|
- mIsFullScreen = mDesc.fullscreen && !mIsChild;
|
|
|
- mColorDepth = 32;
|
|
|
- mWidth = mHeight = mLeft = mTop = 0;
|
|
|
+ props->mIsFullScreen = desc.fullscreen && !mIsChild;
|
|
|
+ props->mColorDepth = 32;
|
|
|
|
|
|
- mActive = true;
|
|
|
- mClosed = false;
|
|
|
+ props->mActive = true;
|
|
|
|
|
|
- if (mDesc.videoMode.isCustom())
|
|
|
+ if (desc.videoMode.isCustom())
|
|
|
{
|
|
|
- mRefreshRateNumerator = Math::roundToInt(mDesc.videoMode.getRefreshRate());
|
|
|
+ mRefreshRateNumerator = Math::roundToInt(desc.videoMode.getRefreshRate());
|
|
|
mRefreshRateDenominator = 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- const D3D11VideoMode& d3d11videoMode = static_cast<const D3D11VideoMode&>(mDesc.videoMode);
|
|
|
+ const D3D11VideoMode& d3d11videoMode = static_cast<const D3D11VideoMode&>(desc.videoMode);
|
|
|
mRefreshRateNumerator = d3d11videoMode.getRefreshRateNumerator();
|
|
|
mRefreshRateDenominator = d3d11videoMode.getRefreshRateDenominator();
|
|
|
}
|
|
|
@@ -76,7 +65,7 @@ namespace BansheeEngine
|
|
|
UINT32 numOutputs = videoModeInfo.getNumOutputs();
|
|
|
if (numOutputs > 0)
|
|
|
{
|
|
|
- UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
|
|
|
+ UINT32 actualMonitorIdx = std::min(desc.videoMode.getOutputIdx(), numOutputs - 1);
|
|
|
outputInfo = static_cast<const D3D11VideoOutputInfo*>(&videoModeInfo.getOutputInfo(actualMonitorIdx));
|
|
|
|
|
|
DXGI_OUTPUT_DESC desc;
|
|
|
@@ -87,7 +76,7 @@ namespace BansheeEngine
|
|
|
|
|
|
if (!externalHandle)
|
|
|
{
|
|
|
- DWORD dwStyle = (mHidden ? 0 : WS_VISIBLE) | WS_CLIPCHILDREN;
|
|
|
+ DWORD dwStyle = (getProperties().isHidden() ? 0 : WS_VISIBLE) | WS_CLIPCHILDREN;
|
|
|
DWORD dwStyleEx = 0;
|
|
|
RECT rc;
|
|
|
MONITORINFO monitorInfo;
|
|
|
@@ -98,8 +87,8 @@ namespace BansheeEngine
|
|
|
POINT windowAnchorPoint;
|
|
|
|
|
|
// Fill in anchor point.
|
|
|
- windowAnchorPoint.x = mDesc.left;
|
|
|
- windowAnchorPoint.y = mDesc.top;
|
|
|
+ windowAnchorPoint.x = desc.left;
|
|
|
+ windowAnchorPoint.y = desc.top;
|
|
|
|
|
|
// Get the nearest monitor to this window.
|
|
|
hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTOPRIMARY);
|
|
|
@@ -110,23 +99,22 @@ namespace BansheeEngine
|
|
|
monitorInfo.cbSize = sizeof(MONITORINFO);
|
|
|
GetMonitorInfo(hMonitor, &monitorInfo);
|
|
|
|
|
|
-
|
|
|
unsigned int winWidth, winHeight;
|
|
|
- winWidth = mDesc.videoMode.getWidth();
|
|
|
- winHeight = mDesc.videoMode.getHeight();
|
|
|
+ winWidth = desc.videoMode.getWidth();
|
|
|
+ winHeight = desc.videoMode.getHeight();
|
|
|
|
|
|
- UINT32 left = mDesc.left;
|
|
|
- UINT32 top = mDesc.top;
|
|
|
+ UINT32 left = desc.left;
|
|
|
+ UINT32 top = desc.top;
|
|
|
|
|
|
// No specified top left -> Center the window in the middle of the monitor
|
|
|
if (left == -1 || top == -1)
|
|
|
- {
|
|
|
- int screenw = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
|
|
|
+ {
|
|
|
+ int screenw = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
|
|
|
int screenh = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
|
|
|
|
|
|
// clamp window dimensions to screen size
|
|
|
- int outerw = (int(winWidth) < screenw)? int(winWidth) : screenw;
|
|
|
- int outerh = (int(winHeight) < screenh)? int(winHeight) : screenh;
|
|
|
+ int outerw = (int(winWidth) < screenw) ? int(winWidth) : screenw;
|
|
|
+ int outerh = (int(winHeight) < screenh) ? int(winHeight) : screenh;
|
|
|
|
|
|
if (left == -1)
|
|
|
left = monitorInfo.rcWork.left + (screenw - outerw) / 2;
|
|
|
@@ -144,62 +132,63 @@ namespace BansheeEngine
|
|
|
top += monitorInfo.rcWork.top;
|
|
|
}
|
|
|
|
|
|
- mWidth = mDesc.videoMode.getWidth();
|
|
|
- mHeight = mDesc.videoMode.getHeight();
|
|
|
- mTop = top;
|
|
|
- mLeft = left;
|
|
|
+ props->mWidth = desc.videoMode.getWidth();
|
|
|
+ props->mHeight = desc.videoMode.getHeight();
|
|
|
+ props->mTop = top;
|
|
|
+ props->mLeft = left;
|
|
|
|
|
|
- if (!mDesc.fullscreen)
|
|
|
+ if (!desc.fullscreen)
|
|
|
{
|
|
|
if (parentHWnd)
|
|
|
{
|
|
|
- if(mDesc.toolWindow)
|
|
|
+ if (desc.toolWindow)
|
|
|
dwStyleEx = WS_EX_TOOLWINDOW;
|
|
|
else
|
|
|
dwStyle |= WS_CHILD;
|
|
|
}
|
|
|
|
|
|
- if (!parentHWnd || mDesc.toolWindow)
|
|
|
+ if (!parentHWnd || desc.toolWindow)
|
|
|
{
|
|
|
- if (mDesc.border == WindowBorder::None)
|
|
|
+ if (desc.border == WindowBorder::None)
|
|
|
dwStyle |= WS_POPUP;
|
|
|
- else if (mDesc.border == WindowBorder::Fixed)
|
|
|
+ else if (desc.border == WindowBorder::Fixed)
|
|
|
dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
|
|
|
WS_SYSMENU | WS_MINIMIZEBOX;
|
|
|
else
|
|
|
dwStyle |= WS_OVERLAPPEDWINDOW;
|
|
|
}
|
|
|
|
|
|
- if (!mDesc.outerDimensions)
|
|
|
+ if (!desc.outerDimensions)
|
|
|
{
|
|
|
// Calculate window dimensions required
|
|
|
// to get the requested client area
|
|
|
- SetRect(&rc, 0, 0, mWidth, mHeight);
|
|
|
+ SetRect(&rc, 0, 0, props->mWidth, props->mHeight);
|
|
|
AdjustWindowRect(&rc, dwStyle, false);
|
|
|
- mWidth = rc.right - rc.left;
|
|
|
- mHeight = rc.bottom - rc.top;
|
|
|
+ props->mWidth = rc.right - rc.left;
|
|
|
+ props->mHeight = rc.bottom - rc.top;
|
|
|
|
|
|
// Clamp width and height to the desktop dimensions
|
|
|
int screenw = GetSystemMetrics(SM_CXSCREEN);
|
|
|
int screenh = GetSystemMetrics(SM_CYSCREEN);
|
|
|
- if ((int)mWidth > screenw)
|
|
|
- mWidth = screenw;
|
|
|
- if ((int)mHeight > screenh)
|
|
|
- mHeight = screenh;
|
|
|
- if (mLeft < 0)
|
|
|
- mLeft = (screenw - mWidth) / 2;
|
|
|
- if (mTop < 0)
|
|
|
- mTop = (screenh - mHeight) / 2;
|
|
|
+ if ((int)props->mWidth > screenw)
|
|
|
+ props->mWidth = screenw;
|
|
|
+ if ((int)props->mHeight > screenh)
|
|
|
+ props->mHeight = screenh;
|
|
|
+ if (props->mLeft < 0)
|
|
|
+ props->mLeft = (screenw - props->mWidth) / 2;
|
|
|
+ if (props->mTop < 0)
|
|
|
+ props->mTop = (screenh - props->mHeight) / 2;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
dwStyle |= WS_POPUP;
|
|
|
- mTop = mLeft = 0;
|
|
|
+ props->mTop = 0;
|
|
|
+ props->mLeft = 0;
|
|
|
}
|
|
|
|
|
|
UINT classStyle = 0;
|
|
|
- if (mDesc.enableDoubleClick)
|
|
|
+ if (desc.enableDoubleClick)
|
|
|
classStyle |= CS_DBLCLKS;
|
|
|
|
|
|
HINSTANCE hInst = NULL;
|
|
|
@@ -208,15 +197,15 @@ namespace BansheeEngine
|
|
|
// Allow 4 bytes of window data for D3D11RenderWindow pointer
|
|
|
WNDCLASS wc = { classStyle, PlatformWndProc::_win32WndProc, 0, 0, hInst,
|
|
|
LoadIcon(0, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW),
|
|
|
- (HBRUSH)GetStockObject(BLACK_BRUSH), 0, "D3D11Wnd" };
|
|
|
+ (HBRUSH)GetStockObject(BLACK_BRUSH), 0, "D3D11Wnd" };
|
|
|
|
|
|
RegisterClass(&wc);
|
|
|
|
|
|
// Create our main window
|
|
|
// Pass pointer to self
|
|
|
mIsExternal = false;
|
|
|
- mHWnd = CreateWindowEx(dwStyleEx, "D3D11Wnd", mDesc.title.c_str(), dwStyle,
|
|
|
- mLeft, mTop, mWidth, mHeight, parentHWnd, 0, hInst, this);
|
|
|
+ mHWnd = CreateWindowEx(dwStyleEx, "D3D11Wnd", desc.title.c_str(), dwStyle,
|
|
|
+ props->mLeft, props->mTop, props->mWidth, props->mHeight, parentHWnd, 0, hInst, this);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -226,16 +215,16 @@ namespace BansheeEngine
|
|
|
|
|
|
RECT rc;
|
|
|
GetWindowRect(mHWnd, &rc);
|
|
|
- mTop = rc.top;
|
|
|
- mLeft = rc.left;
|
|
|
+ props->mTop = rc.top;
|
|
|
+ props->mLeft = rc.left;
|
|
|
|
|
|
GetClientRect(mHWnd, &rc);
|
|
|
- mWidth = rc.right;
|
|
|
- mHeight = rc.bottom;
|
|
|
+ props->mWidth = rc.right;
|
|
|
+ props->mHeight = rc.bottom;
|
|
|
|
|
|
createSwapChain();
|
|
|
|
|
|
- if (mIsFullScreen)
|
|
|
+ if (getProperties().isFullScreen())
|
|
|
{
|
|
|
if (outputInfo != nullptr)
|
|
|
mSwapChain->SetFullscreenState(true, outputInfo->getDXGIOutput());
|
|
|
@@ -245,15 +234,15 @@ namespace BansheeEngine
|
|
|
|
|
|
createSizeDependedD3DResources();
|
|
|
mDXGIFactory->MakeWindowAssociation(mHWnd, NULL);
|
|
|
- setHidden(mHidden);
|
|
|
-
|
|
|
- RenderWindow::initialize_internal();
|
|
|
+ setHidden(getProperties().isHidden());
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::destroy_internal()
|
|
|
+ D3D11RenderWindowCore::~D3D11RenderWindowCore()
|
|
|
{
|
|
|
- mActive = false;
|
|
|
- mClosed = true;
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
+
|
|
|
+ properties->mActive = false;
|
|
|
+ markCoreDirty();
|
|
|
|
|
|
SAFE_RELEASE(mSwapChain);
|
|
|
BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_SwapChain);
|
|
|
@@ -263,7 +252,7 @@ namespace BansheeEngine
|
|
|
DestroyWindow(mHWnd);
|
|
|
}
|
|
|
|
|
|
- if(mDepthStencilView != nullptr)
|
|
|
+ if (mDepthStencilView != nullptr)
|
|
|
{
|
|
|
Texture::releaseView(mDepthStencilView);
|
|
|
mDepthStencilView = nullptr;
|
|
|
@@ -272,65 +261,70 @@ namespace BansheeEngine
|
|
|
mHWnd = nullptr;
|
|
|
|
|
|
destroySizeDependedD3DResources();
|
|
|
-
|
|
|
- RenderWindow::destroy_internal();
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::swapBuffers()
|
|
|
+ void D3D11RenderWindowCore::swapBuffers()
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
if(mDevice.getD3D11Device() != nullptr)
|
|
|
{
|
|
|
- HRESULT hr = mSwapChain->Present(mVSync ? mVSyncInterval : 0, 0);
|
|
|
+ HRESULT hr = mSwapChain->Present(getProperties().getVSync() ? getProperties().getVSyncInterval() : 0, 0);
|
|
|
|
|
|
if( FAILED(hr) )
|
|
|
BS_EXCEPT(RenderingAPIException, "Error Presenting surfaces");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::move(INT32 top, INT32 left)
|
|
|
+ void D3D11RenderWindowCore::move(INT32 top, INT32 left)
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
- if (mHWnd && !mIsFullScreen)
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
+
|
|
|
+ if (mHWnd && !properties->mIsFullScreen)
|
|
|
{
|
|
|
- mTop = top;
|
|
|
- mLeft = left;
|
|
|
+ properties->mTop = top;
|
|
|
+ properties->mLeft = left;
|
|
|
|
|
|
- SetWindowPos(mHWnd, 0, top, left, 0, 0,
|
|
|
- SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
+ SetWindowPos(mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
+ markCoreDirty();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::resize(UINT32 width, UINT32 height)
|
|
|
+ void D3D11RenderWindowCore::resize(UINT32 width, UINT32 height)
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
- if (mHWnd && !mIsFullScreen)
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
+
|
|
|
+ if (mHWnd && !properties->mIsFullScreen)
|
|
|
{
|
|
|
- mWidth = width;
|
|
|
- mHeight = height;
|
|
|
+ properties->mWidth = width;
|
|
|
+ properties->mHeight = height;
|
|
|
|
|
|
RECT rc = { 0, 0, width, height };
|
|
|
AdjustWindowRect(&rc, GetWindowLong(mHWnd, GWL_STYLE), false);
|
|
|
width = rc.right - rc.left;
|
|
|
height = rc.bottom - rc.top;
|
|
|
- SetWindowPos(mHWnd, 0, 0, 0, width, height,
|
|
|
- SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
+
|
|
|
+ SetWindowPos(mHWnd, 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
+ markCoreDirty();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::setActive(bool state)
|
|
|
+ void D3D11RenderWindowCore::setActive(bool state)
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
+
|
|
|
if (mHWnd && mSwapChain)
|
|
|
{
|
|
|
if (state)
|
|
|
{
|
|
|
ShowWindow(mHWnd, SW_RESTORE);
|
|
|
- mSwapChain->SetFullscreenState(mIsFullScreen, nullptr);
|
|
|
+ mSwapChain->SetFullscreenState(properties->mIsFullScreen, nullptr);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -339,14 +333,16 @@ namespace BansheeEngine
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- RenderWindow::setActive(state);
|
|
|
+ RenderWindowCore::setActive(state);
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::setHidden(bool hidden)
|
|
|
+ void D3D11RenderWindowCore::setHidden(bool hidden)
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
- mHidden = hidden;
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
+
|
|
|
+ properties->mHidden = hidden;
|
|
|
if (!mIsExternal)
|
|
|
{
|
|
|
if (hidden)
|
|
|
@@ -354,9 +350,11 @@ namespace BansheeEngine
|
|
|
else
|
|
|
ShowWindow(mHWnd, SW_SHOWNORMAL);
|
|
|
}
|
|
|
+
|
|
|
+ markCoreDirty();
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
|
|
|
+ void D3D11RenderWindowCore::setFullscreen(UINT32 width, UINT32 height, float refreshRate, UINT32 monitorIdx)
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
@@ -387,15 +385,18 @@ namespace BansheeEngine
|
|
|
|
|
|
outputInfo.getDXGIOutput()->FindClosestMatchingMode(&modeDesc, &nearestMode, nullptr);
|
|
|
|
|
|
- mIsFullScreen = true;
|
|
|
- mWidth = width;
|
|
|
- mHeight = height;
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
+ properties->mIsFullScreen = true;
|
|
|
+ properties->mWidth = width;
|
|
|
+ properties->mHeight = height;
|
|
|
|
|
|
mSwapChain->ResizeTarget(&nearestMode);
|
|
|
mSwapChain->SetFullscreenState(true, outputInfo.getDXGIOutput());
|
|
|
+
|
|
|
+ markCoreDirty();
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::setFullscreen(const VideoMode& mode)
|
|
|
+ void D3D11RenderWindowCore::setFullscreen(const VideoMode& mode)
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
@@ -418,42 +419,48 @@ namespace BansheeEngine
|
|
|
|
|
|
const D3D11VideoMode& videoMode = static_cast<const D3D11VideoMode&>(mode);
|
|
|
|
|
|
- mIsFullScreen = true;
|
|
|
- mWidth = mode.getWidth();
|
|
|
- mHeight = mode.getHeight();
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
+ properties->mIsFullScreen = true;
|
|
|
+ properties->mWidth = mode.getWidth();
|
|
|
+ properties->mHeight = mode.getHeight();
|
|
|
|
|
|
mSwapChain->ResizeTarget(&videoMode.getDXGIModeDesc());
|
|
|
mSwapChain->SetFullscreenState(true, outputInfo.getDXGIOutput());
|
|
|
+
|
|
|
+ markCoreDirty();
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::setWindowed(UINT32 width, UINT32 height)
|
|
|
+ void D3D11RenderWindowCore::setWindowed(UINT32 width, UINT32 height)
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
- mWidth = width;
|
|
|
- mHeight = height;
|
|
|
- mIsFullScreen = false;
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
+ properties->mWidth = width;
|
|
|
+ properties->mHeight = height;
|
|
|
+ properties->mIsFullScreen = false;
|
|
|
|
|
|
mSwapChainDesc.Windowed = true;
|
|
|
mSwapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
|
|
|
mSwapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
|
|
|
- mSwapChainDesc.BufferDesc.Width = mWidth;
|
|
|
- mSwapChainDesc.BufferDesc.Height = mHeight;
|
|
|
+ mSwapChainDesc.BufferDesc.Width = width;
|
|
|
+ mSwapChainDesc.BufferDesc.Height = height;
|
|
|
|
|
|
DXGI_MODE_DESC modeDesc;
|
|
|
ZeroMemory(&modeDesc, sizeof(modeDesc));
|
|
|
|
|
|
- modeDesc.Width = mWidth;
|
|
|
- modeDesc.Height = mHeight;
|
|
|
+ modeDesc.Width = width;
|
|
|
+ modeDesc.Height = height;
|
|
|
modeDesc.RefreshRate.Numerator = 0;
|
|
|
modeDesc.RefreshRate.Denominator = 0;
|
|
|
modeDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
|
|
mSwapChain->SetFullscreenState(false, nullptr);
|
|
|
mSwapChain->ResizeTarget(&modeDesc);
|
|
|
+
|
|
|
+ markCoreDirty();
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::getCustomAttribute( const String& name, void* pData ) const
|
|
|
+ void D3D11RenderWindowCore::getCustomAttribute(const String& name, void* pData) const
|
|
|
{
|
|
|
if(name == "WINDOW")
|
|
|
{
|
|
|
@@ -474,10 +481,10 @@ namespace BansheeEngine
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- RenderWindow::getCustomAttribute(name, pData);
|
|
|
+ RenderWindowCore::getCustomAttribute(name, pData);
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::copyToMemory(PixelData &dst, FrameBuffer buffer)
|
|
|
+ void D3D11RenderWindowCore::copyToMemory(PixelData &dst, FrameBuffer buffer)
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
@@ -535,7 +542,7 @@ namespace BansheeEngine
|
|
|
mDevice.getImmediateContext()->Map(tempTexture, 0,D3D11_MAP_READ, 0, &mappedTex2D);
|
|
|
|
|
|
// Copy the the texture to the dest
|
|
|
- PixelData src(mWidth, mHeight, 1, PF_A8B8G8R8);
|
|
|
+ PixelData src(getProperties().getWidth(), getProperties().getHeight(), 1, PF_A8B8G8R8);
|
|
|
src.setExternalBuffer((UINT8*)mappedTex2D.pData);
|
|
|
PixelUtil::bulkPixelConversion(src, dst);
|
|
|
|
|
|
@@ -547,27 +554,7 @@ namespace BansheeEngine
|
|
|
SAFE_RELEASE(backbuffer);
|
|
|
}
|
|
|
|
|
|
- Vector2I D3D11RenderWindow::screenToWindowPos(const Vector2I& screenPos) const
|
|
|
- {
|
|
|
- POINT pos;
|
|
|
- pos.x = screenPos.x;
|
|
|
- pos.y = screenPos.y;
|
|
|
-
|
|
|
- ScreenToClient(mHWnd, &pos);
|
|
|
- return Vector2I(pos.x, pos.y);
|
|
|
- }
|
|
|
-
|
|
|
- Vector2I D3D11RenderWindow::windowToScreenPos(const Vector2I& windowPos) const
|
|
|
- {
|
|
|
- POINT pos;
|
|
|
- pos.x = windowPos.x;
|
|
|
- pos.y = windowPos.y;
|
|
|
-
|
|
|
- ClientToScreen(mHWnd, &pos);
|
|
|
- return Vector2I(pos.x, pos.y);
|
|
|
- }
|
|
|
-
|
|
|
- void D3D11RenderWindow::_windowMovedOrResized()
|
|
|
+ void D3D11RenderWindowCore::_windowMovedOrResized()
|
|
|
{
|
|
|
THROW_IF_NOT_CORE_THREAD;
|
|
|
|
|
|
@@ -576,8 +563,11 @@ namespace BansheeEngine
|
|
|
|
|
|
RECT rc;
|
|
|
GetWindowRect(mHWnd, &rc);
|
|
|
- mTop = rc.top;
|
|
|
- mLeft = rc.left;
|
|
|
+
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
+ properties->mTop = rc.top;
|
|
|
+ properties->mLeft = rc.left;
|
|
|
+ markCoreDirty();
|
|
|
|
|
|
GetClientRect(mHWnd, &rc);
|
|
|
unsigned int width = rc.right - rc.left;
|
|
|
@@ -591,10 +581,10 @@ namespace BansheeEngine
|
|
|
|
|
|
resizeSwapChainBuffers(width, height);
|
|
|
|
|
|
- RenderWindow::_windowMovedOrResized();
|
|
|
+ RenderWindowCore::_windowMovedOrResized();
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::createSwapChain()
|
|
|
+ void D3D11RenderWindowCore::createSwapChain()
|
|
|
{
|
|
|
ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
|
|
|
|
|
|
@@ -603,11 +593,11 @@ namespace BansheeEngine
|
|
|
ZeroMemory(&mSwapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));
|
|
|
DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
mSwapChainDesc.OutputWindow = mHWnd;
|
|
|
- mSwapChainDesc.BufferDesc.Width = mWidth;
|
|
|
- mSwapChainDesc.BufferDesc.Height = mHeight;
|
|
|
+ mSwapChainDesc.BufferDesc.Width = getProperties().getWidth();
|
|
|
+ mSwapChainDesc.BufferDesc.Height = getProperties().getHeight();
|
|
|
mSwapChainDesc.BufferDesc.Format = format;
|
|
|
|
|
|
- if (mIsFullScreen)
|
|
|
+ if (getProperties().isFullScreen())
|
|
|
{
|
|
|
mSwapChainDesc.BufferDesc.RefreshRate.Numerator = mRefreshRateNumerator;
|
|
|
mSwapChainDesc.BufferDesc.RefreshRate.Denominator = mRefreshRateDenominator;
|
|
|
@@ -629,7 +619,7 @@ namespace BansheeEngine
|
|
|
mSwapChainDesc.Windowed = true;
|
|
|
|
|
|
D3D11RenderSystem* rs = static_cast<D3D11RenderSystem*>(RenderSystem::instancePtr());
|
|
|
- rs->determineMultisampleSettings(mMultisampleCount, mMultisampleHint, format, &mMultisampleType);
|
|
|
+ rs->determineMultisampleSettings(getProperties().getMultisampleCount(), getProperties().getMultisampleHint(), format, &mMultisampleType);
|
|
|
mSwapChainDesc.SampleDesc.Count = mMultisampleType.Count;
|
|
|
mSwapChainDesc.SampleDesc.Quality = mMultisampleType.Quality;
|
|
|
|
|
|
@@ -653,7 +643,7 @@ namespace BansheeEngine
|
|
|
BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_SwapChain);
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::createSizeDependedD3DResources()
|
|
|
+ void D3D11RenderWindowCore::createSizeDependedD3DResources()
|
|
|
{
|
|
|
SAFE_RELEASE(mBackBuffer);
|
|
|
|
|
|
@@ -670,7 +660,7 @@ namespace BansheeEngine
|
|
|
ZeroMemory( &RTVDesc, sizeof(RTVDesc) );
|
|
|
|
|
|
RTVDesc.Format = BBDesc.Format;
|
|
|
- RTVDesc.ViewDimension = mMultisampleCount ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D;
|
|
|
+ RTVDesc.ViewDimension = getProperties().getMultisampleCount() ? D3D11_RTV_DIMENSION_TEXTURE2DMS : D3D11_RTV_DIMENSION_TEXTURE2D;
|
|
|
RTVDesc.Texture2D.MipSlice = 0;
|
|
|
hr = mDevice.getD3D11Device()->CreateRenderTargetView(mBackBuffer, &RTVDesc, &mRenderTargetView);
|
|
|
|
|
|
@@ -681,7 +671,8 @@ namespace BansheeEngine
|
|
|
}
|
|
|
|
|
|
mDepthStencilBuffer = TextureManager::instance().createTexture(TEX_TYPE_2D,
|
|
|
- BBDesc.Width, BBDesc.Height, 0, PF_D24S8, TU_DEPTHSTENCIL, false, mMultisampleCount, mMultisampleHint);
|
|
|
+ BBDesc.Width, BBDesc.Height, 0, PF_D24S8, TU_DEPTHSTENCIL, false,
|
|
|
+ getProperties().getMultisampleCount(), getProperties().getMultisampleHint());
|
|
|
|
|
|
if(mDepthStencilView != nullptr)
|
|
|
{
|
|
|
@@ -692,7 +683,7 @@ namespace BansheeEngine
|
|
|
mDepthStencilView = Texture::requestView(mDepthStencilBuffer, 0, 1, 0, 1, GVU_DEPTHSTENCIL);
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::destroySizeDependedD3DResources()
|
|
|
+ void D3D11RenderWindowCore::destroySizeDependedD3DResources()
|
|
|
{
|
|
|
SAFE_RELEASE(mBackBuffer);
|
|
|
SAFE_RELEASE(mRenderTargetView);
|
|
|
@@ -700,27 +691,29 @@ namespace BansheeEngine
|
|
|
mDepthStencilBuffer = nullptr;
|
|
|
}
|
|
|
|
|
|
- void D3D11RenderWindow::resizeSwapChainBuffers(UINT32 width, UINT32 height)
|
|
|
+ void D3D11RenderWindowCore::resizeSwapChainBuffers(UINT32 width, UINT32 height)
|
|
|
{
|
|
|
destroySizeDependedD3DResources();
|
|
|
|
|
|
- UINT Flags = mIsFullScreen ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0;
|
|
|
+ UINT Flags = getProperties().isFullScreen() ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0;
|
|
|
HRESULT hr = mSwapChain->ResizeBuffers(mSwapChainDesc.BufferCount, width, height, mSwapChainDesc.BufferDesc.Format, Flags);
|
|
|
|
|
|
if(hr != S_OK)
|
|
|
BS_EXCEPT(InternalErrorException, "Call to ResizeBuffers failed.");
|
|
|
|
|
|
+ D3D11RenderWindowProperties* properties = static_cast<D3D11RenderWindowProperties*>(mProperties);
|
|
|
mSwapChain->GetDesc(&mSwapChainDesc);
|
|
|
- mWidth = mSwapChainDesc.BufferDesc.Width;
|
|
|
- mHeight = mSwapChainDesc.BufferDesc.Height;
|
|
|
- mIsFullScreen = (0 == mSwapChainDesc.Windowed); // Alt-Enter together with SetWindowAssociation() can change this state
|
|
|
+ properties->mWidth = mSwapChainDesc.BufferDesc.Width;
|
|
|
+ properties->mHeight = mSwapChainDesc.BufferDesc.Height;
|
|
|
+ properties->mIsFullScreen = (0 == mSwapChainDesc.Windowed); // Alt-Enter together with SetWindowAssociation() can change this state
|
|
|
+ markCoreDirty();
|
|
|
|
|
|
createSizeDependedD3DResources();
|
|
|
|
|
|
mDevice.getImmediateContext()->OMSetRenderTargets(0, 0, 0);
|
|
|
}
|
|
|
|
|
|
- IDXGIDevice* D3D11RenderWindow::queryDxgiDevice()
|
|
|
+ IDXGIDevice* D3D11RenderWindowCore::queryDxgiDevice()
|
|
|
{
|
|
|
if (mDevice.getD3D11Device() == nullptr)
|
|
|
{
|
|
|
@@ -735,4 +728,61 @@ namespace BansheeEngine
|
|
|
|
|
|
return pDXGIDevice;
|
|
|
}
|
|
|
+
|
|
|
+ D3D11RenderWindow::D3D11RenderWindow(D3D11Device& device, IDXGIFactory* DXGIFactory)
|
|
|
+ :mDevice(device), mDXGIFactory(DXGIFactory), mHWnd(0)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ void D3D11RenderWindow::getCustomAttribute(const String& name, void* pData) const
|
|
|
+ {
|
|
|
+ THROW_IF_CORE_THREAD;
|
|
|
+
|
|
|
+ if (name == "WINDOW")
|
|
|
+ {
|
|
|
+ HWND *pWnd = (HWND*)pData;
|
|
|
+ *pWnd = mHWnd;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ RenderWindow::getCustomAttribute(name, pData);
|
|
|
+ }
|
|
|
+
|
|
|
+ Vector2I D3D11RenderWindow::screenToWindowPos(const Vector2I& screenPos) const
|
|
|
+ {
|
|
|
+ POINT pos;
|
|
|
+ pos.x = screenPos.x;
|
|
|
+ pos.y = screenPos.y;
|
|
|
+
|
|
|
+ ScreenToClient(mHWnd, &pos);
|
|
|
+ return Vector2I(pos.x, pos.y);
|
|
|
+ }
|
|
|
+
|
|
|
+ Vector2I D3D11RenderWindow::windowToScreenPos(const Vector2I& windowPos) const
|
|
|
+ {
|
|
|
+ POINT pos;
|
|
|
+ pos.x = windowPos.x;
|
|
|
+ pos.y = windowPos.y;
|
|
|
+
|
|
|
+ ClientToScreen(mHWnd, &pos);
|
|
|
+ return Vector2I(pos.x, pos.y);
|
|
|
+ }
|
|
|
+
|
|
|
+ void D3D11RenderWindow::initialize_internal()
|
|
|
+ {
|
|
|
+ RenderWindow::initialize_internal();
|
|
|
+
|
|
|
+ mCore->getCustomAttribute("WINDOW", (void*)&mHWnd);
|
|
|
+ }
|
|
|
+
|
|
|
+ RenderTargetProperties* D3D11RenderWindow::createProperties() const
|
|
|
+ {
|
|
|
+ return bs_new<RenderWindowProperties>();
|
|
|
+ }
|
|
|
+
|
|
|
+ RenderWindowCore* D3D11RenderWindow::createCore(RenderWindowProperties* properties, const RENDER_WINDOW_DESC& desc)
|
|
|
+ {
|
|
|
+ return bs_new<D3D11RenderWindowCore>(this, properties, desc, mDevice, mDXGIFactory);
|
|
|
+ }
|
|
|
}
|