diff options
author | Antti Määttä <antti.maatta@qt.io> | 2016-11-02 11:52:35 +0200 |
---|---|---|
committer | Antti Määttä <antti.maatta@qt.io> | 2017-01-20 11:20:11 +0000 |
commit | 3aafff6a72ca6a1f9c408f33fc18f28edf07a645 (patch) | |
tree | 74f02134ea727fe6bc107b6f462e153b051706d2 | |
parent | 97d8a7bff44af94b4a92624e9431e6e49505432e (diff) | |
download | qt3d-3aafff6a72ca6a1f9c408f33fc18f28edf07a645.tar.gz |
Add resource accessor
Change-Id: Ibeef96469e7bb3bc523300ea72d55a283e13ff79
Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
-rw-r--r-- | src/render/backend/render-backend.pri | 6 | ||||
-rw-r--r-- | src/render/backend/resourceaccessor.cpp | 94 | ||||
-rw-r--r-- | src/render/backend/resourceaccessor_p.h | 93 |
3 files changed, 191 insertions, 2 deletions
diff --git a/src/render/backend/render-backend.pri b/src/render/backend/render-backend.pri index 8cd904efd..91efe9cd2 100644 --- a/src/render/backend/render-backend.pri +++ b/src/render/backend/render-backend.pri @@ -40,7 +40,8 @@ HEADERS += \ $$PWD/shaderparameterpack_p.h \ $$PWD/renderviewbuilder_p.h \ $$PWD/frameprofiler_p.h \ - $$PWD/offscreensurfacehelper_p.h + $$PWD/offscreensurfacehelper_p.h \ + $$PWD/resourceaccessor_p.h SOURCES += \ $$PWD/renderthread.cpp \ @@ -73,5 +74,6 @@ SOURCES += \ $$PWD/uniform.cpp \ $$PWD/shaderparameterpack.cpp \ $$PWD/renderviewbuilder.cpp \ - $$PWD/offscreensurfacehelper.cpp + $$PWD/offscreensurfacehelper.cpp \ + $$PWD/resourceaccessor.cpp diff --git a/src/render/backend/resourceaccessor.cpp b/src/render/backend/resourceaccessor.cpp new file mode 100644 index 000000000..c02130aa9 --- /dev/null +++ b/src/render/backend/resourceaccessor.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** 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 http://www.qt.io/terms-conditions. For further +** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "resourceaccessor_p.h" + +#include <Qt3DRender/qrendertargetoutput.h> + +#include <private/qrendertargetoutput_p.h> +#include <private/nodemanagers_p.h> +#include <private/texture_p.h> +#include <private/rendertargetoutput_p.h> +#include <private/texturedatamanager_p.h> +#include <private/gltexturemanager_p.h> +#include <private/managers_p.h> +#include <private/gltexture_p.h> + +#include <QtCore/qmutex.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +ResourceAccessor::ResourceAccessor(NodeManagers *mgr) + : m_textureManager(mgr->textureManager()) + , m_attachmentManager(mgr->attachmentManager()) + , m_glTextureManager(mgr->glTextureManager()) +{ + +} + +// called by render plugins from arbitrary thread +bool ResourceAccessor::accessResource(Qt3DCore::QNodeId nodeId, void **handle, QMutex **lock) +{ + Texture *tex = m_textureManager->lookupResource(nodeId); + if (!tex) { + RenderTargetOutput *output = m_attachmentManager->lookupResource(nodeId); + if (!output) + return false; + + Attachment **attachmentData = reinterpret_cast<Attachment **>(handle); + *attachmentData = output->attachment(); + return true; + } + GLTexture *glTex = m_glTextureManager->lookupResource(tex->peerId()); + if (!glTex) + return false; + + if (glTex->isDirty()) + return false; + + QOpenGLTexture** glTextureHandle = reinterpret_cast<QOpenGLTexture **>(handle); + *glTextureHandle = glTex->getOrCreateGLTexture(); + *lock = glTex->textureLock(); + return true; +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/backend/resourceaccessor_p.h b/src/render/backend/resourceaccessor_p.h new file mode 100644 index 000000000..653a8adda --- /dev/null +++ b/src/render/backend/resourceaccessor_p.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd and/or its subsidiary(-ies). +** 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_RESOURCEACCESSOR_P_H +#define QT3DRENDER_RENDER_RESOURCEACCESSOR_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 <Qt3DCore/qnodeid.h> + +#include <private/qt3drender_global_p.h> + +QT_BEGIN_NAMESPACE + +class QMutex; + +namespace Qt3DRender +{ +namespace Render { + +class TextureManager; +class AttachmentManager; +class GLTextureManager; +class NodeManagers; + +class RenderBackendResourceAccessor +{ +public: + virtual bool accessResource(Qt3DCore::QNodeId nodeId, void **handle, QMutex **lock) = 0; +}; + +class QT3DRENDERSHARED_PRIVATE_EXPORT ResourceAccessor : public RenderBackendResourceAccessor +{ +public: + ResourceAccessor(NodeManagers *mgr); + bool accessResource(Qt3DCore::QNodeId nodeId, void **handle, QMutex **lock) Q_DECL_FINAL; +private: + GLTextureManager *m_glTextureManager; + TextureManager *m_textureManager; + AttachmentManager *m_attachmentManager; +}; + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +#endif // QT3DRENDER_RENDER_RESOURCEACCESSOR_P_H |