【问题标题】:QML Rectangle Opacity Rendering PerformanceQML 矩形不透明度渲染性能
【发布时间】:2018-03-20 16:18:29
【问题描述】:

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

我可以说从性能角度来看,将可见性设置为 false 和将不透明度设置为 0 是一样的吗?

谢谢

【问题讨论】:

    标签: performance qml qt5 rendering


    【解决方案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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      • 2012-01-16
      • 2012-03-01
      • 2011-04-07
      相关资源
      最近更新 更多