/// <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> /// Gets the handle that can be used for resource sharing. /// </summary> /// <param name="texture">The texture to be shared.</param> private IntPtr GetSharedHandle(D3D11.ID3D11Texture2D texture) { texture.EnsureNotNull(nameof(texture)); using (var resource = texture.QueryInterface <IDXGIResource>()) { return(resource.SharedHandle); } }