summaryrefslogtreecommitdiffstats
path: root/src/render/backend
diff options
context:
space:
mode:
authorWieland Hagen <wieland.hagen@kdab.com>2016-04-14 20:33:21 +0200
committerSean Harmer <sean.harmer@kdab.com>2016-04-16 12:22:30 +0000
commita12f0150f873bc6cef9c6e391d0a6485f94bf772 (patch)
treede18b9f1d5e275338615b3fa60ce613520a0d7f2 /src/render/backend
parent99c62b0d7e723857d2387e7c22777710434cba02 (diff)
Consolidate some functionality into AttachmentPack.
RenderTarget attachments to DrawBuffer mapping was done in different places. For now, lets do it centrally within AttachmentPack. Change-Id: I4f6aa78a9964cd420ab67a991cb4186c15b928ee Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/backend')
-rw-r--r--src/render/backend/attachmentpack.cpp92
-rw-r--r--src/render/backend/attachmentpack_p.h29
-rw-r--r--src/render/backend/render-backend.pri3
-rw-r--r--src/render/backend/renderview.cpp5
-rw-r--r--src/render/backend/renderview_p.h5
5 files changed, 107 insertions, 27 deletions
diff --git a/src/render/backend/attachmentpack.cpp b/src/render/backend/attachmentpack.cpp
new file mode 100644
index 000000000..b438a28c0
--- /dev/null
+++ b/src/render/backend/attachmentpack.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include "attachmentpack_p.h"
+#include <Qt3DRender/private/rendertarget_p.h>
+#include <Qt3DRender/private/rendertargetselectornode_p.h>
+
+QT_BEGIN_NAMESPACE
+
+namespace Qt3DRender {
+namespace Render {
+
+AttachmentPack::AttachmentPack()
+{
+}
+
+AttachmentPack::AttachmentPack(const RenderTargetSelector *selector, const RenderTarget *target, AttachmentManager *attachmentManager)
+{
+ // Cache draw buffers list
+ const QVector<QRenderTargetOutput::AttachmentPoint> selectedAttachmentPoints = selector->outputs();
+
+ // Copy attachments
+ Q_FOREACH (Qt3DCore::QNodeId outputId, target->renderOutputs()) {
+ const RenderTargetOutput *output = attachmentManager->lookupResource(outputId);
+ if (output)
+ m_attachments.append(output->attachment());
+ }
+
+ // Create actual DrawBuffers list that is used for glDrawBuffers
+
+ // If nothing is specified, use all the attachments as draw buffers
+ if (selectedAttachmentPoints.isEmpty()) {
+ for (const Attachment &attachment : qAsConst(m_attachments))
+ // only consider Color Attachments
+ if (attachment.m_point <= QRenderTargetOutput::Color15)
+ m_drawBuffers.push_back((int) attachment.m_point);
+ } else {
+ for (QRenderTargetOutput::AttachmentPoint drawBuffer : selectedAttachmentPoints)
+ if (drawBuffer <= QRenderTargetOutput::Color15)
+ m_drawBuffers.push_back((int) drawBuffer);
+ }
+}
+
+// return index of given attachment within actual draw buffers list
+int AttachmentPack::getDrawBufferIndex(QRenderTargetOutput::AttachmentPoint attachmentPoint) const
+{
+ for (int i = 0; i < m_drawBuffers.size(); i++)
+ if (m_drawBuffers.at(i) == (int)attachmentPoint)
+ return i;
+ return -1;
+}
+
+} // namespace Render
+} // namespace Qt3DRender
+
+QT_END_NAMESPACE
diff --git a/src/render/backend/attachmentpack_p.h b/src/render/backend/attachmentpack_p.h
index cdcdb2b4f..98362149a 100644
--- a/src/render/backend/attachmentpack_p.h
+++ b/src/render/backend/attachmentpack_p.h
@@ -76,32 +76,25 @@ struct Attachment
QAbstractTexture::CubeMapFace m_face;
};
+class RenderTarget;
+class RenderTargetSelector;
+class AttachmentManager;
+
class AttachmentPack
{
public:
- void addAttachment(const Attachment &attachment)
- {
- m_attachments.append(attachment);
- }
-
- QVector<Attachment> attachments() const
- {
- return m_attachments;
- }
+ AttachmentPack();
+ AttachmentPack(const RenderTargetSelector *selector, const RenderTarget *target, AttachmentManager *attachmentManager);
- QVector<QRenderTargetOutput::AttachmentPoint> drawBuffers() const
- {
- return m_drawBuffers;
- }
+ QVector<Attachment> attachments() const { return m_attachments; }
+ QVector<int> getGlDrawBuffers() const { return m_drawBuffers; }
- void setDrawBuffers(const QVector<QRenderTargetOutput::AttachmentPoint> &drawBuffers)
- {
- m_drawBuffers = drawBuffers;
- }
+ // return index of given attachment within actual draw buffers list
+ int getDrawBufferIndex(QRenderTargetOutput::AttachmentPoint attachmentPoint) const;
private:
QVector<Attachment> m_attachments;
- QVector<QRenderTargetOutput::AttachmentPoint> m_drawBuffers;
+ QVector<int> m_drawBuffers;
};
} // namespace Render
diff --git a/src/render/backend/render-backend.pri b/src/render/backend/render-backend.pri
index 93c8381da..ae8bd094f 100644
--- a/src/render/backend/render-backend.pri
+++ b/src/render/backend/render-backend.pri
@@ -61,5 +61,6 @@ SOURCES += \
$$PWD/rendersettings.cpp \
$$PWD/stringtoint.cpp \
$$PWD/backendnode.cpp \
- $$PWD/rendertargetoutput.cpp
+ $$PWD/rendertargetoutput.cpp \
+ $$PWD/attachmentpack.cpp
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp
index fa74b8ea2..d65c70026 100644
--- a/src/render/backend/renderview.cpp
+++ b/src/render/backend/renderview.cpp
@@ -607,11 +607,6 @@ void RenderView::buildComputeRenderCommands(Entity *node)
}
}
-const AttachmentPack &RenderView::attachmentPack() const
-{
- return m_attachmentPack;
-}
-
void RenderView::setUniformValue(ShaderParameterPack &uniformPack, int nameId, const QVariant &value)
{
Texture *tex = Q_NULLPTR;
diff --git a/src/render/backend/renderview_p.h b/src/render/backend/renderview_p.h
index 34a2219e6..de2587ccc 100644
--- a/src/render/backend/renderview_p.h
+++ b/src/render/backend/renderview_p.h
@@ -236,9 +236,8 @@ public:
QVector<RenderCommand *> commands() const { return m_commands; }
void gatherLights(Entity *preprocessedTreeRoot);
- void addRenderAttachment(Attachment attachment) { m_attachmentPack.addAttachment(attachment); }
- void setDrawBuffers(const QVector<QRenderTargetOutput::AttachmentPoint> &drawBuffers) { m_attachmentPack.setDrawBuffers(drawBuffers); }
- const AttachmentPack &attachmentPack() const;
+ void setAttachmentPack(const AttachmentPack &pack) { m_attachmentPack = pack; }
+ const AttachmentPack &attachmentPack() const { return m_attachmentPack; }
void setRenderTargetHandle(HTarget renderTargetHandle) Q_DECL_NOEXCEPT { m_renderTarget = renderTargetHandle; }
HTarget renderTargetHandle() const Q_DECL_NOEXCEPT { return m_renderTarget; }