Beispiel #1
0
        /// <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();
            }
        }