diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,10 +24,15 @@ scenepositionattached.cpp mnemonicattached.cpp wheelhandler.cpp + elevatedrectangle.cpp + scenegraph/elevatedrectanglenode.cpp + scenegraph/elevatedrectanglematerial.cpp ${kirigami_QM_LOADER} ${KIRIGAMI_STATIC_FILES} ) +qt5_add_resources(SHADERS scenegraph/shaders.qrc) + add_subdirectory(libkirigami) if(STATIC_LIBRARY) @@ -55,7 +60,7 @@ endif(STATIC_LIBRARY) -add_library(kirigamiplugin ${kirigami_SRCS} ${RESOURCES}) +add_library(kirigamiplugin ${kirigami_SRCS} ${RESOURCES} ${SHADERS}) if(STATIC_LIBRARY) SET_TARGET_PROPERTIES(kirigamiplugin PROPERTIES diff --git a/src/elevatedrectangle.h b/src/elevatedrectangle.h new file mode 100644 --- /dev/null +++ b/src/elevatedrectangle.h @@ -0,0 +1,73 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef ELEVATEDRECTANGLE_H +#define ELEVATEDRECTANGLE_H + +#include +#include + +class ElevatedRectangle : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(qreal elevation READ elevation WRITE setElevation NOTIFY elevationChanged) + Q_PROPERTY(qreal radius READ radius WRITE setRadius NOTIFY radiusChanged) + Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY xOffsetChanged) + Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY yOffsetChanged) + Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) + Q_PROPERTY(QColor shadowColor READ shadowColor WRITE setShadowColor NOTIFY shadowColorChanged) + +public: + ElevatedRectangle(QQuickItem *parent = nullptr); + ~ElevatedRectangle() override; + + qreal elevation() const; + void setElevation(qreal newElevation); + Q_SIGNAL void elevationChanged(); + + qreal radius() const; + void setRadius(qreal newRadius); + Q_SIGNAL void radiusChanged(); + + qreal xOffset() const; + void setXOffset(qreal newXOffset); + Q_SIGNAL void xOffsetChanged(); + + qreal yOffset() const; + void setYOffset(qreal newYOffset); + Q_SIGNAL void yOffsetChanged(); + + QColor color() const; + void setColor(const QColor &newColor); + Q_SIGNAL void colorChanged(); + + QColor shadowColor() const; + void setShadowColor(const QColor &newShadowColor); + Q_SIGNAL void shadowColorChanged(); + +protected: + QSGNode *updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *data) override; + +private: + class Private; + const std::unique_ptr d; +}; + +#endif // ELEVATEDRECTANGLE_H diff --git a/src/elevatedrectangle.cpp b/src/elevatedrectangle.cpp new file mode 100644 --- /dev/null +++ b/src/elevatedrectangle.cpp @@ -0,0 +1,161 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "elevatedrectangle.h" + +#include "scenegraph/elevatedrectanglenode.h" + +class ElevatedRectangle::Private +{ +public: + qreal elevation = 0.0; + qreal radius = 0.0; + qreal xOffset = 0.0; + qreal yOffset = 0.0; + QColor color = Qt::white; + QColor shadowColor = Qt::black; +}; + +ElevatedRectangle::ElevatedRectangle(QQuickItem *parentItem) + : QQuickItem(parentItem), d(new Private) +{ + setFlag(QQuickItem::ItemHasContents, true); +} + +ElevatedRectangle::~ElevatedRectangle() +{ +} + +qreal ElevatedRectangle::elevation() const +{ + return d->elevation; +} + +void ElevatedRectangle::setElevation(qreal newElevation) +{ + if (newElevation == d->elevation) { + return; + } + + d->elevation = newElevation; + update(); + Q_EMIT elevationChanged(); +} + +qreal ElevatedRectangle::radius() const +{ + return d->radius; +} + +void ElevatedRectangle::setRadius(qreal newRadius) +{ + newRadius = std::min(newRadius, std::min(width(), height())); + + if (newRadius == d->radius) { + return; + } + + d->radius = newRadius; + update(); + Q_EMIT radiusChanged(); +} + +qreal ElevatedRectangle::xOffset() const +{ + return d->xOffset; +} + +void ElevatedRectangle::setXOffset(qreal newXOffset) +{ + if (newXOffset == d->xOffset) { + return; + } + + d->xOffset = newXOffset; + update(); + Q_EMIT xOffsetChanged(); +} + +qreal ElevatedRectangle::yOffset() const +{ + return d->yOffset; +} + +void ElevatedRectangle::setYOffset(qreal newYOffset) +{ + if (newYOffset == d->yOffset) { + return; + } + + d->yOffset = newYOffset; + update(); + Q_EMIT yOffsetChanged(); +} + +QColor ElevatedRectangle::color() const +{ + return d->color; +} + +void ElevatedRectangle::setColor(const QColor & newColor) +{ + if (newColor == d->color) { + return; + } + + d->color = newColor; + update(); + Q_EMIT colorChanged(); +} + +QColor ElevatedRectangle::shadowColor() const +{ + return d->shadowColor; +} + +void ElevatedRectangle::setShadowColor(const QColor &newShadowColor) +{ + if (newShadowColor == d->shadowColor) { + return; + } + + d->shadowColor = newShadowColor; + update(); + Q_EMIT shadowColorChanged(); +} + +QSGNode *ElevatedRectangle::updatePaintNode(QSGNode *node, QQuickItem::UpdatePaintNodeData *data) +{ + Q_UNUSED(data); + + if (!node) { + node = new ElevatedRectangleNode; + } + + auto elevatedNode = static_cast(node); + elevatedNode->setRect(boundingRect().adjusted(-d->elevation, -d->elevation, d->elevation, d->elevation)); + elevatedNode->setElevation(d->elevation); + elevatedNode->setRadius(d->radius); + elevatedNode->setOffset(QVector2D{float(d->xOffset), float(d->yOffset)}); + elevatedNode->setColor(d->color); + elevatedNode->setShadowColor(d->shadowColor); + + return elevatedNode; +} diff --git a/src/kirigamiplugin.cpp b/src/kirigamiplugin.cpp --- a/src/kirigamiplugin.cpp +++ b/src/kirigamiplugin.cpp @@ -17,6 +17,7 @@ #include "pagepool.h" #include "scenepositionattached.h" #include "wheelhandler.h" +#include "elevatedrectangle.h" #include #include @@ -235,6 +236,9 @@ //TODO: remove qmlRegisterType(componentUrl(QStringLiteral("SwipeListItem2.qml")), uri, 2, 11, "SwipeListItem2"); + // 2.12 + qmlRegisterType(uri, 2, 12, "ElevatedRectangle"); + qmlProtectModule(uri, 2); } diff --git a/src/scenegraph/elevatedrectangle.frag b/src/scenegraph/elevatedrectangle.frag new file mode 100644 --- /dev/null +++ b/src/scenegraph/elevatedrectangle.frag @@ -0,0 +1,58 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +uniform lowp float opacity; +uniform lowp float elevation; +uniform lowp float radius; +uniform lowp vec4 color; +uniform lowp vec4 shadowColor; +uniform lowp vec2 offset; +uniform lowp vec2 aspect; + +varying lowp vec2 uv; + +lowp float sdf_rectangle(in lowp vec2 point, in lowp vec2 rect, in lowp vec2 translation, in lowp float radius) +{ + lowp vec2 d = abs(point - translation) - rect; + return (length(max(d, vec2(0.0))) + min(max(d.x, d.y), 0.0)) - radius; +} + +lowp vec4 sdf_render(in lowp float sdf, in lowp vec4 sourceColor, in lowp vec4 sdfColor, in lowp float smoothing) +{ + lowp float g = fwidth(sdf); + return mix(sourceColor, sdfColor, sdfColor.a * (1.0 - smoothstep(smoothing - g, smoothing + g, sdf))); +} + +void main() +{ + lowp float shadowRadius = radius + elevation * (0.25 * (0.1 / max(radius, 0.1))); + lowp vec2 aspectOffset = aspect - vec2(1.0); + + lowp vec4 col = vec4(0.0); + if (elevation > 0.0) { + lowp float shadow = sdf_rectangle(uv, aspect - shadowRadius - elevation, aspectOffset + offset / 2.0, shadowRadius); + col = mix(col, shadowColor, 1.0 - smoothstep(-elevation * 0.5, elevation * 0.5, shadow)); + } + + lowp float rect = sdf_rectangle(uv, aspect - radius - elevation, aspectOffset - offset / 2.0, radius); + col = sdf_render(rect, col, color, 0.001); + + gl_FragColor = col; +} + diff --git a/src/scenegraph/elevatedrectangle.vert b/src/scenegraph/elevatedrectangle.vert new file mode 100644 --- /dev/null +++ b/src/scenegraph/elevatedrectangle.vert @@ -0,0 +1,34 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +uniform highp mat4 matrix; +uniform lowp vec2 aspect; +uniform lowp vec2 offset; + +attribute highp vec4 in_vertex; +attribute mediump vec2 in_uv; + +varying mediump vec2 uv; + +void main() { + lowp vec2 topLeft = vec2(-1.0) - abs(offset) / 2.0; + lowp vec2 bottomRight = vec2(1.0) + abs(offset) / 2.0; + uv = topLeft + (bottomRight - topLeft) * in_uv * aspect; + gl_Position = matrix * in_vertex; +} diff --git a/src/scenegraph/elevatedrectanglematerial.h b/src/scenegraph/elevatedrectanglematerial.h new file mode 100644 --- /dev/null +++ b/src/scenegraph/elevatedrectanglematerial.h @@ -0,0 +1,65 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + */ + +#ifndef ELEVATEDRECTANGLEMATERIAL_H +#define ELEVATEDRECTANGLEMATERIAL_H + +#include +#include + +class ElevatedRectangleMaterial : public QSGMaterial +{ +public: + ElevatedRectangleMaterial(); + + QSGMaterialShader* createShader() const override; + QSGMaterialType* type() const override; + int compare(const QSGMaterial* other) const override; + + QVector2D aspect = QVector2D{1.0, 1.0}; + float elevation = 0.0; + float radius = 0.0; + QColor color = Qt::white; + QColor shadowColor = Qt::black; + QVector2D offset; +}; + +class ElevatedRectangleShader : public QSGMaterialShader +{ +public: + ElevatedRectangleShader(); + + char const *const *attributeNames() const override; + + void initialize() override; + void updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; + +private: + int m_matrixLocation = -1; + int m_opacityLocation = -1; + int m_aspectLocation = -1; + int m_elevationLocation = -1; + int m_radiusLocation = -1; + int m_colorLocation = -1; + int m_shadowColorLocation = -1; + int m_offsetLocation = -1; +}; + +#endif // ELEVATEDRECTANGLEMATERIAL_H diff --git a/src/scenegraph/elevatedrectanglematerial.cpp b/src/scenegraph/elevatedrectanglematerial.cpp new file mode 100644 --- /dev/null +++ b/src/scenegraph/elevatedrectanglematerial.cpp @@ -0,0 +1,111 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + */ + +#include "elevatedrectanglematerial.h" + +#include + +ElevatedRectangleMaterial::ElevatedRectangleMaterial() +{ + setFlag(QSGMaterial::Blending, true); +} + +QSGMaterialShader* ElevatedRectangleMaterial::createShader() const +{ + return new ElevatedRectangleShader{}; +} + +QSGMaterialType* ElevatedRectangleMaterial::type() const +{ + static QSGMaterialType type; + return &type; +} + +int ElevatedRectangleMaterial::compare(const QSGMaterial *other) const +{ + auto material = static_cast(other); + + if (material->color == color + && qFuzzyCompare(material->elevation, elevation) + && qFuzzyCompare(material->radius, radius)) { + return 0; + } + + return QSGMaterial::compare(other); +} + +ElevatedRectangleShader::ElevatedRectangleShader() +{ + auto header = QOpenGLContext::currentContext()->isOpenGLES() ? QStringLiteral("header_es.glsl") : QStringLiteral("header_desktop.glsl"); + + auto shaderRoot = QStringLiteral(":/org/kde/kirigami/shaders/"); + + setShaderSourceFiles(QOpenGLShader::Vertex, { + shaderRoot + header, + shaderRoot + QStringLiteral("elevatedrectangle.vert") + }); + + setShaderSourceFiles(QOpenGLShader::Fragment, { + shaderRoot + header, + shaderRoot + QStringLiteral("elevatedrectangle.frag") + }); +} + +const char *const * ElevatedRectangleShader::attributeNames() const +{ + static char const *const names[] = {"in_vertex", "in_uv", nullptr}; + return names; +} + +void ElevatedRectangleShader::initialize() +{ + QSGMaterialShader::initialize(); + m_matrixLocation = program()->uniformLocation("matrix"); + m_aspectLocation = program()->uniformLocation("aspect"); + m_opacityLocation = program()->uniformLocation("opacity"); + m_elevationLocation = program()->uniformLocation("elevation"); + m_radiusLocation = program()->uniformLocation("radius"); + m_colorLocation = program()->uniformLocation("color"); + m_shadowColorLocation = program()->uniformLocation("shadowColor"); + m_offsetLocation = program()->uniformLocation("offset"); +} + +void ElevatedRectangleShader::updateState(const QSGMaterialShader::RenderState& state, QSGMaterial* newMaterial, QSGMaterial* oldMaterial) +{ + auto p = program(); + + if (state.isMatrixDirty()) { + p->setUniformValue(m_matrixLocation, state.combinedMatrix()); + } + + if (state.isOpacityDirty()) { + p->setUniformValue(m_opacityLocation, state.opacity()); + } + + if (!oldMaterial || newMaterial->compare(oldMaterial) != 0 || state.isCachedMaterialDataDirty()) { + auto material = static_cast(newMaterial); + p->setUniformValue(m_aspectLocation, material->aspect); + p->setUniformValue(m_elevationLocation, material->elevation); + p->setUniformValue(m_radiusLocation, material->radius); + p->setUniformValue(m_colorLocation, material->color); + p->setUniformValue(m_shadowColorLocation, material->shadowColor); + p->setUniformValue(m_offsetLocation, material->offset); + } +} diff --git a/src/scenegraph/elevatedrectanglenode.h b/src/scenegraph/elevatedrectanglenode.h new file mode 100644 --- /dev/null +++ b/src/scenegraph/elevatedrectanglenode.h @@ -0,0 +1,54 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + */ + +#ifndef ELEVATEDRECTANGLENODE_H +#define ELEVATEDRECTANGLENODE_H + +#include +#include +#include + +class ElevatedRectangleMaterial; + +class ElevatedRectangleNode : public QSGGeometryNode +{ +public: + ElevatedRectangleNode(const QRectF &rect = QRectF{}); + + void setRect(const QRectF &rect); + void setElevation(qreal elevation); + void setRadius(qreal radius); + void setColor(const QColor &color); + void setShadowColor(const QColor &color); + void setOffset(const QVector2D &offset); + +private: + void updateGeometry(); + + QSGGeometry *m_geometry; + ElevatedRectangleMaterial *m_material; + + QRectF m_rect; + qreal m_elevation = 0.0; + qreal m_radius = 0.0; + QVector2D m_offset; +}; + +#endif // ELEVATEDRECTANGLENODE_H diff --git a/src/scenegraph/elevatedrectanglenode.cpp b/src/scenegraph/elevatedrectanglenode.cpp new file mode 100644 --- /dev/null +++ b/src/scenegraph/elevatedrectanglenode.cpp @@ -0,0 +1,137 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + */ + +#include "elevatedrectanglenode.h" + +#include "elevatedrectanglematerial.h" + +#include + +ElevatedRectangleNode::ElevatedRectangleNode(const QRectF& rect) +{ + m_geometry = new QSGGeometry{QSGGeometry::defaultAttributes_TexturedPoint2D(), 4}; + setGeometry(m_geometry); + setRect(rect); + + m_material = new ElevatedRectangleMaterial{}; + setMaterial(m_material); + + setFlags(QSGNode::OwnsGeometry | QSGNode::OwnsMaterial); +} + +void ElevatedRectangleNode::setRect(const QRectF& rect) +{ + if (rect == m_rect) { + return; + } + + m_rect = rect; + + QVector2D newAspect{1.0, 1.0}; + if (m_rect.width() >= m_rect.height()) { + newAspect.setX(m_rect.width() / m_rect.height()); + } else { + newAspect.setY(m_rect.height() / m_rect.width()); + } + if (m_material->aspect != newAspect) { + qDebug() << newAspect; + m_material->aspect = newAspect; + markDirty(QSGNode::DirtyMaterial); + } + + updateGeometry(); +} + +void ElevatedRectangleNode::setElevation(qreal elevation) +{ + auto minDimension = std::min(m_rect.width(), m_rect.height()); + float uniformElevation = (elevation / minDimension) * 2.0; + + if (!qFuzzyCompare(m_material->elevation, uniformElevation)) { + m_material->elevation = uniformElevation; + markDirty(QSGNode::DirtyMaterial); + m_elevation = elevation; + updateGeometry(); + } +} + +void ElevatedRectangleNode::setRadius(qreal radius) +{ + auto minDimension = std::min(m_rect.width(), m_rect.height()); + float uniformRadius = radius * 2.0 / minDimension; + + if (!qFuzzyCompare(m_material->radius, uniformRadius)) { + m_material->radius = uniformRadius; + markDirty(QSGNode::DirtyMaterial); + m_radius = radius; + } +} + +void ElevatedRectangleNode::setColor(const QColor &color) +{ + if (m_material->color != color) { + m_material->color = color; + markDirty(QSGNode::DirtyMaterial); + } +} + +void ElevatedRectangleNode::setShadowColor(const QColor& color) +{ + if (m_material->shadowColor != color) { + m_material->shadowColor = color; + markDirty(QSGNode::DirtyMaterial); + } +} + +void ElevatedRectangleNode::setOffset(const QVector2D& offset) +{ + auto minDimension = std::min(m_rect.width(), m_rect.height()); + auto uniformOffset = offset * 2.0 / minDimension; + + if (m_material->offset != uniformOffset) { + m_material->offset = uniformOffset; + markDirty(QSGNode::DirtyMaterial); + m_offset = offset; + updateGeometry(); + } +} + +void ElevatedRectangleNode::updateGeometry() +{ +// auto rect = m_rect.adjusted(-m_elevation, -m_elevation, m_elevation, m_elevation); + auto rect = m_rect; + + if (m_offset.x() < 0.0f) { + rect.setLeft(rect.left() + m_offset.x()); + } else { + rect.setRight(rect.right() + m_offset.x()); + } + + if (m_offset.y() < 0.0f) { + rect.setTop(rect.top() + m_offset.y()); + } else { + rect.setBottom(rect.bottom() + m_offset.y()); + } + + QSGGeometry::updateTexturedRectGeometry(m_geometry, rect, QRectF{0, 0, 1, 1}); + markDirty(QSGNode::DirtyGeometry); +} + + diff --git a/src/scenegraph/header_desktop.glsl b/src/scenegraph/header_desktop.glsl new file mode 100644 --- /dev/null +++ b/src/scenegraph/header_desktop.glsl @@ -0,0 +1,39 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +// This file contains common directives needed for the shaders to work. +// It is included as the very first bit in the shader. +// Important: If a specific GLSL version is needed, it should be set in this +// file. + +// This file is intended for desktop OpenGL version 2.1 or greater. + +#version 120 + +#ifndef lowp + #define lowp +#endif + +#ifndef mediump + #define mediump +#endif + +#ifndef highp + #define highp mediump +#endif diff --git a/src/scenegraph/header_desktop_core.glsl b/src/scenegraph/header_desktop_core.glsl new file mode 100644 --- /dev/null +++ b/src/scenegraph/header_desktop_core.glsl @@ -0,0 +1,27 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +// This file contains common directives needed for the shaders to work. +// It is included as the very first bit in the shader. +// Important: If a specific GLSL version is needed, it should be set in this +// file. + +// This file is intended for desktop OpenGL version 4.5 or greater. + +#version 450 diff --git a/src/scenegraph/header_es.glsl b/src/scenegraph/header_es.glsl new file mode 100644 --- /dev/null +++ b/src/scenegraph/header_es.glsl @@ -0,0 +1,29 @@ +/* + * Copyright 2020 Arjen Hiemstra + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +// This file contains common directives needed for the shaders to work. +// It is included as the very first bit in the shader. +// Important: If a specific GLSL version is needed, it should be set in this +// file. + +// This file is intended for OpenGLES version 2.0 or greater. + +#version 100 +#extension GL_OES_standard_derivatives : enable + diff --git a/src/scenegraph/shaders.qrc b/src/scenegraph/shaders.qrc new file mode 100644 --- /dev/null +++ b/src/scenegraph/shaders.qrc @@ -0,0 +1,11 @@ + + + + header_es.glsl + header_desktop.glsl + header_desktop_core.glsl + elevatedrectangle.vert + elevatedrectangle.frag + + +