Remove BackgroundFiller, use glClear in paintEvent.
This commit is contained in:
parent
1c004580eb
commit
098eb59f2f
4 changed files with 21 additions and 80 deletions
|
|
@ -122,53 +122,4 @@ void FillTexturedRectangle(
|
||||||
f.glDisableVertexAttribArray(texcoord);
|
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
|
} // namespace Ui::GL
|
||||||
|
|
|
||||||
|
|
@ -37,32 +37,4 @@ void FillTexturedRectangle(
|
||||||
not_null<QOpenGLShaderProgram*> program,
|
not_null<QOpenGLShaderProgram*> program,
|
||||||
int skipVertices = 0);
|
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<QOpenGLBuffer> _bgBuffer;
|
|
||||||
std::optional<QOpenGLShaderProgram> _bgProgram;
|
|
||||||
std::vector<float> _bgTriangles;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Ui::GL
|
} // namespace Ui::GL
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
void resizeGL(int w, int h) override;
|
void resizeGL(int w, int h) override;
|
||||||
void paintGL() override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
void callDeInit();
|
void callDeInit();
|
||||||
|
|
||||||
const std::unique_ptr<Renderer> _renderer;
|
const std::unique_ptr<Renderer> _renderer;
|
||||||
|
|
@ -78,8 +78,22 @@ void SurfaceOpenGL::resizeGL(int w, int h) {
|
||||||
_renderer->resize(this, *context()->functions(), w, h);
|
_renderer->resize(this, *context()->functions(), w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SurfaceOpenGL::paintGL() {
|
void SurfaceOpenGL::paintEvent(QPaintEvent *e) {
|
||||||
_renderer->paint(this, *context()->functions());
|
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() {
|
void SurfaceOpenGL::callDeInit() {
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,10 @@ public:
|
||||||
not_null<QOpenGLWidget*> widget,
|
not_null<QOpenGLWidget*> widget,
|
||||||
QOpenGLFunctions &f);
|
QOpenGLFunctions &f);
|
||||||
|
|
||||||
|
[[nodiscard]] virtual std::optional<QColor> clearColor() {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void paintFallback(
|
virtual void paintFallback(
|
||||||
Painter &&p,
|
Painter &&p,
|
||||||
const QRegion &clip,
|
const QRegion &clip,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue