Fix GL detection without a parent window.

This commit is contained in:
John Preston 2021-05-20 12:22:26 +04:00
parent 95ee92088e
commit ca5b2e6746
3 changed files with 8 additions and 17 deletions

View file

@ -18,7 +18,6 @@
namespace Ui::GL {
Capabilities CheckCapabilities(QWidget *widget) {
auto created = QOpenGLContext();
auto format = QSurfaceFormat();
format.setAlphaBufferSize(8);
if (widget) {
@ -33,19 +32,11 @@ Capabilities CheckCapabilities(QWidget *widget) {
LOG_ONCE(("OpenGL: Not supported for window."));
return {};
}
} else {
created.setFormat(format);
if (!created.create()) {
LOG_ONCE(("OpenGL: Could not create context with alpha."));
return {};
}
}
auto tester = QOpenGLWidget(widget);
if (widget) {
tester.setFormat(format);
tester.grabFramebuffer(); // Force initialize().
}
const auto context = (widget ? tester.context() : &created);
tester.setFormat(format);
tester.grabFramebuffer(); // Force initialize().
const auto context = tester.context();
if (!context) {
LOG_ONCE(("OpenGL: Could not create widget in a window."));
return {};

View file

@ -7,8 +7,8 @@
#include "ui/gl/gl_surface.h"
#include "ui/rp_widget.h"
#include "ui/painter.h"
#include <QtGui/QPainter>
#include <QtGui/QtEvents>
#include <QtGui/QOpenGLContext>
#include <QtWidgets/QOpenGLWidget>
@ -72,7 +72,7 @@ SurfaceRaster::SurfaceRaster(
}
void SurfaceRaster::paintEvent(QPaintEvent *e) {
_renderer->paintFallback(QPainter(this), e->region(), Backend::Raster);
_renderer->paintFallback(Painter(this), e->region(), Backend::Raster);
}
} // namespace
@ -80,7 +80,7 @@ void SurfaceRaster::paintEvent(QPaintEvent *e) {
void Renderer::paint(
not_null<QOpenGLWidget*> widget,
not_null<QOpenGLFunctions*> f) {
paintFallback(QPainter(widget.get()), widget->rect(), Backend::OpenGL);
paintFallback(Painter(widget.get()), widget->rect(), Backend::OpenGL);
}
std::unique_ptr<RpWidgetWrap> CreateSurface(

View file

@ -8,7 +8,7 @@
#include "ui/gl/gl_detection.h"
class QPainter;
class Painter;
class QOpenGLWidget;
class QOpenGLFunctions;
@ -42,7 +42,7 @@ public:
not_null<QOpenGLFunctions*> f);
virtual void paintFallback(
QPainter &&p,
Painter &&p,
const QRegion &clip,
Backend backend) {
}