summaryrefslogtreecommitdiffstats
path: root/src/render/defaults/qforwardrenderer.cpp
blob: 0daa261433cc5ccf0231d8a27eff0f8d506004bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/****************************************************************************
**
** Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt3D module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL3$
** 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 http://www.qt.io/terms-conditions. For further
** information use the contact form at http://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.LGPLv3 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.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 later as published by the Free
** Software Foundation and appearing in the file LICENSE.GPL included in
** the packaging of this file. Please review the following information to
** ensure the GNU General Public License version 2.0 requirements will be
** met: http://www.gnu.org/licenses/gpl-2.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qforwardrenderer.h"
#include "qforwardrenderer_p.h"

#include <Qt3DRenderer/qviewport.h>
#include <Qt3DRenderer/qcameraselector.h>
#include <Qt3DRenderer/qclearbuffer.h>
#include <Qt3DRenderer/qannotation.h>

QT_BEGIN_NAMESPACE

namespace Qt3D {

/*!
    \class Qt3D::QForwardRendererPrivate
    \internal
*/
QForwardRendererPrivate::QForwardRendererPrivate()
    : QTechniqueFilterPrivate()
    , m_viewport(new QViewport())
    , m_cameraSelector(new QCameraSelector())
    , m_clearBuffer(new QClearBuffer())
{
}

void QForwardRendererPrivate::init()
{
    Q_Q(QForwardRenderer);

    m_clearBuffer->setParent(m_cameraSelector);
    m_cameraSelector->setParent(m_viewport);
    m_viewport->setParent(q);

    m_viewport->setRect(QRectF(0.0f, 0.0f, 1.0f, 1.0f));
    m_viewport->setClearColor(Qt::white);
    m_clearBuffer->setBuffers(Qt3D::QClearBuffer::ColorDepthBuffer);

    QAnnotation *forwardRenderingStyle = new QAnnotation(q);
    forwardRenderingStyle->setName(QStringLiteral("renderingStyle"));
    forwardRenderingStyle->setValue(QStringLiteral("forward"));
    q->addRequirement(forwardRenderingStyle);
}

/*!
    \class Qt3D::QForwardRenderer
    \brief The Qt3D::QForwardRenderer provides a default FrameGraph implementation of a forward renderer.
    \inmodule Qt3DRender
    \since 5.5

    Forward rendering is how OpenGL is traditionally. It renders directly to the backbuffer
    one object at a time shading each one as it goes.

    Internally the Qt3D::QForwardRenderer is a subclass of Qt3D::QTechniqueFilter.
    This a is a single leaf Framegraph tree which contains a Qt3D::QViewport, a Qt3D::QCameraSelector
    and a Qt3D::QClearBuffer.
    The Qt3D::QForwardRenderer has a default requirement annotation whose name is "renderingStyle" and value "forward".
    If you need to filter out your techniques, you should do so based on that annocation.

    By default the viewport occupies the whole screen and the clear color is white.
*/

/*!
    Constructs a new Qt3D::QForwardRenderer instance with parent object \a parent.
 */
QForwardRenderer::QForwardRenderer(QNode *parent)
    : QTechniqueFilter(*new QForwardRendererPrivate, parent)
{
    Q_D(QForwardRenderer);
    QObject::connect(d->m_viewport, SIGNAL(clearColorChanged()), this, SIGNAL(clearColorChanged()));
    QObject::connect(d->m_viewport, SIGNAL(rectChanged()), this, SIGNAL(viewportRectChanged()));
    QObject::connect(d->m_cameraSelector, SIGNAL(cameraChanged()), this, SIGNAL(cameraChanged()));
    d->init();
}

/*!
    Destroys the QForwardRenderer instance.
*/
QForwardRenderer::~QForwardRenderer()
{
}

void QForwardRenderer::setViewportRect(const QRectF &viewportRect)
{
    Q_D(QForwardRenderer);
    d->m_viewport->setRect(viewportRect);
}

void QForwardRenderer::setClearColor(const QColor &clearColor)
{
    Q_D(QForwardRenderer);
    d->m_viewport->setClearColor(clearColor);
}

void QForwardRenderer::setCamera(QEntity *camera)
{
    Q_D(QForwardRenderer);
    d->m_cameraSelector->setCamera(camera);
}

/*!
    \property Qt3D::QForwardRenderer::viewportRect

    Holds the current viewport rect.
 */
QRectF QForwardRenderer::viewportRect() const
{
    Q_D(const QForwardRenderer);
    return d->m_viewport->rect();
}

/*!
    \property Qt3D::QForwardRenderer::clearColor
    Holds the current clearColor.
 */
QColor QForwardRenderer::clearColor() const
{
    Q_D(const QForwardRenderer);
    return d->m_viewport->clearColor();
}

/*!
    \property Qt3D::QForwardRenderer::camera
    Holds the current QEntity camera used to render the scene.

    \note A camera is a QEntity that has a QCameraLens as one of its components.
 */
QEntity *QForwardRenderer::camera() const
{
    Q_D(const QForwardRenderer);
    return d->m_cameraSelector->camera();
}

} // Qt3D

QT_END_NAMESPACE