Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Submit user interface buffers for rendering
- /// </summary>
- /// <param name="draw_data">ImGui render data to submit</param>
- void RenderPassImgui::RenderGui(ImDrawData* draw_data)
- {
- ImGuiIO& io = ImGui::GetIO();
- mContext->SetPipelineState(mGuiPS);
- mContext->SetRootSignature(mGuiRS);
- mContext->SetPrimitiveTopology(Graphics::TRIANGLELIST);
- mContext->SetConstants(0, DWParam(io.DisplaySize.x), DWParam(io.DisplaySize.y));
- mContext->GetCommandList()->Get()->SetGraphicsRootDescriptorTable(1, mGuiFont->GetSRV().mGpuHandle);
- // TODO: Grow index and vertex buffer if and when necessary
- for (int n = 0; n < draw_data->CmdListsCount; n++)
- {
- int idx_offset = 0;
- int vtx_offset = 0;
- const ImDrawList* cmd_list = draw_data->CmdLists[n];
- size_t verticesCount = cmd_list->VtxBuffer.size();
- size_t indicesCount = cmd_list->IdxBuffer.size();
- size_t verticesSize = verticesCount * sizeof(ImDrawVert);
- size_t indicesSize = indicesCount * sizeof(ImDrawIdx);
- mContext->TransitionResource(mGuiVBO, D3D12_RESOURCE_STATE_COPY_DEST, false);
- mContext->TransitionResource(mGuiIBO, D3D12_RESOURCE_STATE_COPY_DEST, true);
- mContext->WriteBuffer(mGuiVBO, 0, &cmd_list->VtxBuffer[0], verticesSize);
- mContext->WriteBuffer(mGuiIBO, 0, &cmd_list->IdxBuffer[0], indicesSize);
- mContext->TransitionResource(mGuiVBO, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER, false);
- mContext->TransitionResource(mGuiIBO, D3D12_RESOURCE_STATE_INDEX_BUFFER, true);
- mContext->SetIndexBuffer(mGuiIBO->IndexBufferView(0, (unsigned int)indicesSize));
- mContext->SetVertexBuffer(0, mGuiVBO->VertexBufferView(0, (unsigned int)verticesSize, sizeof(ImDrawVert)));
- for (int cmd_i = 0; cmd_i < draw_data->CmdLists[n]->CmdBuffer.Size; cmd_i++)
- {
- const ImDrawCmd* pcmd = &draw_data->CmdLists[n]->CmdBuffer[cmd_i];
- if (pcmd->TextureId != io.Fonts->TexID)
- {
- D3D12_GPU_DESCRIPTOR_HANDLE handle;
- handle.ptr = (uint64_t)pcmd->TextureId;
- if (handle.ptr != 0)
- {
- mContext->GetCommandList()->Get()->SetGraphicsRootDescriptorTable(1, handle);
- if (pcmd->UserCallback)
- {
- pcmd->UserCallback(draw_data->CmdLists[n], pcmd);
- }
- else
- {
- mContext->SetScissorRect(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w);
- mContext->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
- }
- mContext->GetCommandList()->Get()->SetGraphicsRootDescriptorTable(1, mGuiFont->GetSRV().mGpuHandle);
- }
- }
- else
- {
- if (pcmd->UserCallback)
- {
- pcmd->UserCallback(draw_data->CmdLists[n], pcmd);
- }
- else
- {
- mContext->SetScissorRect(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z, pcmd->ClipRect.w);
- mContext->DrawIndexed(pcmd->ElemCount, idx_offset, vtx_offset);
- }
- }
- idx_offset += pcmd->ElemCount;
- }
- vtx_offset += draw_data->CmdLists[n]->VtxBuffer.size();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement