diff options
-rw-r--r-- | src/render/texture/qabstracttexture.cpp | 25 | ||||
-rw-r--r-- | src/render/texture/qabstracttexture.h | 4 | ||||
-rw-r--r-- | src/render/texture/texture.cpp | 2 | ||||
-rw-r--r-- | tests/auto/render/qabstracttexture/tst_qabstracttexture.cpp | 47 | ||||
-rw-r--r-- | tests/auto/render/texture/tst_texture.cpp | 1 |
5 files changed, 78 insertions, 1 deletions
diff --git a/src/render/texture/qabstracttexture.cpp b/src/render/texture/qabstracttexture.cpp index 3cc7177f8..0e8abe090 100644 --- a/src/render/texture/qabstracttexture.cpp +++ b/src/render/texture/qabstracttexture.cpp @@ -588,6 +588,15 @@ void QAbstractTexture::setSamples(int samples) } } +void QAbstractTexture::setMipLevels(int mipLevels) +{ + Q_D(QAbstractTexture); + if (d->m_mipmapLevels != mipLevels) { + d->m_mipmapLevels = mipLevels; + emit mipLevelsChanged(mipLevels); + } +} + /*! Returns the number of samples per texel for the texture provider. @@ -601,6 +610,22 @@ int QAbstractTexture::samples() const } /*! + \property Qt3DRender::QAbstractTexture::mipLevels + + Holds the mipmap levels of the texture provider. + */ +/*! + \qmlproperty int Qt3DRender::QAbstractTexture::format + + Holds the mipmap levels of the texture provider. + */ +int QAbstractTexture::mipLevels() const +{ + Q_D(const QAbstractTexture); + return d->m_mipmapLevels; +} + +/*! \property Qt3DRender::QAbstractTexture::format Holds the format of the texture provider. diff --git a/src/render/texture/qabstracttexture.h b/src/render/texture/qabstracttexture.h index 47fc2a81d..bd5b3fa25 100644 --- a/src/render/texture/qabstracttexture.h +++ b/src/render/texture/qabstracttexture.h @@ -65,6 +65,7 @@ class Q_3DRENDERSHARED_EXPORT QAbstractTexture : public Qt3DCore::QNode Q_PROPERTY(int width READ width WRITE setWidth NOTIFY widthChanged) Q_PROPERTY(int height READ height WRITE setHeight NOTIFY heightChanged) Q_PROPERTY(int depth READ depth WRITE setDepth NOTIFY depthChanged) + Q_PROPERTY(int mipLevels READ mipLevels WRITE setMipLevels NOTIFY mipLevelsChanged) Q_PROPERTY(Filter magnificationFilter READ magnificationFilter WRITE setMagnificationFilter NOTIFY magnificationFilterChanged) Q_PROPERTY(Filter minificationFilter READ minificationFilter WRITE setMinificationFilter NOTIFY minificationFilterChanged) Q_PROPERTY(float maximumAnisotropy READ maximumAnisotropy WRITE setMaximumAnisotropy NOTIFY maximumAnisotropyChanged) @@ -305,6 +306,7 @@ public: int depth() const; int layers() const; int samples() const; + int mipLevels() const; HandleType handleType() const; QVariant handle() const; @@ -324,6 +326,7 @@ public Q_SLOTS: void setComparisonMode(ComparisonMode mode); void setLayers(int layers); void setSamples(int samples); + void setMipLevels(int mipLevels); Q_SIGNALS: void formatChanged(TextureFormat format); @@ -341,6 +344,7 @@ Q_SIGNALS: void samplesChanged(int samples); Q_REVISION(13) void handleTypeChanged(HandleType handleType); Q_REVISION(13) void handleChanged(QVariant handle); + void mipLevelsChanged(int mipLevels); protected: explicit QAbstractTexture(Qt3DCore::QNode *parent = nullptr); diff --git a/src/render/texture/texture.cpp b/src/render/texture/texture.cpp index 956d44a9e..27f45c949 100644 --- a/src/render/texture/texture.cpp +++ b/src/render/texture/texture.cpp @@ -124,7 +124,7 @@ void Texture::syncFromFrontEnd(const QNode *frontEnd, bool firstTime) p.generateMipMaps = node->generateMipMaps(); p.layers = node->layers(); p.samples = node->samples(); - p.mipLevels = static_cast<const QAbstractTexturePrivate*>(QAbstractTexturePrivate::get(node))->m_mipmapLevels; + p.mipLevels = node->mipLevels(); if (p != m_properties) { m_properties = p; addDirtyFlag(DirtyProperties); diff --git a/tests/auto/render/qabstracttexture/tst_qabstracttexture.cpp b/tests/auto/render/qabstracttexture/tst_qabstracttexture.cpp index 99048fbc2..126e77ac2 100644 --- a/tests/auto/render/qabstracttexture/tst_qabstracttexture.cpp +++ b/tests/auto/render/qabstracttexture/tst_qabstracttexture.cpp @@ -85,6 +85,7 @@ private Q_SLOTS: QCOMPARE(abstractTexture.depth(), 1); QCOMPARE(abstractTexture.magnificationFilter(), Qt3DRender::QAbstractTexture::Nearest); QCOMPARE(abstractTexture.minificationFilter(), Qt3DRender::QAbstractTexture::Nearest); + QCOMPARE(abstractTexture.mipLevels(), 1); QCOMPARE(abstractTexture.maximumAnisotropy(), 1.0f); QCOMPARE(abstractTexture.comparisonFunction(), Qt3DRender::QAbstractTexture::CompareLessEqual); QCOMPARE(abstractTexture.comparisonMode(), Qt3DRender::QAbstractTexture::CompareNone); @@ -330,6 +331,25 @@ private Q_SLOTS: QCOMPARE(abstractTexture.samples(), newValue); QCOMPARE(spy.count(), 0); } + { + // WHEN + QSignalSpy spy(&abstractTexture, SIGNAL(mipLevelsChanged(int))); + const int newValue = 1024; + abstractTexture.setMipLevels(newValue); + + // THEN + QVERIFY(spy.isValid()); + QCOMPARE(abstractTexture.mipLevels(), newValue); + QCOMPARE(spy.count(), 1); + + // WHEN + spy.clear(); + abstractTexture.setMipLevels(newValue); + + // THEN + QCOMPARE(abstractTexture.mipLevels(), newValue); + QCOMPARE(spy.count(), 0); + } } void checkFormatUpdate() @@ -668,6 +688,33 @@ private Q_SLOTS: } + void checkMipLevelsUpdate() + { + // GIVEN + TestArbiter arbiter; + FakeTexture abstractTexture; + arbiter.setArbiterOnNode(&abstractTexture); + + { + // WHEN + abstractTexture.setMipLevels(16); + + // THEN + QCOMPARE(arbiter.dirtyNodes().size(), 1); + QCOMPARE(arbiter.dirtyNodes().front(), &abstractTexture); + + arbiter.clear(); + } + + { + // WHEN + abstractTexture.setMipLevels(16); + + // THEN + QCOMPARE(arbiter.dirtyNodes().size(), 0); + } + } + void checkTextureImageAdded() { // GIVEN diff --git a/tests/auto/render/texture/tst_texture.cpp b/tests/auto/render/texture/tst_texture.cpp index caaa4d6f2..ed38f4822 100644 --- a/tests/auto/render/texture/tst_texture.cpp +++ b/tests/auto/render/texture/tst_texture.cpp @@ -223,6 +223,7 @@ void tst_RenderTexture::checkPropertyMirroring() frontend.setDepth(16); frontend.setLayers(8); frontend.setSamples(32); + frontend.setMipLevels(8); // WHEN simulateInitializationSync(&frontend, &backend); |