summaryrefslogtreecommitdiffstats
path: root/src/render/texture/qtexture.cpp
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-02-19 13:34:13 +0100
committerPaul Lemire <paul.lemire@kdab.com>2019-03-04 14:52:38 +0000
commit0a8742532fb1697203dd3d7d9c1c28b4cb052e2d (patch)
treee417fec5065df3d7e8d66f237ba56fb39435185d /src/render/texture/qtexture.cpp
parent299c0bc6d2ea5817ba32b3724290c349789be11b (diff)
Rework internal Texture Handling
- Remove internal GLTexture sharing - Remove dataFunctor data sharing - Simplify the overall texture process: 1) Look for dirty textures (either a property on QTexture or a referenced QTextureImage has changed) 2) Update GL Resources - Create a GLTexture for a given Texture if it doesn't exist - Update GLTexture to reflect Texture state - Perform actual GL texture creation and or upload (call functors at this point) - Cleanup GLTextures when matching Texture node has been destroyed This will provide an easier maintenance over time as it drastically simplifies the handling of textures and removes most of the coupling. Furthermore this will make it possible to send texture updates on a QTexture node to update texture content without having to declare QTextureImages which would not have been (or would have been a lot harder) to do. In practice, I doubt most people were even aware of the internal texture sharing in the first place. [ChangeLog][Qt3DRender] Textures: internal data sharing removed Change-Id: I02867c8105e29eb1e193884e3899062f795f32f4 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/texture/qtexture.cpp')
-rw-r--r--src/render/texture/qtexture.cpp55
1 files changed, 17 insertions, 38 deletions
diff --git a/src/render/texture/qtexture.cpp b/src/render/texture/qtexture.cpp
index cf93f872f..fc62b76ff 100644
--- a/src/render/texture/qtexture.cpp
+++ b/src/render/texture/qtexture.cpp
@@ -56,7 +56,6 @@
#include <Qt3DRender/private/managers_p.h>
#include <Qt3DRender/private/texture_p.h>
#include <Qt3DRender/private/qurlhelper_p.h>
-#include <Qt3DRender/private/texturedatamanager_p.h>
#include <Qt3DRender/private/gltexturemanager_p.h>
QT_BEGIN_NAMESPACE
@@ -925,7 +924,8 @@ QTextureDataPtr QTextureFromSourceGenerator::operator ()()
auto downloadService = Qt3DCore::QDownloadHelperService::getService(m_engine);
Qt3DCore::QDownloadRequestPtr request(new TextureDownloadRequest(sharedFromThis(),
m_url,
- m_engine));
+ m_engine,
+ m_texture));
downloadService->submitRequest(request);
}
return generatedData;
@@ -974,10 +974,12 @@ QTextureDataPtr QTextureFromSourceGenerator::operator ()()
TextureDownloadRequest::TextureDownloadRequest(const QTextureFromSourceGeneratorPtr &functor,
const QUrl &source,
- Qt3DCore::QAspectEngine *engine)
+ Qt3DCore::QAspectEngine *engine,
+ Qt3DCore::QNodeId texNodeId)
: Qt3DCore::QDownloadRequest(source)
, m_functor(functor)
, m_engine(engine)
+ , m_texNodeId(texNodeId)
{
}
@@ -992,46 +994,23 @@ void TextureDownloadRequest::onCompleted()
if (!d_aspect)
return;
- // Find all textures which share the same functor
- // Note: this should be refactored to not pull in API specific managers
- // but texture sharing forces us to do that currently
- Render::TextureDataManager *textureDataManager = d_aspect->m_nodeManagers->textureDataManager();
- const QVector<Render::GLTexture *> referencedGLTextures = textureDataManager->referencesForGenerator(m_functor);
-
- // We should have at most 1 GLTexture referencing this
- // Since all textures having the same source should have the same functor == same GLTexture
- Q_ASSERT(referencedGLTextures.size() <= 1);
-
- Render::GLTexture *glTex = referencedGLTextures.size() > 0 ? referencedGLTextures.first() : nullptr;
- if (glTex == nullptr)
- return;
-
- Render::GLTextureManager *glTextureManager = d_aspect->m_nodeManagers->glTextureManager();
- Qt3DCore::QNodeIdVector referencingTexturesIds = glTextureManager->referencedTextureIds(glTex);
-
-
Render::TextureManager *textureManager = d_aspect->m_nodeManagers->textureManager();
- for (const Qt3DCore::QNodeId texId : referencingTexturesIds) {
- Render::Texture *texture = textureManager->lookupResource(texId);
- if (texture != nullptr) {
- // Each texture has a QTextureFunctor which matches m_functor;
- // Update m_sourceData on each functor as we don't know which one
- // is used as the reference for texture sharing
+ Render::Texture *texture = textureManager->lookupResource(m_texNodeId);
+ if (texture == nullptr)
+ return;
- QTextureFromSourceGeneratorPtr oldGenerator = qSharedPointerCast<QTextureFromSourceGenerator>(texture->dataGenerator());
+ QTextureFromSourceGeneratorPtr oldGenerator = qSharedPointerCast<QTextureFromSourceGenerator>(texture->dataGenerator());
- // We create a new functor
- // Which is a copy of the old one + the downloaded sourceData
- auto newGenerator = QTextureFromSourceGeneratorPtr::create(*oldGenerator);
+ // We create a new functor
+ // Which is a copy of the old one + the downloaded sourceData
+ auto newGenerator = QTextureFromSourceGeneratorPtr::create(*oldGenerator);
- // Set raw data on functor so that it can really load something
- newGenerator->m_sourceData = m_data;
+ // Set raw data on functor so that it can really load something
+ newGenerator->m_sourceData = m_data;
- // Set new generator on texture
- // it implictely marks the texture as dirty so that the functor runs again with the downloaded data
- texture->setDataGenerator(newGenerator);
- }
- }
+ // Set new generator on texture
+ // it implictely marks the texture as dirty so that the functor runs again with the downloaded data
+ texture->setDataGenerator(newGenerator);
}
/*!