summaryrefslogtreecommitdiffstats
path: root/src/render/renderers/opengl/renderer/renderer.cpp
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2018-07-11 11:18:24 +0200
committerPaul Lemire <paul.lemire@kdab.com>2018-07-18 13:44:26 +0000
commitcdf92a8ba06c3df17a11c8931d540a4bf9229f61 (patch)
tree4ef115907f603ac321f4bfc97fb6dcecc1637603 /src/render/renderers/opengl/renderer/renderer.cpp
parentee53b5366eb925b2fbe3cd28209e2f8c7bc9e143 (diff)
Fix: Do not enforce TextureImage to be parented only by Texture
This behavior prevented using TextureImage not directly parented by the Texture that uses them (assert would be triggered). In turn, this also prevents sharing a TextureImage among several Texture instances which is counter productive since this is where the data is actually stored. This patch fixes this issue. It removes all direct coupling between Texture and TextureImages. Now Texture only contains the list of TextureImage ids it references. This allows to not make look-ups into the TextureImageManager to retrieve handles, which could be an issue if TextureImages have not yet had their backend created. TextureImage doesn't keep track of the referencing texture that uses it anymore. Instead, we let the renderer do the job of checking if any of the TextureImage referenced by a Texture has changed to trigger actual Texture update. Change-Id: I3c63379d0f4b314e9b53f225870eeaded0bb4aec Task-number: QTBUG-69407 Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/render/renderers/opengl/renderer/renderer.cpp')
-rw-r--r--src/render/renderers/opengl/renderer/renderer.cpp37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/render/renderers/opengl/renderer/renderer.cpp b/src/render/renderers/opengl/renderer/renderer.cpp
index 1e0a43b30..904527cd5 100644
--- a/src/render/renderers/opengl/renderer/renderer.cpp
+++ b/src/render/renderers/opengl/renderer/renderer.cpp
@@ -1057,13 +1057,42 @@ void Renderer::lookForDownloadableBuffers()
// Executed in a job
void Renderer::lookForDirtyTextures()
{
- const QVector<HTexture> activeTextureHandles = m_nodesManager->textureManager()->activeHandles();
+ // To avoid having Texture or TextureImage maintain relationships between
+ // one another, we instead perform a lookup here to check if a texture
+ // image has been updated to then notify textures referencing the image
+ // that they need to be updated
+ TextureImageManager *imageManager = m_nodesManager->textureImageManager();
+ const QVector<HTextureImage> activeTextureImageHandles = imageManager->activeHandles();
+ Qt3DCore::QNodeIdVector dirtyImageIds;
+ for (const HTextureImage &handle: activeTextureImageHandles) {
+ TextureImage *image = imageManager->data(handle);
+ if (image->isDirty()) {
+ dirtyImageIds.push_back(image->peerId());
+ image->unsetDirty();
+ }
+ }
+
+ TextureManager *textureManager = m_nodesManager->textureManager();
+ const QVector<HTexture> activeTextureHandles = textureManager->activeHandles();
for (const HTexture &handle: activeTextureHandles) {
- Texture *texture = m_nodesManager->textureManager()->data(handle);
+ Texture *texture = textureManager->data(handle);
+ const QNodeIdVector imageIds = texture->textureImageIds();
+
+ // Does the texture reference any of the dirty texture images?
+ for (const QNodeId imageId: imageIds) {
+ if (dirtyImageIds.contains(imageId)) {
+ texture->addDirtyFlag(Texture::DirtyImageGenerators);
+ break;
+ }
+ }
+
// Dirty meaning that something has changed on the texture
// either properties, parameters, generator or a texture image
if (texture->dirtyFlags() != Texture::NotDirty)
m_dirtyTextures.push_back(handle);
+ // Note: texture dirty flags are reset when actually updating the
+ // textures in updateGLResources() as resetting flags here would make
+ // us lose information about what was dirty exactly.
}
}
@@ -1204,7 +1233,7 @@ void Renderer::updateGLResources()
void Renderer::updateTexture(Texture *texture)
{
// Check that the current texture images are still in place, if not, do not update
- const bool isValid = texture->isValid();
+ const bool isValid = texture->isValid(m_nodesManager->textureImageManager());
if (!isValid)
return;
@@ -1278,7 +1307,7 @@ void Renderer::updateTexture(Texture *texture)
// Will make the texture requestUpload
if (dirtyFlags.testFlag(Texture::DirtyImageGenerators) &&
- !glTextureManager->setImages(glTexture, texture->textureImages()))
+ !glTextureManager->setImages(glTexture, texture->textureImageIds()))
qWarning() << "[Qt3DRender::TextureNode] updateTexture: TextureImpl.setGenerators failed, should be non-shared";
// Will make the texture requestUpload