2021-12-04 21:33:04 +01:00
|
|
|
#include "qt_hardwarerenderer.hpp"
|
2021-12-08 16:36:55 +06:00
|
|
|
#include <QApplication>
|
2021-12-15 00:37:48 +02:00
|
|
|
#include <atomic>
|
2021-12-04 21:33:04 +01:00
|
|
|
|
2021-12-05 20:56:07 +01:00
|
|
|
extern "C" {
|
|
|
|
|
#include <86box/86box.h>
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 21:33:04 +01:00
|
|
|
void HardwareRenderer::resizeGL(int w, int h)
|
|
|
|
|
{
|
|
|
|
|
glViewport(0, 0, w, h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HardwareRenderer::initializeGL()
|
|
|
|
|
{
|
|
|
|
|
initializeOpenGLFunctions();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-07 13:47:42 +01:00
|
|
|
void HardwareRenderer::paintGL() {
|
|
|
|
|
onPaint(this);
|
2021-12-04 21:33:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HardwareRenderer::setRenderType(RenderType type) {
|
|
|
|
|
QSurfaceFormat format;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case RenderType::OpenGL:
|
|
|
|
|
setTextureFormat(GL_RGB);
|
|
|
|
|
format.setRenderableType(QSurfaceFormat::OpenGL);
|
|
|
|
|
break;
|
|
|
|
|
case RenderType::OpenGLES:
|
2021-12-08 16:36:55 +06:00
|
|
|
setTextureFormat((QApplication::platformName().contains("wayland") || QApplication::platformName() == "cocoa") ? GL_RGB : GL_RGBA);
|
2021-12-04 21:33:04 +01:00
|
|
|
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
setFormat(format);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-15 00:37:48 +02:00
|
|
|
void HardwareRenderer::onBlit(const QImage& img, int x, int y, int w, int h, std::atomic_flag* in_use) {
|
2021-12-04 21:33:04 +01:00
|
|
|
image = img;
|
2021-12-07 13:47:42 +01:00
|
|
|
source.setRect(x, y, w, h);
|
2021-12-04 21:33:04 +01:00
|
|
|
update();
|
2021-12-15 00:37:48 +02:00
|
|
|
in_use->clear();
|
2021-12-04 21:33:04 +01:00
|
|
|
}
|
2021-12-07 13:47:42 +01:00
|
|
|
|
|
|
|
|
void HardwareRenderer::resizeEvent(QResizeEvent *event) {
|
|
|
|
|
onResize(width(), height());
|
|
|
|
|
QOpenGLWidget::resizeEvent(event);
|
|
|
|
|
}
|