我试图理解QT中的图形示例,并停留在某些东西上。 GLSL顶点和碎片着色器用于绘制图形。
这是顶点着色器代码:
attribute highp vec4 pos;
attribute highp float t;
uniform lowp float size;
uniform highp mat4 qt_Matrix;
varying lowp float vT;
void main(void)
{
vec4 adjustedPos = pos;
adjustedPos.y += (t * size );
gl_Position = qt_Matrix * adjustedPos;
vT = t;
}
什么是vT ???
也是
struct LineVertex {
float x, y, t;
inline void set(float xx, float yy, float tt) {x = xx; y = yy; t = tt;}
};
void LineNode::updateGeometry(const QRectF &bounds, const QList<qreal> &samples) {
m_geometry.allocate(samples.size() * 2);
qreal x = bounds.x();
qreal y = bounds.y();
qreal w = bounds.width();
qreal h = bounds.height();
qreal dx = w / (samples.size() - 1);
LineVertex *v = (LineVertex *) m_geometry.vertexData();
for(int i = 0; i < samples.size(); ++i) {
v[i*2 + 0].set(x + dx * i, y + samples.at(i) * h, 0);
v[i*2 + 1].set(x + dx * i, y + samples.at(i) * h, 1);
}
markDirty(QSGNode::DirtyGeometry);
}
我不明白为什么要进行循环
for(int i = 0; i < samples.size(); ++i) {
v[i*2 + 0].set(x + dx * i, y + samples.at(i) * h, 0);
v[i*2 + 1].set(x + dx * i, y + samples.at(i) * h, 1);
}
他们正在创建一对具有相同位置的顶点,并添加t*size
(在该对的第一个顶点上为0,在第二个顶点上为1)
仅仅正确调整x,y位置还不够
我试图评论adjustedPos.y += (t * size );
,而图表却消失了。