用DirectX 12进行3D游戏编程入门「2」――渲染

匿名 (未验证) 提交于 2019-12-03 00:36:02

mCommandAllocator->Reset();
mCommandList->Reset(mCommandAllocator.Get(), mPSO.Get());

璁剧疆 root signature

mCommandList->SetGraphicsRootSignature(mRootSignature.Get());

璁剧疆 viewport and scissor rectangles

mCommandList->RSSetViewports(1, &mViewPort); mCommandList->RSSetScissorRects(1, &mRectScissor);
mCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(mRenderTarget.Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));
float clearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f }; mCommandList->ClearRenderTargetView(mDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), clearColor, 0, nullptr); mCommandList->OMSetRenderTargets(1, &mDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), true, nullptr); mCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);  mCommandList->IASetVertexBuffers(0, 1, &mDescViewBufVert); mCommandList->DrawInstanced(3, 1, 0, 0);
mCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(mRenderTarget.Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
mCommandList->Close();
ID3D12CommandList* ppCommandLists[] = { mCommandList.Get() };  mCommandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);
mSwapChain->Present(1, 0);  mIndexLastSwapBuf = (1 + mIndexLastSwapBuf) % cNumSwapBufs;  mSwapChain->GetBuffer(mIndexLastSwapBuf, IID_PPV_ARGS(mRenderTarget.ReleaseAndGetAddressOf())); mDevice->CreateRenderTargetView(mRenderTarget.Get(), nullptr,      mDescriptorHeap->GetCPUDescriptorHandleForHeapStart());
waitForGPU();
void populateCommandLists() {     mCommandAllocator->Reset();     mCommandList->Reset(mCommandAllocator.Get(), mPSO.Get());     mCommandList->SetGraphicsRootSignature(mRootSignature.Get());     mCommandList->RSSetViewports(1, &mViewPort);     mCommandList->RSSetScissorRects(1, &mRectScissor);      // indicate this resource will be in use as a render target     mCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(mRenderTarget.Get(),         D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));      float clearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f };     mCommandList->ClearRenderTargetView(mDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), clearColor, 0, nullptr);     mCommandList->OMSetRenderTargets(1, &mDescriptorHeap->GetCPUDescriptorHandleForHeapStart(), true, nullptr);     mCommandList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);      mCommandList->IASetVertexBuffers(0, 1, &mDescViewBufVert);     mCommandList->DrawInstanced(3, 1, 0, 0);      // indicate that the render target will now be used to present when the command list is executing     mCommandList->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(mRenderTarget.Get(),         D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));      mCommandList->Close(); }  void Render() {     // record all the commands we need to render the scene into the command list     populateCommandLists();      // execute the command list     ID3D12CommandList* ppCommandLists[] = { mCommandList.Get() };      mCommandQueue->ExecuteCommandLists(1, ppCommandLists);      // swap the back and front buffers     mSwapChain->Present(1, 0);      mIndexLastSwapBuf = (1 + mIndexLastSwapBuf) % cNumSwapBufs;      mSwapChain->GetBuffer(mIndexLastSwapBuf, IID_PPV_ARGS(mRenderTarget.ReleaseAndGetAddressOf()));     mDevice->CreateRenderTargetView(mRenderTarget.Get(), nullptr,          mDescriptorHeap->GetCPUDescriptorHandleForHeapStart());      // wait and reset everything     waitForGPU(); }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!