QMultiSampleAntiAliasing Class


Enable multisample antialiasing More...

Header: #include <QMultiSampleAntiAliasing>
qmake: QT += 3drender
Since: Qt 5.7
Instantiated By: MultiSampleAntiAliasing
Inherits: Qt3DRender::QRenderState

Public Functions

QMultiSampleAntiAliasing(Qt3DCore::QNode *parent = nullptr)

Additional Inherited Members

Detailed Description

Enable multisample antialiasing

A Qt3DRender::QMultiSampleAntiAliasing class enables multisample antialiasing.

It can be added to a QRenderPass by calling QRenderPass::addRenderState():

QRenderPass *renderPass = new QRenderPass();

QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing();

Or a QRenderStateSet by calling QRenderStateSet::addRenderState():

QRenderStateSet *renderStateSet = new QRenderStateSet();

QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing();

For multisampling to take effect, the render target must have been allocated with multisampling enabled:

QTexture2DMultisample *colorTex = new QTexture2DMultisample;

QRenderTargetOutput *color = new QRenderTargetOutput;

QTexture2DMultisample *depthStencilTex = new QTexture2DMultisample;

QRenderTargetOutput *depthStencil = new QRenderTargetOutput;

Qt3DRender::QRenderTarget *renderTarget = new Qt3DRender::QRenderTarget;

Further, the shader code must use multisampling sampler types and texelFetch() instead of texture().

For example, if you have code like

#version 150

uniform sampler2D colorTexture;
in vec2 texCoord;
out vec4 fragColor;

void main()
    fragColor = texture(colorTexture, texCoord);

you can rewrite it as

#version 150

uniform sampler2DMS colorTexture;
in vec2 texCoord;
out vec4 fragColor;

void main()
    ivec2 tc = ivec2(floor(textureSize(colorTexture) * texCoord));
    vec4 c = texelFetch(colorTexture, tc, 0) +
                texelFetch(colorTexture, tc, 1) +
                texelFetch(colorTexture, tc, 2) +
                texelFetch(colorTexture, tc, 3);
    fragColor = c / 4.0;

Note: When using OpenGL as the graphics API, glEnable(GL_MULTISAMPLE) will be called if QMultiSampleAntiAliasing has been added to the render states.

Member Function Documentation

QMultiSampleAntiAliasing::QMultiSampleAntiAliasing(Qt3DCore::QNode *parent = nullptr)

The constructor creates a new QMultiSampleAntiAliasing::QMultiSampleAntiAliasing instance with the specified parent.

© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.