arxarian
arxarian

Reputation: 397

QML Rectangle Opacity Rendering Performance

If I set Rectangle (or Item) opacity to zero, is the item still rendered? For example if I set its visibility to false, the item is not rendered.

Can I say that setting visibility to false and setting opacity to 0 is the same from performance perspective?

Thanks

Upvotes: 2

Views: 472

Answers (1)

derM
derM

Reputation: 13691

We can test that:

Our QML-File for that will be:

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
}

We set the environment variable:

QSG_RENDERER_DEBUG=renderer

We will see:

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

Conclusion

Fully transparent objects won't show up in the Alpha nodes. They are not rendered, the same as visible: false

Alas, I haven't found this behavior documented, so it might be an optimization that is not promised to be there.

Upvotes: 1

Related Questions