Ensure correct FBO size in QOpenGLWidget.

This commit is contained in:
John Preston 2023-03-13 15:56:17 +04:00
parent 503320296d
commit c80df2cdd2
2 changed files with 20 additions and 0 deletions

View file

@ -73,6 +73,7 @@ QImage Image::takeImage() {
void Image::invalidate() {
_storage = base::take(_image);
_subimage = QSize();
}
void Image::bind(QOpenGLFunctions &f) {
@ -119,8 +120,10 @@ void Image::bind(QOpenGLFunctions &f) {
}
void Image::destroy(QOpenGLFunctions *f) {
invalidate();
_textures.destroy(f);
_cacheKey = 0;
_textureSize = QSize();
}
TexturedRect Image::texturedRect(

View file

@ -30,11 +30,14 @@ 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> _renderer;
QMetaObject::Connection _connection;
QSize _deviceSize;
bool _inPaintEvent = false;
};
@ -76,9 +79,23 @@ void SurfaceOpenGL::initializeGL() {
}
void SurfaceOpenGL::resizeGL(int w, int h) {
_deviceSize = QSize(w, h) * devicePixelRatio();
_renderer->resize(this, *context()->functions(), w, h);
}
void SurfaceOpenGL::paintEvent(QPaintEvent *e) {
if (_inPaintEvent) {
return;
}
_inPaintEvent = true;
if (_deviceSize != size() * devicePixelRatio()) {
QResizeEvent event = { size(), size() };
resizeEvent(&event);
}
QOpenGLWidget::paintEvent(e);
_inPaintEvent = false;
}
void SurfaceOpenGL::paintGL() {
if (!updatesEnabled() || size().isEmpty() || !isValid()) {
return;