/// <summary> /// Render scene /// </summary> public void Render() { // record all the commands we need to render the scene into the command list PopulateCommandLists(); // execute the command list commandQueue.ExecuteCommandList(commandList); // swap the back and front buffers swapChain.Present(1, 0); indexLastSwapBuf = (indexLastSwapBuf + 1) % SwapBufferCount; Utilities.Dispose(ref renderTarget); renderTarget = swapChain.GetBackBuffer<Resource>(indexLastSwapBuf); device.CreateRenderTargetView(renderTarget, null, descriptorHeap.CPUDescriptorHandleForHeapStart); // wait and reset EVERYTHING WaitForPrevFrame(); }
/// <summary> /// Setup resources for rendering /// </summary> private void LoadAssets() { // Create the descriptor heap for the render target view descriptorHeap = device.CreateDescriptorHeap(new DescriptorHeapDescription() { Type = DescriptorHeapType.RenderTargetView, DescriptorCount = 1 }); // Create the main command list commandList = device.CreateCommandList(CommandListType.Direct, commandListAllocator, null); // Get the backbuffer and creates the render target view renderTarget = swapChain.GetBackBuffer<Resource>(0); device.CreateRenderTargetView(renderTarget, null, descriptorHeap.CPUDescriptorHandleForHeapStart); // Create the viewport viewPort = new ViewportF(0, 0, width, height); // Create the scissor scissorRectangle = new Rectangle(0, 0, width, height); // Create a fence to wait for next frame fence = device.CreateFence(0, FenceFlags.None); currentFence = 1; // Close command list commandList.Close(); // Create an event handle use for VTBL eventHandle = new AutoResetEvent(false); // Wait the command list to complete WaitForPrevFrame(); }