From f3744c4ba3ddadd47e280a1ef5fbd002d357d10a Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sun, 5 Mar 2023 15:23:26 +0400 Subject: [PATCH] Use paintGL instead of paintEvent Hopefully making GL code less crashy by using the respective initialization code --- ui/gl/gl_surface.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/ui/gl/gl_surface.cpp b/ui/gl/gl_surface.cpp index fc45dd6..cd57156 100644 --- a/ui/gl/gl_surface.cpp +++ b/ui/gl/gl_surface.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include namespace Ui::GL { @@ -31,7 +30,7 @@ public: private: void initializeGL() override; void resizeGL(int w, int h) override; - void paintEvent(QPaintEvent *e) override; + void paintGL() override; void callDeInit(); const std::unique_ptr _renderer; @@ -55,6 +54,7 @@ SurfaceOpenGL::SurfaceOpenGL( std::unique_ptr renderer) : RpWidgetBase(parent) , _renderer(std::move(renderer)) { + setUpdateBehavior(QOpenGLWidget::PartialUpdate); } SurfaceOpenGL::~SurfaceOpenGL() { @@ -79,30 +79,17 @@ void SurfaceOpenGL::resizeGL(int w, int h) { _renderer->resize(this, *context()->functions(), w, h); } -void SurfaceOpenGL::paintEvent(QPaintEvent *e) { +void SurfaceOpenGL::paintGL() { if (!updatesEnabled() || size().isEmpty() || !isValid()) { return; } - auto redirectOffset = QPoint(); - const auto rpd = redirected(&redirectOffset); - const auto device = rpd ? rpd : static_cast(this); - const auto engine = device->paintEngine(); - if (!engine) { - return; - } - engine->begin(device); - if (!isValid()) { // The call above could lose the context. - return; - } const auto f = context()->functions(); if (const auto bg = _renderer->clearColor()) { f->glClearColor(bg->redF(), bg->greenF(), bg->blueF(), bg->alphaF()); f->glClear(GL_COLOR_BUFFER_BIT); } f->glDisable(GL_BLEND); - f->glViewport(0, 0, device->width(), device->height()); _renderer->paint(this, *f); - engine->end(); } void SurfaceOpenGL::callDeInit() {