1 | // Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "scene3dsgnode_p.h" |
5 | |
6 | #include <QtCore/qthread.h> |
7 | |
8 | #include <scene3dlogging_p.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | namespace Qt3DRender { |
13 | |
14 | /*! |
15 | \class Qt3DCore::Scene3DSGNode |
16 | \internal |
17 | |
18 | \brief The Qt3DCore::Scene3DSGNode class is a simple QSGeometryNode subclass that |
19 | uses a Qt3DCore::Scene3DMaterial |
20 | |
21 | The Qt3DCore::Scene3DSGNode allows to render a simple rectangle textured with a |
22 | texture using premultiplied alpha. |
23 | */ |
24 | Scene3DSGNode::Scene3DSGNode() |
25 | : QSGGeometryNode() |
26 | , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) |
27 | { |
28 | setMaterial(&m_material); |
29 | setOpaqueMaterial(&m_opaqueMaterial); |
30 | setGeometry(&m_geometry); |
31 | qCDebug(Scene3D) << Q_FUNC_INFO << QThread::currentThread(); |
32 | } |
33 | |
34 | Scene3DSGNode::~Scene3DSGNode() |
35 | { |
36 | qCDebug(Scene3D) << Q_FUNC_INFO << QThread::currentThread(); |
37 | // The Scene3DSGNode is deleted by the QSGRenderThread when the SceneGraph |
38 | // is terminated. |
39 | } |
40 | |
41 | void Scene3DSGNode::setRect(const QRectF &rect, bool mirrorVertically) |
42 | { |
43 | if (rect != m_rect) { |
44 | m_rect = rect; |
45 | // By default, map the item's bounding rect to normalized texture coordinates |
46 | |
47 | QRectF textureRect = QRectF(0.0f, 1.0f, 1.0f, -1.0f); |
48 | if (mirrorVertically) { |
49 | float tmp = textureRect.top(); |
50 | textureRect.setTop(textureRect.bottom()); |
51 | textureRect.setBottom(tmp); |
52 | } |
53 | |
54 | QSGGeometry::updateTexturedRectGeometry(g: &m_geometry, rect: m_rect, sourceRect: textureRect); |
55 | markDirty(bits: DirtyGeometry); |
56 | } |
57 | } |
58 | |
59 | void Scene3DSGNode::show() |
60 | { |
61 | m_material.show(); |
62 | m_opaqueMaterial.show(); |
63 | } |
64 | |
65 | } // namespace Qt3DRender |
66 | |
67 | QT_END_NAMESPACE |
68 |