From 54f31a64d01a138e72f79b9585cb90004bbe1e4a Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 29 Aug 2019 12:27:59 +0200 Subject: Avoid introducing rhiTexture() in the public API of QSGTexture MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no need for this. The few internal users can get it via QSGTexturePrivate. The original thinking was based on QRhi* being a public API, but that is not the case in the near future. So avoid introducing a public API relying on QRhiTexture. This of course makes it impossible to retrieve the native object under a QSGTexture (as textureId() is not used anymore when rendering with the RHI). For that, an alternative approach will be introduced later on. Change-Id: I0099b23424cafa4958f78c03300b0c934b60d92c Reviewed-by: Christian Strømme --- src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 2 +- src/quick/scenegraph/coreapi/qsgtexture.cpp | 38 ++++++++++------------- src/quick/scenegraph/coreapi/qsgtexture.h | 1 - src/quick/scenegraph/coreapi/qsgtexture_p.h | 3 +- src/quick/scenegraph/qsgdefaultglyphnode_p.cpp | 4 ++- 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index 2441e14fda..336107a61d 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -3492,7 +3492,7 @@ void Renderer::updateMaterialDynamicData(ShaderManager::Shader *sms, } if (pd->textureBindingTable[binding] && pd->samplerBindingTable[binding]) { - QRhiTexture *texture = pd->textureBindingTable[binding]->rhiTexture(); + QRhiTexture *texture = QSGTexturePrivate::get(pd->textureBindingTable[binding])->rhiTexture(); // texture may be null if the update above failed for any reason, // or if the QSGTexture chose to return null intentionally. This is // valid and we still need to provide something to the shader. diff --git a/src/quick/scenegraph/coreapi/qsgtexture.cpp b/src/quick/scenegraph/coreapi/qsgtexture.cpp index cfd0cb9f06..c47401e5c0 100644 --- a/src/quick/scenegraph/coreapi/qsgtexture.cpp +++ b/src/quick/scenegraph/coreapi/qsgtexture.cpp @@ -695,27 +695,6 @@ void QSGTexture::updateBindOptions(bool force) // legacy (GL-only) #endif } -/*! - \return the QRhiTexture for this QSGTexture or null if there is none. - - Unlike textureId(), this function is not expected to create a new - QRhiTexture in case there is none. Just return null in that case. The - expectation towards the renderer is that a null texture leads to using a - transparent, dummy texture instead. - - \note This function is only used when running the graphics API independent - rendering path of the scene graph. - - \warning This function can only be called from the rendering thread. - - \since 5.14 - */ -QRhiTexture *QSGTexture::rhiTexture() const -{ - Q_D(const QSGTexture); - return d->rhiTexture(); -} - /*! Call this function to enqueue image upload operations to \a resourceUpdates, in case there are any pending ones. When there is no new @@ -762,6 +741,23 @@ int QSGTexturePrivate::comparisonKey() const return q->textureId(); // this is semantically wrong but at least compatible with existing, non-RHI-aware subclasses } +/*! + \internal + + \return the QRhiTexture for this QSGTexture or null if there is none. + + Unlike textureId(), this function is not expected to create a new + QRhiTexture in case there is none. Just return null in that case. The + expectation towards the renderer is that a null texture leads to using a + transparent, dummy texture instead. + + \note This function is only used when running the graphics API independent + rendering path of the scene graph. + + \warning This function can only be called from the rendering thread. + + \since 5.14 + */ QRhiTexture *QSGTexturePrivate::rhiTexture() const { return nullptr; diff --git a/src/quick/scenegraph/coreapi/qsgtexture.h b/src/quick/scenegraph/coreapi/qsgtexture.h index f2b0e902f3..4cd2a5cddd 100644 --- a/src/quick/scenegraph/coreapi/qsgtexture.h +++ b/src/quick/scenegraph/coreapi/qsgtexture.h @@ -113,7 +113,6 @@ public: // ### Qt 6: make these virtual int comparisonKey() const; - QRhiTexture *rhiTexture() const; void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates); // ### Qt 6: make this an argument for removedFromAtlas() diff --git a/src/quick/scenegraph/coreapi/qsgtexture_p.h b/src/quick/scenegraph/coreapi/qsgtexture_p.h index 1d248b0305..cb59d32012 100644 --- a/src/quick/scenegraph/coreapi/qsgtexture_p.h +++ b/src/quick/scenegraph/coreapi/qsgtexture_p.h @@ -83,9 +83,10 @@ public: void resetDirtySamplerOptions(); bool hasDirtySamplerOptions() const; + virtual QRhiTexture *rhiTexture() const; + // ### Qt 6: these should be virtuals in the public class instead virtual int comparisonKey() const; // ### Qt 6: pure virtual - virtual QRhiTexture *rhiTexture() const; virtual void updateRhiTexture(QRhi *rhi, QRhiResourceUpdateBatch *resourceUpdates); QRhiResourceUpdateBatch *workResourceUpdateBatch = nullptr; // ### Qt 6: remove diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index db889c3102..8fc8c711c6 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -451,7 +451,9 @@ bool QSGTextMaskRhiShader::updateUniformData(const RenderState &state, changed = true; } - if (updated || !oldMat || oldMat->texture()->rhiTexture() != mat->texture()->rhiTexture()) { + QRhiTexture *oldRtex = oldMat ? QSGTexturePrivate::get(oldMat->texture())->rhiTexture() : nullptr; + QRhiTexture *newRtex = QSGTexturePrivate::get(mat->texture())->rhiTexture(); + if (updated || !oldMat || oldRtex != newRtex) { const QVector2D textureScale = QVector2D(1.0f / mat->rhiGlyphCache()->width(), 1.0f / mat->rhiGlyphCache()->height()); memcpy(buf->data() + 64 + 16, &textureScale, 8); -- cgit v1.2.3