コード例 #1
0
        public override void DrawBuffer(VertexBufferBase vb, MpGe.Effect.EffectBase eb)
        {
            var eff = eb as Effect.Effect;

            Buffer.VertexBufferDX12 buf = vb as Buffer.VertexBufferDX12;

            var list = eff.commandList;

            //   list.SetRenderTargets(rtvHandle, null);
            CommandList.PipelineState = eff.pipelineState;
            CommandList.SetDescriptorHeaps(eff._descriptorHeaps.Length, eff._descriptorHeaps);
            CommandList.SetGraphicsRootSignature(eff.Root);



            CommandList.SetVertexBuffer(0, buf.vertexBufferView);
            CommandList.SetIndexBuffer(buf.indexBufferView);
            CommandList.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;



            CommandList.SetGraphicsRootDescriptorTable(0, eff._cbvHeap.GPUDescriptorHandleForHeapStart);
            CommandList.DrawIndexedInstanced(buf.IndexCount, 1, 0, 0, 0);


            //CommandQueue.ExecuteCommandList(CommandList);
            //FlushCommandQueue();
        }
コード例 #2
0
        protected override void Draw(GameTimer gt)
        {
            // Reuse the memory associated with command recording.
            // We can only reset when the associated command lists have finished execution on the GPU.
            DirectCmdListAlloc.Reset();

            // A command list can be reset after it has been added to the command queue via ExecuteCommandList.
            // Reusing the command list reuses memory.
            CommandList.Reset(DirectCmdListAlloc, _pso);

            CommandList.SetViewport(Viewport);
            CommandList.SetScissorRectangles(ScissorRectangle);

            // Indicate a state transition on the resource usage.
            CommandList.ResourceBarrierTransition(CurrentBackBuffer, ResourceStates.Present, ResourceStates.RenderTarget);

            // Clear the back buffer and depth buffer.
            CommandList.ClearRenderTargetView(CurrentBackBufferView, Color.LightSteelBlue);
            CommandList.ClearDepthStencilView(DepthStencilView, ClearFlags.FlagsDepth | ClearFlags.FlagsStencil, 1.0f, 0);

            // Specify the buffers we are going to render to.
            CommandList.SetRenderTargets(CurrentBackBufferView, DepthStencilView);

            // TODO: API suggestion: rename descriptorHeapsOut to descriptorHeaps;
            // TODO: Add an overload for a setting a single SetDescriptorHeap?
            // TODO: Make requiring explicit length optional.
            CommandList.SetDescriptorHeaps(_descriptorHeaps.Length, _descriptorHeaps);

            CommandList.SetGraphicsRootSignature(_rootSignature);

            CommandList.SetVertexBuffer(0, _boxGeo.VertexBufferView);
            CommandList.SetIndexBuffer(_boxGeo.IndexBufferView);
            CommandList.PrimitiveTopology = PrimitiveTopology.TriangleList;

            CommandList.SetGraphicsRootDescriptorTable(0, _cbvHeap.GPUDescriptorHandleForHeapStart);

            CommandList.DrawIndexedInstanced(_boxGeo.IndexCount, 1, 0, 0, 0);

            // Indicate a state transition on the resource usage.
            CommandList.ResourceBarrierTransition(CurrentBackBuffer, ResourceStates.RenderTarget, ResourceStates.Present);

            // Done recording commands.
            CommandList.Close();

            // Add the command list to the queue for execution.
            CommandQueue.ExecuteCommandList(CommandList);

            // Present the buffer to the screen. Presenting will automatically swap the back and front buffers.
            SwapChain.Present(0, PresentFlags.None);

            // Wait until frame commands are complete. This waiting is inefficient and is
            // done for simplicity. Later we will show how to organize our rendering code
            // so we do not have to wait per frame.
            FlushCommandQueue();
        }