diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-13 11:01:33 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-09-13 11:01:33 +0200 |
commit | 22a09fef5d56fc7c37d70118532509076ebd7b12 (patch) | |
tree | 5e1cba95e7f84ad56cd9b30ed889c66e23b3132d /servers/rendering | |
parent | ff824b6f9d5bfa021ff788731a7e135afc95accd (diff) | |
parent | 3d08678e133d2220531435399e4fed073bfd2ec2 (diff) |
Merge pull request #65579 from ZuBsPaCe/fix-viewport-sibling-order
Sibling SubViewports must be rendered from top to bottom
Diffstat (limited to 'servers/rendering')
-rw-r--r-- | servers/rendering/renderer_viewport.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/servers/rendering/renderer_viewport.cpp b/servers/rendering/renderer_viewport.cpp index 5771def45f..eacd9bbbc2 100644 --- a/servers/rendering/renderer_viewport.cpp +++ b/servers/rendering/renderer_viewport.cpp @@ -73,33 +73,36 @@ static Transform2D _canvas_get_transform(RendererViewport::Viewport *p_viewport, } Vector<RendererViewport::Viewport *> RendererViewport::_sort_active_viewports() { - // We need to sort the viewports in a "topological order", - // children first and parents last, we use the Kahn's algorithm to achieve that. + // We need to sort the viewports in a "topological order", children first and + // parents last. We also need to keep sibling viewports in the original order + // from top to bottom. Vector<Viewport *> result; List<Viewport *> nodes; - for (Viewport *viewport : active_viewports) { + for (int i = active_viewports.size() - 1; i >= 0; --i) { + Viewport *viewport = active_viewports[i]; if (viewport->parent.is_valid()) { continue; } nodes.push_back(viewport); + result.insert(0, viewport); } while (!nodes.is_empty()) { - Viewport *node = nodes[0]; + const Viewport *node = nodes[0]; nodes.pop_front(); - result.insert(0, node); - - for (Viewport *child : active_viewports) { + for (int i = active_viewports.size() - 1; i >= 0; --i) { + Viewport *child = active_viewports[i]; if (child->parent != node->self) { continue; } if (!nodes.find(child)) { nodes.push_back(child); + result.insert(0, child); } } } |