1

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?

Patrick B.
  • 11,773
  • 8
  • 58
  • 101
  • The only thing I can suggest is look at the [Qt3D line width test](https://github.com/qt/qt3d/tree/dev/tests/manual/pointlinesize). Your code should work otherwise, at least that's what I'd say from looking at y our example. – Florian Blume Dec 11 '20 at 12:56
  • This example shows how to change the line-width of a font, doesn't it? Does that mean QLineWidth has nothing to the lines created by a primitive type? – Patrick B. Dec 11 '20 at 14:12
  • 1
    What? No, where do you take from that it's about a fond? Running the test shows a mesh and you can control point and line size through a slider. – Florian Blume Dec 11 '20 at 15:00
  • I only read the code, sorry. I'm having a hard time to map QML-functionalities to their C++ origins. – Patrick B. Dec 11 '20 at 15:20
  • Sorry, I didn't mean to be rude, I was struggling with reading QML in the begging, too. Does the code somehow help you with your problem? – Florian Blume Dec 11 '20 at 15:38
  • I'd say that you really should run the [Qt3D line width test](https://github.com/qt/qt3d/tree/dev/tests/manual/pointlinesize), confirm that it works, and then see how it's different from what you're doing. If it doesn't work then you may be facing the limitation of your OpenGL driver, in which case you could also try with Angle (if you're on windows). – Kuba hasn't forgotten Monica Dec 11 '20 at 17:25
  • It works - somehow, but it's QML, I don't know how to translate the lineWidth Attribute to QLineWidth my renderstates. – Patrick B. Dec 13 '20 at 17:51

2 Answers2

2

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.

1

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

RandomName
  • 163
  • 1
  • 10