当在同一个界面中绘制多个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());
}
当使用QCustomPlot在同一界面绘制多个图形并开启OpenGL功能时,可能出现QOpenGLFramebufferObject::bind()错误导致渲染错乱。为解决此问题,可以在QCPPaintBufferGlFbo::draw()函数中检查并切换当前OpenGL上下文,确保与缓冲区上下文一致,从而避免渲染异常。
4643

被折叠的 条评论
为什么被折叠?



