QML矩形不透明度渲染性能

时间:2018-03-20 16:18:30

标签: performance qml qt5 rendering

如果我将Rectangle(或Item)的不透明度设置为零,该项目是否仍然呈现?例如,如果我将其可见性设置为false,则不会呈现该项目。

我可以说将性能设置为false并将不透明度设置为0从性能角度来看是否相同?

由于

1 个答案:

答案 0 :(得分:1)

我们可以测试一下:

我们的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

相同

唉,我没有发现这种行为记录在案,所以它可能是一种不承诺存在的优化。