Merge pull request #65579 from ZuBsPaCe/fix-viewport-sibling-order
Sibling SubViewports must be rendered from top to bottom
This commit is contained in:
commit
22a09fef5d
1 changed files with 10 additions and 7 deletions
|
@ -73,33 +73,36 @@ static Transform2D _canvas_get_transform(RendererViewport::Viewport *p_viewport,
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<RendererViewport::Viewport *> RendererViewport::_sort_active_viewports() {
|
Vector<RendererViewport::Viewport *> RendererViewport::_sort_active_viewports() {
|
||||||
// We need to sort the viewports in a "topological order",
|
// We need to sort the viewports in a "topological order", children first and
|
||||||
// children first and parents last, we use the Kahn's algorithm to achieve that.
|
// parents last. We also need to keep sibling viewports in the original order
|
||||||
|
// from top to bottom.
|
||||||
|
|
||||||
Vector<Viewport *> result;
|
Vector<Viewport *> result;
|
||||||
List<Viewport *> nodes;
|
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()) {
|
if (viewport->parent.is_valid()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.push_back(viewport);
|
nodes.push_back(viewport);
|
||||||
|
result.insert(0, viewport);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!nodes.is_empty()) {
|
while (!nodes.is_empty()) {
|
||||||
Viewport *node = nodes[0];
|
const Viewport *node = nodes[0];
|
||||||
nodes.pop_front();
|
nodes.pop_front();
|
||||||
|
|
||||||
result.insert(0, node);
|
for (int i = active_viewports.size() - 1; i >= 0; --i) {
|
||||||
|
Viewport *child = active_viewports[i];
|
||||||
for (Viewport *child : active_viewports) {
|
|
||||||
if (child->parent != node->self) {
|
if (child->parent != node->self) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nodes.find(child)) {
|
if (!nodes.find(child)) {
|
||||||
nodes.push_back(child);
|
nodes.push_back(child);
|
||||||
|
result.insert(0, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue