* Fix rare crash when switching renderers
* Abandon QPainter in hardware renderers in favour of OpenGL * Disable VSync in the application globally
This commit is contained in:
@@ -16,10 +16,18 @@ void HardwareRenderer::initializeGL()
|
|||||||
{
|
{
|
||||||
m_context->makeCurrent(this);
|
m_context->makeCurrent(this);
|
||||||
initializeOpenGLFunctions();
|
initializeOpenGLFunctions();
|
||||||
|
m_texture = new QOpenGLTexture(image);
|
||||||
|
m_blt = new QOpenGLTextureBlitter;
|
||||||
|
m_blt->setRedBlueSwizzle(true);
|
||||||
|
m_blt->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareRenderer::paintGL() {
|
void HardwareRenderer::paintGL() {
|
||||||
onPaint(this);
|
m_context->makeCurrent(this);
|
||||||
|
m_blt->bind();
|
||||||
|
QMatrix4x4 target = QOpenGLTextureBlitter::targetTransform(QRect(0, 0, 2048, 2048), source);
|
||||||
|
m_blt->blit(m_texture->textureId(), target, QOpenGLTextureBlitter::Origin::OriginTopLeft);
|
||||||
|
m_blt->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareRenderer::setRenderType(RenderType type) {
|
void HardwareRenderer::setRenderType(RenderType type) {
|
||||||
@@ -37,7 +45,11 @@ void HardwareRenderer::setRenderType(RenderType type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HardwareRenderer::onBlit(const std::unique_ptr<uint8_t>* img, int x, int y, int w, int h, std::atomic_flag* in_use) {
|
void HardwareRenderer::onBlit(const std::unique_ptr<uint8_t>* img, int x, int y, int w, int h, std::atomic_flag* in_use) {
|
||||||
memcpy(image.bits(), img->get(), 2048 * 2048 * 4);
|
auto tval = this;
|
||||||
|
void* nuldata = 0;
|
||||||
|
if (memcmp(&tval, &nuldata, sizeof(void*)) == 0) return;
|
||||||
|
m_context->makeCurrent(this);
|
||||||
|
m_texture->setData(QOpenGLTexture::PixelFormat::RGBA, QOpenGLTexture::PixelType::UInt8, (const void*)img->get());
|
||||||
in_use->clear();
|
in_use->clear();
|
||||||
source.setRect(x, y, w, h);
|
source.setRect(x, y, w, h);
|
||||||
update();
|
update();
|
||||||
|
@@ -3,6 +3,10 @@
|
|||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
#include <QOpenGLWidget>
|
#include <QOpenGLWidget>
|
||||||
#include <QOpenGLWindow>
|
#include <QOpenGLWindow>
|
||||||
|
#include <QOpenGLTexture>
|
||||||
|
#include <QOpenGLShader>
|
||||||
|
#include <QOpenGLShaderProgram>
|
||||||
|
#include <QOpenGLTextureBlitter>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
@@ -25,6 +29,9 @@ private:
|
|||||||
bool wayland = false;
|
bool wayland = false;
|
||||||
QWidget* parentWidget{nullptr};
|
QWidget* parentWidget{nullptr};
|
||||||
QOpenGLContext* m_context;
|
QOpenGLContext* m_context;
|
||||||
|
QOpenGLTexture* m_texture;
|
||||||
|
QOpenGLShaderProgram* m_prog;
|
||||||
|
QOpenGLTextureBlitter* m_blt;
|
||||||
public:
|
public:
|
||||||
void resizeGL(int w, int h) override;
|
void resizeGL(int w, int h) override;
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
@@ -41,7 +48,8 @@ public:
|
|||||||
}
|
}
|
||||||
~HardwareRenderer()
|
~HardwareRenderer()
|
||||||
{
|
{
|
||||||
makeCurrent();
|
m_context->makeCurrent(this);
|
||||||
|
if (m_blt) m_blt->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class RenderType {
|
enum class RenderType {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QSurfaceFormat>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@@ -94,6 +95,9 @@ main_thread_fn()
|
|||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
|
||||||
|
fmt.setSwapInterval(0);
|
||||||
|
QSurfaceFormat::setDefaultFormat(fmt);
|
||||||
app.setStyle(new StyleOverride());
|
app.setStyle(new StyleOverride());
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
CocoaEventFilter cocoafilter;
|
CocoaEventFilter cocoafilter;
|
||||||
|
@@ -203,6 +203,7 @@ void RendererStack::switchRenderer(Renderer renderer) {
|
|||||||
current->setFocusProxy(this);
|
current->setFocusProxy(this);
|
||||||
addWidget(current.get());
|
addWidget(current.get());
|
||||||
|
|
||||||
|
this->setStyleSheet("background-color: black");
|
||||||
for (auto& in_use : buffers_in_use)
|
for (auto& in_use : buffers_in_use)
|
||||||
in_use.clear();
|
in_use.clear();
|
||||||
|
|
||||||
|
@@ -8,6 +8,9 @@ void SoftwareRenderer::paintEvent(QPaintEvent *event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SoftwareRenderer::onBlit(const std::unique_ptr<uint8_t>* img, int x, int y, int w, int h, std::atomic_flag* in_use) {
|
void SoftwareRenderer::onBlit(const std::unique_ptr<uint8_t>* img, int x, int y, int w, int h, std::atomic_flag* in_use) {
|
||||||
|
auto tval = this;
|
||||||
|
void* nuldata = 0;
|
||||||
|
if (memcmp(&tval, &nuldata, sizeof(void*)) == 0) return;
|
||||||
memcpy(image.bits(), img->get(), 2048 * 2048 * 4);
|
memcpy(image.bits(), img->get(), 2048 * 2048 * 4);
|
||||||
in_use->clear();
|
in_use->clear();
|
||||||
source.setRect(x, y, w, h);
|
source.setRect(x, y, w, h);
|
||||||
|
Reference in New Issue
Block a user