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 "qmultisampleantialiasing.h" |
5 | #include "qrenderstate_p.h" |
6 | #include <private/qnode_p.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | namespace Qt3DRender { |
11 | |
12 | /*! |
13 | \class Qt3DRender::QMultiSampleAntiAliasing |
14 | \brief Enable multisample antialiasing. |
15 | \since 5.7 |
16 | \ingroup renderstates |
17 | \inmodule Qt3DRender |
18 | |
19 | A Qt3DRender::QMultiSampleAntiAliasing class enables multisample antialiasing. |
20 | |
21 | It can be added to a QRenderPass by calling QRenderPass::addRenderState(): |
22 | |
23 | \code |
24 | QRenderPass *renderPass = new QRenderPass(); |
25 | |
26 | QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing(); |
27 | renderPass->addRenderState(msaa); |
28 | \endcode |
29 | |
30 | Or a QRenderStateSet by calling QRenderStateSet::addRenderState(): |
31 | |
32 | \code |
33 | QRenderStateSet *renderStateSet = new QRenderStateSet(); |
34 | |
35 | QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing(); |
36 | renderStateSet->addRenderState(msaa); |
37 | \endcode |
38 | |
39 | For multisampling to take effect, the render target must have been allocated |
40 | with multisampling enabled: |
41 | |
42 | \code |
43 | QTexture2DMultisample *colorTex = new QTexture2DMultisample; |
44 | colorTex->setFormat(QAbstractTexture::RGBA8_UNorm); |
45 | colorTex->setWidth(1024); |
46 | colorTex->setHeight(1024); |
47 | |
48 | QRenderTargetOutput *color = new QRenderTargetOutput; |
49 | color->setAttachmentPoint(QRenderTargetOutput::Color0); |
50 | color->setTexture(colorTex); |
51 | |
52 | QTexture2DMultisample *depthStencilTex = new QTexture2DMultisample; |
53 | depthStencilTex->setFormat(QAbstractTexture::RGBA8_UNorm); |
54 | depthStencilTex->setWidth(1024); |
55 | depthStencilTex->setHeight(1024); |
56 | |
57 | QRenderTargetOutput *depthStencil = new QRenderTargetOutput; |
58 | depthStencil->setAttachmentPoint(QRenderTargetOutput::DepthStencil); |
59 | depthStencil->setTexture(depthStencilTex); |
60 | |
61 | Qt3DRender::QRenderTarget *renderTarget = new Qt3DRender::QRenderTarget; |
62 | renderTarget->addOutput(color); |
63 | renderTarget->addOutput(depthStencil); |
64 | \endcode |
65 | |
66 | \include code/src_render_renderstates_qmultisampleantialiasing.qdocinc |
67 | |
68 | \note When using OpenGL as the graphics API, glEnable(GL_MULTISAMPLE) will be called if |
69 | QMultiSampleAntiAliasing has been added to the render states. |
70 | */ |
71 | |
72 | /*! |
73 | \qmltype MultiSampleAntiAliasing |
74 | \brief Enable multisample antialiasing. |
75 | \since 5.7 |
76 | \ingroup renderstates |
77 | \inqmlmodule Qt3D.Render |
78 | \inherits RenderState |
79 | \instantiates Qt3DRender::QMultiSampleAntiAliasing |
80 | |
81 | A MultiSampleAntiAliasing type enables multisample antialiasing. |
82 | |
83 | It can be added to a RenderPass: |
84 | |
85 | \qml |
86 | RenderPass { |
87 | shaderProgram: ShaderProgram { |
88 | // ... |
89 | } |
90 | renderStates: [ |
91 | MultiSampleAntiAliasing {} |
92 | ] |
93 | } |
94 | \endqml |
95 | |
96 | Or a RenderStateSet: |
97 | |
98 | \qml |
99 | RenderStateSet { |
100 | renderStates: [ |
101 | MultiSampleAntiAliasing {} |
102 | ] |
103 | } |
104 | \endqml |
105 | |
106 | For multisampling to take effect, the render target must have been allocated |
107 | with multisampling enabled: |
108 | |
109 | \qml |
110 | RenderTarget { |
111 | attachments: [ |
112 | RenderTargetOutput { |
113 | attachmentPoint: RenderTargetOutput.Color0 |
114 | texture: Texture2DMultisample { |
115 | width: 1024 |
116 | height: 1024 |
117 | format: Texture.RGBA8_UNorm |
118 | } |
119 | }, |
120 | RenderTargetOutput { |
121 | attachmentPoint: RenderTargetOutput.DepthStencil |
122 | texture: Texture2DMultisample{ |
123 | width: 1024 |
124 | height: 1024 |
125 | format: Texture.D24S8 |
126 | } |
127 | } |
128 | ] |
129 | } |
130 | \endqml |
131 | |
132 | Further, the shader code must use multisampling sampler types and texelFetch() instead |
133 | of texture(). |
134 | |
135 | \include code/src_render_renderstates_qmultisampleantialiasing.qdocinc |
136 | |
137 | \note When using OpenGL as the graphics API, glEnable(GL_MULTISAMPLE) will be called if |
138 | MultiSampleAntiAliasing has been added to the render states. |
139 | */ |
140 | |
141 | class QMultiSampleAntiAliasingPrivate : public QRenderStatePrivate |
142 | { |
143 | public: |
144 | QMultiSampleAntiAliasingPrivate() |
145 | : QRenderStatePrivate(Render::MSAAEnabledStateMask) |
146 | { |
147 | } |
148 | |
149 | Q_DECLARE_PUBLIC(QMultiSampleAntiAliasing) |
150 | }; |
151 | |
152 | /*! |
153 | The constructor creates a new QMultiSampleAntiAliasing::QMultiSampleAntiAliasing |
154 | instance with the specified \a parent. |
155 | */ |
156 | QMultiSampleAntiAliasing::QMultiSampleAntiAliasing(QNode *parent) |
157 | : QRenderState(*new QMultiSampleAntiAliasingPrivate, parent) |
158 | { |
159 | } |
160 | |
161 | /*! \internal */ |
162 | QMultiSampleAntiAliasing::~QMultiSampleAntiAliasing() |
163 | { |
164 | } |
165 | |
166 | } // namespace Qt3DRender |
167 | |
168 | QT_END_NAMESPACE |
169 | |
170 | #include "moc_qmultisampleantialiasing.cpp" |
171 | |
172 | |