Exemplo n.º 1
0
    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);
        DeviceContext.OMSetRenderTargets(RenderTargetView, /*depthStencil*/ null);
        DeviceContext.RSSetViewport(new Viewport(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);
    }