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
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to