/// <summary>
        /// Creates all resources
        /// </summary>
        private void CreateResources(int viewWidth, int viewHeight, DpiScaling dpiScaling, bool forceInit)
        {
            // Calculate the screen size in device independent units
            Size2F scaledScreenSize = new Size2F(
                (float)viewWidth / dpiScaling.ScaleFactorX,
                (float)viewHeight / dpiScaling.ScaleFactorY);

            // Cancel here if the device does not support 2D rendering
            if ((!forceInit) &&
                (!m_device.Supports2D))
            {
                return;
            }

            if (!m_device.IsUsingFallbackMethodFor2D)
            {
                // Create the render target
                using (DXGI.Surface dxgiSurface = m_renderTarget3D.QueryInterface <DXGI.Surface>())
                {
                    D2D.BitmapProperties1 bitmapProperties = new D2D.BitmapProperties1();
                    bitmapProperties.DpiX          = dpiScaling.DpiX;
                    bitmapProperties.DpiY          = dpiScaling.DpiY;
                    bitmapProperties.BitmapOptions = D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw;
                    bitmapProperties.PixelFormat   = new D2D.PixelFormat(GraphicsHelper.DEFAULT_TEXTURE_FORMAT, D2D.AlphaMode.Premultiplied);

                    m_renderTargetBitmap = new SharpDX.Direct2D1.Bitmap1(m_device.DeviceContextD2D, dxgiSurface, bitmapProperties);
                    m_renderTarget2D     = m_device.DeviceContextD2D;
                    m_graphics2D         = new Graphics2D(m_device, m_device.DeviceContextD2D, scaledScreenSize);
                }
            }
            else
            {
                using (DXGI.Surface dxgiSurface = m_renderTarget3D.QueryInterface <DXGI.Surface>())
                {
                    m_renderTarget2D = new D2D.RenderTarget(
                        m_device.Core.FactoryD2D,
                        dxgiSurface,
                        new D2D.RenderTargetProperties()
                    {
                        MinLevel    = D2D.FeatureLevel.Level_10,
                        Type        = D2D.RenderTargetType.Default,
                        Usage       = D2D.RenderTargetUsage.ForceBitmapRemoting,
                        PixelFormat = new D2D.PixelFormat(GraphicsHelper.DEFAULT_TEXTURE_FORMAT, D2D.AlphaMode.Premultiplied),
                        DpiX        = dpiScaling.DpiX,
                        DpiY        = dpiScaling.DpiY
                    });
                    m_graphics2D = new Graphics2D(m_device, m_renderTarget2D, scaledScreenSize);
                    return;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Direct2DOverlayRenderer"/> class.
        /// </summary>
        internal Direct2DOverlayRenderer(EngineDevice device, D3D11.Texture2D renderTarget3D, int viewWidth, int viewHeight, DpiScaling dpiScaling, bool forceInit)
        {
            m_device         = device;
            m_renderTarget3D = renderTarget3D;

            CreateResources(viewWidth, viewHeight, dpiScaling, forceInit);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Direct2DOverlayRenderer"/> class.
 /// </summary>
 public Direct2DOverlayRenderer(EngineDevice device, D3D11.Texture2D renderTarget3D, int viewWidth, int viewHeight, DpiScaling dpiScaling)
     : this(device, renderTarget3D, viewWidth, viewHeight, dpiScaling, false)
 {
 }