/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture2D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> /// <param name = "data">An array of initial texture data for each subresource.</param> public Texture2D(Device device, Texture2DDescription description, DataRectangle[] data) : base(IntPtr.Zero) { DataBox[] subResourceDatas = null; if (data != null) { subResourceDatas = new DataBox[data.Length]; for (int i = 0; i < subResourceDatas.Length; i++) { subResourceDatas[i].DataPointer = data[i].DataPointer; subResourceDatas[i].RowPitch = data[i].Pitch; } } device.CreateTexture2D(ref description, subResourceDatas, this); }
private void CreateDevice() { SharpDX.Direct3D.FeatureLevel[] levels = new SharpDX.Direct3D.FeatureLevel[] { SharpDX.Direct3D.FeatureLevel.Level_11_0, SharpDX.Direct3D.FeatureLevel.Level_10_1, SharpDX.Direct3D.FeatureLevel.Level_10_0, SharpDX.Direct3D.FeatureLevel.Level_9_3, SharpDX.Direct3D.FeatureLevel.Level_9_2, SharpDX.Direct3D.FeatureLevel.Level_9_1 }; foreach (var level in levels) { try { this.device = new D3D11.Device(SharpDX.Direct3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport, level); break; } catch { continue; } } if (this.device == null) { throw new PlatformNotSupportedException("DirectXデバイスの作成に失敗しました"); } device_dxgi = this.device.QueryInterface <DXGI.Device>(); factory_dxgi = device_dxgi.Adapter.GetParent <DXGI.Factory2>(); }
public MainWindow() { _dxgiDevice = AvaloniaLocator.Current.GetService <SharpDX.DXGI.Device>(); _d3dDevice = _dxgiDevice.QueryInterface <SharpDX.Direct3D11.Device>(); _d2dDevice = AvaloniaLocator.Current.GetService <SharpDX.Direct2D1.Device>(); DataContext = _model = new MainWindowViewModel(); _desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription((int)ClientSize.Width, (int)ClientSize.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = PlatformImpl?.Handle.Handle ?? IntPtr.Zero, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; _swapChain = new SwapChain(new Factory1(), _d3dDevice, _desc); _d2dContext = new SharpDX.Direct2D1.DeviceContext(_d2dDevice, DeviceContextOptions.None) { DotsPerInch = new Size2F(96, 96) }; CreateMesh(); _view = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY); this.GetObservable(ClientSizeProperty).Subscribe(Resize); Resize(ClientSize); AvaloniaXamlLoader.Load(this); Background = Avalonia.Media.Brushes.Transparent; }
public DeviceManager() { try { // 创建 Dierect3D 设备。 this.d3DDevice = new D3D11Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport); this.dxgiDevice = d3DDevice.QueryInterface <D3D11Device1>().QueryInterface <DXGIDevice>(); // 创建 Direct2D 设备和工厂。 this.d2DDevice = new D2D1Device(dxgiDevice); this.d2DContext = new DeviceContext(d2DDevice, DeviceContextOptions.None); this.d2DFactory = this.d2DContext.Factory; this.wicFactory = new ImagingFactory2(); } catch { this.ClearResources(); try { // 创建 D3D 设备异常,则尝试 Direct2D 单线程工厂。 this.d2DFactory = new Factory(FactoryType.SingleThreaded); this.wicFactory = new ImagingFactory(); } catch { this.ClearResources(); } } if (this.d2DFactory != null) { Dpi = d2DFactory.DesktopDpi; BitmapProps1 = new BitmapProperties1(D2PixelFormat, Dpi.Width, Dpi.Height, BitmapOptions.Target); } }
public WindowedDirect2dRenderEnvironment(string formName, bool debug) { form = new RenderForm(formName); d3dDevice = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport | (debug ? DeviceCreationFlags.Debug : DeviceCreationFlags.None)); dxgiDevice = d3dDevice.QueryInterface <SharpDX.DXGI.Device>(); dxgiFactory = new SharpDX.DXGI.Factory1(); swapChain = new SwapChain(dxgiFactory, dxgiDevice, new SwapChainDescription { BufferCount = 1, ModeDescription = new ModeDescription(Format.B8G8R8A8_UNorm), OutputHandle = form.Handle, IsWindowed = true, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }); dxgiSurface = swapChain.GetBackBuffer <Surface>(0); d2dFactory = new SharpDX.Direct2D1.Factory1(FactoryType.SingleThreaded, debug ? DebugLevel.Warning : DebugLevel.None); d2dDevice = new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice); d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, DeviceContextOptions.None); bitmap = new Bitmap1(d2dContext, dxgiSurface, null); d2dContext.Target = bitmap; }
/// <summary> /// Disposes of object resources. /// </summary> /// <param name="disposeManagedResources">If true, managed resources should be /// disposed of in addition to unmanaged resources.</param> protected virtual void Dispose(bool disposeManagedResources) { if (disposeManagedResources) { _d3d11Device.Dispose(); _dxgiDevice.Dispose(); _backBuffer.Dispose(); _targetBitmap.Dispose(); _backBuffer2.Dispose(); _targetBitmap2.Dispose(); _d2dDevice.Dispose(); swapChain.Dispose(); swapChain2.Dispose(); d2dContext.Dispose(); d2dContext2.Dispose(); dw_Factory.Dispose(); } _d3d11Device = null; _dxgiDevice = null; _backBuffer = null; _targetBitmap = null; _backBuffer2 = null; _targetBitmap2 = null; _d2dDevice = null; swapChain = null; swapChain2 = null; d2dContext = null; d2dContext2 = null; dw_Factory = null; }
public void Shutdown() { if (_deviceContext != null) { _deviceContext.Dispose(); _deviceContext = null; } if (_device2D != null) { _device2D.Dispose(); _device2D = null; } if (_dxgiDevice != null) { _dxgiDevice.Dispose(); _dxgiDevice = null; } if (_default3DDevice1 != null) { _default3DDevice1.Dispose(); _default3DDevice1 = null; } if (_default3DDevice != null) { _default3DDevice.Dispose(); _default3DDevice = null; } }
internal void ReleaseDevices() { IsRendererSuppressed = true; RenderTarget.Dispose(); Backbuffer.Dispose(); RenderTargetSurface.Dispose(); RenderTargetView.Dispose(); D2DDeviceContext.Dispose(); D2DDevice.Dispose(); D2DFactory.Dispose(); DXGIDevice.Dispose(); D3DDevice.Dispose(); D3DDefaultDevice.Dispose(); SwapChain.Dispose(); SwapChain = null; RenderTarget = null; RenderTargetSurface = null; Backbuffer = null; RenderTargetView = null; D2DDeviceContext = null; D2DFactory = null; D2DDevice = null; DXGIDevice = null; D3DDevice = null; D3DDefaultDevice = null; }
public DXD2D1() { _d3d11Device = new D3D11.Device(D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport, featureLevels); _dxgiDevice = _d3d11Device.QueryInterface <D3D11.Device>().QueryInterface <DXGI.Device>(); _d2dDevice = new D2D1.Device(_dxgiDevice); }
public CpuStreamPlayer(SharpDX.DXGI.Device device, int fps) : base(device, fps) { using (var d3d11device = device.QueryInterface <SharpDX.Direct3D11.Device>()) { context = new DeviceContext(d3d11device); } }
public void BeginFrame() { Debug.Assert(curView == null); using (var backBuffer = chain.GetBackBuffer <Texture2D>(0)) { curView = new RenderTargetView(Device.Get().Handle, backBuffer); } }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture1D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> /// <param name = "data">An array of initial texture data for each subresource.</param> public Texture1D(Device device, Texture1DDescription description, DataStream[] data) : base(IntPtr.Zero) { var subResourceDatas = new DataBox[data.Length]; for (int i = 0; i < subResourceDatas.Length; i++) subResourceDatas[i].DataPointer = data[i].DataPointer; device.CreateTexture1D(ref description, subResourceDatas, this); }
private void StartD3D() { _device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0); _d3DSurface = new DX10ImageSource(); _d3DSurface.IsFrontBufferAvailableChanged += OnIsFrontBufferAvailableChanged; CreateAndBindTargets(); Source = _d3DSurface; }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture1D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> /// <param name = "data">An array of initial texture data for each subresource.</param> public Texture1D(Device device, Texture1DDescription description, DataStream[] data) : base(IntPtr.Zero) { System.Diagnostics.Debug.Assert(data != null); var subResourceDatas = new DataBox[data.Length]; for (int i = 0; i < subResourceDatas.Length; i++) subResourceDatas[i].DataPointer = data[i].DataPointer; device.CreateTexture1D(ref description, subResourceDatas, this); }
/// <summary> /// 清理所有正在使用的资源,并设置为 <c>null</c>。 /// </summary> private void ClearResources() { if (this.d3DDevice != null) { this.d3DDevice.Dispose(); this.d3DDevice = null; } if (this.dxgiDevice != null) { this.dxgiDevice.Dispose(); this.dxgiDevice = null; } if (this.swapChain != null) { this.swapChain.Dispose(); this.swapChain = null; } if (this.backBuffer != null) { this.backBuffer.Dispose(); this.backBuffer = null; } if (this.targetBitmap != null) { this.targetBitmap.Dispose(); this.swapChain = null; } if (this.d2DDevice != null) { this.d2DDevice.Dispose(); this.d2DDevice = null; } if (this.d2DContext != null) { this.d2DContext.Dispose(); this.d2DContext = null; } if (this.d2DFactory != null) { this.d2DFactory.Dispose(); this.d2DFactory = null; } if (this.renderTarget != null) { this.renderTarget.Dispose(); this.renderTarget = null; } if (this.wicFactory != null) { this.wicFactory.Dispose(); this.wicFactory = null; } }
/// <summary> /// Initializes a new instance of the <see cref="DeviceHandlerD3D11" /> class. /// </summary> /// <param name="core">The core.</param> /// <param name="engineDevice">The engine device.</param> internal DeviceHandlerD2D(GraphicsCore core, EngineDevice engineDevice) { try { bool doFallbackMethod = core.Force2DFallbackMethod || (core.FactoryD2D_2 == null); // Simulate exception if requested if (GraphicsCore.ThrowD2DInitDeviceError) { throw new SeeingSharpGraphicsException("Simulation Direct2D device init exception"); } // Do default method (Windows 8 and newer) if (!doFallbackMethod) { try { using (DXGI.Device dxgiDevice = engineDevice.DeviceD3D11_1.QueryInterface <DXGI.Device>()) { m_deviceD2D = new D2D.Device1(engineDevice.Core.FactoryD2D_2, dxgiDevice); m_deviceContextD2D = new SharpDX.Direct2D1.DeviceContext( m_deviceD2D, D2D.DeviceContextOptions.None); m_renderTarget = m_deviceContextD2D; } } catch (Exception) { doFallbackMethod = true; } } // Fallback method (on older windows platforms (< Windows 8)) if (doFallbackMethod) { m_renderTarget = null; m_deviceD2D = null; m_deviceContextD2D = null; m_dummyRenderTargetTexture = GraphicsHelper.CreateRenderTargetTextureDummy( engineDevice.DeviceD3D11_1, 32, 32); m_dummyDirect2DOverlay = new Direct2DOverlayRenderer( engineDevice, m_dummyRenderTargetTexture, 32, 32, DpiScaling.Default, forceInit: true); } } catch (Exception) { GraphicsHelper.SafeDispose(ref m_deviceContextD2D); GraphicsHelper.SafeDispose(ref m_deviceD2D); GraphicsHelper.SafeDispose(ref m_dummyDirect2DOverlay); GraphicsHelper.SafeDispose(ref m_dummyRenderTargetTexture); GraphicsHelper.SafeDispose(ref m_renderTarget); } }
public Direct2DText() { defaultDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, d3d.DeviceCreationFlags.VideoSupport | d3d.DeviceCreationFlags.BgraSupport | d3d.DeviceCreationFlags.None); // take out the Debug flag for better performance d3dDevice = defaultDevice.QueryInterface <d3d.Device1>(); // get a reference to the Direct3D 11.1 device dxgiDevice = d3dDevice.QueryInterface <dxgi.Device>(); // get a reference to DXGI device d2dDevice = new d2.Device(dxgiDevice); // initialize the D2D device imagingFactory = new wic.ImagingFactory2(); // initialize the WIC factory d2dContext = new d2.DeviceContext(d2dDevice, d2.DeviceContextOptions.None); dwFactory = new dw.Factory(); d2dBitmapProps = new BitmapProperties1(d2PixelFormat, dpi, dpi, BitmapOptions.Target | BitmapOptions.CannotDraw); }
private void InitializeDevices() { try { SwapChainDescription = new DXGI.SwapChainDescription(); SwapChainDescription.BufferCount = 2; SwapChainDescription.SampleDescription = new DXGI.SampleDescription(1, 0); SwapChainDescription.SwapEffect = DXGI.SwapEffect.Discard; SwapChainDescription.Usage = DXGI.Usage.BackBuffer | DXGI.Usage.RenderTargetOutput; SwapChainDescription.IsWindowed = true; SwapChainDescription.ModeDescription = new DXGI.ModeDescription(GameWindow.Current.WindowParameters.Width, GameWindow.Current.WindowParameters.Height, new DXGI.Rational(60, 1), DXGI.Format.B8G8R8A8_UNorm); SwapChainDescription.OutputHandle = GameWindowHandle; D3D11.Device.CreateWithSwapChain(DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport, featureLevels, SwapChainDescription, out D3DDefaultDevice, out SwapChain); DXGI.Factory factory = SwapChain.GetParent <DXGI.Factory>(); factory.MakeWindowAssociation(GameWindowHandle, DXGI.WindowAssociationFlags.IgnoreAll); D3DDevice = D3DDefaultDevice.QueryInterface <D3D11.Device1>(); Backbuffer = D3D11.Texture2D.FromSwapChain <D3D11.Texture2D>(SwapChain, 0); RenderTargetView = new D3D11.RenderTargetView(D3DDevice, Backbuffer); D3DDevice.ImmediateContext.Rasterizer.SetViewport(0, 0, GameWindow.Current.WindowParameters.Width, GameWindow.Current.WindowParameters.Height); D3DDevice.ImmediateContext.OutputMerger.SetTargets(RenderTargetView); DXGIDevice = D3DDevice.QueryInterface <DXGI.Device>(); D2DFactory = new D2D1.Factory1(D2D1.FactoryType.MultiThreaded); D2DDevice = new D2D1.Device(D2DFactory, DXGIDevice); D2DDeviceContext = new D2D1.DeviceContext(D2DDevice, D2D1.DeviceContextOptions.None); RenderTargetSurface = Backbuffer.QueryInterface <DXGI.Surface>(); RenderTarget = new D2D1.RenderTarget(D2DFactory, RenderTargetSurface, new D2D1.RenderTargetProperties(new D2D1.PixelFormat(DXGI.Format.Unknown, D2D1.AlphaMode.Premultiplied))); RenderTarget.AntialiasMode = D2D1.AntialiasMode.PerPrimitive; // Initialize debug drawings brushes DrawingBoundsBrush = new D2D1.SolidColorBrush(RenderTarget, new SharpDX.Color(1f, 1f, 0f)); CollisionBoxesBrush = new D2D1.SolidColorBrush(RenderTarget, new SharpDX.Color(1f, 0f, 0f)); RenderFrame = new RenderFrame(RenderTarget); Clock = Stopwatch.StartNew(); } catch (Exception ex) { throw new DeviceInitializationException("Unable to initialize DirectX device!", ex); } }
public StreamPlayer(Device device, int fps) { Device = device.QueryInterface <SharpDX.Direct3D11.Device>(); using (var manager = new DXGIDeviceManager()) using (var factory = new MediaEngineClassFactory()) using (var attributes = new MediaEngineAttributes(2)) { manager.ResetDevice(device); attributes.DxgiManager = manager; attributes.VideoOutputFormat = (int)Format.B8G8R8A8_UNorm; var baseEngine = new MediaEngine(factory, attributes, playbackCallback: OnEngineEvent); engine = baseEngine.QueryInterface <MediaEngineEx>(); } frameTime = TimeSpan.FromSeconds(1.0 / fps); SetCurrentState(StreamPlayerState.NoSource); }
public DXBitmapExportContext(int width, int height, float displayScale = 1, int dpi = 72, bool disposeBitmap = true) : base(width, height, dpi) { _disposeBitmap = disposeBitmap; if (_default3DDevice == null) { _default3DDevice = new d3d.Device(DriverType.Hardware, d3d.DeviceCreationFlags.VideoSupport | d3d.DeviceCreationFlags.BgraSupport); // default3DDevice = new d3d.Device(DriverType.Warp, d3d.DeviceCreationFlags.BgraSupport); _default3DDevice1 = _default3DDevice.QueryInterface <d3d.Device1>(); _dxgiDevice = _default3DDevice1.QueryInterface <dxgi.Device>(); // get a reference to DXGI device _device2D = new d2.Device(_dxgiDevice); // initialize the DeviceContext - it will be the D2D render target _deviceContext = new d2.DeviceContext(_device2D, d2.DeviceContextOptions.None); } // specify a pixel format that is supported by both and WIC _pixelFormat = new d2.PixelFormat(dxgi.Format.B8G8R8A8_UNorm, d2.AlphaMode.Premultiplied); // create the d2d bitmap description using default flags var bitmapProps = new d2.BitmapProperties1(_pixelFormat, Dpi, Dpi, d2.BitmapOptions.Target | d2.BitmapOptions.CannotDraw); // create our d2d bitmap where all drawing will happen _bitmap = new d2.Bitmap1(_deviceContext, new Size2(width, height), bitmapProps); // associate bitmap with the d2d context _deviceContext.Target = _bitmap; _deviceContext.BeginDraw(); _deviceContext.Clear(new Color4 { Alpha = 0, Blue = 0, Green = 0, Red = 0 }); _canvas = new DXCanvas(_deviceContext) { DisplayScale = displayScale }; }
public SwapChain(IntPtr hwnd, int width, int height) { Width = width; Height = height; var desc = new SwapChainDescription { BufferCount = bufferCount, Flags = flags, IsWindowed = true, ModeDescription = new ModeDescription(width, height, new Rational(0, 1), Format.R8G8B8A8_UNorm), OutputHandle = hwnd, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.FlipSequential, Usage = Usage.RenderTargetOutput }; var device = Device.Get(); chain = new SharpDX.DXGI.SwapChain(device.FactoryHandle, device.Handle, desc); }
private void CreateDeviceIndependentResources() { _dxgiDevice = _d3dDevice.QueryInterface <SharpDX.DXGI.Device>(); _d2dDevice = new SharpDX.Direct2D1.Device(_dxgiDevice); _d2dFactory = _d2dDevice.Factory; var dpiX = _d2dFactory.DesktopDpi.Width; var dpiY = _d2dFactory.DesktopDpi.Height; _dc = new SharpDX.Direct2D1.DeviceContext(_d2dDevice, DeviceContextOptions.None); _dc.PrimitiveBlend = PrimitiveBlend.SourceOver; var format = new SharpDX.Direct2D1.PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied); var properties = new BitmapProperties1(format, dpiX, dpiY, BitmapOptions.Target | BitmapOptions.CannotDraw); _surface = _swapChain.GetBackBuffer <Surface>(0); _renderTarget = new Bitmap1(_dc, _surface, properties); _dc.Target = _renderTarget; _dc.AntialiasMode = AntialiasMode.PerPrimitive; OnCreateDeviceIndependentResources(); this._deviceIndependedResourcesCreated = true; }
/// <summary> /// Creates Direct3D11 Device, RenderTargetView, DepthStencilView, Viewport /// </summary> /// <param name="deviceDescription">The device description.</param> /// <exception cref="System.Exception"></exception> /// <exception cref="System.ComponentModel.InvalidEnumArgumentException">deviceDescription.MultiSampleCount</exception> private void Initialize(DeviceDescription deviceDescription) { FeatureLevel[] levels = new FeatureLevel[] { FeatureLevel.Level_10_0, FeatureLevel.Level_10_1, FeatureLevel.Level_11_0, FeatureLevel.Level_11_1, }; d3dDevice = new D3D11.Device(DriverType.Hardware, D3D11.DeviceCreationFlags.Debug, levels); DXGI.ModeDescription backBufferDesc = new DXGI.ModeDescription() { Width = width, Height = height, Format = BackBufferFormat, RefreshRate = new DXGI.Rational(60, 1), Scaling = DXGI.DisplayModeScaling.Unspecified, ScanlineOrdering = DXGI.DisplayModeScanlineOrder.Progressive, }; DXGI.SwapChainDescription swapChainDesc = new DXGI.SwapChainDescription() { BufferCount = 1, Flags = DXGI.SwapChainFlags.None, IsWindowed = !deviceDescription.Fullcreen, ModeDescription = backBufferDesc, OutputHandle = renderControl.Handle, SwapEffect = deviceDescription.SwapEffect, Usage = DXGI.Usage.RenderTargetOutput, }; switch (deviceDescription.MultiSampleCount) { case MultiSampleType.MSAA1: swapChainDesc.SampleDescription = new DXGI.SampleDescription(1, deviceDescription.MultiSampleQuality); break; case MultiSampleType.MSAA2: swapChainDesc.SampleDescription = new DXGI.SampleDescription(2, deviceDescription.MultiSampleQuality); break; case MultiSampleType.MSAA4: swapChainDesc.SampleDescription = new DXGI.SampleDescription(4, deviceDescription.MultiSampleQuality); break; case MultiSampleType.MSAA8: swapChainDesc.SampleDescription = new DXGI.SampleDescription(8, deviceDescription.MultiSampleQuality); break; case MultiSampleType.MSAA16: swapChainDesc.SampleDescription = new DXGI.SampleDescription(16, deviceDescription.MultiSampleQuality); break; case MultiSampleType.Unknown: var samples = SharpDXDevice.CheckMultiSample(); if (samples == null) { throw new Exception(MethodBase.GetCurrentMethod().Name + " Because the MultiSampleCount parameter is [Unknown], the device could not determine the parameter automatically"); } swapChainDesc.SampleDescription = samples.Last(); break; default: throw new System.ComponentModel.InvalidEnumArgumentException("deviceDescription.MultiSampleCount", (int)deviceDescription.MultiSampleCount, typeof(MultiSampleType)); } DXGI.Device device = d3dDevice.QueryInterface <DXGI.Device>(); DXGI.Adapter adapter = device.GetParent <DXGI.Adapter>(); DXGI.Factory factory = adapter.GetParent <DXGI.Factory>(); swapChain = new DXGI.SwapChain(factory, d3dDevice, swapChainDesc); d3dContext = d3dDevice.ImmediateContext; D3D11.RasterizerStateDescription rasterDesc = new D3D11.RasterizerStateDescription() { CullMode = D3D11.CullMode.Back, FillMode = D3D11.FillMode.Solid, IsAntialiasedLineEnabled = true, IsMultisampleEnabled = true, IsDepthClipEnabled = true, }; viewport = new Viewport(0, 0, width, height); this.SetRasterizerState(rasterDesc); d3dRenderTarget = CreateRenderTarget(); d3dDepthStencil = CreateDepthStencil(); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture2D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> /// <param name = "data">The initial texture data.</param> public Texture2D(Device device, Texture2DDescription description, DataRectangle data) : this(device, description, new[] {data}) { }
public DeviceManager() { try { // 创建 Dierect3D 设备。 this.d3DDevice = new D3D11Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport); this.dxgiDevice = d3DDevice.QueryInterface<D3D11Device1>().QueryInterface<DXGIDevice>(); // 创建 Direct2D 设备和工厂。 this.d2DDevice = new D2D1Device(dxgiDevice); this.d2DContext = new DeviceContext(d2DDevice, DeviceContextOptions.None); this.d2DFactory = this.d2DContext.Factory; this.wicFactory = new ImagingFactory2(); } catch { this.ClearResources(); try { // 创建 D3D 设备异常,则尝试 Direct2D 单线程工厂。 this.d2DFactory = new Factory(FactoryType.SingleThreaded); this.wicFactory = new ImagingFactory(); } catch { this.ClearResources(); } } if (this.d2DFactory != null) { Dpi = d2DFactory.DesktopDpi; BitmapProps1 = new BitmapProperties1(D2PixelFormat, Dpi.Width, Dpi.Height, BitmapOptions.Target); } }
/// <summary> /// Must be called when the render size has changed. Adjusts the render size, but does not trigger a new rendering. Call <see cref="Render"/> afterwards. /// If you provide zero for both <paramref name="sizeX"/> and <paramref name="sizeY"/>, you can free resources in case the rendering is not used currently. /// </summary> /// <param name="sizeX">The render size x component in pixels.</param> /// <param name="sizeY">The render size y component in pixels.</param> public void SetRenderSize(int sizeX, int sizeY) { if (_isDisposed) throw new ObjectDisposedException("this"); if (null == _device) { this._device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0); } Scene?.SetHostSize(new PointD2D(sizeX, sizeY)); CreateAndBindTargets(sizeX, sizeY); }
public void Export(int sizeX, int sizeY, ID3D10Scene scene, Altaxo.Graph.Gdi.GraphExportOptions options, System.IO.Stream toStream) { var device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug, FeatureLevel.Level_10_0); // try to get the highest MSAA level with the highest quality int sampleCount = 32; int qlevel_sampleCount = 0; for (; sampleCount >= 0; sampleCount /= 2) { if (0 != (qlevel_sampleCount = device.CheckMultisampleQualityLevels(Format.B8G8R8A8_UNorm, sampleCount))) // quality level for sample count break; } Texture2DDescription colordesc = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm_SRgb, Width = sizeX, Height = sizeY, MipLevels = 1, SampleDescription = new SampleDescription(sampleCount, qlevel_sampleCount - 1), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; Texture2DDescription depthdesc = new Texture2DDescription { BindFlags = BindFlags.DepthStencil, Format = Format.D32_Float_S8X24_UInt, Width = sizeX, Height = sizeY, MipLevels = 1, SampleDescription = new SampleDescription(sampleCount, qlevel_sampleCount - 1), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1, }; var renderTarget = new Texture2D(device, colordesc); var depthStencil = new Texture2D(device, depthdesc); var renderTargetView = new RenderTargetView(device, renderTarget); var depthStencilView = new DepthStencilView(device, depthStencil); // Rendering device.OutputMerger.SetTargets(depthStencilView, renderTargetView); device.Rasterizer.SetViewports(new Viewport(0, 0, sizeX, sizeY, 0.0f, 1.0f)); Color4 clearColor = new Color4(1, 1, 1, 0); // Transparent if (options.BackgroundBrush != null) { var axoColor = options.BackgroundBrush.Color.Color; clearColor = new Color4(axoColor.ScR, axoColor.ScG, axoColor.ScB, axoColor.ScA); } device.ClearRenderTargetView(renderTargetView, clearColor); device.ClearDepthStencilView(depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); scene.Attach(device, new PointD2D(sizeX, sizeY)); scene.Render(); device.Flush(); Texture2D renderTarget2 = null; if (sampleCount > 1) // if renderTarget is an MSAA render target, we first have to copy it into a non-MSAA render target before we can copy it to a CPU texture and then hope to save it { // create a non-MSAA render target with the same size Texture2DDescription renderTarget2Description = new Texture2DDescription { BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource, Format = Format.B8G8R8A8_UNorm_SRgb, Width = sizeX, Height = sizeY, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), // non MSAA Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.Shared, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; renderTarget2 = new Texture2D(device, renderTarget2Description); // create non-MSAA render target device.ResolveSubresource(renderTarget, 0, renderTarget2, 0, renderTarget.Description.Format); // copy from MSAA render target to the non-MSAA render target var h = renderTarget; // exchange renderTarget with renderTarget2 renderTarget = renderTarget2; renderTarget2 = h; } // renderTarget is now a non-MSAA renderTarget Texture2DExtensions.SaveToStream(renderTarget, options.ImageFormat, options.DestinationDpiResolution, toStream); scene.Detach(); Disposer.RemoveAndDispose(ref depthStencilView); Disposer.RemoveAndDispose(ref renderTargetView); Disposer.RemoveAndDispose(ref renderTarget2); Disposer.RemoveAndDispose(ref renderTarget); Disposer.RemoveAndDispose(ref depthStencil); Disposer.RemoveAndDispose(ref device); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture3D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> /// <param name = "data">An array of initial texture data for each subresource.</param> public Texture3D(Device device, Texture3DDescription description, DataBox[] data) : base(IntPtr.Zero) { device.CreateTexture3D(ref description, data, this); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture3D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> /// <param name = "data">The initial texture data.</param> public Texture3D(Device device, Texture3DDescription description, DataBox data) : this(device, description, new[] {data}) { }
public Renderer(Game game, SharpDX.Windows.RenderForm renderForm) { this.game = game; int width = renderForm.ClientSize.Width, height = renderForm.ClientSize.Height; ResolutionX = width; ResolutionY = height; #region 3d device & context D3D11.DeviceCreationFlags creationFlags = D3D11.DeviceCreationFlags.BgraSupport; #if DEBUG creationFlags |= D3D11.DeviceCreationFlags.Debug; #endif DXGI.SwapChainDescription swapChainDesc = new DXGI.SwapChainDescription() { ModeDescription = new DXGI.ModeDescription(width, height, new DXGI.Rational(60, 1), DXGI.Format.R8G8B8A8_UNorm), SampleDescription = new DXGI.SampleDescription(SampleCount, SampleQuality), Usage = DXGI.Usage.RenderTargetOutput, BufferCount = 1, OutputHandle = renderForm.Handle, IsWindowed = true, SwapEffect = DXGI.SwapEffect.Discard }; D3D11.Device device; D3D11.Device.CreateWithSwapChain(DriverType.Hardware, creationFlags, swapChainDesc, out device, out swapChain); Device = device; Context = Device.ImmediateContext; #endregion #region 2d device & context DXGI.Device dxgiDevice = Device.QueryInterface <D3D11.Device1>().QueryInterface <DXGI.Device2>(); D2DDevice = new D2D1.Device(dxgiDevice); D2DContext = new D2D1.DeviceContext(D2DDevice, D2D1.DeviceContextOptions.None); D2DFactory = D2DDevice.Factory; #endregion #region 2d brushes/fonts Brushes = new Dictionary <string, D2D1.Brush>(); Brushes.Add("Red", new D2D1.SolidColorBrush(D2DContext, Color.Red)); Brushes.Add("Green", new D2D1.SolidColorBrush(D2DContext, Color.Green)); Brushes.Add("Blue", new D2D1.SolidColorBrush(D2DContext, Color.Blue)); Brushes.Add("White", new D2D1.SolidColorBrush(D2DContext, Color.White)); Brushes.Add("Black", new D2D1.SolidColorBrush(D2DContext, Color.Black)); Brushes.Add("TransparentWhite", new D2D1.SolidColorBrush(D2DContext, new Color(1, 1, 1, .5f))); Brushes.Add("TransparentBlack", new D2D1.SolidColorBrush(D2DContext, new Color(0, 0, 0, .5f))); Brushes.Add("LightGray", new D2D1.SolidColorBrush(D2DContext, Color.LightGray)); Brushes.Add("OrangeRed", new D2D1.SolidColorBrush(D2DContext, Color.OrangeRed)); Brushes.Add("CornflowerBlue", new D2D1.SolidColorBrush(D2DContext, Color.CornflowerBlue)); Brushes.Add("Yellow", new D2D1.SolidColorBrush(D2DContext, Color.Yellow)); Brushes.Add("Magenta", new D2D1.SolidColorBrush(D2DContext, Color.Magenta)); Brushes.Add("RosyBrown", new D2D1.SolidColorBrush(D2DContext, Color.RosyBrown)); DashStyle = new D2D1.StrokeStyle(D2DFactory, new D2D1.StrokeStyleProperties() { StartCap = D2D1.CapStyle.Flat, DashCap = D2D1.CapStyle.Round, EndCap = D2D1.CapStyle.Flat, DashStyle = D2D1.DashStyle.Custom, DashOffset = 0, LineJoin = D2D1.LineJoin.Round, MiterLimit = 1 }, new float[] { 4f, 4f }); FontFactory = new DWrite.Factory(); SegoeUI24 = new DWrite.TextFormat(FontFactory, "Segoe UI", 24f); SegoeUI14 = new DWrite.TextFormat(FontFactory, "Segoe UI", 14f); Consolas14 = new DWrite.TextFormat(FontFactory, "Consolas", 14f); #endregion #region blend states D3D11.BlendStateDescription opaqueDesc = new D3D11.BlendStateDescription(); opaqueDesc.RenderTarget[0].IsBlendEnabled = false; opaqueDesc.RenderTarget[0].RenderTargetWriteMask = D3D11.ColorWriteMaskFlags.All; blendStateOpaque = new D3D11.BlendState(Device, opaqueDesc); D3D11.BlendStateDescription alphaDesc = new D3D11.BlendStateDescription(); alphaDesc.RenderTarget[0].IsBlendEnabled = true; alphaDesc.RenderTarget[0].SourceBlend = D3D11.BlendOption.SourceAlpha; alphaDesc.RenderTarget[0].DestinationBlend = D3D11.BlendOption.InverseSourceAlpha; alphaDesc.RenderTarget[0].BlendOperation = D3D11.BlendOperation.Add; alphaDesc.RenderTarget[0].SourceAlphaBlend = D3D11.BlendOption.One; alphaDesc.RenderTarget[0].DestinationAlphaBlend = D3D11.BlendOption.Zero; alphaDesc.RenderTarget[0].AlphaBlendOperation = D3D11.BlendOperation.Add; alphaDesc.RenderTarget[0].RenderTargetWriteMask = D3D11.ColorWriteMaskFlags.All; blendStateTransparent = new D3D11.BlendState(Device, alphaDesc); #endregion #region rasterizer states rasterizerStateSolidCullBack = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription() { FillMode = D3D11.FillMode.Solid, CullMode = D3D11.CullMode.Back, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = false, IsMultisampleEnabled = true }); rasterizerStateWireframeCullBack = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription() { FillMode = D3D11.FillMode.Wireframe, CullMode = D3D11.CullMode.Back, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = false, IsMultisampleEnabled = true }); rasterizerStateSolidNoCull = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription() { FillMode = D3D11.FillMode.Solid, CullMode = D3D11.CullMode.None, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = false, IsMultisampleEnabled = true }); rasterizerStateWireframeNoCull = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription() { FillMode = D3D11.FillMode.Wireframe, CullMode = D3D11.CullMode.None, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = false, IsMultisampleEnabled = true }); rasterizerStateSolidCullFront = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription() { FillMode = D3D11.FillMode.Solid, CullMode = D3D11.CullMode.Front, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = false, IsMultisampleEnabled = true }); rasterizerStateWireframeCullFront = new D3D11.RasterizerState(Device, new D3D11.RasterizerStateDescription() { FillMode = D3D11.FillMode.Wireframe, CullMode = D3D11.CullMode.Front, IsAntialiasedLineEnabled = true, IsDepthClipEnabled = false, IsMultisampleEnabled = true }); #endregion #region depth stencil states depthStencilStateDefault = new D3D11.DepthStencilState(Device, new D3D11.DepthStencilStateDescription() { IsDepthEnabled = true, IsStencilEnabled = false, DepthComparison = D3D11.Comparison.Less, DepthWriteMask = D3D11.DepthWriteMask.All }); depthStencilStateNoDepth = new D3D11.DepthStencilState(Device, new D3D11.DepthStencilStateDescription() { IsDepthEnabled = false, IsStencilEnabled = false, DepthComparison = D3D11.Comparison.Less, DepthWriteMask = D3D11.DepthWriteMask.All }); Context.OutputMerger.SetDepthStencilState(depthStencilStateDefault); #endregion #region blank textures D3D11.Texture2D wtex = new D3D11.Texture2D(Device, new D3D11.Texture2DDescription() { ArraySize = 1, Width = 1, Height = 1, Format = DXGI.Format.R32G32B32A32_Float, CpuAccessFlags = D3D11.CpuAccessFlags.None, MipLevels = 0, Usage = D3D11.ResourceUsage.Default, SampleDescription = new DXGI.SampleDescription(1, 0), BindFlags = D3D11.BindFlags.ShaderResource, OptionFlags = D3D11.ResourceOptionFlags.None }); Context.UpdateSubresource(new Vector4[] { Vector4.One }, wtex); WhiteTextureView = new D3D11.ShaderResourceView(Device, wtex); D3D11.Texture2D btex = new D3D11.Texture2D(Device, new D3D11.Texture2DDescription() { ArraySize = 1, Width = 1, Height = 1, Format = DXGI.Format.R32G32B32A32_Float, CpuAccessFlags = D3D11.CpuAccessFlags.None, MipLevels = 0, Usage = D3D11.ResourceUsage.Default, SampleDescription = new DXGI.SampleDescription(1, 0), BindFlags = D3D11.BindFlags.ShaderResource, OptionFlags = D3D11.ResourceOptionFlags.None }); Context.UpdateSubresource(new Vector4[] { new Vector4(0, 0, 0, 1) }, btex); BlackTextureView = new D3D11.ShaderResourceView(Device, btex); AnisotropicSampler = new D3D11.SamplerState(Device, new D3D11.SamplerStateDescription() { AddressU = D3D11.TextureAddressMode.Wrap, AddressV = D3D11.TextureAddressMode.Wrap, AddressW = D3D11.TextureAddressMode.Wrap, Filter = D3D11.Filter.Anisotropic, }); #endregion #region screen vertex & constants constants = new CameraConstants(); constantBuffer = D3D11.Buffer.Create(Device, D3D11.BindFlags.ConstantBuffer, ref constants); #endregion //swapChain.GetParent<DXGI.Factory>().MakeWindowAssociation(renderForm.Handle, DXGI.WindowAssociationFlags.); Cameras = new List <Camera>(); MainCamera = Camera.CreatePerspective(MathUtil.DegreesToRadians(70), 16 / 9f); ActiveCamera = MainCamera; Cameras.Add(MainCamera); ShadowCamera = Camera.CreateOrthographic(500, 1); ShadowCamera.zNear = 0; ShadowCamera.zFar = 1000; ShadowCamera.CreateResources(Device, 1, 0, 1024, 1024); //Cameras.Add(ShadowCamera); // TODO: Shadow camera has no depth Resize(ResolutionX, ResolutionY); }
public void Init(IntPtr hWnd, ApplicationInfo appInfo) { if (m_ApplicationInfo != null) { throw new InvalidOperationException("context already initialized"); } m_ApplicationInfo = appInfo; var swapChainDesc = new DXGI.SwapChainDescription { ModeDescription = new DXGI.ModeDescription { Width = m_ApplicationInfo.Width, Height = m_ApplicationInfo.Height, RefreshRate = new DXGI.Rational(60, 1), Format = DXGI.Format.R8G8B8A8_UNorm }, SampleDescription = new DXGI.SampleDescription { Count = 4 }, BufferCount = 1, Usage = DXGI.Usage.RenderTargetOutput, OutputHandle = hWnd, IsWindowed = !m_ApplicationInfo.FullScreen, SwapEffect = DXGI.SwapEffect.Discard, Flags = DXGI.SwapChainFlags.AllowModeSwitch }; D3D11.Device.CreateWithSwapChain(D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.BgraSupport | D3D11.DeviceCreationFlags.Debug, new[] { m_FeatureLevel }, swapChainDesc, out D3D11.Device dev, out DXGI.SwapChain swapChain); Dev = dev; DevCon = Dev.ImmediateContext; SwapChain = swapChain; D2DFactory = new D2D1.Factory(D2D1.FactoryType.SingleThreaded, D2D1.DebugLevel.Information); DWriteFactory = new DirectWrite.Factory(DirectWrite.FactoryType.Shared); m_MSAAQuality = Dev.CheckMultisampleQualityLevels(DXGI.Format.R8G8B8A8_UNorm, 4); D3D11.DeviceDebug d3dDebug = dev.QueryInterface <D3D11.DeviceDebug>(); if (d3dDebug != null) { D3D11.InfoQueue infoQueue = dev.QueryInterface <D3D11.InfoQueue>(); if (infoQueue != null) { D3D11.MessageId[] hide = { D3D11.MessageId.MessageIdDeviceDrawSamplerNotSet }; infoQueue.AddStorageFilterEntries(new D3D11.InfoQueueFilter() { DenyList = new D3D11.InfoQueueFilterDescription { Ids = hide } }); } } Resize(); CreateBlendStates(); CreateDepthStencilStates(); CreateRasterizerStates(); SetBlend(false); SetDepthTesting(true); SetWireframe(false); SharpDX.DXGI.Device dxgiDev = Dev.QueryInterface <SharpDX.DXGI.Device>(); SharpDX.DXGI.AdapterDescription adapterDesc = dxgiDev.Adapter.Description; Console.WriteLine("----------------------------------"); Console.WriteLine(" Direct3D 11:"); Console.WriteLine(" " + adapterDesc.Description); Console.WriteLine(" VRAM: " + adapterDesc.DedicatedVideoMemory / 1024 / 1024 + " MB"); Console.WriteLine("----------------------------------"); dxgiDev.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture1D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> public Texture1D(Device device, Texture1DDescription description) : base(IntPtr.Zero) { device.CreateTexture1D(ref description, null, this); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture1D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> /// <param name = "data">The initial texture data.</param> public Texture1D(Device device, Texture1DDescription description, DataStream data) : this(device, description, new[] {data}) { System.Diagnostics.Debug.Assert(data != null); }
/// <summary> /// Initializes a new instance of the <see cref = "T:SharpDX.Direct3D10.Texture1D" /> class. /// </summary> /// <param name = "device">The device with which to associate the texture.</param> /// <param name = "description">The description of the texture.</param> /// <param name = "data">The initial texture data.</param> public Texture1D(Device device, Texture1DDescription description, DataStream data) : this(device, description, new[] {data}) { }
public void Run() { #region setup resources var mainForm = new RenderForm(); var scDescription = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription( 0, 0, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = mainForm.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; //DeviceCreationFlags.Debug flag below will show debug layer messages in your output window. //Need proper version of windows sdk for it to work, otherwise it will throw an exception. //You also need to right click your project->properties->debug (on the left panel)-> check "enable native code debugging" // Create Device and SwapChain _d3d11.Device.CreateWithSwapChain( DriverType.Hardware, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug, new[] { _d3d.FeatureLevel.Level_12_1 }, scDescription, out d3d11Device, out swapChain); // Ignore all windows events dxgiFactory = swapChain.GetParent <_dxgi.Factory1>(); dxgiFactory.MakeWindowAssociation(mainForm.Handle, WindowAssociationFlags.IgnoreAll); d2dFactory = new _d2d.Factory(); d2dFactory4 = d2dFactory.QueryInterface <_d2d.Factory4>(); dxgiDevice = d3d11Device.QueryInterface <_dxgi.Device>(); d2dDevice3 = new _d2d.Device3(d2dFactory4, dxgiDevice); d2dDeviceContext3 = new _d2d.DeviceContext3(d2dDevice3, DeviceContextOptions.None); #endregion #region create drawing input sourceImage = createD2DBitmap(@"yourFile.png", d2dDeviceContext3); spriteBatch = new SpriteBatch(d2dDeviceContext3); var destinationRects = new RawRectangleF[1]; destinationRects[0] = new RectangleF(100, 50, sourceImage.Size.Width, sourceImage.Size.Height); var sourceRects = new RawRectangle[1]; sourceRects[0] = new RectangleF(0, 0, sourceImage.Size.Width, sourceImage.Size.Height); #endregion #region mainLoop RenderLoop.Run(mainForm, () => { if (d2dTarget != null) { d2dTarget.Dispose(); d2dTarget = null; } using (var backBuffer = Texture2D.FromSwapChain <Texture2D>(swapChain, 0)) { using (var surface = backBuffer.QueryInterface <Surface>()) { var bmpProperties = new BitmapProperties1( new PixelFormat(Format.R8G8B8A8_UNorm, _d2d.AlphaMode.Premultiplied), dpiX: 96, dpiY: 96, bitmapOptions: BitmapOptions.Target | BitmapOptions.CannotDraw); d2dTarget = new Bitmap1( d2dDeviceContext3, surface, bmpProperties); d2dDeviceContext3.Target = d2dTarget; } } //the key missing piece: cannot use per primitive antialiasing with spritebatch d2dDeviceContext3.AntialiasMode = AntialiasMode.Aliased; d2dDeviceContext3.BeginDraw(); spriteBatch.Clear(); spriteBatch.AddSprites( 1, destinationRects, sourceRects, null, null, destinationRectanglesStride: 0, //0 stride because there is only 1 element sourceRectanglesStride: 0, colorsStride: 0, transformsStride: 0); d2dDeviceContext3.DrawSpriteBatch( spriteBatch: spriteBatch, startIndex: 0, spriteCount: 1, bitmap: sourceImage, interpolationMode: BitmapInterpolationMode.Linear, spriteOptions: SpriteOptions.ClampToSourceRectangle); d2dDeviceContext3.EndDraw(); //first param set to 1 would indicate waitVerticalBlanking swapChain.Present(0, PresentFlags.None); }); #endregion }