void D3D11RenderWindowCoreWindow::create(const String& name, unsigned int width, unsigned int height,
		bool fullScreen, const NameValuePairList *miscParams)
	{
		D3D11RenderWindowSwapChainBased::create(name, width, height, fullScreen, miscParams);

		Windows::UI::Core::CoreWindow^ externalHandle = nullptr;

		if(miscParams)
		{
			// Get variable-length params
			NameValuePairList::const_iterator opt;
			// externalWindowHandle		-> externalHandle
			opt = miscParams->find("externalWindowHandle");
			if(opt != miscParams->end())
				externalHandle = reinterpret_cast<Windows::UI::Core::CoreWindow^>((void*)StringConverter::parseSizeT(opt->second));
		}

		// Reset current window if any
		mCoreWindow = nullptr;

		if (!externalHandle)
		{
			OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS, "External window handle is not specified.", "D3D11RenderWindow::create" );
		}
		else
		{
			mCoreWindow = externalHandle;
			mIsExternal = true;
		}

		Windows::Foundation::Rect rc = mCoreWindow->Bounds;
		float scale = Windows::Graphics::Display::DisplayProperties::LogicalDpi / 96;
		mLeft = (int)(rc.X * scale);
		mTop = (int)(rc.Y * scale);
		mWidth = (int)(rc.Width * scale);
		mHeight = (int)(rc.Height * scale);

		LogManager::getSingleton().stream()
			<< "D3D11 : Created D3D11 Rendering Window '"
			<< mName << "' : " << mWidth << "x" << mHeight 
			<< ", " << mColourDepth << "bpp";

		_createSwapChain();
		_createSizeDependedD3DResources();
	}
Пример #2
0
//---------------------------------------------------------------------
void D3D11RenderWindowImageSource::create(const String& name, unsigned width, unsigned height, bool fullScreen, const NameValuePairList *miscParams)
{
    D3D11RenderWindowBase::create(name, width, height, fullScreen, miscParams);

    mWidth = width;
    mHeight = height;

    bool isOpaque = true;
    if(miscParams)
    {
        // Get variable-length params
        NameValuePairList::const_iterator opt;
        // isOpaque
        opt = miscParams->find("isOpaque");
        if(opt != miscParams->end())
            isOpaque = StringConverter::parseBool(opt->second);
    }

    // create brush
    // TODO: obtain from miscParams optional placeholder image and set inside the brush till first render???
    mBrush = ref new Windows::UI::Xaml::Media::ImageBrush;

    _createSizeDependedD3DResources();
}
Пример #3
0
//---------------------------------------------------------------------
void D3D11RenderWindowHwnd::create(const String& name, unsigned int width, unsigned int height,
                                   bool fullScreen, const NameValuePairList *miscParams)
{
    D3D11RenderWindowSwapChainBased::create(name, width, height, fullScreen, miscParams);

    HWND parentHWnd = 0;
    HWND externalHandle = 0;
    String title = name;
    int left = -1; // Defaults to screen center
    int top = -1; // Defaults to screen center
    String border = "";
    bool outerSize = false;
    bool enableDoubleClick = false;

    if(miscParams)
    {
        // Get variable-length params
        NameValuePairList::const_iterator opt;
        // left (x)
        opt = miscParams->find("left");
        if(opt != miscParams->end())
            left = StringConverter::parseInt(opt->second);
        // top (y)
        opt = miscParams->find("top");
        if(opt != miscParams->end())
            top = StringConverter::parseInt(opt->second);
        // Window title
        opt = miscParams->find("title");
        if(opt != miscParams->end())
            title = opt->second;
        // parentWindowHandle		-> parentHWnd
        opt = miscParams->find("parentWindowHandle");
        if(opt != miscParams->end())
            parentHWnd = (HWND)StringConverter::parseSizeT(opt->second);
        // externalWindowHandle		-> externalHandle
        opt = miscParams->find("externalWindowHandle");
        if(opt != miscParams->end())
            externalHandle = (HWND)StringConverter::parseSizeT(opt->second);
        // window border style
        opt = miscParams->find("border");
        if(opt != miscParams->end())
            border = opt->second;
        // set outer dimensions?
        opt = miscParams->find("outerDimensions");
        if(opt != miscParams->end())
            outerSize = StringConverter::parseBool(opt->second);
        // enable double click messages
        opt = miscParams->find("enableDoubleClick");
        if(opt != miscParams->end())
            enableDoubleClick = StringConverter::parseBool(opt->second);

    }

    // Destroy current window if any
    if( mHWnd )
        destroy();

    if (!externalHandle)
    {
        DWORD dwStyle = (mHidden ? 0 : WS_VISIBLE) | WS_CLIPCHILDREN;
        RECT rc;

        mWidth = width;
        mHeight = height;
        mTop = top;
        mLeft = left;

        if (!fullScreen)
        {
            if (parentHWnd)
            {
                dwStyle |= WS_CHILD;
            }
            else
            {
                if (border == "none")
                    dwStyle |= WS_POPUP;
                else if (border == "fixed")
                    dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
                               WS_SYSMENU | WS_MINIMIZEBOX;
                else
                    dwStyle |= WS_OVERLAPPEDWINDOW;
            }

            if (!outerSize)
            {
                // Calculate window dimensions required
                // to get the requested client area
                SetRect(&rc, 0, 0, mWidth, mHeight);
                AdjustWindowRect(&rc, dwStyle, false);
                mWidth = rc.right - rc.left;
                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;
            }
        }
        else
        {
            dwStyle |= WS_POPUP;
            mTop = mLeft = 0;
        }

        UINT classStyle = 0;
        if (enableDoubleClick)
            classStyle |= CS_DBLCLKS;

        HINSTANCE hInst = NULL;

        // Register the window class
        // NB allow 4 bytes of window data for D3D11RenderWindow pointer
        WNDCLASS wc = { classStyle, WindowEventUtilities::_WndProc, 0, 0, hInst,
                        LoadIcon(0, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW),
                        (HBRUSH)GetStockObject(BLACK_BRUSH), 0, "OgreD3D11Wnd"
                      };


        RegisterClass(&wc);

        // Create our main window
        // Pass pointer to self
        mIsExternal = false;
        mHWnd = CreateWindow("OgreD3D11Wnd", title.c_str(), dwStyle,
                             mLeft, mTop, mWidth, mHeight, parentHWnd, 0, hInst, this);

        WindowEventUtilities::_addRenderWindow(this);
    }
    else
    {
        mHWnd = externalHandle;
        mIsExternal = true;
    }

    RECT rc;
    // top and left represent outer window coordinates
    GetWindowRect(mHWnd, &rc);
    mTop = rc.top;
    mLeft = rc.left;
    // width and height represent interior drawable area
    GetClientRect(mHWnd, &rc);
    mWidth = rc.right;
    mHeight = rc.bottom;

    LogManager::getSingleton().stream()
            << "D3D11 : Created D3D11 Rendering Window '"
            << mName << "' : " << mWidth << "x" << mHeight
            << ", " << mColourDepth << "bpp";

    _createSwapChain();
    _createSizeDependedD3DResources();
    mpDXGIFactory->MakeWindowAssociation(mHWnd, NULL);
    setHidden(mHidden);
}