diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2014-08-28 20:18:16 +0200 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2014-08-29 12:48:19 +0200 |
commit | f9023457dc6c4dda436f690cd9863b3e4238a7d9 (patch) | |
tree | 912080ebbaccb14739aad17f616150b9261d172f /src/render/backend/rendertarget.cpp | |
parent | 7771d548adcf94424b169ac02922a611bf694bae (diff) |
RenderTarget backend class
Change-Id: I914267b6efb9e99976172a795be5d2f17b2b3230
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/backend/rendertarget.cpp')
-rw-r--r-- | src/render/backend/rendertarget.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/src/render/backend/rendertarget.cpp b/src/render/backend/rendertarget.cpp new file mode 100644 index 000000000..dca2e00b0 --- /dev/null +++ b/src/render/backend/rendertarget.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: http://www.qt-project.org/legal +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 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 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <Qt3DRenderer/private/rendertarget_p.h> +#include <Qt3DCore/qchangearbiter.h> +#include <Qt3DCore/qaspectmanager.h> +#include <Qt3DCore/qscenepropertychange.h> +#include <Qt3DRenderer/qrendertarget.h> +#include <Qt3DRenderer/qrenderattachment.h> +#include <Qt3DRenderer/private/renderer_p.h> +#include <Qt3DRenderer/rendereraspect.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3D { + +namespace Render { + +RenderTarget::RenderTarget() + : m_renderer(Q_NULLPTR) +{ +} + +void RenderTarget::setPeer(QRenderTarget *peer) +{ + QUuid peerUuid; + + if (peer != Q_NULLPTR) + peerUuid = peer->uuid(); + if (peerUuid != m_renderTargetUuid) { + QChangeArbiter *arbiter = m_renderer->rendererAspect()->aspectManager()->changeArbiter(); + if (!m_renderTargetUuid.isNull()) { + arbiter->unregisterObserver(this, m_renderTargetUuid); + m_renderAttachments.clear(); + } + m_renderTargetUuid = peerUuid; + if (!m_renderTargetUuid.isNull()) { + arbiter->registerObserver(this, m_renderTargetUuid, NodeAdded|NodeRemoved|ComponentUpdated); + Q_FOREACH (QRenderAttachment *att, peer->attachments()) + appendRenderAttachment(att); + } + } +} + +void RenderTarget::setRenderer(Renderer *renderer) +{ + m_renderer = renderer; +} + +void RenderTarget::appendRenderAttachment(QRenderAttachment *attachment) +{ + if (!m_renderAttachments.contains(attachment->uuid())) + m_renderAttachments.append(attachment->uuid()); +} + +void RenderTarget::removeRenderAttachment(const QUuid &attachmentId) +{ + m_renderAttachments.removeOne(attachmentId); +} + +QList<QUuid> RenderTarget::renderAttachments() const +{ + return m_renderAttachments; +} + +QUuid RenderTarget::renderTargetUuid() const +{ + return m_renderTargetUuid; +} + +void RenderTarget::sceneChangeEvent(const QSceneChangePtr &e) +{ + QScenePropertyChangePtr propertyChange = qSharedPointerCast<QScenePropertyChange>(e); + if (e->type() == NodeAdded && propertyChange->propertyName() == QByteArrayLiteral("attachment")) + appendRenderAttachment(propertyChange->value().value<QRenderAttachment *>()); + else if (e->type() == NodeRemoved && propertyChange->propertyName() == QByteArrayLiteral("attachment")) + removeRenderAttachment(propertyChange->value().value<QRenderAttachment *>()->uuid()); +} + +} // Render + +} // Qt3D + +QT_END_NAMESPACE |