diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-11 14:51:40 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-11 17:24:39 +0200 |
commit | 13374ceb165c44658aa97890c37b206859c9a31c (patch) | |
tree | 562362b196a459ee3449a5a1e60e5216a9dd6984 /src/quick/scenegraph/qsgdefaultinternalimagenode.cpp | |
parent | ae47deba4c943c496412530a8d2a5a688ae12038 (diff) | |
parent | b5d18be5a03406d0aac83856dd41e1525fd14a28 (diff) |
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Change-Id: I2963c1209316fb6755f572969f368970450d7991
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultinternalimagenode.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgdefaultinternalimagenode.cpp | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp index 5dd6eaa4ca..d1711f7524 100644 --- a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp +++ b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp @@ -38,10 +38,12 @@ ****************************************************************************/ #include "qsgdefaultinternalimagenode_p.h" +#include <private/qsgdefaultrendercontext_p.h> #include <private/qsgmaterialshader_p.h> #include <private/qsgtexturematerial_p.h> #include <QtGui/qopenglfunctions.h> #include <QtCore/qmath.h> +#include <QtGui/private/qrhi_p.h> QT_BEGIN_NAMESPACE @@ -59,9 +61,18 @@ protected: int m_pixelSizeLoc; }; +class SmoothTextureMaterialRhiShader : public QSGTextureMaterialRhiShader +{ +public: + SmoothTextureMaterialRhiShader(); + + bool updateUniformData(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; +}; + QSGSmoothTextureMaterial::QSGSmoothTextureMaterial() { + setFlag(SupportsRhiShader, true); setFlag(RequiresFullMatrixExceptTranslate, true); setFlag(Blending, true); } @@ -79,7 +90,10 @@ QSGMaterialType *QSGSmoothTextureMaterial::type() const QSGMaterialShader *QSGSmoothTextureMaterial::createShader() const { - return new SmoothTextureMaterialShader; + if (flags().testFlag(RhiShaderWanted)) + return new SmoothTextureMaterialRhiShader; + else + return new SmoothTextureMaterialShader; } SmoothTextureMaterialShader::SmoothTextureMaterialShader() @@ -116,7 +130,33 @@ void SmoothTextureMaterialShader::initialize() QSGTextureMaterialShader::initialize(); } -QSGDefaultInternalImageNode::QSGDefaultInternalImageNode() +SmoothTextureMaterialRhiShader::SmoothTextureMaterialRhiShader() +{ + setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothtexture.vert.qsb")); + setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/smoothtexture.frag.qsb")); +} + +bool SmoothTextureMaterialRhiShader::updateUniformData(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) +{ + bool changed = false; + QByteArray *buf = state.uniformData(); + + if (!oldMaterial) { + // The viewport is constant, so set the pixel size uniform only once (per batches with the same material). + const QRect r = state.viewportRect(); + const QVector2D v(2.0f / r.width(), 2.0f / r.height()); + memcpy(buf->data() + 64 + 8, &v, 8); + changed = true; + } + + changed |= QSGTextureMaterialRhiShader::updateUniformData(state, newMaterial, oldMaterial); + + return changed; +} + + +QSGDefaultInternalImageNode::QSGDefaultInternalImageNode(QSGDefaultRenderContext *rc) + : m_rc(rc) { setMaterial(&m_materialO); setOpaqueMaterial(&m_material); @@ -209,14 +249,19 @@ bool QSGDefaultInternalImageNode::supportsWrap(const QSize &size) const { bool wrapSupported = true; - QOpenGLContext *ctx = QOpenGLContext::currentContext(); + if (m_rc->rhi()) { + wrapSupported = m_rc->rhi()->isFeatureSupported(QRhi::NPOTTextureRepeat) + || (isPowerOfTwo(size.width()) && isPowerOfTwo(size.height())); + } else { + QOpenGLContext *ctx = QOpenGLContext::currentContext(); #ifndef QT_OPENGL_ES_2 - if (ctx->isOpenGLES()) + if (ctx->isOpenGLES()) #endif - { - bool npotSupported = ctx->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat); - const bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height()); - wrapSupported = npotSupported || !isNpot; + { + bool npotSupported = ctx->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat); + const bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height()); + wrapSupported = npotSupported || !isNpot; + } } return wrapSupported; |