/// <summary> /// Creates all resources /// </summary> private void CreateResources(int viewWidth, int viewHeight, DpiScaling dpiScaling, bool forceInit) { // Calculate the screen size in device independent units var scaledScreenSize = new SizeF( viewWidth / dpiScaling.ScaleFactorX, viewHeight / dpiScaling.ScaleFactorY); // Cancel here if the device does not support 2D rendering if (!forceInit && !_device.Supports2D) { return; } // Create the render target using (var dxgiSurface = _renderTarget3D.QueryInterface <IDXGISurface>()) { var bitmapProperties = new D2D.BitmapProperties1 { DpiX = dpiScaling.DpiX, DpiY = dpiScaling.DpiY, BitmapOptions = D2D.BitmapOptions.Target | D2D.BitmapOptions.CannotDraw, PixelFormat = new PixelFormat( GraphicsHelper.Internals.DEFAULT_TEXTURE_FORMAT, AlphaMode.Premultiplied) }; _renderTargetBitmap = _device.DeviceContextD2D.CreateBitmapFromDxgiSurface(dxgiSurface, bitmapProperties); _renderTarget2D = _device.DeviceContextD2D; _graphics2D = new Graphics2D(_device, _device.DeviceContextD2D, scaledScreenSize); } }
/// <summary> /// Initializes a new instance of the <see cref="Direct2DOverlayRenderer"/> class. /// </summary> internal Direct2DOverlayRenderer(EngineDevice device, D3D11.ID3D11Texture2D renderTarget3D, int viewWidth, int viewHeight, DpiScaling dpiScaling, bool forceInit) { _device = device; _renderTarget3D = renderTarget3D; this.CreateResources(viewWidth, viewHeight, dpiScaling, forceInit); }
/// <summary> /// Initializes a new instance of the <see cref="Direct2DOverlayRenderer"/> class. /// </summary> public Direct2DOverlayRenderer(EngineDevice device, D3D11.ID3D11Texture2D renderTarget3D, int viewWidth, int viewHeight, DpiScaling dpiScaling) : this(device, renderTarget3D, viewWidth, viewHeight, dpiScaling, false) { }