Add QMultiSampleAntiAliasing to a QForwardRenderer

蹲街弑〆低调 提交于 2020-01-05 07:08:01

问题


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:


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.



来源:https://stackoverflow.com/questions/51331270/add-qmultisampleantialiasing-to-a-qforwardrenderer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!