source/dawn/imgui_impl_dawn.cpp
void ImGui_ImplDawn_RenderDrawData(ImDrawData *draw_data)
{
    // Avoid rendering when minimized
    if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
        return;

    // Create and grow vertex/index buffers if needed
    if (mVertexBuffer.Get() == nullptr || mVertexBufferSize < draw_data->TotalVtxCount)
    {
        mVertexBufferSize = draw_data->TotalVtxCount + 5000;
        mVertexBufferSize = mVertexBufferSize % 4 == 0
                                ? mVertexBufferSize
                                : mVertexBufferSize + 4 - mVertexBufferSize % 4;

        wgpu::BufferDescriptor descriptor;
        descriptor.size  = mVertexBufferSize * sizeof(ImDrawVert);
        descriptor.usage = wgpu::BufferUsage::Vertex | wgpu::BufferUsage::CopyDst;

        mVertexBuffer = mContextDawn->mDevice.CreateBuffer(&descriptor);
    }

    if (mIndexBuffer.Get() == nullptr || mIndexBufferSize < draw_data->TotalIdxCount)
    {
        mIndexBufferSize = draw_data->TotalIdxCount + 10000;
        mIndexBufferSize = mIndexBufferSize % 4 == 0 ? mIndexBufferSize
                                                     : mIndexBufferSize + 4 - mIndexBufferSize % 4;

        wgpu::BufferDescriptor descriptor;
        descriptor.size  = mIndexBufferSize * sizeof(ImDrawIdx);
        descriptor.usage = wgpu::BufferUsage::Index | wgpu::BufferUsage::CopyDst;

        mIndexBuffer = mContextDawn->mDevice.CreateBuffer(&descriptor);
    }

    // Upload vertex/index data into a single contiguous GPU buffer
    uint32_t vtx_dst    = 0;
    uint32_t idx_dst    = 0;
    ImDrawVert *pVertex = mVertexData;
    ImDrawIdx *pIndex   = mIndexData;
    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList *cmd_list = draw_data->CmdLists[n];
        memcpy(pVertex, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
        memcpy(pIndex, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));

        pVertex += cmd_list->VtxBuffer.Size;
        pIndex += cmd_list->IdxBuffer.Size;
        vtx_dst += cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
        idx_dst += cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx);
    }
    vtx_dst = vtx_dst % 4 == 0 ? vtx_dst : vtx_dst + 4 - vtx_dst % 4;
    idx_dst = idx_dst % 4 == 0 ? idx_dst : idx_dst + 4 - idx_dst % 4;

    if (vtx_dst != 0 && idx_dst != 0)
    {
        mContextDawn->setBufferData(mVertexBuffer, vtx_dst, mVertexData,
                                    (pVertex - mVertexData) * sizeof(ImDrawVert));
        mContextDawn->setBufferData(mIndexBuffer, idx_dst, mIndexData,
                                    (pIndex - mIndexData) * sizeof(ImDrawIdx));
    }
}
// Render function
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call
// this directly from your main loop)
Render function
(this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call
this directly from your main loop)
Render function ( this used to be set in io . RenderDrawListsFn and called by ImGui :: Render () but you can now call this directly from your main loop )
void ImGui_ImplDawn_RenderDrawData(ImDrawData *draw_data)
{
    if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
        return;
    if (mVertexBuffer.Get() == nullptr || mVertexBufferSize < draw_data->TotalVtxCount)
    {
        mVertexBufferSize = draw_data->TotalVtxCount + 5000;
        mVertexBufferSize = mVertexBufferSize % 4 == 0
                                ? mVertexBufferSize
                                : mVertexBufferSize + 4 - mVertexBufferSize % 4;
        wgpu::BufferDescriptor descriptor;
        descriptor.size  = mVertexBufferSize * sizeof(ImDrawVert);
        descriptor.usage = wgpu::BufferUsage::Vertex | wgpu::BufferUsage::CopyDst;
        mVertexBuffer = mContextDawn->mDevice.CreateBuffer(&descriptor);
    }
    if (mIndexBuffer.Get() == nullptr || mIndexBufferSize < draw_data->TotalIdxCount)
    {
        mIndexBufferSize = draw_data->TotalIdxCount + 10000;
        mIndexBufferSize = mIndexBufferSize % 4 == 0 ? mIndexBufferSize
                                                     : mIndexBufferSize + 4 - mIndexBufferSize % 4;
        wgpu::BufferDescriptor descriptor;
        descriptor.size  = mIndexBufferSize * sizeof(ImDrawIdx);
        descriptor.usage = wgpu::BufferUsage::Index | wgpu::BufferUsage::CopyDst;
        mIndexBuffer = mContextDawn->mDevice.CreateBuffer(&descriptor);
    }
    uint32_t vtx_dst    = 0;
    uint32_t idx_dst    = 0;
    ImDrawVert *pVertex = mVertexData;
    ImDrawIdx *pIndex   = mIndexData;
    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList *cmd_list = draw_data->CmdLists[n];
        memcpy(pVertex, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
        memcpy(pIndex, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
        pVertex += cmd_list->VtxBuffer.Size;
        pIndex += cmd_list->IdxBuffer.Size;
        vtx_dst += cmd_list->VtxBuffer.Size * sizeof(ImDrawVert);
        idx_dst += cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx);
    }
    vtx_dst = vtx_dst % 4 == 0 ? vtx_dst : vtx_dst + 4 - vtx_dst % 4;
    idx_dst = idx_dst % 4 == 0 ? idx_dst : idx_dst + 4 - idx_dst % 4;
    if (vtx_dst != 0 && idx_dst != 0)
    {
        mContextDawn->setBufferData(mVertexBuffer, vtx_dst, mVertexData,
                                    (pVertex - mVertexData) * sizeof(ImDrawVert));
        mContextDawn->setBufferData(mIndexBuffer, idx_dst, mIndexData,
                                    (pIndex - mIndexData) * sizeof(ImDrawIdx));
    }
}
void ImGui_ImplDawn_RenderDrawData ( ImDrawData * draw_data ) { if ( draw_data -> DisplaySize . x <= 0.0f || draw_data -> DisplaySize . y <= 0.0f ) return ; if ( mVertexBuffer . Get ( ) == nullptr || mVertexBufferSize < draw_data -> TotalVtxCount ) { mVertexBufferSize = draw_data -> TotalVtxCount + 5000 ; mVertexBufferSize = mVertexBufferSize % 4 == 0 ? mVertexBufferSize : mVertexBufferSize + 4 - mVertexBufferSize % 4 ; wgpu :: BufferDescriptor descriptor ; descriptor . size = mVertexBufferSize * sizeof ( ImDrawVert ) ; descriptor . usage = wgpu :: BufferUsage :: Vertex | wgpu :: BufferUsage :: CopyDst ; mVertexBuffer = mContextDawn -> mDevice . CreateBuffer ( & descriptor ) ; } if ( mIndexBuffer . Get ( ) == nullptr || mIndexBufferSize < draw_data -> TotalIdxCount ) { mIndexBufferSize = draw_data -> TotalIdxCount + 10000 ; mIndexBufferSize = mIndexBufferSize % 4 == 0 ? mIndexBufferSize : mIndexBufferSize + 4 - mIndexBufferSize % 4 ; wgpu :: BufferDescriptor descriptor ; descriptor . size = mIndexBufferSize * sizeof ( ImDrawIdx ) ; descriptor . usage = wgpu :: BufferUsage :: Index | wgpu :: BufferUsage :: CopyDst ; mIndexBuffer = mContextDawn -> mDevice . CreateBuffer ( & descriptor ) ; } uint32_t vtx_dst = 0 ; uint32_t idx_dst = 0 ; ImDrawVert * pVertex = mVertexData ; ImDrawIdx * pIndex = mIndexData ; for ( int n = 0 ; n < draw_data -> CmdListsCount ; n ++ ) { const ImDrawList * cmd_list = draw_data -> CmdLists [ n ] ; memcpy ( pVertex , cmd_list -> VtxBuffer . Data , cmd_list -> VtxBuffer . Size * sizeof ( ImDrawVert ) ) ; memcpy ( pIndex , cmd_list -> IdxBuffer . Data , cmd_list -> IdxBuffer . Size * sizeof ( ImDrawIdx ) ) ; pVertex += cmd_list -> VtxBuffer . Size ; pIndex += cmd_list -> IdxBuffer . Size ; vtx_dst += cmd_list -> VtxBuffer . Size * sizeof ( ImDrawVert ) ; idx_dst += cmd_list -> IdxBuffer . Size * sizeof ( ImDrawIdx ) ; } vtx_dst = vtx_dst % 4 == 0 ? vtx_dst : vtx_dst + 4 - vtx_dst % 4 ; idx_dst = idx_dst % 4 == 0 ? idx_dst : idx_dst + 4 - idx_dst % 4 ; if ( vtx_dst != 0 && idx_dst != 0 ) { mContextDawn -> setBufferData ( mVertexBuffer , vtx_dst , mVertexData , ( pVertex - mVertexData ) * sizeof ( ImDrawVert ) ) ; mContextDawn -> setBufferData ( mIndexBuffer , idx_dst , mIndexData , ( pIndex - mIndexData ) * sizeof ( ImDrawIdx ) ) ; } }
Render function
(this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call
this directly from your main loop)
Render function ( this used to be set in io . RenderDrawListsFn and called by ImGui :: Render () but you can now call this directly from your main loop )
// Avoid rendering when minimized // Create and grow vertex/index buffers if needed // Upload vertex/index data into a single contiguous GPU buffer