Files
86Box/src/qt/qt_hardwarerenderer.cpp
ts-korhonen 7c2cd35965 qt: Add overload protection to renderers
Added atomic_flags for renderer buffers to prevent concurrent usage and
overloading the renderer with draw requests when it's busy.
2021-12-15 00:37:48 +02:00

49 lines
1.1 KiB
C++

#include "qt_hardwarerenderer.hpp"
#include <QApplication>
#include <atomic>
extern "C" {
#include <86box/86box.h>
}
void HardwareRenderer::resizeGL(int w, int h)
{
glViewport(0, 0, w, h);
}
void HardwareRenderer::initializeGL()
{
initializeOpenGLFunctions();
}
void HardwareRenderer::paintGL() {
onPaint(this);
}
void HardwareRenderer::setRenderType(RenderType type) {
QSurfaceFormat format;
switch (type) {
case RenderType::OpenGL:
setTextureFormat(GL_RGB);
format.setRenderableType(QSurfaceFormat::OpenGL);
break;
case RenderType::OpenGLES:
setTextureFormat((QApplication::platformName().contains("wayland") || QApplication::platformName() == "cocoa") ? GL_RGB : GL_RGBA);
format.setRenderableType(QSurfaceFormat::OpenGLES);
break;
}
setFormat(format);
}
void HardwareRenderer::onBlit(const QImage& img, int x, int y, int w, int h, std::atomic_flag* in_use) {
image = img;
source.setRect(x, y, w, h);
update();
in_use->clear();
}
void HardwareRenderer::resizeEvent(QResizeEvent *event) {
onResize(width(), height());
QOpenGLWidget::resizeEvent(event);
}