diff options
-rw-r--r-- | src/quick/scenegraph/util/qsgdefaultimagenode.cpp | 15 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgdefaultimagenode_p.h | 4 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgimagenode.h | 2 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexture.cpp | 53 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexture.h | 11 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexture_p.h | 2 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexturematerial.cpp | 2 | ||||
-rw-r--r-- | src/quick/scenegraph/util/qsgtexturematerial.h | 7 |
8 files changed, 94 insertions, 2 deletions
diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp index 63773887a0..7186ee4265 100644 --- a/src/quick/scenegraph/util/qsgdefaultimagenode.cpp +++ b/src/quick/scenegraph/util/qsgdefaultimagenode.cpp @@ -94,6 +94,21 @@ QSGTexture::Filtering QSGDefaultImageNode::mipmapFiltering() const return m_material.mipmapFiltering(); } +void QSGDefaultImageNode::setAnisotropyLevel(QSGTexture::AnisotropyLevel level) +{ + if (m_material.anisotropyLevel() == level) + return; + + m_material.setAnisotropyLevel(level); + m_opaque_material.setAnisotropyLevel(level); + markDirty(DirtyMaterial); +} + +QSGTexture::AnisotropyLevel QSGDefaultImageNode::anisotropyLevel() const +{ + return m_material.anisotropyLevel(); +} + void QSGDefaultImageNode::setRect(const QRectF &r) { if (m_rect == r) diff --git a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h index bb9ebec885..cb23e759d3 100644 --- a/src/quick/scenegraph/util/qsgdefaultimagenode_p.h +++ b/src/quick/scenegraph/util/qsgdefaultimagenode_p.h @@ -85,6 +85,10 @@ public: void setOwnsTexture(bool owns) override; bool ownsTexture() const override; + // QSGImageNode now being a public class does not allow any additional virtual methods. Placing these here, non-virtual. + void setAnisotropyLevel(QSGTexture::AnisotropyLevel level); + QSGTexture::AnisotropyLevel anisotropyLevel() const; + private: QSGGeometry m_geometry; QSGOpaqueTextureMaterial m_opaque_material; diff --git a/src/quick/scenegraph/util/qsgimagenode.h b/src/quick/scenegraph/util/qsgimagenode.h index d25e732e4b..0e053c307f 100644 --- a/src/quick/scenegraph/util/qsgimagenode.h +++ b/src/quick/scenegraph/util/qsgimagenode.h @@ -67,6 +67,8 @@ public: virtual void setMipmapFiltering(QSGTexture::Filtering filtering) = 0; virtual QSGTexture::Filtering mipmapFiltering() const = 0; + // ### Qt6: Add anisotropy support here, and possibly a virtual hook or another mean to extend this class. + enum TextureCoordinatesTransformFlag { NoTransform = 0x00, MirrorHorizontally = 0x01, diff --git a/src/quick/scenegraph/util/qsgtexture.cpp b/src/quick/scenegraph/util/qsgtexture.cpp index 47248f2f37..bc59c49162 100644 --- a/src/quick/scenegraph/util/qsgtexture.cpp +++ b/src/quick/scenegraph/util/qsgtexture.cpp @@ -83,6 +83,9 @@ static const bool qsg_leak_check = !qEnvironmentVariableIsEmpty("QML_LEAK_CHECK" #define GL_BGRA 0x80E1 #endif +#ifndef GL_TEXTURE_MAX_ANISOTROPY_EXT +#define GL_TEXTURE_MAX_ANISOTROPY_EXT 0x84FE +#endif QT_BEGIN_NAMESPACE @@ -97,10 +100,12 @@ inline static bool isPowerOfTwo(int x) QSGTexturePrivate::QSGTexturePrivate() : wrapChanged(false) , filteringChanged(false) + , anisotropyChanged(false) , horizontalWrap(QSGTexture::ClampToEdge) , verticalWrap(QSGTexture::ClampToEdge) , mipmapMode(QSGTexture::None) , filterMode(QSGTexture::Nearest) + , anisotropyLevel(QSGTexture::AnisotropyNone) { } @@ -274,6 +279,23 @@ static void qt_debug_remove_texture(QSGTexture* texture) */ /*! + \enum QSGTexture::AnisotropyLevel + + Specifies the anisotropic filtering level to be used when + the texture is not screen aligned. + + \value AnisotropyNone No anisotropic filtering. + + \value Anisotropy2x 2x anisotropic filtering. + + \value Anisotropy4x 4x anisotropic filtering. + + \value Anisotropy8x 8x anisotropic filtering. + + \value Anisotropy16x 16x anisotropic filtering. +*/ + +/*! \fn QSGTexture::QSGTexture(QSGTexturePrivate &dd) \internal */ @@ -472,6 +494,31 @@ QSGTexture::Filtering QSGTexture::filtering() const return (QSGTexture::Filtering) d_func()->filterMode; } +/*! + Sets the level of anisotropic filtering to be used for the upcoming bind() call to \a level. + The default value is QSGTexture::AnisotropyNone, which means no anisotropic filtering is enabled. + + \since 5.9 + */ +void QSGTexture::setAnisotropyLevel(AnisotropyLevel level) +{ + Q_D(QSGTexture); + if (d->anisotropyLevel != (uint) level) { + d->anisotropyLevel = level; + d->anisotropyChanged = true; + } +} + +/*! + Returns the anisotropy level in use for filtering this texture. + + \since 5.9 + */ +QSGTexture::AnisotropyLevel QSGTexture::anisotropyLevel() const +{ + return (QSGTexture::AnisotropyLevel) d_func()->anisotropyLevel; +} + /*! @@ -548,6 +595,12 @@ void QSGTexture::updateBindOptions(bool force) d->filteringChanged = false; } + if (force || d->anisotropyChanged) { + d->anisotropyChanged = false; + if (QOpenGLContext::currentContext()->hasExtension(QByteArrayLiteral("GL_EXT_texture_filter_anisotropic"))) + funcs->glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, float(1 << (d->anisotropyLevel))); + } + if (force || d->wrapChanged) { #ifndef QT_NO_DEBUG if (d->horizontalWrap == Repeat || d->verticalWrap == Repeat) { diff --git a/src/quick/scenegraph/util/qsgtexture.h b/src/quick/scenegraph/util/qsgtexture.h index f0509b58ae..035acc02b1 100644 --- a/src/quick/scenegraph/util/qsgtexture.h +++ b/src/quick/scenegraph/util/qsgtexture.h @@ -67,6 +67,14 @@ public: Linear }; + enum AnisotropyLevel { + AnisotropyNone, + Anisotropy2x, + Anisotropy4x, + Anisotropy8x, + Anisotropy16x + }; + virtual int textureId() const = 0; virtual QSize textureSize() const = 0; virtual bool hasAlphaChannel() const = 0; @@ -87,6 +95,9 @@ public: void setFiltering(Filtering filter); QSGTexture::Filtering filtering() const; + void setAnisotropyLevel(AnisotropyLevel level); + QSGTexture::AnisotropyLevel anisotropyLevel() const; + void setHorizontalWrapMode(WrapMode hwrap); QSGTexture::WrapMode horizontalWrapMode() const; diff --git a/src/quick/scenegraph/util/qsgtexture_p.h b/src/quick/scenegraph/util/qsgtexture_p.h index b6fcfc31c4..36f9b802ba 100644 --- a/src/quick/scenegraph/util/qsgtexture_p.h +++ b/src/quick/scenegraph/util/qsgtexture_p.h @@ -69,11 +69,13 @@ public: uint wrapChanged : 1; uint filteringChanged : 1; + uint anisotropyChanged : 1; uint horizontalWrap : 1; uint verticalWrap : 1; uint mipmapMode : 2; uint filterMode : 2; + uint anisotropyLevel: 3; }; class Q_QUICK_PRIVATE_EXPORT QSGPlainTexture : public QSGTexture diff --git a/src/quick/scenegraph/util/qsgtexturematerial.cpp b/src/quick/scenegraph/util/qsgtexturematerial.cpp index 9326ea640d..c536445e82 100644 --- a/src/quick/scenegraph/util/qsgtexturematerial.cpp +++ b/src/quick/scenegraph/util/qsgtexturematerial.cpp @@ -110,6 +110,7 @@ void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMa Q_UNUSED(state) #endif t->setMipmapFiltering(tx->mipmapFiltering()); + t->setAnisotropyLevel(tx->anisotropyLevel()); if (oldTx == 0 || oldTx->texture()->textureId() != t->textureId()) t->bind(); @@ -173,6 +174,7 @@ QSGOpaqueTextureMaterial::QSGOpaqueTextureMaterial() , m_mipmap_filtering(QSGTexture::None) , m_horizontal_wrap(QSGTexture::ClampToEdge) , m_vertical_wrap(QSGTexture::ClampToEdge) + , m_anisotropy_level(QSGTexture::AnisotropyNone) { } diff --git a/src/quick/scenegraph/util/qsgtexturematerial.h b/src/quick/scenegraph/util/qsgtexturematerial.h index dc87131773..87d8e5fd49 100644 --- a/src/quick/scenegraph/util/qsgtexturematerial.h +++ b/src/quick/scenegraph/util/qsgtexturematerial.h @@ -69,6 +69,9 @@ public: void setVerticalWrapMode(QSGTexture::WrapMode mode) { m_vertical_wrap = mode; } QSGTexture::WrapMode verticalWrapMode() const { return QSGTexture::WrapMode(m_vertical_wrap); } + void setAnisotropyLevel(QSGTexture::AnisotropyLevel level) { m_anisotropy_level = level; } + QSGTexture::AnisotropyLevel anisotropyLevel() const { return QSGTexture::AnisotropyLevel(m_anisotropy_level); } + protected: QSGTexture *m_texture; @@ -76,8 +79,8 @@ protected: uint m_mipmap_filtering: 2; uint m_horizontal_wrap : 1; uint m_vertical_wrap: 1; - - uint m_reserved : 26; + uint m_anisotropy_level : 3; + uint m_reserved : 23; }; |