Allow Ui::GL::Renderer::deinit on lost context.

This commit is contained in:
John Preston 2021-09-03 21:41:04 +03:00
parent a8ce22fd75
commit 29f339e26e
4 changed files with 21 additions and 15 deletions

View file

@ -29,10 +29,12 @@ void GenerateTextures(
}
}
void DestroyTextures(QOpenGLFunctions &f, gsl::span<GLuint> values) {
void DestroyTextures(QOpenGLFunctions *f, gsl::span<GLuint> values) {
Expects(!values.empty());
f.glDeleteTextures(values.size(), values.data());
if (f) {
f->glDeleteTextures(values.size(), values.data());
}
ranges::fill(values, 0);
}
@ -42,10 +44,12 @@ void GenerateFramebuffers(QOpenGLFunctions &f, gsl::span<GLuint> values) {
f.glGenFramebuffers(values.size(), values.data());
}
void DestroyFramebuffers(QOpenGLFunctions &f, gsl::span<GLuint> values) {
void DestroyFramebuffers(QOpenGLFunctions *f, gsl::span<GLuint> values) {
Expects(!values.empty());
f.glDeleteTextures(values.size(), values.data());
if (f) {
f->glDeleteTextures(values.size(), values.data());
}
ranges::fill(values, 0);
}
@ -114,7 +118,7 @@ void Image::bind(QOpenGLFunctions &f) {
}
}
void Image::destroy(QOpenGLFunctions &f) {
void Image::destroy(QOpenGLFunctions *f) {
_textures.destroy(f);
_cacheKey = 0;
}

View file

@ -18,10 +18,10 @@ void GenerateTextures(
gsl::span<GLuint> values,
GLint filter,
GLint clamp);
void DestroyTextures(QOpenGLFunctions &f, gsl::span<GLuint> values);
void DestroyTextures(QOpenGLFunctions *f, gsl::span<GLuint> values);
void GenerateFramebuffers(QOpenGLFunctions &f, gsl::span<GLuint> values);
void DestroyFramebuffers(QOpenGLFunctions &f, gsl::span<GLuint> values);
void DestroyFramebuffers(QOpenGLFunctions *f, gsl::span<GLuint> values);
} // namespace details
@ -42,7 +42,7 @@ public:
clamp);
}
}
void destroy(QOpenGLFunctions &f) {
void destroy(QOpenGLFunctions *f) {
if (created()) {
details::DestroyTextures(f, gsl::make_span(_values));
}
@ -79,7 +79,7 @@ public:
details::GenerateFramebuffers(f, gsl::make_span(_values));
}
}
void destroy(QOpenGLFunctions &f) {
void destroy(QOpenGLFunctions *f) {
if (created()) {
details::DestroyFramebuffers(f, gsl::make_span(_values));
}
@ -113,7 +113,7 @@ public:
void invalidate();
void bind(QOpenGLFunctions &f);
void destroy(QOpenGLFunctions &f);
void destroy(QOpenGLFunctions *f);
[[nodiscard]] TexturedRect texturedRect(
const QRect &geometry,

View file

@ -107,11 +107,13 @@ void SurfaceOpenGL::callDeInit() {
return;
}
QObject::disconnect(base::take(_connection));
const auto surface = window()->windowHandle();
Assert(surface != nullptr);
makeCurrent();
const auto context = this->context();
context->makeCurrent(surface);
_renderer->deinit(this, *context->functions());
_renderer->deinit(
this,
((isValid() && context && QOpenGLContext::currentContext() == context)
? context->functions()
: nullptr));
}
SurfaceRaster::SurfaceRaster(

View file

@ -28,7 +28,7 @@ public:
virtual void deinit(
not_null<QOpenGLWidget*> widget,
QOpenGLFunctions &f) {
QOpenGLFunctions *f) {
}
virtual void resize(