diff --git a/ui/gl/gl_primitives.cpp b/ui/gl/gl_primitives.cpp index c1533fdc..9b8b785d 100644 --- a/ui/gl/gl_primitives.cpp +++ b/ui/gl/gl_primitives.cpp @@ -122,53 +122,4 @@ void FillTexturedRectangle( f.glDisableVertexAttribArray(texcoord); } -void BackgroundFiller::init(QOpenGLFunctions &f) { - _bgBuffer.emplace(); - _bgBuffer->setUsagePattern(QOpenGLBuffer::DynamicDraw); - _bgBuffer->create(); - _bgProgram.emplace(); - LinkProgram( - &*_bgProgram, - VertexShader({ VertexViewportTransform() }), - FragmentShader({ FragmentStaticColor() })); -} - -void BackgroundFiller::deinit(QOpenGLFunctions &f) { - _bgProgram.reset(); - _bgBuffer.reset(); -} - -void BackgroundFiller::fill( - QOpenGLFunctions &f, - const QRegion ®ion, - QSize viewport, - float factor, - const QColor &color) { - const auto rgb = color.toRgb(); - if (region.isEmpty()) { - return; - } else if (region.end() - region.begin() == 1 - && (*region.begin()).size() == viewport) { - f.glClearColor(rgb.redF(), rgb.greenF(), rgb.blueF(), rgb.alphaF()); - f.glClear(GL_COLOR_BUFFER_BIT); - return; - } - _bgTriangles.resize((region.end() - region.begin()) * 12); - auto coords = _bgTriangles.data(); - for (const auto rect : region) { - FillRectTriangleVertices( - coords, - TransformRect(rect, viewport, factor)); - coords += 12; - } - _bgProgram->bind(); - _bgProgram->setUniformValue("viewport", QSizeF(viewport * factor)); - FillTriangles( - f, - _bgTriangles, - &*_bgBuffer, - &*_bgProgram, - rgb); -} - } // namespace Ui::GL diff --git a/ui/gl/gl_primitives.h b/ui/gl/gl_primitives.h index 444b6ba3..bfd13bca 100644 --- a/ui/gl/gl_primitives.h +++ b/ui/gl/gl_primitives.h @@ -37,32 +37,4 @@ void FillTexturedRectangle( not_null program, int skipVertices = 0); -class BackgroundFiller final { -public: - void init(QOpenGLFunctions &f); - void deinit(QOpenGLFunctions &); - - void fill( - QOpenGLFunctions &f, - const QRegion ®ion, - QSize viewport, - float factor, - const QColor &color); - - void fill( - QOpenGLFunctions &f, - const QRegion ®ion, - QSize viewport, - float factor, - const style::color &color) { - return fill(f, region, viewport, factor, color->c); - } - -private: - std::optional _bgBuffer; - std::optional _bgProgram; - std::vector _bgTriangles; - -}; - } // namespace Ui::GL diff --git a/ui/gl/gl_surface.cpp b/ui/gl/gl_surface.cpp index 0196f92f..87ffa293 100644 --- a/ui/gl/gl_surface.cpp +++ b/ui/gl/gl_surface.cpp @@ -30,7 +30,7 @@ class SurfaceOpenGL final private: void initializeGL() override; void resizeGL(int w, int h) override; - void paintGL() override; + void paintEvent(QPaintEvent *e) override; void callDeInit(); const std::unique_ptr _renderer; @@ -78,8 +78,22 @@ void SurfaceOpenGL::resizeGL(int w, int h) { _renderer->resize(this, *context()->functions(), w, h); } -void SurfaceOpenGL::paintGL() { - _renderer->paint(this, *context()->functions()); +void SurfaceOpenGL::paintEvent(QPaintEvent *e) { + if (!updatesEnabled() || size().isEmpty() || !isValid()) { + return; + } + makeCurrent(); + 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->glViewport( + 0, + 0, + width() * devicePixelRatio(), + height() * devicePixelRatio()); + _renderer->paint(this, *f); } void SurfaceOpenGL::callDeInit() { diff --git a/ui/gl/gl_surface.h b/ui/gl/gl_surface.h index 89b925e0..1bf5981d 100644 --- a/ui/gl/gl_surface.h +++ b/ui/gl/gl_surface.h @@ -42,6 +42,10 @@ class Renderer { not_null widget, QOpenGLFunctions &f); + [[nodiscard]] virtual std::optional clearColor() { + return std::nullopt; + } + virtual void paintFallback( Painter &&p, const QRegion &clip,