4#include <private/qquickshadereffect_p_p.h>
5#include <private/qsgcontextplugin_p.h>
6#include <private/qsgrhisupport_p.h>
7#include <private/qquickwindow_p.h>
540 d->inDestructor =
true;
559 return d->fragmentShader();
565 d->setFragmentShader(fileUrl);
584 return d->vertexShader();
590 d->setVertexShader(fileUrl);
605 return d->blending();
654 return d->cullMode();
660 return d->setCullMode(
face);
687 return d->supportsAtlasTextures();
693 d->setSupportsAtlasTextures(supports);
759 d->handleGeometryChanged(newGeometry, oldGeometry);
766 return d->handleUpdatePaintNode(oldNode, updatePaintNodeData);
772 d->maybeUpdateShaders();
779 d->handleItemChange(change,
value);
795 return d->updateUniformValue(
name,
value, node);
808 return idx | (shaderType << 16);
813 return mappedId & 0xFFFF;
818 return mappedId >> 16;
822 : m_meshResolution(1, 1)
826 , m_supportsAtlasTextures(
false)
828 , m_fragNeedsUpdate(true)
829 , m_vertNeedsUpdate(true)
831 qRegisterMetaType<QSGGuiThreadShaderEffectManager::ShaderInfo::Type>(
"ShaderInfo::Type");
832 for (
int i = 0;
i < NShader; ++
i)
833 m_inProgress[
i] =
nullptr;
838 for (
int i = 0;
i < NShader; ++
i) {
839 disconnectSignals(Shader(
i));
840 clearMappers(Shader(
i));
849 if (m_fragShader == fileUrl)
852 m_fragShader = fileUrl;
854 m_fragNeedsUpdate =
true;
855 if (
q->isComponentComplete())
858 emit q->fragmentShaderChanged();
864 if (m_vertShader == fileUrl)
867 m_vertShader = fileUrl;
869 m_vertNeedsUpdate =
true;
870 if (
q->isComponentComplete())
873 emit q->vertexShaderChanged();
884 emit q->blendingChanged();
897 if (newMesh && newMesh == m_mesh)
913 bool ok =
res.size() == 2;
915 int w =
res.at(0).toInt(&
ok);
917 int h =
res.at(1).toInt(&
ok);
919 m_meshResolution =
QSize(
w,
h);
923 qWarning(
"ShaderEffect: mesh property must be a size or an object deriving from QQuickShaderEffectMesh");
931 emit q->meshChanged();
937 if (m_cullMode ==
face)
942 emit q->cullModeChanged();
948 if (m_supportsAtlasTextures == supports)
951 m_supportsAtlasTextures = supports;
953 emit q->supportsAtlasTexturesChanged();
984 const auto mappedId = findMappedShaderVariableId(propertyName);
1000 if (
q->width() <= 0 ||
q->height() <= 0) {
1006 if (m_inProgress[
Vertex] || m_inProgress[Fragment])
1053 geometry =
mesh->updateGeometry(geometry, 2, 0, srcRect,
rect);
1063 for (
int i = 0;
i < NShader; ++
i) {
1064 m_dirtyConstants[
i].
clear();
1065 m_dirtyTextures[
i].
clear();
1074 if (m_vertNeedsUpdate)
1075 m_vertNeedsUpdate = !updateShader(
Vertex, m_vertShader);
1076 if (m_fragNeedsUpdate)
1077 m_fragNeedsUpdate = !updateShader(Fragment, m_fragShader);
1078 if (m_vertNeedsUpdate || m_fragNeedsUpdate) {
1085 if (!
q->window() || !
q->window()->isSceneGraphInitialized())
1094 const auto mappedId = findMappedShaderVariableId(
name);
1133 for (
int shaderType = 0; shaderType < NShader; ++shaderType) {
1134 for (
const auto &vd : std::as_const(m_shaders[shaderType].varData)) {
1172void QQuickShaderEffectPrivate::disconnectSignals(Shader shaderType)
1175 for (
auto *
mapper : m_mappers[shaderType]) {
1180 for (
const auto &vd :
std::as_const(m_shaders[shaderType].varData)) {
1187 if (
it != m_destroyedConnections.
constEnd()) {
1189 m_destroyedConnections.
erase(
it);
1196void QQuickShaderEffectPrivate::clearMappers(QQuickShaderEffectPrivate::Shader shaderType)
1198 for (
auto *
mapper :
std::as_const(m_mappers[shaderType])) {
1200 mapper->destroyIfLastRef();
1202 m_mappers[shaderType].clear();
1209 if (propertyIndex == -1) {
1222 shaderInfoCache()->clear();
1225bool QQuickShaderEffectPrivate::updateShader(Shader shaderType,
const QUrl &fileUrl)
1234 disconnectSignals(shaderType);
1237 m_shaders[shaderType].
varData.clear();
1243 if (
it != shaderInfoCache()->
cend()) {
1265 if (shaderType == Fragment) {
1280 updateShaderVars(shaderType);
1294 if (
result != m_inProgress[shaderType]) {
1301 m_inProgress[shaderType] =
nullptr;
1304 qWarning(
"ShaderEffect: shader preparation failed for %s\n%s\n",
1311 shaderInfoCache()->insert(loadUrl, m_shaders[shaderType].shaderInfo);
1312 updateShaderVars(shaderType);
1317void QQuickShaderEffectPrivate::updateShaderVars(Shader shaderType)
1327 m_shaders[shaderType].
varData.resize(varCount);
1330 clearMappers(shaderType);
1334 if (!m_itemMetaObject)
1335 m_itemMetaObject =
q->metaObject();
1339 for (
int i = 0;
i < varCount; ++
i) {
1340 const auto &
v(m_shaders[shaderType].shaderInfo.variables.at(
i));
1342 const bool isSpecial =
v.name.startsWith(
"qt_");
1344 if (
v.name ==
"qt_Opacity")
1346 else if (
v.name ==
"qt_Matrix")
1348 else if (
v.name.startsWith(
"qt_SubRect_"))
1357 if (texturesSeparate) {
1374 pd = propCache->property(
QLatin1String(
v.name),
nullptr,
nullptr);
1383 qWarning(
"QQuickShaderEffect: property '%s' does not have notification method!",
v.name.constData());
1389 m_mappers[shaderType].append(
mapper);
1391 Q_ASSERT(
q->metaObject() == m_itemMetaObject);
1396 <<
"(" << propIdx <<
", signal index" << pd->
notifyIndex()
1397 <<
") of item" <<
q;
1402 if (!
q->property(
v.name.constData()).isValid())
1403 qWarning(
"ShaderEffect: '%s' does not have a matching property",
v.name.constData());
1407 vd.propertyIndex = propIdx;
1428std::optional<int> QQuickShaderEffectPrivate::findMappedShaderVariableId(
const QByteArray &
name)
const
1430 for (
int shaderType = 0; shaderType < NShader; ++shaderType) {
1432 for (
int idx = 0; idx < vars.size(); ++idx) {
1441bool QQuickShaderEffectPrivate::sourceIsUnique(
QQuickItem *
source, Shader typeToSkip,
int indexToSkip)
const
1443 for (
int shaderType = 0; shaderType < NShader; ++shaderType) {
1444 for (
int idx = 0; idx < m_shaders[shaderType].
varData.size(); ++idx) {
1445 if (shaderType != typeToSkip || idx != indexToSkip) {
1446 const auto &vd(m_shaders[shaderType].varData[idx]);
1460 const auto &
v(m_shaders[
type].shaderInfo.variables[idx]);
1461 auto &vd(m_shaders[
type].varData[idx]);
1476 if (
it != m_destroyedConnections.
constEnd()) {
1478 m_destroyedConnections.
erase(
it);
1508 for (
int shaderType = 0; shaderType < NShader; ++shaderType) {
1509 for (
auto &vd : m_shaders[shaderType].
varData) {
1511 if (qvariant_cast<QObject *>(vd.value) ==
object)
1527 if (m_supportsAtlasTextures)
1533#include "moc_qquickshadereffect_p.cpp"
QList< QByteArray > split(char sep) const
Splits the byte array into subarrays wherever sep occurs, and returns the list of those arrays.
const_iterator constFind(const Key &key) const noexcept
const_iterator constEnd() const noexcept
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the ...
iterator erase(const_iterator it)
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
static QMetaObject::Connection connectImpl(const QObject *sender, int signal_index, const QObject *receiver, void **slot, QtPrivate::QSlotObjectBase *slotObj, int type, const int *types, const QMetaObject *senderMetaObject)
static bool disconnect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
QThread * thread() const
Returns the thread in which the object lives.
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.
static QQmlPropertyCache::ConstPtr ensurePropertyCache(QObject *object)
void setResolution(const QSize &res)
\qmlproperty size QtQuick::GridMesh::resolution
void refWindow(QQuickWindow *)
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
bool event(QEvent *) override
\reimp
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
void maybeUpdateShaders()
void updatePolish() override
QQuickShaderEffectPrivate()
void setVertexShader(const QUrl &fileUrl)
void propertyChanged(int mappedId)
void shaderCodePrepared(bool ok, QSGGuiThreadShaderEffectManager::ShaderInfo::Type typeHint, const QUrl &loadUrl, QSGGuiThreadShaderEffectManager::ShaderInfo *result)
void markGeometryDirtyAndUpdate()
~QQuickShaderEffectPrivate()
void setBlending(bool enable)
void handleEvent(QEvent *)
QSGNode * handleUpdatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *)
void setMesh(const QVariant &mesh)
void setSupportsAtlasTextures(bool supports)
bool updateUniformValue(const QByteArray &name, const QVariant &value, QSGShaderEffectNode *node)
QQuickShaderEffect::Status status() const
void setFragmentShader(const QUrl &fileUrl)
void setCullMode(QQuickShaderEffect::CullMode face)
void handleGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
void sourceDestroyed(QObject *object)
void markGeometryDirtyAndUpdateIfSupportsAtlas()
void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
void setBlending(bool enable)
void setFragmentShader(const QUrl &fileUrl)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
void setCullMode(CullMode face)
void setVertexShader(const QUrl &fileUrl)
bool event(QEvent *e) override
\reimp
void setMesh(const QVariant &mesh)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
~QQuickShaderEffect() override
bool supportsAtlasTextures
QQuickShaderEffect(QQuickItem *parent=nullptr)
bool updateUniformValue(const QByteArray &name, const QVariant &value)
void setSupportsAtlasTextures(bool supports)
QSGNode * updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData) override
Called on the render thread when it is time to sync the state of the item with the scene graph.
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
bool isComponentComplete() const
static QQuickWindowPrivate * get(QQuickWindow *c)
QSGRenderContext * context
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
\inmodule QtCore\reentrant
const QSGGeometry * geometry() const
Returns this node's geometry.
void setGeometry(QSGGeometry *geometry)
Sets the geometry of this node to geometry.
virtual QSGShaderEffectNode * createShaderEffectNode(QSGRenderContext *renderContext)
Creates a new shader effect node.
virtual QSGGuiThreadShaderEffectManager * createGuiThreadShaderEffectManager()
Creates a new shader effect helper instance.
The QSGGeometry class provides low-level storage for graphics primitives in the \l{Qt Quick Scene Gra...
virtual Status status() const =0
void shaderCodePrepared(bool ok, ShaderInfo::Type typeHint, const QUrl &src, ShaderInfo *result)
virtual bool hasSeparateSamplerAndTextureObjects() const =0
virtual QString log() const =0
virtual void prepareShaderCode(ShaderInfo::Type typeHint, const QUrl &src, ShaderInfo *result)=0
void logAndStatusChanged()
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
void setFlag(Flag, bool=true)
Sets the flag f on this node if enabled is true; otherwise clears the flag.
QSGContext * sceneGraphContext() const
virtual QRectF updateNormalizedTextureSubRect(bool supportsAtlasTextures)=0
virtual void syncMaterial(SyncData *syncData)=0
const_iterator constFind(const T &value) const
iterator insert(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QThread * currentThread()
bool isEmpty() const
Returns true if the URL has no data; otherwise returns false.
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
QSize toSize() const
Returns the variant as a QSize if the variant has userType() \l QMetaType::QSize; otherwise returns a...
bool canConvert(QMetaType targetType) const
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has userType() \l QMetaType::QByteArray or \l QMet...
std::function< void()> PropChangedFunc
void setSignalIndex(int idx)
EffectSlotMapper(PropChangedFunc func)
QSet< QString >::iterator it
const PluginKeyMapConstIterator cend
Combined button and popup list for selecting options.
#define QByteArrayLiteral(str)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
GLsizei const GLfloat * v
[13]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
GLdouble GLdouble GLdouble GLdouble q
QQmlEngine * qmlEngine(const QObject *obj)
QQmlContext * qmlContext(const QObject *obj)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
constexpr int mappedIdToShaderType(const int mappedId)
constexpr int mappedIdToIndex(const int mappedId)
static QVariant getValueFromProperty(QObject *item, const QMetaObject *itemMetaObject, const QByteArray &name, int propertyIndex)
void qtquick_shadereffect_purge_gui_thread_shader_cache()
constexpr int indexToMappedId(const int shaderType, const int idx)
#define qPrintable(string)
QLatin1StringView QLatin1String
QVector< Variable > variables
QVector< VariableData > varData
QSGGuiThreadShaderEffectManager::ShaderInfo shaderInfo
const QSet< int > * dirtyTextures
const ShaderData * shader
const QSet< int > * dirtyConstants
void * materialTypeCacheKey
\qmltype MapCircle \instantiates QDeclarativeCircleMapItem \inqmlmodule QtLocation
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent