Класс QMultiSampleAntiAliasing
класс Qt3DRender::QMultiSampleAntiAliasingВключить сглаживание с множественной выборкой. Подробнее...
| Заголовок: | #include <QMultiSampleAntiAliasing> |
| CMake: | find_package(Qt6 COMPONENTS 3drender REQUIRED) target_link_libraries(mytarget PRIVATE Qt6::3drender) |
| qmake: | QT += 3drender |
| С момента: | Qt 5.7 |
| Инициализируется: | MultiSampleAntiAliasing |
| Наследуется от: | Qt3DRender::QRenderState |
Открытые функции
| QMultiSampleAntiAliasing(Qt3DCore::QNode *parent = nullptr) |
Подробное описание
Класс Qt3DRender::QMultiSampleAntiAliasing позволяет включить сглаживание с множественной выборкой.
Его можно добавить в QRenderPass, вызвав QRenderPass::addRenderState():
QRenderPass *renderPass = new QRenderPass(); QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing(); renderPass->addRenderState(msaa);
Или в QRenderStateSet, вызвав QRenderStateSet::addRenderState():
QRenderStateSet *renderStateSet = new QRenderStateSet(); QMultiSampleAntiAliasing *msaa = new QMultiSampleAntiAliasing(); renderStateSet->addRenderState(msaa);
Для того, чтобы сглаживание с множественной выборкой подействовало, целевой рендеринг должен быть выделен с поддержкой множественной выборки:
QTexture2DMultisample *colorTex = new QTexture2DMultisample; colorTex->setFormat(QAbstractTexture::RGBA8_UNorm); colorTex->setWidth(1024); colorTex->setHeight(1024); QRenderTargetOutput *color = new QRenderTargetOutput; color->setAttachmentPoint(QRenderTargetOutput::Color0); color->setTexture(colorTex); QTexture2DMultisample *depthStencilTex = new QTexture2DMultisample; depthStencilTex->setFormat(QAbstractTexture::RGBA8_UNorm); depthStencilTex->setWidth(1024); depthStencilTex->setHeight(1024); QRenderTargetOutput *depthStencil = new QRenderTargetOutput; depthStencil->setAttachmentPoint(QRenderTargetOutput::DepthStencil); depthStencil->setTexture(depthStencilTex); Qt3DRender::QRenderTarget *renderTarget = new Qt3DRender::QRenderTarget; renderTarget->addOutput(color); renderTarget->addOutput(depthStencil);
Кроме того, код шейдера должен использовать типы выборки с множественной выборкой и texelFetch() вместо texture().
Например, если у вас есть код типа
#version 150
uniform sampler2D colorTexture;
in vec2 texCoord;
out vec4 fragColor;
void main()
{
fragColor = texture(colorTexture, texCoord);
} вы можете переписать его как
#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;
} Примечание: При использовании OpenGL в качестве графического API вызов glEnable(GL_MULTISAMPLE) будет выполнен, если QMultiSampleAntiAliasing был добавлен в состояния рендеринга.
Документация по функциям-членам
QMultiSampleAntiAliasing::QMultiSampleAntiAliasing(Qt3DCore::QNode *parent = nullptr)
Конструктор создает новый экземпляр QMultiSampleAntiAliasing::QMultiSampleAntiAliasing с указанным parent.
© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.0/qt3drender-qmultisampleantialiasing.html