summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2015-05-13 10:36:05 +0200
committerPaul Lemire <paul.lemire@kdab.com>2015-05-15 09:10:51 +0000
commit298c9012a1c564ce6b6a40af012ebf5c8f1b9d57 (patch)
treec9469ffcb394da05ca68514ad637cb865942df08
parent214e1bf2ed8fb4fd6407d4cd7f8565e53f1bb2ca (diff)
Allow to have different clearColor per RenderView
Previously the clearColor was the same for the whole frame using the first RenderView's clear color. In some cases (FBO rendering) we may want the renderer to set/update the clear color between RenderViews. Change-Id: I85318d10a8ae0b03a8e5576ec39e15b14f1bc21d Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
-rw-r--r--src/render/backend/qgraphicscontext.cpp9
-rw-r--r--src/render/backend/qgraphicscontext_p.h3
-rw-r--r--src/render/backend/renderer.cpp10
3 files changed, 18 insertions, 4 deletions
diff --git a/src/render/backend/qgraphicscontext.cpp b/src/render/backend/qgraphicscontext.cpp
index e42bcbfac..1280f8439 100644
--- a/src/render/backend/qgraphicscontext.cpp
+++ b/src/render/backend/qgraphicscontext.cpp
@@ -132,7 +132,7 @@ void QGraphicsContext::initialize()
qCDebug(Backend) << "VAO support = " << m_supportsVAO;
}
-bool QGraphicsContext::beginDrawing(QSurface *surface, const QColor &clearColor)
+bool QGraphicsContext::beginDrawing(QSurface *surface, const QColor &color)
{
Q_ASSERT(surface);
Q_ASSERT(m_gl);
@@ -156,7 +156,7 @@ bool QGraphicsContext::beginDrawing(QSurface *surface, const QColor &clearColor)
initialize();
}
- m_gl->functions()->glClearColor(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), clearColor.alphaF());
+ clearColor(color);
if (m_activeShader)
m_activeShader = NULL;
@@ -651,6 +651,11 @@ GLuint QGraphicsContext::boundFrameBufferObject()
return m_glHelper->boundFrameBufferObject();
}
+void QGraphicsContext::clearColor(const QColor &color)
+{
+ m_gl->functions()->glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF());
+}
+
/*!
\internal
\returns a texture unit for a texture, -1 if all texture units are assigned.
diff --git a/src/render/backend/qgraphicscontext_p.h b/src/render/backend/qgraphicscontext_p.h
index b2796e72e..33eaff7a3 100644
--- a/src/render/backend/qgraphicscontext_p.h
+++ b/src/render/backend/qgraphicscontext_p.h
@@ -90,7 +90,7 @@ public:
int id() const; // unique, small integer ID of this context
- bool beginDrawing(QSurface *surface, const QColor &clearColor);
+ bool beginDrawing(QSurface *surface, const QColor &color);
void clearBackBuffer(QClearBuffer::BufferType buffers);
void endDrawing(bool swapBuffers);
@@ -178,6 +178,7 @@ public:
void enableAlphaCoverage();
void disableAlphaCoverage();
GLuint boundFrameBufferObject();
+ void clearColor(const QColor &color);
// Helper methods
static GLint elementType(GLint type);
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp
index f11f0e2df..78805c47e 100644
--- a/src/render/backend/renderer.cpp
+++ b/src/render/backend/renderer.cpp
@@ -596,8 +596,9 @@ void Renderer::submitRenderViews(int maxFrameCount)
if (renderViewsCount <= 0)
continue;
+ QColor previousClearColor = renderViews.first()->clearColor();
// Bail out if we cannot make the OpenGL context current (e.g. if the window has been destroyed)
- if (!m_graphicsContext->beginDrawing(m_surface, renderViews.first()->clearColor())) {
+ if (!m_graphicsContext->beginDrawing(m_surface, previousClearColor)) {
qDeleteAll(renderViews);
m_renderQueues->popFrameQueue();
break;
@@ -622,6 +623,13 @@ void Renderer::submitRenderViews(int maxFrameCount)
// Activate RenderTarget
m_graphicsContext->activateRenderTarget(m_renderTargetManager->data(renderViews[i]->renderTargetHandle()),
renderViews[i]->attachmentPack(), defaultFboId);
+
+ // Set clear color if different
+ if (previousClearColor != renderViews[i]->clearColor()) {
+ previousClearColor = renderViews[i]->clearColor();
+ m_graphicsContext->clearColor(previousClearColor);
+ }
+
// Clear BackBuffer
m_graphicsContext->clearBackBuffer(renderViews[i]->clearBuffer());
// Set the Viewport