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 )
55 , QString( QMetaEnum::fromType<Qt3DRender::QAbstractTexture::TextureFormat>().valueToKey( texture->format() ) )
59QString QgsFgUtils::formatNode( FgDumpContext context,
const Qt3DCore::QNode *node )
61 QString res = QLatin1String(
"(%1%2)" )
62 .arg( QLatin1String( node->metaObject()->className() ) )
63 .arg( formatIdName( context, node->id().id(), node->objectName() ) );
64 if ( !node->isEnabled() )
65 res += QLatin1String(
" [D]" );
69QString QgsFgUtils::formatList(
const QStringList &lst )
71 return QString( QLatin1String(
"[ %1 ]" ) ).arg( lst.join( QLatin1String(
", " ) ) );
74QString QgsFgUtils::formatLongList(
const QStringList &lst,
int level )
76 QString out = formatList( lst );
77 if ( out.size() < 200 )
80 out = QString( QLatin1String(
"[\n" ) );
81 for ( QString item : lst )
83 item = QString(
"-> %1\n" ).arg( item );
84 out += item.rightJustified( item.length() + ( 1 + level ) * 2,
' ' );
86 QString end( QLatin1String(
"]" ) );
87 return out + end.rightJustified( end.length() + ( 1 + level ) * 2,
' ' );
90QString QgsFgUtils::formatField(
const QString &name,
const QString &value )
92 if ( value ==
"<no_value>" )
93 return QString( QLatin1String(
"(%1)" ) ).arg( name );
94 return QString( QLatin1String(
"(%1:%2)" ) ).arg( name, value );
97QString QgsFgUtils::dumpSGEntity( FgDumpContext context,
const Qt3DCore::QEntity *node,
int level )
99 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() ) );
134 if (
const auto *material = qobject_cast<const Qt3DRender::QMaterial *>(
comp ) )
136 if ( material->effect() )
138 const auto techniques = material->effect()->techniques();
139 for (
const auto *tech : techniques )
141 extractTextureParam( context, tech->parameters(), fl );
142 const auto passes = tech->renderPasses();
143 for (
const auto *pass : passes )
145 extractTextureParam( context, pass->parameters(), fl );
148 extractTextureParam( context, material->effect()->parameters(), fl );
150 extractTextureParam( context, material->parameters(), fl );
152 res += formatList( fl );
155 componentNames << res;
157 res += formatLongList( componentNames, level );
163QStringList QgsFgUtils::dumpSG( FgDumpContext context,
const Qt3DCore::QNode *node,
int level )
166 const auto *entity = qobject_cast<const Qt3DCore::QEntity *>( node );
169 QString res = dumpSGEntity( context, entity, level );
170 reply += res.rightJustified( res.length() + level * 2,
' ' );
174 const auto children = node->childNodes();
175 for (
auto *child : children )
176 reply += dumpSG( context, child, level );
181QString QgsFgUtils::dumpFGNode( FgDumpContext context,
const Qt3DRender::QFrameGraphNode *node )
183 QString res = formatNode( context, node );
185 if (
const auto *lf = qobject_cast<const Qt3DRender::QLayerFilter *>( node ) )
188 const auto layers = lf->layers();
189 for (
auto layer : layers )
191 sl += formatIdName( context, layer->id().id(), layer->objectName() );
195 fl += formatField( QMetaEnum::fromType<Qt3DRender::QLayerFilter::FilterMode>().valueToKey( lf->filterMode() )
196 , 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(),
204 formatIdName( context, cs->camera()->id().id(), cs->camera()->objectName() ) );
205 res += QString(
" %1" ).arg( formatList( fl ) );
208 else if (
const auto *rss = qobject_cast<const Qt3DRender::QRenderStateSet *>( node ) )
211 const auto renderStates = rss->renderStates();
212 for (
auto rs : renderStates )
214 if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QCullFace *>( rs ) )
216 sl += formatField(
"QCullFace", QMetaEnum::fromType<Qt3DRender::QCullFace::CullingMode>().valueToKey( rs_cast->mode() ) );
218 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QBlendEquation *>( rs ) )
220 sl += formatField(
"QBlendEquation", QMetaEnum::fromType<Qt3DRender::QBlendEquation::BlendFunction>().valueToKey( rs_cast->blendFunction() ) );
222 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QBlendEquationArguments *>( rs ) )
225 fl += formatField(
"sourceRgb", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->sourceRgb() ) );
226 fl += formatField(
"destinationRgb", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->destinationRgb() ) );
227 fl += formatField(
"sourceAlpha", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->sourceAlpha() ) );
228 fl += formatField(
"destinationAlpha", QMetaEnum::fromType<Qt3DRender::QBlendEquationArguments::Blending>().valueToKey( rs_cast->destinationAlpha() ) );
229 fl += formatField(
"bufferIndex", QString::number( rs_cast->bufferIndex() ) );
231 sl += formatField(
"QBlendEquationArguments", formatList( fl ) );
233 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QColorMask *>( rs ) )
236 fl += formatField(
"red", ( rs_cast->isRedMasked() ? QLatin1String(
"true" ) : QLatin1String(
"false" ) ) );
237 fl += formatField(
"green", ( rs_cast->isGreenMasked() ? QLatin1String(
"true" ) : QLatin1String(
"false" ) ) );
238 fl += formatField(
"blue", ( rs_cast->isBlueMasked() ? QLatin1String(
"true" ) : QLatin1String(
"false" ) ) );
239 fl += formatField(
"alpha", ( rs_cast->isAlphaMasked() ? QLatin1String(
"true" ) : QLatin1String(
"false" ) ) );
240 sl += formatField(
"QColorMask", formatList( fl ) );
242 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QDepthTest *>( rs ) )
244 sl += formatField(
"QDepthTest", QMetaEnum::fromType<Qt3DRender::QDepthTest::DepthFunction>().valueToKey( rs_cast->depthFunction() ) );
246 else if ( qobject_cast<const Qt3DRender::QNoDepthMask *>( rs ) )
248 sl += formatField(
"QNoDepthMask",
"<no_value>" );
250 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QPointSize *>( rs ) )
253 fl += formatField(
"sizeMode", QMetaEnum::fromType<Qt3DRender::QPointSize::SizeMode>().valueToKey( rs_cast->sizeMode() ) );
254 fl += formatField(
"value", QString::number( rs_cast->value() ) );
255 sl += formatField(
"QPointSize", formatList( fl ) );
257 else if (
const auto *rs_cast = qobject_cast<const Qt3DRender::QPolygonOffset *>( rs ) )
260 fl += formatField(
"scaleFactor", QString::number( rs_cast->scaleFactor() ) );
261 fl += formatField(
"depthSteps", QString::number( rs_cast->depthSteps() ) );
262 sl += formatField(
"QPolygonOffset", formatList( fl ) );
264 else if ( qobject_cast<const Qt3DRender::QSeamlessCubemap *>( rs ) )
266 sl += formatField(
"QSeamlessCubemap",
"<no_value>" );
269 res += QString(
" %1" ).arg( formatList( sl ) );
272 else if (
const auto *rs = qobject_cast<const Qt3DRender::QRenderTargetSelector *>( node ) )
277 const auto outputs = rs->target()->outputs();
278 for (
auto output : outputs )
280 sl += formatField( QMetaEnum::fromType<Qt3DRender::QRenderTargetOutput::AttachmentPoint>().valueToKey( output->attachmentPoint() ),
281 formatIdName( context, output->texture() ) );
284 fl += formatField( QLatin1String(
"outputs" ),
286 res += QString(
" %1" ).arg( formatList( fl ) );
294QStringList QgsFgUtils::dumpFG( FgDumpContext context,
const Qt3DCore::QNode *node,
int level )
298 const Qt3DRender::QFrameGraphNode *fgNode = qobject_cast<const Qt3DRender::QFrameGraphNode *>( node );
301 QString res = dumpFGNode( context, fgNode );
302 reply += res.rightJustified( res.length() + level * 2,
' ' );
305 const auto children = node->childNodes();
306 const int inc = fgNode ? 1 : 0;
307 for (
auto *child : children )
309 auto *childFGNode = qobject_cast<Qt3DCore::QNode *>( child );
311 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...