2

I'm trying to enable Multisampling in qt3d. The Qt3DExtras::Qt3DWindow already does the following during initialisation:

format.setDepthBufferSize(24);
format.setSamples(4);
format.setStencilBufferSize(8);
setFormat(format);
QSurfaceFormat::setDefaultFormat(format);

which is a good start. So according to this post, the only OpenGL call necessary to enable Multisampling would be

glEnable(GL_MULTISAMPLE);

And indeed, the documentation of documentation of QMultiSampleAntiAliasing states:

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

So to add the QMultiSampleAntiAliasing to the Framegraph, I came up with the following:

//For antialiasing
Qt3DRender::QRenderStateSet *multiSampleRenderStateSet = new Qt3DRender::QRenderStateSet;
Qt3DRender::QMultiSampleAntiAliasing *msaa = new Qt3DRender::QMultiSampleAntiAliasing;
multiSampleRenderStateSet->addRenderState(msaa);
this->activeFrameGraph()->setParent(multiSampleRenderStateSet);
this->setActiveFrameGraph(multiSampleRenderStateSet);

But obviously, as this overwrites all default RenderStates globally, it leaves me with a pretty messed up rendering. And I'm not even sure Multisampling is enabled (or whether it was even already enabled before?).

So basically, my question is:

What is the easiest way to add a QRenderState to a default QForwardRenderer framegraph? Especially a QMultiSampleAntiAliasing?

1 Answers1

3

Okay, so after reading this email-thread, I now use the following lines:

//For antialiasing
Qt3DRender::QRenderStateSet *renderStateSet = new Qt3DRender::QRenderStateSet;

Qt3DRender::QMultiSampleAntiAliasing *msaa = new Qt3DRender::QMultiSampleAntiAliasing;
renderStateSet->addRenderState(msaa);
Qt3DRender::QDepthTest *depthTest = new Qt3DRender::QDepthTest;
depthTest->setDepthFunction(Qt3DRender::QDepthTest::LessOrEqual);
renderStateSet->addRenderState(depthTest);

this->activeFrameGraph()->setParent(renderStateSet);
this->setActiveFrameGraph(renderStateSet);

This apparently restores the default DepthTest of Qt3D and gives me a seemingly clean render.