我在Qt项目中使用libQGL来制作点云查看器。问题是,随着更多点(超过300.000),与查看器(旋转,平移,缩放)的交互很慢。我该如何解决这个问题?
答案 0 :(得分:1)
在缩放/平移/旋转时渲染较少的点。渲染点云时,您可以通过将顶点属性缓冲区的步幅乘以3
来渲染每三个点(使用QOpenGLShaderProgram方法)
void PointCloud::paintGL(){
glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
pointProgram->bind ();
points.bind ();
if(transforming){
pointProgram->setAttributeBuffer (pointLoc, GL_FLOAT, offsetof (PointStruct, data), 3,sizeof(PointStruct)*3);
} else {
pointProgram->setAttributeBuffer (pointLoc, GL_FLOAT, offsetof (PointStruct, data), 3,sizeof(PointStruct));
}
CHECK_GL_ERR;
if(transforming){
pointProgram->setAttributeBuffer (pointCol, GL_FLOAT, offsetof (GrabberPointXYZIT,color), 3,sizeof(GrabberPointXYZIT)*3);
} else {
pointProgram->setAttributeBuffer (pointCol, GL_FLOAT, offsetof (GrabberPointXYZIT,color), 3,sizeof(GrabberPointXYZIT));
}
CHECK_GL_ERR;
pointProgram->enableAttributeArray (pointLoc);
pointProgram->enableAttributeArray (pointCol);
pointProgram->setUniformValue (mvpLoc, pMat*vMat);
glDrawArrays (GL_POINTS,0, numPoints);
CHECK_GL_ERR;
pointProgram->release ();
points.release ();
}