summaryrefslogtreecommitdiffstats
path: root/src/render/backend
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2018-03-02 10:27:07 +0100
committerPaul Lemire <paul.lemire@kdab.com>2018-03-16 11:21:02 +0000
commitc1b495f70c3b4f0c23d44dfcd99aed5882312100 (patch)
treeced8484d36d999395f520f2d7262d832afc73c99 /src/render/backend
parent02dff327fae71d6efdda091f8ae0a4483e72e849 (diff)
Split GraphicsContext in two
- GraphicsContext is now a stateless wrapper around GL calls - SubmissionContext is a GraphicsContext + caches and states used to render a frame Change-Id: I147b56dfd4c403911faadc0e9821fff9a892f71c Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/render/backend')
-rw-r--r--src/render/backend/commandexecuter.cpp3
-rw-r--r--src/render/backend/offscreensurfacehelper_p.h2
-rw-r--r--src/render/backend/openglvertexarrayobject.cpp12
-rw-r--r--src/render/backend/openglvertexarrayobject_p.h14
-rw-r--r--src/render/backend/renderer.cpp167
-rw-r--r--src/render/backend/renderer_p.h8
6 files changed, 106 insertions, 100 deletions
diff --git a/src/render/backend/commandexecuter.cpp b/src/render/backend/commandexecuter.cpp
index cd1ec0e2b..182ba89d1 100644
--- a/src/render/backend/commandexecuter.cpp
+++ b/src/render/backend/commandexecuter.cpp
@@ -45,6 +45,7 @@
#include <Qt3DRender/private/nodemanagers_p.h>
#include <Qt3DRender/private/geometryrenderermanager_p.h>
#include <Qt3DRender/private/stringtoint_p.h>
+#include <Qt3DRender/private/submissioncontext_p.h>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
@@ -310,7 +311,7 @@ void CommandExecuter::performAsynchronousCommandExecution(const QVector<Render::
for (auto *reply : shellCommands) {
if (reply->commandName() == QLatin1String("glinfo")) {
QJsonObject replyObj;
- const GraphicsApiFilterData *contextInfo = m_renderer->m_graphicsContext->contextInfo();
+ const GraphicsApiFilterData *contextInfo = m_renderer->submissionContext()->contextInfo();
if (contextInfo != nullptr) {
replyObj.insert(QLatin1String("api"),
contextInfo->m_api == QGraphicsApiFilter::OpenGL
diff --git a/src/render/backend/offscreensurfacehelper_p.h b/src/render/backend/offscreensurfacehelper_p.h
index a2c383162..8dc86d9a4 100644
--- a/src/render/backend/offscreensurfacehelper_p.h
+++ b/src/render/backend/offscreensurfacehelper_p.h
@@ -62,7 +62,7 @@ namespace Render {
class AbstractRenderer;
-class OffscreenSurfaceHelper : public QObject
+class Q_AUTOTEST_EXPORT OffscreenSurfaceHelper : public QObject
{
Q_OBJECT
public:
diff --git a/src/render/backend/openglvertexarrayobject.cpp b/src/render/backend/openglvertexarrayobject.cpp
index c0fdd8e65..0c4fd8c9d 100644
--- a/src/render/backend/openglvertexarrayobject.cpp
+++ b/src/render/backend/openglvertexarrayobject.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "openglvertexarrayobject_p.h"
-#include <Qt3DRender/private/graphicscontext_p.h>
+#include <Qt3DRender/private/submissioncontext_p.h>
#include <Qt3DRender/private/renderer_p.h>
#include <Qt3DRender/private/nodemanagers_p.h>
#include <Qt3DRender/private/managers_p.h>
@@ -68,7 +68,7 @@ void OpenGLVertexArrayObject::bind()
m_ctx->m_currentVAO = this;
// We need to specify array and vertex attributes
- for (const GraphicsContext::VAOVertexAttribute &attr : qAsConst(m_vertexAttributes))
+ for (const SubmissionContext::VAOVertexAttribute &attr : qAsConst(m_vertexAttributes))
m_ctx->enableAttribute(attr);
if (!m_indexAttribute.isNull())
m_ctx->bindGLBuffer(m_ctx->m_renderer->nodeManagers()->glBufferManager()->data(m_indexAttribute),
@@ -85,7 +85,7 @@ void OpenGLVertexArrayObject::release()
m_vao->release();
} else {
if (m_ctx->m_currentVAO == this) {
- for (const GraphicsContext::VAOVertexAttribute &attr : qAsConst(m_vertexAttributes))
+ for (const SubmissionContext::VAOVertexAttribute &attr : qAsConst(m_vertexAttributes))
m_ctx->disableAttribute(attr);
m_ctx->m_currentVAO = nullptr;
}
@@ -93,7 +93,7 @@ void OpenGLVertexArrayObject::release()
}
// called from Render thread
-void OpenGLVertexArrayObject::create(GraphicsContext *ctx, const VAOIdentifier &key)
+void OpenGLVertexArrayObject::create(SubmissionContext *ctx, const VAOIdentifier &key)
{
QMutexLocker lock(&m_mutex);
@@ -123,7 +123,7 @@ void OpenGLVertexArrayObject::cleanup()
m_ctx = nullptr;
m_specified = false;
m_supportsVao = false;
- m_indexAttribute = GraphicsContext::VAOIndexAttribute();
+ m_indexAttribute = SubmissionContext::VAOIndexAttribute();
m_vertexAttributes.clear();
}
@@ -141,7 +141,7 @@ bool OpenGLVertexArrayObject::isAbandoned(GeometryManager *geomMgr, ShaderManage
return !geometryExists || !shaderExists;
}
-void OpenGLVertexArrayObject::saveVertexAttribute(const GraphicsContext::VAOVertexAttribute &attr)
+void OpenGLVertexArrayObject::saveVertexAttribute(const SubmissionContext::VAOVertexAttribute &attr)
{
// Remove any vertexAttribute already at location
for (auto i = m_vertexAttributes.size() - 1; i >= 0; --i) {
diff --git a/src/render/backend/openglvertexarrayobject_p.h b/src/render/backend/openglvertexarrayobject_p.h
index a564175f6..eee837221 100644
--- a/src/render/backend/openglvertexarrayobject_p.h
+++ b/src/render/backend/openglvertexarrayobject_p.h
@@ -52,7 +52,7 @@
//
#include <QtGui/qopenglvertexarrayobject.h>
-#include <Qt3DRender/private/graphicscontext_p.h>
+#include <Qt3DRender/private/submissioncontext_p.h>
QT_BEGIN_NAMESPACE
@@ -72,7 +72,7 @@ public:
void bind();
void release();
- void create(GraphicsContext *ctx, const VAOIdentifier &key);
+ void create(SubmissionContext *ctx, const VAOIdentifier &key);
void destroy();
void cleanup();
@@ -87,19 +87,19 @@ public:
private:
QMutex m_mutex;
- GraphicsContext *m_ctx;
+ SubmissionContext *m_ctx;
QScopedPointer<QOpenGLVertexArrayObject> m_vao;
bool m_specified;
bool m_supportsVao;
VAOIdentifier m_owners;
- friend class GraphicsContext;
+ friend class SubmissionContext;
- void saveVertexAttribute(const GraphicsContext::VAOVertexAttribute &attr);
+ void saveVertexAttribute(const SubmissionContext::VAOVertexAttribute &attr);
inline void saveIndexAttribute(HGLBuffer glBufferHandle) { m_indexAttribute = glBufferHandle; }
- QVector<GraphicsContext::VAOVertexAttribute> m_vertexAttributes;
- GraphicsContext::VAOIndexAttribute m_indexAttribute;
+ QVector<SubmissionContext::VAOVertexAttribute> m_vertexAttributes;
+ SubmissionContext::VAOIndexAttribute m_indexAttribute;
};
} // namespace Render
diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp
index 68b6dd1fd..cdec9af01 100644
--- a/src/render/backend/renderer.cpp
+++ b/src/render/backend/renderer.cpp
@@ -156,7 +156,7 @@ Renderer::Renderer(QRenderAspect::RenderType type)
, m_nodesManager(nullptr)
, m_renderSceneRoot(nullptr)
, m_defaultRenderStateSet(nullptr)
- , m_graphicsContext(nullptr)
+ , m_submissionContext(nullptr)
, m_renderQueue(new RenderQueue())
, m_renderThread(type == QRenderAspect::Threaded ? new RenderThread(this) : nullptr)
, m_commandThread(new CommandThread(this))
@@ -167,6 +167,7 @@ Renderer::Renderer(QRenderAspect::RenderType type)
, m_lastFrameCorrect(0)
, m_glContext(nullptr)
, m_shareContext(nullptr)
+ , m_shaderCache(new ShaderCache())
, m_pickBoundingVolumeJob(PickBoundingVolumeJobPtr::create())
, m_rayCastingJob(RayCastingJobPtr::create())
, m_time(0)
@@ -242,6 +243,7 @@ Renderer::~Renderer()
delete m_renderQueue;
delete m_defaultRenderStateSet;
+ delete m_shaderCache;
if (!m_ownedContext)
QObject::disconnect(m_contextConnection);
@@ -314,8 +316,8 @@ QOpenGLContext *Renderer::shareContext() const
{
QMutexLocker lock(&m_shareContextMutex);
return m_shareContext ? m_shareContext
- : (m_graphicsContext->openGLContext()
- ? m_graphicsContext->openGLContext()->shareContext()
+ : (m_submissionContext->openGLContext()
+ ? m_submissionContext->openGLContext()->shareContext()
: nullptr);
}
@@ -334,8 +336,8 @@ void Renderer::setOpenGLContext(QOpenGLContext *context)
// method termintates
void Renderer::initialize()
{
- m_graphicsContext.reset(new GraphicsContext);
- m_graphicsContext->setRenderer(this);
+ m_submissionContext.reset(new SubmissionContext);
+ m_submissionContext->setRenderer(this);
QOpenGLContext* ctx = m_glContext;
@@ -376,22 +378,22 @@ void Renderer::initialize()
m_shareContext->create();
}
+ // Set shader cache on submission context and command thread
+ m_submissionContext->setShaderCache(m_shaderCache);
+
// Note: we don't have a surface at this point
// The context will be made current later on (at render time)
- m_graphicsContext->setOpenGLContext(ctx);
-
- // Initialize command thread
- m_commandThread->initialize(ctx);
+ m_submissionContext->setOpenGLContext(ctx);
+
+ // Store the format used by the context and queue up creating an
+ // offscreen surface in the main thread so that it is available
+ // for use when we want to shutdown the renderer. We need to create
+ // the offscreen surface on the main thread because on some platforms
+ // (MS Windows), an offscreen surface is just a hidden QWindow.
+ m_format = ctx->format();
+ QMetaObject::invokeMethod(m_offscreenHelper, "createOffscreenSurface");
}
- // Store the format used by the context and queue up creating an
- // offscreen surface in the main thread so that it is available
- // for use when we want to shutdown the renderer. We need to create
- // the offscreen surface on the main thread because on some platforms
- // (MS Windows), an offscreen surface is just a hidden QWindow.
- m_format = ctx->format();
- QMetaObject::invokeMethod(m_offscreenHelper, "createOffscreenSurface");
-
// Awake setScenegraphRoot in case it was waiting
m_waitForInitializationToBeCompleted.release(1);
// Allow the aspect manager to proceed
@@ -445,7 +447,7 @@ void Renderer::releaseGraphicsResources()
// We may get called twice when running inside of a Scene3D. Once when Qt Quick
// wants to shutdown, and again when the render aspect gets unregistered. So
// check that we haven't already cleaned up before going any further.
- if (!m_graphicsContext)
+ if (!m_submissionContext)
return;
// Try to temporarily make the context current so we can free up any resources
@@ -456,7 +458,7 @@ void Renderer::releaseGraphicsResources()
return;
}
- QOpenGLContext *context = m_graphicsContext->openGLContext();
+ QOpenGLContext *context = m_submissionContext->openGLContext();
Q_ASSERT(context);
if (context->makeCurrent(offscreenSurface)) {
@@ -469,7 +471,7 @@ void Renderer::releaseGraphicsResources()
const QVector<HGLBuffer> activeBuffers = m_nodesManager->glBufferManager()->activeHandles();
for (const HGLBuffer &bufferHandle : activeBuffers) {
GLBuffer *buffer = m_nodesManager->glBufferManager()->data(bufferHandle);
- buffer->destroy(m_graphicsContext.data());
+ buffer->destroy(m_submissionContext.data());
}
// Do the same thing with VAOs
@@ -489,7 +491,7 @@ void Renderer::releaseGraphicsResources()
if (m_shareContext)
delete m_shareContext;
- m_graphicsContext.reset(nullptr);
+ m_submissionContext.reset(nullptr);
qCDebug(Backend) << Q_FUNC_INFO << "Renderer properly shutdown";
}
@@ -645,8 +647,8 @@ void Renderer::doRender(bool scene3dBlocking)
if (surfaceIsValid) {
// Reset state for each draw if we don't have complete control of the context
if (!m_ownedContext)
- m_graphicsContext->setCurrentStateSet(nullptr);
- beganDrawing = m_graphicsContext->beginDrawing(surface);
+ m_submissionContext->setCurrentStateSet(nullptr);
+ beganDrawing = m_submissionContext->beginDrawing(surface);
if (beganDrawing) {
// 1) Execute commands for buffer uploads, texture updates, shader loading first
updateGLResources();
@@ -734,7 +736,7 @@ void Renderer::doRender(bool scene3dBlocking)
if (beganDrawing) {
SurfaceLocker surfaceLock(submissionData.surface);
// Finish up with last surface used in the list of RenderViews
- m_graphicsContext->endDrawing(submissionData.lastBoundFBOId == m_graphicsContext->defaultFBO() && surfaceLock.isSurfaceValid());
+ m_submissionContext->endDrawing(submissionData.lastBoundFBOId == m_submissionContext->defaultFBO() && surfaceLock.isSurfaceValid());
}
}
@@ -868,7 +870,7 @@ void Renderer::prepareCommandsSubmission(const QVector<RenderView *> &renderView
if (!command->m_attributes.isEmpty() && (requiresFullVAOUpdate || requiresPartialVAOUpdate)) {
Profiling::GLTimeRecorder recorder(Profiling::VAOUpload);
// Activate shader
- m_graphicsContext->activateShader(shader->dna());
+ m_submissionContext->activateShader(shader->dna());
// Bind VAO
vao->bind();
// Update or set Attributes and Buffers for the given rGeometry and Command
@@ -1117,10 +1119,10 @@ void Renderer::updateGLResources()
Buffer *buffer = m_nodesManager->bufferManager()->data(handle);
// Forces creation if it doesn't exit
// Also note the binding point doesn't really matter here, we just upload data
- if (!m_graphicsContext->hasGLBufferForBuffer(buffer))
- m_graphicsContext->glBufferForRenderBuffer(buffer, GLBuffer::ArrayBuffer);
+ if (!m_submissionContext->hasGLBufferForBuffer(buffer))
+ m_submissionContext->glBufferForRenderBuffer(buffer, GLBuffer::ArrayBuffer);
// Update the glBuffer data
- m_graphicsContext->updateBuffer(buffer);
+ m_submissionContext->updateBuffer(buffer);
buffer->unsetDirty();
}
}
@@ -1132,7 +1134,7 @@ void Renderer::updateGLResources()
for (const HShader &handle: dirtyShaderHandles) {
Shader *shader = shaderManager->data(handle);
// Compile shader
- m_graphicsContext->loadShader(shader, shaderManager);
+ m_submissionContext->loadShader(shader, shaderManager);
}
}
@@ -1263,7 +1265,7 @@ void Renderer::downloadGLBuffers()
const QVector<HBuffer> downloadableHandles = std::move(m_downloadableBuffers);
for (const HBuffer &handle : downloadableHandles) {
Buffer *buffer = m_nodesManager->bufferManager()->data(handle);
- QByteArray content = m_graphicsContext->downloadBufferContent(buffer);
+ QByteArray content = m_submissionContext->downloadBufferContent(buffer);
m_sendBufferCaptureJob->addRequest(QPair<Buffer*, QByteArray>(buffer, content));
}
}
@@ -1283,7 +1285,7 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren
qCDebug(Memory) << Q_FUNC_INFO << "rendering frame ";
// We might not want to render on the default FBO
- uint lastBoundFBOId = m_graphicsContext->boundFrameBufferObject();
+ uint lastBoundFBOId = m_submissionContext->boundFrameBufferObject();
QSurface *surface = nullptr;
QSurface *previousSurface = nullptr;
for (const Render::RenderView *rv: renderViews) {
@@ -1319,27 +1321,27 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren
const bool surfaceHasChanged = surface != previousSurface;
if (surfaceHasChanged && previousSurface) {
- const bool swapBuffers = (lastBoundFBOId == m_graphicsContext->defaultFBO()) && PlatformSurfaceFilter::isSurfaceValid(previousSurface);
+ const bool swapBuffers = (lastBoundFBOId == m_submissionContext->defaultFBO()) && PlatformSurfaceFilter::isSurfaceValid(previousSurface);
// We only call swap buffer if we are sure the previous surface is still valid
- m_graphicsContext->endDrawing(swapBuffers);
+ m_submissionContext->endDrawing(swapBuffers);
}
if (surfaceHasChanged) {
// If we can't make the context current on the surface, skip to the
// next RenderView. We won't get the full frame but we may get something
- if (!m_graphicsContext->beginDrawing(surface)) {
+ if (!m_submissionContext->beginDrawing(surface)) {
qWarning() << "Failed to make OpenGL context current on surface";
m_lastFrameCorrect.store(0);
continue;
}
previousSurface = surface;
- lastBoundFBOId = m_graphicsContext->boundFrameBufferObject();
+ lastBoundFBOId = m_submissionContext->boundFrameBufferObject();
}
// Apply Memory Barrier if needed
if (renderView->memoryBarrier() != QMemoryBarrier::None)
- m_graphicsContext->memoryBarrier(renderView->memoryBarrier());
+ m_submissionContext->memoryBarrier(renderView->memoryBarrier());
// Note: the RenderStateSet is allocated once per RV if needed
// and it contains a list of StateVariant value types
@@ -1349,16 +1351,16 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren
Profiling::GLTimeRecorder recorder(Profiling::StateUpdate);
// Set the RV state if not null,
if (renderViewStateSet != nullptr)
- m_graphicsContext->setCurrentStateSet(renderViewStateSet);
+ m_submissionContext->setCurrentStateSet(renderViewStateSet);
else
- m_graphicsContext->setCurrentStateSet(m_defaultRenderStateSet);
+ m_submissionContext->setCurrentStateSet(m_defaultRenderStateSet);
}
// Set RenderTarget ...
// Activate RenderTarget
{
Profiling::GLTimeRecorder recorder(Profiling::RenderTargetUpdate);
- m_graphicsContext->activateRenderTarget(renderView->renderTargetId(),
+ m_submissionContext->activateRenderTarget(renderView->renderTargetId(),
renderView->attachmentPack(),
lastBoundFBOId);
}
@@ -1369,25 +1371,25 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren
auto clearBufferTypes = renderView->clearTypes();
if (clearBufferTypes & QClearBuffers::ColorBuffer) {
const QVector4D vCol = renderView->globalClearColorBufferInfo().clearColor;
- m_graphicsContext->clearColor(QColor::fromRgbF(vCol.x(), vCol.y(), vCol.z(), vCol.w()));
+ m_submissionContext->clearColor(QColor::fromRgbF(vCol.x(), vCol.y(), vCol.z(), vCol.w()));
}
if (clearBufferTypes & QClearBuffers::DepthBuffer)
- m_graphicsContext->clearDepthValue(renderView->clearDepthValue());
+ m_submissionContext->clearDepthValue(renderView->clearDepthValue());
if (clearBufferTypes & QClearBuffers::StencilBuffer)
- m_graphicsContext->clearStencilValue(renderView->clearStencilValue());
+ m_submissionContext->clearStencilValue(renderView->clearStencilValue());
// Clear BackBuffer
- m_graphicsContext->clearBackBuffer(clearBufferTypes);
+ m_submissionContext->clearBackBuffer(clearBufferTypes);
// if there are ClearColors set for different draw buffers,
// clear each of these draw buffers individually now
const QVector<ClearBufferInfo> clearDrawBuffers = renderView->specificClearColorBufferInfo();
for (const ClearBufferInfo &clearBuffer : clearDrawBuffers)
- m_graphicsContext->clearBufferf(clearBuffer.drawBufferIndex, clearBuffer.clearColor);
+ m_submissionContext->clearBufferf(clearBuffer.drawBufferIndex, clearBuffer.clearColor);
}
// Set the Viewport
- m_graphicsContext->setViewport(renderView->viewport(), renderView->surfaceSize() * renderView->devicePixelRatio());
+ m_submissionContext->setViewport(renderView->viewport(), renderView->surfaceSize() * renderView->devicePixelRatio());
// Execute the render commands
if (!executeCommandsSubmission(renderView))
@@ -1398,15 +1400,15 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren
// renderViewStateSet or m_defaultRenderStateSet)
if (!renderView->renderCaptureNodeId().isNull()) {
const QRenderCaptureRequest request = renderView->renderCaptureRequest();
- const QSize size = m_graphicsContext->renderTargetSize(renderView->surfaceSize() * renderView->devicePixelRatio());
+ const QSize size = m_submissionContext->renderTargetSize(renderView->surfaceSize() * renderView->devicePixelRatio());
QRect rect(QPoint(0, 0), size);
if (!request.rect.isEmpty())
rect = rect.intersected(request.rect);
QImage image;
if (!rect.isEmpty()) {
// Bind fbo as read framebuffer
- m_graphicsContext->bindFramebuffer(m_graphicsContext->activeFBO(), GraphicsHelperInterface::FBORead);
- image = m_graphicsContext->readFramebuffer(rect);
+ m_submissionContext->bindFramebuffer(m_submissionContext->activeFBO(), GraphicsHelperInterface::FBORead);
+ image = m_submissionContext->readFramebuffer(rect);
} else {
qWarning() << "Requested capture rectangle is outside framebuffer";
}
@@ -1429,9 +1431,9 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren
const QRenderTargetOutput::AttachmentPoint inputAttachmentPoint = blitFramebufferInfo.sourceAttachmentPoint;
const QRenderTargetOutput::AttachmentPoint outputAttachmentPoint = blitFramebufferInfo.destinationAttachmentPoint;
const QBlitFramebuffer::InterpolationMethod interpolationMethod = blitFramebufferInfo.interpolationMethod;
- m_graphicsContext->blitFramebuffer(inputTargetId, outputTargetId, inputRect, outputRect, lastBoundFBOId,
- inputAttachmentPoint, outputAttachmentPoint,
- interpolationMethod);
+ m_submissionContext->blitFramebuffer(inputTargetId, outputTargetId, inputRect, outputRect, lastBoundFBOId,
+ inputAttachmentPoint, outputAttachmentPoint,
+ interpolationMethod);
}
@@ -1443,16 +1445,16 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren
// Bind lastBoundFBOId back. Needed also in threaded mode.
// lastBoundFBOId != m_graphicsContext->activeFBO() when the last FrameGraph leaf node/renderView
// contains RenderTargetSelector/RenderTarget
- if (lastBoundFBOId != m_graphicsContext->activeFBO())
- m_graphicsContext->bindFramebuffer(lastBoundFBOId, GraphicsHelperInterface::FBOReadAndDraw);
+ if (lastBoundFBOId != m_submissionContext->activeFBO())
+ m_submissionContext->bindFramebuffer(lastBoundFBOId, GraphicsHelperInterface::FBOReadAndDraw);
// Reset state and call doneCurrent if the surface
// is valid and was actually activated
- if (surface && m_graphicsContext->hasValidGLHelper()) {
+ if (surface && m_submissionContext->hasValidGLHelper()) {
// Reset state to the default state if the last stateset is not the
// defaultRenderStateSet
- if (m_graphicsContext->currentStateSet() != m_defaultRenderStateSet)
- m_graphicsContext->setCurrentStateSet(m_defaultRenderStateSet);
+ if (m_submissionContext->currentStateSet() != m_defaultRenderStateSet)
+ m_submissionContext->setCurrentStateSet(m_defaultRenderStateSet);
}
queueElapsed = timer.elapsed() - queueElapsed;
@@ -1618,7 +1620,7 @@ QVector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs()
notCleared |= AbstractRenderer::LayersDirty;
}
- if (isRunning() && m_graphicsContext->isInitialized()) {
+ if (isRunning() && m_submissionContext->isInitialized()) {
if (dirtyBitsForFrame & AbstractRenderer::TechniquesDirty )
renderBinJobs.push_back(m_filterCompatibleTechniqueJob);
if (dirtyBitsForFrame & AbstractRenderer::ShadersDirty)
@@ -1688,23 +1690,23 @@ void Renderer::performDraw(RenderCommand *command)
}
// Get GLBuffer from Buffer;
- GLBuffer *indirectDrawGLBuffer = m_graphicsContext->glBufferForRenderBuffer(indirectDrawBuffer, GLBuffer::DrawIndirectBuffer);
+ GLBuffer *indirectDrawGLBuffer = m_submissionContext->glBufferForRenderBuffer(indirectDrawBuffer, GLBuffer::DrawIndirectBuffer);
if (Q_UNLIKELY(indirectDrawGLBuffer == nullptr)) {
qWarning() << "Invalid Indirect Draw Buffer - failed to retrieve GLBuffer";
return;
}
// Bind GLBuffer
- const bool successfullyBound = indirectDrawGLBuffer->bind(m_graphicsContext.data(), GLBuffer::DrawIndirectBuffer);
+ const bool successfullyBound = indirectDrawGLBuffer->bind(m_submissionContext.data(), GLBuffer::DrawIndirectBuffer);
if (Q_LIKELY(successfullyBound)) {
// TO DO: Handle multi draw variants if attribute count > 1
if (command->m_drawIndexed) {
- m_graphicsContext->drawElementsIndirect(command->m_primitiveType,
+ m_submissionContext->drawElementsIndirect(command->m_primitiveType,
command->m_indexAttributeDataType,
reinterpret_cast<void*>(quintptr(command->m_indirectAttributeByteOffset)));
} else {
- m_graphicsContext->drawArraysIndirect(command->m_primitiveType,
+ m_submissionContext->drawArraysIndirect(command->m_primitiveType,
reinterpret_cast<void*>(quintptr(command->m_indirectAttributeByteOffset)));
}
} else {
@@ -1712,17 +1714,18 @@ void Renderer::performDraw(RenderCommand *command)
}
} else { // Direct Draw Calls
+
// TO DO: Add glMulti Draw variants
if (command->m_primitiveType == QGeometryRenderer::Patches)
- m_graphicsContext->setVerticesPerPatch(command->m_verticesPerPatch);
+ m_submissionContext->setVerticesPerPatch(command->m_verticesPerPatch);
if (command->m_primitiveRestartEnabled)
- m_graphicsContext->enablePrimitiveRestart(command->m_restartIndexValue);
+ m_submissionContext->enablePrimitiveRestart(command->m_restartIndexValue);
// TO DO: Add glMulti Draw variants
if (command->m_drawIndexed) {
Profiling::GLTimeRecorder recorder(Profiling::DrawElement);
- m_graphicsContext->drawElementsInstancedBaseVertexBaseInstance(command->m_primitiveType,
+ m_submissionContext->drawElementsInstancedBaseVertexBaseInstance(command->m_primitiveType,
command->m_primitiveCount,
command->m_indexAttributeDataType,
reinterpret_cast<void*>(quintptr(command->m_indexAttributeByteOffset)),
@@ -1731,7 +1734,7 @@ void Renderer::performDraw(RenderCommand *command)
command->m_firstVertex);
} else {
Profiling::GLTimeRecorder recorder(Profiling::DrawArray);
- m_graphicsContext->drawArraysInstancedBaseInstance(command->m_primitiveType,
+ m_submissionContext->drawArraysInstancedBaseInstance(command->m_primitiveType,
command->m_firstInstance,
command->m_primitiveCount,
command->m_instanceCount,
@@ -1746,22 +1749,22 @@ void Renderer::performDraw(RenderCommand *command)
#endif
if (command->m_primitiveRestartEnabled)
- m_graphicsContext->disablePrimitiveRestart();
+ m_submissionContext->disablePrimitiveRestart();
}
void Renderer::performCompute(const RenderView *, RenderCommand *command)
{
{
Profiling::GLTimeRecorder recorder(Profiling::ShaderUpdate);
- m_graphicsContext->activateShader(command->m_shaderDna);
+ m_submissionContext->activateShader(command->m_shaderDna);
}
{
Profiling::GLTimeRecorder recorder(Profiling::UniformUpdate);
- m_graphicsContext->setParameters(command->m_parameterPack);
+ m_submissionContext->setParameters(command->m_parameterPack);
}
{
Profiling::GLTimeRecorder recorder(Profiling::DispatchCompute);
- m_graphicsContext->dispatchCompute(command->m_workGroups[0],
+ m_submissionContext->dispatchCompute(command->m_workGroups[0],
command->m_workGroups[1],
command->m_workGroups[2]);
}
@@ -1787,7 +1790,7 @@ void Renderer::createOrUpdateVAO(RenderCommand *command,
if (command->m_vao.isNull()) {
qCDebug(Rendering) << Q_FUNC_INFO << "Allocating new VAO";
command->m_vao = vaoManager->getOrAcquireHandle(vaoKey);
- vaoManager->data(command->m_vao)->create(m_graphicsContext.data(), vaoKey);
+ vaoManager->data(command->m_vao)->create(m_submissionContext.data(), vaoKey);
}
if (*previousVaoHandle != command->m_vao) {
@@ -1810,7 +1813,7 @@ bool Renderer::executeCommandsSubmission(const RenderView *rv)
// graphics API (OpenGL)
// Save the RenderView base stateset
- RenderStateSet *globalState = m_graphicsContext->currentStateSet();
+ RenderStateSet *globalState = m_submissionContext->currentStateSet();
OpenGLVertexArrayObject *vao = nullptr;
for (RenderCommand *command : qAsConst(commands)) {
@@ -1835,7 +1838,7 @@ bool Renderer::executeCommandsSubmission(const RenderView *rv)
{
Profiling::GLTimeRecorder recorder(Profiling::ShaderUpdate);
//// We activate the shader here
- if (!m_graphicsContext->activateShader(command->m_shaderDna)) {
+ if (!m_submissionContext->activateShader(command->m_shaderDna)) {
allCommandsIssued = false;
continue;
}
@@ -1850,7 +1853,7 @@ bool Renderer::executeCommandsSubmission(const RenderView *rv)
{
Profiling::GLTimeRecorder recorder(Profiling::UniformUpdate);
//// Update program uniforms
- if (!m_graphicsContext->setParameters(command->m_parameterPack)) {
+ if (!m_submissionContext->setParameters(command->m_parameterPack)) {
allCommandsIssued = false;
// If we have failed to set uniform (e.g unable to bind a texture)
// we won't perform the draw call which could show invalid content
@@ -1870,9 +1873,9 @@ bool Renderer::executeCommandsSubmission(const RenderView *rv)
// Or restore the globalState if no stateSet for the RenderCommand
if (localState != nullptr) {
command->m_stateSet->merge(globalState);
- m_graphicsContext->setCurrentStateSet(command->m_stateSet);
+ m_submissionContext->setCurrentStateSet(command->m_stateSet);
} else {
- m_graphicsContext->setCurrentStateSet(globalState);
+ m_submissionContext->setCurrentStateSet(globalState);
}
}
// All Uniforms for a pass are stored in the QUniformPack of the command
@@ -1890,7 +1893,7 @@ bool Renderer::executeCommandsSubmission(const RenderView *rv)
vao->release();
// Reset to the state we were in before executing the render commands
- m_graphicsContext->setCurrentStateSet(globalState);
+ m_submissionContext->setCurrentStateSet(globalState);
return allCommandsIssued;
}
@@ -1921,7 +1924,7 @@ bool Renderer::updateVAOWithAttributes(Geometry *geometry,
bool attributeWasDirty = false;
if (attribute->attributeType() == QAttribute::IndexAttribute) {
if ((attributeWasDirty = attribute->isDirty()) == true || forceUpdate)
- m_graphicsContext->specifyIndices(buffer);
+ m_submissionContext->specifyIndices(buffer);
// Vertex Attribute
} else if (command->m_attributes.contains(attribute->nameId())) {
if ((attributeWasDirty = attribute->isDirty()) == true || forceUpdate) {
@@ -1936,7 +1939,7 @@ bool Renderer::updateVAOWithAttributes(Geometry *geometry,
}
if (!attributeDescription || attributeDescription->m_location < 0)
return false;
- m_graphicsContext->specifyAttribute(attribute, buffer, attributeDescription);
+ m_submissionContext->specifyAttribute(attribute, buffer, attributeDescription);
}
}
@@ -1980,7 +1983,7 @@ void Renderer::cleanGraphicsResources()
// Clean buffers
const QVector<Qt3DCore::QNodeId> buffersToRelease = m_nodesManager->bufferManager()->takeBuffersToRelease();
for (Qt3DCore::QNodeId bufferId : buffersToRelease)
- m_graphicsContext->releaseBuffer(bufferId);
+ m_submissionContext->releaseBuffer(bufferId);
// Delete abandoned textures
const QVector<GLTexture*> abandonedTextures = m_nodesManager->glTextureManager()->takeAbandonedTextures();
@@ -2016,12 +2019,12 @@ QList<QKeyEvent> Renderer::pendingKeyEvents() const
const GraphicsApiFilterData *Renderer::contextInfo() const
{
- return m_graphicsContext->contextInfo();
+ return m_submissionContext->contextInfo();
}
-GraphicsContext *Renderer::graphicsContext() const
+SubmissionContext *Renderer::submissionContext() const
{
- return m_graphicsContext.data();
+ return m_submissionContext.data();
}
void Renderer::addRenderCaptureSendRequest(Qt3DCore::QNodeId nodeId)
diff --git a/src/render/backend/renderer_p.h b/src/render/backend/renderer_p.h
index d79bf6136..d174fa428 100644
--- a/src/render/backend/renderer_p.h
+++ b/src/render/backend/renderer_p.h
@@ -125,7 +125,7 @@ class CommandExecuter;
namespace Render {
class CameraLens;
-class GraphicsContext;
+class SubmissionContext;
class FrameGraphNode;
class Material;
class Technique;
@@ -142,6 +142,7 @@ class RenderStateSet;
class VSyncFrameAdvanceService;
class PickEventFilter;
class NodeManagers;
+class ShaderCache;
class UpdateLevelOfDetailJob;
typedef QSharedPointer<UpdateLevelOfDetailJob> UpdateLevelOfDetailJobPtr;
@@ -249,7 +250,7 @@ public:
void setOpenGLContext(QOpenGLContext *context);
const GraphicsApiFilterData *contextInfo() const;
- GraphicsContext *graphicsContext() const;
+ SubmissionContext *submissionContext() const;
inline RenderStateSet *defaultRenderState() const { return m_defaultRenderStateSet; }
@@ -302,7 +303,7 @@ private:
RenderStateSet *m_defaultRenderStateSet;
ShaderParameterPack m_defaultUniformPack;
- QScopedPointer<GraphicsContext> m_graphicsContext;
+ QScopedPointer<SubmissionContext> m_submissionContext;
QSurfaceFormat m_format;
RenderQueue *m_renderQueue;
@@ -331,6 +332,7 @@ private:
QOpenGLContext *m_glContext;
QOpenGLContext *m_shareContext;
mutable QMutex m_shareContextMutex;
+ ShaderCache *m_shaderCache;
PickBoundingVolumeJobPtr m_pickBoundingVolumeJob;
RayCastingJobPtr m_rayCastingJob;