internal Device() { var flags = d3d.DeviceCreationFlags.VideoSupport | d3d.DeviceCreationFlags.BgraSupport; d3dDevice = new d3d.Device(SharpDX.Direct3D.DriverType.Hardware, flags); d3dDevice1 = d3dDevice.QueryInterface <d3d.Device1>(); dxgiDevice = d3dDevice.QueryInterface <dxgi.Device>(); d2dDevice = new d2.Device(dxgiDevice); ImagingFactory = new wic.ImagingFactory2(); }
internal CDevice() { var flags = d3d.DeviceCreationFlags.BgraSupport; d3dDevice = new d3d.Device(DriverType.Hardware, flags); Device = d3dDevice.QueryInterface <d3d.Device1>(); dxgiDevice = d3dDevice.QueryInterface <dxgi.Device>(); dxgiDevice1 = dxgiDevice.QueryInterface <dxgi.Device1>(); dxgiAdapter = dxgiDevice.Adapter.QueryInterface <dxgi.Adapter>(); dxgiFactory = dxgiAdapter.GetParent <dxgi.Factory>(); CreateResources(); }
/// <summary> /// Creates a <see cref="d3d.Texture2D"/> from a WIC <see cref="BitmapSource"/> /// </summary> /// <param name="device">The Direct3D11 device</param> /// <param name="bitmapSource">The WIC bitmap source</param> /// <returns>A Texture2D</returns> public static d3d.Texture2D CreateTexture2DFromBitmap(d3d.Device device, wic.BitmapSource bitmapSource, Color[] filterColors = null) { // Allocate DataStream to receive the WIC image pixels int stride = bitmapSource.Size.Width * 4; using (var buffer = new SharpDX.DataStream(bitmapSource.Size.Height * stride, true, true)) { // Copy the content of the WIC to the buffer bitmapSource.CopyPixels(stride, buffer); if (filterColors.Length > 0) { Xe.Tools.Utilities.BitmapUtility.MakeTransparent_Bgra32(buffer.DataPointer, stride, bitmapSource.Size.Height, filterColors .Select(x => new Xe.Graphics.Color() { a = x.A, r = x.R, g = x.G, b = x.B }) .ToArray() ); } return(new d3d.Texture2D(device, new d3d.Texture2DDescription() { Width = bitmapSource.Size.Width, Height = bitmapSource.Size.Height, ArraySize = 1, BindFlags = d3d.BindFlags.ShaderResource, Usage = d3d.ResourceUsage.Immutable, CpuAccessFlags = d3d.CpuAccessFlags.None, Format = dxgi.Format.R8G8B8A8_UNorm, MipLevels = 1, OptionFlags = d3d.ResourceOptionFlags.None, SampleDescription = new dxgi.SampleDescription(1, 0), }, new SharpDX.DataRectangle(buffer.DataPointer, stride))); } }