[英]Culling items that are outside the visible area
The default renderer does not do any CPU-side viewport clipping nor occlusion detection. 默认渲染器不执行任何CPU端视口剪切也不执行遮挡检测。 If something is not supposed to be visible, it should not be shown. 如果某些东西不可见,则不应显示。 Use
Item::visible: false
for items that should not be drawn. 对于不应绘制的项目,请使用Item::visible: false
。 The primary reason for not adding such logic is that it adds additional cost which would also hurt applications that took care in behaving well. 不添加这种逻辑的主要原因是它增加了额外的成本,这也会损害表现良好的应用程序。
So is there a trick to do it easily, without implementing it myself? 那么有没有一个技巧可以很容易地做到,而不是自己实现它?
Note that in my case the items that are outside the visible area are there because they are in a ScrollView
and they are not scrolled-to. 请注意,在我的情况下,可见区域之外的项目是存在的,因为它们位于ScrollView
并且它们不会滚动到。
The reason I want culling is to reduce CPU usage for full-scene redraws. 我想要剔除的原因是为了减少全景重绘的CPU使用率。
Here is a trivial example you can extend upon: 这是一个可以扩展的简单示例:
Window {
visible: true
width: 640
height: 480
Rectangle {
anchors.centerIn: parent
width: 200
height: 200
color: "yellow"
Flickable {
id: view
anchors.fill: parent
contentWidth: 200
contentHeight: col.height
property real span : contentY + height
Column {
id: col
x: 90
spacing: 2
Repeater {
model: 50
delegate: Rectangle {
width: 10
height: 10
color: inView ? "blue" : "red"
property bool inView: y > view.contentY && y < view.span
}
}
}
}
}
}
Obviously, a full-proof solution would also include the item's height in the calculation. 显然,完全证明的解决方案还包括计算中项目的高度。 You can also do the check in the x axis if necessary. 如有必要,您还可以在x轴上进行检查。
为了增加dtech的答案,我刚刚了解到有一些QML组件,比如GridView和ListView,它们会自动进行剔除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.