1/****************************************************************************
2**
3** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt3D module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qviewport.h"
41#include "qviewport_p.h"
42
43#include <Qt3DRender/qframegraphnodecreatedchange.h>
44
45QT_BEGIN_NAMESPACE
46
47namespace Qt3DRender {
48
49QViewportPrivate::QViewportPrivate()
50 : QFrameGraphNodePrivate()
51 , m_normalizedRect(QRectF(0.0f, 0.0f, 1.0f, 1.0f))
52 , m_gamma(2.2f)
53{
54}
55
56/*!
57 \class Qt3DRender::QViewport
58 \inmodule Qt3DRender
59 \brief A viewport on the Qt3D Scene.
60 \since 5.7
61
62 \inherits Qt3DRender::QFrameGraphNode
63
64 Qt3DRender::QViewport of the scene specifies at which portion of the render surface Qt3D
65 is rendering to. Area outside the viewport is left untouched. It also controls global parameters
66 to the rendering in that viewport like gamma.
67 */
68
69/*!
70 \qmltype Viewport
71 \inqmlmodule Qt3D.Render
72 \since 5.7
73 \inherits FrameGraphNode
74 \instantiates Qt3DRender::QViewport
75 \brief A viewport on the Qt3D Scene.
76
77 Viewport of the scene specifies at which portion of the render surface Qt3D is
78 rendering to. Area outside the viewport is left untouched. It also controls global parameters
79 to the rendering in that viewport like gamma.
80 */
81
82/*!
83 \qmlproperty rect Viewport::normalizedRect
84
85 Specifies the normalised rectangle for the viewport, i.e. the viewport rectangle
86 is specified relative to the render surface size. Whole surface sized viewport
87 is specified as [0.0, 0.0, 1.0, 1.0], which is the default.
88 */
89
90/*!
91 \qmlproperty rect Viewport::gamma
92
93 Specifies the gamma factor for the viewport. The default is 2.2 which should give proper result on most screens.
94 */
95
96/*!
97 Constructs QViewport with given \a parent.
98 */
99QViewport::QViewport(QNode *parent)
100 : QFrameGraphNode(*new QViewportPrivate, parent)
101{
102}
103
104/*! \internal */
105QViewport::~QViewport()
106{
107}
108
109/*! \internal */
110QViewport::QViewport(QViewportPrivate &dd, QNode *parent)
111 : QFrameGraphNode(dd, parent)
112{
113}
114
115
116QRectF QViewport::normalizedRect() const
117{
118 Q_D(const QViewport);
119 return d->m_normalizedRect;
120}
121
122float QViewport::gamma() const
123{
124 Q_D(const QViewport);
125 return d->m_gamma;
126}
127
128/*!
129 \property QViewport::normalizedRect
130
131 Specifies the normalised rectangle for the viewport, i.e. the viewport rectangle
132 is specified relative to the render surface size. Whole surface sized viewport
133 is specified as [0.0, 0.0, 1.0, 1.0], which is the default.
134 */
135void QViewport::setNormalizedRect(const QRectF &normalizedRect)
136{
137 Q_D(QViewport);
138 if (normalizedRect != d->m_normalizedRect) {
139 d->m_normalizedRect = normalizedRect;
140 emit normalizedRectChanged(normalizedRect);
141 }
142}
143
144/*!
145 \property QViewport::gamma
146
147 Specifies the gamma factor for the viewport. The default is 2.2 which should give proper result on most screens.
148 */
149void QViewport::setGamma(float gamma)
150{
151 Q_D(QViewport);
152 if (gamma != d->m_gamma) {
153 d->m_gamma = gamma;
154 emit gammaChanged(gamma);
155 }
156}
157
158Qt3DCore::QNodeCreatedChangeBasePtr QViewport::createNodeCreationChange() const
159{
160 auto creationChange = QFrameGraphNodeCreatedChangePtr<QViewportData>::create(arguments: this);
161 auto &data = creationChange->data;
162 Q_D(const QViewport);
163 data.normalizedRect = d->m_normalizedRect;
164 data.gamma = d->m_gamma;
165 return creationChange;
166}
167
168} // namespace Qt3DRender
169
170QT_END_NAMESPACE
171

source code of qt3d/src/render/framegraph/qviewport.cpp