20#include <Qt3DExtras/QTextureMaterial>
21#include <Qt3DRender/QAbstractTexture>
22#include <Qt3DRender/QBlendEquation>
23#include <Qt3DRender/QBlendEquationArguments>
24#include <Qt3DRender/QColorMask>
25#include <Qt3DRender/QEffect>
26#include <Qt3DRender/QGeometryRenderer>
27#include <Qt3DRender/QGraphicsApiFilter>
28#include <Qt3DRender/QNoDepthMask>
29#include <Qt3DRender/QNoDraw>
30#include <Qt3DRender/QPointSize>
31#include <Qt3DRender/QSeamlessCubemap>
32#include <Qt3DRender/QSortPolicy>
33#include <Qt3DRender/QTechnique>
35using namespace Qt::StringLiterals;
39 return dumpSG( context, node );
44 return dumpFG( context, node );
47QString QgsFrameGraphUtils::formatIdName( FgDumpContext context, quint64
id,
const QString &name )
49 QString fixedName = name.isEmpty() ?
"<no_name>"_L1 : name;
50 return "{%1/%2}"_L1.arg( QString::number(
id - context.lowestId ) ).arg( fixedName );
53QString QgsFrameGraphUtils::formatIdName( FgDumpContext context,
const Qt3DRender::QAbstractTexture *texture )
55 QString fixedName = texture->objectName().isEmpty() ?
"<no_name>"_L1 : texture->objectName();
56 return "{%1[%2]/%3"_L1.arg( QString::number( texture->id().id() - context.lowestId ), QString( QMetaEnum::fromType<Qt3DRender::QAbstractTexture::TextureFormat>().valueToKey( texture->format() ) ), fixedName );
59QString QgsFrameGraphUtils::formatNode( FgDumpContext context,
const Qt3DCore::QNode *node )
61 QString res =
"(%1%2)"_L1.arg( QLatin1String( node->metaObject()->className() ) ).arg( formatIdName( context, node->id().id(), node->objectName() ) );
62 if ( !node->isEnabled() )
67QString QgsFrameGraphUtils::formatList(
const QStringList &lst )
69 return QString(
"[ %1 ]"_L1 ).arg( lst.join(
", "_L1 ) );
72QString QgsFrameGraphUtils::formatLongList(
const QStringList &lst,
int level )
74 QString out = formatList( lst );
75 if ( out.size() < 200 )
78 out = QString(
"[\n"_L1 );
79 for ( QString item : lst )
81 item = QString(
"-> %1\n" ).arg( item );
82 out += item.rightJustified( item.length() + ( 1 + level ) * 2,
' ' );
84 QString end(
"]"_L1 );
85 return out + end.rightJustified( end.length() + ( 1 + level ) * 2,
' ' );
88QString QgsFrameGraphUtils::formatField(
const QString &name,
const QString &value )
90 if ( value ==
"<no_value>" )
91 return QString(
"(%1)"_L1 ).arg( name );
92 return QString(
"(%1:%2)"_L1 ).arg( name, value );
95QString QgsFrameGraphUtils::dumpSGEntity( FgDumpContext context,
const Qt3DCore::QEntity *node,
int level )
97 auto extractTextureParam = [](
FgDumpContext context,
const QVector<Qt3DRender::QParameter *> ¶ms, QStringList &fl ) {
98 for (
const auto *param : params )
100 if ( strstr( param->value().typeName(),
"QAbstractTexture*" ) )
102 const Qt3DRender::QAbstractTexture *tex = param->value().value<Qt3DRender::QAbstractTexture *>();
103 fl += formatField( param->name(), formatIdName( context, tex ) );
109 QString res = formatNode( context, node );
110 const auto &components = node->components();
111 if ( !components.isEmpty() )
113 QStringList componentNames;
114 for (
const auto &comp : components )
116 QString res = formatNode( context, comp );
118 if (
const auto *textMat = qobject_cast<const Qt3DExtras::QTextureMaterial *>( comp ) )
120 if ( textMat->texture() )
122 const auto texImages = textMat->texture()->textureImages();
123 for (
const auto *texImg : texImages )
125 fl += formatField( texImg->metaObject()->className(), formatIdName( context, texImg->id().id(), texImg->objectName() ) );
129 if (
const auto *material = qobject_cast<const Qt3DRender::QMaterial *>( comp ) )
131 if ( material->effect() )
133 const auto techniques = material->effect()->techniques();
134 for (
const auto *tech : techniques )
136 extractTextureParam( context, tech->parameters(), fl );
137 const auto passes = tech->renderPasses();
138 for (
const auto *pass : passes )
140 extractTextureParam( context, pass->parameters(), fl );
143 extractTextureParam( context, material->effect()->parameters(), fl );
145 extractTextureParam( context, material->parameters(), fl );
147 res += formatList( fl );
150 componentNames << res;
152 res += formatLongList( componentNames, level );
158QStringList QgsFrameGraphUtils::dumpSG( FgDumpContext context,
const Qt3DCore::QNode *node,
int level )
161 const auto *entity = qobject_cast<const Qt3DCore::QEntity *>( node );
164 QString res = dumpSGEntity( context, entity, level );
165 reply += res.rightJustified( res.length() + level * 2,
' ' );
169 const auto children = node->childNodes();
170 for (
auto *child : children )
171 reply += dumpSG( context, child, level );
176QString QgsFrameGraphUtils::dumpFGNode( FgDumpContext context,
const Qt3DRender::QFrameGraphNode *node )
178 QString res = formatNode( context, node );
180 if (
const auto *lf = qobject_cast<const Qt3DRender::QLayerFilter *>( node ) )
183 const auto layers = lf->layers();
184 for (
auto layer : layers )
186 sl += formatIdName( context, layer->id().id(), layer->objectName() );
190 fl += formatField( QMetaEnum::fromType<Qt3DRender::QLayerFilter::FilterMode>().valueToKey( lf->filterMode() ), formatList( sl ) );
191 res += QString(
" %1" ).arg( formatList( fl ) );
194 else if (
const auto *cs = qobject_cast<const Qt3DRender::QCameraSelector *>( node ) )
197 fl += formatField( cs->camera()->metaObject()->className(), formatIdName( context, cs->camera()->id().id(), cs->camera()->objectName() ) );
198 res += QString(
" %1" ).arg( formatList( fl ) );
201 else if (
const auto *rss = qobject_cast<const Qt3DRender::QRenderStateSet *>( node ) )
204 const auto renderStates = rss->renderStates();
205 for (
auto rs : renderStates )
207 if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QCullFace *>( rs ) )
209 sl += formatField(
"QCullFace", QMetaEnum::fromType<Qt3DRender::QCullFace::CullingMode>().valueToKey( rs_cast->mode() ) );
211 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QBlendEquation *>( rs ) )
213 sl += formatField(
"QBlendEquation", QMetaEnum::fromType<Qt3DRender::QBlendEquation::BlendFunction>().valueToKey( rs_cast->blendFunction() ) );
215 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QBlendEquationArguments *>( rs ) )
218 fl += formatField(
"sourceRgb", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->sourceRgb() ) );
219 fl += formatField(
"destinationRgb", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->destinationRgb() ) );
220 fl += formatField(
"sourceAlpha", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->sourceAlpha() ) );
221 fl += formatField(
"destinationAlpha", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->destinationAlpha() ) );
222 fl += formatField(
"bufferIndex", QString::number( rs_cast->bufferIndex() ) );
224 sl += formatField(
"QBlendEquationArguments", formatList( fl ) );
226 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QColorMask *>( rs ) )
229 fl += formatField(
"red", ( rs_cast->isRedMasked() ?
"true"_L1 :
"false"_L1 ) );
230 fl += formatField(
"green", ( rs_cast->isGreenMasked() ?
"true"_L1 :
"false"_L1 ) );
231 fl += formatField(
"blue", ( rs_cast->isBlueMasked() ?
"true"_L1 :
"false"_L1 ) );
232 fl += formatField(
"alpha", ( rs_cast->isAlphaMasked() ?
"true"_L1 :
"false"_L1 ) );
233 sl += formatField(
"QColorMask", formatList( fl ) );
235 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QDepthTest *>( rs ) )
237 sl += formatField(
"QDepthTest", QMetaEnum::fromType<Qt3DRender::QDepthTest::DepthFunction>().valueToKey( rs_cast->depthFunction() ) );
239 else if ( qobject_cast<const Qt3DRender::QNoDepthMask *>( rs ) )
241 sl += formatField(
"QNoDepthMask",
"<no_value>" );
243 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QPointSize *>( rs ) )
246 fl += formatField(
"sizeMode", QMetaEnum::fromType<Qt3DRender::QPointSize::SizeMode>().valueToKey( rs_cast->sizeMode() ) );
247 fl += formatField(
"value", QString::number( rs_cast->value() ) );
248 sl += formatField(
"QPointSize", formatList( fl ) );
250 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QPolygonOffset *>( rs ) )
253 fl += formatField(
"scaleFactor", QString::number( rs_cast->scaleFactor() ) );
254 fl += formatField(
"depthSteps", QString::number( rs_cast->depthSteps() ) );
255 sl += formatField(
"QPolygonOffset", formatList( fl ) );
257 else if ( qobject_cast<const Qt3DRender::QSeamlessCubemap *>( rs ) )
259 sl += formatField(
"QSeamlessCubemap",
"<no_value>" );
262 res += QString(
" %1" ).arg( formatList( sl ) );
265 else if (
const auto *rs = qobject_cast<const Qt3DRender::QRenderTargetSelector *>( node ) )
270 const auto outputs = rs->target()->outputs();
271 for (
auto output : outputs )
273 sl += formatField( QMetaEnum::fromType<Qt3DRender::QRenderTargetOutput::AttachmentPoint>().valueToKey( output->attachmentPoint() ), formatIdName( context, output->texture() ) );
276 fl += formatField(
"outputs"_L1, formatList( sl ) );
277 res += QString(
" %1" ).arg( formatList( fl ) );
285QStringList QgsFrameGraphUtils::dumpFG( FgDumpContext context,
const Qt3DCore::QNode *node,
int level )
289 const Qt3DRender::QFrameGraphNode *fgNode = qobject_cast<const Qt3DRender::QFrameGraphNode *>( node );
292 QString res = dumpFGNode( context, fgNode );
293 reply += res.rightJustified( res.length() + level * 2,
' ' );
296 const auto children = node->childNodes();
297 const int inc = fgNode ? 1 : 0;
298 for (
auto *child : children )
300 auto *childFGNode = qobject_cast<Qt3DCore::QNode *>( child );
302 reply += dumpFG( context, childFGNode, level + inc );
static QStringList dumpFrameGraph(const Qt3DCore::QNode *node, FgDumpContext context)
Returns a tree view of the frame graph starting from node. The object ids will be given relatively to...
static QStringList dumpSceneGraph(const Qt3DCore::QNode *node, FgDumpContext context)
Returns a tree view of the scene graph starting from node. The object ids will be given relatively to...