如果我将矩形(或项目(不透明度设置为零,项目是否仍会渲染?例如,如果我将其可见性设置为 false,则不会呈现该项目。
我可以说从性能角度来看,将可见性设置为 false 和将不透明度设置为 0 是相同的吗?
谢谢
我们可以测试一下:
我们的QML文件将是:
Rectangle {
width: 100
height: 100
color: 'green'
opacity: timer.val ? 1 : 0
}
Rectangle {
width: 100
height: 100
x: 105
color: 'green'
}
Rectangle {
width: 100
height: 100
color: 'green'
y: 105
visible: timer.val
}
Rectangle {
width: 100
height: 100
x: 105
y: 105
color: 'green'
opacity: 0.5
}
Timer {
id: timer
running: true
repeat: true
interval: 2000
onTriggered: val = !val
property bool val: true
}
我们设置环境变量:
QSG_RENDERER_DEBUG=renderer
我们将看到:
Rendering: -> Opaque: 3 nodes in 1 batches... -> Alpha: 1 nodes in 1 batches... - 0x22e79428 [ upload] [noclip] [opaque] [ merged] Nodes: 3 Vertices: 12 Indices: 18 root: 0x0 - 0x22e790c8 [ upload] [noclip] [ alpha] [ merged] Nodes: 1 Vertices: 4 Indices: 6 root: 0x0 opacity: 0.5 -> times: build: 0, prepare(opaque/alpha): 0/0, sorting: 0, upload(opaque/alpha): 0/0, render: 4 Renderer::render() QSGAbstractRenderer(0x22e75640) "rebuild: full" Rendering: -> Opaque: 1 nodes in 1 batches... -> Alpha: 1 nodes in 1 batches... - 0x22e790c8 [ upload] [noclip] [opaque] [ merged] Nodes: 1 Vertices: 4 Indices: 6 root: 0x0 - 0x22e79428 [ upload] [noclip] [ alpha] [ merged] Nodes: 1 Vertices: 4 Indices: 6 root: 0x0 opacity: 0.5 -> times: build: 0, prepare(opaque/alpha): 0/0, sorting: 0, upload(opaque/alpha): 0/0, render: 1
结论
完全透明的对象不会显示在 Alpha 节点中。它们不会呈现,与visible: false
相同
唉,我还没有发现这种行为被记录下来,所以它可能是一个没有承诺存在的优化。