Пример #1
0
    /// <summary>Initializes the GUI for this sample.</summary>
    /// <param name="application">The hosting <see cref="Application" />.</param>
    /// <param name="timeout">The <see cref="TimeSpan" /> after which this sample should stop running.</param>
    /// <param name="windowLocation">The <see cref="Vector2" /> that defines the initial window location.</param>
    /// <param name="windowSize">The <see cref="Vector2" /> that defines the initial window client rectangle size.</param>
    public virtual void Initialize(Application application, TimeSpan timeout, Vector2?windowLocation, Vector2?windowSize)
    {
        ExceptionUtilities.ThrowIfNull(application);

        var uiService = application.UIService;

        _window = uiService.DispatcherForCurrentThread.CreateWindow();
        _window.SetTitle(Name);

        if (windowLocation.HasValue)
        {
            _window.Relocate(windowLocation.GetValueOrDefault());
        }

        if (windowSize.HasValue)
        {
            _window.ResizeClient(windowSize.GetValueOrDefault());
        }

        _window.Show();

        var graphicsService = application.GraphicsService;
        var graphicsAdapter = graphicsService.Adapters.First();

        var graphicsDevice = graphicsAdapter.CreateDevice();

        _graphicsDevice = graphicsDevice;

        _renderPass = graphicsDevice.CreateRenderPass(_window, GraphicsFormat.B8G8R8A8_UNORM);
        base.Initialize(application, timeout);
    }
Пример #2
0
        GraphicsPipeline CreateGraphicsPipeline(GraphicsRenderPass renderPass, string shaderName, string vertexShaderEntryPoint, string pixelShaderEntryPoint)
        {
            var graphicsDevice = renderPass.Device;

            var pipelineCreateOptions = new GraphicsPipelineCreateOptions {
                Signature    = CreateGraphicsPipelineSignature(graphicsDevice),
                PixelShader  = CompileShader(graphicsDevice, GraphicsShaderKind.Pixel, shaderName, pixelShaderEntryPoint),
                VertexShader = CompileShader(graphicsDevice, GraphicsShaderKind.Vertex, shaderName, vertexShaderEntryPoint),
            };

            return(renderPass.CreatePipeline(in pipelineCreateOptions));
        }
Пример #3
0
    /// <summary>Begins a render pass.</summary>
    /// <param name="renderPass">The render pass to begin.</param>
    /// <param name="renderTargetClearColor">The color to which the render target should be cleared.</param>
    /// <exception cref="ArgumentNullException"><paramref name="renderPass" /> is <c>null</c>.</exception>
    /// <exception cref="InvalidOperationException">A render pass is already active.</exception>
    /// <exception cref="ObjectDisposedException">The context has been disposed.</exception>
    public void BeginRenderPass(GraphicsRenderPass renderPass, ColorRgba renderTargetClearColor)
    {
        ThrowIfNull(renderPass);

        if (Interlocked.CompareExchange(ref _renderPass, renderPass, null) is not null)
        {
            ThrowForInvalidState(nameof(RenderPass));
        }

        var d3d12GraphicsCommandList = D3D12GraphicsCommandList;
        var renderTarget             = renderPass.Swapchain.CurrentRenderTarget;

        var d3d12RtvResourceBarrier = D3D12_RESOURCE_BARRIER.InitTransition(renderTarget.D3D12RtvResource, D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET);

        d3d12GraphicsCommandList->ResourceBarrier(1, &d3d12RtvResourceBarrier);

        var d3d12RtvDescriptorHandle = renderTarget.D3D12RtvDescriptorHandle;

        d3d12GraphicsCommandList->OMSetRenderTargets(1, &d3d12RtvDescriptorHandle, RTsSingleHandleToDescriptorRange: TRUE, pDepthStencilDescriptor: null);

        d3d12GraphicsCommandList->ClearRenderTargetView(d3d12RtvDescriptorHandle, (float *)&renderTargetClearColor, NumRects: 0, pRects: null);
        d3d12GraphicsCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
    }
Пример #4
0
 /// <summary>Initializes a new instance of the <see cref="GraphicsRenderPassObject" /> class.</summary>
 /// <param name="renderPass">The render pass for which the object is being created.</param>
 /// <param name="name">The name of the object or <c>null</c> to use <see cref="MemberInfo.Name" />.</param>
 /// <exception cref="ArgumentNullException"><paramref name="renderPass" /> is <c>null</c>.</exception>
 protected GraphicsRenderPassObject(GraphicsRenderPass renderPass, string?name = null) : base(renderPass.Device, name)
 {
     _renderPass = renderPass;
 }
Пример #5
0
 internal GraphicsPipeline(GraphicsRenderPass renderPass, in GraphicsPipelineCreateOptions createOptions) : base(renderPass)
Пример #6
0
 internal GraphicsSwapchain(GraphicsRenderPass renderPass, in GraphicsSwapchainCreateOptions createOptions) : base(renderPass)