Unsolved QML QSGGeometryNode GL_LINES does not work with scaling in vertex shader
-
I am using Qt 5.12
When I render my Custom GeometryNode the lines are not where I expect them to be when using GL_LINES but using GL_LINE_LOOP the lines are where they should be.I have a QSGGeometryNode that renders 3 axis lines.
(0,0) -> (0, 1)
(0,0) -> (1, 1)
(0,0) -> (1, 0)SimpleLine{ x: 1 // when this i a 1 the line are not in the correct spot. As shown in the attached picture unless GL_LINE_LOOP is used y: 0 width: 100 height: 100 }
// X = 0 or GL_LINE_LOOP
// X = 1 and GL_LINES
SimpleLineNode::SimpleLineNode(QColor c) : m_geometry(lineAttributes(), 0) { setGeometry(&m_geometry); // Using GL_LINES // Changing this to GL_LINE_STRIP works with my scaling QMatrix4x4 m_geometry.setDrawingMode(GL_LINES); m_geometry.setLineWidth(5); QSGSimpleMaterial<LineMaterial> *m = LineShader::createMaterial(); m->state()->color = c; m->setFlag(QSGMaterial::Blending); setMaterial(m); setFlag(OwnsMaterial); } void SimpleLineNode::updateGeometry(float x1, float y1, float x2, float y2, const QMatrix4x4 &trans) { QSGGeometry *g = geometry(); g->allocate(2); LineVertex* v = static_cast<LineVertex*>(g->vertexData()); v[0].set(x1, y1); v[1].set(x2, y2); QSGSimpleMaterial<LineMaterial> *m = static_cast<QSGSimpleMaterial<LineMaterial>*>(material()); m->state()->trans = trans; markDirty(QSGNode::DirtyGeometry); markDirty(QSGNode::DirtyMaterial); }
Here is where the lines are being setup and the trans matrix is being computed.
The first 2 lines Red and green are using the trans matrix in the shader.
The blue line is using it on the CPU and just an Identity matrix in the shader.simplelines.cpp SimpleLines::updatePaintNode(QSGNode * old, QQuickItem::UpdatePaintNodeData * data)
float x = rect.x(); float y = rect.y(); float x2 = rect.right(); float y2 = rect.bottom(); float w = rect.width(); float h = rect.height(); float xMax = 1; float yMax = 1; float xScale = w/xMax; float yScale = h/yMax; // I matrix QMatrix4x4 trans = QMatrix4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); trans.scale(xScale,yScale); trans.rotate(180.0f, QVector3D(1,0,0)); trans.translate(0,-1); // Red xLine lineArray->lineOne->updateGeometry(0, 0, xMax, 0, trans); // Green yLine lineArray->lineTwo->updateGeometry(0, 0, 0, yMax, trans); QVector4D point1(0,0,0,1); QVector4D point2(xMax,yMax,0,1); // Blue Diagonal QVector4D point1T = trans*point1; QVector4D point2T = trans*point2; lineArray->lineThree->updateGeometry(point1T.x(), point1T.y(), point2T.x(), point2T.y(), QMatrix4x4());
line.vsh
attribute highp vec2 pos; uniform highp mat4 qt_Matrix; uniform highp mat4 trans; void main(void) { gl_Position = qt_Matrix * trans * vec4(pos.x, pos.y, 0, 1); }