This commit is contained in:
ts-korhonen
2021-12-17 16:48:31 +02:00
4 changed files with 15 additions and 11 deletions

View File

@@ -24,11 +24,9 @@ void HardwareRenderer::setRenderType(RenderType type) {
QSurfaceFormat format; QSurfaceFormat format;
switch (type) { switch (type) {
case RenderType::OpenGL: case RenderType::OpenGL:
setTextureFormat(GL_RGB);
format.setRenderableType(QSurfaceFormat::OpenGL); format.setRenderableType(QSurfaceFormat::OpenGL);
break; break;
case RenderType::OpenGLES: case RenderType::OpenGLES:
setTextureFormat((QApplication::platformName().contains("wayland") || QApplication::platformName() == "cocoa") ? GL_RGB : GL_RGBA);
format.setRenderableType(QSurfaceFormat::OpenGLES); format.setRenderableType(QSurfaceFormat::OpenGLES);
break; break;
} }
@@ -45,5 +43,5 @@ void HardwareRenderer::onBlit(const QImage& img, int x, int y, int w, int h, std
void HardwareRenderer::resizeEvent(QResizeEvent *event) { void HardwareRenderer::resizeEvent(QResizeEvent *event) {
onResize(width(), height()); onResize(width(), height());
QOpenGLWidget::resizeEvent(event); QOpenGLWindow::resizeEvent(event);
} }

View File

@@ -2,6 +2,7 @@
#include <QOpenGLFunctions> #include <QOpenGLFunctions>
#include <QOpenGLWidget> #include <QOpenGLWidget>
#include <QOpenGLWindow>
#include <QPainter> #include <QPainter>
#include <QEvent> #include <QEvent>
#include <QKeyEvent> #include <QKeyEvent>
@@ -16,7 +17,7 @@
#include "wl_mouse.hpp" #include "wl_mouse.hpp"
#endif #endif
class HardwareRenderer : public QOpenGLWidget, protected QOpenGLFunctions, public RendererCommon class HardwareRenderer : public QOpenGLWindow, protected QOpenGLFunctions, public RendererCommon
{ {
Q_OBJECT Q_OBJECT
@@ -26,10 +27,11 @@ public:
void resizeGL(int w, int h) override; void resizeGL(int w, int h) override;
void initializeGL() override; void initializeGL() override;
void paintGL() override; void paintGL() override;
HardwareRenderer(QWidget* parent = nullptr) HardwareRenderer(QWindow* parent = nullptr)
: QOpenGLWidget(parent), QOpenGLFunctions() : QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent), QOpenGLFunctions()
{ {
setMinimumSize(16, 16); setMinimumSize(QSize(16, 16));
setFlags(Qt::FramelessWindowHint);
} }
~HardwareRenderer() ~HardwareRenderer()
{ {

View File

@@ -15,6 +15,8 @@ RendererCommon::RendererCommon() = default;
void RendererCommon::onPaint(QPaintDevice* device) { void RendererCommon::onPaint(QPaintDevice* device) {
QPainter painter(device); QPainter painter(device);
painter.setRenderHint(QPainter::SmoothPixmapTransform, video_filter_method > 0 ? true : false); painter.setRenderHint(QPainter::SmoothPixmapTransform, video_filter_method > 0 ? true : false);
painter.fillRect(0, 0, device->width(), device->height(), QColorConstants::Black);
painter.setCompositionMode(QPainter::CompositionMode_Plus);
painter.drawImage(destination, image, source); painter.drawImage(destination, image, source);
// "release" image, reducing it's refcount, so renderstack::blit() // "release" image, reducing it's refcount, so renderstack::blit()
// won't have to reallocate // won't have to reallocate

View File

@@ -183,18 +183,20 @@ void RendererStack::switchRenderer(Renderer renderer) {
break; break;
case Renderer::OpenGL: case Renderer::OpenGL:
{ {
auto hw = new HardwareRenderer(this); this->createWinId();
auto hw = new HardwareRenderer(this->windowHandle());
connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection); connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection);
hw->setRenderType(HardwareRenderer::RenderType::OpenGL); hw->setRenderType(HardwareRenderer::RenderType::OpenGL);
current.reset(hw); current.reset(this->createWindowContainer(hw, this));
break; break;
} }
case Renderer::OpenGLES: case Renderer::OpenGLES:
{ {
auto hw = new HardwareRenderer(this); this->createWinId();
auto hw = new HardwareRenderer(this->windowHandle());
connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection); connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection);
hw->setRenderType(HardwareRenderer::RenderType::OpenGLES); hw->setRenderType(HardwareRenderer::RenderType::OpenGLES);
current.reset(hw); current.reset(this->createWindowContainer(hw, this));
break; break;
} }
} }