2025-01-30

Construct using QRhi

Qt Rendering Hardware Interface is the underlying mechanism that Qt uses to do hardware accelerated rendering cross platform across many heterogenous platforms such as

  • OpenGL
  • OpenGL ES
  • Vulcan
  • DirectX (Microsoft)
  • Metal (Apple)
Previously Qt relied on OpenGL under the hood, but due to the evolution of graphics APIs the decision was made to tranistion to this abstraction layer.




The way QRhi works is by standardizing on a low level "common denominator" API similar to that of Vulcan and then adorning it with well integrated Qt spesific tools, helper classes and helper functions to make it as easy as possible to work with.

For example, Qt Shader Tools (qst) is a commandline tool that allows taking as input shaders in a single source language and spit out a compiled shader binary that is compatible across platforms.

Another example is how easy it is to use existing Qt resource management to work with texture data:

void ExampleRhiWidget::updateCubeTexture()
{
    QImage image(CUBE_TEX_SIZE, QImage::Format_RGBA8888);
    const QRect r(QPoint(0, 0), CUBE_TEX_SIZE);
    QPainter p(&image);
    p.fillRect(r, QGradient::DeepBlue);
    QFont font;
    font.setPointSize(24);
    p.setFont(font);
    p.drawText(r, itemData.cubeText);
    p.end();

    if (!scene.resourceUpdates)
        scene.resourceUpdates = m_rhi->nextResourceUpdateBatch();
    scene.resourceUpdates->uploadTexture(scene.cubeTex.get(), image);
}
We want to create a virtual environment in OctoMY™ called construct that allows us to edit robot layouts, preview 3D data and more. We want to use the modern approaches available in Qt to do this. Since the Qt3D project is deprecated, we will instead focus on using QRhi directly.


No comments:

Post a Comment