public override void Draw(SharpDX.Direct3D11.DeviceContext context, int index) { if (_engine.CurrentMSAASampling.Count <= 1) { if (OffSreenRenderTarget == null) { context.CopyResource(_engine.BackBufferTex, _renderTexture); } else { context.CopyResource(OffSreenRenderTarget, _renderTexture); } } else { if (OffSreenRenderTarget == null) { context.ResolveSubresource(_engine.BackBufferTex, 0, _renderTexture, 0, Format.R8G8B8A8_UNorm); } else { context.ResolveSubresource(OffSreenRenderTarget, 0, _renderTexture, 0, Format.R8G8B8A8_UNorm); } } }
internal void EndRender() { if (SyncInterval > 0 || sw.Elapsed.TotalMilliseconds >= 1000.0 / refreshRate) { D3D11.Texture2D backBuffer = swapChain.GetBackBuffer <D3D11.Texture2D>(0); deviceContext.ResolveSubresource(surfaceTexture, 0, backBuffer, 0, DXGI.Format.R8G8B8A8_UNorm); backBuffer.Dispose(); swapChain.Present(SyncInterval, DXGI.PresentFlags.None); sw.Restart(); } }
/// <summary> /// Called when RenderLoop wants to present its results. /// </summary> void IRenderLoopHost.OnRenderLoop_Present(EngineDevice engineDevice) { if (m_d3dImageSource == null) { return; } if (!this.IsLoaded) { return; } bool isLocked = false; GraphicsCore.Current.PerformanceCalculator.ExecuteAndMeasureActivityDuration( "Render.Lock", () => isLocked = m_d3dImageSource.TryLock(MAX_IMAGE_LOCK_DURATION)); if (!isLocked) { return; } try { // Draw current 3d scene to wpf D3D11.DeviceContext deviceContext = engineDevice.DeviceImmediateContextD3D11; deviceContext.ResolveSubresource(m_backBufferD3D11, 0, m_backBufferForWpf, 0, DXGI.Format.B8G8R8A8_UNorm); deviceContext.Flush(); deviceContext.ClearState(); // Apply true background texture if a cached bitmap was applied before if (this.Source != m_d3dImageSource) { this.Source = m_d3dImageSource; } // Invalidate the D3D image m_d3dImageSource.InvalidateD3DImage(); } finally { m_d3dImageSource.Unlock(); } }