WIP: Rendering optimization: store rounded corners in texture to use 1 quad per corner.
diff --git a/imgui.cpp b/imgui.cpp
index 76c11c1..af17f0a 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -4836,16 +4836,62 @@
     ImVec2  CornerPosN;
     ImVec2  InnerDir;
     int     AngleMin12, AngleMax12;
+    ImDrawCornerFlags CornerFlags;
 };
 
 static const ImGuiResizeGripDef resize_grip_def[4] =
 {
-    { ImVec2(1,1), ImVec2(-1,-1), 0, 3 }, // Lower-right
-    { ImVec2(0,1), ImVec2(+1,-1), 3, 6 }, // Lower-left
-    { ImVec2(0,0), ImVec2(+1,+1), 6, 9 }, // Upper-left (Unused)
-    { ImVec2(1,0), ImVec2(-1,+1), 9,12 }, // Upper-right (Unused)
+    { ImVec2(1,1), ImVec2(-1,-1), 0, 3, ImDrawCornerFlags_BotRight  }, // Lower-right
+    { ImVec2(0,1), ImVec2(+1,-1), 3, 6, ImDrawCornerFlags_BotLeft   }, // Lower-left
+    { ImVec2(0,0), ImVec2(+1,+1), 6, 9, ImDrawCornerFlags_TopLeft   }, // Upper-left (Unused)
+    { ImVec2(1,0), ImVec2(-1,+1), 9,12, ImDrawCornerFlags_TopRight  }, // Upper-right (Unused)
 };
 
+static void AddResizeGrip(ImDrawList* dl, const ImVec2& corner, unsigned int rad, int rounding_corners_flags, ImU32 col)
+{
+    ImTextureID tex = dl->_Data->Font->ContainerAtlas->TexID;
+    IM_ASSERT(tex == dl->_TextureIdStack.back());  // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
+
+    switch (rounding_corners_flags)
+    {
+    case ImDrawCornerFlags_TopLeft:
+    case ImDrawCornerFlags_TopRight:
+    case ImDrawCornerFlags_BotRight:
+    case ImDrawCornerFlags_BotLeft:
+        break;
+    default:
+    {
+        IM_ASSERT("Invalid ImDrawCornerFlags for corner quad. {Top,Bot}{Left,Right} pick exactly one of each!");
+        return;
+    }
+    }
+
+    const ImVec4& uvs = (*dl->_Data->TexUvRoundCornerFilled)[rad - 1];
+
+    // NOTE: test performance using locals instead of array
+    const ImVec2 uv[] =
+    {
+        ImVec2(ImLerp(uvs.x, uvs.z, 0.5f), ImLerp(uvs.y, uvs.w, 0.5f)),
+        ImVec2(uvs.x, uvs.w),
+        ImVec2(uvs.z, uvs.w),
+    };
+
+    ImVec2 in_x = corner, in_y = corner;
+    if (rounding_corners_flags & ImDrawCornerFlags_Top)
+        in_y.y += rad;
+    else if (rounding_corners_flags & ImDrawCornerFlags_Bot)
+        in_y.y -= rad;
+    if (rounding_corners_flags & ImDrawCornerFlags_Left)
+        in_x.x += rad;
+    else if (rounding_corners_flags & ImDrawCornerFlags_Right)
+        in_x.x -= rad;
+
+    const ImVec2 mid = ImVec2(ImLerp(in_x.x, in_y.x, 0.5f), ImLerp(in_x.y, in_y.y, 0.5f));
+
+    dl->PrimReserve(6, 4);
+    dl->PrimQuadUV(mid, in_y, corner, in_x, uv[0], uv[1], uv[2], uv[1], col);
+}
+
 static ImRect GetResizeBorderRect(ImGuiWindow* window, int border_n, float perp_padding, float thickness)
 {
     ImRect rect = window->Rect();
@@ -5103,10 +5149,20 @@
             {
                 const ImGuiResizeGripDef& grip = resize_grip_def[resize_grip_n];
                 const ImVec2 corner = ImLerp(window->Pos, window->Pos + window->Size, grip.CornerPosN);
-                window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(window_border_size, resize_grip_draw_size) : ImVec2(resize_grip_draw_size, window_border_size)));
-                window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(resize_grip_draw_size, window_border_size) : ImVec2(window_border_size, resize_grip_draw_size)));
-                window->DrawList->PathArcToFast(ImVec2(corner.x + grip.InnerDir.x * (window_rounding + window_border_size), corner.y + grip.InnerDir.y * (window_rounding + window_border_size)), window_rounding, grip.AngleMin12, grip.AngleMax12);
-                window->DrawList->PathFillConvex(resize_grip_col[resize_grip_n]);
+                if (g.IO.KeyAlt)
+                {
+                    ImVec2 grip_corner = corner;
+                    grip_corner.x += grip.InnerDir.x * window_border_size;
+                    grip_corner.y += grip.InnerDir.y * window_border_size;
+                    AddResizeGrip(window->DrawList, grip_corner, (unsigned int)window_rounding, grip.CornerFlags, resize_grip_col[resize_grip_n]);
+                }
+                else
+                {
+                    //window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(window_border_size, resize_grip_draw_size) : ImVec2(resize_grip_draw_size, window_border_size)));
+                    window->DrawList->PathLineTo(corner + grip.InnerDir * ((resize_grip_n & 1) ? ImVec2(resize_grip_draw_size, window_border_size) : ImVec2(window_border_size, resize_grip_draw_size)));
+                    window->DrawList->PathArcToFast(ImVec2(corner.x + grip.InnerDir.x * (window_rounding + window_border_size), corner.y + grip.InnerDir.y * (window_rounding + window_border_size)), window_rounding, grip.AngleMin12, grip.AngleMax12);
+                    window->DrawList->PathFillConvex(resize_grip_col[resize_grip_n]);
+                }
             }
         }
 
@@ -6060,6 +6116,8 @@
 
     ImFontAtlas* atlas = g.Font->ContainerAtlas;
     g.DrawListSharedData.TexUvWhitePixel = atlas->TexUvWhitePixel;
+    g.DrawListSharedData.TexUvRoundCornerFilled = &atlas->TexUvRoundCornerFilled;
+    g.DrawListSharedData.TexUvRoundCornerStroked = &atlas->TexUvRoundCornerStroked;
     g.DrawListSharedData.Font = g.Font;
     g.DrawListSharedData.FontSize = g.FontSize;
 }
diff --git a/imgui.h b/imgui.h
index bde32ce..b7058ea 100644
--- a/imgui.h
+++ b/imgui.h
@@ -2071,7 +2071,8 @@
 {
     ImFontAtlasFlags_None               = 0,
     ImFontAtlasFlags_NoPowerOfTwoHeight = 1 << 0,   // Don't round the height to next power of two
-    ImFontAtlasFlags_NoMouseCursors     = 1 << 1    // Don't build software mouse cursors into the atlas
+    ImFontAtlasFlags_NoMouseCursors     = 1 << 1,   // Don't build software mouse cursors into the atlas
+    ImFontAtlasFlags_NoRoundCorners     = 1 << 2    // Don't use software rendered quads for round corners
 };
 
 // Load and rasterize multiple TTF/OTF fonts into a same texture. The font atlas will build a single texture holding:
@@ -2173,6 +2174,12 @@
     ImVector<ImFontConfig>      ConfigData;         // Internal data
     int                         CustomRectIds[1];   // Identifiers of custom texture rectangle used by ImFontAtlas/ImDrawList
 
+    // FIXME-ROUND-SHAPES: WIP
+    int                     RoundCornersMaxSize;    // Max pixel size of round corner textures to generate
+    ImVector<int>           RoundCornersRectIds;    // Ids of custom rects for round corners indexed by size [0] is 1px, [n] is (n+1)px (index up to RoundCornersMaxSize - 1).
+    ImVector<ImVec4>        TexUvRoundCornerFilled; // Texture coordinates to filled round corner quads
+    ImVector<ImVec4>        TexUvRoundCornerStroked;// Texture coordinates to stroked round corner quads
+
 #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
     typedef ImFontAtlasCustomRect    CustomRect;         // OBSOLETED in 1.72+
     typedef ImFontGlyphRangesBuilder GlyphRangesBuilder; // OBSOLETED in 1.67+
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index deaf4bc..a040e05 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -179,6 +179,111 @@
 }
 
 //-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+
+static void GetVtxIdxDelta(ImDrawList* dl, int* vtx, int *idx)
+{
+    static int vtx_n, idx_n;
+    static int vtx_o, idx_o;
+    vtx_n = dl->VtxBuffer.Size;
+    idx_n = dl->IdxBuffer.Size;
+
+    *vtx = vtx_n - vtx_o;
+    *idx = idx_n - idx_o;
+
+    vtx_o = vtx_n;
+    idx_o = idx_n;
+}
+
+static void TestTextureBasedRender()
+{
+    ImGuiIO& io = ImGui::GetIO();
+
+    ImGui::TextUnformatted("Press SHIFT to toggle quads (hold to see them).");
+    ImGui::TextUnformatted(io.KeyShift ? "SHIFT ON  -- Rasterized quad circle! w00t! OPTIMIZATION!"
+        : "SHIFT OFF -- Regular, boring circle with PathArcToFast.");
+
+    static float radius = io.Fonts->RoundCornersMaxSize * 0.5f;
+    ImGui::SliderFloat("radius", &radius, 0.0f, (float)io.Fonts->RoundCornersMaxSize, "%.0f");
+    ImGui::BeginGroup();
+
+    static int segments = 20;
+    ImGui::PushItemWidth(120);
+    ImGui::SliderInt("segments", &segments, 3, 100);
+    ImGui::PopItemWidth();
+
+    int vtx = 0;
+    int idx = 0;
+    ImDrawList* dl = ImGui::GetWindowDrawList();
+
+    {
+        ImGui::Button("##1", ImVec2(200, 200));
+        GetVtxIdxDelta(dl, &vtx, &idx);
+        ImVec2 min = ImGui::GetItemRectMin();
+        ImVec2 size = ImGui::GetItemRectSize();
+        dl->AddCircleFilled(ImVec2(min.x + size.x * 0.5f, min.y + size.y * 0.5f), radius, 0xFFFF00FF, segments);
+        GetVtxIdxDelta(dl, &vtx, &idx);
+        ImGui::Text("AddCircleFilled\n %d vtx, %d idx", vtx, idx);
+    }
+    {
+        ImGui::Button("##2", ImVec2(200, 200));
+        GetVtxIdxDelta(dl, &vtx, &idx);
+        ImVec2 min = ImGui::GetItemRectMin();
+        ImVec2 size = ImGui::GetItemRectSize();
+        dl->AddCircle(ImVec2(min.x + size.x * 0.5f, min.y + size.y * 0.5f), radius, 0xFFFF00FF, segments);
+        GetVtxIdxDelta(dl, &vtx, &idx);
+        ImGui::Text("AddCircle\n %d vtx, %d idx", vtx, idx);
+    }
+    ImGui::EndGroup();
+
+    ImGui::SameLine();
+
+    ImGui::BeginGroup();
+    static bool tl = true, tr = true, bl = true, br = true;
+    int flags = 0;
+    ImGui::Checkbox("TL", &tl);
+    ImGui::SameLine(0, 12);
+    ImGui::Checkbox("TR", &tr);
+    ImGui::SameLine(0, 12);
+    ImGui::Checkbox("BL", &bl);
+    ImGui::SameLine(0, 12);
+    ImGui::Checkbox("BR", &br);
+
+    flags |= tl ? ImDrawCornerFlags_TopLeft : 0;
+    flags |= tr ? ImDrawCornerFlags_TopRight : 0;
+    flags |= bl ? ImDrawCornerFlags_BotLeft : 0;
+    flags |= br ? ImDrawCornerFlags_BotRight : 0;
+
+    {
+        ImGui::Button("", ImVec2(200, 200));
+        ImVec2 r_min = ImGui::GetItemRectMin();
+        ImVec2 r_max = ImGui::GetItemRectMax();
+
+        GetVtxIdxDelta(dl, &vtx, &idx);
+        dl->AddRectFilled(r_min, r_max, 0xFFFF00FF, radius, flags);
+        GetVtxIdxDelta(dl, &vtx, &idx);
+        ImGui::Text("AddRectFilled\n %d vtx, %d idx", vtx, idx);
+    }
+    {
+        ImGui::Button("", ImVec2(200, 200));
+        ImVec2 r_min = ImGui::GetItemRectMin();
+        ImVec2 r_max = ImGui::GetItemRectMax();
+
+        GetVtxIdxDelta(dl, &vtx, &idx);
+        dl->AddRect(r_min, r_max, 0xFFFF00FF, radius, flags);
+        GetVtxIdxDelta(dl, &vtx, &idx);
+        ImGui::Text("AddRect\n %d vtx, %d idx", vtx, idx);
+    }
+
+    ImGui::EndGroup();
+
+    ImGui::Separator();
+
+    ImFontAtlas* atlas = ImGui::GetIO().Fonts;
+    ImGui::Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0, 0), ImVec2(1, 1), ImColor(255, 255, 255, 255), ImColor(255, 255, 255, 128));
+}
+
+//-----------------------------------------------------------------------------
 // [SECTION] Demo Window / ShowDemoWindow()
 //-----------------------------------------------------------------------------
 // - ShowDemoWindowWidgets()
@@ -314,6 +419,8 @@
     ImGui::Text("dear imgui says hello. (%s)", IMGUI_VERSION);
     ImGui::Spacing();
 
+    TestTextureBasedRender();
+
     if (ImGui::CollapsingHeader("Help"))
     {
         ImGui::Text("PROGRAMMER GUIDE:");
diff --git a/imgui_draw.cpp b/imgui_draw.cpp
index f73e0e3..23f2c3a 100644
--- a/imgui_draw.cpp
+++ b/imgui_draw.cpp
@@ -977,12 +977,190 @@
     PathStroke(col, false, thickness);
 }
 
+inline void AddRoundCornerRect(ImDrawList* draw_list, const ImVec2& a, const ImVec2& b, ImU32 col, float rounding, int rounding_corners_flags, bool fill)
+{
+    const ImDrawListSharedData* data = draw_list->_Data;
+    const int rad = (int)rounding;
+    IM_ASSERT(rad <= data->Font->ContainerAtlas->RoundCornersMaxSize);
+
+    ImTextureID tex_id = data->Font->ContainerAtlas->TexID;
+    IM_ASSERT(tex_id == draw_list->_TextureIdStack.back());  // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
+
+    const ImVec4& uvs = (*(fill ? data->TexUvRoundCornerFilled : data->TexUvRoundCornerStroked))[rad - 1];
+    const ImVec2 corner_uv[3] =
+    {
+        ImVec2(uvs.x, uvs.y),
+        fill ? ImVec2(uvs.x, uvs.w) : ImVec2(uvs.z, uvs.y),
+        ImVec2(uvs.z, uvs.w),
+    };
+
+    const bool ba = (rounding_corners_flags & ImDrawCornerFlags_TopLeft) != 0;
+    const bool bb = (rounding_corners_flags & ImDrawCornerFlags_TopRight) != 0;
+    const bool bc = (rounding_corners_flags & ImDrawCornerFlags_BotRight) != 0;
+    const bool bd = (rounding_corners_flags & ImDrawCornerFlags_BotLeft) != 0;
+
+    // TODO: fix "D" shaped stroked rects
+
+    const int rad_l = (ba || bd) ? rad : 0;
+    const int rad_t = (ba || bb) ? rad : 0;
+    const int rad_r = (bc || bb) ? rad : 0;
+    const int rad_b = (bc || bd) ? rad : 0;
+
+    const ImVec2 ca(a.x, a.y), cb(b.x, a.y);
+    const ImVec2 ma1(ca.x + rad_l, ca.y), mb1(cb.x - rad_r, cb.y);
+    const ImVec2 ma2(ca.x, ca.y + rad_t), mb2(cb.x, cb.y + rad_t);
+    const ImVec2 ia(ma1.x, ma2.y), ib(mb1.x, mb2.y);
+
+    const ImVec2 cc(b.x, b.y), cd(a.x, b.y);
+    const ImVec2 md3(cd.x, cd.y - rad_b), mc3(cc.x, cc.y - rad_b);
+    const ImVec2 md4(cd.x + rad_l, cd.y), mc4(cc.x - rad_r, cc.y);
+    const ImVec2 id(md4.x, md3.y), ic(mc4.x, mc3.y);
+
+    const int vtcs = 16;
+    const int idcs = 54;
+    draw_list->PrimReserve(idcs, vtcs);
+
+    const ImDrawIdx idx = (ImDrawIdx)draw_list->_VtxCurrentIdx;
+
+    #define VTX_WRITE(d, p, i)                          \
+        draw_list->_VtxWritePtr[d].pos = (p);           \
+        draw_list->_VtxWritePtr[d].uv = corner_uv[(i)]; \
+        draw_list->_VtxWritePtr[d].col = col
+
+    const int vca = 0, vcb = 1, vcc = 2, vcd = 3;
+    VTX_WRITE(vca, ca, ba ? 2 : 1);
+    VTX_WRITE(vcb, cb, bb ? 2 : 1);
+    VTX_WRITE(vcc, cc, bc ? 2 : 1);
+    VTX_WRITE(vcd, cd, bd ? 2 : 1);
+
+    int dv = 4;
+
+    int vya = vca, vxa = vca, via = vca;
+    int vyb = vcb, vxb = vcb, vib = vcb;
+    int vyc = vcc, vxc = vcc, vic = vcc;
+    int vyd = vcd, vxd = vcd, vid = vcd;
+
+    // FIXME-ROUND_SHAPES: TODO: find a way of saving vertices/triangles here?
+    // currently it's the same cost regardless of how many corners are rounded
+
+    if (ba || 1)
+    {
+        vya = dv;
+        vxa = dv + 1;
+        via = dv + 2;
+        VTX_WRITE(vya, ma1, 1);
+        VTX_WRITE(vxa, ma2, 1);
+        VTX_WRITE(via, ia, 0);
+        dv += 3;
+    }
+
+    if (bb || 1) 
+    {
+        vyb = dv;
+        vxb = dv + 1;
+        vib = dv + 2;
+        VTX_WRITE(vyb, mb1, 1);
+        VTX_WRITE(vxb, mb2, 1);
+        VTX_WRITE(vib, ib, 0);
+        dv += 3;
+    }
+
+    if (bc || 1) 
+    {
+        vyc = dv;
+        vxc = dv + 1;
+        vic = dv + 2;
+        VTX_WRITE(vyc, mc4, 1);
+        VTX_WRITE(vxc, mc3, 1);
+        VTX_WRITE(vic, ic, 0);
+        dv += 3;
+    }
+
+    if (bd || 1)
+    {
+        vyd = dv;
+        vxd = dv + 1;
+        vid = dv + 2;
+        VTX_WRITE(vyd, md4, 1);
+        VTX_WRITE(vxd, md3, 1);
+        VTX_WRITE(vid, id, 0);
+        dv += 3;
+    }
+
+    int di = 0;
+    #define IDX_WRITE_TRI(idx0, idx1, idx2)                      \
+        draw_list->_IdxWritePtr[di]   = (ImDrawIdx)(idx+(idx0)); \
+        draw_list->_IdxWritePtr[di+1] = (ImDrawIdx)(idx+(idx1)); \
+        draw_list->_IdxWritePtr[di+2] = (ImDrawIdx)(idx+(idx2)); \
+        di += 3
+
+    // Inner
+    if (fill)
+    {
+      IDX_WRITE_TRI(via, vic, vib);
+      IDX_WRITE_TRI(via, vic, vid);
+    }
+
+    if (ba || 1)
+    {
+        IDX_WRITE_TRI(vca, vya, via);
+        IDX_WRITE_TRI(vca, vxa, via);
+
+        IDX_WRITE_TRI(vib, vya, via);
+        IDX_WRITE_TRI(vid, vxa, via);
+    }
+
+    if (bb || 1)
+    {
+        IDX_WRITE_TRI(vcb, vyb, vib);
+        IDX_WRITE_TRI(vcb, vxb, vib);
+
+        IDX_WRITE_TRI(vya, vyb, vib);
+        IDX_WRITE_TRI(vic, vxb, vib);
+    }
+
+    if (bc || 1)
+    {
+        IDX_WRITE_TRI(vcc, vyc, vic);
+        IDX_WRITE_TRI(vcc, vxc, vic);
+
+        IDX_WRITE_TRI(vxb, vxc, vic);
+        IDX_WRITE_TRI(vyd, vyc, vic);
+    }
+
+    if (bd || 1)
+    {
+        IDX_WRITE_TRI(vcd, vyd, vid);
+        IDX_WRITE_TRI(vcd, vxd, vid);
+
+        IDX_WRITE_TRI(vic, vyd, vid);
+        IDX_WRITE_TRI(vxa, vxd, vid);
+    }
+
+    draw_list->_VtxWritePtr += dv;
+    draw_list->_VtxCurrentIdx += dv;
+    draw_list->_IdxWritePtr += di;
+
+    draw_list->PrimReserve(di - idcs, dv - vtcs);   // FIXME-OPT
+
+    #undef IDX_WRITE_TRI
+    #undef VTX_WRITE
+}
+
 // p_min = upper-left, p_max = lower-right
 // Note we don't render 1 pixels sized rectangles properly.
 void ImDrawList::AddRect(const ImVec2& p_min, const ImVec2& p_max, ImU32 col, float rounding, ImDrawCornerFlags rounding_corners, float thickness)
 {
     if ((col & IM_COL32_A_MASK) == 0)
         return;
+
+    rounding = ImMin(rounding, ImFabs(p_max.x - p_min.x) * (((rounding_corners & ImDrawCornerFlags_Top) == ImDrawCornerFlags_Top) || ((rounding_corners & ImDrawCornerFlags_Bot) == ImDrawCornerFlags_Bot) ? 0.5f : 1.0f) - 1.0f);
+    rounding = ImMin(rounding, ImFabs(p_max.y - p_min.y) * (((rounding_corners & ImDrawCornerFlags_Left) == ImDrawCornerFlags_Left) || ((rounding_corners & ImDrawCornerFlags_Right) == ImDrawCornerFlags_Right) ? 0.5f : 1.0f) - 1.0f);
+
+    // FIXME-ROUND-SHAPES: NOTE HACK TODO figure out why it's broken on small rounding
+    if (ImGui::GetIO().KeyShift && rounding > 3)
+        return AddRoundCornerRect(this, p_min, p_max, col, rounding, rounding_corners, /* fill */ false);
+
     if (Flags & ImDrawListFlags_AntiAliasedLines)
         PathRect(p_min + ImVec2(0.50f,0.50f), p_max - ImVec2(0.50f,0.50f), rounding, rounding_corners);
     else
@@ -994,10 +1172,23 @@
 {
     if ((col & IM_COL32_A_MASK) == 0)
         return;
-    if (rounding > 0.0f)
+
+    rounding = ImMin(rounding, ImFabs(p_max.x - p_min.x) * ( ((rounding_corners & ImDrawCornerFlags_Top)  == ImDrawCornerFlags_Top)  || ((rounding_corners & ImDrawCornerFlags_Bot)   == ImDrawCornerFlags_Bot)   ? 0.5f : 1.0f ) - 1.0f);
+    rounding = ImMin(rounding, ImFabs(p_max.y - p_min.y) * ( ((rounding_corners & ImDrawCornerFlags_Left) == ImDrawCornerFlags_Left) || ((rounding_corners & ImDrawCornerFlags_Right) == ImDrawCornerFlags_Right) ? 0.5f : 1.0f ) - 1.0f);
+
+    if (rounding > 0.0f && rounding_corners != 0)
     {
-        PathRect(p_min, p_max, rounding, rounding_corners);
-        PathFillConvex(col);
+        // FIXME-ROUND-SHAPES: NOTE HACK TODO figure out why it's broken on small rounding
+        if (ImGui::GetIO().KeyShift && rounding > 3)
+        {
+            AddRoundCornerRect(this, p_min, p_max, col, rounding, rounding_corners, /* fill */ true);
+            return;
+        }
+        else
+        {
+            PathRect(p_min, p_max, rounding, rounding_corners);
+            PathFillConvex(col);
+        }
     }
     else
     {
@@ -1068,11 +1259,85 @@
     PathFillConvex(col);
 }
 
+inline void AddRoundCornerCircle(ImDrawList* draw_list, const ImVec2& center, float radius, ImU32 col, bool fill)
+{
+    const ImDrawListSharedData* data = draw_list->_Data;
+    ImTextureID tex_id = data->Font->ContainerAtlas->TexID;
+    IM_ASSERT(tex_id == draw_list->_TextureIdStack.back());  // Use high-level ImGui::PushFont() or low-level ImDrawList::PushTextureId() to change font.
+
+    const int rad = (int)radius;
+    IM_ASSERT(rad <= data->Font->ContainerAtlas->RoundCornersMaxSize);
+
+    const ImVec4& uvs = (*(fill ? data->TexUvRoundCornerFilled : data->TexUvRoundCornerStroked))[rad - 1];
+    const ImVec2 corner_uv[3] = 
+    {
+        ImVec2(uvs.x, uvs.y),
+        fill ? ImVec2(uvs.x, uvs.w) : ImVec2(uvs.z, uvs.y),
+        ImVec2(uvs.z, uvs.w),
+    };
+
+    const ImVec2& c = center;
+    ImVec2 tl = ImVec2(c.x - rad, c.y - rad);
+    ImVec2 br = ImVec2(c.x + rad, c.y + rad);
+
+    // NOTE: test performance using locals instead of array
+    const ImVec2 circle_vt[9] = 
+    {
+        c,
+        tl,
+        ImVec2(c.x, tl.y),
+        ImVec2(br.x, tl.y),
+        ImVec2(br.x, c.y),
+        br,
+        ImVec2(c.x, br.y),
+        ImVec2(tl.x, br.y),
+        ImVec2(tl.x, c.y),
+    };
+
+    #define IDX_WRITE_TRI(d, idx0, idx1, idx2)                  \
+        draw_list->_IdxWritePtr[d+0] = (ImDrawIdx)(idx+idx0);   \
+        draw_list->_IdxWritePtr[d+1] = (ImDrawIdx)(idx+idx1);   \
+        draw_list->_IdxWritePtr[d+2] = (ImDrawIdx)(idx+idx2)
+
+    #define VTX_WRITE(d, i)                                     \
+        draw_list->_VtxWritePtr[d].pos = circle_vt[d];          \
+        draw_list->_VtxWritePtr[d].uv = corner_uv[i];           \
+        draw_list->_VtxWritePtr[d].col = col
+
+    draw_list->PrimReserve(24, 9);
+    ImDrawIdx idx = (ImDrawIdx)draw_list->_VtxCurrentIdx;
+    IDX_WRITE_TRI( 0, 0, 1, 2);
+    IDX_WRITE_TRI( 3, 0, 3, 2);
+    IDX_WRITE_TRI( 6, 0, 3, 4);
+    IDX_WRITE_TRI( 9, 0, 5, 4);
+    IDX_WRITE_TRI(12, 0, 5, 6);
+    IDX_WRITE_TRI(15, 0, 7, 6);
+    IDX_WRITE_TRI(18, 0, 7, 8);
+    IDX_WRITE_TRI(21, 0, 1, 8);
+
+    VTX_WRITE(1, 2); VTX_WRITE(2, 1); VTX_WRITE(3, 2);
+    VTX_WRITE(8, 1); VTX_WRITE(0, 0); VTX_WRITE(4, 1);
+    VTX_WRITE(7, 2); VTX_WRITE(6, 1); VTX_WRITE(5, 2);
+
+    draw_list->_VtxWritePtr += 9;
+    draw_list->_VtxCurrentIdx += 9;
+    draw_list->_IdxWritePtr += 24;
+
+#undef IDX_WRITE_TRI
+#undef VTX_WRITE
+}
+
 void ImDrawList::AddCircle(const ImVec2& center, float radius, ImU32 col, int num_segments, float thickness)
 {
     if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
         return;
 
+    if (ImGui::GetIO().KeyShift)
+    {
+        AddRoundCornerCircle(this, center, radius, col, false);
+        return;
+    }
+
     // Because we are filling a closed shape we remove 1 from the count of segments/points
     const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
     PathArcTo(center, radius - 0.5f, 0.0f, a_max, num_segments - 1);
@@ -1084,6 +1349,12 @@
     if ((col & IM_COL32_A_MASK) == 0 || num_segments <= 2)
         return;
 
+    if (ImGui::GetIO().KeyShift)
+    {
+        AddRoundCornerCircle(this, center, radius, col, true);
+        return;
+    }
+
     // Because we are filling a closed shape we remove 1 from the count of segments/points
     const float a_max = (IM_PI * 2.0f) * ((float)num_segments - 1.0f) / (float)num_segments;
     PathArcTo(center, radius, 0.0f, a_max, num_segments - 1);
@@ -1498,6 +1769,8 @@
     TexWidth = TexHeight = 0;
     TexUvScale = ImVec2(0.0f, 0.0f);
     TexUvWhitePixel = ImVec2(0.0f, 0.0f);
+
+    RoundCornersMaxSize = 60;
     for (int n = 0; n < IM_ARRAYSIZE(CustomRectIds); n++)
         CustomRectIds[n] = -1;
 }
@@ -1529,6 +1802,7 @@
     CustomRects.clear();
     for (int n = 0; n < IM_ARRAYSIZE(CustomRectIds); n++)
         CustomRectIds[n] = -1;
+    RoundCornersRectIds.clear();
 }
 
 void    ImFontAtlas::ClearTexData()
@@ -1540,6 +1814,8 @@
         IM_FREE(TexPixelsRGBA32);
     TexPixelsAlpha8 = NULL;
     TexPixelsRGBA32 = NULL;
+    TexUvRoundCornerFilled.clear();
+    TexUvRoundCornerStroked.clear();
 }
 
 void    ImFontAtlas::ClearFonts()
@@ -1847,6 +2123,7 @@
     IM_ASSERT(atlas->ConfigData.Size > 0);
 
     ImFontAtlasBuildRegisterDefaultCustomRects(atlas);
+    ImFontAtlasBuildRegisterRoundCornersCustomRects(atlas);
 
     // Clear atlas
     atlas->TexID = (ImTextureID)NULL;
@@ -2180,11 +2457,103 @@
     atlas->TexUvWhitePixel = ImVec2((r.X + 0.5f) * atlas->TexUvScale.x, (r.Y + 0.5f) * atlas->TexUvScale.y);
 }
 
+const unsigned int FONT_ATLAS_ROUNDED_CORNER_TEX_DATA_ID = 0x80000001;
+const int          FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING = 2;
+
+void ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas)
+{
+    if (atlas->RoundCornersRectIds.size() > 0)
+        return;
+
+    if ((atlas->Flags & ImFontAtlasFlags_NoRoundCorners))
+        return;
+
+    const int pad = FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING;
+    const int max = atlas->RoundCornersMaxSize;
+
+    // Filled
+    for (int n = 0; n < max; n++)
+        atlas->RoundCornersRectIds.push_back(atlas->AddCustomRectRegular(FONT_ATLAS_ROUNDED_CORNER_TEX_DATA_ID + n,
+            n + 1 + pad * 2, n + 1 + pad * 2));
+
+    // Stroked
+    for (int n = 0; n < max; n++)
+        atlas->RoundCornersRectIds.push_back(atlas->AddCustomRectRegular(FONT_ATLAS_ROUNDED_CORNER_TEX_DATA_ID + max + n,
+            n + 1 + pad * 2, n + 1 + pad * 2));
+}
+
+static void ImFontAtlasBuildRenderRoundCornersTexData(ImFontAtlas* atlas)
+{
+    IM_ASSERT(atlas->TexPixelsAlpha8 != NULL);
+    IM_ASSERT(atlas->TexUvRoundCornerFilled.size() == 0);
+    IM_ASSERT(atlas->TexUvRoundCornerStroked.size() == 0);
+
+    if ((atlas->Flags & ImFontAtlasFlags_NoRoundCorners))
+        return;
+
+    const int w = atlas->TexWidth;
+    const unsigned int max = atlas->RoundCornersMaxSize;
+
+    // Filled
+    for (unsigned int stage = 0; stage < 2; stage++)
+    {
+        bool filled = stage == 0;
+        for (unsigned int n = 0; n < max; n++)
+        {
+            const unsigned int id = (filled ? 0 : max) + n;
+            IM_ASSERT(atlas->RoundCornersRectIds.size() > (int) n);
+            ImFontAtlas::CustomRect& r = atlas->CustomRects[atlas->RoundCornersRectIds[id]];
+            IM_ASSERT(r.ID == FONT_ATLAS_ROUNDED_CORNER_TEX_DATA_ID + id);
+            IM_ASSERT(r.IsPacked());
+
+            const int pad = FONT_ATLAS_ROUNDED_CORNER_TEX_PADDING;
+
+            IM_ASSERT(r.Width == n + 1 + pad * 2 && r.Height == n + 1 + pad * 2);
+
+            const int radius = (int)(r.Width - pad * 2);
+            const float stroke_width = 1.0f;
+
+            for (int y = -pad; y < (int) (radius); y++)
+                for (int x = (filled ? -pad : y); x < (int)(filled ? y + pad : radius); x++)
+                {
+                    const float dist = ImSqrt((float)(x*x+y*y)) - (float)(radius - (filled ? 0 : stroke_width));
+
+                    float alpha = 0.0f;
+                    if (filled)
+                    {
+                        alpha = ImClamp(-dist, 0.0f, 1.0f);
+                    }
+                    else
+                    {
+                        const float alpha1 = ImClamp(dist + stroke_width, 0.0f, 1.0f);
+                        const float alpha2 = ImClamp(dist, 0.0f, 1.0f);
+                        alpha = alpha1 - alpha2;
+                    }
+
+                    const unsigned int offset = (int)(r.X + pad + x) + (int)(r.Y + pad + y) * w;
+                    atlas->TexPixelsAlpha8[offset] = (unsigned char)(0xFF * ImSaturate(alpha));
+                }
+
+            ImVec2 uv0, uv1;
+            r.X += pad;
+            r.Y += pad;
+            r.Width -= pad * 2;
+            r.Height -= pad * 2;
+            atlas->CalcCustomRectUV(&r, &uv0, &uv1);
+            ImVector<ImVec4>& uvs = (filled ? atlas->TexUvRoundCornerFilled : atlas->TexUvRoundCornerStroked);
+            uvs.push_back(ImVec4(uv0.x, uv0.y, uv1.x, uv1.y));
+        }
+    }
+}
+
 void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
 {
     // Render into our custom data block
     ImFontAtlasBuildRenderDefaultTexData(atlas);
 
+    // Render into our rounded corner data block
+    ImFontAtlasBuildRenderRoundCornersTexData(atlas);
+
     // Register custom rectangle glyphs
     for (int i = 0; i < atlas->CustomRects.Size; i++)
     {
diff --git a/imgui_internal.h b/imgui_internal.h
index bbdf0b6..04a6178 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -808,6 +808,10 @@
     // FIXME: Bake rounded corners fill/borders in atlas
     ImVec2          CircleVtx12[12];
 
+    // FIXME-ROUNDSHAPES: WIP + need to remove CircleVtx12 before PR
+    ImVector<ImVec4>* TexUvRoundCornerFilled;   // UV of filled round corner quad in the atlas
+    ImVector<ImVec4>* TexUvRoundCornerStroked;  // UV of stroked round corner quad in the atlas
+
     ImDrawListSharedData();
 };
 
@@ -1765,6 +1769,7 @@
 // ImFontAtlas internals
 IMGUI_API bool              ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas);
 IMGUI_API void              ImFontAtlasBuildRegisterDefaultCustomRects(ImFontAtlas* atlas);
+IMGUI_API void              ImFontAtlasBuildRegisterRoundCornersCustomRects(ImFontAtlas* atlas);
 IMGUI_API void              ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* font_config, float ascent, float descent);
 IMGUI_API void              ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opaque);
 IMGUI_API void              ImFontAtlasBuildFinish(ImFontAtlas* atlas);