19#include <Qt3DRender/QGeometryRenderer>
20#include <Qt3DRender/QTechnique>
21#include <Qt3DRender/QGraphicsApiFilter>
22#include <Qt3DRender/QBlendEquation>
23#include <Qt3DRender/QColorMask>
24#include <Qt3DRender/QSortPolicy>
25#include <Qt3DRender/QPointSize>
26#include <Qt3DRender/QSeamlessCubemap>
27#include <Qt3DRender/QNoDepthMask>
28#include <Qt3DRender/QBlendEquationArguments>
29#include <Qt3DExtras/QTextureMaterial>
30#include <Qt3DRender/QAbstractTexture>
31#include <Qt3DRender/QNoDraw>
32#include <Qt3DRender/QEffect>
36 return dumpSG( context, node );
41 return dumpFG( context, node );
44QString QgsFgUtils::formatIdName( FgDumpContext context, quint64
id,
const QString &name )
46 QString fixedName = name.isEmpty() ? QLatin1String(
"<no_name>" ) : name;
47 return QLatin1String(
"{%1/%2}" ).arg( QString::number(
id - context.lowestId ) ).arg( fixedName );
50QString QgsFgUtils::formatIdName( FgDumpContext context,
const Qt3DRender::QAbstractTexture *texture )
52 QString fixedName = texture->objectName().isEmpty() ? QLatin1String(
"<no_name>" ) : texture->objectName();
53 return QLatin1String(
"{%1[%2]/%3" )
54 .arg( QString::number( texture->id().id() - context.lowestId ), QString( QMetaEnum::fromType<Qt3DRender::QAbstractTexture::TextureFormat>().valueToKey( texture->format() ) ), fixedName );
57QString QgsFgUtils::formatNode( FgDumpContext context,
const Qt3DCore::QNode *node )
59 QString res = QLatin1String(
"(%1%2)" )
60 .arg( QLatin1String( node->metaObject()->className() ) )
61 .arg( formatIdName( context, node->id().id(), node->objectName() ) );
62 if ( !node->isEnabled() )
63 res += QLatin1String(
" [D]" );
67QString QgsFgUtils::formatList(
const QStringList &lst )
69 return QString( QLatin1String(
"[ %1 ]" ) ).arg( lst.join( QLatin1String(
", " ) ) );
72QString QgsFgUtils::formatLongList(
const QStringList &lst,
int level )
74 QString out = formatList( lst );
75 if ( out.size() < 200 )
78 out = QString( QLatin1String(
"[\n" ) );
79 for ( QString item : lst )
81 item = QString(
"-> %1\n" ).arg( item );
82 out += item.rightJustified( item.length() + ( 1 + level ) * 2,
' ' );
84 QString end( QLatin1String(
"]" ) );
85 return out + end.rightJustified( end.length() + ( 1 + level ) * 2,
' ' );
88QString QgsFgUtils::formatField(
const QString &name,
const QString &value )
90 if ( value ==
"<no_value>" )
91 return QString( QLatin1String(
"(%1)" ) ).arg( name );
92 return QString( QLatin1String(
"(%1:%2)" ) ).arg( name, value );
95QString QgsFgUtils::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 )
126 texImg->metaObject()->className(),
127 formatIdName( context, texImg->id().id(), texImg->objectName() )
132 if (
const auto *material = qobject_cast<const Qt3DRender::QMaterial *>(
comp ) )
134 if ( material->effect() )
136 const auto techniques = material->effect()->techniques();
137 for (
const auto *tech : techniques )
139 extractTextureParam( context, tech->parameters(), fl );
140 const auto passes = tech->renderPasses();
141 for (
const auto *pass : passes )
143 extractTextureParam( context, pass->parameters(), fl );
146 extractTextureParam( context, material->effect()->parameters(), fl );
148 extractTextureParam( context, material->parameters(), fl );
150 res += formatList( fl );
153 componentNames << res;
155 res += formatLongList( componentNames, level );
161QStringList QgsFgUtils::dumpSG( FgDumpContext context,
const Qt3DCore::QNode *node,
int level )
164 const auto *entity = qobject_cast<const Qt3DCore::QEntity *>( node );
167 QString res = dumpSGEntity( context, entity, level );
168 reply += res.rightJustified( res.length() + level * 2,
' ' );
172 const auto children = node->childNodes();
173 for (
auto *child : children )
174 reply += dumpSG( context, child, level );
179QString QgsFgUtils::dumpFGNode( FgDumpContext context,
const Qt3DRender::QFrameGraphNode *node )
181 QString res = formatNode( context, node );
183 if (
const auto *lf = qobject_cast<const Qt3DRender::QLayerFilter *>( node ) )
186 const auto layers = lf->layers();
187 for (
auto layer : layers )
189 sl += formatIdName( context, layer->id().id(), layer->objectName() );
193 fl += formatField( QMetaEnum::fromType<Qt3DRender::QLayerFilter::FilterMode>().valueToKey( lf->filterMode() ), formatList( sl ) );
194 res += QString(
" %1" ).arg( formatList( fl ) );
197 else if (
const auto *cs = qobject_cast<const Qt3DRender::QCameraSelector *>( node ) )
200 fl += formatField( cs->camera()->metaObject()->className(), formatIdName( context, cs->camera()->id().id(), cs->camera()->objectName() ) );
201 res += QString(
" %1" ).arg( formatList( fl ) );
204 else if (
const auto *rss = qobject_cast<const Qt3DRender::QRenderStateSet *>( node ) )
207 const auto renderStates = rss->renderStates();
208 for (
auto rs : renderStates )
210 if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QCullFace *>( rs ) )
212 sl += formatField(
"QCullFace", QMetaEnum::fromType<Qt3DRender::QCullFace::CullingMode>().valueToKey( rs_cast->mode() ) );
214 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QBlendEquation *>( rs ) )
216 sl += formatField(
"QBlendEquation", QMetaEnum::fromType<Qt3DRender::QBlendEquation::BlendFunction>().valueToKey( rs_cast->blendFunction() ) );
218 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QBlendEquationArguments *>( rs ) )
221 fl += formatField(
"sourceRgb", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->sourceRgb() ) );
222 fl += formatField(
"destinationRgb", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->destinationRgb() ) );
223 fl += formatField(
"sourceAlpha", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->sourceAlpha() ) );
224 fl += formatField(
"destinationAlpha", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->destinationAlpha() ) );
225 fl += formatField(
"bufferIndex", QString::number( rs_cast->bufferIndex() ) );
227 sl += formatField(
"QBlendEquationArguments", formatList( fl ) );
229 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QColorMask *>( rs ) )
232 fl += formatField(
"red", ( rs_cast->isRedMasked() ? QLatin1String(
"true" ) : QLatin1String(
"false" ) ) );
233 fl += formatField(
"green", ( rs_cast->isGreenMasked() ? QLatin1String(
"true" ) : QLatin1String(
"false" ) ) );
234 fl += formatField(
"blue", ( rs_cast->isBlueMasked() ? QLatin1String(
"true" ) : QLatin1String(
"false" ) ) );
235 fl += formatField(
"alpha", ( rs_cast->isAlphaMasked() ? QLatin1String(
"true" ) : QLatin1String(
"false" ) ) );
236 sl += formatField(
"QColorMask", formatList( fl ) );
238 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QDepthTest *>( rs ) )
240 sl += formatField(
"QDepthTest", QMetaEnum::fromType<Qt3DRender::QDepthTest::DepthFunction>().valueToKey( rs_cast->depthFunction() ) );
242 else if ( qobject_cast<const Qt3DRender::QNoDepthMask *>( rs ) )
244 sl += formatField(
"QNoDepthMask",
"<no_value>" );
246 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QPointSize *>( rs ) )
249 fl += formatField(
"sizeMode", QMetaEnum::fromType<Qt3DRender::QPointSize::SizeMode>().valueToKey( rs_cast->sizeMode() ) );
250 fl += formatField(
"value", QString::number( rs_cast->value() ) );
251 sl += formatField(
"QPointSize", formatList( fl ) );
253 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QPolygonOffset *>( rs ) )
256 fl += formatField(
"scaleFactor", QString::number( rs_cast->scaleFactor() ) );
257 fl += formatField(
"depthSteps", QString::number( rs_cast->depthSteps() ) );
258 sl += formatField(
"QPolygonOffset", formatList( fl ) );
260 else if ( qobject_cast<const Qt3DRender::QSeamlessCubemap *>( rs ) )
262 sl += formatField(
"QSeamlessCubemap",
"<no_value>" );
265 res += QString(
" %1" ).arg( formatList( sl ) );
268 else if (
const auto *rs = qobject_cast<const Qt3DRender::QRenderTargetSelector *>( node ) )
273 const auto outputs = rs->target()->outputs();
274 for (
auto output : outputs )
276 sl += formatField( QMetaEnum::fromType<Qt3DRender::QRenderTargetOutput::AttachmentPoint>().valueToKey( output->attachmentPoint() ), formatIdName( context, output->texture() ) );
279 fl += formatField( QLatin1String(
"outputs" ), formatList( sl ) );
280 res += QString(
" %1" ).arg( formatList( fl ) );
288QStringList QgsFgUtils::dumpFG( FgDumpContext context,
const Qt3DCore::QNode *node,
int level )
292 const Qt3DRender::QFrameGraphNode *fgNode = qobject_cast<const Qt3DRender::QFrameGraphNode *>( node );
295 QString res = dumpFGNode( context, fgNode );
296 reply += res.rightJustified( res.length() + level * 2,
' ' );
299 const auto children = node->childNodes();
300 const int inc = fgNode ? 1 : 0;
301 for (
auto *child : children )
303 auto *childFGNode = qobject_cast<Qt3DCore::QNode *>( child );
305 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...