このページでは

QRhiTextureRenderTargetDescription Class

レンダリングターゲットの色や深度、あるいは深度/ステンシルアタッチメントについて説明します。詳細...

ヘッダー: #include <rhi/qrhi.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS GuiPrivate)
target_link_libraries(mytarget PRIVATE Qt6::GuiPrivate)
qmake: QT += gui-private
以下のように: Qt 6.6

パブリック関数

QRhiTextureRenderTargetDescription()
QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment)
QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiRenderBuffer *depthStencilBuffer)
QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiTexture *depthTexture)
const QRhiColorAttachment *cbeginColorAttachments() const
const QRhiColorAttachment *cendColorAttachments() const
const QRhiColorAttachment *colorAttachmentAt(qsizetype index) const
qsizetype colorAttachmentCount() const
(since 6.12) int depthLayer() const
(since 6.8) QRhiTexture *depthResolveTexture() const
QRhiRenderBuffer *depthStencilBuffer() const
QRhiTexture *depthTexture() const
void setColorAttachments(std::initializer_list<QRhiColorAttachment> list)
void setColorAttachments(InputIterator first, InputIterator last)
(since 6.12) void setDepthLayer(int depthLayer)
(since 6.8) void setDepthResolveTexture(QRhiTexture *tex)
void setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer)
void setDepthTexture(QRhiTexture *texture)
(since 6.9) void setShadingRateMap(QRhiShadingRateMap *map)
(since 6.9) QRhiShadingRateMap *shadingRateMap() const

詳細な説明

テクスチャ・レンダリング・ターゲットは、カラー・アタッチメントとして 0 個以上のテクスチャ、結合された深度/ステンシル・バッファとして 0 個または 1 個のレンダリング・バッファ、あるいは深度バッファとして 0 個または 1 個のテクスチャを持ちます。

注: depthStencilBuffer() とdepthTexture() を同時に設定することはできません(同時に null 以外にすることはできません)。

QRhiTextureRenderTarget と組み合わせて使用する例をいくつか見てみましょう。

コンストラクタのおかげで、テクスチャ(深度/ステンシルバッファなし)をターゲットに設定するのは簡単です:

QRhiTexture *texture = rhi->newTexture(QRhiTexture::RGBA8, QSize(256, 256), 1, QRhiTexture::RenderTarget);
texture->create();
QRhiTextureRenderTarget *rt = rhi->newTextureRenderTarget({ texture }));

以下は、テクスチャのミップレベル #2 をターゲットとするテクスチャ・レンダーターゲットを作成します:

QRhiTexture *texture = rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 1, QRhiTexture::RenderTarget | QRhiTexture::MipMapped);
texture->create();
QRhiColorAttachment colorAtt(texture);
colorAtt.setLevel(2);
QRhiTextureRenderTarget *rt = rhi->newTextureRenderTarget({ colorAtt });

別の例として、深度テクスチャにレンダリングする場合です:

QRhiTexture *shadowMap = rhi->newTexture(QRhiTexture::D32F, QSize(1024, 1024), 1, QRhiTexture::RenderTarget);
shadowMap->create();
QRhiTextureRenderTargetDescription rtDesc;
rtDesc.setDepthTexture(shadowMap);
QRhiTextureRenderTarget *rt = rhi->newTextureRenderTarget(rtDesc);

非常に一般的なケースとして、カラーアタッチメントにテクスチャを、深度/ステンシルにレンダーバッファを設定して深度テストを有効にする例があります:

QRhiTexture *texture = rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 1, QRhiTexture::RenderTarget);
texture->create();
QRhiRenderBuffer *depthStencil = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, QSize(512, 512));
depthStencil->create();
QRhiTextureRenderTargetDescription rtDesc({ texture }, depthStencil);
QRhiTextureRenderTarget *rt = rhi->newTextureRenderTarget(rtDesc);

最後に、移植性の高い方法でマルチサンプルレンダリングを有効にする(つまり OpenGL ES 3.0 もサポートする)には、QRhiRenderBuffer を(マルチサンプルの)カラーバッファとして使用し、それを通常の(マルチサンプルではない)2D テクスチャに解決します。 深度テストを有効にするには、同じサンプル数を使用する必要がある深度・ステンシルバッファも併せて使用します:

QRhiRenderBuffer *colorBuffer = rhi->newRenderBuffer(QRhiRenderBuffer::Color, QSize(512, 512), 4); // 4x MSAA
colorBuffer->create();
QRhiRenderBuffer *depthStencil = rhi->newRenderBuffer(QRhiRenderBuffer::DepthStencil, QSize(512, 512), 4);
depthStencil->create();
QRhiTexture *texture = rhi->newTexture(QRhiTexture::RGBA8, QSize(512, 512), 1, QRhiTexture::RenderTarget);
texture->create();
QRhiColorAttachment colorAtt(colorBuffer);
colorAtt.setResolveTexture(texture);
QRhiTextureRenderTarget *rt = rhi->newTextureRenderTarget({ colorAtt, depthStencil });

注: マルチサンプル解決が有効になっている場合 、マルチサンプルデータは一切書き出されない可能性があります。 つまり、resolveテクスチャが設定されている場合、カラーアタッチメント内のマルチサンプルテクスチャは、サンプリング(またはその他の目的)のためにシェーダーで使用してはなりません。これは、マルチサンプルカラーバッファが単なる中間記憶領域であり、一部のGPUアーキテクチャではデータが一切書き戻されないためです。詳細については、PreserveColorContents を参照してください。

注:` setDepthTexture()` を使用し、` setDepthStencilBuffer()`を使用しない場合 、かつその後、深度(ステンシル)データが必要ない場合は、`QRhiTextureRenderTarget` で `DoNotStoreDepthStencilContents` フラグを設定してください。これにより、基盤となる 3D API に対して、深度/ステンシルデータを破棄してもよいことを示すことができ、タイル型 GPU アーキテクチャではパフォーマンスが向上する可能性があります。 深度-ステンシルバッファがQRhiRenderBuffer である場合(およびマルチサンプルカラーテクスチャの場合も、前述の注を参照)、これは暗黙的に行われますが、深度(ステンシル)QRhiTexture を使用する場合は、その意図を明示的に宣言する必要があります。デフォルトでは、QRhi はデータが必要であると想定します(例:深度テクスチャが後でシェーダー内でサンプリングされる場合など)。

注:これは 互換性の保証が限定的な RHI API です。詳細についてはQRhi を参照してください。

QRhiColorAttachment およびQRhiTextureRenderTargetも参照してください 。

メンバ関数のドキュメント

[constexpr noexcept default] QRhiTextureRenderTargetDescription::QRhiTextureRenderTargetDescription()

空のテクスチャ・レンダーターゲット記述を作成します。

QRhiTextureRenderTargetDescription::QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment)

colorAttachment で定義される1つのアタッチメントを持つテクスチャ・レンダリングターゲットの記述を構築します。

QRhiTextureRenderTargetDescription::QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiRenderBuffer *depthStencilBuffer)

colorAttachment で記述されるカラーアタッチメントと、depthStencilBuffer で記述される深度/ステンシルアタッチメントの2つのアタッチメントを持つテクスチャ・レンダリングターゲット記述を構築します。

QRhiTextureRenderTargetDescription::QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiTexture *depthTexture)

2つのアタッチメントを持つテクスチャ・レンダリング・ターゲット記述を構築します。1つはcolorAttachment で記述されるカラー・アタッチメント、もう1つはdepthTexture で記述される深度アタッチメントです。

注: depthTexture は 、QRhiTexture::D16 やQRhiTexture::D32F などの適切なフォーマットでなければなりません。

const QRhiColorAttachment *QRhiTextureRenderTargetDescription::cbeginColorAttachments() const

添付リストの最初の項目を指す const イテレータを返します。

const QRhiColorAttachment *QRhiTextureRenderTargetDescription::cendColorAttachments() const

添付リストの最後の項目の直後を指す const イテレータを返します。

const QRhiColorAttachment *QRhiTextureRenderTargetDescription::colorAttachmentAt(qsizetype index) const

指定されたindex の位置にあるカラーアタッチメントを返します。

qsizetype QRhiTextureRenderTargetDescription::colorAttachmentCount() const

現在設定されているカラーアタッチメントの数を返します。

[since 6.12] int QRhiTextureRenderTargetDescription::depthLayer() const

深度/ステンシルアタッチメントに使用される配列スライスのインデックスを返します。デフォルトでは -1 を返します。

この関数は Qt 6.12 で導入されました。

setDepthLayer() およびsetDepthTexture()も参照してください 。

[since 6.8] QRhiTexture *QRhiTextureRenderTargetDescription::depthResolveTexture() const

マルチサンプル深度(または深度・ステンシル)テクスチャ(またはテクスチャ配列)が解決されるテクスチャを返します。該当するテクスチャがない場合は `nullptr ` を返します。これは最も一般的なケースです。

この関数は Qt 6.8 で導入されました。

setDepthResolveTexture()、QRhiColorAttachment::resolveTexture()、およびdepthTexture()も参照してください 。

QRhiRenderBuffer *QRhiTextureRenderTargetDescription::depthStencilBuffer() const

深度・ステンシルバッファとして使用されるレンダリングバッファを返します。設定されていない場合は、nullptr を返します。

setDepthStencilBuffer()も参照してください 。

QRhiTexture *QRhiTextureRenderTargetDescription::depthTexture() const

現在参照されている深度テクスチャを返します。設定されていない場合は、nullptr を返します。

setDepthTexture()も参照してください 。

void QRhiTextureRenderTargetDescription::setColorAttachments(std::initializer_list<QRhiColorAttachment> list)

カラーアタッチメントのlist を設定します。

template <typename InputIterator> void QRhiTextureRenderTargetDescription::setColorAttachments(InputIterator first, InputIterator last)

イテレータ `first ` および `last` を使用して、カラーアタッチメントのリストを設定します。

[since 6.12] void QRhiTextureRenderTargetDescription::setDepthLayer(int depthLayer)

深度/ステンシルアタッチメントに使用する配列のスライスインデックスを設定します。

特定のレイヤーをターゲットにしない場合は、-1(デフォルト)を渡します。非負の値に設定すると、レンダリングターゲットは、深度テクスチャのそのレイヤー(スライス)を正確にターゲットとするビューをアタッチします。これは、setDepthTexture() を通じて 2D 配列の深度テクスチャが提供された場合にのみ有効です。それ以外の場合は、この値は無視されます。

値は深度テクスチャの配列サイズ範囲内である必要があります。範囲外のインデックスを指定すると、未定義の挙動となります。インデックスは、テクスチャの作成時に指定された配列範囲に関係なく、基になるテクスチャに対して絶対的なものです。

depthLayer を指定すると、深度アタッチメントに対するレイヤード/マルチビューレンダリングが無効になります。

この関数は Qt 6.12 で導入されました。

depthLayer() およびsetDepthTexture()も参照してください 。

[since 6.8] void QRhiTextureRenderTargetDescription::setDepthResolveTexture(QRhiTexture *tex)

tex を使用して、深度(または深度・ステンシル)解像度テクスチャを設定します。

tex setDepthTexture() を通じて設定されたテクスチャとフォーマットが一致する 2D テクスチャまたは 2D テクスチャ配列であることが期待されます。

注: 深度(または深度・ステンシル)データの解決は 、実行時にQRhi::ResolveDepthStencil 機能がサポートされていると報告されている場合にのみ機能します。深度・ステンシル解決のサポートは、すべてのグラフィックス API で利用可能というわけではありません。したがって、深度・ステンシル解決が無条件に利用可能であることを前提とした設計は移植性がなく、避けるべきです。

注: 特に OpenGL ES における追加の制限として 、深度解決テクスチャの設定は、setDepthTexture() と組み合わせてのみ機能し、setDepthStencilBuffer() とは組み合わせて機能しない場合があります。

この関数は Qt 6.8 で導入されました。

関連項目: depthResolveTexture()、QRhiColorAttachment::setResolveTexture()、およびsetDepthTexture()。

void QRhiTextureRenderTargetDescription::setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer)

深度・ステンシル用のrenderBuffer を設定します。必須ではありません。例えば、このレンダリングターゲットのいずれかのレンダリングパスにおいて、グラフィックスパイプライン内で深度テスト/書き込みやステンシル関連の機能が一切使用されていない場合は、nullptr に設定したままにしておくことができます。

注: depthStencilBuffer() とdepthTexture() を同時に設定することはできません(両方が null 以外になることはできません)。

2DQRhiTexture ではなく、QRhiRenderBuffer を深度または深度/ステンシルバッファとして使用することは非常に一般的であり、アプリケーションではこのアプローチが推奨されます。QRhiTexture を使用する場合、深度データに後でアクセスする(たとえば、シェーダーでサンプリングする)場合や、multiview rendering が関与する場合(その場合は深度テクスチャがテクスチャ配列でなければならないため)、setDepthTexture()が重要になります。

depthStencilBuffer() およびsetDepthTexture()も参照してください 。

void QRhiTextureRenderTargetDescription::setDepthTexture(QRhiTexture *texture)

深度・ステンシル用のtexture を設定します。これはsetDepthStencilBuffer()の代替手段であり、QRhiRenderBuffer の代わりに、適切な型(例:QRhiTexture::D32F )を持つQRhiTexture を指定します。

注: depthStencilBuffer() とdepthTexture() は、同時に設定することはできません(同時に null 以外にすることはできません)。

texture は、2Dテクスチャか、2Dテクスチャ配列(テクスチャ配列がサポートされている場合)のいずれかです。テクスチャ配列の指定は、特にmultiview rendering に関連します。

注: texture がQRhiTexture::D24S8 のようなステンシル成分を持つフォーマットである場合 、それはステンシルバッファとしても機能します。

depthTexture() およびsetDepthStencilBuffer()も参照してください 。

[since 6.9] void QRhiTextureRenderTargetDescription::setShadingRateMap(QRhiShadingRateMap *map)

指定されたQRhiShadingRateMap map と関連付けられます。これは、QRhi::VariableRateShadingMap 機能がサポートされていると報告されている場合にのみ機能します。

QRhiCommandBuffer::setShadingRate() も呼び出された場合、各タイルに対して 2 つのシェーディングレートのうち高い方が使用されます。現在、コンバイナの動作を制御する手段は提供されていません。

注: レンダリングターゲットがすでに構築済み(create()が正常に呼び出された)の場合 、シェーディングレートマップを設定すると、異なる新しいQRhiRenderPassDescriptor が必要となるため、再構築が必要になります。 setRenderPassDescriptor()を再度呼び出し(レンダリングパスの外で)、create()を呼び出して再構築してください。これには、グラフィックスパイプラインなど、他の連鎖的な影響も生じます。これらも新しいQRhiRenderPassDescriptor に関連付けられ、再構築される必要があります。この対処法については、QRhiRenderPassDescriptor::serializedFormat()を参照してください。QRhiGraphicsPipeline::UsesShadingRate フラグも設定することを忘れないでください。

この関数は Qt 6.9 で導入されました。

shadingRateMap()も参照してください 。

[since 6.9] QRhiShadingRateMap *QRhiTextureRenderTargetDescription::shadingRateMap() const

現在設定されているQRhiShadingRateMap を返します。デフォルトでは、nullptr です。

この関数は Qt 6.9 で導入されました。

setShadingRateMap()も参照してください 。

© 2026 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.