diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-04-13 12:33:00 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2016-04-20 13:22:19 +0000 |
commit | 28f8795d716035516f03542cd55275375462fdc5 (patch) | |
tree | dd8afa6ae6b86e8867ca0af7543e3fd6ba24f942 /src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | |
parent | 40f1aa2d06e8217abb36f29d2a5a9189beab0826 (diff) |
Make rendernode suitable for public consumption
For non-OpenGL APIs the primary (and likely the only) way to add custom
rendering into the Qt Quick scene is via the render node. Other
approaches,like the before/afterRendering signals,
QQuickFramebufferObject, remain OpenGL-only. (although QQuickFramebufferObject
may get a multi-API replacement based on QSGRenderNode at a later time)
Note that this is not a generic 3D content integration enabler. It targets
creating 2D and 2.5D Quick items with custom rendering via the graphics
API in use.
Make QSGRenderNode public, enhance the docs a bit and add a releaseResources().
Add a QSGRendererInterface with a query function in QQuickWindow and
QSGEngine. The scenegraph adaptation can then return a custom implementation of
the interface. This will be necessary to query API-specific values, f.ex. the
ID3D12Device and ID3D12CommandList when running with the d3d12 backend.
The interface allows querying the API and void* resources. Resources that
we know about in advance are enum-based to prevent the
QPlatformNativeInterface-like ugliness of string keys.
Support is there in the batch renderer already, fix this up according to
the new public API, and implement the corresponding bits for the D3D12
renderer.
For D3D12, fix also an issue with QSGNode destruction where graphics resources
in use were attempted to be final-released without a proper wait.
The semantics of changedStates() in QSGRenderNode is changed so that it can be
called at any time, including before render(). This is very useful since we can
implement some state restoring in a more efficient manner.
Added a new example as well. Documentation for QSGRenderNode is heavily
expanded.
Change-Id: I4c4a261c55791d0e38743a784bc4c05a53b3462d
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp')
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index a89dbc0ea2..f277475dbf 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -2763,6 +2763,21 @@ void Renderer::render() m_vao->release(); } +struct RenderNodeState : public QSGRenderNode::RenderState +{ + const QMatrix4x4 *projectionMatrix() const override { return m_projectionMatrix; } + QRect scissorRect() const { return m_scissorRect; } + bool scissorEnabled() const { return m_scissorEnabled; } + int stencilValue() const { return m_stencilValue; } + bool stencilEnabled() const { return m_stencilEnabled; } + + const QMatrix4x4 *m_projectionMatrix; + QRect m_scissorRect; + bool m_scissorEnabled; + int m_stencilValue; + bool m_stencilEnabled; +}; + void Renderer::renderRenderNode(Batch *batch) { if (Q_UNLIKELY(debug_render())) @@ -2774,24 +2789,25 @@ void Renderer::renderRenderNode(Batch *batch) setActiveShader(0, 0); QSGNode *clip = e->renderNode->parent(); - e->renderNode->m_clip_list = 0; + QSGRenderNodePrivate *rd = QSGRenderNodePrivate::get(e->renderNode); + rd->m_clip_list = 0; while (clip != rootNode()) { if (clip->type() == QSGNode::ClipNodeType) { - e->renderNode->m_clip_list = static_cast<QSGClipNode *>(clip); + rd->m_clip_list = static_cast<QSGClipNode *>(clip); break; } clip = clip->parent(); } - updateClip(e->renderNode->m_clip_list, batch); + updateClip(rd->m_clip_list, batch); - QSGRenderNode::RenderState state; + RenderNodeState state; QMatrix4x4 pm = projectionMatrix(); - state.projectionMatrix = ± - state.scissorEnabled = m_currentClipType & ScissorClip; - state.stencilEnabled = m_currentClipType & StencilClip; - state.scissorRect = m_currentScissorRect; - state.stencilValue = m_currentStencilValue; + state.m_projectionMatrix = ± + state.m_scissorEnabled = m_currentClipType & ScissorClip; + state.m_stencilEnabled = m_currentClipType & StencilClip; + state.m_scissorRect = m_currentScissorRect; + state.m_stencilValue = m_currentStencilValue; QSGNode *xform = e->renderNode->parent(); QMatrix4x4 matrix; @@ -2807,13 +2823,13 @@ void Renderer::renderRenderNode(Batch *batch) } xform = xform->parent(); } - e->renderNode->m_matrix = &matrix; + rd->m_matrix = &matrix; QSGNode *opacity = e->renderNode->parent(); - e->renderNode->m_opacity = 1.0; + rd->m_opacity = 1.0; while (opacity != rootNode()) { if (opacity->type() == QSGNode::OpacityNodeType) { - e->renderNode->m_opacity = static_cast<QSGOpacityNode *>(opacity)->combinedOpacity(); + rd->m_opacity = static_cast<QSGOpacityNode *>(opacity)->combinedOpacity(); break; } opacity = opacity->parent(); @@ -2825,12 +2841,17 @@ void Renderer::renderRenderNode(Batch *batch) glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); - e->renderNode->render(state); + QSGRenderNode::StateFlags changes = e->renderNode->changedStates(); + + GLuint prevFbo = 0; + if (changes & QSGRenderNode::RenderTargetState) + glGetIntegerv(GL_FRAMEBUFFER_BINDING, (GLint *) &prevFbo); - e->renderNode->m_matrix = 0; - e->renderNode->m_clip_list = 0; + e->renderNode->render(&state); + + rd->m_matrix = 0; + rd->m_clip_list = 0; - QSGRenderNode::StateFlags changes = e->renderNode->changedStates(); if (changes & QSGRenderNode::ViewportState) { QRect r = viewportRect(); glViewport(r.x(), deviceRect().bottom() - r.bottom(), r.width(), r.height()); @@ -2864,6 +2885,8 @@ void Renderer::renderRenderNode(Batch *batch) glDisable(GL_CULL_FACE); } + if (changes & QSGRenderNode::RenderTargetState) + glBindFramebuffer(GL_FRAMEBUFFER, prevFbo); } class VisualizeShader : public QOpenGLShaderProgram |