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-17 18:37:57 +02:00
|
|
|
#include <86box/plat.h>
|
2021-12-05 20:56:07 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-04 21:33:04 +01:00
|
|
|
void HardwareRenderer::resizeGL(int w, int h)
|
|
|
|
|
{
|
|
|
|
|
glViewport(0, 0, w, h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HardwareRenderer::initializeGL()
|
|
|
|
|
{
|
2021-12-23 20:31:51 +02:00
|
|
|
m_context->makeCurrent(this);
|
2021-12-04 21:33:04 +01:00
|
|
|
initializeOpenGLFunctions();
|
2021-12-25 15:34:00 +06:00
|
|
|
m_texture = new QOpenGLTexture(image);
|
|
|
|
|
m_blt = new QOpenGLTextureBlitter;
|
|
|
|
|
m_blt->setRedBlueSwizzle(true);
|
|
|
|
|
m_blt->create();
|
2021-12-04 21:33:04 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-07 13:47:42 +01:00
|
|
|
void HardwareRenderer::paintGL() {
|
2021-12-25 15:34:00 +06:00
|
|
|
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();
|
2021-12-04 21:33:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HardwareRenderer::setRenderType(RenderType type) {
|
|
|
|
|
QSurfaceFormat format;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case RenderType::OpenGL:
|
|
|
|
|
format.setRenderableType(QSurfaceFormat::OpenGL);
|
|
|
|
|
break;
|
|
|
|
|
case RenderType::OpenGLES:
|
|
|
|
|
format.setRenderableType(QSurfaceFormat::OpenGLES);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-12-16 07:52:33 +02:00
|
|
|
format.setSwapInterval(0);
|
2021-12-04 21:33:04 +01:00
|
|
|
setFormat(format);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 16:38:13 +06:00
|
|
|
void HardwareRenderer::onBlit(const std::unique_ptr<uint8_t>* img, int x, int y, int w, int h, std::atomic_flag* in_use) {
|
2021-12-25 15:34:00 +06:00
|
|
|
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());
|
2021-12-21 16:38:13 +06:00
|
|
|
in_use->clear();
|
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-07 13:47:42 +01:00
|
|
|
|
|
|
|
|
void HardwareRenderer::resizeEvent(QResizeEvent *event) {
|
|
|
|
|
onResize(width(), height());
|
2021-12-23 20:31:51 +02:00
|
|
|
|
2021-12-17 12:17:54 +06:00
|
|
|
QOpenGLWindow::resizeEvent(event);
|
2021-12-07 13:47:42 +01:00
|
|
|
}
|
2021-12-17 18:37:57 +02:00
|
|
|
|
2021-12-18 00:37:30 +06:00
|
|
|
bool HardwareRenderer::event(QEvent *event)
|
2021-12-17 18:37:57 +02:00
|
|
|
{
|
2021-12-18 00:37:30 +06:00
|
|
|
switch (event->type())
|
2021-12-17 18:37:57 +02:00
|
|
|
{
|
2021-12-18 00:37:30 +06:00
|
|
|
default:
|
|
|
|
|
return QOpenGLWindow::event(event);
|
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
|
case QEvent::MouseMove:
|
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
|
case QEvent::KeyPress:
|
|
|
|
|
case QEvent::KeyRelease:
|
|
|
|
|
case QEvent::Wheel:
|
|
|
|
|
case QEvent::Enter:
|
|
|
|
|
case QEvent::Leave:
|
|
|
|
|
return QApplication::sendEvent(parentWidget, event);
|
2021-12-17 18:37:57 +02:00
|
|
|
}
|
2021-12-18 00:37:30 +06:00
|
|
|
return false;
|
|
|
|
|
}
|