summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-03-30 10:08:35 +0200
committerPaul Lemire <paul.lemire@kdab.com>2015-05-10 12:25:13 +0000
commitbe1bf4bd32d170b2066cadae6e929f7a46d5e222 (patch)
treec5ed91f79aa339a88e0d3c5d5c5c8f24fc0100a4
parent092f86e5bad3101b760cda33d499a3aa736fbb2e (diff)
Renderer: glDrawBuffers using QRenderTargetSelector drawBuffer
Change-Id: I760401c7749ca97801e2254cda6b306b1748e10d Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
-rw-r--r--src/render/backend/attachmentpack.cpp10
-rw-r--r--src/render/backend/attachmentpack_p.h4
-rw-r--r--src/render/backend/jobs/renderviewjobutils.cpp9
-rw-r--r--src/render/backend/qgraphicscontext.cpp31
-rw-r--r--src/render/backend/qgraphicscontext_p.h1
-rw-r--r--src/render/backend/renderview_p.h1
6 files changed, 49 insertions, 7 deletions
diff --git a/src/render/backend/attachmentpack.cpp b/src/render/backend/attachmentpack.cpp
index 03bd723e3..95bdb3c0c 100644
--- a/src/render/backend/attachmentpack.cpp
+++ b/src/render/backend/attachmentpack.cpp
@@ -56,6 +56,16 @@ QVector<Attachment> AttachmentPack::attachments() const
return m_attachments;
}
+QList<QRenderAttachment::RenderAttachmentType> AttachmentPack::drawBuffers() const
+{
+ return m_drawBuffers;
+}
+
+void AttachmentPack::setDrawBuffers(const QList<QRenderAttachment::RenderAttachmentType> &drawBuffers)
+{
+ m_drawBuffers = drawBuffers;
+}
+
Attachment::Attachment()
: m_mipLevel(0)
, m_layer(0)
diff --git a/src/render/backend/attachmentpack_p.h b/src/render/backend/attachmentpack_p.h
index c2fcb34e4..74c5d6430 100644
--- a/src/render/backend/attachmentpack_p.h
+++ b/src/render/backend/attachmentpack_p.h
@@ -64,9 +64,13 @@ public:
void addAttachment(const Attachment &attachment);
QVector<Attachment> attachments() const;
+ QList<QRenderAttachment::RenderAttachmentType> drawBuffers() const;
+
+ void setDrawBuffers(const QList<QRenderAttachment::RenderAttachmentType> &drawBuffers);
private:
QVector<Attachment> m_attachments;
+ QList<QRenderAttachment::RenderAttachmentType> m_drawBuffers;
};
} // Render
diff --git a/src/render/backend/jobs/renderviewjobutils.cpp b/src/render/backend/jobs/renderviewjobutils.cpp
index 22725eb06..d16d124a9 100644
--- a/src/render/backend/jobs/renderviewjobutils.cpp
+++ b/src/render/backend/jobs/renderviewjobutils.cpp
@@ -112,7 +112,8 @@ void setRenderViewConfigFromFrameGraphLeafNode(RenderView *rv, const FrameGraphN
case FrameGraphNode::RenderTarget: {
// Can be set once and we take render target nearest to the leaf node
- QNodeId renderTargetUid = static_cast<const RenderTargetSelector *>(node)->renderTargetUuid();
+ const RenderTargetSelector *targetSelector = static_cast<const RenderTargetSelector *>(node);
+ QNodeId renderTargetUid = targetSelector->renderTargetUuid();
HTarget renderTargetHandle = renderer->renderTargetManager()->lookupHandle(renderTargetUid);
if (rv->renderTargetHandle().isNull()) {
rv->setRenderTargetHandle(renderTargetHandle);
@@ -120,11 +121,17 @@ void setRenderViewConfigFromFrameGraphLeafNode(RenderView *rv, const FrameGraphN
RenderTarget *renderTarget = renderer->renderTargetManager()->data(renderTargetHandle);
if (renderTarget) {
// Add renderTarget Handle and build renderCommand AttachmentPack
+
+ // Copy draw buffers list
+ rv->setDrawBuffers(targetSelector->drawBuffers());
+
+ // Copy attachments
Q_FOREACH (const QNodeId &attachmentId, renderTarget->renderAttachments()) {
RenderAttachment *attachment = renderer->attachmentManager()->lookupResource(attachmentId);
if (attachment)
rv->addRenderAttachment(attachment->attachment());
}
+
}
}
break;
diff --git a/src/render/backend/qgraphicscontext.cpp b/src/render/backend/qgraphicscontext.cpp
index 166893f8c..e42bcbfac 100644
--- a/src/render/backend/qgraphicscontext.cpp
+++ b/src/render/backend/qgraphicscontext.cpp
@@ -328,13 +328,14 @@ void QGraphicsContext::activateRenderTarget(RenderTarget *renderTarget, const At
}
m_activeFBO = fboId;
m_glHelper->bindFrameBufferObject(m_activeFBO);
+ // Set active drawBuffers
+ activateDrawBuffers(attachments);
}
void QGraphicsContext::bindFrameBufferAttachmentHelper(GLuint fboId, const AttachmentPack &attachments)
{
// Set FBO attachments
- int drawBuffers[QRenderAttachment::ColorAttachment15 + 1];
- int i = 0;
+
QSize fboSize;
Q_FOREACH (const Attachment &attachment, attachments.attachments()) {
RenderTexture *rTex = m_renderer->textureManager()->lookupResource(attachment.m_textureUuid);
@@ -346,23 +347,41 @@ void QGraphicsContext::bindFrameBufferAttachmentHelper(GLuint fboId, const Attac
else
fboSize = QSize(qMin(fboSize.width(), glTex->width()), qMin(fboSize.width(), glTex->width()));
m_glHelper->bindFrameBufferAttachment(glTex, attachment);
- if (attachment.m_type <= QRenderAttachment::ColorAttachment15)
- drawBuffers[i++] = attachment.m_type;
}
}
}
+ m_renderTargetsSize.insert(fboId, fboSize);
+}
+
+void QGraphicsContext::activateDrawBuffers(const AttachmentPack &attachments)
+{
+ int activeDrawBuffers[QRenderAttachment::ColorAttachment15 + 1];
+ int i = 0;
+
+ const QList<QRenderAttachment::RenderAttachmentType> &drawBuffers = attachments.drawBuffers();
+
+ // If drawBuffers is empty, use all the attachments as draw buffers
+ if (drawBuffers.isEmpty()) {
+ Q_FOREACH (const Attachment &attachment, attachments.attachments())
+ if (attachment.m_type <= QRenderAttachment::ColorAttachment15)
+ activeDrawBuffers[i++] = attachment.m_type;
+ } else {
+ Q_FOREACH (const QRenderAttachment::RenderAttachmentType drawBuffer, drawBuffers)
+ if (drawBuffer <= QRenderAttachment::ColorAttachment15)
+ activeDrawBuffers[i++] = drawBuffer;
+ }
+
if (m_glHelper->checkFrameBufferComplete()) {
if (i > 1) {// We need MRT
if (m_glHelper->supportsFeature(QGraphicsHelperInterface::MRT)) {
// Set up MRT, glDrawBuffers...
- m_glHelper->drawBuffers(i, drawBuffers);
+ m_glHelper->drawBuffers(i, activeDrawBuffers);
}
qDebug() << "FBO Complete";
}
} else {
qWarning() << "FBO incomplete";
}
- m_renderTargetsSize.insert(fboId, fboSize);
}
diff --git a/src/render/backend/qgraphicscontext_p.h b/src/render/backend/qgraphicscontext_p.h
index 6cae74612..b2796e72e 100644
--- a/src/render/backend/qgraphicscontext_p.h
+++ b/src/render/backend/qgraphicscontext_p.h
@@ -197,6 +197,7 @@ private:
void resolveHighestOpenGLFunctions();
void bindFrameBufferAttachmentHelper(GLuint fboId, const AttachmentPack &attachments);
+ void activateDrawBuffers(const AttachmentPack &attachments);
bool m_initialized;
const unsigned int m_id;
diff --git a/src/render/backend/renderview_p.h b/src/render/backend/renderview_p.h
index 029a11f62..67bb57cef 100644
--- a/src/render/backend/renderview_p.h
+++ b/src/render/backend/renderview_p.h
@@ -185,6 +185,7 @@ public:
int frameIndex() const { return m_frameIndex; }
void addRenderAttachment(Attachment attachment) { m_attachmentPack.addAttachment(attachment); }
+ void setDrawBuffers(const QList<QRenderAttachment::RenderAttachmentType> &drawBuffers) { m_attachmentPack.setDrawBuffers(drawBuffers); }
const AttachmentPack &attachmentPack() const;
void setRenderTargetHandle(HTarget renderTargetHandle) { m_renderTarget = renderTargetHandle; }