1/****************************************************************************
2**
3** Copyright (C) 2016 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 "qmultisampleantialiasing.h"
41#include "qrenderstate_p.h"
42#include <private/qnode_p.h>
43
44QT_BEGIN_NAMESPACE
45
46namespace Qt3DRender {
47
48/*!
49 \class Qt3DRender::QMultiSampleAntiAliasing
50 \brief Enable multisample antialiasing.
51 \since 5.7
52 \ingroup renderstates
53 \inmodule Qt3DRender
54
55 A Qt3DRender::QMultiSampleAntiAliasing class enables multisample antialiasing.
56
57 It can be added to a QRenderPass by calling QRenderPass::addRenderState():
58
59 \code
60 QRenderPass *renderPass = new QRenderPass();
61
62 QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing();
63 renderPass->addRenderState(msaa);
64 \endcode
65
66 Or a QRenderStateSet by calling QRenderStateSet::addRenderState():
67
68 \code
69 QRenderStateSet *renderStateSet = new QRenderStateSet();
70
71 QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing();
72 renderStateSet->addRenderState(msaa);
73 \endcode
74
75 For multisampling to take effect, the render target must have been allocated
76 with multisampling enabled:
77
78 \code
79 QTexture2DMultisample *colorTex = new QTexture2DMultisample;
80 colorTex->setFormat(QAbstractTexture::RGBA8_UNorm);
81 colorTex->setWidth(1024);
82 colorTex->setHeight(1024);
83
84 QRenderTargetOutput *color = new QRenderTargetOutput;
85 color->setAttachmentPoint(QRenderTargetOutput::Color0);
86 color->setTexture(colorTex);
87
88 QTexture2DMultisample *depthStencilTex = new QTexture2DMultisample;
89 depthStencilTex->setFormat(QAbstractTexture::RGBA8_UNorm);
90 depthStencilTex->setWidth(1024);
91 depthStencilTex->setHeight(1024);
92
93 QRenderTargetOutput *depthStencil = new QRenderTargetOutput;
94 depthStencil->setAttachmentPoint(QRenderTargetOutput::DepthStencil);
95 depthStencil->setTexture(depthStencilTex);
96
97 Qt3DRender::QRenderTarget *renderTarget = new Qt3DRender::QRenderTarget;
98 renderTarget->addOutput(color);
99 renderTarget->addOutput(depthStencil);
100 \endcode
101
102 \include code/src_render_renderstates_qmultisampleantialiasing.qdocinc
103
104 \note When using OpenGL as the graphics API, glEnable(GL_MULTISAMPLE) will be called if
105 QMultiSampleAntiAliasing has been added to the render states.
106 */
107
108/*!
109 \qmltype MultiSampleAntiAliasing
110 \brief Enable multisample antialiasing.
111 \since 5.7
112 \ingroup renderstates
113 \inqmlmodule Qt3D.Render
114 \inherits RenderState
115 \instantiates Qt3DRender::QMultiSampleAntiAliasing
116
117 A MultiSampleAntiAliasing type enables multisample antialiasing.
118
119 It can be added to a RenderPass:
120
121 \qml
122 RenderPass {
123 shaderProgram: ShaderProgram {
124 // ...
125 }
126 renderStates: [
127 MultiSampleAntiAliasing {}
128 ]
129 }
130 \endqml
131
132 Or a RenderStateSet:
133
134 \qml
135 RenderStateSet {
136 renderStates: [
137 MultiSampleAntiAliasing {}
138 ]
139 }
140 \endqml
141
142 For multisampling to take effect, the render target must have been allocated
143 with multisampling enabled:
144
145 \qml
146 RenderTarget {
147 attachments: [
148 RenderTargetOutput {
149 attachmentPoint: RenderTargetOutput.Color0
150 texture: Texture2DMultisample {
151 width: 1024
152 height: 1024
153 format: Texture.RGBA8_UNorm
154 }
155 },
156 RenderTargetOutput {
157 attachmentPoint: RenderTargetOutput.DepthStencil
158 texture: Texture2DMultisample{
159 width: 1024
160 height: 1024
161 format: Texture.D24S8
162 }
163 }
164 ]
165 }
166 \endqml
167
168 Further, the shader code must use multisampling sampler types and texelFetch() instead
169 of texture().
170
171 \include code/src_render_renderstates_qmultisampleantialiasing.qdocinc
172
173 \note When using OpenGL as the graphics API, glEnable(GL_MULTISAMPLE) will be called if
174 MultiSampleAntiAliasing has been added to the render states.
175 */
176
177class QMultiSampleAntiAliasingPrivate : public QRenderStatePrivate
178{
179public:
180 QMultiSampleAntiAliasingPrivate()
181 : QRenderStatePrivate(Render::MSAAEnabledStateMask)
182 {
183 }
184
185 Q_DECLARE_PUBLIC(QMultiSampleAntiAliasing)
186};
187
188/*!
189 The constructor creates a new QMultiSampleAntiAliasing::QMultiSampleAntiAliasing
190 instance with the specified \a parent.
191 */
192QMultiSampleAntiAliasing::QMultiSampleAntiAliasing(QNode *parent)
193 : QRenderState(*new QMultiSampleAntiAliasingPrivate, parent)
194{
195}
196
197/*! \internal */
198QMultiSampleAntiAliasing::~QMultiSampleAntiAliasing()
199{
200}
201
202} // namespace Qt3DRender
203
204QT_END_NAMESPACE
205
206

source code of qt3d/src/render/renderstates/qmultisampleantialiasing.cpp