private void RenderLoop() { while (!threadStop) { SharpDX.DXGI.Resource resource = screenCapture.AcquireFrame(); if (resource == null && OnScreenCaptured != null) { OnScreenCaptured(null, 0, 0, 0); continue; } Texture2D original = resource.QueryInterface <Texture2D>(); cDev.context.CopySubresourceRegion(original, 0, null, mipTexture, 0, 0, 0, 0); original.Dispose(); resource.Dispose(); screenCapture.ReleaseFrame(); cDev.context.GenerateMips(mipView); float scale = topPosition - bottomPosition; float offset = topPosition + bottomPosition - 1f; cDev.context.ClearRenderTargetView(intermediateView, Color4.Black); passThroughFilter.Apply(cDev.context, mipView, intermediateView, scale, offset); cDev.context.CopyResource(intermediateTexture, cpuTexture); cDev.context.ClearRenderTargetView(cDev.renderView, Color.Black); passThroughFilter.Apply(cDev.context, mipView, cDev.renderView, 1f, 0f); cDev.Present(); DataStream stream; DataBox dataBox = cDev.context.MapSubresource(cpuTexture, 0, MapMode.Read, SharpDX.Direct3D11.MapFlags.None, out stream); int count = dataBox.RowPitch / 16 * screenCaptureHeight; System.Numerics.Vector4[] pixels = stream.ReadRange <System.Numerics.Vector4>(count); stream.Dispose(); cDev.context.UnmapSubresource(cpuTexture, 0); if (OnScreenCaptured != null) { OnScreenCaptured(pixels, screenCaptureWidth, screenCaptureHeight, dataBox.RowPitch / 16); } } }