summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSvenn-Arne Dragly <s@dragly.com>2018-10-29 12:17:07 +0100
committerAndy Nichols <andy.nichols@qt.io>2018-11-09 09:00:41 +0000
commit8619fa84c095057989b14192a582b50911267227 (patch)
tree844d89a97f757913ccd399944a8ab428ae88175d
parent620ff320780843dc9ba322367bef6236231f57f7 (diff)
Reuse existing GLTexture for equal LoadedTexture
Change-Id: I585b0f914ca02c12b3f8a0460ce2eb04e2861763 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r--src/runtime/dragon/dragon.pri3
-rw-r--r--src/runtime/dragon/dragoncomparegenerators_p.h72
-rw-r--r--src/runtime/dragon/dragongltexture.cpp2
-rw-r--r--src/runtime/dragon/dragongltexture_p.h1
-rw-r--r--src/runtime/dragon/dragonrenderer.cpp11
-rw-r--r--src/runtime/dragon/dragontexture.cpp14
-rw-r--r--src/runtime/dragon/dragontexture_p.h8
-rw-r--r--src/runtime/dragon/dragontextureimage.cpp12
-rw-r--r--src/runtime/dragon/dragontextureimage_p.h1
9 files changed, 118 insertions, 6 deletions
diff --git a/src/runtime/dragon/dragon.pri b/src/runtime/dragon/dragon.pri
index 0f84f43..476269b 100644
--- a/src/runtime/dragon/dragon.pri
+++ b/src/runtime/dragon/dragon.pri
@@ -44,7 +44,8 @@ HEADERS += \
$$PWD/dragonoptional_p.h \
$$PWD/dragonstringtoint_p.h \
$$PWD/dragonimmutable_p.h \
- $$PWD/dragonmutable_p.h
+ $$PWD/dragonmutable_p.h \
+ $$PWD/dragoncomparegenerators_p.h
SOURCES += \
$$PWD/dragonattachmentpack.cpp \
diff --git a/src/runtime/dragon/dragoncomparegenerators_p.h b/src/runtime/dragon/dragoncomparegenerators_p.h
new file mode 100644
index 0000000..769ec3e
--- /dev/null
+++ b/src/runtime/dragon/dragoncomparegenerators_p.h
@@ -0,0 +1,72 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of Qt 3D Studio.
+**
+** $QT_BEGIN_LICENSE:GPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 or (at your option) any later version
+** approved by the KDE Free Qt Foundation. The licenses are as published by
+** the Free Software Foundation and appearing in the file LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_DRAGON_COMPAREGENERATORS_P_H
+#define QT3DRENDER_DRAGON_COMPAREGENERATORS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of other Qt classes. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <QSharedPointer>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+namespace Dragon {
+
+/*! \internal
+ * Make sure two generators are equal by first checking if they are nullptr,
+ * then comparing them if they are not.
+ */
+template<typename T>
+bool compareGenerators(const QSharedPointer<T> &a, const QSharedPointer<T> &b)
+{
+ if (a == nullptr && b == nullptr)
+ return true;
+
+ if (a == nullptr || b == nullptr)
+ return false;
+
+ return *a == *b;
+}
+
+} // namespace Dragon
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // QT3DRENDER_DRAGON_COMPAREGENERATORS_P_H
diff --git a/src/runtime/dragon/dragongltexture.cpp b/src/runtime/dragon/dragongltexture.cpp
index 48b9bb2..3bedd7f 100644
--- a/src/runtime/dragon/dragongltexture.cpp
+++ b/src/runtime/dragon/dragongltexture.cpp
@@ -128,7 +128,9 @@ GLTexture createGlTexture(const Immutable<LoadedTexture> &loadedTexture, QOpenGL
if (loadedTexture->generator != nullptr || loadedTexture->images.size() > 0) {
needUpload = true;
}
+
GLTexture result;
+ result.loadedTexture = loadedTexture;
result.properties = deriveProperties(loadedTexture);
result.parameters = loadedTexture->texture->parameters;
result.actualTarget = loadedTexture->texture->properties.target;
diff --git a/src/runtime/dragon/dragongltexture_p.h b/src/runtime/dragon/dragongltexture_p.h
index 6d75bd5..a490db9 100644
--- a/src/runtime/dragon/dragongltexture_p.h
+++ b/src/runtime/dragon/dragongltexture_p.h
@@ -59,6 +59,7 @@ struct GLTexture
QAbstractTexture::Target actualTarget = QAbstractTexture::TargetAutomatic;
TextureProperties properties;
TextureParameters parameters;
+ Immutable<LoadedTexture> loadedTexture;
QSize size() const { return QSize(properties.width, properties.height); }
diff --git a/src/runtime/dragon/dragonrenderer.cpp b/src/runtime/dragon/dragonrenderer.cpp
index 09a1191..afe93db 100644
--- a/src/runtime/dragon/dragonrenderer.cpp
+++ b/src/runtime/dragon/dragonrenderer.cpp
@@ -399,12 +399,17 @@ Renderer::Frame Renderer::doRender(Renderer::Frame frame)
// TODO not nice to have to take this by reference, but what can we do?
auto createGLTextureHelper =
[&activeSurface](const QNodeId &id, const Immutable<LoadedTexture> &loadedTexture) {
- Q_UNUSED(id);
- return createGlTexture(loadedTexture, activeSurface.openGLContext());
- };
+ Q_UNUSED(id);
+ return Mutable<GLTexture>(createGlTexture(loadedTexture, activeSurface.openGLContext()));
+ };
+
+ auto compareGLTexture = [](const GLTexture &glTexture, const Immutable<LoadedTexture> &loaded){
+ return glTexture.loadedTexture == loaded;
+ };
frame.uploadedTextures = synchronizeNew(std::move(frame.uploadedTextures),
loadedTextures,
+ compareGLTexture,
createGLTextureHelper);
auto updateGLTextureHelper = [&activeSurface](const QNodeId &id, Mutable<GLTexture> glTexture,
diff --git a/src/runtime/dragon/dragontexture.cpp b/src/runtime/dragon/dragontexture.cpp
index ea786de..7e181a5 100644
--- a/src/runtime/dragon/dragontexture.cpp
+++ b/src/runtime/dragon/dragontexture.cpp
@@ -30,12 +30,14 @@
#include "dragontexture_p.h"
+#include <private/dragontextureimage_p.h>
+#include <private/dragoncomparegenerators_p.h>
+
#include <Qt3DRender/private/qabstracttexture_p.h>
#include <Qt3DCore/QPropertyUpdatedChange>
#include <Qt3DCore/QPropertyNodeAddedChange>
#include <Qt3DCore/QPropertyNodeRemovedChange>
-
QT_BEGIN_NAMESPACE
using namespace Qt3DCore;
@@ -189,6 +191,16 @@ void Texture::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &chan
addDirtyFlag(DirtyFlags(DirtyImageGenerators|DirtyProperties|DirtyParameters));
}
+bool operator ==(const LoadedTexture &a, const LoadedTexture &b)
+{
+ return a.images == b.images && a.texture == b.texture;
+}
+
+bool operator ==(const Texture &a, const Texture &b)
+{
+ return compareGenerators(a.generator, b.generator) && a.properties == b.properties && a.parameters == b.parameters;
+}
+
}
}
diff --git a/src/runtime/dragon/dragontexture_p.h b/src/runtime/dragon/dragontexture_p.h
index b53e6e8..435416b 100644
--- a/src/runtime/dragon/dragontexture_p.h
+++ b/src/runtime/dragon/dragontexture_p.h
@@ -49,6 +49,8 @@
#include <Qt3DRender/qtexturedata.h>
+#include <private/q3dsruntimeglobal_p.h>
+
#include <private/dragonimmutable_p.h>
#include <QFuture>
@@ -110,7 +112,7 @@ struct TextureParameters
inline bool operator!=(const TextureParameters &o) const { return !(*this == o); }
};
-class Texture : public BackendNode
+class Q3DSV_PRIVATE_EXPORT Texture : public BackendNode
{
public:
enum DirtyFlag {
@@ -139,6 +141,8 @@ public:
// QVector<Qt3DCore::QNodeId> m_textureImages;
};
+bool operator ==(const Texture &a, const Texture &b);
+
// TODO add support for texture generators and not just texture images
struct LoadedTexture
{
@@ -149,6 +153,8 @@ struct LoadedTexture
QTextureDataPtr data;
};
+bool operator ==(const LoadedTexture &a, const LoadedTexture &b);;
+
} // namespace Dragon
} // namespace Qt3DRender
QT_END_NAMESPACE
diff --git a/src/runtime/dragon/dragontextureimage.cpp b/src/runtime/dragon/dragontextureimage.cpp
index 58872fe..fca57de 100644
--- a/src/runtime/dragon/dragontextureimage.cpp
+++ b/src/runtime/dragon/dragontextureimage.cpp
@@ -30,6 +30,8 @@
#include "dragontextureimage_p.h"
+#include <private/dragoncomparegenerators_p.h>
+
#include <Qt3DRender/qabstracttextureimage.h>
#include <Qt3DRender/private/qabstracttextureimage_p.h>
@@ -79,6 +81,16 @@ void TextureImage::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e)
BackendNode::sceneChangeEvent(e);
}
+bool operator ==(const TextureImage &a, const TextureImage &b)
+{
+ return compareGenerators(a.generator, b.generator) && a.face == b.face && a.layer == b.layer && a.mipLevel == b.mipLevel;
+}
+
+bool operator ==(const LoadedTextureImage &a, const LoadedTextureImage &b)
+{
+ return *a.generator == *b.generator;
+}
+
}
}
QT_END_NAMESPACE
diff --git a/src/runtime/dragon/dragontextureimage_p.h b/src/runtime/dragon/dragontextureimage_p.h
index e9da84d..441f3be 100644
--- a/src/runtime/dragon/dragontextureimage_p.h
+++ b/src/runtime/dragon/dragontextureimage_p.h
@@ -92,6 +92,7 @@ struct LoadedTextureImage
QTextureImageDataPtr data;
};
+bool operator ==(const LoadedTextureImage &a, const LoadedTextureImage &b);
} // namespace Dragon
} // namespace Qt3DRender