Fix custom OpenGL renderers on macOS.

This commit is contained in:
John Preston 2021-06-11 17:22:55 +04:00
parent 43efd9e307
commit 9294c8c695

View file

@ -12,6 +12,7 @@
#include <QtGui/QtEvents> #include <QtGui/QtEvents>
#include <QtGui/QOpenGLContext> #include <QtGui/QOpenGLContext>
#include <QtGui/QWindow> #include <QtGui/QWindow>
#include <QtGui/QPaintEngine>
#include <QtWidgets/QOpenGLWidget> #include <QtWidgets/QOpenGLWidget>
namespace Ui::GL { namespace Ui::GL {
@ -82,7 +83,14 @@ void SurfaceOpenGL::paintEvent(QPaintEvent *e) {
if (!updatesEnabled() || size().isEmpty() || !isValid()) { if (!updatesEnabled() || size().isEmpty() || !isValid()) {
return; return;
} }
makeCurrent(); auto redirectOffset = QPoint();
const auto rpd = redirected(&redirectOffset);
const auto device = rpd ? rpd : static_cast<QPaintDevice*>(this);
const auto engine = device->paintEngine();
if (!engine) {
return;
}
engine->begin(device);
const auto f = context()->functions(); const auto f = context()->functions();
if (const auto bg = _renderer->clearColor()) { if (const auto bg = _renderer->clearColor()) {
f->glClearColor(bg->redF(), bg->greenF(), bg->blueF(), bg->alphaF()); f->glClearColor(bg->redF(), bg->greenF(), bg->blueF(), bg->alphaF());
@ -94,6 +102,7 @@ void SurfaceOpenGL::paintEvent(QPaintEvent *e) {
width() * devicePixelRatio(), width() * devicePixelRatio(),
height() * devicePixelRatio()); height() * devicePixelRatio());
_renderer->paint(this, *f); _renderer->paint(this, *f);
engine->end();
} }
void SurfaceOpenGL::callDeInit() { void SurfaceOpenGL::callDeInit() {