QSGGeometryNode DrawLineStrip (GL_LINE_STRIP) not respecting the depth value
-
I'm currently using a "QSGGeometryNode" with a "DrawLineStrip" "DrawingMode" to render a stroke. My vertex attributes look like this:
using Attributes = std::vector<QSGGeometry::Attribute>; static auto attributeIndex = 0; static auto attributes = Attributes { QSGGeometry::Attribute::create(attributeIndex++, 2, GL_FLOAT, true), //position QSGGeometry::Attribute::create(attributeIndex++, 4, GL_FLOAT), //color QSGGeometry::Attribute::create(attributeIndex++, 1, GL_FLOAT), //depth };
As you can see the depth is fed to the vertex shader separately to the position for simplicity's sake, but also so that the vertex shader can change the depth dynamically.
The following image illustrates the problem where I'm rendering just one line strip geometry (one draw call).
On the left of the following image, you can see that I'm showing the depth value of the stroke in the fragment shader like this:
gl_FragColor = vec4(vec3(gl_FragCoord.z), qt_Opacity);
Note that the stroke looks like it has the correct incremental depth yet there's a lot of self-intersecting happening which I'm guessing has to do with how the vertex data is aligned in the buffer, meaning that the strips that are last in the buffer are rendering last, but instead I want a depth test to be responsible for this.
From what I've read in the documentation the depth testing should be enabled by default, and I can see that the surface is created with a 24bit depth channel.
- The scene graph can support pseudo 3D and proper 3D primitives. For instance, one can implement a "page curl" effect using a ShaderEffect or implement a bumpmapped torus using QSGGeometry and a custom material. While doing so, one needs to take into account that the default renderer already makes use of the depth buffer.
Now I'm not even sure if this is an OpenGL issue or a Qt issue. I've tried enabling the depth test using OpenGL commands like:
glEnable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS);
but I'm not entirely sure where these commands should live exactly. Please take into account that I'm using a plain QQuickItem and a updatePaintNode to create this geometry.
Any help would be much appreciated.