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
57 .arg( QString::number( texture->id().id() - context.lowestId ), QString( QMetaEnum::fromType<Qt3DRender::QAbstractTexture::TextureFormat>().valueToKey( texture->format() ) ), fixedName );
60QString QgsFrameGraphUtils::formatNode( FgDumpContext context,
const Qt3DCore::QNode *node )
62 QString res =
"(%1%2)"_L1
63 .arg( QLatin1String( node->metaObject()->className() ) )
64 .arg( formatIdName( context, node->id().id(), node->objectName() ) );
65 if ( !node->isEnabled() )
70QString QgsFrameGraphUtils::formatList(
const QStringList &lst )
72 return QString(
"[ %1 ]"_L1 ).arg( lst.join(
", "_L1 ) );
75QString QgsFrameGraphUtils::formatLongList(
const QStringList &lst,
int level )
77 QString out = formatList( lst );
78 if ( out.size() < 200 )
81 out = QString(
"[\n"_L1 );
82 for ( QString item : lst )
84 item = QString(
"-> %1\n" ).arg( item );
85 out += item.rightJustified( item.length() + ( 1 + level ) * 2,
' ' );
87 QString end(
"]"_L1 );
88 return out + end.rightJustified( end.length() + ( 1 + level ) * 2,
' ' );
91QString QgsFrameGraphUtils::formatField(
const QString &name,
const QString &value )
93 if ( value ==
"<no_value>" )
94 return QString(
"(%1)"_L1 ).arg( name );
95 return QString(
"(%1:%2)"_L1 ).arg( name, value );
98QString QgsFrameGraphUtils::dumpSGEntity( FgDumpContext context,
const Qt3DCore::QEntity *node,
int level )
100 auto extractTextureParam = [](
FgDumpContext context,
const QVector<Qt3DRender::QParameter *> ¶ms, QStringList &fl ) {
101 for (
const auto *param : params )
103 if ( strstr( param->value().typeName(),
"QAbstractTexture*" ) )
105 const Qt3DRender::QAbstractTexture *tex = param->value().value<Qt3DRender::QAbstractTexture *>();
106 fl += formatField( param->name(), formatIdName( context, tex ) );
112 QString res = formatNode( context, node );
113 const auto &components = node->components();
114 if ( !components.isEmpty() )
116 QStringList componentNames;
117 for (
const auto &comp : components )
119 QString res = formatNode( context, comp );
121 if (
const auto *textMat = qobject_cast<const Qt3DExtras::QTextureMaterial *>( comp ) )
123 if ( textMat->texture() )
125 const auto texImages = textMat->texture()->textureImages();
126 for (
const auto *texImg : texImages )
129 texImg->metaObject()->className(),
130 formatIdName( context, texImg->id().id(), texImg->objectName() )
135 if (
const auto *material = qobject_cast<const Qt3DRender::QMaterial *>( comp ) )
137 if ( material->effect() )
139 const auto techniques = material->effect()->techniques();
140 for (
const auto *tech : techniques )
142 extractTextureParam( context, tech->parameters(), fl );
143 const auto passes = tech->renderPasses();
144 for (
const auto *pass : passes )
146 extractTextureParam( context, pass->parameters(), fl );
149 extractTextureParam( context, material->effect()->parameters(), fl );
151 extractTextureParam( context, material->parameters(), fl );
153 res += formatList( fl );
156 componentNames << res;
158 res += formatLongList( componentNames, level );
164QStringList QgsFrameGraphUtils::dumpSG( FgDumpContext context,
const Qt3DCore::QNode *node,
int level )
167 const auto *entity = qobject_cast<const Qt3DCore::QEntity *>( node );
170 QString res = dumpSGEntity( context, entity, level );
171 reply += res.rightJustified( res.length() + level * 2,
' ' );
175 const auto children = node->childNodes();
176 for (
auto *child : children )
177 reply += dumpSG( context, child, level );
182QString QgsFrameGraphUtils::dumpFGNode( FgDumpContext context,
const Qt3DRender::QFrameGraphNode *node )
184 QString res = formatNode( context, node );
186 if (
const auto *lf = qobject_cast<const Qt3DRender::QLayerFilter *>( node ) )
189 const auto layers = lf->layers();
190 for (
auto layer : layers )
192 sl += formatIdName( context, layer->id().id(), layer->objectName() );
196 fl += formatField( QMetaEnum::fromType<Qt3DRender::QLayerFilter::FilterMode>().valueToKey( lf->filterMode() ), formatList( sl ) );
197 res += QString(
" %1" ).arg( formatList( fl ) );
200 else if (
const auto *cs = qobject_cast<const Qt3DRender::QCameraSelector *>( node ) )
203 fl += formatField( cs->camera()->metaObject()->className(), formatIdName( context, cs->camera()->id().id(), cs->camera()->objectName() ) );
204 res += QString(
" %1" ).arg( formatList( fl ) );
207 else if (
const auto *rss = qobject_cast<const Qt3DRender::QRenderStateSet *>( node ) )
210 const auto renderStates = rss->renderStates();
211 for (
auto rs : renderStates )
213 if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QCullFace *>( rs ) )
215 sl += formatField(
"QCullFace", QMetaEnum::fromType<Qt3DRender::QCullFace::CullingMode>().valueToKey( rs_cast->mode() ) );
217 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QBlendEquation *>( rs ) )
219 sl += formatField(
"QBlendEquation", QMetaEnum::fromType<Qt3DRender::QBlendEquation::BlendFunction>().valueToKey( rs_cast->blendFunction() ) );
221 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QBlendEquationArguments *>( rs ) )
224 fl += formatField(
"sourceRgb", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->sourceRgb() ) );
225 fl += formatField(
"destinationRgb", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->destinationRgb() ) );
226 fl += formatField(
"sourceAlpha", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->sourceAlpha() ) );
227 fl += formatField(
"destinationAlpha", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->destinationAlpha() ) );
228 fl += formatField(
"bufferIndex", QString::number( rs_cast->bufferIndex() ) );
230 sl += formatField(
"QBlendEquationArguments", formatList( fl ) );
232 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QColorMask *>( rs ) )
235 fl += formatField(
"red", ( rs_cast->isRedMasked() ?
"true"_L1 :
"false"_L1 ) );
236 fl += formatField(
"green", ( rs_cast->isGreenMasked() ?
"true"_L1 :
"false"_L1 ) );
237 fl += formatField(
"blue", ( rs_cast->isBlueMasked() ?
"true"_L1 :
"false"_L1 ) );
238 fl += formatField(
"alpha", ( rs_cast->isAlphaMasked() ?
"true"_L1 :
"false"_L1 ) );
239 sl += formatField(
"QColorMask", formatList( fl ) );
241 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QDepthTest *>( rs ) )
243 sl += formatField(
"QDepthTest", QMetaEnum::fromType<Qt3DRender::QDepthTest::DepthFunction>().valueToKey( rs_cast->depthFunction() ) );
245 else if ( qobject_cast<const Qt3DRender::QNoDepthMask *>( rs ) )
247 sl += formatField(
"QNoDepthMask",
"<no_value>" );
249 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QPointSize *>( rs ) )
252 fl += formatField(
"sizeMode", QMetaEnum::fromType<Qt3DRender::QPointSize::SizeMode>().valueToKey( rs_cast->sizeMode() ) );
253 fl += formatField(
"value", QString::number( rs_cast->value() ) );
254 sl += formatField(
"QPointSize", formatList( fl ) );
256 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QPolygonOffset *>( rs ) )
259 fl += formatField(
"scaleFactor", QString::number( rs_cast->scaleFactor() ) );
260 fl += formatField(
"depthSteps", QString::number( rs_cast->depthSteps() ) );
261 sl += formatField(
"QPolygonOffset", formatList( fl ) );
263 else if ( qobject_cast<const Qt3DRender::QSeamlessCubemap *>( rs ) )
265 sl += formatField(
"QSeamlessCubemap",
"<no_value>" );
268 res += QString(
" %1" ).arg( formatList( sl ) );
271 else if (
const auto *rs = qobject_cast<const Qt3DRender::QRenderTargetSelector *>( node ) )
276 const auto outputs = rs->target()->outputs();
277 for (
auto output : outputs )
279 sl += formatField( QMetaEnum::fromType<Qt3DRender::QRenderTargetOutput::AttachmentPoint>().valueToKey( output->attachmentPoint() ), formatIdName( context, output->texture() ) );
282 fl += formatField(
"outputs"_L1, formatList( sl ) );
283 res += QString(
" %1" ).arg( formatList( fl ) );
291QStringList QgsFrameGraphUtils::dumpFG( FgDumpContext context,
const Qt3DCore::QNode *node,
int level )
295 const Qt3DRender::QFrameGraphNode *fgNode = qobject_cast<const Qt3DRender::QFrameGraphNode *>( node );
298 QString res = dumpFGNode( context, fgNode );
299 reply += res.rightJustified( res.length() + level * 2,
' ' );
302 const auto children = node->childNodes();
303 const int inc = fgNode ? 1 : 0;
304 for (
auto *child : children )
306 auto *childFGNode = qobject_cast<Qt3DCore::QNode *>( child );
308 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...