[Interest] Qt 6.7: How to set the blend equation when doing blend on updateGraphicsPipelineState?

Laszlo Agocs laszlo.agocs at qt.io
Fri May 10 11:53:07 CEST 2024


Hi Nuno,

There is no immediate solution to this, or any similar cases where a QSGMaterialShader subclass alters arbitrary OpenGL state, completely unknown to Qt and the scenegraph renderer. (the number of such materials out there is believed to be quite low, though)

The old Qt 5 approach is not compatible with Qt 6, for multiple reasons: one being the obvious problem that application code calling glWhatever() when the scenegraph is rendering with D3D or Metal is not going to work very well; the other that even if one only cares about OpenGL, the internal rendering pipeline in Qt 6 is different enough from Qt 5 so that a QSGMaterialShader subclass attempting to issue OpenGL calls in any of its virtual overrides is futile.

See also https://doc.qt.io/qt-6/qsgmaterialshader-graphicspipelinestate.html#details

Graphics pipeline state settings that we deem important enough for custom scenegraph materials to have control over, need to have explicit support in the GraphicsPipelineState struct and the scenegraph renderer. Some things got added during the 6.x series so far (polygon mode, separate blend factors). What we can do with regards to the rgb/alpha blend operations is to follow the same pattern and introduce these in Qt 6.8 for example. (but it will not be possible to support this in patch releases of earlier versions)

Best regards,
Laszlo

________________________________
From: Nuno Santos <nuno.santos at imaginando.pt>
Sent: Wednesday, May 8, 2024 5:55 PM
To: Laszlo Agocs <laszlo.agocs at qt.io>
Cc: interestqt-project. org <interest at qt-project.org>
Subject: Re: [Interest] Qt 6.7: How to set the blend equation when doing blend on updateGraphicsPipelineState?

Lazslo,

Thank you very much for your reply.

I was really hopeful that there was some kind of workaround for this limitation. This renders impossible to port an application from Qt 5 to Qt 6 at least as far as my knowledge goes.

Is there any possible workaround for this limitation? Can I do it if I edit the source code in any way? Can you please advise?

With the current architecture the application relies heavily on this to make blending between layers.

Thank you in advance!

Best regards,

Nuno

On 8 May 2024, at 16:42, Laszlo Agocs <laszlo.agocs at qt.io> wrote:

Hi,

As you found, QSGMaterialShader::GraphicsPipelineState allows specifying the blend factors, and from Qt 6.5 on it also supports specifying separate RGB and alpha factors.

However, the blend equation is always ADD. There is no way to change that currently.

Best regards,
Laszlo

________________________________
From: Interest <interest-bounces at qt-project.org> on behalf of Nuno Santos via Interest <interest at qt-project.org>
Sent: Monday, May 6, 2024 7:21 PM
To: interestqt-project. org <interest at qt-project.org>
Subject: [Interest] Qt 6.7: How to set the blend equation when doing blend on updateGraphicsPipelineState?

Hi,

I’m porting an app from Qt 5.15 to Qt 6.7 but I’m stumbling on the fact that there is no equivalent to blend equation in OpenGL.

Note: At the time being, I’m still using OpenGL as graphics backend to minimise the already huge ongoing port.


To achieve blending mode between nodes, I was using a mix between glBlendFunc and glBlendEquation:

case Normal:
QOpenGLContext::currentContext()->functions()->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
QOpenGLContext::currentContext()->functions()->glBlendEquation(GL_FUNC_ADD);
break;
case Screen:
QOpenGLContext::currentContext()->functions()->glBlendFunc(GL_SRC_COLOR, GL_ONE);
QOpenGLContext::currentContext()->functions()->glBlendEquation(GL_FUNC_ADD);
break;
case Overlay:
QOpenGLContext::currentContext()->functions()->glBlendFunc(GL_SRC_COLOR, GL_ONE);
QOpenGLContext::currentContext()->functions()->glBlendEquation(GL_MAX);
break;
case Difference:
QOpenGLContext::currentContext()->functions()->glBlendFunc(GL_SRC_COLOR, GL_ONE);
QOpenGLContext::currentContext()->functions()->glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
break;

But in the newest version of QSGMaterialShader class documentation it says:

"The shader pipeline state changes are less often used. One use case is materials that wish to use a specific blend mode. The relevant function is updateGraphicsPipelineState(). This function is not called unless the QSGMaterialShader has opted in by setting the flag UpdatesGraphicsPipelineState. The task of the function is to update the GraphicsPipelineState struct instance that is passed to it with the desired changes. Currently only blending and culling-related features are available, other states cannot be controlled by materials.”

So I’m now trying to use

bool QSGMaterialShader::updateGraphicsPipelineState(QSGMaterialShader::RenderState &state, QSGMaterialShader::GraphicsPipelineState *ps, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)

case Normal:
ps->srcColor = QSGMaterialShader::GraphicsPipelineState::One;
ps->dstColor = QSGMaterialShader::GraphicsPipelineState::OneMinusSrcAlpha;
break;
case Screen:
ps->srcColor = QSGMaterialShader::GraphicsPipelineState::SrcColor;
ps->dstColor = QSGMaterialShader::GraphicsPipelineState::One;
break;
case Overlay:
ps->srcColor = QSGMaterialShader::GraphicsPipelineState::SrcColor;
ps->dstColor = QSGMaterialShader::GraphicsPipelineState::One;
break;
case Difference:
ps->srcColor = QSGMaterialShader::GraphicsPipelineState::SrcColor;
ps->dstColor = QSGMaterialShader::GraphicsPipelineState::One;
break;


When the blendEquation GL_FUNC_ADD was used, it seems to be working.

But when I get to modes like Overlay and Difference, where the SRC and DST are the same, without a blend equation, I don’t know how to do it.

Is there support to this use case?

Thank you in advance!

Best regards,

Nuno

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240510/9dcacaed/attachment.htm>


More information about the Interest mailing list