summaryrefslogtreecommitdiffstats
path: root/src/render/texture
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2018-03-12 08:32:35 +0100
committerPaul Lemire <paul.lemire@kdab.com>2020-02-05 11:33:49 +0100
commit0e115ff000fb294de8519bf5b39beee0d6bfa605 (patch)
treec66c1f19ad5e4b7fc4f3be7951fa74d1d4df64bb /src/render/texture
parentf1f387c22dac8748a7edb1f4aa1ea6dac7dfbdfd (diff)
Make the OpenGL renderer a plugin
By default the QRenderAspect will try to load this plugin Change-Id: Ie55e207fb8e6d0b64f717bbb99699eb669eaa3f2 Task-number: QTBUG-61151 Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/render/texture')
-rw-r--r--src/render/texture/qtexture.cpp2
-rw-r--r--src/render/texture/qtextureimagedata_p.h3
-rw-r--r--src/render/texture/texture.cpp2
-rw-r--r--src/render/texture/texture_p.h2
-rw-r--r--src/render/texture/texturedatamanager_p.h227
-rw-r--r--src/render/texture/textureimage_p.h2
6 files changed, 233 insertions, 5 deletions
diff --git a/src/render/texture/qtexture.cpp b/src/render/texture/qtexture.cpp
index 7f662dfc5..6b7b92166 100644
--- a/src/render/texture/qtexture.cpp
+++ b/src/render/texture/qtexture.cpp
@@ -57,7 +57,7 @@
#include <Qt3DRender/private/managers_p.h>
#include <Qt3DRender/private/texture_p.h>
#include <Qt3DRender/private/qurlhelper_p.h>
-#include <Qt3DRender/private/glresourcemanagers_p.h>
+#include <qmath.h>
QT_BEGIN_NAMESPACE
diff --git a/src/render/texture/qtextureimagedata_p.h b/src/render/texture/qtextureimagedata_p.h
index d9a0952de..14095e2eb 100644
--- a/src/render/texture/qtextureimagedata_p.h
+++ b/src/render/texture/qtextureimagedata_p.h
@@ -52,12 +52,13 @@
//
#include "qtextureimagedata.h"
+#include <Qt3DRender/private/qt3drender_global_p.h>
QT_BEGIN_NAMESPACE
namespace Qt3DRender {
-class QTextureImageDataPrivate
+class Q_3DRENDERSHARED_PRIVATE_EXPORT QTextureImageDataPrivate
{
public:
QTextureImageDataPrivate();
diff --git a/src/render/texture/texture.cpp b/src/render/texture/texture.cpp
index 795c5844e..dab037568 100644
--- a/src/render/texture/texture.cpp
+++ b/src/render/texture/texture.cpp
@@ -47,7 +47,7 @@
#include <Qt3DCore/qpropertynoderemovedchange.h>
#include <Qt3DRender/private/texture_p.h>
-#include <Qt3DRender/private/glresourcemanagers_p.h>
+#include <Qt3DRender/private/qabstracttexture_p.h>
#include <Qt3DRender/private/managers_p.h>
QT_BEGIN_NAMESPACE
diff --git a/src/render/texture/texture_p.h b/src/render/texture/texture_p.h
index 83a05ebcc..61011bb68 100644
--- a/src/render/texture/texture_p.h
+++ b/src/render/texture/texture_p.h
@@ -128,7 +128,7 @@ struct TextureParameters
* Will query the TextureImplManager for an instance of TextureImpl that matches it's
* properties.
*/
-class Q_AUTOTEST_EXPORT Texture : public BackendNode
+class Q_3DRENDERSHARED_PRIVATE_EXPORT Texture : public BackendNode
{
public:
Texture();
diff --git a/src/render/texture/texturedatamanager_p.h b/src/render/texture/texturedatamanager_p.h
new file mode 100644
index 000000000..61ebd1125
--- /dev/null
+++ b/src/render/texture/texturedatamanager_p.h
@@ -0,0 +1,227 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or 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.GPL2 and 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-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QT3DRENDER_RENDER_TEXTUREDATAMANAGER_H
+#define QT3DRENDER_RENDER_TEXTUREDATAMANAGER_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 <QMutex>
+#include <QMutexLocker>
+#include <Qt3DRender/qtexture.h>
+#include <Qt3DRender/qtextureimagedata.h>
+#include <Qt3DRender/qtexturegenerator.h>
+#include <Qt3DRender/qtextureimagedatagenerator.h>
+#include <Qt3DRender/private/qt3drender_global_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+namespace Render {
+
+/**
+ * The texture data managers associates each texture data generator
+ * with the data objects generated by them. That is, either
+ *
+ * QTextureImageDataGenerator -> QTextureImageData, or
+ * QTextureGenerator -> QTextureData
+ *
+ * This way, texture classes only need to refer to the texture functors used.
+ * Aspect jobs will make sure that at the start of each frame, all generators
+ * registered with the GeneratorDataManagers have been executed.
+ *
+ * This guarantees that no texture data generator is executed twice.
+ *
+ * Each Generator is associated with a number of textures that reference it.
+ * If the last texture disassociates from a generator, the QTextureData will
+ * be deleted.
+ */
+template <class GeneratorPtr, class DataPtr, class ReferencedType>
+class GeneratorDataManager
+{
+public:
+ GeneratorDataManager() {}
+
+ /*!
+ * If no data for the given generator exists, make sure that the
+ * generators are executed the next frame. Reference generator by
+ * given texture
+ *
+ * Returns true if the Entry for a given generator had to be created
+ */
+ bool requestData(const GeneratorPtr &generator, ReferencedType r)
+ {
+ QMutexLocker lock(&m_mutex);
+
+ Entry *entry = findEntry(generator);
+ const bool needsToBeCreated = (entry == nullptr);
+ if (needsToBeCreated)
+ entry = createEntry(generator);
+ Q_ASSERT(entry);
+ if (!entry->referencingObjects.contains(r))
+ entry->referencingObjects.push_back(r);
+ return needsToBeCreated;
+ }
+
+ /*!
+ * Dereference given generator from texture. If no other textures still reference
+ * the generator, the associated data will be deleted
+ */
+ void releaseData(const GeneratorPtr &generator, ReferencedType r)
+ {
+ QMutexLocker lock(&m_mutex);
+
+ const auto end = m_data.end();
+ for (auto it = m_data.begin(); it != end; ++it) {
+ Entry &entry = *it;
+ if (*entry.generator == *generator) {
+ entry.referencingObjects.removeAll(r);
+ // delete, if that was the last reference
+ if (entry.referencingObjects.empty()) {
+ m_data.erase(it);
+ return;
+ }
+ }
+ }
+ }
+
+ /*!
+ * Return data associated with given generator, if existent
+ */
+ DataPtr getData(const GeneratorPtr &generator)
+ {
+ QMutexLocker lock(&m_mutex);
+
+ const Entry *entry = findEntry(generator);
+ return entry ? entry->data : DataPtr();
+ }
+
+ /*!
+ * Returns all generators that were not yet executed
+ */
+ QVector<GeneratorPtr> pendingGenerators()
+ {
+ QMutexLocker lock(&m_mutex);
+
+ QVector<GeneratorPtr> ret;
+ for (const Entry &entry : m_data)
+ if (!entry.data && !ret.contains(entry.generator))
+ ret.push_back(entry.generator);
+ return ret;
+ }
+
+ /*!
+ * Assigns a piece of data to the generator that was used to
+ * create it.
+ */
+ void assignData(const GeneratorPtr &generator, const DataPtr &data)
+ {
+ QMutexLocker lock(&m_mutex);
+
+ Entry *entry = findEntry(generator);
+ if (!entry) {
+ qWarning() << "[TextureDataManager] assignData() called with non-existent generator";
+ return;
+ }
+ entry->data = data;
+ }
+
+ bool contains(const GeneratorPtr &generator)
+ {
+ return findEntry(generator) != nullptr;
+ }
+
+private:
+
+ struct Entry {
+ GeneratorPtr generator;
+ QVector<ReferencedType> referencingObjects;
+ DataPtr data;
+ };
+
+ /*!
+ * Helper function: return entry for given generator if it exists, nullptr
+ * otherwise.
+ */
+ Entry* findEntry(const GeneratorPtr &generator)
+ {
+ for (int i = 0, sz = m_data.size(); i < sz; ++i)
+ if (*m_data[i].generator == *generator)
+ return &m_data[i];
+ return nullptr;
+ }
+
+ Entry *createEntry(const GeneratorPtr &generator)
+ {
+ Entry newEntry;
+ newEntry.generator = generator;
+
+ m_data.push_back(newEntry);
+ return &m_data.back();
+ }
+
+ QMutex m_mutex;
+ QVector<Entry> m_data;
+};
+
+class QT3DRENDERSHARED_PRIVATE_EXPORT TextureDataManager
+ : public GeneratorDataManager<QTextureGeneratorPtr, QTextureDataPtr, void*>
+{
+};
+
+class QT3DRENDERSHARED_PRIVATE_EXPORT TextureImageDataManager
+ : public GeneratorDataManager<QTextureImageDataGeneratorPtr, QTextureImageDataPtr, Qt3DCore::QNodeId>
+{
+};
+
+} // namespace Render
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
+
+#endif // TEXTUREDATAMANAGER_H
diff --git a/src/render/texture/textureimage_p.h b/src/render/texture/textureimage_p.h
index ced8f1ad2..42ef242a7 100644
--- a/src/render/texture/textureimage_p.h
+++ b/src/render/texture/textureimage_p.h
@@ -70,7 +70,7 @@ class TextureImageDataManager;
* Backend class for QAbstractTextureImage.
* Will only hold the generator and some info values.
*/
-class Q_AUTOTEST_EXPORT TextureImage : public BackendNode
+class Q_3DRENDERSHARED_PRIVATE_EXPORT TextureImage : public BackendNode
{
public:
TextureImage();