其他分享
首页 > 其他分享> > 【三】QCustomPlot开启OpenGL绘图上下文异常问题

【三】QCustomPlot开启OpenGL绘图上下文异常问题

作者:互联网

当在同一个界面中绘制多个QCustomPlot图形时,此时如果开启了OpenGL功能,则会提示QOpenGLFramebufferObject::bind() called from incompatible context的警告,界面图形渲染时会出现错乱,可以通过在qcustomplot.cpp的QCPPaintBufferGlFbo::draw()函数中添加以下红色的代码即可。

/* inherits documentation from base class */
void QCPPaintBufferGlFbo::draw(QCPPainter *painter) const
{
  if (!painter || !painter->isActive())
  {
    qDebug() << Q_FUNC_INFO << "invalid or inactive painter passed";
    return;
  }
  if (!mGlFrameBuffer)
  {
    qDebug() << Q_FUNC_INFO << "OpenGL frame buffer object doesn't exist, reallocateBuffer was not called?";
    return;
  }
  if (QOpenGLContext::currentContext() != mGlContext.data()) {
      mGlContext.data()->makeCurrent(mGlContext.data()->surface());
  }
  painter->drawImage(0, 0, mGlFrameBuffer->toImage());
}

标签:mGlFrameBuffer,mGlContext,OpenGL,QCustomPlot,qDebug,上下文,data,painter
来源: https://blog.51cto.com/u_13492397/2973670