diff options
Diffstat (limited to 'src/quick/scenegraph/coreapi')
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 55 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h | 3 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgnode.h | 2 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgnodeupdater.cpp | 7 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgrendererinterface.cpp | 119 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgrendererinterface.h | 75 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgrendernode.cpp | 235 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgrendernode.h | 94 | ||||
-rw-r--r-- | src/quick/scenegraph/coreapi/qsgrendernode_p.h | 51 |
9 files changed, 545 insertions, 96 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 diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index a84ac6d177..c56f15d655 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -56,9 +56,8 @@ #include <private/qsgrenderer_p.h> #include <private/qsgdefaultrendercontext_p.h> #include <private/qsgnodeupdater_p.h> -#include <private/qdatabuffer_p.h> - #include <private/qsgrendernode_p.h> +#include <private/qdatabuffer_p.h> #include <QtCore/QBitArray> diff --git a/src/quick/scenegraph/coreapi/qsgnode.h b/src/quick/scenegraph/coreapi/qsgnode.h index 349753a361..627fe6e27f 100644 --- a/src/quick/scenegraph/coreapi/qsgnode.h +++ b/src/quick/scenegraph/coreapi/qsgnode.h @@ -79,8 +79,8 @@ public: OpacityNodeType, #ifndef qdoc RootNodeType, - RenderNodeType #endif + RenderNodeType }; enum Flag { diff --git a/src/quick/scenegraph/coreapi/qsgnodeupdater.cpp b/src/quick/scenegraph/coreapi/qsgnodeupdater.cpp index 372ffce9d6..d6d533307e 100644 --- a/src/quick/scenegraph/coreapi/qsgnodeupdater.cpp +++ b/src/quick/scenegraph/coreapi/qsgnodeupdater.cpp @@ -175,9 +175,10 @@ void QSGNodeUpdater::enterRenderNode(QSGRenderNode *r) qDebug() << "enter render:" << r; #endif - r->m_matrix = m_combined_matrix_stack.isEmpty() ? 0 : m_combined_matrix_stack.last(); - r->m_clip_list = m_current_clip; - r->setInheritedOpacity(m_opacity_stack.last()); + QSGRenderNodePrivate *rd = QSGRenderNodePrivate::get(r); + rd->m_matrix = m_combined_matrix_stack.isEmpty() ? 0 : m_combined_matrix_stack.last(); + rd->m_clip_list = m_current_clip; + rd->m_opacity = m_opacity_stack.last(); } void QSGNodeUpdater::leaveRenderNode(QSGRenderNode *r) diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp new file mode 100644 index 0000000000..6a01fac212 --- /dev/null +++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.cpp @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick 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 "qsgrendererinterface.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QSGRendererInterface + \brief An interface providing access to some of the graphics API specific internals + of the scenegraph. + \inmodule QtQuick + \since 5.8 + + Renderer interfaces allow accessing graphics API specific functionality in + the scenegraph. Such internals are not typically exposed. However, when + integrating custom rendering via QSGRenderNode for example, it may become + necessary to query certain values, for instance the graphics device (e.g. + the Direct3D or Vulkan device) that is used by the scenegraph. + + \note QSGRendererInterface is only available after the scenegraph is + initialized. Additionally, there may be backend-specific limitations on + when the functions can be called. The only way that is guaranteed to + succeed is calling them when the rendering of a node (i.e. the preparation + of the command list for the next frame) is active. In practice this + typically means QSGRenderNode::render(). + */ + +/*! + \enum QSGRenderNode::GraphicsAPI + \value Unknown An unknown graphics API is in use + \value Software The Qt Quick 2D Renderer is in use + \value OpenGL OpenGL ES 2.0 or higher + \value Direct3D12 Direct3D 12 + \value Vulkan Vulkan + \value Metal Metal + */ + +/*! + \enum QSGRenderNode::Resource + \value Device The graphics device + \value CommandQueue The graphics command queue used by the scenergaph + \value CommandList The command list or buffer used by the scenegraph + */ + +QSGRendererInterface::~QSGRendererInterface() +{ +} + +/*! + \fn QSGRenderNode::GraphicsAPI QSGRenderNode::graphicsAPI() const + + Returns the graphics API that is in use by the Qt Quick scenegraph. + */ + +/*! + Queries a graphics \a resource. Returns null when the resource in question is + not supported or not available. + + When successful, the returned pointer is either a direct pointer to an + interface (and can be cast, for example, to \c{ID3D12Device *}) or a + pointer to an opaque handle that needs to be dereferenced first (for + example, \c{VkDevice dev = *static_cast<VkDevice *>(result)}). The latter + is necessary since such handles may have sizes different from a pointer. + */ +void *QSGRendererInterface::getResource(Resource resource) const +{ + Q_UNUSED(resource); + return nullptr; +} + +/*! + Queries a graphics resource. \a resource is a backend-specific key. This + allows supporting any future resources that are not listed in the + Resource enum. + */ +void *QSGRendererInterface::getResource(const char *resource) const +{ + Q_UNUSED(resource); + return nullptr; +} + +QT_END_NAMESPACE diff --git a/src/quick/scenegraph/coreapi/qsgrendererinterface.h b/src/quick/scenegraph/coreapi/qsgrendererinterface.h new file mode 100644 index 0000000000..c4a145dd0f --- /dev/null +++ b/src/quick/scenegraph/coreapi/qsgrendererinterface.h @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick 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$ +** +****************************************************************************/ + +#ifndef QSGRENDERERINTERFACE_H +#define QSGRENDERERINTERFACE_H + +#include <QtQuick/qsgnode.h> + +QT_BEGIN_NAMESPACE + +class Q_QUICK_EXPORT QSGRendererInterface +{ +public: + enum GraphicsAPI { + Unknown, + Software, + OpenGL, + Direct3D12, + Vulkan, + Metal + }; + + enum Resource { + Device, + CommandQueue, + CommandList + }; + + virtual ~QSGRendererInterface(); + + virtual GraphicsAPI graphicsAPI() const = 0; + + virtual void *getResource(Resource resource) const; + virtual void *getResource(const char *resource) const; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/quick/scenegraph/coreapi/qsgrendernode.cpp b/src/quick/scenegraph/coreapi/qsgrendernode.cpp index 1a38f6495e..8dc82a0d66 100644 --- a/src/quick/scenegraph/coreapi/qsgrendernode.cpp +++ b/src/quick/scenegraph/coreapi/qsgrendernode.cpp @@ -37,28 +37,51 @@ ** ****************************************************************************/ +#include "qsgrendernode.h" #include "qsgrendernode_p.h" QT_BEGIN_NAMESPACE +/*! + \class QSGRenderNode + \brief The QSGMaterialShader class represents a set of custom rendering commands + targeting the graphics API that is in use by the scenegraph. + \inmodule QtQuick + \since 5.8 + */ + QSGRenderNode::QSGRenderNode() - : QSGNode(RenderNodeType) - , m_matrix(0) - , m_clip_list(0) - , m_opacity(1) + : QSGNode(RenderNodeType), + d(new QSGRenderNodePrivate) { } -void QSGRenderNode::setInheritedOpacity(qreal opacity) +/*! + Destructs the render node. Derived classes are expected to perform cleanup + similar to releaseResources() in here. + + When a low-level graphics API is in use, the scenegraph will make sure + there is a CPU-side wait for the GPU to complete all work submitted to the + scenegraph's graphics command queue before the scenegraph's nodes are + deleted. Therefore there is no need to issue additional waits here, unless + the render() implementation is using additional command queues. + + \sa releaseResources() + */ +QSGRenderNode::~QSGRenderNode() { - Q_ASSERT(opacity >= 0 && opacity <= 1); - m_opacity = opacity; + delete d; } -/*! - \fn QSGRenderNode::StateFlags QSGRenderNode::changedStates() +QSGRenderNodePrivate::QSGRenderNodePrivate() + : m_matrix(0) + , m_clip_list(0) + , m_opacity(1) +{ +} - This function should return a mask where each bit represents OpenGL states changed by +/*! + This function should return a mask where each bit represents graphics states changed by the \l render() function: \list \li DepthState - depth write mask, depth test enabled, depth comparison function @@ -69,30 +92,72 @@ void QSGRenderNode::setInheritedOpacity(qreal opacity) \li BlendState - blend enabled, blend function \li CullState - front face, cull face enabled \li ViewportState - viewport + \li RenderTargetState - render target \endlist - The function is called by the renderer so it can reset the OpenGL states after rendering this - node. + The function is called by the renderer so it can reset the states after + rendering this node. This makes the implementation of render() simpler + since it does not have to query and restore these states. - \internal + The default implementation returns 0, meaning no relevant state was changed + in render(). + + With APIs other than OpenGL the relevant states are only those that are set + via the command list (for example, OMSetRenderTargets, RSSetViewports, + RSSetScissorRects, OMSetBlendFactor, OMSetStencilRef in case of D3D12), and + only when such commands were added to the scenegraph's command list queried + via the QSGRendererInterface::CommandList resource enum. States set in + pipeline state objects do not need to be reported here. Similarly, draw + call related settings (root signature, descriptor heaps, etc.) are always + set again by the scenegraph so render() can freely change them. + + \note This function may be called before render(). */ +QSGRenderNode::StateFlags QSGRenderNode::changedStates() const +{ + return 0; +} /*! - \fn void QSGRenderNode::render(const RenderState &state) + \fn void QSGRenderNode::render(const RenderState *state) - This function is called by the renderer and should paint this node with OpenGL commands. + This function is called by the renderer and should paint this node with + directly invoking commands in the graphics API (OpenGL, Direct3D, etc.) + currently in use. - The states necessary for clipping has already been set before the function is called. - The clip is a combination of a stencil clip and scissor clip. Information about the clip is - found in \a state. + The states necessary for clipping has already been set before the function + is called. The clip is a combination of a stencil clip and scissor clip. + Information about the clip is found in \a state. + + \note This means that setting viewport, scissor rectangle, stencil + reference value, and similar is not necessary in render() since the + corresponding commands are on the command list (or, in case of OpenGL, the + context) already. However, for APIs other than OpenGL stencil-based + clipping will need enabling stencil testing in the pipeline state that is + used by render(). The effective opacity can be retrieved with \l inheritedOpacity(). - The projection matrix is available through \a state, while the model-view matrix can be - fetched with \l matrix(). The combined matrix is then the projection matrix times the - model-view matrix. + The projection matrix is available through \a state, while the model-view + matrix can be fetched with \l matrix(). The combined matrix is then the + projection matrix times the model-view matrix. The correct stacking of the + items in the scene is ensured by the projection matrix. + + When using the provided matrices, the coordinate system for vertex data + follows the usual QQuickItem conventions: top-left is (0, 0), bottom-right + is the corresponding QQuickItem's width() and height() minus one. For + example, assuming a two float (x-y) per vertex coordinate layout, a + triangle covering half of the item can be specified as (width - 1, height - 1), + (0, 0), (0, height - 1) using counter-clockwise direction. + + \note QSGRenderNode is provided as a means to implement custom 2D or 2.5D + Qt Quick items. It is not intended for integrating true 3D content into the + Qt Quick scene. That use case is better supported by + QQuickFramebufferObject, QQuickWindow::beforeRendering(), or the + equivalents of those for APIs other than OpenGL. - The following states are set before this function is called: + For OpenGL the following states are set on the render thread's context + before this function is called: \list \li glDepthMask(false) \li glDisable(GL_DEPTH_TEST) @@ -107,14 +172,128 @@ void QSGRenderNode::setInheritedOpacity(qreal opacity) \li glDisable(GL_CULL_FACE) \endlist - States that are not listed above, but are included in \l StateFlags, can have arbitrary - values. + States that are not listed above, but are included in \l StateFlags, can + have arbitrary values. - \l changedStates() should return which states this function has changed. If a state is not - covered by \l StateFlags, the state should be set to the default value according to the - OpenGL specification. + \l changedStates() should return which states this function changes. If a + state is not covered by \l StateFlags, the state should be set to the + default value according to the OpenGL specification. For other APIs, see + the documentation for changedStates() for more information. - \internal + For APIs other than OpenGL, it will likely be necessary to query certain + API-specific resources (for example, the graphics device or the command + list/buffer to add the commands to). This is done via QSGRendererInterface. + + \sa QSGRendererInterface, QQuickWindow::rendererInterface() */ +/*! + \fn void QSGRenderNode::releaseResources() + + This function is called when all custom graphics resources allocated by + this node have to be freed immediately. In case the node does not directly + allocate graphics resources (buffers, textures, render targets, fences, + etc.) through the graphics API that is in use, there is nothing to do here. + + Failing to release all custom resources can lead to incorrect behavior in + graphics device loss scenarios on some systems since subsequent + reinitialization of the graphics system may fail. + + \note Some scenegraph backends may choose not to call this function. + Therefore it is expected that QSGRenderNode implementations perform cleanup + both in their destructor and in releaseResources(). + + Unlike with the destructor, it is expected that render() can reinitialize + all resources it needs when called after a call to releaseResources(). + + With OpenGL, the scenegraph's OpenGL context will be current both when + calling the destructor and this function. + */ + +/*! + \return pointer to the current model-view matrix. + */ +const QMatrix4x4 *QSGRenderNode::matrix() const +{ + return d->m_matrix; +} + +/*! + \return the current clip list. + */ +const QSGClipNode *QSGRenderNode::clipList() const +{ + return d->m_clip_list; +} + +/*! + \return the current effective opacity. + */ +qreal QSGRenderNode::inheritedOpacity() const +{ + return d->m_opacity; +} + +QSGRenderNode::RenderState::~RenderState() +{ +} + +/*! + \fn const QMatrix4x4 *QSGRenderNode::RenderState::projectionMatrix() const + + \return pointer to the current projection matrix. + + The model-view matrix can be retrieved with QSGRenderNode::matrix(). + Typically \c{projection * modelview} is the matrix that is then used in the + vertex shader to transform the vertices. + */ + +/*! + \fn const QMatrix4x4 *QSGRenderNode::RenderState::scissorRect() const + + \return the current scissor rectangle when clipping is active. + + \note Be aware of the differences between graphics APIs: for some the + scissor rect is only active when scissoring is enabled (for example, + OpenGL), while for others the scissor rect is equal to the viewport rect + when there is no need to scissor away anything (for example, Direct3D 12). + */ + +/*! + \fn const QMatrix4x4 *QSGRenderNode::RenderState::scissorEnabled() const + + \return the current state of scissoring. + + \note Only relevant for graphics APIs that have a dedicated on/off state of + scissoring. + */ + +/*! + \fn const QMatrix4x4 *QSGRenderNode::RenderState::stencilValue() const + + \return the current stencil reference value when clipping is active. + */ + +/*! + \fn const QMatrix4x4 *QSGRenderNode::RenderState::stencilEnabled() const + + \return the current state of stencil testing. + + \note With graphics APIs where stencil testing is enabled in pipeline state + objects, instead of individual state-setting commands, it is up to the + implementation of render() to enable stencil testing with operations + \c KEEP, comparison function \c EQUAL, and a read and write mask of \c 0xFF. + */ + +/*! + \return pointer to a \a state value. + + Reserved for future use. + */ +void *QSGRenderNode::RenderState::get(const char *state) const +{ + Q_UNUSED(state); + return nullptr; +} + QT_END_NAMESPACE diff --git a/src/quick/scenegraph/coreapi/qsgrendernode.h b/src/quick/scenegraph/coreapi/qsgrendernode.h new file mode 100644 index 0000000000..5441b64fe4 --- /dev/null +++ b/src/quick/scenegraph/coreapi/qsgrendernode.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick 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$ +** +****************************************************************************/ + +#ifndef QSGRENDERNODE_H +#define QSGRENDERNODE_H + +#include <QtQuick/qsgnode.h> + +QT_BEGIN_NAMESPACE + +class QSGRenderNodePrivate; + +class Q_QUICK_EXPORT QSGRenderNode : public QSGNode +{ +public: + enum StateFlag { + DepthState = 0x01, + StencilState = 0x02, + ScissorState = 0x04, + ColorState = 0x08, + BlendState = 0x10, + CullState = 0x20, + ViewportState = 0x40, + RenderTargetState = 0x80 + }; + Q_DECLARE_FLAGS(StateFlags, StateFlag) + + struct Q_QUICK_EXPORT RenderState { + virtual ~RenderState(); + virtual const QMatrix4x4 *projectionMatrix() const = 0; + virtual QRect scissorRect() const = 0; + virtual bool scissorEnabled() const = 0; + virtual int stencilValue() const = 0; + virtual bool stencilEnabled() const = 0; + virtual void *get(const char *state) const; + }; + + QSGRenderNode(); + ~QSGRenderNode(); + + virtual StateFlags changedStates() const; + virtual void render(const RenderState *state) = 0; + virtual void releaseResources() = 0; + + const QMatrix4x4 *matrix() const; + const QSGClipNode *clipList() const; + qreal inheritedOpacity() const; + +private: + QSGRenderNodePrivate *d; + friend class QSGRenderNodePrivate; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QSGRenderNode::StateFlags) + +QT_END_NAMESPACE + +#endif diff --git a/src/quick/scenegraph/coreapi/qsgrendernode_p.h b/src/quick/scenegraph/coreapi/qsgrendernode_p.h index 8659b0e62c..5c42e55689 100644 --- a/src/quick/scenegraph/coreapi/qsgrendernode_p.h +++ b/src/quick/scenegraph/coreapi/qsgrendernode_p.h @@ -51,64 +51,23 @@ // We mean it. // -#include "qsgnode.h" -#include <private/qtquickglobal_p.h> +#include <QtQuick/qsgnode.h> +#include <QtQuick/qsgrendernode.h> QT_BEGIN_NAMESPACE -namespace QSGBatchRenderer { - class Renderer; -} - -class Q_QUICK_PRIVATE_EXPORT QSGRenderNode : public QSGNode +class QSGRenderNodePrivate { public: - enum StateFlag - { - DepthState = 0x01, // depth mask, depth test enable, depth func, clear depth - StencilState = 0x02, // stencil mask, stencil test enable, stencil op, stencil func, clear stencil - ScissorState = 0x04, // scissor enable, scissor test enable - ColorState = 0x08, // clear color, color mask - BlendState = 0x10, // blend enable, blend func - CullState = 0x20, // front face, cull face enable - ViewportState = 0x40 // viewport - }; - Q_DECLARE_FLAGS(StateFlags, StateFlag) - - struct RenderState - { - // The model-view matrix can be retrieved with matrix(). - // The opacity can be retrieved with inheritedOpacity(). - const QMatrix4x4 *projectionMatrix; - QRect scissorRect; - int stencilValue; - - bool stencilEnabled; - bool scissorEnabled; - }; - - QSGRenderNode(); + QSGRenderNodePrivate(); - virtual StateFlags changedStates() = 0; - virtual void render(const RenderState &state) = 0; - - const QMatrix4x4 *matrix() const { return m_matrix; } - const QSGClipNode *clipList() const { return m_clip_list; } - - void setInheritedOpacity(qreal opacity); - qreal inheritedOpacity() const { return m_opacity; } - -private: - friend class QSGNodeUpdater; - friend class QSGBatchRenderer::Renderer; + static QSGRenderNodePrivate *get(QSGRenderNode *node) { return node->d; } const QMatrix4x4 *m_matrix; const QSGClipNode *m_clip_list; qreal m_opacity; }; -Q_DECLARE_OPERATORS_FOR_FLAGS(QSGRenderNode::StateFlags) - QT_END_NAMESPACE #endif |