diff options
Diffstat (limited to 'examples')
7 files changed, 169 insertions, 6 deletions
diff --git a/examples/quick/scenegraph/rendernode/customrenderitem.cpp b/examples/quick/scenegraph/rendernode/customrenderitem.cpp index 433f3c5a1e..2465f4cbc7 100644 --- a/examples/quick/scenegraph/rendernode/customrenderitem.cpp +++ b/examples/quick/scenegraph/rendernode/customrenderitem.cpp @@ -44,6 +44,7 @@ #include "openglrenderer.h" #include "d3d12renderer.h" +#include "softwarerenderer.h" CustomRenderItem::CustomRenderItem(QQuickItem *parent) : QQuickItem(parent) @@ -70,6 +71,10 @@ QSGNode *CustomRenderItem::updatePaintNode(QSGNode *node, UpdatePaintNodeData *) n = new D3D12RenderNode(this); break; #endif + case QSGRendererInterface::Software: + n = new SoftwareRenderNode(this); + break; + default: return nullptr; } diff --git a/examples/quick/scenegraph/rendernode/d3d12renderer.cpp b/examples/quick/scenegraph/rendernode/d3d12renderer.cpp index b7dc62fe86..f475ec838b 100644 --- a/examples/quick/scenegraph/rendernode/d3d12renderer.cpp +++ b/examples/quick/scenegraph/rendernode/d3d12renderer.cpp @@ -78,7 +78,7 @@ void D3D12RenderNode::releaseResources() void D3D12RenderNode::init() { QSGRendererInterface *rif = m_item->window()->rendererInterface(); - m_device = static_cast<ID3D12Device *>(rif->getResource(QSGRendererInterface::Device)); + m_device = static_cast<ID3D12Device *>(rif->getResource(m_item->window(), QSGRendererInterface::Device)); Q_ASSERT(m_device); D3D12_ROOT_PARAMETER rootParameter; @@ -235,7 +235,7 @@ void D3D12RenderNode::render(const RenderState *state) init(); QSGRendererInterface *rif = m_item->window()->rendererInterface(); - ID3D12GraphicsCommandList *commandList = static_cast<ID3D12GraphicsCommandList *>(rif->getResource(QSGRendererInterface::CommandList)); + ID3D12GraphicsCommandList *commandList = static_cast<ID3D12GraphicsCommandList *>(rif->getResource(m_item->window(), QSGRendererInterface::CommandList)); Q_ASSERT(commandList); const int msize = 16 * sizeof(float); diff --git a/examples/quick/scenegraph/rendernode/main.qml b/examples/quick/scenegraph/rendernode/main.qml index a91656dfaa..7c8d82181f 100644 --- a/examples/quick/scenegraph/rendernode/main.qml +++ b/examples/quick/scenegraph/rendernode/main.qml @@ -90,7 +90,10 @@ Item { anchors.margins: 20 wrapMode: Text.WordWrap property int api: GraphicsInfo.api - text: "Custom rendering via the graphics API " + (api === GraphicsInfo.OpenGL ? "OpenGL" : (api === GraphicsInfo.Direct3D12 ? "Direct3D 12" : "")) + text: "Custom rendering via the graphics API " + + (api === GraphicsInfo.OpenGL ? "OpenGL" + : api === GraphicsInfo.Direct3D12 ? "Direct3D 12" + : api === GraphicsInfo.Software ? "Software" : "") color: "yellow" } } diff --git a/examples/quick/scenegraph/rendernode/openglrenderer.cpp b/examples/quick/scenegraph/rendernode/openglrenderer.cpp index 3eff70cb42..33c59198b8 100644 --- a/examples/quick/scenegraph/rendernode/openglrenderer.cpp +++ b/examples/quick/scenegraph/rendernode/openglrenderer.cpp @@ -97,8 +97,6 @@ void OpenGLRenderNode::init() const int VERTEX_SIZE = 6 * sizeof(GLfloat); - // A fully featured renderer should also take inheritedOpacity() into account - // and blend, but ignore that for now. static GLfloat colors[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, @@ -140,6 +138,8 @@ void OpenGLRenderNode::render(const RenderState *state) m_program->enableAttributeArray(0); m_program->enableAttributeArray(1); + // Note that clipping (scissor or stencil) is ignored in this example. + f->glEnable(GL_BLEND); f->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); diff --git a/examples/quick/scenegraph/rendernode/rendernode.pro b/examples/quick/scenegraph/rendernode/rendernode.pro index d7ae715a7d..851d5927bd 100644 --- a/examples/quick/scenegraph/rendernode/rendernode.pro +++ b/examples/quick/scenegraph/rendernode/rendernode.pro @@ -1,10 +1,12 @@ QT += qml quick HEADERS += customrenderitem.h \ - openglrenderer.h + openglrenderer.h \ + softwarerenderer.h SOURCES += customrenderitem.cpp \ openglrenderer.cpp \ + softwarerenderer.cpp \ main.cpp RESOURCES += rendernode.qrc diff --git a/examples/quick/scenegraph/rendernode/softwarerenderer.cpp b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp new file mode 100644 index 0000000000..2f11c56f29 --- /dev/null +++ b/examples/quick/scenegraph/rendernode/softwarerenderer.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "softwarerenderer.h" +#include <QQuickItem> +#include <QQuickWindow> +#include <QSGRendererInterface> +#include <QPainter> + +SoftwareRenderNode::SoftwareRenderNode(QQuickItem *item) + : m_item(item) +{ +} + +SoftwareRenderNode::~SoftwareRenderNode() +{ + releaseResources(); +} + +void SoftwareRenderNode::releaseResources() +{ +} + +void SoftwareRenderNode::render(const RenderState *renderState) +{ + QSGRendererInterface *rif = m_item->window()->rendererInterface(); + QPainter *p = static_cast<QPainter *>(rif->getResource(m_item->window(), QSGRendererInterface::Painter)); + Q_ASSERT(p); + + p->setTransform(matrix()->toTransform()); + p->setOpacity(inheritedOpacity()); + const QRegion *clipRegion = renderState->clipRegion(); + if (clipRegion && !clipRegion->isEmpty()) + p->setClipRegion(*clipRegion); + + const QPointF p0(m_item->width() - 1, m_item->height() - 1); + const QPointF p1(0, 0); + const QPointF p2(0, m_item->height() - 1); + QPainterPath path(p0); + path.lineTo(p1); + path.lineTo(p2); + path.closeSubpath(); + + QLinearGradient gradient(QPointF(0, 0), QPointF(m_item->width(), m_item->height())); + gradient.setColorAt(0, Qt::green); + gradient.setColorAt(1, Qt::red); + + p->fillPath(path, gradient); +} + +QSGRenderNode::StateFlags SoftwareRenderNode::changedStates() const +{ + return 0; +} diff --git a/examples/quick/scenegraph/rendernode/softwarerenderer.h b/examples/quick/scenegraph/rendernode/softwarerenderer.h new file mode 100644 index 0000000000..60036f96a1 --- /dev/null +++ b/examples/quick/scenegraph/rendernode/softwarerenderer.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SOFTWARERENDERER_H +#define SOFTWARERENDERER_H + +#include <qsgrendernode.h> + +class QQuickItem; + +class SoftwareRenderNode : public QSGRenderNode +{ +public: + SoftwareRenderNode(QQuickItem *item); + ~SoftwareRenderNode(); + + void render(const RenderState *state) override; + void releaseResources() override; + StateFlags changedStates() const override; + +private: + QQuickItem *m_item; +}; + +#endif |