Why is QLineWidth not taken into account?

546 Views Asked by At

In Qt3D certain properties of rendered objects are not just simply set on the renderer, but they are globally (per view) or locally (on the material of a rendered object) added to the renderPasses - or so is my comprehension at least. (I'm using PySide2 - but the code is almost the same in C++)

For example when adding a geometry-renderer and using its primitive type point (Qt3DRender.QGeometryRenderer.Point) instead of rendering triangle-faces it displays the points of the geometry.

Here is an example figure with the default type.

enter image description here

The same only showing the points (renderer.setPrimitiveType(Qt3DRender.QGeometryRenderer.Points))

enter image description here

Hard to guess, but here the point-size has been already been changed - using the following code:

material = Qt3DExtras.QPhongMaterial(e)
for t in material.effect().techniques():
    for rp in t.renderPasses():
        pointSize = Qt3DRender.QPointSize(rp)

        pointSize.setSizeMode(Qt3DRender.QPointSize.SizeMode.Fixed)
        pointSize.setValue(5.0)
        rp.addRenderState(pointSize)

According to the documentation the same mechanism can be used to change the line-width when rendering the object with Lines (LineStrip) as primitive type. Adding

    lineWidth = Qt3DRender.QLineWidth(rp)
    lineWidth.setValue(5.)
    lineWidth.setSmooth(True)
    rp.addRenderState(lineWidth)

does not change the line-width.

enter image description here

Why? Where do I need to add QLineWidth? Is it the material I chose which ignores the QLineWidth-state?

2

There are 2 best solutions below

0
On

I'm fighting with similar problems at the moment. I tried to reproduce the behaviour with Qt3D line width test. When setting format version to 4.6 with CoreProfile, the maximum of linewidth seems to be 1 (or equivalently width=3 displayed by the line test). It might be possible that this is the maximum supported range. See: https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glLineWidth.xhtml

opengl glLineWidth() doesn't change size of lines

Note: I deliberately chose version 4.6 as that is the supported openGL version on my environment.

0
On

I ran into the same issue. It appears the problem is caused by Qt3DExtras::Qt3DWindow, which constructs a QSurfaceFormat with an OpenGL core profile. The glLineWidth function is not supported in the core profile.

Unfortunately there is no way to pass a QSurfaceFormat to Qt3DWindow. Setting a new format after the window is created also does not work.

The only way around this is to write your own window class with a QSurfaceFormat in compatibility mode. For example:

setSurfaceType(QSurface::OpenGLSurface);

QSurfaceFormat format = QSurfaceFormat::defaultFormat();
format.setVersion(4, 3);
format.setProfile(QSurfaceFormat::CompatibilityProfile);
format.setDepthBufferSize(24);
format.setSamples(4);
format.setStencilBufferSize(8);
setFormat(format);

QSurfaceFormat::setDefaultFormat(format);

Fortunately Qt3DExtras::Qt3DWindow does not actually contain a lot of functionality and you can easily write a similar class with the QSurfaceFormat changes mentioned above.

You can find the original source here for reference: https://code.woboq.org/qt5/qt3d/src/extras/defaults/qt3dwindow.cpp.html