将QMultiSampleAntiAliasing添加到QForwardRenderer [英] Add QMultiSampleAntiAliasing to a QForwardRenderer
问题描述
我正在尝试在qt3d中启用多重采样. Qt3DExtras :: Qt3DWindow在初始化过程中已经执行了以下操作:
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);
这是一个好的开始.因此,根据这篇文章,这是唯一的启用多重采样所需的OpenGL调用将是
which is a good start. So according to this post, the only OpenGL call necessary to enable Multisampling would be
glEnable(GL_MULTISAMPLE);
确实, QMultiSampleAntiAliasing的文档指出:
注意:使用OpenGL作为图形API时,如果已将QMultiSampleAntiAliasing添加到渲染状态,则会调用glEnable(GL_MULTISAMPLE).
Note: When using OpenGL as the graphics API, glEnable(GL_MULTISAMPLE) will be called if QMultiSampleAntiAliasing has been added to the render states.
因此,要将QMultiSampleAntiAliasing添加到框架图中,我想到了以下内容:
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);
但是很明显,由于这会全局覆盖所有默认的RenderState,因此给我留下了相当混乱的渲染.而且我什至不能确定是否启用了多重采样(或者之前是否已经启用了多重采样?).
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?).
基本上,我的问题是:
将QRenderState添加到默认QForwardRenderer框架图的最简单方法是什么?尤其是QMultiSampleAntiAliasing?
推荐答案
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);
这显然恢复了Qt3D的默认DepthTest,并给了我看似干净的渲染.
This apparently restores the default DepthTest of Qt3D and gives me a seemingly clean render.
这篇关于将QMultiSampleAntiAliasing添加到QForwardRenderer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!