6#include <QtQuick3DRuntimeRender/private/qssgrendercontextcore_p.h>
7#include <QtQuick3DRuntimeRender/private/qssgrendereffect_p.h>
8#include <QtQuick3DRuntimeRender/private/qssgshadermaterialadapter_p.h>
9#include <QtQuick3DUtils/private/qssgutils_p.h>
10#include <QtQuick/qquickwindow.h>
11#include <QtQuick3D/private/qquick3dobject_p.h>
12#include <QtQuick3D/private/qquick3dscenemanager_p.h>
13#include <QtCore/qfile.h>
14#include <QtCore/qurl.h>
545 " FRAGCOLOR = texture(INPUT, INPUT_UV);\n"
550 static const char *argKey =
"/*%QT_ARGS_MAIN%*/";
551 const int argKeyLen = int(strlen(argKey));
552 const int argKeyPos = snippet.
indexOf(argKey);
562 if (!renderContext) {
563 qWarning(
"QQuick3DEffect: No render context interface?");
568 bool newBackendNode =
false;
571 newBackendNode =
true;
574 bool shadersMayChange =
false;
575 if (m_dirtyAttributes & Dirty::EffectChainDirty)
576 shadersMayChange =
true;
580 if (fullUpdate || shadersMayChange) {
584 const int idx =
metaObject()->indexOfSlot(
"onPropertyDirty()");
586 propertyDirtyMethod =
metaObject()->method(idx);
591 int propOffset =
metaObject()->propertyOffset();
595 while (superClass &&
qstrcmp(superClass->
className(),
"QQuick3DEffect") != 0) {
608 const auto name =
property.name();
609 QMetaType propType =
property.metaType();
610 QVariant propValue =
property.read(
this);
615 if (propType.
id() == qMetaTypeId<QQuick3DShaderUtilsTextureInput *>()) {
619 }
else if (propType ==
QMetaType(QMetaType::QObjectStar)) {
623 const auto type = uniformType(propType);
625 uniforms.
append({ uniformTypeName(propType),
name });
626 effectNode->
properties.push_back({
name, uniformTypeName(propType),
627 propValue, uniformType(propType),
i});
672 else if (tex && tex->textureData() && tex->textureData()->depth() > 0)
681 for (
const auto &
property :
std::as_const(textureProperties))
684 if (effectNode->incompleteBuildTimeObject) {
685 const auto names = dynamicPropertyNames();
693 if (propType.
id() == qMetaTypeId<QQuick3DShaderUtilsTextureInput *>()) {
697 }
else if (propType.
id() == QMetaType::QObjectStar) {
710 qWarning(
"No known uniform conversion found for effect property %s. Skipping",
name.constData());
715 for (
const auto &
property :
std::as_const(textureProperties))
720 uniforms.append({
"mat4",
"qt_modelViewProjection" });
721 uniforms.append({
"sampler2D",
"qt_inputTexture" });
722 uniforms.append({
"vec2",
"qt_inputSize" });
723 uniforms.append({
"vec2",
"qt_outputSize" });
724 uniforms.append({
"float",
"qt_frame_num" });
725 uniforms.append({
"float",
"qt_fps" });
726 uniforms.append({
"vec2",
"qt_cameraProperties" });
727 uniforms.append({
"float",
"qt_normalAdjustViewportFactor" });
728 uniforms.append({
"float",
"qt_nearClipValue" });
731 builtinVertexInputs.
append({
"vec3",
"attr_pos" });
732 builtinVertexInputs.
append({
"vec2",
"attr_uv" });
735 builtinVertexOutputs.
append({
"vec2",
"qt_inputUV" });
736 builtinVertexOutputs.
append({
"vec2",
"qt_textureUV" });
740 if (!m_passes.isEmpty()) {
742 effectNode->resetCommands();
750 QByteArray shaderPathKey(
"effect pipeline--");
755 if (
s->stage == stage) {
789 if (!shaderPathKey.isEmpty())
790 shaderPathKey.append(
'>');
791 shaderPathKey +=
"DEFAULT";
802 uniforms, builtinVertexInputs, builtinVertexOutputs);
805 uniforms, builtinVertexOutputs);
809 effectNode->requiresDepthTexture =
true;
824 effectNode->commands.push_back({
nullptr,
true });
829 effectNode->shaderPrepData.passes.
append(passData);
830 effectNode->shaderPrepData.valid =
true;
841 effectNode->commands.push_back({
new QSSGBindTarget(outputFormat),
true });
842 effectNode->outputFormat = outputFormat;
845 effectNode->commands.push_back({ outputBuffer->
getCommand(),
false });
847 effectNode->commands.push_back({
new QSSGBindBuffer(outBufferName),
true });
856 const auto &extraCommands = pass->m_commands;
857 for (
const auto &command : extraCommands) {
858 const int bufferCount = command->bufferCount();
859 for (
int i = 0;
i != bufferCount; ++
i)
860 effectNode->commands.push_back({ command->bufferAt(i)->getCommand(), false });
861 effectNode->commands.push_back({ command->getCommand(),
false });
864 effectNode->commands.push_back({
new QSSGRender,
true });
869 if (m_dirtyAttributes & Dirty::PropertyDirty) {
870 for (
const auto &prop :
std::as_const(effectNode->
properties)) {
873 prop.value =
p.read(
this);
877 m_dirtyAttributes = 0;
884void QQuick3DEffect::onPropertyDirty()
886 markDirty(Dirty::PropertyDirty);
889void QQuick3DEffect::onTextureDirty()
891 markDirty(Dirty::TextureDirty);
894void QQuick3DEffect::onPassDirty()
896 markDirty(Dirty::EffectChainDirty);
901 markDirty(Dirty::EffectChainDirty);
904void QQuick3DEffect::markDirty(QQuick3DEffect::Dirty
type)
915 for (
const auto &
it :
std::as_const(m_dynamicTextureMaps)) {
916 if (
auto tex =
it->texture())
920 for (
const auto &
it :
std::as_const(m_dynamicTextureMaps)) {
921 if (
auto tex =
it->texture())
929 if (change == QQuick3DObject::ItemSceneChange)
930 updateSceneManager(
value.sceneManager);
939 that->m_passes.push_back(pass);
948 return that->m_passes.at(
index);
954 return that->m_passes.size();
962 pass->disconnect(that);
964 that->m_passes.clear();
972 auto it = m_dynamicTextureMaps.
constFind(textureMap);
977 auto it = m_dynamicTextureMaps.
constFind(textureMap);
979 m_dynamicTextureMaps.
erase(
it);
981 m_dynamicTextureMaps.
insert(textureMap);
qsizetype indexOf(char c, qsizetype from=0) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
void push_back(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
QByteArray left(qsizetype len) const
Returns a byte array that contains the first len bytes of this byte array.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QByteArray mid(qsizetype index, qsizetype len=-1) const
Returns a byte array containing len bytes from this byte array, starting at position pos.
void push_back(parameter_type t)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
The QQmlContext class defines a context within a QML engine.
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
QQmlListProperty< QQuick3DShaderUtilsRenderPass > passes
static void qmlPassClear(QQmlListProperty< QQuick3DShaderUtilsRenderPass > *list)
static qsizetype qmlPassCount(QQmlListProperty< QQuick3DShaderUtilsRenderPass > *list)
QQuick3DEffect(QQuick3DObject *parent=nullptr)
\qmlproperty list Effect::passes Contains a list of render \l {Pass}{passes} implemented by the effec...
void itemChange(QQuick3DObject::ItemChange, const QQuick3DObject::ItemChangeData &) override
static void qmlAppendPass(QQmlListProperty< QQuick3DShaderUtilsRenderPass > *list, QQuick3DShaderUtilsRenderPass *pass)
QSSGRenderGraphObject * updateSpatialNode(QSSGRenderGraphObject *node) override
static QQuick3DShaderUtilsRenderPass * qmlPassAt(QQmlListProperty< QQuick3DShaderUtilsRenderPass > *list, qsizetype index)
QPointer< QQuick3DSceneManager > sceneManager
void refSceneManager(QQuick3DSceneManager &)
static QQuick3DObjectPrivate * get(QQuick3DObject *item)
\qmltype Object3D \inqmlmodule QtQuick3D \instantiates QQuick3DObject \inherits QtObject
virtual void markAllDirty()
QPointer< QQuick3DWindowAttachment > wattached
static QSSGRenderTextureFormat::Format mapTextureFormat(QQuick3DShaderUtilsBuffer::TextureFormat fmt)
QSSGCommand * getCommand()
QSSGRenderImage * getRenderImage()
TilingMode verticalTiling() const
\qmlproperty enumeration QtQuick3D::Texture::tilingModeVertical
TilingMode horizontalTiling() const
\qmlproperty enumeration QtQuick3D::Texture::tilingModeHorizontal
const std::shared_ptr< QSSGRenderContextInterface > & rci() const
const_iterator constEnd() const noexcept
iterator erase(const_iterator i)
const_iterator constFind(const T &value) const
iterator insert(const T &value)
QString first(qsizetype n) const
QMetaType metaType() const
QSet< QString >::iterator it
void ensureDebugObjectName(T *node, QObject *src)
\qmltype Shader \inherits Object \inqmlmodule QtQuick3D
QSSGRenderShaderDataType uniformType(QMetaType type)
QByteArray resolveShader(const QUrl &fileUrl, const QQmlContext *context, QByteArray &shaderPathKey)
QByteArray uniformTypeName(QMetaType type)
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
std::pair< T1, T2 > QPair
static const QCssKnownValue properties[NumProperties - 1]
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLenum GLuint GLsizei propCount
QQmlContext * qmlContext(const QObject *obj)
static const char * default_effect_fragment_shader
static void insertVertexMainArgs(QByteArray &snippet)
static const char * default_effect_vertex_shader
obj metaObject() -> className()
QByteArray shaderPathKeyPrefix
QByteArray vertexShaderCode
QSSGCustomShaderMetaData vertexMetaData
QSSGCustomShaderMetaData fragmentMetaData
QByteArray fragmentShaderCode
QSSGRenderTextureCoordOp horizontalClampType
QSSGRenderTextureCoordOp verticalClampType
QSSGRenderShaderDataType shaderDataType
QSSGRenderImage * texImage
QSSGRenderTextureFilterOp magFilterType
QSSGRenderTextureFilterOp minFilterType
QSSGRenderTextureFilterOp mipFilterType
QVector< Property > properties
QVector< TextureProperty > textureProperties
bool incompleteBuildTimeObject
static ShaderCodeAndMetaData prepareCustomShader(QByteArray &dst, const QByteArray &shaderCode, QSSGShaderCache::ShaderType type, const StringPairList &baseUniforms, const StringPairList &baseInputs=StringPairList(), const StringPairList &baseOutputs=StringPairList())
QPair< QByteArray, QSSGCustomShaderMetaData > ShaderCodeAndMetaData
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent