Qt 3D:マルチビューポート QML の例

複数のビューポートから Scenegraph をレンダリングする QML の例。

Multi Viewportは、4つの仮想カメラの視点から、ウィンドウの4つの象限に Scenegraph をレンダリングします。これは、3D CAD やモデリングツールの一般的なコンフィギュレーションで、カーレースゲームや CCTV カメラディスプレイのバックミラーをレンダリングするのに役立ちます。

詳しくは、A Multi Viewport FrameGraphを参照してください。

例の実行

からサンプルを実行するには Qt Creatorからサンプルを実行するには、Welcome モードを開き、Examples からサンプルを選択します。詳細については、Building and Running an Exampleを参照してください。

複数のRenderViewの作成

Framegraph Rulesで定義されたルールを使って、FrameGraphから5つのRenderViewオブジェクトを作成します:

Viewport {
    id: mainViewport
    normalizedRect: Qt.rect(0, 0, 1, 1)

    ClearBuffers {
        buffers: ClearBuffers.ColorDepthBuffer
        clearColor: Qt.rgba(0.6, 0.6, 0.6, 1.0)
    }

    Viewport {
        id: topLeftViewport
        normalizedRect: Qt.rect(0, 0, 0.5, 0.5)
        CameraSelector { id: cameraSelectorTopLeftViewport }
    }

    Viewport {
        id: topRightViewport
        normalizedRect: Qt.rect(0.5, 0, 0.5, 0.5)
        CameraSelector { id: cameraSelectorTopRightViewport }
    }

    Viewport {
        id: bottomLeftViewport
        normalizedRect: Qt.rect(0, 0.5, 0.5, 0.5)
        CameraSelector { id: cameraSelectorBottomLeftViewport }
    }

    Viewport {
        id: bottomRightViewport
        normalizedRect: Qt.rect(0.5, 0.5, 0.5, 0.5)
        CameraSelector { id: cameraSelectorBottomRightViewport }
    }
}

順番は重要です。もし、ClearBuffers ノードが最初でなく最後であった場合、注意深くレンダリングされた直後に全てがクリアされてしまうという単純な理由で、黒い画面になってしまいます。同じような理由で、FrameGraphのルートとして使用することはできません。それは、各ビューポートの画面全体をクリアする呼び出しになるからです。

FrameGraphの宣言順序は重要ですが、Qt 3D 、RenderViewの状態が有効である間に送信されるRenderCommandのセットを生成する目的で、各RenderViewが他のRenderViewから独立しているため、各RenderViewを並列に処理することができます。

Qt 3D は、利用可能なコア数に応じて自然にスケールアップする並列性へのタスクベースのアプローチを使用しています。RenderView用のRenderCommandは、多くのコアで並列に生成することができ、専用のOpenGLサブミッションスレッドで正しい順序でRenderViewをサブミットするように注意しさえすれば、結果のシーンは正しくレンダリングされます。

サンプルプロジェクト @ code.qt.io

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.