public unsafe bool DrawFrame(Action <int, int> draw, [CallerMemberName] string?frameName = null) { var clearColor = new Color4(0.0f, 0.2f, 0.4f, 1.0f); DeviceContext.ClearRenderTargetView(RenderTargetView, clearColor); if (DepthStencilView != null) { DeviceContext.ClearDepthStencilView(DepthStencilView, DepthStencilClearFlags.Depth, 1.0f, 0); } DeviceContext.OMSetRenderTargets(RenderTargetView, DepthStencilView); DeviceContext.RSSetViewport(new Viewport(Size.Width, Size.Height)); DeviceContext.RSSetScissorRect(Size.Width, Size.Height); DeviceContext.IASetPrimitiveTopology(PrimitiveTopology.TriangleList); DeviceContext.VSSetShader(_vertexShader); DeviceContext.PSSetShader(_pixelShader); DeviceContext.IASetInputLayout(_inputLayout); DeviceContext.IASetVertexBuffer(0, _vertexBuffer, sizeof(VertexPositionColor)); DeviceContext.Draw(3, 0); // Call callback. draw(Size.Width, Size.Height); if (SwapChain != null) { Result result = SwapChain.Present(1, PresentFlags.None); if (result.Failure && result.Code == Vortice.DXGI.ResultCode.DeviceRemoved.Code) { return(false); } } return(true); }