qt opengl paintgl 画点云内存溢出
在paintgl() 这个函数中更新点云时需要注意以下两个问题
1 : 在paintgl()这个函数中使用 glGenBuffer(vbo) 后 需要使用 glDeleteBuffers(1,&vbo) 不然你只要update()后都会导致之前Gen的内存没有释放从而导致内存泄漏
2: 在paintgl()循环的加载点云中时,每次更新都需要使用 shaderProgram_point.bind();不然着色器将会实效,显示白色的点云。
for (int i = pcd_start_num; i < pcd_end_num; ++i)
{
//绑定 顶点与着色器配置
shaderProgram_point.bind();
QMatrix4x4 model_pcd;
const Eigen::Matrix4d ipose = map_.poses_.at(i);
model_pcd.translate(ipose(0,3), ipose(1,3), ipose(2,3));
Eigen::Vector3d iypr = R2ypr(ipose.block<3, 3>(0, 0));
model_pcd.rotate(iypr.z(), 1.0, 0.0, 0.0);
model_pcd.rotate(iypr.y(), 0.0, 1.0, 0.0);
model_pcd.rotate(iypr.x(), 0.0, 0.0, 1.0);
shaderProgram_point.setUniformValue("model", model_pcd);
std::vector<float> pointCloud = map_.opengle_pointCloud[i];
//加载点云
point_num = draw_pointdata(pointCloud);
// std::cout << " point_num " << point_num << std::endl;
// be sure to activate shader when setting uniforms/drawing objects
glBindVertexArray(VAO_Point);
glPointSize(1.0f);
//std::cout << " point_num : " << point_num << std::endl;
glDrawArrays(GL_POINTS, 0, point_num);
//释放内存
glDeleteBuffers(1, &VBO_Point);
}
效果图如下: